blob: 185d667fc71bfcdb985e90d2cc052b4d3a4fa07e [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Reinette Chatreeb7ae892008-03-11 16:17:17 -07003 * Copyright(c) 2003 - 2008 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:
25 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
Zhu Yib481de92007-09-25 17:54:57 -070030#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/version.h>
33#include <linux/init.h>
34#include <linux/pci.h>
35#include <linux/dma-mapping.h>
36#include <linux/delay.h>
37#include <linux/skbuff.h>
38#include <linux/netdevice.h>
39#include <linux/wireless.h>
40#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070041#include <linux/etherdevice.h>
42#include <linux/if_arp.h>
43
Zhu Yib481de92007-09-25 17:54:57 -070044#include <net/mac80211.h>
45
46#include <asm/div64.h>
47
Assaf Krauss6bc913b2008-03-11 16:17:18 -070048#include "iwl-eeprom.h"
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070049#include "iwl-dev.h"
Tomas Winklerfee12472008-04-03 16:05:21 -070050#include "iwl-core.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070051#include "iwl-io.h"
Zhu Yib481de92007-09-25 17:54:57 -070052#include "iwl-helpers.h"
Emmanuel Grumbach6974e362008-04-14 21:16:06 -070053#include "iwl-sta.h"
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -070054#include "iwl-calib.h"
Zhu Yib481de92007-09-25 17:54:57 -070055
Christoph Hellwig416e1432007-10-25 17:15:49 +080056
Zhu Yib481de92007-09-25 17:54:57 -070057/******************************************************************************
58 *
59 * module boiler plate
60 *
61 ******************************************************************************/
62
Zhu Yib481de92007-09-25 17:54:57 -070063/*
64 * module name, copyright, version, etc.
65 * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
66 */
67
68#define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux"
69
Tomas Winkler0a6857e2008-03-12 16:58:49 -070070#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070071#define VD "d"
72#else
73#define VD
74#endif
75
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080076#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070077#define VS "s"
78#else
79#define VS
80#endif
81
Tomas Winklerdf48c322008-03-06 10:40:19 -080082#define DRV_VERSION IWLWIFI_VERSION VD VS
Zhu Yib481de92007-09-25 17:54:57 -070083
Zhu Yib481de92007-09-25 17:54:57 -070084
85MODULE_DESCRIPTION(DRV_DESCRIPTION);
86MODULE_VERSION(DRV_VERSION);
87MODULE_AUTHOR(DRV_COPYRIGHT);
88MODULE_LICENSE("GPL");
89
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -070090static const struct ieee80211_supported_band *iwl_get_hw_mode(
Tomas Winklerc79dd5b2008-03-12 16:58:50 -070091 struct iwl_priv *priv, enum ieee80211_band band)
Zhu Yib481de92007-09-25 17:54:57 -070092{
Johannes Berg8318d782008-01-24 19:38:38 +010093 return priv->hw->wiphy->bands[band];
Zhu Yib481de92007-09-25 17:54:57 -070094}
95
Christoph Hellwigbb8c0932008-01-27 16:41:47 -080096static int iwl4965_is_empty_essid(const char *essid, int essid_len)
Zhu Yib481de92007-09-25 17:54:57 -070097{
98 /* Single white space is for Linksys APs */
99 if (essid_len == 1 && essid[0] == ' ')
100 return 1;
101
102 /* Otherwise, if the entire essid is 0, we assume it is hidden */
103 while (essid_len) {
104 essid_len--;
105 if (essid[essid_len] != '\0')
106 return 0;
107 }
108
109 return 1;
110}
111
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800112static const char *iwl4965_escape_essid(const char *essid, u8 essid_len)
Zhu Yib481de92007-09-25 17:54:57 -0700113{
114 static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
115 const char *s = essid;
116 char *d = escaped;
117
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800118 if (iwl4965_is_empty_essid(essid, essid_len)) {
Zhu Yib481de92007-09-25 17:54:57 -0700119 memcpy(escaped, "<hidden>", sizeof("<hidden>"));
120 return escaped;
121 }
122
123 essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE);
124 while (essid_len--) {
125 if (*s == '\0') {
126 *d++ = '\\';
127 *d++ = '0';
128 s++;
129 } else
130 *d++ = *s++;
131 }
132 *d = '\0';
133 return escaped;
134}
135
Zhu Yib481de92007-09-25 17:54:57 -0700136/*************** STATION TABLE MANAGEMENT ****
Ben Cahill9fbab512007-11-29 11:09:47 +0800137 * mac80211 should be examined to determine if sta_info is duplicating
Zhu Yib481de92007-09-25 17:54:57 -0700138 * the functionality provided here
139 */
140
141/**************************************************************/
142
Zhu Yib481de92007-09-25 17:54:57 -0700143
Zhu Yib481de92007-09-25 17:54:57 -0700144
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -0700145static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
146{
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800147 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -0700148
149 if (hw_decrypt)
150 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
151 else
152 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
153
154}
155
Zhu Yib481de92007-09-25 17:54:57 -0700156/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800157 * iwl4965_check_rxon_cmd - validate RXON structure is valid
Zhu Yib481de92007-09-25 17:54:57 -0700158 *
159 * NOTE: This is really only useful during development and can eventually
160 * be #ifdef'd out once the driver is stable and folks aren't actively
161 * making changes
162 */
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800163static int iwl4965_check_rxon_cmd(struct iwl_rxon_cmd *rxon)
Zhu Yib481de92007-09-25 17:54:57 -0700164{
165 int error = 0;
166 int counter = 1;
167
168 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
169 error |= le32_to_cpu(rxon->flags &
170 (RXON_FLG_TGJ_NARROW_BAND_MSK |
171 RXON_FLG_RADAR_DETECT_MSK));
172 if (error)
173 IWL_WARNING("check 24G fields %d | %d\n",
174 counter++, error);
175 } else {
176 error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
177 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
178 if (error)
179 IWL_WARNING("check 52 fields %d | %d\n",
180 counter++, error);
181 error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
182 if (error)
183 IWL_WARNING("check 52 CCK %d | %d\n",
184 counter++, error);
185 }
186 error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
187 if (error)
188 IWL_WARNING("check mac addr %d | %d\n", counter++, error);
189
190 /* make sure basic rates 6Mbps and 1Mbps are supported */
191 error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
192 ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
193 if (error)
194 IWL_WARNING("check basic rate %d | %d\n", counter++, error);
195
196 error |= (le16_to_cpu(rxon->assoc_id) > 2007);
197 if (error)
198 IWL_WARNING("check assoc id %d | %d\n", counter++, error);
199
200 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
201 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
202 if (error)
203 IWL_WARNING("check CCK and short slot %d | %d\n",
204 counter++, error);
205
206 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
207 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
208 if (error)
209 IWL_WARNING("check CCK & auto detect %d | %d\n",
210 counter++, error);
211
212 error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
213 RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
214 if (error)
215 IWL_WARNING("check TGG and auto detect %d | %d\n",
216 counter++, error);
217
218 if (error)
219 IWL_WARNING("Tuning to channel %d\n",
220 le16_to_cpu(rxon->channel));
221
222 if (error) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800223 IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
Zhu Yib481de92007-09-25 17:54:57 -0700224 return -1;
225 }
226 return 0;
227}
228
229/**
Ben Cahill9fbab512007-11-29 11:09:47 +0800230 * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
Ian Schram01ebd062007-10-25 17:15:22 +0800231 * @priv: staging_rxon is compared to active_rxon
Zhu Yib481de92007-09-25 17:54:57 -0700232 *
Ben Cahill9fbab512007-11-29 11:09:47 +0800233 * If the RXON structure is changing enough to require a new tune,
234 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
235 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
Zhu Yib481de92007-09-25 17:54:57 -0700236 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700237static int iwl4965_full_rxon_required(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700238{
239
240 /* These items are only settable from the full RXON command */
241 if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ||
242 compare_ether_addr(priv->staging_rxon.bssid_addr,
243 priv->active_rxon.bssid_addr) ||
244 compare_ether_addr(priv->staging_rxon.node_addr,
245 priv->active_rxon.node_addr) ||
246 compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
247 priv->active_rxon.wlap_bssid_addr) ||
248 (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
249 (priv->staging_rxon.channel != priv->active_rxon.channel) ||
250 (priv->staging_rxon.air_propagation !=
251 priv->active_rxon.air_propagation) ||
252 (priv->staging_rxon.ofdm_ht_single_stream_basic_rates !=
253 priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
254 (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
255 priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
256 (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) ||
257 (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
258 return 1;
259
260 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
261 * be updated with the RXON_ASSOC command -- however only some
262 * flag transitions are allowed using RXON_ASSOC */
263
264 /* Check if we are not switching bands */
265 if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
266 (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
267 return 1;
268
269 /* Check if we are switching association toggle */
270 if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
271 (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
272 return 1;
273
274 return 0;
275}
276
Zhu Yib481de92007-09-25 17:54:57 -0700277/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800278 * iwl4965_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -0700279 *
Ian Schram01ebd062007-10-25 17:15:22 +0800280 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -0700281 * the active_rxon structure is updated with the new data. This
282 * function correctly transitions out of the RXON_ASSOC_MSK state if
283 * a HW tune is required based on the RXON structure changes.
284 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700285static int iwl4965_commit_rxon(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700286{
287 /* cast away the const for active_rxon in this function */
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800288 struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
Joe Perches0795af52007-10-03 17:59:30 -0700289 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -0700290 int rc = 0;
291
Tomas Winklerfee12472008-04-03 16:05:21 -0700292 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700293 return -1;
294
295 /* always get timestamp with Rx frame */
296 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
297
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800298 rc = iwl4965_check_rxon_cmd(&priv->staging_rxon);
Zhu Yib481de92007-09-25 17:54:57 -0700299 if (rc) {
300 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
301 return -EINVAL;
302 }
303
304 /* If we don't need to send a full RXON, we can use
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800305 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -0700306 * and other flags for the current radio configuration. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800307 if (!iwl4965_full_rxon_required(priv)) {
Tomas Winkler7e8c5192008-04-15 16:01:43 -0700308 rc = iwl_send_rxon_assoc(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700309 if (rc) {
310 IWL_ERROR("Error setting RXON_ASSOC "
311 "configuration (%d).\n", rc);
312 return rc;
313 }
314
315 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
316
317 return 0;
318 }
319
320 /* station table will be cleared */
321 priv->assoc_station_added = 0;
322
Zhu Yib481de92007-09-25 17:54:57 -0700323 /* If we are currently associated and the new config requires
324 * an RXON_ASSOC and the new config wants the associated mask enabled,
325 * we must clear the associated from the active configuration
326 * before we apply the new config */
Tomas Winkler3109ece2008-03-28 16:33:35 -0700327 if (iwl_is_associated(priv) &&
Zhu Yib481de92007-09-25 17:54:57 -0700328 (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
329 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
330 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
331
Tomas Winkler857485c2008-03-21 13:53:44 -0700332 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800333 sizeof(struct iwl_rxon_cmd),
Zhu Yib481de92007-09-25 17:54:57 -0700334 &priv->active_rxon);
335
336 /* If the mask clearing failed then we set
337 * active_rxon back to what it was previously */
338 if (rc) {
339 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
340 IWL_ERROR("Error clearing ASSOC_MSK on current "
341 "configuration (%d).\n", rc);
342 return rc;
343 }
Zhu Yib481de92007-09-25 17:54:57 -0700344 }
345
346 IWL_DEBUG_INFO("Sending RXON\n"
347 "* with%s RXON_FILTER_ASSOC_MSK\n"
348 "* channel = %d\n"
Joe Perches0795af52007-10-03 17:59:30 -0700349 "* bssid = %s\n",
Zhu Yib481de92007-09-25 17:54:57 -0700350 ((priv->staging_rxon.filter_flags &
351 RXON_FILTER_ASSOC_MSK) ? "" : "out"),
352 le16_to_cpu(priv->staging_rxon.channel),
Joe Perches0795af52007-10-03 17:59:30 -0700353 print_mac(mac, priv->staging_rxon.bssid_addr));
Zhu Yib481de92007-09-25 17:54:57 -0700354
Ron Rindjunsky099b40b2008-04-21 15:41:53 -0700355 iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
Zhu Yib481de92007-09-25 17:54:57 -0700356 /* Apply the new configuration */
Tomas Winkler857485c2008-03-21 13:53:44 -0700357 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800358 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
Zhu Yib481de92007-09-25 17:54:57 -0700359 if (rc) {
360 IWL_ERROR("Error setting new configuration (%d).\n", rc);
361 return rc;
362 }
363
Tomas Winkler7a999bf2008-05-29 16:35:02 +0800364 iwl_remove_station(priv, iwl_bcast_addr, 0);
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700365 iwlcore_clear_stations_table(priv);
Zhu Yi556f8db2007-09-27 11:27:33 +0800366
Zhu Yib481de92007-09-25 17:54:57 -0700367 if (!priv->error_recovering)
368 priv->start_calib = 0;
369
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700370 iwl_init_sensitivity(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700371
372 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
373
374 /* If we issue a new RXON command which required a tune then we must
375 * send a new TXPOWER command or we won't be able to Tx any frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800376 rc = iwl4965_hw_reg_send_txpower(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700377 if (rc) {
378 IWL_ERROR("Error setting Tx power (%d).\n", rc);
379 return rc;
380 }
381
382 /* Add the broadcast address so we can send broadcast frames */
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800383 if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) ==
Zhu Yib481de92007-09-25 17:54:57 -0700384 IWL_INVALID_STATION) {
385 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
386 return -EIO;
387 }
388
389 /* If we have set the ASSOC_MSK and we are in BSS mode then
390 * add the IWL_AP_ID to the station rate table */
Tomas Winkler3109ece2008-03-28 16:33:35 -0700391 if (iwl_is_associated(priv) &&
Zhu Yib481de92007-09-25 17:54:57 -0700392 (priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800393 if (iwl_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1)
Zhu Yib481de92007-09-25 17:54:57 -0700394 == IWL_INVALID_STATION) {
395 IWL_ERROR("Error adding AP address for transmit.\n");
396 return -EIO;
397 }
398 priv->assoc_station_added = 1;
Emmanuel Grumbach6974e362008-04-14 21:16:06 -0700399 if (priv->default_wep_key &&
400 iwl_send_static_wepkey_cmd(priv, 0))
401 IWL_ERROR("Could not send WEP static key.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700402 }
403
404 return 0;
405}
406
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700407void iwl4965_update_chain_flags(struct iwl_priv *priv)
408{
409
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -0700410 iwl_set_rxon_chain(priv);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700411 iwl4965_commit_rxon(priv);
412}
413
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700414static int iwl4965_send_bt_config(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700415{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800416 struct iwl4965_bt_cmd bt_cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700417 .flags = 3,
418 .lead_time = 0xAA,
419 .max_kill = 1,
420 .kill_ack_mask = 0,
421 .kill_cts_mask = 0,
422 };
423
Tomas Winkler857485c2008-03-21 13:53:44 -0700424 return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800425 sizeof(struct iwl4965_bt_cmd), &bt_cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700426}
427
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700428static int iwl4965_send_scan_abort(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700429{
Tomas Winklerdb11d632008-05-05 10:22:33 +0800430 int ret = 0;
431 struct iwl_rx_packet *res;
Tomas Winkler857485c2008-03-21 13:53:44 -0700432 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700433 .id = REPLY_SCAN_ABORT_CMD,
434 .meta.flags = CMD_WANT_SKB,
435 };
436
437 /* If there isn't a scan actively going on in the hardware
438 * then we are in between scan bands and not actually
439 * actively scanning, so don't send the abort command */
440 if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
441 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
442 return 0;
443 }
444
Tomas Winklerdb11d632008-05-05 10:22:33 +0800445 ret = iwl_send_cmd_sync(priv, &cmd);
446 if (ret) {
Zhu Yib481de92007-09-25 17:54:57 -0700447 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
Tomas Winklerdb11d632008-05-05 10:22:33 +0800448 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700449 }
450
Tomas Winklerdb11d632008-05-05 10:22:33 +0800451 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700452 if (res->u.status != CAN_ABORT_STATUS) {
453 /* The scan abort will return 1 for success or
454 * 2 for "failure". A failure condition can be
455 * due to simply not being in an active scan which
456 * can occur if we send the scan abort before we
457 * the microcode has notified us that a scan is
458 * completed. */
459 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status);
460 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
461 clear_bit(STATUS_SCAN_HW, &priv->status);
462 }
463
464 dev_kfree_skb_any(cmd.meta.u.skb);
465
Tomas Winklerdb11d632008-05-05 10:22:33 +0800466 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700467}
468
Zhu Yib481de92007-09-25 17:54:57 -0700469/*
470 * CARD_STATE_CMD
471 *
Ben Cahill9fbab512007-11-29 11:09:47 +0800472 * Use: Sets the device's internal card state to enable, disable, or halt
Zhu Yib481de92007-09-25 17:54:57 -0700473 *
474 * When in the 'enable' state the card operates as normal.
475 * When in the 'disable' state, the card enters into a low power mode.
476 * When in the 'halt' state, the card is shut down and must be fully
477 * restarted to come back on.
478 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700479static int iwl4965_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag)
Zhu Yib481de92007-09-25 17:54:57 -0700480{
Tomas Winkler857485c2008-03-21 13:53:44 -0700481 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700482 .id = REPLY_CARD_STATE_CMD,
483 .len = sizeof(u32),
484 .data = &flags,
485 .meta.flags = meta_flag,
486 };
487
Tomas Winkler857485c2008-03-21 13:53:44 -0700488 return iwl_send_cmd(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700489}
490
Tomas Winklerfcab4232008-05-15 13:54:01 +0800491static void iwl_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700492{
493 struct list_head *element;
494
495 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
496 priv->frames_count);
497
498 while (!list_empty(&priv->free_frames)) {
499 element = priv->free_frames.next;
500 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800501 kfree(list_entry(element, struct iwl_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700502 priv->frames_count--;
503 }
504
505 if (priv->frames_count) {
506 IWL_WARNING("%d frames still in use. Did we lose one?\n",
507 priv->frames_count);
508 priv->frames_count = 0;
509 }
510}
511
Tomas Winklerfcab4232008-05-15 13:54:01 +0800512static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700513{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800514 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700515 struct list_head *element;
516 if (list_empty(&priv->free_frames)) {
517 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
518 if (!frame) {
519 IWL_ERROR("Could not allocate frame!\n");
520 return NULL;
521 }
522
523 priv->frames_count++;
524 return frame;
525 }
526
527 element = priv->free_frames.next;
528 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800529 return list_entry(element, struct iwl_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700530}
531
Tomas Winklerfcab4232008-05-15 13:54:01 +0800532static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700533{
534 memset(frame, 0, sizeof(*frame));
535 list_add(&frame->list, &priv->free_frames);
536}
537
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700538unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700539 struct ieee80211_hdr *hdr,
540 const u8 *dest, int left)
541{
542
Tomas Winkler3109ece2008-03-28 16:33:35 -0700543 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
Zhu Yib481de92007-09-25 17:54:57 -0700544 ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) &&
545 (priv->iw_mode != IEEE80211_IF_TYPE_AP)))
546 return 0;
547
548 if (priv->ibss_beacon->len > left)
549 return 0;
550
551 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
552
553 return priv->ibss_beacon->len;
554}
555
Guy Cohen39e88502008-04-23 17:14:57 -0700556static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700557{
Guy Cohen39e88502008-04-23 17:14:57 -0700558 int i;
559 int rate_mask;
Zhu Yib481de92007-09-25 17:54:57 -0700560
Guy Cohen39e88502008-04-23 17:14:57 -0700561 /* Set rate mask*/
562 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
563 rate_mask = priv->active_rate_basic & 0xF;
564 else
565 rate_mask = priv->active_rate_basic & 0xFF0;
566
567 /* Find lowest valid rate */
Zhu Yib481de92007-09-25 17:54:57 -0700568 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800569 i = iwl_rates[i].next_ieee) {
Zhu Yib481de92007-09-25 17:54:57 -0700570 if (rate_mask & (1 << i))
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800571 return iwl_rates[i].plcp;
Zhu Yib481de92007-09-25 17:54:57 -0700572 }
573
Guy Cohen39e88502008-04-23 17:14:57 -0700574 /* No valid rate was found. Assign the lowest one */
575 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
576 return IWL_RATE_1M_PLCP;
577 else
578 return IWL_RATE_6M_PLCP;
Zhu Yib481de92007-09-25 17:54:57 -0700579}
580
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700581static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700582{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800583 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700584 unsigned int frame_size;
585 int rc;
586 u8 rate;
587
Tomas Winklerfcab4232008-05-15 13:54:01 +0800588 frame = iwl_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700589
590 if (!frame) {
591 IWL_ERROR("Could not obtain free frame buffer for beacon "
592 "command.\n");
593 return -ENOMEM;
594 }
595
Guy Cohen39e88502008-04-23 17:14:57 -0700596 rate = iwl4965_rate_get_lowest_plcp(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700597
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800598 frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -0700599
Tomas Winkler857485c2008-03-21 13:53:44 -0700600 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700601 &frame->u.cmd[0]);
602
Tomas Winklerfcab4232008-05-15 13:54:01 +0800603 iwl_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700604
605 return rc;
606}
607
608/******************************************************************************
609 *
Zhu Yib481de92007-09-25 17:54:57 -0700610 * Misc. internal state and helper functions
611 *
612 ******************************************************************************/
Zhu Yib481de92007-09-25 17:54:57 -0700613
Zhu Yib481de92007-09-25 17:54:57 -0700614/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800615 * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field
Zhu Yib481de92007-09-25 17:54:57 -0700616 *
617 * return : set the bit for each supported rate insert in ie
618 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800619static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate,
Tomas Winklerc7c46672007-10-18 02:04:15 +0200620 u16 basic_rate, int *left)
Zhu Yib481de92007-09-25 17:54:57 -0700621{
622 u16 ret_rates = 0, bit;
623 int i;
Tomas Winklerc7c46672007-10-18 02:04:15 +0200624 u8 *cnt = ie;
625 u8 *rates = ie + 1;
Zhu Yib481de92007-09-25 17:54:57 -0700626
627 for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) {
628 if (bit & supported_rate) {
629 ret_rates |= bit;
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800630 rates[*cnt] = iwl_rates[i].ieee |
Tomas Winklerc7c46672007-10-18 02:04:15 +0200631 ((bit & basic_rate) ? 0x80 : 0x00);
632 (*cnt)++;
633 (*left)--;
634 if ((*left <= 0) ||
635 (*cnt >= IWL_SUPPORTED_RATES_IE_LEN))
Zhu Yib481de92007-09-25 17:54:57 -0700636 break;
637 }
638 }
639
640 return ret_rates;
641}
642
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700643#ifdef CONFIG_IWL4965_HT
644static void iwl4965_ht_conf(struct iwl_priv *priv,
645 struct ieee80211_bss_conf *bss_conf)
646{
647 struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf;
648 struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf;
649 struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
650
651 IWL_DEBUG_MAC80211("enter: \n");
652
653 iwl_conf->is_ht = bss_conf->assoc_ht;
654
655 if (!iwl_conf->is_ht)
656 return;
657
658 priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
659
660 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
Emmanuel Grumbacha9841012008-05-15 13:54:08 +0800661 iwl_conf->sgf |= HT_SHORT_GI_20MHZ;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700662 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
Emmanuel Grumbacha9841012008-05-15 13:54:08 +0800663 iwl_conf->sgf |= HT_SHORT_GI_40MHZ;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700664
665 iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
666 iwl_conf->max_amsdu_size =
667 !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
668
669 iwl_conf->supported_chan_width =
670 !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH);
671 iwl_conf->extension_chan_offset =
672 ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET;
673 /* If no above or below channel supplied disable FAT channel */
674 if (iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_ABOVE &&
675 iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_BELOW)
676 iwl_conf->supported_chan_width = 0;
677
678 iwl_conf->tx_mimo_ps_mode =
679 (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
680 memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16);
681
682 iwl_conf->control_channel = ht_bss_conf->primary_channel;
683 iwl_conf->tx_chan_width =
684 !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH);
685 iwl_conf->ht_protection =
686 ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION;
687 iwl_conf->non_GF_STA_present =
688 !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT);
689
690 IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel);
691 IWL_DEBUG_MAC80211("leave\n");
692}
693
694static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband,
695 u8 *pos, int *left)
696{
697 struct ieee80211_ht_cap *ht_cap;
698
699 if (!sband || !sband->ht_info.ht_supported)
700 return;
701
702 if (*left < sizeof(struct ieee80211_ht_cap))
703 return;
704
705 *pos++ = sizeof(struct ieee80211_ht_cap);
706 ht_cap = (struct ieee80211_ht_cap *) pos;
707
708 ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap);
709 memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16);
710 ht_cap->ampdu_params_info =
711 (sband->ht_info.ampdu_factor & IEEE80211_HT_CAP_AMPDU_FACTOR) |
712 ((sband->ht_info.ampdu_density << 2) &
713 IEEE80211_HT_CAP_AMPDU_DENSITY);
714 *left -= sizeof(struct ieee80211_ht_cap);
715}
716#else
717static inline void iwl4965_ht_conf(struct iwl_priv *priv,
718 struct ieee80211_bss_conf *bss_conf)
719{
720}
721static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband,
722 u8 *pos, int *left)
723{
724}
725#endif
726
727
Zhu Yib481de92007-09-25 17:54:57 -0700728/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800729 * iwl4965_fill_probe_req - fill in all required fields and IE for probe request
Zhu Yib481de92007-09-25 17:54:57 -0700730 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700731static u16 iwl4965_fill_probe_req(struct iwl_priv *priv,
Tomas Winkler78330fd2008-02-06 02:37:18 +0200732 enum ieee80211_band band,
733 struct ieee80211_mgmt *frame,
734 int left, int is_direct)
Zhu Yib481de92007-09-25 17:54:57 -0700735{
736 int len = 0;
737 u8 *pos = NULL;
mabbasbee488d2007-10-25 17:15:42 +0800738 u16 active_rates, ret_rates, cck_rates, active_rate_basic;
Tomas Winkler78330fd2008-02-06 02:37:18 +0200739 const struct ieee80211_supported_band *sband =
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700740 iwl_get_hw_mode(priv, band);
Zhu Yib481de92007-09-25 17:54:57 -0700741
742 /* Make sure there is enough space for the probe request,
743 * two mandatory IEs and the data */
744 left -= 24;
745 if (left < 0)
746 return 0;
747 len += 24;
748
749 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
Tomas Winkler57bd1be2008-05-15 13:54:03 +0800750 memcpy(frame->da, iwl_bcast_addr, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -0700751 memcpy(frame->sa, priv->mac_addr, ETH_ALEN);
Tomas Winkler57bd1be2008-05-15 13:54:03 +0800752 memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -0700753 frame->seq_ctrl = 0;
754
755 /* fill in our indirect SSID IE */
756 /* ...next IE... */
757
758 left -= 2;
759 if (left < 0)
760 return 0;
761 len += 2;
762 pos = &(frame->u.probe_req.variable[0]);
763 *pos++ = WLAN_EID_SSID;
764 *pos++ = 0;
765
766 /* fill in our direct SSID IE... */
767 if (is_direct) {
768 /* ...next IE... */
769 left -= 2 + priv->essid_len;
770 if (left < 0)
771 return 0;
772 /* ... fill it in... */
773 *pos++ = WLAN_EID_SSID;
774 *pos++ = priv->essid_len;
775 memcpy(pos, priv->essid, priv->essid_len);
776 pos += priv->essid_len;
777 len += 2 + priv->essid_len;
778 }
779
780 /* fill in supported rate */
781 /* ...next IE... */
782 left -= 2;
783 if (left < 0)
784 return 0;
Tomas Winklerc7c46672007-10-18 02:04:15 +0200785
Zhu Yib481de92007-09-25 17:54:57 -0700786 /* ... fill it in... */
787 *pos++ = WLAN_EID_SUPP_RATES;
788 *pos = 0;
Tomas Winklerc7c46672007-10-18 02:04:15 +0200789
mabbasbee488d2007-10-25 17:15:42 +0800790 /* exclude 60M rate */
791 active_rates = priv->rates_mask;
792 active_rates &= ~IWL_RATE_60M_MASK;
793
794 active_rate_basic = active_rates & IWL_BASIC_RATES_MASK;
Zhu Yib481de92007-09-25 17:54:57 -0700795
Tomas Winklerc7c46672007-10-18 02:04:15 +0200796 cck_rates = IWL_CCK_RATES_MASK & active_rates;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800797 ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates,
mabbasbee488d2007-10-25 17:15:42 +0800798 active_rate_basic, &left);
Tomas Winklerc7c46672007-10-18 02:04:15 +0200799 active_rates &= ~ret_rates;
800
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800801 ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates,
mabbasbee488d2007-10-25 17:15:42 +0800802 active_rate_basic, &left);
Tomas Winklerc7c46672007-10-18 02:04:15 +0200803 active_rates &= ~ret_rates;
804
Zhu Yib481de92007-09-25 17:54:57 -0700805 len += 2 + *pos;
806 pos += (*pos) + 1;
Tomas Winklerc7c46672007-10-18 02:04:15 +0200807 if (active_rates == 0)
Zhu Yib481de92007-09-25 17:54:57 -0700808 goto fill_end;
809
810 /* fill in supported extended rate */
811 /* ...next IE... */
812 left -= 2;
813 if (left < 0)
814 return 0;
815 /* ... fill it in... */
816 *pos++ = WLAN_EID_EXT_SUPP_RATES;
817 *pos = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800818 iwl4965_supported_rate_to_ie(pos, active_rates,
mabbasbee488d2007-10-25 17:15:42 +0800819 active_rate_basic, &left);
Zhu Yib481de92007-09-25 17:54:57 -0700820 if (*pos > 0)
821 len += 2 + *pos;
822
Zhu Yib481de92007-09-25 17:54:57 -0700823 fill_end:
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700824 /* fill in HT IE */
825 left -= 2;
826 if (left < 0)
827 return 0;
828
829 *pos++ = WLAN_EID_HT_CAPABILITY;
830 *pos = 0;
831
832 iwl_ht_cap_to_ie(sband, pos, &left);
833
834 if (*pos > 0)
835 len += 2 + *pos;
Zhu Yib481de92007-09-25 17:54:57 -0700836 return (u16)len;
837}
838
839/*
840 * QoS support
841*/
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700842static int iwl4965_send_qos_params_command(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800843 struct iwl4965_qosparam_cmd *qos)
Zhu Yib481de92007-09-25 17:54:57 -0700844{
845
Tomas Winkler857485c2008-03-21 13:53:44 -0700846 return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800847 sizeof(struct iwl4965_qosparam_cmd), qos);
Zhu Yib481de92007-09-25 17:54:57 -0700848}
849
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700850static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force)
Zhu Yib481de92007-09-25 17:54:57 -0700851{
852 unsigned long flags;
853
Zhu Yib481de92007-09-25 17:54:57 -0700854 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
855 return;
856
857 if (!priv->qos_data.qos_enable)
858 return;
859
860 spin_lock_irqsave(&priv->lock, flags);
861 priv->qos_data.def_qos_parm.qos_flags = 0;
862
863 if (priv->qos_data.qos_cap.q_AP.queue_request &&
864 !priv->qos_data.qos_cap.q_AP.txop_request)
865 priv->qos_data.def_qos_parm.qos_flags |=
866 QOS_PARAM_FLG_TXOP_TYPE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700867 if (priv->qos_data.qos_active)
868 priv->qos_data.def_qos_parm.qos_flags |=
869 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
870
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800871#ifdef CONFIG_IWL4965_HT
Ron Rindjunskyfd105e72007-11-26 16:14:39 +0200872 if (priv->current_ht_config.is_ht)
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800873 priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800874#endif /* CONFIG_IWL4965_HT */
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800875
Zhu Yib481de92007-09-25 17:54:57 -0700876 spin_unlock_irqrestore(&priv->lock, flags);
877
Tomas Winkler3109ece2008-03-28 16:33:35 -0700878 if (force || iwl_is_associated(priv)) {
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800879 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
880 priv->qos_data.qos_active,
881 priv->qos_data.def_qos_parm.qos_flags);
Zhu Yib481de92007-09-25 17:54:57 -0700882
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800883 iwl4965_send_qos_params_command(priv,
Zhu Yib481de92007-09-25 17:54:57 -0700884 &(priv->qos_data.def_qos_parm));
885 }
886}
887
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700888int iwl4965_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
Zhu Yib481de92007-09-25 17:54:57 -0700889{
890 /* Filter incoming packets to determine if they are targeted toward
891 * this network, discarding packets coming from ourselves */
892 switch (priv->iw_mode) {
893 case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */
894 /* packets from our adapter are dropped (echo) */
895 if (!compare_ether_addr(header->addr2, priv->mac_addr))
896 return 0;
897 /* {broad,multi}cast packets to our IBSS go through */
898 if (is_multicast_ether_addr(header->addr1))
899 return !compare_ether_addr(header->addr3, priv->bssid);
900 /* packets to our adapter go through */
901 return !compare_ether_addr(header->addr1, priv->mac_addr);
902 case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */
903 /* packets from our adapter are dropped (echo) */
904 if (!compare_ether_addr(header->addr3, priv->mac_addr))
905 return 0;
906 /* {broad,multi}cast packets to our BSS go through */
907 if (is_multicast_ether_addr(header->addr1))
908 return !compare_ether_addr(header->addr2, priv->bssid);
909 /* packets to our adapter go through */
910 return !compare_ether_addr(header->addr1, priv->mac_addr);
Tomas Winkler69dc5d92008-03-25 16:33:41 -0700911 default:
912 break;
Zhu Yib481de92007-09-25 17:54:57 -0700913 }
914
915 return 1;
916}
917
918#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
919
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800920static const char *iwl4965_get_tx_fail_reason(u32 status)
Zhu Yib481de92007-09-25 17:54:57 -0700921{
922 switch (status & TX_STATUS_MSK) {
923 case TX_STATUS_SUCCESS:
924 return "SUCCESS";
925 TX_STATUS_ENTRY(SHORT_LIMIT);
926 TX_STATUS_ENTRY(LONG_LIMIT);
927 TX_STATUS_ENTRY(FIFO_UNDERRUN);
928 TX_STATUS_ENTRY(MGMNT_ABORT);
929 TX_STATUS_ENTRY(NEXT_FRAG);
930 TX_STATUS_ENTRY(LIFE_EXPIRE);
931 TX_STATUS_ENTRY(DEST_PS);
932 TX_STATUS_ENTRY(ABORTED);
933 TX_STATUS_ENTRY(BT_RETRY);
934 TX_STATUS_ENTRY(STA_INVALID);
935 TX_STATUS_ENTRY(FRAG_DROPPED);
936 TX_STATUS_ENTRY(TID_DISABLE);
937 TX_STATUS_ENTRY(FRAME_FLUSHED);
938 TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
939 TX_STATUS_ENTRY(TX_LOCKED);
940 TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
941 }
942
943 return "UNKNOWN";
944}
945
946/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800947 * iwl4965_scan_cancel - Cancel any currently executing HW scan
Zhu Yib481de92007-09-25 17:54:57 -0700948 *
949 * NOTE: priv->mutex is not required before calling this function
950 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700951static int iwl4965_scan_cancel(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700952{
953 if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
954 clear_bit(STATUS_SCANNING, &priv->status);
955 return 0;
956 }
957
958 if (test_bit(STATUS_SCANNING, &priv->status)) {
959 if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
960 IWL_DEBUG_SCAN("Queuing scan abort.\n");
961 set_bit(STATUS_SCAN_ABORTING, &priv->status);
962 queue_work(priv->workqueue, &priv->abort_scan);
963
964 } else
965 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
966
967 return test_bit(STATUS_SCANNING, &priv->status);
968 }
969
970 return 0;
971}
972
973/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800974 * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan
Zhu Yib481de92007-09-25 17:54:57 -0700975 * @ms: amount of time to wait (in milliseconds) for scan to abort
976 *
977 * NOTE: priv->mutex must be held before calling this function
978 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700979static int iwl4965_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms)
Zhu Yib481de92007-09-25 17:54:57 -0700980{
981 unsigned long now = jiffies;
982 int ret;
983
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800984 ret = iwl4965_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700985 if (ret && ms) {
986 mutex_unlock(&priv->mutex);
987 while (!time_after(jiffies, now + msecs_to_jiffies(ms)) &&
988 test_bit(STATUS_SCANNING, &priv->status))
989 msleep(1);
990 mutex_lock(&priv->mutex);
991
992 return test_bit(STATUS_SCANNING, &priv->status);
993 }
994
995 return ret;
996}
997
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700998static void iwl4965_sequence_reset(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700999{
1000 /* Reset ieee stats */
1001
1002 /* We don't reset the net_device_stats (ieee->stats) on
1003 * re-association */
1004
1005 priv->last_seq_num = -1;
1006 priv->last_frag_num = -1;
1007 priv->last_packet_time = 0;
1008
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001009 iwl4965_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001010}
1011
1012#define MAX_UCODE_BEACON_INTERVAL 4096
1013#define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
1014
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001015static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -07001016{
1017 u16 new_val = 0;
1018 u16 beacon_factor = 0;
1019
1020 beacon_factor =
1021 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
1022 / MAX_UCODE_BEACON_INTERVAL;
1023 new_val = beacon_val / beacon_factor;
1024
1025 return cpu_to_le16(new_val);
1026}
1027
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001028static void iwl4965_setup_rxon_timing(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001029{
1030 u64 interval_tm_unit;
1031 u64 tsf, result;
1032 unsigned long flags;
1033 struct ieee80211_conf *conf = NULL;
1034 u16 beacon_int = 0;
1035
1036 conf = ieee80211_get_hw_conf(priv->hw);
1037
1038 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3109ece2008-03-28 16:33:35 -07001039 priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32);
1040 priv->rxon_timing.timestamp.dw[0] =
1041 cpu_to_le32(priv->timestamp & 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07001042
1043 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
1044
Tomas Winkler3109ece2008-03-28 16:33:35 -07001045 tsf = priv->timestamp;
Zhu Yib481de92007-09-25 17:54:57 -07001046
1047 beacon_int = priv->beacon_int;
1048 spin_unlock_irqrestore(&priv->lock, flags);
1049
1050 if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
1051 if (beacon_int == 0) {
1052 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
1053 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
1054 } else {
1055 priv->rxon_timing.beacon_interval =
1056 cpu_to_le16(beacon_int);
1057 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001058 iwl4965_adjust_beacon_interval(
Zhu Yib481de92007-09-25 17:54:57 -07001059 le16_to_cpu(priv->rxon_timing.beacon_interval));
1060 }
1061
1062 priv->rxon_timing.atim_window = 0;
1063 } else {
1064 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001065 iwl4965_adjust_beacon_interval(conf->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -07001066 /* TODO: we need to get atim_window from upper stack
1067 * for now we set to 0 */
1068 priv->rxon_timing.atim_window = 0;
1069 }
1070
1071 interval_tm_unit =
1072 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
1073 result = do_div(tsf, interval_tm_unit);
1074 priv->rxon_timing.beacon_init_val =
1075 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
1076
1077 IWL_DEBUG_ASSOC
1078 ("beacon interval %d beacon timer %d beacon tim %d\n",
1079 le16_to_cpu(priv->rxon_timing.beacon_interval),
1080 le32_to_cpu(priv->rxon_timing.beacon_init_val),
1081 le16_to_cpu(priv->rxon_timing.atim_window));
1082}
1083
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001084static int iwl4965_scan_initiate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001085{
1086 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
1087 IWL_ERROR("APs don't scan.\n");
1088 return 0;
1089 }
1090
Tomas Winklerfee12472008-04-03 16:05:21 -07001091 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001092 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
1093 return -EIO;
1094 }
1095
1096 if (test_bit(STATUS_SCANNING, &priv->status)) {
1097 IWL_DEBUG_SCAN("Scan already in progress.\n");
1098 return -EAGAIN;
1099 }
1100
1101 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
1102 IWL_DEBUG_SCAN("Scan request while abort pending. "
1103 "Queuing.\n");
1104 return -EAGAIN;
1105 }
1106
1107 IWL_DEBUG_INFO("Starting scan...\n");
1108 priv->scan_bands = 2;
1109 set_bit(STATUS_SCANNING, &priv->status);
1110 priv->scan_start = jiffies;
1111 priv->scan_pass_start = priv->scan_start;
1112
1113 queue_work(priv->workqueue, &priv->request_scan);
1114
1115 return 0;
1116}
1117
Zhu Yib481de92007-09-25 17:54:57 -07001118
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001119static void iwl4965_set_flags_for_phymode(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01001120 enum ieee80211_band band)
Zhu Yib481de92007-09-25 17:54:57 -07001121{
Johannes Berg8318d782008-01-24 19:38:38 +01001122 if (band == IEEE80211_BAND_5GHZ) {
Zhu Yib481de92007-09-25 17:54:57 -07001123 priv->staging_rxon.flags &=
1124 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
1125 | RXON_FLG_CCK_MSK);
1126 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
1127 } else {
Reinette Chatre508e32e2008-04-14 21:16:13 -07001128 /* Copied from iwl4965_post_associate() */
Zhu Yib481de92007-09-25 17:54:57 -07001129 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
1130 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
1131 else
1132 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
1133
1134 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
1135 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
1136
1137 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
1138 priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
1139 priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
1140 }
1141}
1142
1143/*
Ian Schram01ebd062007-10-25 17:15:22 +08001144 * initialize rxon structure with default values from eeprom
Zhu Yib481de92007-09-25 17:54:57 -07001145 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001146static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001147{
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001148 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07001149
1150 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
1151
1152 switch (priv->iw_mode) {
1153 case IEEE80211_IF_TYPE_AP:
1154 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
1155 break;
1156
1157 case IEEE80211_IF_TYPE_STA:
1158 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
1159 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
1160 break;
1161
1162 case IEEE80211_IF_TYPE_IBSS:
1163 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
1164 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
1165 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
1166 RXON_FILTER_ACCEPT_GRP_MSK;
1167 break;
1168
1169 case IEEE80211_IF_TYPE_MNTR:
1170 priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
1171 priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
1172 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
1173 break;
Tomas Winkler69dc5d92008-03-25 16:33:41 -07001174 default:
1175 IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode);
1176 break;
Zhu Yib481de92007-09-25 17:54:57 -07001177 }
1178
1179#if 0
1180 /* TODO: Figure out when short_preamble would be set and cache from
1181 * that */
1182 if (!hw_to_local(priv->hw)->short_preamble)
1183 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
1184 else
1185 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
1186#endif
1187
Assaf Krauss8622e702008-03-21 13:53:43 -07001188 ch_info = iwl_get_channel_info(priv, priv->band,
Zhu Yib481de92007-09-25 17:54:57 -07001189 le16_to_cpu(priv->staging_rxon.channel));
1190
1191 if (!ch_info)
1192 ch_info = &priv->channel_info[0];
1193
1194 /*
1195 * in some case A channels are all non IBSS
1196 * in this case force B/G channel
1197 */
1198 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
1199 !(is_channel_ibss(ch_info)))
1200 ch_info = &priv->channel_info[0];
1201
1202 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
Johannes Berg8318d782008-01-24 19:38:38 +01001203 priv->band = ch_info->band;
Zhu Yib481de92007-09-25 17:54:57 -07001204
Johannes Berg8318d782008-01-24 19:38:38 +01001205 iwl4965_set_flags_for_phymode(priv, priv->band);
Zhu Yib481de92007-09-25 17:54:57 -07001206
1207 priv->staging_rxon.ofdm_basic_rates =
1208 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
1209 priv->staging_rxon.cck_basic_rates =
1210 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
1211
1212 priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
1213 RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
1214 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
1215 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
1216 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
1217 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07001218 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001219}
1220
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001221static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -07001222{
Zhu Yib481de92007-09-25 17:54:57 -07001223 if (mode == IEEE80211_IF_TYPE_IBSS) {
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001224 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07001225
Assaf Krauss8622e702008-03-21 13:53:43 -07001226 ch_info = iwl_get_channel_info(priv,
Johannes Berg8318d782008-01-24 19:38:38 +01001227 priv->band,
Zhu Yib481de92007-09-25 17:54:57 -07001228 le16_to_cpu(priv->staging_rxon.channel));
1229
1230 if (!ch_info || !is_channel_ibss(ch_info)) {
1231 IWL_ERROR("channel %d not IBSS channel\n",
1232 le16_to_cpu(priv->staging_rxon.channel));
1233 return -EINVAL;
1234 }
1235 }
1236
Zhu Yib481de92007-09-25 17:54:57 -07001237 priv->iw_mode = mode;
1238
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001239 iwl4965_connection_init_rx_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001240 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
1241
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001242 iwlcore_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001243
Mohamed Abbasfde35712007-11-29 11:10:15 +08001244 /* dont commit rxon if rf-kill is on*/
Tomas Winklerfee12472008-04-03 16:05:21 -07001245 if (!iwl_is_ready_rf(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08001246 return -EAGAIN;
1247
1248 cancel_delayed_work(&priv->scan_check);
1249 if (iwl4965_scan_cancel_timeout(priv, 100)) {
1250 IWL_WARNING("Aborted scan still in progress after 100ms\n");
1251 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
1252 return -EAGAIN;
1253 }
1254
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001255 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001256
1257 return 0;
1258}
1259
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001260static void iwl4965_set_rate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001261{
Johannes Berg8318d782008-01-24 19:38:38 +01001262 const struct ieee80211_supported_band *hw = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001263 struct ieee80211_rate *rate;
1264 int i;
1265
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -07001266 hw = iwl_get_hw_mode(priv, priv->band);
Saleem Abdulrasoolc4ba9622007-11-18 23:59:08 -08001267 if (!hw) {
1268 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
1269 return;
1270 }
Zhu Yib481de92007-09-25 17:54:57 -07001271
1272 priv->active_rate = 0;
1273 priv->active_rate_basic = 0;
1274
Johannes Berg8318d782008-01-24 19:38:38 +01001275 for (i = 0; i < hw->n_bitrates; i++) {
1276 rate = &(hw->bitrates[i]);
1277 if (rate->hw_value < IWL_RATE_COUNT)
1278 priv->active_rate |= (1 << rate->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07001279 }
1280
1281 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
1282 priv->active_rate, priv->active_rate_basic);
1283
1284 /*
1285 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
1286 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
1287 * OFDM
1288 */
1289 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
1290 priv->staging_rxon.cck_basic_rates =
1291 ((priv->active_rate_basic &
1292 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
1293 else
1294 priv->staging_rxon.cck_basic_rates =
1295 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
1296
1297 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
1298 priv->staging_rxon.ofdm_basic_rates =
1299 ((priv->active_rate_basic &
1300 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
1301 IWL_FIRST_OFDM_RATE) & 0xFF;
1302 else
1303 priv->staging_rxon.ofdm_basic_rates =
1304 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
1305}
1306
Mohamed Abbasad97edd2008-03-28 16:21:06 -07001307void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
Zhu Yib481de92007-09-25 17:54:57 -07001308{
1309 unsigned long flags;
1310
1311 if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
1312 return;
1313
1314 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
1315 disable_radio ? "OFF" : "ON");
1316
1317 if (disable_radio) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001318 iwl4965_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001319 /* FIXME: This is a workaround for AP */
1320 if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
1321 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001322 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001323 CSR_UCODE_SW_BIT_RFKILL);
1324 spin_unlock_irqrestore(&priv->lock, flags);
Mohamed Abbasad97edd2008-03-28 16:21:06 -07001325 /* call the host command only if no hw rf-kill set */
Mohamed Abbas59003832008-04-15 16:01:46 -07001326 if (!test_bit(STATUS_RF_KILL_HW, &priv->status) &&
1327 iwl_is_ready(priv))
Mohamed Abbasad97edd2008-03-28 16:21:06 -07001328 iwl4965_send_card_state(priv,
1329 CARD_STATE_CMD_DISABLE,
1330 0);
Zhu Yib481de92007-09-25 17:54:57 -07001331 set_bit(STATUS_RF_KILL_SW, &priv->status);
Mohamed Abbasad97edd2008-03-28 16:21:06 -07001332
1333 /* make sure mac80211 stop sending Tx frame */
1334 if (priv->mac80211_registered)
1335 ieee80211_stop_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07001336 }
1337 return;
1338 }
1339
1340 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001341 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07001342
1343 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1344 spin_unlock_irqrestore(&priv->lock, flags);
1345
1346 /* wake up ucode */
1347 msleep(10);
1348
1349 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001350 iwl_read32(priv, CSR_UCODE_DRV_GP1);
1351 if (!iwl_grab_nic_access(priv))
1352 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001353 spin_unlock_irqrestore(&priv->lock, flags);
1354
1355 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
1356 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
1357 "disabled by HW switch\n");
1358 return;
1359 }
1360
1361 queue_work(priv->workqueue, &priv->restart);
1362 return;
1363}
1364
Zhu Yib481de92007-09-25 17:54:57 -07001365#define IWL_PACKET_RETRY_TIME HZ
1366
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001367int iwl4965_is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
Zhu Yib481de92007-09-25 17:54:57 -07001368{
1369 u16 sc = le16_to_cpu(header->seq_ctrl);
1370 u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
1371 u16 frag = sc & IEEE80211_SCTL_FRAG;
1372 u16 *last_seq, *last_frag;
1373 unsigned long *last_time;
1374
1375 switch (priv->iw_mode) {
1376 case IEEE80211_IF_TYPE_IBSS:{
1377 struct list_head *p;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001378 struct iwl4965_ibss_seq *entry = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001379 u8 *mac = header->addr2;
1380 int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1);
1381
1382 __list_for_each(p, &priv->ibss_mac_hash[index]) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001383 entry = list_entry(p, struct iwl4965_ibss_seq, list);
Zhu Yib481de92007-09-25 17:54:57 -07001384 if (!compare_ether_addr(entry->mac, mac))
1385 break;
1386 }
1387 if (p == &priv->ibss_mac_hash[index]) {
1388 entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
1389 if (!entry) {
Ian Schrambc434dd2007-10-25 17:15:29 +08001390 IWL_ERROR("Cannot malloc new mac entry\n");
Zhu Yib481de92007-09-25 17:54:57 -07001391 return 0;
1392 }
1393 memcpy(entry->mac, mac, ETH_ALEN);
1394 entry->seq_num = seq;
1395 entry->frag_num = frag;
1396 entry->packet_time = jiffies;
Ian Schrambc434dd2007-10-25 17:15:29 +08001397 list_add(&entry->list, &priv->ibss_mac_hash[index]);
Zhu Yib481de92007-09-25 17:54:57 -07001398 return 0;
1399 }
1400 last_seq = &entry->seq_num;
1401 last_frag = &entry->frag_num;
1402 last_time = &entry->packet_time;
1403 break;
1404 }
1405 case IEEE80211_IF_TYPE_STA:
1406 last_seq = &priv->last_seq_num;
1407 last_frag = &priv->last_frag_num;
1408 last_time = &priv->last_packet_time;
1409 break;
1410 default:
1411 return 0;
1412 }
1413 if ((*last_seq == seq) &&
1414 time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) {
1415 if (*last_frag == frag)
1416 goto drop;
1417 if (*last_frag + 1 != frag)
1418 /* out-of-order fragment */
1419 goto drop;
1420 } else
1421 *last_seq = seq;
1422
1423 *last_frag = frag;
1424 *last_time = jiffies;
1425 return 0;
1426
1427 drop:
1428 return 1;
1429}
1430
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001431#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07001432
1433#include "iwl-spectrum.h"
1434
1435#define BEACON_TIME_MASK_LOW 0x00FFFFFF
1436#define BEACON_TIME_MASK_HIGH 0xFF000000
1437#define TIME_UNIT 1024
1438
1439/*
1440 * extended beacon time format
1441 * time in usec will be changed into a 32-bit value in 8:24 format
1442 * the high 1 byte is the beacon counts
1443 * the lower 3 bytes is the time in usec within one beacon interval
1444 */
1445
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001446static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001447{
1448 u32 quot;
1449 u32 rem;
1450 u32 interval = beacon_interval * 1024;
1451
1452 if (!interval || !usec)
1453 return 0;
1454
1455 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
1456 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
1457
1458 return (quot << 24) + rem;
1459}
1460
1461/* base is usually what we get from ucode with each received frame,
1462 * the same as HW timer counter counting down
1463 */
1464
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001465static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001466{
1467 u32 base_low = base & BEACON_TIME_MASK_LOW;
1468 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
1469 u32 interval = beacon_interval * TIME_UNIT;
1470 u32 res = (base & BEACON_TIME_MASK_HIGH) +
1471 (addon & BEACON_TIME_MASK_HIGH);
1472
1473 if (base_low > addon_low)
1474 res += base_low - addon_low;
1475 else if (base_low < addon_low) {
1476 res += interval + base_low - addon_low;
1477 res += (1 << 24);
1478 } else
1479 res += (1 << 24);
1480
1481 return cpu_to_le32(res);
1482}
1483
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001484static int iwl4965_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001485 struct ieee80211_measurement_params *params,
1486 u8 type)
1487{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001488 struct iwl4965_spectrum_cmd spectrum;
Tomas Winklerdb11d632008-05-05 10:22:33 +08001489 struct iwl_rx_packet *res;
Tomas Winkler857485c2008-03-21 13:53:44 -07001490 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001491 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
1492 .data = (void *)&spectrum,
1493 .meta.flags = CMD_WANT_SKB,
1494 };
1495 u32 add_time = le64_to_cpu(params->start_time);
1496 int rc;
1497 int spectrum_resp_status;
1498 int duration = le16_to_cpu(params->duration);
1499
Tomas Winkler3109ece2008-03-28 16:33:35 -07001500 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001501 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001502 iwl4965_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -07001503 le64_to_cpu(params->start_time) - priv->last_tsf,
1504 le16_to_cpu(priv->rxon_timing.beacon_interval));
1505
1506 memset(&spectrum, 0, sizeof(spectrum));
1507
1508 spectrum.channel_count = cpu_to_le16(1);
1509 spectrum.flags =
1510 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
1511 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
1512 cmd.len = sizeof(spectrum);
1513 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
1514
Tomas Winkler3109ece2008-03-28 16:33:35 -07001515 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001516 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001517 iwl4965_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -07001518 add_time,
1519 le16_to_cpu(priv->rxon_timing.beacon_interval));
1520 else
1521 spectrum.start_time = 0;
1522
1523 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
1524 spectrum.channels[0].channel = params->channel;
1525 spectrum.channels[0].type = type;
1526 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
1527 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
1528 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
1529
Tomas Winkler857485c2008-03-21 13:53:44 -07001530 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001531 if (rc)
1532 return rc;
1533
Tomas Winklerdb11d632008-05-05 10:22:33 +08001534 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001535 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1536 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
1537 rc = -EIO;
1538 }
1539
1540 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
1541 switch (spectrum_resp_status) {
1542 case 0: /* Command will be handled */
1543 if (res->u.spectrum.id != 0xff) {
1544 IWL_DEBUG_INFO
1545 ("Replaced existing measurement: %d\n",
1546 res->u.spectrum.id);
1547 priv->measurement_status &= ~MEASUREMENT_READY;
1548 }
1549 priv->measurement_status |= MEASUREMENT_ACTIVE;
1550 rc = 0;
1551 break;
1552
1553 case 1: /* Command will not be handled */
1554 rc = -EAGAIN;
1555 break;
1556 }
1557
1558 dev_kfree_skb_any(cmd.meta.u.skb);
1559
1560 return rc;
1561}
1562#endif
1563
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001564static void iwl4965_txstatus_to_ieee(struct iwl_priv *priv,
Tomas Winkler8567c632008-05-15 13:53:58 +08001565 struct iwl_tx_info *tx_sta)
Zhu Yib481de92007-09-25 17:54:57 -07001566{
Johannes Berge039fa42008-05-15 12:55:29 +02001567 ieee80211_tx_status_irqsafe(priv->hw, tx_sta->skb[0]);
Zhu Yib481de92007-09-25 17:54:57 -07001568 tx_sta->skb[0] = NULL;
1569}
1570
1571/**
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001572 * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
Zhu Yib481de92007-09-25 17:54:57 -07001573 *
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001574 * When FW advances 'R' index, all entries between old and new 'R' index
1575 * need to be reclaimed. As result, some free space forms. If there is
1576 * enough free space (> low mark), wake the stack that feeds us.
Zhu Yib481de92007-09-25 17:54:57 -07001577 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001578int iwl4965_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index)
Zhu Yib481de92007-09-25 17:54:57 -07001579{
Ron Rindjunsky16466902008-05-05 10:22:50 +08001580 struct iwl_tx_queue *txq = &priv->txq[txq_id];
Tomas Winkler443cfd42008-05-15 13:53:57 +08001581 struct iwl_queue *q = &txq->q;
Zhu Yib481de92007-09-25 17:54:57 -07001582 int nfreed = 0;
1583
Tomas Winkler443cfd42008-05-15 13:53:57 +08001584 if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
Zhu Yib481de92007-09-25 17:54:57 -07001585 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
1586 "is out of range [0-%d] %d %d.\n", txq_id,
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001587 index, q->n_bd, q->write_ptr, q->read_ptr);
Zhu Yib481de92007-09-25 17:54:57 -07001588 return 0;
1589 }
1590
Tomas Winklerc54b6792008-03-06 17:36:53 -08001591 for (index = iwl_queue_inc_wrap(index, q->n_bd);
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001592 q->read_ptr != index;
Tomas Winklerc54b6792008-03-06 17:36:53 -08001593 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
Zhu Yib481de92007-09-25 17:54:57 -07001594 if (txq_id != IWL_CMD_QUEUE_NUM) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001595 iwl4965_txstatus_to_ieee(priv,
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001596 &(txq->txb[txq->q.read_ptr]));
Ron Rindjunsky1053d352008-05-05 10:22:43 +08001597 iwl_hw_txq_free_tfd(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001598 } else if (nfreed > 1) {
1599 IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index,
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001600 q->write_ptr, q->read_ptr);
Zhu Yib481de92007-09-25 17:54:57 -07001601 queue_work(priv->workqueue, &priv->restart);
1602 }
1603 nfreed++;
1604 }
1605
Zhu Yib481de92007-09-25 17:54:57 -07001606 return nfreed;
1607}
1608
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001609static int iwl4965_is_tx_success(u32 status)
Zhu Yib481de92007-09-25 17:54:57 -07001610{
1611 status &= TX_STATUS_MSK;
1612 return (status == TX_STATUS_SUCCESS)
1613 || (status == TX_STATUS_DIRECT_DONE);
1614}
1615
1616/******************************************************************************
1617 *
1618 * Generic RX handler implementations
1619 *
1620 ******************************************************************************/
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001621#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -07001622
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001623static inline int iwl4965_get_ra_sta_id(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001624 struct ieee80211_hdr *hdr)
1625{
1626 if (priv->iw_mode == IEEE80211_IF_TYPE_STA)
1627 return IWL_AP_ID;
1628 else {
1629 u8 *da = ieee80211_get_DA(hdr);
Tomas Winkler947b13a2008-04-16 16:34:48 -07001630 return iwl_find_station(priv, da);
Zhu Yib481de92007-09-25 17:54:57 -07001631 }
1632}
1633
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001634static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr(
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001635 struct iwl_priv *priv, int txq_id, int idx)
Zhu Yib481de92007-09-25 17:54:57 -07001636{
1637 if (priv->txq[txq_id].txb[idx].skb[0])
1638 return (struct ieee80211_hdr *)priv->txq[txq_id].
1639 txb[idx].skb[0]->data;
1640 return NULL;
1641}
1642
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001643static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp)
Zhu Yib481de92007-09-25 17:54:57 -07001644{
1645 __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status +
1646 tx_resp->frame_count);
1647 return le32_to_cpu(*scd_ssn) & MAX_SN;
1648
1649}
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001650
1651/**
1652 * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue
1653 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001654static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv,
Tomas Winkler6def9762008-05-05 10:22:31 +08001655 struct iwl_ht_agg *agg,
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02001656 struct iwl4965_tx_resp_agg *tx_resp,
Zhu Yib481de92007-09-25 17:54:57 -07001657 u16 start_idx)
1658{
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02001659 u16 status;
1660 struct agg_tx_status *frame_status = &tx_resp->status;
Johannes Berge039fa42008-05-15 12:55:29 +02001661 struct ieee80211_tx_info *info = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001662 struct ieee80211_hdr *hdr = NULL;
1663 int i, sh;
1664 int txq_id, idx;
1665 u16 seq;
1666
1667 if (agg->wait_for_ba)
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001668 IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
Zhu Yib481de92007-09-25 17:54:57 -07001669
1670 agg->frame_count = tx_resp->frame_count;
1671 agg->start_idx = start_idx;
1672 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02001673 agg->bitmap = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001674
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001675 /* # frames attempted by Tx command */
Zhu Yib481de92007-09-25 17:54:57 -07001676 if (agg->frame_count == 1) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001677 /* Only one frame was attempted; no block-ack will arrive */
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02001678 status = le16_to_cpu(frame_status[0].status);
1679 seq = le16_to_cpu(frame_status[0].sequence);
1680 idx = SEQ_TO_INDEX(seq);
1681 txq_id = SEQ_TO_QUEUE(seq);
Zhu Yib481de92007-09-25 17:54:57 -07001682
Zhu Yib481de92007-09-25 17:54:57 -07001683 /* FIXME: code repetition */
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02001684 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
1685 agg->frame_count, agg->start_idx, idx);
Zhu Yib481de92007-09-25 17:54:57 -07001686
Johannes Berge039fa42008-05-15 12:55:29 +02001687 info = IEEE80211_SKB_CB(priv->txq[txq_id].txb[idx].skb[0]);
1688 info->status.retry_count = tx_resp->failure_frame;
1689 info->flags &= ~IEEE80211_TX_CTL_AMPDU;
1690 info->flags |= iwl4965_is_tx_success(status)?
1691 IEEE80211_TX_STAT_ACK : 0;
Ron Rindjunsky4c424e42008-03-04 18:09:27 -08001692 iwl4965_hwrate_to_tx_control(priv,
1693 le32_to_cpu(tx_resp->rate_n_flags),
Johannes Berge039fa42008-05-15 12:55:29 +02001694 info);
Zhu Yib481de92007-09-25 17:54:57 -07001695 /* FIXME: code repetition end */
1696
1697 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
1698 status & 0xff, tx_resp->failure_frame);
1699 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001700 iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags));
Zhu Yib481de92007-09-25 17:54:57 -07001701
1702 agg->wait_for_ba = 0;
1703 } else {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001704 /* Two or more frames were attempted; expect block-ack */
Zhu Yib481de92007-09-25 17:54:57 -07001705 u64 bitmap = 0;
1706 int start = agg->start_idx;
1707
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001708 /* Construct bit-map of pending frames within Tx window */
Zhu Yib481de92007-09-25 17:54:57 -07001709 for (i = 0; i < agg->frame_count; i++) {
1710 u16 sc;
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02001711 status = le16_to_cpu(frame_status[i].status);
1712 seq = le16_to_cpu(frame_status[i].sequence);
Zhu Yib481de92007-09-25 17:54:57 -07001713 idx = SEQ_TO_INDEX(seq);
1714 txq_id = SEQ_TO_QUEUE(seq);
1715
1716 if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
1717 AGG_TX_STATE_ABORT_MSK))
1718 continue;
1719
1720 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
1721 agg->frame_count, txq_id, idx);
1722
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001723 hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx);
Zhu Yib481de92007-09-25 17:54:57 -07001724
1725 sc = le16_to_cpu(hdr->seq_ctrl);
1726 if (idx != (SEQ_TO_SN(sc) & 0xff)) {
1727 IWL_ERROR("BUG_ON idx doesn't match seq control"
1728 " idx=%d, seq_idx=%d, seq=%d\n",
1729 idx, SEQ_TO_SN(sc),
1730 hdr->seq_ctrl);
1731 return -1;
1732 }
1733
1734 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
1735 i, idx, SEQ_TO_SN(sc));
1736
1737 sh = idx - start;
1738 if (sh > 64) {
1739 sh = (start - idx) + 0xff;
1740 bitmap = bitmap << sh;
1741 sh = 0;
1742 start = idx;
1743 } else if (sh < -64)
1744 sh = 0xff - (start - idx);
1745 else if (sh < 0) {
1746 sh = start - idx;
1747 start = idx;
1748 bitmap = bitmap << sh;
1749 sh = 0;
1750 }
1751 bitmap |= (1 << sh);
1752 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
1753 start, (u32)(bitmap & 0xFFFFFFFF));
1754 }
1755
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02001756 agg->bitmap = bitmap;
Zhu Yib481de92007-09-25 17:54:57 -07001757 agg->start_idx = start;
1758 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02001759 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
Zhu Yib481de92007-09-25 17:54:57 -07001760 agg->frame_count, agg->start_idx,
John W. Linville06501d22008-04-01 17:38:47 -04001761 (unsigned long long)agg->bitmap);
Zhu Yib481de92007-09-25 17:54:57 -07001762
1763 if (bitmap)
1764 agg->wait_for_ba = 1;
1765 }
1766 return 0;
1767}
1768#endif
Zhu Yib481de92007-09-25 17:54:57 -07001769
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001770/**
1771 * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
1772 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001773static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001774 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001775{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001776 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001777 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
1778 int txq_id = SEQ_TO_QUEUE(sequence);
1779 int index = SEQ_TO_INDEX(sequence);
Ron Rindjunsky16466902008-05-05 10:22:50 +08001780 struct iwl_tx_queue *txq = &priv->txq[txq_id];
Johannes Berge039fa42008-05-15 12:55:29 +02001781 struct ieee80211_tx_info *info;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001782 struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
Zhu Yib481de92007-09-25 17:54:57 -07001783 u32 status = le32_to_cpu(tx_resp->status);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001784#ifdef CONFIG_IWL4965_HT
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02001785 int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION;
Tomas Winkler54dbb522008-05-15 13:54:06 +08001786 u16 fc;
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02001787 struct ieee80211_hdr *hdr;
Tomas Winkler54dbb522008-05-15 13:54:06 +08001788 u8 *qc = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001789#endif
1790
Tomas Winkler443cfd42008-05-15 13:53:57 +08001791 if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) {
Zhu Yib481de92007-09-25 17:54:57 -07001792 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
1793 "is out of range [0-%d] %d %d\n", txq_id,
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001794 index, txq->q.n_bd, txq->q.write_ptr,
1795 txq->q.read_ptr);
Zhu Yib481de92007-09-25 17:54:57 -07001796 return;
1797 }
1798
Johannes Berge039fa42008-05-15 12:55:29 +02001799 info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
1800 memset(&info->status, 0, sizeof(info->status));
1801
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001802#ifdef CONFIG_IWL4965_HT
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02001803 hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, index);
Tomas Winkler54dbb522008-05-15 13:54:06 +08001804 fc = le16_to_cpu(hdr->frame_control);
1805 if (ieee80211_is_qos_data(fc)) {
1806 qc = ieee80211_get_qos_ctrl(hdr, ieee80211_get_hdrlen(fc));
1807 tid = qc[0] & 0xf;
1808 }
Zhu Yib481de92007-09-25 17:54:57 -07001809
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02001810 sta_id = iwl4965_get_ra_sta_id(priv, hdr);
1811 if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) {
1812 IWL_ERROR("Station not known\n");
1813 return;
1814 }
1815
1816 if (txq->sched_retry) {
1817 const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp);
Tomas Winkler6def9762008-05-05 10:22:31 +08001818 struct iwl_ht_agg *agg = NULL;
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02001819
1820 if (!qc)
Zhu Yib481de92007-09-25 17:54:57 -07001821 return;
Zhu Yib481de92007-09-25 17:54:57 -07001822
1823 agg = &priv->stations[sta_id].tid[tid].agg;
1824
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02001825 iwl4965_tx_status_reply_tx(priv, agg,
1826 (struct iwl4965_tx_resp_agg *)tx_resp, index);
Zhu Yib481de92007-09-25 17:54:57 -07001827
1828 if ((tx_resp->frame_count == 1) &&
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001829 !iwl4965_is_tx_success(status)) {
Zhu Yib481de92007-09-25 17:54:57 -07001830 /* TODO: send BAR */
1831 }
1832
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02001833 if (txq->q.read_ptr != (scd_ssn & 0xff)) {
Ron Rindjunsky0d0b2c12008-05-04 14:48:18 +03001834 int freed, ampdu_q;
Tomas Winklerc54b6792008-03-06 17:36:53 -08001835 index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
Zhu Yib481de92007-09-25 17:54:57 -07001836 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
1837 "%d index %d\n", scd_ssn , index);
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02001838 freed = iwl4965_tx_queue_reclaim(priv, txq_id, index);
1839 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
1840
Tomas Winkler443cfd42008-05-15 13:53:57 +08001841 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02001842 txq_id >= 0 && priv->mac80211_registered &&
Ron Rindjunsky0d0b2c12008-05-04 14:48:18 +03001843 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) {
1844 /* calculate mac80211 ampdu sw queue to wake */
1845 ampdu_q = txq_id - IWL_BACK_QUEUE_FIRST_ID +
1846 priv->hw->queues;
1847 if (agg->state == IWL_AGG_OFF)
1848 ieee80211_wake_queue(priv->hw, txq_id);
1849 else
1850 ieee80211_wake_queue(priv->hw, ampdu_q);
1851 }
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02001852 iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id);
Zhu Yib481de92007-09-25 17:54:57 -07001853 }
1854 } else {
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001855#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07001856
Johannes Berge039fa42008-05-15 12:55:29 +02001857 info->status.retry_count = tx_resp->failure_frame;
1858 info->flags |=
1859 iwl4965_is_tx_success(status) ? IEEE80211_TX_STAT_ACK : 0;
Ron Rindjunsky4c424e42008-03-04 18:09:27 -08001860 iwl4965_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags),
Johannes Berge039fa42008-05-15 12:55:29 +02001861 info);
Zhu Yib481de92007-09-25 17:54:57 -07001862
Zhu Yib481de92007-09-25 17:54:57 -07001863 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x "
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001864 "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status),
Zhu Yib481de92007-09-25 17:54:57 -07001865 status, le32_to_cpu(tx_resp->rate_n_flags),
1866 tx_resp->failure_frame);
1867
1868 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
Tomas Winkler47c51962008-05-05 10:22:41 +08001869#ifdef CONFIG_IWL4965_HT
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02001870 if (index != -1) {
1871 int freed = iwl4965_tx_queue_reclaim(priv, txq_id, index);
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02001872 if (tid != MAX_TID_COUNT)
1873 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
Tomas Winkler443cfd42008-05-15 13:53:57 +08001874 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
Ron Rindjunsky0d0b2c12008-05-04 14:48:18 +03001875 (txq_id >= 0) && priv->mac80211_registered)
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02001876 ieee80211_wake_queue(priv->hw, txq_id);
1877 if (tid != MAX_TID_COUNT)
1878 iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id);
Zhu Yib481de92007-09-25 17:54:57 -07001879 }
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02001880 }
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001881#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07001882
1883 if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
1884 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
1885}
1886
1887
Tomas Winkler885ba202008-05-29 16:34:55 +08001888static void iwl_rx_reply_alive(struct iwl_priv *priv,
1889 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001890{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001891 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Tomas Winkler885ba202008-05-29 16:34:55 +08001892 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -07001893 struct delayed_work *pwork;
1894
1895 palive = &pkt->u.alive_frame;
1896
1897 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
1898 "0x%01X 0x%01X\n",
1899 palive->is_valid, palive->ver_type,
1900 palive->ver_subtype);
1901
1902 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
1903 IWL_DEBUG_INFO("Initialization Alive received.\n");
1904 memcpy(&priv->card_alive_init,
1905 &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +08001906 sizeof(struct iwl_init_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001907 pwork = &priv->init_alive_start;
1908 } else {
1909 IWL_DEBUG_INFO("Runtime Alive received.\n");
1910 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +08001911 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001912 pwork = &priv->alive_start;
1913 }
1914
1915 /* We delay the ALIVE response by 5ms to
1916 * give the HW RF Kill time to activate... */
1917 if (palive->is_valid == UCODE_VALID_OK)
1918 queue_delayed_work(priv->workqueue, pwork,
1919 msecs_to_jiffies(5));
1920 else
1921 IWL_WARNING("uCode did not respond OK.\n");
1922}
1923
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001924static void iwl4965_rx_reply_add_sta(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001925 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001926{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001927 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001928
1929 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
1930 return;
1931}
1932
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001933static void iwl4965_rx_reply_error(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001934 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001935{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001936 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001937
1938 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
1939 "seq 0x%04X ser 0x%08X\n",
1940 le32_to_cpu(pkt->u.err_resp.error_type),
1941 get_cmd_string(pkt->u.err_resp.cmd_id),
1942 pkt->u.err_resp.cmd_id,
1943 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
1944 le32_to_cpu(pkt->u.err_resp.error_info));
1945}
1946
1947#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1948
Tomas Winklera55360e2008-05-05 10:22:28 +08001949static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001950{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001951 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001952 struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001953 struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001954 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
1955 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
1956 rxon->channel = csa->channel;
1957 priv->staging_rxon.channel = csa->channel;
1958}
1959
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001960static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001961 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001962{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001963#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Tomas Winklerdb11d632008-05-05 10:22:33 +08001964 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001965 struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001966
1967 if (!report->state) {
Ester Kummerf3d67992008-05-06 11:05:12 +08001968 IWL_DEBUG(IWL_DL_11H,
1969 "Spectrum Measure Notification: Start\n");
Zhu Yib481de92007-09-25 17:54:57 -07001970 return;
1971 }
1972
1973 memcpy(&priv->measure_report, report, sizeof(*report));
1974 priv->measurement_status |= MEASUREMENT_READY;
1975#endif
1976}
1977
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001978static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001979 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001980{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001981#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklerdb11d632008-05-05 10:22:33 +08001982 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001983 struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001984 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
1985 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
1986#endif
1987}
1988
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001989static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001990 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001991{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001992 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001993 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
1994 "notification for %s:\n",
1995 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
Ester Kummerbf403db2008-05-05 10:22:40 +08001996 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
Zhu Yib481de92007-09-25 17:54:57 -07001997}
1998
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001999static void iwl4965_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07002000{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002001 struct iwl_priv *priv =
2002 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07002003 struct sk_buff *beacon;
2004
2005 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02002006 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07002007
2008 if (!beacon) {
2009 IWL_ERROR("update beacon failed\n");
2010 return;
2011 }
2012
2013 mutex_lock(&priv->mutex);
2014 /* new beacon skb is allocated every time; dispose previous.*/
2015 if (priv->ibss_beacon)
2016 dev_kfree_skb(priv->ibss_beacon);
2017
2018 priv->ibss_beacon = beacon;
2019 mutex_unlock(&priv->mutex);
2020
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002021 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002022}
2023
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002024static void iwl4965_rx_beacon_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08002025 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002026{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07002027#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklerdb11d632008-05-05 10:22:33 +08002028 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002029 struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status);
2030 u8 rate = iwl4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -07002031
2032 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
2033 "tsf %d %d rate %d\n",
2034 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
2035 beacon->beacon_notify_hdr.failure_frame,
2036 le32_to_cpu(beacon->ibss_mgr_status),
2037 le32_to_cpu(beacon->high_tsf),
2038 le32_to_cpu(beacon->low_tsf), rate);
2039#endif
2040
2041 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
2042 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
2043 queue_work(priv->workqueue, &priv->beacon_update);
2044}
2045
2046/* Service response to REPLY_SCAN_CMD (0x80) */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002047static void iwl4965_rx_reply_scan(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08002048 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002049{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07002050#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklerdb11d632008-05-05 10:22:33 +08002051 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002052 struct iwl4965_scanreq_notification *notif =
2053 (struct iwl4965_scanreq_notification *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07002054
2055 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status);
2056#endif
2057}
2058
2059/* Service SCAN_START_NOTIFICATION (0x82) */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002060static void iwl4965_rx_scan_start_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08002061 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002062{
Tomas Winklerdb11d632008-05-05 10:22:33 +08002063 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002064 struct iwl4965_scanstart_notification *notif =
2065 (struct iwl4965_scanstart_notification *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07002066 priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
2067 IWL_DEBUG_SCAN("Scan start: "
2068 "%d [802.11%s] "
2069 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
2070 notif->channel,
2071 notif->band ? "bg" : "a",
2072 notif->tsf_high,
2073 notif->tsf_low, notif->status, notif->beacon_timer);
2074}
2075
2076/* Service SCAN_RESULTS_NOTIFICATION (0x83) */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002077static void iwl4965_rx_scan_results_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08002078 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002079{
Tomas Winklerdb11d632008-05-05 10:22:33 +08002080 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002081 struct iwl4965_scanresults_notification *notif =
2082 (struct iwl4965_scanresults_notification *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07002083
2084 IWL_DEBUG_SCAN("Scan ch.res: "
2085 "%d [802.11%s] "
2086 "(TSF: 0x%08X:%08X) - %d "
2087 "elapsed=%lu usec (%dms since last)\n",
2088 notif->channel,
2089 notif->band ? "bg" : "a",
2090 le32_to_cpu(notif->tsf_high),
2091 le32_to_cpu(notif->tsf_low),
2092 le32_to_cpu(notif->statistics[0]),
2093 le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
2094 jiffies_to_msecs(elapsed_jiffies
2095 (priv->last_scan_jiffies, jiffies)));
2096
2097 priv->last_scan_jiffies = jiffies;
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002098 priv->next_scan_jiffies = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002099}
2100
2101/* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002102static void iwl4965_rx_scan_complete_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08002103 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002104{
Tomas Winklerdb11d632008-05-05 10:22:33 +08002105 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002106 struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07002107
2108 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
2109 scan_notif->scanned_channels,
2110 scan_notif->tsf_low,
2111 scan_notif->tsf_high, scan_notif->status);
2112
2113 /* The HW is no longer scanning */
2114 clear_bit(STATUS_SCAN_HW, &priv->status);
2115
2116 /* The scan completion notification came in, so kill that timer... */
2117 cancel_delayed_work(&priv->scan_check);
2118
2119 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
2120 (priv->scan_bands == 2) ? "2.4" : "5.2",
2121 jiffies_to_msecs(elapsed_jiffies
2122 (priv->scan_pass_start, jiffies)));
2123
2124 /* Remove this scanned band from the list
2125 * of pending bands to scan */
2126 priv->scan_bands--;
2127
2128 /* If a request to abort was given, or the scan did not succeed
2129 * then we reset the scan state machine and terminate,
2130 * re-queuing another scan if one has been requested */
2131 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
2132 IWL_DEBUG_INFO("Aborted scan completed.\n");
2133 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
2134 } else {
2135 /* If there are more bands on this scan pass reschedule */
2136 if (priv->scan_bands > 0)
2137 goto reschedule;
2138 }
2139
2140 priv->last_scan_jiffies = jiffies;
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002141 priv->next_scan_jiffies = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002142 IWL_DEBUG_INFO("Setting scan to off\n");
2143
2144 clear_bit(STATUS_SCANNING, &priv->status);
2145
2146 IWL_DEBUG_INFO("Scan took %dms\n",
2147 jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
2148
2149 queue_work(priv->workqueue, &priv->scan_completed);
2150
2151 return;
2152
2153reschedule:
2154 priv->scan_pass_start = jiffies;
2155 queue_work(priv->workqueue, &priv->request_scan);
2156}
2157
2158/* Handle notification from uCode that card's power state is changing
2159 * due to software, hardware, or critical temperature RFKILL */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002160static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08002161 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002162{
Tomas Winklerdb11d632008-05-05 10:22:33 +08002163 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002164 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
2165 unsigned long status = priv->status;
2166
2167 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
2168 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
2169 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
2170
2171 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
2172 RF_CARD_DISABLED)) {
2173
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002174 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07002175 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2176
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002177 if (!iwl_grab_nic_access(priv)) {
2178 iwl_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07002179 priv, HBUS_TARG_MBX_C,
2180 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
2181
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002182 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002183 }
2184
2185 if (!(flags & RXON_CARD_DISABLED)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002186 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07002187 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002188 if (!iwl_grab_nic_access(priv)) {
2189 iwl_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07002190 priv, HBUS_TARG_MBX_C,
2191 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
2192
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002193 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002194 }
2195 }
2196
2197 if (flags & RF_CARD_DISABLED) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002198 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07002199 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002200 iwl_read32(priv, CSR_UCODE_DRV_GP1);
2201 if (!iwl_grab_nic_access(priv))
2202 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002203 }
2204 }
2205
2206 if (flags & HW_CARD_DISABLED)
2207 set_bit(STATUS_RF_KILL_HW, &priv->status);
2208 else
2209 clear_bit(STATUS_RF_KILL_HW, &priv->status);
2210
2211
2212 if (flags & SW_CARD_DISABLED)
2213 set_bit(STATUS_RF_KILL_SW, &priv->status);
2214 else
2215 clear_bit(STATUS_RF_KILL_SW, &priv->status);
2216
2217 if (!(flags & RXON_CARD_DISABLED))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002218 iwl4965_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002219
2220 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
2221 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
2222 (test_bit(STATUS_RF_KILL_SW, &status) !=
2223 test_bit(STATUS_RF_KILL_SW, &priv->status)))
2224 queue_work(priv->workqueue, &priv->rf_kill);
2225 else
2226 wake_up_interruptible(&priv->wait_command_queue);
2227}
2228
2229/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002230 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07002231 *
2232 * Setup the RX handlers for each of the reply types sent from the uCode
2233 * to the host.
2234 *
2235 * This function chains into the hardware specific files for them to setup
2236 * any hardware specific handlers as well.
2237 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002238static void iwl4965_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002239{
Tomas Winkler885ba202008-05-29 16:34:55 +08002240 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002241 priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta;
2242 priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error;
2243 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa;
Zhu Yib481de92007-09-25 17:54:57 -07002244 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002245 iwl4965_rx_spectrum_measure_notif;
2246 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07002247 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002248 iwl4965_rx_pm_debug_statistics_notif;
2249 priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07002250
Ben Cahill9fbab512007-11-29 11:09:47 +08002251 /*
2252 * The same handler is used for both the REPLY to a discrete
2253 * statistics request from the host as well as for the periodic
2254 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07002255 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002256 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics;
2257 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -07002258
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002259 priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan;
2260 priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif;
Zhu Yib481de92007-09-25 17:54:57 -07002261 priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002262 iwl4965_rx_scan_results_notif;
Zhu Yib481de92007-09-25 17:54:57 -07002263 priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002264 iwl4965_rx_scan_complete_notif;
2265 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif;
2266 priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx;
Zhu Yib481de92007-09-25 17:54:57 -07002267
Ben Cahill9fbab512007-11-29 11:09:47 +08002268 /* Set up hardware specific Rx handlers */
Emmanuel Grumbachd4789ef2008-04-24 11:55:20 -07002269 priv->cfg->ops->lib->rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002270}
2271
2272/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002273 * iwl4965_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
Zhu Yib481de92007-09-25 17:54:57 -07002274 * @rxb: Rx buffer to reclaim
2275 *
2276 * If an Rx buffer has an async callback associated with it the callback
2277 * will be executed. The attached skb (if present) will only be freed
2278 * if the callback returns 1
2279 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002280static void iwl4965_tx_cmd_complete(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08002281 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002282{
Tomas Winklerdb11d632008-05-05 10:22:33 +08002283 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002284 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
2285 int txq_id = SEQ_TO_QUEUE(sequence);
2286 int index = SEQ_TO_INDEX(sequence);
2287 int huge = sequence & SEQ_HUGE_FRAME;
2288 int cmd_index;
Tomas Winkler857485c2008-03-21 13:53:44 -07002289 struct iwl_cmd *cmd;
Zhu Yib481de92007-09-25 17:54:57 -07002290
2291 /* If a Tx command is being handled and it isn't in the actual
2292 * command queue then there a command routing bug has been introduced
2293 * in the queue management code. */
2294 if (txq_id != IWL_CMD_QUEUE_NUM)
2295 IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
2296 txq_id, pkt->hdr.cmd);
2297 BUG_ON(txq_id != IWL_CMD_QUEUE_NUM);
2298
2299 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
2300 cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
2301
2302 /* Input error checking is done when commands are added to queue. */
2303 if (cmd->meta.flags & CMD_WANT_SKB) {
2304 cmd->meta.source->u.skb = rxb->skb;
2305 rxb->skb = NULL;
2306 } else if (cmd->meta.u.callback &&
2307 !cmd->meta.u.callback(priv, cmd, rxb->skb))
2308 rxb->skb = NULL;
2309
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002310 iwl4965_tx_queue_reclaim(priv, txq_id, index);
Zhu Yib481de92007-09-25 17:54:57 -07002311
2312 if (!(cmd->meta.flags & CMD_ASYNC)) {
2313 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
2314 wake_up_interruptible(&priv->wait_command_queue);
2315 }
2316}
2317
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002318/*
2319 * this should be called while priv->lock is locked
2320*/
Tomas Winklera55360e2008-05-05 10:22:28 +08002321static void __iwl_rx_replenish(struct iwl_priv *priv)
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002322{
Tomas Winklera55360e2008-05-05 10:22:28 +08002323 iwl_rx_allocate(priv);
2324 iwl_rx_queue_restock(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002325}
2326
2327
Zhu Yib481de92007-09-25 17:54:57 -07002328/**
Tomas Winklera55360e2008-05-05 10:22:28 +08002329 * iwl_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07002330 *
2331 * Uses the priv->rx_handlers callback function array to invoke
2332 * the appropriate handlers, including command responses,
2333 * frame-received notifications, and other notifications.
2334 */
Tomas Winklera55360e2008-05-05 10:22:28 +08002335void iwl_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002336{
Tomas Winklera55360e2008-05-05 10:22:28 +08002337 struct iwl_rx_mem_buffer *rxb;
Tomas Winklerdb11d632008-05-05 10:22:33 +08002338 struct iwl_rx_packet *pkt;
Tomas Winklera55360e2008-05-05 10:22:28 +08002339 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07002340 u32 r, i;
2341 int reclaim;
2342 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002343 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08002344 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07002345
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002346 /* uCode's read index (stored in shared DRAM) indicates the last Rx
2347 * buffer that the driver may process (last buffer filled by ucode). */
Ron Rindjunskyd67f5482008-05-05 10:22:49 +08002348 r = priv->cfg->ops->lib->shared_mem_rx_idx(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002349 i = rxq->read;
2350
2351 /* Rx interrupt, but nothing sent from uCode */
2352 if (i == r)
Ester Kummerf3d67992008-05-06 11:05:12 +08002353 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07002354
Tomas Winklera55360e2008-05-05 10:22:28 +08002355 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002356 fill_rx = 1;
2357
Zhu Yib481de92007-09-25 17:54:57 -07002358 while (i != r) {
2359 rxb = rxq->queue[i];
2360
Ben Cahill9fbab512007-11-29 11:09:47 +08002361 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07002362 * then a bug has been introduced in the queue refilling
2363 * routines -- catch it here */
2364 BUG_ON(rxb == NULL);
2365
2366 rxq->queue[i] = NULL;
2367
2368 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
Tomas Winkler5425e492008-04-15 16:01:38 -07002369 priv->hw_params.rx_buf_size,
Zhu Yib481de92007-09-25 17:54:57 -07002370 PCI_DMA_FROMDEVICE);
Tomas Winklerdb11d632008-05-05 10:22:33 +08002371 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002372
2373 /* Reclaim a command buffer only if this packet is a response
2374 * to a (driver-originated) command.
2375 * If the packet (e.g. Rx frame) originated from uCode,
2376 * there is no command buffer to reclaim.
2377 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
2378 * but apparently a few don't get set; catch them here. */
2379 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
2380 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
Tomas Winkler857485c2008-03-21 13:53:44 -07002381 (pkt->hdr.cmd != REPLY_RX) &&
Zhu Yicfe01702007-09-27 11:27:31 +08002382 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
Zhu Yib481de92007-09-25 17:54:57 -07002383 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
2384 (pkt->hdr.cmd != REPLY_TX);
2385
2386 /* Based on type of command response or notification,
2387 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002388 * rx_handlers table. See iwl4965_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07002389 if (priv->rx_handlers[pkt->hdr.cmd]) {
Ester Kummerf3d67992008-05-06 11:05:12 +08002390 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r,
2391 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
Zhu Yib481de92007-09-25 17:54:57 -07002392 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
2393 } else {
2394 /* No handling needed */
Ester Kummerf3d67992008-05-06 11:05:12 +08002395 IWL_DEBUG(IWL_DL_RX,
Zhu Yib481de92007-09-25 17:54:57 -07002396 "r %d i %d No handler needed for %s, 0x%02x\n",
2397 r, i, get_cmd_string(pkt->hdr.cmd),
2398 pkt->hdr.cmd);
2399 }
2400
2401 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08002402 /* Invoke any callbacks, transfer the skb to caller, and
Tomas Winkler857485c2008-03-21 13:53:44 -07002403 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07002404 * as we reclaim the driver command queue */
2405 if (rxb && rxb->skb)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002406 iwl4965_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07002407 else
2408 IWL_WARNING("Claim null rxb?\n");
2409 }
2410
2411 /* For now we just don't re-use anything. We can tweak this
2412 * later to try and re-use notification packets and SKBs that
2413 * fail to Rx correctly */
2414 if (rxb->skb != NULL) {
2415 priv->alloc_rxb_skb--;
2416 dev_kfree_skb_any(rxb->skb);
2417 rxb->skb = NULL;
2418 }
2419
2420 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
Tomas Winkler5425e492008-04-15 16:01:38 -07002421 priv->hw_params.rx_buf_size,
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02002422 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07002423 spin_lock_irqsave(&rxq->lock, flags);
2424 list_add_tail(&rxb->list, &priv->rxq.rx_used);
2425 spin_unlock_irqrestore(&rxq->lock, flags);
2426 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002427 /* If there are a lot of unused frames,
2428 * restock the Rx queue so ucode wont assert. */
2429 if (fill_rx) {
2430 count++;
2431 if (count >= 8) {
2432 priv->rxq.read = i;
Tomas Winklera55360e2008-05-05 10:22:28 +08002433 __iwl_rx_replenish(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002434 count = 0;
2435 }
2436 }
Zhu Yib481de92007-09-25 17:54:57 -07002437 }
2438
2439 /* Backtrack one entry */
2440 priv->rxq.read = i;
Tomas Winklera55360e2008-05-05 10:22:28 +08002441 iwl_rx_queue_restock(priv);
2442}
2443/* Convert linear signal-to-noise ratio into dB */
2444static u8 ratio2dB[100] = {
2445/* 0 1 2 3 4 5 6 7 8 9 */
2446 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
2447 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
2448 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
2449 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
2450 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
2451 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
2452 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
2453 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
2454 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
2455 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
2456};
2457
2458/* Calculates a relative dB value from a ratio of linear
2459 * (i.e. not dB) signal levels.
2460 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
2461int iwl4965_calc_db_from_ratio(int sig_ratio)
2462{
2463 /* 1000:1 or higher just report as 60 dB */
2464 if (sig_ratio >= 1000)
2465 return 60;
2466
2467 /* 100:1 or higher, divide by 10 and use table,
2468 * add 20 dB to make up for divide by 10 */
2469 if (sig_ratio >= 100)
2470 return (20 + (int)ratio2dB[sig_ratio/10]);
2471
2472 /* We shouldn't see this */
2473 if (sig_ratio < 1)
2474 return 0;
2475
2476 /* Use table for ratios 1:1 - 99:1 */
2477 return (int)ratio2dB[sig_ratio];
2478}
2479
2480#define PERFECT_RSSI (-20) /* dBm */
2481#define WORST_RSSI (-95) /* dBm */
2482#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
2483
2484/* Calculate an indication of rx signal quality (a percentage, not dBm!).
2485 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
2486 * about formulas used below. */
2487int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm)
2488{
2489 int sig_qual;
2490 int degradation = PERFECT_RSSI - rssi_dbm;
2491
2492 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
2493 * as indicator; formula is (signal dbm - noise dbm).
2494 * SNR at or above 40 is a great signal (100%).
2495 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
2496 * Weakest usable signal is usually 10 - 15 dB SNR. */
2497 if (noise_dbm) {
2498 if (rssi_dbm - noise_dbm >= 40)
2499 return 100;
2500 else if (rssi_dbm < noise_dbm)
2501 return 0;
2502 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
2503
2504 /* Else use just the signal level.
2505 * This formula is a least squares fit of data points collected and
2506 * compared with a reference system that had a percentage (%) display
2507 * for signal quality. */
2508 } else
2509 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
2510 (15 * RSSI_RANGE + 62 * degradation)) /
2511 (RSSI_RANGE * RSSI_RANGE);
2512
2513 if (sig_qual > 100)
2514 sig_qual = 100;
2515 else if (sig_qual < 1)
2516 sig_qual = 0;
2517
2518 return sig_qual;
Zhu Yib481de92007-09-25 17:54:57 -07002519}
2520
Tomas Winkler0a6857e2008-03-12 16:58:49 -07002521#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08002522static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002523{
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08002524 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
Joe Perches0795af52007-10-03 17:59:30 -07002525 DECLARE_MAC_BUF(mac);
2526
Zhu Yib481de92007-09-25 17:54:57 -07002527 IWL_DEBUG_RADIO("RX CONFIG:\n");
Ester Kummerbf403db2008-05-05 10:22:40 +08002528 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
Zhu Yib481de92007-09-25 17:54:57 -07002529 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
2530 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
2531 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
2532 le32_to_cpu(rxon->filter_flags));
2533 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
2534 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
2535 rxon->ofdm_basic_rates);
2536 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
Joe Perches0795af52007-10-03 17:59:30 -07002537 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
2538 print_mac(mac, rxon->node_addr));
2539 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
2540 print_mac(mac, rxon->bssid_addr));
Zhu Yib481de92007-09-25 17:54:57 -07002541 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
2542}
2543#endif
2544
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002545static void iwl4965_enable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002546{
2547 IWL_DEBUG_ISR("Enabling interrupts\n");
2548 set_bit(STATUS_INT_ENABLED, &priv->status);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002549 iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07002550}
2551
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002552/* call this function to flush any scheduled tasklet */
2553static inline void iwl_synchronize_irq(struct iwl_priv *priv)
2554{
2555 /* wait to make sure we flush pedding tasklet*/
2556 synchronize_irq(priv->pci_dev->irq);
2557 tasklet_kill(&priv->irq_tasklet);
2558}
2559
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002560static inline void iwl4965_disable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002561{
2562 clear_bit(STATUS_INT_ENABLED, &priv->status);
2563
2564 /* disable interrupts from uCode/NIC to host */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002565 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07002566
2567 /* acknowledge/clear/reset any interrupts still pending
2568 * from uCode or flow handler (Rx/Tx DMA) */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002569 iwl_write32(priv, CSR_INT, 0xffffffff);
2570 iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
Zhu Yib481de92007-09-25 17:54:57 -07002571 IWL_DEBUG_ISR("Disabled interrupts\n");
2572}
2573
Zhu Yib481de92007-09-25 17:54:57 -07002574
Zhu Yib481de92007-09-25 17:54:57 -07002575/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002576 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
Zhu Yib481de92007-09-25 17:54:57 -07002577 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002578static void iwl4965_irq_handle_error(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002579{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002580 /* Set the FW error flag -- cleared on iwl4965_down */
Zhu Yib481de92007-09-25 17:54:57 -07002581 set_bit(STATUS_FW_ERROR, &priv->status);
2582
2583 /* Cancel currently queued command. */
2584 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
2585
Tomas Winkler0a6857e2008-03-12 16:58:49 -07002586#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08002587 if (priv->debug_level & IWL_DL_FW_ERRORS) {
Ester Kummerede0cba2008-05-29 16:34:46 +08002588 iwl_dump_nic_error_log(priv);
Ester Kummer189a2b52008-05-15 13:54:18 +08002589 iwl_dump_nic_event_log(priv);
Ester Kummerbf403db2008-05-05 10:22:40 +08002590 iwl4965_print_rx_config_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002591 }
2592#endif
2593
2594 wake_up_interruptible(&priv->wait_command_queue);
2595
2596 /* Keep the restart process from trying to send host
2597 * commands by clearing the INIT status bit */
2598 clear_bit(STATUS_READY, &priv->status);
2599
2600 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Ester Kummerf3d67992008-05-06 11:05:12 +08002601 IWL_DEBUG(IWL_DL_FW_ERRORS,
Zhu Yib481de92007-09-25 17:54:57 -07002602 "Restarting adapter due to uCode error.\n");
2603
Tomas Winkler3109ece2008-03-28 16:33:35 -07002604 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002605 memcpy(&priv->recovery_rxon, &priv->active_rxon,
2606 sizeof(priv->recovery_rxon));
2607 priv->error_recovering = 1;
2608 }
Ester Kummer3a1081e2008-05-06 11:05:14 +08002609 if (priv->cfg->mod_params->restart_fw)
2610 queue_work(priv->workqueue, &priv->restart);
Zhu Yib481de92007-09-25 17:54:57 -07002611 }
2612}
2613
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002614static void iwl4965_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002615{
2616 unsigned long flags;
2617
2618 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
2619 sizeof(priv->staging_rxon));
2620 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002621 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002622
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002623 iwl_rxon_add_station(priv, priv->bssid, 1);
Zhu Yib481de92007-09-25 17:54:57 -07002624
2625 spin_lock_irqsave(&priv->lock, flags);
2626 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
2627 priv->error_recovering = 0;
2628 spin_unlock_irqrestore(&priv->lock, flags);
2629}
2630
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002631static void iwl4965_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002632{
2633 u32 inta, handled = 0;
2634 u32 inta_fh;
2635 unsigned long flags;
Tomas Winkler0a6857e2008-03-12 16:58:49 -07002636#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07002637 u32 inta_mask;
2638#endif
2639
2640 spin_lock_irqsave(&priv->lock, flags);
2641
2642 /* Ack/clear/reset pending uCode interrupts.
2643 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
2644 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002645 inta = iwl_read32(priv, CSR_INT);
2646 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07002647
2648 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
2649 * Any new interrupts that happen after this, either while we're
2650 * in this tasklet, or later, will show up in next ISR/tasklet. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002651 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
2652 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002653
Tomas Winkler0a6857e2008-03-12 16:58:49 -07002654#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08002655 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08002656 /* just for debug */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002657 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07002658 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
2659 inta, inta_mask, inta_fh);
2660 }
2661#endif
2662
2663 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
2664 * atomic, make sure that inta covers all the interrupts that
2665 * we've discovered, even if FH interrupt came in just after
2666 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002667 if (inta_fh & CSR49_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002668 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002669 if (inta_fh & CSR49_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002670 inta |= CSR_INT_BIT_FH_TX;
2671
2672 /* Now service all interrupt bits discovered above. */
2673 if (inta & CSR_INT_BIT_HW_ERR) {
2674 IWL_ERROR("Microcode HW error detected. Restarting.\n");
2675
2676 /* Tell the device to stop sending interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002677 iwl4965_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002678
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002679 iwl4965_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002680
2681 handled |= CSR_INT_BIT_HW_ERR;
2682
2683 spin_unlock_irqrestore(&priv->lock, flags);
2684
2685 return;
2686 }
2687
Tomas Winkler0a6857e2008-03-12 16:58:49 -07002688#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08002689 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07002690 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002691 if (inta & CSR_INT_BIT_SCD)
2692 IWL_DEBUG_ISR("Scheduler finished to transmit "
2693 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002694
2695 /* Alive notification via Rx interrupt will do the real work */
2696 if (inta & CSR_INT_BIT_ALIVE)
2697 IWL_DEBUG_ISR("Alive interrupt\n");
2698 }
2699#endif
2700 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002701 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07002702
Ben Cahill9fbab512007-11-29 11:09:47 +08002703 /* HW RF KILL switch toggled */
Zhu Yib481de92007-09-25 17:54:57 -07002704 if (inta & CSR_INT_BIT_RF_KILL) {
2705 int hw_rf_kill = 0;
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002706 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yib481de92007-09-25 17:54:57 -07002707 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
2708 hw_rf_kill = 1;
2709
Ester Kummerf3d67992008-05-06 11:05:12 +08002710 IWL_DEBUG(IWL_DL_RF_KILL, "RF_KILL bit toggled to %s.\n",
Zhu Yib481de92007-09-25 17:54:57 -07002711 hw_rf_kill ? "disable radio":"enable radio");
2712
2713 /* Queue restart only if RF_KILL switch was set to "kill"
2714 * when we loaded driver, and is now set to "enable".
2715 * After we're Alive, RF_KILL gets handled by
Reinette Chatre32304552008-02-15 14:34:37 -08002716 * iwl4965_rx_card_state_notif() */
Zhu Yi53e49092007-12-06 16:08:44 +08002717 if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) {
2718 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002719 queue_work(priv->workqueue, &priv->restart);
Zhu Yi53e49092007-12-06 16:08:44 +08002720 }
Zhu Yib481de92007-09-25 17:54:57 -07002721
2722 handled |= CSR_INT_BIT_RF_KILL;
2723 }
2724
Ben Cahill9fbab512007-11-29 11:09:47 +08002725 /* Chip got too hot and stopped itself */
Zhu Yib481de92007-09-25 17:54:57 -07002726 if (inta & CSR_INT_BIT_CT_KILL) {
2727 IWL_ERROR("Microcode CT kill error detected.\n");
2728 handled |= CSR_INT_BIT_CT_KILL;
2729 }
2730
2731 /* Error detected by uCode */
2732 if (inta & CSR_INT_BIT_SW_ERR) {
2733 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
2734 inta);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002735 iwl4965_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002736 handled |= CSR_INT_BIT_SW_ERR;
2737 }
2738
2739 /* uCode wakes up after power-down sleep */
2740 if (inta & CSR_INT_BIT_WAKEUP) {
2741 IWL_DEBUG_ISR("Wakeup interrupt\n");
Tomas Winklera55360e2008-05-05 10:22:28 +08002742 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Tomas Winklerbabcebf2008-05-15 13:54:00 +08002743 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
2744 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
2745 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
2746 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
2747 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
2748 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07002749
2750 handled |= CSR_INT_BIT_WAKEUP;
2751 }
2752
2753 /* All uCode command responses, including Tx command responses,
2754 * Rx "responses" (frame-received notification), and other
2755 * notifications from uCode come through here*/
2756 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Tomas Winklera55360e2008-05-05 10:22:28 +08002757 iwl_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002758 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
2759 }
2760
2761 if (inta & CSR_INT_BIT_FH_TX) {
2762 IWL_DEBUG_ISR("Tx interrupt\n");
2763 handled |= CSR_INT_BIT_FH_TX;
Ron Rindjunskydbb983b2008-05-15 13:54:12 +08002764 /* FH finished to write, send event */
2765 priv->ucode_write_complete = 1;
2766 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07002767 }
2768
2769 if (inta & ~handled)
2770 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
2771
2772 if (inta & ~CSR_INI_SET_MASK) {
2773 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
2774 inta & ~CSR_INI_SET_MASK);
2775 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
2776 }
2777
2778 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002779 /* only Re-enable if diabled by irq */
2780 if (test_bit(STATUS_INT_ENABLED, &priv->status))
2781 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002782
Tomas Winkler0a6857e2008-03-12 16:58:49 -07002783#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08002784 if (priv->debug_level & (IWL_DL_ISR)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002785 inta = iwl_read32(priv, CSR_INT);
2786 inta_mask = iwl_read32(priv, CSR_INT_MASK);
2787 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07002788 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
2789 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
2790 }
2791#endif
2792 spin_unlock_irqrestore(&priv->lock, flags);
2793}
2794
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002795static irqreturn_t iwl4965_isr(int irq, void *data)
Zhu Yib481de92007-09-25 17:54:57 -07002796{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002797 struct iwl_priv *priv = data;
Zhu Yib481de92007-09-25 17:54:57 -07002798 u32 inta, inta_mask;
2799 u32 inta_fh;
2800 if (!priv)
2801 return IRQ_NONE;
2802
2803 spin_lock(&priv->lock);
2804
2805 /* Disable (but don't clear!) interrupts here to avoid
2806 * back-to-back ISRs and sporadic interrupts from our NIC.
2807 * If we have something to service, the tasklet will re-enable ints.
2808 * If we *don't* have something, we'll re-enable before leaving here. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002809 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
2810 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07002811
2812 /* Discover which interrupts are active/pending */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002813 inta = iwl_read32(priv, CSR_INT);
2814 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07002815
2816 /* Ignore interrupt if there's nothing in NIC to service.
2817 * This may be due to IRQ shared with another device,
2818 * or due to sporadic interrupts thrown from our NIC. */
2819 if (!inta && !inta_fh) {
2820 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
2821 goto none;
2822 }
2823
2824 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
Oliver Neukum66fbb542007-11-15 09:31:10 +08002825 /* Hardware disappeared. It might have already raised
2826 * an interrupt */
Zhu Yib481de92007-09-25 17:54:57 -07002827 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
Oliver Neukum66fbb542007-11-15 09:31:10 +08002828 goto unplugged;
Zhu Yib481de92007-09-25 17:54:57 -07002829 }
2830
2831 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
2832 inta, inta_mask, inta_fh);
2833
Joonwoo Park25c03d82008-01-23 10:15:20 -08002834 inta &= ~CSR_INT_BIT_SCD;
2835
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002836 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002837 if (likely(inta || inta_fh))
2838 tasklet_schedule(&priv->irq_tasklet);
Zhu Yib481de92007-09-25 17:54:57 -07002839
Oliver Neukum66fbb542007-11-15 09:31:10 +08002840 unplugged:
2841 spin_unlock(&priv->lock);
Zhu Yib481de92007-09-25 17:54:57 -07002842 return IRQ_HANDLED;
2843
2844 none:
2845 /* re-enable interrupts here since we don't have anything to service. */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002846 /* only Re-enable if diabled by irq */
2847 if (test_bit(STATUS_INT_ENABLED, &priv->status))
2848 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002849 spin_unlock(&priv->lock);
2850 return IRQ_NONE;
2851}
2852
Zhu Yib481de92007-09-25 17:54:57 -07002853/* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
2854 * sending probe req. This should be set long enough to hear probe responses
2855 * from more than one AP. */
2856#define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
2857#define IWL_ACTIVE_DWELL_TIME_52 (10)
2858
2859/* For faster active scanning, scan will move to the next channel if fewer than
2860 * PLCP_QUIET_THRESH packets are heard on this channel within
2861 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
2862 * time if it's a quiet channel (nothing responded to our probe, and there's
2863 * no other traffic).
2864 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
2865#define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
2866#define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
2867
2868/* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
2869 * Must be set longer than active dwell time.
2870 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
2871#define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
2872#define IWL_PASSIVE_DWELL_TIME_52 (10)
2873#define IWL_PASSIVE_DWELL_BASE (100)
2874#define IWL_CHANNEL_TUNE_TIME 5
2875
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002876static inline u16 iwl4965_get_active_dwell_time(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01002877 enum ieee80211_band band)
Zhu Yib481de92007-09-25 17:54:57 -07002878{
Johannes Berg8318d782008-01-24 19:38:38 +01002879 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07002880 return IWL_ACTIVE_DWELL_TIME_52;
2881 else
2882 return IWL_ACTIVE_DWELL_TIME_24;
2883}
2884
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002885static u16 iwl4965_get_passive_dwell_time(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01002886 enum ieee80211_band band)
Zhu Yib481de92007-09-25 17:54:57 -07002887{
Johannes Berg8318d782008-01-24 19:38:38 +01002888 u16 active = iwl4965_get_active_dwell_time(priv, band);
2889 u16 passive = (band != IEEE80211_BAND_5GHZ) ?
Zhu Yib481de92007-09-25 17:54:57 -07002890 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
2891 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
2892
Tomas Winkler3109ece2008-03-28 16:33:35 -07002893 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002894 /* If we're associated, we clamp the maximum passive
2895 * dwell time to be 98% of the beacon interval (minus
2896 * 2 * channel tune time) */
2897 passive = priv->beacon_int;
2898 if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive)
2899 passive = IWL_PASSIVE_DWELL_BASE;
2900 passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
2901 }
2902
2903 if (passive <= active)
2904 passive = active + 1;
2905
2906 return passive;
2907}
2908
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002909static int iwl4965_get_channels_for_scan(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01002910 enum ieee80211_band band,
Zhu Yib481de92007-09-25 17:54:57 -07002911 u8 is_active, u8 direct_mask,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002912 struct iwl4965_scan_channel *scan_ch)
Zhu Yib481de92007-09-25 17:54:57 -07002913{
2914 const struct ieee80211_channel *channels = NULL;
Johannes Berg8318d782008-01-24 19:38:38 +01002915 const struct ieee80211_supported_band *sband;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07002916 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07002917 u16 passive_dwell = 0;
2918 u16 active_dwell = 0;
2919 int added, i;
2920
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -07002921 sband = iwl_get_hw_mode(priv, band);
Johannes Berg8318d782008-01-24 19:38:38 +01002922 if (!sband)
Zhu Yib481de92007-09-25 17:54:57 -07002923 return 0;
2924
Johannes Berg8318d782008-01-24 19:38:38 +01002925 channels = sband->channels;
Zhu Yib481de92007-09-25 17:54:57 -07002926
Johannes Berg8318d782008-01-24 19:38:38 +01002927 active_dwell = iwl4965_get_active_dwell_time(priv, band);
2928 passive_dwell = iwl4965_get_passive_dwell_time(priv, band);
Zhu Yib481de92007-09-25 17:54:57 -07002929
Johannes Berg8318d782008-01-24 19:38:38 +01002930 for (i = 0, added = 0; i < sband->n_channels; i++) {
Johannes Berg182e2e62008-04-04 10:41:56 +02002931 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
2932 continue;
2933
Johannes Berg8318d782008-01-24 19:38:38 +01002934 scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq);
Zhu Yib481de92007-09-25 17:54:57 -07002935
Assaf Krauss8622e702008-03-21 13:53:43 -07002936 ch_info = iwl_get_channel_info(priv, band,
Ben Cahill9fbab512007-11-29 11:09:47 +08002937 scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07002938 if (!is_channel_valid(ch_info)) {
2939 IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
2940 scan_ch->channel);
2941 continue;
2942 }
2943
2944 if (!is_active || is_channel_passive(ch_info) ||
Johannes Berg8318d782008-01-24 19:38:38 +01002945 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN))
Zhu Yib481de92007-09-25 17:54:57 -07002946 scan_ch->type = 0; /* passive */
2947 else
2948 scan_ch->type = 1; /* active */
2949
2950 if (scan_ch->type & 1)
2951 scan_ch->type |= (direct_mask << 1);
2952
Zhu Yib481de92007-09-25 17:54:57 -07002953 scan_ch->active_dwell = cpu_to_le16(active_dwell);
2954 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
2955
Ben Cahill9fbab512007-11-29 11:09:47 +08002956 /* Set txpower levels to defaults */
Zhu Yib481de92007-09-25 17:54:57 -07002957 scan_ch->tpc.dsp_atten = 110;
2958 /* scan_pwr_info->tpc.dsp_atten; */
2959
2960 /*scan_pwr_info->tpc.tx_gain; */
Johannes Berg8318d782008-01-24 19:38:38 +01002961 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07002962 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
2963 else {
2964 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
2965 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
Ben Cahill9fbab512007-11-29 11:09:47 +08002966 * power level:
Reinette Chatre8a1b0242008-01-14 17:46:25 -08002967 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
Zhu Yib481de92007-09-25 17:54:57 -07002968 */
2969 }
2970
2971 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
2972 scan_ch->channel,
2973 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
2974 (scan_ch->type & 1) ?
2975 active_dwell : passive_dwell);
2976
2977 scan_ch++;
2978 added++;
2979 }
2980
2981 IWL_DEBUG_SCAN("total channels to scan %d \n", added);
2982 return added;
2983}
2984
Zhu Yib481de92007-09-25 17:54:57 -07002985/******************************************************************************
2986 *
2987 * uCode download functions
2988 *
2989 ******************************************************************************/
2990
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002991static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002992{
Tomas Winkler98c92212008-01-14 17:46:20 -08002993 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
2994 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
2995 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
2996 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
2997 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
2998 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07002999}
3000
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08003001static void iwl4965_nic_start(struct iwl_priv *priv)
3002{
3003 /* Remove all resets to allow NIC to operate */
3004 iwl_write32(priv, CSR_RESET, 0);
3005}
3006
3007
Zhu Yib481de92007-09-25 17:54:57 -07003008/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003009 * iwl4965_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07003010 *
3011 * Copy into buffers for card to fetch via bus-mastering
3012 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003013static int iwl4965_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003014{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003015 struct iwl4965_ucode *ucode;
Tomas Winkler90e759d2007-11-29 11:09:41 +08003016 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003017 const struct firmware *ucode_raw;
Tomas Winkler4bf775c2008-03-04 18:09:31 -08003018 const char *name = priv->cfg->fw_name;
Zhu Yib481de92007-09-25 17:54:57 -07003019 u8 *src;
3020 size_t len;
3021 u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
3022
3023 /* Ask kernel firmware_class module to get the boot firmware off disk.
3024 * request_firmware() is synchronous, file is in memory on return. */
Tomas Winkler90e759d2007-11-29 11:09:41 +08003025 ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
3026 if (ret < 0) {
3027 IWL_ERROR("%s firmware file req failed: Reason %d\n",
3028 name, ret);
Zhu Yib481de92007-09-25 17:54:57 -07003029 goto error;
3030 }
3031
3032 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
3033 name, ucode_raw->size);
3034
3035 /* Make sure that we got at least our header! */
3036 if (ucode_raw->size < sizeof(*ucode)) {
3037 IWL_ERROR("File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08003038 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003039 goto err_release;
3040 }
3041
3042 /* Data from ucode file: header followed by uCode images */
3043 ucode = (void *)ucode_raw->data;
3044
3045 ver = le32_to_cpu(ucode->ver);
3046 inst_size = le32_to_cpu(ucode->inst_size);
3047 data_size = le32_to_cpu(ucode->data_size);
3048 init_size = le32_to_cpu(ucode->init_size);
3049 init_data_size = le32_to_cpu(ucode->init_data_size);
3050 boot_size = le32_to_cpu(ucode->boot_size);
3051
3052 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
3053 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
3054 inst_size);
3055 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
3056 data_size);
3057 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
3058 init_size);
3059 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
3060 init_data_size);
3061 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
3062 boot_size);
3063
3064 /* Verify size of file vs. image size info in file's header */
3065 if (ucode_raw->size < sizeof(*ucode) +
3066 inst_size + data_size + init_size +
3067 init_data_size + boot_size) {
3068
3069 IWL_DEBUG_INFO("uCode file size %d too small\n",
3070 (int)ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08003071 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003072 goto err_release;
3073 }
3074
3075 /* Verify that uCode images will fit in card's SRAM */
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07003076 if (inst_size > priv->hw_params.max_inst_size) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08003077 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
3078 inst_size);
3079 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003080 goto err_release;
3081 }
3082
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07003083 if (data_size > priv->hw_params.max_data_size) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08003084 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
3085 data_size);
3086 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003087 goto err_release;
3088 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07003089 if (init_size > priv->hw_params.max_inst_size) {
Zhu Yib481de92007-09-25 17:54:57 -07003090 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08003091 ("uCode init instr len %d too large to fit in\n",
3092 init_size);
3093 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003094 goto err_release;
3095 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07003096 if (init_data_size > priv->hw_params.max_data_size) {
Zhu Yib481de92007-09-25 17:54:57 -07003097 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08003098 ("uCode init data len %d too large to fit in\n",
3099 init_data_size);
3100 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003101 goto err_release;
3102 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07003103 if (boot_size > priv->hw_params.max_bsm_size) {
Zhu Yib481de92007-09-25 17:54:57 -07003104 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08003105 ("uCode boot instr len %d too large to fit in\n",
3106 boot_size);
3107 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003108 goto err_release;
3109 }
3110
3111 /* Allocate ucode buffers for card's bus-master loading ... */
3112
3113 /* Runtime instructions and 2 copies of data:
3114 * 1) unmodified from disk
3115 * 2) backup cache for save/restore during power-downs */
3116 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003117 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07003118
3119 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003120 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07003121
3122 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003123 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07003124
3125 /* Initialization instructions and data */
Tomas Winkler90e759d2007-11-29 11:09:41 +08003126 if (init_size && init_data_size) {
3127 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003128 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Zhu Yib481de92007-09-25 17:54:57 -07003129
Tomas Winkler90e759d2007-11-29 11:09:41 +08003130 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003131 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08003132
3133 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
3134 goto err_pci_alloc;
3135 }
Zhu Yib481de92007-09-25 17:54:57 -07003136
3137 /* Bootstrap (instructions only, no data) */
Tomas Winkler90e759d2007-11-29 11:09:41 +08003138 if (boot_size) {
3139 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08003140 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07003141
Tomas Winkler90e759d2007-11-29 11:09:41 +08003142 if (!priv->ucode_boot.v_addr)
3143 goto err_pci_alloc;
3144 }
Zhu Yib481de92007-09-25 17:54:57 -07003145
3146 /* Copy images into buffers for card's bus-master reads ... */
3147
3148 /* Runtime instructions (first block of data in file) */
3149 src = &ucode->data[0];
3150 len = priv->ucode_code.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08003151 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07003152 memcpy(priv->ucode_code.v_addr, src, len);
3153 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
3154 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
3155
3156 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003157 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
Zhu Yib481de92007-09-25 17:54:57 -07003158 src = &ucode->data[inst_size];
3159 len = priv->ucode_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08003160 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07003161 memcpy(priv->ucode_data.v_addr, src, len);
3162 memcpy(priv->ucode_data_backup.v_addr, src, len);
3163
3164 /* Initialization instructions (3rd block) */
3165 if (init_size) {
3166 src = &ucode->data[inst_size + data_size];
3167 len = priv->ucode_init.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08003168 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
3169 len);
Zhu Yib481de92007-09-25 17:54:57 -07003170 memcpy(priv->ucode_init.v_addr, src, len);
3171 }
3172
3173 /* Initialization data (4th block) */
3174 if (init_data_size) {
3175 src = &ucode->data[inst_size + data_size + init_size];
3176 len = priv->ucode_init_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08003177 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
3178 len);
Zhu Yib481de92007-09-25 17:54:57 -07003179 memcpy(priv->ucode_init_data.v_addr, src, len);
3180 }
3181
3182 /* Bootstrap instructions (5th block) */
3183 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
3184 len = priv->ucode_boot.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08003185 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07003186 memcpy(priv->ucode_boot.v_addr, src, len);
3187
3188 /* We have our copies now, allow OS release its copies */
3189 release_firmware(ucode_raw);
3190 return 0;
3191
3192 err_pci_alloc:
3193 IWL_ERROR("failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08003194 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003195 iwl4965_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003196
3197 err_release:
3198 release_firmware(ucode_raw);
3199
3200 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08003201 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003202}
3203
Zhu Yib481de92007-09-25 17:54:57 -07003204/**
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08003205 * iwl_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07003206 * from protocol/runtime uCode (initialization uCode's
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08003207 * Alive gets handled by iwl_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07003208 */
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08003209static void iwl_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003210{
Tomas Winkler57aab752008-04-14 21:16:03 -07003211 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003212
3213 IWL_DEBUG_INFO("Runtime Alive received.\n");
3214
3215 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
3216 /* We had an error bringing up the hardware, so take it
3217 * all the way back down so we can try again */
3218 IWL_DEBUG_INFO("Alive failed.\n");
3219 goto restart;
3220 }
3221
3222 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
3223 * This is a paranoid check, because we would not have gotten the
3224 * "runtime" alive if code weren't properly loaded. */
Emmanuel Grumbachb0692f22008-04-24 11:55:18 -07003225 if (iwl_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003226 /* Runtime instruction load was bad;
3227 * take it all the way back down so we can try again */
3228 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
3229 goto restart;
3230 }
3231
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003232 iwlcore_clear_stations_table(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07003233 ret = priv->cfg->ops->lib->alive_notify(priv);
3234 if (ret) {
Zhu Yib481de92007-09-25 17:54:57 -07003235 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
Tomas Winkler57aab752008-04-14 21:16:03 -07003236 ret);
Zhu Yib481de92007-09-25 17:54:57 -07003237 goto restart;
3238 }
3239
Ben Cahill9fbab512007-11-29 11:09:47 +08003240 /* After the ALIVE response, we can send host commands to 4965 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07003241 set_bit(STATUS_ALIVE, &priv->status);
3242
3243 /* Clear out the uCode error bit if it is set */
3244 clear_bit(STATUS_FW_ERROR, &priv->status);
3245
Tomas Winklerfee12472008-04-03 16:05:21 -07003246 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003247 return;
3248
Johannes Berg36d68252008-05-15 12:55:26 +02003249 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07003250
3251 priv->active_rate = priv->rates_mask;
3252 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
3253
Tomas Winkler3109ece2008-03-28 16:33:35 -07003254 if (iwl_is_associated(priv)) {
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08003255 struct iwl_rxon_cmd *active_rxon =
3256 (struct iwl_rxon_cmd *)&priv->active_rxon;
Zhu Yib481de92007-09-25 17:54:57 -07003257
3258 memcpy(&priv->staging_rxon, &priv->active_rxon,
3259 sizeof(priv->staging_rxon));
3260 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3261 } else {
3262 /* Initialize our rx_config data */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003263 iwl4965_connection_init_rx_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003264 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
3265 }
3266
Ben Cahill9fbab512007-11-29 11:09:47 +08003267 /* Configure Bluetooth device coexistence support */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003268 iwl4965_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003269
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08003270 iwl_reset_run_time_calib(priv);
3271
Zhu Yib481de92007-09-25 17:54:57 -07003272 /* Configure the adapter for unassociated operation */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003273 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003274
3275 /* At this point, the NIC is initialized and operational */
Zhu Yib481de92007-09-25 17:54:57 -07003276 iwl4965_rf_kill_ct_config(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003277
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07003278 iwl_leds_register(priv);
3279
Zhu Yib481de92007-09-25 17:54:57 -07003280 IWL_DEBUG_INFO("ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07003281 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003282 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07003283
3284 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003285 iwl4965_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003286
Mohamed Abbasc8381fd2008-03-28 16:21:05 -07003287 iwlcore_low_level_notify(priv, IWLCORE_START_EVT);
Mohamed Abbas84363e62008-04-04 16:59:58 -07003288 ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC);
Zhu Yib481de92007-09-25 17:54:57 -07003289 return;
3290
3291 restart:
3292 queue_work(priv->workqueue, &priv->restart);
3293}
3294
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003295static void iwl4965_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07003296
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003297static void __iwl4965_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003298{
3299 unsigned long flags;
3300 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003301
3302 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
3303
Zhu Yib481de92007-09-25 17:54:57 -07003304 if (!exit_pending)
3305 set_bit(STATUS_EXIT_PENDING, &priv->status);
3306
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07003307 iwl_leds_unregister(priv);
3308
Mohamed Abbasc8381fd2008-03-28 16:21:05 -07003309 iwlcore_low_level_notify(priv, IWLCORE_STOP_EVT);
3310
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003311 iwlcore_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003312
3313 /* Unblock any waiting calls */
3314 wake_up_interruptible_all(&priv->wait_command_queue);
3315
Zhu Yib481de92007-09-25 17:54:57 -07003316 /* Wipe out the EXIT_PENDING status bit if we are not actually
3317 * exiting the module */
3318 if (!exit_pending)
3319 clear_bit(STATUS_EXIT_PENDING, &priv->status);
3320
3321 /* stop and reset the on-board processor */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07003322 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07003323
3324 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003325 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003326 iwl4965_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003327 spin_unlock_irqrestore(&priv->lock, flags);
3328 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003329
3330 if (priv->mac80211_registered)
3331 ieee80211_stop_queues(priv->hw);
3332
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003333 /* If we have not previously called iwl4965_init() then
Zhu Yib481de92007-09-25 17:54:57 -07003334 * clear all bits but the RF Kill and SUSPEND bits and return */
Tomas Winklerfee12472008-04-03 16:05:21 -07003335 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003336 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3337 STATUS_RF_KILL_HW |
3338 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3339 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003340 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3341 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003342 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
3343 STATUS_IN_SUSPEND;
3344 goto exit;
3345 }
3346
3347 /* ...otherwise clear out all the status bits but the RF Kill and
3348 * SUSPEND bits and continue taking the NIC down. */
3349 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3350 STATUS_RF_KILL_HW |
3351 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3352 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003353 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3354 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003355 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
3356 STATUS_IN_SUSPEND |
3357 test_bit(STATUS_FW_ERROR, &priv->status) <<
3358 STATUS_FW_ERROR;
3359
3360 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07003361 iwl_clear_bit(priv, CSR_GP_CNTRL,
Ben Cahill9fbab512007-11-29 11:09:47 +08003362 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07003363 spin_unlock_irqrestore(&priv->lock, flags);
3364
Tomas Winklerda1bc452008-05-29 16:35:00 +08003365 iwl_txq_ctx_stop(priv);
Tomas Winklerb3bbacb2008-05-29 16:35:01 +08003366 iwl_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003367
3368 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07003369 if (!iwl_grab_nic_access(priv)) {
3370 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07003371 APMG_CLK_VAL_DMA_CLK_RQT);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07003372 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003373 }
3374 spin_unlock_irqrestore(&priv->lock, flags);
3375
3376 udelay(5);
3377
Tomas Winkler7f066102008-05-29 16:34:57 +08003378 /* FIXME: apm_ops.suspend(priv) */
3379 priv->cfg->ops->lib->apm_ops.reset(priv);
Ron Rindjunsky399f4902008-04-23 17:14:56 -07003380 priv->cfg->ops->lib->free_shared_mem(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003381
3382 exit:
Tomas Winkler885ba202008-05-29 16:34:55 +08003383 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07003384
3385 if (priv->ibss_beacon)
3386 dev_kfree_skb(priv->ibss_beacon);
3387 priv->ibss_beacon = NULL;
3388
3389 /* clear out any free frames */
Tomas Winklerfcab4232008-05-15 13:54:01 +08003390 iwl_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003391}
3392
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003393static void iwl4965_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003394{
3395 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003396 __iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003397 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08003398
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003399 iwl4965_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003400}
3401
3402#define MAX_HW_RESTARTS 5
3403
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003404static int __iwl4965_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003405{
Tomas Winkler57aab752008-04-14 21:16:03 -07003406 int i;
3407 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003408
3409 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
3410 IWL_WARNING("Exit pending; will not bring the NIC up\n");
3411 return -EIO;
3412 }
3413
3414 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
3415 IWL_WARNING("Radio disabled by SW RF kill (module "
3416 "parameter)\n");
Mohamed Abbasad97edd2008-03-28 16:21:06 -07003417 iwl_rfkill_set_hw_state(priv);
Zhu Yie655b9f2008-01-24 02:19:38 -08003418 return -ENODEV;
3419 }
3420
Reinette Chatree903fbd2008-01-30 22:05:15 -08003421 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
3422 IWL_ERROR("ucode not available for device bringup\n");
3423 return -EIO;
3424 }
3425
Zhu Yie655b9f2008-01-24 02:19:38 -08003426 /* If platform's RF_KILL switch is NOT set to KILL */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07003427 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08003428 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3429 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3430 else {
3431 set_bit(STATUS_RF_KILL_HW, &priv->status);
3432 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
Mohamed Abbasad97edd2008-03-28 16:21:06 -07003433 iwl_rfkill_set_hw_state(priv);
Zhu Yie655b9f2008-01-24 02:19:38 -08003434 IWL_WARNING("Radio disabled by HW RF Kill switch\n");
3435 return -ENODEV;
3436 }
Zhu Yib481de92007-09-25 17:54:57 -07003437 }
3438
Mohamed Abbasad97edd2008-03-28 16:21:06 -07003439 iwl_rfkill_set_hw_state(priv);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07003440 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07003441
Ron Rindjunsky399f4902008-04-23 17:14:56 -07003442 ret = priv->cfg->ops->lib->alloc_shared_mem(priv);
3443 if (ret) {
3444 IWL_ERROR("Unable to allocate shared memory\n");
3445 return ret;
3446 }
3447
Ron Rindjunsky1053d352008-05-05 10:22:43 +08003448 ret = iwl_hw_nic_init(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07003449 if (ret) {
3450 IWL_ERROR("Unable to init nic\n");
3451 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003452 }
3453
3454 /* make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07003455 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3456 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07003457 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3458
3459 /* clear (again), then enable host interrupts */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07003460 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003461 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003462
3463 /* really make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07003464 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3465 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07003466
3467 /* Copy original ucode data image from disk into backup cache.
3468 * This will be used to initialize the on-board processor's
3469 * data SRAM for a clean start when the runtime program first loads. */
3470 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a66926a2008-01-14 17:46:18 -08003471 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07003472
Zhu Yie655b9f2008-01-24 02:19:38 -08003473 /* We return success when we resume from suspend and rf_kill is on. */
3474 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07003475 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07003476
3477 for (i = 0; i < MAX_HW_RESTARTS; i++) {
3478
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003479 iwlcore_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003480
3481 /* load bootstrap state machine,
3482 * load bootstrap program into processor's memory,
3483 * prepare to load the "initialize" uCode */
Tomas Winkler57aab752008-04-14 21:16:03 -07003484 ret = priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003485
Tomas Winkler57aab752008-04-14 21:16:03 -07003486 if (ret) {
3487 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret);
Zhu Yib481de92007-09-25 17:54:57 -07003488 continue;
3489 }
3490
3491 /* start card; "initialize" will load runtime ucode */
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08003492 iwl4965_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003493
Zhu Yib481de92007-09-25 17:54:57 -07003494 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
3495
3496 return 0;
3497 }
3498
3499 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003500 __iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003501
3502 /* tried to restart and config the device for as long as our
3503 * patience could withstand */
3504 IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
3505 return -EIO;
3506}
3507
3508
3509/*****************************************************************************
3510 *
3511 * Workqueue callbacks
3512 *
3513 *****************************************************************************/
3514
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08003515static void iwl_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003516{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003517 struct iwl_priv *priv =
3518 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003519
3520 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3521 return;
3522
3523 mutex_lock(&priv->mutex);
Emmanuel Grumbachf3ccc082008-05-05 10:22:45 +08003524 priv->cfg->ops->lib->init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003525 mutex_unlock(&priv->mutex);
3526}
3527
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08003528static void iwl_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003529{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003530 struct iwl_priv *priv =
3531 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003532
3533 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3534 return;
3535
3536 mutex_lock(&priv->mutex);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08003537 iwl_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003538 mutex_unlock(&priv->mutex);
3539}
3540
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003541static void iwl4965_bg_rf_kill(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07003542{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003543 struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill);
Zhu Yib481de92007-09-25 17:54:57 -07003544
3545 wake_up_interruptible(&priv->wait_command_queue);
3546
3547 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3548 return;
3549
3550 mutex_lock(&priv->mutex);
3551
Tomas Winklerfee12472008-04-03 16:05:21 -07003552 if (!iwl_is_rfkill(priv)) {
Ester Kummerf3d67992008-05-06 11:05:12 +08003553 IWL_DEBUG(IWL_DL_RF_KILL,
Zhu Yib481de92007-09-25 17:54:57 -07003554 "HW and/or SW RF Kill no longer active, restarting "
3555 "device\n");
3556 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
3557 queue_work(priv->workqueue, &priv->restart);
3558 } else {
Mohamed Abbasad97edd2008-03-28 16:21:06 -07003559 /* make sure mac80211 stop sending Tx frame */
3560 if (priv->mac80211_registered)
3561 ieee80211_stop_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07003562
3563 if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
3564 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
3565 "disabled by SW switch\n");
3566 else
3567 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
3568 "Kill switch must be turned off for "
3569 "wireless networking to work.\n");
3570 }
Mohamed Abbasad97edd2008-03-28 16:21:06 -07003571 iwl_rfkill_set_hw_state(priv);
3572
Zhu Yib481de92007-09-25 17:54:57 -07003573 mutex_unlock(&priv->mutex);
3574}
3575
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08003576static void iwl4965_bg_set_monitor(struct work_struct *work)
3577{
3578 struct iwl_priv *priv = container_of(work,
3579 struct iwl_priv, set_monitor);
3580
3581 IWL_DEBUG(IWL_DL_STATE, "setting monitor mode\n");
3582
3583 mutex_lock(&priv->mutex);
3584
3585 if (!iwl_is_ready(priv))
3586 IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n");
3587 else
3588 if (iwl4965_set_mode(priv, IEEE80211_IF_TYPE_MNTR) != 0)
3589 IWL_ERROR("iwl4965_set_mode() failed\n");
3590
3591 mutex_unlock(&priv->mutex);
3592}
3593
Zhu Yib481de92007-09-25 17:54:57 -07003594#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
3595
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003596static void iwl4965_bg_scan_check(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003597{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003598 struct iwl_priv *priv =
3599 container_of(data, struct iwl_priv, scan_check.work);
Zhu Yib481de92007-09-25 17:54:57 -07003600
3601 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3602 return;
3603
3604 mutex_lock(&priv->mutex);
3605 if (test_bit(STATUS_SCANNING, &priv->status) ||
3606 test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
Ester Kummerf3d67992008-05-06 11:05:12 +08003607 IWL_DEBUG(IWL_DL_SCAN, "Scan completion watchdog resetting "
3608 "adapter (%dms)\n",
3609 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG));
mabbas052c4b92007-10-25 17:15:43 +08003610
Zhu Yib481de92007-09-25 17:54:57 -07003611 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003612 iwl4965_send_scan_abort(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003613 }
3614 mutex_unlock(&priv->mutex);
3615}
3616
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003617static void iwl4965_bg_request_scan(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003618{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003619 struct iwl_priv *priv =
3620 container_of(data, struct iwl_priv, request_scan);
Tomas Winkler857485c2008-03-21 13:53:44 -07003621 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07003622 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003623 .len = sizeof(struct iwl4965_scan_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07003624 .meta.flags = CMD_SIZE_HUGE,
3625 };
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003626 struct iwl4965_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07003627 struct ieee80211_conf *conf = NULL;
Tomas Winkler78330fd2008-02-06 02:37:18 +02003628 u16 cmd_len;
Johannes Berg8318d782008-01-24 19:38:38 +01003629 enum ieee80211_band band;
Tomas Winkler78330fd2008-02-06 02:37:18 +02003630 u8 direct_mask;
Tomas Winkler857485c2008-03-21 13:53:44 -07003631 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003632
3633 conf = ieee80211_get_hw_conf(priv->hw);
3634
3635 mutex_lock(&priv->mutex);
3636
Tomas Winklerfee12472008-04-03 16:05:21 -07003637 if (!iwl_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003638 IWL_WARNING("request scan called when driver not ready.\n");
3639 goto done;
3640 }
3641
3642 /* Make sure the scan wasn't cancelled before this queued work
3643 * was given the chance to run... */
3644 if (!test_bit(STATUS_SCANNING, &priv->status))
3645 goto done;
3646
3647 /* This should never be called or scheduled if there is currently
3648 * a scan active in the hardware. */
3649 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
3650 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
3651 "Ignoring second request.\n");
Tomas Winkler857485c2008-03-21 13:53:44 -07003652 ret = -EIO;
Zhu Yib481de92007-09-25 17:54:57 -07003653 goto done;
3654 }
3655
3656 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
3657 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
3658 goto done;
3659 }
3660
3661 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
3662 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
3663 goto done;
3664 }
3665
Tomas Winklerfee12472008-04-03 16:05:21 -07003666 if (iwl_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003667 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
3668 goto done;
3669 }
3670
3671 if (!test_bit(STATUS_READY, &priv->status)) {
3672 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
3673 goto done;
3674 }
3675
3676 if (!priv->scan_bands) {
3677 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
3678 goto done;
3679 }
3680
3681 if (!priv->scan) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003682 priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) +
Zhu Yib481de92007-09-25 17:54:57 -07003683 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
3684 if (!priv->scan) {
Tomas Winkler857485c2008-03-21 13:53:44 -07003685 ret = -ENOMEM;
Zhu Yib481de92007-09-25 17:54:57 -07003686 goto done;
3687 }
3688 }
3689 scan = priv->scan;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003690 memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07003691
3692 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
3693 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
3694
Tomas Winkler3109ece2008-03-28 16:33:35 -07003695 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003696 u16 interval = 0;
3697 u32 extra;
3698 u32 suspend_time = 100;
3699 u32 scan_suspend_time = 100;
3700 unsigned long flags;
3701
3702 IWL_DEBUG_INFO("Scanning while associated...\n");
3703
3704 spin_lock_irqsave(&priv->lock, flags);
3705 interval = priv->beacon_int;
3706 spin_unlock_irqrestore(&priv->lock, flags);
3707
3708 scan->suspend_time = 0;
mabbas052c4b92007-10-25 17:15:43 +08003709 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07003710 if (!interval)
3711 interval = suspend_time;
3712
3713 extra = (suspend_time / interval) << 22;
3714 scan_suspend_time = (extra |
3715 ((suspend_time % interval) * 1024));
3716 scan->suspend_time = cpu_to_le32(scan_suspend_time);
3717 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
3718 scan_suspend_time, interval);
3719 }
3720
3721 /* We should add the ability for user to lock to PASSIVE ONLY */
3722 if (priv->one_direct_scan) {
3723 IWL_DEBUG_SCAN
3724 ("Kicking off one direct scan for '%s'\n",
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003725 iwl4965_escape_essid(priv->direct_ssid,
Zhu Yib481de92007-09-25 17:54:57 -07003726 priv->direct_ssid_len));
3727 scan->direct_scan[0].id = WLAN_EID_SSID;
3728 scan->direct_scan[0].len = priv->direct_ssid_len;
3729 memcpy(scan->direct_scan[0].ssid,
3730 priv->direct_ssid, priv->direct_ssid_len);
3731 direct_mask = 1;
Tomas Winkler3109ece2008-03-28 16:33:35 -07003732 } else if (!iwl_is_associated(priv) && priv->essid_len) {
Bill Moss786b4552008-04-17 16:03:40 -07003733 IWL_DEBUG_SCAN
3734 ("Kicking off one direct scan for '%s' when not associated\n",
3735 iwl4965_escape_essid(priv->essid, priv->essid_len));
Zhu Yib481de92007-09-25 17:54:57 -07003736 scan->direct_scan[0].id = WLAN_EID_SSID;
3737 scan->direct_scan[0].len = priv->essid_len;
3738 memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
3739 direct_mask = 1;
Tomas Winkler857485c2008-03-21 13:53:44 -07003740 } else {
Bill Moss786b4552008-04-17 16:03:40 -07003741 IWL_DEBUG_SCAN("Kicking off one indirect scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003742 direct_mask = 0;
Tomas Winkler857485c2008-03-21 13:53:44 -07003743 }
Zhu Yib481de92007-09-25 17:54:57 -07003744
Zhu Yib481de92007-09-25 17:54:57 -07003745 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler5425e492008-04-15 16:01:38 -07003746 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07003747 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
3748
Zhu Yib481de92007-09-25 17:54:57 -07003749
3750 switch (priv->scan_bands) {
3751 case 2:
3752 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
3753 scan->tx_cmd.rate_n_flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003754 iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP,
Zhu Yib481de92007-09-25 17:54:57 -07003755 RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK);
3756
3757 scan->good_CRC_th = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01003758 band = IEEE80211_BAND_2GHZ;
Zhu Yib481de92007-09-25 17:54:57 -07003759 break;
3760
3761 case 1:
3762 scan->tx_cmd.rate_n_flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003763 iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP,
Zhu Yib481de92007-09-25 17:54:57 -07003764 RATE_MCS_ANT_B_MSK);
3765 scan->good_CRC_th = IWL_GOOD_CRC_TH;
Johannes Berg8318d782008-01-24 19:38:38 +01003766 band = IEEE80211_BAND_5GHZ;
Zhu Yib481de92007-09-25 17:54:57 -07003767 break;
3768
3769 default:
3770 IWL_WARNING("Invalid scan band count\n");
3771 goto done;
3772 }
3773
Tomas Winkler78330fd2008-02-06 02:37:18 +02003774 /* We don't build a direct scan probe request; the uCode will do
3775 * that based on the direct_mask added to each channel entry */
3776 cmd_len = iwl4965_fill_probe_req(priv, band,
3777 (struct ieee80211_mgmt *)scan->data,
3778 IWL_MAX_SCAN_SIZE - sizeof(*scan), 0);
3779
3780 scan->tx_cmd.len = cpu_to_le16(cmd_len);
Zhu Yib481de92007-09-25 17:54:57 -07003781 /* select Rx chains */
3782
3783 /* Force use of chains B and C (0x6) for scan Rx.
3784 * Avoid A (0x1) because of its off-channel reception on A-band.
3785 * MIMO is not used here, but value is required to make uCode happy. */
3786 scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK |
3787 cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) |
3788 (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) |
3789 (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS));
3790
3791 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR)
3792 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
3793
Bill Moss786b4552008-04-17 16:03:40 -07003794 if (direct_mask)
Reinette Chatre26c0f032008-03-11 16:17:15 -07003795 scan->channel_count =
3796 iwl4965_get_channels_for_scan(
3797 priv, band, 1, /* active */
3798 direct_mask,
3799 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
Bill Moss786b4552008-04-17 16:03:40 -07003800 else
Reinette Chatre26c0f032008-03-11 16:17:15 -07003801 scan->channel_count =
3802 iwl4965_get_channels_for_scan(
3803 priv, band, 0, /* passive */
3804 direct_mask,
3805 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
Zhu Yib481de92007-09-25 17:54:57 -07003806
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003807 scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK |
3808 RXON_FILTER_BCON_AWARE_MSK);
Zhu Yib481de92007-09-25 17:54:57 -07003809 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003810 scan->channel_count * sizeof(struct iwl4965_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07003811 cmd.data = scan;
3812 scan->len = cpu_to_le16(cmd.len);
3813
3814 set_bit(STATUS_SCAN_HW, &priv->status);
Tomas Winkler857485c2008-03-21 13:53:44 -07003815 ret = iwl_send_cmd_sync(priv, &cmd);
3816 if (ret)
Zhu Yib481de92007-09-25 17:54:57 -07003817 goto done;
3818
3819 queue_delayed_work(priv->workqueue, &priv->scan_check,
3820 IWL_SCAN_CHECK_WATCHDOG);
3821
3822 mutex_unlock(&priv->mutex);
3823 return;
3824
3825 done:
Ian Schram01ebd062007-10-25 17:15:22 +08003826 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07003827 queue_work(priv->workqueue, &priv->scan_completed);
3828 mutex_unlock(&priv->mutex);
3829}
3830
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003831static void iwl4965_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003832{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003833 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07003834
3835 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3836 return;
3837
3838 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003839 __iwl4965_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003840 mutex_unlock(&priv->mutex);
3841}
3842
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003843static void iwl4965_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003844{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003845 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07003846
3847 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3848 return;
3849
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003850 iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003851 queue_work(priv->workqueue, &priv->up);
3852}
3853
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003854static void iwl4965_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003855{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003856 struct iwl_priv *priv =
3857 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07003858
3859 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3860 return;
3861
3862 mutex_lock(&priv->mutex);
Tomas Winklera55360e2008-05-05 10:22:28 +08003863 iwl_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003864 mutex_unlock(&priv->mutex);
3865}
3866
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003867#define IWL_DELAY_NEXT_SCAN (HZ*2)
3868
Reinette Chatre508e32e2008-04-14 21:16:13 -07003869static void iwl4965_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003870{
Zhu Yib481de92007-09-25 17:54:57 -07003871 struct ieee80211_conf *conf = NULL;
Tomas Winkler857485c2008-03-21 13:53:44 -07003872 int ret = 0;
Joe Perches0795af52007-10-03 17:59:30 -07003873 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07003874
3875 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
3876 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__);
3877 return;
3878 }
3879
Joe Perches0795af52007-10-03 17:59:30 -07003880 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
3881 priv->assoc_id,
3882 print_mac(mac, priv->active_rxon.bssid_addr));
Zhu Yib481de92007-09-25 17:54:57 -07003883
3884
3885 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3886 return;
3887
Zhu Yib481de92007-09-25 17:54:57 -07003888
Reinette Chatre508e32e2008-04-14 21:16:13 -07003889 if (!priv->vif || !priv->is_open)
Mohamed Abbas948c1712007-10-25 17:15:45 +08003890 return;
Reinette Chatre508e32e2008-04-14 21:16:13 -07003891
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003892 iwl4965_scan_cancel_timeout(priv, 200);
mabbas052c4b92007-10-25 17:15:43 +08003893
Zhu Yib481de92007-09-25 17:54:57 -07003894 conf = ieee80211_get_hw_conf(priv->hw);
3895
3896 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003897 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003898
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003899 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
3900 iwl4965_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07003901 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07003902 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07003903 if (ret)
Zhu Yib481de92007-09-25 17:54:57 -07003904 IWL_WARNING("REPLY_RXON_TIMING failed - "
3905 "Attempting to continue.\n");
3906
3907 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
3908
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003909#ifdef CONFIG_IWL4965_HT
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02003910 if (priv->current_ht_config.is_ht)
Tomas Winkler47c51962008-05-05 10:22:41 +08003911 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003912#endif /* CONFIG_IWL4965_HT*/
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003913 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003914 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
3915
3916 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
3917 priv->assoc_id, priv->beacon_int);
3918
3919 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
3920 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
3921 else
3922 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
3923
3924 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
3925 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
3926 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
3927 else
3928 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
3929
3930 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
3931 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
3932
3933 }
3934
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003935 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003936
3937 switch (priv->iw_mode) {
3938 case IEEE80211_IF_TYPE_STA:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003939 iwl4965_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07003940 break;
3941
3942 case IEEE80211_IF_TYPE_IBSS:
3943
3944 /* clear out the station table */
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003945 iwlcore_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003946
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08003947 iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
3948 iwl_rxon_add_station(priv, priv->bssid, 0);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003949 iwl4965_rate_scale_init(priv->hw, IWL_STA_ID);
3950 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003951
3952 break;
3953
3954 default:
3955 IWL_ERROR("%s Should not be called in %d mode\n",
3956 __FUNCTION__, priv->iw_mode);
3957 break;
3958 }
3959
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003960 iwl4965_sequence_reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003961
Zhu Yib481de92007-09-25 17:54:57 -07003962 /* Enable Rx differential gain and sensitivity calibrations */
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -07003963 iwl_chain_noise_reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003964 priv->start_calib = 1;
Zhu Yib481de92007-09-25 17:54:57 -07003965
3966 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
3967 priv->assoc_station_added = 1;
3968
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003969 iwl4965_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08003970
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003971 iwl_power_update_mode(priv, 0);
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003972 /* we have just associated, don't start scan too early */
3973 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Reinette Chatre508e32e2008-04-14 21:16:13 -07003974}
3975
3976
3977static void iwl4965_bg_post_associate(struct work_struct *data)
3978{
3979 struct iwl_priv *priv = container_of(data, struct iwl_priv,
3980 post_associate.work);
3981
3982 mutex_lock(&priv->mutex);
3983 iwl4965_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003984 mutex_unlock(&priv->mutex);
Reinette Chatre508e32e2008-04-14 21:16:13 -07003985
Zhu Yib481de92007-09-25 17:54:57 -07003986}
3987
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003988static void iwl4965_bg_abort_scan(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07003989{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003990 struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan);
Zhu Yib481de92007-09-25 17:54:57 -07003991
Tomas Winklerfee12472008-04-03 16:05:21 -07003992 if (!iwl_is_ready(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003993 return;
3994
3995 mutex_lock(&priv->mutex);
3996
3997 set_bit(STATUS_SCAN_ABORTING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003998 iwl4965_send_scan_abort(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003999
4000 mutex_unlock(&priv->mutex);
4001}
4002
Zhu Yi76bb77e2007-11-22 10:53:22 +08004003static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
4004
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004005static void iwl4965_bg_scan_completed(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07004006{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004007 struct iwl_priv *priv =
4008 container_of(work, struct iwl_priv, scan_completed);
Zhu Yib481de92007-09-25 17:54:57 -07004009
Ester Kummerf3d67992008-05-06 11:05:12 +08004010 IWL_DEBUG(IWL_DL_SCAN, "SCAN complete scan\n");
Zhu Yib481de92007-09-25 17:54:57 -07004011
4012 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
4013 return;
4014
Zhu Yia0646472007-12-20 14:10:01 +08004015 if (test_bit(STATUS_CONF_PENDING, &priv->status))
4016 iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw));
Zhu Yi76bb77e2007-11-22 10:53:22 +08004017
Zhu Yib481de92007-09-25 17:54:57 -07004018 ieee80211_scan_completed(priv->hw);
4019
4020 /* Since setting the TXPOWER may have been deferred while
4021 * performing the scan, fire one off */
4022 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004023 iwl4965_hw_reg_send_txpower(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004024 mutex_unlock(&priv->mutex);
4025}
4026
4027/*****************************************************************************
4028 *
4029 * mac80211 entry point functions
4030 *
4031 *****************************************************************************/
4032
Zhu Yi5a66926a2008-01-14 17:46:18 -08004033#define UCODE_READY_TIMEOUT (2 * HZ)
4034
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004035static int iwl4965_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07004036{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004037 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08004038 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07004039
4040 IWL_DEBUG_MAC80211("enter\n");
4041
Zhu Yi5a66926a2008-01-14 17:46:18 -08004042 if (pci_enable_device(priv->pci_dev)) {
4043 IWL_ERROR("Fail to pci_enable_device\n");
4044 return -ENODEV;
4045 }
4046 pci_restore_state(priv->pci_dev);
4047 pci_enable_msi(priv->pci_dev);
4048
4049 ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED,
4050 DRV_NAME, priv);
4051 if (ret) {
4052 IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq);
4053 goto out_disable_msi;
4054 }
4055
Zhu Yib481de92007-09-25 17:54:57 -07004056 /* we should be verifying the device is ready to be opened */
4057 mutex_lock(&priv->mutex);
4058
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08004059 memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd));
Zhu Yi5a66926a2008-01-14 17:46:18 -08004060 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
4061 * ucode filename and max sizes are card-specific. */
4062
4063 if (!priv->ucode_code.len) {
4064 ret = iwl4965_read_ucode(priv);
4065 if (ret) {
4066 IWL_ERROR("Could not read microcode: %d\n", ret);
4067 mutex_unlock(&priv->mutex);
4068 goto out_release_irq;
4069 }
4070 }
4071
Zhu Yie655b9f2008-01-24 02:19:38 -08004072 ret = __iwl4965_up(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08004073
Zhu Yib481de92007-09-25 17:54:57 -07004074 mutex_unlock(&priv->mutex);
Zhu Yi5a66926a2008-01-14 17:46:18 -08004075
Zhu Yie655b9f2008-01-24 02:19:38 -08004076 if (ret)
4077 goto out_release_irq;
4078
4079 IWL_DEBUG_INFO("Start UP work done.\n");
4080
4081 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
4082 return 0;
4083
Zhu Yi5a66926a2008-01-14 17:46:18 -08004084 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
4085 * mac80211 will not be run successfully. */
4086 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
4087 test_bit(STATUS_READY, &priv->status),
4088 UCODE_READY_TIMEOUT);
4089 if (!ret) {
4090 if (!test_bit(STATUS_READY, &priv->status)) {
4091 IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n",
4092 jiffies_to_msecs(UCODE_READY_TIMEOUT));
4093 ret = -ETIMEDOUT;
4094 goto out_release_irq;
4095 }
4096 }
4097
Zhu Yie655b9f2008-01-24 02:19:38 -08004098 priv->is_open = 1;
Zhu Yib481de92007-09-25 17:54:57 -07004099 IWL_DEBUG_MAC80211("leave\n");
4100 return 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08004101
4102out_release_irq:
4103 free_irq(priv->pci_dev->irq, priv);
4104out_disable_msi:
4105 pci_disable_msi(priv->pci_dev);
Zhu Yie655b9f2008-01-24 02:19:38 -08004106 pci_disable_device(priv->pci_dev);
4107 priv->is_open = 0;
4108 IWL_DEBUG_MAC80211("leave - failed\n");
Zhu Yi5a66926a2008-01-14 17:46:18 -08004109 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004110}
4111
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004112static void iwl4965_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07004113{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004114 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004115
4116 IWL_DEBUG_MAC80211("enter\n");
Mohamed Abbas948c1712007-10-25 17:15:45 +08004117
Zhu Yie655b9f2008-01-24 02:19:38 -08004118 if (!priv->is_open) {
4119 IWL_DEBUG_MAC80211("leave - skip\n");
4120 return;
4121 }
4122
Zhu Yib481de92007-09-25 17:54:57 -07004123 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08004124
Tomas Winklerfee12472008-04-03 16:05:21 -07004125 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08004126 /* stop mac, cancel any scan request and clear
4127 * RXON_FILTER_ASSOC_MSK BIT
4128 */
Zhu Yi5a66926a2008-01-14 17:46:18 -08004129 mutex_lock(&priv->mutex);
4130 iwl4965_scan_cancel_timeout(priv, 100);
4131 cancel_delayed_work(&priv->post_associate);
Mohamed Abbasfde35712007-11-29 11:10:15 +08004132 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08004133 }
4134
Zhu Yi5a66926a2008-01-14 17:46:18 -08004135 iwl4965_down(priv);
4136
4137 flush_workqueue(priv->workqueue);
4138 free_irq(priv->pci_dev->irq, priv);
4139 pci_disable_msi(priv->pci_dev);
4140 pci_save_state(priv->pci_dev);
4141 pci_disable_device(priv->pci_dev);
Mohamed Abbas948c1712007-10-25 17:15:45 +08004142
Zhu Yib481de92007-09-25 17:54:57 -07004143 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004144}
4145
Johannes Berge039fa42008-05-15 12:55:29 +02004146static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07004147{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004148 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004149
4150 IWL_DEBUG_MAC80211("enter\n");
4151
4152 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
4153 IWL_DEBUG_MAC80211("leave - monitor\n");
4154 return -1;
4155 }
4156
4157 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02004158 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07004159
Johannes Berge039fa42008-05-15 12:55:29 +02004160 if (iwl_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07004161 dev_kfree_skb_any(skb);
4162
4163 IWL_DEBUG_MAC80211("leave\n");
4164 return 0;
4165}
4166
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004167static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004168 struct ieee80211_if_init_conf *conf)
4169{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004170 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004171 unsigned long flags;
Joe Perches0795af52007-10-03 17:59:30 -07004172 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07004173
Johannes Berg32bfd352007-12-19 01:31:26 +01004174 IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07004175
Johannes Berg32bfd352007-12-19 01:31:26 +01004176 if (priv->vif) {
4177 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
Reinette Chatre75849d22008-01-23 10:15:17 -08004178 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07004179 }
4180
4181 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01004182 priv->vif = conf->vif;
Zhu Yib481de92007-09-25 17:54:57 -07004183
4184 spin_unlock_irqrestore(&priv->lock, flags);
4185
4186 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02004187
4188 if (conf->mac_addr) {
4189 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr));
4190 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
4191 }
Zhu Yib481de92007-09-25 17:54:57 -07004192
Tomas Winklerfee12472008-04-03 16:05:21 -07004193 if (iwl_is_ready(priv))
Zhu Yi5a66926a2008-01-14 17:46:18 -08004194 iwl4965_set_mode(priv, conf->type);
4195
Zhu Yib481de92007-09-25 17:54:57 -07004196 mutex_unlock(&priv->mutex);
4197
Zhu Yi5a66926a2008-01-14 17:46:18 -08004198 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004199 return 0;
4200}
4201
4202/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004203 * iwl4965_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07004204 *
4205 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
4206 * be set inappropriately and the driver currently sets the hardware up to
4207 * use it whenever needed.
4208 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004209static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07004210{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004211 struct iwl_priv *priv = hw->priv;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07004212 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07004213 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08004214 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004215
4216 mutex_lock(&priv->mutex);
Johannes Berg8318d782008-01-24 19:38:38 +01004217 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07004218
Zhu Yi12342c42007-12-20 11:27:32 +08004219 priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
4220
Tomas Winklerfee12472008-04-03 16:05:21 -07004221 if (!iwl_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004222 IWL_DEBUG_MAC80211("leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08004223 ret = -EIO;
4224 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004225 }
4226
Assaf Krauss1ea87392008-03-18 14:57:50 -07004227 if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07004228 test_bit(STATUS_SCANNING, &priv->status))) {
Zhu Yia0646472007-12-20 14:10:01 +08004229 IWL_DEBUG_MAC80211("leave - scanning\n");
4230 set_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004231 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08004232 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07004233 }
4234
4235 spin_lock_irqsave(&priv->lock, flags);
4236
Assaf Krauss8622e702008-03-21 13:53:43 -07004237 ch_info = iwl_get_channel_info(priv, conf->channel->band,
Johannes Berg8318d782008-01-24 19:38:38 +01004238 ieee80211_frequency_to_channel(conf->channel->center_freq));
Zhu Yib481de92007-09-25 17:54:57 -07004239 if (!is_channel_valid(ch_info)) {
Zhu Yib481de92007-09-25 17:54:57 -07004240 IWL_DEBUG_MAC80211("leave - invalid channel\n");
4241 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yi76bb77e2007-11-22 10:53:22 +08004242 ret = -EINVAL;
4243 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004244 }
4245
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004246#ifdef CONFIG_IWL4965_HT
Tomas Winkler78330fd2008-02-06 02:37:18 +02004247 /* if we are switching from ht to 2.4 clear flags
Zhu Yib481de92007-09-25 17:54:57 -07004248 * from any ht related info since 2.4 does not
4249 * support ht */
Tomas Winkler78330fd2008-02-06 02:37:18 +02004250 if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel->hw_value)
Zhu Yib481de92007-09-25 17:54:57 -07004251#ifdef IEEE80211_CONF_CHANNEL_SWITCH
4252 && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
4253#endif
4254 )
4255 priv->staging_rxon.flags = 0;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004256#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07004257
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07004258 iwl_set_rxon_channel(priv, conf->channel->band,
Johannes Berg8318d782008-01-24 19:38:38 +01004259 ieee80211_frequency_to_channel(conf->channel->center_freq));
Zhu Yib481de92007-09-25 17:54:57 -07004260
Johannes Berg8318d782008-01-24 19:38:38 +01004261 iwl4965_set_flags_for_phymode(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07004262
4263 /* The list of supported rates and rate mask can be different
Johannes Berg8318d782008-01-24 19:38:38 +01004264 * for each band; since the band may have changed, reset
Zhu Yib481de92007-09-25 17:54:57 -07004265 * the rate mask to what mac80211 lists */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004266 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004267
4268 spin_unlock_irqrestore(&priv->lock, flags);
4269
4270#ifdef IEEE80211_CONF_CHANNEL_SWITCH
4271 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004272 iwl4965_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08004273 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004274 }
4275#endif
4276
Mohamed Abbasad97edd2008-03-28 16:21:06 -07004277 if (priv->cfg->ops->lib->radio_kill_sw)
4278 priv->cfg->ops->lib->radio_kill_sw(priv, !conf->radio_enabled);
Zhu Yib481de92007-09-25 17:54:57 -07004279
4280 if (!conf->radio_enabled) {
4281 IWL_DEBUG_MAC80211("leave - radio disabled\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08004282 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004283 }
4284
Tomas Winklerfee12472008-04-03 16:05:21 -07004285 if (iwl_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004286 IWL_DEBUG_MAC80211("leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08004287 ret = -EIO;
4288 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004289 }
4290
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004291 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004292
4293 if (memcmp(&priv->active_rxon,
4294 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004295 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004296 else
4297 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
4298
4299 IWL_DEBUG_MAC80211("leave\n");
4300
Zhu Yia0646472007-12-20 14:10:01 +08004301out:
4302 clear_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08004303 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08004304 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004305}
4306
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004307static void iwl4965_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004308{
Tomas Winkler857485c2008-03-21 13:53:44 -07004309 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004310
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08004311 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07004312 return;
4313
4314 /* The following should be done only at AP bring up */
4315 if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) {
4316
4317 /* RXON - unassoc (to set timing command) */
4318 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004319 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004320
4321 /* RXON Timing */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004322 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
4323 iwl4965_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07004324 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07004325 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07004326 if (ret)
Zhu Yib481de92007-09-25 17:54:57 -07004327 IWL_WARNING("REPLY_RXON_TIMING failed - "
4328 "Attempting to continue.\n");
4329
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07004330 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004331
4332 /* FIXME: what should be the assoc_id for AP? */
4333 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
4334 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
4335 priv->staging_rxon.flags |=
4336 RXON_FLG_SHORT_PREAMBLE_MSK;
4337 else
4338 priv->staging_rxon.flags &=
4339 ~RXON_FLG_SHORT_PREAMBLE_MSK;
4340
4341 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
4342 if (priv->assoc_capability &
4343 WLAN_CAPABILITY_SHORT_SLOT_TIME)
4344 priv->staging_rxon.flags |=
4345 RXON_FLG_SHORT_SLOT_MSK;
4346 else
4347 priv->staging_rxon.flags &=
4348 ~RXON_FLG_SHORT_SLOT_MSK;
4349
4350 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
4351 priv->staging_rxon.flags &=
4352 ~RXON_FLG_SHORT_SLOT_MSK;
4353 }
4354 /* restore RXON assoc */
4355 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004356 iwl4965_commit_rxon(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004357 iwl4965_activate_qos(priv, 1);
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08004358 iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
Zhu Yie1493de2007-09-27 11:27:32 +08004359 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004360 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004361
4362 /* FIXME - we need to add code here to detect a totally new
4363 * configuration, reset the AP, unassoc, rxon timing, assoc,
4364 * clear sta table, add BCAST sta... */
4365}
4366
Johannes Berg32bfd352007-12-19 01:31:26 +01004367static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
4368 struct ieee80211_vif *vif,
Zhu Yib481de92007-09-25 17:54:57 -07004369 struct ieee80211_if_conf *conf)
4370{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004371 struct iwl_priv *priv = hw->priv;
Joe Perches0795af52007-10-03 17:59:30 -07004372 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07004373 unsigned long flags;
4374 int rc;
4375
4376 if (conf == NULL)
4377 return -EIO;
4378
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08004379 if (priv->vif != vif) {
4380 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08004381 return 0;
4382 }
4383
Zhu Yib481de92007-09-25 17:54:57 -07004384 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
4385 (!conf->beacon || !conf->ssid_len)) {
4386 IWL_DEBUG_MAC80211
4387 ("Leaving in AP mode because HostAPD is not ready.\n");
4388 return 0;
4389 }
4390
Tomas Winklerfee12472008-04-03 16:05:21 -07004391 if (!iwl_is_alive(priv))
Zhu Yi5a66926a2008-01-14 17:46:18 -08004392 return -EAGAIN;
4393
Zhu Yib481de92007-09-25 17:54:57 -07004394 mutex_lock(&priv->mutex);
4395
Zhu Yib481de92007-09-25 17:54:57 -07004396 if (conf->bssid)
Joe Perches0795af52007-10-03 17:59:30 -07004397 IWL_DEBUG_MAC80211("bssid: %s\n",
4398 print_mac(mac, conf->bssid));
Zhu Yib481de92007-09-25 17:54:57 -07004399
Johannes Berg4150c572007-09-17 01:29:23 -04004400/*
4401 * very dubious code was here; the probe filtering flag is never set:
4402 *
Zhu Yib481de92007-09-25 17:54:57 -07004403 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
4404 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04004405 */
Zhu Yib481de92007-09-25 17:54:57 -07004406
4407 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
4408 if (!conf->bssid) {
4409 conf->bssid = priv->mac_addr;
4410 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Joe Perches0795af52007-10-03 17:59:30 -07004411 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
4412 print_mac(mac, conf->bssid));
Zhu Yib481de92007-09-25 17:54:57 -07004413 }
4414 if (priv->ibss_beacon)
4415 dev_kfree_skb(priv->ibss_beacon);
4416
4417 priv->ibss_beacon = conf->beacon;
4418 }
4419
Tomas Winklerfee12472008-04-03 16:05:21 -07004420 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08004421 goto done;
4422
Zhu Yib481de92007-09-25 17:54:57 -07004423 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
4424 !is_multicast_ether_addr(conf->bssid)) {
4425 /* If there is currently a HW scan going on in the background
4426 * then we need to cancel it else the RXON below will fail. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004427 if (iwl4965_scan_cancel_timeout(priv, 100)) {
Zhu Yib481de92007-09-25 17:54:57 -07004428 IWL_WARNING("Aborted scan still in progress "
4429 "after 100ms\n");
4430 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
4431 mutex_unlock(&priv->mutex);
4432 return -EAGAIN;
4433 }
4434 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
4435
4436 /* TODO: Audit driver for usage of these members and see
4437 * if mac80211 deprecates them (priv->bssid looks like it
4438 * shouldn't be there, but I haven't scanned the IBSS code
4439 * to verify) - jpk */
4440 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
4441
4442 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004443 iwl4965_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004444 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004445 rc = iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004446 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08004447 iwl_rxon_add_station(
Zhu Yib481de92007-09-25 17:54:57 -07004448 priv, priv->active_rxon.bssid_addr, 1);
4449 }
4450
4451 } else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004452 iwl4965_scan_cancel_timeout(priv, 100);
Zhu Yib481de92007-09-25 17:54:57 -07004453 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004454 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004455 }
4456
Mohamed Abbasfde35712007-11-29 11:10:15 +08004457 done:
Zhu Yib481de92007-09-25 17:54:57 -07004458 spin_lock_irqsave(&priv->lock, flags);
4459 if (!conf->ssid_len)
4460 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
4461 else
4462 memcpy(priv->essid, conf->ssid, conf->ssid_len);
4463
4464 priv->essid_len = conf->ssid_len;
4465 spin_unlock_irqrestore(&priv->lock, flags);
4466
4467 IWL_DEBUG_MAC80211("leave\n");
4468 mutex_unlock(&priv->mutex);
4469
4470 return 0;
4471}
4472
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004473static void iwl4965_configure_filter(struct ieee80211_hw *hw,
Johannes Berg4150c572007-09-17 01:29:23 -04004474 unsigned int changed_flags,
4475 unsigned int *total_flags,
4476 int mc_count, struct dev_addr_list *mc_list)
4477{
4478 /*
4479 * XXX: dummy
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004480 * see also iwl4965_connection_init_rx_config
Johannes Berg4150c572007-09-17 01:29:23 -04004481 */
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08004482 struct iwl_priv *priv = hw->priv;
4483 int new_flags = 0;
4484 if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
4485 if (*total_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
4486 IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n",
4487 IEEE80211_IF_TYPE_MNTR,
4488 changed_flags, *total_flags);
4489 /* queue work 'cuz mac80211 is holding a lock which
4490 * prevents us from issuing (synchronous) f/w cmds */
4491 queue_work(priv->workqueue, &priv->set_monitor);
4492 new_flags &= FIF_PROMISC_IN_BSS |
4493 FIF_OTHER_BSS |
4494 FIF_ALLMULTI;
4495 }
4496 }
4497 *total_flags = new_flags;
Johannes Berg4150c572007-09-17 01:29:23 -04004498}
4499
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004500static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004501 struct ieee80211_if_init_conf *conf)
4502{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004503 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004504
4505 IWL_DEBUG_MAC80211("enter\n");
4506
4507 mutex_lock(&priv->mutex);
Mohamed Abbas948c1712007-10-25 17:15:45 +08004508
Tomas Winklerfee12472008-04-03 16:05:21 -07004509 if (iwl_is_ready_rf(priv)) {
Mohamed Abbasfde35712007-11-29 11:10:15 +08004510 iwl4965_scan_cancel_timeout(priv, 100);
4511 cancel_delayed_work(&priv->post_associate);
4512 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
4513 iwl4965_commit_rxon(priv);
4514 }
Johannes Berg32bfd352007-12-19 01:31:26 +01004515 if (priv->vif == conf->vif) {
4516 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07004517 memset(priv->bssid, 0, ETH_ALEN);
4518 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
4519 priv->essid_len = 0;
4520 }
4521 mutex_unlock(&priv->mutex);
4522
4523 IWL_DEBUG_MAC80211("leave\n");
4524
4525}
Johannes Berg471b3ef2007-12-28 14:32:58 +01004526
Tomas Winkler3109ece2008-03-28 16:33:35 -07004527#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
Johannes Berg471b3ef2007-12-28 14:32:58 +01004528static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
4529 struct ieee80211_vif *vif,
4530 struct ieee80211_bss_conf *bss_conf,
4531 u32 changes)
Tomas Winkler220173b2007-10-16 00:50:25 +02004532{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004533 struct iwl_priv *priv = hw->priv;
Tomas Winkler220173b2007-10-16 00:50:25 +02004534
Tomas Winkler3109ece2008-03-28 16:33:35 -07004535 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
4536
Johannes Berg471b3ef2007-12-28 14:32:58 +01004537 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07004538 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
4539 bss_conf->use_short_preamble);
Johannes Berg471b3ef2007-12-28 14:32:58 +01004540 if (bss_conf->use_short_preamble)
Tomas Winkler220173b2007-10-16 00:50:25 +02004541 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
4542 else
4543 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
4544 }
4545
Johannes Berg471b3ef2007-12-28 14:32:58 +01004546 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07004547 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
Johannes Berg8318d782008-01-24 19:38:38 +01004548 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Tomas Winkler220173b2007-10-16 00:50:25 +02004549 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
4550 else
4551 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
4552 }
4553
Tomas Winkler98952d52008-03-28 16:33:33 -07004554 if (changes & BSS_CHANGED_HT) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07004555 IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht);
Tomas Winkler98952d52008-03-28 16:33:33 -07004556 iwl4965_ht_conf(priv, bss_conf);
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07004557 iwl_set_rxon_chain(priv);
Tomas Winkler98952d52008-03-28 16:33:33 -07004558 }
4559
Johannes Berg471b3ef2007-12-28 14:32:58 +01004560 if (changes & BSS_CHANGED_ASSOC) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07004561 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
Reinette Chatre508e32e2008-04-14 21:16:13 -07004562 /* This should never happen as this function should
4563 * never be called from interrupt context. */
4564 if (WARN_ON_ONCE(in_interrupt()))
4565 return;
Tomas Winkler3109ece2008-03-28 16:33:35 -07004566 if (bss_conf->assoc) {
4567 priv->assoc_id = bss_conf->aid;
4568 priv->beacon_int = bss_conf->beacon_int;
4569 priv->timestamp = bss_conf->timestamp;
4570 priv->assoc_capability = bss_conf->assoc_capability;
4571 priv->next_scan_jiffies = jiffies +
4572 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
Reinette Chatre508e32e2008-04-14 21:16:13 -07004573 mutex_lock(&priv->mutex);
4574 iwl4965_post_associate(priv);
4575 mutex_unlock(&priv->mutex);
Tomas Winkler3109ece2008-03-28 16:33:35 -07004576 } else {
4577 priv->assoc_id = 0;
4578 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
4579 }
4580 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
4581 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
Tomas Winkler7e8c5192008-04-15 16:01:43 -07004582 iwl_send_rxon_assoc(priv);
Johannes Berg471b3ef2007-12-28 14:32:58 +01004583 }
4584
Tomas Winkler220173b2007-10-16 00:50:25 +02004585}
Zhu Yib481de92007-09-25 17:54:57 -07004586
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004587static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
Zhu Yib481de92007-09-25 17:54:57 -07004588{
4589 int rc = 0;
4590 unsigned long flags;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004591 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004592
4593 IWL_DEBUG_MAC80211("enter\n");
4594
mabbas052c4b92007-10-25 17:15:43 +08004595 mutex_lock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07004596 spin_lock_irqsave(&priv->lock, flags);
4597
Tomas Winklerfee12472008-04-03 16:05:21 -07004598 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004599 rc = -EIO;
4600 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
4601 goto out_unlock;
4602 }
4603
4604 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */
4605 rc = -EIO;
4606 IWL_ERROR("ERROR: APs don't scan\n");
4607 goto out_unlock;
4608 }
4609
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08004610 /* we don't schedule scan within next_scan_jiffies period */
4611 if (priv->next_scan_jiffies &&
4612 time_after(priv->next_scan_jiffies, jiffies)) {
4613 rc = -EAGAIN;
4614 goto out_unlock;
4615 }
Zhu Yib481de92007-09-25 17:54:57 -07004616 /* if we just finished scan ask for delay */
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08004617 if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies +
4618 IWL_DELAY_NEXT_SCAN, jiffies)) {
Zhu Yib481de92007-09-25 17:54:57 -07004619 rc = -EAGAIN;
4620 goto out_unlock;
4621 }
4622 if (len) {
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08004623 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004624 iwl4965_escape_essid(ssid, len), (int)len);
Zhu Yib481de92007-09-25 17:54:57 -07004625
4626 priv->one_direct_scan = 1;
4627 priv->direct_ssid_len = (u8)
4628 min((u8) len, (u8) IW_ESSID_MAX_SIZE);
4629 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
Mohamed Abbas948c1712007-10-25 17:15:45 +08004630 } else
4631 priv->one_direct_scan = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004632
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004633 rc = iwl4965_scan_initiate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004634
4635 IWL_DEBUG_MAC80211("leave\n");
4636
4637out_unlock:
4638 spin_unlock_irqrestore(&priv->lock, flags);
mabbas052c4b92007-10-25 17:15:43 +08004639 mutex_unlock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07004640
4641 return rc;
4642}
4643
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02004644static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw,
4645 struct ieee80211_key_conf *keyconf, const u8 *addr,
4646 u32 iv32, u16 *phase1key)
4647{
4648 struct iwl_priv *priv = hw->priv;
4649 u8 sta_id = IWL_INVALID_STATION;
4650 unsigned long flags;
4651 __le16 key_flags = 0;
4652 int i;
4653 DECLARE_MAC_BUF(mac);
4654
4655 IWL_DEBUG_MAC80211("enter\n");
4656
Tomas Winkler947b13a2008-04-16 16:34:48 -07004657 sta_id = iwl_find_station(priv, addr);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02004658 if (sta_id == IWL_INVALID_STATION) {
4659 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
4660 print_mac(mac, addr));
4661 return;
4662 }
4663
4664 iwl4965_scan_cancel_timeout(priv, 100);
4665
4666 key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
4667 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
4668 key_flags &= ~STA_KEY_FLG_INVALID;
4669
Tomas Winkler5425e492008-04-15 16:01:38 -07004670 if (sta_id == priv->hw_params.bcast_sta_id)
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02004671 key_flags |= STA_KEY_MULTICAST_MSK;
4672
4673 spin_lock_irqsave(&priv->sta_lock, flags);
4674
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02004675 priv->stations[sta_id].sta.key.key_flags = key_flags;
4676 priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
4677
4678 for (i = 0; i < 5; i++)
4679 priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
4680 cpu_to_le16(phase1key[i]);
4681
4682 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
4683 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
4684
Tomas Winkler133636d2008-05-05 10:22:34 +08004685 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02004686
4687 spin_unlock_irqrestore(&priv->sta_lock, flags);
4688
4689 IWL_DEBUG_MAC80211("leave\n");
4690}
4691
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004692static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Zhu Yib481de92007-09-25 17:54:57 -07004693 const u8 *local_addr, const u8 *addr,
4694 struct ieee80211_key_conf *key)
4695{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004696 struct iwl_priv *priv = hw->priv;
Joe Perches0795af52007-10-03 17:59:30 -07004697 DECLARE_MAC_BUF(mac);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07004698 int ret = 0;
4699 u8 sta_id = IWL_INVALID_STATION;
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07004700 u8 is_default_wep_key = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004701
4702 IWL_DEBUG_MAC80211("enter\n");
4703
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07004704 if (priv->hw_params.sw_crypto) {
Zhu Yib481de92007-09-25 17:54:57 -07004705 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
4706 return -EOPNOTSUPP;
4707 }
4708
4709 if (is_zero_ether_addr(addr))
4710 /* only support pairwise keys */
4711 return -EOPNOTSUPP;
4712
Tomas Winkler947b13a2008-04-16 16:34:48 -07004713 sta_id = iwl_find_station(priv, addr);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07004714 if (sta_id == IWL_INVALID_STATION) {
4715 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
4716 print_mac(mac, addr));
4717 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07004718
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07004719 }
Zhu Yib481de92007-09-25 17:54:57 -07004720
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07004721 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004722 iwl4965_scan_cancel_timeout(priv, 100);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07004723 mutex_unlock(&priv->mutex);
4724
4725 /* If we are getting WEP group key and we didn't receive any key mapping
4726 * so far, we are in legacy wep mode (group key only), otherwise we are
4727 * in 1X mode.
4728 * In legacy wep mode, we use another host command to the uCode */
Tomas Winkler5425e492008-04-15 16:01:38 -07004729 if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07004730 priv->iw_mode != IEEE80211_IF_TYPE_AP) {
4731 if (cmd == SET_KEY)
4732 is_default_wep_key = !priv->key_mapping_key;
4733 else
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +08004734 is_default_wep_key =
4735 (key->hw_key_idx == HW_KEY_DEFAULT);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07004736 }
mabbas052c4b92007-10-25 17:15:43 +08004737
Zhu Yib481de92007-09-25 17:54:57 -07004738 switch (cmd) {
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07004739 case SET_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07004740 if (is_default_wep_key)
4741 ret = iwl_set_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07004742 else
Emmanuel Grumbach74805132008-04-14 21:16:09 -07004743 ret = iwl_set_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07004744
4745 IWL_DEBUG_MAC80211("enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07004746 break;
4747 case DISABLE_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07004748 if (is_default_wep_key)
4749 ret = iwl_remove_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07004750 else
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07004751 ret = iwl_remove_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07004752
4753 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07004754 break;
4755 default:
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07004756 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07004757 }
4758
4759 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004760
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07004761 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004762}
4763
Johannes Berge100bb62008-04-30 18:51:21 +02004764static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
Zhu Yib481de92007-09-25 17:54:57 -07004765 const struct ieee80211_tx_queue_params *params)
4766{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004767 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004768 unsigned long flags;
4769 int q;
Zhu Yib481de92007-09-25 17:54:57 -07004770
4771 IWL_DEBUG_MAC80211("enter\n");
4772
Tomas Winklerfee12472008-04-03 16:05:21 -07004773 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004774 IWL_DEBUG_MAC80211("leave - RF not ready\n");
4775 return -EIO;
4776 }
4777
4778 if (queue >= AC_NUM) {
4779 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
4780 return 0;
4781 }
4782
Zhu Yib481de92007-09-25 17:54:57 -07004783 if (!priv->qos_data.qos_enable) {
4784 priv->qos_data.qos_active = 0;
4785 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
4786 return 0;
4787 }
4788 q = AC_NUM - 1 - queue;
4789
4790 spin_lock_irqsave(&priv->lock, flags);
4791
4792 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
4793 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
4794 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
4795 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7b2008-02-10 16:49:38 +01004796 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07004797
4798 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
4799 priv->qos_data.qos_active = 1;
4800
4801 spin_unlock_irqrestore(&priv->lock, flags);
4802
4803 mutex_lock(&priv->mutex);
4804 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004805 iwl4965_activate_qos(priv, 1);
Tomas Winkler3109ece2008-03-28 16:33:35 -07004806 else if (priv->assoc_id && iwl_is_associated(priv))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004807 iwl4965_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004808
4809 mutex_unlock(&priv->mutex);
4810
Zhu Yib481de92007-09-25 17:54:57 -07004811 IWL_DEBUG_MAC80211("leave\n");
4812 return 0;
4813}
4814
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004815static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004816 struct ieee80211_tx_queue_stats *stats)
4817{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004818 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004819 int i, avail;
Ron Rindjunsky16466902008-05-05 10:22:50 +08004820 struct iwl_tx_queue *txq;
Tomas Winkler443cfd42008-05-15 13:53:57 +08004821 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07004822 unsigned long flags;
4823
4824 IWL_DEBUG_MAC80211("enter\n");
4825
Tomas Winklerfee12472008-04-03 16:05:21 -07004826 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004827 IWL_DEBUG_MAC80211("leave - RF not ready\n");
4828 return -EIO;
4829 }
4830
4831 spin_lock_irqsave(&priv->lock, flags);
4832
4833 for (i = 0; i < AC_NUM; i++) {
4834 txq = &priv->txq[i];
4835 q = &txq->q;
Tomas Winkler443cfd42008-05-15 13:53:57 +08004836 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07004837
Johannes Berg57ffc582008-04-29 17:18:59 +02004838 stats[i].len = q->n_window - avail;
4839 stats[i].limit = q->n_window - q->high_mark;
4840 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07004841
4842 }
4843 spin_unlock_irqrestore(&priv->lock, flags);
4844
4845 IWL_DEBUG_MAC80211("leave\n");
4846
4847 return 0;
4848}
4849
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004850static int iwl4965_mac_get_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004851 struct ieee80211_low_level_stats *stats)
4852{
Ester Kummerbf403db2008-05-05 10:22:40 +08004853 struct iwl_priv *priv = hw->priv;
4854
4855 priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004856 IWL_DEBUG_MAC80211("enter\n");
4857 IWL_DEBUG_MAC80211("leave\n");
4858
4859 return 0;
4860}
4861
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004862static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07004863{
Ester Kummerbf403db2008-05-05 10:22:40 +08004864 struct iwl_priv *priv;
4865
4866 priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004867 IWL_DEBUG_MAC80211("enter\n");
4868 IWL_DEBUG_MAC80211("leave\n");
4869
4870 return 0;
4871}
4872
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004873static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07004874{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004875 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004876 unsigned long flags;
4877
4878 mutex_lock(&priv->mutex);
4879 IWL_DEBUG_MAC80211("enter\n");
4880
4881 priv->lq_mngr.lq_ready = 0;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004882#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -07004883 spin_lock_irqsave(&priv->lock, flags);
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02004884 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
Zhu Yib481de92007-09-25 17:54:57 -07004885 spin_unlock_irqrestore(&priv->lock, flags);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004886#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07004887
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07004888 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004889
4890 cancel_delayed_work(&priv->post_associate);
4891
4892 spin_lock_irqsave(&priv->lock, flags);
4893 priv->assoc_id = 0;
4894 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004895 priv->assoc_station_added = 0;
4896
4897 /* new association get rid of ibss beacon skb */
4898 if (priv->ibss_beacon)
4899 dev_kfree_skb(priv->ibss_beacon);
4900
4901 priv->ibss_beacon = NULL;
4902
4903 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler3109ece2008-03-28 16:33:35 -07004904 priv->timestamp = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004905 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
4906 priv->beacon_int = 0;
4907
4908 spin_unlock_irqrestore(&priv->lock, flags);
4909
Tomas Winklerfee12472008-04-03 16:05:21 -07004910 if (!iwl_is_ready_rf(priv)) {
Mohamed Abbasfde35712007-11-29 11:10:15 +08004911 IWL_DEBUG_MAC80211("leave - not ready\n");
4912 mutex_unlock(&priv->mutex);
4913 return;
4914 }
4915
mabbas052c4b92007-10-25 17:15:43 +08004916 /* we are restarting association process
4917 * clear RXON_FILTER_ASSOC_MSK bit
4918 */
4919 if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004920 iwl4965_scan_cancel_timeout(priv, 100);
mabbas052c4b92007-10-25 17:15:43 +08004921 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004922 iwl4965_commit_rxon(priv);
mabbas052c4b92007-10-25 17:15:43 +08004923 }
4924
Mohamed Abbas5da4b552008-04-21 15:41:51 -07004925 iwl_power_update_mode(priv, 0);
4926
Zhu Yib481de92007-09-25 17:54:57 -07004927 /* Per mac80211.h: This is only used in IBSS mode... */
4928 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
mabbas052c4b92007-10-25 17:15:43 +08004929
Zhu Yib481de92007-09-25 17:54:57 -07004930 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
4931 mutex_unlock(&priv->mutex);
4932 return;
4933 }
4934
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004935 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004936
4937 mutex_unlock(&priv->mutex);
4938
4939 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004940}
4941
Johannes Berge039fa42008-05-15 12:55:29 +02004942static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07004943{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004944 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004945 unsigned long flags;
4946
4947 mutex_lock(&priv->mutex);
4948 IWL_DEBUG_MAC80211("enter\n");
4949
Tomas Winklerfee12472008-04-03 16:05:21 -07004950 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004951 IWL_DEBUG_MAC80211("leave - RF not ready\n");
4952 mutex_unlock(&priv->mutex);
4953 return -EIO;
4954 }
4955
4956 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
4957 IWL_DEBUG_MAC80211("leave - not IBSS\n");
4958 mutex_unlock(&priv->mutex);
4959 return -EIO;
4960 }
4961
4962 spin_lock_irqsave(&priv->lock, flags);
4963
4964 if (priv->ibss_beacon)
4965 dev_kfree_skb(priv->ibss_beacon);
4966
4967 priv->ibss_beacon = skb;
4968
4969 priv->assoc_id = 0;
4970
4971 IWL_DEBUG_MAC80211("leave\n");
4972 spin_unlock_irqrestore(&priv->lock, flags);
4973
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07004974 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004975
4976 queue_work(priv->workqueue, &priv->post_associate.work);
4977
4978 mutex_unlock(&priv->mutex);
4979
4980 return 0;
4981}
4982
Zhu Yib481de92007-09-25 17:54:57 -07004983/*****************************************************************************
4984 *
4985 * sysfs attributes
4986 *
4987 *****************************************************************************/
4988
Tomas Winkler0a6857e2008-03-12 16:58:49 -07004989#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07004990
4991/*
4992 * The following adds a new attribute to the sysfs representation
4993 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
4994 * used for controlling the debug level.
4995 *
4996 * See the level definitions in iwl for details.
4997 */
4998
Ester Kummer8cf769c2008-05-06 11:05:11 +08004999static ssize_t show_debug_level(struct device *d,
5000 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07005001{
Ester Kummer8cf769c2008-05-06 11:05:11 +08005002 struct iwl_priv *priv = d->driver_data;
5003
5004 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07005005}
Ester Kummer8cf769c2008-05-06 11:05:11 +08005006static ssize_t store_debug_level(struct device *d,
5007 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07005008 const char *buf, size_t count)
5009{
Ester Kummer8cf769c2008-05-06 11:05:11 +08005010 struct iwl_priv *priv = d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07005011 char *p = (char *)buf;
5012 u32 val;
5013
5014 val = simple_strtoul(p, &p, 0);
5015 if (p == buf)
5016 printk(KERN_INFO DRV_NAME
5017 ": %s is not in hex or decimal form.\n", buf);
5018 else
Ester Kummer8cf769c2008-05-06 11:05:11 +08005019 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07005020
5021 return strnlen(buf, count);
5022}
5023
Ester Kummer8cf769c2008-05-06 11:05:11 +08005024static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
5025 show_debug_level, store_debug_level);
5026
Zhu Yib481de92007-09-25 17:54:57 -07005027
Tomas Winkler0a6857e2008-03-12 16:58:49 -07005028#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07005029
Zhu Yib481de92007-09-25 17:54:57 -07005030
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08005031static ssize_t show_version(struct device *d,
5032 struct device_attribute *attr, char *buf)
5033{
5034 struct iwl_priv *priv = d->driver_data;
Tomas Winkler885ba202008-05-29 16:34:55 +08005035 struct iwl_alive_resp *palive = &priv->card_alive;
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08005036
5037 if (palive->is_valid)
5038 return sprintf(buf, "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n"
5039 "fw type: 0x%01X 0x%01X\n",
5040 palive->ucode_major, palive->ucode_minor,
5041 palive->sw_rev[0], palive->sw_rev[1],
5042 palive->ver_type, palive->ver_subtype);
5043
5044 else
5045 return sprintf(buf, "fw not loaded\n");
5046}
5047
5048static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL);
5049
Zhu Yib481de92007-09-25 17:54:57 -07005050static ssize_t show_temperature(struct device *d,
5051 struct device_attribute *attr, char *buf)
5052{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005053 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07005054
Tomas Winklerfee12472008-04-03 16:05:21 -07005055 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07005056 return -EAGAIN;
5057
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005058 return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07005059}
5060
5061static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
5062
5063static ssize_t show_rs_window(struct device *d,
5064 struct device_attribute *attr,
5065 char *buf)
5066{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005067 struct iwl_priv *priv = d->driver_data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005068 return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07005069}
5070static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
5071
5072static ssize_t show_tx_power(struct device *d,
5073 struct device_attribute *attr, char *buf)
5074{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005075 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07005076 return sprintf(buf, "%d\n", priv->user_txpower_limit);
5077}
5078
5079static ssize_t store_tx_power(struct device *d,
5080 struct device_attribute *attr,
5081 const char *buf, size_t count)
5082{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005083 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07005084 char *p = (char *)buf;
5085 u32 val;
5086
5087 val = simple_strtoul(p, &p, 10);
5088 if (p == buf)
5089 printk(KERN_INFO DRV_NAME
5090 ": %s is not in decimal form.\n", buf);
5091 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005092 iwl4965_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07005093
5094 return count;
5095}
5096
5097static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
5098
5099static ssize_t show_flags(struct device *d,
5100 struct device_attribute *attr, char *buf)
5101{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005102 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07005103
5104 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
5105}
5106
5107static ssize_t store_flags(struct device *d,
5108 struct device_attribute *attr,
5109 const char *buf, size_t count)
5110{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005111 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07005112 u32 flags = simple_strtoul(buf, NULL, 0);
5113
5114 mutex_lock(&priv->mutex);
5115 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
5116 /* Cancel any currently running scans... */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005117 if (iwl4965_scan_cancel_timeout(priv, 100))
Zhu Yib481de92007-09-25 17:54:57 -07005118 IWL_WARNING("Could not cancel scan.\n");
5119 else {
5120 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
5121 flags);
5122 priv->staging_rxon.flags = cpu_to_le32(flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005123 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005124 }
5125 }
5126 mutex_unlock(&priv->mutex);
5127
5128 return count;
5129}
5130
5131static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
5132
5133static ssize_t show_filter_flags(struct device *d,
5134 struct device_attribute *attr, char *buf)
5135{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005136 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07005137
5138 return sprintf(buf, "0x%04X\n",
5139 le32_to_cpu(priv->active_rxon.filter_flags));
5140}
5141
5142static ssize_t store_filter_flags(struct device *d,
5143 struct device_attribute *attr,
5144 const char *buf, size_t count)
5145{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005146 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07005147 u32 filter_flags = simple_strtoul(buf, NULL, 0);
5148
5149 mutex_lock(&priv->mutex);
5150 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
5151 /* Cancel any currently running scans... */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005152 if (iwl4965_scan_cancel_timeout(priv, 100))
Zhu Yib481de92007-09-25 17:54:57 -07005153 IWL_WARNING("Could not cancel scan.\n");
5154 else {
5155 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
5156 "0x%04X\n", filter_flags);
5157 priv->staging_rxon.filter_flags =
5158 cpu_to_le32(filter_flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005159 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005160 }
5161 }
5162 mutex_unlock(&priv->mutex);
5163
5164 return count;
5165}
5166
5167static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
5168 store_filter_flags);
5169
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005170#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07005171
5172static ssize_t show_measurement(struct device *d,
5173 struct device_attribute *attr, char *buf)
5174{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005175 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005176 struct iwl4965_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07005177 u32 size = sizeof(measure_report), len = 0, ofs = 0;
5178 u8 *data = (u8 *) & measure_report;
5179 unsigned long flags;
5180
5181 spin_lock_irqsave(&priv->lock, flags);
5182 if (!(priv->measurement_status & MEASUREMENT_READY)) {
5183 spin_unlock_irqrestore(&priv->lock, flags);
5184 return 0;
5185 }
5186 memcpy(&measure_report, &priv->measure_report, size);
5187 priv->measurement_status = 0;
5188 spin_unlock_irqrestore(&priv->lock, flags);
5189
5190 while (size && (PAGE_SIZE - len)) {
5191 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
5192 PAGE_SIZE - len, 1);
5193 len = strlen(buf);
5194 if (PAGE_SIZE - len)
5195 buf[len++] = '\n';
5196
5197 ofs += 16;
5198 size -= min(size, 16U);
5199 }
5200
5201 return len;
5202}
5203
5204static ssize_t store_measurement(struct device *d,
5205 struct device_attribute *attr,
5206 const char *buf, size_t count)
5207{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005208 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07005209 struct ieee80211_measurement_params params = {
5210 .channel = le16_to_cpu(priv->active_rxon.channel),
5211 .start_time = cpu_to_le64(priv->last_tsf),
5212 .duration = cpu_to_le16(1),
5213 };
5214 u8 type = IWL_MEASURE_BASIC;
5215 u8 buffer[32];
5216 u8 channel;
5217
5218 if (count) {
5219 char *p = buffer;
5220 strncpy(buffer, buf, min(sizeof(buffer), count));
5221 channel = simple_strtoul(p, NULL, 0);
5222 if (channel)
5223 params.channel = channel;
5224
5225 p = buffer;
5226 while (*p && *p != ' ')
5227 p++;
5228 if (*p)
5229 type = simple_strtoul(p + 1, NULL, 0);
5230 }
5231
5232 IWL_DEBUG_INFO("Invoking measurement of type %d on "
5233 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005234 iwl4965_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07005235
5236 return count;
5237}
5238
5239static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
5240 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005241#endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07005242
5243static ssize_t store_retry_rate(struct device *d,
5244 struct device_attribute *attr,
5245 const char *buf, size_t count)
5246{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005247 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07005248
5249 priv->retry_rate = simple_strtoul(buf, NULL, 0);
5250 if (priv->retry_rate <= 0)
5251 priv->retry_rate = 1;
5252
5253 return count;
5254}
5255
5256static ssize_t show_retry_rate(struct device *d,
5257 struct device_attribute *attr, char *buf)
5258{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005259 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07005260 return sprintf(buf, "%d", priv->retry_rate);
5261}
5262
5263static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
5264 store_retry_rate);
5265
5266static ssize_t store_power_level(struct device *d,
5267 struct device_attribute *attr,
5268 const char *buf, size_t count)
5269{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005270 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07005271 int rc;
5272 int mode;
5273
5274 mode = simple_strtoul(buf, NULL, 0);
5275 mutex_lock(&priv->mutex);
5276
Tomas Winklerfee12472008-04-03 16:05:21 -07005277 if (!iwl_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005278 rc = -EAGAIN;
5279 goto out;
5280 }
5281
Mohamed Abbas5da4b552008-04-21 15:41:51 -07005282 rc = iwl_power_set_user_mode(priv, mode);
5283 if (rc) {
5284 IWL_DEBUG_MAC80211("failed setting power mode.\n");
5285 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07005286 }
Zhu Yib481de92007-09-25 17:54:57 -07005287 rc = count;
5288
5289 out:
5290 mutex_unlock(&priv->mutex);
5291 return rc;
5292}
5293
5294#define MAX_WX_STRING 80
5295
5296/* Values are in microsecond */
5297static const s32 timeout_duration[] = {
5298 350000,
5299 250000,
5300 75000,
5301 37000,
5302 25000,
5303};
5304static const s32 period_duration[] = {
5305 400000,
5306 700000,
5307 1000000,
5308 1000000,
5309 1000000
5310};
5311
5312static ssize_t show_power_level(struct device *d,
5313 struct device_attribute *attr, char *buf)
5314{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005315 struct iwl_priv *priv = dev_get_drvdata(d);
Mohamed Abbas5da4b552008-04-21 15:41:51 -07005316 int level = priv->power_data.power_mode;
Zhu Yib481de92007-09-25 17:54:57 -07005317 char *p = buf;
5318
5319 p += sprintf(p, "%d ", level);
5320 switch (level) {
5321 case IWL_POWER_MODE_CAM:
5322 case IWL_POWER_AC:
5323 p += sprintf(p, "(AC)");
5324 break;
5325 case IWL_POWER_BATTERY:
5326 p += sprintf(p, "(BATTERY)");
5327 break;
5328 default:
5329 p += sprintf(p,
5330 "(Timeout %dms, Period %dms)",
5331 timeout_duration[level - 1] / 1000,
5332 period_duration[level - 1] / 1000);
5333 }
Mohamed Abbas5da4b552008-04-21 15:41:51 -07005334/*
Zhu Yib481de92007-09-25 17:54:57 -07005335 if (!(priv->power_mode & IWL_POWER_ENABLED))
5336 p += sprintf(p, " OFF\n");
5337 else
5338 p += sprintf(p, " \n");
Mohamed Abbas5da4b552008-04-21 15:41:51 -07005339*/
5340 p += sprintf(p, " \n");
Zhu Yib481de92007-09-25 17:54:57 -07005341 return (p - buf + 1);
Zhu Yib481de92007-09-25 17:54:57 -07005342}
5343
5344static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
5345 store_power_level);
5346
5347static ssize_t show_channels(struct device *d,
5348 struct device_attribute *attr, char *buf)
5349{
Johannes Berg8318d782008-01-24 19:38:38 +01005350 /* all this shit doesn't belong into sysfs anyway */
5351 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07005352}
5353
5354static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
5355
5356static ssize_t show_statistics(struct device *d,
5357 struct device_attribute *attr, char *buf)
5358{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005359 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005360 u32 size = sizeof(struct iwl4965_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07005361 u32 len = 0, ofs = 0;
5362 u8 *data = (u8 *) & priv->statistics;
5363 int rc = 0;
5364
Tomas Winklerfee12472008-04-03 16:05:21 -07005365 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07005366 return -EAGAIN;
5367
5368 mutex_lock(&priv->mutex);
Emmanuel Grumbach49ea8592008-04-15 16:01:37 -07005369 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07005370 mutex_unlock(&priv->mutex);
5371
5372 if (rc) {
5373 len = sprintf(buf,
5374 "Error sending statistics request: 0x%08X\n", rc);
5375 return len;
5376 }
5377
5378 while (size && (PAGE_SIZE - len)) {
5379 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
5380 PAGE_SIZE - len, 1);
5381 len = strlen(buf);
5382 if (PAGE_SIZE - len)
5383 buf[len++] = '\n';
5384
5385 ofs += 16;
5386 size -= min(size, 16U);
5387 }
5388
5389 return len;
5390}
5391
5392static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
5393
Zhu Yib481de92007-09-25 17:54:57 -07005394static ssize_t show_status(struct device *d,
5395 struct device_attribute *attr, char *buf)
5396{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005397 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winklerfee12472008-04-03 16:05:21 -07005398 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07005399 return -EAGAIN;
5400 return sprintf(buf, "0x%08x\n", (int)priv->status);
5401}
5402
5403static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
5404
Zhu Yib481de92007-09-25 17:54:57 -07005405/*****************************************************************************
5406 *
5407 * driver setup and teardown
5408 *
5409 *****************************************************************************/
5410
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005411static void iwl4965_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005412{
5413 priv->workqueue = create_workqueue(DRV_NAME);
5414
5415 init_waitqueue_head(&priv->wait_command_queue);
5416
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005417 INIT_WORK(&priv->up, iwl4965_bg_up);
5418 INIT_WORK(&priv->restart, iwl4965_bg_restart);
5419 INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish);
5420 INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed);
5421 INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan);
5422 INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan);
5423 INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill);
5424 INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update);
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08005425 INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005426 INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08005427 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
5428 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005429 INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check);
Zhu Yib481de92007-09-25 17:54:57 -07005430
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005431 iwl4965_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005432
5433 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005434 iwl4965_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07005435}
5436
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005437static void iwl4965_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005438{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005439 iwl4965_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005440
Joonwoo Park3ae6a052007-11-29 10:43:16 +09005441 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07005442 cancel_delayed_work(&priv->scan_check);
5443 cancel_delayed_work(&priv->alive_start);
5444 cancel_delayed_work(&priv->post_associate);
5445 cancel_work_sync(&priv->beacon_update);
5446}
5447
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005448static struct attribute *iwl4965_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07005449 &dev_attr_channels.attr,
Zhu Yib481de92007-09-25 17:54:57 -07005450 &dev_attr_flags.attr,
5451 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005452#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07005453 &dev_attr_measurement.attr,
5454#endif
5455 &dev_attr_power_level.attr,
5456 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07005457 &dev_attr_rs_window.attr,
5458 &dev_attr_statistics.attr,
5459 &dev_attr_status.attr,
5460 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07005461 &dev_attr_tx_power.attr,
Ester Kummer8cf769c2008-05-06 11:05:11 +08005462#ifdef CONFIG_IWLWIFI_DEBUG
5463 &dev_attr_debug_level.attr,
5464#endif
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08005465 &dev_attr_version.attr,
Zhu Yib481de92007-09-25 17:54:57 -07005466
5467 NULL
5468};
5469
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005470static struct attribute_group iwl4965_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07005471 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005472 .attrs = iwl4965_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07005473};
5474
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005475static struct ieee80211_ops iwl4965_hw_ops = {
5476 .tx = iwl4965_mac_tx,
5477 .start = iwl4965_mac_start,
5478 .stop = iwl4965_mac_stop,
5479 .add_interface = iwl4965_mac_add_interface,
5480 .remove_interface = iwl4965_mac_remove_interface,
5481 .config = iwl4965_mac_config,
5482 .config_interface = iwl4965_mac_config_interface,
5483 .configure_filter = iwl4965_configure_filter,
5484 .set_key = iwl4965_mac_set_key,
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02005485 .update_tkip_key = iwl4965_mac_update_tkip_key,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005486 .get_stats = iwl4965_mac_get_stats,
5487 .get_tx_stats = iwl4965_mac_get_tx_stats,
5488 .conf_tx = iwl4965_mac_conf_tx,
5489 .get_tsf = iwl4965_mac_get_tsf,
5490 .reset_tsf = iwl4965_mac_reset_tsf,
5491 .beacon_update = iwl4965_mac_beacon_update,
Johannes Berg471b3ef2007-12-28 14:32:58 +01005492 .bss_info_changed = iwl4965_bss_info_changed,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005493#ifdef CONFIG_IWL4965_HT
Ron Rindjunsky9ab46172007-12-25 17:00:38 +02005494 .ampdu_action = iwl4965_mac_ampdu_action,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005495#endif /* CONFIG_IWL4965_HT */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005496 .hw_scan = iwl4965_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07005497};
5498
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005499static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07005500{
5501 int err = 0;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005502 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07005503 struct ieee80211_hw *hw;
Tomas Winkler82b9a122008-03-04 18:09:30 -08005504 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005505 unsigned long flags;
Zhu Yi5a66926a2008-01-14 17:46:18 -08005506 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07005507
Assaf Krauss316c30d2008-03-14 10:38:46 -07005508 /************************
5509 * 1. Allocating HW data
5510 ************************/
5511
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005512 /* Disabling hardware scan means that mac80211 will perform scans
5513 * "the hard way", rather than using device's scan. */
Assaf Krauss1ea87392008-03-18 14:57:50 -07005514 if (cfg->mod_params->disable_hw_scan) {
Ester Kummerbf403db2008-05-05 10:22:40 +08005515 if (cfg->mod_params->debug & IWL_DL_INFO)
5516 dev_printk(KERN_DEBUG, &(pdev->dev),
5517 "Disabling hw_scan\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005518 iwl4965_hw_ops.hw_scan = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07005519 }
5520
Assaf Krauss1d0a0822008-03-14 10:38:48 -07005521 hw = iwl_alloc_all(cfg, &iwl4965_hw_ops);
5522 if (!hw) {
Zhu Yib481de92007-09-25 17:54:57 -07005523 err = -ENOMEM;
5524 goto out;
5525 }
Assaf Krauss1d0a0822008-03-14 10:38:48 -07005526 priv = hw->priv;
5527 /* At this point both hw and priv are allocated. */
5528
Zhu Yib481de92007-09-25 17:54:57 -07005529 SET_IEEE80211_DEV(hw, &pdev->dev);
5530
5531 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
Tomas Winkler82b9a122008-03-04 18:09:30 -08005532 priv->cfg = cfg;
Zhu Yib481de92007-09-25 17:54:57 -07005533 priv->pci_dev = pdev;
Assaf Krauss316c30d2008-03-14 10:38:46 -07005534
Tomas Winkler0a6857e2008-03-12 16:58:49 -07005535#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08005536 priv->debug_level = priv->cfg->mod_params->debug;
Zhu Yib481de92007-09-25 17:54:57 -07005537 atomic_set(&priv->restrict_refcnt, 0);
5538#endif
Zhu Yib481de92007-09-25 17:54:57 -07005539
Assaf Krauss316c30d2008-03-14 10:38:46 -07005540 /**************************
5541 * 2. Initializing PCI bus
5542 **************************/
5543 if (pci_enable_device(pdev)) {
5544 err = -ENODEV;
5545 goto out_ieee80211_free_hw;
5546 }
5547
5548 pci_set_master(pdev);
5549
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07005550 err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
Assaf Krauss316c30d2008-03-14 10:38:46 -07005551 if (!err)
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07005552 err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
5553 if (err) {
5554 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
5555 if (!err)
5556 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
5557 /* both attempts failed: */
Assaf Krauss316c30d2008-03-14 10:38:46 -07005558 if (err) {
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07005559 printk(KERN_WARNING "%s: No suitable DMA available.\n",
5560 DRV_NAME);
Assaf Krauss316c30d2008-03-14 10:38:46 -07005561 goto out_pci_disable_device;
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07005562 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07005563 }
5564
5565 err = pci_request_regions(pdev, DRV_NAME);
5566 if (err)
5567 goto out_pci_disable_device;
5568
5569 pci_set_drvdata(pdev, priv);
5570
5571 /* We disable the RETRY_TIMEOUT register (0x41) to keep
5572 * PCI Tx retries from interfering with C3 CPU state */
5573 pci_write_config_byte(pdev, 0x41, 0x00);
5574
5575 /***********************
5576 * 3. Read REV register
5577 ***********************/
5578 priv->hw_base = pci_iomap(pdev, 0, 0);
5579 if (!priv->hw_base) {
5580 err = -ENODEV;
5581 goto out_pci_release_regions;
5582 }
5583
5584 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
5585 (unsigned long long) pci_resource_len(pdev, 0));
5586 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
5587
Tomas Winklerb661c812008-04-23 17:14:54 -07005588 iwl_hw_detect(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07005589 printk(KERN_INFO DRV_NAME
Tomas Winklerb661c812008-04-23 17:14:54 -07005590 ": Detected Intel Wireless WiFi Link %s REV=0x%X\n",
5591 priv->cfg->name, priv->hw_rev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07005592
Tomas Winkler91238712008-04-23 17:14:53 -07005593 /* amp init */
5594 err = priv->cfg->ops->lib->apm_ops.init(priv);
5595 if (err < 0) {
5596 IWL_DEBUG_INFO("Failed to init APMG\n");
5597 goto out_iounmap;
5598 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07005599 /*****************
5600 * 4. Read EEPROM
5601 *****************/
Assaf Krauss316c30d2008-03-14 10:38:46 -07005602 /* Read the EEPROM */
5603 err = iwl_eeprom_init(priv);
5604 if (err) {
5605 IWL_ERROR("Unable to init EEPROM\n");
5606 goto out_iounmap;
5607 }
Tomas Winkler8614f362008-04-23 17:14:55 -07005608 err = iwl_eeprom_check_version(priv);
5609 if (err)
5610 goto out_iounmap;
5611
Ron Rindjunsky02883012008-05-15 13:53:53 +08005612 /* extract MAC Address */
Assaf Krauss316c30d2008-03-14 10:38:46 -07005613 iwl_eeprom_get_mac(priv, priv->mac_addr);
5614 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr));
5615 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
5616
5617 /************************
5618 * 5. Setup HW constants
5619 ************************/
5620 /* Device-specific setup */
Tomas Winkler5425e492008-04-15 16:01:38 -07005621 if (priv->cfg->ops->lib->set_hw_params(priv)) {
5622 IWL_ERROR("failed to set hw parameters\n");
Tomas Winkler073d3f52008-04-21 15:41:52 -07005623 goto out_free_eeprom;
Assaf Krauss316c30d2008-03-14 10:38:46 -07005624 }
5625
5626 /*******************
Tomas Winkler6ba87952008-05-15 13:54:17 +08005627 * 6. Setup priv
Assaf Krauss316c30d2008-03-14 10:38:46 -07005628 *******************/
Zhu Yib481de92007-09-25 17:54:57 -07005629
Tomas Winkler6ba87952008-05-15 13:54:17 +08005630 err = iwl_init_drv(priv);
Assaf Kraussbf85ea42008-03-14 10:38:49 -07005631 if (err)
Ron Rindjunsky399f4902008-04-23 17:14:56 -07005632 goto out_free_eeprom;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07005633 /* At this point both hw and priv are initialized. */
Assaf Krauss316c30d2008-03-14 10:38:46 -07005634
5635 /**********************************
5636 * 7. Initialize module parameters
5637 **********************************/
5638
5639 /* Disable radio (SW RF KILL) via parameter when loading driver */
Assaf Krauss1ea87392008-03-18 14:57:50 -07005640 if (priv->cfg->mod_params->disable) {
Assaf Krauss316c30d2008-03-14 10:38:46 -07005641 set_bit(STATUS_RF_KILL_SW, &priv->status);
5642 IWL_DEBUG_INFO("Radio disabled.\n");
5643 }
5644
Assaf Krauss316c30d2008-03-14 10:38:46 -07005645 /********************
5646 * 8. Setup services
5647 ********************/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005648 spin_lock_irqsave(&priv->lock, flags);
Assaf Krauss316c30d2008-03-14 10:38:46 -07005649 iwl4965_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005650 spin_unlock_irqrestore(&priv->lock, flags);
Assaf Krauss316c30d2008-03-14 10:38:46 -07005651
5652 err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
5653 if (err) {
5654 IWL_ERROR("failed to create sysfs device attributes\n");
Tomas Winkler6ba87952008-05-15 13:54:17 +08005655 goto out_uninit_drv;
Assaf Krauss316c30d2008-03-14 10:38:46 -07005656 }
5657
Assaf Krauss316c30d2008-03-14 10:38:46 -07005658
5659 iwl4965_setup_deferred_work(priv);
5660 iwl4965_setup_rx_handlers(priv);
5661
5662 /********************
5663 * 9. Conclude
5664 ********************/
Zhu Yi5a66926a2008-01-14 17:46:18 -08005665 pci_save_state(pdev);
5666 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005667
Tomas Winkler6ba87952008-05-15 13:54:17 +08005668 /**********************************
5669 * 10. Setup and register mac80211
5670 **********************************/
5671
5672 err = iwl_setup_mac(priv);
5673 if (err)
5674 goto out_remove_sysfs;
5675
5676 err = iwl_dbgfs_register(priv, DRV_NAME);
5677 if (err)
5678 IWL_ERROR("failed to create debugfs files\n");
5679
Mohamed Abbasc8381fd2008-03-28 16:21:05 -07005680 /* notify iwlcore to init */
5681 iwlcore_low_level_notify(priv, IWLCORE_INIT_EVT);
Zhu Yib481de92007-09-25 17:54:57 -07005682 return 0;
5683
Assaf Krauss316c30d2008-03-14 10:38:46 -07005684 out_remove_sysfs:
5685 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
Tomas Winkler6ba87952008-05-15 13:54:17 +08005686 out_uninit_drv:
5687 iwl_uninit_drv(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07005688 out_free_eeprom:
5689 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005690 out_iounmap:
5691 pci_iounmap(pdev, priv->hw_base);
5692 out_pci_release_regions:
5693 pci_release_regions(pdev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07005694 pci_set_drvdata(pdev, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07005695 out_pci_disable_device:
5696 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005697 out_ieee80211_free_hw:
5698 ieee80211_free_hw(priv->hw);
5699 out:
5700 return err;
5701}
5702
Reinette Chatrec83dbf62008-03-21 13:53:41 -07005703static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07005704{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005705 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005706 struct list_head *p, *q;
5707 int i;
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005708 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07005709
5710 if (!priv)
5711 return;
5712
5713 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
5714
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07005715 if (priv->mac80211_registered) {
5716 ieee80211_unregister_hw(priv->hw);
5717 priv->mac80211_registered = 0;
5718 }
5719
Zhu Yib481de92007-09-25 17:54:57 -07005720 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08005721
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005722 iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005723
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005724 /* make sure we flush any pending irq or
5725 * tasklet for the driver
5726 */
5727 spin_lock_irqsave(&priv->lock, flags);
5728 iwl4965_disable_interrupts(priv);
5729 spin_unlock_irqrestore(&priv->lock, flags);
5730
5731 iwl_synchronize_irq(priv);
5732
Zhu Yib481de92007-09-25 17:54:57 -07005733 /* Free MAC hash list for ADHOC */
5734 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
5735 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
5736 list_del(p);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005737 kfree(list_entry(p, struct iwl4965_ibss_seq, list));
Zhu Yib481de92007-09-25 17:54:57 -07005738 }
5739 }
5740
Mohamed Abbasc8381fd2008-03-28 16:21:05 -07005741 iwlcore_low_level_notify(priv, IWLCORE_REMOVE_EVT);
Tomas Winkler712b6cf2008-03-12 16:58:52 -07005742 iwl_dbgfs_unregister(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005743 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07005744
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005745 iwl4965_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005746
5747 if (priv->rxq.bd)
Tomas Winklera55360e2008-05-05 10:22:28 +08005748 iwl_rx_queue_free(priv, &priv->rxq);
Ron Rindjunsky1053d352008-05-05 10:22:43 +08005749 iwl_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005750
Assaf Kraussbf85ea42008-03-14 10:38:49 -07005751 iwlcore_clear_stations_table(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07005752 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005753
Zhu Yib481de92007-09-25 17:54:57 -07005754
Mohamed Abbas948c1712007-10-25 17:15:45 +08005755 /*netif_stop_queue(dev); */
5756 flush_workqueue(priv->workqueue);
5757
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005758 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07005759 * priv->workqueue... so we can't take down the workqueue
5760 * until now... */
5761 destroy_workqueue(priv->workqueue);
5762 priv->workqueue = NULL;
5763
Zhu Yib481de92007-09-25 17:54:57 -07005764 pci_iounmap(pdev, priv->hw_base);
5765 pci_release_regions(pdev);
5766 pci_disable_device(pdev);
5767 pci_set_drvdata(pdev, NULL);
5768
Tomas Winkler6ba87952008-05-15 13:54:17 +08005769 iwl_uninit_drv(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005770
5771 if (priv->ibss_beacon)
5772 dev_kfree_skb(priv->ibss_beacon);
5773
5774 ieee80211_free_hw(priv->hw);
5775}
5776
5777#ifdef CONFIG_PM
5778
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005779static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07005780{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005781 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005782
Zhu Yie655b9f2008-01-24 02:19:38 -08005783 if (priv->is_open) {
5784 set_bit(STATUS_IN_SUSPEND, &priv->status);
5785 iwl4965_mac_stop(priv->hw);
5786 priv->is_open = 1;
5787 }
Zhu Yib481de92007-09-25 17:54:57 -07005788
Zhu Yib481de92007-09-25 17:54:57 -07005789 pci_set_power_state(pdev, PCI_D3hot);
5790
Zhu Yib481de92007-09-25 17:54:57 -07005791 return 0;
5792}
5793
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005794static int iwl4965_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07005795{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005796 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005797
Zhu Yib481de92007-09-25 17:54:57 -07005798 pci_set_power_state(pdev, PCI_D0);
Zhu Yib481de92007-09-25 17:54:57 -07005799
Zhu Yie655b9f2008-01-24 02:19:38 -08005800 if (priv->is_open)
5801 iwl4965_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07005802
Zhu Yie655b9f2008-01-24 02:19:38 -08005803 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07005804 return 0;
5805}
5806
5807#endif /* CONFIG_PM */
5808
5809/*****************************************************************************
5810 *
5811 * driver and module entry point
5812 *
5813 *****************************************************************************/
5814
Ron Rindjunskyfed90172008-04-15 16:01:41 -07005815/* Hardware specific file defines the PCI IDs table for that hardware module */
5816static struct pci_device_id iwl_hw_card_ids[] = {
5817 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
5818 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07005819#ifdef CONFIG_IWL5000
5820 {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)},
5821 {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)},
5822 {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID, iwl5350_agn_cfg)},
5823#endif /* CONFIG_IWL5000 */
Ron Rindjunskyfed90172008-04-15 16:01:41 -07005824 {0}
5825};
5826MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
5827
5828static struct pci_driver iwl_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07005829 .name = DRV_NAME,
Ron Rindjunskyfed90172008-04-15 16:01:41 -07005830 .id_table = iwl_hw_card_ids,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005831 .probe = iwl4965_pci_probe,
5832 .remove = __devexit_p(iwl4965_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07005833#ifdef CONFIG_PM
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005834 .suspend = iwl4965_pci_suspend,
5835 .resume = iwl4965_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07005836#endif
5837};
5838
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005839static int __init iwl4965_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07005840{
5841
5842 int ret;
5843 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
5844 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005845
5846 ret = iwl4965_rate_control_register();
5847 if (ret) {
5848 IWL_ERROR("Unable to register rate control algorithm: %d\n", ret);
5849 return ret;
5850 }
5851
Ron Rindjunskyfed90172008-04-15 16:01:41 -07005852 ret = pci_register_driver(&iwl_driver);
Zhu Yib481de92007-09-25 17:54:57 -07005853 if (ret) {
5854 IWL_ERROR("Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005855 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07005856 }
Zhu Yib481de92007-09-25 17:54:57 -07005857
5858 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005859
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005860error_register:
5861 iwl4965_rate_control_unregister();
5862 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07005863}
5864
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005865static void __exit iwl4965_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07005866{
Ron Rindjunskyfed90172008-04-15 16:01:41 -07005867 pci_unregister_driver(&iwl_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005868 iwl4965_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07005869}
5870
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005871module_exit(iwl4965_exit);
5872module_init(iwl4965_init);