blob: adf4ebe6bb78816aba436dc23844d6ce27d83245 [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;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700458 }
Zhu Yib481de92007-09-25 17:54:57 -0700459
Winkler, Tomase52119c2008-12-22 11:31:19 +0800460 tx->driver_txop = 0;
461 tx->tx_flags = tx_flags;
462 tx->next_frame_len = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700463}
464
Zhu Yib481de92007-09-25 17:54:57 -0700465/*
466 * start REPLY_TX command process
467 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800468static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -0700469{
470 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berge039fa42008-05-15 12:55:29 +0200471 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800472 struct iwl3945_tx_cmd *tx;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800473 struct iwl_tx_queue *txq = NULL;
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800474 struct iwl_queue *q = NULL;
Johannes Bergc2acea82009-07-24 11:13:05 -0700475 struct iwl_device_cmd *out_cmd;
476 struct iwl_cmd_meta *out_meta;
Zhu Yib481de92007-09-25 17:54:57 -0700477 dma_addr_t phys_addr;
478 dma_addr_t txcmd_phys;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800479 int txq_id = skb_get_queue_mapping(skb);
Reinette Chatredf833b12009-04-21 10:55:48 -0700480 u16 len, idx, len_org, hdr_len; /* TODO: len_org is not used */
Tomas Winkler54dbb522008-05-15 13:54:06 +0800481 u8 id;
482 u8 unicast;
Zhu Yib481de92007-09-25 17:54:57 -0700483 u8 sta_id;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800484 u8 tid = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700485 u16 seq_number = 0;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700486 __le16 fc;
Zhu Yib481de92007-09-25 17:54:57 -0700487 u8 wait_write_ptr = 0;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800488 u8 *qc = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700489 unsigned long flags;
490 int rc;
491
492 spin_lock_irqsave(&priv->lock, flags);
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800493 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800494 IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
Zhu Yib481de92007-09-25 17:54:57 -0700495 goto drop_unlock;
496 }
497
Johannes Berge039fa42008-05-15 12:55:29 +0200498 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800499 IWL_ERR(priv, "ERROR: No TX rate available.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700500 goto drop_unlock;
501 }
502
503 unicast = !is_multicast_ether_addr(hdr->addr1);
504 id = 0;
505
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700506 fc = hdr->frame_control;
Zhu Yib481de92007-09-25 17:54:57 -0700507
Samuel Ortizd08853a2009-01-23 13:45:17 -0800508#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -0700509 if (ieee80211_is_auth(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800510 IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700511 else if (ieee80211_is_assoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800512 IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700513 else if (ieee80211_is_reassoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800514 IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
Zhu Yib481de92007-09-25 17:54:57 -0700515#endif
516
Gábor Stefanikaa065262009-08-21 20:44:09 +0200517 /* drop all non-injected data frame if we are not associated */
Stefanik Gábor914233d2008-06-30 17:23:30 +0800518 if (ieee80211_is_data(fc) &&
Gábor Stefanikaa065262009-08-21 20:44:09 +0200519 !(info->flags & IEEE80211_TX_CTL_INJECTED) &&
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800520 (!iwl_is_associated(priv) ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200521 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
Tomas Winklere1623442009-01-27 14:27:56 -0800522 IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n");
Zhu Yib481de92007-09-25 17:54:57 -0700523 goto drop_unlock;
524 }
525
526 spin_unlock_irqrestore(&priv->lock, flags);
527
Harvey Harrison7294ec92008-07-15 18:43:59 -0700528 hdr_len = ieee80211_hdrlen(fc);
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800529
530 /* Find (or create) index into station table for destination station */
Gábor Stefanikaa065262009-08-21 20:44:09 +0200531 if (info->flags & IEEE80211_TX_CTL_INJECTED)
532 sta_id = priv->hw_params.bcast_sta_id;
533 else
534 sta_id = iwl_get_sta_id(priv, hdr);
Zhu Yib481de92007-09-25 17:54:57 -0700535 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -0800536 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -0700537 hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700538 goto drop;
539 }
540
Tomas Winklere1623442009-01-27 14:27:56 -0800541 IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id);
Zhu Yib481de92007-09-25 17:54:57 -0700542
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700543 if (ieee80211_is_data_qos(fc)) {
544 qc = ieee80211_get_qos_ctl(hdr);
Harvey Harrison7294ec92008-07-15 18:43:59 -0700545 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
Reinette Chatree6a6cf42009-08-13 13:30:50 -0700546 if (unlikely(tid >= MAX_TID_COUNT))
547 goto drop;
Tomas Winklerc587de02009-06-03 11:44:07 -0700548 seq_number = priv->stations[sta_id].tid[tid].seq_number &
Zhu Yib481de92007-09-25 17:54:57 -0700549 IEEE80211_SCTL_SEQ;
550 hdr->seq_ctrl = cpu_to_le16(seq_number) |
551 (hdr->seq_ctrl &
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -0800552 cpu_to_le16(IEEE80211_SCTL_FRAG));
Zhu Yib481de92007-09-25 17:54:57 -0700553 seq_number += 0x10;
554 }
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800555
556 /* Descriptor for chosen Tx queue */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800557 txq = &priv->txq[txq_id];
Zhu Yib481de92007-09-25 17:54:57 -0700558 q = &txq->q;
559
560 spin_lock_irqsave(&priv->lock, flags);
561
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800562 idx = get_cmd_index(q, q->write_ptr, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700563
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800564 /* Set up driver data for this TFD */
Winkler, Tomasdbb66542008-12-22 11:31:14 +0800565 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800566 txq->txb[q->write_ptr].skb[0] = skb;
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800567
568 /* Init first empty entry in queue's array of Tx/cmd buffers */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800569 out_cmd = txq->cmd[idx];
Johannes Bergc2acea82009-07-24 11:13:05 -0700570 out_meta = &txq->meta[idx];
Winkler, Tomase52119c2008-12-22 11:31:19 +0800571 tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
Zhu Yib481de92007-09-25 17:54:57 -0700572 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
Winkler, Tomase52119c2008-12-22 11:31:19 +0800573 memset(tx, 0, sizeof(*tx));
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800574
575 /*
576 * Set up the Tx-command (not MAC!) header.
577 * Store the chosen Tx queue and TFD index within the sequence field;
578 * after Tx, uCode's Tx response will return this value so driver can
579 * locate the frame within the tx queue and do post-tx processing.
580 */
Zhu Yib481de92007-09-25 17:54:57 -0700581 out_cmd->hdr.cmd = REPLY_TX;
582 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800583 INDEX_TO_SEQ(q->write_ptr)));
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800584
585 /* Copy MAC header from skb into command buffer */
Winkler, Tomase52119c2008-12-22 11:31:19 +0800586 memcpy(tx->hdr, hdr, hdr_len);
Zhu Yib481de92007-09-25 17:54:57 -0700587
Reinette Chatredf833b12009-04-21 10:55:48 -0700588
589 if (info->control.hw_key)
590 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, sta_id);
591
592 /* TODO need this for burst mode later on */
593 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
594
595 /* set is_hcca to 0; it probably will never be implemented */
596 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
597
598 /* Total # bytes to be transmitted */
599 len = (u16)skb->len;
600 tx->len = cpu_to_le16(len);
601
Wey-Yi Guy20594eb2009-08-07 15:41:39 -0700602 iwl_dbg_log_tx_data_frame(priv, len, hdr);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700603 iwl_update_stats(priv, true, fc, len);
Reinette Chatredf833b12009-04-21 10:55:48 -0700604 tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
605 tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
606
607 if (!ieee80211_has_morefrags(hdr->frame_control)) {
608 txq->need_update = 1;
609 if (qc)
Tomas Winklerc587de02009-06-03 11:44:07 -0700610 priv->stations[sta_id].tid[tid].seq_number = seq_number;
Reinette Chatredf833b12009-04-21 10:55:48 -0700611 } else {
612 wait_write_ptr = 1;
613 txq->need_update = 0;
614 }
615
616 IWL_DEBUG_TX(priv, "sequence nr = 0X%x \n",
617 le16_to_cpu(out_cmd->hdr.sequence));
618 IWL_DEBUG_TX(priv, "tx_flags = 0X%x \n", le32_to_cpu(tx->tx_flags));
Reinette Chatre3d816c72009-08-07 15:41:37 -0700619 iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx));
620 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr,
Reinette Chatredf833b12009-04-21 10:55:48 -0700621 ieee80211_hdrlen(fc));
622
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800623 /*
624 * Use the first empty entry in this queue's command buffer array
625 * to contain the Tx command and MAC header concatenated together
626 * (payload data will be in another buffer).
627 * Size of this varies, due to varying MAC header length.
628 * If end is not dword aligned, we'll have 2 extra bytes at the end
629 * of the MAC header (device reads on dword boundaries).
630 * We'll tell device about this padding later.
631 */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800632 len = sizeof(struct iwl3945_tx_cmd) +
Tomas Winkler4c897252008-12-19 10:37:05 +0800633 sizeof(struct iwl_cmd_header) + hdr_len;
Zhu Yib481de92007-09-25 17:54:57 -0700634
635 len_org = len;
636 len = (len + 3) & ~3;
637
638 if (len_org != len)
639 len_org = 1;
640 else
641 len_org = 0;
642
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800643 /* Physical address of this Tx command's header (not MAC header!),
644 * within command buffer array. */
Reinette Chatredf833b12009-04-21 10:55:48 -0700645 txcmd_phys = pci_map_single(priv->pci_dev, &out_cmd->hdr,
646 len, PCI_DMA_TODEVICE);
647 /* we do not map meta data ... so we can safely access address to
648 * provide to unmap command*/
Johannes Bergc2acea82009-07-24 11:13:05 -0700649 pci_unmap_addr_set(out_meta, mapping, txcmd_phys);
650 pci_unmap_len_set(out_meta, len, len);
Zhu Yib481de92007-09-25 17:54:57 -0700651
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800652 /* Add buffer containing Tx command and MAC(!) header to TFD's
653 * first entry */
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800654 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
655 txcmd_phys, len, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700656
Zhu Yib481de92007-09-25 17:54:57 -0700657
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800658 /* Set up TFD's 2nd entry to point directly to remainder of skb,
659 * if any (802.11 null frames have no payload). */
Zhu Yib481de92007-09-25 17:54:57 -0700660 len = skb->len - hdr_len;
661 if (len) {
662 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
663 len, PCI_DMA_TODEVICE);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800664 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
665 phys_addr, len,
666 0, U32_PAD(len));
Zhu Yib481de92007-09-25 17:54:57 -0700667 }
668
Zhu Yib481de92007-09-25 17:54:57 -0700669
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800670 /* Tell device the write index *just past* this latest filled TFD */
Tomas Winklerc54b6792008-03-06 17:36:53 -0800671 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -0800672 rc = iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -0700673 spin_unlock_irqrestore(&priv->lock, flags);
674
675 if (rc)
676 return rc;
677
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800678 if ((iwl_queue_space(q) < q->high_mark)
Zhu Yib481de92007-09-25 17:54:57 -0700679 && priv->mac80211_registered) {
680 if (wait_write_ptr) {
681 spin_lock_irqsave(&priv->lock, flags);
682 txq->need_update = 1;
Samuel Ortiz4f3602c2009-01-19 15:30:25 -0800683 iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -0700684 spin_unlock_irqrestore(&priv->lock, flags);
685 }
686
Johannes Berge4e72fb2009-03-23 17:28:42 +0100687 iwl_stop_queue(priv, skb_get_queue_mapping(skb));
Zhu Yib481de92007-09-25 17:54:57 -0700688 }
689
690 return 0;
691
692drop_unlock:
693 spin_unlock_irqrestore(&priv->lock, flags);
694drop:
695 return -1;
696}
697
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800698#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -0700699
700#include "iwl-spectrum.h"
701
702#define BEACON_TIME_MASK_LOW 0x00FFFFFF
703#define BEACON_TIME_MASK_HIGH 0xFF000000
704#define TIME_UNIT 1024
705
706/*
707 * extended beacon time format
708 * time in usec will be changed into a 32-bit value in 8:24 format
709 * the high 1 byte is the beacon counts
710 * the lower 3 bytes is the time in usec within one beacon interval
711 */
712
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800713static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -0700714{
715 u32 quot;
716 u32 rem;
717 u32 interval = beacon_interval * 1024;
718
719 if (!interval || !usec)
720 return 0;
721
722 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
723 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
724
725 return (quot << 24) + rem;
726}
727
728/* base is usually what we get from ucode with each received frame,
729 * the same as HW timer counter counting down
730 */
731
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800732static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -0700733{
734 u32 base_low = base & BEACON_TIME_MASK_LOW;
735 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
736 u32 interval = beacon_interval * TIME_UNIT;
737 u32 res = (base & BEACON_TIME_MASK_HIGH) +
738 (addon & BEACON_TIME_MASK_HIGH);
739
740 if (base_low > addon_low)
741 res += base_low - addon_low;
742 else if (base_low < addon_low) {
743 res += interval + base_low - addon_low;
744 res += (1 << 24);
745 } else
746 res += (1 << 24);
747
748 return cpu_to_le32(res);
749}
750
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800751static int iwl3945_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700752 struct ieee80211_measurement_params *params,
753 u8 type)
754{
Tomas Winkler600c0e12008-12-19 10:37:04 +0800755 struct iwl_spectrum_cmd spectrum;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800756 struct iwl_rx_packet *res;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800757 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700758 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
759 .data = (void *)&spectrum,
Johannes Bergc2acea82009-07-24 11:13:05 -0700760 .flags = CMD_WANT_SKB,
Zhu Yib481de92007-09-25 17:54:57 -0700761 };
762 u32 add_time = le64_to_cpu(params->start_time);
763 int rc;
764 int spectrum_resp_status;
765 int duration = le16_to_cpu(params->duration);
766
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800767 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700768 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800769 iwl3945_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -0700770 le64_to_cpu(params->start_time) - priv->last_tsf,
771 le16_to_cpu(priv->rxon_timing.beacon_interval));
772
773 memset(&spectrum, 0, sizeof(spectrum));
774
775 spectrum.channel_count = cpu_to_le16(1);
776 spectrum.flags =
777 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
778 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
779 cmd.len = sizeof(spectrum);
780 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
781
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800782 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700783 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800784 iwl3945_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -0700785 add_time,
786 le16_to_cpu(priv->rxon_timing.beacon_interval));
787 else
788 spectrum.start_time = 0;
789
790 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
791 spectrum.channels[0].channel = params->channel;
792 spectrum.channels[0].type = type;
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800793 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
Zhu Yib481de92007-09-25 17:54:57 -0700794 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
795 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
796
Samuel Ortiz518099a2009-01-19 15:30:27 -0800797 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700798 if (rc)
799 return rc;
800
Johannes Bergc2acea82009-07-24 11:13:05 -0700801 res = (struct iwl_rx_packet *)cmd.reply_skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700802 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800803 IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -0700804 rc = -EIO;
805 }
806
807 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
808 switch (spectrum_resp_status) {
809 case 0: /* Command will be handled */
810 if (res->u.spectrum.id != 0xff) {
Tomas Winklere1623442009-01-27 14:27:56 -0800811 IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n",
Ian Schrambc434dd2007-10-25 17:15:29 +0800812 res->u.spectrum.id);
Zhu Yib481de92007-09-25 17:54:57 -0700813 priv->measurement_status &= ~MEASUREMENT_READY;
814 }
815 priv->measurement_status |= MEASUREMENT_ACTIVE;
816 rc = 0;
817 break;
818
819 case 1: /* Command will not be handled */
820 rc = -EAGAIN;
821 break;
822 }
823
Johannes Bergc2acea82009-07-24 11:13:05 -0700824 dev_kfree_skb_any(cmd.reply_skb);
Zhu Yib481de92007-09-25 17:54:57 -0700825
826 return rc;
827}
828#endif
829
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800830static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +0800831 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700832{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800833 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
834 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -0700835 struct delayed_work *pwork;
836
837 palive = &pkt->u.alive_frame;
838
Tomas Winklere1623442009-01-27 14:27:56 -0800839 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
Zhu Yib481de92007-09-25 17:54:57 -0700840 "0x%01X 0x%01X\n",
841 palive->is_valid, palive->ver_type,
842 palive->ver_subtype);
843
844 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
Tomas Winklere1623442009-01-27 14:27:56 -0800845 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800846 memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
847 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700848 pwork = &priv->init_alive_start;
849 } else {
Tomas Winklere1623442009-01-27 14:27:56 -0800850 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700851 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800852 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700853 pwork = &priv->alive_start;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800854 iwl3945_disable_events(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700855 }
856
857 /* We delay the ALIVE response by 5ms to
858 * give the HW RF Kill time to activate... */
859 if (palive->is_valid == UCODE_VALID_OK)
860 queue_delayed_work(priv->workqueue, pwork,
861 msecs_to_jiffies(5));
862 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800863 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700864}
865
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800866static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +0800867 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700868{
Helmut Schaac7e035a2009-01-19 13:02:15 +0100869#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800870 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Helmut Schaac7e035a2009-01-19 13:02:15 +0100871#endif
Zhu Yib481de92007-09-25 17:54:57 -0700872
Tomas Winklere1623442009-01-27 14:27:56 -0800873 IWL_DEBUG_RX(priv, "Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
Zhu Yib481de92007-09-25 17:54:57 -0700874 return;
875}
876
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800877static void iwl3945_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -0700878{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800879 struct iwl_priv *priv =
880 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -0700881 struct sk_buff *beacon;
882
883 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +0200884 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -0700885
886 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800887 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -0700888 return;
889 }
890
891 mutex_lock(&priv->mutex);
892 /* new beacon skb is allocated every time; dispose previous.*/
893 if (priv->ibss_beacon)
894 dev_kfree_skb(priv->ibss_beacon);
895
896 priv->ibss_beacon = beacon;
897 mutex_unlock(&priv->mutex);
898
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800899 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700900}
901
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800902static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +0800903 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700904{
Samuel Ortizd08853a2009-01-23 13:45:17 -0800905#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800906 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800907 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
Zhu Yib481de92007-09-25 17:54:57 -0700908 u8 rate = beacon->beacon_notify_hdr.rate;
909
Tomas Winklere1623442009-01-27 14:27:56 -0800910 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
Zhu Yib481de92007-09-25 17:54:57 -0700911 "tsf %d %d rate %d\n",
912 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
913 beacon->beacon_notify_hdr.failure_frame,
914 le32_to_cpu(beacon->ibss_mgr_status),
915 le32_to_cpu(beacon->high_tsf),
916 le32_to_cpu(beacon->low_tsf), rate);
917#endif
918
Johannes Berg05c914f2008-09-11 00:01:58 +0200919 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -0700920 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
921 queue_work(priv->workqueue, &priv->beacon_update);
922}
923
Zhu Yib481de92007-09-25 17:54:57 -0700924/* Handle notification from uCode that card's power state is changing
925 * due to software, hardware, or critical temperature RFKILL */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800926static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +0800927 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700928{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800929 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700930 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
931 unsigned long status = priv->status;
932
Reinette Chatre4c423a22009-07-17 09:30:26 -0700933 IWL_WARN(priv, "Card state received: HW:%s SW:%s\n",
Zhu Yib481de92007-09-25 17:54:57 -0700934 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
935 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
936
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +0800937 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -0700938 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
939
940 if (flags & HW_CARD_DISABLED)
941 set_bit(STATUS_RF_KILL_HW, &priv->status);
942 else
943 clear_bit(STATUS_RF_KILL_HW, &priv->status);
944
945
Winkler, Tomasaf0053d2009-01-19 15:30:23 -0800946 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700947
948 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
Johannes Berga60e77e2009-06-04 18:26:06 +0200949 test_bit(STATUS_RF_KILL_HW, &priv->status)))
950 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
951 test_bit(STATUS_RF_KILL_HW, &priv->status));
Zhu Yib481de92007-09-25 17:54:57 -0700952 else
953 wake_up_interruptible(&priv->wait_command_queue);
954}
955
956/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800957 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -0700958 *
959 * Setup the RX handlers for each of the reply types sent from the uCode
960 * to the host.
961 *
962 * This function chains into the hardware specific files for them to setup
963 * any hardware specific handlers as well.
964 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800965static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700966{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800967 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
968 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -0800969 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800970 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -0800971 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700972 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -0800973 iwl_rx_pm_debug_statistics_notif;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800974 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700975
Ben Cahill9fbab512007-11-29 11:09:47 +0800976 /*
977 * The same handler is used for both the REPLY to a discrete
978 * statistics request from the host as well as for the periodic
979 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -0700980 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800981 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
982 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -0700983
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -0800984 iwl_setup_spectrum_handlers(priv);
Abhijeet Kolekarcade0eb2009-02-18 15:54:26 -0800985 iwl_setup_rx_scan_handlers(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800986 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700987
Ben Cahill9fbab512007-11-29 11:09:47 +0800988 /* Set up hardware specific Rx handlers */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800989 iwl3945_hw_rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700990}
991
Zhu Yib481de92007-09-25 17:54:57 -0700992/************************** RX-FUNCTIONS ****************************/
993/*
994 * Rx theory of operation
995 *
996 * The host allocates 32 DMA target addresses and passes the host address
997 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
998 * 0 to 31
999 *
1000 * Rx Queue Indexes
1001 * The host/firmware share two index registers for managing the Rx buffers.
1002 *
1003 * The READ index maps to the first position that the firmware may be writing
1004 * to -- the driver can read up to (but not including) this position and get
1005 * good data.
1006 * The READ index is managed by the firmware once the card is enabled.
1007 *
1008 * The WRITE index maps to the last position the driver has read from -- the
1009 * position preceding WRITE is the last slot the firmware can place a packet.
1010 *
1011 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
1012 * WRITE = READ.
1013 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001014 * During initialization, the host sets up the READ queue position to the first
Zhu Yib481de92007-09-25 17:54:57 -07001015 * INDEX position, and WRITE to the last (READ - 1 wrapped)
1016 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001017 * When the firmware places a packet in a buffer, it will advance the READ index
Zhu Yib481de92007-09-25 17:54:57 -07001018 * and fire the RX interrupt. The driver can then query the READ index and
1019 * process as many packets as possible, moving the WRITE index forward as it
1020 * resets the Rx queue buffers with new memory.
1021 *
1022 * The management in the driver is as follows:
1023 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
1024 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Ian Schram01ebd062007-10-25 17:15:22 +08001025 * to replenish the iwl->rxq->rx_free.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001026 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
Zhu Yib481de92007-09-25 17:54:57 -07001027 * iwl->rxq is replenished and the READ INDEX is updated (updating the
1028 * 'processed' and 'read' driver indexes as well)
1029 * + A received packet is processed and handed to the kernel network stack,
1030 * detached from the iwl->rxq. The driver 'processed' index is updated.
1031 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
1032 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
1033 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
1034 * were enough free buffers and RX_STALLED is set it is cleared.
1035 *
1036 *
1037 * Driver sequence:
1038 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001039 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001040 * iwl3945_rx_queue_restock
Ben Cahill9fbab512007-11-29 11:09:47 +08001041 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
Zhu Yib481de92007-09-25 17:54:57 -07001042 * queue, updates firmware pointers, and updates
1043 * the WRITE index. If insufficient rx_free buffers
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001044 * are available, schedules iwl3945_rx_replenish
Zhu Yib481de92007-09-25 17:54:57 -07001045 *
1046 * -- enable interrupts --
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001047 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
Zhu Yib481de92007-09-25 17:54:57 -07001048 * READ INDEX, detaching the SKB from the pool.
1049 * Moves the packet buffer from queue to rx_used.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001050 * Calls iwl3945_rx_queue_restock to refill any empty
Zhu Yib481de92007-09-25 17:54:57 -07001051 * slots.
1052 * ...
1053 *
1054 */
1055
1056/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001057 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
Zhu Yib481de92007-09-25 17:54:57 -07001058 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001059static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001060 dma_addr_t dma_addr)
1061{
1062 return cpu_to_le32((u32)dma_addr);
1063}
1064
1065/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001066 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
Zhu Yib481de92007-09-25 17:54:57 -07001067 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001068 * If there are slots in the RX queue that need to be restocked,
Zhu Yib481de92007-09-25 17:54:57 -07001069 * and we have free pre-allocated buffers, fill the ranks as much
Ben Cahill9fbab512007-11-29 11:09:47 +08001070 * as we can, pulling from rx_free.
Zhu Yib481de92007-09-25 17:54:57 -07001071 *
1072 * This moves the 'write' index forward to catch up with 'processed', and
1073 * also updates the memory address in the firmware to reference the new
1074 * target buffer.
1075 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001076static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001077{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001078 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001079 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001080 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001081 unsigned long flags;
1082 int write, rc;
1083
1084 spin_lock_irqsave(&rxq->lock, flags);
1085 write = rxq->write & ~0x7;
Winkler, Tomas37d68312009-01-08 10:19:54 -08001086 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001087 /* Get next free Rx buffer, remove from free list */
Zhu Yib481de92007-09-25 17:54:57 -07001088 element = rxq->rx_free.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001089 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07001090 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001091
1092 /* Point to Rx buffer via next RBD in circular buffer */
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001093 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
Zhu Yib481de92007-09-25 17:54:57 -07001094 rxq->queue[rxq->write] = rxb;
1095 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
1096 rxq->free_count--;
1097 }
1098 spin_unlock_irqrestore(&rxq->lock, flags);
1099 /* If the pre-allocated buffer pool is dropping low, schedule to
1100 * refill it */
1101 if (rxq->free_count <= RX_LOW_WATERMARK)
1102 queue_work(priv->workqueue, &priv->rx_replenish);
1103
1104
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001105 /* If we've added more space for the firmware to place data, tell it.
1106 * Increment device's write pointer in multiples of 8. */
Abhijeet Kolekard14d4442009-06-03 11:44:08 -07001107 if ((rxq->write_actual != (rxq->write & ~0x7))
Zhu Yib481de92007-09-25 17:54:57 -07001108 || (abs(rxq->write - rxq->read) > 7)) {
1109 spin_lock_irqsave(&rxq->lock, flags);
1110 rxq->need_update = 1;
1111 spin_unlock_irqrestore(&rxq->lock, flags);
Winkler, Tomas141c43a2009-01-08 10:19:53 -08001112 rc = iwl_rx_queue_update_write_ptr(priv, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07001113 if (rc)
1114 return rc;
1115 }
1116
1117 return 0;
1118}
1119
1120/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001121 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
Zhu Yib481de92007-09-25 17:54:57 -07001122 *
1123 * When moving to rx_free an SKB is allocated for the slot.
1124 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001125 * Also restock the Rx queue via iwl3945_rx_queue_restock.
Ian Schram01ebd062007-10-25 17:15:22 +08001126 * This is called as a scheduled work item (except for during initialization)
Zhu Yib481de92007-09-25 17:54:57 -07001127 */
Abhijeet Kolekard14d4442009-06-03 11:44:08 -07001128static void iwl3945_rx_allocate(struct iwl_priv *priv, gfp_t priority)
Zhu Yib481de92007-09-25 17:54:57 -07001129{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001130 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001131 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001132 struct iwl_rx_mem_buffer *rxb;
Reinette Chatrede0bd502009-09-11 10:38:12 -07001133 struct sk_buff *skb;
Zhu Yib481de92007-09-25 17:54:57 -07001134 unsigned long flags;
Abhijeet Kolekar72240492009-04-30 13:56:26 -07001135
1136 while (1) {
1137 spin_lock_irqsave(&rxq->lock, flags);
1138
1139 if (list_empty(&rxq->rx_used)) {
1140 spin_unlock_irqrestore(&rxq->lock, flags);
1141 return;
1142 }
Abhijeet Kolekar72240492009-04-30 13:56:26 -07001143 spin_unlock_irqrestore(&rxq->lock, flags);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001144
Reinette Chatref82a9242009-09-17 10:43:56 -07001145 if (rxq->free_count > RX_LOW_WATERMARK)
1146 priority |= __GFP_NOWARN;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001147 /* Alloc a new receive buffer */
Reinette Chatrede0bd502009-09-11 10:38:12 -07001148 skb = alloc_skb(priv->hw_params.rx_buf_size, priority);
1149 if (!skb) {
Zhu Yib481de92007-09-25 17:54:57 -07001150 if (net_ratelimit())
Reinette Chatref82a9242009-09-17 10:43:56 -07001151 IWL_DEBUG_INFO(priv, "Failed to allocate SKB buffer.\n");
1152 if ((rxq->free_count <= RX_LOW_WATERMARK) &&
1153 net_ratelimit())
1154 IWL_CRIT(priv, "Failed to allocate SKB buffer with %s. Only %u free buffers remaining.\n",
1155 priority == GFP_ATOMIC ? "GFP_ATOMIC" : "GFP_KERNEL",
1156 rxq->free_count);
Zhu Yib481de92007-09-25 17:54:57 -07001157 /* We don't reschedule replenish work here -- we will
1158 * call the restock method and if it still needs
1159 * more buffers it will schedule replenish */
1160 break;
1161 }
Zhu Yi12342c42007-12-20 11:27:32 +08001162
Reinette Chatrede0bd502009-09-11 10:38:12 -07001163 spin_lock_irqsave(&rxq->lock, flags);
1164 if (list_empty(&rxq->rx_used)) {
1165 spin_unlock_irqrestore(&rxq->lock, flags);
1166 dev_kfree_skb_any(skb);
1167 return;
1168 }
1169 element = rxq->rx_used.next;
1170 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
1171 list_del(element);
1172 spin_unlock_irqrestore(&rxq->lock, flags);
1173
1174 rxb->skb = skb;
1175
Zhu Yi12342c42007-12-20 11:27:32 +08001176 /* If radiotap head is required, reserve some headroom here.
1177 * The physical head count is a variable rx_stats->phy_count.
1178 * We reserve 4 bytes here. Plus these extra bytes, the
1179 * headroom of the physical head should be enough for the
1180 * radiotap head that iwl3945 supported. See iwl3945_rt.
1181 */
1182 skb_reserve(rxb->skb, 4);
1183
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001184 /* Get physical address of RB/SKB */
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001185 rxb->real_dma_addr = pci_map_single(priv->pci_dev,
1186 rxb->skb->data,
1187 priv->hw_params.rx_buf_size,
1188 PCI_DMA_FROMDEVICE);
Abhijeet Kolekar72240492009-04-30 13:56:26 -07001189
1190 spin_lock_irqsave(&rxq->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -07001191 list_add_tail(&rxb->list, &rxq->rx_free);
Abhijeet Kolekar72240492009-04-30 13:56:26 -07001192 priv->alloc_rxb_skb++;
Zhu Yib481de92007-09-25 17:54:57 -07001193 rxq->free_count++;
Abhijeet Kolekar72240492009-04-30 13:56:26 -07001194 spin_unlock_irqrestore(&rxq->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -07001195 }
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001196}
1197
Reinette Chatredf833b12009-04-21 10:55:48 -07001198void iwl3945_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
1199{
1200 unsigned long flags;
1201 int i;
1202 spin_lock_irqsave(&rxq->lock, flags);
1203 INIT_LIST_HEAD(&rxq->rx_free);
1204 INIT_LIST_HEAD(&rxq->rx_used);
1205 /* Fill the rx_used queue with _all_ of the Rx buffers */
1206 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
1207 /* In the reset function, these buffers may have been allocated
1208 * to an SKB, so we need to unmap and free potential storage */
1209 if (rxq->pool[i].skb != NULL) {
1210 pci_unmap_single(priv->pci_dev,
1211 rxq->pool[i].real_dma_addr,
1212 priv->hw_params.rx_buf_size,
1213 PCI_DMA_FROMDEVICE);
1214 priv->alloc_rxb_skb--;
1215 dev_kfree_skb(rxq->pool[i].skb);
1216 rxq->pool[i].skb = NULL;
1217 }
1218 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
1219 }
1220
1221 /* Set us so that we have processed and used all buffers, but have
1222 * not restocked the Rx queue with fresh buffers */
1223 rxq->read = rxq->write = 0;
1224 rxq->free_count = 0;
Abhijeet Kolekard14d4442009-06-03 11:44:08 -07001225 rxq->write_actual = 0;
Reinette Chatredf833b12009-04-21 10:55:48 -07001226 spin_unlock_irqrestore(&rxq->lock, flags);
1227}
Reinette Chatredf833b12009-04-21 10:55:48 -07001228
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001229void iwl3945_rx_replenish(void *data)
1230{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001231 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001232 unsigned long flags;
1233
Abhijeet Kolekard14d4442009-06-03 11:44:08 -07001234 iwl3945_rx_allocate(priv, GFP_KERNEL);
Zhu Yib481de92007-09-25 17:54:57 -07001235
1236 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001237 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001238 spin_unlock_irqrestore(&priv->lock, flags);
1239}
1240
Abhijeet Kolekard14d4442009-06-03 11:44:08 -07001241static void iwl3945_rx_replenish_now(struct iwl_priv *priv)
1242{
1243 iwl3945_rx_allocate(priv, GFP_ATOMIC);
1244
1245 iwl3945_rx_queue_restock(priv);
1246}
1247
1248
Reinette Chatredf833b12009-04-21 10:55:48 -07001249/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
1250 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
1251 * This free routine walks the list of POOL entries and if SKB is set to
1252 * non NULL it is unmapped and freed
1253 */
1254static void iwl3945_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
1255{
1256 int i;
1257 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
1258 if (rxq->pool[i].skb != NULL) {
1259 pci_unmap_single(priv->pci_dev,
1260 rxq->pool[i].real_dma_addr,
1261 priv->hw_params.rx_buf_size,
1262 PCI_DMA_FROMDEVICE);
1263 dev_kfree_skb(rxq->pool[i].skb);
1264 }
1265 }
1266
1267 pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd,
1268 rxq->dma_addr);
1269 pci_free_consistent(priv->pci_dev, sizeof(struct iwl_rb_status),
1270 rxq->rb_stts, rxq->rb_stts_dma);
1271 rxq->bd = NULL;
1272 rxq->rb_stts = NULL;
1273}
Reinette Chatredf833b12009-04-21 10:55:48 -07001274
1275
Zhu Yib481de92007-09-25 17:54:57 -07001276/* Convert linear signal-to-noise ratio into dB */
1277static u8 ratio2dB[100] = {
1278/* 0 1 2 3 4 5 6 7 8 9 */
1279 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
1280 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
1281 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
1282 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
1283 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
1284 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
1285 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
1286 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
1287 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
1288 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
1289};
1290
1291/* Calculates a relative dB value from a ratio of linear
1292 * (i.e. not dB) signal levels.
1293 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001294int iwl3945_calc_db_from_ratio(int sig_ratio)
Zhu Yib481de92007-09-25 17:54:57 -07001295{
Adrian Bunk221c80c2008-02-02 23:19:01 +02001296 /* 1000:1 or higher just report as 60 dB */
1297 if (sig_ratio >= 1000)
Zhu Yib481de92007-09-25 17:54:57 -07001298 return 60;
1299
Adrian Bunk221c80c2008-02-02 23:19:01 +02001300 /* 100:1 or higher, divide by 10 and use table,
Zhu Yib481de92007-09-25 17:54:57 -07001301 * add 20 dB to make up for divide by 10 */
Adrian Bunk221c80c2008-02-02 23:19:01 +02001302 if (sig_ratio >= 100)
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001303 return 20 + (int)ratio2dB[sig_ratio/10];
Zhu Yib481de92007-09-25 17:54:57 -07001304
1305 /* We shouldn't see this */
1306 if (sig_ratio < 1)
1307 return 0;
1308
1309 /* Use table for ratios 1:1 - 99:1 */
1310 return (int)ratio2dB[sig_ratio];
1311}
1312
1313#define PERFECT_RSSI (-20) /* dBm */
1314#define WORST_RSSI (-95) /* dBm */
1315#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
1316
1317/* Calculate an indication of rx signal quality (a percentage, not dBm!).
1318 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
1319 * about formulas used below. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001320int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
Zhu Yib481de92007-09-25 17:54:57 -07001321{
1322 int sig_qual;
1323 int degradation = PERFECT_RSSI - rssi_dbm;
1324
1325 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
1326 * as indicator; formula is (signal dbm - noise dbm).
1327 * SNR at or above 40 is a great signal (100%).
1328 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
1329 * Weakest usable signal is usually 10 - 15 dB SNR. */
1330 if (noise_dbm) {
1331 if (rssi_dbm - noise_dbm >= 40)
1332 return 100;
1333 else if (rssi_dbm < noise_dbm)
1334 return 0;
1335 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
1336
1337 /* Else use just the signal level.
1338 * This formula is a least squares fit of data points collected and
1339 * compared with a reference system that had a percentage (%) display
1340 * for signal quality. */
1341 } else
1342 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
1343 (15 * RSSI_RANGE + 62 * degradation)) /
1344 (RSSI_RANGE * RSSI_RANGE);
1345
1346 if (sig_qual > 100)
1347 sig_qual = 100;
1348 else if (sig_qual < 1)
1349 sig_qual = 0;
1350
1351 return sig_qual;
1352}
1353
1354/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001355 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001356 *
1357 * Uses the priv->rx_handlers callback function array to invoke
1358 * the appropriate handlers, including command responses,
1359 * frame-received notifications, and other notifications.
1360 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001361static void iwl3945_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001362{
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001363 struct iwl_rx_mem_buffer *rxb;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001364 struct iwl_rx_packet *pkt;
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001365 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001366 u32 r, i;
1367 int reclaim;
1368 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001369 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001370 u32 count = 8;
Abhijeet Kolekard14d4442009-06-03 11:44:08 -07001371 int total_empty = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001372
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001373 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1374 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8cd812b2008-12-19 10:37:43 +08001375 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07001376 i = rxq->read;
1377
Abhijeet Kolekard14d4442009-06-03 11:44:08 -07001378 /* calculate total frames need to be restock after handling RX */
1379 total_empty = r - priv->rxq.write_actual;
1380 if (total_empty < 0)
1381 total_empty += RX_QUEUE_SIZE;
1382
1383 if (total_empty > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001384 fill_rx = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001385 /* Rx interrupt, but nothing sent from uCode */
1386 if (i == r)
Reinette Chatreaf472a952009-08-28 09:58:50 -07001387 IWL_DEBUG_RX(priv, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001388
1389 while (i != r) {
1390 rxb = rxq->queue[i];
1391
Ben Cahill9fbab512007-11-29 11:09:47 +08001392 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001393 * then a bug has been introduced in the queue refilling
1394 * routines -- catch it here */
1395 BUG_ON(rxb == NULL);
1396
1397 rxq->queue[i] = NULL;
1398
Reinette Chatredf833b12009-04-21 10:55:48 -07001399 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
1400 priv->hw_params.rx_buf_size,
1401 PCI_DMA_FROMDEVICE);
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001402 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001403
Johannes Bergbe1a71a2009-10-02 13:44:02 -07001404 trace_iwlwifi_dev_rx(priv, pkt,
1405 le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK);
1406
Zhu Yib481de92007-09-25 17:54:57 -07001407 /* Reclaim a command buffer only if this packet is a response
1408 * to a (driver-originated) command.
1409 * If the packet (e.g. Rx frame) originated from uCode,
1410 * there is no command buffer to reclaim.
1411 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1412 * but apparently a few don't get set; catch them here. */
1413 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1414 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1415 (pkt->hdr.cmd != REPLY_TX);
1416
1417 /* Based on type of command response or notification,
1418 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001419 * rx_handlers table. See iwl3945_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001420 if (priv->rx_handlers[pkt->hdr.cmd]) {
Reinette Chatreaf472a952009-08-28 09:58:50 -07001421 IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r, i,
Zhu Yib481de92007-09-25 17:54:57 -07001422 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
1423 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001424 priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
Zhu Yib481de92007-09-25 17:54:57 -07001425 } else {
1426 /* No handling needed */
Reinette Chatreaf472a952009-08-28 09:58:50 -07001427 IWL_DEBUG_RX(priv, "r %d i %d No handler needed for %s, 0x%02x\n",
Zhu Yib481de92007-09-25 17:54:57 -07001428 r, i, get_cmd_string(pkt->hdr.cmd),
1429 pkt->hdr.cmd);
1430 }
1431
1432 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001433 /* Invoke any callbacks, transfer the skb to caller, and
Samuel Ortiz518099a2009-01-19 15:30:27 -08001434 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001435 * as we reclaim the driver command queue */
1436 if (rxb && rxb->skb)
Abhijeet Kolekar732587a2009-03-11 11:17:57 -07001437 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001438 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001439 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07001440 }
1441
1442 /* For now we just don't re-use anything. We can tweak this
1443 * later to try and re-use notification packets and SKBs that
1444 * fail to Rx correctly */
1445 if (rxb->skb != NULL) {
1446 priv->alloc_rxb_skb--;
1447 dev_kfree_skb_any(rxb->skb);
1448 rxb->skb = NULL;
1449 }
1450
Zhu Yib481de92007-09-25 17:54:57 -07001451 spin_lock_irqsave(&rxq->lock, flags);
1452 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1453 spin_unlock_irqrestore(&rxq->lock, flags);
1454 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001455 /* If there are a lot of unused frames,
1456 * restock the Rx queue so ucode won't assert. */
1457 if (fill_rx) {
1458 count++;
1459 if (count >= 8) {
1460 priv->rxq.read = i;
Abhijeet Kolekard14d4442009-06-03 11:44:08 -07001461 iwl3945_rx_replenish_now(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001462 count = 0;
1463 }
1464 }
Zhu Yib481de92007-09-25 17:54:57 -07001465 }
1466
1467 /* Backtrack one entry */
1468 priv->rxq.read = i;
Abhijeet Kolekard14d4442009-06-03 11:44:08 -07001469 if (fill_rx)
1470 iwl3945_rx_replenish_now(priv);
1471 else
1472 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001473}
1474
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001475/* call this function to flush any scheduled tasklet */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001476static inline void iwl_synchronize_irq(struct iwl_priv *priv)
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001477{
Tomas Winklera96a27f2008-10-23 23:48:56 -07001478 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001479 synchronize_irq(priv->pci_dev->irq);
1480 tasklet_kill(&priv->irq_tasklet);
1481}
1482
Reinette Chatreb7a79402009-09-25 14:24:23 -07001483#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001484static const char *desc_lookup(int i)
1485{
1486 switch (i) {
1487 case 1:
1488 return "FAIL";
1489 case 2:
1490 return "BAD_PARAM";
1491 case 3:
1492 return "BAD_CHECKSUM";
1493 case 4:
1494 return "NMI_INTERRUPT";
1495 case 5:
1496 return "SYSASSERT";
1497 case 6:
1498 return "FATAL_ERROR";
1499 }
1500
1501 return "UNKNOWN";
1502}
1503
1504#define ERROR_START_OFFSET (1 * sizeof(u32))
1505#define ERROR_ELEM_SIZE (7 * sizeof(u32))
1506
Reinette Chatreb7a79402009-09-25 14:24:23 -07001507void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001508{
1509 u32 i;
1510 u32 desc, time, count, base, data1;
1511 u32 blink1, blink2, ilink1, ilink2;
Zhu Yib481de92007-09-25 17:54:57 -07001512
1513 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
1514
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001515 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001516 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07001517 return;
1518 }
1519
Zhu Yib481de92007-09-25 17:54:57 -07001520
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001521 count = iwl_read_targ_mem(priv, base);
Zhu Yib481de92007-09-25 17:54:57 -07001522
1523 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001524 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
1525 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
1526 priv->status, count);
Zhu Yib481de92007-09-25 17:54:57 -07001527 }
1528
Winkler, Tomas15b16872008-12-19 10:37:33 +08001529 IWL_ERR(priv, "Desc Time asrtPC blink2 "
Zhu Yib481de92007-09-25 17:54:57 -07001530 "ilink1 nmiPC Line\n");
1531 for (i = ERROR_START_OFFSET;
1532 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
1533 i += ERROR_ELEM_SIZE) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001534 desc = iwl_read_targ_mem(priv, base + i);
Zhu Yib481de92007-09-25 17:54:57 -07001535 time =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001536 iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001537 blink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001538 iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001539 blink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001540 iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001541 ilink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001542 iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001543 ilink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001544 iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001545 data1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001546 iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001547
Winkler, Tomas15b16872008-12-19 10:37:33 +08001548 IWL_ERR(priv,
1549 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
1550 desc_lookup(desc), desc, time, blink1, blink2,
1551 ilink1, ilink2, data1);
Johannes Bergbe1a71a2009-10-02 13:44:02 -07001552 trace_iwlwifi_dev_ucode_error(priv, desc, time, data1, 0,
1553 0, blink1, blink2, ilink1, ilink2);
Zhu Yib481de92007-09-25 17:54:57 -07001554 }
Zhu Yib481de92007-09-25 17:54:57 -07001555}
1556
Ben Cahillf58177b2007-11-29 11:09:43 +08001557#define EVENT_START_OFFSET (6 * sizeof(u32))
Zhu Yib481de92007-09-25 17:54:57 -07001558
1559/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001560 * iwl3945_print_event_log - Dump error event log to syslog
Zhu Yib481de92007-09-25 17:54:57 -07001561 *
Zhu Yib481de92007-09-25 17:54:57 -07001562 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001563static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
Zhu Yib481de92007-09-25 17:54:57 -07001564 u32 num_events, u32 mode)
1565{
1566 u32 i;
1567 u32 base; /* SRAM byte address of event log header */
1568 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
1569 u32 ptr; /* SRAM byte address of log data */
1570 u32 ev, time, data; /* event log data */
1571
1572 if (num_events == 0)
1573 return;
1574
1575 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
1576
1577 if (mode == 0)
1578 event_size = 2 * sizeof(u32);
1579 else
1580 event_size = 3 * sizeof(u32);
1581
1582 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
1583
1584 /* "time" is actually "data" for mode 0 (no timestamp).
1585 * place event id # at far right for easier visual parsing. */
1586 for (i = 0; i < num_events; i++) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001587 ev = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07001588 ptr += sizeof(u32);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001589 time = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07001590 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08001591 if (mode == 0) {
1592 /* data, ev */
1593 IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
Johannes Bergbe1a71a2009-10-02 13:44:02 -07001594 trace_iwlwifi_dev_ucode_event(priv, 0, time, ev);
Winkler, Tomas15b16872008-12-19 10:37:33 +08001595 } else {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001596 data = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07001597 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08001598 IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
Johannes Bergbe1a71a2009-10-02 13:44:02 -07001599 trace_iwlwifi_dev_ucode_event(priv, time, data, ev);
Zhu Yib481de92007-09-25 17:54:57 -07001600 }
1601 }
1602}
1603
Reinette Chatreb7a79402009-09-25 14:24:23 -07001604void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001605{
Zhu Yib481de92007-09-25 17:54:57 -07001606 u32 base; /* SRAM byte address of event log header */
1607 u32 capacity; /* event log capacity in # entries */
1608 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
1609 u32 num_wraps; /* # times uCode wrapped to top of log */
1610 u32 next_entry; /* index of next entry to be written by uCode */
1611 u32 size; /* # entries that we'll print */
1612
1613 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001614 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001615 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07001616 return;
1617 }
1618
Zhu Yib481de92007-09-25 17:54:57 -07001619 /* event log header */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001620 capacity = iwl_read_targ_mem(priv, base);
1621 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
1622 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
1623 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -07001624
1625 size = num_wraps ? capacity : next_entry;
1626
1627 /* bail out if nothing in log */
1628 if (size == 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001629 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Zhu Yib481de92007-09-25 17:54:57 -07001630 return;
1631 }
1632
Winkler, Tomas15b16872008-12-19 10:37:33 +08001633 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07001634 size, num_wraps);
1635
1636 /* if uCode has wrapped back to top of log, start at the oldest entry,
1637 * i.e the next one that uCode would fill. */
1638 if (num_wraps)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001639 iwl3945_print_event_log(priv, next_entry,
Zhu Yib481de92007-09-25 17:54:57 -07001640 capacity - next_entry, mode);
1641
1642 /* (then/else) start at top of log */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001643 iwl3945_print_event_log(priv, 0, next_entry, mode);
Zhu Yib481de92007-09-25 17:54:57 -07001644
Zhu Yib481de92007-09-25 17:54:57 -07001645}
Reinette Chatreb7a79402009-09-25 14:24:23 -07001646#else
1647void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
1648{
1649}
1650
1651void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
1652{
1653}
1654
1655#endif
Zhu Yib481de92007-09-25 17:54:57 -07001656
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001657static void iwl3945_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001658{
1659 u32 inta, handled = 0;
1660 u32 inta_fh;
1661 unsigned long flags;
Samuel Ortizd08853a2009-01-23 13:45:17 -08001662#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001663 u32 inta_mask;
1664#endif
1665
1666 spin_lock_irqsave(&priv->lock, flags);
1667
1668 /* Ack/clear/reset pending uCode interrupts.
1669 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1670 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001671 inta = iwl_read32(priv, CSR_INT);
1672 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07001673
1674 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1675 * Any new interrupts that happen after this, either while we're
1676 * in this tasklet, or later, will show up in next ISR/tasklet. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001677 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1678 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001679
Samuel Ortizd08853a2009-01-23 13:45:17 -08001680#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001681 if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001682 /* just for debug */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001683 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Tomas Winklere1623442009-01-27 14:27:56 -08001684 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07001685 inta, inta_mask, inta_fh);
1686 }
1687#endif
1688
1689 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1690 * atomic, make sure that inta covers all the interrupts that
1691 * we've discovered, even if FH interrupt came in just after
1692 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001693 if (inta_fh & CSR39_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001694 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001695 if (inta_fh & CSR39_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001696 inta |= CSR_INT_BIT_FH_TX;
1697
1698 /* Now service all interrupt bits discovered above. */
1699 if (inta & CSR_INT_BIT_HW_ERR) {
Reinette Chatre58dba722009-07-17 09:30:25 -07001700 IWL_ERR(priv, "Hardware error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001701
1702 /* Tell the device to stop sending interrupts */
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08001703 iwl_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001704
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001705 priv->isr_stats.hw++;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001706 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001707
1708 handled |= CSR_INT_BIT_HW_ERR;
1709
1710 spin_unlock_irqrestore(&priv->lock, flags);
1711
1712 return;
1713 }
1714
Samuel Ortizd08853a2009-01-23 13:45:17 -08001715#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001716 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07001717 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001718 if (inta & CSR_INT_BIT_SCD) {
Tomas Winklere1623442009-01-27 14:27:56 -08001719 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
Joonwoo Park25c03d82008-01-23 10:15:20 -08001720 "the frame/frames.\n");
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001721 priv->isr_stats.sch++;
1722 }
Zhu Yib481de92007-09-25 17:54:57 -07001723
1724 /* Alive notification via Rx interrupt will do the real work */
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001725 if (inta & CSR_INT_BIT_ALIVE) {
Tomas Winklere1623442009-01-27 14:27:56 -08001726 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001727 priv->isr_stats.alive++;
1728 }
Zhu Yib481de92007-09-25 17:54:57 -07001729 }
1730#endif
1731 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001732 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07001733
Zhu Yib481de92007-09-25 17:54:57 -07001734 /* Error detected by uCode */
1735 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001736 IWL_ERR(priv, "Microcode SW error detected. "
1737 "Restarting 0x%X.\n", inta);
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001738 priv->isr_stats.sw++;
1739 priv->isr_stats.sw_err = inta;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001740 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001741 handled |= CSR_INT_BIT_SW_ERR;
1742 }
1743
1744 /* uCode wakes up after power-down sleep */
1745 if (inta & CSR_INT_BIT_WAKEUP) {
Tomas Winklere1623442009-01-27 14:27:56 -08001746 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
Winkler, Tomas141c43a2009-01-08 10:19:53 -08001747 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001748 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
1749 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
1750 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
1751 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
1752 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1753 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07001754
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001755 priv->isr_stats.wakeup++;
Zhu Yib481de92007-09-25 17:54:57 -07001756 handled |= CSR_INT_BIT_WAKEUP;
1757 }
1758
1759 /* All uCode command responses, including Tx command responses,
1760 * Rx "responses" (frame-received notification), and other
1761 * notifications from uCode come through here*/
1762 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001763 iwl3945_rx_handle(priv);
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001764 priv->isr_stats.rx++;
Zhu Yib481de92007-09-25 17:54:57 -07001765 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1766 }
1767
1768 if (inta & CSR_INT_BIT_FH_TX) {
Tomas Winklere1623442009-01-27 14:27:56 -08001769 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001770 priv->isr_stats.tx++;
Zhu Yib481de92007-09-25 17:54:57 -07001771
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001772 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07001773 iwl_write_direct32(priv, FH39_TCSR_CREDIT
1774 (FH39_SRVC_CHNL), 0x0);
Zhu Yib481de92007-09-25 17:54:57 -07001775 handled |= CSR_INT_BIT_FH_TX;
1776 }
1777
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001778 if (inta & ~handled) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001779 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001780 priv->isr_stats.unhandled++;
1781 }
Zhu Yib481de92007-09-25 17:54:57 -07001782
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001783 if (inta & ~priv->inta_mask) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001784 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001785 inta & ~priv->inta_mask);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001786 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001787 }
1788
1789 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001790 /* only Re-enable if disabled by irq */
1791 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08001792 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001793
Samuel Ortizd08853a2009-01-23 13:45:17 -08001794#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001795 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001796 inta = iwl_read32(priv, CSR_INT);
1797 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1798 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Tomas Winklere1623442009-01-27 14:27:56 -08001799 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
Zhu Yib481de92007-09-25 17:54:57 -07001800 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
1801 }
1802#endif
1803 spin_unlock_irqrestore(&priv->lock, flags);
1804}
1805
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001806static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01001807 enum ieee80211_band band,
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08001808 u8 is_active, u8 n_probes,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001809 struct iwl3945_scan_channel *scan_ch)
Zhu Yib481de92007-09-25 17:54:57 -07001810{
Johannes Berg4e05c232009-06-19 13:52:44 -07001811 struct ieee80211_channel *chan;
Johannes Berg8318d782008-01-24 19:38:38 +01001812 const struct ieee80211_supported_band *sband;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001813 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07001814 u16 passive_dwell = 0;
1815 u16 active_dwell = 0;
1816 int added, i;
1817
Kolekar, Abhijeetcbba18c2008-12-19 10:37:42 +08001818 sband = iwl_get_hw_mode(priv, band);
Johannes Berg8318d782008-01-24 19:38:38 +01001819 if (!sband)
Zhu Yib481de92007-09-25 17:54:57 -07001820 return 0;
1821
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08001822 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
1823 passive_dwell = iwl_get_passive_dwell_time(priv, band);
Zhu Yib481de92007-09-25 17:54:57 -07001824
Abhijeet Kolekar8f4807a2008-09-03 11:26:31 +08001825 if (passive_dwell <= active_dwell)
1826 passive_dwell = active_dwell + 1;
1827
Johannes Berg4e05c232009-06-19 13:52:44 -07001828 for (i = 0, added = 0; i < priv->scan_request->n_channels; i++) {
1829 chan = priv->scan_request->channels[i];
1830
1831 if (chan->band != band)
Johannes Berg182e2e62008-04-04 10:41:56 +02001832 continue;
1833
Johannes Berg4e05c232009-06-19 13:52:44 -07001834 scan_ch->channel = chan->hw_value;
Zhu Yib481de92007-09-25 17:54:57 -07001835
Samuel Ortize6148912009-01-23 13:45:15 -08001836 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07001837 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08001838 IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
Zhu Yib481de92007-09-25 17:54:57 -07001839 scan_ch->channel);
1840 continue;
1841 }
1842
Zhu Yib481de92007-09-25 17:54:57 -07001843 scan_ch->active_dwell = cpu_to_le16(active_dwell);
1844 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08001845 /* If passive , set up for auto-switch
1846 * and use long active_dwell time.
1847 */
1848 if (!is_active || is_channel_passive(ch_info) ||
Johannes Berg4e05c232009-06-19 13:52:44 -07001849 (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08001850 scan_ch->type = 0; /* passive */
1851 if (IWL_UCODE_API(priv->ucode_ver) == 1)
1852 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
1853 } else {
1854 scan_ch->type = 1; /* active */
1855 }
1856
1857 /* Set direct probe bits. These may be used both for active
1858 * scan channels (probes gets sent right away),
1859 * or for passive channels (probes get se sent only after
1860 * hearing clear Rx packet).*/
1861 if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
1862 if (n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08001863 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08001864 } else {
1865 /* uCode v1 does not allow setting direct probe bits on
1866 * passive channel. */
1867 if ((scan_ch->type & 1) && n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08001868 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08001869 }
Zhu Yib481de92007-09-25 17:54:57 -07001870
Ben Cahill9fbab512007-11-29 11:09:47 +08001871 /* Set txpower levels to defaults */
Zhu Yib481de92007-09-25 17:54:57 -07001872 scan_ch->tpc.dsp_atten = 110;
1873 /* scan_pwr_info->tpc.dsp_atten; */
1874
1875 /*scan_pwr_info->tpc.tx_gain; */
Johannes Berg8318d782008-01-24 19:38:38 +01001876 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07001877 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
1878 else {
1879 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
1880 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
Ben Cahill9fbab512007-11-29 11:09:47 +08001881 * power level:
Reinette Chatre8a1b0242008-01-14 17:46:25 -08001882 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
Zhu Yib481de92007-09-25 17:54:57 -07001883 */
1884 }
1885
Tomas Winklere1623442009-01-27 14:27:56 -08001886 IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n",
Zhu Yib481de92007-09-25 17:54:57 -07001887 scan_ch->channel,
1888 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
1889 (scan_ch->type & 1) ?
1890 active_dwell : passive_dwell);
1891
1892 scan_ch++;
1893 added++;
1894 }
1895
Tomas Winklere1623442009-01-27 14:27:56 -08001896 IWL_DEBUG_SCAN(priv, "total channels to scan %d \n", added);
Zhu Yib481de92007-09-25 17:54:57 -07001897 return added;
1898}
1899
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001900static void iwl3945_init_hw_rates(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001901 struct ieee80211_rate *rates)
1902{
1903 int i;
1904
1905 for (i = 0; i < IWL_RATE_COUNT; i++) {
Johannes Berg8318d782008-01-24 19:38:38 +01001906 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
1907 rates[i].hw_value = i; /* Rate scaling will work on indexes */
1908 rates[i].hw_value_short = i;
1909 rates[i].flags = 0;
Samuel Ortizd9829a62008-12-19 10:37:12 +08001910 if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
Zhu Yib481de92007-09-25 17:54:57 -07001911 /*
Johannes Berg8318d782008-01-24 19:38:38 +01001912 * If CCK != 1M then set short preamble rate flag.
Zhu Yib481de92007-09-25 17:54:57 -07001913 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001914 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
Johannes Berg8318d782008-01-24 19:38:38 +01001915 0 : IEEE80211_RATE_SHORT_PREAMBLE;
Zhu Yib481de92007-09-25 17:54:57 -07001916 }
Zhu Yib481de92007-09-25 17:54:57 -07001917 }
1918}
1919
Zhu Yib481de92007-09-25 17:54:57 -07001920/******************************************************************************
1921 *
1922 * uCode download functions
1923 *
1924 ******************************************************************************/
1925
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001926static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001927{
Tomas Winkler98c92212008-01-14 17:46:20 -08001928 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
1929 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
1930 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1931 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
1932 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1933 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001934}
1935
1936/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001937 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07001938 * looking at all data.
1939 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001940static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07001941{
1942 u32 val;
1943 u32 save_len = len;
1944 int rc = 0;
1945 u32 errcnt;
1946
Tomas Winklere1623442009-01-27 14:27:56 -08001947 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001948
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001949 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08001950 IWL39_RTC_INST_LOWER_BOUND);
Zhu Yib481de92007-09-25 17:54:57 -07001951
1952 errcnt = 0;
1953 for (; len > 0; len -= sizeof(u32), image++) {
1954 /* read data comes through single port, auto-incr addr */
1955 /* NOTE: Use the debugless read so we don't flood kernel log
1956 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001957 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07001958 if (val != le32_to_cpu(*image)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001959 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07001960 "offset 0x%x, is 0x%x, s/b 0x%x\n",
1961 save_len - len, val, le32_to_cpu(*image));
1962 rc = -EIO;
1963 errcnt++;
1964 if (errcnt >= 20)
1965 break;
1966 }
1967 }
1968
Zhu Yib481de92007-09-25 17:54:57 -07001969
1970 if (!errcnt)
Tomas Winklere1623442009-01-27 14:27:56 -08001971 IWL_DEBUG_INFO(priv,
1972 "ucode image in INSTRUCTION memory is good\n");
Zhu Yib481de92007-09-25 17:54:57 -07001973
1974 return rc;
1975}
1976
1977
1978/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001979 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07001980 * using sample data 100 bytes apart. If these sample points are good,
1981 * it's a pretty good bet that everything between them is good, too.
1982 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001983static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07001984{
1985 u32 val;
1986 int rc = 0;
1987 u32 errcnt = 0;
1988 u32 i;
1989
Tomas Winklere1623442009-01-27 14:27:56 -08001990 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001991
Zhu Yib481de92007-09-25 17:54:57 -07001992 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
1993 /* read data comes through single port, auto-incr addr */
1994 /* NOTE: Use the debugless read so we don't flood kernel log
1995 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001996 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08001997 i + IWL39_RTC_INST_LOWER_BOUND);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001998 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07001999 if (val != le32_to_cpu(*image)) {
2000#if 0 /* Enable this if you want to see details */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002001 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002002 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2003 i, val, *image);
2004#endif
2005 rc = -EIO;
2006 errcnt++;
2007 if (errcnt >= 3)
2008 break;
2009 }
2010 }
2011
Zhu Yib481de92007-09-25 17:54:57 -07002012 return rc;
2013}
2014
2015
2016/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002017 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
Zhu Yib481de92007-09-25 17:54:57 -07002018 * and verify its contents
2019 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002020static int iwl3945_verify_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002021{
2022 __le32 *image;
2023 u32 len;
2024 int rc = 0;
2025
2026 /* Try bootstrap */
2027 image = (__le32 *)priv->ucode_boot.v_addr;
2028 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002029 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002030 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002031 IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002032 return 0;
2033 }
2034
2035 /* Try initialize */
2036 image = (__le32 *)priv->ucode_init.v_addr;
2037 len = priv->ucode_init.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002038 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002039 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002040 IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002041 return 0;
2042 }
2043
2044 /* Try runtime/protocol */
2045 image = (__le32 *)priv->ucode_code.v_addr;
2046 len = priv->ucode_code.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002047 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002048 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002049 IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002050 return 0;
2051 }
2052
Winkler, Tomas15b16872008-12-19 10:37:33 +08002053 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
Zhu Yib481de92007-09-25 17:54:57 -07002054
Ben Cahill9fbab512007-11-29 11:09:47 +08002055 /* Since nothing seems to match, show first several data entries in
2056 * instruction SRAM, so maybe visual inspection will give a clue.
2057 * Selection of bootstrap image (vs. other images) is arbitrary. */
Zhu Yib481de92007-09-25 17:54:57 -07002058 image = (__le32 *)priv->ucode_boot.v_addr;
2059 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002060 rc = iwl3945_verify_inst_full(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002061
2062 return rc;
2063}
2064
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002065static void iwl3945_nic_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002066{
2067 /* Remove all resets to allow NIC to operate */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002068 iwl_write32(priv, CSR_RESET, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002069}
2070
2071/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002072 * iwl3945_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07002073 *
2074 * Copy into buffers for card to fetch via bus-mastering
2075 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002076static int iwl3945_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002077{
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002078 const struct iwl_ucode_header *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002079 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07002080 const struct firmware *ucode_raw;
2081 /* firmware file name contains uCode/driver compatibility version */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002082 const char *name_pre = priv->cfg->fw_name_pre;
2083 const unsigned int api_max = priv->cfg->ucode_api_max;
2084 const unsigned int api_min = priv->cfg->ucode_api_min;
2085 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07002086 u8 *src;
2087 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002088 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07002089
2090 /* Ask kernel firmware_class module to get the boot firmware off disk.
2091 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002092 for (index = api_max; index >= api_min; index--) {
2093 sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
2094 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
2095 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002096 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002097 buf, ret);
2098 if (ret == -ENOENT)
2099 continue;
2100 else
2101 goto error;
2102 } else {
2103 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002104 IWL_ERR(priv, "Loaded firmware %s, "
2105 "which is deprecated. "
2106 " Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002107 buf, api_max);
Tomas Winklere1623442009-01-27 14:27:56 -08002108 IWL_DEBUG_INFO(priv, "Got firmware '%s' file "
2109 "(%zd bytes) from disk\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002110 buf, ucode_raw->size);
2111 break;
2112 }
Zhu Yib481de92007-09-25 17:54:57 -07002113 }
2114
Reinette Chatrea0987a82008-12-02 12:14:06 -08002115 if (ret < 0)
2116 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07002117
2118 /* Make sure that we got at least our header! */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002119 if (ucode_raw->size < priv->cfg->ops->ucode->get_header_size(1)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002120 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002121 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002122 goto err_release;
2123 }
2124
2125 /* Data from ucode file: header followed by uCode images */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002126 ucode = (struct iwl_ucode_header *)ucode_raw->data;
Zhu Yib481de92007-09-25 17:54:57 -07002127
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08002128 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08002129 api_ver = IWL_UCODE_API(priv->ucode_ver);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002130 inst_size = priv->cfg->ops->ucode->get_inst_size(ucode, api_ver);
2131 data_size = priv->cfg->ops->ucode->get_data_size(ucode, api_ver);
2132 init_size = priv->cfg->ops->ucode->get_init_size(ucode, api_ver);
2133 init_data_size =
2134 priv->cfg->ops->ucode->get_init_data_size(ucode, api_ver);
2135 boot_size = priv->cfg->ops->ucode->get_boot_size(ucode, api_ver);
2136 src = priv->cfg->ops->ucode->get_data(ucode, api_ver);
Zhu Yib481de92007-09-25 17:54:57 -07002137
Reinette Chatrea0987a82008-12-02 12:14:06 -08002138 /* api_ver should match the api version forming part of the
2139 * firmware filename ... but we don't check for that and only rely
Nick Andrew877d0312009-01-26 11:06:57 +01002140 * on the API version read from firmware header from here on forward */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002141
2142 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002143 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002144 "Driver supports v%u, firmware is v%u.\n",
2145 api_max, api_ver);
2146 priv->ucode_ver = 0;
2147 ret = -EINVAL;
2148 goto err_release;
2149 }
2150 if (api_ver != api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002151 IWL_ERR(priv, "Firmware has old API version. Expected %u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002152 "got %u. New firmware can be obtained "
2153 "from http://www.intellinuxwireless.org.\n",
2154 api_max, api_ver);
2155
Tomas Winkler978785a2008-12-19 10:37:31 +08002156 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
2157 IWL_UCODE_MAJOR(priv->ucode_ver),
2158 IWL_UCODE_MINOR(priv->ucode_ver),
2159 IWL_UCODE_API(priv->ucode_ver),
2160 IWL_UCODE_SERIAL(priv->ucode_ver));
2161
Tomas Winklere1623442009-01-27 14:27:56 -08002162 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002163 priv->ucode_ver);
Tomas Winklere1623442009-01-27 14:27:56 -08002164 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
2165 inst_size);
2166 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
2167 data_size);
2168 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
2169 init_size);
2170 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
2171 init_data_size);
2172 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
2173 boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07002174
Reinette Chatrea0987a82008-12-02 12:14:06 -08002175
Zhu Yib481de92007-09-25 17:54:57 -07002176 /* Verify size of file vs. image size info in file's header */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002177 if (ucode_raw->size != priv->cfg->ops->ucode->get_header_size(api_ver) +
Zhu Yib481de92007-09-25 17:54:57 -07002178 inst_size + data_size + init_size +
2179 init_data_size + boot_size) {
2180
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002181 IWL_DEBUG_INFO(priv,
2182 "uCode file size %zd does not match expected size\n",
2183 ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002184 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002185 goto err_release;
2186 }
2187
2188 /* Verify that uCode images will fit in card's SRAM */
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002189 if (inst_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002190 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002191 inst_size);
2192 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002193 goto err_release;
2194 }
2195
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002196 if (data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002197 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002198 data_size);
2199 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002200 goto err_release;
2201 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002202 if (init_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002203 IWL_DEBUG_INFO(priv,
2204 "uCode init instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002205 init_size);
2206 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002207 goto err_release;
2208 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002209 if (init_data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002210 IWL_DEBUG_INFO(priv,
2211 "uCode init data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002212 init_data_size);
2213 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002214 goto err_release;
2215 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002216 if (boot_size > IWL39_MAX_BSM_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002217 IWL_DEBUG_INFO(priv,
2218 "uCode boot instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002219 boot_size);
2220 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002221 goto err_release;
2222 }
2223
2224 /* Allocate ucode buffers for card's bus-master loading ... */
2225
2226 /* Runtime instructions and 2 copies of data:
2227 * 1) unmodified from disk
2228 * 2) backup cache for save/restore during power-downs */
2229 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002230 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07002231
2232 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002233 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07002234
2235 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002236 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07002237
2238 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
Tomas Winkler90e759d2007-11-29 11:09:41 +08002239 !priv->ucode_data_backup.v_addr)
Zhu Yib481de92007-09-25 17:54:57 -07002240 goto err_pci_alloc;
2241
Tomas Winkler90e759d2007-11-29 11:09:41 +08002242 /* Initialization instructions and data */
2243 if (init_size && init_data_size) {
2244 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002245 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002246
2247 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002248 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002249
2250 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
2251 goto err_pci_alloc;
2252 }
2253
2254 /* Bootstrap (instructions only, no data) */
2255 if (boot_size) {
2256 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002257 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002258
2259 if (!priv->ucode_boot.v_addr)
2260 goto err_pci_alloc;
2261 }
2262
Zhu Yib481de92007-09-25 17:54:57 -07002263 /* Copy images into buffers for card's bus-master reads ... */
2264
2265 /* Runtime instructions (first block of data in file) */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002266 len = inst_size;
Tomas Winklere1623442009-01-27 14:27:56 -08002267 IWL_DEBUG_INFO(priv,
2268 "Copying (but not loading) uCode instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002269 memcpy(priv->ucode_code.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002270 src += len;
2271
Tomas Winklere1623442009-01-27 14:27:56 -08002272 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002273 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
2274
2275 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002276 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002277 len = data_size;
Tomas Winklere1623442009-01-27 14:27:56 -08002278 IWL_DEBUG_INFO(priv,
2279 "Copying (but not loading) uCode data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002280 memcpy(priv->ucode_data.v_addr, src, len);
2281 memcpy(priv->ucode_data_backup.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002282 src += len;
Zhu Yib481de92007-09-25 17:54:57 -07002283
2284 /* Initialization instructions (3rd block) */
2285 if (init_size) {
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002286 len = init_size;
Tomas Winklere1623442009-01-27 14:27:56 -08002287 IWL_DEBUG_INFO(priv,
2288 "Copying (but not loading) init instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002289 memcpy(priv->ucode_init.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002290 src += len;
Zhu Yib481de92007-09-25 17:54:57 -07002291 }
2292
2293 /* Initialization data (4th block) */
2294 if (init_data_size) {
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002295 len = init_data_size;
Tomas Winklere1623442009-01-27 14:27:56 -08002296 IWL_DEBUG_INFO(priv,
2297 "Copying (but not loading) init data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002298 memcpy(priv->ucode_init_data.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002299 src += len;
Zhu Yib481de92007-09-25 17:54:57 -07002300 }
2301
2302 /* Bootstrap instructions (5th block) */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002303 len = boot_size;
Tomas Winklere1623442009-01-27 14:27:56 -08002304 IWL_DEBUG_INFO(priv,
2305 "Copying (but not loading) boot instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002306 memcpy(priv->ucode_boot.v_addr, src, len);
2307
2308 /* We have our copies now, allow OS release its copies */
2309 release_firmware(ucode_raw);
2310 return 0;
2311
2312 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002313 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002314 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002315 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002316
2317 err_release:
2318 release_firmware(ucode_raw);
2319
2320 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08002321 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002322}
2323
2324
2325/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002326 * iwl3945_set_ucode_ptrs - Set uCode address location
Zhu Yib481de92007-09-25 17:54:57 -07002327 *
2328 * Tell initialization uCode where to find runtime uCode.
2329 *
2330 * BSM registers initially contain pointers to initialization uCode.
2331 * We need to replace them to load runtime uCode inst and data,
2332 * and to save runtime data when powering down.
2333 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002334static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002335{
2336 dma_addr_t pinst;
2337 dma_addr_t pdata;
Zhu Yib481de92007-09-25 17:54:57 -07002338
2339 /* bits 31:0 for 3945 */
2340 pinst = priv->ucode_code.p_addr;
2341 pdata = priv->ucode_data_backup.p_addr;
2342
Zhu Yib481de92007-09-25 17:54:57 -07002343 /* Tell bootstrap uCode where to find image to load */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002344 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
2345 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
2346 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002347 priv->ucode_data.len);
2348
Tomas Winklera96a27f2008-10-23 23:48:56 -07002349 /* Inst byte count must be last to set up, bit 31 signals uCode
Zhu Yib481de92007-09-25 17:54:57 -07002350 * that all new ptr/size info is in place */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002351 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002352 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
2353
Tomas Winklere1623442009-01-27 14:27:56 -08002354 IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002355
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07002356 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002357}
2358
2359/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002360 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002361 *
2362 * Called after REPLY_ALIVE notification received from "initialize" uCode.
2363 *
Zhu Yib481de92007-09-25 17:54:57 -07002364 * Tell "initialize" uCode to go ahead and load the runtime uCode.
Ben Cahill9fbab512007-11-29 11:09:47 +08002365 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002366static void iwl3945_init_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002367{
2368 /* Check alive response for "valid" sign from uCode */
2369 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
2370 /* We had an error bringing up the hardware, so take it
2371 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002372 IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002373 goto restart;
2374 }
2375
2376 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
2377 * This is a paranoid check, because we would not have gotten the
2378 * "initialize" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002379 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002380 /* Runtime instruction load was bad;
2381 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002382 IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002383 goto restart;
2384 }
2385
2386 /* Send pointers to protocol/runtime uCode image ... init code will
2387 * load and launch runtime uCode, which will send us another "Alive"
2388 * notification. */
Tomas Winklere1623442009-01-27 14:27:56 -08002389 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002390 if (iwl3945_set_ucode_ptrs(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002391 /* Runtime instruction load won't happen;
2392 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002393 IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002394 goto restart;
2395 }
2396 return;
2397
2398 restart:
2399 queue_work(priv->workqueue, &priv->restart);
2400}
2401
Zhu Yib481de92007-09-25 17:54:57 -07002402/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002403 * iwl3945_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002404 * from protocol/runtime uCode (initialization uCode's
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002405 * Alive gets handled by iwl3945_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07002406 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002407static void iwl3945_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002408{
Zhu Yib481de92007-09-25 17:54:57 -07002409 int thermal_spin = 0;
2410 u32 rfkill;
2411
Tomas Winklere1623442009-01-27 14:27:56 -08002412 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002413
2414 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
2415 /* We had an error bringing up the hardware, so take it
2416 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002417 IWL_DEBUG_INFO(priv, "Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002418 goto restart;
2419 }
2420
2421 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2422 * This is a paranoid check, because we would not have gotten the
2423 * "runtime" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002424 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002425 /* Runtime instruction load was bad;
2426 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002427 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002428 goto restart;
2429 }
2430
Tomas Winklerc587de02009-06-03 11:44:07 -07002431 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002432
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002433 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
Tomas Winklere1623442009-01-27 14:27:56 -08002434 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
Zhu Yib481de92007-09-25 17:54:57 -07002435
2436 if (rfkill & 0x1) {
2437 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winklera96a27f2008-10-23 23:48:56 -07002438 /* if RFKILL is not on, then wait for thermal
Zhu Yib481de92007-09-25 17:54:57 -07002439 * sensor in adapter to kick in */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002440 while (iwl3945_hw_get_temperature(priv) == 0) {
Zhu Yib481de92007-09-25 17:54:57 -07002441 thermal_spin++;
2442 udelay(10);
2443 }
2444
2445 if (thermal_spin)
Tomas Winklere1623442009-01-27 14:27:56 -08002446 IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n",
Zhu Yib481de92007-09-25 17:54:57 -07002447 thermal_spin * 10);
2448 } else
2449 set_bit(STATUS_RF_KILL_HW, &priv->status);
2450
Ben Cahill9fbab512007-11-29 11:09:47 +08002451 /* After the ALIVE response, we can send commands to 3945 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07002452 set_bit(STATUS_ALIVE, &priv->status);
2453
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002454 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002455 return;
2456
Johannes Berg36d68252008-05-15 12:55:26 +02002457 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002458
2459 priv->active_rate = priv->rates_mask;
2460 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
2461
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08002462 iwl_power_update_mode(priv, false);
Zhu Yib481de92007-09-25 17:54:57 -07002463
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002464 if (iwl_is_associated(priv)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002465 struct iwl3945_rxon_cmd *active_rxon =
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002466 (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07002467
Abhijeet Kolekar8a9b9922009-06-12 13:22:52 -07002468 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07002469 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2470 } else {
2471 /* Initialize our rx_config data */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002472 iwl_connection_init_rx_config(priv, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002473 }
2474
Ben Cahill9fbab512007-11-29 11:09:47 +08002475 /* Configure Bluetooth device coexistence support */
Samuel Ortiz17f841c2009-01-23 13:45:20 -08002476 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002477
2478 /* Configure the adapter for unassociated operation */
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002479 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002480
Zhu Yib481de92007-09-25 17:54:57 -07002481 iwl3945_reg_txpower_periodic(priv);
2482
Johannes Berge932a602009-10-02 13:44:03 -07002483 iwl_leds_init(priv);
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07002484
Tomas Winklere1623442009-01-27 14:27:56 -08002485 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07002486 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a669262008-01-14 17:46:18 -08002487 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07002488
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08002489 /* reassociate for ADHOC mode */
2490 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
2491 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
2492 priv->vif);
2493 if (beacon)
Abhijeet Kolekar9944b932009-04-08 11:26:36 -07002494 iwl_mac_beacon_update(priv->hw, beacon);
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08002495 }
2496
Abhijeet Kolekarf45c2712009-04-08 11:26:38 -07002497 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
Abhijeet Kolekar727882d2009-04-08 11:26:45 -07002498 iwl_set_mode(priv, priv->iw_mode);
Abhijeet Kolekarf45c2712009-04-08 11:26:38 -07002499
Zhu Yib481de92007-09-25 17:54:57 -07002500 return;
2501
2502 restart:
2503 queue_work(priv->workqueue, &priv->restart);
2504}
2505
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002506static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07002507
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002508static void __iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002509{
2510 unsigned long flags;
2511 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
2512 struct ieee80211_conf *conf = NULL;
2513
Tomas Winklere1623442009-01-27 14:27:56 -08002514 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07002515
2516 conf = ieee80211_get_hw_conf(priv->hw);
2517
2518 if (!exit_pending)
2519 set_bit(STATUS_EXIT_PENDING, &priv->status);
2520
Tomas Winklerc587de02009-06-03 11:44:07 -07002521 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002522
2523 /* Unblock any waiting calls */
2524 wake_up_interruptible_all(&priv->wait_command_queue);
2525
Zhu Yib481de92007-09-25 17:54:57 -07002526 /* Wipe out the EXIT_PENDING status bit if we are not actually
2527 * exiting the module */
2528 if (!exit_pending)
2529 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2530
2531 /* stop and reset the on-board processor */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002532 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07002533
2534 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002535 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002536 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002537 spin_unlock_irqrestore(&priv->lock, flags);
2538 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002539
2540 if (priv->mac80211_registered)
2541 ieee80211_stop_queues(priv->hw);
2542
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002543 /* If we have not previously called iwl3945_init() then
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002544 * clear all bits but the RF Kill bits and return */
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002545 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002546 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2547 STATUS_RF_KILL_HW |
Reinette Chatre97888642008-02-06 11:20:38 -08002548 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2549 STATUS_GEO_CONFIGURED |
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08002550 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2551 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002552 goto exit;
2553 }
2554
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002555 /* ...otherwise clear out all the status bits but the RF Kill
Johannes Berga60e77e2009-06-04 18:26:06 +02002556 * bit and continue taking the NIC down. */
Zhu Yib481de92007-09-25 17:54:57 -07002557 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2558 STATUS_RF_KILL_HW |
Reinette Chatre97888642008-02-06 11:20:38 -08002559 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2560 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002561 test_bit(STATUS_FW_ERROR, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08002562 STATUS_FW_ERROR |
2563 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2564 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002565
Abbas, Mohamede9414b62009-01-20 21:33:55 -08002566 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002567 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002568 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07002569 spin_unlock_irqrestore(&priv->lock, flags);
2570
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002571 iwl3945_hw_txq_ctx_stop(priv);
2572 iwl3945_hw_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002573
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07002574 iwl_write_prph(priv, APMG_CLK_DIS_REG,
2575 APMG_CLK_VAL_DMA_CLK_RQT);
Zhu Yib481de92007-09-25 17:54:57 -07002576
2577 udelay(5);
2578
Ben Cahill4d2ccdb2009-10-09 13:20:20 -07002579 /* Stop the device, and put it in low power state */
2580 priv->cfg->ops->lib->apm_ops.stop(priv);
Abbas, Mohamede9414b62009-01-20 21:33:55 -08002581
Zhu Yib481de92007-09-25 17:54:57 -07002582 exit:
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002583 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07002584
2585 if (priv->ibss_beacon)
2586 dev_kfree_skb(priv->ibss_beacon);
2587 priv->ibss_beacon = NULL;
2588
2589 /* clear out any free frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002590 iwl3945_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002591}
2592
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002593static void iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002594{
2595 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002596 __iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002597 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08002598
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002599 iwl3945_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002600}
2601
2602#define MAX_HW_RESTARTS 5
2603
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002604static int __iwl3945_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002605{
2606 int rc, i;
2607
2608 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002609 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07002610 return -EIO;
2611 }
2612
Reinette Chatree903fbd2008-01-30 22:05:15 -08002613 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002614 IWL_ERR(priv, "ucode not available for device bring up\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08002615 return -EIO;
2616 }
2617
Zhu Yie655b9f2008-01-24 02:19:38 -08002618 /* If platform's RF_KILL switch is NOT set to KILL */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002619 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08002620 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
2621 clear_bit(STATUS_RF_KILL_HW, &priv->status);
2622 else {
2623 set_bit(STATUS_RF_KILL_HW, &priv->status);
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002624 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
2625 return -ENODEV;
Zhu Yib481de92007-09-25 17:54:57 -07002626 }
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002627
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002628 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07002629
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002630 rc = iwl3945_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002631 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002632 IWL_ERR(priv, "Unable to int nic\n");
Zhu Yib481de92007-09-25 17:54:57 -07002633 return rc;
2634 }
2635
2636 /* make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002637 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2638 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07002639 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2640
2641 /* clear (again), then enable host interrupts */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002642 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002643 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002644
2645 /* really make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002646 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2647 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07002648
2649 /* Copy original ucode data image from disk into backup cache.
2650 * This will be used to initialize the on-board processor's
2651 * data SRAM for a clean start when the runtime program first loads. */
2652 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a669262008-01-14 17:46:18 -08002653 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07002654
Zhu Yie655b9f2008-01-24 02:19:38 -08002655 /* We return success when we resume from suspend and rf_kill is on. */
2656 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
2657 return 0;
2658
Zhu Yib481de92007-09-25 17:54:57 -07002659 for (i = 0; i < MAX_HW_RESTARTS; i++) {
2660
Tomas Winklerc587de02009-06-03 11:44:07 -07002661 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002662
2663 /* load bootstrap state machine,
2664 * load bootstrap program into processor's memory,
2665 * prepare to load the "initialize" uCode */
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002666 priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002667
2668 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002669 IWL_ERR(priv,
2670 "Unable to set up bootstrap uCode: %d\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -07002671 continue;
2672 }
2673
2674 /* start card; "initialize" will load runtime ucode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002675 iwl3945_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002676
Tomas Winklere1623442009-01-27 14:27:56 -08002677 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
Zhu Yib481de92007-09-25 17:54:57 -07002678
2679 return 0;
2680 }
2681
2682 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002683 __iwl3945_down(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08002684 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002685
2686 /* tried to restart and config the device for as long as our
2687 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002688 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07002689 return -EIO;
2690}
2691
2692
2693/*****************************************************************************
2694 *
2695 * Workqueue callbacks
2696 *
2697 *****************************************************************************/
2698
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002699static void iwl3945_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002700{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002701 struct iwl_priv *priv =
2702 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002703
2704 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2705 return;
2706
2707 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002708 iwl3945_init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002709 mutex_unlock(&priv->mutex);
2710}
2711
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002712static void iwl3945_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002713{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002714 struct iwl_priv *priv =
2715 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002716
2717 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2718 return;
2719
2720 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002721 iwl3945_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002722 mutex_unlock(&priv->mutex);
2723}
2724
Helmut Schaa26635162009-01-15 09:38:44 +01002725static void iwl3945_rfkill_poll(struct work_struct *data)
2726{
2727 struct iwl_priv *priv =
2728 container_of(data, struct iwl_priv, rfkill_poll.work);
Helmut Schaa26635162009-01-15 09:38:44 +01002729
2730 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
2731 clear_bit(STATUS_RF_KILL_HW, &priv->status);
2732 else
2733 set_bit(STATUS_RF_KILL_HW, &priv->status);
2734
Johannes Berga60e77e2009-06-04 18:26:06 +02002735 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
2736 test_bit(STATUS_RF_KILL_HW, &priv->status));
Helmut Schaa26635162009-01-15 09:38:44 +01002737
2738 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
2739 round_jiffies_relative(2 * HZ));
2740
2741}
2742
Zhu Yib481de92007-09-25 17:54:57 -07002743#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002744static void iwl3945_bg_request_scan(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002745{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002746 struct iwl_priv *priv =
2747 container_of(data, struct iwl_priv, request_scan);
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08002748 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07002749 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002750 .len = sizeof(struct iwl3945_scan_cmd),
Johannes Bergc2acea82009-07-24 11:13:05 -07002751 .flags = CMD_SIZE_HUGE,
Zhu Yib481de92007-09-25 17:54:57 -07002752 };
2753 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002754 struct iwl3945_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07002755 struct ieee80211_conf *conf = NULL;
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002756 u8 n_probes = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01002757 enum ieee80211_band band;
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002758 bool is_active = false;
Zhu Yib481de92007-09-25 17:54:57 -07002759
2760 conf = ieee80211_get_hw_conf(priv->hw);
2761
2762 mutex_lock(&priv->mutex);
2763
Reinette Chatrefbc9f972009-05-15 16:13:46 -07002764 cancel_delayed_work(&priv->scan_check);
2765
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002766 if (!iwl_is_ready(priv)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002767 IWL_WARN(priv, "request scan called when driver not ready.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002768 goto done;
2769 }
2770
Tomas Winklera96a27f2008-10-23 23:48:56 -07002771 /* Make sure the scan wasn't canceled before this queued work
Zhu Yib481de92007-09-25 17:54:57 -07002772 * was given the chance to run... */
2773 if (!test_bit(STATUS_SCANNING, &priv->status))
2774 goto done;
2775
2776 /* This should never be called or scheduled if there is currently
2777 * a scan active in the hardware. */
2778 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002779 IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests "
2780 "Ignoring second request.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002781 rc = -EIO;
2782 goto done;
2783 }
2784
2785 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002786 IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n");
Zhu Yib481de92007-09-25 17:54:57 -07002787 goto done;
2788 }
2789
2790 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002791 IWL_DEBUG_HC(priv,
2792 "Scan request while abort pending. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002793 goto done;
2794 }
2795
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002796 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002797 IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n");
Zhu Yib481de92007-09-25 17:54:57 -07002798 goto done;
2799 }
2800
2801 if (!test_bit(STATUS_READY, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002802 IWL_DEBUG_HC(priv,
2803 "Scan request while uninitialized. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002804 goto done;
2805 }
2806
2807 if (!priv->scan_bands) {
Tomas Winklere1623442009-01-27 14:27:56 -08002808 IWL_DEBUG_HC(priv, "Aborting scan due to no requested bands\n");
Zhu Yib481de92007-09-25 17:54:57 -07002809 goto done;
2810 }
2811
Winkler, Tomas805cee52009-01-19 15:30:28 -08002812 if (!priv->scan) {
2813 priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
Zhu Yib481de92007-09-25 17:54:57 -07002814 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
Winkler, Tomas805cee52009-01-19 15:30:28 -08002815 if (!priv->scan) {
Zhu Yib481de92007-09-25 17:54:57 -07002816 rc = -ENOMEM;
2817 goto done;
2818 }
2819 }
Winkler, Tomas805cee52009-01-19 15:30:28 -08002820 scan = priv->scan;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002821 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07002822
2823 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
2824 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
2825
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002826 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002827 u16 interval = 0;
2828 u32 extra;
2829 u32 suspend_time = 100;
2830 u32 scan_suspend_time = 100;
2831 unsigned long flags;
2832
Tomas Winklere1623442009-01-27 14:27:56 -08002833 IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
Zhu Yib481de92007-09-25 17:54:57 -07002834
2835 spin_lock_irqsave(&priv->lock, flags);
2836 interval = priv->beacon_int;
2837 spin_unlock_irqrestore(&priv->lock, flags);
2838
2839 scan->suspend_time = 0;
Mohamed Abbas15e869d2007-10-25 17:15:46 +08002840 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07002841 if (!interval)
2842 interval = suspend_time;
2843 /*
2844 * suspend time format:
2845 * 0-19: beacon interval in usec (time before exec.)
2846 * 20-23: 0
2847 * 24-31: number of beacons (suspend between channels)
2848 */
2849
2850 extra = (suspend_time / interval) << 24;
2851 scan_suspend_time = 0xFF0FFFFF &
2852 (extra | ((suspend_time % interval) * 1024));
2853
2854 scan->suspend_time = cpu_to_le32(scan_suspend_time);
Tomas Winklere1623442009-01-27 14:27:56 -08002855 IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07002856 scan_suspend_time, interval);
2857 }
2858
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002859 if (priv->scan_request->n_ssids) {
2860 int i, p = 0;
2861 IWL_DEBUG_SCAN(priv, "Kicking off active scan\n");
2862 for (i = 0; i < priv->scan_request->n_ssids; i++) {
2863 /* always does wildcard anyway */
2864 if (!priv->scan_request->ssids[i].ssid_len)
2865 continue;
2866 scan->direct_scan[p].id = WLAN_EID_SSID;
2867 scan->direct_scan[p].len =
2868 priv->scan_request->ssids[i].ssid_len;
2869 memcpy(scan->direct_scan[p].ssid,
2870 priv->scan_request->ssids[i].ssid,
2871 priv->scan_request->ssids[i].ssid_len);
2872 n_probes++;
2873 p++;
2874 }
2875 is_active = true;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08002876 } else
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002877 IWL_DEBUG_SCAN(priv, "Kicking off passive scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002878
2879 /* We don't build a direct scan probe request; the uCode will do
2880 * that based on the direct_mask added to each channel entry */
Zhu Yib481de92007-09-25 17:54:57 -07002881 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08002882 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07002883 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
2884
2885 /* flags + rate selection */
2886
Ron Rindjunsky66b50042008-06-25 16:46:31 +08002887 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07002888 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
2889 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
2890 scan->good_CRC_th = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01002891 band = IEEE80211_BAND_2GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08002892 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07002893 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
Johannes Bergb097ad22009-04-20 14:36:57 -07002894 /*
2895 * If active scaning is requested but a certain channel
2896 * is marked passive, we can do active scanning if we
2897 * detect transmissions.
2898 */
2899 scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH : 0;
Johannes Berg8318d782008-01-24 19:38:38 +01002900 band = IEEE80211_BAND_5GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08002901 } else {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002902 IWL_WARN(priv, "Invalid scan band count\n");
Zhu Yib481de92007-09-25 17:54:57 -07002903 goto done;
2904 }
2905
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08002906 scan->tx_cmd.len = cpu_to_le16(
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002907 iwl_fill_probe_req(priv,
2908 (struct ieee80211_mgmt *)scan->data,
2909 priv->scan_request->ie,
2910 priv->scan_request->ie_len,
2911 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08002912
Zhu Yib481de92007-09-25 17:54:57 -07002913 /* select Rx antennas */
2914 scan->flags |= iwl3945_get_antenna_flags(priv);
2915
Wey-Yi Guy279b05d2009-04-20 14:37:00 -07002916 if (iwl_is_monitor_mode(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002917 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
2918
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08002919 scan->channel_count =
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002920 iwl3945_get_channels_for_scan(priv, band, is_active, n_probes,
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08002921 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
Zhu Yib481de92007-09-25 17:54:57 -07002922
Reinette Chatre14b54332008-11-04 12:21:35 -08002923 if (scan->channel_count == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002924 IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
Reinette Chatre14b54332008-11-04 12:21:35 -08002925 goto done;
2926 }
2927
Zhu Yib481de92007-09-25 17:54:57 -07002928 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002929 scan->channel_count * sizeof(struct iwl3945_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07002930 cmd.data = scan;
2931 scan->len = cpu_to_le16(cmd.len);
2932
2933 set_bit(STATUS_SCAN_HW, &priv->status);
Samuel Ortiz518099a2009-01-19 15:30:27 -08002934 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07002935 if (rc)
2936 goto done;
2937
2938 queue_delayed_work(priv->workqueue, &priv->scan_check,
2939 IWL_SCAN_CHECK_WATCHDOG);
2940
2941 mutex_unlock(&priv->mutex);
2942 return;
2943
2944 done:
Mohamed Abbas2420ebc2008-11-04 12:21:34 -08002945 /* can not perform scan make sure we clear scanning
2946 * bits from status so next scan request can be performed.
2947 * if we dont clear scanning status bit here all next scan
2948 * will fail
2949 */
2950 clear_bit(STATUS_SCAN_HW, &priv->status);
2951 clear_bit(STATUS_SCANNING, &priv->status);
2952
Ian Schram01ebd062007-10-25 17:15:22 +08002953 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07002954 queue_work(priv->workqueue, &priv->scan_completed);
2955 mutex_unlock(&priv->mutex);
2956}
2957
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002958static void iwl3945_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002959{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002960 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07002961
2962 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2963 return;
2964
2965 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002966 __iwl3945_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002967 mutex_unlock(&priv->mutex);
2968}
2969
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002970static void iwl3945_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002971{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002972 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07002973
2974 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2975 return;
2976
Johannes Berg19cc1082009-05-08 13:44:36 -07002977 if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
2978 mutex_lock(&priv->mutex);
2979 priv->vif = NULL;
2980 priv->is_open = 0;
2981 mutex_unlock(&priv->mutex);
2982 iwl3945_down(priv);
2983 ieee80211_restart_hw(priv->hw);
2984 } else {
2985 iwl3945_down(priv);
2986 queue_work(priv->workqueue, &priv->up);
2987 }
Zhu Yib481de92007-09-25 17:54:57 -07002988}
2989
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002990static void iwl3945_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002991{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002992 struct iwl_priv *priv =
2993 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07002994
2995 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2996 return;
2997
2998 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002999 iwl3945_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003000 mutex_unlock(&priv->mutex);
3001}
3002
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003003#define IWL_DELAY_NEXT_SCAN (HZ*2)
3004
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07003005void iwl3945_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003006{
Zhu Yib481de92007-09-25 17:54:57 -07003007 int rc = 0;
3008 struct ieee80211_conf *conf = NULL;
3009
Johannes Berg05c914f2008-09-11 00:01:58 +02003010 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003011 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07003012 return;
3013 }
3014
3015
Tomas Winklere1623442009-01-27 14:27:56 -08003016 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003017 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07003018
3019 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3020 return;
3021
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003022 if (!priv->vif || !priv->is_open)
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003023 return;
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003024
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003025 iwl_scan_cancel_timeout(priv, 200);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003026
Zhu Yib481de92007-09-25 17:54:57 -07003027 conf = ieee80211_get_hw_conf(priv->hw);
3028
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003029 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003030 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003031
Tomas Winkler28afaf92008-12-19 10:37:06 +08003032 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Tomas Winkler2c2f3b32009-06-19 13:52:45 -07003033 iwl_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003034 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07003035 sizeof(priv->rxon_timing), &priv->rxon_timing);
3036 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003037 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003038 "Attempting to continue.\n");
3039
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003040 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003041
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003042 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003043
Tomas Winklere1623442009-01-27 14:27:56 -08003044 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003045 priv->assoc_id, priv->beacon_int);
3046
3047 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003048 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003049 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003050 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003051
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003052 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003053 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003054 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_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_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003057
Johannes Berg05c914f2008-09-11 00:01:58 +02003058 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003059 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003060
3061 }
3062
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003063 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003064
3065 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02003066 case NL80211_IFTYPE_STATION:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003067 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07003068 break;
3069
Johannes Berg05c914f2008-09-11 00:01:58 +02003070 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07003071
Abhijeet Kolekarce546fd2008-11-19 15:32:22 -08003072 priv->assoc_id = 1;
Tomas Winklerc587de02009-06-03 11:44:07 -07003073 iwl_add_station(priv, priv->bssid, 0, CMD_SYNC, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07003074 iwl3945_sync_sta(priv, IWL_STA_ID,
Johannes Berg8318d782008-01-24 19:38:38 +01003075 (priv->band == IEEE80211_BAND_5GHZ) ?
Zhu Yib481de92007-09-25 17:54:57 -07003076 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
3077 CMD_ASYNC);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003078 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
3079 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003080
3081 break;
3082
3083 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08003084 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003085 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003086 break;
3087 }
3088
Abhijeet Kolekar14d2aac2009-02-27 16:21:24 -08003089 iwl_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08003090
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003091 /* we have just associated, don't start scan too early */
3092 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08003093}
3094
Zhu Yib481de92007-09-25 17:54:57 -07003095/*****************************************************************************
3096 *
3097 * mac80211 entry point functions
3098 *
3099 *****************************************************************************/
3100
Zhu Yi5a669262008-01-14 17:46:18 -08003101#define UCODE_READY_TIMEOUT (2 * HZ)
3102
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003103static int iwl3945_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003104{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003105 struct iwl_priv *priv = hw->priv;
Zhu Yi5a669262008-01-14 17:46:18 -08003106 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003107
Tomas Winklere1623442009-01-27 14:27:56 -08003108 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003109
3110 /* we should be verifying the device is ready to be opened */
3111 mutex_lock(&priv->mutex);
3112
Zhu Yi5a669262008-01-14 17:46:18 -08003113 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
3114 * ucode filename and max sizes are card-specific. */
3115
3116 if (!priv->ucode_code.len) {
3117 ret = iwl3945_read_ucode(priv);
3118 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003119 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a669262008-01-14 17:46:18 -08003120 mutex_unlock(&priv->mutex);
3121 goto out_release_irq;
3122 }
3123 }
3124
Zhu Yie655b9f2008-01-24 02:19:38 -08003125 ret = __iwl3945_up(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08003126
Zhu Yib481de92007-09-25 17:54:57 -07003127 mutex_unlock(&priv->mutex);
Zhu Yi5a669262008-01-14 17:46:18 -08003128
Zhu Yie655b9f2008-01-24 02:19:38 -08003129 if (ret)
3130 goto out_release_irq;
3131
Tomas Winklere1623442009-01-27 14:27:56 -08003132 IWL_DEBUG_INFO(priv, "Start UP work.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003133
Zhu Yi5a669262008-01-14 17:46:18 -08003134 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
3135 * mac80211 will not be run successfully. */
3136 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
3137 test_bit(STATUS_READY, &priv->status),
3138 UCODE_READY_TIMEOUT);
3139 if (!ret) {
3140 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003141 IWL_ERR(priv,
3142 "Wait for START_ALIVE timeout after %dms.\n",
3143 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Zhu Yi5a669262008-01-14 17:46:18 -08003144 ret = -ETIMEDOUT;
3145 goto out_release_irq;
3146 }
3147 }
3148
Helmut Schaa26635162009-01-15 09:38:44 +01003149 /* ucode is running and will send rfkill notifications,
3150 * no need to poll the killswitch state anymore */
3151 cancel_delayed_work(&priv->rfkill_poll);
3152
Johannes Berge932a602009-10-02 13:44:03 -07003153 iwl_led_start(priv);
3154
Zhu Yie655b9f2008-01-24 02:19:38 -08003155 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08003156 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003157 return 0;
Zhu Yi5a669262008-01-14 17:46:18 -08003158
3159out_release_irq:
Zhu Yie655b9f2008-01-24 02:19:38 -08003160 priv->is_open = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08003161 IWL_DEBUG_MAC80211(priv, "leave - failed\n");
Zhu Yi5a669262008-01-14 17:46:18 -08003162 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003163}
3164
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003165static void iwl3945_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003166{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003167 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003168
Tomas Winklere1623442009-01-27 14:27:56 -08003169 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003170
Zhu Yie655b9f2008-01-24 02:19:38 -08003171 if (!priv->is_open) {
Tomas Winklere1623442009-01-27 14:27:56 -08003172 IWL_DEBUG_MAC80211(priv, "leave - skip\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003173 return;
3174 }
3175
Zhu Yib481de92007-09-25 17:54:57 -07003176 priv->is_open = 0;
Zhu Yi5a669262008-01-14 17:46:18 -08003177
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003178 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08003179 /* stop mac, cancel any scan request and clear
3180 * RXON_FILTER_ASSOC_MSK BIT
3181 */
Zhu Yi5a669262008-01-14 17:46:18 -08003182 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003183 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003184 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003185 }
3186
Zhu Yi5a669262008-01-14 17:46:18 -08003187 iwl3945_down(priv);
3188
3189 flush_workqueue(priv->workqueue);
Helmut Schaa26635162009-01-15 09:38:44 +01003190
3191 /* start polling the killswitch state again */
3192 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3193 round_jiffies_relative(2 * HZ));
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003194
Tomas Winklere1623442009-01-27 14:27:56 -08003195 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003196}
3197
Johannes Berge039fa42008-05-15 12:55:29 +02003198static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003199{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003200 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003201
Tomas Winklere1623442009-01-27 14:27:56 -08003202 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003203
Tomas Winklere1623442009-01-27 14:27:56 -08003204 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02003205 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07003206
Johannes Berge039fa42008-05-15 12:55:29 +02003207 if (iwl3945_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07003208 dev_kfree_skb_any(skb);
3209
Tomas Winklere1623442009-01-27 14:27:56 -08003210 IWL_DEBUG_MAC80211(priv, "leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08003211 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07003212}
3213
Abhijeet Kolekar60690a62009-04-08 11:26:49 -07003214void iwl3945_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003215{
3216 int rc = 0;
3217
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08003218 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07003219 return;
3220
3221 /* The following should be done only at AP bring up */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003222 if (!(iwl_is_associated(priv))) {
Zhu Yib481de92007-09-25 17:54:57 -07003223
3224 /* RXON - unassoc (to set timing command) */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003225 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003226 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003227
3228 /* RXON Timing */
Tomas Winkler28afaf92008-12-19 10:37:06 +08003229 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Tomas Winkler2c2f3b32009-06-19 13:52:45 -07003230 iwl_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003231 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
3232 sizeof(priv->rxon_timing),
3233 &priv->rxon_timing);
Zhu Yib481de92007-09-25 17:54:57 -07003234 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003235 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003236 "Attempting to continue.\n");
3237
3238 /* FIXME: what should be the assoc_id for AP? */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003239 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003240 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003241 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003242 RXON_FLG_SHORT_PREAMBLE_MSK;
3243 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003244 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003245 ~RXON_FLG_SHORT_PREAMBLE_MSK;
3246
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003247 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003248 if (priv->assoc_capability &
3249 WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003250 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003251 RXON_FLG_SHORT_SLOT_MSK;
3252 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003253 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003254 ~RXON_FLG_SHORT_SLOT_MSK;
3255
Johannes Berg05c914f2008-09-11 00:01:58 +02003256 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
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 }
3260 /* restore RXON assoc */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003261 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003262 iwlcore_commit_rxon(priv);
Tomas Winklerc587de02009-06-03 11:44:07 -07003263 iwl_add_station(priv, iwl_bcast_addr, 0, CMD_SYNC, NULL);
Zhu Yi556f8db2007-09-27 11:27:33 +08003264 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003265 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003266
3267 /* FIXME - we need to add code here to detect a totally new
3268 * configuration, reset the AP, unassoc, rxon timing, assoc,
3269 * clear sta table, add BCAST sta... */
3270}
3271
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003272static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01003273 struct ieee80211_vif *vif,
3274 struct ieee80211_sta *sta,
3275 struct ieee80211_key_conf *key)
Zhu Yib481de92007-09-25 17:54:57 -07003276{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003277 struct iwl_priv *priv = hw->priv;
Johannes Bergdc822b52008-12-29 12:55:09 +01003278 const u8 *addr;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003279 int ret = 0;
3280 u8 sta_id = IWL_INVALID_STATION;
3281 u8 static_key;
Zhu Yib481de92007-09-25 17:54:57 -07003282
Tomas Winklere1623442009-01-27 14:27:56 -08003283 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003284
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08003285 if (iwl3945_mod_params.sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08003286 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07003287 return -EOPNOTSUPP;
3288 }
3289
Winkler, Tomas42986792009-01-19 15:30:22 -08003290 addr = sta ? sta->addr : iwl_bcast_addr;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003291 static_key = !iwl_is_associated(priv);
3292
3293 if (!static_key) {
Tomas Winklerc587de02009-06-03 11:44:07 -07003294 sta_id = iwl_find_station(priv, addr);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003295 if (sta_id == IWL_INVALID_STATION) {
Joe Perches12514392009-04-16 16:23:26 -07003296 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003297 addr);
3298 return -EINVAL;
3299 }
Zhu Yib481de92007-09-25 17:54:57 -07003300 }
3301
3302 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003303 iwl_scan_cancel_timeout(priv, 100);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003304 mutex_unlock(&priv->mutex);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003305
Zhu Yib481de92007-09-25 17:54:57 -07003306 switch (cmd) {
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003307 case SET_KEY:
3308 if (static_key)
3309 ret = iwl3945_set_static_key(priv, key);
3310 else
3311 ret = iwl3945_set_dynamic_key(priv, key, sta_id);
3312 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003313 break;
3314 case DISABLE_KEY:
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003315 if (static_key)
3316 ret = iwl3945_remove_static_key(priv);
3317 else
3318 ret = iwl3945_clear_sta_key_info(priv, sta_id);
3319 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003320 break;
3321 default:
Winkler, Tomas42986792009-01-19 15:30:22 -08003322 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003323 }
3324
Tomas Winklere1623442009-01-27 14:27:56 -08003325 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003326
Winkler, Tomas42986792009-01-19 15:30:22 -08003327 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003328}
3329
Zhu Yib481de92007-09-25 17:54:57 -07003330/*****************************************************************************
3331 *
3332 * sysfs attributes
3333 *
3334 *****************************************************************************/
3335
Samuel Ortizd08853a2009-01-23 13:45:17 -08003336#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07003337
3338/*
3339 * The following adds a new attribute to the sysfs representation
3340 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
3341 * used for controlling the debug level.
3342 *
3343 * See the level definitions in iwl for details.
Reinette Chatrea562a9d2009-07-17 09:30:24 -07003344 *
Reinette Chatre3d816c72009-08-07 15:41:37 -07003345 * The debug_level being managed using sysfs below is a per device debug
3346 * level that is used instead of the global debug level if it (the per
3347 * device debug level) is set.
Zhu Yib481de92007-09-25 17:54:57 -07003348 */
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003349static ssize_t show_debug_level(struct device *d,
3350 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07003351{
Reinette Chatre3d816c72009-08-07 15:41:37 -07003352 struct iwl_priv *priv = dev_get_drvdata(d);
3353 return sprintf(buf, "0x%08X\n", iwl_get_debug_level(priv));
Zhu Yib481de92007-09-25 17:54:57 -07003354}
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003355static ssize_t store_debug_level(struct device *d,
3356 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07003357 const char *buf, size_t count)
3358{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003359 struct iwl_priv *priv = dev_get_drvdata(d);
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003360 unsigned long val;
3361 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003362
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003363 ret = strict_strtoul(buf, 0, &val);
3364 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08003365 IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003366 else {
Reinette Chatre3d816c72009-08-07 15:41:37 -07003367 priv->debug_level = val;
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003368 if (iwl_alloc_traffic_mem(priv))
3369 IWL_ERR(priv,
3370 "Not enough memory to generate traffic log\n");
3371 }
Zhu Yib481de92007-09-25 17:54:57 -07003372 return strnlen(buf, count);
3373}
3374
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003375static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
3376 show_debug_level, store_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07003377
Samuel Ortizd08853a2009-01-23 13:45:17 -08003378#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07003379
Zhu Yib481de92007-09-25 17:54:57 -07003380static ssize_t show_temperature(struct device *d,
3381 struct device_attribute *attr, char *buf)
3382{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003383 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003384
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003385 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003386 return -EAGAIN;
3387
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003388 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07003389}
3390
3391static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
3392
Zhu Yib481de92007-09-25 17:54:57 -07003393static ssize_t show_tx_power(struct device *d,
3394 struct device_attribute *attr, char *buf)
3395{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003396 struct iwl_priv *priv = dev_get_drvdata(d);
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08003397 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07003398}
3399
3400static ssize_t store_tx_power(struct device *d,
3401 struct device_attribute *attr,
3402 const char *buf, size_t count)
3403{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003404 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003405 char *p = (char *)buf;
3406 u32 val;
3407
3408 val = simple_strtoul(p, &p, 10);
3409 if (p == buf)
Tomas Winkler978785a2008-12-19 10:37:31 +08003410 IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07003411 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003412 iwl3945_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07003413
3414 return count;
3415}
3416
3417static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
3418
3419static ssize_t show_flags(struct device *d,
3420 struct device_attribute *attr, char *buf)
3421{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003422 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003423
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003424 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
Zhu Yib481de92007-09-25 17:54:57 -07003425}
3426
3427static ssize_t store_flags(struct device *d,
3428 struct device_attribute *attr,
3429 const char *buf, size_t count)
3430{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003431 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003432 u32 flags = simple_strtoul(buf, NULL, 0);
3433
3434 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003435 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
Zhu Yib481de92007-09-25 17:54:57 -07003436 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003437 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003438 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003439 else {
Tomas Winklere1623442009-01-27 14:27:56 -08003440 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
Zhu Yib481de92007-09-25 17:54:57 -07003441 flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003442 priv->staging_rxon.flags = cpu_to_le32(flags);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003443 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003444 }
3445 }
3446 mutex_unlock(&priv->mutex);
3447
3448 return count;
3449}
3450
3451static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
3452
3453static ssize_t show_filter_flags(struct device *d,
3454 struct device_attribute *attr, char *buf)
3455{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003456 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003457
3458 return sprintf(buf, "0x%04X\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003459 le32_to_cpu(priv->active_rxon.filter_flags));
Zhu Yib481de92007-09-25 17:54:57 -07003460}
3461
3462static ssize_t store_filter_flags(struct device *d,
3463 struct device_attribute *attr,
3464 const char *buf, size_t count)
3465{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003466 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003467 u32 filter_flags = simple_strtoul(buf, NULL, 0);
3468
3469 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003470 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
Zhu Yib481de92007-09-25 17:54:57 -07003471 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003472 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003473 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003474 else {
Tomas Winklere1623442009-01-27 14:27:56 -08003475 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
Zhu Yib481de92007-09-25 17:54:57 -07003476 "0x%04X\n", filter_flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003477 priv->staging_rxon.filter_flags =
Zhu Yib481de92007-09-25 17:54:57 -07003478 cpu_to_le32(filter_flags);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003479 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003480 }
3481 }
3482 mutex_unlock(&priv->mutex);
3483
3484 return count;
3485}
3486
3487static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
3488 store_filter_flags);
3489
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003490#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07003491
3492static ssize_t show_measurement(struct device *d,
3493 struct device_attribute *attr, char *buf)
3494{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003495 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler600c0e12008-12-19 10:37:04 +08003496 struct iwl_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07003497 u32 size = sizeof(measure_report), len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003498 u8 *data = (u8 *)&measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07003499 unsigned long flags;
3500
3501 spin_lock_irqsave(&priv->lock, flags);
3502 if (!(priv->measurement_status & MEASUREMENT_READY)) {
3503 spin_unlock_irqrestore(&priv->lock, flags);
3504 return 0;
3505 }
3506 memcpy(&measure_report, &priv->measure_report, size);
3507 priv->measurement_status = 0;
3508 spin_unlock_irqrestore(&priv->lock, flags);
3509
3510 while (size && (PAGE_SIZE - len)) {
3511 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
3512 PAGE_SIZE - len, 1);
3513 len = strlen(buf);
3514 if (PAGE_SIZE - len)
3515 buf[len++] = '\n';
3516
3517 ofs += 16;
3518 size -= min(size, 16U);
3519 }
3520
3521 return len;
3522}
3523
3524static ssize_t store_measurement(struct device *d,
3525 struct device_attribute *attr,
3526 const char *buf, size_t count)
3527{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003528 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003529 struct ieee80211_measurement_params params = {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003530 .channel = le16_to_cpu(priv->active_rxon.channel),
Zhu Yib481de92007-09-25 17:54:57 -07003531 .start_time = cpu_to_le64(priv->last_tsf),
3532 .duration = cpu_to_le16(1),
3533 };
3534 u8 type = IWL_MEASURE_BASIC;
3535 u8 buffer[32];
3536 u8 channel;
3537
3538 if (count) {
3539 char *p = buffer;
3540 strncpy(buffer, buf, min(sizeof(buffer), count));
3541 channel = simple_strtoul(p, NULL, 0);
3542 if (channel)
3543 params.channel = channel;
3544
3545 p = buffer;
3546 while (*p && *p != ' ')
3547 p++;
3548 if (*p)
3549 type = simple_strtoul(p + 1, NULL, 0);
3550 }
3551
Tomas Winklere1623442009-01-27 14:27:56 -08003552 IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on "
Zhu Yib481de92007-09-25 17:54:57 -07003553 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003554 iwl3945_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07003555
3556 return count;
3557}
3558
3559static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
3560 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003561#endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07003562
Zhu Yib481de92007-09-25 17:54:57 -07003563static ssize_t store_retry_rate(struct device *d,
3564 struct device_attribute *attr,
3565 const char *buf, size_t count)
3566{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003567 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003568
3569 priv->retry_rate = simple_strtoul(buf, NULL, 0);
3570 if (priv->retry_rate <= 0)
3571 priv->retry_rate = 1;
3572
3573 return count;
3574}
3575
3576static ssize_t show_retry_rate(struct device *d,
3577 struct device_attribute *attr, char *buf)
3578{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003579 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003580 return sprintf(buf, "%d", priv->retry_rate);
3581}
3582
3583static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
3584 store_retry_rate);
3585
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08003586
Zhu Yib481de92007-09-25 17:54:57 -07003587static ssize_t show_channels(struct device *d,
3588 struct device_attribute *attr, char *buf)
3589{
Johannes Berg8318d782008-01-24 19:38:38 +01003590 /* all this shit doesn't belong into sysfs anyway */
3591 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07003592}
3593
3594static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
3595
3596static ssize_t show_statistics(struct device *d,
3597 struct device_attribute *attr, char *buf)
3598{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003599 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003600 u32 size = sizeof(struct iwl3945_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07003601 u32 len = 0, ofs = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003602 u8 *data = (u8 *)&priv->statistics_39;
Zhu Yib481de92007-09-25 17:54:57 -07003603 int rc = 0;
3604
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003605 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003606 return -EAGAIN;
3607
3608 mutex_lock(&priv->mutex);
Samuel Ortiz17f841c2009-01-23 13:45:20 -08003609 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003610 mutex_unlock(&priv->mutex);
3611
3612 if (rc) {
3613 len = sprintf(buf,
3614 "Error sending statistics request: 0x%08X\n", rc);
3615 return len;
3616 }
3617
3618 while (size && (PAGE_SIZE - len)) {
3619 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
3620 PAGE_SIZE - len, 1);
3621 len = strlen(buf);
3622 if (PAGE_SIZE - len)
3623 buf[len++] = '\n';
3624
3625 ofs += 16;
3626 size -= min(size, 16U);
3627 }
3628
3629 return len;
3630}
3631
3632static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
3633
3634static ssize_t show_antenna(struct device *d,
3635 struct device_attribute *attr, char *buf)
3636{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003637 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003638
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003639 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003640 return -EAGAIN;
3641
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08003642 return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
Zhu Yib481de92007-09-25 17:54:57 -07003643}
3644
3645static ssize_t store_antenna(struct device *d,
3646 struct device_attribute *attr,
3647 const char *buf, size_t count)
3648{
Winkler, Tomas7530f852009-01-27 14:27:53 -08003649 struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003650 int ant;
Zhu Yib481de92007-09-25 17:54:57 -07003651
3652 if (count == 0)
3653 return 0;
3654
3655 if (sscanf(buf, "%1i", &ant) != 1) {
Tomas Winklere1623442009-01-27 14:27:56 -08003656 IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003657 return count;
3658 }
3659
3660 if ((ant >= 0) && (ant <= 2)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003661 IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant);
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08003662 iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
Zhu Yib481de92007-09-25 17:54:57 -07003663 } else
Tomas Winklere1623442009-01-27 14:27:56 -08003664 IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant);
Zhu Yib481de92007-09-25 17:54:57 -07003665
3666
3667 return count;
3668}
3669
3670static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
3671
3672static ssize_t show_status(struct device *d,
3673 struct device_attribute *attr, char *buf)
3674{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003675 struct iwl_priv *priv = dev_get_drvdata(d);
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003676 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003677 return -EAGAIN;
3678 return sprintf(buf, "0x%08x\n", (int)priv->status);
3679}
3680
3681static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
3682
3683static ssize_t dump_error_log(struct device *d,
3684 struct device_attribute *attr,
3685 const char *buf, size_t count)
3686{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003687 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003688 char *p = (char *)buf;
3689
3690 if (p[0] == '1')
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003691 iwl3945_dump_nic_error_log(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003692
3693 return strnlen(buf, count);
3694}
3695
3696static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
3697
Zhu Yib481de92007-09-25 17:54:57 -07003698/*****************************************************************************
3699 *
Tomas Winklera96a27f2008-10-23 23:48:56 -07003700 * driver setup and tear down
Zhu Yib481de92007-09-25 17:54:57 -07003701 *
3702 *****************************************************************************/
3703
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003704static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003705{
Reinette Chatred21050c2009-02-13 11:51:18 -08003706 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07003707
3708 init_waitqueue_head(&priv->wait_command_queue);
3709
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003710 INIT_WORK(&priv->up, iwl3945_bg_up);
3711 INIT_WORK(&priv->restart, iwl3945_bg_restart);
3712 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003713 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003714 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
3715 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
Helmut Schaa26635162009-01-15 09:38:44 +01003716 INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08003717 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
3718 INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
3719 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
3720 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
Zhu Yib481de92007-09-25 17:54:57 -07003721
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003722 iwl3945_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003723
3724 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003725 iwl3945_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07003726}
3727
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003728static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003729{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003730 iwl3945_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003731
Joonwoo Parke47eb6a2007-11-29 10:42:49 +09003732 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07003733 cancel_delayed_work(&priv->scan_check);
3734 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07003735 cancel_work_sync(&priv->beacon_update);
3736}
3737
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003738static struct attribute *iwl3945_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07003739 &dev_attr_antenna.attr,
3740 &dev_attr_channels.attr,
3741 &dev_attr_dump_errors.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003742 &dev_attr_flags.attr,
3743 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003744#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07003745 &dev_attr_measurement.attr,
3746#endif
Zhu Yib481de92007-09-25 17:54:57 -07003747 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003748 &dev_attr_statistics.attr,
3749 &dev_attr_status.attr,
3750 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003751 &dev_attr_tx_power.attr,
Samuel Ortizd08853a2009-01-23 13:45:17 -08003752#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003753 &dev_attr_debug_level.attr,
3754#endif
Zhu Yib481de92007-09-25 17:54:57 -07003755 NULL
3756};
3757
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003758static struct attribute_group iwl3945_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07003759 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003760 .attrs = iwl3945_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07003761};
3762
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003763static struct ieee80211_ops iwl3945_hw_ops = {
3764 .tx = iwl3945_mac_tx,
3765 .start = iwl3945_mac_start,
3766 .stop = iwl3945_mac_stop,
Abhijeet Kolekarcbb6ab92009-04-08 11:26:46 -07003767 .add_interface = iwl_mac_add_interface,
Abhijeet Kolekard8052312009-04-08 11:26:47 -07003768 .remove_interface = iwl_mac_remove_interface,
Abhijeet Kolekar48083682009-04-08 11:26:48 -07003769 .config = iwl_mac_config,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003770 .configure_filter = iwl_configure_filter,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003771 .set_key = iwl3945_mac_set_key,
Abhijeet Kolekaraa89f312009-04-08 11:26:51 -07003772 .get_tx_stats = iwl_mac_get_tx_stats,
Abhijeet Kolekar488829f2009-03-26 10:14:10 -07003773 .conf_tx = iwl_mac_conf_tx,
Abhijeet Kolekarbd564262009-04-08 11:26:52 -07003774 .reset_tsf = iwl_mac_reset_tsf,
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07003775 .bss_info_changed = iwl_bss_info_changed,
Abhijeet Kolekare9dde6f62009-02-18 15:54:27 -08003776 .hw_scan = iwl_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07003777};
3778
Winkler, Tomase52119c2008-12-22 11:31:19 +08003779static int iwl3945_init_drv(struct iwl_priv *priv)
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003780{
3781 int ret;
Samuel Ortize6148912009-01-23 13:45:15 -08003782 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003783
3784 priv->retry_rate = 1;
3785 priv->ibss_beacon = NULL;
3786
3787 spin_lock_init(&priv->lock);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003788 spin_lock_init(&priv->sta_lock);
3789 spin_lock_init(&priv->hcmd_lock);
3790
3791 INIT_LIST_HEAD(&priv->free_frames);
3792
3793 mutex_init(&priv->mutex);
3794
3795 /* Clear the driver's (not device's) station table */
Tomas Winklerc587de02009-06-03 11:44:07 -07003796 iwl_clear_stations_table(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003797
3798 priv->data_retry_limit = -1;
3799 priv->ieee_channels = NULL;
3800 priv->ieee_rates = NULL;
3801 priv->band = IEEE80211_BAND_2GHZ;
3802
3803 priv->iw_mode = NL80211_IFTYPE_STATION;
3804
3805 iwl_reset_qos(priv);
3806
3807 priv->qos_data.qos_active = 0;
3808 priv->qos_data.qos_cap.val = 0;
3809
3810 priv->rates_mask = IWL_RATES_MASK;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08003811 priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003812
Samuel Ortize6148912009-01-23 13:45:15 -08003813 if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
3814 IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
3815 eeprom->version);
3816 ret = -EINVAL;
3817 goto err;
3818 }
3819 ret = iwl_init_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003820 if (ret) {
3821 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
3822 goto err;
3823 }
3824
Samuel Ortize6148912009-01-23 13:45:15 -08003825 /* Set up txpower settings in driver for all channels */
3826 if (iwl3945_txpower_set_from_eeprom(priv)) {
3827 ret = -EIO;
3828 goto err_free_channel_map;
3829 }
3830
Samuel Ortiz534166d2009-01-23 13:45:16 -08003831 ret = iwlcore_init_geos(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003832 if (ret) {
3833 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
3834 goto err_free_channel_map;
3835 }
Samuel Ortiz534166d2009-01-23 13:45:16 -08003836 iwl3945_init_hw_rates(priv, priv->ieee_rates);
3837
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003838 return 0;
3839
3840err_free_channel_map:
Samuel Ortize6148912009-01-23 13:45:15 -08003841 iwl_free_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003842err:
3843 return ret;
3844}
3845
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08003846static int iwl3945_setup_mac(struct iwl_priv *priv)
3847{
3848 int ret;
3849 struct ieee80211_hw *hw = priv->hw;
3850
3851 hw->rate_control_algorithm = "iwl-3945-rs";
3852 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
3853
3854 /* Tell mac80211 our characteristics */
3855 hw->flags = IEEE80211_HW_SIGNAL_DBM |
Mohamed Abbasb1c60192009-03-17 21:51:47 -07003856 IEEE80211_HW_NOISE_DBM |
Johannes Berge312c242009-08-07 15:41:51 -07003857 IEEE80211_HW_SPECTRUM_MGMT |
3858 IEEE80211_HW_SUPPORTS_PS |
3859 IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08003860
3861 hw->wiphy->interface_modes =
3862 BIT(NL80211_IFTYPE_STATION) |
3863 BIT(NL80211_IFTYPE_ADHOC);
3864
3865 hw->wiphy->custom_regulatory = true;
3866
Luis R. Rodriguez37184242009-07-30 17:43:48 -07003867 /* Firmware does not support this */
3868 hw->wiphy->disable_beacon_hints = true;
3869
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07003870 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX_3945;
3871 /* we create the 802.11 header and a zero-length SSID element */
3872 hw->wiphy->max_scan_ie_len = IWL_MAX_PROBE_REQUEST - 24 - 2;
Johannes Bergd60cc912009-04-09 09:56:02 +02003873
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08003874 /* Default value; 4 EDCA QOS priorities */
3875 hw->queues = 4;
3876
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08003877 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
3878 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
3879 &priv->bands[IEEE80211_BAND_2GHZ];
3880
3881 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
3882 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
3883 &priv->bands[IEEE80211_BAND_5GHZ];
3884
3885 ret = ieee80211_register_hw(priv->hw);
3886 if (ret) {
3887 IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
3888 return ret;
3889 }
3890 priv->mac80211_registered = 1;
3891
3892 return 0;
3893}
3894
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003895static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07003896{
3897 int err = 0;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003898 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07003899 struct ieee80211_hw *hw;
Kolekar, Abhijeetc0f20d92008-12-19 10:37:19 +08003900 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Samuel Ortize6148912009-01-23 13:45:15 -08003901 struct iwl3945_eeprom *eeprom;
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003902 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07003903
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08003904 /***********************
3905 * 1. Allocating HW data
3906 * ********************/
3907
Zhu Yib481de92007-09-25 17:54:57 -07003908 /* mac80211 allocates memory for this device instance, including
3909 * space for this driver's private structure */
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003910 hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
Zhu Yib481de92007-09-25 17:54:57 -07003911 if (hw == NULL) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08003912 printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
Zhu Yib481de92007-09-25 17:54:57 -07003913 err = -ENOMEM;
3914 goto out;
3915 }
Zhu Yib481de92007-09-25 17:54:57 -07003916 priv = hw->priv;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003917 SET_IEEE80211_DEV(hw, &pdev->dev);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003918
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003919 /*
3920 * Disabling hardware scan means that mac80211 will perform scans
3921 * "the hard way", rather than using device's scan.
3922 */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08003923 if (iwl3945_mod_params.disable_hw_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08003924 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003925 iwl3945_hw_ops.hw_scan = NULL;
3926 }
3927
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003928
Tomas Winklere1623442009-01-27 14:27:56 -08003929 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003930 priv->cfg = cfg;
3931 priv->pci_dev = pdev;
Mohamed Abbas40cefda2009-05-22 11:01:52 -07003932 priv->inta_mask = CSR_INI_SET_MASK;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003933
Samuel Ortizd08853a2009-01-23 13:45:17 -08003934#ifdef CONFIG_IWLWIFI_DEBUG
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003935 atomic_set(&priv->restrict_refcnt, 0);
3936#endif
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003937 if (iwl_alloc_traffic_mem(priv))
3938 IWL_ERR(priv, "Not enough memory to generate traffic log\n");
Zhu Yib481de92007-09-25 17:54:57 -07003939
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08003940 /***************************
3941 * 2. Initializing PCI bus
3942 * *************************/
Zhu Yib481de92007-09-25 17:54:57 -07003943 if (pci_enable_device(pdev)) {
3944 err = -ENODEV;
3945 goto out_ieee80211_free_hw;
3946 }
3947
3948 pci_set_master(pdev);
3949
Yang Hongyang284901a2009-04-06 19:01:15 -07003950 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Zhu Yib481de92007-09-25 17:54:57 -07003951 if (!err)
Yang Hongyang284901a2009-04-06 19:01:15 -07003952 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Zhu Yib481de92007-09-25 17:54:57 -07003953 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08003954 IWL_WARN(priv, "No suitable DMA available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003955 goto out_pci_disable_device;
3956 }
3957
3958 pci_set_drvdata(pdev, priv);
3959 err = pci_request_regions(pdev, DRV_NAME);
3960 if (err)
3961 goto out_pci_disable_device;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003962
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08003963 /***********************
3964 * 3. Read REV Register
3965 * ********************/
Zhu Yib481de92007-09-25 17:54:57 -07003966 priv->hw_base = pci_iomap(pdev, 0, 0);
3967 if (!priv->hw_base) {
3968 err = -ENODEV;
3969 goto out_pci_release_regions;
3970 }
3971
Tomas Winklere1623442009-01-27 14:27:56 -08003972 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Zhu Yib481de92007-09-25 17:54:57 -07003973 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08003974 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Zhu Yib481de92007-09-25 17:54:57 -07003975
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08003976 /* We disable the RETRY_TIMEOUT register (0x41) to keep
3977 * PCI Tx retries from interfering with C3 CPU state */
3978 pci_write_config_byte(pdev, 0x41, 0x00);
Zhu Yib481de92007-09-25 17:54:57 -07003979
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07003980 /* this spin lock will be used in apm_ops.init and EEPROM access
3981 * we should init now
3982 */
3983 spin_lock_init(&priv->reg_lock);
3984
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003985 /* amp init */
3986 err = priv->cfg->ops->lib->apm_ops.init(priv);
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003987 if (err < 0) {
David S. Millerd5df2a12009-03-10 05:04:16 -07003988 IWL_DEBUG_INFO(priv, "Failed to init the card\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003989 goto out_iounmap;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003990 }
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08003991
3992 /***********************
3993 * 4. Read EEPROM
3994 * ********************/
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003995
Zhu Yi5a669262008-01-14 17:46:18 -08003996 /* Read the EEPROM */
Samuel Ortize6148912009-01-23 13:45:15 -08003997 err = iwl_eeprom_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003998 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003999 IWL_ERR(priv, "Unable to init EEPROM\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08004000 goto out_iounmap;
Zhu Yi5a669262008-01-14 17:46:18 -08004001 }
4002 /* MAC Address location in EEPROM same for 3945/4965 */
Samuel Ortize6148912009-01-23 13:45:15 -08004003 eeprom = (struct iwl3945_eeprom *)priv->eeprom;
4004 memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08004005 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
Zhu Yi5a669262008-01-14 17:46:18 -08004006 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
4007
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004008 /***********************
4009 * 5. Setup HW Constants
4010 * ********************/
4011 /* Device-specific setup */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08004012 if (iwl3945_hw_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004013 IWL_ERR(priv, "failed to set hw settings\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08004014 goto out_eeprom_free;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004015 }
4016
4017 /***********************
4018 * 6. Setup priv
4019 * ********************/
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004020
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004021 err = iwl3945_init_drv(priv);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08004022 if (err) {
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004023 IWL_ERR(priv, "initializing driver failed\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08004024 goto out_unset_hw_params;
Reinette Chatre849e0dc2008-01-23 10:15:18 -08004025 }
Reinette Chatre849e0dc2008-01-23 10:15:18 -08004026
Tomas Winkler978785a2008-12-19 10:37:31 +08004027 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
4028 priv->cfg->name);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004029
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004030 /***********************
Abhijeet Kolekar09f9bf72009-04-20 14:37:03 -07004031 * 7. Setup Services
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004032 * ********************/
4033
4034 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08004035 iwl_disable_interrupts(priv);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004036 spin_unlock_irqrestore(&priv->lock, flags);
4037
Helmut Schaa26635162009-01-15 09:38:44 +01004038 pci_enable_msi(priv->pci_dev);
4039
Mohamed Abbasef850d72009-05-22 11:01:50 -07004040 err = request_irq(priv->pci_dev->irq, priv->cfg->ops->lib->isr,
4041 IRQF_SHARED, DRV_NAME, priv);
Helmut Schaa26635162009-01-15 09:38:44 +01004042 if (err) {
4043 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
4044 goto out_disable_msi;
4045 }
4046
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004047 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
4048 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004049 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004050 goto out_release_irq;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004051 }
4052
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004053 iwl_set_rxon_channel(priv,
4054 &priv->bands[IEEE80211_BAND_2GHZ].channels[5]);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004055 iwl3945_setup_deferred_work(priv);
4056 iwl3945_setup_rx_handlers(priv);
4057
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004058 /*********************************
Abhijeet Kolekar09f9bf72009-04-20 14:37:03 -07004059 * 8. Setup and Register mac80211
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004060 * *******************************/
4061
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004062 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004063
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004064 err = iwl3945_setup_mac(priv);
4065 if (err)
4066 goto out_remove_sysfs;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004067
Abhijeet Kolekara75fbe82009-04-20 14:36:58 -07004068 err = iwl_dbgfs_register(priv, DRV_NAME);
4069 if (err)
4070 IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
4071
Helmut Schaa26635162009-01-15 09:38:44 +01004072 /* Start monitoring the killswitch */
4073 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
4074 2 * HZ);
4075
Zhu Yib481de92007-09-25 17:54:57 -07004076 return 0;
4077
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004078 out_remove_sysfs:
Zhu Yib481de92007-09-25 17:54:57 -07004079 destroy_workqueue(priv->workqueue);
4080 priv->workqueue = NULL;
Reinette Chatrec8f16132009-02-27 16:21:22 -08004081 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
4082 out_release_irq:
4083 free_irq(priv->pci_dev->irq, priv);
Helmut Schaa26635162009-01-15 09:38:44 +01004084 out_disable_msi:
4085 pci_disable_msi(priv->pci_dev);
Reinette Chatrec8f16132009-02-27 16:21:22 -08004086 iwlcore_free_geos(priv);
4087 iwl_free_channel_map(priv);
4088 out_unset_hw_params:
4089 iwl3945_unset_hw_params(priv);
4090 out_eeprom_free:
4091 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004092 out_iounmap:
4093 pci_iounmap(pdev, priv->hw_base);
4094 out_pci_release_regions:
4095 pci_release_regions(pdev);
4096 out_pci_disable_device:
Zhu Yib481de92007-09-25 17:54:57 -07004097 pci_set_drvdata(pdev, NULL);
Reinette Chatre623d5632009-03-03 11:37:04 -08004098 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004099 out_ieee80211_free_hw:
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07004100 iwl_free_traffic_mem(priv);
Wey-Yi Guyd7c76f42009-10-09 13:20:17 -07004101 ieee80211_free_hw(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07004102 out:
4103 return err;
4104}
4105
Reinette Chatrec83dbf62008-03-21 13:53:41 -07004106static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004107{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004108 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004109 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07004110
4111 if (!priv)
4112 return;
4113
Tomas Winklere1623442009-01-27 14:27:56 -08004114 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07004115
Abhijeet Kolekara75fbe82009-04-20 14:36:58 -07004116 iwl_dbgfs_unregister(priv);
4117
Zhu Yib481de92007-09-25 17:54:57 -07004118 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08004119
Kolekar, Abhijeetd552bfb2008-12-19 10:37:41 +08004120 if (priv->mac80211_registered) {
4121 ieee80211_unregister_hw(priv->hw);
4122 priv->mac80211_registered = 0;
4123 } else {
4124 iwl3945_down(priv);
4125 }
Zhu Yib481de92007-09-25 17:54:57 -07004126
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004127 /* make sure we flush any pending irq or
4128 * tasklet for the driver
4129 */
4130 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08004131 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004132 spin_unlock_irqrestore(&priv->lock, flags);
4133
4134 iwl_synchronize_irq(priv);
4135
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004136 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07004137
Reinette Chatre71d449b2009-04-20 14:37:01 -07004138 cancel_delayed_work_sync(&priv->rfkill_poll);
Helmut Schaa26635162009-01-15 09:38:44 +01004139
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004140 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004141
4142 if (priv->rxq.bd)
Reinette Chatredf833b12009-04-21 10:55:48 -07004143 iwl3945_rx_queue_free(priv, &priv->rxq);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004144 iwl3945_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004145
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08004146 iwl3945_unset_hw_params(priv);
Tomas Winklerc587de02009-06-03 11:44:07 -07004147 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004148
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004149 /*netif_stop_queue(dev); */
4150 flush_workqueue(priv->workqueue);
4151
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004152 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07004153 * priv->workqueue... so we can't take down the workqueue
4154 * until now... */
4155 destroy_workqueue(priv->workqueue);
4156 priv->workqueue = NULL;
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07004157 iwl_free_traffic_mem(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004158
Helmut Schaa26635162009-01-15 09:38:44 +01004159 free_irq(pdev->irq, priv);
4160 pci_disable_msi(pdev);
4161
Zhu Yib481de92007-09-25 17:54:57 -07004162 pci_iounmap(pdev, priv->hw_base);
4163 pci_release_regions(pdev);
4164 pci_disable_device(pdev);
4165 pci_set_drvdata(pdev, NULL);
4166
Samuel Ortize6148912009-01-23 13:45:15 -08004167 iwl_free_channel_map(priv);
Samuel Ortiz534166d2009-01-23 13:45:16 -08004168 iwlcore_free_geos(priv);
Winkler, Tomas805cee52009-01-19 15:30:28 -08004169 kfree(priv->scan);
Zhu Yib481de92007-09-25 17:54:57 -07004170 if (priv->ibss_beacon)
4171 dev_kfree_skb(priv->ibss_beacon);
4172
4173 ieee80211_free_hw(priv->hw);
4174}
4175
Zhu Yib481de92007-09-25 17:54:57 -07004176
4177/*****************************************************************************
4178 *
4179 * driver and module entry point
4180 *
4181 *****************************************************************************/
4182
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004183static struct pci_driver iwl3945_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07004184 .name = DRV_NAME,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004185 .id_table = iwl3945_hw_card_ids,
4186 .probe = iwl3945_pci_probe,
4187 .remove = __devexit_p(iwl3945_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07004188#ifdef CONFIG_PM
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07004189 .suspend = iwl_pci_suspend,
4190 .resume = iwl_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07004191#endif
4192};
4193
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004194static int __init iwl3945_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07004195{
4196
4197 int ret;
4198 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
4199 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004200
4201 ret = iwl3945_rate_control_register();
4202 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08004203 printk(KERN_ERR DRV_NAME
4204 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004205 return ret;
4206 }
4207
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004208 ret = pci_register_driver(&iwl3945_driver);
Zhu Yib481de92007-09-25 17:54:57 -07004209 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08004210 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004211 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07004212 }
Zhu Yib481de92007-09-25 17:54:57 -07004213
4214 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004215
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004216error_register:
4217 iwl3945_rate_control_unregister();
4218 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004219}
4220
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004221static void __exit iwl3945_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07004222{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004223 pci_unregister_driver(&iwl3945_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004224 iwl3945_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07004225}
4226
Reinette Chatrea0987a82008-12-02 12:14:06 -08004227MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
Zhu Yi25cb6ca2008-09-11 11:45:22 +08004228
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07004229module_param_named(antenna, iwl3945_mod_params.antenna, int, S_IRUGO);
Zhu Yib481de92007-09-25 17:54:57 -07004230MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07004231module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, S_IRUGO);
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -08004232MODULE_PARM_DESC(swcrypto,
4233 "using software crypto (default 1 [software])\n");
Reinette Chatrea562a9d2009-07-17 09:30:24 -07004234#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07004235module_param_named(debug, iwl_debug_level, uint, S_IRUGO | S_IWUSR);
Zhu Yib481de92007-09-25 17:54:57 -07004236MODULE_PARM_DESC(debug, "debug output mask");
Reinette Chatrea562a9d2009-07-17 09:30:24 -07004237#endif
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07004238module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan,
4239 int, S_IRUGO);
Zhu Yib481de92007-09-25 17:54:57 -07004240MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07004241module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, S_IRUGO);
Samuel Ortizaf48d042009-01-23 13:45:19 -08004242MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
4243
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004244module_exit(iwl3945_exit);
4245module_init(iwl3945_init);