blob: 757a9bd3ecd6a8830d641acd92fbc3270d1b1c74 [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Reinette Chatre01f81622009-01-08 10:20:02 -08003 * Copyright(c) 2003 - 2009 Intel Corporation. All rights reserved.
Zhu Yib481de92007-09-25 17:54:57 -07004 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
Winkler, Tomas759ef892008-12-09 11:28:58 -080025 * Intel Linux Wireless <ilw@linux.intel.com>
Zhu Yib481de92007-09-25 17:54:57 -070026 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
Zhu Yib481de92007-09-25 17:54:57 -070030#include <linux/kernel.h>
31#include <linux/module.h>
Zhu Yib481de92007-09-25 17:54:57 -070032#include <linux/init.h>
33#include <linux/pci.h>
34#include <linux/dma-mapping.h>
35#include <linux/delay.h>
36#include <linux/skbuff.h>
37#include <linux/netdevice.h>
38#include <linux/wireless.h>
39#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070040#include <linux/etherdevice.h>
41#include <linux/if_arp.h>
42
Zhu Yib481de92007-09-25 17:54:57 -070043#include <net/mac80211.h>
44
45#include <asm/div64.h>
46
Samuel Ortiza3139c52008-12-19 10:37:09 +080047#define DRV_NAME "iwlagn"
48
Assaf Krauss6bc913b2008-03-11 16:17:18 -070049#include "iwl-eeprom.h"
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070050#include "iwl-dev.h"
Tomas Winklerfee12472008-04-03 16:05:21 -070051#include "iwl-core.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070052#include "iwl-io.h"
Zhu Yib481de92007-09-25 17:54:57 -070053#include "iwl-helpers.h"
Emmanuel Grumbach6974e362008-04-14 21:16:06 -070054#include "iwl-sta.h"
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -070055#include "iwl-calib.h"
Zhu Yib481de92007-09-25 17:54:57 -070056
Christoph Hellwig416e1432007-10-25 17:15:49 +080057
Zhu Yib481de92007-09-25 17:54:57 -070058/******************************************************************************
59 *
60 * module boiler plate
61 *
62 ******************************************************************************/
63
Zhu Yib481de92007-09-25 17:54:57 -070064/*
65 * module name, copyright, version, etc.
Zhu Yib481de92007-09-25 17:54:57 -070066 */
Tomas Winklerd783b062008-07-18 13:53:02 +080067#define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
Zhu Yib481de92007-09-25 17:54:57 -070068
Tomas Winkler0a6857e2008-03-12 16:58:49 -070069#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070070#define VD "d"
71#else
72#define VD
73#endif
74
Tomas Winkler4fc22b22008-07-21 18:54:42 +030075#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070076#define VS "s"
77#else
78#define VS
79#endif
80
Tomas Winklerdf48c322008-03-06 10:40:19 -080081#define DRV_VERSION IWLWIFI_VERSION VD VS
Zhu Yib481de92007-09-25 17:54:57 -070082
Zhu Yib481de92007-09-25 17:54:57 -070083
84MODULE_DESCRIPTION(DRV_DESCRIPTION);
85MODULE_VERSION(DRV_VERSION);
Tomas Winklera7b75202008-12-11 10:33:41 -080086MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
Zhu Yib481de92007-09-25 17:54:57 -070087MODULE_LICENSE("GPL");
Tomas Winkler4fc22b22008-07-21 18:54:42 +030088MODULE_ALIAS("iwl4965");
Zhu Yib481de92007-09-25 17:54:57 -070089
Zhu Yib481de92007-09-25 17:54:57 -070090/*************** STATION TABLE MANAGEMENT ****
Ben Cahill9fbab512007-11-29 11:09:47 +080091 * mac80211 should be examined to determine if sta_info is duplicating
Zhu Yib481de92007-09-25 17:54:57 -070092 * the functionality provided here
93 */
94
95/**************************************************************/
96
Zhu Yib481de92007-09-25 17:54:57 -070097
Zhu Yib481de92007-09-25 17:54:57 -070098
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -070099static void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -0700100{
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800101 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -0700102
103 if (hw_decrypt)
104 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
105 else
106 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
107
108}
109
Zhu Yib481de92007-09-25 17:54:57 -0700110/**
Mohamed Abbas54559702008-09-03 11:18:44 +0800111 * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
Ian Schram01ebd062007-10-25 17:15:22 +0800112 * @priv: staging_rxon is compared to active_rxon
Zhu Yib481de92007-09-25 17:54:57 -0700113 *
Ben Cahill9fbab512007-11-29 11:09:47 +0800114 * If the RXON structure is changing enough to require a new tune,
115 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
116 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
Zhu Yib481de92007-09-25 17:54:57 -0700117 */
Mohamed Abbas54559702008-09-03 11:18:44 +0800118static int iwl_full_rxon_required(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700119{
120
121 /* These items are only settable from the full RXON command */
Ron Rindjunsky5d1e2322008-06-30 17:23:04 +0800122 if (!(iwl_is_associated(priv)) ||
Zhu Yib481de92007-09-25 17:54:57 -0700123 compare_ether_addr(priv->staging_rxon.bssid_addr,
124 priv->active_rxon.bssid_addr) ||
125 compare_ether_addr(priv->staging_rxon.node_addr,
126 priv->active_rxon.node_addr) ||
127 compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
128 priv->active_rxon.wlap_bssid_addr) ||
129 (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
130 (priv->staging_rxon.channel != priv->active_rxon.channel) ||
131 (priv->staging_rxon.air_propagation !=
132 priv->active_rxon.air_propagation) ||
133 (priv->staging_rxon.ofdm_ht_single_stream_basic_rates !=
134 priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
135 (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
136 priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
Zhu Yib481de92007-09-25 17:54:57 -0700137 (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
138 return 1;
139
140 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
141 * be updated with the RXON_ASSOC command -- however only some
142 * flag transitions are allowed using RXON_ASSOC */
143
144 /* Check if we are not switching bands */
145 if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
146 (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
147 return 1;
148
149 /* Check if we are switching association toggle */
150 if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
151 (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
152 return 1;
153
154 return 0;
155}
156
Zhu Yib481de92007-09-25 17:54:57 -0700157/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700158 * iwl_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -0700159 *
Ian Schram01ebd062007-10-25 17:15:22 +0800160 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -0700161 * the active_rxon structure is updated with the new data. This
162 * function correctly transitions out of the RXON_ASSOC_MSK state if
163 * a HW tune is required based on the RXON structure changes.
164 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700165static int iwl_commit_rxon(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700166{
167 /* cast away the const for active_rxon in this function */
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800168 struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800169 int ret;
170 bool new_assoc =
171 !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK);
Zhu Yib481de92007-09-25 17:54:57 -0700172
Tomas Winklerfee12472008-04-03 16:05:21 -0700173 if (!iwl_is_alive(priv))
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800174 return -EBUSY;
Zhu Yib481de92007-09-25 17:54:57 -0700175
176 /* always get timestamp with Rx frame */
177 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
Emmanuel Grumbacha326a5d2008-07-11 11:53:31 +0800178 /* allow CTS-to-self if possible. this is relevant only for
179 * 5000, but will not damage 4965 */
180 priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN;
Zhu Yib481de92007-09-25 17:54:57 -0700181
Samuel Ortiza3139c52008-12-19 10:37:09 +0800182 ret = iwl_agn_check_rxon_cmd(priv);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800183 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800184 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700185 return -EINVAL;
186 }
187
188 /* If we don't need to send a full RXON, we can use
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700189 * iwl_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -0700190 * and other flags for the current radio configuration. */
Mohamed Abbas54559702008-09-03 11:18:44 +0800191 if (!iwl_full_rxon_required(priv)) {
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800192 ret = iwl_send_rxon_assoc(priv);
193 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800194 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800195 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700196 }
197
198 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700199 return 0;
200 }
201
202 /* station table will be cleared */
203 priv->assoc_station_added = 0;
204
Zhu Yib481de92007-09-25 17:54:57 -0700205 /* If we are currently associated and the new config requires
206 * an RXON_ASSOC and the new config wants the associated mask enabled,
207 * we must clear the associated from the active configuration
208 * before we apply the new config */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800209 if (iwl_is_associated(priv) && new_assoc) {
Zhu Yib481de92007-09-25 17:54:57 -0700210 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
211 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
212
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800213 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800214 sizeof(struct iwl_rxon_cmd),
Zhu Yib481de92007-09-25 17:54:57 -0700215 &priv->active_rxon);
216
217 /* If the mask clearing failed then we set
218 * active_rxon back to what it was previously */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800219 if (ret) {
Zhu Yib481de92007-09-25 17:54:57 -0700220 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
Winkler, Tomas15b16872008-12-19 10:37:33 +0800221 IWL_ERR(priv, "Error clearing ASSOC_MSK (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800222 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700223 }
Zhu Yib481de92007-09-25 17:54:57 -0700224 }
225
226 IWL_DEBUG_INFO("Sending RXON\n"
227 "* with%s RXON_FILTER_ASSOC_MSK\n"
228 "* channel = %d\n"
Johannes Berge1749612008-10-27 15:59:26 -0700229 "* bssid = %pM\n",
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800230 (new_assoc ? "" : "out"),
Zhu Yib481de92007-09-25 17:54:57 -0700231 le16_to_cpu(priv->staging_rxon.channel),
Johannes Berge1749612008-10-27 15:59:26 -0700232 priv->staging_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -0700233
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700234 iwl_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800235
236 /* Apply the new configuration
237 * RXON unassoc clears the station table in uCode, send it before
238 * we add the bcast station. If assoc bit is set, we will send RXON
239 * after having added the bcast and bssid station.
240 */
241 if (!new_assoc) {
242 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800243 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800244 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800245 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800246 return ret;
247 }
248 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700249 }
250
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +0800251 iwl_clear_stations_table(priv);
Zhu Yi556f8db2007-09-27 11:27:33 +0800252
Zhu Yib481de92007-09-25 17:54:57 -0700253 if (!priv->error_recovering)
254 priv->start_calib = 0;
255
Zhu Yib481de92007-09-25 17:54:57 -0700256 /* Add the broadcast address so we can send broadcast frames */
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800257 if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) ==
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800258 IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800259 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700260 return -EIO;
261 }
262
263 /* If we have set the ASSOC_MSK and we are in BSS mode then
264 * add the IWL_AP_ID to the station rate table */
Tomas Winkler91851592008-06-30 17:23:14 +0800265 if (new_assoc) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200266 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Tomas Winkler91851592008-06-30 17:23:14 +0800267 ret = iwl_rxon_add_station(priv,
268 priv->active_rxon.bssid_addr, 1);
269 if (ret == IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800270 IWL_ERR(priv,
271 "Error adding AP address for TX.\n");
Tomas Winkler91851592008-06-30 17:23:14 +0800272 return -EIO;
273 }
274 priv->assoc_station_added = 1;
275 if (priv->default_wep_key &&
276 iwl_send_static_wepkey_cmd(priv, 0))
Winkler, Tomas15b16872008-12-19 10:37:33 +0800277 IWL_ERR(priv,
278 "Could not send WEP static key.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700279 }
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800280
281 /* Apply the new configuration
282 * RXON assoc doesn't clear the station table in uCode,
283 */
284 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
285 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
286 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800287 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800288 return ret;
289 }
290 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700291 }
292
Zhu Yi36da7d72008-07-11 11:53:40 +0800293 iwl_init_sensitivity(priv);
294
295 /* If we issue a new RXON command which required a tune then we must
296 * send a new TXPOWER command or we won't be able to Tx any frames */
297 ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
298 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800299 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
Zhu Yi36da7d72008-07-11 11:53:40 +0800300 return ret;
301 }
302
Zhu Yib481de92007-09-25 17:54:57 -0700303 return 0;
304}
305
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700306void iwl_update_chain_flags(struct iwl_priv *priv)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700307{
308
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -0700309 iwl_set_rxon_chain(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700310 iwl_commit_rxon(priv);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700311}
312
Tomas Winklerfcab4232008-05-15 13:54:01 +0800313static void iwl_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700314{
315 struct list_head *element;
316
317 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
318 priv->frames_count);
319
320 while (!list_empty(&priv->free_frames)) {
321 element = priv->free_frames.next;
322 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800323 kfree(list_entry(element, struct iwl_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700324 priv->frames_count--;
325 }
326
327 if (priv->frames_count) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800328 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
Zhu Yib481de92007-09-25 17:54:57 -0700329 priv->frames_count);
330 priv->frames_count = 0;
331 }
332}
333
Tomas Winklerfcab4232008-05-15 13:54:01 +0800334static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700335{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800336 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700337 struct list_head *element;
338 if (list_empty(&priv->free_frames)) {
339 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
340 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800341 IWL_ERR(priv, "Could not allocate frame!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700342 return NULL;
343 }
344
345 priv->frames_count++;
346 return frame;
347 }
348
349 element = priv->free_frames.next;
350 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800351 return list_entry(element, struct iwl_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700352}
353
Tomas Winklerfcab4232008-05-15 13:54:01 +0800354static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700355{
356 memset(frame, 0, sizeof(*frame));
357 list_add(&frame->list, &priv->free_frames);
358}
359
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800360static unsigned int iwl_fill_beacon_frame(struct iwl_priv *priv,
361 struct ieee80211_hdr *hdr,
Rami Rosen73ec1cc2008-12-16 09:37:07 +0200362 int left)
Zhu Yib481de92007-09-25 17:54:57 -0700363{
Tomas Winkler3109ece2008-03-28 16:33:35 -0700364 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200365 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
366 (priv->iw_mode != NL80211_IFTYPE_AP)))
Zhu Yib481de92007-09-25 17:54:57 -0700367 return 0;
368
369 if (priv->ibss_beacon->len > left)
370 return 0;
371
372 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
373
374 return priv->ibss_beacon->len;
375}
376
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700377static u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700378{
Guy Cohen39e88502008-04-23 17:14:57 -0700379 int i;
380 int rate_mask;
Zhu Yib481de92007-09-25 17:54:57 -0700381
Guy Cohen39e88502008-04-23 17:14:57 -0700382 /* Set rate mask*/
383 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
Chatre, Reinettedbce56a2008-11-12 13:14:07 -0800384 rate_mask = priv->active_rate_basic & IWL_CCK_RATES_MASK;
Guy Cohen39e88502008-04-23 17:14:57 -0700385 else
Chatre, Reinettedbce56a2008-11-12 13:14:07 -0800386 rate_mask = priv->active_rate_basic & IWL_OFDM_RATES_MASK;
Guy Cohen39e88502008-04-23 17:14:57 -0700387
388 /* Find lowest valid rate */
Zhu Yib481de92007-09-25 17:54:57 -0700389 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800390 i = iwl_rates[i].next_ieee) {
Zhu Yib481de92007-09-25 17:54:57 -0700391 if (rate_mask & (1 << i))
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800392 return iwl_rates[i].plcp;
Zhu Yib481de92007-09-25 17:54:57 -0700393 }
394
Guy Cohen39e88502008-04-23 17:14:57 -0700395 /* No valid rate was found. Assign the lowest one */
396 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
397 return IWL_RATE_1M_PLCP;
398 else
399 return IWL_RATE_6M_PLCP;
Zhu Yib481de92007-09-25 17:54:57 -0700400}
401
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700402static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800403 struct iwl_frame *frame, u8 rate)
404{
405 struct iwl_tx_beacon_cmd *tx_beacon_cmd;
406 unsigned int frame_size;
407
408 tx_beacon_cmd = &frame->u.beacon;
409 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
410
411 tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
412 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
413
414 frame_size = iwl_fill_beacon_frame(priv, tx_beacon_cmd->frame,
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800415 sizeof(frame->u) - sizeof(*tx_beacon_cmd));
416
417 BUG_ON(frame_size > MAX_MPDU_SIZE);
418 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
419
420 if ((rate == IWL_RATE_1M_PLCP) || (rate >= IWL_RATE_2M_PLCP))
421 tx_beacon_cmd->tx.rate_n_flags =
422 iwl_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK);
423 else
424 tx_beacon_cmd->tx.rate_n_flags =
425 iwl_hw_set_rate_n_flags(rate, 0);
426
427 tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
428 TX_CMD_FLG_TSF_MSK |
429 TX_CMD_FLG_STA_RATE_MSK;
430
431 return sizeof(*tx_beacon_cmd) + frame_size;
432}
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700433static int iwl_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700434{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800435 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700436 unsigned int frame_size;
437 int rc;
438 u8 rate;
439
Tomas Winklerfcab4232008-05-15 13:54:01 +0800440 frame = iwl_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700441
442 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800443 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
Zhu Yib481de92007-09-25 17:54:57 -0700444 "command.\n");
445 return -ENOMEM;
446 }
447
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700448 rate = iwl_rate_get_lowest_plcp(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700449
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700450 frame_size = iwl_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -0700451
Tomas Winkler857485c2008-03-21 13:53:44 -0700452 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700453 &frame->u.cmd[0]);
454
Tomas Winklerfcab4232008-05-15 13:54:01 +0800455 iwl_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700456
457 return rc;
458}
459
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800460static inline dma_addr_t iwl_tfd_tb_get_addr(struct iwl_tfd *tfd, u8 idx)
461{
462 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
463
464 dma_addr_t addr = get_unaligned_le32(&tb->lo);
465 if (sizeof(dma_addr_t) > sizeof(u32))
466 addr |=
467 ((dma_addr_t)(le16_to_cpu(tb->hi_n_len) & 0xF) << 16) << 16;
468
469 return addr;
470}
471
472static inline u16 iwl_tfd_tb_get_len(struct iwl_tfd *tfd, u8 idx)
473{
474 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
475
476 return le16_to_cpu(tb->hi_n_len) >> 4;
477}
478
479static inline void iwl_tfd_set_tb(struct iwl_tfd *tfd, u8 idx,
480 dma_addr_t addr, u16 len)
481{
482 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
483 u16 hi_n_len = len << 4;
484
485 put_unaligned_le32(addr, &tb->lo);
486 if (sizeof(dma_addr_t) > sizeof(u32))
487 hi_n_len |= ((addr >> 16) >> 16) & 0xF;
488
489 tb->hi_n_len = cpu_to_le16(hi_n_len);
490
491 tfd->num_tbs = idx + 1;
492}
493
494static inline u8 iwl_tfd_get_num_tbs(struct iwl_tfd *tfd)
495{
496 return tfd->num_tbs & 0x1f;
497}
498
499/**
500 * iwl_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
501 * @priv - driver private data
502 * @txq - tx queue
503 *
504 * Does NOT advance any TFD circular buffer read/write indexes
505 * Does NOT free the TFD itself (which is within circular buffer)
506 */
507void iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq)
508{
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800509 struct iwl_tfd *tfd_tmp = (struct iwl_tfd *)txq->tfds;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800510 struct iwl_tfd *tfd;
511 struct pci_dev *dev = priv->pci_dev;
512 int index = txq->q.read_ptr;
513 int i;
514 int num_tbs;
515
516 tfd = &tfd_tmp[index];
517
518 /* Sanity check on number of chunks */
519 num_tbs = iwl_tfd_get_num_tbs(tfd);
520
521 if (num_tbs >= IWL_NUM_OF_TBS) {
522 IWL_ERR(priv, "Too many chunks: %i\n", num_tbs);
523 /* @todo issue fatal error, it is quite serious situation */
524 return;
525 }
526
527 /* Unmap tx_cmd */
528 if (num_tbs)
529 pci_unmap_single(dev,
530 pci_unmap_addr(&txq->cmd[index]->meta, mapping),
531 pci_unmap_len(&txq->cmd[index]->meta, len),
532 PCI_DMA_TODEVICE);
533
534 /* Unmap chunks, if any. */
535 for (i = 1; i < num_tbs; i++) {
536 pci_unmap_single(dev, iwl_tfd_tb_get_addr(tfd, i),
537 iwl_tfd_tb_get_len(tfd, i), PCI_DMA_TODEVICE);
538
539 if (txq->txb) {
540 dev_kfree_skb(txq->txb[txq->q.read_ptr].skb[i - 1]);
541 txq->txb[txq->q.read_ptr].skb[i - 1] = NULL;
542 }
543 }
544}
545
546int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv,
547 struct iwl_tx_queue *txq,
548 dma_addr_t addr, u16 len,
549 u8 reset, u8 pad)
550{
551 struct iwl_queue *q;
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800552 struct iwl_tfd *tfd, *tfd_tmp;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800553 u32 num_tbs;
554
555 q = &txq->q;
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800556 tfd_tmp = (struct iwl_tfd *)txq->tfds;
557 tfd = &tfd_tmp[q->write_ptr];
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800558
559 if (reset)
560 memset(tfd, 0, sizeof(*tfd));
561
562 num_tbs = iwl_tfd_get_num_tbs(tfd);
563
564 /* Each TFD can point to a maximum 20 Tx buffers */
565 if (num_tbs >= IWL_NUM_OF_TBS) {
566 IWL_ERR(priv, "Error can not send more than %d chunks\n",
567 IWL_NUM_OF_TBS);
568 return -EINVAL;
569 }
570
571 BUG_ON(addr & ~DMA_BIT_MASK(36));
572 if (unlikely(addr & ~IWL_TX_DMA_MASK))
573 IWL_ERR(priv, "Unaligned address = %llx\n",
574 (unsigned long long)addr);
575
576 iwl_tfd_set_tb(tfd, num_tbs, addr, len);
577
578 return 0;
579}
580
Samuel Ortiza8e74e22009-01-23 13:45:14 -0800581/*
582 * Tell nic where to find circular buffer of Tx Frame Descriptors for
583 * given Tx queue, and enable the DMA channel used for that queue.
584 *
585 * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
586 * channels supported in hardware.
587 */
588int iwl_hw_tx_queue_init(struct iwl_priv *priv,
589 struct iwl_tx_queue *txq)
590{
591 int ret;
592 unsigned long flags;
593 int txq_id = txq->q.id;
594
595 spin_lock_irqsave(&priv->lock, flags);
596 ret = iwl_grab_nic_access(priv);
597 if (ret) {
598 spin_unlock_irqrestore(&priv->lock, flags);
599 return ret;
600 }
601
602 /* Circular buffer (TFD queue in DRAM) physical base address */
603 iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
604 txq->q.dma_addr >> 8);
605
606 iwl_release_nic_access(priv);
607 spin_unlock_irqrestore(&priv->lock, flags);
608
609 return 0;
610}
611
612
Zhu Yib481de92007-09-25 17:54:57 -0700613/******************************************************************************
614 *
Zhu Yib481de92007-09-25 17:54:57 -0700615 * Misc. internal state and helper functions
616 *
617 ******************************************************************************/
Zhu Yib481de92007-09-25 17:54:57 -0700618
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700619static void iwl_ht_conf(struct iwl_priv *priv,
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700620 struct ieee80211_bss_conf *bss_conf)
621{
Johannes Bergae5eb022008-10-14 16:58:37 +0200622 struct ieee80211_sta_ht_cap *ht_conf;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700623 struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
Johannes Bergae5eb022008-10-14 16:58:37 +0200624 struct ieee80211_sta *sta;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700625
626 IWL_DEBUG_MAC80211("enter: \n");
627
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700628 if (!iwl_conf->is_ht)
629 return;
630
Johannes Bergae5eb022008-10-14 16:58:37 +0200631
632 /*
633 * It is totally wrong to base global information on something
634 * that is valid only when associated, alas, this driver works
635 * that way and I don't know how to fix it.
636 */
637
638 rcu_read_lock();
639 sta = ieee80211_find_sta(priv->hw, priv->bssid);
640 if (!sta) {
641 rcu_read_unlock();
642 return;
643 }
644 ht_conf = &sta->ht_cap;
645
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700646 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
Emmanuel Grumbacha9841012008-05-15 13:54:08 +0800647 iwl_conf->sgf |= HT_SHORT_GI_20MHZ;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700648 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
Emmanuel Grumbacha9841012008-05-15 13:54:08 +0800649 iwl_conf->sgf |= HT_SHORT_GI_40MHZ;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700650
651 iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
652 iwl_conf->max_amsdu_size =
653 !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
654
655 iwl_conf->supported_chan_width =
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200656 !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40);
Johannes Bergae5eb022008-10-14 16:58:37 +0200657
Sujith094d05d2008-12-12 11:57:43 +0530658 /*
659 * XXX: The HT configuration needs to be moved into iwl_mac_config()
660 * to be done there correctly.
661 */
662
663 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
Luis R. Rodriguezde27e642008-12-23 15:58:44 -0800664 if (conf_is_ht40_minus(&priv->hw->conf))
Sujith094d05d2008-12-12 11:57:43 +0530665 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
Luis R. Rodriguezde27e642008-12-23 15:58:44 -0800666 else if (conf_is_ht40_plus(&priv->hw->conf))
Sujith094d05d2008-12-12 11:57:43 +0530667 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
668
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700669 /* If no above or below channel supplied disable FAT channel */
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200670 if (iwl_conf->extension_chan_offset != IEEE80211_HT_PARAM_CHA_SEC_ABOVE &&
Sujith094d05d2008-12-12 11:57:43 +0530671 iwl_conf->extension_chan_offset != IEEE80211_HT_PARAM_CHA_SEC_BELOW)
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700672 iwl_conf->supported_chan_width = 0;
673
Ron Rindjunsky12837be2008-09-03 11:26:47 +0800674 iwl_conf->sm_ps = (u8)((ht_conf->cap & IEEE80211_HT_CAP_SM_PS) >> 2);
675
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200676 memcpy(&iwl_conf->mcs, &ht_conf->mcs, 16);
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700677
Sujith094d05d2008-12-12 11:57:43 +0530678 iwl_conf->tx_chan_width = iwl_conf->supported_chan_width != 0;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700679 iwl_conf->ht_protection =
Johannes Bergae5eb022008-10-14 16:58:37 +0200680 bss_conf->ht.operation_mode & IEEE80211_HT_OP_MODE_PROTECTION;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700681 iwl_conf->non_GF_STA_present =
Johannes Bergae5eb022008-10-14 16:58:37 +0200682 !!(bss_conf->ht.operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700683
Johannes Bergae5eb022008-10-14 16:58:37 +0200684 rcu_read_unlock();
685
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700686 IWL_DEBUG_MAC80211("leave\n");
687}
688
Zhu Yib481de92007-09-25 17:54:57 -0700689/*
690 * QoS support
691*/
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +0800692static void iwl_activate_qos(struct iwl_priv *priv, u8 force)
Zhu Yib481de92007-09-25 17:54:57 -0700693{
Zhu Yib481de92007-09-25 17:54:57 -0700694 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
695 return;
696
Zhu Yib481de92007-09-25 17:54:57 -0700697 priv->qos_data.def_qos_parm.qos_flags = 0;
698
699 if (priv->qos_data.qos_cap.q_AP.queue_request &&
700 !priv->qos_data.qos_cap.q_AP.txop_request)
701 priv->qos_data.def_qos_parm.qos_flags |=
702 QOS_PARAM_FLG_TXOP_TYPE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700703 if (priv->qos_data.qos_active)
704 priv->qos_data.def_qos_parm.qos_flags |=
705 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
706
Ron Rindjunskyfd105e72007-11-26 16:14:39 +0200707 if (priv->current_ht_config.is_ht)
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800708 priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800709
Tomas Winkler3109ece2008-03-28 16:33:35 -0700710 if (force || iwl_is_associated(priv)) {
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800711 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
712 priv->qos_data.qos_active,
713 priv->qos_data.def_qos_parm.qos_flags);
Zhu Yib481de92007-09-25 17:54:57 -0700714
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +0800715 iwl_send_cmd_pdu_async(priv, REPLY_QOS_PARAM,
716 sizeof(struct iwl_qosparam_cmd),
717 &priv->qos_data.def_qos_parm, NULL);
Zhu Yib481de92007-09-25 17:54:57 -0700718 }
719}
720
Zhu Yib481de92007-09-25 17:54:57 -0700721#define MAX_UCODE_BEACON_INTERVAL 4096
Zhu Yib481de92007-09-25 17:54:57 -0700722
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800723static u16 iwl_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -0700724{
725 u16 new_val = 0;
726 u16 beacon_factor = 0;
727
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800728 beacon_factor = (beacon_val + MAX_UCODE_BEACON_INTERVAL)
729 / MAX_UCODE_BEACON_INTERVAL;
Zhu Yib481de92007-09-25 17:54:57 -0700730 new_val = beacon_val / beacon_factor;
731
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800732 return new_val;
Zhu Yib481de92007-09-25 17:54:57 -0700733}
734
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800735static void iwl_setup_rxon_timing(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700736{
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800737 u64 tsf;
738 s32 interval_tm, rem;
Zhu Yib481de92007-09-25 17:54:57 -0700739 unsigned long flags;
740 struct ieee80211_conf *conf = NULL;
741 u16 beacon_int = 0;
742
743 conf = ieee80211_get_hw_conf(priv->hw);
744
745 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800746 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
Tomas Winklerb5d7be52008-07-19 04:41:24 +0300747 priv->rxon_timing.listen_interval = cpu_to_le16(conf->listen_interval);
Zhu Yib481de92007-09-25 17:54:57 -0700748
Johannes Berg05c914f2008-09-11 00:01:58 +0200749 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800750 beacon_int = iwl_adjust_beacon_interval(priv->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -0700751 priv->rxon_timing.atim_window = 0;
752 } else {
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800753 beacon_int = iwl_adjust_beacon_interval(conf->beacon_int);
754
Zhu Yib481de92007-09-25 17:54:57 -0700755 /* TODO: we need to get atim_window from upper stack
756 * for now we set to 0 */
757 priv->rxon_timing.atim_window = 0;
758 }
759
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800760 priv->rxon_timing.beacon_interval = cpu_to_le16(beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -0700761
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800762 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
763 interval_tm = beacon_int * 1024;
764 rem = do_div(tsf, interval_tm);
765 priv->rxon_timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
766
767 spin_unlock_irqrestore(&priv->lock, flags);
768 IWL_DEBUG_ASSOC("beacon interval %d beacon timer %d beacon tim %d\n",
769 le16_to_cpu(priv->rxon_timing.beacon_interval),
770 le32_to_cpu(priv->rxon_timing.beacon_init_val),
771 le16_to_cpu(priv->rxon_timing.atim_window));
Zhu Yib481de92007-09-25 17:54:57 -0700772}
773
Tomas Winkler82a66bb2008-05-29 16:35:28 +0800774static void iwl_set_flags_for_band(struct iwl_priv *priv,
775 enum ieee80211_band band)
Zhu Yib481de92007-09-25 17:54:57 -0700776{
Johannes Berg8318d782008-01-24 19:38:38 +0100777 if (band == IEEE80211_BAND_5GHZ) {
Zhu Yib481de92007-09-25 17:54:57 -0700778 priv->staging_rxon.flags &=
779 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
780 | RXON_FLG_CCK_MSK);
781 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
782 } else {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700783 /* Copied from iwl_post_associate() */
Zhu Yib481de92007-09-25 17:54:57 -0700784 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
785 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
786 else
787 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
788
Johannes Berg05c914f2008-09-11 00:01:58 +0200789 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -0700790 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
791
792 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
793 priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
794 priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
795 }
796}
797
798/*
Ian Schram01ebd062007-10-25 17:15:22 +0800799 * initialize rxon structure with default values from eeprom
Zhu Yib481de92007-09-25 17:54:57 -0700800 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700801static void iwl_connection_init_rx_config(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700802{
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700803 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -0700804
805 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
806
Zhu, Yi60294de2008-10-29 14:05:45 -0700807 switch (mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200808 case NL80211_IFTYPE_AP:
Zhu Yib481de92007-09-25 17:54:57 -0700809 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
810 break;
811
Johannes Berg05c914f2008-09-11 00:01:58 +0200812 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -0700813 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
814 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
815 break;
816
Johannes Berg05c914f2008-09-11 00:01:58 +0200817 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -0700818 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
819 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
820 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
821 RXON_FILTER_ACCEPT_GRP_MSK;
822 break;
823
Johannes Berg05c914f2008-09-11 00:01:58 +0200824 case NL80211_IFTYPE_MONITOR:
Zhu Yib481de92007-09-25 17:54:57 -0700825 priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
826 priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
827 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
828 break;
Tomas Winkler69dc5d92008-03-25 16:33:41 -0700829 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +0800830 IWL_ERR(priv, "Unsupported interface type %d\n", mode);
Tomas Winkler69dc5d92008-03-25 16:33:41 -0700831 break;
Zhu Yib481de92007-09-25 17:54:57 -0700832 }
833
834#if 0
835 /* TODO: Figure out when short_preamble would be set and cache from
836 * that */
837 if (!hw_to_local(priv->hw)->short_preamble)
838 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
839 else
840 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
841#endif
842
Assaf Krauss8622e702008-03-21 13:53:43 -0700843 ch_info = iwl_get_channel_info(priv, priv->band,
Rick Farrington25b3f572008-06-30 17:23:28 +0800844 le16_to_cpu(priv->active_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700845
846 if (!ch_info)
847 ch_info = &priv->channel_info[0];
848
849 /*
850 * in some case A channels are all non IBSS
851 * in this case force B/G channel
852 */
Johannes Berg05c914f2008-09-11 00:01:58 +0200853 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
Zhu Yib481de92007-09-25 17:54:57 -0700854 !(is_channel_ibss(ch_info)))
855 ch_info = &priv->channel_info[0];
856
857 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
Johannes Berg8318d782008-01-24 19:38:38 +0100858 priv->band = ch_info->band;
Zhu Yib481de92007-09-25 17:54:57 -0700859
Tomas Winkler82a66bb2008-05-29 16:35:28 +0800860 iwl_set_flags_for_band(priv, priv->band);
Zhu Yib481de92007-09-25 17:54:57 -0700861
862 priv->staging_rxon.ofdm_basic_rates =
863 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
864 priv->staging_rxon.cck_basic_rates =
865 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
866
867 priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
868 RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
869 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
870 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
871 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
872 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -0700873 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700874}
875
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700876static int iwl_set_mode(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700877{
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700878 iwl_connection_init_rx_config(priv, mode);
Zhu Yib481de92007-09-25 17:54:57 -0700879 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
880
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +0800881 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700882
Mohamed Abbasfde35712007-11-29 11:10:15 +0800883 /* dont commit rxon if rf-kill is on*/
Tomas Winklerfee12472008-04-03 16:05:21 -0700884 if (!iwl_is_ready_rf(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +0800885 return -EAGAIN;
886
887 cancel_delayed_work(&priv->scan_check);
Tomas Winkler2a421b92008-06-12 09:47:10 +0800888 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800889 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +0800890 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
891 return -EAGAIN;
892 }
893
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700894 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700895
896 return 0;
897}
898
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700899static void iwl_set_rate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700900{
Johannes Berg8318d782008-01-24 19:38:38 +0100901 const struct ieee80211_supported_band *hw = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700902 struct ieee80211_rate *rate;
903 int i;
904
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700905 hw = iwl_get_hw_mode(priv, priv->band);
Saleem Abdulrasoolc4ba9622007-11-18 23:59:08 -0800906 if (!hw) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800907 IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
Saleem Abdulrasoolc4ba9622007-11-18 23:59:08 -0800908 return;
909 }
Zhu Yib481de92007-09-25 17:54:57 -0700910
911 priv->active_rate = 0;
912 priv->active_rate_basic = 0;
913
Johannes Berg8318d782008-01-24 19:38:38 +0100914 for (i = 0; i < hw->n_bitrates; i++) {
915 rate = &(hw->bitrates[i]);
916 if (rate->hw_value < IWL_RATE_COUNT)
917 priv->active_rate |= (1 << rate->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -0700918 }
919
920 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
921 priv->active_rate, priv->active_rate_basic);
922
923 /*
924 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
925 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
926 * OFDM
927 */
928 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
929 priv->staging_rxon.cck_basic_rates =
930 ((priv->active_rate_basic &
931 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
932 else
933 priv->staging_rxon.cck_basic_rates =
934 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
935
936 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
937 priv->staging_rxon.ofdm_basic_rates =
938 ((priv->active_rate_basic &
939 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
940 IWL_FIRST_OFDM_RATE) & 0xFF;
941 else
942 priv->staging_rxon.ofdm_basic_rates =
943 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
944}
945
Zhu Yib481de92007-09-25 17:54:57 -0700946
Zhu Yib481de92007-09-25 17:54:57 -0700947/******************************************************************************
948 *
949 * Generic RX handler implementations
950 *
951 ******************************************************************************/
Tomas Winkler885ba202008-05-29 16:34:55 +0800952static void iwl_rx_reply_alive(struct iwl_priv *priv,
953 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700954{
Tomas Winklerdb11d632008-05-05 10:22:33 +0800955 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Tomas Winkler885ba202008-05-29 16:34:55 +0800956 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -0700957 struct delayed_work *pwork;
958
959 palive = &pkt->u.alive_frame;
960
961 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
962 "0x%01X 0x%01X\n",
963 palive->is_valid, palive->ver_type,
964 palive->ver_subtype);
965
966 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
967 IWL_DEBUG_INFO("Initialization Alive received.\n");
968 memcpy(&priv->card_alive_init,
969 &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +0800970 sizeof(struct iwl_init_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700971 pwork = &priv->init_alive_start;
972 } else {
973 IWL_DEBUG_INFO("Runtime Alive received.\n");
974 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +0800975 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700976 pwork = &priv->alive_start;
977 }
978
979 /* We delay the ALIVE response by 5ms to
980 * give the HW RF Kill time to activate... */
981 if (palive->is_valid == UCODE_VALID_OK)
982 queue_delayed_work(priv->workqueue, pwork,
983 msecs_to_jiffies(5));
984 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800985 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700986}
987
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700988static void iwl_rx_reply_error(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +0800989 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700990{
Tomas Winklerdb11d632008-05-05 10:22:33 +0800991 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700992
Winkler, Tomas15b16872008-12-19 10:37:33 +0800993 IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
Zhu Yib481de92007-09-25 17:54:57 -0700994 "seq 0x%04X ser 0x%08X\n",
995 le32_to_cpu(pkt->u.err_resp.error_type),
996 get_cmd_string(pkt->u.err_resp.cmd_id),
997 pkt->u.err_resp.cmd_id,
998 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
999 le32_to_cpu(pkt->u.err_resp.error_info));
1000}
1001
1002#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1003
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001004static void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001005{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001006 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001007 struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
Tomas Winkler2aa6ab82008-12-11 10:33:40 -08001008 struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001009 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
1010 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
1011 rxon->channel = csa->channel;
1012 priv->staging_rxon.channel = csa->channel;
1013}
1014
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001015static void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001016 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001017{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001018#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklerdb11d632008-05-05 10:22:33 +08001019 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Tomas Winkler2aa6ab82008-12-11 10:33:40 -08001020 struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001021 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
1022 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
1023#endif
1024}
1025
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001026static void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001027 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001028{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001029 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001030 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
1031 "notification for %s:\n",
1032 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
Ester Kummerbf403db2008-05-05 10:22:40 +08001033 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
Zhu Yib481de92007-09-25 17:54:57 -07001034}
1035
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001036static void iwl_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07001037{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001038 struct iwl_priv *priv =
1039 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07001040 struct sk_buff *beacon;
1041
1042 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02001043 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07001044
1045 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001046 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07001047 return;
1048 }
1049
1050 mutex_lock(&priv->mutex);
1051 /* new beacon skb is allocated every time; dispose previous.*/
1052 if (priv->ibss_beacon)
1053 dev_kfree_skb(priv->ibss_beacon);
1054
1055 priv->ibss_beacon = beacon;
1056 mutex_unlock(&priv->mutex);
1057
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001058 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001059}
1060
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001061/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001062 * iwl_bg_statistics_periodic - Timer callback to queue statistics
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001063 *
1064 * This callback is provided in order to send a statistics request.
1065 *
1066 * This timer function is continually reset to execute within
1067 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
1068 * was received. We need to ensure we receive the statistics in order
1069 * to update the temperature used for calibrating the TXPOWER.
1070 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001071static void iwl_bg_statistics_periodic(unsigned long data)
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001072{
1073 struct iwl_priv *priv = (struct iwl_priv *)data;
1074
1075 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1076 return;
1077
Mohamed Abbas61780ee2008-10-29 14:05:49 -07001078 /* dont send host command if rf-kill is on */
1079 if (!iwl_is_ready_rf(priv))
1080 return;
1081
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001082 iwl_send_statistics_request(priv, CMD_ASYNC);
1083}
1084
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001085static void iwl_rx_beacon_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001086 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001087{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001088#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklerdb11d632008-05-05 10:22:33 +08001089 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Tomas Winkler2aa6ab82008-12-11 10:33:40 -08001090 struct iwl4965_beacon_notif *beacon =
1091 (struct iwl4965_beacon_notif *)pkt->u.raw;
Tomas Winklere7d326a2008-06-12 09:47:11 +08001092 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -07001093
1094 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
1095 "tsf %d %d rate %d\n",
Tomas Winkler25a65722008-06-12 09:47:07 +08001096 le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
Zhu Yib481de92007-09-25 17:54:57 -07001097 beacon->beacon_notify_hdr.failure_frame,
1098 le32_to_cpu(beacon->ibss_mgr_status),
1099 le32_to_cpu(beacon->high_tsf),
1100 le32_to_cpu(beacon->low_tsf), rate);
1101#endif
1102
Johannes Berg05c914f2008-09-11 00:01:58 +02001103 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -07001104 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1105 queue_work(priv->workqueue, &priv->beacon_update);
1106}
1107
Zhu Yib481de92007-09-25 17:54:57 -07001108/* Handle notification from uCode that card's power state is changing
1109 * due to software, hardware, or critical temperature RFKILL */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001110static void iwl_rx_card_state_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001111 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001112{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001113 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001114 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1115 unsigned long status = priv->status;
1116
1117 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
1118 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1119 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1120
1121 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
1122 RF_CARD_DISABLED)) {
1123
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001124 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001125 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1126
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001127 if (!iwl_grab_nic_access(priv)) {
1128 iwl_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07001129 priv, HBUS_TARG_MBX_C,
1130 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
1131
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001132 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001133 }
1134
1135 if (!(flags & RXON_CARD_DISABLED)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001136 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07001137 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001138 if (!iwl_grab_nic_access(priv)) {
1139 iwl_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07001140 priv, HBUS_TARG_MBX_C,
1141 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
1142
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001143 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001144 }
1145 }
1146
1147 if (flags & RF_CARD_DISABLED) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001148 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001149 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001150 iwl_read32(priv, CSR_UCODE_DRV_GP1);
1151 if (!iwl_grab_nic_access(priv))
1152 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001153 }
1154 }
1155
1156 if (flags & HW_CARD_DISABLED)
1157 set_bit(STATUS_RF_KILL_HW, &priv->status);
1158 else
1159 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1160
1161
1162 if (flags & SW_CARD_DISABLED)
1163 set_bit(STATUS_RF_KILL_SW, &priv->status);
1164 else
1165 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1166
1167 if (!(flags & RXON_CARD_DISABLED))
Tomas Winkler2a421b92008-06-12 09:47:10 +08001168 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001169
1170 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1171 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1172 (test_bit(STATUS_RF_KILL_SW, &status) !=
1173 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1174 queue_work(priv->workqueue, &priv->rf_kill);
1175 else
1176 wake_up_interruptible(&priv->wait_command_queue);
1177}
1178
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001179int iwl_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
Tomas Winklere2e3c572008-07-18 13:53:04 +08001180{
1181 int ret;
1182 unsigned long flags;
1183
1184 spin_lock_irqsave(&priv->lock, flags);
1185 ret = iwl_grab_nic_access(priv);
1186 if (ret)
1187 goto err;
1188
1189 if (src == IWL_PWR_SRC_VAUX) {
1190 u32 val;
Tomas Winklere7b63582008-09-03 11:26:49 +08001191 ret = pci_read_config_dword(priv->pci_dev, PCI_CFG_POWER_SOURCE,
Tomas Winklere2e3c572008-07-18 13:53:04 +08001192 &val);
1193
1194 if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT)
1195 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
1196 APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
1197 ~APMG_PS_CTRL_MSK_PWR_SRC);
1198 } else {
1199 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
1200 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
1201 ~APMG_PS_CTRL_MSK_PWR_SRC);
1202 }
1203
1204 iwl_release_nic_access(priv);
1205err:
1206 spin_unlock_irqrestore(&priv->lock, flags);
1207 return ret;
1208}
1209
Zhu Yib481de92007-09-25 17:54:57 -07001210/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001211 * iwl_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07001212 *
1213 * Setup the RX handlers for each of the reply types sent from the uCode
1214 * to the host.
1215 *
1216 * This function chains into the hardware specific files for them to setup
1217 * any hardware specific handlers as well.
1218 */
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08001219static void iwl_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001220{
Tomas Winkler885ba202008-05-29 16:34:55 +08001221 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001222 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
1223 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001224 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001225 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001226 iwl_rx_pm_debug_statistics_notif;
1227 priv->rx_handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001228
Ben Cahill9fbab512007-11-29 11:09:47 +08001229 /*
1230 * The same handler is used for both the REPLY to a discrete
1231 * statistics request from the host as well as for the periodic
1232 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07001233 */
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08001234 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_rx_statistics;
1235 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
Tomas Winkler2a421b92008-06-12 09:47:10 +08001236
Tomas Winkler21c339b2008-11-07 09:58:41 -08001237 iwl_setup_spectrum_handlers(priv);
Tomas Winkler2a421b92008-06-12 09:47:10 +08001238 iwl_setup_rx_scan_handlers(priv);
1239
Ron Rindjunsky37a44212008-05-29 16:35:18 +08001240 /* status change handler */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001241 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001242
Tomas Winklerc1354752008-05-29 16:35:04 +08001243 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
1244 iwl_rx_missed_beacon_notif;
Ron Rindjunsky37a44212008-05-29 16:35:18 +08001245 /* Rx handlers */
Emmanuel Grumbach1781a072008-06-30 17:23:09 +08001246 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl_rx_reply_rx_phy;
1247 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl_rx_reply_rx;
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08001248 /* block ack */
1249 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl_rx_reply_compressed_ba;
Ben Cahill9fbab512007-11-29 11:09:47 +08001250 /* Set up hardware specific Rx handlers */
Emmanuel Grumbachd4789ef2008-04-24 11:55:20 -07001251 priv->cfg->ops->lib->rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001252}
1253
Zhu Yib481de92007-09-25 17:54:57 -07001254/**
Tomas Winklera55360e2008-05-05 10:22:28 +08001255 * iwl_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001256 *
1257 * Uses the priv->rx_handlers callback function array to invoke
1258 * the appropriate handlers, including command responses,
1259 * frame-received notifications, and other notifications.
1260 */
Tomas Winklera55360e2008-05-05 10:22:28 +08001261void iwl_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001262{
Tomas Winklera55360e2008-05-05 10:22:28 +08001263 struct iwl_rx_mem_buffer *rxb;
Tomas Winklerdb11d632008-05-05 10:22:33 +08001264 struct iwl_rx_packet *pkt;
Tomas Winklera55360e2008-05-05 10:22:28 +08001265 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001266 u32 r, i;
1267 int reclaim;
1268 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001269 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001270 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07001271
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001272 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1273 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8d864222008-11-07 09:58:39 -08001274 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07001275 i = rxq->read;
1276
1277 /* Rx interrupt, but nothing sent from uCode */
1278 if (i == r)
Ester Kummerf3d67992008-05-06 11:05:12 +08001279 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001280
Tomas Winklera55360e2008-05-05 10:22:28 +08001281 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001282 fill_rx = 1;
1283
Zhu Yib481de92007-09-25 17:54:57 -07001284 while (i != r) {
1285 rxb = rxq->queue[i];
1286
Ben Cahill9fbab512007-11-29 11:09:47 +08001287 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001288 * then a bug has been introduced in the queue refilling
1289 * routines -- catch it here */
1290 BUG_ON(rxb == NULL);
1291
1292 rxq->queue[i] = NULL;
1293
Johannes Berge91af0a2008-11-19 01:22:51 +01001294 dma_sync_single_range_for_cpu(
1295 &priv->pci_dev->dev, rxb->real_dma_addr,
1296 rxb->aligned_dma_addr - rxb->real_dma_addr,
1297 priv->hw_params.rx_buf_size,
1298 PCI_DMA_FROMDEVICE);
Tomas Winklerdb11d632008-05-05 10:22:33 +08001299 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001300
1301 /* Reclaim a command buffer only if this packet is a response
1302 * to a (driver-originated) command.
1303 * If the packet (e.g. Rx frame) originated from uCode,
1304 * there is no command buffer to reclaim.
1305 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1306 * but apparently a few don't get set; catch them here. */
1307 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1308 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
Tomas Winkler857485c2008-03-21 13:53:44 -07001309 (pkt->hdr.cmd != REPLY_RX) &&
Daniel Halperin7dddaf12008-10-23 23:48:58 -07001310 (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) &&
Zhu Yicfe01702007-09-27 11:27:31 +08001311 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
Zhu Yib481de92007-09-25 17:54:57 -07001312 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1313 (pkt->hdr.cmd != REPLY_TX);
1314
1315 /* Based on type of command response or notification,
1316 * handle those that need handling via function in
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001317 * rx_handlers table. See iwl_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001318 if (priv->rx_handlers[pkt->hdr.cmd]) {
Ester Kummerf3d67992008-05-06 11:05:12 +08001319 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r,
1320 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001321 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1322 } else {
1323 /* No handling needed */
Ester Kummerf3d67992008-05-06 11:05:12 +08001324 IWL_DEBUG(IWL_DL_RX,
Zhu Yib481de92007-09-25 17:54:57 -07001325 "r %d i %d No handler needed for %s, 0x%02x\n",
1326 r, i, get_cmd_string(pkt->hdr.cmd),
1327 pkt->hdr.cmd);
1328 }
1329
1330 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001331 /* Invoke any callbacks, transfer the skb to caller, and
Tomas Winkler857485c2008-03-21 13:53:44 -07001332 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001333 * as we reclaim the driver command queue */
1334 if (rxb && rxb->skb)
Tomas Winkler17b88922008-05-29 16:35:12 +08001335 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001336 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001337 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07001338 }
1339
1340 /* For now we just don't re-use anything. We can tweak this
1341 * later to try and re-use notification packets and SKBs that
1342 * fail to Rx correctly */
1343 if (rxb->skb != NULL) {
1344 priv->alloc_rxb_skb--;
1345 dev_kfree_skb_any(rxb->skb);
1346 rxb->skb = NULL;
1347 }
1348
Johannes Berg40185172008-11-18 01:47:21 +01001349 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
1350 priv->hw_params.rx_buf_size + 256,
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02001351 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001352 spin_lock_irqsave(&rxq->lock, flags);
1353 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1354 spin_unlock_irqrestore(&rxq->lock, flags);
1355 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001356 /* If there are a lot of unused frames,
1357 * restock the Rx queue so ucode wont assert. */
1358 if (fill_rx) {
1359 count++;
1360 if (count >= 8) {
1361 priv->rxq.read = i;
Zhu Yif1bc4ac2008-12-17 16:52:33 +08001362 iwl_rx_queue_restock(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001363 count = 0;
1364 }
1365 }
Zhu Yib481de92007-09-25 17:54:57 -07001366 }
1367
1368 /* Backtrack one entry */
1369 priv->rxq.read = i;
Tomas Winklera55360e2008-05-05 10:22:28 +08001370 iwl_rx_queue_restock(priv);
1371}
Tomas Winklera55360e2008-05-05 10:22:28 +08001372
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001373#ifdef CONFIG_IWLWIFI_DEBUG
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001374static void iwl_print_rx_config_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001375{
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001376 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
Joe Perches0795af52007-10-03 17:59:30 -07001377
Zhu Yib481de92007-09-25 17:54:57 -07001378 IWL_DEBUG_RADIO("RX CONFIG:\n");
Ester Kummerbf403db2008-05-05 10:22:40 +08001379 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
Zhu Yib481de92007-09-25 17:54:57 -07001380 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
1381 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
1382 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
1383 le32_to_cpu(rxon->filter_flags));
1384 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
1385 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
1386 rxon->ofdm_basic_rates);
1387 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
Johannes Berge1749612008-10-27 15:59:26 -07001388 IWL_DEBUG_RADIO("u8[6] node_addr: %pM\n", rxon->node_addr);
1389 IWL_DEBUG_RADIO("u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07001390 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
1391}
1392#endif
1393
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001394/* call this function to flush any scheduled tasklet */
1395static inline void iwl_synchronize_irq(struct iwl_priv *priv)
1396{
Tomas Winklera96a27f2008-10-23 23:48:56 -07001397 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001398 synchronize_irq(priv->pci_dev->irq);
1399 tasklet_kill(&priv->irq_tasklet);
1400}
1401
Zhu Yib481de92007-09-25 17:54:57 -07001402/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001403 * iwl_irq_handle_error - called for HW or SW error interrupt from card
Zhu Yib481de92007-09-25 17:54:57 -07001404 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001405static void iwl_irq_handle_error(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001406{
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001407 /* Set the FW error flag -- cleared on iwl_down */
Zhu Yib481de92007-09-25 17:54:57 -07001408 set_bit(STATUS_FW_ERROR, &priv->status);
1409
1410 /* Cancel currently queued command. */
1411 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1412
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001413#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001414 if (priv->debug_level & IWL_DL_FW_ERRORS) {
Ester Kummerede0cba2008-05-29 16:34:46 +08001415 iwl_dump_nic_error_log(priv);
Ester Kummer189a2b52008-05-15 13:54:18 +08001416 iwl_dump_nic_event_log(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001417 iwl_print_rx_config_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001418 }
1419#endif
1420
1421 wake_up_interruptible(&priv->wait_command_queue);
1422
1423 /* Keep the restart process from trying to send host
1424 * commands by clearing the INIT status bit */
1425 clear_bit(STATUS_READY, &priv->status);
1426
1427 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Ester Kummerf3d67992008-05-06 11:05:12 +08001428 IWL_DEBUG(IWL_DL_FW_ERRORS,
Zhu Yib481de92007-09-25 17:54:57 -07001429 "Restarting adapter due to uCode error.\n");
1430
Tomas Winkler3109ece2008-03-28 16:33:35 -07001431 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001432 memcpy(&priv->recovery_rxon, &priv->active_rxon,
1433 sizeof(priv->recovery_rxon));
1434 priv->error_recovering = 1;
1435 }
Ester Kummer3a1081e2008-05-06 11:05:14 +08001436 if (priv->cfg->mod_params->restart_fw)
1437 queue_work(priv->workqueue, &priv->restart);
Zhu Yib481de92007-09-25 17:54:57 -07001438 }
1439}
1440
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001441static void iwl_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001442{
1443 unsigned long flags;
1444
1445 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
1446 sizeof(priv->staging_rxon));
1447 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001448 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001449
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08001450 iwl_rxon_add_station(priv, priv->bssid, 1);
Zhu Yib481de92007-09-25 17:54:57 -07001451
1452 spin_lock_irqsave(&priv->lock, flags);
1453 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
1454 priv->error_recovering = 0;
1455 spin_unlock_irqrestore(&priv->lock, flags);
1456}
1457
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001458static void iwl_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001459{
1460 u32 inta, handled = 0;
1461 u32 inta_fh;
1462 unsigned long flags;
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001463#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001464 u32 inta_mask;
1465#endif
1466
1467 spin_lock_irqsave(&priv->lock, flags);
1468
1469 /* Ack/clear/reset pending uCode interrupts.
1470 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1471 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001472 inta = iwl_read32(priv, CSR_INT);
1473 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07001474
1475 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1476 * Any new interrupts that happen after this, either while we're
1477 * in this tasklet, or later, will show up in next ISR/tasklet. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001478 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1479 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001480
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001481#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001482 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001483 /* just for debug */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001484 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07001485 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1486 inta, inta_mask, inta_fh);
1487 }
1488#endif
1489
1490 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1491 * atomic, make sure that inta covers all the interrupts that
1492 * we've discovered, even if FH interrupt came in just after
1493 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001494 if (inta_fh & CSR49_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001495 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001496 if (inta_fh & CSR49_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001497 inta |= CSR_INT_BIT_FH_TX;
1498
1499 /* Now service all interrupt bits discovered above. */
1500 if (inta & CSR_INT_BIT_HW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001501 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001502
1503 /* Tell the device to stop sending interrupts */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001504 iwl_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001505
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001506 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001507
1508 handled |= CSR_INT_BIT_HW_ERR;
1509
1510 spin_unlock_irqrestore(&priv->lock, flags);
1511
1512 return;
1513 }
1514
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001515#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001516 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07001517 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001518 if (inta & CSR_INT_BIT_SCD)
1519 IWL_DEBUG_ISR("Scheduler finished to transmit "
1520 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001521
1522 /* Alive notification via Rx interrupt will do the real work */
1523 if (inta & CSR_INT_BIT_ALIVE)
1524 IWL_DEBUG_ISR("Alive interrupt\n");
1525 }
1526#endif
1527 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001528 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07001529
Ben Cahill9fbab512007-11-29 11:09:47 +08001530 /* HW RF KILL switch toggled */
Zhu Yib481de92007-09-25 17:54:57 -07001531 if (inta & CSR_INT_BIT_RF_KILL) {
1532 int hw_rf_kill = 0;
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001533 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yib481de92007-09-25 17:54:57 -07001534 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
1535 hw_rf_kill = 1;
1536
Ester Kummerf3d67992008-05-06 11:05:12 +08001537 IWL_DEBUG(IWL_DL_RF_KILL, "RF_KILL bit toggled to %s.\n",
Abhijeet Kolekarc3056062008-11-12 13:14:08 -08001538 hw_rf_kill ? "disable radio" : "enable radio");
Zhu Yib481de92007-09-25 17:54:57 -07001539
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +08001540 /* driver only loads ucode once setting the interface up.
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01001541 * the driver allows loading the ucode even if the radio
1542 * is killed. Hence update the killswitch state here. The
1543 * rfkill handler will care about restarting if needed.
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +08001544 */
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01001545 if (!test_bit(STATUS_ALIVE, &priv->status)) {
1546 if (hw_rf_kill)
1547 set_bit(STATUS_RF_KILL_HW, &priv->status);
1548 else
1549 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1550 queue_work(priv->workqueue, &priv->rf_kill);
Mohamed Abbasedb34222008-12-11 10:33:37 -08001551 }
Zhu Yib481de92007-09-25 17:54:57 -07001552
1553 handled |= CSR_INT_BIT_RF_KILL;
1554 }
1555
Ben Cahill9fbab512007-11-29 11:09:47 +08001556 /* Chip got too hot and stopped itself */
Zhu Yib481de92007-09-25 17:54:57 -07001557 if (inta & CSR_INT_BIT_CT_KILL) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001558 IWL_ERR(priv, "Microcode CT kill error detected.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001559 handled |= CSR_INT_BIT_CT_KILL;
1560 }
1561
1562 /* Error detected by uCode */
1563 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001564 IWL_ERR(priv, "Microcode SW error detected. "
1565 " Restarting 0x%X.\n", inta);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001566 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001567 handled |= CSR_INT_BIT_SW_ERR;
1568 }
1569
1570 /* uCode wakes up after power-down sleep */
1571 if (inta & CSR_INT_BIT_WAKEUP) {
1572 IWL_DEBUG_ISR("Wakeup interrupt\n");
Tomas Winklera55360e2008-05-05 10:22:28 +08001573 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Tomas Winklerbabcebf2008-05-15 13:54:00 +08001574 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
1575 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
1576 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
1577 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
1578 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1579 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07001580
1581 handled |= CSR_INT_BIT_WAKEUP;
1582 }
1583
1584 /* All uCode command responses, including Tx command responses,
1585 * Rx "responses" (frame-received notification), and other
1586 * notifications from uCode come through here*/
1587 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Tomas Winklera55360e2008-05-05 10:22:28 +08001588 iwl_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001589 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1590 }
1591
1592 if (inta & CSR_INT_BIT_FH_TX) {
1593 IWL_DEBUG_ISR("Tx interrupt\n");
1594 handled |= CSR_INT_BIT_FH_TX;
Ron Rindjunskydbb983b2008-05-15 13:54:12 +08001595 /* FH finished to write, send event */
1596 priv->ucode_write_complete = 1;
1597 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07001598 }
1599
1600 if (inta & ~handled)
Winkler, Tomas15b16872008-12-19 10:37:33 +08001601 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Zhu Yib481de92007-09-25 17:54:57 -07001602
1603 if (inta & ~CSR_INI_SET_MASK) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001604 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Zhu Yib481de92007-09-25 17:54:57 -07001605 inta & ~CSR_INI_SET_MASK);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001606 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001607 }
1608
1609 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001610 /* only Re-enable if diabled by irq */
1611 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001612 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001613
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001614#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001615 if (priv->debug_level & (IWL_DL_ISR)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001616 inta = iwl_read32(priv, CSR_INT);
1617 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1618 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07001619 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
1620 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
1621 }
1622#endif
1623 spin_unlock_irqrestore(&priv->lock, flags);
1624}
1625
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001626static irqreturn_t iwl_isr(int irq, void *data)
Zhu Yib481de92007-09-25 17:54:57 -07001627{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001628 struct iwl_priv *priv = data;
Zhu Yib481de92007-09-25 17:54:57 -07001629 u32 inta, inta_mask;
1630 u32 inta_fh;
1631 if (!priv)
1632 return IRQ_NONE;
1633
1634 spin_lock(&priv->lock);
1635
1636 /* Disable (but don't clear!) interrupts here to avoid
1637 * back-to-back ISRs and sporadic interrupts from our NIC.
1638 * If we have something to service, the tasklet will re-enable ints.
1639 * If we *don't* have something, we'll re-enable before leaving here. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001640 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
1641 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07001642
1643 /* Discover which interrupts are active/pending */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001644 inta = iwl_read32(priv, CSR_INT);
1645 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07001646
1647 /* Ignore interrupt if there's nothing in NIC to service.
1648 * This may be due to IRQ shared with another device,
1649 * or due to sporadic interrupts thrown from our NIC. */
1650 if (!inta && !inta_fh) {
1651 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
1652 goto none;
1653 }
1654
1655 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
Oliver Neukum66fbb542007-11-15 09:31:10 +08001656 /* Hardware disappeared. It might have already raised
1657 * an interrupt */
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001658 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
Oliver Neukum66fbb542007-11-15 09:31:10 +08001659 goto unplugged;
Zhu Yib481de92007-09-25 17:54:57 -07001660 }
1661
1662 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1663 inta, inta_mask, inta_fh);
1664
Joonwoo Park25c03d82008-01-23 10:15:20 -08001665 inta &= ~CSR_INT_BIT_SCD;
1666
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001667 /* iwl_irq_tasklet() will service interrupts and re-enable them */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001668 if (likely(inta || inta_fh))
1669 tasklet_schedule(&priv->irq_tasklet);
Zhu Yib481de92007-09-25 17:54:57 -07001670
Oliver Neukum66fbb542007-11-15 09:31:10 +08001671 unplugged:
1672 spin_unlock(&priv->lock);
Zhu Yib481de92007-09-25 17:54:57 -07001673 return IRQ_HANDLED;
1674
1675 none:
1676 /* re-enable interrupts here since we don't have anything to service. */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001677 /* only Re-enable if diabled by irq */
1678 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001679 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001680 spin_unlock(&priv->lock);
1681 return IRQ_NONE;
1682}
1683
Zhu Yib481de92007-09-25 17:54:57 -07001684/******************************************************************************
1685 *
1686 * uCode download functions
1687 *
1688 ******************************************************************************/
1689
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001690static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001691{
Tomas Winkler98c92212008-01-14 17:46:20 -08001692 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
1693 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
1694 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1695 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
1696 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1697 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001698}
1699
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001700static void iwl_nic_start(struct iwl_priv *priv)
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08001701{
1702 /* Remove all resets to allow NIC to operate */
1703 iwl_write32(priv, CSR_RESET, 0);
1704}
1705
1706
Zhu Yib481de92007-09-25 17:54:57 -07001707/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001708 * iwl_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07001709 *
1710 * Copy into buffers for card to fetch via bus-mastering
1711 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001712static int iwl_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001713{
Ron Rindjunsky14b3d332008-06-13 15:44:54 +08001714 struct iwl_ucode *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001715 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07001716 const struct firmware *ucode_raw;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001717 const char *name_pre = priv->cfg->fw_name_pre;
1718 const unsigned int api_max = priv->cfg->ucode_api_max;
1719 const unsigned int api_min = priv->cfg->ucode_api_min;
1720 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07001721 u8 *src;
1722 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001723 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07001724
1725 /* Ask kernel firmware_class module to get the boot firmware off disk.
1726 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08001727 for (index = api_max; index >= api_min; index--) {
1728 sprintf(buf, "%s%d%s", name_pre, index, ".ucode");
1729 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
1730 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001731 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001732 buf, ret);
1733 if (ret == -ENOENT)
1734 continue;
1735 else
1736 goto error;
1737 } else {
1738 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08001739 IWL_ERR(priv, "Loaded firmware %s, "
1740 "which is deprecated. "
1741 "Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001742 buf, api_max);
Winkler, Tomas15b16872008-12-19 10:37:33 +08001743
Reinette Chatrea0987a82008-12-02 12:14:06 -08001744 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
1745 buf, ucode_raw->size);
1746 break;
1747 }
Zhu Yib481de92007-09-25 17:54:57 -07001748 }
1749
Reinette Chatrea0987a82008-12-02 12:14:06 -08001750 if (ret < 0)
1751 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07001752
1753 /* Make sure that we got at least our header! */
1754 if (ucode_raw->size < sizeof(*ucode)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001755 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001756 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001757 goto err_release;
1758 }
1759
1760 /* Data from ucode file: header followed by uCode images */
1761 ucode = (void *)ucode_raw->data;
1762
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08001763 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08001764 api_ver = IWL_UCODE_API(priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07001765 inst_size = le32_to_cpu(ucode->inst_size);
1766 data_size = le32_to_cpu(ucode->data_size);
1767 init_size = le32_to_cpu(ucode->init_size);
1768 init_data_size = le32_to_cpu(ucode->init_data_size);
1769 boot_size = le32_to_cpu(ucode->boot_size);
1770
Reinette Chatrea0987a82008-12-02 12:14:06 -08001771 /* api_ver should match the api version forming part of the
1772 * firmware filename ... but we don't check for that and only rely
1773 * on the API version read from firware header from here on forward */
1774
1775 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001776 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08001777 "Driver supports v%u, firmware is v%u.\n",
1778 api_max, api_ver);
1779 priv->ucode_ver = 0;
1780 ret = -EINVAL;
1781 goto err_release;
1782 }
1783 if (api_ver != api_max)
Tomas Winkler978785a2008-12-19 10:37:31 +08001784 IWL_ERR(priv, "Firmware has old API version. Expected v%u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08001785 "got v%u. New firmware can be obtained "
1786 "from http://www.intellinuxwireless.org.\n",
1787 api_max, api_ver);
1788
Tomas Winkler978785a2008-12-19 10:37:31 +08001789 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
1790 IWL_UCODE_MAJOR(priv->ucode_ver),
1791 IWL_UCODE_MINOR(priv->ucode_ver),
1792 IWL_UCODE_API(priv->ucode_ver),
1793 IWL_UCODE_SERIAL(priv->ucode_ver));
Reinette Chatrea0987a82008-12-02 12:14:06 -08001794
1795 IWL_DEBUG_INFO("f/w package hdr ucode version raw = 0x%x\n",
1796 priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07001797 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
1798 inst_size);
1799 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
1800 data_size);
1801 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
1802 init_size);
1803 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
1804 init_data_size);
1805 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
1806 boot_size);
1807
1808 /* Verify size of file vs. image size info in file's header */
1809 if (ucode_raw->size < sizeof(*ucode) +
1810 inst_size + data_size + init_size +
1811 init_data_size + boot_size) {
1812
1813 IWL_DEBUG_INFO("uCode file size %d too small\n",
1814 (int)ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001815 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001816 goto err_release;
1817 }
1818
1819 /* Verify that uCode images will fit in card's SRAM */
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001820 if (inst_size > priv->hw_params.max_inst_size) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08001821 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
1822 inst_size);
1823 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001824 goto err_release;
1825 }
1826
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001827 if (data_size > priv->hw_params.max_data_size) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08001828 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
1829 data_size);
1830 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001831 goto err_release;
1832 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001833 if (init_size > priv->hw_params.max_inst_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001834 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001835 ("uCode init instr len %d too large to fit in\n",
1836 init_size);
1837 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001838 goto err_release;
1839 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001840 if (init_data_size > priv->hw_params.max_data_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001841 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001842 ("uCode init data len %d too large to fit in\n",
1843 init_data_size);
1844 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001845 goto err_release;
1846 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001847 if (boot_size > priv->hw_params.max_bsm_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001848 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001849 ("uCode boot instr len %d too large to fit in\n",
1850 boot_size);
1851 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001852 goto err_release;
1853 }
1854
1855 /* Allocate ucode buffers for card's bus-master loading ... */
1856
1857 /* Runtime instructions and 2 copies of data:
1858 * 1) unmodified from disk
1859 * 2) backup cache for save/restore during power-downs */
1860 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001861 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07001862
1863 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001864 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07001865
1866 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001867 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07001868
1869 /* Initialization instructions and data */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001870 if (init_size && init_data_size) {
1871 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001872 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Zhu Yib481de92007-09-25 17:54:57 -07001873
Tomas Winkler90e759d2007-11-29 11:09:41 +08001874 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001875 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001876
1877 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
1878 goto err_pci_alloc;
1879 }
Zhu Yib481de92007-09-25 17:54:57 -07001880
1881 /* Bootstrap (instructions only, no data) */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001882 if (boot_size) {
1883 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001884 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001885
Tomas Winkler90e759d2007-11-29 11:09:41 +08001886 if (!priv->ucode_boot.v_addr)
1887 goto err_pci_alloc;
1888 }
Zhu Yib481de92007-09-25 17:54:57 -07001889
1890 /* Copy images into buffers for card's bus-master reads ... */
1891
1892 /* Runtime instructions (first block of data in file) */
1893 src = &ucode->data[0];
1894 len = priv->ucode_code.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001895 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001896 memcpy(priv->ucode_code.v_addr, src, len);
1897 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
1898 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
1899
1900 /* Runtime data (2nd block)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001901 * NOTE: Copy into backup buffer will be done in iwl_up() */
Zhu Yib481de92007-09-25 17:54:57 -07001902 src = &ucode->data[inst_size];
1903 len = priv->ucode_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001904 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001905 memcpy(priv->ucode_data.v_addr, src, len);
1906 memcpy(priv->ucode_data_backup.v_addr, src, len);
1907
1908 /* Initialization instructions (3rd block) */
1909 if (init_size) {
1910 src = &ucode->data[inst_size + data_size];
1911 len = priv->ucode_init.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001912 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
1913 len);
Zhu Yib481de92007-09-25 17:54:57 -07001914 memcpy(priv->ucode_init.v_addr, src, len);
1915 }
1916
1917 /* Initialization data (4th block) */
1918 if (init_data_size) {
1919 src = &ucode->data[inst_size + data_size + init_size];
1920 len = priv->ucode_init_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001921 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
1922 len);
Zhu Yib481de92007-09-25 17:54:57 -07001923 memcpy(priv->ucode_init_data.v_addr, src, len);
1924 }
1925
1926 /* Bootstrap instructions (5th block) */
1927 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
1928 len = priv->ucode_boot.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001929 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001930 memcpy(priv->ucode_boot.v_addr, src, len);
1931
1932 /* We have our copies now, allow OS release its copies */
1933 release_firmware(ucode_raw);
1934 return 0;
1935
1936 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08001937 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001938 ret = -ENOMEM;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001939 iwl_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001940
1941 err_release:
1942 release_firmware(ucode_raw);
1943
1944 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08001945 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07001946}
1947
Mohamed Abbasada17512008-11-07 09:58:34 -08001948/* temporary */
1949static int iwl_mac_beacon_update(struct ieee80211_hw *hw,
1950 struct sk_buff *skb);
1951
Zhu Yib481de92007-09-25 17:54:57 -07001952/**
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001953 * iwl_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07001954 * from protocol/runtime uCode (initialization uCode's
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001955 * Alive gets handled by iwl_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07001956 */
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001957static void iwl_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001958{
Tomas Winkler57aab752008-04-14 21:16:03 -07001959 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001960
1961 IWL_DEBUG_INFO("Runtime Alive received.\n");
1962
1963 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
1964 /* We had an error bringing up the hardware, so take it
1965 * all the way back down so we can try again */
1966 IWL_DEBUG_INFO("Alive failed.\n");
1967 goto restart;
1968 }
1969
1970 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
1971 * This is a paranoid check, because we would not have gotten the
1972 * "runtime" alive if code weren't properly loaded. */
Emmanuel Grumbachb0692f22008-04-24 11:55:18 -07001973 if (iwl_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001974 /* Runtime instruction load was bad;
1975 * take it all the way back down so we can try again */
1976 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
1977 goto restart;
1978 }
1979
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08001980 iwl_clear_stations_table(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07001981 ret = priv->cfg->ops->lib->alive_notify(priv);
1982 if (ret) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001983 IWL_WARN(priv,
1984 "Could not complete ALIVE transition [ntf]: %d\n", ret);
Zhu Yib481de92007-09-25 17:54:57 -07001985 goto restart;
1986 }
1987
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001988 /* After the ALIVE response, we can send host commands to the uCode */
Zhu Yib481de92007-09-25 17:54:57 -07001989 set_bit(STATUS_ALIVE, &priv->status);
1990
Tomas Winklerfee12472008-04-03 16:05:21 -07001991 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001992 return;
1993
Johannes Berg36d68252008-05-15 12:55:26 +02001994 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07001995
1996 priv->active_rate = priv->rates_mask;
1997 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
1998
Tomas Winkler3109ece2008-03-28 16:33:35 -07001999 if (iwl_is_associated(priv)) {
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08002000 struct iwl_rxon_cmd *active_rxon =
2001 (struct iwl_rxon_cmd *)&priv->active_rxon;
Zhu Yib481de92007-09-25 17:54:57 -07002002
2003 memcpy(&priv->staging_rxon, &priv->active_rxon,
2004 sizeof(priv->staging_rxon));
2005 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2006 } else {
2007 /* Initialize our rx_config data */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002008 iwl_connection_init_rx_config(priv, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002009 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2010 }
2011
Ben Cahill9fbab512007-11-29 11:09:47 +08002012 /* Configure Bluetooth device coexistence support */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002013 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002014
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002015 iwl_reset_run_time_calib(priv);
2016
Zhu Yib481de92007-09-25 17:54:57 -07002017 /* Configure the adapter for unassociated operation */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002018 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002019
2020 /* At this point, the NIC is initialized and operational */
Emmanuel Grumbach47f4a582008-06-12 09:47:13 +08002021 iwl_rf_kill_ct_config(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08002022
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07002023 iwl_leds_register(priv);
2024
Zhu Yib481de92007-09-25 17:54:57 -07002025 IWL_DEBUG_INFO("ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07002026 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a669262008-01-14 17:46:18 -08002027 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07002028
2029 if (priv->error_recovering)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002030 iwl_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002031
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08002032 iwl_power_update_mode(priv, 1);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002033
Mohamed Abbasada17512008-11-07 09:58:34 -08002034 /* reassociate for ADHOC mode */
2035 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
2036 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
2037 priv->vif);
2038 if (beacon)
2039 iwl_mac_beacon_update(priv->hw, beacon);
2040 }
2041
2042
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002043 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002044 iwl_set_mode(priv, priv->iw_mode);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002045
Zhu Yib481de92007-09-25 17:54:57 -07002046 return;
2047
2048 restart:
2049 queue_work(priv->workqueue, &priv->restart);
2050}
2051
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002052static void iwl_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07002053
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002054static void __iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002055{
2056 unsigned long flags;
2057 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002058
2059 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
2060
Zhu Yib481de92007-09-25 17:54:57 -07002061 if (!exit_pending)
2062 set_bit(STATUS_EXIT_PENDING, &priv->status);
2063
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07002064 iwl_leds_unregister(priv);
2065
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08002066 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002067
2068 /* Unblock any waiting calls */
2069 wake_up_interruptible_all(&priv->wait_command_queue);
2070
Zhu Yib481de92007-09-25 17:54:57 -07002071 /* Wipe out the EXIT_PENDING status bit if we are not actually
2072 * exiting the module */
2073 if (!exit_pending)
2074 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2075
2076 /* stop and reset the on-board processor */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002077 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07002078
2079 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002080 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002081 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002082 spin_unlock_irqrestore(&priv->lock, flags);
2083 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002084
2085 if (priv->mac80211_registered)
2086 ieee80211_stop_queues(priv->hw);
2087
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002088 /* If we have not previously called iwl_init() then
Zhu Yib481de92007-09-25 17:54:57 -07002089 * clear all bits but the RF Kill and SUSPEND bits and return */
Tomas Winklerfee12472008-04-03 16:05:21 -07002090 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002091 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2092 STATUS_RF_KILL_HW |
2093 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2094 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08002095 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2096 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002097 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002098 STATUS_IN_SUSPEND |
2099 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2100 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002101 goto exit;
2102 }
2103
2104 /* ...otherwise clear out all the status bits but the RF Kill and
2105 * SUSPEND bits and continue taking the NIC down. */
2106 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2107 STATUS_RF_KILL_HW |
2108 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2109 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08002110 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2111 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002112 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
2113 STATUS_IN_SUSPEND |
2114 test_bit(STATUS_FW_ERROR, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002115 STATUS_FW_ERROR |
2116 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2117 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002118
2119 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002120 iwl_clear_bit(priv, CSR_GP_CNTRL,
Ben Cahill9fbab512007-11-29 11:09:47 +08002121 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07002122 spin_unlock_irqrestore(&priv->lock, flags);
2123
Tomas Winklerda1bc452008-05-29 16:35:00 +08002124 iwl_txq_ctx_stop(priv);
Tomas Winklerb3bbacb2008-05-29 16:35:01 +08002125 iwl_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002126
2127 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002128 if (!iwl_grab_nic_access(priv)) {
2129 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002130 APMG_CLK_VAL_DMA_CLK_RQT);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002131 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002132 }
2133 spin_unlock_irqrestore(&priv->lock, flags);
2134
2135 udelay(5);
2136
Tomas Winkler7f066102008-05-29 16:34:57 +08002137 /* FIXME: apm_ops.suspend(priv) */
Gregory Greenmand5353112008-09-03 11:18:49 +08002138 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
2139 priv->cfg->ops->lib->apm_ops.stop(priv);
2140 else
2141 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002142 exit:
Tomas Winkler885ba202008-05-29 16:34:55 +08002143 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07002144
2145 if (priv->ibss_beacon)
2146 dev_kfree_skb(priv->ibss_beacon);
2147 priv->ibss_beacon = NULL;
2148
2149 /* clear out any free frames */
Tomas Winklerfcab4232008-05-15 13:54:01 +08002150 iwl_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002151}
2152
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002153static void iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002154{
2155 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002156 __iwl_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002157 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08002158
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002159 iwl_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002160}
2161
2162#define MAX_HW_RESTARTS 5
2163
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002164static int __iwl_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002165{
Tomas Winkler57aab752008-04-14 21:16:03 -07002166 int i;
2167 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002168
2169 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002170 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07002171 return -EIO;
2172 }
2173
Reinette Chatree903fbd2008-01-30 22:05:15 -08002174 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002175 IWL_ERR(priv, "ucode not available for device bringup\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08002176 return -EIO;
2177 }
2178
Zhu Yie655b9f2008-01-24 02:19:38 -08002179 /* If platform's RF_KILL switch is NOT set to KILL */
Tomas Winklerc1842d62008-08-04 16:00:43 +08002180 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
Zhu Yie655b9f2008-01-24 02:19:38 -08002181 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002182 else
Zhu Yie655b9f2008-01-24 02:19:38 -08002183 set_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002184
Tomas Winklerc1842d62008-08-04 16:00:43 +08002185 if (iwl_is_rfkill(priv)) {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002186 iwl_enable_interrupts(priv);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002187 IWL_WARN(priv, "Radio disabled by %s RF Kill switch\n",
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002188 test_bit(STATUS_RF_KILL_HW, &priv->status) ? "HW" : "SW");
Tomas Winklerc1842d62008-08-04 16:00:43 +08002189 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002190 }
2191
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002192 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07002193
Ron Rindjunsky1053d352008-05-05 10:22:43 +08002194 ret = iwl_hw_nic_init(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07002195 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002196 IWL_ERR(priv, "Unable to init nic\n");
Tomas Winkler57aab752008-04-14 21:16:03 -07002197 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002198 }
2199
2200 /* make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002201 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2202 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07002203 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2204
2205 /* clear (again), then enable host interrupts */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002206 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002207 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002208
2209 /* really make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002210 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2211 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07002212
2213 /* Copy original ucode data image from disk into backup cache.
2214 * This will be used to initialize the on-board processor's
2215 * data SRAM for a clean start when the runtime program first loads. */
2216 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a669262008-01-14 17:46:18 -08002217 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07002218
Zhu Yib481de92007-09-25 17:54:57 -07002219 for (i = 0; i < MAX_HW_RESTARTS; i++) {
2220
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08002221 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002222
2223 /* load bootstrap state machine,
2224 * load bootstrap program into processor's memory,
2225 * prepare to load the "initialize" uCode */
Tomas Winkler57aab752008-04-14 21:16:03 -07002226 ret = priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002227
Tomas Winkler57aab752008-04-14 21:16:03 -07002228 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002229 IWL_ERR(priv, "Unable to set up bootstrap uCode: %d\n",
2230 ret);
Zhu Yib481de92007-09-25 17:54:57 -07002231 continue;
2232 }
2233
Emmanuel Grumbachf3d5b452008-06-12 09:47:04 +08002234 /* Clear out the uCode error bit if it is set */
2235 clear_bit(STATUS_FW_ERROR, &priv->status);
2236
Zhu Yib481de92007-09-25 17:54:57 -07002237 /* start card; "initialize" will load runtime ucode */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002238 iwl_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002239
Zhu Yib481de92007-09-25 17:54:57 -07002240 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
2241
2242 return 0;
2243 }
2244
2245 set_bit(STATUS_EXIT_PENDING, &priv->status);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002246 __iwl_down(priv);
Mohamed Abbas64e72c32008-06-12 09:47:03 +08002247 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002248
2249 /* tried to restart and config the device for as long as our
2250 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002251 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07002252 return -EIO;
2253}
2254
2255
2256/*****************************************************************************
2257 *
2258 * Workqueue callbacks
2259 *
2260 *****************************************************************************/
2261
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002262static void iwl_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002263{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002264 struct iwl_priv *priv =
2265 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002266
2267 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2268 return;
2269
2270 mutex_lock(&priv->mutex);
Emmanuel Grumbachf3ccc082008-05-05 10:22:45 +08002271 priv->cfg->ops->lib->init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002272 mutex_unlock(&priv->mutex);
2273}
2274
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002275static void iwl_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002276{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002277 struct iwl_priv *priv =
2278 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002279
2280 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2281 return;
2282
2283 mutex_lock(&priv->mutex);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002284 iwl_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002285 mutex_unlock(&priv->mutex);
2286}
2287
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08002288static void iwl_bg_run_time_calib_work(struct work_struct *work)
2289{
2290 struct iwl_priv *priv = container_of(work, struct iwl_priv,
2291 run_time_calib_work);
2292
2293 mutex_lock(&priv->mutex);
2294
2295 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
2296 test_bit(STATUS_SCANNING, &priv->status)) {
2297 mutex_unlock(&priv->mutex);
2298 return;
2299 }
2300
2301 if (priv->start_calib) {
2302 iwl_chain_noise_calibration(priv, &priv->statistics);
2303
2304 iwl_sensitivity_calibration(priv, &priv->statistics);
2305 }
2306
2307 mutex_unlock(&priv->mutex);
2308 return;
2309}
2310
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002311static void iwl_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002312{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002313 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07002314
2315 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2316 return;
2317
2318 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002319 __iwl_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002320 mutex_unlock(&priv->mutex);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002321 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002322}
2323
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002324static void iwl_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002325{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002326 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07002327
2328 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2329 return;
2330
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002331 iwl_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002332 queue_work(priv->workqueue, &priv->up);
2333}
2334
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002335static void iwl_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002336{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002337 struct iwl_priv *priv =
2338 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07002339
2340 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2341 return;
2342
2343 mutex_lock(&priv->mutex);
Tomas Winklera55360e2008-05-05 10:22:28 +08002344 iwl_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002345 mutex_unlock(&priv->mutex);
2346}
2347
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002348#define IWL_DELAY_NEXT_SCAN (HZ*2)
2349
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002350static void iwl_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002351{
Zhu Yib481de92007-09-25 17:54:57 -07002352 struct ieee80211_conf *conf = NULL;
Tomas Winkler857485c2008-03-21 13:53:44 -07002353 int ret = 0;
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002354 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07002355
Johannes Berg05c914f2008-09-11 00:01:58 +02002356 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002357 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07002358 return;
2359 }
2360
Johannes Berge1749612008-10-27 15:59:26 -07002361 IWL_DEBUG_ASSOC("Associated as %d to: %pM\n",
2362 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07002363
2364
2365 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2366 return;
2367
Zhu Yib481de92007-09-25 17:54:57 -07002368
Reinette Chatre508e32e2008-04-14 21:16:13 -07002369 if (!priv->vif || !priv->is_open)
Mohamed Abbas948c1712007-10-25 17:15:45 +08002370 return;
Reinette Chatre508e32e2008-04-14 21:16:13 -07002371
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08002372 iwl_power_cancel_timeout(priv);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002373 iwl_scan_cancel_timeout(priv, 200);
mabbas052c4b92007-10-25 17:15:43 +08002374
Zhu Yib481de92007-09-25 17:54:57 -07002375 conf = ieee80211_get_hw_conf(priv->hw);
2376
2377 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002378 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002379
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002380 iwl_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002381 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002382 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002383 if (ret)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002384 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07002385 "Attempting to continue.\n");
2386
2387 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
2388
Emmanuel Grumbach42eb7c62008-09-17 10:10:05 +08002389 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03002390
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07002391 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002392 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2393
2394 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
2395 priv->assoc_id, priv->beacon_int);
2396
2397 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2398 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2399 else
2400 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2401
2402 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2403 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2404 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2405 else
2406 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2407
Johannes Berg05c914f2008-09-11 00:01:58 +02002408 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002409 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2410
2411 }
2412
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002413 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002414
2415 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02002416 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -07002417 break;
2418
Johannes Berg05c914f2008-09-11 00:01:58 +02002419 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07002420
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002421 /* assume default assoc id */
2422 priv->assoc_id = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002423
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002424 iwl_rxon_add_station(priv, priv->bssid, 0);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002425 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002426
2427 break;
2428
2429 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002430 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03002431 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002432 break;
2433 }
2434
Johannes Berg05c914f2008-09-11 00:01:58 +02002435 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002436 priv->assoc_station_added = 1;
2437
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002438 spin_lock_irqsave(&priv->lock, flags);
2439 iwl_activate_qos(priv, 0);
2440 spin_unlock_irqrestore(&priv->lock, flags);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08002441
Grumbach, Emmanuel04816442008-09-03 11:26:53 +08002442 /* the chain noise calibration will enabled PM upon completion
2443 * If chain noise has already been run, then we need to enable
2444 * power management here */
2445 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
2446 iwl_power_enable_management(priv);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08002447
2448 /* Enable Rx differential gain and sensitivity calibrations */
2449 iwl_chain_noise_reset(priv);
2450 priv->start_calib = 1;
2451
Reinette Chatre508e32e2008-04-14 21:16:13 -07002452}
2453
Zhu Yib481de92007-09-25 17:54:57 -07002454/*****************************************************************************
2455 *
2456 * mac80211 entry point functions
2457 *
2458 *****************************************************************************/
2459
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002460#define UCODE_READY_TIMEOUT (4 * HZ)
Zhu Yi5a669262008-01-14 17:46:18 -08002461
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002462static int iwl_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002463{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002464 struct iwl_priv *priv = hw->priv;
Zhu Yi5a669262008-01-14 17:46:18 -08002465 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002466
2467 IWL_DEBUG_MAC80211("enter\n");
2468
2469 /* we should be verifying the device is ready to be opened */
2470 mutex_lock(&priv->mutex);
2471
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08002472 memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd));
Zhu Yi5a669262008-01-14 17:46:18 -08002473 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
2474 * ucode filename and max sizes are card-specific. */
2475
2476 if (!priv->ucode_code.len) {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002477 ret = iwl_read_ucode(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08002478 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002479 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a669262008-01-14 17:46:18 -08002480 mutex_unlock(&priv->mutex);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002481 return ret;
Zhu Yi5a669262008-01-14 17:46:18 -08002482 }
2483 }
2484
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002485 ret = __iwl_up(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08002486
Zhu Yib481de92007-09-25 17:54:57 -07002487 mutex_unlock(&priv->mutex);
Zhu Yi5a669262008-01-14 17:46:18 -08002488
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002489 iwl_rfkill_set_hw_state(priv);
2490
Zhu Yie655b9f2008-01-24 02:19:38 -08002491 if (ret)
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002492 return ret;
Zhu Yie655b9f2008-01-24 02:19:38 -08002493
Tomas Winklerc1842d62008-08-04 16:00:43 +08002494 if (iwl_is_rfkill(priv))
2495 goto out;
2496
Zhu Yie655b9f2008-01-24 02:19:38 -08002497 IWL_DEBUG_INFO("Start UP work done.\n");
2498
2499 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
2500 return 0;
2501
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002502 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
Zhu Yi5a669262008-01-14 17:46:18 -08002503 * mac80211 will not be run successfully. */
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002504 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
2505 test_bit(STATUS_READY, &priv->status),
2506 UCODE_READY_TIMEOUT);
2507 if (!ret) {
2508 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002509 IWL_ERR(priv, "START_ALIVE timeout after %dms.\n",
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002510 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002511 return -ETIMEDOUT;
Zhu Yi5a669262008-01-14 17:46:18 -08002512 }
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002513 }
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002514
Tomas Winklerc1842d62008-08-04 16:00:43 +08002515out:
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002516 priv->is_open = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002517 IWL_DEBUG_MAC80211("leave\n");
2518 return 0;
2519}
2520
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002521static void iwl_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002522{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002523 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002524
2525 IWL_DEBUG_MAC80211("enter\n");
Mohamed Abbas948c1712007-10-25 17:15:45 +08002526
Zhu Yie655b9f2008-01-24 02:19:38 -08002527 if (!priv->is_open) {
2528 IWL_DEBUG_MAC80211("leave - skip\n");
2529 return;
2530 }
2531
Zhu Yib481de92007-09-25 17:54:57 -07002532 priv->is_open = 0;
Zhu Yi5a669262008-01-14 17:46:18 -08002533
Tomas Winklerfee12472008-04-03 16:05:21 -07002534 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08002535 /* stop mac, cancel any scan request and clear
2536 * RXON_FILTER_ASSOC_MSK BIT
2537 */
Zhu Yi5a669262008-01-14 17:46:18 -08002538 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002539 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002540 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002541 }
2542
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002543 iwl_down(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08002544
2545 flush_workqueue(priv->workqueue);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002546
2547 /* enable interrupts again in order to receive rfkill changes */
2548 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
2549 iwl_enable_interrupts(priv);
Mohamed Abbas948c1712007-10-25 17:15:45 +08002550
Zhu Yib481de92007-09-25 17:54:57 -07002551 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002552}
2553
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002554static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07002555{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002556 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002557
Tomas Winklerf3674222008-08-04 16:00:44 +08002558 IWL_DEBUG_MACDUMP("enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002559
Zhu Yib481de92007-09-25 17:54:57 -07002560 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02002561 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07002562
Johannes Berge039fa42008-05-15 12:55:29 +02002563 if (iwl_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07002564 dev_kfree_skb_any(skb);
2565
Tomas Winklerf3674222008-08-04 16:00:44 +08002566 IWL_DEBUG_MACDUMP("leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08002567 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07002568}
2569
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002570static int iwl_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07002571 struct ieee80211_if_init_conf *conf)
2572{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002573 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002574 unsigned long flags;
2575
Johannes Berg32bfd352007-12-19 01:31:26 +01002576 IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07002577
Johannes Berg32bfd352007-12-19 01:31:26 +01002578 if (priv->vif) {
2579 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
Reinette Chatre75849d22008-01-23 10:15:17 -08002580 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07002581 }
2582
2583 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01002584 priv->vif = conf->vif;
Zhu, Yi60294de2008-10-29 14:05:45 -07002585 priv->iw_mode = conf->type;
Zhu Yib481de92007-09-25 17:54:57 -07002586
2587 spin_unlock_irqrestore(&priv->lock, flags);
2588
2589 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02002590
2591 if (conf->mac_addr) {
Johannes Berge1749612008-10-27 15:59:26 -07002592 IWL_DEBUG_MAC80211("Set %pM\n", conf->mac_addr);
Tomas Winkler864792e2007-11-27 21:00:52 +02002593 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
2594 }
Zhu Yib481de92007-09-25 17:54:57 -07002595
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002596 if (iwl_set_mode(priv, conf->type) == -EAGAIN)
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002597 /* we are not ready, will run again when ready */
2598 set_bit(STATUS_MODE_PENDING, &priv->status);
Zhu Yi5a669262008-01-14 17:46:18 -08002599
Zhu Yib481de92007-09-25 17:54:57 -07002600 mutex_unlock(&priv->mutex);
2601
Zhu Yi5a669262008-01-14 17:46:18 -08002602 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002603 return 0;
2604}
2605
2606/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002607 * iwl_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07002608 *
2609 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
2610 * be set inappropriately and the driver currently sets the hardware up to
2611 * use it whenever needed.
2612 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002613static int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
Zhu Yib481de92007-09-25 17:54:57 -07002614{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002615 struct iwl_priv *priv = hw->priv;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07002616 const struct iwl_channel_info *ch_info;
Johannes Berge8975582008-10-09 12:18:51 +02002617 struct ieee80211_conf *conf = &hw->conf;
Zhu Yib481de92007-09-25 17:54:57 -07002618 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08002619 int ret = 0;
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002620 u16 channel;
Zhu Yib481de92007-09-25 17:54:57 -07002621
2622 mutex_lock(&priv->mutex);
Johannes Berg8318d782008-01-24 19:38:38 +01002623 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07002624
Luis R. Rodriguezde27e642008-12-23 15:58:44 -08002625 priv->current_ht_config.is_ht = conf_is_ht(conf);
Johannes Bergae5eb022008-10-14 16:58:37 +02002626
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +08002627 if (conf->radio_enabled && iwl_radio_kill_sw_enable_radio(priv)) {
Mohamed Abbas64e72c32008-06-12 09:47:03 +08002628 IWL_DEBUG_MAC80211("leave - RF-KILL - waiting for uCode\n");
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +08002629 goto out;
Mohamed Abbas64e72c32008-06-12 09:47:03 +08002630 }
2631
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +08002632 if (!conf->radio_enabled)
2633 iwl_radio_kill_sw_disable_radio(priv);
2634
Tomas Winklerfee12472008-04-03 16:05:21 -07002635 if (!iwl_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002636 IWL_DEBUG_MAC80211("leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002637 ret = -EIO;
2638 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002639 }
2640
Assaf Krauss1ea87392008-03-18 14:57:50 -07002641 if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07002642 test_bit(STATUS_SCANNING, &priv->status))) {
Zhu Yia0646472007-12-20 14:10:01 +08002643 IWL_DEBUG_MAC80211("leave - scanning\n");
Zhu Yib481de92007-09-25 17:54:57 -07002644 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08002645 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002646 }
2647
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002648 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2649 ch_info = iwl_get_channel_info(priv, conf->channel->band, channel);
Zhu Yib481de92007-09-25 17:54:57 -07002650 if (!is_channel_valid(ch_info)) {
Zhu Yib481de92007-09-25 17:54:57 -07002651 IWL_DEBUG_MAC80211("leave - invalid channel\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002652 ret = -EINVAL;
2653 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002654 }
2655
Johannes Berg05c914f2008-09-11 00:01:58 +02002656 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Assaf Krauss398f9e72008-06-12 09:47:06 +08002657 !is_channel_ibss(ch_info)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002658 IWL_ERR(priv, "channel %d in band %d not IBSS channel\n",
Assaf Krauss398f9e72008-06-12 09:47:06 +08002659 conf->channel->hw_value, conf->channel->band);
2660 ret = -EINVAL;
2661 goto out;
2662 }
2663
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002664 spin_lock_irqsave(&priv->lock, flags);
2665
Tomas Winklerb5d7be52008-07-19 04:41:24 +03002666
Tomas Winkler78330fd2008-02-06 02:37:18 +02002667 /* if we are switching from ht to 2.4 clear flags
Zhu Yib481de92007-09-25 17:54:57 -07002668 * from any ht related info since 2.4 does not
2669 * support ht */
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002670 if ((le16_to_cpu(priv->staging_rxon.channel) != channel)
Zhu Yib481de92007-09-25 17:54:57 -07002671#ifdef IEEE80211_CONF_CHANNEL_SWITCH
2672 && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
2673#endif
2674 )
2675 priv->staging_rxon.flags = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002676
Tomas Winkler17e72782008-09-03 11:26:26 +08002677 iwl_set_rxon_channel(priv, conf->channel);
Zhu Yib481de92007-09-25 17:54:57 -07002678
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002679 iwl_set_flags_for_band(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07002680
2681 /* The list of supported rates and rate mask can be different
Johannes Berg8318d782008-01-24 19:38:38 +01002682 * for each band; since the band may have changed, reset
Zhu Yib481de92007-09-25 17:54:57 -07002683 * the rate mask to what mac80211 lists */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002684 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002685
2686 spin_unlock_irqrestore(&priv->lock, flags);
2687
2688#ifdef IEEE80211_CONF_CHANNEL_SWITCH
2689 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002690 iwl_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08002691 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002692 }
2693#endif
2694
Zhu Yib481de92007-09-25 17:54:57 -07002695 if (!conf->radio_enabled) {
2696 IWL_DEBUG_MAC80211("leave - radio disabled\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002697 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002698 }
2699
Tomas Winklerfee12472008-04-03 16:05:21 -07002700 if (iwl_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002701 IWL_DEBUG_MAC80211("leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002702 ret = -EIO;
2703 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002704 }
2705
Ester Kummere602cb12008-09-26 15:09:33 +08002706 if (conf->flags & IEEE80211_CONF_PS)
2707 ret = iwl_power_set_user_mode(priv, IWL_POWER_INDEX_3);
2708 else
2709 ret = iwl_power_set_user_mode(priv, IWL_POWER_MODE_CAM);
2710 if (ret)
2711 IWL_DEBUG_MAC80211("Error setting power level\n");
2712
Tomas Winkler630fe9b2008-06-12 09:47:08 +08002713 IWL_DEBUG_MAC80211("TX Power old=%d new=%d\n",
2714 priv->tx_power_user_lmt, conf->power_level);
2715
2716 iwl_set_tx_power(priv, conf->power_level, false);
2717
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002718 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002719
Rick Farrington7b841722009-01-23 13:45:10 -08002720 /* call to ensure that 4965 rx_chain is set properly in monitor mode */
2721 iwl_set_rxon_chain(priv);
2722
Zhu Yib481de92007-09-25 17:54:57 -07002723 if (memcmp(&priv->active_rxon,
2724 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002725 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002726 else
2727 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
2728
2729 IWL_DEBUG_MAC80211("leave\n");
2730
Zhu Yia0646472007-12-20 14:10:01 +08002731out:
Zhu Yi5a669262008-01-14 17:46:18 -08002732 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08002733 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002734}
2735
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002736static void iwl_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002737{
Tomas Winkler857485c2008-03-21 13:53:44 -07002738 int ret = 0;
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002739 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07002740
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08002741 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07002742 return;
2743
2744 /* The following should be done only at AP bring up */
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002745 if (!iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002746
2747 /* RXON - unassoc (to set timing command) */
2748 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002749 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002750
2751 /* RXON Timing */
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002752 iwl_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002753 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002754 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002755 if (ret)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002756 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07002757 "Attempting to continue.\n");
2758
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07002759 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002760
2761 /* FIXME: what should be the assoc_id for AP? */
2762 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2763 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2764 priv->staging_rxon.flags |=
2765 RXON_FLG_SHORT_PREAMBLE_MSK;
2766 else
2767 priv->staging_rxon.flags &=
2768 ~RXON_FLG_SHORT_PREAMBLE_MSK;
2769
2770 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2771 if (priv->assoc_capability &
2772 WLAN_CAPABILITY_SHORT_SLOT_TIME)
2773 priv->staging_rxon.flags |=
2774 RXON_FLG_SHORT_SLOT_MSK;
2775 else
2776 priv->staging_rxon.flags &=
2777 ~RXON_FLG_SHORT_SLOT_MSK;
2778
Johannes Berg05c914f2008-09-11 00:01:58 +02002779 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002780 priv->staging_rxon.flags &=
2781 ~RXON_FLG_SHORT_SLOT_MSK;
2782 }
2783 /* restore RXON assoc */
2784 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002785 iwl_commit_rxon(priv);
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002786 spin_lock_irqsave(&priv->lock, flags);
2787 iwl_activate_qos(priv, 1);
2788 spin_unlock_irqrestore(&priv->lock, flags);
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002789 iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
Zhu Yie1493de2007-09-27 11:27:32 +08002790 }
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002791 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002792
2793 /* FIXME - we need to add code here to detect a totally new
2794 * configuration, reset the AP, unassoc, rxon timing, assoc,
2795 * clear sta table, add BCAST sta... */
2796}
2797
Johannes Berg9d139c82008-07-09 14:40:37 +02002798
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002799static int iwl_mac_config_interface(struct ieee80211_hw *hw,
Johannes Berg32bfd352007-12-19 01:31:26 +01002800 struct ieee80211_vif *vif,
Zhu Yib481de92007-09-25 17:54:57 -07002801 struct ieee80211_if_conf *conf)
2802{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002803 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002804 int rc;
2805
2806 if (conf == NULL)
2807 return -EIO;
2808
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08002809 if (priv->vif != vif) {
2810 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08002811 return 0;
2812 }
2813
Johannes Berg05c914f2008-09-11 00:01:58 +02002814 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Johannes Berg9d139c82008-07-09 14:40:37 +02002815 conf->changed & IEEE80211_IFCC_BEACON) {
2816 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
2817 if (!beacon)
2818 return -ENOMEM;
Mohamed Abbasada17512008-11-07 09:58:34 -08002819 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002820 rc = iwl_mac_beacon_update(hw, beacon);
Mohamed Abbasada17512008-11-07 09:58:34 -08002821 mutex_unlock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02002822 if (rc)
2823 return rc;
2824 }
2825
Tomas Winklerfee12472008-04-03 16:05:21 -07002826 if (!iwl_is_alive(priv))
Zhu Yi5a669262008-01-14 17:46:18 -08002827 return -EAGAIN;
2828
Zhu Yib481de92007-09-25 17:54:57 -07002829 mutex_lock(&priv->mutex);
2830
Zhu Yib481de92007-09-25 17:54:57 -07002831 if (conf->bssid)
Johannes Berge1749612008-10-27 15:59:26 -07002832 IWL_DEBUG_MAC80211("bssid: %pM\n", conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07002833
Johannes Berg4150c572007-09-17 01:29:23 -04002834/*
2835 * very dubious code was here; the probe filtering flag is never set:
2836 *
Zhu Yib481de92007-09-25 17:54:57 -07002837 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
2838 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04002839 */
Zhu Yib481de92007-09-25 17:54:57 -07002840
Johannes Berg05c914f2008-09-11 00:01:58 +02002841 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07002842 if (!conf->bssid) {
2843 conf->bssid = priv->mac_addr;
2844 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -07002845 IWL_DEBUG_MAC80211("bssid was set to: %pM\n",
2846 conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07002847 }
2848 if (priv->ibss_beacon)
2849 dev_kfree_skb(priv->ibss_beacon);
2850
Johannes Berg9d139c82008-07-09 14:40:37 +02002851 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
Zhu Yib481de92007-09-25 17:54:57 -07002852 }
2853
Tomas Winklerfee12472008-04-03 16:05:21 -07002854 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08002855 goto done;
2856
Zhu Yib481de92007-09-25 17:54:57 -07002857 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
2858 !is_multicast_ether_addr(conf->bssid)) {
2859 /* If there is currently a HW scan going on in the background
2860 * then we need to cancel it else the RXON below will fail. */
Tomas Winkler2a421b92008-06-12 09:47:10 +08002861 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002862 IWL_WARN(priv, "Aborted scan still in progress "
Zhu Yib481de92007-09-25 17:54:57 -07002863 "after 100ms\n");
2864 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2865 mutex_unlock(&priv->mutex);
2866 return -EAGAIN;
2867 }
2868 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
2869
2870 /* TODO: Audit driver for usage of these members and see
2871 * if mac80211 deprecates them (priv->bssid looks like it
2872 * shouldn't be there, but I haven't scanned the IBSS code
2873 * to verify) - jpk */
2874 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
2875
Johannes Berg05c914f2008-09-11 00:01:58 +02002876 if (priv->iw_mode == NL80211_IFTYPE_AP)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002877 iwl_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002878 else {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002879 rc = iwl_commit_rxon(priv);
Johannes Berg05c914f2008-09-11 00:01:58 +02002880 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002881 iwl_rxon_add_station(
Zhu Yib481de92007-09-25 17:54:57 -07002882 priv, priv->active_rxon.bssid_addr, 1);
2883 }
2884
2885 } else {
Tomas Winkler2a421b92008-06-12 09:47:10 +08002886 iwl_scan_cancel_timeout(priv, 100);
Zhu Yib481de92007-09-25 17:54:57 -07002887 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002888 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002889 }
2890
Mohamed Abbasfde35712007-11-29 11:10:15 +08002891 done:
Zhu Yib481de92007-09-25 17:54:57 -07002892 IWL_DEBUG_MAC80211("leave\n");
2893 mutex_unlock(&priv->mutex);
2894
2895 return 0;
2896}
2897
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002898static void iwl_configure_filter(struct ieee80211_hw *hw,
Johannes Berg4150c572007-09-17 01:29:23 -04002899 unsigned int changed_flags,
2900 unsigned int *total_flags,
2901 int mc_count, struct dev_addr_list *mc_list)
2902{
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08002903 struct iwl_priv *priv = hw->priv;
Zhu, Yi352bc8d2008-11-12 13:14:09 -08002904 __le32 *filter_flags = &priv->staging_rxon.filter_flags;
Rick Farrington25b3f572008-06-30 17:23:28 +08002905
Zhu, Yi352bc8d2008-11-12 13:14:09 -08002906 IWL_DEBUG_MAC80211("Enter: changed: 0x%x, total: 0x%x\n",
2907 changed_flags, *total_flags);
2908
2909 if (changed_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) {
2910 if (*total_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS))
2911 *filter_flags |= RXON_FILTER_PROMISC_MSK;
2912 else
2913 *filter_flags &= ~RXON_FILTER_PROMISC_MSK;
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08002914 }
Zhu, Yi352bc8d2008-11-12 13:14:09 -08002915 if (changed_flags & FIF_ALLMULTI) {
2916 if (*total_flags & FIF_ALLMULTI)
2917 *filter_flags |= RXON_FILTER_ACCEPT_GRP_MSK;
2918 else
2919 *filter_flags &= ~RXON_FILTER_ACCEPT_GRP_MSK;
2920 }
2921 if (changed_flags & FIF_CONTROL) {
2922 if (*total_flags & FIF_CONTROL)
2923 *filter_flags |= RXON_FILTER_CTL2HOST_MSK;
2924 else
2925 *filter_flags &= ~RXON_FILTER_CTL2HOST_MSK;
2926 }
2927 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
2928 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
2929 *filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
2930 else
2931 *filter_flags &= ~RXON_FILTER_BCON_AWARE_MSK;
2932 }
2933
2934 /* We avoid iwl_commit_rxon here to commit the new filter flags
2935 * since mac80211 will call ieee80211_hw_config immediately.
2936 * (mc_list is not supported at this time). Otherwise, we need to
2937 * queue a background iwl_commit_rxon work.
2938 */
2939
2940 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
Rick Farrington25b3f572008-06-30 17:23:28 +08002941 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
Johannes Berg4150c572007-09-17 01:29:23 -04002942}
2943
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002944static void iwl_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07002945 struct ieee80211_if_init_conf *conf)
2946{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002947 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002948
2949 IWL_DEBUG_MAC80211("enter\n");
2950
2951 mutex_lock(&priv->mutex);
Mohamed Abbas948c1712007-10-25 17:15:45 +08002952
Tomas Winklerfee12472008-04-03 16:05:21 -07002953 if (iwl_is_ready_rf(priv)) {
Tomas Winkler2a421b92008-06-12 09:47:10 +08002954 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002955 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002956 iwl_commit_rxon(priv);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002957 }
Johannes Berg32bfd352007-12-19 01:31:26 +01002958 if (priv->vif == conf->vif) {
2959 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07002960 memset(priv->bssid, 0, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07002961 }
2962 mutex_unlock(&priv->mutex);
2963
2964 IWL_DEBUG_MAC80211("leave\n");
2965
2966}
Johannes Berg471b3ef2007-12-28 14:32:58 +01002967
Tomas Winkler3109ece2008-03-28 16:33:35 -07002968#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002969static void iwl_bss_info_changed(struct ieee80211_hw *hw,
Johannes Berg471b3ef2007-12-28 14:32:58 +01002970 struct ieee80211_vif *vif,
2971 struct ieee80211_bss_conf *bss_conf,
2972 u32 changes)
Tomas Winkler220173b2007-10-16 00:50:25 +02002973{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002974 struct iwl_priv *priv = hw->priv;
Tomas Winkler220173b2007-10-16 00:50:25 +02002975
Tomas Winkler3109ece2008-03-28 16:33:35 -07002976 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
2977
Johannes Berg471b3ef2007-12-28 14:32:58 +01002978 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07002979 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
2980 bss_conf->use_short_preamble);
Johannes Berg471b3ef2007-12-28 14:32:58 +01002981 if (bss_conf->use_short_preamble)
Tomas Winkler220173b2007-10-16 00:50:25 +02002982 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2983 else
2984 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2985 }
2986
Johannes Berg471b3ef2007-12-28 14:32:58 +01002987 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07002988 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
Johannes Berg8318d782008-01-24 19:38:38 +01002989 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Tomas Winkler220173b2007-10-16 00:50:25 +02002990 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
2991 else
2992 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
2993 }
2994
Tomas Winkler98952d52008-03-28 16:33:33 -07002995 if (changes & BSS_CHANGED_HT) {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002996 iwl_ht_conf(priv, bss_conf);
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07002997 iwl_set_rxon_chain(priv);
Tomas Winkler98952d52008-03-28 16:33:33 -07002998 }
2999
Johannes Berg471b3ef2007-12-28 14:32:58 +01003000 if (changes & BSS_CHANGED_ASSOC) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07003001 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
Reinette Chatre508e32e2008-04-14 21:16:13 -07003002 /* This should never happen as this function should
3003 * never be called from interrupt context. */
3004 if (WARN_ON_ONCE(in_interrupt()))
3005 return;
Tomas Winkler3109ece2008-03-28 16:33:35 -07003006 if (bss_conf->assoc) {
3007 priv->assoc_id = bss_conf->aid;
3008 priv->beacon_int = bss_conf->beacon_int;
Tomas Winklerb5d7be52008-07-19 04:41:24 +03003009 priv->power_data.dtim_period = bss_conf->dtim_period;
Tomas Winkler3109ece2008-03-28 16:33:35 -07003010 priv->timestamp = bss_conf->timestamp;
3011 priv->assoc_capability = bss_conf->assoc_capability;
Tomas Winkler9ccacb82008-09-16 14:01:03 +08003012
3013 /* we have just associated, don't start scan too early
3014 * leave time for EAPOL exchange to complete
3015 */
Tomas Winkler3109ece2008-03-28 16:33:35 -07003016 priv->next_scan_jiffies = jiffies +
3017 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
Reinette Chatre508e32e2008-04-14 21:16:13 -07003018 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003019 iwl_post_associate(priv);
Reinette Chatre508e32e2008-04-14 21:16:13 -07003020 mutex_unlock(&priv->mutex);
Tomas Winkler3109ece2008-03-28 16:33:35 -07003021 } else {
3022 priv->assoc_id = 0;
3023 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
3024 }
3025 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
3026 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
Tomas Winkler7e8c5192008-04-15 16:01:43 -07003027 iwl_send_rxon_assoc(priv);
Johannes Berg471b3ef2007-12-28 14:32:58 +01003028 }
3029
Tomas Winkler220173b2007-10-16 00:50:25 +02003030}
Zhu Yib481de92007-09-25 17:54:57 -07003031
Tomas Winklercb43dc22008-09-03 11:26:23 +08003032static int iwl_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t ssid_len)
Zhu Yib481de92007-09-25 17:54:57 -07003033{
Zhu Yib481de92007-09-25 17:54:57 -07003034 unsigned long flags;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003035 struct iwl_priv *priv = hw->priv;
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003036 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003037
3038 IWL_DEBUG_MAC80211("enter\n");
3039
mabbas052c4b92007-10-25 17:15:43 +08003040 mutex_lock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07003041 spin_lock_irqsave(&priv->lock, flags);
3042
Tomas Winklerfee12472008-04-03 16:05:21 -07003043 if (!iwl_is_ready_rf(priv)) {
Tomas Winklercb43dc22008-09-03 11:26:23 +08003044 ret = -EIO;
Zhu Yib481de92007-09-25 17:54:57 -07003045 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
3046 goto out_unlock;
3047 }
3048
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003049 /* We don't schedule scan within next_scan_jiffies period.
3050 * Avoid scanning during possible EAPOL exchange, return
3051 * success immediately.
3052 */
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003053 if (priv->next_scan_jiffies &&
Tomas Winklercb43dc22008-09-03 11:26:23 +08003054 time_after(priv->next_scan_jiffies, jiffies)) {
Ron Rindjunsky681c0052008-09-03 11:26:25 +08003055 IWL_DEBUG_SCAN("scan rejected: within next scan period\n");
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003056 queue_work(priv->workqueue, &priv->scan_completed);
3057 ret = 0;
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003058 goto out_unlock;
3059 }
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003060
Zhu Yib481de92007-09-25 17:54:57 -07003061 /* if we just finished scan ask for delay */
Ron Rindjunsky681c0052008-09-03 11:26:25 +08003062 if (iwl_is_associated(priv) && priv->last_scan_jiffies &&
Tomas Winklercb43dc22008-09-03 11:26:23 +08003063 time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN, jiffies)) {
Ron Rindjunsky681c0052008-09-03 11:26:25 +08003064 IWL_DEBUG_SCAN("scan rejected: within previous scan period\n");
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003065 queue_work(priv->workqueue, &priv->scan_completed);
3066 ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003067 goto out_unlock;
3068 }
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003069
Tomas Winklercb43dc22008-09-03 11:26:23 +08003070 if (ssid_len) {
Zhu Yib481de92007-09-25 17:54:57 -07003071 priv->one_direct_scan = 1;
Tomas Winklercb43dc22008-09-03 11:26:23 +08003072 priv->direct_ssid_len = min_t(u8, ssid_len, IW_ESSID_MAX_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07003073 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
Tomas Winklercb43dc22008-09-03 11:26:23 +08003074 } else {
Mohamed Abbas948c1712007-10-25 17:15:45 +08003075 priv->one_direct_scan = 0;
Tomas Winklercb43dc22008-09-03 11:26:23 +08003076 }
Zhu Yib481de92007-09-25 17:54:57 -07003077
Tomas Winklercb43dc22008-09-03 11:26:23 +08003078 ret = iwl_scan_initiate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003079
3080 IWL_DEBUG_MAC80211("leave\n");
3081
3082out_unlock:
3083 spin_unlock_irqrestore(&priv->lock, flags);
mabbas052c4b92007-10-25 17:15:43 +08003084 mutex_unlock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07003085
Tomas Winklercb43dc22008-09-03 11:26:23 +08003086 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003087}
3088
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003089static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw,
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003090 struct ieee80211_key_conf *keyconf, const u8 *addr,
3091 u32 iv32, u16 *phase1key)
3092{
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003093
Tomas Winkler9f586712008-11-12 13:14:05 -08003094 struct iwl_priv *priv = hw->priv;
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003095 IWL_DEBUG_MAC80211("enter\n");
3096
Tomas Winkler9f586712008-11-12 13:14:05 -08003097 iwl_update_tkip_key(priv, keyconf, addr, iv32, phase1key);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003098
3099 IWL_DEBUG_MAC80211("leave\n");
3100}
3101
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003102static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01003103 struct ieee80211_vif *vif,
3104 struct ieee80211_sta *sta,
Zhu Yib481de92007-09-25 17:54:57 -07003105 struct ieee80211_key_conf *key)
3106{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003107 struct iwl_priv *priv = hw->priv;
Winkler, Tomas42986792009-01-19 15:30:22 -08003108 const u8 *addr;
3109 int ret;
3110 u8 sta_id;
3111 bool is_default_wep_key = false;
Zhu Yib481de92007-09-25 17:54:57 -07003112
3113 IWL_DEBUG_MAC80211("enter\n");
3114
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07003115 if (priv->hw_params.sw_crypto) {
Zhu Yib481de92007-09-25 17:54:57 -07003116 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
3117 return -EOPNOTSUPP;
3118 }
Winkler, Tomas42986792009-01-19 15:30:22 -08003119 addr = sta ? sta->addr : iwl_bcast_addr;
Tomas Winkler947b13a2008-04-16 16:34:48 -07003120 sta_id = iwl_find_station(priv, addr);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003121 if (sta_id == IWL_INVALID_STATION) {
Johannes Berge1749612008-10-27 15:59:26 -07003122 IWL_DEBUG_MAC80211("leave - %pM not in station map.\n",
3123 addr);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003124 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003125
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003126 }
Zhu Yib481de92007-09-25 17:54:57 -07003127
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003128 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08003129 iwl_scan_cancel_timeout(priv, 100);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003130 mutex_unlock(&priv->mutex);
3131
3132 /* If we are getting WEP group key and we didn't receive any key mapping
3133 * so far, we are in legacy wep mode (group key only), otherwise we are
3134 * in 1X mode.
3135 * In legacy wep mode, we use another host command to the uCode */
Tomas Winkler5425e492008-04-15 16:01:38 -07003136 if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
Johannes Berg05c914f2008-09-11 00:01:58 +02003137 priv->iw_mode != NL80211_IFTYPE_AP) {
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003138 if (cmd == SET_KEY)
3139 is_default_wep_key = !priv->key_mapping_key;
3140 else
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +08003141 is_default_wep_key =
3142 (key->hw_key_idx == HW_KEY_DEFAULT);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003143 }
mabbas052c4b92007-10-25 17:15:43 +08003144
Zhu Yib481de92007-09-25 17:54:57 -07003145 switch (cmd) {
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003146 case SET_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003147 if (is_default_wep_key)
3148 ret = iwl_set_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003149 else
Emmanuel Grumbach74805132008-04-14 21:16:09 -07003150 ret = iwl_set_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003151
3152 IWL_DEBUG_MAC80211("enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003153 break;
3154 case DISABLE_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003155 if (is_default_wep_key)
3156 ret = iwl_remove_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003157 else
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07003158 ret = iwl_remove_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003159
3160 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003161 break;
3162 default:
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003163 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003164 }
3165
3166 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003167
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003168 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003169}
3170
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003171static int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
Zhu Yib481de92007-09-25 17:54:57 -07003172 const struct ieee80211_tx_queue_params *params)
3173{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003174 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003175 unsigned long flags;
3176 int q;
Zhu Yib481de92007-09-25 17:54:57 -07003177
3178 IWL_DEBUG_MAC80211("enter\n");
3179
Tomas Winklerfee12472008-04-03 16:05:21 -07003180 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003181 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3182 return -EIO;
3183 }
3184
3185 if (queue >= AC_NUM) {
3186 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
3187 return 0;
3188 }
3189
Zhu Yib481de92007-09-25 17:54:57 -07003190 q = AC_NUM - 1 - queue;
3191
3192 spin_lock_irqsave(&priv->lock, flags);
3193
3194 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
3195 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
3196 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
3197 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7be2008-02-10 16:49:38 +01003198 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07003199
3200 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
3201 priv->qos_data.qos_active = 1;
3202
Johannes Berg05c914f2008-09-11 00:01:58 +02003203 if (priv->iw_mode == NL80211_IFTYPE_AP)
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08003204 iwl_activate_qos(priv, 1);
Tomas Winkler3109ece2008-03-28 16:33:35 -07003205 else if (priv->assoc_id && iwl_is_associated(priv))
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08003206 iwl_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003207
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08003208 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -07003209
Zhu Yib481de92007-09-25 17:54:57 -07003210 IWL_DEBUG_MAC80211("leave\n");
3211 return 0;
3212}
3213
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003214static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
Tomas Winklerd783b062008-07-18 13:53:02 +08003215 enum ieee80211_ampdu_mlme_action action,
Johannes Berg17741cd2008-09-11 00:02:02 +02003216 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
Tomas Winklerd783b062008-07-18 13:53:02 +08003217{
3218 struct iwl_priv *priv = hw->priv;
Tomas Winklerd783b062008-07-18 13:53:02 +08003219
Johannes Berge1749612008-10-27 15:59:26 -07003220 IWL_DEBUG_HT("A-MPDU action on addr %pM tid %d\n",
3221 sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08003222
3223 if (!(priv->cfg->sku & IWL_SKU_N))
3224 return -EACCES;
3225
3226 switch (action) {
3227 case IEEE80211_AMPDU_RX_START:
3228 IWL_DEBUG_HT("start Rx\n");
Tomas Winkler9f586712008-11-12 13:14:05 -08003229 return iwl_sta_rx_agg_start(priv, sta->addr, tid, *ssn);
Tomas Winklerd783b062008-07-18 13:53:02 +08003230 case IEEE80211_AMPDU_RX_STOP:
3231 IWL_DEBUG_HT("stop Rx\n");
Tomas Winkler9f586712008-11-12 13:14:05 -08003232 return iwl_sta_rx_agg_stop(priv, sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08003233 case IEEE80211_AMPDU_TX_START:
3234 IWL_DEBUG_HT("start Tx\n");
Johannes Berg17741cd2008-09-11 00:02:02 +02003235 return iwl_tx_agg_start(priv, sta->addr, tid, ssn);
Tomas Winklerd783b062008-07-18 13:53:02 +08003236 case IEEE80211_AMPDU_TX_STOP:
3237 IWL_DEBUG_HT("stop Tx\n");
Johannes Berg17741cd2008-09-11 00:02:02 +02003238 return iwl_tx_agg_stop(priv, sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08003239 default:
3240 IWL_DEBUG_HT("unknown\n");
3241 return -EINVAL;
3242 break;
3243 }
3244 return 0;
3245}
Tomas Winkler9f586712008-11-12 13:14:05 -08003246
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003247static int iwl_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003248 struct ieee80211_tx_queue_stats *stats)
3249{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003250 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003251 int i, avail;
Ron Rindjunsky16466902008-05-05 10:22:50 +08003252 struct iwl_tx_queue *txq;
Tomas Winkler443cfd42008-05-15 13:53:57 +08003253 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07003254 unsigned long flags;
3255
3256 IWL_DEBUG_MAC80211("enter\n");
3257
Tomas Winklerfee12472008-04-03 16:05:21 -07003258 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003259 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3260 return -EIO;
3261 }
3262
3263 spin_lock_irqsave(&priv->lock, flags);
3264
3265 for (i = 0; i < AC_NUM; i++) {
3266 txq = &priv->txq[i];
3267 q = &txq->q;
Tomas Winkler443cfd42008-05-15 13:53:57 +08003268 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07003269
Johannes Berg57ffc582008-04-29 17:18:59 +02003270 stats[i].len = q->n_window - avail;
3271 stats[i].limit = q->n_window - q->high_mark;
3272 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07003273
3274 }
3275 spin_unlock_irqrestore(&priv->lock, flags);
3276
3277 IWL_DEBUG_MAC80211("leave\n");
3278
3279 return 0;
3280}
3281
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003282static int iwl_mac_get_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003283 struct ieee80211_low_level_stats *stats)
3284{
Ester Kummerbf403db2008-05-05 10:22:40 +08003285 struct iwl_priv *priv = hw->priv;
3286
3287 priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003288 IWL_DEBUG_MAC80211("enter\n");
3289 IWL_DEBUG_MAC80211("leave\n");
3290
3291 return 0;
3292}
3293
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003294static void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003295{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003296 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003297 unsigned long flags;
3298
3299 mutex_lock(&priv->mutex);
3300 IWL_DEBUG_MAC80211("enter\n");
3301
Zhu Yib481de92007-09-25 17:54:57 -07003302 spin_lock_irqsave(&priv->lock, flags);
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02003303 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
Zhu Yib481de92007-09-25 17:54:57 -07003304 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -07003305
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003306 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003307
Zhu Yib481de92007-09-25 17:54:57 -07003308 spin_lock_irqsave(&priv->lock, flags);
3309 priv->assoc_id = 0;
3310 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003311 priv->assoc_station_added = 0;
3312
3313 /* new association get rid of ibss beacon skb */
3314 if (priv->ibss_beacon)
3315 dev_kfree_skb(priv->ibss_beacon);
3316
3317 priv->ibss_beacon = NULL;
3318
3319 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler3109ece2008-03-28 16:33:35 -07003320 priv->timestamp = 0;
Johannes Berg05c914f2008-09-11 00:01:58 +02003321 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
Zhu Yib481de92007-09-25 17:54:57 -07003322 priv->beacon_int = 0;
3323
3324 spin_unlock_irqrestore(&priv->lock, flags);
3325
Tomas Winklerfee12472008-04-03 16:05:21 -07003326 if (!iwl_is_ready_rf(priv)) {
Mohamed Abbasfde35712007-11-29 11:10:15 +08003327 IWL_DEBUG_MAC80211("leave - not ready\n");
3328 mutex_unlock(&priv->mutex);
3329 return;
3330 }
3331
mabbas052c4b92007-10-25 17:15:43 +08003332 /* we are restarting association process
3333 * clear RXON_FILTER_ASSOC_MSK bit
3334 */
Johannes Berg05c914f2008-09-11 00:01:58 +02003335 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Tomas Winkler2a421b92008-06-12 09:47:10 +08003336 iwl_scan_cancel_timeout(priv, 100);
mabbas052c4b92007-10-25 17:15:43 +08003337 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003338 iwl_commit_rxon(priv);
mabbas052c4b92007-10-25 17:15:43 +08003339 }
3340
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003341 iwl_power_update_mode(priv, 0);
3342
Zhu Yib481de92007-09-25 17:54:57 -07003343 /* Per mac80211.h: This is only used in IBSS mode... */
Johannes Berg05c914f2008-09-11 00:01:58 +02003344 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
mabbas052c4b92007-10-25 17:15:43 +08003345
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08003346 /* switch to CAM during association period.
3347 * the ucode will block any association/authentication
3348 * frome during assiciation period if it can not hear
3349 * the AP because of PM. the timer enable PM back is
3350 * association do not complete
3351 */
3352 if (priv->hw->conf.channel->flags & (IEEE80211_CHAN_PASSIVE_SCAN |
3353 IEEE80211_CHAN_RADAR))
3354 iwl_power_disable_management(priv, 3000);
3355
Zhu Yib481de92007-09-25 17:54:57 -07003356 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
3357 mutex_unlock(&priv->mutex);
3358 return;
3359 }
3360
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003361 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003362
3363 mutex_unlock(&priv->mutex);
3364
3365 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003366}
3367
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003368static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003369{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003370 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003371 unsigned long flags;
Assaf Krauss2ff75b72008-06-30 17:23:17 +08003372 __le64 timestamp;
Zhu Yib481de92007-09-25 17:54:57 -07003373
Zhu Yib481de92007-09-25 17:54:57 -07003374 IWL_DEBUG_MAC80211("enter\n");
3375
Tomas Winklerfee12472008-04-03 16:05:21 -07003376 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003377 IWL_DEBUG_MAC80211("leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07003378 return -EIO;
3379 }
3380
Johannes Berg05c914f2008-09-11 00:01:58 +02003381 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Zhu Yib481de92007-09-25 17:54:57 -07003382 IWL_DEBUG_MAC80211("leave - not IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07003383 return -EIO;
3384 }
3385
3386 spin_lock_irqsave(&priv->lock, flags);
3387
3388 if (priv->ibss_beacon)
3389 dev_kfree_skb(priv->ibss_beacon);
3390
3391 priv->ibss_beacon = skb;
3392
3393 priv->assoc_id = 0;
Assaf Krauss2ff75b72008-06-30 17:23:17 +08003394 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
Assaf Kraussb94d8ee2008-09-03 11:18:42 +08003395 priv->timestamp = le64_to_cpu(timestamp);
Zhu Yib481de92007-09-25 17:54:57 -07003396
3397 IWL_DEBUG_MAC80211("leave\n");
3398 spin_unlock_irqrestore(&priv->lock, flags);
3399
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003400 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003401
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003402 iwl_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003403
Zhu Yib481de92007-09-25 17:54:57 -07003404
3405 return 0;
3406}
3407
Zhu Yib481de92007-09-25 17:54:57 -07003408/*****************************************************************************
3409 *
3410 * sysfs attributes
3411 *
3412 *****************************************************************************/
3413
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003414#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07003415
3416/*
3417 * The following adds a new attribute to the sysfs representation
Wu, Fengguangc3a739f2008-12-17 16:52:29 +08003418 * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
Zhu Yib481de92007-09-25 17:54:57 -07003419 * used for controlling the debug level.
3420 *
3421 * See the level definitions in iwl for details.
3422 */
3423
Ester Kummer8cf769c2008-05-06 11:05:11 +08003424static ssize_t show_debug_level(struct device *d,
3425 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07003426{
Ester Kummer8cf769c2008-05-06 11:05:11 +08003427 struct iwl_priv *priv = d->driver_data;
3428
3429 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07003430}
Ester Kummer8cf769c2008-05-06 11:05:11 +08003431static ssize_t store_debug_level(struct device *d,
3432 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07003433 const char *buf, size_t count)
3434{
Ester Kummer8cf769c2008-05-06 11:05:11 +08003435 struct iwl_priv *priv = d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003436 unsigned long val;
3437 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003438
Tomas Winkler9257746f2008-09-03 11:26:32 +08003439 ret = strict_strtoul(buf, 0, &val);
3440 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08003441 IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07003442 else
Ester Kummer8cf769c2008-05-06 11:05:11 +08003443 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07003444
3445 return strnlen(buf, count);
3446}
3447
Ester Kummer8cf769c2008-05-06 11:05:11 +08003448static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
3449 show_debug_level, store_debug_level);
3450
Zhu Yib481de92007-09-25 17:54:57 -07003451
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003452#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07003453
Zhu Yib481de92007-09-25 17:54:57 -07003454
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003455static ssize_t show_version(struct device *d,
3456 struct device_attribute *attr, char *buf)
3457{
3458 struct iwl_priv *priv = d->driver_data;
Tomas Winkler885ba202008-05-29 16:34:55 +08003459 struct iwl_alive_resp *palive = &priv->card_alive;
Tomas Winklerf236a262008-06-30 17:23:02 +08003460 ssize_t pos = 0;
3461 u16 eeprom_ver;
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003462
3463 if (palive->is_valid)
Tomas Winklerf236a262008-06-30 17:23:02 +08003464 pos += sprintf(buf + pos,
3465 "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n"
3466 "fw type: 0x%01X 0x%01X\n",
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003467 palive->ucode_major, palive->ucode_minor,
3468 palive->sw_rev[0], palive->sw_rev[1],
3469 palive->ver_type, palive->ver_subtype);
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003470 else
Tomas Winklerf236a262008-06-30 17:23:02 +08003471 pos += sprintf(buf + pos, "fw not loaded\n");
3472
3473 if (priv->eeprom) {
3474 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
3475 pos += sprintf(buf + pos, "EEPROM version: 0x%x\n",
3476 eeprom_ver);
3477 } else {
3478 pos += sprintf(buf + pos, "EEPROM not initialzed\n");
3479 }
3480
3481 return pos;
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003482}
3483
3484static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL);
3485
Zhu Yib481de92007-09-25 17:54:57 -07003486static ssize_t show_temperature(struct device *d,
3487 struct device_attribute *attr, char *buf)
3488{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003489 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003490
Tomas Winklerfee12472008-04-03 16:05:21 -07003491 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003492 return -EAGAIN;
3493
Emmanuel Grumbach91dbc5b2008-06-12 09:47:14 +08003494 return sprintf(buf, "%d\n", priv->temperature);
Zhu Yib481de92007-09-25 17:54:57 -07003495}
3496
3497static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
3498
Zhu Yib481de92007-09-25 17:54:57 -07003499static ssize_t show_tx_power(struct device *d,
3500 struct device_attribute *attr, char *buf)
3501{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003502 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Jay Sternberg91f39e82008-12-17 16:52:34 +08003503
3504 if (!iwl_is_ready_rf(priv))
3505 return sprintf(buf, "off\n");
3506 else
3507 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07003508}
3509
3510static ssize_t store_tx_power(struct device *d,
3511 struct device_attribute *attr,
3512 const char *buf, size_t count)
3513{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003514 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003515 unsigned long val;
3516 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003517
Tomas Winkler9257746f2008-09-03 11:26:32 +08003518 ret = strict_strtoul(buf, 10, &val);
3519 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08003520 IWL_INFO(priv, "%s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07003521 else
Tomas Winkler630fe9b2008-06-12 09:47:08 +08003522 iwl_set_tx_power(priv, val, false);
Zhu Yib481de92007-09-25 17:54:57 -07003523
3524 return count;
3525}
3526
3527static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
3528
3529static ssize_t show_flags(struct device *d,
3530 struct device_attribute *attr, char *buf)
3531{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003532 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003533
3534 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
3535}
3536
3537static ssize_t store_flags(struct device *d,
3538 struct device_attribute *attr,
3539 const char *buf, size_t count)
3540{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003541 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003542 unsigned long val;
3543 u32 flags;
3544 int ret = strict_strtoul(buf, 0, &val);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08003545 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08003546 return ret;
3547 flags = (u32)val;
Zhu Yib481de92007-09-25 17:54:57 -07003548
3549 mutex_lock(&priv->mutex);
3550 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
3551 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08003552 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003553 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003554 else {
Tomas Winkler9257746f2008-09-03 11:26:32 +08003555 IWL_DEBUG_INFO("Commit rxon.flags = 0x%04X\n", flags);
Zhu Yib481de92007-09-25 17:54:57 -07003556 priv->staging_rxon.flags = cpu_to_le32(flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003557 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003558 }
3559 }
3560 mutex_unlock(&priv->mutex);
3561
3562 return count;
3563}
3564
3565static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
3566
3567static ssize_t show_filter_flags(struct device *d,
3568 struct device_attribute *attr, char *buf)
3569{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003570 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003571
3572 return sprintf(buf, "0x%04X\n",
3573 le32_to_cpu(priv->active_rxon.filter_flags));
3574}
3575
3576static ssize_t store_filter_flags(struct device *d,
3577 struct device_attribute *attr,
3578 const char *buf, size_t count)
3579{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003580 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003581 unsigned long val;
3582 u32 filter_flags;
3583 int ret = strict_strtoul(buf, 0, &val);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08003584 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08003585 return ret;
3586 filter_flags = (u32)val;
Zhu Yib481de92007-09-25 17:54:57 -07003587
3588 mutex_lock(&priv->mutex);
3589 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
3590 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08003591 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003592 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003593 else {
3594 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
3595 "0x%04X\n", filter_flags);
3596 priv->staging_rxon.filter_flags =
3597 cpu_to_le32(filter_flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003598 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003599 }
3600 }
3601 mutex_unlock(&priv->mutex);
3602
3603 return count;
3604}
3605
3606static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
3607 store_filter_flags);
3608
Zhu Yib481de92007-09-25 17:54:57 -07003609static ssize_t store_power_level(struct device *d,
3610 struct device_attribute *attr,
3611 const char *buf, size_t count)
3612{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003613 struct iwl_priv *priv = dev_get_drvdata(d);
Esti Kummer298df1f2008-07-18 13:52:58 +08003614 int ret;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003615 unsigned long mode;
Zhu Yib481de92007-09-25 17:54:57 -07003616
Tomas Winkler9257746f2008-09-03 11:26:32 +08003617
Zhu Yib481de92007-09-25 17:54:57 -07003618 mutex_lock(&priv->mutex);
3619
Tomas Winklerfee12472008-04-03 16:05:21 -07003620 if (!iwl_is_ready(priv)) {
Esti Kummer298df1f2008-07-18 13:52:58 +08003621 ret = -EAGAIN;
Zhu Yib481de92007-09-25 17:54:57 -07003622 goto out;
3623 }
3624
Tomas Winkler9257746f2008-09-03 11:26:32 +08003625 ret = strict_strtoul(buf, 10, &mode);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08003626 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08003627 goto out;
3628
Esti Kummer298df1f2008-07-18 13:52:58 +08003629 ret = iwl_power_set_user_mode(priv, mode);
3630 if (ret) {
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003631 IWL_DEBUG_MAC80211("failed setting power mode.\n");
3632 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003633 }
Esti Kummer298df1f2008-07-18 13:52:58 +08003634 ret = count;
Zhu Yib481de92007-09-25 17:54:57 -07003635
3636 out:
3637 mutex_unlock(&priv->mutex);
Esti Kummer298df1f2008-07-18 13:52:58 +08003638 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003639}
3640
Zhu Yib481de92007-09-25 17:54:57 -07003641static ssize_t show_power_level(struct device *d,
3642 struct device_attribute *attr, char *buf)
3643{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003644 struct iwl_priv *priv = dev_get_drvdata(d);
Esti Kummer298df1f2008-07-18 13:52:58 +08003645 int mode = priv->power_data.user_power_setting;
3646 int system = priv->power_data.system_power_setting;
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003647 int level = priv->power_data.power_mode;
Zhu Yib481de92007-09-25 17:54:57 -07003648 char *p = buf;
3649
Esti Kummer298df1f2008-07-18 13:52:58 +08003650 switch (system) {
3651 case IWL_POWER_SYS_AUTO:
3652 p += sprintf(p, "SYSTEM:auto");
Zhu Yib481de92007-09-25 17:54:57 -07003653 break;
Esti Kummer298df1f2008-07-18 13:52:58 +08003654 case IWL_POWER_SYS_AC:
3655 p += sprintf(p, "SYSTEM:ac");
Zhu Yib481de92007-09-25 17:54:57 -07003656 break;
Esti Kummer298df1f2008-07-18 13:52:58 +08003657 case IWL_POWER_SYS_BATTERY:
3658 p += sprintf(p, "SYSTEM:battery");
3659 break;
Zhu Yib481de92007-09-25 17:54:57 -07003660 }
Esti Kummer298df1f2008-07-18 13:52:58 +08003661
Abhijeet Kolekarc3056062008-11-12 13:14:08 -08003662 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
3663 "fixed" : "auto");
Esti Kummer298df1f2008-07-18 13:52:58 +08003664 p += sprintf(p, "\tINDEX:%d", level);
3665 p += sprintf(p, "\n");
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003666 return p - buf + 1;
Zhu Yib481de92007-09-25 17:54:57 -07003667}
3668
3669static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
3670 store_power_level);
3671
Zhu Yib481de92007-09-25 17:54:57 -07003672
3673static ssize_t show_statistics(struct device *d,
3674 struct device_attribute *attr, char *buf)
3675{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003676 struct iwl_priv *priv = dev_get_drvdata(d);
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08003677 u32 size = sizeof(struct iwl_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07003678 u32 len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003679 u8 *data = (u8 *)&priv->statistics;
Zhu Yib481de92007-09-25 17:54:57 -07003680 int rc = 0;
3681
Tomas Winklerfee12472008-04-03 16:05:21 -07003682 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003683 return -EAGAIN;
3684
3685 mutex_lock(&priv->mutex);
Emmanuel Grumbach49ea8592008-04-15 16:01:37 -07003686 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003687 mutex_unlock(&priv->mutex);
3688
3689 if (rc) {
3690 len = sprintf(buf,
3691 "Error sending statistics request: 0x%08X\n", rc);
3692 return len;
3693 }
3694
3695 while (size && (PAGE_SIZE - len)) {
3696 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
3697 PAGE_SIZE - len, 1);
3698 len = strlen(buf);
3699 if (PAGE_SIZE - len)
3700 buf[len++] = '\n';
3701
3702 ofs += 16;
3703 size -= min(size, 16U);
3704 }
3705
3706 return len;
3707}
3708
3709static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
3710
Zhu Yib481de92007-09-25 17:54:57 -07003711
Zhu Yib481de92007-09-25 17:54:57 -07003712/*****************************************************************************
3713 *
3714 * driver setup and teardown
3715 *
3716 *****************************************************************************/
3717
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003718static void iwl_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003719{
3720 priv->workqueue = create_workqueue(DRV_NAME);
3721
3722 init_waitqueue_head(&priv->wait_command_queue);
3723
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003724 INIT_WORK(&priv->up, iwl_bg_up);
3725 INIT_WORK(&priv->restart, iwl_bg_restart);
3726 INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish);
3727 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
3728 INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08003729 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08003730 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
3731 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
Tomas Winkler2a421b92008-06-12 09:47:10 +08003732
Tomas Winkler2a421b92008-06-12 09:47:10 +08003733 iwl_setup_scan_deferred_work(priv);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08003734 iwl_setup_power_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003735
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003736 if (priv->cfg->ops->lib->setup_deferred_work)
3737 priv->cfg->ops->lib->setup_deferred_work(priv);
3738
3739 init_timer(&priv->statistics_periodic);
3740 priv->statistics_periodic.data = (unsigned long)priv;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003741 priv->statistics_periodic.function = iwl_bg_statistics_periodic;
Zhu Yib481de92007-09-25 17:54:57 -07003742
3743 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003744 iwl_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07003745}
3746
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003747static void iwl_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003748{
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003749 if (priv->cfg->ops->lib->cancel_deferred_work)
3750 priv->cfg->ops->lib->cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003751
Joonwoo Park3ae6a052007-11-29 10:43:16 +09003752 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07003753 cancel_delayed_work(&priv->scan_check);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08003754 cancel_delayed_work_sync(&priv->set_power_save);
Zhu Yib481de92007-09-25 17:54:57 -07003755 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07003756 cancel_work_sync(&priv->beacon_update);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003757 del_timer_sync(&priv->statistics_periodic);
Zhu Yib481de92007-09-25 17:54:57 -07003758}
3759
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003760static struct attribute *iwl_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07003761 &dev_attr_flags.attr,
3762 &dev_attr_filter_flags.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003763 &dev_attr_power_level.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003764 &dev_attr_statistics.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003765 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003766 &dev_attr_tx_power.attr,
Ester Kummer8cf769c2008-05-06 11:05:11 +08003767#ifdef CONFIG_IWLWIFI_DEBUG
3768 &dev_attr_debug_level.attr,
3769#endif
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003770 &dev_attr_version.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003771
3772 NULL
3773};
3774
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003775static struct attribute_group iwl_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07003776 .name = NULL, /* put in device directory */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003777 .attrs = iwl_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07003778};
3779
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003780static struct ieee80211_ops iwl_hw_ops = {
3781 .tx = iwl_mac_tx,
3782 .start = iwl_mac_start,
3783 .stop = iwl_mac_stop,
3784 .add_interface = iwl_mac_add_interface,
3785 .remove_interface = iwl_mac_remove_interface,
3786 .config = iwl_mac_config,
3787 .config_interface = iwl_mac_config_interface,
3788 .configure_filter = iwl_configure_filter,
3789 .set_key = iwl_mac_set_key,
3790 .update_tkip_key = iwl_mac_update_tkip_key,
3791 .get_stats = iwl_mac_get_stats,
3792 .get_tx_stats = iwl_mac_get_tx_stats,
3793 .conf_tx = iwl_mac_conf_tx,
3794 .reset_tsf = iwl_mac_reset_tsf,
3795 .bss_info_changed = iwl_bss_info_changed,
3796 .ampdu_action = iwl_mac_ampdu_action,
Tomas Winklercb43dc22008-09-03 11:26:23 +08003797 .hw_scan = iwl_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07003798};
3799
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003800static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07003801{
3802 int err = 0;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003803 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07003804 struct ieee80211_hw *hw;
Tomas Winkler82b9a122008-03-04 18:09:30 -08003805 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003806 unsigned long flags;
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003807 u16 pci_cmd;
Zhu Yib481de92007-09-25 17:54:57 -07003808
Assaf Krauss316c30d2008-03-14 10:38:46 -07003809 /************************
3810 * 1. Allocating HW data
3811 ************************/
3812
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003813 /* Disabling hardware scan means that mac80211 will perform scans
3814 * "the hard way", rather than using device's scan. */
Assaf Krauss1ea87392008-03-18 14:57:50 -07003815 if (cfg->mod_params->disable_hw_scan) {
Ester Kummerbf403db2008-05-05 10:22:40 +08003816 if (cfg->mod_params->debug & IWL_DL_INFO)
3817 dev_printk(KERN_DEBUG, &(pdev->dev),
3818 "Disabling hw_scan\n");
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003819 iwl_hw_ops.hw_scan = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07003820 }
3821
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003822 hw = iwl_alloc_all(cfg, &iwl_hw_ops);
Assaf Krauss1d0a0822008-03-14 10:38:48 -07003823 if (!hw) {
Zhu Yib481de92007-09-25 17:54:57 -07003824 err = -ENOMEM;
3825 goto out;
3826 }
Assaf Krauss1d0a0822008-03-14 10:38:48 -07003827 priv = hw->priv;
3828 /* At this point both hw and priv are allocated. */
3829
Zhu Yib481de92007-09-25 17:54:57 -07003830 SET_IEEE80211_DEV(hw, &pdev->dev);
3831
3832 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
Tomas Winkler82b9a122008-03-04 18:09:30 -08003833 priv->cfg = cfg;
Zhu Yib481de92007-09-25 17:54:57 -07003834 priv->pci_dev = pdev;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003835
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003836#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08003837 priv->debug_level = priv->cfg->mod_params->debug;
Zhu Yib481de92007-09-25 17:54:57 -07003838 atomic_set(&priv->restrict_refcnt, 0);
3839#endif
Zhu Yib481de92007-09-25 17:54:57 -07003840
Assaf Krauss316c30d2008-03-14 10:38:46 -07003841 /**************************
3842 * 2. Initializing PCI bus
3843 **************************/
3844 if (pci_enable_device(pdev)) {
3845 err = -ENODEV;
3846 goto out_ieee80211_free_hw;
3847 }
3848
3849 pci_set_master(pdev);
3850
Winkler, Tomas093d8742008-09-26 15:09:34 +08003851 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
Assaf Krauss316c30d2008-03-14 10:38:46 -07003852 if (!err)
Winkler, Tomas093d8742008-09-26 15:09:34 +08003853 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003854 if (err) {
Winkler, Tomas093d8742008-09-26 15:09:34 +08003855 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003856 if (!err)
Winkler, Tomas093d8742008-09-26 15:09:34 +08003857 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003858 /* both attempts failed: */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003859 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08003860 IWL_WARN(priv, "No suitable DMA available.\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07003861 goto out_pci_disable_device;
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003862 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07003863 }
3864
3865 err = pci_request_regions(pdev, DRV_NAME);
3866 if (err)
3867 goto out_pci_disable_device;
3868
3869 pci_set_drvdata(pdev, priv);
3870
Assaf Krauss316c30d2008-03-14 10:38:46 -07003871
3872 /***********************
3873 * 3. Read REV register
3874 ***********************/
3875 priv->hw_base = pci_iomap(pdev, 0, 0);
3876 if (!priv->hw_base) {
3877 err = -ENODEV;
3878 goto out_pci_release_regions;
3879 }
3880
3881 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
3882 (unsigned long long) pci_resource_len(pdev, 0));
3883 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
3884
Tomas Winklerb661c812008-04-23 17:14:54 -07003885 iwl_hw_detect(priv);
Tomas Winkler978785a2008-12-19 10:37:31 +08003886 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s REV=0x%X\n",
Tomas Winklerb661c812008-04-23 17:14:54 -07003887 priv->cfg->name, priv->hw_rev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003888
Tomas Winklere7b63582008-09-03 11:26:49 +08003889 /* We disable the RETRY_TIMEOUT register (0x41) to keep
3890 * PCI Tx retries from interfering with C3 CPU state */
3891 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
3892
Tomas Winkler91238712008-04-23 17:14:53 -07003893 /* amp init */
3894 err = priv->cfg->ops->lib->apm_ops.init(priv);
3895 if (err < 0) {
3896 IWL_DEBUG_INFO("Failed to init APMG\n");
3897 goto out_iounmap;
3898 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07003899 /*****************
3900 * 4. Read EEPROM
3901 *****************/
Assaf Krauss316c30d2008-03-14 10:38:46 -07003902 /* Read the EEPROM */
3903 err = iwl_eeprom_init(priv);
3904 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003905 IWL_ERR(priv, "Unable to init EEPROM\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07003906 goto out_iounmap;
3907 }
Tomas Winkler8614f362008-04-23 17:14:55 -07003908 err = iwl_eeprom_check_version(priv);
3909 if (err)
3910 goto out_iounmap;
3911
Ron Rindjunsky02883012008-05-15 13:53:53 +08003912 /* extract MAC Address */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003913 iwl_eeprom_get_mac(priv, priv->mac_addr);
Johannes Berge1749612008-10-27 15:59:26 -07003914 IWL_DEBUG_INFO("MAC address: %pM\n", priv->mac_addr);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003915 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
3916
3917 /************************
3918 * 5. Setup HW constants
3919 ************************/
Ron Rindjunskyda154e32008-06-30 17:23:20 +08003920 if (iwl_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003921 IWL_ERR(priv, "failed to set hw parameters\n");
Tomas Winkler073d3f52008-04-21 15:41:52 -07003922 goto out_free_eeprom;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003923 }
3924
3925 /*******************
Tomas Winkler6ba87952008-05-15 13:54:17 +08003926 * 6. Setup priv
Assaf Krauss316c30d2008-03-14 10:38:46 -07003927 *******************/
Zhu Yib481de92007-09-25 17:54:57 -07003928
Tomas Winkler6ba87952008-05-15 13:54:17 +08003929 err = iwl_init_drv(priv);
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003930 if (err)
Ron Rindjunsky399f49002008-04-23 17:14:56 -07003931 goto out_free_eeprom;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003932 /* At this point both hw and priv are initialized. */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003933
3934 /**********************************
3935 * 7. Initialize module parameters
3936 **********************************/
3937
3938 /* Disable radio (SW RF KILL) via parameter when loading driver */
Assaf Krauss1ea87392008-03-18 14:57:50 -07003939 if (priv->cfg->mod_params->disable) {
Assaf Krauss316c30d2008-03-14 10:38:46 -07003940 set_bit(STATUS_RF_KILL_SW, &priv->status);
3941 IWL_DEBUG_INFO("Radio disabled.\n");
3942 }
3943
Assaf Krauss316c30d2008-03-14 10:38:46 -07003944 /********************
3945 * 8. Setup services
3946 ********************/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003947 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003948 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003949 spin_unlock_irqrestore(&priv->lock, flags);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003950
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003951 pci_enable_msi(priv->pci_dev);
3952
3953 err = request_irq(priv->pci_dev->irq, iwl_isr, IRQF_SHARED,
3954 DRV_NAME, priv);
3955 if (err) {
3956 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
3957 goto out_disable_msi;
3958 }
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003959 err = sysfs_create_group(&pdev->dev.kobj, &iwl_attribute_group);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003960 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003961 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Tomas Winkler6ba87952008-05-15 13:54:17 +08003962 goto out_uninit_drv;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003963 }
3964
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003965 iwl_setup_deferred_work(priv);
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08003966 iwl_setup_rx_handlers(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003967
Tomas Winkler6ba87952008-05-15 13:54:17 +08003968 /**********************************
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003969 * 9. Setup and register mac80211
Tomas Winkler6ba87952008-05-15 13:54:17 +08003970 **********************************/
3971
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003972 /* enable interrupts if needed: hw bug w/a */
3973 pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd);
3974 if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
3975 pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
3976 pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
3977 }
3978
3979 iwl_enable_interrupts(priv);
3980
Tomas Winkler6ba87952008-05-15 13:54:17 +08003981 err = iwl_setup_mac(priv);
3982 if (err)
3983 goto out_remove_sysfs;
3984
3985 err = iwl_dbgfs_register(priv, DRV_NAME);
3986 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08003987 IWL_ERR(priv, "failed to create debugfs files\n");
Tomas Winkler6ba87952008-05-15 13:54:17 +08003988
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003989 /* If platform's RF_KILL switch is NOT set to KILL */
3990 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3991 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3992 else
3993 set_bit(STATUS_RF_KILL_HW, &priv->status);
3994
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08003995 err = iwl_rfkill_init(priv);
3996 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08003997 IWL_ERR(priv, "Unable to initialize RFKILL system. "
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08003998 "Ignoring error: %d\n", err);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003999 else
4000 iwl_rfkill_set_hw_state(priv);
4001
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08004002 iwl_power_initialize(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004003 return 0;
4004
Assaf Krauss316c30d2008-03-14 10:38:46 -07004005 out_remove_sysfs:
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004006 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004007 out_disable_msi:
4008 pci_disable_msi(priv->pci_dev);
4009 pci_disable_device(priv->pci_dev);
Tomas Winkler6ba87952008-05-15 13:54:17 +08004010 out_uninit_drv:
4011 iwl_uninit_drv(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07004012 out_free_eeprom:
4013 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004014 out_iounmap:
4015 pci_iounmap(pdev, priv->hw_base);
4016 out_pci_release_regions:
4017 pci_release_regions(pdev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004018 pci_set_drvdata(pdev, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07004019 out_pci_disable_device:
4020 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004021 out_ieee80211_free_hw:
4022 ieee80211_free_hw(priv->hw);
4023 out:
4024 return err;
4025}
4026
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004027static void __devexit iwl_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004028{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004029 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004030 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07004031
4032 if (!priv)
4033 return;
4034
4035 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
4036
Emmanuel Grumbach67249622008-05-29 16:35:26 +08004037 iwl_dbgfs_unregister(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004038 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
Emmanuel Grumbach67249622008-05-29 16:35:26 +08004039
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004040 /* ieee80211_unregister_hw call wil cause iwl_mac_stop to
4041 * to be called and iwl_down since we are removing the device
Gregory Greenman0b124c32008-09-03 11:18:50 +08004042 * we need to set STATUS_EXIT_PENDING bit.
4043 */
4044 set_bit(STATUS_EXIT_PENDING, &priv->status);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07004045 if (priv->mac80211_registered) {
4046 ieee80211_unregister_hw(priv->hw);
4047 priv->mac80211_registered = 0;
Gregory Greenman0b124c32008-09-03 11:18:50 +08004048 } else {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004049 iwl_down(priv);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07004050 }
4051
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004052 /* make sure we flush any pending irq or
4053 * tasklet for the driver
4054 */
4055 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004056 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004057 spin_unlock_irqrestore(&priv->lock, flags);
4058
4059 iwl_synchronize_irq(priv);
4060
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08004061 iwl_rfkill_unregister(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004062 iwl_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004063
4064 if (priv->rxq.bd)
Tomas Winklera55360e2008-05-05 10:22:28 +08004065 iwl_rx_queue_free(priv, &priv->rxq);
Ron Rindjunsky1053d352008-05-05 10:22:43 +08004066 iwl_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004067
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08004068 iwl_clear_stations_table(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07004069 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004070
Zhu Yib481de92007-09-25 17:54:57 -07004071
Mohamed Abbas948c1712007-10-25 17:15:45 +08004072 /*netif_stop_queue(dev); */
4073 flush_workqueue(priv->workqueue);
4074
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004075 /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07004076 * priv->workqueue... so we can't take down the workqueue
4077 * until now... */
4078 destroy_workqueue(priv->workqueue);
4079 priv->workqueue = NULL;
4080
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004081 free_irq(priv->pci_dev->irq, priv);
4082 pci_disable_msi(priv->pci_dev);
Zhu Yib481de92007-09-25 17:54:57 -07004083 pci_iounmap(pdev, priv->hw_base);
4084 pci_release_regions(pdev);
4085 pci_disable_device(pdev);
4086 pci_set_drvdata(pdev, NULL);
4087
Tomas Winkler6ba87952008-05-15 13:54:17 +08004088 iwl_uninit_drv(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004089
4090 if (priv->ibss_beacon)
4091 dev_kfree_skb(priv->ibss_beacon);
4092
4093 ieee80211_free_hw(priv->hw);
4094}
4095
4096#ifdef CONFIG_PM
4097
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004098static int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07004099{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004100 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004101
Zhu Yie655b9f2008-01-24 02:19:38 -08004102 if (priv->is_open) {
4103 set_bit(STATUS_IN_SUSPEND, &priv->status);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004104 iwl_mac_stop(priv->hw);
Zhu Yie655b9f2008-01-24 02:19:38 -08004105 priv->is_open = 1;
4106 }
Zhu Yib481de92007-09-25 17:54:57 -07004107
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004108 pci_save_state(pdev);
4109 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004110 pci_set_power_state(pdev, PCI_D3hot);
4111
Zhu Yib481de92007-09-25 17:54:57 -07004112 return 0;
4113}
4114
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004115static int iwl_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004116{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004117 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004118
Zhu Yib481de92007-09-25 17:54:57 -07004119 pci_set_power_state(pdev, PCI_D0);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004120 pci_enable_device(pdev);
4121 pci_restore_state(pdev);
4122 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004123
Zhu Yie655b9f2008-01-24 02:19:38 -08004124 if (priv->is_open)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004125 iwl_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07004126
Zhu Yie655b9f2008-01-24 02:19:38 -08004127 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004128 return 0;
4129}
4130
4131#endif /* CONFIG_PM */
4132
4133/*****************************************************************************
4134 *
4135 * driver and module entry point
4136 *
4137 *****************************************************************************/
4138
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004139/* Hardware specific file defines the PCI IDs table for that hardware module */
4140static struct pci_device_id iwl_hw_card_ids[] = {
Tomas Winkler4fc22b22008-07-21 18:54:42 +03004141#ifdef CONFIG_IWL4965
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004142 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
4143 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
Tomas Winkler4fc22b22008-07-21 18:54:42 +03004144#endif /* CONFIG_IWL4965 */
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004145#ifdef CONFIG_IWL5000
Esti Kummer47408632008-07-11 11:53:30 +08004146 {IWL_PCI_DEVICE(0x4232, 0x1205, iwl5100_bg_cfg)},
4147 {IWL_PCI_DEVICE(0x4232, 0x1305, iwl5100_bg_cfg)},
4148 {IWL_PCI_DEVICE(0x4232, 0x1206, iwl5100_abg_cfg)},
4149 {IWL_PCI_DEVICE(0x4232, 0x1306, iwl5100_abg_cfg)},
4150 {IWL_PCI_DEVICE(0x4232, 0x1326, iwl5100_abg_cfg)},
4151 {IWL_PCI_DEVICE(0x4237, 0x1216, iwl5100_abg_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004152 {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)},
Esti Kummer47408632008-07-11 11:53:30 +08004153 {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)},
4154 {IWL_PCI_DEVICE(0x4236, PCI_ANY_ID, iwl5300_agn_cfg)},
4155 {IWL_PCI_DEVICE(0x4237, PCI_ANY_ID, iwl5100_agn_cfg)},
Tomas Winklere96a8492008-09-11 11:45:20 +08004156/* 5350 WiFi/WiMax */
4157 {IWL_PCI_DEVICE(0x423A, 0x1001, iwl5350_agn_cfg)},
4158 {IWL_PCI_DEVICE(0x423A, 0x1021, iwl5350_agn_cfg)},
4159 {IWL_PCI_DEVICE(0x423B, 0x1011, iwl5350_agn_cfg)},
Tomas Winkler7100e922008-12-01 16:32:18 -08004160/* 5150 Wifi/WiMax */
4161 {IWL_PCI_DEVICE(0x423C, PCI_ANY_ID, iwl5150_agn_cfg)},
4162 {IWL_PCI_DEVICE(0x423D, PCI_ANY_ID, iwl5150_agn_cfg)},
Jay Sternberge1228372009-01-19 15:30:34 -08004163/* 6000/6050 Series */
4164 {IWL_PCI_DEVICE(0x0082, 0x1102, iwl6000_2ag_cfg)},
4165 {IWL_PCI_DEVICE(0x0085, 0x1112, iwl6000_2ag_cfg)},
4166 {IWL_PCI_DEVICE(0x0082, 0x1122, iwl6000_2ag_cfg)},
4167 {IWL_PCI_DEVICE(0x422B, PCI_ANY_ID, iwl6000_3agn_cfg)},
4168 {IWL_PCI_DEVICE(0x4238, PCI_ANY_ID, iwl6000_3agn_cfg)},
4169 {IWL_PCI_DEVICE(0x0082, PCI_ANY_ID, iwl6000_2agn_cfg)},
4170 {IWL_PCI_DEVICE(0x0085, PCI_ANY_ID, iwl6000_3agn_cfg)},
4171 {IWL_PCI_DEVICE(0x0086, PCI_ANY_ID, iwl6050_3agn_cfg)},
4172 {IWL_PCI_DEVICE(0x0087, PCI_ANY_ID, iwl6050_2agn_cfg)},
4173 {IWL_PCI_DEVICE(0x0088, PCI_ANY_ID, iwl6050_3agn_cfg)},
4174 {IWL_PCI_DEVICE(0x0089, PCI_ANY_ID, iwl6050_2agn_cfg)},
Jay Sternbergc5d05692009-01-19 15:30:35 -08004175/* 100 Series WiFi */
4176 {IWL_PCI_DEVICE(0x0083, PCI_ANY_ID, iwl100_bgn_cfg)},
4177 {IWL_PCI_DEVICE(0x0084, PCI_ANY_ID, iwl100_bgn_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004178#endif /* CONFIG_IWL5000 */
Tomas Winkler7100e922008-12-01 16:32:18 -08004179
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004180 {0}
4181};
4182MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
4183
4184static struct pci_driver iwl_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07004185 .name = DRV_NAME,
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004186 .id_table = iwl_hw_card_ids,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004187 .probe = iwl_pci_probe,
4188 .remove = __devexit_p(iwl_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07004189#ifdef CONFIG_PM
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004190 .suspend = iwl_pci_suspend,
4191 .resume = iwl_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07004192#endif
4193};
4194
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004195static int __init iwl_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07004196{
4197
4198 int ret;
4199 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
4200 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004201
Tomas Winklere227cea2008-07-18 13:53:05 +08004202 ret = iwlagn_rate_control_register();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004203 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08004204 printk(KERN_ERR DRV_NAME
4205 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004206 return ret;
4207 }
4208
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004209 ret = pci_register_driver(&iwl_driver);
Zhu Yib481de92007-09-25 17:54:57 -07004210 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08004211 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004212 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07004213 }
Zhu Yib481de92007-09-25 17:54:57 -07004214
4215 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004216
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004217error_register:
Tomas Winklere227cea2008-07-18 13:53:05 +08004218 iwlagn_rate_control_unregister();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004219 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004220}
4221
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004222static void __exit iwl_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07004223{
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004224 pci_unregister_driver(&iwl_driver);
Tomas Winklere227cea2008-07-18 13:53:05 +08004225 iwlagn_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07004226}
4227
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004228module_exit(iwl_exit);
4229module_init(iwl_init);