blob: 956798f2c80c1eedb6f18c3681c036ddffd7b6d7 [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Reinette Chatre01f81622009-01-08 10:20:02 -08003 * Copyright(c) 2003 - 2009 Intel Corporation. All rights reserved.
Zhu Yib481de92007-09-25 17:54:57 -07004 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
Winkler, Tomas759ef892008-12-09 11:28:58 -080025 * Intel Linux Wireless <ilw@linux.intel.com>
Zhu Yib481de92007-09-25 17:54:57 -070026 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
Zhu Yib481de92007-09-25 17:54:57 -070030#include <linux/kernel.h>
31#include <linux/module.h>
Zhu Yib481de92007-09-25 17:54:57 -070032#include <linux/init.h>
33#include <linux/pci.h>
34#include <linux/dma-mapping.h>
35#include <linux/delay.h>
36#include <linux/skbuff.h>
37#include <linux/netdevice.h>
38#include <linux/wireless.h>
39#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070040#include <linux/etherdevice.h>
41#include <linux/if_arp.h>
42
43#include <net/ieee80211_radiotap.h>
John W. Linville7e272fc2008-09-24 18:13:14 -040044#include <net/lib80211.h>
Zhu Yib481de92007-09-25 17:54:57 -070045#include <net/mac80211.h>
46
47#include <asm/div64.h>
48
Samuel Ortiza3139c52008-12-19 10:37:09 +080049#define DRV_NAME "iwl3945"
50
Winkler, Tomasdbb66542008-12-22 11:31:14 +080051#include "iwl-fh.h"
52#include "iwl-3945-fh.h"
Tomas Winkler600c0e12008-12-19 10:37:04 +080053#include "iwl-commands.h"
Samuel Ortiz17f841c2009-01-23 13:45:20 -080054#include "iwl-sta.h"
Zhu Yib481de92007-09-25 17:54:57 -070055#include "iwl-3945.h"
56#include "iwl-helpers.h"
Kolekar, Abhijeet5747d472008-12-19 10:37:18 +080057#include "iwl-core.h"
Samuel Ortizd20b3c62008-12-19 10:37:15 +080058#include "iwl-dev.h"
Zhu Yib481de92007-09-25 17:54:57 -070059
Zhu Yib481de92007-09-25 17:54:57 -070060/*
61 * module name, copyright, version, etc.
Zhu Yib481de92007-09-25 17:54:57 -070062 */
63
64#define DRV_DESCRIPTION \
65"Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
66
Samuel Ortizd08853a2009-01-23 13:45:17 -080067#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070068#define VD "d"
69#else
70#define VD
71#endif
72
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080073#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070074#define VS "s"
75#else
76#define VS
77#endif
78
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080079#define IWL39_VERSION "1.2.26k" VD VS
Reinette Chatre01f81622009-01-08 10:20:02 -080080#define DRV_COPYRIGHT "Copyright(c) 2003-2009 Intel Corporation"
Tomas Winklera7b75202008-12-11 10:33:41 -080081#define DRV_AUTHOR "<ilw@linux.intel.com>"
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080082#define DRV_VERSION IWL39_VERSION
Zhu Yib481de92007-09-25 17:54:57 -070083
Zhu Yib481de92007-09-25 17:54:57 -070084
85MODULE_DESCRIPTION(DRV_DESCRIPTION);
86MODULE_VERSION(DRV_VERSION);
Tomas Winklera7b75202008-12-11 10:33:41 -080087MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
Zhu Yib481de92007-09-25 17:54:57 -070088MODULE_LICENSE("GPL");
89
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080090 /* module parameters */
91struct iwl_mod_params iwl3945_mod_params = {
92 .num_of_queues = IWL39_MAX_NUM_QUEUES,
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -080093 .sw_crypto = 1,
Samuel Ortizaf48d042009-01-23 13:45:19 -080094 .restart_fw = 1,
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080095 /* the rest are 0 by default */
96};
97
Zhu Yib481de92007-09-25 17:54:57 -070098/**
Samuel Ortiz7e4bca52009-01-23 13:45:18 -080099 * iwl3945_get_antenna_flags - Get antenna flags for RXON command
100 * @priv: eeprom and antenna fields are used to determine antenna flags
101 *
102 * priv->eeprom39 is used to determine if antenna AUX/MAIN are reversed
103 * iwl3945_mod_params.antenna specifies the antenna diversity mode:
104 *
105 * IWL_ANTENNA_DIVERSITY - NIC selects best antenna by itself
106 * IWL_ANTENNA_MAIN - Force MAIN antenna
107 * IWL_ANTENNA_AUX - Force AUX antenna
108 */
109__le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv)
110{
111 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
112
113 switch (iwl3945_mod_params.antenna) {
114 case IWL_ANTENNA_DIVERSITY:
115 return 0;
116
117 case IWL_ANTENNA_MAIN:
118 if (eeprom->antenna_switch_type)
119 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
120 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
121
122 case IWL_ANTENNA_AUX:
123 if (eeprom->antenna_switch_type)
124 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
125 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
126 }
127
128 /* bad antenna selector value */
129 IWL_ERR(priv, "Bad antenna selector value (0x%x)\n",
130 iwl3945_mod_params.antenna);
131
132 return 0; /* "diversity" is default if error */
133}
134
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800135static int iwl3945_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700136 struct ieee80211_key_conf *keyconf,
137 u8 sta_id)
138{
139 unsigned long flags;
140 __le16 key_flags = 0;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800141 int ret;
Zhu Yib481de92007-09-25 17:54:57 -0700142
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800143 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
144 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
145
146 if (sta_id == priv->hw_params.bcast_sta_id)
147 key_flags |= STA_KEY_MULTICAST_MSK;
148
149 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
150 keyconf->hw_key_idx = keyconf->keyidx;
151 key_flags &= ~STA_KEY_FLG_INVALID;
152
Zhu Yib481de92007-09-25 17:54:57 -0700153 spin_lock_irqsave(&priv->sta_lock, flags);
Tomas Winklerc587de02009-06-03 11:44:07 -0700154 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
155 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
156 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700157 keyconf->keylen);
158
Tomas Winklerc587de02009-06-03 11:44:07 -0700159 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700160 keyconf->keylen);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800161
Tomas Winklerc587de02009-06-03 11:44:07 -0700162 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800163 == STA_KEY_FLG_NO_ENC)
Tomas Winklerc587de02009-06-03 11:44:07 -0700164 priv->stations[sta_id].sta.key.key_offset =
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800165 iwl_get_free_ucode_key_index(priv);
166 /* else, we are overriding an existing key => no need to allocated room
167 * in uCode. */
168
Tomas Winklerc587de02009-06-03 11:44:07 -0700169 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800170 "no space for a new key");
171
Tomas Winklerc587de02009-06-03 11:44:07 -0700172 priv->stations[sta_id].sta.key.key_flags = key_flags;
173 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
174 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700175
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800176 IWL_DEBUG_INFO(priv, "hwcrypto: modify ucode station key info\n");
177
Tomas Winklerc587de02009-06-03 11:44:07 -0700178 ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800179
Zhu Yib481de92007-09-25 17:54:57 -0700180 spin_unlock_irqrestore(&priv->sta_lock, flags);
181
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800182 return ret;
183}
184
185static int iwl3945_set_tkip_dynamic_key_info(struct iwl_priv *priv,
186 struct ieee80211_key_conf *keyconf,
187 u8 sta_id)
188{
189 return -EOPNOTSUPP;
190}
191
192static int iwl3945_set_wep_dynamic_key_info(struct iwl_priv *priv,
193 struct ieee80211_key_conf *keyconf,
194 u8 sta_id)
195{
196 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -0700197}
198
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800199static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
Zhu Yib481de92007-09-25 17:54:57 -0700200{
201 unsigned long flags;
202
203 spin_lock_irqsave(&priv->sta_lock, flags);
Tomas Winklerc587de02009-06-03 11:44:07 -0700204 memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl_hw_key));
205 memset(&priv->stations[sta_id].sta.key, 0,
Tomas Winkler4c897252008-12-19 10:37:05 +0800206 sizeof(struct iwl4965_keyinfo));
Tomas Winklerc587de02009-06-03 11:44:07 -0700207 priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
208 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
209 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700210 spin_unlock_irqrestore(&priv->sta_lock, flags);
211
Tomas Winklere1623442009-01-27 14:27:56 -0800212 IWL_DEBUG_INFO(priv, "hwcrypto: clear ucode station key info\n");
Tomas Winklerc587de02009-06-03 11:44:07 -0700213 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700214 return 0;
215}
216
Abhijeet Kolekarfa11d522009-03-11 11:17:54 -0700217static int iwl3945_set_dynamic_key(struct iwl_priv *priv,
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800218 struct ieee80211_key_conf *keyconf, u8 sta_id)
219{
220 int ret = 0;
221
222 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
223
224 switch (keyconf->alg) {
225 case ALG_CCMP:
226 ret = iwl3945_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
227 break;
228 case ALG_TKIP:
229 ret = iwl3945_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
230 break;
231 case ALG_WEP:
232 ret = iwl3945_set_wep_dynamic_key_info(priv, keyconf, sta_id);
233 break;
234 default:
Abhijeet Kolekar1e680232009-03-17 21:51:50 -0700235 IWL_ERR(priv, "Unknown alg: %s alg = %d\n", __func__, keyconf->alg);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800236 ret = -EINVAL;
237 }
238
239 IWL_DEBUG_WEP(priv, "Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n",
240 keyconf->alg, keyconf->keylen, keyconf->keyidx,
241 sta_id, ret);
242
243 return ret;
244}
245
246static int iwl3945_remove_static_key(struct iwl_priv *priv)
247{
248 int ret = -EOPNOTSUPP;
249
250 return ret;
251}
252
253static int iwl3945_set_static_key(struct iwl_priv *priv,
254 struct ieee80211_key_conf *key)
255{
256 if (key->alg == ALG_WEP)
257 return -EOPNOTSUPP;
258
259 IWL_ERR(priv, "Static key invalid: alg %d\n", key->alg);
260 return -EINVAL;
261}
262
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800263static void iwl3945_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700264{
265 struct list_head *element;
266
Tomas Winklere1623442009-01-27 14:27:56 -0800267 IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
Zhu Yib481de92007-09-25 17:54:57 -0700268 priv->frames_count);
269
270 while (!list_empty(&priv->free_frames)) {
271 element = priv->free_frames.next;
272 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800273 kfree(list_entry(element, struct iwl3945_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700274 priv->frames_count--;
275 }
276
277 if (priv->frames_count) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800278 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
Zhu Yib481de92007-09-25 17:54:57 -0700279 priv->frames_count);
280 priv->frames_count = 0;
281 }
282}
283
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800284static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700285{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800286 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700287 struct list_head *element;
288 if (list_empty(&priv->free_frames)) {
289 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
290 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800291 IWL_ERR(priv, "Could not allocate frame!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700292 return NULL;
293 }
294
295 priv->frames_count++;
296 return frame;
297 }
298
299 element = priv->free_frames.next;
300 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800301 return list_entry(element, struct iwl3945_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700302}
303
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800304static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700305{
306 memset(frame, 0, sizeof(*frame));
307 list_add(&frame->list, &priv->free_frames);
308}
309
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800310unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700311 struct ieee80211_hdr *hdr,
Rami Rosen73ec1cc2008-12-16 09:37:07 +0200312 int left)
Zhu Yib481de92007-09-25 17:54:57 -0700313{
314
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800315 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200316 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
317 (priv->iw_mode != NL80211_IFTYPE_AP)))
Zhu Yib481de92007-09-25 17:54:57 -0700318 return 0;
319
320 if (priv->ibss_beacon->len > left)
321 return 0;
322
323 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
324
325 return priv->ibss_beacon->len;
326}
327
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800328static int iwl3945_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700329{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800330 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700331 unsigned int frame_size;
332 int rc;
333 u8 rate;
334
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800335 frame = iwl3945_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700336
337 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800338 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
Zhu Yib481de92007-09-25 17:54:57 -0700339 "command.\n");
340 return -ENOMEM;
341 }
342
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800343 rate = iwl_rate_get_lowest_plcp(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700344
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800345 frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -0700346
Samuel Ortiz518099a2009-01-19 15:30:27 -0800347 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700348 &frame->u.cmd[0]);
349
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800350 iwl3945_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700351
352 return rc;
353}
354
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800355static void iwl3945_unset_hw_params(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700356{
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800357 if (priv->shared_virt)
Zhu Yib481de92007-09-25 17:54:57 -0700358 pci_free_consistent(priv->pci_dev,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800359 sizeof(struct iwl3945_shared),
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800360 priv->shared_virt,
361 priv->shared_phys);
Zhu Yib481de92007-09-25 17:54:57 -0700362}
363
Zhu Yib481de92007-09-25 17:54:57 -0700364#define MAX_UCODE_BEACON_INTERVAL 1024
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -0800365#define INTEL_CONN_LISTEN_INTERVAL cpu_to_le16(0xA)
Zhu Yib481de92007-09-25 17:54:57 -0700366
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800367static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -0700368{
369 u16 new_val = 0;
370 u16 beacon_factor = 0;
371
372 beacon_factor =
373 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
374 / MAX_UCODE_BEACON_INTERVAL;
375 new_val = beacon_val / beacon_factor;
376
377 return cpu_to_le16(new_val);
378}
379
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800380static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700381{
382 u64 interval_tm_unit;
383 u64 tsf, result;
384 unsigned long flags;
385 struct ieee80211_conf *conf = NULL;
386 u16 beacon_int = 0;
387
388 conf = ieee80211_get_hw_conf(priv->hw);
389
390 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler28afaf92008-12-19 10:37:06 +0800391 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
Zhu Yib481de92007-09-25 17:54:57 -0700392 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
393
Tomas Winkler28afaf92008-12-19 10:37:06 +0800394 tsf = priv->timestamp;
Zhu Yib481de92007-09-25 17:54:57 -0700395
396 beacon_int = priv->beacon_int;
397 spin_unlock_irqrestore(&priv->lock, flags);
398
Johannes Berg05c914f2008-09-11 00:01:58 +0200399 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Zhu Yib481de92007-09-25 17:54:57 -0700400 if (beacon_int == 0) {
401 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
402 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
403 } else {
404 priv->rxon_timing.beacon_interval =
405 cpu_to_le16(beacon_int);
406 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800407 iwl3945_adjust_beacon_interval(
Zhu Yib481de92007-09-25 17:54:57 -0700408 le16_to_cpu(priv->rxon_timing.beacon_interval));
409 }
410
411 priv->rxon_timing.atim_window = 0;
412 } else {
413 priv->rxon_timing.beacon_interval =
Johannes Berg57c4d7b2009-04-23 16:10:04 +0200414 iwl3945_adjust_beacon_interval(
415 priv->vif->bss_conf.beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -0700416 /* TODO: we need to get atim_window from upper stack
417 * for now we set to 0 */
418 priv->rxon_timing.atim_window = 0;
419 }
420
421 interval_tm_unit =
422 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
423 result = do_div(tsf, interval_tm_unit);
424 priv->rxon_timing.beacon_init_val =
425 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
426
Tomas Winklere1623442009-01-27 14:27:56 -0800427 IWL_DEBUG_ASSOC(priv,
428 "beacon interval %d beacon timer %d beacon tim %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700429 le16_to_cpu(priv->rxon_timing.beacon_interval),
430 le32_to_cpu(priv->rxon_timing.beacon_init_val),
431 le16_to_cpu(priv->rxon_timing.atim_window));
432}
433
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800434static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
Johannes Berge039fa42008-05-15 12:55:29 +0200435 struct ieee80211_tx_info *info,
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800436 struct iwl_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -0700437 struct sk_buff *skb_frag,
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800438 int sta_id)
Zhu Yib481de92007-09-25 17:54:57 -0700439{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800440 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
Tomas Winklerc587de02009-06-03 11:44:07 -0700441 struct iwl_hw_key *keyinfo = &priv->stations[sta_id].keyinfo;
Zhu Yib481de92007-09-25 17:54:57 -0700442
443 switch (keyinfo->alg) {
444 case ALG_CCMP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800445 tx->sec_ctl = TX_CMD_SEC_CCM;
446 memcpy(tx->key, keyinfo->key, keyinfo->keylen);
Tomas Winklere1623442009-01-27 14:27:56 -0800447 IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -0700448 break;
449
450 case ALG_TKIP:
Zhu Yib481de92007-09-25 17:54:57 -0700451 break;
452
453 case ALG_WEP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800454 tx->sec_ctl = TX_CMD_SEC_WEP |
Johannes Berge039fa42008-05-15 12:55:29 +0200455 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
Zhu Yib481de92007-09-25 17:54:57 -0700456
457 if (keyinfo->keylen == 13)
Winkler, Tomase52119c2008-12-22 11:31:19 +0800458 tx->sec_ctl |= TX_CMD_SEC_KEY128;
Zhu Yib481de92007-09-25 17:54:57 -0700459
Winkler, Tomase52119c2008-12-22 11:31:19 +0800460 memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen);
Zhu Yib481de92007-09-25 17:54:57 -0700461
Tomas Winklere1623442009-01-27 14:27:56 -0800462 IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
Johannes Berge039fa42008-05-15 12:55:29 +0200463 "with key %d\n", info->control.hw_key->hw_key_idx);
Zhu Yib481de92007-09-25 17:54:57 -0700464 break;
465
Zhu Yib481de92007-09-25 17:54:57 -0700466 default:
Tomas Winkler978785a2008-12-19 10:37:31 +0800467 IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg);
Zhu Yib481de92007-09-25 17:54:57 -0700468 break;
469 }
470}
471
472/*
473 * handle build REPLY_TX command notification.
474 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800475static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800476 struct iwl_cmd *cmd,
Johannes Berge039fa42008-05-15 12:55:29 +0200477 struct ieee80211_tx_info *info,
Winkler, Tomase52119c2008-12-22 11:31:19 +0800478 struct ieee80211_hdr *hdr, u8 std_id)
Zhu Yib481de92007-09-25 17:54:57 -0700479{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800480 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
481 __le32 tx_flags = tx->tx_flags;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700482 __le16 fc = hdr->frame_control;
Johannes Berge6a98542008-10-21 12:40:02 +0200483 u8 rc_flags = info->control.rates[0].flags;
Zhu Yib481de92007-09-25 17:54:57 -0700484
Winkler, Tomase52119c2008-12-22 11:31:19 +0800485 tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Johannes Berge039fa42008-05-15 12:55:29 +0200486 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
Zhu Yib481de92007-09-25 17:54:57 -0700487 tx_flags |= TX_CMD_FLG_ACK_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700488 if (ieee80211_is_mgmt(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700489 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700490 if (ieee80211_is_probe_resp(fc) &&
Zhu Yib481de92007-09-25 17:54:57 -0700491 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
492 tx_flags |= TX_CMD_FLG_TSF_MSK;
493 } else {
494 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
495 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
496 }
497
Winkler, Tomase52119c2008-12-22 11:31:19 +0800498 tx->sta_id = std_id;
Harvey Harrison8b7b1e02008-06-11 14:21:56 -0700499 if (ieee80211_has_morefrags(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700500 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
501
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700502 if (ieee80211_is_data_qos(fc)) {
503 u8 *qc = ieee80211_get_qos_ctl(hdr);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800504 tx->tid_tspec = qc[0] & 0xf;
Zhu Yib481de92007-09-25 17:54:57 -0700505 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800506 } else {
Zhu Yib481de92007-09-25 17:54:57 -0700507 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800508 }
Zhu Yib481de92007-09-25 17:54:57 -0700509
Johannes Berge6a98542008-10-21 12:40:02 +0200510 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
Zhu Yib481de92007-09-25 17:54:57 -0700511 tx_flags |= TX_CMD_FLG_RTS_MSK;
512 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
Johannes Berge6a98542008-10-21 12:40:02 +0200513 } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
Zhu Yib481de92007-09-25 17:54:57 -0700514 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
515 tx_flags |= TX_CMD_FLG_CTS_MSK;
516 }
517
518 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
519 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
520
521 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700522 if (ieee80211_is_mgmt(fc)) {
523 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
Winkler, Tomase52119c2008-12-22 11:31:19 +0800524 tx->timeout.pm_frame_timeout = cpu_to_le16(3);
Zhu Yib481de92007-09-25 17:54:57 -0700525 else
Winkler, Tomase52119c2008-12-22 11:31:19 +0800526 tx->timeout.pm_frame_timeout = cpu_to_le16(2);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700527 } else {
Winkler, Tomase52119c2008-12-22 11:31:19 +0800528 tx->timeout.pm_frame_timeout = 0;
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700529#ifdef CONFIG_IWLWIFI_LEDS
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700530 priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
531#endif
532 }
Zhu Yib481de92007-09-25 17:54:57 -0700533
Winkler, Tomase52119c2008-12-22 11:31:19 +0800534 tx->driver_txop = 0;
535 tx->tx_flags = tx_flags;
536 tx->next_frame_len = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700537}
538
Zhu Yib481de92007-09-25 17:54:57 -0700539/*
540 * start REPLY_TX command process
541 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800542static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -0700543{
544 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berge039fa42008-05-15 12:55:29 +0200545 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800546 struct iwl3945_tx_cmd *tx;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800547 struct iwl_tx_queue *txq = NULL;
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800548 struct iwl_queue *q = NULL;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800549 struct iwl_cmd *out_cmd = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700550 dma_addr_t phys_addr;
551 dma_addr_t txcmd_phys;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800552 int txq_id = skb_get_queue_mapping(skb);
Reinette Chatredf833b12009-04-21 10:55:48 -0700553 u16 len, idx, len_org, hdr_len; /* TODO: len_org is not used */
Tomas Winkler54dbb522008-05-15 13:54:06 +0800554 u8 id;
555 u8 unicast;
Zhu Yib481de92007-09-25 17:54:57 -0700556 u8 sta_id;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800557 u8 tid = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700558 u16 seq_number = 0;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700559 __le16 fc;
Zhu Yib481de92007-09-25 17:54:57 -0700560 u8 wait_write_ptr = 0;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800561 u8 *qc = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700562 unsigned long flags;
563 int rc;
564
565 spin_lock_irqsave(&priv->lock, flags);
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800566 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800567 IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
Zhu Yib481de92007-09-25 17:54:57 -0700568 goto drop_unlock;
569 }
570
Johannes Berge039fa42008-05-15 12:55:29 +0200571 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800572 IWL_ERR(priv, "ERROR: No TX rate available.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700573 goto drop_unlock;
574 }
575
576 unicast = !is_multicast_ether_addr(hdr->addr1);
577 id = 0;
578
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700579 fc = hdr->frame_control;
Zhu Yib481de92007-09-25 17:54:57 -0700580
Samuel Ortizd08853a2009-01-23 13:45:17 -0800581#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -0700582 if (ieee80211_is_auth(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800583 IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700584 else if (ieee80211_is_assoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800585 IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700586 else if (ieee80211_is_reassoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800587 IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
Zhu Yib481de92007-09-25 17:54:57 -0700588#endif
589
Mohamed Abbas7878a5a2007-11-29 11:10:13 +0800590 /* drop all data frame if we are not associated */
Stefanik Gábor914233d2008-06-30 17:23:30 +0800591 if (ieee80211_is_data(fc) &&
Wey-Yi Guy279b05d2009-04-20 14:37:00 -0700592 (!iwl_is_monitor_mode(priv)) && /* packet injection */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800593 (!iwl_is_associated(priv) ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200594 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
Tomas Winklere1623442009-01-27 14:27:56 -0800595 IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n");
Zhu Yib481de92007-09-25 17:54:57 -0700596 goto drop_unlock;
597 }
598
599 spin_unlock_irqrestore(&priv->lock, flags);
600
Harvey Harrison7294ec92008-07-15 18:43:59 -0700601 hdr_len = ieee80211_hdrlen(fc);
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800602
603 /* Find (or create) index into station table for destination station */
Abhijeet Kolekarf5d30262009-04-08 11:26:43 -0700604 sta_id = iwl_get_sta_id(priv, hdr);
Zhu Yib481de92007-09-25 17:54:57 -0700605 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -0800606 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -0700607 hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700608 goto drop;
609 }
610
Tomas Winklere1623442009-01-27 14:27:56 -0800611 IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id);
Zhu Yib481de92007-09-25 17:54:57 -0700612
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700613 if (ieee80211_is_data_qos(fc)) {
614 qc = ieee80211_get_qos_ctl(hdr);
Harvey Harrison7294ec92008-07-15 18:43:59 -0700615 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
Tomas Winklerc587de02009-06-03 11:44:07 -0700616 seq_number = priv->stations[sta_id].tid[tid].seq_number &
Zhu Yib481de92007-09-25 17:54:57 -0700617 IEEE80211_SCTL_SEQ;
618 hdr->seq_ctrl = cpu_to_le16(seq_number) |
619 (hdr->seq_ctrl &
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -0800620 cpu_to_le16(IEEE80211_SCTL_FRAG));
Zhu Yib481de92007-09-25 17:54:57 -0700621 seq_number += 0x10;
622 }
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800623
624 /* Descriptor for chosen Tx queue */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800625 txq = &priv->txq[txq_id];
Zhu Yib481de92007-09-25 17:54:57 -0700626 q = &txq->q;
627
628 spin_lock_irqsave(&priv->lock, flags);
629
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800630 idx = get_cmd_index(q, q->write_ptr, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700631
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800632 /* Set up driver data for this TFD */
Winkler, Tomasdbb66542008-12-22 11:31:14 +0800633 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800634 txq->txb[q->write_ptr].skb[0] = skb;
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800635
636 /* Init first empty entry in queue's array of Tx/cmd buffers */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800637 out_cmd = txq->cmd[idx];
Winkler, Tomase52119c2008-12-22 11:31:19 +0800638 tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
Zhu Yib481de92007-09-25 17:54:57 -0700639 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
Winkler, Tomase52119c2008-12-22 11:31:19 +0800640 memset(tx, 0, sizeof(*tx));
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800641
642 /*
643 * Set up the Tx-command (not MAC!) header.
644 * Store the chosen Tx queue and TFD index within the sequence field;
645 * after Tx, uCode's Tx response will return this value so driver can
646 * locate the frame within the tx queue and do post-tx processing.
647 */
Zhu Yib481de92007-09-25 17:54:57 -0700648 out_cmd->hdr.cmd = REPLY_TX;
649 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800650 INDEX_TO_SEQ(q->write_ptr)));
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800651
652 /* Copy MAC header from skb into command buffer */
Winkler, Tomase52119c2008-12-22 11:31:19 +0800653 memcpy(tx->hdr, hdr, hdr_len);
Zhu Yib481de92007-09-25 17:54:57 -0700654
Reinette Chatredf833b12009-04-21 10:55:48 -0700655
656 if (info->control.hw_key)
657 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, sta_id);
658
659 /* TODO need this for burst mode later on */
660 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
661
662 /* set is_hcca to 0; it probably will never be implemented */
663 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
664
665 /* Total # bytes to be transmitted */
666 len = (u16)skb->len;
667 tx->len = cpu_to_le16(len);
668
669
670 tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
671 tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
672
673 if (!ieee80211_has_morefrags(hdr->frame_control)) {
674 txq->need_update = 1;
675 if (qc)
Tomas Winklerc587de02009-06-03 11:44:07 -0700676 priv->stations[sta_id].tid[tid].seq_number = seq_number;
Reinette Chatredf833b12009-04-21 10:55:48 -0700677 } else {
678 wait_write_ptr = 1;
679 txq->need_update = 0;
680 }
681
682 IWL_DEBUG_TX(priv, "sequence nr = 0X%x \n",
683 le16_to_cpu(out_cmd->hdr.sequence));
684 IWL_DEBUG_TX(priv, "tx_flags = 0X%x \n", le32_to_cpu(tx->tx_flags));
685 iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx));
686 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr,
687 ieee80211_hdrlen(fc));
688
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800689 /*
690 * Use the first empty entry in this queue's command buffer array
691 * to contain the Tx command and MAC header concatenated together
692 * (payload data will be in another buffer).
693 * Size of this varies, due to varying MAC header length.
694 * If end is not dword aligned, we'll have 2 extra bytes at the end
695 * of the MAC header (device reads on dword boundaries).
696 * We'll tell device about this padding later.
697 */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800698 len = sizeof(struct iwl3945_tx_cmd) +
Tomas Winkler4c897252008-12-19 10:37:05 +0800699 sizeof(struct iwl_cmd_header) + hdr_len;
Zhu Yib481de92007-09-25 17:54:57 -0700700
701 len_org = len;
702 len = (len + 3) & ~3;
703
704 if (len_org != len)
705 len_org = 1;
706 else
707 len_org = 0;
708
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800709 /* Physical address of this Tx command's header (not MAC header!),
710 * within command buffer array. */
Reinette Chatredf833b12009-04-21 10:55:48 -0700711 txcmd_phys = pci_map_single(priv->pci_dev, &out_cmd->hdr,
712 len, PCI_DMA_TODEVICE);
713 /* we do not map meta data ... so we can safely access address to
714 * provide to unmap command*/
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800715 pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys);
Reinette Chatredf833b12009-04-21 10:55:48 -0700716 pci_unmap_len_set(&out_cmd->meta, len, len);
Zhu Yib481de92007-09-25 17:54:57 -0700717
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800718 /* Add buffer containing Tx command and MAC(!) header to TFD's
719 * first entry */
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800720 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
721 txcmd_phys, len, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700722
Zhu Yib481de92007-09-25 17:54:57 -0700723
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800724 /* Set up TFD's 2nd entry to point directly to remainder of skb,
725 * if any (802.11 null frames have no payload). */
Zhu Yib481de92007-09-25 17:54:57 -0700726 len = skb->len - hdr_len;
727 if (len) {
728 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
729 len, PCI_DMA_TODEVICE);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800730 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
731 phys_addr, len,
732 0, U32_PAD(len));
Zhu Yib481de92007-09-25 17:54:57 -0700733 }
734
Zhu Yib481de92007-09-25 17:54:57 -0700735
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800736 /* Tell device the write index *just past* this latest filled TFD */
Tomas Winklerc54b6792008-03-06 17:36:53 -0800737 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -0800738 rc = iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -0700739 spin_unlock_irqrestore(&priv->lock, flags);
740
741 if (rc)
742 return rc;
743
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800744 if ((iwl_queue_space(q) < q->high_mark)
Zhu Yib481de92007-09-25 17:54:57 -0700745 && priv->mac80211_registered) {
746 if (wait_write_ptr) {
747 spin_lock_irqsave(&priv->lock, flags);
748 txq->need_update = 1;
Samuel Ortiz4f3602c2009-01-19 15:30:25 -0800749 iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -0700750 spin_unlock_irqrestore(&priv->lock, flags);
751 }
752
Johannes Berge4e72fb2009-03-23 17:28:42 +0100753 iwl_stop_queue(priv, skb_get_queue_mapping(skb));
Zhu Yib481de92007-09-25 17:54:57 -0700754 }
755
756 return 0;
757
758drop_unlock:
759 spin_unlock_irqrestore(&priv->lock, flags);
760drop:
761 return -1;
762}
763
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800764#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -0700765
766#include "iwl-spectrum.h"
767
768#define BEACON_TIME_MASK_LOW 0x00FFFFFF
769#define BEACON_TIME_MASK_HIGH 0xFF000000
770#define TIME_UNIT 1024
771
772/*
773 * extended beacon time format
774 * time in usec will be changed into a 32-bit value in 8:24 format
775 * the high 1 byte is the beacon counts
776 * the lower 3 bytes is the time in usec within one beacon interval
777 */
778
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800779static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -0700780{
781 u32 quot;
782 u32 rem;
783 u32 interval = beacon_interval * 1024;
784
785 if (!interval || !usec)
786 return 0;
787
788 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
789 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
790
791 return (quot << 24) + rem;
792}
793
794/* base is usually what we get from ucode with each received frame,
795 * the same as HW timer counter counting down
796 */
797
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800798static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -0700799{
800 u32 base_low = base & BEACON_TIME_MASK_LOW;
801 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
802 u32 interval = beacon_interval * TIME_UNIT;
803 u32 res = (base & BEACON_TIME_MASK_HIGH) +
804 (addon & BEACON_TIME_MASK_HIGH);
805
806 if (base_low > addon_low)
807 res += base_low - addon_low;
808 else if (base_low < addon_low) {
809 res += interval + base_low - addon_low;
810 res += (1 << 24);
811 } else
812 res += (1 << 24);
813
814 return cpu_to_le32(res);
815}
816
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800817static int iwl3945_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700818 struct ieee80211_measurement_params *params,
819 u8 type)
820{
Tomas Winkler600c0e12008-12-19 10:37:04 +0800821 struct iwl_spectrum_cmd spectrum;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800822 struct iwl_rx_packet *res;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800823 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700824 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
825 .data = (void *)&spectrum,
826 .meta.flags = CMD_WANT_SKB,
827 };
828 u32 add_time = le64_to_cpu(params->start_time);
829 int rc;
830 int spectrum_resp_status;
831 int duration = le16_to_cpu(params->duration);
832
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800833 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700834 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800835 iwl3945_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -0700836 le64_to_cpu(params->start_time) - priv->last_tsf,
837 le16_to_cpu(priv->rxon_timing.beacon_interval));
838
839 memset(&spectrum, 0, sizeof(spectrum));
840
841 spectrum.channel_count = cpu_to_le16(1);
842 spectrum.flags =
843 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
844 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
845 cmd.len = sizeof(spectrum);
846 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
847
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800848 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700849 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800850 iwl3945_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -0700851 add_time,
852 le16_to_cpu(priv->rxon_timing.beacon_interval));
853 else
854 spectrum.start_time = 0;
855
856 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
857 spectrum.channels[0].channel = params->channel;
858 spectrum.channels[0].type = type;
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800859 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
Zhu Yib481de92007-09-25 17:54:57 -0700860 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
861 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
862
Samuel Ortiz518099a2009-01-19 15:30:27 -0800863 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700864 if (rc)
865 return rc;
866
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800867 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700868 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800869 IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -0700870 rc = -EIO;
871 }
872
873 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
874 switch (spectrum_resp_status) {
875 case 0: /* Command will be handled */
876 if (res->u.spectrum.id != 0xff) {
Tomas Winklere1623442009-01-27 14:27:56 -0800877 IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n",
Ian Schrambc434dd2007-10-25 17:15:29 +0800878 res->u.spectrum.id);
Zhu Yib481de92007-09-25 17:54:57 -0700879 priv->measurement_status &= ~MEASUREMENT_READY;
880 }
881 priv->measurement_status |= MEASUREMENT_ACTIVE;
882 rc = 0;
883 break;
884
885 case 1: /* Command will not be handled */
886 rc = -EAGAIN;
887 break;
888 }
889
890 dev_kfree_skb_any(cmd.meta.u.skb);
891
892 return rc;
893}
894#endif
895
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800896static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +0800897 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700898{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800899 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
900 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -0700901 struct delayed_work *pwork;
902
903 palive = &pkt->u.alive_frame;
904
Tomas Winklere1623442009-01-27 14:27:56 -0800905 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
Zhu Yib481de92007-09-25 17:54:57 -0700906 "0x%01X 0x%01X\n",
907 palive->is_valid, palive->ver_type,
908 palive->ver_subtype);
909
910 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
Tomas Winklere1623442009-01-27 14:27:56 -0800911 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800912 memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
913 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700914 pwork = &priv->init_alive_start;
915 } else {
Tomas Winklere1623442009-01-27 14:27:56 -0800916 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700917 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800918 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700919 pwork = &priv->alive_start;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800920 iwl3945_disable_events(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700921 }
922
923 /* We delay the ALIVE response by 5ms to
924 * give the HW RF Kill time to activate... */
925 if (palive->is_valid == UCODE_VALID_OK)
926 queue_delayed_work(priv->workqueue, pwork,
927 msecs_to_jiffies(5));
928 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800929 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700930}
931
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800932static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +0800933 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700934{
Helmut Schaac7e035a2009-01-19 13:02:15 +0100935#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800936 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Helmut Schaac7e035a2009-01-19 13:02:15 +0100937#endif
Zhu Yib481de92007-09-25 17:54:57 -0700938
Tomas Winklere1623442009-01-27 14:27:56 -0800939 IWL_DEBUG_RX(priv, "Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
Zhu Yib481de92007-09-25 17:54:57 -0700940 return;
941}
942
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800943static void iwl3945_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -0700944{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800945 struct iwl_priv *priv =
946 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -0700947 struct sk_buff *beacon;
948
949 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +0200950 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -0700951
952 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800953 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -0700954 return;
955 }
956
957 mutex_lock(&priv->mutex);
958 /* new beacon skb is allocated every time; dispose previous.*/
959 if (priv->ibss_beacon)
960 dev_kfree_skb(priv->ibss_beacon);
961
962 priv->ibss_beacon = beacon;
963 mutex_unlock(&priv->mutex);
964
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800965 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700966}
967
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800968static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +0800969 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700970{
Samuel Ortizd08853a2009-01-23 13:45:17 -0800971#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800972 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800973 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
Zhu Yib481de92007-09-25 17:54:57 -0700974 u8 rate = beacon->beacon_notify_hdr.rate;
975
Tomas Winklere1623442009-01-27 14:27:56 -0800976 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
Zhu Yib481de92007-09-25 17:54:57 -0700977 "tsf %d %d rate %d\n",
978 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
979 beacon->beacon_notify_hdr.failure_frame,
980 le32_to_cpu(beacon->ibss_mgr_status),
981 le32_to_cpu(beacon->high_tsf),
982 le32_to_cpu(beacon->low_tsf), rate);
983#endif
984
Johannes Berg05c914f2008-09-11 00:01:58 +0200985 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -0700986 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
987 queue_work(priv->workqueue, &priv->beacon_update);
988}
989
Zhu Yib481de92007-09-25 17:54:57 -0700990/* Handle notification from uCode that card's power state is changing
991 * due to software, hardware, or critical temperature RFKILL */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800992static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +0800993 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700994{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800995 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700996 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
997 unsigned long status = priv->status;
998
Tomas Winklere1623442009-01-27 14:27:56 -0800999 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
Zhu Yib481de92007-09-25 17:54:57 -07001000 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1001 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1002
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001003 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001004 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1005
1006 if (flags & HW_CARD_DISABLED)
1007 set_bit(STATUS_RF_KILL_HW, &priv->status);
1008 else
1009 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1010
1011
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08001012 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001013
1014 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
Johannes Berga60e77e2009-06-04 18:26:06 +02001015 test_bit(STATUS_RF_KILL_HW, &priv->status)))
1016 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
1017 test_bit(STATUS_RF_KILL_HW, &priv->status));
Zhu Yib481de92007-09-25 17:54:57 -07001018 else
1019 wake_up_interruptible(&priv->wait_command_queue);
1020}
1021
1022/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001023 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07001024 *
1025 * Setup the RX handlers for each of the reply types sent from the uCode
1026 * to the host.
1027 *
1028 * This function chains into the hardware specific files for them to setup
1029 * any hardware specific handlers as well.
1030 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001031static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001032{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001033 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
1034 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -08001035 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001036 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -08001037 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001038 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -08001039 iwl_rx_pm_debug_statistics_notif;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001040 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001041
Ben Cahill9fbab512007-11-29 11:09:47 +08001042 /*
1043 * The same handler is used for both the REPLY to a discrete
1044 * statistics request from the host as well as for the periodic
1045 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07001046 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001047 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
1048 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -07001049
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -08001050 iwl_setup_spectrum_handlers(priv);
Abhijeet Kolekarcade0eb2009-02-18 15:54:26 -08001051 iwl_setup_rx_scan_handlers(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001052 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001053
Ben Cahill9fbab512007-11-29 11:09:47 +08001054 /* Set up hardware specific Rx handlers */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001055 iwl3945_hw_rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001056}
1057
Zhu Yib481de92007-09-25 17:54:57 -07001058/************************** RX-FUNCTIONS ****************************/
1059/*
1060 * Rx theory of operation
1061 *
1062 * The host allocates 32 DMA target addresses and passes the host address
1063 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
1064 * 0 to 31
1065 *
1066 * Rx Queue Indexes
1067 * The host/firmware share two index registers for managing the Rx buffers.
1068 *
1069 * The READ index maps to the first position that the firmware may be writing
1070 * to -- the driver can read up to (but not including) this position and get
1071 * good data.
1072 * The READ index is managed by the firmware once the card is enabled.
1073 *
1074 * The WRITE index maps to the last position the driver has read from -- the
1075 * position preceding WRITE is the last slot the firmware can place a packet.
1076 *
1077 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
1078 * WRITE = READ.
1079 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001080 * During initialization, the host sets up the READ queue position to the first
Zhu Yib481de92007-09-25 17:54:57 -07001081 * INDEX position, and WRITE to the last (READ - 1 wrapped)
1082 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001083 * When the firmware places a packet in a buffer, it will advance the READ index
Zhu Yib481de92007-09-25 17:54:57 -07001084 * and fire the RX interrupt. The driver can then query the READ index and
1085 * process as many packets as possible, moving the WRITE index forward as it
1086 * resets the Rx queue buffers with new memory.
1087 *
1088 * The management in the driver is as follows:
1089 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
1090 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Ian Schram01ebd062007-10-25 17:15:22 +08001091 * to replenish the iwl->rxq->rx_free.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001092 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
Zhu Yib481de92007-09-25 17:54:57 -07001093 * iwl->rxq is replenished and the READ INDEX is updated (updating the
1094 * 'processed' and 'read' driver indexes as well)
1095 * + A received packet is processed and handed to the kernel network stack,
1096 * detached from the iwl->rxq. The driver 'processed' index is updated.
1097 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
1098 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
1099 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
1100 * were enough free buffers and RX_STALLED is set it is cleared.
1101 *
1102 *
1103 * Driver sequence:
1104 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001105 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001106 * iwl3945_rx_queue_restock
Ben Cahill9fbab512007-11-29 11:09:47 +08001107 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
Zhu Yib481de92007-09-25 17:54:57 -07001108 * queue, updates firmware pointers, and updates
1109 * the WRITE index. If insufficient rx_free buffers
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001110 * are available, schedules iwl3945_rx_replenish
Zhu Yib481de92007-09-25 17:54:57 -07001111 *
1112 * -- enable interrupts --
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001113 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
Zhu Yib481de92007-09-25 17:54:57 -07001114 * READ INDEX, detaching the SKB from the pool.
1115 * Moves the packet buffer from queue to rx_used.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001116 * Calls iwl3945_rx_queue_restock to refill any empty
Zhu Yib481de92007-09-25 17:54:57 -07001117 * slots.
1118 * ...
1119 *
1120 */
1121
1122/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001123 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
Zhu Yib481de92007-09-25 17:54:57 -07001124 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001125static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001126 dma_addr_t dma_addr)
1127{
1128 return cpu_to_le32((u32)dma_addr);
1129}
1130
1131/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001132 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
Zhu Yib481de92007-09-25 17:54:57 -07001133 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001134 * If there are slots in the RX queue that need to be restocked,
Zhu Yib481de92007-09-25 17:54:57 -07001135 * and we have free pre-allocated buffers, fill the ranks as much
Ben Cahill9fbab512007-11-29 11:09:47 +08001136 * as we can, pulling from rx_free.
Zhu Yib481de92007-09-25 17:54:57 -07001137 *
1138 * This moves the 'write' index forward to catch up with 'processed', and
1139 * also updates the memory address in the firmware to reference the new
1140 * target buffer.
1141 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001142static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001143{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001144 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001145 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001146 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001147 unsigned long flags;
1148 int write, rc;
1149
1150 spin_lock_irqsave(&rxq->lock, flags);
1151 write = rxq->write & ~0x7;
Winkler, Tomas37d68312009-01-08 10:19:54 -08001152 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001153 /* Get next free Rx buffer, remove from free list */
Zhu Yib481de92007-09-25 17:54:57 -07001154 element = rxq->rx_free.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001155 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07001156 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001157
1158 /* Point to Rx buffer via next RBD in circular buffer */
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001159 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
Zhu Yib481de92007-09-25 17:54:57 -07001160 rxq->queue[rxq->write] = rxb;
1161 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
1162 rxq->free_count--;
1163 }
1164 spin_unlock_irqrestore(&rxq->lock, flags);
1165 /* If the pre-allocated buffer pool is dropping low, schedule to
1166 * refill it */
1167 if (rxq->free_count <= RX_LOW_WATERMARK)
1168 queue_work(priv->workqueue, &priv->rx_replenish);
1169
1170
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001171 /* If we've added more space for the firmware to place data, tell it.
1172 * Increment device's write pointer in multiples of 8. */
Abhijeet Kolekard14d4442009-06-03 11:44:08 -07001173 if ((rxq->write_actual != (rxq->write & ~0x7))
Zhu Yib481de92007-09-25 17:54:57 -07001174 || (abs(rxq->write - rxq->read) > 7)) {
1175 spin_lock_irqsave(&rxq->lock, flags);
1176 rxq->need_update = 1;
1177 spin_unlock_irqrestore(&rxq->lock, flags);
Winkler, Tomas141c43a2009-01-08 10:19:53 -08001178 rc = iwl_rx_queue_update_write_ptr(priv, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07001179 if (rc)
1180 return rc;
1181 }
1182
1183 return 0;
1184}
1185
1186/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001187 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
Zhu Yib481de92007-09-25 17:54:57 -07001188 *
1189 * When moving to rx_free an SKB is allocated for the slot.
1190 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001191 * Also restock the Rx queue via iwl3945_rx_queue_restock.
Ian Schram01ebd062007-10-25 17:15:22 +08001192 * This is called as a scheduled work item (except for during initialization)
Zhu Yib481de92007-09-25 17:54:57 -07001193 */
Abhijeet Kolekard14d4442009-06-03 11:44:08 -07001194static void iwl3945_rx_allocate(struct iwl_priv *priv, gfp_t priority)
Zhu Yib481de92007-09-25 17:54:57 -07001195{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001196 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001197 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001198 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001199 unsigned long flags;
Abhijeet Kolekar72240492009-04-30 13:56:26 -07001200
1201 while (1) {
1202 spin_lock_irqsave(&rxq->lock, flags);
1203
1204 if (list_empty(&rxq->rx_used)) {
1205 spin_unlock_irqrestore(&rxq->lock, flags);
1206 return;
1207 }
1208
Zhu Yib481de92007-09-25 17:54:57 -07001209 element = rxq->rx_used.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001210 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Abhijeet Kolekar72240492009-04-30 13:56:26 -07001211 list_del(element);
1212 spin_unlock_irqrestore(&rxq->lock, flags);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001213
1214 /* Alloc a new receive buffer */
Zhu Yib481de92007-09-25 17:54:57 -07001215 rxb->skb =
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001216 alloc_skb(priv->hw_params.rx_buf_size,
Abhijeet Kolekard14d4442009-06-03 11:44:08 -07001217 priority);
Zhu Yib481de92007-09-25 17:54:57 -07001218 if (!rxb->skb) {
1219 if (net_ratelimit())
Tomas Winkler978785a2008-12-19 10:37:31 +08001220 IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
Zhu Yib481de92007-09-25 17:54:57 -07001221 /* We don't reschedule replenish work here -- we will
1222 * call the restock method and if it still needs
1223 * more buffers it will schedule replenish */
1224 break;
1225 }
Zhu Yi12342c42007-12-20 11:27:32 +08001226
1227 /* If radiotap head is required, reserve some headroom here.
1228 * The physical head count is a variable rx_stats->phy_count.
1229 * We reserve 4 bytes here. Plus these extra bytes, the
1230 * headroom of the physical head should be enough for the
1231 * radiotap head that iwl3945 supported. See iwl3945_rt.
1232 */
1233 skb_reserve(rxb->skb, 4);
1234
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001235 /* Get physical address of RB/SKB */
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001236 rxb->real_dma_addr = pci_map_single(priv->pci_dev,
1237 rxb->skb->data,
1238 priv->hw_params.rx_buf_size,
1239 PCI_DMA_FROMDEVICE);
Abhijeet Kolekar72240492009-04-30 13:56:26 -07001240
1241 spin_lock_irqsave(&rxq->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -07001242 list_add_tail(&rxb->list, &rxq->rx_free);
Abhijeet Kolekar72240492009-04-30 13:56:26 -07001243 priv->alloc_rxb_skb++;
Zhu Yib481de92007-09-25 17:54:57 -07001244 rxq->free_count++;
Abhijeet Kolekar72240492009-04-30 13:56:26 -07001245 spin_unlock_irqrestore(&rxq->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -07001246 }
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001247}
1248
Reinette Chatredf833b12009-04-21 10:55:48 -07001249void iwl3945_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
1250{
1251 unsigned long flags;
1252 int i;
1253 spin_lock_irqsave(&rxq->lock, flags);
1254 INIT_LIST_HEAD(&rxq->rx_free);
1255 INIT_LIST_HEAD(&rxq->rx_used);
1256 /* Fill the rx_used queue with _all_ of the Rx buffers */
1257 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
1258 /* In the reset function, these buffers may have been allocated
1259 * to an SKB, so we need to unmap and free potential storage */
1260 if (rxq->pool[i].skb != NULL) {
1261 pci_unmap_single(priv->pci_dev,
1262 rxq->pool[i].real_dma_addr,
1263 priv->hw_params.rx_buf_size,
1264 PCI_DMA_FROMDEVICE);
1265 priv->alloc_rxb_skb--;
1266 dev_kfree_skb(rxq->pool[i].skb);
1267 rxq->pool[i].skb = NULL;
1268 }
1269 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
1270 }
1271
1272 /* Set us so that we have processed and used all buffers, but have
1273 * not restocked the Rx queue with fresh buffers */
1274 rxq->read = rxq->write = 0;
1275 rxq->free_count = 0;
Abhijeet Kolekard14d4442009-06-03 11:44:08 -07001276 rxq->write_actual = 0;
Reinette Chatredf833b12009-04-21 10:55:48 -07001277 spin_unlock_irqrestore(&rxq->lock, flags);
1278}
Reinette Chatredf833b12009-04-21 10:55:48 -07001279
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001280void iwl3945_rx_replenish(void *data)
1281{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001282 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001283 unsigned long flags;
1284
Abhijeet Kolekard14d4442009-06-03 11:44:08 -07001285 iwl3945_rx_allocate(priv, GFP_KERNEL);
Zhu Yib481de92007-09-25 17:54:57 -07001286
1287 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001288 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001289 spin_unlock_irqrestore(&priv->lock, flags);
1290}
1291
Abhijeet Kolekard14d4442009-06-03 11:44:08 -07001292static void iwl3945_rx_replenish_now(struct iwl_priv *priv)
1293{
1294 iwl3945_rx_allocate(priv, GFP_ATOMIC);
1295
1296 iwl3945_rx_queue_restock(priv);
1297}
1298
1299
Reinette Chatredf833b12009-04-21 10:55:48 -07001300/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
1301 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
1302 * This free routine walks the list of POOL entries and if SKB is set to
1303 * non NULL it is unmapped and freed
1304 */
1305static void iwl3945_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
1306{
1307 int i;
1308 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
1309 if (rxq->pool[i].skb != NULL) {
1310 pci_unmap_single(priv->pci_dev,
1311 rxq->pool[i].real_dma_addr,
1312 priv->hw_params.rx_buf_size,
1313 PCI_DMA_FROMDEVICE);
1314 dev_kfree_skb(rxq->pool[i].skb);
1315 }
1316 }
1317
1318 pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd,
1319 rxq->dma_addr);
1320 pci_free_consistent(priv->pci_dev, sizeof(struct iwl_rb_status),
1321 rxq->rb_stts, rxq->rb_stts_dma);
1322 rxq->bd = NULL;
1323 rxq->rb_stts = NULL;
1324}
Reinette Chatredf833b12009-04-21 10:55:48 -07001325
1326
Zhu Yib481de92007-09-25 17:54:57 -07001327/* Convert linear signal-to-noise ratio into dB */
1328static u8 ratio2dB[100] = {
1329/* 0 1 2 3 4 5 6 7 8 9 */
1330 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
1331 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
1332 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
1333 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
1334 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
1335 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
1336 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
1337 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
1338 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
1339 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
1340};
1341
1342/* Calculates a relative dB value from a ratio of linear
1343 * (i.e. not dB) signal levels.
1344 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001345int iwl3945_calc_db_from_ratio(int sig_ratio)
Zhu Yib481de92007-09-25 17:54:57 -07001346{
Adrian Bunk221c80c2008-02-02 23:19:01 +02001347 /* 1000:1 or higher just report as 60 dB */
1348 if (sig_ratio >= 1000)
Zhu Yib481de92007-09-25 17:54:57 -07001349 return 60;
1350
Adrian Bunk221c80c2008-02-02 23:19:01 +02001351 /* 100:1 or higher, divide by 10 and use table,
Zhu Yib481de92007-09-25 17:54:57 -07001352 * add 20 dB to make up for divide by 10 */
Adrian Bunk221c80c2008-02-02 23:19:01 +02001353 if (sig_ratio >= 100)
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001354 return 20 + (int)ratio2dB[sig_ratio/10];
Zhu Yib481de92007-09-25 17:54:57 -07001355
1356 /* We shouldn't see this */
1357 if (sig_ratio < 1)
1358 return 0;
1359
1360 /* Use table for ratios 1:1 - 99:1 */
1361 return (int)ratio2dB[sig_ratio];
1362}
1363
1364#define PERFECT_RSSI (-20) /* dBm */
1365#define WORST_RSSI (-95) /* dBm */
1366#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
1367
1368/* Calculate an indication of rx signal quality (a percentage, not dBm!).
1369 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
1370 * about formulas used below. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001371int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
Zhu Yib481de92007-09-25 17:54:57 -07001372{
1373 int sig_qual;
1374 int degradation = PERFECT_RSSI - rssi_dbm;
1375
1376 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
1377 * as indicator; formula is (signal dbm - noise dbm).
1378 * SNR at or above 40 is a great signal (100%).
1379 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
1380 * Weakest usable signal is usually 10 - 15 dB SNR. */
1381 if (noise_dbm) {
1382 if (rssi_dbm - noise_dbm >= 40)
1383 return 100;
1384 else if (rssi_dbm < noise_dbm)
1385 return 0;
1386 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
1387
1388 /* Else use just the signal level.
1389 * This formula is a least squares fit of data points collected and
1390 * compared with a reference system that had a percentage (%) display
1391 * for signal quality. */
1392 } else
1393 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
1394 (15 * RSSI_RANGE + 62 * degradation)) /
1395 (RSSI_RANGE * RSSI_RANGE);
1396
1397 if (sig_qual > 100)
1398 sig_qual = 100;
1399 else if (sig_qual < 1)
1400 sig_qual = 0;
1401
1402 return sig_qual;
1403}
1404
1405/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001406 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001407 *
1408 * Uses the priv->rx_handlers callback function array to invoke
1409 * the appropriate handlers, including command responses,
1410 * frame-received notifications, and other notifications.
1411 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001412static void iwl3945_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001413{
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001414 struct iwl_rx_mem_buffer *rxb;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001415 struct iwl_rx_packet *pkt;
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001416 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001417 u32 r, i;
1418 int reclaim;
1419 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001420 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001421 u32 count = 8;
Abhijeet Kolekard14d4442009-06-03 11:44:08 -07001422 int total_empty = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001423
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001424 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1425 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8cd812b2008-12-19 10:37:43 +08001426 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07001427 i = rxq->read;
1428
Abhijeet Kolekard14d4442009-06-03 11:44:08 -07001429 /* calculate total frames need to be restock after handling RX */
1430 total_empty = r - priv->rxq.write_actual;
1431 if (total_empty < 0)
1432 total_empty += RX_QUEUE_SIZE;
1433
1434 if (total_empty > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001435 fill_rx = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001436 /* Rx interrupt, but nothing sent from uCode */
1437 if (i == r)
Tomas Winklere1623442009-01-27 14:27:56 -08001438 IWL_DEBUG(priv, IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001439
1440 while (i != r) {
1441 rxb = rxq->queue[i];
1442
Ben Cahill9fbab512007-11-29 11:09:47 +08001443 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001444 * then a bug has been introduced in the queue refilling
1445 * routines -- catch it here */
1446 BUG_ON(rxb == NULL);
1447
1448 rxq->queue[i] = NULL;
1449
Reinette Chatredf833b12009-04-21 10:55:48 -07001450 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
1451 priv->hw_params.rx_buf_size,
1452 PCI_DMA_FROMDEVICE);
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001453 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001454
1455 /* Reclaim a command buffer only if this packet is a response
1456 * to a (driver-originated) command.
1457 * If the packet (e.g. Rx frame) originated from uCode,
1458 * there is no command buffer to reclaim.
1459 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1460 * but apparently a few don't get set; catch them here. */
1461 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1462 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1463 (pkt->hdr.cmd != REPLY_TX);
1464
1465 /* Based on type of command response or notification,
1466 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001467 * rx_handlers table. See iwl3945_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001468 if (priv->rx_handlers[pkt->hdr.cmd]) {
Tomas Winklere1623442009-01-27 14:27:56 -08001469 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07001470 "r = %d, i = %d, %s, 0x%02x\n", r, i,
1471 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
1472 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001473 priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
Zhu Yib481de92007-09-25 17:54:57 -07001474 } else {
1475 /* No handling needed */
Tomas Winklere1623442009-01-27 14:27:56 -08001476 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07001477 "r %d i %d No handler needed for %s, 0x%02x\n",
1478 r, i, get_cmd_string(pkt->hdr.cmd),
1479 pkt->hdr.cmd);
1480 }
1481
1482 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001483 /* Invoke any callbacks, transfer the skb to caller, and
Samuel Ortiz518099a2009-01-19 15:30:27 -08001484 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001485 * as we reclaim the driver command queue */
1486 if (rxb && rxb->skb)
Abhijeet Kolekar732587a2009-03-11 11:17:57 -07001487 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001488 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001489 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07001490 }
1491
1492 /* For now we just don't re-use anything. We can tweak this
1493 * later to try and re-use notification packets and SKBs that
1494 * fail to Rx correctly */
1495 if (rxb->skb != NULL) {
1496 priv->alloc_rxb_skb--;
1497 dev_kfree_skb_any(rxb->skb);
1498 rxb->skb = NULL;
1499 }
1500
Zhu Yib481de92007-09-25 17:54:57 -07001501 spin_lock_irqsave(&rxq->lock, flags);
1502 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1503 spin_unlock_irqrestore(&rxq->lock, flags);
1504 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001505 /* If there are a lot of unused frames,
1506 * restock the Rx queue so ucode won't assert. */
1507 if (fill_rx) {
1508 count++;
1509 if (count >= 8) {
1510 priv->rxq.read = i;
Abhijeet Kolekard14d4442009-06-03 11:44:08 -07001511 iwl3945_rx_replenish_now(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001512 count = 0;
1513 }
1514 }
Zhu Yib481de92007-09-25 17:54:57 -07001515 }
1516
1517 /* Backtrack one entry */
1518 priv->rxq.read = i;
Abhijeet Kolekard14d4442009-06-03 11:44:08 -07001519 if (fill_rx)
1520 iwl3945_rx_replenish_now(priv);
1521 else
1522 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001523}
1524
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001525/* call this function to flush any scheduled tasklet */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001526static inline void iwl_synchronize_irq(struct iwl_priv *priv)
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001527{
Tomas Winklera96a27f2008-10-23 23:48:56 -07001528 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001529 synchronize_irq(priv->pci_dev->irq);
1530 tasklet_kill(&priv->irq_tasklet);
1531}
1532
Zhu Yib481de92007-09-25 17:54:57 -07001533static const char *desc_lookup(int i)
1534{
1535 switch (i) {
1536 case 1:
1537 return "FAIL";
1538 case 2:
1539 return "BAD_PARAM";
1540 case 3:
1541 return "BAD_CHECKSUM";
1542 case 4:
1543 return "NMI_INTERRUPT";
1544 case 5:
1545 return "SYSASSERT";
1546 case 6:
1547 return "FATAL_ERROR";
1548 }
1549
1550 return "UNKNOWN";
1551}
1552
1553#define ERROR_START_OFFSET (1 * sizeof(u32))
1554#define ERROR_ELEM_SIZE (7 * sizeof(u32))
1555
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001556static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001557{
1558 u32 i;
1559 u32 desc, time, count, base, data1;
1560 u32 blink1, blink2, ilink1, ilink2;
Zhu Yib481de92007-09-25 17:54:57 -07001561
1562 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
1563
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001564 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001565 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07001566 return;
1567 }
1568
Zhu Yib481de92007-09-25 17:54:57 -07001569
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001570 count = iwl_read_targ_mem(priv, base);
Zhu Yib481de92007-09-25 17:54:57 -07001571
1572 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001573 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
1574 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
1575 priv->status, count);
Zhu Yib481de92007-09-25 17:54:57 -07001576 }
1577
Winkler, Tomas15b16872008-12-19 10:37:33 +08001578 IWL_ERR(priv, "Desc Time asrtPC blink2 "
Zhu Yib481de92007-09-25 17:54:57 -07001579 "ilink1 nmiPC Line\n");
1580 for (i = ERROR_START_OFFSET;
1581 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
1582 i += ERROR_ELEM_SIZE) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001583 desc = iwl_read_targ_mem(priv, base + i);
Zhu Yib481de92007-09-25 17:54:57 -07001584 time =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001585 iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001586 blink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001587 iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001588 blink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001589 iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001590 ilink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001591 iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001592 ilink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001593 iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001594 data1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001595 iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001596
Winkler, Tomas15b16872008-12-19 10:37:33 +08001597 IWL_ERR(priv,
1598 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
1599 desc_lookup(desc), desc, time, blink1, blink2,
1600 ilink1, ilink2, data1);
Zhu Yib481de92007-09-25 17:54:57 -07001601 }
1602
Zhu Yib481de92007-09-25 17:54:57 -07001603}
1604
Ben Cahillf58177b2007-11-29 11:09:43 +08001605#define EVENT_START_OFFSET (6 * sizeof(u32))
Zhu Yib481de92007-09-25 17:54:57 -07001606
1607/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001608 * iwl3945_print_event_log - Dump error event log to syslog
Zhu Yib481de92007-09-25 17:54:57 -07001609 *
Zhu Yib481de92007-09-25 17:54:57 -07001610 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001611static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
Zhu Yib481de92007-09-25 17:54:57 -07001612 u32 num_events, u32 mode)
1613{
1614 u32 i;
1615 u32 base; /* SRAM byte address of event log header */
1616 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
1617 u32 ptr; /* SRAM byte address of log data */
1618 u32 ev, time, data; /* event log data */
1619
1620 if (num_events == 0)
1621 return;
1622
1623 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
1624
1625 if (mode == 0)
1626 event_size = 2 * sizeof(u32);
1627 else
1628 event_size = 3 * sizeof(u32);
1629
1630 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
1631
1632 /* "time" is actually "data" for mode 0 (no timestamp).
1633 * place event id # at far right for easier visual parsing. */
1634 for (i = 0; i < num_events; i++) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001635 ev = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07001636 ptr += sizeof(u32);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001637 time = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07001638 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08001639 if (mode == 0) {
1640 /* data, ev */
1641 IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
1642 } else {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001643 data = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07001644 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08001645 IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
Zhu Yib481de92007-09-25 17:54:57 -07001646 }
1647 }
1648}
1649
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001650static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001651{
Zhu Yib481de92007-09-25 17:54:57 -07001652 u32 base; /* SRAM byte address of event log header */
1653 u32 capacity; /* event log capacity in # entries */
1654 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
1655 u32 num_wraps; /* # times uCode wrapped to top of log */
1656 u32 next_entry; /* index of next entry to be written by uCode */
1657 u32 size; /* # entries that we'll print */
1658
1659 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001660 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001661 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07001662 return;
1663 }
1664
Zhu Yib481de92007-09-25 17:54:57 -07001665 /* event log header */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001666 capacity = iwl_read_targ_mem(priv, base);
1667 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
1668 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
1669 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -07001670
1671 size = num_wraps ? capacity : next_entry;
1672
1673 /* bail out if nothing in log */
1674 if (size == 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001675 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Zhu Yib481de92007-09-25 17:54:57 -07001676 return;
1677 }
1678
Winkler, Tomas15b16872008-12-19 10:37:33 +08001679 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07001680 size, num_wraps);
1681
1682 /* if uCode has wrapped back to top of log, start at the oldest entry,
1683 * i.e the next one that uCode would fill. */
1684 if (num_wraps)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001685 iwl3945_print_event_log(priv, next_entry,
Zhu Yib481de92007-09-25 17:54:57 -07001686 capacity - next_entry, mode);
1687
1688 /* (then/else) start at top of log */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001689 iwl3945_print_event_log(priv, 0, next_entry, mode);
Zhu Yib481de92007-09-25 17:54:57 -07001690
Zhu Yib481de92007-09-25 17:54:57 -07001691}
1692
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001693static void iwl3945_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001694{
1695 u32 inta, handled = 0;
1696 u32 inta_fh;
1697 unsigned long flags;
Samuel Ortizd08853a2009-01-23 13:45:17 -08001698#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001699 u32 inta_mask;
1700#endif
1701
1702 spin_lock_irqsave(&priv->lock, flags);
1703
1704 /* Ack/clear/reset pending uCode interrupts.
1705 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1706 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001707 inta = iwl_read32(priv, CSR_INT);
1708 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07001709
1710 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1711 * Any new interrupts that happen after this, either while we're
1712 * in this tasklet, or later, will show up in next ISR/tasklet. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001713 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1714 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001715
Samuel Ortizd08853a2009-01-23 13:45:17 -08001716#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08001717 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001718 /* just for debug */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001719 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Tomas Winklere1623442009-01-27 14:27:56 -08001720 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07001721 inta, inta_mask, inta_fh);
1722 }
1723#endif
1724
1725 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1726 * atomic, make sure that inta covers all the interrupts that
1727 * we've discovered, even if FH interrupt came in just after
1728 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001729 if (inta_fh & CSR39_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001730 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001731 if (inta_fh & CSR39_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001732 inta |= CSR_INT_BIT_FH_TX;
1733
1734 /* Now service all interrupt bits discovered above. */
1735 if (inta & CSR_INT_BIT_HW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001736 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001737
1738 /* Tell the device to stop sending interrupts */
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08001739 iwl_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001740
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001741 priv->isr_stats.hw++;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001742 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001743
1744 handled |= CSR_INT_BIT_HW_ERR;
1745
1746 spin_unlock_irqrestore(&priv->lock, flags);
1747
1748 return;
1749 }
1750
Samuel Ortizd08853a2009-01-23 13:45:17 -08001751#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08001752 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07001753 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001754 if (inta & CSR_INT_BIT_SCD) {
Tomas Winklere1623442009-01-27 14:27:56 -08001755 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
Joonwoo Park25c03d82008-01-23 10:15:20 -08001756 "the frame/frames.\n");
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001757 priv->isr_stats.sch++;
1758 }
Zhu Yib481de92007-09-25 17:54:57 -07001759
1760 /* Alive notification via Rx interrupt will do the real work */
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001761 if (inta & CSR_INT_BIT_ALIVE) {
Tomas Winklere1623442009-01-27 14:27:56 -08001762 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001763 priv->isr_stats.alive++;
1764 }
Zhu Yib481de92007-09-25 17:54:57 -07001765 }
1766#endif
1767 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001768 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07001769
Zhu Yib481de92007-09-25 17:54:57 -07001770 /* Error detected by uCode */
1771 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001772 IWL_ERR(priv, "Microcode SW error detected. "
1773 "Restarting 0x%X.\n", inta);
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001774 priv->isr_stats.sw++;
1775 priv->isr_stats.sw_err = inta;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001776 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001777 handled |= CSR_INT_BIT_SW_ERR;
1778 }
1779
1780 /* uCode wakes up after power-down sleep */
1781 if (inta & CSR_INT_BIT_WAKEUP) {
Tomas Winklere1623442009-01-27 14:27:56 -08001782 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
Winkler, Tomas141c43a2009-01-08 10:19:53 -08001783 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001784 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
1785 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
1786 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
1787 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
1788 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1789 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07001790
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001791 priv->isr_stats.wakeup++;
Zhu Yib481de92007-09-25 17:54:57 -07001792 handled |= CSR_INT_BIT_WAKEUP;
1793 }
1794
1795 /* All uCode command responses, including Tx command responses,
1796 * Rx "responses" (frame-received notification), and other
1797 * notifications from uCode come through here*/
1798 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001799 iwl3945_rx_handle(priv);
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001800 priv->isr_stats.rx++;
Zhu Yib481de92007-09-25 17:54:57 -07001801 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1802 }
1803
1804 if (inta & CSR_INT_BIT_FH_TX) {
Tomas Winklere1623442009-01-27 14:27:56 -08001805 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001806 priv->isr_stats.tx++;
Zhu Yib481de92007-09-25 17:54:57 -07001807
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001808 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07001809 iwl_write_direct32(priv, FH39_TCSR_CREDIT
1810 (FH39_SRVC_CHNL), 0x0);
Zhu Yib481de92007-09-25 17:54:57 -07001811 handled |= CSR_INT_BIT_FH_TX;
1812 }
1813
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001814 if (inta & ~handled) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001815 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001816 priv->isr_stats.unhandled++;
1817 }
Zhu Yib481de92007-09-25 17:54:57 -07001818
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001819 if (inta & ~priv->inta_mask) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001820 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001821 inta & ~priv->inta_mask);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001822 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001823 }
1824
1825 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001826 /* only Re-enable if disabled by irq */
1827 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08001828 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001829
Samuel Ortizd08853a2009-01-23 13:45:17 -08001830#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08001831 if (priv->debug_level & (IWL_DL_ISR)) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001832 inta = iwl_read32(priv, CSR_INT);
1833 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1834 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Tomas Winklere1623442009-01-27 14:27:56 -08001835 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
Zhu Yib481de92007-09-25 17:54:57 -07001836 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
1837 }
1838#endif
1839 spin_unlock_irqrestore(&priv->lock, flags);
1840}
1841
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001842static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01001843 enum ieee80211_band band,
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08001844 u8 is_active, u8 n_probes,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001845 struct iwl3945_scan_channel *scan_ch)
Zhu Yib481de92007-09-25 17:54:57 -07001846{
1847 const struct ieee80211_channel *channels = NULL;
Johannes Berg8318d782008-01-24 19:38:38 +01001848 const struct ieee80211_supported_band *sband;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001849 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07001850 u16 passive_dwell = 0;
1851 u16 active_dwell = 0;
1852 int added, i;
1853
Kolekar, Abhijeetcbba18c2008-12-19 10:37:42 +08001854 sband = iwl_get_hw_mode(priv, band);
Johannes Berg8318d782008-01-24 19:38:38 +01001855 if (!sband)
Zhu Yib481de92007-09-25 17:54:57 -07001856 return 0;
1857
Johannes Berg8318d782008-01-24 19:38:38 +01001858 channels = sband->channels;
Zhu Yib481de92007-09-25 17:54:57 -07001859
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08001860 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
1861 passive_dwell = iwl_get_passive_dwell_time(priv, band);
Zhu Yib481de92007-09-25 17:54:57 -07001862
Abhijeet Kolekar8f4807a2008-09-03 11:26:31 +08001863 if (passive_dwell <= active_dwell)
1864 passive_dwell = active_dwell + 1;
1865
Johannes Berg8318d782008-01-24 19:38:38 +01001866 for (i = 0, added = 0; i < sband->n_channels; i++) {
Johannes Berg182e2e62008-04-04 10:41:56 +02001867 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
1868 continue;
1869
Johannes Berg8318d782008-01-24 19:38:38 +01001870 scan_ch->channel = channels[i].hw_value;
Zhu Yib481de92007-09-25 17:54:57 -07001871
Samuel Ortize6148912009-01-23 13:45:15 -08001872 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07001873 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08001874 IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
Zhu Yib481de92007-09-25 17:54:57 -07001875 scan_ch->channel);
1876 continue;
1877 }
1878
Zhu Yib481de92007-09-25 17:54:57 -07001879 scan_ch->active_dwell = cpu_to_le16(active_dwell);
1880 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08001881 /* If passive , set up for auto-switch
1882 * and use long active_dwell time.
1883 */
1884 if (!is_active || is_channel_passive(ch_info) ||
1885 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
1886 scan_ch->type = 0; /* passive */
1887 if (IWL_UCODE_API(priv->ucode_ver) == 1)
1888 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
1889 } else {
1890 scan_ch->type = 1; /* active */
1891 }
1892
1893 /* Set direct probe bits. These may be used both for active
1894 * scan channels (probes gets sent right away),
1895 * or for passive channels (probes get se sent only after
1896 * hearing clear Rx packet).*/
1897 if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
1898 if (n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08001899 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08001900 } else {
1901 /* uCode v1 does not allow setting direct probe bits on
1902 * passive channel. */
1903 if ((scan_ch->type & 1) && n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08001904 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08001905 }
Zhu Yib481de92007-09-25 17:54:57 -07001906
Ben Cahill9fbab512007-11-29 11:09:47 +08001907 /* Set txpower levels to defaults */
Zhu Yib481de92007-09-25 17:54:57 -07001908 scan_ch->tpc.dsp_atten = 110;
1909 /* scan_pwr_info->tpc.dsp_atten; */
1910
1911 /*scan_pwr_info->tpc.tx_gain; */
Johannes Berg8318d782008-01-24 19:38:38 +01001912 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07001913 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
1914 else {
1915 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
1916 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
Ben Cahill9fbab512007-11-29 11:09:47 +08001917 * power level:
Reinette Chatre8a1b0242008-01-14 17:46:25 -08001918 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
Zhu Yib481de92007-09-25 17:54:57 -07001919 */
1920 }
1921
Tomas Winklere1623442009-01-27 14:27:56 -08001922 IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n",
Zhu Yib481de92007-09-25 17:54:57 -07001923 scan_ch->channel,
1924 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
1925 (scan_ch->type & 1) ?
1926 active_dwell : passive_dwell);
1927
1928 scan_ch++;
1929 added++;
1930 }
1931
Tomas Winklere1623442009-01-27 14:27:56 -08001932 IWL_DEBUG_SCAN(priv, "total channels to scan %d \n", added);
Zhu Yib481de92007-09-25 17:54:57 -07001933 return added;
1934}
1935
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001936static void iwl3945_init_hw_rates(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001937 struct ieee80211_rate *rates)
1938{
1939 int i;
1940
1941 for (i = 0; i < IWL_RATE_COUNT; i++) {
Johannes Berg8318d782008-01-24 19:38:38 +01001942 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
1943 rates[i].hw_value = i; /* Rate scaling will work on indexes */
1944 rates[i].hw_value_short = i;
1945 rates[i].flags = 0;
Samuel Ortizd9829a62008-12-19 10:37:12 +08001946 if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
Zhu Yib481de92007-09-25 17:54:57 -07001947 /*
Johannes Berg8318d782008-01-24 19:38:38 +01001948 * If CCK != 1M then set short preamble rate flag.
Zhu Yib481de92007-09-25 17:54:57 -07001949 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001950 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
Johannes Berg8318d782008-01-24 19:38:38 +01001951 0 : IEEE80211_RATE_SHORT_PREAMBLE;
Zhu Yib481de92007-09-25 17:54:57 -07001952 }
Zhu Yib481de92007-09-25 17:54:57 -07001953 }
1954}
1955
Zhu Yib481de92007-09-25 17:54:57 -07001956/******************************************************************************
1957 *
1958 * uCode download functions
1959 *
1960 ******************************************************************************/
1961
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001962static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001963{
Tomas Winkler98c92212008-01-14 17:46:20 -08001964 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
1965 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
1966 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1967 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
1968 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1969 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001970}
1971
1972/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001973 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07001974 * looking at all data.
1975 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001976static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07001977{
1978 u32 val;
1979 u32 save_len = len;
1980 int rc = 0;
1981 u32 errcnt;
1982
Tomas Winklere1623442009-01-27 14:27:56 -08001983 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001984
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001985 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08001986 IWL39_RTC_INST_LOWER_BOUND);
Zhu Yib481de92007-09-25 17:54:57 -07001987
1988 errcnt = 0;
1989 for (; len > 0; len -= sizeof(u32), image++) {
1990 /* read data comes through single port, auto-incr addr */
1991 /* NOTE: Use the debugless read so we don't flood kernel log
1992 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001993 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07001994 if (val != le32_to_cpu(*image)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001995 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07001996 "offset 0x%x, is 0x%x, s/b 0x%x\n",
1997 save_len - len, val, le32_to_cpu(*image));
1998 rc = -EIO;
1999 errcnt++;
2000 if (errcnt >= 20)
2001 break;
2002 }
2003 }
2004
Zhu Yib481de92007-09-25 17:54:57 -07002005
2006 if (!errcnt)
Tomas Winklere1623442009-01-27 14:27:56 -08002007 IWL_DEBUG_INFO(priv,
2008 "ucode image in INSTRUCTION memory is good\n");
Zhu Yib481de92007-09-25 17:54:57 -07002009
2010 return rc;
2011}
2012
2013
2014/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002015 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002016 * using sample data 100 bytes apart. If these sample points are good,
2017 * it's a pretty good bet that everything between them is good, too.
2018 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002019static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002020{
2021 u32 val;
2022 int rc = 0;
2023 u32 errcnt = 0;
2024 u32 i;
2025
Tomas Winklere1623442009-01-27 14:27:56 -08002026 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002027
Zhu Yib481de92007-09-25 17:54:57 -07002028 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
2029 /* read data comes through single port, auto-incr addr */
2030 /* NOTE: Use the debugless read so we don't flood kernel log
2031 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002032 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002033 i + IWL39_RTC_INST_LOWER_BOUND);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002034 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002035 if (val != le32_to_cpu(*image)) {
2036#if 0 /* Enable this if you want to see details */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002037 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002038 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2039 i, val, *image);
2040#endif
2041 rc = -EIO;
2042 errcnt++;
2043 if (errcnt >= 3)
2044 break;
2045 }
2046 }
2047
Zhu Yib481de92007-09-25 17:54:57 -07002048 return rc;
2049}
2050
2051
2052/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002053 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
Zhu Yib481de92007-09-25 17:54:57 -07002054 * and verify its contents
2055 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002056static int iwl3945_verify_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002057{
2058 __le32 *image;
2059 u32 len;
2060 int rc = 0;
2061
2062 /* Try bootstrap */
2063 image = (__le32 *)priv->ucode_boot.v_addr;
2064 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002065 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002066 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002067 IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002068 return 0;
2069 }
2070
2071 /* Try initialize */
2072 image = (__le32 *)priv->ucode_init.v_addr;
2073 len = priv->ucode_init.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002074 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002075 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002076 IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002077 return 0;
2078 }
2079
2080 /* Try runtime/protocol */
2081 image = (__le32 *)priv->ucode_code.v_addr;
2082 len = priv->ucode_code.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002083 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002084 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002085 IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002086 return 0;
2087 }
2088
Winkler, Tomas15b16872008-12-19 10:37:33 +08002089 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
Zhu Yib481de92007-09-25 17:54:57 -07002090
Ben Cahill9fbab512007-11-29 11:09:47 +08002091 /* Since nothing seems to match, show first several data entries in
2092 * instruction SRAM, so maybe visual inspection will give a clue.
2093 * Selection of bootstrap image (vs. other images) is arbitrary. */
Zhu Yib481de92007-09-25 17:54:57 -07002094 image = (__le32 *)priv->ucode_boot.v_addr;
2095 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002096 rc = iwl3945_verify_inst_full(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002097
2098 return rc;
2099}
2100
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002101static void iwl3945_nic_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002102{
2103 /* Remove all resets to allow NIC to operate */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002104 iwl_write32(priv, CSR_RESET, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002105}
2106
2107/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002108 * iwl3945_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07002109 *
2110 * Copy into buffers for card to fetch via bus-mastering
2111 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002112static int iwl3945_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002113{
Kolekar, Abhijeeta78fe752008-12-19 10:37:21 +08002114 struct iwl_ucode *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002115 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07002116 const struct firmware *ucode_raw;
2117 /* firmware file name contains uCode/driver compatibility version */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002118 const char *name_pre = priv->cfg->fw_name_pre;
2119 const unsigned int api_max = priv->cfg->ucode_api_max;
2120 const unsigned int api_min = priv->cfg->ucode_api_min;
2121 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07002122 u8 *src;
2123 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002124 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07002125
2126 /* Ask kernel firmware_class module to get the boot firmware off disk.
2127 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002128 for (index = api_max; index >= api_min; index--) {
2129 sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
2130 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
2131 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002132 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002133 buf, ret);
2134 if (ret == -ENOENT)
2135 continue;
2136 else
2137 goto error;
2138 } else {
2139 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002140 IWL_ERR(priv, "Loaded firmware %s, "
2141 "which is deprecated. "
2142 " Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002143 buf, api_max);
Tomas Winklere1623442009-01-27 14:27:56 -08002144 IWL_DEBUG_INFO(priv, "Got firmware '%s' file "
2145 "(%zd bytes) from disk\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002146 buf, ucode_raw->size);
2147 break;
2148 }
Zhu Yib481de92007-09-25 17:54:57 -07002149 }
2150
Reinette Chatrea0987a82008-12-02 12:14:06 -08002151 if (ret < 0)
2152 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07002153
2154 /* Make sure that we got at least our header! */
2155 if (ucode_raw->size < sizeof(*ucode)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002156 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002157 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002158 goto err_release;
2159 }
2160
2161 /* Data from ucode file: header followed by uCode images */
2162 ucode = (void *)ucode_raw->data;
2163
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08002164 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08002165 api_ver = IWL_UCODE_API(priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07002166 inst_size = le32_to_cpu(ucode->inst_size);
2167 data_size = le32_to_cpu(ucode->data_size);
2168 init_size = le32_to_cpu(ucode->init_size);
2169 init_data_size = le32_to_cpu(ucode->init_data_size);
2170 boot_size = le32_to_cpu(ucode->boot_size);
2171
Reinette Chatrea0987a82008-12-02 12:14:06 -08002172 /* api_ver should match the api version forming part of the
2173 * firmware filename ... but we don't check for that and only rely
Nick Andrew877d0312009-01-26 11:06:57 +01002174 * on the API version read from firmware header from here on forward */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002175
2176 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002177 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002178 "Driver supports v%u, firmware is v%u.\n",
2179 api_max, api_ver);
2180 priv->ucode_ver = 0;
2181 ret = -EINVAL;
2182 goto err_release;
2183 }
2184 if (api_ver != api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002185 IWL_ERR(priv, "Firmware has old API version. Expected %u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002186 "got %u. New firmware can be obtained "
2187 "from http://www.intellinuxwireless.org.\n",
2188 api_max, api_ver);
2189
Tomas Winkler978785a2008-12-19 10:37:31 +08002190 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
2191 IWL_UCODE_MAJOR(priv->ucode_ver),
2192 IWL_UCODE_MINOR(priv->ucode_ver),
2193 IWL_UCODE_API(priv->ucode_ver),
2194 IWL_UCODE_SERIAL(priv->ucode_ver));
2195
Tomas Winklere1623442009-01-27 14:27:56 -08002196 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002197 priv->ucode_ver);
Tomas Winklere1623442009-01-27 14:27:56 -08002198 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
2199 inst_size);
2200 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
2201 data_size);
2202 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
2203 init_size);
2204 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
2205 init_data_size);
2206 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
2207 boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07002208
Reinette Chatrea0987a82008-12-02 12:14:06 -08002209
Zhu Yib481de92007-09-25 17:54:57 -07002210 /* Verify size of file vs. image size info in file's header */
2211 if (ucode_raw->size < sizeof(*ucode) +
2212 inst_size + data_size + init_size +
2213 init_data_size + boot_size) {
2214
Tomas Winklere1623442009-01-27 14:27:56 -08002215 IWL_DEBUG_INFO(priv, "uCode file size %zd too small\n",
2216 ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002217 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002218 goto err_release;
2219 }
2220
2221 /* Verify that uCode images will fit in card's SRAM */
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002222 if (inst_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002223 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002224 inst_size);
2225 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002226 goto err_release;
2227 }
2228
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002229 if (data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002230 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002231 data_size);
2232 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002233 goto err_release;
2234 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002235 if (init_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002236 IWL_DEBUG_INFO(priv,
2237 "uCode init instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002238 init_size);
2239 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002240 goto err_release;
2241 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002242 if (init_data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002243 IWL_DEBUG_INFO(priv,
2244 "uCode init data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002245 init_data_size);
2246 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002247 goto err_release;
2248 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002249 if (boot_size > IWL39_MAX_BSM_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002250 IWL_DEBUG_INFO(priv,
2251 "uCode boot instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002252 boot_size);
2253 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002254 goto err_release;
2255 }
2256
2257 /* Allocate ucode buffers for card's bus-master loading ... */
2258
2259 /* Runtime instructions and 2 copies of data:
2260 * 1) unmodified from disk
2261 * 2) backup cache for save/restore during power-downs */
2262 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002263 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07002264
2265 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002266 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07002267
2268 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002269 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07002270
2271 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
Tomas Winkler90e759d2007-11-29 11:09:41 +08002272 !priv->ucode_data_backup.v_addr)
Zhu Yib481de92007-09-25 17:54:57 -07002273 goto err_pci_alloc;
2274
Tomas Winkler90e759d2007-11-29 11:09:41 +08002275 /* Initialization instructions and data */
2276 if (init_size && init_data_size) {
2277 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002278 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002279
2280 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002281 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002282
2283 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
2284 goto err_pci_alloc;
2285 }
2286
2287 /* Bootstrap (instructions only, no data) */
2288 if (boot_size) {
2289 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002290 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002291
2292 if (!priv->ucode_boot.v_addr)
2293 goto err_pci_alloc;
2294 }
2295
Zhu Yib481de92007-09-25 17:54:57 -07002296 /* Copy images into buffers for card's bus-master reads ... */
2297
2298 /* Runtime instructions (first block of data in file) */
2299 src = &ucode->data[0];
2300 len = priv->ucode_code.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002301 IWL_DEBUG_INFO(priv,
2302 "Copying (but not loading) uCode instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002303 memcpy(priv->ucode_code.v_addr, src, len);
Tomas Winklere1623442009-01-27 14:27:56 -08002304 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002305 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
2306
2307 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002308 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
Zhu Yib481de92007-09-25 17:54:57 -07002309 src = &ucode->data[inst_size];
2310 len = priv->ucode_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002311 IWL_DEBUG_INFO(priv,
2312 "Copying (but not loading) uCode data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002313 memcpy(priv->ucode_data.v_addr, src, len);
2314 memcpy(priv->ucode_data_backup.v_addr, src, len);
2315
2316 /* Initialization instructions (3rd block) */
2317 if (init_size) {
2318 src = &ucode->data[inst_size + data_size];
2319 len = priv->ucode_init.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002320 IWL_DEBUG_INFO(priv,
2321 "Copying (but not loading) init instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002322 memcpy(priv->ucode_init.v_addr, src, len);
2323 }
2324
2325 /* Initialization data (4th block) */
2326 if (init_data_size) {
2327 src = &ucode->data[inst_size + data_size + init_size];
2328 len = priv->ucode_init_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002329 IWL_DEBUG_INFO(priv,
2330 "Copying (but not loading) init data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002331 memcpy(priv->ucode_init_data.v_addr, src, len);
2332 }
2333
2334 /* Bootstrap instructions (5th block) */
2335 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
2336 len = priv->ucode_boot.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002337 IWL_DEBUG_INFO(priv,
2338 "Copying (but not loading) boot instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002339 memcpy(priv->ucode_boot.v_addr, src, len);
2340
2341 /* We have our copies now, allow OS release its copies */
2342 release_firmware(ucode_raw);
2343 return 0;
2344
2345 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002346 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002347 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002348 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002349
2350 err_release:
2351 release_firmware(ucode_raw);
2352
2353 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08002354 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002355}
2356
2357
2358/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002359 * iwl3945_set_ucode_ptrs - Set uCode address location
Zhu Yib481de92007-09-25 17:54:57 -07002360 *
2361 * Tell initialization uCode where to find runtime uCode.
2362 *
2363 * BSM registers initially contain pointers to initialization uCode.
2364 * We need to replace them to load runtime uCode inst and data,
2365 * and to save runtime data when powering down.
2366 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002367static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002368{
2369 dma_addr_t pinst;
2370 dma_addr_t pdata;
Zhu Yib481de92007-09-25 17:54:57 -07002371
2372 /* bits 31:0 for 3945 */
2373 pinst = priv->ucode_code.p_addr;
2374 pdata = priv->ucode_data_backup.p_addr;
2375
Zhu Yib481de92007-09-25 17:54:57 -07002376 /* Tell bootstrap uCode where to find image to load */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002377 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
2378 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
2379 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002380 priv->ucode_data.len);
2381
Tomas Winklera96a27f2008-10-23 23:48:56 -07002382 /* Inst byte count must be last to set up, bit 31 signals uCode
Zhu Yib481de92007-09-25 17:54:57 -07002383 * that all new ptr/size info is in place */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002384 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002385 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
2386
Tomas Winklere1623442009-01-27 14:27:56 -08002387 IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002388
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07002389 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002390}
2391
2392/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002393 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002394 *
2395 * Called after REPLY_ALIVE notification received from "initialize" uCode.
2396 *
Zhu Yib481de92007-09-25 17:54:57 -07002397 * Tell "initialize" uCode to go ahead and load the runtime uCode.
Ben Cahill9fbab512007-11-29 11:09:47 +08002398 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002399static void iwl3945_init_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002400{
2401 /* Check alive response for "valid" sign from uCode */
2402 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
2403 /* We had an error bringing up the hardware, so take it
2404 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002405 IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002406 goto restart;
2407 }
2408
2409 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
2410 * This is a paranoid check, because we would not have gotten the
2411 * "initialize" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002412 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002413 /* Runtime instruction load was bad;
2414 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002415 IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002416 goto restart;
2417 }
2418
2419 /* Send pointers to protocol/runtime uCode image ... init code will
2420 * load and launch runtime uCode, which will send us another "Alive"
2421 * notification. */
Tomas Winklere1623442009-01-27 14:27:56 -08002422 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002423 if (iwl3945_set_ucode_ptrs(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002424 /* Runtime instruction load won't happen;
2425 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002426 IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002427 goto restart;
2428 }
2429 return;
2430
2431 restart:
2432 queue_work(priv->workqueue, &priv->restart);
2433}
2434
Zhu Yib481de92007-09-25 17:54:57 -07002435/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002436 * iwl3945_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002437 * from protocol/runtime uCode (initialization uCode's
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002438 * Alive gets handled by iwl3945_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07002439 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002440static void iwl3945_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002441{
Zhu Yib481de92007-09-25 17:54:57 -07002442 int thermal_spin = 0;
2443 u32 rfkill;
2444
Tomas Winklere1623442009-01-27 14:27:56 -08002445 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002446
2447 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
2448 /* We had an error bringing up the hardware, so take it
2449 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002450 IWL_DEBUG_INFO(priv, "Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002451 goto restart;
2452 }
2453
2454 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2455 * This is a paranoid check, because we would not have gotten the
2456 * "runtime" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002457 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002458 /* Runtime instruction load was bad;
2459 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002460 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002461 goto restart;
2462 }
2463
Tomas Winklerc587de02009-06-03 11:44:07 -07002464 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002465
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002466 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
Tomas Winklere1623442009-01-27 14:27:56 -08002467 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
Zhu Yib481de92007-09-25 17:54:57 -07002468
2469 if (rfkill & 0x1) {
2470 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winklera96a27f2008-10-23 23:48:56 -07002471 /* if RFKILL is not on, then wait for thermal
Zhu Yib481de92007-09-25 17:54:57 -07002472 * sensor in adapter to kick in */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002473 while (iwl3945_hw_get_temperature(priv) == 0) {
Zhu Yib481de92007-09-25 17:54:57 -07002474 thermal_spin++;
2475 udelay(10);
2476 }
2477
2478 if (thermal_spin)
Tomas Winklere1623442009-01-27 14:27:56 -08002479 IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n",
Zhu Yib481de92007-09-25 17:54:57 -07002480 thermal_spin * 10);
2481 } else
2482 set_bit(STATUS_RF_KILL_HW, &priv->status);
2483
Ben Cahill9fbab512007-11-29 11:09:47 +08002484 /* After the ALIVE response, we can send commands to 3945 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07002485 set_bit(STATUS_ALIVE, &priv->status);
2486
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002487 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002488 return;
2489
Johannes Berg36d68252008-05-15 12:55:26 +02002490 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002491
2492 priv->active_rate = priv->rates_mask;
2493 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
2494
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08002495 iwl_power_update_mode(priv, false);
Zhu Yib481de92007-09-25 17:54:57 -07002496
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002497 if (iwl_is_associated(priv)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002498 struct iwl3945_rxon_cmd *active_rxon =
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002499 (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07002500
Abhijeet Kolekar8a9b9922009-06-12 13:22:52 -07002501 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07002502 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2503 } else {
2504 /* Initialize our rx_config data */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002505 iwl_connection_init_rx_config(priv, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002506 }
2507
Ben Cahill9fbab512007-11-29 11:09:47 +08002508 /* Configure Bluetooth device coexistence support */
Samuel Ortiz17f841c2009-01-23 13:45:20 -08002509 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002510
2511 /* Configure the adapter for unassociated operation */
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002512 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002513
Zhu Yib481de92007-09-25 17:54:57 -07002514 iwl3945_reg_txpower_periodic(priv);
2515
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07002516 iwl3945_led_register(priv);
2517
Tomas Winklere1623442009-01-27 14:27:56 -08002518 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07002519 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a669262008-01-14 17:46:18 -08002520 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07002521
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08002522 /* reassociate for ADHOC mode */
2523 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
2524 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
2525 priv->vif);
2526 if (beacon)
Abhijeet Kolekar9944b932009-04-08 11:26:36 -07002527 iwl_mac_beacon_update(priv->hw, beacon);
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08002528 }
2529
Abhijeet Kolekarf45c2712009-04-08 11:26:38 -07002530 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
Abhijeet Kolekar727882d2009-04-08 11:26:45 -07002531 iwl_set_mode(priv, priv->iw_mode);
Abhijeet Kolekarf45c2712009-04-08 11:26:38 -07002532
Zhu Yib481de92007-09-25 17:54:57 -07002533 return;
2534
2535 restart:
2536 queue_work(priv->workqueue, &priv->restart);
2537}
2538
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002539static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07002540
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002541static void __iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002542{
2543 unsigned long flags;
2544 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
2545 struct ieee80211_conf *conf = NULL;
2546
Tomas Winklere1623442009-01-27 14:27:56 -08002547 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07002548
2549 conf = ieee80211_get_hw_conf(priv->hw);
2550
2551 if (!exit_pending)
2552 set_bit(STATUS_EXIT_PENDING, &priv->status);
2553
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07002554 iwl3945_led_unregister(priv);
Tomas Winklerc587de02009-06-03 11:44:07 -07002555 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002556
2557 /* Unblock any waiting calls */
2558 wake_up_interruptible_all(&priv->wait_command_queue);
2559
Zhu Yib481de92007-09-25 17:54:57 -07002560 /* Wipe out the EXIT_PENDING status bit if we are not actually
2561 * exiting the module */
2562 if (!exit_pending)
2563 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2564
2565 /* stop and reset the on-board processor */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002566 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07002567
2568 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002569 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002570 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002571 spin_unlock_irqrestore(&priv->lock, flags);
2572 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002573
2574 if (priv->mac80211_registered)
2575 ieee80211_stop_queues(priv->hw);
2576
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002577 /* If we have not previously called iwl3945_init() then
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002578 * clear all bits but the RF Kill bits and return */
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002579 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002580 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2581 STATUS_RF_KILL_HW |
Reinette Chatre97888642008-02-06 11:20:38 -08002582 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2583 STATUS_GEO_CONFIGURED |
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08002584 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2585 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002586 goto exit;
2587 }
2588
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002589 /* ...otherwise clear out all the status bits but the RF Kill
Johannes Berga60e77e2009-06-04 18:26:06 +02002590 * bit and continue taking the NIC down. */
Zhu Yib481de92007-09-25 17:54:57 -07002591 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2592 STATUS_RF_KILL_HW |
Reinette Chatre97888642008-02-06 11:20:38 -08002593 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2594 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002595 test_bit(STATUS_FW_ERROR, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08002596 STATUS_FW_ERROR |
2597 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2598 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002599
Abbas, Mohamede9414b62009-01-20 21:33:55 -08002600 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002601 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002602 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07002603 spin_unlock_irqrestore(&priv->lock, flags);
2604
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002605 iwl3945_hw_txq_ctx_stop(priv);
2606 iwl3945_hw_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002607
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07002608 iwl_write_prph(priv, APMG_CLK_DIS_REG,
2609 APMG_CLK_VAL_DMA_CLK_RQT);
Zhu Yib481de92007-09-25 17:54:57 -07002610
2611 udelay(5);
2612
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002613 if (exit_pending)
Abbas, Mohamede9414b62009-01-20 21:33:55 -08002614 priv->cfg->ops->lib->apm_ops.stop(priv);
2615 else
2616 priv->cfg->ops->lib->apm_ops.reset(priv);
2617
Zhu Yib481de92007-09-25 17:54:57 -07002618 exit:
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002619 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07002620
2621 if (priv->ibss_beacon)
2622 dev_kfree_skb(priv->ibss_beacon);
2623 priv->ibss_beacon = NULL;
2624
2625 /* clear out any free frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002626 iwl3945_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002627}
2628
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002629static void iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002630{
2631 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002632 __iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002633 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08002634
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002635 iwl3945_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002636}
2637
2638#define MAX_HW_RESTARTS 5
2639
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002640static int __iwl3945_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002641{
2642 int rc, i;
2643
2644 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002645 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07002646 return -EIO;
2647 }
2648
Reinette Chatree903fbd2008-01-30 22:05:15 -08002649 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002650 IWL_ERR(priv, "ucode not available for device bring up\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08002651 return -EIO;
2652 }
2653
Zhu Yie655b9f2008-01-24 02:19:38 -08002654 /* If platform's RF_KILL switch is NOT set to KILL */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002655 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08002656 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
2657 clear_bit(STATUS_RF_KILL_HW, &priv->status);
2658 else {
2659 set_bit(STATUS_RF_KILL_HW, &priv->status);
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002660 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
2661 return -ENODEV;
Zhu Yib481de92007-09-25 17:54:57 -07002662 }
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002663
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002664 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07002665
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002666 rc = iwl3945_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002667 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002668 IWL_ERR(priv, "Unable to int nic\n");
Zhu Yib481de92007-09-25 17:54:57 -07002669 return rc;
2670 }
2671
2672 /* make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002673 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2674 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07002675 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2676
2677 /* clear (again), then enable host interrupts */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002678 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002679 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002680
2681 /* really make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002682 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2683 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07002684
2685 /* Copy original ucode data image from disk into backup cache.
2686 * This will be used to initialize the on-board processor's
2687 * data SRAM for a clean start when the runtime program first loads. */
2688 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a669262008-01-14 17:46:18 -08002689 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07002690
Zhu Yie655b9f2008-01-24 02:19:38 -08002691 /* We return success when we resume from suspend and rf_kill is on. */
2692 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
2693 return 0;
2694
Zhu Yib481de92007-09-25 17:54:57 -07002695 for (i = 0; i < MAX_HW_RESTARTS; i++) {
2696
Tomas Winklerc587de02009-06-03 11:44:07 -07002697 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002698
2699 /* load bootstrap state machine,
2700 * load bootstrap program into processor's memory,
2701 * prepare to load the "initialize" uCode */
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08002702 priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002703
2704 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002705 IWL_ERR(priv,
2706 "Unable to set up bootstrap uCode: %d\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -07002707 continue;
2708 }
2709
2710 /* start card; "initialize" will load runtime ucode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002711 iwl3945_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002712
Tomas Winklere1623442009-01-27 14:27:56 -08002713 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
Zhu Yib481de92007-09-25 17:54:57 -07002714
2715 return 0;
2716 }
2717
2718 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002719 __iwl3945_down(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08002720 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002721
2722 /* tried to restart and config the device for as long as our
2723 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002724 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07002725 return -EIO;
2726}
2727
2728
2729/*****************************************************************************
2730 *
2731 * Workqueue callbacks
2732 *
2733 *****************************************************************************/
2734
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002735static void iwl3945_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002736{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002737 struct iwl_priv *priv =
2738 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002739
2740 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2741 return;
2742
2743 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002744 iwl3945_init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002745 mutex_unlock(&priv->mutex);
2746}
2747
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002748static void iwl3945_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002749{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002750 struct iwl_priv *priv =
2751 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002752
2753 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2754 return;
2755
2756 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002757 iwl3945_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002758 mutex_unlock(&priv->mutex);
2759}
2760
Helmut Schaa26635162009-01-15 09:38:44 +01002761static void iwl3945_rfkill_poll(struct work_struct *data)
2762{
2763 struct iwl_priv *priv =
2764 container_of(data, struct iwl_priv, rfkill_poll.work);
Helmut Schaa26635162009-01-15 09:38:44 +01002765
2766 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
2767 clear_bit(STATUS_RF_KILL_HW, &priv->status);
2768 else
2769 set_bit(STATUS_RF_KILL_HW, &priv->status);
2770
Johannes Berga60e77e2009-06-04 18:26:06 +02002771 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
2772 test_bit(STATUS_RF_KILL_HW, &priv->status));
Helmut Schaa26635162009-01-15 09:38:44 +01002773
2774 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
2775 round_jiffies_relative(2 * HZ));
2776
2777}
2778
Zhu Yib481de92007-09-25 17:54:57 -07002779#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002780static void iwl3945_bg_request_scan(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002781{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002782 struct iwl_priv *priv =
2783 container_of(data, struct iwl_priv, request_scan);
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08002784 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07002785 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002786 .len = sizeof(struct iwl3945_scan_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07002787 .meta.flags = CMD_SIZE_HUGE,
2788 };
2789 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002790 struct iwl3945_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07002791 struct ieee80211_conf *conf = NULL;
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002792 u8 n_probes = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01002793 enum ieee80211_band band;
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002794 bool is_active = false;
Zhu Yib481de92007-09-25 17:54:57 -07002795
2796 conf = ieee80211_get_hw_conf(priv->hw);
2797
2798 mutex_lock(&priv->mutex);
2799
Reinette Chatrefbc9f972009-05-15 16:13:46 -07002800 cancel_delayed_work(&priv->scan_check);
2801
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002802 if (!iwl_is_ready(priv)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002803 IWL_WARN(priv, "request scan called when driver not ready.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002804 goto done;
2805 }
2806
Tomas Winklera96a27f2008-10-23 23:48:56 -07002807 /* Make sure the scan wasn't canceled before this queued work
Zhu Yib481de92007-09-25 17:54:57 -07002808 * was given the chance to run... */
2809 if (!test_bit(STATUS_SCANNING, &priv->status))
2810 goto done;
2811
2812 /* This should never be called or scheduled if there is currently
2813 * a scan active in the hardware. */
2814 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002815 IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests "
2816 "Ignoring second request.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002817 rc = -EIO;
2818 goto done;
2819 }
2820
2821 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002822 IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n");
Zhu Yib481de92007-09-25 17:54:57 -07002823 goto done;
2824 }
2825
2826 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002827 IWL_DEBUG_HC(priv,
2828 "Scan request while abort pending. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002829 goto done;
2830 }
2831
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002832 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002833 IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n");
Zhu Yib481de92007-09-25 17:54:57 -07002834 goto done;
2835 }
2836
2837 if (!test_bit(STATUS_READY, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002838 IWL_DEBUG_HC(priv,
2839 "Scan request while uninitialized. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002840 goto done;
2841 }
2842
2843 if (!priv->scan_bands) {
Tomas Winklere1623442009-01-27 14:27:56 -08002844 IWL_DEBUG_HC(priv, "Aborting scan due to no requested bands\n");
Zhu Yib481de92007-09-25 17:54:57 -07002845 goto done;
2846 }
2847
Winkler, Tomas805cee52009-01-19 15:30:28 -08002848 if (!priv->scan) {
2849 priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
Zhu Yib481de92007-09-25 17:54:57 -07002850 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
Winkler, Tomas805cee52009-01-19 15:30:28 -08002851 if (!priv->scan) {
Zhu Yib481de92007-09-25 17:54:57 -07002852 rc = -ENOMEM;
2853 goto done;
2854 }
2855 }
Winkler, Tomas805cee52009-01-19 15:30:28 -08002856 scan = priv->scan;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002857 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07002858
2859 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
2860 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
2861
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002862 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002863 u16 interval = 0;
2864 u32 extra;
2865 u32 suspend_time = 100;
2866 u32 scan_suspend_time = 100;
2867 unsigned long flags;
2868
Tomas Winklere1623442009-01-27 14:27:56 -08002869 IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
Zhu Yib481de92007-09-25 17:54:57 -07002870
2871 spin_lock_irqsave(&priv->lock, flags);
2872 interval = priv->beacon_int;
2873 spin_unlock_irqrestore(&priv->lock, flags);
2874
2875 scan->suspend_time = 0;
Mohamed Abbas15e869d2007-10-25 17:15:46 +08002876 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07002877 if (!interval)
2878 interval = suspend_time;
2879 /*
2880 * suspend time format:
2881 * 0-19: beacon interval in usec (time before exec.)
2882 * 20-23: 0
2883 * 24-31: number of beacons (suspend between channels)
2884 */
2885
2886 extra = (suspend_time / interval) << 24;
2887 scan_suspend_time = 0xFF0FFFFF &
2888 (extra | ((suspend_time % interval) * 1024));
2889
2890 scan->suspend_time = cpu_to_le32(scan_suspend_time);
Tomas Winklere1623442009-01-27 14:27:56 -08002891 IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07002892 scan_suspend_time, interval);
2893 }
2894
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002895 if (priv->scan_request->n_ssids) {
2896 int i, p = 0;
2897 IWL_DEBUG_SCAN(priv, "Kicking off active scan\n");
2898 for (i = 0; i < priv->scan_request->n_ssids; i++) {
2899 /* always does wildcard anyway */
2900 if (!priv->scan_request->ssids[i].ssid_len)
2901 continue;
2902 scan->direct_scan[p].id = WLAN_EID_SSID;
2903 scan->direct_scan[p].len =
2904 priv->scan_request->ssids[i].ssid_len;
2905 memcpy(scan->direct_scan[p].ssid,
2906 priv->scan_request->ssids[i].ssid,
2907 priv->scan_request->ssids[i].ssid_len);
2908 n_probes++;
2909 p++;
2910 }
2911 is_active = true;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08002912 } else
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002913 IWL_DEBUG_SCAN(priv, "Kicking off passive scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002914
2915 /* We don't build a direct scan probe request; the uCode will do
2916 * that based on the direct_mask added to each channel entry */
Zhu Yib481de92007-09-25 17:54:57 -07002917 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08002918 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07002919 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
2920
2921 /* flags + rate selection */
2922
Ron Rindjunsky66b50042008-06-25 16:46:31 +08002923 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07002924 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
2925 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
2926 scan->good_CRC_th = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01002927 band = IEEE80211_BAND_2GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08002928 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07002929 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
Johannes Bergb097ad22009-04-20 14:36:57 -07002930 /*
2931 * If active scaning is requested but a certain channel
2932 * is marked passive, we can do active scanning if we
2933 * detect transmissions.
2934 */
2935 scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH : 0;
Johannes Berg8318d782008-01-24 19:38:38 +01002936 band = IEEE80211_BAND_5GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08002937 } else {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002938 IWL_WARN(priv, "Invalid scan band count\n");
Zhu Yib481de92007-09-25 17:54:57 -07002939 goto done;
2940 }
2941
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08002942 scan->tx_cmd.len = cpu_to_le16(
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002943 iwl_fill_probe_req(priv,
2944 (struct ieee80211_mgmt *)scan->data,
2945 priv->scan_request->ie,
2946 priv->scan_request->ie_len,
2947 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08002948
Zhu Yib481de92007-09-25 17:54:57 -07002949 /* select Rx antennas */
2950 scan->flags |= iwl3945_get_antenna_flags(priv);
2951
Wey-Yi Guy279b05d2009-04-20 14:37:00 -07002952 if (iwl_is_monitor_mode(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002953 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
2954
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08002955 scan->channel_count =
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002956 iwl3945_get_channels_for_scan(priv, band, is_active, n_probes,
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08002957 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
Zhu Yib481de92007-09-25 17:54:57 -07002958
Reinette Chatre14b54332008-11-04 12:21:35 -08002959 if (scan->channel_count == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002960 IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
Reinette Chatre14b54332008-11-04 12:21:35 -08002961 goto done;
2962 }
2963
Zhu Yib481de92007-09-25 17:54:57 -07002964 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002965 scan->channel_count * sizeof(struct iwl3945_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07002966 cmd.data = scan;
2967 scan->len = cpu_to_le16(cmd.len);
2968
2969 set_bit(STATUS_SCAN_HW, &priv->status);
Samuel Ortiz518099a2009-01-19 15:30:27 -08002970 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07002971 if (rc)
2972 goto done;
2973
2974 queue_delayed_work(priv->workqueue, &priv->scan_check,
2975 IWL_SCAN_CHECK_WATCHDOG);
2976
2977 mutex_unlock(&priv->mutex);
2978 return;
2979
2980 done:
Mohamed Abbas2420ebc2008-11-04 12:21:34 -08002981 /* can not perform scan make sure we clear scanning
2982 * bits from status so next scan request can be performed.
2983 * if we dont clear scanning status bit here all next scan
2984 * will fail
2985 */
2986 clear_bit(STATUS_SCAN_HW, &priv->status);
2987 clear_bit(STATUS_SCANNING, &priv->status);
2988
Ian Schram01ebd062007-10-25 17:15:22 +08002989 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07002990 queue_work(priv->workqueue, &priv->scan_completed);
2991 mutex_unlock(&priv->mutex);
2992}
2993
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002994static void iwl3945_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002995{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002996 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07002997
2998 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2999 return;
3000
3001 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003002 __iwl3945_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003003 mutex_unlock(&priv->mutex);
3004}
3005
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003006static void iwl3945_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003007{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003008 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07003009
3010 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3011 return;
3012
Johannes Berg19cc1082009-05-08 13:44:36 -07003013 if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
3014 mutex_lock(&priv->mutex);
3015 priv->vif = NULL;
3016 priv->is_open = 0;
3017 mutex_unlock(&priv->mutex);
3018 iwl3945_down(priv);
3019 ieee80211_restart_hw(priv->hw);
3020 } else {
3021 iwl3945_down(priv);
3022 queue_work(priv->workqueue, &priv->up);
3023 }
Zhu Yib481de92007-09-25 17:54:57 -07003024}
3025
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003026static void iwl3945_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003027{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003028 struct iwl_priv *priv =
3029 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07003030
3031 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3032 return;
3033
3034 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003035 iwl3945_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003036 mutex_unlock(&priv->mutex);
3037}
3038
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003039#define IWL_DELAY_NEXT_SCAN (HZ*2)
3040
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07003041void iwl3945_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003042{
Zhu Yib481de92007-09-25 17:54:57 -07003043 int rc = 0;
3044 struct ieee80211_conf *conf = NULL;
3045
Johannes Berg05c914f2008-09-11 00:01:58 +02003046 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003047 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07003048 return;
3049 }
3050
3051
Tomas Winklere1623442009-01-27 14:27:56 -08003052 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003053 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07003054
3055 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3056 return;
3057
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003058 if (!priv->vif || !priv->is_open)
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003059 return;
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003060
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003061 iwl_scan_cancel_timeout(priv, 200);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003062
Zhu Yib481de92007-09-25 17:54:57 -07003063 conf = ieee80211_get_hw_conf(priv->hw);
3064
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003065 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003066 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003067
Tomas Winkler28afaf92008-12-19 10:37:06 +08003068 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003069 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003070 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07003071 sizeof(priv->rxon_timing), &priv->rxon_timing);
3072 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003073 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003074 "Attempting to continue.\n");
3075
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003076 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003077
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003078 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003079
Tomas Winklere1623442009-01-27 14:27:56 -08003080 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003081 priv->assoc_id, priv->beacon_int);
3082
3083 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003084 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003085 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003086 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003087
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003088 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003089 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003090 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003091 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003092 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003093
Johannes Berg05c914f2008-09-11 00:01:58 +02003094 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003095 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003096
3097 }
3098
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003099 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003100
3101 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02003102 case NL80211_IFTYPE_STATION:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003103 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07003104 break;
3105
Johannes Berg05c914f2008-09-11 00:01:58 +02003106 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07003107
Abhijeet Kolekarce546fd2008-11-19 15:32:22 -08003108 priv->assoc_id = 1;
Tomas Winklerc587de02009-06-03 11:44:07 -07003109 iwl_add_station(priv, priv->bssid, 0, CMD_SYNC, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07003110 iwl3945_sync_sta(priv, IWL_STA_ID,
Johannes Berg8318d782008-01-24 19:38:38 +01003111 (priv->band == IEEE80211_BAND_5GHZ) ?
Zhu Yib481de92007-09-25 17:54:57 -07003112 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
3113 CMD_ASYNC);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003114 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
3115 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003116
3117 break;
3118
3119 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08003120 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003121 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003122 break;
3123 }
3124
Abhijeet Kolekar14d2aac2009-02-27 16:21:24 -08003125 iwl_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08003126
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003127 /* we have just associated, don't start scan too early */
3128 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08003129}
3130
Zhu Yib481de92007-09-25 17:54:57 -07003131/*****************************************************************************
3132 *
3133 * mac80211 entry point functions
3134 *
3135 *****************************************************************************/
3136
Zhu Yi5a669262008-01-14 17:46:18 -08003137#define UCODE_READY_TIMEOUT (2 * HZ)
3138
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003139static int iwl3945_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003140{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003141 struct iwl_priv *priv = hw->priv;
Zhu Yi5a669262008-01-14 17:46:18 -08003142 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003143
Tomas Winklere1623442009-01-27 14:27:56 -08003144 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003145
3146 /* we should be verifying the device is ready to be opened */
3147 mutex_lock(&priv->mutex);
3148
Zhu Yi5a669262008-01-14 17:46:18 -08003149 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
3150 * ucode filename and max sizes are card-specific. */
3151
3152 if (!priv->ucode_code.len) {
3153 ret = iwl3945_read_ucode(priv);
3154 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003155 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a669262008-01-14 17:46:18 -08003156 mutex_unlock(&priv->mutex);
3157 goto out_release_irq;
3158 }
3159 }
3160
Zhu Yie655b9f2008-01-24 02:19:38 -08003161 ret = __iwl3945_up(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08003162
Zhu Yib481de92007-09-25 17:54:57 -07003163 mutex_unlock(&priv->mutex);
Zhu Yi5a669262008-01-14 17:46:18 -08003164
Zhu Yie655b9f2008-01-24 02:19:38 -08003165 if (ret)
3166 goto out_release_irq;
3167
Tomas Winklere1623442009-01-27 14:27:56 -08003168 IWL_DEBUG_INFO(priv, "Start UP work.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003169
Zhu Yi5a669262008-01-14 17:46:18 -08003170 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
3171 * mac80211 will not be run successfully. */
3172 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
3173 test_bit(STATUS_READY, &priv->status),
3174 UCODE_READY_TIMEOUT);
3175 if (!ret) {
3176 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003177 IWL_ERR(priv,
3178 "Wait for START_ALIVE timeout after %dms.\n",
3179 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Zhu Yi5a669262008-01-14 17:46:18 -08003180 ret = -ETIMEDOUT;
3181 goto out_release_irq;
3182 }
3183 }
3184
Helmut Schaa26635162009-01-15 09:38:44 +01003185 /* ucode is running and will send rfkill notifications,
3186 * no need to poll the killswitch state anymore */
3187 cancel_delayed_work(&priv->rfkill_poll);
3188
Zhu Yie655b9f2008-01-24 02:19:38 -08003189 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08003190 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003191 return 0;
Zhu Yi5a669262008-01-14 17:46:18 -08003192
3193out_release_irq:
Zhu Yie655b9f2008-01-24 02:19:38 -08003194 priv->is_open = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08003195 IWL_DEBUG_MAC80211(priv, "leave - failed\n");
Zhu Yi5a669262008-01-14 17:46:18 -08003196 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003197}
3198
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003199static void iwl3945_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003200{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003201 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003202
Tomas Winklere1623442009-01-27 14:27:56 -08003203 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003204
Zhu Yie655b9f2008-01-24 02:19:38 -08003205 if (!priv->is_open) {
Tomas Winklere1623442009-01-27 14:27:56 -08003206 IWL_DEBUG_MAC80211(priv, "leave - skip\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003207 return;
3208 }
3209
Zhu Yib481de92007-09-25 17:54:57 -07003210 priv->is_open = 0;
Zhu Yi5a669262008-01-14 17:46:18 -08003211
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003212 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08003213 /* stop mac, cancel any scan request and clear
3214 * RXON_FILTER_ASSOC_MSK BIT
3215 */
Zhu Yi5a669262008-01-14 17:46:18 -08003216 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003217 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003218 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003219 }
3220
Zhu Yi5a669262008-01-14 17:46:18 -08003221 iwl3945_down(priv);
3222
3223 flush_workqueue(priv->workqueue);
Helmut Schaa26635162009-01-15 09:38:44 +01003224
3225 /* start polling the killswitch state again */
3226 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3227 round_jiffies_relative(2 * HZ));
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003228
Tomas Winklere1623442009-01-27 14:27:56 -08003229 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003230}
3231
Johannes Berge039fa42008-05-15 12:55:29 +02003232static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003233{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003234 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003235
Tomas Winklere1623442009-01-27 14:27:56 -08003236 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003237
Tomas Winklere1623442009-01-27 14:27:56 -08003238 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02003239 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07003240
Johannes Berge039fa42008-05-15 12:55:29 +02003241 if (iwl3945_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07003242 dev_kfree_skb_any(skb);
3243
Tomas Winklere1623442009-01-27 14:27:56 -08003244 IWL_DEBUG_MAC80211(priv, "leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08003245 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07003246}
3247
Abhijeet Kolekar60690a62009-04-08 11:26:49 -07003248void iwl3945_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003249{
3250 int rc = 0;
3251
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08003252 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07003253 return;
3254
3255 /* The following should be done only at AP bring up */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003256 if (!(iwl_is_associated(priv))) {
Zhu Yib481de92007-09-25 17:54:57 -07003257
3258 /* RXON - unassoc (to set timing command) */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003259 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003260 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003261
3262 /* RXON Timing */
Tomas Winkler28afaf92008-12-19 10:37:06 +08003263 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003264 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003265 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
3266 sizeof(priv->rxon_timing),
3267 &priv->rxon_timing);
Zhu Yib481de92007-09-25 17:54:57 -07003268 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003269 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003270 "Attempting to continue.\n");
3271
3272 /* FIXME: what should be the assoc_id for AP? */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003273 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003274 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003275 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003276 RXON_FLG_SHORT_PREAMBLE_MSK;
3277 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003278 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003279 ~RXON_FLG_SHORT_PREAMBLE_MSK;
3280
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003281 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003282 if (priv->assoc_capability &
3283 WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003284 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003285 RXON_FLG_SHORT_SLOT_MSK;
3286 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003287 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003288 ~RXON_FLG_SHORT_SLOT_MSK;
3289
Johannes Berg05c914f2008-09-11 00:01:58 +02003290 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003291 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003292 ~RXON_FLG_SHORT_SLOT_MSK;
3293 }
3294 /* restore RXON assoc */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003295 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003296 iwlcore_commit_rxon(priv);
Tomas Winklerc587de02009-06-03 11:44:07 -07003297 iwl_add_station(priv, iwl_bcast_addr, 0, CMD_SYNC, NULL);
Zhu Yi556f8db2007-09-27 11:27:33 +08003298 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003299 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003300
3301 /* FIXME - we need to add code here to detect a totally new
3302 * configuration, reset the AP, unassoc, rxon timing, assoc,
3303 * clear sta table, add BCAST sta... */
3304}
3305
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003306static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01003307 struct ieee80211_vif *vif,
3308 struct ieee80211_sta *sta,
3309 struct ieee80211_key_conf *key)
Zhu Yib481de92007-09-25 17:54:57 -07003310{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003311 struct iwl_priv *priv = hw->priv;
Johannes Bergdc822b52008-12-29 12:55:09 +01003312 const u8 *addr;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003313 int ret = 0;
3314 u8 sta_id = IWL_INVALID_STATION;
3315 u8 static_key;
Zhu Yib481de92007-09-25 17:54:57 -07003316
Tomas Winklere1623442009-01-27 14:27:56 -08003317 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003318
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08003319 if (iwl3945_mod_params.sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08003320 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07003321 return -EOPNOTSUPP;
3322 }
3323
Winkler, Tomas42986792009-01-19 15:30:22 -08003324 addr = sta ? sta->addr : iwl_bcast_addr;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003325 static_key = !iwl_is_associated(priv);
3326
3327 if (!static_key) {
Tomas Winklerc587de02009-06-03 11:44:07 -07003328 sta_id = iwl_find_station(priv, addr);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003329 if (sta_id == IWL_INVALID_STATION) {
Joe Perches12514392009-04-16 16:23:26 -07003330 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003331 addr);
3332 return -EINVAL;
3333 }
Zhu Yib481de92007-09-25 17:54:57 -07003334 }
3335
3336 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003337 iwl_scan_cancel_timeout(priv, 100);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003338 mutex_unlock(&priv->mutex);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003339
Zhu Yib481de92007-09-25 17:54:57 -07003340 switch (cmd) {
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003341 case SET_KEY:
3342 if (static_key)
3343 ret = iwl3945_set_static_key(priv, key);
3344 else
3345 ret = iwl3945_set_dynamic_key(priv, key, sta_id);
3346 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003347 break;
3348 case DISABLE_KEY:
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003349 if (static_key)
3350 ret = iwl3945_remove_static_key(priv);
3351 else
3352 ret = iwl3945_clear_sta_key_info(priv, sta_id);
3353 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003354 break;
3355 default:
Winkler, Tomas42986792009-01-19 15:30:22 -08003356 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003357 }
3358
Tomas Winklere1623442009-01-27 14:27:56 -08003359 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003360
Winkler, Tomas42986792009-01-19 15:30:22 -08003361 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003362}
3363
Zhu Yib481de92007-09-25 17:54:57 -07003364/*****************************************************************************
3365 *
3366 * sysfs attributes
3367 *
3368 *****************************************************************************/
3369
Samuel Ortizd08853a2009-01-23 13:45:17 -08003370#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07003371
3372/*
3373 * The following adds a new attribute to the sysfs representation
3374 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
3375 * used for controlling the debug level.
3376 *
3377 * See the level definitions in iwl for details.
3378 */
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003379static ssize_t show_debug_level(struct device *d,
3380 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07003381{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003382 struct iwl_priv *priv = dev_get_drvdata(d);
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003383
3384 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07003385}
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003386static ssize_t store_debug_level(struct device *d,
3387 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07003388 const char *buf, size_t count)
3389{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003390 struct iwl_priv *priv = dev_get_drvdata(d);
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003391 unsigned long val;
3392 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003393
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003394 ret = strict_strtoul(buf, 0, &val);
3395 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08003396 IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07003397 else
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003398 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07003399
3400 return strnlen(buf, count);
3401}
3402
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003403static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
3404 show_debug_level, store_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07003405
Samuel Ortizd08853a2009-01-23 13:45:17 -08003406#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07003407
Zhu Yib481de92007-09-25 17:54:57 -07003408static ssize_t show_temperature(struct device *d,
3409 struct device_attribute *attr, char *buf)
3410{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003411 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003412
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003413 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003414 return -EAGAIN;
3415
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003416 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07003417}
3418
3419static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
3420
Zhu Yib481de92007-09-25 17:54:57 -07003421static ssize_t show_tx_power(struct device *d,
3422 struct device_attribute *attr, char *buf)
3423{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003424 struct iwl_priv *priv = dev_get_drvdata(d);
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08003425 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07003426}
3427
3428static ssize_t store_tx_power(struct device *d,
3429 struct device_attribute *attr,
3430 const char *buf, size_t count)
3431{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003432 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003433 char *p = (char *)buf;
3434 u32 val;
3435
3436 val = simple_strtoul(p, &p, 10);
3437 if (p == buf)
Tomas Winkler978785a2008-12-19 10:37:31 +08003438 IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07003439 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003440 iwl3945_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07003441
3442 return count;
3443}
3444
3445static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
3446
3447static ssize_t show_flags(struct device *d,
3448 struct device_attribute *attr, char *buf)
3449{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003450 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003451
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003452 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
Zhu Yib481de92007-09-25 17:54:57 -07003453}
3454
3455static ssize_t store_flags(struct device *d,
3456 struct device_attribute *attr,
3457 const char *buf, size_t count)
3458{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003459 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003460 u32 flags = simple_strtoul(buf, NULL, 0);
3461
3462 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003463 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
Zhu Yib481de92007-09-25 17:54:57 -07003464 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003465 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003466 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003467 else {
Tomas Winklere1623442009-01-27 14:27:56 -08003468 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
Zhu Yib481de92007-09-25 17:54:57 -07003469 flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003470 priv->staging_rxon.flags = cpu_to_le32(flags);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003471 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003472 }
3473 }
3474 mutex_unlock(&priv->mutex);
3475
3476 return count;
3477}
3478
3479static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
3480
3481static ssize_t show_filter_flags(struct device *d,
3482 struct device_attribute *attr, char *buf)
3483{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003484 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003485
3486 return sprintf(buf, "0x%04X\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003487 le32_to_cpu(priv->active_rxon.filter_flags));
Zhu Yib481de92007-09-25 17:54:57 -07003488}
3489
3490static ssize_t store_filter_flags(struct device *d,
3491 struct device_attribute *attr,
3492 const char *buf, size_t count)
3493{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003494 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003495 u32 filter_flags = simple_strtoul(buf, NULL, 0);
3496
3497 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003498 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
Zhu Yib481de92007-09-25 17:54:57 -07003499 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003500 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003501 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003502 else {
Tomas Winklere1623442009-01-27 14:27:56 -08003503 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
Zhu Yib481de92007-09-25 17:54:57 -07003504 "0x%04X\n", filter_flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003505 priv->staging_rxon.filter_flags =
Zhu Yib481de92007-09-25 17:54:57 -07003506 cpu_to_le32(filter_flags);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003507 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003508 }
3509 }
3510 mutex_unlock(&priv->mutex);
3511
3512 return count;
3513}
3514
3515static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
3516 store_filter_flags);
3517
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003518#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07003519
3520static ssize_t show_measurement(struct device *d,
3521 struct device_attribute *attr, char *buf)
3522{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003523 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler600c0e12008-12-19 10:37:04 +08003524 struct iwl_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07003525 u32 size = sizeof(measure_report), len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003526 u8 *data = (u8 *)&measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07003527 unsigned long flags;
3528
3529 spin_lock_irqsave(&priv->lock, flags);
3530 if (!(priv->measurement_status & MEASUREMENT_READY)) {
3531 spin_unlock_irqrestore(&priv->lock, flags);
3532 return 0;
3533 }
3534 memcpy(&measure_report, &priv->measure_report, size);
3535 priv->measurement_status = 0;
3536 spin_unlock_irqrestore(&priv->lock, flags);
3537
3538 while (size && (PAGE_SIZE - len)) {
3539 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
3540 PAGE_SIZE - len, 1);
3541 len = strlen(buf);
3542 if (PAGE_SIZE - len)
3543 buf[len++] = '\n';
3544
3545 ofs += 16;
3546 size -= min(size, 16U);
3547 }
3548
3549 return len;
3550}
3551
3552static ssize_t store_measurement(struct device *d,
3553 struct device_attribute *attr,
3554 const char *buf, size_t count)
3555{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003556 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003557 struct ieee80211_measurement_params params = {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003558 .channel = le16_to_cpu(priv->active_rxon.channel),
Zhu Yib481de92007-09-25 17:54:57 -07003559 .start_time = cpu_to_le64(priv->last_tsf),
3560 .duration = cpu_to_le16(1),
3561 };
3562 u8 type = IWL_MEASURE_BASIC;
3563 u8 buffer[32];
3564 u8 channel;
3565
3566 if (count) {
3567 char *p = buffer;
3568 strncpy(buffer, buf, min(sizeof(buffer), count));
3569 channel = simple_strtoul(p, NULL, 0);
3570 if (channel)
3571 params.channel = channel;
3572
3573 p = buffer;
3574 while (*p && *p != ' ')
3575 p++;
3576 if (*p)
3577 type = simple_strtoul(p + 1, NULL, 0);
3578 }
3579
Tomas Winklere1623442009-01-27 14:27:56 -08003580 IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on "
Zhu Yib481de92007-09-25 17:54:57 -07003581 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003582 iwl3945_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07003583
3584 return count;
3585}
3586
3587static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
3588 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003589#endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07003590
Zhu Yib481de92007-09-25 17:54:57 -07003591static ssize_t store_retry_rate(struct device *d,
3592 struct device_attribute *attr,
3593 const char *buf, size_t count)
3594{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003595 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003596
3597 priv->retry_rate = simple_strtoul(buf, NULL, 0);
3598 if (priv->retry_rate <= 0)
3599 priv->retry_rate = 1;
3600
3601 return count;
3602}
3603
3604static ssize_t show_retry_rate(struct device *d,
3605 struct device_attribute *attr, char *buf)
3606{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003607 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003608 return sprintf(buf, "%d", priv->retry_rate);
3609}
3610
3611static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
3612 store_retry_rate);
3613
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08003614
Zhu Yib481de92007-09-25 17:54:57 -07003615static ssize_t store_power_level(struct device *d,
3616 struct device_attribute *attr,
3617 const char *buf, size_t count)
3618{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003619 struct iwl_priv *priv = dev_get_drvdata(d);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08003620 int ret;
3621 unsigned long mode;
Zhu Yib481de92007-09-25 17:54:57 -07003622
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08003623
Zhu Yib481de92007-09-25 17:54:57 -07003624 mutex_lock(&priv->mutex);
3625
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08003626 ret = strict_strtoul(buf, 10, &mode);
3627 if (ret)
3628 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003629
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08003630 ret = iwl_power_set_user_mode(priv, mode);
3631 if (ret) {
3632 IWL_DEBUG_MAC80211(priv, "failed setting power mode.\n");
3633 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003634 }
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08003635 ret = count;
Zhu Yib481de92007-09-25 17:54:57 -07003636
3637 out:
3638 mutex_unlock(&priv->mutex);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08003639 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003640}
3641
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08003642static ssize_t show_power_level(struct device *d,
3643 struct device_attribute *attr, char *buf)
3644{
3645 struct iwl_priv *priv = dev_get_drvdata(d);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08003646 int level = priv->power_data.power_mode;
3647 char *p = buf;
3648
Reinette Chatre872ed192009-07-09 10:33:37 -07003649 p += sprintf(p, "%d\n", level);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08003650 return p - buf + 1;
3651}
3652
3653static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR,
3654 show_power_level, store_power_level);
3655
Zhu Yib481de92007-09-25 17:54:57 -07003656#define MAX_WX_STRING 80
3657
3658/* Values are in microsecond */
3659static const s32 timeout_duration[] = {
3660 350000,
3661 250000,
3662 75000,
3663 37000,
3664 25000,
3665};
3666static const s32 period_duration[] = {
3667 400000,
3668 700000,
3669 1000000,
3670 1000000,
3671 1000000
3672};
3673
Zhu Yib481de92007-09-25 17:54:57 -07003674static ssize_t show_channels(struct device *d,
3675 struct device_attribute *attr, char *buf)
3676{
Johannes Berg8318d782008-01-24 19:38:38 +01003677 /* all this shit doesn't belong into sysfs anyway */
3678 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07003679}
3680
3681static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
3682
3683static ssize_t show_statistics(struct device *d,
3684 struct device_attribute *attr, char *buf)
3685{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003686 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003687 u32 size = sizeof(struct iwl3945_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07003688 u32 len = 0, ofs = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003689 u8 *data = (u8 *)&priv->statistics_39;
Zhu Yib481de92007-09-25 17:54:57 -07003690 int rc = 0;
3691
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003692 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003693 return -EAGAIN;
3694
3695 mutex_lock(&priv->mutex);
Samuel Ortiz17f841c2009-01-23 13:45:20 -08003696 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003697 mutex_unlock(&priv->mutex);
3698
3699 if (rc) {
3700 len = sprintf(buf,
3701 "Error sending statistics request: 0x%08X\n", rc);
3702 return len;
3703 }
3704
3705 while (size && (PAGE_SIZE - len)) {
3706 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
3707 PAGE_SIZE - len, 1);
3708 len = strlen(buf);
3709 if (PAGE_SIZE - len)
3710 buf[len++] = '\n';
3711
3712 ofs += 16;
3713 size -= min(size, 16U);
3714 }
3715
3716 return len;
3717}
3718
3719static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
3720
3721static ssize_t show_antenna(struct device *d,
3722 struct device_attribute *attr, char *buf)
3723{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003724 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003725
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003726 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003727 return -EAGAIN;
3728
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08003729 return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
Zhu Yib481de92007-09-25 17:54:57 -07003730}
3731
3732static ssize_t store_antenna(struct device *d,
3733 struct device_attribute *attr,
3734 const char *buf, size_t count)
3735{
Winkler, Tomas7530f852009-01-27 14:27:53 -08003736 struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003737 int ant;
Zhu Yib481de92007-09-25 17:54:57 -07003738
3739 if (count == 0)
3740 return 0;
3741
3742 if (sscanf(buf, "%1i", &ant) != 1) {
Tomas Winklere1623442009-01-27 14:27:56 -08003743 IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003744 return count;
3745 }
3746
3747 if ((ant >= 0) && (ant <= 2)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003748 IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant);
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08003749 iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
Zhu Yib481de92007-09-25 17:54:57 -07003750 } else
Tomas Winklere1623442009-01-27 14:27:56 -08003751 IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant);
Zhu Yib481de92007-09-25 17:54:57 -07003752
3753
3754 return count;
3755}
3756
3757static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
3758
3759static ssize_t show_status(struct device *d,
3760 struct device_attribute *attr, char *buf)
3761{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003762 struct iwl_priv *priv = dev_get_drvdata(d);
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003763 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003764 return -EAGAIN;
3765 return sprintf(buf, "0x%08x\n", (int)priv->status);
3766}
3767
3768static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
3769
3770static ssize_t dump_error_log(struct device *d,
3771 struct device_attribute *attr,
3772 const char *buf, size_t count)
3773{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003774 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003775 char *p = (char *)buf;
3776
3777 if (p[0] == '1')
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003778 iwl3945_dump_nic_error_log(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003779
3780 return strnlen(buf, count);
3781}
3782
3783static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
3784
3785static ssize_t dump_event_log(struct device *d,
3786 struct device_attribute *attr,
3787 const char *buf, size_t count)
3788{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003789 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003790 char *p = (char *)buf;
3791
3792 if (p[0] == '1')
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003793 iwl3945_dump_nic_event_log(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003794
3795 return strnlen(buf, count);
3796}
3797
3798static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
3799
3800/*****************************************************************************
3801 *
Tomas Winklera96a27f2008-10-23 23:48:56 -07003802 * driver setup and tear down
Zhu Yib481de92007-09-25 17:54:57 -07003803 *
3804 *****************************************************************************/
3805
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003806static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003807{
Reinette Chatred21050c2009-02-13 11:51:18 -08003808 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07003809
3810 init_waitqueue_head(&priv->wait_command_queue);
3811
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003812 INIT_WORK(&priv->up, iwl3945_bg_up);
3813 INIT_WORK(&priv->restart, iwl3945_bg_restart);
3814 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003815 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003816 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
3817 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
Helmut Schaa26635162009-01-15 09:38:44 +01003818 INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08003819 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
3820 INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
3821 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
3822 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
Zhu Yib481de92007-09-25 17:54:57 -07003823
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003824 iwl3945_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003825
3826 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003827 iwl3945_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07003828}
3829
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003830static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003831{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003832 iwl3945_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003833
Joonwoo Parke47eb6a2007-11-29 10:42:49 +09003834 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07003835 cancel_delayed_work(&priv->scan_check);
3836 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07003837 cancel_work_sync(&priv->beacon_update);
3838}
3839
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003840static struct attribute *iwl3945_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07003841 &dev_attr_antenna.attr,
3842 &dev_attr_channels.attr,
3843 &dev_attr_dump_errors.attr,
3844 &dev_attr_dump_events.attr,
3845 &dev_attr_flags.attr,
3846 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003847#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07003848 &dev_attr_measurement.attr,
3849#endif
3850 &dev_attr_power_level.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003851 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003852 &dev_attr_statistics.attr,
3853 &dev_attr_status.attr,
3854 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003855 &dev_attr_tx_power.attr,
Samuel Ortizd08853a2009-01-23 13:45:17 -08003856#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003857 &dev_attr_debug_level.attr,
3858#endif
Zhu Yib481de92007-09-25 17:54:57 -07003859 NULL
3860};
3861
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003862static struct attribute_group iwl3945_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07003863 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003864 .attrs = iwl3945_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07003865};
3866
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003867static struct ieee80211_ops iwl3945_hw_ops = {
3868 .tx = iwl3945_mac_tx,
3869 .start = iwl3945_mac_start,
3870 .stop = iwl3945_mac_stop,
Abhijeet Kolekarcbb6ab92009-04-08 11:26:46 -07003871 .add_interface = iwl_mac_add_interface,
Abhijeet Kolekard8052312009-04-08 11:26:47 -07003872 .remove_interface = iwl_mac_remove_interface,
Abhijeet Kolekar48083682009-04-08 11:26:48 -07003873 .config = iwl_mac_config,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003874 .configure_filter = iwl_configure_filter,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003875 .set_key = iwl3945_mac_set_key,
Abhijeet Kolekaraa89f312009-04-08 11:26:51 -07003876 .get_tx_stats = iwl_mac_get_tx_stats,
Abhijeet Kolekar488829f2009-03-26 10:14:10 -07003877 .conf_tx = iwl_mac_conf_tx,
Abhijeet Kolekarbd564262009-04-08 11:26:52 -07003878 .reset_tsf = iwl_mac_reset_tsf,
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07003879 .bss_info_changed = iwl_bss_info_changed,
Abhijeet Kolekare9dde6f62009-02-18 15:54:27 -08003880 .hw_scan = iwl_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07003881};
3882
Winkler, Tomase52119c2008-12-22 11:31:19 +08003883static int iwl3945_init_drv(struct iwl_priv *priv)
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003884{
3885 int ret;
Samuel Ortize6148912009-01-23 13:45:15 -08003886 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003887
3888 priv->retry_rate = 1;
3889 priv->ibss_beacon = NULL;
3890
3891 spin_lock_init(&priv->lock);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003892 spin_lock_init(&priv->sta_lock);
3893 spin_lock_init(&priv->hcmd_lock);
3894
3895 INIT_LIST_HEAD(&priv->free_frames);
3896
3897 mutex_init(&priv->mutex);
3898
3899 /* Clear the driver's (not device's) station table */
Tomas Winklerc587de02009-06-03 11:44:07 -07003900 iwl_clear_stations_table(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003901
3902 priv->data_retry_limit = -1;
3903 priv->ieee_channels = NULL;
3904 priv->ieee_rates = NULL;
3905 priv->band = IEEE80211_BAND_2GHZ;
3906
3907 priv->iw_mode = NL80211_IFTYPE_STATION;
3908
3909 iwl_reset_qos(priv);
3910
3911 priv->qos_data.qos_active = 0;
3912 priv->qos_data.qos_cap.val = 0;
3913
3914 priv->rates_mask = IWL_RATES_MASK;
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08003915 /* If power management is turned on, default to CAM mode */
3916 priv->power_mode = IWL_POWER_MODE_CAM;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08003917 priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003918
Samuel Ortize6148912009-01-23 13:45:15 -08003919 if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
3920 IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
3921 eeprom->version);
3922 ret = -EINVAL;
3923 goto err;
3924 }
3925 ret = iwl_init_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003926 if (ret) {
3927 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
3928 goto err;
3929 }
3930
Samuel Ortize6148912009-01-23 13:45:15 -08003931 /* Set up txpower settings in driver for all channels */
3932 if (iwl3945_txpower_set_from_eeprom(priv)) {
3933 ret = -EIO;
3934 goto err_free_channel_map;
3935 }
3936
Samuel Ortiz534166d2009-01-23 13:45:16 -08003937 ret = iwlcore_init_geos(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003938 if (ret) {
3939 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
3940 goto err_free_channel_map;
3941 }
Samuel Ortiz534166d2009-01-23 13:45:16 -08003942 iwl3945_init_hw_rates(priv, priv->ieee_rates);
3943
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003944 return 0;
3945
3946err_free_channel_map:
Samuel Ortize6148912009-01-23 13:45:15 -08003947 iwl_free_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003948err:
3949 return ret;
3950}
3951
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08003952static int iwl3945_setup_mac(struct iwl_priv *priv)
3953{
3954 int ret;
3955 struct ieee80211_hw *hw = priv->hw;
3956
3957 hw->rate_control_algorithm = "iwl-3945-rs";
3958 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
3959
3960 /* Tell mac80211 our characteristics */
3961 hw->flags = IEEE80211_HW_SIGNAL_DBM |
Mohamed Abbasb1c60192009-03-17 21:51:47 -07003962 IEEE80211_HW_NOISE_DBM |
3963 IEEE80211_HW_SPECTRUM_MGMT;
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08003964
3965 hw->wiphy->interface_modes =
3966 BIT(NL80211_IFTYPE_STATION) |
3967 BIT(NL80211_IFTYPE_ADHOC);
3968
3969 hw->wiphy->custom_regulatory = true;
3970
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07003971 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX_3945;
3972 /* we create the 802.11 header and a zero-length SSID element */
3973 hw->wiphy->max_scan_ie_len = IWL_MAX_PROBE_REQUEST - 24 - 2;
Johannes Bergd60cc912009-04-09 09:56:02 +02003974
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08003975 /* Default value; 4 EDCA QOS priorities */
3976 hw->queues = 4;
3977
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08003978 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
3979 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
3980 &priv->bands[IEEE80211_BAND_2GHZ];
3981
3982 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
3983 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
3984 &priv->bands[IEEE80211_BAND_5GHZ];
3985
3986 ret = ieee80211_register_hw(priv->hw);
3987 if (ret) {
3988 IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
3989 return ret;
3990 }
3991 priv->mac80211_registered = 1;
3992
3993 return 0;
3994}
3995
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003996static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07003997{
3998 int err = 0;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003999 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07004000 struct ieee80211_hw *hw;
Kolekar, Abhijeetc0f20d92008-12-19 10:37:19 +08004001 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Samuel Ortize6148912009-01-23 13:45:15 -08004002 struct iwl3945_eeprom *eeprom;
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004003 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07004004
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004005 /***********************
4006 * 1. Allocating HW data
4007 * ********************/
4008
Zhu Yib481de92007-09-25 17:54:57 -07004009 /* mac80211 allocates memory for this device instance, including
4010 * space for this driver's private structure */
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004011 hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
Zhu Yib481de92007-09-25 17:54:57 -07004012 if (hw == NULL) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08004013 printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
Zhu Yib481de92007-09-25 17:54:57 -07004014 err = -ENOMEM;
4015 goto out;
4016 }
Zhu Yib481de92007-09-25 17:54:57 -07004017 priv = hw->priv;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004018 SET_IEEE80211_DEV(hw, &pdev->dev);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004019
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004020 if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) ||
4021 (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004022 IWL_ERR(priv,
4023 "invalid queues_num, should be between %d and %d\n",
4024 IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
Samuel Ortiza3139c52008-12-19 10:37:09 +08004025 err = -EINVAL;
Reinette Chatrec8f16132009-02-27 16:21:22 -08004026 goto out_ieee80211_free_hw;
Samuel Ortiza3139c52008-12-19 10:37:09 +08004027 }
4028
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004029 /*
4030 * Disabling hardware scan means that mac80211 will perform scans
4031 * "the hard way", rather than using device's scan.
4032 */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004033 if (iwl3945_mod_params.disable_hw_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08004034 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004035 iwl3945_hw_ops.hw_scan = NULL;
4036 }
4037
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004038
Tomas Winklere1623442009-01-27 14:27:56 -08004039 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004040 priv->cfg = cfg;
4041 priv->pci_dev = pdev;
Mohamed Abbas40cefda2009-05-22 11:01:52 -07004042 priv->inta_mask = CSR_INI_SET_MASK;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004043
Samuel Ortizd08853a2009-01-23 13:45:17 -08004044#ifdef CONFIG_IWLWIFI_DEBUG
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004045 priv->debug_level = iwl3945_mod_params.debug;
4046 atomic_set(&priv->restrict_refcnt, 0);
4047#endif
Zhu Yib481de92007-09-25 17:54:57 -07004048
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004049 /***************************
4050 * 2. Initializing PCI bus
4051 * *************************/
Zhu Yib481de92007-09-25 17:54:57 -07004052 if (pci_enable_device(pdev)) {
4053 err = -ENODEV;
4054 goto out_ieee80211_free_hw;
4055 }
4056
4057 pci_set_master(pdev);
4058
Yang Hongyang284901a2009-04-06 19:01:15 -07004059 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Zhu Yib481de92007-09-25 17:54:57 -07004060 if (!err)
Yang Hongyang284901a2009-04-06 19:01:15 -07004061 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Zhu Yib481de92007-09-25 17:54:57 -07004062 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08004063 IWL_WARN(priv, "No suitable DMA available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004064 goto out_pci_disable_device;
4065 }
4066
4067 pci_set_drvdata(pdev, priv);
4068 err = pci_request_regions(pdev, DRV_NAME);
4069 if (err)
4070 goto out_pci_disable_device;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004071
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004072 /***********************
4073 * 3. Read REV Register
4074 * ********************/
Zhu Yib481de92007-09-25 17:54:57 -07004075 priv->hw_base = pci_iomap(pdev, 0, 0);
4076 if (!priv->hw_base) {
4077 err = -ENODEV;
4078 goto out_pci_release_regions;
4079 }
4080
Tomas Winklere1623442009-01-27 14:27:56 -08004081 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Zhu Yib481de92007-09-25 17:54:57 -07004082 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08004083 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Zhu Yib481de92007-09-25 17:54:57 -07004084
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004085 /* We disable the RETRY_TIMEOUT register (0x41) to keep
4086 * PCI Tx retries from interfering with C3 CPU state */
4087 pci_write_config_byte(pdev, 0x41, 0x00);
Zhu Yib481de92007-09-25 17:54:57 -07004088
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07004089 /* this spin lock will be used in apm_ops.init and EEPROM access
4090 * we should init now
4091 */
4092 spin_lock_init(&priv->reg_lock);
4093
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004094 /* amp init */
4095 err = priv->cfg->ops->lib->apm_ops.init(priv);
Tomas Winkler3ac7f142008-07-21 02:40:14 +03004096 if (err < 0) {
David S. Millerd5df2a12009-03-10 05:04:16 -07004097 IWL_DEBUG_INFO(priv, "Failed to init the card\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004098 goto out_iounmap;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03004099 }
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004100
4101 /***********************
4102 * 4. Read EEPROM
4103 * ********************/
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004104
Zhu Yi5a669262008-01-14 17:46:18 -08004105 /* Read the EEPROM */
Samuel Ortize6148912009-01-23 13:45:15 -08004106 err = iwl_eeprom_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004107 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004108 IWL_ERR(priv, "Unable to init EEPROM\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08004109 goto out_iounmap;
Zhu Yi5a669262008-01-14 17:46:18 -08004110 }
4111 /* MAC Address location in EEPROM same for 3945/4965 */
Samuel Ortize6148912009-01-23 13:45:15 -08004112 eeprom = (struct iwl3945_eeprom *)priv->eeprom;
4113 memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08004114 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
Zhu Yi5a669262008-01-14 17:46:18 -08004115 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
4116
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004117 /***********************
4118 * 5. Setup HW Constants
4119 * ********************/
4120 /* Device-specific setup */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08004121 if (iwl3945_hw_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004122 IWL_ERR(priv, "failed to set hw settings\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08004123 goto out_eeprom_free;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004124 }
4125
4126 /***********************
4127 * 6. Setup priv
4128 * ********************/
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004129
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004130 err = iwl3945_init_drv(priv);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08004131 if (err) {
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004132 IWL_ERR(priv, "initializing driver failed\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08004133 goto out_unset_hw_params;
Reinette Chatre849e0dc2008-01-23 10:15:18 -08004134 }
Reinette Chatre849e0dc2008-01-23 10:15:18 -08004135
Tomas Winkler978785a2008-12-19 10:37:31 +08004136 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
4137 priv->cfg->name);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004138
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004139 /***********************
Abhijeet Kolekar09f9bf72009-04-20 14:37:03 -07004140 * 7. Setup Services
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004141 * ********************/
4142
4143 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08004144 iwl_disable_interrupts(priv);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004145 spin_unlock_irqrestore(&priv->lock, flags);
4146
Helmut Schaa26635162009-01-15 09:38:44 +01004147 pci_enable_msi(priv->pci_dev);
4148
Mohamed Abbasef850d72009-05-22 11:01:50 -07004149 err = request_irq(priv->pci_dev->irq, priv->cfg->ops->lib->isr,
4150 IRQF_SHARED, DRV_NAME, priv);
Helmut Schaa26635162009-01-15 09:38:44 +01004151 if (err) {
4152 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
4153 goto out_disable_msi;
4154 }
4155
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004156 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
4157 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004158 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004159 goto out_release_irq;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004160 }
4161
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004162 iwl_set_rxon_channel(priv,
4163 &priv->bands[IEEE80211_BAND_2GHZ].channels[5]);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004164 iwl3945_setup_deferred_work(priv);
4165 iwl3945_setup_rx_handlers(priv);
4166
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004167 /*********************************
Abhijeet Kolekar09f9bf72009-04-20 14:37:03 -07004168 * 8. Setup and Register mac80211
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004169 * *******************************/
4170
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004171 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004172
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004173 err = iwl3945_setup_mac(priv);
4174 if (err)
4175 goto out_remove_sysfs;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004176
Abhijeet Kolekara75fbe82009-04-20 14:36:58 -07004177 err = iwl_dbgfs_register(priv, DRV_NAME);
4178 if (err)
4179 IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
4180
Helmut Schaa26635162009-01-15 09:38:44 +01004181 /* Start monitoring the killswitch */
4182 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
4183 2 * HZ);
4184
Zhu Yib481de92007-09-25 17:54:57 -07004185 return 0;
4186
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004187 out_remove_sysfs:
Zhu Yib481de92007-09-25 17:54:57 -07004188 destroy_workqueue(priv->workqueue);
4189 priv->workqueue = NULL;
Reinette Chatrec8f16132009-02-27 16:21:22 -08004190 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
4191 out_release_irq:
4192 free_irq(priv->pci_dev->irq, priv);
Helmut Schaa26635162009-01-15 09:38:44 +01004193 out_disable_msi:
4194 pci_disable_msi(priv->pci_dev);
Reinette Chatrec8f16132009-02-27 16:21:22 -08004195 iwlcore_free_geos(priv);
4196 iwl_free_channel_map(priv);
4197 out_unset_hw_params:
4198 iwl3945_unset_hw_params(priv);
4199 out_eeprom_free:
4200 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004201 out_iounmap:
4202 pci_iounmap(pdev, priv->hw_base);
4203 out_pci_release_regions:
4204 pci_release_regions(pdev);
4205 out_pci_disable_device:
Zhu Yib481de92007-09-25 17:54:57 -07004206 pci_set_drvdata(pdev, NULL);
Reinette Chatre623d5632009-03-03 11:37:04 -08004207 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004208 out_ieee80211_free_hw:
4209 ieee80211_free_hw(priv->hw);
4210 out:
4211 return err;
4212}
4213
Reinette Chatrec83dbf62008-03-21 13:53:41 -07004214static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004215{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004216 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004217 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07004218
4219 if (!priv)
4220 return;
4221
Tomas Winklere1623442009-01-27 14:27:56 -08004222 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07004223
Abhijeet Kolekara75fbe82009-04-20 14:36:58 -07004224 iwl_dbgfs_unregister(priv);
4225
Zhu Yib481de92007-09-25 17:54:57 -07004226 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08004227
Kolekar, Abhijeetd552bfb2008-12-19 10:37:41 +08004228 if (priv->mac80211_registered) {
4229 ieee80211_unregister_hw(priv->hw);
4230 priv->mac80211_registered = 0;
4231 } else {
4232 iwl3945_down(priv);
4233 }
Zhu Yib481de92007-09-25 17:54:57 -07004234
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004235 /* make sure we flush any pending irq or
4236 * tasklet for the driver
4237 */
4238 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08004239 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004240 spin_unlock_irqrestore(&priv->lock, flags);
4241
4242 iwl_synchronize_irq(priv);
4243
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004244 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07004245
Reinette Chatre71d449b2009-04-20 14:37:01 -07004246 cancel_delayed_work_sync(&priv->rfkill_poll);
Helmut Schaa26635162009-01-15 09:38:44 +01004247
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004248 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004249
4250 if (priv->rxq.bd)
Reinette Chatredf833b12009-04-21 10:55:48 -07004251 iwl3945_rx_queue_free(priv, &priv->rxq);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004252 iwl3945_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004253
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08004254 iwl3945_unset_hw_params(priv);
Tomas Winklerc587de02009-06-03 11:44:07 -07004255 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004256
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004257 /*netif_stop_queue(dev); */
4258 flush_workqueue(priv->workqueue);
4259
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004260 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07004261 * priv->workqueue... so we can't take down the workqueue
4262 * until now... */
4263 destroy_workqueue(priv->workqueue);
4264 priv->workqueue = NULL;
4265
Helmut Schaa26635162009-01-15 09:38:44 +01004266 free_irq(pdev->irq, priv);
4267 pci_disable_msi(pdev);
4268
Zhu Yib481de92007-09-25 17:54:57 -07004269 pci_iounmap(pdev, priv->hw_base);
4270 pci_release_regions(pdev);
4271 pci_disable_device(pdev);
4272 pci_set_drvdata(pdev, NULL);
4273
Samuel Ortize6148912009-01-23 13:45:15 -08004274 iwl_free_channel_map(priv);
Samuel Ortiz534166d2009-01-23 13:45:16 -08004275 iwlcore_free_geos(priv);
Winkler, Tomas805cee52009-01-19 15:30:28 -08004276 kfree(priv->scan);
Zhu Yib481de92007-09-25 17:54:57 -07004277 if (priv->ibss_beacon)
4278 dev_kfree_skb(priv->ibss_beacon);
4279
4280 ieee80211_free_hw(priv->hw);
4281}
4282
Zhu Yib481de92007-09-25 17:54:57 -07004283
4284/*****************************************************************************
4285 *
4286 * driver and module entry point
4287 *
4288 *****************************************************************************/
4289
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004290static struct pci_driver iwl3945_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07004291 .name = DRV_NAME,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004292 .id_table = iwl3945_hw_card_ids,
4293 .probe = iwl3945_pci_probe,
4294 .remove = __devexit_p(iwl3945_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07004295#ifdef CONFIG_PM
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07004296 .suspend = iwl_pci_suspend,
4297 .resume = iwl_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07004298#endif
4299};
4300
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004301static int __init iwl3945_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07004302{
4303
4304 int ret;
4305 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
4306 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004307
4308 ret = iwl3945_rate_control_register();
4309 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08004310 printk(KERN_ERR DRV_NAME
4311 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004312 return ret;
4313 }
4314
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004315 ret = pci_register_driver(&iwl3945_driver);
Zhu Yib481de92007-09-25 17:54:57 -07004316 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08004317 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004318 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07004319 }
Zhu Yib481de92007-09-25 17:54:57 -07004320
4321 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004322
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004323error_register:
4324 iwl3945_rate_control_unregister();
4325 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004326}
4327
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004328static void __exit iwl3945_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07004329{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004330 pci_unregister_driver(&iwl3945_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004331 iwl3945_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07004332}
4333
Reinette Chatrea0987a82008-12-02 12:14:06 -08004334MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
Zhu Yi25cb6ca2008-09-11 11:45:22 +08004335
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004336module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07004337MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -08004338module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
4339MODULE_PARM_DESC(swcrypto,
4340 "using software crypto (default 1 [software])\n");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004341module_param_named(debug, iwl3945_mod_params.debug, uint, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07004342MODULE_PARM_DESC(debug, "debug output mask");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004343module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07004344MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
4345
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004346module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07004347MODULE_PARM_DESC(queues_num, "number of hw queues.");
4348
Samuel Ortizaf48d042009-01-23 13:45:19 -08004349module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, 0444);
4350MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
4351
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004352module_exit(iwl3945_exit);
4353module_init(iwl3945_init);