blob: 8b07632641417c21d882845eb26221fdfe321f24 [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Reinette Chatre1f447802010-01-15 13:43:41 -08003 * Copyright(c) 2003 - 2010 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
Joe Perchesc96c31e2010-07-26 14:39:58 -070030#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31
Zhu Yib481de92007-09-25 17:54:57 -070032#include <linux/kernel.h>
33#include <linux/module.h>
Zhu Yib481de92007-09-25 17:54:57 -070034#include <linux/init.h>
35#include <linux/pci.h>
John W. Linville1a7123c2010-08-05 14:39:31 -040036#include <linux/pci-aspm.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090037#include <linux/slab.h>
Zhu Yib481de92007-09-25 17:54:57 -070038#include <linux/dma-mapping.h>
39#include <linux/delay.h>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040040#include <linux/sched.h>
Zhu Yib481de92007-09-25 17:54:57 -070041#include <linux/skbuff.h>
42#include <linux/netdevice.h>
43#include <linux/wireless.h>
44#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070045#include <linux/etherdevice.h>
46#include <linux/if_arp.h>
47
48#include <net/ieee80211_radiotap.h>
49#include <net/mac80211.h>
50
51#include <asm/div64.h>
52
Samuel Ortiza3139c52008-12-19 10:37:09 +080053#define DRV_NAME "iwl3945"
54
Winkler, Tomasdbb66542008-12-22 11:31:14 +080055#include "iwl-fh.h"
56#include "iwl-3945-fh.h"
Tomas Winkler600c0e12008-12-19 10:37:04 +080057#include "iwl-commands.h"
Samuel Ortiz17f841c2009-01-23 13:45:20 -080058#include "iwl-sta.h"
Zhu Yib481de92007-09-25 17:54:57 -070059#include "iwl-3945.h"
Kolekar, Abhijeet5747d472008-12-19 10:37:18 +080060#include "iwl-core.h"
Reinette Chatre4a6547c2010-02-18 22:03:02 -080061#include "iwl-helpers.h"
Samuel Ortizd20b3c62008-12-19 10:37:15 +080062#include "iwl-dev.h"
Reinette Chatre81963d62010-01-22 14:22:57 -080063#include "iwl-spectrum.h"
Zhu Yib481de92007-09-25 17:54:57 -070064
Zhu Yib481de92007-09-25 17:54:57 -070065/*
66 * module name, copyright, version, etc.
Zhu Yib481de92007-09-25 17:54:57 -070067 */
68
69#define DRV_DESCRIPTION \
70"Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
71
Samuel Ortizd08853a2009-01-23 13:45:17 -080072#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070073#define VD "d"
74#else
75#define VD
76#endif
77
Reinette Chatre81963d62010-01-22 14:22:57 -080078/*
79 * add "s" to indicate spectrum measurement included.
80 * we add it here to be consistent with previous releases in which
81 * this was configurable.
82 */
83#define DRV_VERSION IWLWIFI_VERSION VD "s"
Reinette Chatre1f447802010-01-15 13:43:41 -080084#define DRV_COPYRIGHT "Copyright(c) 2003-2010 Intel Corporation"
Tomas Winklera7b75202008-12-11 10:33:41 -080085#define DRV_AUTHOR "<ilw@linux.intel.com>"
Zhu Yib481de92007-09-25 17:54:57 -070086
87MODULE_DESCRIPTION(DRV_DESCRIPTION);
88MODULE_VERSION(DRV_VERSION);
Tomas Winklera7b75202008-12-11 10:33:41 -080089MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
Zhu Yib481de92007-09-25 17:54:57 -070090MODULE_LICENSE("GPL");
91
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080092 /* module parameters */
93struct iwl_mod_params iwl3945_mod_params = {
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -080094 .sw_crypto = 1,
Samuel Ortizaf48d042009-01-23 13:45:19 -080095 .restart_fw = 1,
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080096 /* the rest are 0 by default */
97};
98
Zhu Yib481de92007-09-25 17:54:57 -070099/**
Samuel Ortiz7e4bca52009-01-23 13:45:18 -0800100 * iwl3945_get_antenna_flags - Get antenna flags for RXON command
101 * @priv: eeprom and antenna fields are used to determine antenna flags
102 *
103 * priv->eeprom39 is used to determine if antenna AUX/MAIN are reversed
104 * iwl3945_mod_params.antenna specifies the antenna diversity mode:
105 *
106 * IWL_ANTENNA_DIVERSITY - NIC selects best antenna by itself
107 * IWL_ANTENNA_MAIN - Force MAIN antenna
108 * IWL_ANTENNA_AUX - Force AUX antenna
109 */
110__le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv)
111{
112 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
113
114 switch (iwl3945_mod_params.antenna) {
115 case IWL_ANTENNA_DIVERSITY:
116 return 0;
117
118 case IWL_ANTENNA_MAIN:
119 if (eeprom->antenna_switch_type)
120 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
121 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
122
123 case IWL_ANTENNA_AUX:
124 if (eeprom->antenna_switch_type)
125 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
126 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
127 }
128
129 /* bad antenna selector value */
130 IWL_ERR(priv, "Bad antenna selector value (0x%x)\n",
131 iwl3945_mod_params.antenna);
132
133 return 0; /* "diversity" is default if error */
134}
135
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800136static int iwl3945_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700137 struct ieee80211_key_conf *keyconf,
138 u8 sta_id)
139{
140 unsigned long flags;
141 __le16 key_flags = 0;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800142 int ret;
Zhu Yib481de92007-09-25 17:54:57 -0700143
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800144 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
145 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
146
Johannes Berga194e322010-08-27 08:53:46 -0700147 if (sta_id == priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id)
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800148 key_flags |= STA_KEY_MULTICAST_MSK;
149
150 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
151 keyconf->hw_key_idx = keyconf->keyidx;
152 key_flags &= ~STA_KEY_FLG_INVALID;
153
Zhu Yib481de92007-09-25 17:54:57 -0700154 spin_lock_irqsave(&priv->sta_lock, flags);
Johannes Berg97359d12010-08-10 09:46:38 +0200155 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
Tomas Winklerc587de02009-06-03 11:44:07 -0700156 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
157 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700158 keyconf->keylen);
159
Tomas Winklerc587de02009-06-03 11:44:07 -0700160 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700161 keyconf->keylen);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800162
Tomas Winklerc587de02009-06-03 11:44:07 -0700163 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800164 == STA_KEY_FLG_NO_ENC)
Tomas Winklerc587de02009-06-03 11:44:07 -0700165 priv->stations[sta_id].sta.key.key_offset =
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800166 iwl_get_free_ucode_key_index(priv);
167 /* else, we are overriding an existing key => no need to allocated room
168 * in uCode. */
169
Tomas Winklerc587de02009-06-03 11:44:07 -0700170 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800171 "no space for a new key");
172
Tomas Winklerc587de02009-06-03 11:44:07 -0700173 priv->stations[sta_id].sta.key.key_flags = key_flags;
174 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
175 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700176
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800177 IWL_DEBUG_INFO(priv, "hwcrypto: modify ucode station key info\n");
178
Tomas Winklerc587de02009-06-03 11:44:07 -0700179 ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800180
Zhu Yib481de92007-09-25 17:54:57 -0700181 spin_unlock_irqrestore(&priv->sta_lock, flags);
182
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800183 return ret;
184}
185
186static int iwl3945_set_tkip_dynamic_key_info(struct iwl_priv *priv,
187 struct ieee80211_key_conf *keyconf,
188 u8 sta_id)
189{
190 return -EOPNOTSUPP;
191}
192
193static int iwl3945_set_wep_dynamic_key_info(struct iwl_priv *priv,
194 struct ieee80211_key_conf *keyconf,
195 u8 sta_id)
196{
197 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -0700198}
199
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800200static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
Zhu Yib481de92007-09-25 17:54:57 -0700201{
202 unsigned long flags;
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700203 struct iwl_addsta_cmd sta_cmd;
Zhu Yib481de92007-09-25 17:54:57 -0700204
205 spin_lock_irqsave(&priv->sta_lock, flags);
Tomas Winklerc587de02009-06-03 11:44:07 -0700206 memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl_hw_key));
207 memset(&priv->stations[sta_id].sta.key, 0,
Tomas Winkler4c897252008-12-19 10:37:05 +0800208 sizeof(struct iwl4965_keyinfo));
Tomas Winklerc587de02009-06-03 11:44:07 -0700209 priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
210 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
211 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700212 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
Zhu Yib481de92007-09-25 17:54:57 -0700213 spin_unlock_irqrestore(&priv->sta_lock, flags);
214
Tomas Winklere1623442009-01-27 14:27:56 -0800215 IWL_DEBUG_INFO(priv, "hwcrypto: clear ucode station key info\n");
Reinette Chatre9c5ac092010-05-05 02:26:06 -0700216 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
Zhu Yib481de92007-09-25 17:54:57 -0700217}
218
Abhijeet Kolekarfa11d522009-03-11 11:17:54 -0700219static int iwl3945_set_dynamic_key(struct iwl_priv *priv,
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800220 struct ieee80211_key_conf *keyconf, u8 sta_id)
221{
222 int ret = 0;
223
224 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
225
Johannes Berg97359d12010-08-10 09:46:38 +0200226 switch (keyconf->cipher) {
227 case WLAN_CIPHER_SUITE_CCMP:
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800228 ret = iwl3945_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
229 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200230 case WLAN_CIPHER_SUITE_TKIP:
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800231 ret = iwl3945_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
232 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200233 case WLAN_CIPHER_SUITE_WEP40:
234 case WLAN_CIPHER_SUITE_WEP104:
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800235 ret = iwl3945_set_wep_dynamic_key_info(priv, keyconf, sta_id);
236 break;
237 default:
Johannes Berg97359d12010-08-10 09:46:38 +0200238 IWL_ERR(priv, "Unknown alg: %s alg=%x\n", __func__,
239 keyconf->cipher);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800240 ret = -EINVAL;
241 }
242
Johannes Berg97359d12010-08-10 09:46:38 +0200243 IWL_DEBUG_WEP(priv, "Set dynamic key: alg=%x len=%d idx=%d sta=%d ret=%d\n",
244 keyconf->cipher, keyconf->keylen, keyconf->keyidx,
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800245 sta_id, ret);
246
247 return ret;
248}
249
250static int iwl3945_remove_static_key(struct iwl_priv *priv)
251{
252 int ret = -EOPNOTSUPP;
253
254 return ret;
255}
256
257static int iwl3945_set_static_key(struct iwl_priv *priv,
258 struct ieee80211_key_conf *key)
259{
Johannes Berg97359d12010-08-10 09:46:38 +0200260 if (key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
261 key->cipher == WLAN_CIPHER_SUITE_WEP104)
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800262 return -EOPNOTSUPP;
263
Johannes Berg97359d12010-08-10 09:46:38 +0200264 IWL_ERR(priv, "Static key invalid: cipher %x\n", key->cipher);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800265 return -EINVAL;
266}
267
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800268static void iwl3945_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700269{
270 struct list_head *element;
271
Tomas Winklere1623442009-01-27 14:27:56 -0800272 IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
Zhu Yib481de92007-09-25 17:54:57 -0700273 priv->frames_count);
274
275 while (!list_empty(&priv->free_frames)) {
276 element = priv->free_frames.next;
277 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800278 kfree(list_entry(element, struct iwl3945_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700279 priv->frames_count--;
280 }
281
282 if (priv->frames_count) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800283 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
Zhu Yib481de92007-09-25 17:54:57 -0700284 priv->frames_count);
285 priv->frames_count = 0;
286 }
287}
288
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800289static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700290{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800291 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700292 struct list_head *element;
293 if (list_empty(&priv->free_frames)) {
294 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
295 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800296 IWL_ERR(priv, "Could not allocate frame!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700297 return NULL;
298 }
299
300 priv->frames_count++;
301 return frame;
302 }
303
304 element = priv->free_frames.next;
305 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800306 return list_entry(element, struct iwl3945_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700307}
308
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800309static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700310{
311 memset(frame, 0, sizeof(*frame));
312 list_add(&frame->list, &priv->free_frames);
313}
314
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800315unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700316 struct ieee80211_hdr *hdr,
Rami Rosen73ec1cc2008-12-16 09:37:07 +0200317 int left)
Zhu Yib481de92007-09-25 17:54:57 -0700318{
319
Johannes Berg246ed352010-08-23 10:46:32 +0200320 if (!iwl_is_associated(priv, IWL_RXON_CTX_BSS) || !priv->ibss_beacon)
Zhu Yib481de92007-09-25 17:54:57 -0700321 return 0;
322
323 if (priv->ibss_beacon->len > left)
324 return 0;
325
326 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
327
328 return priv->ibss_beacon->len;
329}
330
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800331static int iwl3945_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700332{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800333 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700334 unsigned int frame_size;
335 int rc;
336 u8 rate;
337
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800338 frame = iwl3945_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700339
340 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800341 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
Zhu Yib481de92007-09-25 17:54:57 -0700342 "command.\n");
343 return -ENOMEM;
344 }
345
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800346 rate = iwl_rate_get_lowest_plcp(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700347
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800348 frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -0700349
Samuel Ortiz518099a2009-01-19 15:30:27 -0800350 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700351 &frame->u.cmd[0]);
352
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800353 iwl3945_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700354
355 return rc;
356}
357
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800358static void iwl3945_unset_hw_params(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700359{
Johannes Bergee525d12010-01-21 06:09:28 -0800360 if (priv->_3945.shared_virt)
Stanislaw Gruszkaf36d04a2010-02-10 05:07:45 -0800361 dma_free_coherent(&priv->pci_dev->dev,
362 sizeof(struct iwl3945_shared),
Johannes Bergee525d12010-01-21 06:09:28 -0800363 priv->_3945.shared_virt,
364 priv->_3945.shared_phys);
Zhu Yib481de92007-09-25 17:54:57 -0700365}
366
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800367static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
Johannes Berge039fa42008-05-15 12:55:29 +0200368 struct ieee80211_tx_info *info,
Johannes Bergc2acea82009-07-24 11:13:05 -0700369 struct iwl_device_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -0700370 struct sk_buff *skb_frag,
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800371 int sta_id)
Zhu Yib481de92007-09-25 17:54:57 -0700372{
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700373 struct iwl3945_tx_cmd *tx_cmd = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
Tomas Winklerc587de02009-06-03 11:44:07 -0700374 struct iwl_hw_key *keyinfo = &priv->stations[sta_id].keyinfo;
Zhu Yib481de92007-09-25 17:54:57 -0700375
Johannes Berg97359d12010-08-10 09:46:38 +0200376 tx_cmd->sec_ctl = 0;
377
378 switch (keyinfo->cipher) {
379 case WLAN_CIPHER_SUITE_CCMP:
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700380 tx_cmd->sec_ctl = TX_CMD_SEC_CCM;
381 memcpy(tx_cmd->key, keyinfo->key, keyinfo->keylen);
Tomas Winklere1623442009-01-27 14:27:56 -0800382 IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -0700383 break;
384
Johannes Berg97359d12010-08-10 09:46:38 +0200385 case WLAN_CIPHER_SUITE_TKIP:
Zhu Yib481de92007-09-25 17:54:57 -0700386 break;
387
Johannes Berg97359d12010-08-10 09:46:38 +0200388 case WLAN_CIPHER_SUITE_WEP104:
389 tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128;
390 /* fall through */
391 case WLAN_CIPHER_SUITE_WEP40:
392 tx_cmd->sec_ctl |= TX_CMD_SEC_WEP |
Johannes Berge039fa42008-05-15 12:55:29 +0200393 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
Zhu Yib481de92007-09-25 17:54:57 -0700394
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700395 memcpy(&tx_cmd->key[3], keyinfo->key, keyinfo->keylen);
Zhu Yib481de92007-09-25 17:54:57 -0700396
Tomas Winklere1623442009-01-27 14:27:56 -0800397 IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
Johannes Berge039fa42008-05-15 12:55:29 +0200398 "with key %d\n", info->control.hw_key->hw_key_idx);
Zhu Yib481de92007-09-25 17:54:57 -0700399 break;
400
Zhu Yib481de92007-09-25 17:54:57 -0700401 default:
Johannes Berg97359d12010-08-10 09:46:38 +0200402 IWL_ERR(priv, "Unknown encode cipher %x\n", keyinfo->cipher);
Zhu Yib481de92007-09-25 17:54:57 -0700403 break;
404 }
405}
406
407/*
408 * handle build REPLY_TX command notification.
409 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800410static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
Johannes Bergc2acea82009-07-24 11:13:05 -0700411 struct iwl_device_cmd *cmd,
Johannes Berge039fa42008-05-15 12:55:29 +0200412 struct ieee80211_tx_info *info,
Winkler, Tomase52119c2008-12-22 11:31:19 +0800413 struct ieee80211_hdr *hdr, u8 std_id)
Zhu Yib481de92007-09-25 17:54:57 -0700414{
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700415 struct iwl3945_tx_cmd *tx_cmd = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
416 __le32 tx_flags = tx_cmd->tx_flags;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700417 __le16 fc = hdr->frame_control;
Zhu Yib481de92007-09-25 17:54:57 -0700418
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700419 tx_cmd->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Johannes Berge039fa42008-05-15 12:55:29 +0200420 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
Zhu Yib481de92007-09-25 17:54:57 -0700421 tx_flags |= TX_CMD_FLG_ACK_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700422 if (ieee80211_is_mgmt(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700423 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700424 if (ieee80211_is_probe_resp(fc) &&
Zhu Yib481de92007-09-25 17:54:57 -0700425 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
426 tx_flags |= TX_CMD_FLG_TSF_MSK;
427 } else {
428 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
429 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
430 }
431
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700432 tx_cmd->sta_id = std_id;
Harvey Harrison8b7b1e02008-06-11 14:21:56 -0700433 if (ieee80211_has_morefrags(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700434 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
435
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700436 if (ieee80211_is_data_qos(fc)) {
437 u8 *qc = ieee80211_get_qos_ctl(hdr);
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700438 tx_cmd->tid_tspec = qc[0] & 0xf;
Zhu Yib481de92007-09-25 17:54:57 -0700439 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800440 } else {
Zhu Yib481de92007-09-25 17:54:57 -0700441 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800442 }
Zhu Yib481de92007-09-25 17:54:57 -0700443
Johannes Berg94597ab2010-08-09 10:57:02 -0700444 priv->cfg->ops->utils->tx_cmd_protection(priv, info, fc, &tx_flags);
Zhu Yib481de92007-09-25 17:54:57 -0700445
446 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700447 if (ieee80211_is_mgmt(fc)) {
448 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700449 tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(3);
Zhu Yib481de92007-09-25 17:54:57 -0700450 else
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700451 tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(2);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700452 } else {
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700453 tx_cmd->timeout.pm_frame_timeout = 0;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700454 }
Zhu Yib481de92007-09-25 17:54:57 -0700455
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700456 tx_cmd->driver_txop = 0;
457 tx_cmd->tx_flags = tx_flags;
458 tx_cmd->next_frame_len = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700459}
460
Zhu Yib481de92007-09-25 17:54:57 -0700461/*
462 * start REPLY_TX command process
463 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800464static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -0700465{
466 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berge039fa42008-05-15 12:55:29 +0200467 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700468 struct iwl3945_tx_cmd *tx_cmd;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800469 struct iwl_tx_queue *txq = NULL;
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800470 struct iwl_queue *q = NULL;
Johannes Bergc2acea82009-07-24 11:13:05 -0700471 struct iwl_device_cmd *out_cmd;
472 struct iwl_cmd_meta *out_meta;
Zhu Yib481de92007-09-25 17:54:57 -0700473 dma_addr_t phys_addr;
474 dma_addr_t txcmd_phys;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800475 int txq_id = skb_get_queue_mapping(skb);
Reinette Chatredf833b12009-04-21 10:55:48 -0700476 u16 len, idx, len_org, hdr_len; /* TODO: len_org is not used */
Tomas Winkler54dbb522008-05-15 13:54:06 +0800477 u8 id;
478 u8 unicast;
Zhu Yib481de92007-09-25 17:54:57 -0700479 u8 sta_id;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800480 u8 tid = 0;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700481 __le16 fc;
Zhu Yib481de92007-09-25 17:54:57 -0700482 u8 wait_write_ptr = 0;
483 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -0700484
485 spin_lock_irqsave(&priv->lock, flags);
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800486 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800487 IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
Zhu Yib481de92007-09-25 17:54:57 -0700488 goto drop_unlock;
489 }
490
Johannes Berge039fa42008-05-15 12:55:29 +0200491 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800492 IWL_ERR(priv, "ERROR: No TX rate available.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700493 goto drop_unlock;
494 }
495
496 unicast = !is_multicast_ether_addr(hdr->addr1);
497 id = 0;
498
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700499 fc = hdr->frame_control;
Zhu Yib481de92007-09-25 17:54:57 -0700500
Samuel Ortizd08853a2009-01-23 13:45:17 -0800501#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -0700502 if (ieee80211_is_auth(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800503 IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700504 else if (ieee80211_is_assoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800505 IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700506 else if (ieee80211_is_reassoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800507 IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
Zhu Yib481de92007-09-25 17:54:57 -0700508#endif
509
Zhu Yib481de92007-09-25 17:54:57 -0700510 spin_unlock_irqrestore(&priv->lock, flags);
511
Harvey Harrison7294ec92008-07-15 18:43:59 -0700512 hdr_len = ieee80211_hdrlen(fc);
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800513
Johannes Berg2a87c262010-04-30 11:30:45 -0700514 /* Find index into station table for destination station */
Johannes Berga194e322010-08-27 08:53:46 -0700515 sta_id = iwl_sta_id_or_broadcast(
516 priv, &priv->contexts[IWL_RXON_CTX_BSS],
517 info->control.sta);
Zhu Yib481de92007-09-25 17:54:57 -0700518 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -0800519 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -0700520 hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700521 goto drop;
522 }
523
Tomas Winklere1623442009-01-27 14:27:56 -0800524 IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id);
Zhu Yib481de92007-09-25 17:54:57 -0700525
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700526 if (ieee80211_is_data_qos(fc)) {
Johannes Bergf862a232010-05-03 01:20:52 -0700527 u8 *qc = ieee80211_get_qos_ctl(hdr);
Harvey Harrison7294ec92008-07-15 18:43:59 -0700528 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
Reinette Chatree6a6cf42009-08-13 13:30:50 -0700529 if (unlikely(tid >= MAX_TID_COUNT))
530 goto drop;
Zhu Yib481de92007-09-25 17:54:57 -0700531 }
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800532
533 /* Descriptor for chosen Tx queue */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800534 txq = &priv->txq[txq_id];
Zhu Yib481de92007-09-25 17:54:57 -0700535 q = &txq->q;
536
Zhu Yidc57a302009-12-14 14:12:12 -0800537 if ((iwl_queue_space(q) < q->high_mark))
538 goto drop;
539
Zhu Yib481de92007-09-25 17:54:57 -0700540 spin_lock_irqsave(&priv->lock, flags);
541
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800542 idx = get_cmd_index(q, q->write_ptr, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700543
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800544 /* Set up driver data for this TFD */
Winkler, Tomasdbb66542008-12-22 11:31:14 +0800545 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
Johannes Bergff0d91c2010-05-17 02:37:34 -0700546 txq->txb[q->write_ptr].skb = skb;
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800547
548 /* Init first empty entry in queue's array of Tx/cmd buffers */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800549 out_cmd = txq->cmd[idx];
Johannes Bergc2acea82009-07-24 11:13:05 -0700550 out_meta = &txq->meta[idx];
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700551 tx_cmd = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
Zhu Yib481de92007-09-25 17:54:57 -0700552 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700553 memset(tx_cmd, 0, sizeof(*tx_cmd));
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800554
555 /*
556 * Set up the Tx-command (not MAC!) header.
557 * Store the chosen Tx queue and TFD index within the sequence field;
558 * after Tx, uCode's Tx response will return this value so driver can
559 * locate the frame within the tx queue and do post-tx processing.
560 */
Zhu Yib481de92007-09-25 17:54:57 -0700561 out_cmd->hdr.cmd = REPLY_TX;
562 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800563 INDEX_TO_SEQ(q->write_ptr)));
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800564
565 /* Copy MAC header from skb into command buffer */
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700566 memcpy(tx_cmd->hdr, hdr, hdr_len);
Zhu Yib481de92007-09-25 17:54:57 -0700567
Reinette Chatredf833b12009-04-21 10:55:48 -0700568
569 if (info->control.hw_key)
570 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, sta_id);
571
572 /* TODO need this for burst mode later on */
573 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
574
575 /* set is_hcca to 0; it probably will never be implemented */
576 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
577
578 /* Total # bytes to be transmitted */
579 len = (u16)skb->len;
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700580 tx_cmd->len = cpu_to_le16(len);
Reinette Chatredf833b12009-04-21 10:55:48 -0700581
Wey-Yi Guy20594eb2009-08-07 15:41:39 -0700582 iwl_dbg_log_tx_data_frame(priv, len, hdr);
Wey-Yi Guy22fdf3c2009-08-07 15:41:40 -0700583 iwl_update_stats(priv, true, fc, len);
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700584 tx_cmd->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
585 tx_cmd->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
Reinette Chatredf833b12009-04-21 10:55:48 -0700586
587 if (!ieee80211_has_morefrags(hdr->frame_control)) {
588 txq->need_update = 1;
Reinette Chatredf833b12009-04-21 10:55:48 -0700589 } else {
590 wait_write_ptr = 1;
591 txq->need_update = 0;
592 }
593
Frans Pop91dd6c22010-03-24 14:19:58 -0700594 IWL_DEBUG_TX(priv, "sequence nr = 0X%x\n",
Reinette Chatredf833b12009-04-21 10:55:48 -0700595 le16_to_cpu(out_cmd->hdr.sequence));
Frans Pop91dd6c22010-03-24 14:19:58 -0700596 IWL_DEBUG_TX(priv, "tx_flags = 0X%x\n", le32_to_cpu(tx_cmd->tx_flags));
Abhijeet Kolekar9744c912009-10-09 13:20:31 -0700597 iwl_print_hex_dump(priv, IWL_DL_TX, tx_cmd, sizeof(*tx_cmd));
598 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx_cmd->hdr,
Reinette Chatredf833b12009-04-21 10:55:48 -0700599 ieee80211_hdrlen(fc));
600
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800601 /*
602 * Use the first empty entry in this queue's command buffer array
603 * to contain the Tx command and MAC header concatenated together
604 * (payload data will be in another buffer).
605 * Size of this varies, due to varying MAC header length.
606 * If end is not dword aligned, we'll have 2 extra bytes at the end
607 * of the MAC header (device reads on dword boundaries).
608 * We'll tell device about this padding later.
609 */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800610 len = sizeof(struct iwl3945_tx_cmd) +
Tomas Winkler4c897252008-12-19 10:37:05 +0800611 sizeof(struct iwl_cmd_header) + hdr_len;
Zhu Yib481de92007-09-25 17:54:57 -0700612
613 len_org = len;
614 len = (len + 3) & ~3;
615
616 if (len_org != len)
617 len_org = 1;
618 else
619 len_org = 0;
620
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800621 /* Physical address of this Tx command's header (not MAC header!),
622 * within command buffer array. */
Reinette Chatredf833b12009-04-21 10:55:48 -0700623 txcmd_phys = pci_map_single(priv->pci_dev, &out_cmd->hdr,
624 len, PCI_DMA_TODEVICE);
625 /* we do not map meta data ... so we can safely access address to
626 * provide to unmap command*/
FUJITA Tomonori2e724442010-06-03 14:19:20 +0900627 dma_unmap_addr_set(out_meta, mapping, txcmd_phys);
628 dma_unmap_len_set(out_meta, len, len);
Zhu Yib481de92007-09-25 17:54:57 -0700629
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800630 /* Add buffer containing Tx command and MAC(!) header to TFD's
631 * first entry */
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800632 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
633 txcmd_phys, len, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700634
Zhu Yib481de92007-09-25 17:54:57 -0700635
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800636 /* Set up TFD's 2nd entry to point directly to remainder of skb,
637 * if any (802.11 null frames have no payload). */
Zhu Yib481de92007-09-25 17:54:57 -0700638 len = skb->len - hdr_len;
639 if (len) {
640 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
641 len, PCI_DMA_TODEVICE);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800642 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
643 phys_addr, len,
644 0, U32_PAD(len));
Zhu Yib481de92007-09-25 17:54:57 -0700645 }
646
Zhu Yib481de92007-09-25 17:54:57 -0700647
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800648 /* Tell device the write index *just past* this latest filled TFD */
Tomas Winklerc54b6792008-03-06 17:36:53 -0800649 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
Abhijeet Kolekar7bfedc52010-02-03 13:47:56 -0800650 iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -0700651 spin_unlock_irqrestore(&priv->lock, flags);
652
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800653 if ((iwl_queue_space(q) < q->high_mark)
Zhu Yib481de92007-09-25 17:54:57 -0700654 && priv->mac80211_registered) {
655 if (wait_write_ptr) {
656 spin_lock_irqsave(&priv->lock, flags);
657 txq->need_update = 1;
Samuel Ortiz4f3602c2009-01-19 15:30:25 -0800658 iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -0700659 spin_unlock_irqrestore(&priv->lock, flags);
660 }
661
Johannes Berge4e72fb2009-03-23 17:28:42 +0100662 iwl_stop_queue(priv, skb_get_queue_mapping(skb));
Zhu Yib481de92007-09-25 17:54:57 -0700663 }
664
665 return 0;
666
667drop_unlock:
668 spin_unlock_irqrestore(&priv->lock, flags);
669drop:
670 return -1;
671}
672
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800673static int iwl3945_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700674 struct ieee80211_measurement_params *params,
675 u8 type)
676{
Tomas Winkler600c0e12008-12-19 10:37:04 +0800677 struct iwl_spectrum_cmd spectrum;
Zhu Yi2f301222009-10-09 17:19:45 +0800678 struct iwl_rx_packet *pkt;
Winkler, Tomasc2d79b482008-12-19 10:37:34 +0800679 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700680 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
681 .data = (void *)&spectrum,
Johannes Bergc2acea82009-07-24 11:13:05 -0700682 .flags = CMD_WANT_SKB,
Zhu Yib481de92007-09-25 17:54:57 -0700683 };
684 u32 add_time = le64_to_cpu(params->start_time);
685 int rc;
686 int spectrum_resp_status;
687 int duration = le16_to_cpu(params->duration);
Johannes Berg246ed352010-08-23 10:46:32 +0200688 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Zhu Yib481de92007-09-25 17:54:57 -0700689
Johannes Berg246ed352010-08-23 10:46:32 +0200690 if (iwl_is_associated(priv, IWL_RXON_CTX_BSS))
Wey-Yi Guya0ee74c2010-05-06 08:54:10 -0700691 add_time = iwl_usecs_to_beacons(priv,
Johannes Berge99f168c2010-01-19 10:04:28 -0800692 le64_to_cpu(params->start_time) - priv->_3945.last_tsf,
Johannes Berg246ed352010-08-23 10:46:32 +0200693 le16_to_cpu(ctx->timing.beacon_interval));
Zhu Yib481de92007-09-25 17:54:57 -0700694
695 memset(&spectrum, 0, sizeof(spectrum));
696
697 spectrum.channel_count = cpu_to_le16(1);
698 spectrum.flags =
699 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
700 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
701 cmd.len = sizeof(spectrum);
702 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
703
Johannes Berg246ed352010-08-23 10:46:32 +0200704 if (iwl_is_associated(priv, IWL_RXON_CTX_BSS))
Zhu Yib481de92007-09-25 17:54:57 -0700705 spectrum.start_time =
Wey-Yi Guya0ee74c2010-05-06 08:54:10 -0700706 iwl_add_beacon_time(priv,
707 priv->_3945.last_beacon_time, add_time,
Johannes Berg246ed352010-08-23 10:46:32 +0200708 le16_to_cpu(ctx->timing.beacon_interval));
Zhu Yib481de92007-09-25 17:54:57 -0700709 else
710 spectrum.start_time = 0;
711
712 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
713 spectrum.channels[0].channel = params->channel;
714 spectrum.channels[0].type = type;
Johannes Berg246ed352010-08-23 10:46:32 +0200715 if (ctx->active.flags & RXON_FLG_BAND_24G_MSK)
Zhu Yib481de92007-09-25 17:54:57 -0700716 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
717 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
718
Samuel Ortiz518099a2009-01-19 15:30:27 -0800719 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700720 if (rc)
721 return rc;
722
Zhu Yi2f301222009-10-09 17:19:45 +0800723 pkt = (struct iwl_rx_packet *)cmd.reply_page;
724 if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800725 IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -0700726 rc = -EIO;
727 }
728
Zhu Yi2f301222009-10-09 17:19:45 +0800729 spectrum_resp_status = le16_to_cpu(pkt->u.spectrum.status);
Zhu Yib481de92007-09-25 17:54:57 -0700730 switch (spectrum_resp_status) {
731 case 0: /* Command will be handled */
Zhu Yi2f301222009-10-09 17:19:45 +0800732 if (pkt->u.spectrum.id != 0xff) {
Tomas Winklere1623442009-01-27 14:27:56 -0800733 IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n",
Zhu Yi2f301222009-10-09 17:19:45 +0800734 pkt->u.spectrum.id);
Zhu Yib481de92007-09-25 17:54:57 -0700735 priv->measurement_status &= ~MEASUREMENT_READY;
736 }
737 priv->measurement_status |= MEASUREMENT_ACTIVE;
738 rc = 0;
739 break;
740
741 case 1: /* Command will not be handled */
742 rc = -EAGAIN;
743 break;
744 }
745
Zhu Yi64a76b52009-12-10 14:37:21 -0800746 iwl_free_pages(priv, cmd.reply_page);
Zhu Yib481de92007-09-25 17:54:57 -0700747
748 return rc;
749}
Zhu Yib481de92007-09-25 17:54:57 -0700750
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800751static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +0800752 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700753{
Zhu Yi2f301222009-10-09 17:19:45 +0800754 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800755 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -0700756 struct delayed_work *pwork;
757
758 palive = &pkt->u.alive_frame;
759
Tomas Winklere1623442009-01-27 14:27:56 -0800760 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
Zhu Yib481de92007-09-25 17:54:57 -0700761 "0x%01X 0x%01X\n",
762 palive->is_valid, palive->ver_type,
763 palive->ver_subtype);
764
765 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
Tomas Winklere1623442009-01-27 14:27:56 -0800766 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800767 memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
768 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700769 pwork = &priv->init_alive_start;
770 } else {
Tomas Winklere1623442009-01-27 14:27:56 -0800771 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700772 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800773 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700774 pwork = &priv->alive_start;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800775 iwl3945_disable_events(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700776 }
777
778 /* We delay the ALIVE response by 5ms to
779 * give the HW RF Kill time to activate... */
780 if (palive->is_valid == UCODE_VALID_OK)
781 queue_delayed_work(priv->workqueue, pwork,
782 msecs_to_jiffies(5));
783 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800784 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700785}
786
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800787static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +0800788 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700789{
Helmut Schaac7e035a2009-01-19 13:02:15 +0100790#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yi2f301222009-10-09 17:19:45 +0800791 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Helmut Schaac7e035a2009-01-19 13:02:15 +0100792#endif
Zhu Yib481de92007-09-25 17:54:57 -0700793
Tomas Winklere1623442009-01-27 14:27:56 -0800794 IWL_DEBUG_RX(priv, "Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
Zhu Yib481de92007-09-25 17:54:57 -0700795}
796
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800797static void iwl3945_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -0700798{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800799 struct iwl_priv *priv =
800 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -0700801 struct sk_buff *beacon;
802
803 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +0200804 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -0700805
806 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800807 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -0700808 return;
809 }
810
811 mutex_lock(&priv->mutex);
812 /* new beacon skb is allocated every time; dispose previous.*/
813 if (priv->ibss_beacon)
814 dev_kfree_skb(priv->ibss_beacon);
815
816 priv->ibss_beacon = beacon;
817 mutex_unlock(&priv->mutex);
818
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800819 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700820}
821
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800822static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +0800823 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700824{
Zhu Yi2f301222009-10-09 17:19:45 +0800825 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800826 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
Johannes Berga85d7cc2010-07-31 08:34:10 -0700827#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -0700828 u8 rate = beacon->beacon_notify_hdr.rate;
829
Tomas Winklere1623442009-01-27 14:27:56 -0800830 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
Zhu Yib481de92007-09-25 17:54:57 -0700831 "tsf %d %d rate %d\n",
832 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
833 beacon->beacon_notify_hdr.failure_frame,
834 le32_to_cpu(beacon->ibss_mgr_status),
835 le32_to_cpu(beacon->high_tsf),
836 le32_to_cpu(beacon->low_tsf), rate);
837#endif
838
Johannes Berga85d7cc2010-07-31 08:34:10 -0700839 priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
840
Johannes Berg05c914f2008-09-11 00:01:58 +0200841 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -0700842 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
843 queue_work(priv->workqueue, &priv->beacon_update);
844}
845
Zhu Yib481de92007-09-25 17:54:57 -0700846/* Handle notification from uCode that card's power state is changing
847 * due to software, hardware, or critical temperature RFKILL */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800848static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +0800849 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700850{
Zhu Yi2f301222009-10-09 17:19:45 +0800851 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Zhu Yib481de92007-09-25 17:54:57 -0700852 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
853 unsigned long status = priv->status;
854
Reinette Chatre4c423a22009-07-17 09:30:26 -0700855 IWL_WARN(priv, "Card state received: HW:%s SW:%s\n",
Zhu Yib481de92007-09-25 17:54:57 -0700856 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
857 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
858
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +0800859 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -0700860 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
861
862 if (flags & HW_CARD_DISABLED)
863 set_bit(STATUS_RF_KILL_HW, &priv->status);
864 else
865 clear_bit(STATUS_RF_KILL_HW, &priv->status);
866
867
Winkler, Tomasaf0053d2009-01-19 15:30:23 -0800868 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700869
870 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
Johannes Berga60e77e2009-06-04 18:26:06 +0200871 test_bit(STATUS_RF_KILL_HW, &priv->status)))
872 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
873 test_bit(STATUS_RF_KILL_HW, &priv->status));
Zhu Yib481de92007-09-25 17:54:57 -0700874 else
875 wake_up_interruptible(&priv->wait_command_queue);
876}
877
878/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800879 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -0700880 *
881 * Setup the RX handlers for each of the reply types sent from the uCode
882 * to the host.
883 *
884 * This function chains into the hardware specific files for them to setup
885 * any hardware specific handlers as well.
886 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800887static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700888{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800889 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
890 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -0800891 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800892 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Reinette Chatre81963d62010-01-22 14:22:57 -0800893 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
894 iwl_rx_spectrum_measure_notif;
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -0800895 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700896 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -0800897 iwl_rx_pm_debug_statistics_notif;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800898 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700899
Ben Cahill9fbab512007-11-29 11:09:47 +0800900 /*
901 * The same handler is used for both the REPLY to a discrete
902 * statistics request from the host as well as for the periodic
903 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -0700904 */
Abhijeet Kolekar17f36fc2010-04-16 10:03:54 -0700905 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_reply_statistics;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800906 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -0700907
Abhijeet Kolekarcade0eb2009-02-18 15:54:26 -0800908 iwl_setup_rx_scan_handlers(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800909 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700910
Ben Cahill9fbab512007-11-29 11:09:47 +0800911 /* Set up hardware specific Rx handlers */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800912 iwl3945_hw_rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700913}
914
Zhu Yib481de92007-09-25 17:54:57 -0700915/************************** RX-FUNCTIONS ****************************/
916/*
917 * Rx theory of operation
918 *
919 * The host allocates 32 DMA target addresses and passes the host address
920 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
921 * 0 to 31
922 *
923 * Rx Queue Indexes
924 * The host/firmware share two index registers for managing the Rx buffers.
925 *
926 * The READ index maps to the first position that the firmware may be writing
927 * to -- the driver can read up to (but not including) this position and get
928 * good data.
929 * The READ index is managed by the firmware once the card is enabled.
930 *
931 * The WRITE index maps to the last position the driver has read from -- the
932 * position preceding WRITE is the last slot the firmware can place a packet.
933 *
934 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
935 * WRITE = READ.
936 *
Ben Cahill9fbab512007-11-29 11:09:47 +0800937 * During initialization, the host sets up the READ queue position to the first
Zhu Yib481de92007-09-25 17:54:57 -0700938 * INDEX position, and WRITE to the last (READ - 1 wrapped)
939 *
Ben Cahill9fbab512007-11-29 11:09:47 +0800940 * When the firmware places a packet in a buffer, it will advance the READ index
Zhu Yib481de92007-09-25 17:54:57 -0700941 * and fire the RX interrupt. The driver can then query the READ index and
942 * process as many packets as possible, moving the WRITE index forward as it
943 * resets the Rx queue buffers with new memory.
944 *
945 * The management in the driver is as follows:
946 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
947 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Ian Schram01ebd062007-10-25 17:15:22 +0800948 * to replenish the iwl->rxq->rx_free.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800949 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
Zhu Yib481de92007-09-25 17:54:57 -0700950 * iwl->rxq is replenished and the READ INDEX is updated (updating the
951 * 'processed' and 'read' driver indexes as well)
952 * + A received packet is processed and handed to the kernel network stack,
953 * detached from the iwl->rxq. The driver 'processed' index is updated.
954 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
955 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
956 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
957 * were enough free buffers and RX_STALLED is set it is cleared.
958 *
959 *
960 * Driver sequence:
961 *
Ben Cahill9fbab512007-11-29 11:09:47 +0800962 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800963 * iwl3945_rx_queue_restock
Ben Cahill9fbab512007-11-29 11:09:47 +0800964 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
Zhu Yib481de92007-09-25 17:54:57 -0700965 * queue, updates firmware pointers, and updates
966 * the WRITE index. If insufficient rx_free buffers
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800967 * are available, schedules iwl3945_rx_replenish
Zhu Yib481de92007-09-25 17:54:57 -0700968 *
969 * -- enable interrupts --
Abhijeet Kolekar6100b582008-12-19 10:37:24 +0800970 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
Zhu Yib481de92007-09-25 17:54:57 -0700971 * READ INDEX, detaching the SKB from the pool.
972 * Moves the packet buffer from queue to rx_used.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800973 * Calls iwl3945_rx_queue_restock to refill any empty
Zhu Yib481de92007-09-25 17:54:57 -0700974 * slots.
975 * ...
976 *
977 */
978
979/**
Ben Cahill9fbab512007-11-29 11:09:47 +0800980 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
Zhu Yib481de92007-09-25 17:54:57 -0700981 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800982static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700983 dma_addr_t dma_addr)
984{
985 return cpu_to_le32((u32)dma_addr);
986}
987
988/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800989 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
Zhu Yib481de92007-09-25 17:54:57 -0700990 *
Ben Cahill9fbab512007-11-29 11:09:47 +0800991 * If there are slots in the RX queue that need to be restocked,
Zhu Yib481de92007-09-25 17:54:57 -0700992 * and we have free pre-allocated buffers, fill the ranks as much
Ben Cahill9fbab512007-11-29 11:09:47 +0800993 * as we can, pulling from rx_free.
Zhu Yib481de92007-09-25 17:54:57 -0700994 *
995 * This moves the 'write' index forward to catch up with 'processed', and
996 * also updates the memory address in the firmware to reference the new
997 * target buffer.
998 */
Abhijeet Kolekar7bfedc52010-02-03 13:47:56 -0800999static void iwl3945_rx_queue_restock(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001000{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001001 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001002 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001003 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001004 unsigned long flags;
Abhijeet Kolekar7bfedc52010-02-03 13:47:56 -08001005 int write;
Zhu Yib481de92007-09-25 17:54:57 -07001006
1007 spin_lock_irqsave(&rxq->lock, flags);
1008 write = rxq->write & ~0x7;
Winkler, Tomas37d68312009-01-08 10:19:54 -08001009 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001010 /* Get next free Rx buffer, remove from free list */
Zhu Yib481de92007-09-25 17:54:57 -07001011 element = rxq->rx_free.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001012 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07001013 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001014
1015 /* Point to Rx buffer via next RBD in circular buffer */
Zhu Yi2f301222009-10-09 17:19:45 +08001016 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->page_dma);
Zhu Yib481de92007-09-25 17:54:57 -07001017 rxq->queue[rxq->write] = rxb;
1018 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
1019 rxq->free_count--;
1020 }
1021 spin_unlock_irqrestore(&rxq->lock, flags);
1022 /* If the pre-allocated buffer pool is dropping low, schedule to
1023 * refill it */
1024 if (rxq->free_count <= RX_LOW_WATERMARK)
1025 queue_work(priv->workqueue, &priv->rx_replenish);
1026
1027
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001028 /* If we've added more space for the firmware to place data, tell it.
1029 * Increment device's write pointer in multiples of 8. */
Abhijeet Kolekard14d44402009-06-03 11:44:08 -07001030 if ((rxq->write_actual != (rxq->write & ~0x7))
Zhu Yib481de92007-09-25 17:54:57 -07001031 || (abs(rxq->write - rxq->read) > 7)) {
1032 spin_lock_irqsave(&rxq->lock, flags);
1033 rxq->need_update = 1;
1034 spin_unlock_irqrestore(&rxq->lock, flags);
Abhijeet Kolekar7bfedc52010-02-03 13:47:56 -08001035 iwl_rx_queue_update_write_ptr(priv, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07001036 }
Zhu Yib481de92007-09-25 17:54:57 -07001037}
1038
1039/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001040 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
Zhu Yib481de92007-09-25 17:54:57 -07001041 *
1042 * When moving to rx_free an SKB is allocated for the slot.
1043 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001044 * Also restock the Rx queue via iwl3945_rx_queue_restock.
Ian Schram01ebd062007-10-25 17:15:22 +08001045 * This is called as a scheduled work item (except for during initialization)
Zhu Yib481de92007-09-25 17:54:57 -07001046 */
Abhijeet Kolekard14d44402009-06-03 11:44:08 -07001047static void iwl3945_rx_allocate(struct iwl_priv *priv, gfp_t priority)
Zhu Yib481de92007-09-25 17:54:57 -07001048{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001049 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001050 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001051 struct iwl_rx_mem_buffer *rxb;
Zhu Yi2f301222009-10-09 17:19:45 +08001052 struct page *page;
Zhu Yib481de92007-09-25 17:54:57 -07001053 unsigned long flags;
Zhu Yi29b1b262009-10-23 13:42:25 -07001054 gfp_t gfp_mask = priority;
Abhijeet Kolekar72240492009-04-30 13:56:26 -07001055
1056 while (1) {
1057 spin_lock_irqsave(&rxq->lock, flags);
1058
1059 if (list_empty(&rxq->rx_used)) {
1060 spin_unlock_irqrestore(&rxq->lock, flags);
1061 return;
1062 }
Abhijeet Kolekar72240492009-04-30 13:56:26 -07001063 spin_unlock_irqrestore(&rxq->lock, flags);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001064
Reinette Chatref82a9242009-09-17 10:43:56 -07001065 if (rxq->free_count > RX_LOW_WATERMARK)
Zhu Yi29b1b262009-10-23 13:42:25 -07001066 gfp_mask |= __GFP_NOWARN;
Zhu Yi2f301222009-10-09 17:19:45 +08001067
1068 if (priv->hw_params.rx_page_order > 0)
Zhu Yi29b1b262009-10-23 13:42:25 -07001069 gfp_mask |= __GFP_COMP;
Zhu Yi2f301222009-10-09 17:19:45 +08001070
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001071 /* Alloc a new receive buffer */
Zhu Yi29b1b262009-10-23 13:42:25 -07001072 page = alloc_pages(gfp_mask, priv->hw_params.rx_page_order);
Zhu Yi2f301222009-10-09 17:19:45 +08001073 if (!page) {
Zhu Yib481de92007-09-25 17:54:57 -07001074 if (net_ratelimit())
Reinette Chatref82a9242009-09-17 10:43:56 -07001075 IWL_DEBUG_INFO(priv, "Failed to allocate SKB buffer.\n");
1076 if ((rxq->free_count <= RX_LOW_WATERMARK) &&
1077 net_ratelimit())
1078 IWL_CRIT(priv, "Failed to allocate SKB buffer with %s. Only %u free buffers remaining.\n",
1079 priority == GFP_ATOMIC ? "GFP_ATOMIC" : "GFP_KERNEL",
1080 rxq->free_count);
Zhu Yib481de92007-09-25 17:54:57 -07001081 /* We don't reschedule replenish work here -- we will
1082 * call the restock method and if it still needs
1083 * more buffers it will schedule replenish */
1084 break;
1085 }
Zhu Yi12342c42007-12-20 11:27:32 +08001086
Reinette Chatrede0bd502009-09-11 10:38:12 -07001087 spin_lock_irqsave(&rxq->lock, flags);
1088 if (list_empty(&rxq->rx_used)) {
1089 spin_unlock_irqrestore(&rxq->lock, flags);
Zhu Yi2f301222009-10-09 17:19:45 +08001090 __free_pages(page, priv->hw_params.rx_page_order);
Reinette Chatrede0bd502009-09-11 10:38:12 -07001091 return;
1092 }
1093 element = rxq->rx_used.next;
1094 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
1095 list_del(element);
1096 spin_unlock_irqrestore(&rxq->lock, flags);
1097
Zhu Yi2f301222009-10-09 17:19:45 +08001098 rxb->page = page;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001099 /* Get physical address of RB/SKB */
Zhu Yi2f301222009-10-09 17:19:45 +08001100 rxb->page_dma = pci_map_page(priv->pci_dev, page, 0,
1101 PAGE_SIZE << priv->hw_params.rx_page_order,
1102 PCI_DMA_FROMDEVICE);
Abhijeet Kolekar72240492009-04-30 13:56:26 -07001103
1104 spin_lock_irqsave(&rxq->lock, flags);
Zhu Yi2f301222009-10-09 17:19:45 +08001105
Zhu Yib481de92007-09-25 17:54:57 -07001106 list_add_tail(&rxb->list, &rxq->rx_free);
1107 rxq->free_count++;
Zhu Yi2f301222009-10-09 17:19:45 +08001108 priv->alloc_rxb_page++;
1109
Abhijeet Kolekar72240492009-04-30 13:56:26 -07001110 spin_unlock_irqrestore(&rxq->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -07001111 }
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001112}
1113
Reinette Chatredf833b12009-04-21 10:55:48 -07001114void iwl3945_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
1115{
1116 unsigned long flags;
1117 int i;
1118 spin_lock_irqsave(&rxq->lock, flags);
1119 INIT_LIST_HEAD(&rxq->rx_free);
1120 INIT_LIST_HEAD(&rxq->rx_used);
1121 /* Fill the rx_used queue with _all_ of the Rx buffers */
1122 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
1123 /* In the reset function, these buffers may have been allocated
1124 * to an SKB, so we need to unmap and free potential storage */
Zhu Yi2f301222009-10-09 17:19:45 +08001125 if (rxq->pool[i].page != NULL) {
1126 pci_unmap_page(priv->pci_dev, rxq->pool[i].page_dma,
1127 PAGE_SIZE << priv->hw_params.rx_page_order,
1128 PCI_DMA_FROMDEVICE);
Zhu Yi64a76b52009-12-10 14:37:21 -08001129 __iwl_free_pages(priv, rxq->pool[i].page);
Zhu Yi2f301222009-10-09 17:19:45 +08001130 rxq->pool[i].page = NULL;
Reinette Chatredf833b12009-04-21 10:55:48 -07001131 }
1132 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
1133 }
1134
1135 /* Set us so that we have processed and used all buffers, but have
1136 * not restocked the Rx queue with fresh buffers */
1137 rxq->read = rxq->write = 0;
Abhijeet Kolekard14d44402009-06-03 11:44:08 -07001138 rxq->write_actual = 0;
Zhu Yi2f301222009-10-09 17:19:45 +08001139 rxq->free_count = 0;
Reinette Chatredf833b12009-04-21 10:55:48 -07001140 spin_unlock_irqrestore(&rxq->lock, flags);
1141}
Reinette Chatredf833b12009-04-21 10:55:48 -07001142
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001143void iwl3945_rx_replenish(void *data)
1144{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001145 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001146 unsigned long flags;
1147
Abhijeet Kolekard14d44402009-06-03 11:44:08 -07001148 iwl3945_rx_allocate(priv, GFP_KERNEL);
Zhu Yib481de92007-09-25 17:54:57 -07001149
1150 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001151 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001152 spin_unlock_irqrestore(&priv->lock, flags);
1153}
1154
Abhijeet Kolekard14d44402009-06-03 11:44:08 -07001155static void iwl3945_rx_replenish_now(struct iwl_priv *priv)
1156{
1157 iwl3945_rx_allocate(priv, GFP_ATOMIC);
1158
1159 iwl3945_rx_queue_restock(priv);
1160}
1161
1162
Reinette Chatredf833b12009-04-21 10:55:48 -07001163/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
1164 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
1165 * This free routine walks the list of POOL entries and if SKB is set to
1166 * non NULL it is unmapped and freed
1167 */
1168static void iwl3945_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
1169{
1170 int i;
1171 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
Zhu Yi2f301222009-10-09 17:19:45 +08001172 if (rxq->pool[i].page != NULL) {
1173 pci_unmap_page(priv->pci_dev, rxq->pool[i].page_dma,
1174 PAGE_SIZE << priv->hw_params.rx_page_order,
1175 PCI_DMA_FROMDEVICE);
Zhu Yi64a76b52009-12-10 14:37:21 -08001176 __iwl_free_pages(priv, rxq->pool[i].page);
Zhu Yi2f301222009-10-09 17:19:45 +08001177 rxq->pool[i].page = NULL;
Reinette Chatredf833b12009-04-21 10:55:48 -07001178 }
1179 }
1180
Stanislaw Gruszkaf36d04a2010-02-10 05:07:45 -08001181 dma_free_coherent(&priv->pci_dev->dev, 4 * RX_QUEUE_SIZE, rxq->bd,
Emmanuel Grumbachd5b25c92010-06-07 13:21:46 -07001182 rxq->bd_dma);
Stanislaw Gruszkaf36d04a2010-02-10 05:07:45 -08001183 dma_free_coherent(&priv->pci_dev->dev, sizeof(struct iwl_rb_status),
1184 rxq->rb_stts, rxq->rb_stts_dma);
Reinette Chatredf833b12009-04-21 10:55:48 -07001185 rxq->bd = NULL;
1186 rxq->rb_stts = NULL;
1187}
Reinette Chatredf833b12009-04-21 10:55:48 -07001188
1189
Zhu Yib481de92007-09-25 17:54:57 -07001190/* Convert linear signal-to-noise ratio into dB */
1191static u8 ratio2dB[100] = {
1192/* 0 1 2 3 4 5 6 7 8 9 */
1193 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
1194 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
1195 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
1196 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
1197 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
1198 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
1199 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
1200 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
1201 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
1202 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
1203};
1204
1205/* Calculates a relative dB value from a ratio of linear
1206 * (i.e. not dB) signal levels.
1207 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001208int iwl3945_calc_db_from_ratio(int sig_ratio)
Zhu Yib481de92007-09-25 17:54:57 -07001209{
Adrian Bunk221c80c2008-02-02 23:19:01 +02001210 /* 1000:1 or higher just report as 60 dB */
1211 if (sig_ratio >= 1000)
Zhu Yib481de92007-09-25 17:54:57 -07001212 return 60;
1213
Adrian Bunk221c80c2008-02-02 23:19:01 +02001214 /* 100:1 or higher, divide by 10 and use table,
Zhu Yib481de92007-09-25 17:54:57 -07001215 * add 20 dB to make up for divide by 10 */
Adrian Bunk221c80c2008-02-02 23:19:01 +02001216 if (sig_ratio >= 100)
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001217 return 20 + (int)ratio2dB[sig_ratio/10];
Zhu Yib481de92007-09-25 17:54:57 -07001218
1219 /* We shouldn't see this */
1220 if (sig_ratio < 1)
1221 return 0;
1222
1223 /* Use table for ratios 1:1 - 99:1 */
1224 return (int)ratio2dB[sig_ratio];
1225}
1226
Zhu Yib481de92007-09-25 17:54:57 -07001227/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001228 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001229 *
1230 * Uses the priv->rx_handlers callback function array to invoke
1231 * the appropriate handlers, including command responses,
1232 * frame-received notifications, and other notifications.
1233 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001234static void iwl3945_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001235{
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001236 struct iwl_rx_mem_buffer *rxb;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001237 struct iwl_rx_packet *pkt;
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001238 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001239 u32 r, i;
1240 int reclaim;
1241 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001242 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001243 u32 count = 8;
Abhijeet Kolekard14d44402009-06-03 11:44:08 -07001244 int total_empty = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001245
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001246 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1247 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8cd812b2008-12-19 10:37:43 +08001248 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07001249 i = rxq->read;
1250
Abhijeet Kolekard14d44402009-06-03 11:44:08 -07001251 /* calculate total frames need to be restock after handling RX */
Zhu Yi73005152009-10-23 13:42:32 -07001252 total_empty = r - rxq->write_actual;
Abhijeet Kolekard14d44402009-06-03 11:44:08 -07001253 if (total_empty < 0)
1254 total_empty += RX_QUEUE_SIZE;
1255
1256 if (total_empty > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001257 fill_rx = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001258 /* Rx interrupt, but nothing sent from uCode */
1259 if (i == r)
Reinette Chatreaf472a952009-08-28 09:58:50 -07001260 IWL_DEBUG_RX(priv, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001261
1262 while (i != r) {
Johannes Bergf4989d92010-05-28 04:08:30 -07001263 int len;
1264
Zhu Yib481de92007-09-25 17:54:57 -07001265 rxb = rxq->queue[i];
1266
Ben Cahill9fbab512007-11-29 11:09:47 +08001267 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001268 * then a bug has been introduced in the queue refilling
1269 * routines -- catch it here */
1270 BUG_ON(rxb == NULL);
1271
1272 rxq->queue[i] = NULL;
1273
Zhu Yi2f301222009-10-09 17:19:45 +08001274 pci_unmap_page(priv->pci_dev, rxb->page_dma,
1275 PAGE_SIZE << priv->hw_params.rx_page_order,
1276 PCI_DMA_FROMDEVICE);
1277 pkt = rxb_addr(rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001278
Johannes Bergf4989d92010-05-28 04:08:30 -07001279 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
1280 len += sizeof(u32); /* account for status word */
1281 trace_iwlwifi_dev_rx(priv, pkt, len);
Johannes Bergbe1a71a2009-10-02 13:44:02 -07001282
Zhu Yib481de92007-09-25 17:54:57 -07001283 /* Reclaim a command buffer only if this packet is a response
1284 * to a (driver-originated) command.
1285 * If the packet (e.g. Rx frame) originated from uCode,
1286 * there is no command buffer to reclaim.
1287 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1288 * but apparently a few don't get set; catch them here. */
1289 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1290 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1291 (pkt->hdr.cmd != REPLY_TX);
1292
1293 /* Based on type of command response or notification,
1294 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001295 * rx_handlers table. See iwl3945_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001296 if (priv->rx_handlers[pkt->hdr.cmd]) {
Reinette Chatreaf472a952009-08-28 09:58:50 -07001297 IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r, i,
Zhu Yib481de92007-09-25 17:54:57 -07001298 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001299 priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
Zhu Yi29b1b262009-10-23 13:42:25 -07001300 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001301 } else {
1302 /* No handling needed */
Zhu Yi2f301222009-10-09 17:19:45 +08001303 IWL_DEBUG_RX(priv,
1304 "r %d i %d No handler needed for %s, 0x%02x\n",
Zhu Yib481de92007-09-25 17:54:57 -07001305 r, i, get_cmd_string(pkt->hdr.cmd),
1306 pkt->hdr.cmd);
1307 }
1308
Zhu Yi29b1b262009-10-23 13:42:25 -07001309 /*
1310 * XXX: After here, we should always check rxb->page
1311 * against NULL before touching it or its virtual
1312 * memory (pkt). Because some rx_handler might have
1313 * already taken or freed the pages.
1314 */
1315
Zhu Yib481de92007-09-25 17:54:57 -07001316 if (reclaim) {
Zhu Yi2f301222009-10-09 17:19:45 +08001317 /* Invoke any callbacks, transfer the buffer to caller,
1318 * and fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001319 * as we reclaim the driver command queue */
Zhu Yi29b1b262009-10-23 13:42:25 -07001320 if (rxb->page)
Abhijeet Kolekar732587a2009-03-11 11:17:57 -07001321 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001322 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001323 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07001324 }
1325
Zhu Yi73005152009-10-23 13:42:32 -07001326 /* Reuse the page if possible. For notification packets and
1327 * SKBs that fail to Rx correctly, add them back into the
1328 * rx_free list for reuse later. */
Zhu Yib481de92007-09-25 17:54:57 -07001329 spin_lock_irqsave(&rxq->lock, flags);
Zhu Yi73005152009-10-23 13:42:32 -07001330 if (rxb->page != NULL) {
1331 rxb->page_dma = pci_map_page(priv->pci_dev, rxb->page,
1332 0, PAGE_SIZE << priv->hw_params.rx_page_order,
1333 PCI_DMA_FROMDEVICE);
1334 list_add_tail(&rxb->list, &rxq->rx_free);
1335 rxq->free_count++;
1336 } else
1337 list_add_tail(&rxb->list, &rxq->rx_used);
1338
Zhu Yib481de92007-09-25 17:54:57 -07001339 spin_unlock_irqrestore(&rxq->lock, flags);
Zhu Yi73005152009-10-23 13:42:32 -07001340
Zhu Yib481de92007-09-25 17:54:57 -07001341 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001342 /* If there are a lot of unused frames,
1343 * restock the Rx queue so ucode won't assert. */
1344 if (fill_rx) {
1345 count++;
1346 if (count >= 8) {
Zhu Yi73005152009-10-23 13:42:32 -07001347 rxq->read = i;
Abhijeet Kolekard14d44402009-06-03 11:44:08 -07001348 iwl3945_rx_replenish_now(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001349 count = 0;
1350 }
1351 }
Zhu Yib481de92007-09-25 17:54:57 -07001352 }
1353
1354 /* Backtrack one entry */
Zhu Yi73005152009-10-23 13:42:32 -07001355 rxq->read = i;
Abhijeet Kolekard14d44402009-06-03 11:44:08 -07001356 if (fill_rx)
1357 iwl3945_rx_replenish_now(priv);
1358 else
1359 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001360}
1361
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001362/* call this function to flush any scheduled tasklet */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001363static inline void iwl_synchronize_irq(struct iwl_priv *priv)
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001364{
Tomas Winklera96a27f2008-10-23 23:48:56 -07001365 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001366 synchronize_irq(priv->pci_dev->irq);
1367 tasklet_kill(&priv->irq_tasklet);
1368}
1369
Zhu Yib481de92007-09-25 17:54:57 -07001370static const char *desc_lookup(int i)
1371{
1372 switch (i) {
1373 case 1:
1374 return "FAIL";
1375 case 2:
1376 return "BAD_PARAM";
1377 case 3:
1378 return "BAD_CHECKSUM";
1379 case 4:
1380 return "NMI_INTERRUPT";
1381 case 5:
1382 return "SYSASSERT";
1383 case 6:
1384 return "FATAL_ERROR";
1385 }
1386
1387 return "UNKNOWN";
1388}
1389
1390#define ERROR_START_OFFSET (1 * sizeof(u32))
1391#define ERROR_ELEM_SIZE (7 * sizeof(u32))
1392
Reinette Chatreb7a79402009-09-25 14:24:23 -07001393void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001394{
1395 u32 i;
1396 u32 desc, time, count, base, data1;
1397 u32 blink1, blink2, ilink1, ilink2;
Zhu Yib481de92007-09-25 17:54:57 -07001398
1399 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
1400
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001401 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001402 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07001403 return;
1404 }
1405
Zhu Yib481de92007-09-25 17:54:57 -07001406
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001407 count = iwl_read_targ_mem(priv, base);
Zhu Yib481de92007-09-25 17:54:57 -07001408
1409 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001410 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
1411 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
1412 priv->status, count);
Zhu Yib481de92007-09-25 17:54:57 -07001413 }
1414
Winkler, Tomas15b16872008-12-19 10:37:33 +08001415 IWL_ERR(priv, "Desc Time asrtPC blink2 "
Zhu Yib481de92007-09-25 17:54:57 -07001416 "ilink1 nmiPC Line\n");
1417 for (i = ERROR_START_OFFSET;
1418 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
1419 i += ERROR_ELEM_SIZE) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001420 desc = iwl_read_targ_mem(priv, base + i);
Zhu Yib481de92007-09-25 17:54:57 -07001421 time =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001422 iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001423 blink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001424 iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001425 blink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001426 iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001427 ilink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001428 iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001429 ilink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001430 iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001431 data1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001432 iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001433
Winkler, Tomas15b16872008-12-19 10:37:33 +08001434 IWL_ERR(priv,
Jay Sternberg87563712010-06-14 14:40:40 -07001435 "%-13s (0x%X) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
Winkler, Tomas15b16872008-12-19 10:37:33 +08001436 desc_lookup(desc), desc, time, blink1, blink2,
1437 ilink1, ilink2, data1);
Johannes Bergbe1a71a2009-10-02 13:44:02 -07001438 trace_iwlwifi_dev_ucode_error(priv, desc, time, data1, 0,
1439 0, blink1, blink2, ilink1, ilink2);
Zhu Yib481de92007-09-25 17:54:57 -07001440 }
Zhu Yib481de92007-09-25 17:54:57 -07001441}
1442
Ben Cahillf58177b2007-11-29 11:09:43 +08001443#define EVENT_START_OFFSET (6 * sizeof(u32))
Zhu Yib481de92007-09-25 17:54:57 -07001444
1445/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001446 * iwl3945_print_event_log - Dump error event log to syslog
Zhu Yib481de92007-09-25 17:54:57 -07001447 *
Zhu Yib481de92007-09-25 17:54:57 -07001448 */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001449static int iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
1450 u32 num_events, u32 mode,
1451 int pos, char **buf, size_t bufsz)
Zhu Yib481de92007-09-25 17:54:57 -07001452{
1453 u32 i;
1454 u32 base; /* SRAM byte address of event log header */
1455 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
1456 u32 ptr; /* SRAM byte address of log data */
1457 u32 ev, time, data; /* event log data */
Ben Cahille5854472009-11-06 14:52:58 -08001458 unsigned long reg_flags;
Zhu Yib481de92007-09-25 17:54:57 -07001459
1460 if (num_events == 0)
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001461 return pos;
Zhu Yib481de92007-09-25 17:54:57 -07001462
1463 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
1464
1465 if (mode == 0)
1466 event_size = 2 * sizeof(u32);
1467 else
1468 event_size = 3 * sizeof(u32);
1469
1470 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
1471
Ben Cahille5854472009-11-06 14:52:58 -08001472 /* Make sure device is powered up for SRAM reads */
1473 spin_lock_irqsave(&priv->reg_lock, reg_flags);
1474 iwl_grab_nic_access(priv);
1475
1476 /* Set starting address; reads will auto-increment */
1477 _iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, ptr);
1478 rmb();
1479
Zhu Yib481de92007-09-25 17:54:57 -07001480 /* "time" is actually "data" for mode 0 (no timestamp).
1481 * place event id # at far right for easier visual parsing. */
1482 for (i = 0; i < num_events; i++) {
Ben Cahille5854472009-11-06 14:52:58 -08001483 ev = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
1484 time = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Winkler, Tomas15b16872008-12-19 10:37:33 +08001485 if (mode == 0) {
1486 /* data, ev */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001487 if (bufsz) {
1488 pos += scnprintf(*buf + pos, bufsz - pos,
1489 "0x%08x:%04u\n",
1490 time, ev);
1491 } else {
1492 IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
1493 trace_iwlwifi_dev_ucode_event(priv, 0,
1494 time, ev);
1495 }
Winkler, Tomas15b16872008-12-19 10:37:33 +08001496 } else {
Ben Cahille5854472009-11-06 14:52:58 -08001497 data = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001498 if (bufsz) {
1499 pos += scnprintf(*buf + pos, bufsz - pos,
1500 "%010u:0x%08x:%04u\n",
1501 time, data, ev);
1502 } else {
1503 IWL_ERR(priv, "%010u\t0x%08x\t%04u\n",
1504 time, data, ev);
1505 trace_iwlwifi_dev_ucode_event(priv, time,
1506 data, ev);
1507 }
Zhu Yib481de92007-09-25 17:54:57 -07001508 }
1509 }
Ben Cahille5854472009-11-06 14:52:58 -08001510
1511 /* Allow device to power down */
1512 iwl_release_nic_access(priv);
1513 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001514 return pos;
Zhu Yib481de92007-09-25 17:54:57 -07001515}
1516
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001517/**
1518 * iwl3945_print_last_event_logs - Dump the newest # of event log to syslog
1519 */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001520static int iwl3945_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001521 u32 num_wraps, u32 next_entry,
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001522 u32 size, u32 mode,
1523 int pos, char **buf, size_t bufsz)
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001524{
1525 /*
1526 * display the newest DEFAULT_LOG_ENTRIES entries
1527 * i.e the entries just before the next ont that uCode would fill.
1528 */
1529 if (num_wraps) {
1530 if (next_entry < size) {
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001531 pos = iwl3945_print_event_log(priv,
1532 capacity - (size - next_entry),
1533 size - next_entry, mode,
1534 pos, buf, bufsz);
1535 pos = iwl3945_print_event_log(priv, 0,
1536 next_entry, mode,
1537 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001538 } else
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001539 pos = iwl3945_print_event_log(priv, next_entry - size,
1540 size, mode,
1541 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001542 } else {
1543 if (next_entry < size)
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001544 pos = iwl3945_print_event_log(priv, 0,
1545 next_entry, mode,
1546 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001547 else
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001548 pos = iwl3945_print_event_log(priv, next_entry - size,
1549 size, mode,
1550 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001551 }
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001552 return pos;
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001553}
1554
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001555#define DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES (20)
1556
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001557int iwl3945_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
1558 char **buf, bool display)
Zhu Yib481de92007-09-25 17:54:57 -07001559{
Zhu Yib481de92007-09-25 17:54:57 -07001560 u32 base; /* SRAM byte address of event log header */
1561 u32 capacity; /* event log capacity in # entries */
1562 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
1563 u32 num_wraps; /* # times uCode wrapped to top of log */
1564 u32 next_entry; /* index of next entry to be written by uCode */
1565 u32 size; /* # entries that we'll print */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001566 int pos = 0;
1567 size_t bufsz = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001568
1569 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001570 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001571 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
Wey-Yi Guy937c3972010-01-15 13:43:36 -08001572 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001573 }
1574
Zhu Yib481de92007-09-25 17:54:57 -07001575 /* event log header */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001576 capacity = iwl_read_targ_mem(priv, base);
1577 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
1578 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
1579 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -07001580
Wey-Yi Guy678b3852010-03-26 12:54:37 -07001581 if (capacity > priv->cfg->max_event_log_size) {
Ben Cahill84c40692009-11-06 14:52:57 -08001582 IWL_ERR(priv, "Log capacity %d is bogus, limit to %d entries\n",
Wey-Yi Guy678b3852010-03-26 12:54:37 -07001583 capacity, priv->cfg->max_event_log_size);
1584 capacity = priv->cfg->max_event_log_size;
Ben Cahill84c40692009-11-06 14:52:57 -08001585 }
1586
Wey-Yi Guy678b3852010-03-26 12:54:37 -07001587 if (next_entry > priv->cfg->max_event_log_size) {
Ben Cahill84c40692009-11-06 14:52:57 -08001588 IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
Wey-Yi Guy678b3852010-03-26 12:54:37 -07001589 next_entry, priv->cfg->max_event_log_size);
1590 next_entry = priv->cfg->max_event_log_size;
Ben Cahill84c40692009-11-06 14:52:57 -08001591 }
1592
Zhu Yib481de92007-09-25 17:54:57 -07001593 size = num_wraps ? capacity : next_entry;
1594
1595 /* bail out if nothing in log */
1596 if (size == 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001597 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001598 return pos;
Zhu Yib481de92007-09-25 17:54:57 -07001599 }
1600
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001601#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guy521d9bc2009-12-10 14:37:23 -08001602 if (!(iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) && !full_log)
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001603 size = (size > DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES)
1604 ? DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES : size;
1605#else
1606 size = (size > DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES)
1607 ? DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES : size;
1608#endif
1609
1610 IWL_ERR(priv, "Start IWL Event Log Dump: display last %d count\n",
1611 size);
Zhu Yib481de92007-09-25 17:54:57 -07001612
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001613#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001614 if (display) {
1615 if (full_log)
1616 bufsz = capacity * 48;
1617 else
1618 bufsz = size * 48;
1619 *buf = kmalloc(bufsz, GFP_KERNEL);
1620 if (!*buf)
Wey-Yi Guy937c3972010-01-15 13:43:36 -08001621 return -ENOMEM;
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001622 }
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001623 if ((iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) || full_log) {
1624 /* if uCode has wrapped back to top of log,
1625 * start at the oldest entry,
1626 * i.e the next one that uCode would fill.
1627 */
1628 if (num_wraps)
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001629 pos = iwl3945_print_event_log(priv, next_entry,
1630 capacity - next_entry, mode,
1631 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001632
1633 /* (then/else) start at top of log */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001634 pos = iwl3945_print_event_log(priv, 0, next_entry, mode,
1635 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001636 } else
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001637 pos = iwl3945_print_last_event_logs(priv, capacity, num_wraps,
1638 next_entry, size, mode,
1639 pos, buf, bufsz);
Reinette Chatreb7a79402009-09-25 14:24:23 -07001640#else
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001641 pos = iwl3945_print_last_event_logs(priv, capacity, num_wraps,
1642 next_entry, size, mode,
1643 pos, buf, bufsz);
Reinette Chatreb7a79402009-09-25 14:24:23 -07001644#endif
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001645 return pos;
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001646}
1647
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001648static void iwl3945_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001649{
1650 u32 inta, handled = 0;
1651 u32 inta_fh;
1652 unsigned long flags;
Samuel Ortizd08853a2009-01-23 13:45:17 -08001653#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001654 u32 inta_mask;
1655#endif
1656
1657 spin_lock_irqsave(&priv->lock, flags);
1658
1659 /* Ack/clear/reset pending uCode interrupts.
1660 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1661 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001662 inta = iwl_read32(priv, CSR_INT);
1663 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07001664
1665 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1666 * Any new interrupts that happen after this, either while we're
1667 * in this tasklet, or later, will show up in next ISR/tasklet. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001668 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1669 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001670
Samuel Ortizd08853a2009-01-23 13:45:17 -08001671#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001672 if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001673 /* just for debug */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001674 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Tomas Winklere1623442009-01-27 14:27:56 -08001675 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07001676 inta, inta_mask, inta_fh);
1677 }
1678#endif
1679
Zhu Yi2f301222009-10-09 17:19:45 +08001680 spin_unlock_irqrestore(&priv->lock, flags);
1681
Zhu Yib481de92007-09-25 17:54:57 -07001682 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1683 * atomic, make sure that inta covers all the interrupts that
1684 * we've discovered, even if FH interrupt came in just after
1685 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001686 if (inta_fh & CSR39_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001687 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001688 if (inta_fh & CSR39_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001689 inta |= CSR_INT_BIT_FH_TX;
1690
1691 /* Now service all interrupt bits discovered above. */
1692 if (inta & CSR_INT_BIT_HW_ERR) {
Reinette Chatre58dba722009-07-17 09:30:25 -07001693 IWL_ERR(priv, "Hardware error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001694
1695 /* Tell the device to stop sending interrupts */
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08001696 iwl_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001697
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001698 priv->isr_stats.hw++;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001699 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001700
1701 handled |= CSR_INT_BIT_HW_ERR;
1702
Zhu Yib481de92007-09-25 17:54:57 -07001703 return;
1704 }
1705
Samuel Ortizd08853a2009-01-23 13:45:17 -08001706#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001707 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07001708 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001709 if (inta & CSR_INT_BIT_SCD) {
Tomas Winklere1623442009-01-27 14:27:56 -08001710 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
Joonwoo Park25c03d82008-01-23 10:15:20 -08001711 "the frame/frames.\n");
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001712 priv->isr_stats.sch++;
1713 }
Zhu Yib481de92007-09-25 17:54:57 -07001714
1715 /* Alive notification via Rx interrupt will do the real work */
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001716 if (inta & CSR_INT_BIT_ALIVE) {
Tomas Winklere1623442009-01-27 14:27:56 -08001717 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001718 priv->isr_stats.alive++;
1719 }
Zhu Yib481de92007-09-25 17:54:57 -07001720 }
1721#endif
1722 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001723 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07001724
Zhu Yib481de92007-09-25 17:54:57 -07001725 /* Error detected by uCode */
1726 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001727 IWL_ERR(priv, "Microcode SW error detected. "
1728 "Restarting 0x%X.\n", inta);
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001729 priv->isr_stats.sw++;
1730 priv->isr_stats.sw_err = inta;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001731 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001732 handled |= CSR_INT_BIT_SW_ERR;
1733 }
1734
1735 /* uCode wakes up after power-down sleep */
1736 if (inta & CSR_INT_BIT_WAKEUP) {
Tomas Winklere1623442009-01-27 14:27:56 -08001737 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
Winkler, Tomas141c43a2009-01-08 10:19:53 -08001738 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001739 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
1740 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
1741 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
1742 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
1743 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1744 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07001745
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001746 priv->isr_stats.wakeup++;
Zhu Yib481de92007-09-25 17:54:57 -07001747 handled |= CSR_INT_BIT_WAKEUP;
1748 }
1749
1750 /* All uCode command responses, including Tx command responses,
1751 * Rx "responses" (frame-received notification), and other
1752 * notifications from uCode come through here*/
1753 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001754 iwl3945_rx_handle(priv);
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001755 priv->isr_stats.rx++;
Zhu Yib481de92007-09-25 17:54:57 -07001756 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1757 }
1758
1759 if (inta & CSR_INT_BIT_FH_TX) {
Tomas Winklere1623442009-01-27 14:27:56 -08001760 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001761 priv->isr_stats.tx++;
Zhu Yib481de92007-09-25 17:54:57 -07001762
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001763 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07001764 iwl_write_direct32(priv, FH39_TCSR_CREDIT
1765 (FH39_SRVC_CHNL), 0x0);
Zhu Yib481de92007-09-25 17:54:57 -07001766 handled |= CSR_INT_BIT_FH_TX;
1767 }
1768
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001769 if (inta & ~handled) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001770 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Abhijeet Kolekar86ddbf62009-04-20 14:36:59 -07001771 priv->isr_stats.unhandled++;
1772 }
Zhu Yib481de92007-09-25 17:54:57 -07001773
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001774 if (inta & ~priv->inta_mask) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001775 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001776 inta & ~priv->inta_mask);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001777 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001778 }
1779
1780 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001781 /* only Re-enable if disabled by irq */
1782 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08001783 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001784
Samuel Ortizd08853a2009-01-23 13:45:17 -08001785#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001786 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001787 inta = iwl_read32(priv, CSR_INT);
1788 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1789 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Tomas Winklere1623442009-01-27 14:27:56 -08001790 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
Zhu Yib481de92007-09-25 17:54:57 -07001791 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
1792 }
1793#endif
Zhu Yib481de92007-09-25 17:54:57 -07001794}
1795
Abhijeet Kolekar14023642010-06-02 21:15:10 -07001796static int iwl3945_get_single_channel_for_scan(struct iwl_priv *priv,
1797 struct ieee80211_vif *vif,
1798 enum ieee80211_band band,
1799 struct iwl3945_scan_channel *scan_ch)
1800{
1801 const struct ieee80211_supported_band *sband;
1802 u16 passive_dwell = 0;
1803 u16 active_dwell = 0;
1804 int added = 0;
1805 u8 channel = 0;
1806
1807 sband = iwl_get_hw_mode(priv, band);
1808 if (!sband) {
1809 IWL_ERR(priv, "invalid band\n");
1810 return added;
1811 }
1812
1813 active_dwell = iwl_get_active_dwell_time(priv, band, 0);
1814 passive_dwell = iwl_get_passive_dwell_time(priv, band, vif);
1815
1816 if (passive_dwell <= active_dwell)
1817 passive_dwell = active_dwell + 1;
1818
1819
1820 channel = iwl_get_single_channel_number(priv, band);
1821
1822 if (channel) {
1823 scan_ch->channel = channel;
1824 scan_ch->type = 0; /* passive */
1825 scan_ch->active_dwell = cpu_to_le16(active_dwell);
1826 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
1827 /* Set txpower levels to defaults */
1828 scan_ch->tpc.dsp_atten = 110;
1829 if (band == IEEE80211_BAND_5GHZ)
1830 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
1831 else
1832 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
1833 added++;
1834 } else
1835 IWL_ERR(priv, "no valid channel found\n");
1836 return added;
1837}
1838
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001839static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01001840 enum ieee80211_band band,
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08001841 u8 is_active, u8 n_probes,
Johannes Berg1dda6d22010-04-29 04:43:06 -07001842 struct iwl3945_scan_channel *scan_ch,
1843 struct ieee80211_vif *vif)
Zhu Yib481de92007-09-25 17:54:57 -07001844{
Johannes Berg4e05c232009-06-19 13:52:44 -07001845 struct ieee80211_channel *chan;
Johannes Berg8318d782008-01-24 19:38:38 +01001846 const struct ieee80211_supported_band *sband;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001847 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07001848 u16 passive_dwell = 0;
1849 u16 active_dwell = 0;
1850 int added, i;
1851
Kolekar, Abhijeetcbba18c2008-12-19 10:37:42 +08001852 sband = iwl_get_hw_mode(priv, band);
Johannes Berg8318d782008-01-24 19:38:38 +01001853 if (!sband)
Zhu Yib481de92007-09-25 17:54:57 -07001854 return 0;
1855
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08001856 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
Johannes Berg1dda6d22010-04-29 04:43:06 -07001857 passive_dwell = iwl_get_passive_dwell_time(priv, band, vif);
Zhu Yib481de92007-09-25 17:54:57 -07001858
Abhijeet Kolekar8f4807a2008-09-03 11:26:31 +08001859 if (passive_dwell <= active_dwell)
1860 passive_dwell = active_dwell + 1;
1861
Johannes Berg4e05c232009-06-19 13:52:44 -07001862 for (i = 0, added = 0; i < priv->scan_request->n_channels; i++) {
1863 chan = priv->scan_request->channels[i];
1864
1865 if (chan->band != band)
Johannes Berg182e2e62008-04-04 10:41:56 +02001866 continue;
1867
Johannes Berg4e05c232009-06-19 13:52:44 -07001868 scan_ch->channel = chan->hw_value;
Zhu Yib481de92007-09-25 17:54:57 -07001869
Samuel Ortize6148912009-01-23 13:45:15 -08001870 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07001871 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08001872 IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
Zhu Yib481de92007-09-25 17:54:57 -07001873 scan_ch->channel);
1874 continue;
1875 }
1876
Zhu Yib481de92007-09-25 17:54:57 -07001877 scan_ch->active_dwell = cpu_to_le16(active_dwell);
1878 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08001879 /* If passive , set up for auto-switch
1880 * and use long active_dwell time.
1881 */
1882 if (!is_active || is_channel_passive(ch_info) ||
Johannes Berg4e05c232009-06-19 13:52:44 -07001883 (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08001884 scan_ch->type = 0; /* passive */
1885 if (IWL_UCODE_API(priv->ucode_ver) == 1)
1886 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
1887 } else {
1888 scan_ch->type = 1; /* active */
1889 }
1890
1891 /* Set direct probe bits. These may be used both for active
1892 * scan channels (probes gets sent right away),
1893 * or for passive channels (probes get se sent only after
1894 * hearing clear Rx packet).*/
1895 if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
1896 if (n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08001897 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08001898 } else {
1899 /* uCode v1 does not allow setting direct probe bits on
1900 * passive channel. */
1901 if ((scan_ch->type & 1) && n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08001902 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08001903 }
Zhu Yib481de92007-09-25 17:54:57 -07001904
Ben Cahill9fbab512007-11-29 11:09:47 +08001905 /* Set txpower levels to defaults */
Zhu Yib481de92007-09-25 17:54:57 -07001906 scan_ch->tpc.dsp_atten = 110;
1907 /* scan_pwr_info->tpc.dsp_atten; */
1908
1909 /*scan_pwr_info->tpc.tx_gain; */
Johannes Berg8318d782008-01-24 19:38:38 +01001910 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07001911 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
1912 else {
1913 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
1914 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
Ben Cahill9fbab512007-11-29 11:09:47 +08001915 * power level:
Reinette Chatre8a1b0242008-01-14 17:46:25 -08001916 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
Zhu Yib481de92007-09-25 17:54:57 -07001917 */
1918 }
1919
Tomas Winklere1623442009-01-27 14:27:56 -08001920 IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n",
Zhu Yib481de92007-09-25 17:54:57 -07001921 scan_ch->channel,
1922 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
1923 (scan_ch->type & 1) ?
1924 active_dwell : passive_dwell);
1925
1926 scan_ch++;
1927 added++;
1928 }
1929
Frans Pop91dd6c22010-03-24 14:19:58 -07001930 IWL_DEBUG_SCAN(priv, "total channels to scan %d\n", added);
Zhu Yib481de92007-09-25 17:54:57 -07001931 return added;
1932}
1933
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001934static void iwl3945_init_hw_rates(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001935 struct ieee80211_rate *rates)
1936{
1937 int i;
1938
Dan Carpenter8e1a53c2010-03-28 14:55:00 +03001939 for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
Johannes Berg8318d782008-01-24 19:38:38 +01001940 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
1941 rates[i].hw_value = i; /* Rate scaling will work on indexes */
1942 rates[i].hw_value_short = i;
1943 rates[i].flags = 0;
Samuel Ortizd9829a62008-12-19 10:37:12 +08001944 if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
Zhu Yib481de92007-09-25 17:54:57 -07001945 /*
Johannes Berg8318d782008-01-24 19:38:38 +01001946 * If CCK != 1M then set short preamble rate flag.
Zhu Yib481de92007-09-25 17:54:57 -07001947 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001948 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
Johannes Berg8318d782008-01-24 19:38:38 +01001949 0 : IEEE80211_RATE_SHORT_PREAMBLE;
Zhu Yib481de92007-09-25 17:54:57 -07001950 }
Zhu Yib481de92007-09-25 17:54:57 -07001951 }
1952}
1953
Zhu Yib481de92007-09-25 17:54:57 -07001954/******************************************************************************
1955 *
1956 * uCode download functions
1957 *
1958 ******************************************************************************/
1959
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001960static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001961{
Tomas Winkler98c92212008-01-14 17:46:20 -08001962 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
1963 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
1964 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1965 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
1966 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1967 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001968}
1969
1970/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001971 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07001972 * looking at all data.
1973 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001974static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07001975{
1976 u32 val;
1977 u32 save_len = len;
1978 int rc = 0;
1979 u32 errcnt;
1980
Tomas Winklere1623442009-01-27 14:27:56 -08001981 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001982
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001983 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08001984 IWL39_RTC_INST_LOWER_BOUND);
Zhu Yib481de92007-09-25 17:54:57 -07001985
1986 errcnt = 0;
1987 for (; len > 0; len -= sizeof(u32), image++) {
1988 /* read data comes through single port, auto-incr addr */
1989 /* NOTE: Use the debugless read so we don't flood kernel log
1990 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001991 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07001992 if (val != le32_to_cpu(*image)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001993 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07001994 "offset 0x%x, is 0x%x, s/b 0x%x\n",
1995 save_len - len, val, le32_to_cpu(*image));
1996 rc = -EIO;
1997 errcnt++;
1998 if (errcnt >= 20)
1999 break;
2000 }
2001 }
2002
Zhu Yib481de92007-09-25 17:54:57 -07002003
2004 if (!errcnt)
Tomas Winklere1623442009-01-27 14:27:56 -08002005 IWL_DEBUG_INFO(priv,
2006 "ucode image in INSTRUCTION memory is good\n");
Zhu Yib481de92007-09-25 17:54:57 -07002007
2008 return rc;
2009}
2010
2011
2012/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002013 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002014 * using sample data 100 bytes apart. If these sample points are good,
2015 * it's a pretty good bet that everything between them is good, too.
2016 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002017static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002018{
2019 u32 val;
2020 int rc = 0;
2021 u32 errcnt = 0;
2022 u32 i;
2023
Tomas Winklere1623442009-01-27 14:27:56 -08002024 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002025
Zhu Yib481de92007-09-25 17:54:57 -07002026 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
2027 /* read data comes through single port, auto-incr addr */
2028 /* NOTE: Use the debugless read so we don't flood kernel log
2029 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002030 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002031 i + IWL39_RTC_INST_LOWER_BOUND);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002032 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002033 if (val != le32_to_cpu(*image)) {
2034#if 0 /* Enable this if you want to see details */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002035 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002036 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2037 i, val, *image);
2038#endif
2039 rc = -EIO;
2040 errcnt++;
2041 if (errcnt >= 3)
2042 break;
2043 }
2044 }
2045
Zhu Yib481de92007-09-25 17:54:57 -07002046 return rc;
2047}
2048
2049
2050/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002051 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
Zhu Yib481de92007-09-25 17:54:57 -07002052 * and verify its contents
2053 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002054static int iwl3945_verify_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002055{
2056 __le32 *image;
2057 u32 len;
2058 int rc = 0;
2059
2060 /* Try bootstrap */
2061 image = (__le32 *)priv->ucode_boot.v_addr;
2062 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002063 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002064 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002065 IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002066 return 0;
2067 }
2068
2069 /* Try initialize */
2070 image = (__le32 *)priv->ucode_init.v_addr;
2071 len = priv->ucode_init.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002072 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002073 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002074 IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002075 return 0;
2076 }
2077
2078 /* Try runtime/protocol */
2079 image = (__le32 *)priv->ucode_code.v_addr;
2080 len = priv->ucode_code.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002081 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002082 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002083 IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002084 return 0;
2085 }
2086
Winkler, Tomas15b16872008-12-19 10:37:33 +08002087 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
Zhu Yib481de92007-09-25 17:54:57 -07002088
Ben Cahill9fbab512007-11-29 11:09:47 +08002089 /* Since nothing seems to match, show first several data entries in
2090 * instruction SRAM, so maybe visual inspection will give a clue.
2091 * Selection of bootstrap image (vs. other images) is arbitrary. */
Zhu Yib481de92007-09-25 17:54:57 -07002092 image = (__le32 *)priv->ucode_boot.v_addr;
2093 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002094 rc = iwl3945_verify_inst_full(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002095
2096 return rc;
2097}
2098
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002099static void iwl3945_nic_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002100{
2101 /* Remove all resets to allow NIC to operate */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002102 iwl_write32(priv, CSR_RESET, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002103}
2104
Johannes Berg93b1a2f2010-04-28 12:09:13 -07002105#define IWL3945_UCODE_GET(item) \
2106static u32 iwl3945_ucode_get_##item(const struct iwl_ucode_header *ucode)\
2107{ \
2108 return le32_to_cpu(ucode->u.v1.item); \
2109}
2110
2111static u32 iwl3945_ucode_get_header_size(u32 api_ver)
2112{
Johannes Berg22adba22010-04-28 12:09:14 -07002113 return 24;
Johannes Berg93b1a2f2010-04-28 12:09:13 -07002114}
2115
2116static u8 *iwl3945_ucode_get_data(const struct iwl_ucode_header *ucode)
2117{
2118 return (u8 *) ucode->u.v1.data;
2119}
2120
2121IWL3945_UCODE_GET(inst_size);
2122IWL3945_UCODE_GET(data_size);
2123IWL3945_UCODE_GET(init_size);
2124IWL3945_UCODE_GET(init_data_size);
2125IWL3945_UCODE_GET(boot_size);
2126
Zhu Yib481de92007-09-25 17:54:57 -07002127/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002128 * iwl3945_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07002129 *
2130 * Copy into buffers for card to fetch via bus-mastering
2131 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002132static int iwl3945_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002133{
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002134 const struct iwl_ucode_header *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002135 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07002136 const struct firmware *ucode_raw;
2137 /* firmware file name contains uCode/driver compatibility version */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002138 const char *name_pre = priv->cfg->fw_name_pre;
2139 const unsigned int api_max = priv->cfg->ucode_api_max;
2140 const unsigned int api_min = priv->cfg->ucode_api_min;
2141 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07002142 u8 *src;
2143 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002144 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07002145
2146 /* Ask kernel firmware_class module to get the boot firmware off disk.
2147 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002148 for (index = api_max; index >= api_min; index--) {
2149 sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
2150 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
2151 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002152 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002153 buf, ret);
2154 if (ret == -ENOENT)
2155 continue;
2156 else
2157 goto error;
2158 } else {
2159 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002160 IWL_ERR(priv, "Loaded firmware %s, "
2161 "which is deprecated. "
2162 " Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002163 buf, api_max);
Tomas Winklere1623442009-01-27 14:27:56 -08002164 IWL_DEBUG_INFO(priv, "Got firmware '%s' file "
2165 "(%zd bytes) from disk\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002166 buf, ucode_raw->size);
2167 break;
2168 }
Zhu Yib481de92007-09-25 17:54:57 -07002169 }
2170
Reinette Chatrea0987a82008-12-02 12:14:06 -08002171 if (ret < 0)
2172 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07002173
2174 /* Make sure that we got at least our header! */
Johannes Berg93b1a2f2010-04-28 12:09:13 -07002175 if (ucode_raw->size < iwl3945_ucode_get_header_size(1)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002176 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002177 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002178 goto err_release;
2179 }
2180
2181 /* Data from ucode file: header followed by uCode images */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002182 ucode = (struct iwl_ucode_header *)ucode_raw->data;
Zhu Yib481de92007-09-25 17:54:57 -07002183
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08002184 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08002185 api_ver = IWL_UCODE_API(priv->ucode_ver);
Johannes Berg93b1a2f2010-04-28 12:09:13 -07002186 inst_size = iwl3945_ucode_get_inst_size(ucode);
2187 data_size = iwl3945_ucode_get_data_size(ucode);
2188 init_size = iwl3945_ucode_get_init_size(ucode);
2189 init_data_size = iwl3945_ucode_get_init_data_size(ucode);
2190 boot_size = iwl3945_ucode_get_boot_size(ucode);
2191 src = iwl3945_ucode_get_data(ucode);
Zhu Yib481de92007-09-25 17:54:57 -07002192
Reinette Chatrea0987a82008-12-02 12:14:06 -08002193 /* api_ver should match the api version forming part of the
2194 * firmware filename ... but we don't check for that and only rely
Nick Andrew877d0312009-01-26 11:06:57 +01002195 * on the API version read from firmware header from here on forward */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002196
2197 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002198 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002199 "Driver supports v%u, firmware is v%u.\n",
2200 api_max, api_ver);
2201 priv->ucode_ver = 0;
2202 ret = -EINVAL;
2203 goto err_release;
2204 }
2205 if (api_ver != api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002206 IWL_ERR(priv, "Firmware has old API version. Expected %u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002207 "got %u. New firmware can be obtained "
2208 "from http://www.intellinuxwireless.org.\n",
2209 api_max, api_ver);
2210
Tomas Winkler978785a2008-12-19 10:37:31 +08002211 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
2212 IWL_UCODE_MAJOR(priv->ucode_ver),
2213 IWL_UCODE_MINOR(priv->ucode_ver),
2214 IWL_UCODE_API(priv->ucode_ver),
2215 IWL_UCODE_SERIAL(priv->ucode_ver));
2216
Reinette Chatre5ebeb5a2009-10-30 14:36:04 -07002217 snprintf(priv->hw->wiphy->fw_version,
2218 sizeof(priv->hw->wiphy->fw_version),
2219 "%u.%u.%u.%u",
2220 IWL_UCODE_MAJOR(priv->ucode_ver),
2221 IWL_UCODE_MINOR(priv->ucode_ver),
2222 IWL_UCODE_API(priv->ucode_ver),
2223 IWL_UCODE_SERIAL(priv->ucode_ver));
2224
Tomas Winklere1623442009-01-27 14:27:56 -08002225 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002226 priv->ucode_ver);
Tomas Winklere1623442009-01-27 14:27:56 -08002227 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
2228 inst_size);
2229 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
2230 data_size);
2231 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
2232 init_size);
2233 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
2234 init_data_size);
2235 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
2236 boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07002237
Reinette Chatrea0987a82008-12-02 12:14:06 -08002238
Zhu Yib481de92007-09-25 17:54:57 -07002239 /* Verify size of file vs. image size info in file's header */
Johannes Berg93b1a2f2010-04-28 12:09:13 -07002240 if (ucode_raw->size != iwl3945_ucode_get_header_size(api_ver) +
Zhu Yib481de92007-09-25 17:54:57 -07002241 inst_size + data_size + init_size +
2242 init_data_size + boot_size) {
2243
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002244 IWL_DEBUG_INFO(priv,
2245 "uCode file size %zd does not match expected size\n",
2246 ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002247 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002248 goto err_release;
2249 }
2250
2251 /* Verify that uCode images will fit in card's SRAM */
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002252 if (inst_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002253 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002254 inst_size);
2255 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002256 goto err_release;
2257 }
2258
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002259 if (data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002260 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002261 data_size);
2262 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002263 goto err_release;
2264 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002265 if (init_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002266 IWL_DEBUG_INFO(priv,
2267 "uCode init instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002268 init_size);
2269 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002270 goto err_release;
2271 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002272 if (init_data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002273 IWL_DEBUG_INFO(priv,
2274 "uCode init data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002275 init_data_size);
2276 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002277 goto err_release;
2278 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002279 if (boot_size > IWL39_MAX_BSM_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002280 IWL_DEBUG_INFO(priv,
2281 "uCode boot instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002282 boot_size);
2283 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002284 goto err_release;
2285 }
2286
2287 /* Allocate ucode buffers for card's bus-master loading ... */
2288
2289 /* Runtime instructions and 2 copies of data:
2290 * 1) unmodified from disk
2291 * 2) backup cache for save/restore during power-downs */
2292 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002293 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07002294
2295 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002296 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07002297
2298 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002299 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07002300
2301 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
Tomas Winkler90e759d2007-11-29 11:09:41 +08002302 !priv->ucode_data_backup.v_addr)
Zhu Yib481de92007-09-25 17:54:57 -07002303 goto err_pci_alloc;
2304
Tomas Winkler90e759d2007-11-29 11:09:41 +08002305 /* Initialization instructions and data */
2306 if (init_size && init_data_size) {
2307 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002308 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002309
2310 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002311 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002312
2313 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
2314 goto err_pci_alloc;
2315 }
2316
2317 /* Bootstrap (instructions only, no data) */
2318 if (boot_size) {
2319 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002320 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002321
2322 if (!priv->ucode_boot.v_addr)
2323 goto err_pci_alloc;
2324 }
2325
Zhu Yib481de92007-09-25 17:54:57 -07002326 /* Copy images into buffers for card's bus-master reads ... */
2327
2328 /* Runtime instructions (first block of data in file) */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002329 len = inst_size;
Tomas Winklere1623442009-01-27 14:27:56 -08002330 IWL_DEBUG_INFO(priv,
2331 "Copying (but not loading) uCode instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002332 memcpy(priv->ucode_code.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002333 src += len;
2334
Tomas Winklere1623442009-01-27 14:27:56 -08002335 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002336 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
2337
2338 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002339 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002340 len = data_size;
Tomas Winklere1623442009-01-27 14:27:56 -08002341 IWL_DEBUG_INFO(priv,
2342 "Copying (but not loading) uCode data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002343 memcpy(priv->ucode_data.v_addr, src, len);
2344 memcpy(priv->ucode_data_backup.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002345 src += len;
Zhu Yib481de92007-09-25 17:54:57 -07002346
2347 /* Initialization instructions (3rd block) */
2348 if (init_size) {
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002349 len = init_size;
Tomas Winklere1623442009-01-27 14:27:56 -08002350 IWL_DEBUG_INFO(priv,
2351 "Copying (but not loading) init instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002352 memcpy(priv->ucode_init.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002353 src += len;
Zhu Yib481de92007-09-25 17:54:57 -07002354 }
2355
2356 /* Initialization data (4th block) */
2357 if (init_data_size) {
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002358 len = init_data_size;
Tomas Winklere1623442009-01-27 14:27:56 -08002359 IWL_DEBUG_INFO(priv,
2360 "Copying (but not loading) init data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002361 memcpy(priv->ucode_init_data.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002362 src += len;
Zhu Yib481de92007-09-25 17:54:57 -07002363 }
2364
2365 /* Bootstrap instructions (5th block) */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002366 len = boot_size;
Tomas Winklere1623442009-01-27 14:27:56 -08002367 IWL_DEBUG_INFO(priv,
2368 "Copying (but not loading) boot instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002369 memcpy(priv->ucode_boot.v_addr, src, len);
2370
2371 /* We have our copies now, allow OS release its copies */
2372 release_firmware(ucode_raw);
2373 return 0;
2374
2375 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002376 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002377 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002378 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002379
2380 err_release:
2381 release_firmware(ucode_raw);
2382
2383 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08002384 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002385}
2386
2387
2388/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002389 * iwl3945_set_ucode_ptrs - Set uCode address location
Zhu Yib481de92007-09-25 17:54:57 -07002390 *
2391 * Tell initialization uCode where to find runtime uCode.
2392 *
2393 * BSM registers initially contain pointers to initialization uCode.
2394 * We need to replace them to load runtime uCode inst and data,
2395 * and to save runtime data when powering down.
2396 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002397static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002398{
2399 dma_addr_t pinst;
2400 dma_addr_t pdata;
Zhu Yib481de92007-09-25 17:54:57 -07002401
2402 /* bits 31:0 for 3945 */
2403 pinst = priv->ucode_code.p_addr;
2404 pdata = priv->ucode_data_backup.p_addr;
2405
Zhu Yib481de92007-09-25 17:54:57 -07002406 /* Tell bootstrap uCode where to find image to load */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002407 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
2408 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
2409 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002410 priv->ucode_data.len);
2411
Tomas Winklera96a27f2008-10-23 23:48:56 -07002412 /* Inst byte count must be last to set up, bit 31 signals uCode
Zhu Yib481de92007-09-25 17:54:57 -07002413 * that all new ptr/size info is in place */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002414 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002415 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
2416
Tomas Winklere1623442009-01-27 14:27:56 -08002417 IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002418
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07002419 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002420}
2421
2422/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002423 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002424 *
2425 * Called after REPLY_ALIVE notification received from "initialize" uCode.
2426 *
Zhu Yib481de92007-09-25 17:54:57 -07002427 * Tell "initialize" uCode to go ahead and load the runtime uCode.
Ben Cahill9fbab512007-11-29 11:09:47 +08002428 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002429static void iwl3945_init_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002430{
2431 /* Check alive response for "valid" sign from uCode */
2432 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
2433 /* We had an error bringing up the hardware, so take it
2434 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002435 IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002436 goto restart;
2437 }
2438
2439 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
2440 * This is a paranoid check, because we would not have gotten the
2441 * "initialize" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002442 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002443 /* Runtime instruction load was bad;
2444 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002445 IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002446 goto restart;
2447 }
2448
2449 /* Send pointers to protocol/runtime uCode image ... init code will
2450 * load and launch runtime uCode, which will send us another "Alive"
2451 * notification. */
Tomas Winklere1623442009-01-27 14:27:56 -08002452 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002453 if (iwl3945_set_ucode_ptrs(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002454 /* Runtime instruction load won't happen;
2455 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002456 IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002457 goto restart;
2458 }
2459 return;
2460
2461 restart:
2462 queue_work(priv->workqueue, &priv->restart);
2463}
2464
Zhu Yib481de92007-09-25 17:54:57 -07002465/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002466 * iwl3945_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002467 * from protocol/runtime uCode (initialization uCode's
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002468 * Alive gets handled by iwl3945_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07002469 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002470static void iwl3945_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002471{
Zhu Yib481de92007-09-25 17:54:57 -07002472 int thermal_spin = 0;
2473 u32 rfkill;
Johannes Berg246ed352010-08-23 10:46:32 +02002474 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Zhu Yib481de92007-09-25 17:54:57 -07002475
Tomas Winklere1623442009-01-27 14:27:56 -08002476 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002477
2478 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
2479 /* We had an error bringing up the hardware, so take it
2480 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002481 IWL_DEBUG_INFO(priv, "Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002482 goto restart;
2483 }
2484
2485 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2486 * This is a paranoid check, because we would not have gotten the
2487 * "runtime" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002488 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002489 /* Runtime instruction load was bad;
2490 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002491 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002492 goto restart;
2493 }
2494
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002495 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
Tomas Winklere1623442009-01-27 14:27:56 -08002496 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
Zhu Yib481de92007-09-25 17:54:57 -07002497
2498 if (rfkill & 0x1) {
2499 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winklera96a27f2008-10-23 23:48:56 -07002500 /* if RFKILL is not on, then wait for thermal
Zhu Yib481de92007-09-25 17:54:57 -07002501 * sensor in adapter to kick in */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002502 while (iwl3945_hw_get_temperature(priv) == 0) {
Zhu Yib481de92007-09-25 17:54:57 -07002503 thermal_spin++;
2504 udelay(10);
2505 }
2506
2507 if (thermal_spin)
Tomas Winklere1623442009-01-27 14:27:56 -08002508 IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n",
Zhu Yib481de92007-09-25 17:54:57 -07002509 thermal_spin * 10);
2510 } else
2511 set_bit(STATUS_RF_KILL_HW, &priv->status);
2512
Ben Cahill9fbab512007-11-29 11:09:47 +08002513 /* After the ALIVE response, we can send commands to 3945 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07002514 set_bit(STATUS_ALIVE, &priv->status);
2515
Wey-Yi Guyb74e31a2010-03-01 17:23:50 -08002516 if (priv->cfg->ops->lib->recover_from_tx_stall) {
2517 /* Enable timer to monitor the driver queues */
2518 mod_timer(&priv->monitor_recover,
2519 jiffies +
2520 msecs_to_jiffies(priv->cfg->monitor_recover_period));
2521 }
2522
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002523 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002524 return;
2525
Johannes Berg36d68252008-05-15 12:55:26 +02002526 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002527
Johannes Berg470ab2d2010-01-21 11:23:30 -08002528 priv->active_rate = IWL_RATES_MASK;
Zhu Yib481de92007-09-25 17:54:57 -07002529
Ben Cahill4d6ccbf2009-11-13 11:56:29 -08002530 iwl_power_update_mode(priv, true);
Zhu Yib481de92007-09-25 17:54:57 -07002531
Johannes Berg246ed352010-08-23 10:46:32 +02002532 if (iwl_is_associated(priv, IWL_RXON_CTX_BSS)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002533 struct iwl3945_rxon_cmd *active_rxon =
Johannes Berg246ed352010-08-23 10:46:32 +02002534 (struct iwl3945_rxon_cmd *)(&ctx->active);
Zhu Yib481de92007-09-25 17:54:57 -07002535
Johannes Berg246ed352010-08-23 10:46:32 +02002536 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07002537 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2538 } else {
2539 /* Initialize our rx_config data */
Johannes Berg1dda6d22010-04-29 04:43:06 -07002540 iwl_connection_init_rx_config(priv, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07002541 }
2542
Ben Cahill9fbab512007-11-29 11:09:47 +08002543 /* Configure Bluetooth device coexistence support */
Johannes Berg65b52bd2010-04-13 01:04:31 -07002544 priv->cfg->ops->hcmd->send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002545
2546 /* Configure the adapter for unassociated operation */
Johannes Berg246ed352010-08-23 10:46:32 +02002547 iwlcore_commit_rxon(priv, ctx);
Zhu Yib481de92007-09-25 17:54:57 -07002548
Zhu Yib481de92007-09-25 17:54:57 -07002549 iwl3945_reg_txpower_periodic(priv);
2550
Johannes Berge932a602009-10-02 13:44:03 -07002551 iwl_leds_init(priv);
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07002552
Tomas Winklere1623442009-01-27 14:27:56 -08002553 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07002554 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002555 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07002556
Zhu Yib481de92007-09-25 17:54:57 -07002557 return;
2558
2559 restart:
2560 queue_work(priv->workqueue, &priv->restart);
2561}
2562
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002563static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07002564
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002565static void __iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002566{
2567 unsigned long flags;
2568 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
2569 struct ieee80211_conf *conf = NULL;
2570
Tomas Winklere1623442009-01-27 14:27:56 -08002571 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07002572
2573 conf = ieee80211_get_hw_conf(priv->hw);
2574
2575 if (!exit_pending)
2576 set_bit(STATUS_EXIT_PENDING, &priv->status);
2577
Stanislaw Gruszkab62177a2010-08-20 15:23:47 +02002578 /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
2579 * to prevent rearm timer */
2580 if (priv->cfg->ops->lib->recover_from_tx_stall)
2581 del_timer_sync(&priv->monitor_recover);
2582
Reinette Chatre7e246192010-02-18 22:58:32 -08002583 /* Station information will now be cleared in device */
Johannes Berg2c810cc2010-04-29 00:53:29 -07002584 iwl_clear_ucode_stations(priv);
Johannes Berga194e322010-08-27 08:53:46 -07002585 iwl_dealloc_bcast_stations(priv);
Johannes Bergdb125c72010-05-07 01:49:15 -07002586 iwl_clear_driver_stations(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002587
2588 /* Unblock any waiting calls */
2589 wake_up_interruptible_all(&priv->wait_command_queue);
2590
Zhu Yib481de92007-09-25 17:54:57 -07002591 /* Wipe out the EXIT_PENDING status bit if we are not actually
2592 * exiting the module */
2593 if (!exit_pending)
2594 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2595
2596 /* stop and reset the on-board processor */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002597 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07002598
2599 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002600 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002601 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002602 spin_unlock_irqrestore(&priv->lock, flags);
2603 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002604
2605 if (priv->mac80211_registered)
2606 ieee80211_stop_queues(priv->hw);
2607
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002608 /* If we have not previously called iwl3945_init() then
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002609 * clear all bits but the RF Kill bits and return */
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002610 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002611 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2612 STATUS_RF_KILL_HW |
Reinette Chatre97888642008-02-06 11:20:38 -08002613 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2614 STATUS_GEO_CONFIGURED |
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08002615 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2616 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002617 goto exit;
2618 }
2619
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002620 /* ...otherwise clear out all the status bits but the RF Kill
Johannes Berga60e77e2009-06-04 18:26:06 +02002621 * bit and continue taking the NIC down. */
Zhu Yib481de92007-09-25 17:54:57 -07002622 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2623 STATUS_RF_KILL_HW |
Reinette Chatre97888642008-02-06 11:20:38 -08002624 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2625 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002626 test_bit(STATUS_FW_ERROR, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08002627 STATUS_FW_ERROR |
2628 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2629 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002630
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002631 iwl3945_hw_txq_ctx_stop(priv);
2632 iwl3945_hw_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002633
Ben Cahill309e7312009-11-06 14:53:03 -08002634 /* Power-down device's busmaster DMA clocks */
2635 iwl_write_prph(priv, APMG_CLK_DIS_REG, APMG_CLK_VAL_DMA_CLK_RQT);
Zhu Yib481de92007-09-25 17:54:57 -07002636 udelay(5);
2637
Ben Cahill4d2ccdb2009-10-09 13:20:20 -07002638 /* Stop the device, and put it in low power state */
2639 priv->cfg->ops->lib->apm_ops.stop(priv);
Abbas, Mohamede9414b62009-01-20 21:33:55 -08002640
Zhu Yib481de92007-09-25 17:54:57 -07002641 exit:
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002642 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07002643
2644 if (priv->ibss_beacon)
2645 dev_kfree_skb(priv->ibss_beacon);
2646 priv->ibss_beacon = NULL;
2647
2648 /* clear out any free frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002649 iwl3945_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002650}
2651
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002652static void iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002653{
2654 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002655 __iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002656 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08002657
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002658 iwl3945_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002659}
2660
2661#define MAX_HW_RESTARTS 5
2662
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002663static int __iwl3945_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002664{
2665 int rc, i;
2666
Johannes Berga194e322010-08-27 08:53:46 -07002667 rc = iwl_alloc_bcast_station(priv, &priv->contexts[IWL_RXON_CTX_BSS],
2668 false);
Johannes Berg2c810cc2010-04-29 00:53:29 -07002669 if (rc)
2670 return rc;
2671
Zhu Yib481de92007-09-25 17:54:57 -07002672 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002673 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07002674 return -EIO;
2675 }
2676
Reinette Chatree903fbd2008-01-30 22:05:15 -08002677 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002678 IWL_ERR(priv, "ucode not available for device bring up\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08002679 return -EIO;
2680 }
2681
Zhu Yie655b9f2008-01-24 02:19:38 -08002682 /* If platform's RF_KILL switch is NOT set to KILL */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002683 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08002684 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
2685 clear_bit(STATUS_RF_KILL_HW, &priv->status);
2686 else {
2687 set_bit(STATUS_RF_KILL_HW, &priv->status);
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002688 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
2689 return -ENODEV;
Zhu Yib481de92007-09-25 17:54:57 -07002690 }
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002691
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002692 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07002693
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002694 rc = iwl3945_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002695 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002696 IWL_ERR(priv, "Unable to int nic\n");
Zhu Yib481de92007-09-25 17:54:57 -07002697 return rc;
2698 }
2699
2700 /* make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002701 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2702 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07002703 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2704
2705 /* clear (again), then enable host interrupts */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002706 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002707 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002708
2709 /* really make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002710 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2711 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07002712
2713 /* Copy original ucode data image from disk into backup cache.
2714 * This will be used to initialize the on-board processor's
2715 * data SRAM for a clean start when the runtime program first loads. */
2716 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a66926a2008-01-14 17:46:18 -08002717 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07002718
Zhu Yie655b9f2008-01-24 02:19:38 -08002719 /* We return success when we resume from suspend and rf_kill is on. */
2720 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
2721 return 0;
2722
Zhu Yib481de92007-09-25 17:54:57 -07002723 for (i = 0; i < MAX_HW_RESTARTS; i++) {
2724
Zhu Yib481de92007-09-25 17:54:57 -07002725 /* load bootstrap state machine,
2726 * load bootstrap program into processor's memory,
2727 * prepare to load the "initialize" uCode */
Abhijeet Kolekar75a9a922010-02-26 15:17:01 -08002728 rc = priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002729
2730 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002731 IWL_ERR(priv,
2732 "Unable to set up bootstrap uCode: %d\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -07002733 continue;
2734 }
2735
2736 /* start card; "initialize" will load runtime ucode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002737 iwl3945_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002738
Tomas Winklere1623442009-01-27 14:27:56 -08002739 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
Zhu Yib481de92007-09-25 17:54:57 -07002740
2741 return 0;
2742 }
2743
2744 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002745 __iwl3945_down(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08002746 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002747
2748 /* tried to restart and config the device for as long as our
2749 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002750 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07002751 return -EIO;
2752}
2753
2754
2755/*****************************************************************************
2756 *
2757 * Workqueue callbacks
2758 *
2759 *****************************************************************************/
2760
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002761static void iwl3945_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002762{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002763 struct iwl_priv *priv =
2764 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002765
2766 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2767 return;
2768
2769 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002770 iwl3945_init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002771 mutex_unlock(&priv->mutex);
2772}
2773
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002774static void iwl3945_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002775{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002776 struct iwl_priv *priv =
2777 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002778
2779 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2780 return;
2781
2782 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002783 iwl3945_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002784 mutex_unlock(&priv->mutex);
2785}
2786
Ben Cahill743cdf12009-10-09 13:20:26 -07002787/*
2788 * 3945 cannot interrupt driver when hardware rf kill switch toggles;
2789 * driver must poll CSR_GP_CNTRL_REG register for change. This register
2790 * *is* readable even when device has been SW_RESET into low power mode
2791 * (e.g. during RF KILL).
2792 */
Helmut Schaa26635162009-01-15 09:38:44 +01002793static void iwl3945_rfkill_poll(struct work_struct *data)
2794{
2795 struct iwl_priv *priv =
Johannes Bergee525d12010-01-21 06:09:28 -08002796 container_of(data, struct iwl_priv, _3945.rfkill_poll.work);
Ben Cahill743cdf12009-10-09 13:20:26 -07002797 bool old_rfkill = test_bit(STATUS_RF_KILL_HW, &priv->status);
2798 bool new_rfkill = !(iwl_read32(priv, CSR_GP_CNTRL)
2799 & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW);
Helmut Schaa26635162009-01-15 09:38:44 +01002800
Ben Cahill743cdf12009-10-09 13:20:26 -07002801 if (new_rfkill != old_rfkill) {
2802 if (new_rfkill)
2803 set_bit(STATUS_RF_KILL_HW, &priv->status);
2804 else
2805 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Helmut Schaa26635162009-01-15 09:38:44 +01002806
Ben Cahill743cdf12009-10-09 13:20:26 -07002807 wiphy_rfkill_set_hw_state(priv->hw->wiphy, new_rfkill);
Helmut Schaa26635162009-01-15 09:38:44 +01002808
Ben Cahill743cdf12009-10-09 13:20:26 -07002809 IWL_DEBUG_RF_KILL(priv, "RF_KILL bit toggled to %s.\n",
2810 new_rfkill ? "disable radio" : "enable radio");
2811 }
2812
2813 /* Keep this running, even if radio now enabled. This will be
2814 * cancelled in mac_start() if system decides to start again */
Johannes Bergee525d12010-01-21 06:09:28 -08002815 queue_delayed_work(priv->workqueue, &priv->_3945.rfkill_poll,
Helmut Schaa26635162009-01-15 09:38:44 +01002816 round_jiffies_relative(2 * HZ));
2817
2818}
2819
Johannes Berg1dda6d22010-04-29 04:43:06 -07002820void iwl3945_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
Zhu Yib481de92007-09-25 17:54:57 -07002821{
Winkler, Tomasc2d79b482008-12-19 10:37:34 +08002822 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07002823 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002824 .len = sizeof(struct iwl3945_scan_cmd),
Johannes Bergc2acea82009-07-24 11:13:05 -07002825 .flags = CMD_SIZE_HUGE,
Zhu Yib481de92007-09-25 17:54:57 -07002826 };
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002827 struct iwl3945_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07002828 struct ieee80211_conf *conf = NULL;
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002829 u8 n_probes = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01002830 enum ieee80211_band band;
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002831 bool is_active = false;
Zhu Yib481de92007-09-25 17:54:57 -07002832
2833 conf = ieee80211_get_hw_conf(priv->hw);
2834
Reinette Chatrefbc9f972009-05-15 16:13:46 -07002835 cancel_delayed_work(&priv->scan_check);
2836
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002837 if (!iwl_is_ready(priv)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002838 IWL_WARN(priv, "request scan called when driver not ready.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002839 goto done;
2840 }
2841
Tomas Winklera96a27f2008-10-23 23:48:56 -07002842 /* Make sure the scan wasn't canceled before this queued work
Zhu Yib481de92007-09-25 17:54:57 -07002843 * was given the chance to run... */
2844 if (!test_bit(STATUS_SCANNING, &priv->status))
2845 goto done;
2846
2847 /* This should never be called or scheduled if there is currently
2848 * a scan active in the hardware. */
2849 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002850 IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests "
2851 "Ignoring second request.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002852 goto done;
2853 }
2854
2855 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002856 IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n");
Zhu Yib481de92007-09-25 17:54:57 -07002857 goto done;
2858 }
2859
2860 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002861 IWL_DEBUG_HC(priv,
2862 "Scan request while abort pending. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002863 goto done;
2864 }
2865
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002866 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002867 IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n");
Zhu Yib481de92007-09-25 17:54:57 -07002868 goto done;
2869 }
2870
2871 if (!test_bit(STATUS_READY, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002872 IWL_DEBUG_HC(priv,
2873 "Scan request while uninitialized. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002874 goto done;
2875 }
2876
Johannes Berg811ecc92010-04-06 04:12:41 -07002877 if (!priv->scan_cmd) {
2878 priv->scan_cmd = kmalloc(sizeof(struct iwl3945_scan_cmd) +
2879 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
2880 if (!priv->scan_cmd) {
Wey-Yi Guy4f4d4082010-02-24 08:28:30 -08002881 IWL_DEBUG_SCAN(priv, "Fail to allocate scan memory\n");
Zhu Yib481de92007-09-25 17:54:57 -07002882 goto done;
2883 }
2884 }
Johannes Berg811ecc92010-04-06 04:12:41 -07002885 scan = priv->scan_cmd;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002886 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07002887
2888 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
2889 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
2890
Johannes Berg246ed352010-08-23 10:46:32 +02002891 if (iwl_is_associated(priv, IWL_RXON_CTX_BSS)) {
Zhu Yib481de92007-09-25 17:54:57 -07002892 u16 interval = 0;
2893 u32 extra;
2894 u32 suspend_time = 100;
2895 u32 scan_suspend_time = 100;
2896 unsigned long flags;
2897
Tomas Winklere1623442009-01-27 14:27:56 -08002898 IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
Zhu Yib481de92007-09-25 17:54:57 -07002899
2900 spin_lock_irqsave(&priv->lock, flags);
John W. Linvillea6e492b2010-07-22 15:24:56 -04002901 if (priv->is_internal_short_scan)
2902 interval = 0;
2903 else
2904 interval = vif->bss_conf.beacon_int;
Zhu Yib481de92007-09-25 17:54:57 -07002905 spin_unlock_irqrestore(&priv->lock, flags);
2906
2907 scan->suspend_time = 0;
Mohamed Abbas15e869d2007-10-25 17:15:46 +08002908 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07002909 if (!interval)
2910 interval = suspend_time;
2911 /*
2912 * suspend time format:
2913 * 0-19: beacon interval in usec (time before exec.)
2914 * 20-23: 0
2915 * 24-31: number of beacons (suspend between channels)
2916 */
2917
2918 extra = (suspend_time / interval) << 24;
2919 scan_suspend_time = 0xFF0FFFFF &
2920 (extra | ((suspend_time % interval) * 1024));
2921
2922 scan->suspend_time = cpu_to_le32(scan_suspend_time);
Tomas Winklere1623442009-01-27 14:27:56 -08002923 IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07002924 scan_suspend_time, interval);
2925 }
2926
Wey-Yi Guy4f4d4082010-02-24 08:28:30 -08002927 if (priv->is_internal_short_scan) {
2928 IWL_DEBUG_SCAN(priv, "Start internal passive scan.\n");
2929 } else if (priv->scan_request->n_ssids) {
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002930 int i, p = 0;
2931 IWL_DEBUG_SCAN(priv, "Kicking off active scan\n");
2932 for (i = 0; i < priv->scan_request->n_ssids; i++) {
2933 /* always does wildcard anyway */
2934 if (!priv->scan_request->ssids[i].ssid_len)
2935 continue;
2936 scan->direct_scan[p].id = WLAN_EID_SSID;
2937 scan->direct_scan[p].len =
2938 priv->scan_request->ssids[i].ssid_len;
2939 memcpy(scan->direct_scan[p].ssid,
2940 priv->scan_request->ssids[i].ssid,
2941 priv->scan_request->ssids[i].ssid_len);
2942 n_probes++;
2943 p++;
2944 }
2945 is_active = true;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08002946 } else
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002947 IWL_DEBUG_SCAN(priv, "Kicking off passive scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002948
2949 /* We don't build a direct scan probe request; the uCode will do
2950 * that based on the direct_mask added to each channel entry */
Zhu Yib481de92007-09-25 17:54:57 -07002951 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
Johannes Berga194e322010-08-27 08:53:46 -07002952 scan->tx_cmd.sta_id = priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07002953 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
2954
2955 /* flags + rate selection */
2956
Johannes Berg00700ee2010-04-06 04:12:37 -07002957 switch (priv->scan_band) {
2958 case IEEE80211_BAND_2GHZ:
Zhu Yib481de92007-09-25 17:54:57 -07002959 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
2960 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
2961 scan->good_CRC_th = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01002962 band = IEEE80211_BAND_2GHZ;
Johannes Berg00700ee2010-04-06 04:12:37 -07002963 break;
2964 case IEEE80211_BAND_5GHZ:
Zhu Yib481de92007-09-25 17:54:57 -07002965 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
Johannes Bergb097ad22009-04-20 14:36:57 -07002966 /*
2967 * If active scaning is requested but a certain channel
2968 * is marked passive, we can do active scanning if we
2969 * detect transmissions.
2970 */
Johannes Berg96ff5642010-04-30 14:42:15 -07002971 scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT :
2972 IWL_GOOD_CRC_TH_DISABLED;
Johannes Berg8318d782008-01-24 19:38:38 +01002973 band = IEEE80211_BAND_5GHZ;
Johannes Berg00700ee2010-04-06 04:12:37 -07002974 break;
2975 default:
2976 IWL_WARN(priv, "Invalid scan band\n");
Zhu Yib481de92007-09-25 17:54:57 -07002977 goto done;
2978 }
2979
Wey-Yi Guy4f4d4082010-02-24 08:28:30 -08002980 if (!priv->is_internal_short_scan) {
2981 scan->tx_cmd.len = cpu_to_le16(
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002982 iwl_fill_probe_req(priv,
2983 (struct ieee80211_mgmt *)scan->data,
Johannes Berg3a0b9aa2010-05-12 03:33:12 -07002984 vif->addr,
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07002985 priv->scan_request->ie,
2986 priv->scan_request->ie_len,
2987 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
Wey-Yi Guy4f4d4082010-02-24 08:28:30 -08002988 } else {
Johannes Berg3a0b9aa2010-05-12 03:33:12 -07002989 /* use bcast addr, will not be transmitted but must be valid */
Wey-Yi Guy4f4d4082010-02-24 08:28:30 -08002990 scan->tx_cmd.len = cpu_to_le16(
2991 iwl_fill_probe_req(priv,
2992 (struct ieee80211_mgmt *)scan->data,
Johannes Berg3a0b9aa2010-05-12 03:33:12 -07002993 iwl_bcast_addr, NULL, 0,
Wey-Yi Guy4f4d4082010-02-24 08:28:30 -08002994 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
2995 }
Zhu Yib481de92007-09-25 17:54:57 -07002996 /* select Rx antennas */
2997 scan->flags |= iwl3945_get_antenna_flags(priv);
2998
Abhijeet Kolekar14023642010-06-02 21:15:10 -07002999 if (priv->is_internal_short_scan) {
3000 scan->channel_count =
3001 iwl3945_get_single_channel_for_scan(priv, vif, band,
3002 (void *)&scan->data[le16_to_cpu(
3003 scan->tx_cmd.len)]);
3004 } else {
3005 scan->channel_count =
3006 iwl3945_get_channels_for_scan(priv, band, is_active, n_probes,
3007 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)], vif);
3008 }
Zhu Yib481de92007-09-25 17:54:57 -07003009
Reinette Chatre14b54332008-11-04 12:21:35 -08003010 if (scan->channel_count == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08003011 IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
Reinette Chatre14b54332008-11-04 12:21:35 -08003012 goto done;
3013 }
3014
Zhu Yib481de92007-09-25 17:54:57 -07003015 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003016 scan->channel_count * sizeof(struct iwl3945_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07003017 cmd.data = scan;
3018 scan->len = cpu_to_le16(cmd.len);
3019
3020 set_bit(STATUS_SCAN_HW, &priv->status);
Wey-Yi Guy4f4d4082010-02-24 08:28:30 -08003021 if (iwl_send_cmd_sync(priv, &cmd))
Zhu Yib481de92007-09-25 17:54:57 -07003022 goto done;
3023
3024 queue_delayed_work(priv->workqueue, &priv->scan_check,
3025 IWL_SCAN_CHECK_WATCHDOG);
3026
Zhu Yib481de92007-09-25 17:54:57 -07003027 return;
3028
3029 done:
Mohamed Abbas2420ebc2008-11-04 12:21:34 -08003030 /* can not perform scan make sure we clear scanning
3031 * bits from status so next scan request can be performed.
3032 * if we dont clear scanning status bit here all next scan
3033 * will fail
3034 */
3035 clear_bit(STATUS_SCAN_HW, &priv->status);
3036 clear_bit(STATUS_SCANNING, &priv->status);
3037
Ian Schram01ebd062007-10-25 17:15:22 +08003038 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07003039 queue_work(priv->workqueue, &priv->scan_completed);
Zhu Yib481de92007-09-25 17:54:57 -07003040}
3041
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003042static void iwl3945_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003043{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003044 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07003045
3046 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3047 return;
3048
Johannes Berg19cc1082009-05-08 13:44:36 -07003049 if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
3050 mutex_lock(&priv->mutex);
3051 priv->vif = NULL;
3052 priv->is_open = 0;
3053 mutex_unlock(&priv->mutex);
3054 iwl3945_down(priv);
3055 ieee80211_restart_hw(priv->hw);
3056 } else {
3057 iwl3945_down(priv);
Johannes Berg80676512010-01-21 06:07:17 -08003058
3059 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3060 return;
3061
3062 mutex_lock(&priv->mutex);
3063 __iwl3945_up(priv);
3064 mutex_unlock(&priv->mutex);
Johannes Berg19cc1082009-05-08 13:44:36 -07003065 }
Zhu Yib481de92007-09-25 17:54:57 -07003066}
3067
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003068static void iwl3945_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003069{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003070 struct iwl_priv *priv =
3071 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07003072
3073 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3074 return;
3075
3076 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003077 iwl3945_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003078 mutex_unlock(&priv->mutex);
3079}
3080
Johannes Berg1dda6d22010-04-29 04:43:06 -07003081void iwl3945_post_associate(struct iwl_priv *priv, struct ieee80211_vif *vif)
Zhu Yib481de92007-09-25 17:54:57 -07003082{
Zhu Yib481de92007-09-25 17:54:57 -07003083 int rc = 0;
3084 struct ieee80211_conf *conf = NULL;
Johannes Berg246ed352010-08-23 10:46:32 +02003085 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Zhu Yib481de92007-09-25 17:54:57 -07003086
Johannes Berg1dda6d22010-04-29 04:43:06 -07003087 if (!vif || !priv->is_open)
3088 return;
3089
3090 if (vif->type == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003091 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07003092 return;
3093 }
3094
Tomas Winklere1623442009-01-27 14:27:56 -08003095 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
Johannes Berg246ed352010-08-23 10:46:32 +02003096 vif->bss_conf.aid, ctx->active.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07003097
3098 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3099 return;
3100
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003101 iwl_scan_cancel_timeout(priv, 200);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003102
Zhu Yib481de92007-09-25 17:54:57 -07003103 conf = ieee80211_get_hw_conf(priv->hw);
3104
Johannes Berg246ed352010-08-23 10:46:32 +02003105 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3106 iwlcore_commit_rxon(priv, ctx);
Zhu Yib481de92007-09-25 17:54:57 -07003107
Johannes Berg948f5a22010-07-29 07:07:51 -07003108 rc = iwl_send_rxon_timing(priv, vif);
Zhu Yib481de92007-09-25 17:54:57 -07003109 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003110 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003111 "Attempting to continue.\n");
3112
Johannes Berg246ed352010-08-23 10:46:32 +02003113 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003114
Johannes Berg246ed352010-08-23 10:46:32 +02003115 ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
Zhu Yib481de92007-09-25 17:54:57 -07003116
Tomas Winklere1623442009-01-27 14:27:56 -08003117 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
Johannes Berg1dda6d22010-04-29 04:43:06 -07003118 vif->bss_conf.aid, vif->bss_conf.beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -07003119
Johannes Bergc213d742010-05-06 12:21:40 -07003120 if (vif->bss_conf.use_short_preamble)
Johannes Berg246ed352010-08-23 10:46:32 +02003121 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003122 else
Johannes Berg246ed352010-08-23 10:46:32 +02003123 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003124
Johannes Berg246ed352010-08-23 10:46:32 +02003125 if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) {
Johannes Bergc213d742010-05-06 12:21:40 -07003126 if (vif->bss_conf.use_short_slot)
Johannes Berg246ed352010-08-23 10:46:32 +02003127 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003128 else
Johannes Berg246ed352010-08-23 10:46:32 +02003129 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003130 }
3131
Johannes Berg246ed352010-08-23 10:46:32 +02003132 iwlcore_commit_rxon(priv, ctx);
Zhu Yib481de92007-09-25 17:54:57 -07003133
Johannes Berg1dda6d22010-04-29 04:43:06 -07003134 switch (vif->type) {
Johannes Berg05c914f2008-09-11 00:01:58 +02003135 case NL80211_IFTYPE_STATION:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003136 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07003137 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02003138 case NL80211_IFTYPE_ADHOC:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003139 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003140 break;
Zhu Yib481de92007-09-25 17:54:57 -07003141 default:
Johannes Berg1dda6d22010-04-29 04:43:06 -07003142 IWL_ERR(priv, "%s Should not be called in %d mode\n",
3143 __func__, vif->type);
Zhu Yib481de92007-09-25 17:54:57 -07003144 break;
3145 }
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08003146}
3147
Zhu Yib481de92007-09-25 17:54:57 -07003148/*****************************************************************************
3149 *
3150 * mac80211 entry point functions
3151 *
3152 *****************************************************************************/
3153
Zhu Yi5a66926a2008-01-14 17:46:18 -08003154#define UCODE_READY_TIMEOUT (2 * HZ)
3155
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003156static int iwl3945_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003157{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003158 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003159 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003160
Tomas Winklere1623442009-01-27 14:27:56 -08003161 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003162
3163 /* we should be verifying the device is ready to be opened */
3164 mutex_lock(&priv->mutex);
3165
Zhu Yi5a66926a2008-01-14 17:46:18 -08003166 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
3167 * ucode filename and max sizes are card-specific. */
3168
3169 if (!priv->ucode_code.len) {
3170 ret = iwl3945_read_ucode(priv);
3171 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003172 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003173 mutex_unlock(&priv->mutex);
3174 goto out_release_irq;
3175 }
3176 }
3177
Zhu Yie655b9f2008-01-24 02:19:38 -08003178 ret = __iwl3945_up(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003179
Zhu Yib481de92007-09-25 17:54:57 -07003180 mutex_unlock(&priv->mutex);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003181
Zhu Yie655b9f2008-01-24 02:19:38 -08003182 if (ret)
3183 goto out_release_irq;
3184
Tomas Winklere1623442009-01-27 14:27:56 -08003185 IWL_DEBUG_INFO(priv, "Start UP work.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003186
Zhu Yi5a66926a2008-01-14 17:46:18 -08003187 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
3188 * mac80211 will not be run successfully. */
3189 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
3190 test_bit(STATUS_READY, &priv->status),
3191 UCODE_READY_TIMEOUT);
3192 if (!ret) {
3193 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003194 IWL_ERR(priv,
3195 "Wait for START_ALIVE timeout after %dms.\n",
3196 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Zhu Yi5a66926a2008-01-14 17:46:18 -08003197 ret = -ETIMEDOUT;
3198 goto out_release_irq;
3199 }
3200 }
3201
Helmut Schaa26635162009-01-15 09:38:44 +01003202 /* ucode is running and will send rfkill notifications,
3203 * no need to poll the killswitch state anymore */
Johannes Bergee525d12010-01-21 06:09:28 -08003204 cancel_delayed_work(&priv->_3945.rfkill_poll);
Helmut Schaa26635162009-01-15 09:38:44 +01003205
Johannes Berge932a602009-10-02 13:44:03 -07003206 iwl_led_start(priv);
3207
Zhu Yie655b9f2008-01-24 02:19:38 -08003208 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08003209 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003210 return 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003211
3212out_release_irq:
Zhu Yie655b9f2008-01-24 02:19:38 -08003213 priv->is_open = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08003214 IWL_DEBUG_MAC80211(priv, "leave - failed\n");
Zhu Yi5a66926a2008-01-14 17:46:18 -08003215 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003216}
3217
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003218static void iwl3945_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003219{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003220 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003221
Tomas Winklere1623442009-01-27 14:27:56 -08003222 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003223
Zhu Yie655b9f2008-01-24 02:19:38 -08003224 if (!priv->is_open) {
Tomas Winklere1623442009-01-27 14:27:56 -08003225 IWL_DEBUG_MAC80211(priv, "leave - skip\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003226 return;
3227 }
3228
Zhu Yib481de92007-09-25 17:54:57 -07003229 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003230
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003231 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08003232 /* stop mac, cancel any scan request and clear
3233 * RXON_FILTER_ASSOC_MSK BIT
3234 */
Zhu Yi5a66926a2008-01-14 17:46:18 -08003235 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003236 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003237 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003238 }
3239
Zhu Yi5a66926a2008-01-14 17:46:18 -08003240 iwl3945_down(priv);
3241
3242 flush_workqueue(priv->workqueue);
Helmut Schaa26635162009-01-15 09:38:44 +01003243
3244 /* start polling the killswitch state again */
Johannes Bergee525d12010-01-21 06:09:28 -08003245 queue_delayed_work(priv->workqueue, &priv->_3945.rfkill_poll,
Helmut Schaa26635162009-01-15 09:38:44 +01003246 round_jiffies_relative(2 * HZ));
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003247
Tomas Winklere1623442009-01-27 14:27:56 -08003248 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003249}
3250
Johannes Berge039fa42008-05-15 12:55:29 +02003251static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003252{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003253 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003254
Tomas Winklere1623442009-01-27 14:27:56 -08003255 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003256
Tomas Winklere1623442009-01-27 14:27:56 -08003257 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02003258 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07003259
Johannes Berge039fa42008-05-15 12:55:29 +02003260 if (iwl3945_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07003261 dev_kfree_skb_any(skb);
3262
Tomas Winklere1623442009-01-27 14:27:56 -08003263 IWL_DEBUG_MAC80211(priv, "leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08003264 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07003265}
3266
Johannes Berg1dda6d22010-04-29 04:43:06 -07003267void iwl3945_config_ap(struct iwl_priv *priv, struct ieee80211_vif *vif)
Zhu Yib481de92007-09-25 17:54:57 -07003268{
Johannes Berg246ed352010-08-23 10:46:32 +02003269 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Zhu Yib481de92007-09-25 17:54:57 -07003270 int rc = 0;
3271
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08003272 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07003273 return;
3274
3275 /* The following should be done only at AP bring up */
Johannes Berg246ed352010-08-23 10:46:32 +02003276 if (!(iwl_is_associated(priv, IWL_RXON_CTX_BSS))) {
Zhu Yib481de92007-09-25 17:54:57 -07003277
3278 /* RXON - unassoc (to set timing command) */
Johannes Berg246ed352010-08-23 10:46:32 +02003279 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3280 iwlcore_commit_rxon(priv, ctx);
Zhu Yib481de92007-09-25 17:54:57 -07003281
3282 /* RXON Timing */
Johannes Berg948f5a22010-07-29 07:07:51 -07003283 rc = iwl_send_rxon_timing(priv, vif);
Zhu Yib481de92007-09-25 17:54:57 -07003284 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003285 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003286 "Attempting to continue.\n");
3287
Johannes Berg246ed352010-08-23 10:46:32 +02003288 ctx->staging.assoc_id = 0;
Johannes Berg1dda6d22010-04-29 04:43:06 -07003289
Johannes Bergc213d742010-05-06 12:21:40 -07003290 if (vif->bss_conf.use_short_preamble)
Johannes Berg246ed352010-08-23 10:46:32 +02003291 ctx->staging.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003292 RXON_FLG_SHORT_PREAMBLE_MSK;
3293 else
Johannes Berg246ed352010-08-23 10:46:32 +02003294 ctx->staging.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003295 ~RXON_FLG_SHORT_PREAMBLE_MSK;
3296
Johannes Berg246ed352010-08-23 10:46:32 +02003297 if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) {
Johannes Bergc213d742010-05-06 12:21:40 -07003298 if (vif->bss_conf.use_short_slot)
Johannes Berg246ed352010-08-23 10:46:32 +02003299 ctx->staging.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003300 RXON_FLG_SHORT_SLOT_MSK;
3301 else
Johannes Berg246ed352010-08-23 10:46:32 +02003302 ctx->staging.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003303 ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003304 }
3305 /* restore RXON assoc */
Johannes Berg246ed352010-08-23 10:46:32 +02003306 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
3307 iwlcore_commit_rxon(priv, ctx);
Zhu Yi556f8db2007-09-27 11:27:33 +08003308 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003309 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003310
3311 /* FIXME - we need to add code here to detect a totally new
3312 * configuration, reset the AP, unassoc, rxon timing, assoc,
3313 * clear sta table, add BCAST sta... */
3314}
3315
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003316static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01003317 struct ieee80211_vif *vif,
3318 struct ieee80211_sta *sta,
3319 struct ieee80211_key_conf *key)
Zhu Yib481de92007-09-25 17:54:57 -07003320{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003321 struct iwl_priv *priv = hw->priv;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003322 int ret = 0;
3323 u8 sta_id = IWL_INVALID_STATION;
3324 u8 static_key;
Zhu Yib481de92007-09-25 17:54:57 -07003325
Tomas Winklere1623442009-01-27 14:27:56 -08003326 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003327
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08003328 if (iwl3945_mod_params.sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08003329 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07003330 return -EOPNOTSUPP;
3331 }
3332
Johannes Berg246ed352010-08-23 10:46:32 +02003333 static_key = !iwl_is_associated(priv, IWL_RXON_CTX_BSS);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003334
3335 if (!static_key) {
Johannes Berga194e322010-08-27 08:53:46 -07003336 sta_id = iwl_sta_id_or_broadcast(
3337 priv, &priv->contexts[IWL_RXON_CTX_BSS], sta);
Johannes Berg0af8bca2010-04-30 14:08:00 -07003338 if (sta_id == IWL_INVALID_STATION)
3339 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003340 }
3341
3342 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003343 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003344
Zhu Yib481de92007-09-25 17:54:57 -07003345 switch (cmd) {
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003346 case SET_KEY:
3347 if (static_key)
3348 ret = iwl3945_set_static_key(priv, key);
3349 else
3350 ret = iwl3945_set_dynamic_key(priv, key, sta_id);
3351 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003352 break;
3353 case DISABLE_KEY:
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003354 if (static_key)
3355 ret = iwl3945_remove_static_key(priv);
3356 else
3357 ret = iwl3945_clear_sta_key_info(priv, sta_id);
3358 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003359 break;
3360 default:
Winkler, Tomas42986792009-01-19 15:30:22 -08003361 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003362 }
3363
Johannes Berg72e15d72010-02-19 11:42:32 -08003364 mutex_unlock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08003365 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003366
Winkler, Tomas42986792009-01-19 15:30:22 -08003367 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003368}
3369
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003370static int iwl3945_mac_sta_add(struct ieee80211_hw *hw,
3371 struct ieee80211_vif *vif,
3372 struct ieee80211_sta *sta)
3373{
3374 struct iwl_priv *priv = hw->priv;
Johannes Bergfd1af152010-04-30 11:30:43 -07003375 struct iwl3945_sta_priv *sta_priv = (void *)sta->drv_priv;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003376 int ret;
Johannes Bergfd1af152010-04-30 11:30:43 -07003377 bool is_ap = vif->type == NL80211_IFTYPE_STATION;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003378 u8 sta_id;
3379
3380 IWL_DEBUG_INFO(priv, "received request to add station %pM\n",
3381 sta->addr);
Reinette Chatreda5ae1c2010-05-28 09:28:39 -07003382 mutex_lock(&priv->mutex);
3383 IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
3384 sta->addr);
3385 sta_priv->common.sta_id = IWL_INVALID_STATION;
3386
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003387
Johannes Berga194e322010-08-27 08:53:46 -07003388 ret = iwl_add_station_common(priv, &priv->contexts[IWL_RXON_CTX_BSS],
3389 sta->addr, is_ap, &sta->ht_cap, &sta_id);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003390 if (ret) {
3391 IWL_ERR(priv, "Unable to add station %pM (%d)\n",
3392 sta->addr, ret);
3393 /* Should we return success if return code is EEXIST ? */
Reinette Chatreda5ae1c2010-05-28 09:28:39 -07003394 mutex_unlock(&priv->mutex);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003395 return ret;
3396 }
3397
Johannes Bergfd1af152010-04-30 11:30:43 -07003398 sta_priv->common.sta_id = sta_id;
3399
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003400 /* Initialize rate scaling */
Frans Pop91dd6c22010-03-24 14:19:58 -07003401 IWL_DEBUG_INFO(priv, "Initializing rate scaling for station %pM\n",
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003402 sta->addr);
3403 iwl3945_rs_rate_init(priv, sta, sta_id);
Reinette Chatreda5ae1c2010-05-28 09:28:39 -07003404 mutex_unlock(&priv->mutex);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003405
3406 return 0;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003407}
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02003408
3409static void iwl3945_configure_filter(struct ieee80211_hw *hw,
3410 unsigned int changed_flags,
3411 unsigned int *total_flags,
3412 u64 multicast)
3413{
3414 struct iwl_priv *priv = hw->priv;
3415 __le32 filter_or = 0, filter_nand = 0;
Johannes Berg246ed352010-08-23 10:46:32 +02003416 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02003417
3418#define CHK(test, flag) do { \
3419 if (*total_flags & (test)) \
3420 filter_or |= (flag); \
3421 else \
3422 filter_nand |= (flag); \
3423 } while (0)
3424
3425 IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
3426 changed_flags, *total_flags);
3427
3428 CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
3429 CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK);
3430 CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
3431
3432#undef CHK
3433
3434 mutex_lock(&priv->mutex);
3435
Johannes Berg246ed352010-08-23 10:46:32 +02003436 ctx->staging.filter_flags &= ~filter_nand;
3437 ctx->staging.filter_flags |= filter_or;
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02003438
3439 /*
3440 * Committing directly here breaks for some reason,
3441 * but we'll eventually commit the filter flags
3442 * change anyway.
3443 */
3444
3445 mutex_unlock(&priv->mutex);
3446
3447 /*
3448 * Receiving all multicast frames is always enabled by the
3449 * default flags setup in iwl_connection_init_rx_config()
3450 * since we currently do not support programming multicast
3451 * filters into the device.
3452 */
3453 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
3454 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
3455}
3456
3457
Zhu Yib481de92007-09-25 17:54:57 -07003458/*****************************************************************************
3459 *
3460 * sysfs attributes
3461 *
3462 *****************************************************************************/
3463
Samuel Ortizd08853a2009-01-23 13:45:17 -08003464#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07003465
3466/*
3467 * The following adds a new attribute to the sysfs representation
3468 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
3469 * used for controlling the debug level.
3470 *
3471 * See the level definitions in iwl for details.
Reinette Chatrea562a9d2009-07-17 09:30:24 -07003472 *
Reinette Chatre3d816c72009-08-07 15:41:37 -07003473 * The debug_level being managed using sysfs below is a per device debug
3474 * level that is used instead of the global debug level if it (the per
3475 * device debug level) is set.
Zhu Yib481de92007-09-25 17:54:57 -07003476 */
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003477static ssize_t show_debug_level(struct device *d,
3478 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07003479{
Reinette Chatre3d816c72009-08-07 15:41:37 -07003480 struct iwl_priv *priv = dev_get_drvdata(d);
3481 return sprintf(buf, "0x%08X\n", iwl_get_debug_level(priv));
Zhu Yib481de92007-09-25 17:54:57 -07003482}
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003483static ssize_t store_debug_level(struct device *d,
3484 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07003485 const char *buf, size_t count)
3486{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003487 struct iwl_priv *priv = dev_get_drvdata(d);
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003488 unsigned long val;
3489 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003490
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003491 ret = strict_strtoul(buf, 0, &val);
3492 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08003493 IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003494 else {
Reinette Chatre3d816c72009-08-07 15:41:37 -07003495 priv->debug_level = val;
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003496 if (iwl_alloc_traffic_mem(priv))
3497 IWL_ERR(priv,
3498 "Not enough memory to generate traffic log\n");
3499 }
Zhu Yib481de92007-09-25 17:54:57 -07003500 return strnlen(buf, count);
3501}
3502
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003503static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
3504 show_debug_level, store_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07003505
Samuel Ortizd08853a2009-01-23 13:45:17 -08003506#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07003507
Zhu Yib481de92007-09-25 17:54:57 -07003508static ssize_t show_temperature(struct device *d,
3509 struct device_attribute *attr, char *buf)
3510{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003511 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003512
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003513 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003514 return -EAGAIN;
3515
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003516 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07003517}
3518
3519static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
3520
Zhu Yib481de92007-09-25 17:54:57 -07003521static ssize_t show_tx_power(struct device *d,
3522 struct device_attribute *attr, char *buf)
3523{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003524 struct iwl_priv *priv = dev_get_drvdata(d);
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08003525 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07003526}
3527
3528static ssize_t store_tx_power(struct device *d,
3529 struct device_attribute *attr,
3530 const char *buf, size_t count)
3531{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003532 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003533 char *p = (char *)buf;
3534 u32 val;
3535
3536 val = simple_strtoul(p, &p, 10);
3537 if (p == buf)
Tomas Winkler978785a2008-12-19 10:37:31 +08003538 IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07003539 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003540 iwl3945_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07003541
3542 return count;
3543}
3544
3545static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
3546
3547static ssize_t show_flags(struct device *d,
3548 struct device_attribute *attr, char *buf)
3549{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003550 struct iwl_priv *priv = dev_get_drvdata(d);
Johannes Berg246ed352010-08-23 10:46:32 +02003551 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Zhu Yib481de92007-09-25 17:54:57 -07003552
Johannes Berg246ed352010-08-23 10:46:32 +02003553 return sprintf(buf, "0x%04X\n", ctx->active.flags);
Zhu Yib481de92007-09-25 17:54:57 -07003554}
3555
3556static ssize_t store_flags(struct device *d,
3557 struct device_attribute *attr,
3558 const char *buf, size_t count)
3559{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003560 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003561 u32 flags = simple_strtoul(buf, NULL, 0);
Johannes Berg246ed352010-08-23 10:46:32 +02003562 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Zhu Yib481de92007-09-25 17:54:57 -07003563
3564 mutex_lock(&priv->mutex);
Johannes Berg246ed352010-08-23 10:46:32 +02003565 if (le32_to_cpu(ctx->staging.flags) != flags) {
Zhu Yib481de92007-09-25 17:54:57 -07003566 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003567 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003568 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003569 else {
Tomas Winklere1623442009-01-27 14:27:56 -08003570 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
Zhu Yib481de92007-09-25 17:54:57 -07003571 flags);
Johannes Berg246ed352010-08-23 10:46:32 +02003572 ctx->staging.flags = cpu_to_le32(flags);
3573 iwlcore_commit_rxon(priv, ctx);
Zhu Yib481de92007-09-25 17:54:57 -07003574 }
3575 }
3576 mutex_unlock(&priv->mutex);
3577
3578 return count;
3579}
3580
3581static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
3582
3583static ssize_t show_filter_flags(struct device *d,
3584 struct device_attribute *attr, char *buf)
3585{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003586 struct iwl_priv *priv = dev_get_drvdata(d);
Johannes Berg246ed352010-08-23 10:46:32 +02003587 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Zhu Yib481de92007-09-25 17:54:57 -07003588
3589 return sprintf(buf, "0x%04X\n",
Johannes Berg246ed352010-08-23 10:46:32 +02003590 le32_to_cpu(ctx->active.filter_flags));
Zhu Yib481de92007-09-25 17:54:57 -07003591}
3592
3593static ssize_t store_filter_flags(struct device *d,
3594 struct device_attribute *attr,
3595 const char *buf, size_t count)
3596{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003597 struct iwl_priv *priv = dev_get_drvdata(d);
Johannes Berg246ed352010-08-23 10:46:32 +02003598 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Zhu Yib481de92007-09-25 17:54:57 -07003599 u32 filter_flags = simple_strtoul(buf, NULL, 0);
3600
3601 mutex_lock(&priv->mutex);
Johannes Berg246ed352010-08-23 10:46:32 +02003602 if (le32_to_cpu(ctx->staging.filter_flags) != filter_flags) {
Zhu Yib481de92007-09-25 17:54:57 -07003603 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003604 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003605 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003606 else {
Tomas Winklere1623442009-01-27 14:27:56 -08003607 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
Zhu Yib481de92007-09-25 17:54:57 -07003608 "0x%04X\n", filter_flags);
Johannes Berg246ed352010-08-23 10:46:32 +02003609 ctx->staging.filter_flags =
Zhu Yib481de92007-09-25 17:54:57 -07003610 cpu_to_le32(filter_flags);
Johannes Berg246ed352010-08-23 10:46:32 +02003611 iwlcore_commit_rxon(priv, ctx);
Zhu Yib481de92007-09-25 17:54:57 -07003612 }
3613 }
3614 mutex_unlock(&priv->mutex);
3615
3616 return count;
3617}
3618
3619static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
3620 store_filter_flags);
3621
Zhu Yib481de92007-09-25 17:54:57 -07003622static ssize_t show_measurement(struct device *d,
3623 struct device_attribute *attr, char *buf)
3624{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003625 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler600c0e12008-12-19 10:37:04 +08003626 struct iwl_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07003627 u32 size = sizeof(measure_report), len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003628 u8 *data = (u8 *)&measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07003629 unsigned long flags;
3630
3631 spin_lock_irqsave(&priv->lock, flags);
3632 if (!(priv->measurement_status & MEASUREMENT_READY)) {
3633 spin_unlock_irqrestore(&priv->lock, flags);
3634 return 0;
3635 }
3636 memcpy(&measure_report, &priv->measure_report, size);
3637 priv->measurement_status = 0;
3638 spin_unlock_irqrestore(&priv->lock, flags);
3639
3640 while (size && (PAGE_SIZE - len)) {
3641 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
3642 PAGE_SIZE - len, 1);
3643 len = strlen(buf);
3644 if (PAGE_SIZE - len)
3645 buf[len++] = '\n';
3646
3647 ofs += 16;
3648 size -= min(size, 16U);
3649 }
3650
3651 return len;
3652}
3653
3654static ssize_t store_measurement(struct device *d,
3655 struct device_attribute *attr,
3656 const char *buf, size_t count)
3657{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003658 struct iwl_priv *priv = dev_get_drvdata(d);
Johannes Berg246ed352010-08-23 10:46:32 +02003659 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Zhu Yib481de92007-09-25 17:54:57 -07003660 struct ieee80211_measurement_params params = {
Johannes Berg246ed352010-08-23 10:46:32 +02003661 .channel = le16_to_cpu(ctx->active.channel),
Johannes Berge99f168c2010-01-19 10:04:28 -08003662 .start_time = cpu_to_le64(priv->_3945.last_tsf),
Zhu Yib481de92007-09-25 17:54:57 -07003663 .duration = cpu_to_le16(1),
3664 };
3665 u8 type = IWL_MEASURE_BASIC;
3666 u8 buffer[32];
3667 u8 channel;
3668
3669 if (count) {
3670 char *p = buffer;
3671 strncpy(buffer, buf, min(sizeof(buffer), count));
3672 channel = simple_strtoul(p, NULL, 0);
3673 if (channel)
3674 params.channel = channel;
3675
3676 p = buffer;
3677 while (*p && *p != ' ')
3678 p++;
3679 if (*p)
3680 type = simple_strtoul(p + 1, NULL, 0);
3681 }
3682
Tomas Winklere1623442009-01-27 14:27:56 -08003683 IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on "
Zhu Yib481de92007-09-25 17:54:57 -07003684 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003685 iwl3945_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07003686
3687 return count;
3688}
3689
3690static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
3691 show_measurement, store_measurement);
Zhu Yib481de92007-09-25 17:54:57 -07003692
Zhu Yib481de92007-09-25 17:54:57 -07003693static ssize_t store_retry_rate(struct device *d,
3694 struct device_attribute *attr,
3695 const char *buf, size_t count)
3696{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003697 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003698
3699 priv->retry_rate = simple_strtoul(buf, NULL, 0);
3700 if (priv->retry_rate <= 0)
3701 priv->retry_rate = 1;
3702
3703 return count;
3704}
3705
3706static ssize_t show_retry_rate(struct device *d,
3707 struct device_attribute *attr, char *buf)
3708{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003709 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003710 return sprintf(buf, "%d", priv->retry_rate);
3711}
3712
3713static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
3714 store_retry_rate);
3715
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08003716
Zhu Yib481de92007-09-25 17:54:57 -07003717static ssize_t show_channels(struct device *d,
3718 struct device_attribute *attr, char *buf)
3719{
Johannes Berg8318d782008-01-24 19:38:38 +01003720 /* all this shit doesn't belong into sysfs anyway */
3721 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07003722}
3723
3724static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
3725
Zhu Yib481de92007-09-25 17:54:57 -07003726static ssize_t show_antenna(struct device *d,
3727 struct device_attribute *attr, char *buf)
3728{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003729 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003730
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003731 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003732 return -EAGAIN;
3733
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08003734 return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
Zhu Yib481de92007-09-25 17:54:57 -07003735}
3736
3737static ssize_t store_antenna(struct device *d,
3738 struct device_attribute *attr,
3739 const char *buf, size_t count)
3740{
Winkler, Tomas7530f852009-01-27 14:27:53 -08003741 struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003742 int ant;
Zhu Yib481de92007-09-25 17:54:57 -07003743
3744 if (count == 0)
3745 return 0;
3746
3747 if (sscanf(buf, "%1i", &ant) != 1) {
Tomas Winklere1623442009-01-27 14:27:56 -08003748 IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003749 return count;
3750 }
3751
3752 if ((ant >= 0) && (ant <= 2)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003753 IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant);
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08003754 iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
Zhu Yib481de92007-09-25 17:54:57 -07003755 } else
Tomas Winklere1623442009-01-27 14:27:56 -08003756 IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant);
Zhu Yib481de92007-09-25 17:54:57 -07003757
3758
3759 return count;
3760}
3761
3762static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
3763
3764static ssize_t show_status(struct device *d,
3765 struct device_attribute *attr, char *buf)
3766{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003767 struct iwl_priv *priv = dev_get_drvdata(d);
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003768 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003769 return -EAGAIN;
3770 return sprintf(buf, "0x%08x\n", (int)priv->status);
3771}
3772
3773static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
3774
3775static ssize_t dump_error_log(struct device *d,
3776 struct device_attribute *attr,
3777 const char *buf, size_t count)
3778{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003779 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003780 char *p = (char *)buf;
3781
3782 if (p[0] == '1')
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003783 iwl3945_dump_nic_error_log(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003784
3785 return strnlen(buf, count);
3786}
3787
3788static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
3789
Zhu Yib481de92007-09-25 17:54:57 -07003790/*****************************************************************************
3791 *
Tomas Winklera96a27f2008-10-23 23:48:56 -07003792 * driver setup and tear down
Zhu Yib481de92007-09-25 17:54:57 -07003793 *
3794 *****************************************************************************/
3795
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003796static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003797{
Reinette Chatred21050c2009-02-13 11:51:18 -08003798 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07003799
3800 init_waitqueue_head(&priv->wait_command_queue);
3801
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003802 INIT_WORK(&priv->restart, iwl3945_bg_restart);
3803 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003804 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003805 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
3806 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
Johannes Bergee525d12010-01-21 06:09:28 -08003807 INIT_DELAYED_WORK(&priv->_3945.rfkill_poll, iwl3945_rfkill_poll);
Stanislaw Gruszkac2408792010-07-30 16:41:08 +02003808
3809 iwl_setup_scan_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003810
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003811 iwl3945_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003812
Wey-Yi Guyb74e31a2010-03-01 17:23:50 -08003813 if (priv->cfg->ops->lib->recover_from_tx_stall) {
3814 init_timer(&priv->monitor_recover);
3815 priv->monitor_recover.data = (unsigned long)priv;
3816 priv->monitor_recover.function =
3817 priv->cfg->ops->lib->recover_from_tx_stall;
3818 }
3819
Zhu Yib481de92007-09-25 17:54:57 -07003820 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003821 iwl3945_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07003822}
3823
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003824static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003825{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003826 iwl3945_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003827
Joonwoo Parke47eb6a2007-11-29 10:42:49 +09003828 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07003829 cancel_delayed_work(&priv->scan_check);
3830 cancel_delayed_work(&priv->alive_start);
Abhijeet Kolekar1e460532010-04-23 14:14:53 -07003831 cancel_work_sync(&priv->start_internal_scan);
Zhu Yib481de92007-09-25 17:54:57 -07003832 cancel_work_sync(&priv->beacon_update);
3833}
3834
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003835static struct attribute *iwl3945_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07003836 &dev_attr_antenna.attr,
3837 &dev_attr_channels.attr,
3838 &dev_attr_dump_errors.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003839 &dev_attr_flags.attr,
3840 &dev_attr_filter_flags.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003841 &dev_attr_measurement.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003842 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003843 &dev_attr_status.attr,
3844 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003845 &dev_attr_tx_power.attr,
Samuel Ortizd08853a2009-01-23 13:45:17 -08003846#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003847 &dev_attr_debug_level.attr,
3848#endif
Zhu Yib481de92007-09-25 17:54:57 -07003849 NULL
3850};
3851
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003852static struct attribute_group iwl3945_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07003853 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003854 .attrs = iwl3945_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07003855};
3856
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003857static struct ieee80211_ops iwl3945_hw_ops = {
3858 .tx = iwl3945_mac_tx,
3859 .start = iwl3945_mac_start,
3860 .stop = iwl3945_mac_stop,
Abhijeet Kolekarcbb6ab92009-04-08 11:26:46 -07003861 .add_interface = iwl_mac_add_interface,
Abhijeet Kolekard8052312009-04-08 11:26:47 -07003862 .remove_interface = iwl_mac_remove_interface,
Abhijeet Kolekar48083682009-04-08 11:26:48 -07003863 .config = iwl_mac_config,
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02003864 .configure_filter = iwl3945_configure_filter,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003865 .set_key = iwl3945_mac_set_key,
Abhijeet Kolekar488829f2009-03-26 10:14:10 -07003866 .conf_tx = iwl_mac_conf_tx,
Abhijeet Kolekarbd564262009-04-08 11:26:52 -07003867 .reset_tsf = iwl_mac_reset_tsf,
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07003868 .bss_info_changed = iwl_bss_info_changed,
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003869 .hw_scan = iwl_mac_hw_scan,
3870 .sta_add = iwl3945_mac_sta_add,
3871 .sta_remove = iwl_mac_sta_remove,
Johannes Berga85d7cc2010-07-31 08:34:10 -07003872 .tx_last_beacon = iwl_mac_tx_last_beacon,
Zhu Yib481de92007-09-25 17:54:57 -07003873};
3874
Winkler, Tomase52119c2008-12-22 11:31:19 +08003875static int iwl3945_init_drv(struct iwl_priv *priv)
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003876{
3877 int ret;
Samuel Ortize6148912009-01-23 13:45:15 -08003878 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003879
3880 priv->retry_rate = 1;
3881 priv->ibss_beacon = NULL;
3882
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003883 spin_lock_init(&priv->sta_lock);
3884 spin_lock_init(&priv->hcmd_lock);
3885
3886 INIT_LIST_HEAD(&priv->free_frames);
3887
3888 mutex_init(&priv->mutex);
Reinette Chatred2dfe6d2010-02-18 22:03:04 -08003889 mutex_init(&priv->sync_cmd_mutex);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003890
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003891 priv->ieee_channels = NULL;
3892 priv->ieee_rates = NULL;
3893 priv->band = IEEE80211_BAND_2GHZ;
3894
3895 priv->iw_mode = NL80211_IFTYPE_STATION;
Wey-Yi Guya13d2762010-01-22 14:22:42 -08003896 priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003897
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08003898 priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003899
Samuel Ortize6148912009-01-23 13:45:15 -08003900 if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
3901 IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
3902 eeprom->version);
3903 ret = -EINVAL;
3904 goto err;
3905 }
3906 ret = iwl_init_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003907 if (ret) {
3908 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
3909 goto err;
3910 }
3911
Samuel Ortize6148912009-01-23 13:45:15 -08003912 /* Set up txpower settings in driver for all channels */
3913 if (iwl3945_txpower_set_from_eeprom(priv)) {
3914 ret = -EIO;
3915 goto err_free_channel_map;
3916 }
3917
Samuel Ortiz534166d2009-01-23 13:45:16 -08003918 ret = iwlcore_init_geos(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003919 if (ret) {
3920 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
3921 goto err_free_channel_map;
3922 }
Samuel Ortiz534166d2009-01-23 13:45:16 -08003923 iwl3945_init_hw_rates(priv, priv->ieee_rates);
3924
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003925 return 0;
3926
3927err_free_channel_map:
Samuel Ortize6148912009-01-23 13:45:15 -08003928 iwl_free_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003929err:
3930 return ret;
3931}
3932
Johannes Bergdd7a2502010-04-28 23:33:10 -07003933#define IWL3945_MAX_PROBE_REQUEST 200
3934
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08003935static int iwl3945_setup_mac(struct iwl_priv *priv)
3936{
3937 int ret;
3938 struct ieee80211_hw *hw = priv->hw;
3939
3940 hw->rate_control_algorithm = "iwl-3945-rs";
3941 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
Johannes Bergfd1af152010-04-30 11:30:43 -07003942 hw->vif_data_size = sizeof(struct iwl_vif_priv);
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08003943
3944 /* Tell mac80211 our characteristics */
3945 hw->flags = IEEE80211_HW_SIGNAL_DBM |
Reinette Chatrebc45a672009-12-14 14:12:10 -08003946 IEEE80211_HW_SPECTRUM_MGMT;
3947
3948 if (!priv->cfg->broken_powersave)
3949 hw->flags |= IEEE80211_HW_SUPPORTS_PS |
3950 IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08003951
3952 hw->wiphy->interface_modes =
3953 BIT(NL80211_IFTYPE_STATION) |
3954 BIT(NL80211_IFTYPE_ADHOC);
3955
Reinette Chatref6c8f152010-03-12 11:13:26 -08003956 hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
Johannes Berg5be83de2009-11-19 00:56:28 +01003957 WIPHY_FLAG_DISABLE_BEACON_HINTS;
Luis R. Rodriguez37184242009-07-30 17:43:48 -07003958
Johannes Berg1ecf9fc2009-04-20 14:36:56 -07003959 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX_3945;
3960 /* we create the 802.11 header and a zero-length SSID element */
Johannes Bergdd7a2502010-04-28 23:33:10 -07003961 hw->wiphy->max_scan_ie_len = IWL3945_MAX_PROBE_REQUEST - 24 - 2;
Johannes Bergd60cc912009-04-09 09:56:02 +02003962
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08003963 /* Default value; 4 EDCA QOS priorities */
3964 hw->queues = 4;
3965
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08003966 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
3967 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
3968 &priv->bands[IEEE80211_BAND_2GHZ];
3969
3970 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
3971 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
3972 &priv->bands[IEEE80211_BAND_5GHZ];
3973
3974 ret = ieee80211_register_hw(priv->hw);
3975 if (ret) {
3976 IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
3977 return ret;
3978 }
3979 priv->mac80211_registered = 1;
3980
3981 return 0;
3982}
3983
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003984static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07003985{
Johannes Berg246ed352010-08-23 10:46:32 +02003986 int err = 0, i;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003987 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07003988 struct ieee80211_hw *hw;
Kolekar, Abhijeetc0f20d92008-12-19 10:37:19 +08003989 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Samuel Ortize6148912009-01-23 13:45:15 -08003990 struct iwl3945_eeprom *eeprom;
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003991 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07003992
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08003993 /***********************
3994 * 1. Allocating HW data
3995 * ********************/
3996
Zhu Yib481de92007-09-25 17:54:57 -07003997 /* mac80211 allocates memory for this device instance, including
3998 * space for this driver's private structure */
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08003999 hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
Zhu Yib481de92007-09-25 17:54:57 -07004000 if (hw == NULL) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07004001 pr_err("Can not allocate network device\n");
Zhu Yib481de92007-09-25 17:54:57 -07004002 err = -ENOMEM;
4003 goto out;
4004 }
Zhu Yib481de92007-09-25 17:54:57 -07004005 priv = hw->priv;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004006 SET_IEEE80211_DEV(hw, &pdev->dev);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004007
Johannes Berg13bb9482010-08-23 10:46:33 +02004008 priv->cmd_queue = IWL39_CMD_QUEUE_NUM;
4009
Johannes Berg246ed352010-08-23 10:46:32 +02004010 /* 3945 has only one valid context */
4011 priv->valid_contexts = BIT(IWL_RXON_CTX_BSS);
4012
4013 for (i = 0; i < NUM_IWL_RXON_CTX; i++)
4014 priv->contexts[i].ctxid = i;
4015
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004016 /*
4017 * Disabling hardware scan means that mac80211 will perform scans
4018 * "the hard way", rather than using device's scan.
4019 */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004020 if (iwl3945_mod_params.disable_hw_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08004021 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004022 iwl3945_hw_ops.hw_scan = NULL;
4023 }
4024
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004025
Tomas Winklere1623442009-01-27 14:27:56 -08004026 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004027 priv->cfg = cfg;
4028 priv->pci_dev = pdev;
Mohamed Abbas40cefda2009-05-22 11:01:52 -07004029 priv->inta_mask = CSR_INI_SET_MASK;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004030
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07004031 if (iwl_alloc_traffic_mem(priv))
4032 IWL_ERR(priv, "Not enough memory to generate traffic log\n");
Zhu Yib481de92007-09-25 17:54:57 -07004033
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004034 /***************************
4035 * 2. Initializing PCI bus
4036 * *************************/
John W. Linville1a7123c2010-08-05 14:39:31 -04004037 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
4038 PCIE_LINK_STATE_CLKPM);
4039
Zhu Yib481de92007-09-25 17:54:57 -07004040 if (pci_enable_device(pdev)) {
4041 err = -ENODEV;
4042 goto out_ieee80211_free_hw;
4043 }
4044
4045 pci_set_master(pdev);
4046
Yang Hongyang284901a2009-04-06 19:01:15 -07004047 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Zhu Yib481de92007-09-25 17:54:57 -07004048 if (!err)
Yang Hongyang284901a2009-04-06 19:01:15 -07004049 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Zhu Yib481de92007-09-25 17:54:57 -07004050 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08004051 IWL_WARN(priv, "No suitable DMA available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004052 goto out_pci_disable_device;
4053 }
4054
4055 pci_set_drvdata(pdev, priv);
4056 err = pci_request_regions(pdev, DRV_NAME);
4057 if (err)
4058 goto out_pci_disable_device;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004059
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004060 /***********************
4061 * 3. Read REV Register
4062 * ********************/
Zhu Yib481de92007-09-25 17:54:57 -07004063 priv->hw_base = pci_iomap(pdev, 0, 0);
4064 if (!priv->hw_base) {
4065 err = -ENODEV;
4066 goto out_pci_release_regions;
4067 }
4068
Tomas Winklere1623442009-01-27 14:27:56 -08004069 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Zhu Yib481de92007-09-25 17:54:57 -07004070 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08004071 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Zhu Yib481de92007-09-25 17:54:57 -07004072
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004073 /* We disable the RETRY_TIMEOUT register (0x41) to keep
4074 * PCI Tx retries from interfering with C3 CPU state */
4075 pci_write_config_byte(pdev, 0x41, 0x00);
Zhu Yib481de92007-09-25 17:54:57 -07004076
Reinette Chatre731a29b2009-12-14 14:12:11 -08004077 /* these spin locks will be used in apm_ops.init and EEPROM access
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07004078 * we should init now
4079 */
4080 spin_lock_init(&priv->reg_lock);
Reinette Chatre731a29b2009-12-14 14:12:11 -08004081 spin_lock_init(&priv->lock);
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07004082
Reinette Chatre4843b5a2010-02-03 09:38:59 -08004083 /*
4084 * stop and reset the on-board processor just in case it is in a
4085 * strange state ... like being left stranded by a primary kernel
4086 * and this is now the kdump kernel trying to start up
4087 */
4088 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
4089
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004090 /***********************
4091 * 4. Read EEPROM
4092 * ********************/
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004093
Zhu Yi5a66926a2008-01-14 17:46:18 -08004094 /* Read the EEPROM */
Samuel Ortize6148912009-01-23 13:45:15 -08004095 err = iwl_eeprom_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004096 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004097 IWL_ERR(priv, "Unable to init EEPROM\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08004098 goto out_iounmap;
Zhu Yi5a66926a2008-01-14 17:46:18 -08004099 }
4100 /* MAC Address location in EEPROM same for 3945/4965 */
Samuel Ortize6148912009-01-23 13:45:15 -08004101 eeprom = (struct iwl3945_eeprom *)priv->eeprom;
Johannes Berg30eabc12010-05-12 03:33:10 -07004102 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", eeprom->mac_address);
4103 SET_IEEE80211_PERM_ADDR(priv->hw, eeprom->mac_address);
Zhu Yi5a66926a2008-01-14 17:46:18 -08004104
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004105 /***********************
4106 * 5. Setup HW Constants
4107 * ********************/
4108 /* Device-specific setup */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08004109 if (iwl3945_hw_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004110 IWL_ERR(priv, "failed to set hw settings\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08004111 goto out_eeprom_free;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004112 }
4113
4114 /***********************
4115 * 6. Setup priv
4116 * ********************/
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004117
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004118 err = iwl3945_init_drv(priv);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08004119 if (err) {
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004120 IWL_ERR(priv, "initializing driver failed\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08004121 goto out_unset_hw_params;
Reinette Chatre849e0dc2008-01-23 10:15:18 -08004122 }
Reinette Chatre849e0dc2008-01-23 10:15:18 -08004123
Tomas Winkler978785a2008-12-19 10:37:31 +08004124 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
4125 priv->cfg->name);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004126
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004127 /***********************
Abhijeet Kolekar09f9bf72009-04-20 14:37:03 -07004128 * 7. Setup Services
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004129 * ********************/
4130
4131 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08004132 iwl_disable_interrupts(priv);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004133 spin_unlock_irqrestore(&priv->lock, flags);
4134
Helmut Schaa26635162009-01-15 09:38:44 +01004135 pci_enable_msi(priv->pci_dev);
4136
Mohamed Abbasef850d72009-05-22 11:01:50 -07004137 err = request_irq(priv->pci_dev->irq, priv->cfg->ops->lib->isr,
4138 IRQF_SHARED, DRV_NAME, priv);
Helmut Schaa26635162009-01-15 09:38:44 +01004139 if (err) {
4140 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
4141 goto out_disable_msi;
4142 }
4143
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004144 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
4145 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004146 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004147 goto out_release_irq;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004148 }
4149
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004150 iwl_set_rxon_channel(priv,
Johannes Berg246ed352010-08-23 10:46:32 +02004151 &priv->bands[IEEE80211_BAND_2GHZ].channels[5],
4152 &priv->contexts[IWL_RXON_CTX_BSS]);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004153 iwl3945_setup_deferred_work(priv);
4154 iwl3945_setup_rx_handlers(priv);
Ben Cahill008a9e32009-10-09 13:20:27 -07004155 iwl_power_initialize(priv);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004156
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004157 /*********************************
Abhijeet Kolekar09f9bf72009-04-20 14:37:03 -07004158 * 8. Setup and Register mac80211
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004159 * *******************************/
4160
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004161 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004162
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004163 err = iwl3945_setup_mac(priv);
4164 if (err)
4165 goto out_remove_sysfs;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004166
Abhijeet Kolekara75fbe82009-04-20 14:36:58 -07004167 err = iwl_dbgfs_register(priv, DRV_NAME);
4168 if (err)
4169 IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
4170
Helmut Schaa26635162009-01-15 09:38:44 +01004171 /* Start monitoring the killswitch */
Johannes Bergee525d12010-01-21 06:09:28 -08004172 queue_delayed_work(priv->workqueue, &priv->_3945.rfkill_poll,
Helmut Schaa26635162009-01-15 09:38:44 +01004173 2 * HZ);
4174
Zhu Yib481de92007-09-25 17:54:57 -07004175 return 0;
4176
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004177 out_remove_sysfs:
Zhu Yib481de92007-09-25 17:54:57 -07004178 destroy_workqueue(priv->workqueue);
4179 priv->workqueue = NULL;
Reinette Chatrec8f16132009-02-27 16:21:22 -08004180 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
4181 out_release_irq:
4182 free_irq(priv->pci_dev->irq, priv);
Helmut Schaa26635162009-01-15 09:38:44 +01004183 out_disable_msi:
4184 pci_disable_msi(priv->pci_dev);
Reinette Chatrec8f16132009-02-27 16:21:22 -08004185 iwlcore_free_geos(priv);
4186 iwl_free_channel_map(priv);
4187 out_unset_hw_params:
4188 iwl3945_unset_hw_params(priv);
4189 out_eeprom_free:
4190 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004191 out_iounmap:
4192 pci_iounmap(pdev, priv->hw_base);
4193 out_pci_release_regions:
4194 pci_release_regions(pdev);
4195 out_pci_disable_device:
Zhu Yib481de92007-09-25 17:54:57 -07004196 pci_set_drvdata(pdev, NULL);
Reinette Chatre623d5632009-03-03 11:37:04 -08004197 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004198 out_ieee80211_free_hw:
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07004199 iwl_free_traffic_mem(priv);
Wey-Yi Guyd7c76f42009-10-09 13:20:17 -07004200 ieee80211_free_hw(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07004201 out:
4202 return err;
4203}
4204
Reinette Chatrec83dbf62008-03-21 13:53:41 -07004205static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004206{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004207 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004208 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07004209
4210 if (!priv)
4211 return;
4212
Tomas Winklere1623442009-01-27 14:27:56 -08004213 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07004214
Abhijeet Kolekara75fbe82009-04-20 14:36:58 -07004215 iwl_dbgfs_unregister(priv);
4216
Zhu Yib481de92007-09-25 17:54:57 -07004217 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08004218
Kolekar, Abhijeetd552bfb2008-12-19 10:37:41 +08004219 if (priv->mac80211_registered) {
4220 ieee80211_unregister_hw(priv->hw);
4221 priv->mac80211_registered = 0;
4222 } else {
4223 iwl3945_down(priv);
4224 }
Zhu Yib481de92007-09-25 17:54:57 -07004225
Ben Cahillc166b252009-10-23 13:42:35 -07004226 /*
4227 * Make sure device is reset to low power before unloading driver.
4228 * This may be redundant with iwl_down(), but there are paths to
4229 * run iwl_down() without calling apm_ops.stop(), and there are
4230 * paths to avoid running iwl_down() at all before leaving driver.
4231 * This (inexpensive) call *makes sure* device is reset.
4232 */
4233 priv->cfg->ops->lib->apm_ops.stop(priv);
4234
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
Johannes Bergee525d12010-01-21 06:09:28 -08004246 cancel_delayed_work_sync(&priv->_3945.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);
Zhu Yib481de92007-09-25 17:54:57 -07004255
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004256 /*netif_stop_queue(dev); */
4257 flush_workqueue(priv->workqueue);
4258
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004259 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07004260 * priv->workqueue... so we can't take down the workqueue
4261 * until now... */
4262 destroy_workqueue(priv->workqueue);
4263 priv->workqueue = NULL;
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07004264 iwl_free_traffic_mem(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004265
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);
Johannes Berg811ecc92010-04-06 04:12:41 -07004276 kfree(priv->scan_cmd);
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;
Joe Perchesc96c31e2010-07-26 14:39:58 -07004305 pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
4306 pr_info(DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004307
4308 ret = iwl3945_rate_control_register();
4309 if (ret) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07004310 pr_err("Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004311 return ret;
4312 }
4313
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004314 ret = pci_register_driver(&iwl3945_driver);
Zhu Yib481de92007-09-25 17:54:57 -07004315 if (ret) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07004316 pr_err("Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004317 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07004318 }
Zhu Yib481de92007-09-25 17:54:57 -07004319
4320 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004321
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004322error_register:
4323 iwl3945_rate_control_unregister();
4324 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004325}
4326
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004327static void __exit iwl3945_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07004328{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004329 pci_unregister_driver(&iwl3945_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004330 iwl3945_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07004331}
4332
Reinette Chatrea0987a82008-12-02 12:14:06 -08004333MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
Zhu Yi25cb6ca2008-09-11 11:45:22 +08004334
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07004335module_param_named(antenna, iwl3945_mod_params.antenna, int, S_IRUGO);
Zhu Yib481de92007-09-25 17:54:57 -07004336MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07004337module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, S_IRUGO);
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -08004338MODULE_PARM_DESC(swcrypto,
4339 "using software crypto (default 1 [software])\n");
Reinette Chatrea562a9d2009-07-17 09:30:24 -07004340#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07004341module_param_named(debug, iwl_debug_level, uint, S_IRUGO | S_IWUSR);
Zhu Yib481de92007-09-25 17:54:57 -07004342MODULE_PARM_DESC(debug, "debug output mask");
Reinette Chatrea562a9d2009-07-17 09:30:24 -07004343#endif
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07004344module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan,
4345 int, S_IRUGO);
Zhu Yib481de92007-09-25 17:54:57 -07004346MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07004347module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, S_IRUGO);
Samuel Ortizaf48d042009-01-23 13:45:19 -08004348MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
4349
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004350module_exit(iwl3945_exit);
4351module_init(iwl3945_init);