blob: 5c6b3fe3eedfb6197a0c67b21a3ae96fa02fa47d [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
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700313static int iwl_send_bt_config(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700314{
Tomas Winkler2aa6ab82008-12-11 10:33:40 -0800315 struct iwl_bt_cmd bt_cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700316 .flags = 3,
317 .lead_time = 0xAA,
318 .max_kill = 1,
319 .kill_ack_mask = 0,
320 .kill_cts_mask = 0,
321 };
322
Tomas Winkler857485c2008-03-21 13:53:44 -0700323 return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
Tomas Winkler2aa6ab82008-12-11 10:33:40 -0800324 sizeof(struct iwl_bt_cmd), &bt_cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700325}
326
Tomas Winklerfcab4232008-05-15 13:54:01 +0800327static void iwl_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700328{
329 struct list_head *element;
330
331 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
332 priv->frames_count);
333
334 while (!list_empty(&priv->free_frames)) {
335 element = priv->free_frames.next;
336 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800337 kfree(list_entry(element, struct iwl_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700338 priv->frames_count--;
339 }
340
341 if (priv->frames_count) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800342 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
Zhu Yib481de92007-09-25 17:54:57 -0700343 priv->frames_count);
344 priv->frames_count = 0;
345 }
346}
347
Tomas Winklerfcab4232008-05-15 13:54:01 +0800348static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700349{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800350 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700351 struct list_head *element;
352 if (list_empty(&priv->free_frames)) {
353 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
354 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800355 IWL_ERR(priv, "Could not allocate frame!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700356 return NULL;
357 }
358
359 priv->frames_count++;
360 return frame;
361 }
362
363 element = priv->free_frames.next;
364 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800365 return list_entry(element, struct iwl_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700366}
367
Tomas Winklerfcab4232008-05-15 13:54:01 +0800368static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700369{
370 memset(frame, 0, sizeof(*frame));
371 list_add(&frame->list, &priv->free_frames);
372}
373
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800374static unsigned int iwl_fill_beacon_frame(struct iwl_priv *priv,
375 struct ieee80211_hdr *hdr,
Rami Rosen73ec1cc2008-12-16 09:37:07 +0200376 int left)
Zhu Yib481de92007-09-25 17:54:57 -0700377{
Tomas Winkler3109ece2008-03-28 16:33:35 -0700378 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200379 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
380 (priv->iw_mode != NL80211_IFTYPE_AP)))
Zhu Yib481de92007-09-25 17:54:57 -0700381 return 0;
382
383 if (priv->ibss_beacon->len > left)
384 return 0;
385
386 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
387
388 return priv->ibss_beacon->len;
389}
390
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700391static u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700392{
Guy Cohen39e88502008-04-23 17:14:57 -0700393 int i;
394 int rate_mask;
Zhu Yib481de92007-09-25 17:54:57 -0700395
Guy Cohen39e88502008-04-23 17:14:57 -0700396 /* Set rate mask*/
397 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
Chatre, Reinettedbce56a2008-11-12 13:14:07 -0800398 rate_mask = priv->active_rate_basic & IWL_CCK_RATES_MASK;
Guy Cohen39e88502008-04-23 17:14:57 -0700399 else
Chatre, Reinettedbce56a2008-11-12 13:14:07 -0800400 rate_mask = priv->active_rate_basic & IWL_OFDM_RATES_MASK;
Guy Cohen39e88502008-04-23 17:14:57 -0700401
402 /* Find lowest valid rate */
Zhu Yib481de92007-09-25 17:54:57 -0700403 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800404 i = iwl_rates[i].next_ieee) {
Zhu Yib481de92007-09-25 17:54:57 -0700405 if (rate_mask & (1 << i))
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800406 return iwl_rates[i].plcp;
Zhu Yib481de92007-09-25 17:54:57 -0700407 }
408
Guy Cohen39e88502008-04-23 17:14:57 -0700409 /* No valid rate was found. Assign the lowest one */
410 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
411 return IWL_RATE_1M_PLCP;
412 else
413 return IWL_RATE_6M_PLCP;
Zhu Yib481de92007-09-25 17:54:57 -0700414}
415
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700416static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800417 struct iwl_frame *frame, u8 rate)
418{
419 struct iwl_tx_beacon_cmd *tx_beacon_cmd;
420 unsigned int frame_size;
421
422 tx_beacon_cmd = &frame->u.beacon;
423 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
424
425 tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
426 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
427
428 frame_size = iwl_fill_beacon_frame(priv, tx_beacon_cmd->frame,
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800429 sizeof(frame->u) - sizeof(*tx_beacon_cmd));
430
431 BUG_ON(frame_size > MAX_MPDU_SIZE);
432 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
433
434 if ((rate == IWL_RATE_1M_PLCP) || (rate >= IWL_RATE_2M_PLCP))
435 tx_beacon_cmd->tx.rate_n_flags =
436 iwl_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK);
437 else
438 tx_beacon_cmd->tx.rate_n_flags =
439 iwl_hw_set_rate_n_flags(rate, 0);
440
441 tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
442 TX_CMD_FLG_TSF_MSK |
443 TX_CMD_FLG_STA_RATE_MSK;
444
445 return sizeof(*tx_beacon_cmd) + frame_size;
446}
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700447static int iwl_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700448{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800449 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700450 unsigned int frame_size;
451 int rc;
452 u8 rate;
453
Tomas Winklerfcab4232008-05-15 13:54:01 +0800454 frame = iwl_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700455
456 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800457 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
Zhu Yib481de92007-09-25 17:54:57 -0700458 "command.\n");
459 return -ENOMEM;
460 }
461
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700462 rate = iwl_rate_get_lowest_plcp(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700463
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700464 frame_size = iwl_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -0700465
Tomas Winkler857485c2008-03-21 13:53:44 -0700466 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700467 &frame->u.cmd[0]);
468
Tomas Winklerfcab4232008-05-15 13:54:01 +0800469 iwl_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700470
471 return rc;
472}
473
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800474static inline dma_addr_t iwl_tfd_tb_get_addr(struct iwl_tfd *tfd, u8 idx)
475{
476 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
477
478 dma_addr_t addr = get_unaligned_le32(&tb->lo);
479 if (sizeof(dma_addr_t) > sizeof(u32))
480 addr |=
481 ((dma_addr_t)(le16_to_cpu(tb->hi_n_len) & 0xF) << 16) << 16;
482
483 return addr;
484}
485
486static inline u16 iwl_tfd_tb_get_len(struct iwl_tfd *tfd, u8 idx)
487{
488 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
489
490 return le16_to_cpu(tb->hi_n_len) >> 4;
491}
492
493static inline void iwl_tfd_set_tb(struct iwl_tfd *tfd, u8 idx,
494 dma_addr_t addr, u16 len)
495{
496 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
497 u16 hi_n_len = len << 4;
498
499 put_unaligned_le32(addr, &tb->lo);
500 if (sizeof(dma_addr_t) > sizeof(u32))
501 hi_n_len |= ((addr >> 16) >> 16) & 0xF;
502
503 tb->hi_n_len = cpu_to_le16(hi_n_len);
504
505 tfd->num_tbs = idx + 1;
506}
507
508static inline u8 iwl_tfd_get_num_tbs(struct iwl_tfd *tfd)
509{
510 return tfd->num_tbs & 0x1f;
511}
512
513/**
514 * iwl_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
515 * @priv - driver private data
516 * @txq - tx queue
517 *
518 * Does NOT advance any TFD circular buffer read/write indexes
519 * Does NOT free the TFD itself (which is within circular buffer)
520 */
521void iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq)
522{
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800523 struct iwl_tfd *tfd_tmp = (struct iwl_tfd *)txq->tfds;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800524 struct iwl_tfd *tfd;
525 struct pci_dev *dev = priv->pci_dev;
526 int index = txq->q.read_ptr;
527 int i;
528 int num_tbs;
529
530 tfd = &tfd_tmp[index];
531
532 /* Sanity check on number of chunks */
533 num_tbs = iwl_tfd_get_num_tbs(tfd);
534
535 if (num_tbs >= IWL_NUM_OF_TBS) {
536 IWL_ERR(priv, "Too many chunks: %i\n", num_tbs);
537 /* @todo issue fatal error, it is quite serious situation */
538 return;
539 }
540
541 /* Unmap tx_cmd */
542 if (num_tbs)
543 pci_unmap_single(dev,
544 pci_unmap_addr(&txq->cmd[index]->meta, mapping),
545 pci_unmap_len(&txq->cmd[index]->meta, len),
546 PCI_DMA_TODEVICE);
547
548 /* Unmap chunks, if any. */
549 for (i = 1; i < num_tbs; i++) {
550 pci_unmap_single(dev, iwl_tfd_tb_get_addr(tfd, i),
551 iwl_tfd_tb_get_len(tfd, i), PCI_DMA_TODEVICE);
552
553 if (txq->txb) {
554 dev_kfree_skb(txq->txb[txq->q.read_ptr].skb[i - 1]);
555 txq->txb[txq->q.read_ptr].skb[i - 1] = NULL;
556 }
557 }
558}
559
560int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv,
561 struct iwl_tx_queue *txq,
562 dma_addr_t addr, u16 len,
563 u8 reset, u8 pad)
564{
565 struct iwl_queue *q;
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800566 struct iwl_tfd *tfd, *tfd_tmp;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800567 u32 num_tbs;
568
569 q = &txq->q;
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800570 tfd_tmp = (struct iwl_tfd *)txq->tfds;
571 tfd = &tfd_tmp[q->write_ptr];
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800572
573 if (reset)
574 memset(tfd, 0, sizeof(*tfd));
575
576 num_tbs = iwl_tfd_get_num_tbs(tfd);
577
578 /* Each TFD can point to a maximum 20 Tx buffers */
579 if (num_tbs >= IWL_NUM_OF_TBS) {
580 IWL_ERR(priv, "Error can not send more than %d chunks\n",
581 IWL_NUM_OF_TBS);
582 return -EINVAL;
583 }
584
585 BUG_ON(addr & ~DMA_BIT_MASK(36));
586 if (unlikely(addr & ~IWL_TX_DMA_MASK))
587 IWL_ERR(priv, "Unaligned address = %llx\n",
588 (unsigned long long)addr);
589
590 iwl_tfd_set_tb(tfd, num_tbs, addr, len);
591
592 return 0;
593}
594
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800595/*
596 * Tell nic where to find circular buffer of Tx Frame Descriptors for
597 * given Tx queue, and enable the DMA channel used for that queue.
598 *
599 * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
600 * channels supported in hardware.
601 */
602int iwl_hw_tx_queue_init(struct iwl_priv *priv,
603 struct iwl_tx_queue *txq)
604{
605 int ret;
606 unsigned long flags;
607 int txq_id = txq->q.id;
608
609 spin_lock_irqsave(&priv->lock, flags);
610 ret = iwl_grab_nic_access(priv);
611 if (ret) {
612 spin_unlock_irqrestore(&priv->lock, flags);
613 return ret;
614 }
615
616 /* Circular buffer (TFD queue in DRAM) physical base address */
617 iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
618 txq->q.dma_addr >> 8);
619
620 iwl_release_nic_access(priv);
621 spin_unlock_irqrestore(&priv->lock, flags);
622
623 return 0;
624}
625
626
Zhu Yib481de92007-09-25 17:54:57 -0700627/******************************************************************************
628 *
Zhu Yib481de92007-09-25 17:54:57 -0700629 * Misc. internal state and helper functions
630 *
631 ******************************************************************************/
Zhu Yib481de92007-09-25 17:54:57 -0700632
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700633static void iwl_ht_conf(struct iwl_priv *priv,
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700634 struct ieee80211_bss_conf *bss_conf)
635{
Johannes Bergae5eb022008-10-14 16:58:37 +0200636 struct ieee80211_sta_ht_cap *ht_conf;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700637 struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
Johannes Bergae5eb022008-10-14 16:58:37 +0200638 struct ieee80211_sta *sta;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700639
640 IWL_DEBUG_MAC80211("enter: \n");
641
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700642 if (!iwl_conf->is_ht)
643 return;
644
Johannes Bergae5eb022008-10-14 16:58:37 +0200645
646 /*
647 * It is totally wrong to base global information on something
648 * that is valid only when associated, alas, this driver works
649 * that way and I don't know how to fix it.
650 */
651
652 rcu_read_lock();
653 sta = ieee80211_find_sta(priv->hw, priv->bssid);
654 if (!sta) {
655 rcu_read_unlock();
656 return;
657 }
658 ht_conf = &sta->ht_cap;
659
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700660 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
Emmanuel Grumbacha9841012008-05-15 13:54:08 +0800661 iwl_conf->sgf |= HT_SHORT_GI_20MHZ;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700662 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
Emmanuel Grumbacha9841012008-05-15 13:54:08 +0800663 iwl_conf->sgf |= HT_SHORT_GI_40MHZ;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700664
665 iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
666 iwl_conf->max_amsdu_size =
667 !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
668
669 iwl_conf->supported_chan_width =
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200670 !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40);
Johannes Bergae5eb022008-10-14 16:58:37 +0200671
Sujith094d05d2008-12-12 11:57:43 +0530672 /*
673 * XXX: The HT configuration needs to be moved into iwl_mac_config()
674 * to be done there correctly.
675 */
676
677 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
Luis R. Rodriguezde27e642008-12-23 15:58:44 -0800678 if (conf_is_ht40_minus(&priv->hw->conf))
Sujith094d05d2008-12-12 11:57:43 +0530679 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
Luis R. Rodriguezde27e642008-12-23 15:58:44 -0800680 else if (conf_is_ht40_plus(&priv->hw->conf))
Sujith094d05d2008-12-12 11:57:43 +0530681 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
682
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700683 /* If no above or below channel supplied disable FAT channel */
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200684 if (iwl_conf->extension_chan_offset != IEEE80211_HT_PARAM_CHA_SEC_ABOVE &&
Sujith094d05d2008-12-12 11:57:43 +0530685 iwl_conf->extension_chan_offset != IEEE80211_HT_PARAM_CHA_SEC_BELOW)
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700686 iwl_conf->supported_chan_width = 0;
687
Ron Rindjunsky12837be2008-09-03 11:26:47 +0800688 iwl_conf->sm_ps = (u8)((ht_conf->cap & IEEE80211_HT_CAP_SM_PS) >> 2);
689
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200690 memcpy(&iwl_conf->mcs, &ht_conf->mcs, 16);
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700691
Sujith094d05d2008-12-12 11:57:43 +0530692 iwl_conf->tx_chan_width = iwl_conf->supported_chan_width != 0;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700693 iwl_conf->ht_protection =
Johannes Bergae5eb022008-10-14 16:58:37 +0200694 bss_conf->ht.operation_mode & IEEE80211_HT_OP_MODE_PROTECTION;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700695 iwl_conf->non_GF_STA_present =
Johannes Bergae5eb022008-10-14 16:58:37 +0200696 !!(bss_conf->ht.operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700697
Johannes Bergae5eb022008-10-14 16:58:37 +0200698 rcu_read_unlock();
699
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700700 IWL_DEBUG_MAC80211("leave\n");
701}
702
Zhu Yib481de92007-09-25 17:54:57 -0700703/*
704 * QoS support
705*/
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +0800706static void iwl_activate_qos(struct iwl_priv *priv, u8 force)
Zhu Yib481de92007-09-25 17:54:57 -0700707{
Zhu Yib481de92007-09-25 17:54:57 -0700708 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
709 return;
710
Zhu Yib481de92007-09-25 17:54:57 -0700711 priv->qos_data.def_qos_parm.qos_flags = 0;
712
713 if (priv->qos_data.qos_cap.q_AP.queue_request &&
714 !priv->qos_data.qos_cap.q_AP.txop_request)
715 priv->qos_data.def_qos_parm.qos_flags |=
716 QOS_PARAM_FLG_TXOP_TYPE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700717 if (priv->qos_data.qos_active)
718 priv->qos_data.def_qos_parm.qos_flags |=
719 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
720
Ron Rindjunskyfd105e72007-11-26 16:14:39 +0200721 if (priv->current_ht_config.is_ht)
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800722 priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800723
Tomas Winkler3109ece2008-03-28 16:33:35 -0700724 if (force || iwl_is_associated(priv)) {
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800725 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
726 priv->qos_data.qos_active,
727 priv->qos_data.def_qos_parm.qos_flags);
Zhu Yib481de92007-09-25 17:54:57 -0700728
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +0800729 iwl_send_cmd_pdu_async(priv, REPLY_QOS_PARAM,
730 sizeof(struct iwl_qosparam_cmd),
731 &priv->qos_data.def_qos_parm, NULL);
Zhu Yib481de92007-09-25 17:54:57 -0700732 }
733}
734
Zhu Yib481de92007-09-25 17:54:57 -0700735#define MAX_UCODE_BEACON_INTERVAL 4096
Zhu Yib481de92007-09-25 17:54:57 -0700736
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800737static u16 iwl_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -0700738{
739 u16 new_val = 0;
740 u16 beacon_factor = 0;
741
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800742 beacon_factor = (beacon_val + MAX_UCODE_BEACON_INTERVAL)
743 / MAX_UCODE_BEACON_INTERVAL;
Zhu Yib481de92007-09-25 17:54:57 -0700744 new_val = beacon_val / beacon_factor;
745
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800746 return new_val;
Zhu Yib481de92007-09-25 17:54:57 -0700747}
748
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800749static void iwl_setup_rxon_timing(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700750{
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800751 u64 tsf;
752 s32 interval_tm, rem;
Zhu Yib481de92007-09-25 17:54:57 -0700753 unsigned long flags;
754 struct ieee80211_conf *conf = NULL;
755 u16 beacon_int = 0;
756
757 conf = ieee80211_get_hw_conf(priv->hw);
758
759 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800760 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
Tomas Winklerb5d7be52008-07-19 04:41:24 +0300761 priv->rxon_timing.listen_interval = cpu_to_le16(conf->listen_interval);
Zhu Yib481de92007-09-25 17:54:57 -0700762
Johannes Berg05c914f2008-09-11 00:01:58 +0200763 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800764 beacon_int = iwl_adjust_beacon_interval(priv->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -0700765 priv->rxon_timing.atim_window = 0;
766 } else {
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800767 beacon_int = iwl_adjust_beacon_interval(conf->beacon_int);
768
Zhu Yib481de92007-09-25 17:54:57 -0700769 /* TODO: we need to get atim_window from upper stack
770 * for now we set to 0 */
771 priv->rxon_timing.atim_window = 0;
772 }
773
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800774 priv->rxon_timing.beacon_interval = cpu_to_le16(beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -0700775
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800776 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
777 interval_tm = beacon_int * 1024;
778 rem = do_div(tsf, interval_tm);
779 priv->rxon_timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
780
781 spin_unlock_irqrestore(&priv->lock, flags);
782 IWL_DEBUG_ASSOC("beacon interval %d beacon timer %d beacon tim %d\n",
783 le16_to_cpu(priv->rxon_timing.beacon_interval),
784 le32_to_cpu(priv->rxon_timing.beacon_init_val),
785 le16_to_cpu(priv->rxon_timing.atim_window));
Zhu Yib481de92007-09-25 17:54:57 -0700786}
787
Tomas Winkler82a66bb2008-05-29 16:35:28 +0800788static void iwl_set_flags_for_band(struct iwl_priv *priv,
789 enum ieee80211_band band)
Zhu Yib481de92007-09-25 17:54:57 -0700790{
Johannes Berg8318d782008-01-24 19:38:38 +0100791 if (band == IEEE80211_BAND_5GHZ) {
Zhu Yib481de92007-09-25 17:54:57 -0700792 priv->staging_rxon.flags &=
793 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
794 | RXON_FLG_CCK_MSK);
795 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
796 } else {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700797 /* Copied from iwl_post_associate() */
Zhu Yib481de92007-09-25 17:54:57 -0700798 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
799 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
800 else
801 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
802
Johannes Berg05c914f2008-09-11 00:01:58 +0200803 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -0700804 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
805
806 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
807 priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
808 priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
809 }
810}
811
812/*
Ian Schram01ebd062007-10-25 17:15:22 +0800813 * initialize rxon structure with default values from eeprom
Zhu Yib481de92007-09-25 17:54:57 -0700814 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700815static void iwl_connection_init_rx_config(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700816{
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700817 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -0700818
819 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
820
Zhu, Yi60294de2008-10-29 14:05:45 -0700821 switch (mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200822 case NL80211_IFTYPE_AP:
Zhu Yib481de92007-09-25 17:54:57 -0700823 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
824 break;
825
Johannes Berg05c914f2008-09-11 00:01:58 +0200826 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -0700827 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
828 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
829 break;
830
Johannes Berg05c914f2008-09-11 00:01:58 +0200831 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -0700832 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
833 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
834 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
835 RXON_FILTER_ACCEPT_GRP_MSK;
836 break;
837
Johannes Berg05c914f2008-09-11 00:01:58 +0200838 case NL80211_IFTYPE_MONITOR:
Zhu Yib481de92007-09-25 17:54:57 -0700839 priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
840 priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
841 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
842 break;
Tomas Winkler69dc5d92008-03-25 16:33:41 -0700843 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +0800844 IWL_ERR(priv, "Unsupported interface type %d\n", mode);
Tomas Winkler69dc5d92008-03-25 16:33:41 -0700845 break;
Zhu Yib481de92007-09-25 17:54:57 -0700846 }
847
848#if 0
849 /* TODO: Figure out when short_preamble would be set and cache from
850 * that */
851 if (!hw_to_local(priv->hw)->short_preamble)
852 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
853 else
854 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
855#endif
856
Assaf Krauss8622e702008-03-21 13:53:43 -0700857 ch_info = iwl_get_channel_info(priv, priv->band,
Rick Farrington25b3f572008-06-30 17:23:28 +0800858 le16_to_cpu(priv->active_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700859
860 if (!ch_info)
861 ch_info = &priv->channel_info[0];
862
863 /*
864 * in some case A channels are all non IBSS
865 * in this case force B/G channel
866 */
Johannes Berg05c914f2008-09-11 00:01:58 +0200867 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
Zhu Yib481de92007-09-25 17:54:57 -0700868 !(is_channel_ibss(ch_info)))
869 ch_info = &priv->channel_info[0];
870
871 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
Johannes Berg8318d782008-01-24 19:38:38 +0100872 priv->band = ch_info->band;
Zhu Yib481de92007-09-25 17:54:57 -0700873
Tomas Winkler82a66bb2008-05-29 16:35:28 +0800874 iwl_set_flags_for_band(priv, priv->band);
Zhu Yib481de92007-09-25 17:54:57 -0700875
876 priv->staging_rxon.ofdm_basic_rates =
877 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
878 priv->staging_rxon.cck_basic_rates =
879 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
880
881 priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
882 RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
883 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
884 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
885 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
886 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -0700887 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700888}
889
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700890static int iwl_set_mode(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700891{
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700892 iwl_connection_init_rx_config(priv, mode);
Zhu Yib481de92007-09-25 17:54:57 -0700893 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
894
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +0800895 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700896
Mohamed Abbasfde35712007-11-29 11:10:15 +0800897 /* dont commit rxon if rf-kill is on*/
Tomas Winklerfee12472008-04-03 16:05:21 -0700898 if (!iwl_is_ready_rf(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +0800899 return -EAGAIN;
900
901 cancel_delayed_work(&priv->scan_check);
Tomas Winkler2a421b92008-06-12 09:47:10 +0800902 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800903 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +0800904 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
905 return -EAGAIN;
906 }
907
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700908 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700909
910 return 0;
911}
912
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700913static void iwl_set_rate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700914{
Johannes Berg8318d782008-01-24 19:38:38 +0100915 const struct ieee80211_supported_band *hw = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700916 struct ieee80211_rate *rate;
917 int i;
918
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700919 hw = iwl_get_hw_mode(priv, priv->band);
Saleem Abdulrasoolc4ba9622007-11-18 23:59:08 -0800920 if (!hw) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800921 IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
Saleem Abdulrasoolc4ba9622007-11-18 23:59:08 -0800922 return;
923 }
Zhu Yib481de92007-09-25 17:54:57 -0700924
925 priv->active_rate = 0;
926 priv->active_rate_basic = 0;
927
Johannes Berg8318d782008-01-24 19:38:38 +0100928 for (i = 0; i < hw->n_bitrates; i++) {
929 rate = &(hw->bitrates[i]);
930 if (rate->hw_value < IWL_RATE_COUNT)
931 priv->active_rate |= (1 << rate->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -0700932 }
933
934 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
935 priv->active_rate, priv->active_rate_basic);
936
937 /*
938 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
939 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
940 * OFDM
941 */
942 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
943 priv->staging_rxon.cck_basic_rates =
944 ((priv->active_rate_basic &
945 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
946 else
947 priv->staging_rxon.cck_basic_rates =
948 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
949
950 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
951 priv->staging_rxon.ofdm_basic_rates =
952 ((priv->active_rate_basic &
953 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
954 IWL_FIRST_OFDM_RATE) & 0xFF;
955 else
956 priv->staging_rxon.ofdm_basic_rates =
957 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
958}
959
Zhu Yib481de92007-09-25 17:54:57 -0700960
Zhu Yib481de92007-09-25 17:54:57 -0700961/******************************************************************************
962 *
963 * Generic RX handler implementations
964 *
965 ******************************************************************************/
Tomas Winkler885ba202008-05-29 16:34:55 +0800966static void iwl_rx_reply_alive(struct iwl_priv *priv,
967 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700968{
Tomas Winklerdb11d632008-05-05 10:22:33 +0800969 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Tomas Winkler885ba202008-05-29 16:34:55 +0800970 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -0700971 struct delayed_work *pwork;
972
973 palive = &pkt->u.alive_frame;
974
975 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
976 "0x%01X 0x%01X\n",
977 palive->is_valid, palive->ver_type,
978 palive->ver_subtype);
979
980 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
981 IWL_DEBUG_INFO("Initialization Alive received.\n");
982 memcpy(&priv->card_alive_init,
983 &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +0800984 sizeof(struct iwl_init_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700985 pwork = &priv->init_alive_start;
986 } else {
987 IWL_DEBUG_INFO("Runtime Alive received.\n");
988 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +0800989 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700990 pwork = &priv->alive_start;
991 }
992
993 /* We delay the ALIVE response by 5ms to
994 * give the HW RF Kill time to activate... */
995 if (palive->is_valid == UCODE_VALID_OK)
996 queue_delayed_work(priv->workqueue, pwork,
997 msecs_to_jiffies(5));
998 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800999 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001000}
1001
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001002static void iwl_rx_reply_error(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001003 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001004{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001005 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001006
Winkler, Tomas15b16872008-12-19 10:37:33 +08001007 IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
Zhu Yib481de92007-09-25 17:54:57 -07001008 "seq 0x%04X ser 0x%08X\n",
1009 le32_to_cpu(pkt->u.err_resp.error_type),
1010 get_cmd_string(pkt->u.err_resp.cmd_id),
1011 pkt->u.err_resp.cmd_id,
1012 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
1013 le32_to_cpu(pkt->u.err_resp.error_info));
1014}
1015
1016#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1017
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001018static void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001019{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001020 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001021 struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
Tomas Winkler2aa6ab82008-12-11 10:33:40 -08001022 struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001023 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
1024 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
1025 rxon->channel = csa->channel;
1026 priv->staging_rxon.channel = csa->channel;
1027}
1028
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001029static void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001030 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001031{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001032#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklerdb11d632008-05-05 10:22:33 +08001033 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Tomas Winkler2aa6ab82008-12-11 10:33:40 -08001034 struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001035 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
1036 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
1037#endif
1038}
1039
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001040static void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001041 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001042{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001043 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001044 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
1045 "notification for %s:\n",
1046 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
Ester Kummerbf403db2008-05-05 10:22:40 +08001047 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
Zhu Yib481de92007-09-25 17:54:57 -07001048}
1049
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001050static void iwl_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07001051{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001052 struct iwl_priv *priv =
1053 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07001054 struct sk_buff *beacon;
1055
1056 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02001057 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07001058
1059 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001060 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07001061 return;
1062 }
1063
1064 mutex_lock(&priv->mutex);
1065 /* new beacon skb is allocated every time; dispose previous.*/
1066 if (priv->ibss_beacon)
1067 dev_kfree_skb(priv->ibss_beacon);
1068
1069 priv->ibss_beacon = beacon;
1070 mutex_unlock(&priv->mutex);
1071
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001072 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001073}
1074
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001075/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001076 * iwl_bg_statistics_periodic - Timer callback to queue statistics
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001077 *
1078 * This callback is provided in order to send a statistics request.
1079 *
1080 * This timer function is continually reset to execute within
1081 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
1082 * was received. We need to ensure we receive the statistics in order
1083 * to update the temperature used for calibrating the TXPOWER.
1084 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001085static void iwl_bg_statistics_periodic(unsigned long data)
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001086{
1087 struct iwl_priv *priv = (struct iwl_priv *)data;
1088
1089 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1090 return;
1091
Mohamed Abbas61780ee2008-10-29 14:05:49 -07001092 /* dont send host command if rf-kill is on */
1093 if (!iwl_is_ready_rf(priv))
1094 return;
1095
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001096 iwl_send_statistics_request(priv, CMD_ASYNC);
1097}
1098
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001099static void iwl_rx_beacon_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001100 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001101{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001102#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklerdb11d632008-05-05 10:22:33 +08001103 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Tomas Winkler2aa6ab82008-12-11 10:33:40 -08001104 struct iwl4965_beacon_notif *beacon =
1105 (struct iwl4965_beacon_notif *)pkt->u.raw;
Tomas Winklere7d326a2008-06-12 09:47:11 +08001106 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -07001107
1108 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
1109 "tsf %d %d rate %d\n",
Tomas Winkler25a65722008-06-12 09:47:07 +08001110 le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
Zhu Yib481de92007-09-25 17:54:57 -07001111 beacon->beacon_notify_hdr.failure_frame,
1112 le32_to_cpu(beacon->ibss_mgr_status),
1113 le32_to_cpu(beacon->high_tsf),
1114 le32_to_cpu(beacon->low_tsf), rate);
1115#endif
1116
Johannes Berg05c914f2008-09-11 00:01:58 +02001117 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -07001118 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1119 queue_work(priv->workqueue, &priv->beacon_update);
1120}
1121
Zhu Yib481de92007-09-25 17:54:57 -07001122/* Handle notification from uCode that card's power state is changing
1123 * due to software, hardware, or critical temperature RFKILL */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001124static void iwl_rx_card_state_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001125 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001126{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001127 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001128 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1129 unsigned long status = priv->status;
1130
1131 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
1132 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1133 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1134
1135 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
1136 RF_CARD_DISABLED)) {
1137
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001138 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001139 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1140
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001141 if (!iwl_grab_nic_access(priv)) {
1142 iwl_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07001143 priv, HBUS_TARG_MBX_C,
1144 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
1145
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001146 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001147 }
1148
1149 if (!(flags & RXON_CARD_DISABLED)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001150 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07001151 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001152 if (!iwl_grab_nic_access(priv)) {
1153 iwl_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07001154 priv, HBUS_TARG_MBX_C,
1155 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
1156
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001157 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001158 }
1159 }
1160
1161 if (flags & RF_CARD_DISABLED) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001162 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001163 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001164 iwl_read32(priv, CSR_UCODE_DRV_GP1);
1165 if (!iwl_grab_nic_access(priv))
1166 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001167 }
1168 }
1169
1170 if (flags & HW_CARD_DISABLED)
1171 set_bit(STATUS_RF_KILL_HW, &priv->status);
1172 else
1173 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1174
1175
1176 if (flags & SW_CARD_DISABLED)
1177 set_bit(STATUS_RF_KILL_SW, &priv->status);
1178 else
1179 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1180
1181 if (!(flags & RXON_CARD_DISABLED))
Tomas Winkler2a421b92008-06-12 09:47:10 +08001182 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001183
1184 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1185 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1186 (test_bit(STATUS_RF_KILL_SW, &status) !=
1187 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1188 queue_work(priv->workqueue, &priv->rf_kill);
1189 else
1190 wake_up_interruptible(&priv->wait_command_queue);
1191}
1192
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001193int iwl_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
Tomas Winklere2e3c572008-07-18 13:53:04 +08001194{
1195 int ret;
1196 unsigned long flags;
1197
1198 spin_lock_irqsave(&priv->lock, flags);
1199 ret = iwl_grab_nic_access(priv);
1200 if (ret)
1201 goto err;
1202
1203 if (src == IWL_PWR_SRC_VAUX) {
1204 u32 val;
Tomas Winklere7b63582008-09-03 11:26:49 +08001205 ret = pci_read_config_dword(priv->pci_dev, PCI_CFG_POWER_SOURCE,
Tomas Winklere2e3c572008-07-18 13:53:04 +08001206 &val);
1207
1208 if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT)
1209 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
1210 APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
1211 ~APMG_PS_CTRL_MSK_PWR_SRC);
1212 } else {
1213 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
1214 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
1215 ~APMG_PS_CTRL_MSK_PWR_SRC);
1216 }
1217
1218 iwl_release_nic_access(priv);
1219err:
1220 spin_unlock_irqrestore(&priv->lock, flags);
1221 return ret;
1222}
1223
Zhu Yib481de92007-09-25 17:54:57 -07001224/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001225 * iwl_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07001226 *
1227 * Setup the RX handlers for each of the reply types sent from the uCode
1228 * to the host.
1229 *
1230 * This function chains into the hardware specific files for them to setup
1231 * any hardware specific handlers as well.
1232 */
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08001233static void iwl_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001234{
Tomas Winkler885ba202008-05-29 16:34:55 +08001235 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001236 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
1237 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001238 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001239 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001240 iwl_rx_pm_debug_statistics_notif;
1241 priv->rx_handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001242
Ben Cahill9fbab512007-11-29 11:09:47 +08001243 /*
1244 * The same handler is used for both the REPLY to a discrete
1245 * statistics request from the host as well as for the periodic
1246 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07001247 */
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08001248 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_rx_statistics;
1249 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
Tomas Winkler2a421b92008-06-12 09:47:10 +08001250
Tomas Winkler21c339b2008-11-07 09:58:41 -08001251 iwl_setup_spectrum_handlers(priv);
Tomas Winkler2a421b92008-06-12 09:47:10 +08001252 iwl_setup_rx_scan_handlers(priv);
1253
Ron Rindjunsky37a44212008-05-29 16:35:18 +08001254 /* status change handler */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001255 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001256
Tomas Winklerc1354752008-05-29 16:35:04 +08001257 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
1258 iwl_rx_missed_beacon_notif;
Ron Rindjunsky37a44212008-05-29 16:35:18 +08001259 /* Rx handlers */
Emmanuel Grumbach1781a072008-06-30 17:23:09 +08001260 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl_rx_reply_rx_phy;
1261 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl_rx_reply_rx;
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08001262 /* block ack */
1263 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl_rx_reply_compressed_ba;
Ben Cahill9fbab512007-11-29 11:09:47 +08001264 /* Set up hardware specific Rx handlers */
Emmanuel Grumbachd4789ef2008-04-24 11:55:20 -07001265 priv->cfg->ops->lib->rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001266}
1267
Zhu Yib481de92007-09-25 17:54:57 -07001268/**
Tomas Winklera55360e2008-05-05 10:22:28 +08001269 * iwl_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001270 *
1271 * Uses the priv->rx_handlers callback function array to invoke
1272 * the appropriate handlers, including command responses,
1273 * frame-received notifications, and other notifications.
1274 */
Tomas Winklera55360e2008-05-05 10:22:28 +08001275void iwl_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001276{
Tomas Winklera55360e2008-05-05 10:22:28 +08001277 struct iwl_rx_mem_buffer *rxb;
Tomas Winklerdb11d632008-05-05 10:22:33 +08001278 struct iwl_rx_packet *pkt;
Tomas Winklera55360e2008-05-05 10:22:28 +08001279 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001280 u32 r, i;
1281 int reclaim;
1282 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001283 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001284 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07001285
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001286 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1287 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8d864222008-11-07 09:58:39 -08001288 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07001289 i = rxq->read;
1290
1291 /* Rx interrupt, but nothing sent from uCode */
1292 if (i == r)
Ester Kummerf3d67992008-05-06 11:05:12 +08001293 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001294
Tomas Winklera55360e2008-05-05 10:22:28 +08001295 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001296 fill_rx = 1;
1297
Zhu Yib481de92007-09-25 17:54:57 -07001298 while (i != r) {
1299 rxb = rxq->queue[i];
1300
Ben Cahill9fbab512007-11-29 11:09:47 +08001301 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001302 * then a bug has been introduced in the queue refilling
1303 * routines -- catch it here */
1304 BUG_ON(rxb == NULL);
1305
1306 rxq->queue[i] = NULL;
1307
Johannes Berge91af0a2008-11-19 01:22:51 +01001308 dma_sync_single_range_for_cpu(
1309 &priv->pci_dev->dev, rxb->real_dma_addr,
1310 rxb->aligned_dma_addr - rxb->real_dma_addr,
1311 priv->hw_params.rx_buf_size,
1312 PCI_DMA_FROMDEVICE);
Tomas Winklerdb11d632008-05-05 10:22:33 +08001313 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001314
1315 /* Reclaim a command buffer only if this packet is a response
1316 * to a (driver-originated) command.
1317 * If the packet (e.g. Rx frame) originated from uCode,
1318 * there is no command buffer to reclaim.
1319 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1320 * but apparently a few don't get set; catch them here. */
1321 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1322 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
Tomas Winkler857485c2008-03-21 13:53:44 -07001323 (pkt->hdr.cmd != REPLY_RX) &&
Daniel Halperin7dddaf12008-10-23 23:48:58 -07001324 (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) &&
Zhu Yicfe01702007-09-27 11:27:31 +08001325 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
Zhu Yib481de92007-09-25 17:54:57 -07001326 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1327 (pkt->hdr.cmd != REPLY_TX);
1328
1329 /* Based on type of command response or notification,
1330 * handle those that need handling via function in
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001331 * rx_handlers table. See iwl_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001332 if (priv->rx_handlers[pkt->hdr.cmd]) {
Ester Kummerf3d67992008-05-06 11:05:12 +08001333 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r,
1334 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001335 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1336 } else {
1337 /* No handling needed */
Ester Kummerf3d67992008-05-06 11:05:12 +08001338 IWL_DEBUG(IWL_DL_RX,
Zhu Yib481de92007-09-25 17:54:57 -07001339 "r %d i %d No handler needed for %s, 0x%02x\n",
1340 r, i, get_cmd_string(pkt->hdr.cmd),
1341 pkt->hdr.cmd);
1342 }
1343
1344 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001345 /* Invoke any callbacks, transfer the skb to caller, and
Tomas Winkler857485c2008-03-21 13:53:44 -07001346 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001347 * as we reclaim the driver command queue */
1348 if (rxb && rxb->skb)
Tomas Winkler17b88922008-05-29 16:35:12 +08001349 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001350 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001351 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07001352 }
1353
1354 /* For now we just don't re-use anything. We can tweak this
1355 * later to try and re-use notification packets and SKBs that
1356 * fail to Rx correctly */
1357 if (rxb->skb != NULL) {
1358 priv->alloc_rxb_skb--;
1359 dev_kfree_skb_any(rxb->skb);
1360 rxb->skb = NULL;
1361 }
1362
Johannes Berg40185172008-11-18 01:47:21 +01001363 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
1364 priv->hw_params.rx_buf_size + 256,
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02001365 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001366 spin_lock_irqsave(&rxq->lock, flags);
1367 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1368 spin_unlock_irqrestore(&rxq->lock, flags);
1369 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001370 /* If there are a lot of unused frames,
1371 * restock the Rx queue so ucode wont assert. */
1372 if (fill_rx) {
1373 count++;
1374 if (count >= 8) {
1375 priv->rxq.read = i;
Zhu Yif1bc4ac2008-12-17 16:52:33 +08001376 iwl_rx_queue_restock(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001377 count = 0;
1378 }
1379 }
Zhu Yib481de92007-09-25 17:54:57 -07001380 }
1381
1382 /* Backtrack one entry */
1383 priv->rxq.read = i;
Tomas Winklera55360e2008-05-05 10:22:28 +08001384 iwl_rx_queue_restock(priv);
1385}
Tomas Winklera55360e2008-05-05 10:22:28 +08001386
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001387#ifdef CONFIG_IWLWIFI_DEBUG
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001388static void iwl_print_rx_config_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001389{
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001390 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
Joe Perches0795af52007-10-03 17:59:30 -07001391
Zhu Yib481de92007-09-25 17:54:57 -07001392 IWL_DEBUG_RADIO("RX CONFIG:\n");
Ester Kummerbf403db2008-05-05 10:22:40 +08001393 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
Zhu Yib481de92007-09-25 17:54:57 -07001394 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
1395 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
1396 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
1397 le32_to_cpu(rxon->filter_flags));
1398 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
1399 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
1400 rxon->ofdm_basic_rates);
1401 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
Johannes Berge1749612008-10-27 15:59:26 -07001402 IWL_DEBUG_RADIO("u8[6] node_addr: %pM\n", rxon->node_addr);
1403 IWL_DEBUG_RADIO("u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07001404 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
1405}
1406#endif
1407
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001408/* call this function to flush any scheduled tasklet */
1409static inline void iwl_synchronize_irq(struct iwl_priv *priv)
1410{
Tomas Winklera96a27f2008-10-23 23:48:56 -07001411 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001412 synchronize_irq(priv->pci_dev->irq);
1413 tasklet_kill(&priv->irq_tasklet);
1414}
1415
Zhu Yib481de92007-09-25 17:54:57 -07001416/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001417 * iwl_irq_handle_error - called for HW or SW error interrupt from card
Zhu Yib481de92007-09-25 17:54:57 -07001418 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001419static void iwl_irq_handle_error(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001420{
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001421 /* Set the FW error flag -- cleared on iwl_down */
Zhu Yib481de92007-09-25 17:54:57 -07001422 set_bit(STATUS_FW_ERROR, &priv->status);
1423
1424 /* Cancel currently queued command. */
1425 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1426
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001427#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001428 if (priv->debug_level & IWL_DL_FW_ERRORS) {
Ester Kummerede0cba2008-05-29 16:34:46 +08001429 iwl_dump_nic_error_log(priv);
Ester Kummer189a2b52008-05-15 13:54:18 +08001430 iwl_dump_nic_event_log(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001431 iwl_print_rx_config_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001432 }
1433#endif
1434
1435 wake_up_interruptible(&priv->wait_command_queue);
1436
1437 /* Keep the restart process from trying to send host
1438 * commands by clearing the INIT status bit */
1439 clear_bit(STATUS_READY, &priv->status);
1440
1441 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Ester Kummerf3d67992008-05-06 11:05:12 +08001442 IWL_DEBUG(IWL_DL_FW_ERRORS,
Zhu Yib481de92007-09-25 17:54:57 -07001443 "Restarting adapter due to uCode error.\n");
1444
Tomas Winkler3109ece2008-03-28 16:33:35 -07001445 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001446 memcpy(&priv->recovery_rxon, &priv->active_rxon,
1447 sizeof(priv->recovery_rxon));
1448 priv->error_recovering = 1;
1449 }
Ester Kummer3a1081e2008-05-06 11:05:14 +08001450 if (priv->cfg->mod_params->restart_fw)
1451 queue_work(priv->workqueue, &priv->restart);
Zhu Yib481de92007-09-25 17:54:57 -07001452 }
1453}
1454
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001455static void iwl_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001456{
1457 unsigned long flags;
1458
1459 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
1460 sizeof(priv->staging_rxon));
1461 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001462 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001463
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08001464 iwl_rxon_add_station(priv, priv->bssid, 1);
Zhu Yib481de92007-09-25 17:54:57 -07001465
1466 spin_lock_irqsave(&priv->lock, flags);
1467 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
1468 priv->error_recovering = 0;
1469 spin_unlock_irqrestore(&priv->lock, flags);
1470}
1471
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001472static void iwl_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001473{
1474 u32 inta, handled = 0;
1475 u32 inta_fh;
1476 unsigned long flags;
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001477#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001478 u32 inta_mask;
1479#endif
1480
1481 spin_lock_irqsave(&priv->lock, flags);
1482
1483 /* Ack/clear/reset pending uCode interrupts.
1484 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1485 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001486 inta = iwl_read32(priv, CSR_INT);
1487 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07001488
1489 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1490 * Any new interrupts that happen after this, either while we're
1491 * in this tasklet, or later, will show up in next ISR/tasklet. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001492 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1493 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001494
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001495#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001496 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001497 /* just for debug */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001498 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07001499 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1500 inta, inta_mask, inta_fh);
1501 }
1502#endif
1503
1504 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1505 * atomic, make sure that inta covers all the interrupts that
1506 * we've discovered, even if FH interrupt came in just after
1507 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001508 if (inta_fh & CSR49_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001509 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001510 if (inta_fh & CSR49_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001511 inta |= CSR_INT_BIT_FH_TX;
1512
1513 /* Now service all interrupt bits discovered above. */
1514 if (inta & CSR_INT_BIT_HW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001515 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001516
1517 /* Tell the device to stop sending interrupts */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001518 iwl_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001519
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001520 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001521
1522 handled |= CSR_INT_BIT_HW_ERR;
1523
1524 spin_unlock_irqrestore(&priv->lock, flags);
1525
1526 return;
1527 }
1528
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001529#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001530 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07001531 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001532 if (inta & CSR_INT_BIT_SCD)
1533 IWL_DEBUG_ISR("Scheduler finished to transmit "
1534 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001535
1536 /* Alive notification via Rx interrupt will do the real work */
1537 if (inta & CSR_INT_BIT_ALIVE)
1538 IWL_DEBUG_ISR("Alive interrupt\n");
1539 }
1540#endif
1541 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001542 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07001543
Ben Cahill9fbab512007-11-29 11:09:47 +08001544 /* HW RF KILL switch toggled */
Zhu Yib481de92007-09-25 17:54:57 -07001545 if (inta & CSR_INT_BIT_RF_KILL) {
1546 int hw_rf_kill = 0;
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001547 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yib481de92007-09-25 17:54:57 -07001548 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
1549 hw_rf_kill = 1;
1550
Ester Kummerf3d67992008-05-06 11:05:12 +08001551 IWL_DEBUG(IWL_DL_RF_KILL, "RF_KILL bit toggled to %s.\n",
Abhijeet Kolekarc3056062008-11-12 13:14:08 -08001552 hw_rf_kill ? "disable radio" : "enable radio");
Zhu Yib481de92007-09-25 17:54:57 -07001553
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +08001554 /* driver only loads ucode once setting the interface up.
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01001555 * the driver allows loading the ucode even if the radio
1556 * is killed. Hence update the killswitch state here. The
1557 * rfkill handler will care about restarting if needed.
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +08001558 */
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01001559 if (!test_bit(STATUS_ALIVE, &priv->status)) {
1560 if (hw_rf_kill)
1561 set_bit(STATUS_RF_KILL_HW, &priv->status);
1562 else
1563 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1564 queue_work(priv->workqueue, &priv->rf_kill);
Mohamed Abbasedb34222008-12-11 10:33:37 -08001565 }
Zhu Yib481de92007-09-25 17:54:57 -07001566
1567 handled |= CSR_INT_BIT_RF_KILL;
1568 }
1569
Ben Cahill9fbab512007-11-29 11:09:47 +08001570 /* Chip got too hot and stopped itself */
Zhu Yib481de92007-09-25 17:54:57 -07001571 if (inta & CSR_INT_BIT_CT_KILL) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001572 IWL_ERR(priv, "Microcode CT kill error detected.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001573 handled |= CSR_INT_BIT_CT_KILL;
1574 }
1575
1576 /* Error detected by uCode */
1577 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001578 IWL_ERR(priv, "Microcode SW error detected. "
1579 " Restarting 0x%X.\n", inta);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001580 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001581 handled |= CSR_INT_BIT_SW_ERR;
1582 }
1583
1584 /* uCode wakes up after power-down sleep */
1585 if (inta & CSR_INT_BIT_WAKEUP) {
1586 IWL_DEBUG_ISR("Wakeup interrupt\n");
Tomas Winklera55360e2008-05-05 10:22:28 +08001587 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Tomas Winklerbabcebf2008-05-15 13:54:00 +08001588 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
1589 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
1590 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
1591 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
1592 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1593 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07001594
1595 handled |= CSR_INT_BIT_WAKEUP;
1596 }
1597
1598 /* All uCode command responses, including Tx command responses,
1599 * Rx "responses" (frame-received notification), and other
1600 * notifications from uCode come through here*/
1601 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Tomas Winklera55360e2008-05-05 10:22:28 +08001602 iwl_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001603 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1604 }
1605
1606 if (inta & CSR_INT_BIT_FH_TX) {
1607 IWL_DEBUG_ISR("Tx interrupt\n");
1608 handled |= CSR_INT_BIT_FH_TX;
Ron Rindjunskydbb983b2008-05-15 13:54:12 +08001609 /* FH finished to write, send event */
1610 priv->ucode_write_complete = 1;
1611 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07001612 }
1613
1614 if (inta & ~handled)
Winkler, Tomas15b16872008-12-19 10:37:33 +08001615 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Zhu Yib481de92007-09-25 17:54:57 -07001616
1617 if (inta & ~CSR_INI_SET_MASK) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001618 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Zhu Yib481de92007-09-25 17:54:57 -07001619 inta & ~CSR_INI_SET_MASK);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001620 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001621 }
1622
1623 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001624 /* only Re-enable if diabled by irq */
1625 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001626 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001627
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001628#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001629 if (priv->debug_level & (IWL_DL_ISR)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001630 inta = iwl_read32(priv, CSR_INT);
1631 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1632 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07001633 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
1634 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
1635 }
1636#endif
1637 spin_unlock_irqrestore(&priv->lock, flags);
1638}
1639
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001640static irqreturn_t iwl_isr(int irq, void *data)
Zhu Yib481de92007-09-25 17:54:57 -07001641{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001642 struct iwl_priv *priv = data;
Zhu Yib481de92007-09-25 17:54:57 -07001643 u32 inta, inta_mask;
1644 u32 inta_fh;
1645 if (!priv)
1646 return IRQ_NONE;
1647
1648 spin_lock(&priv->lock);
1649
1650 /* Disable (but don't clear!) interrupts here to avoid
1651 * back-to-back ISRs and sporadic interrupts from our NIC.
1652 * If we have something to service, the tasklet will re-enable ints.
1653 * If we *don't* have something, we'll re-enable before leaving here. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001654 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
1655 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07001656
1657 /* Discover which interrupts are active/pending */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001658 inta = iwl_read32(priv, CSR_INT);
1659 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07001660
1661 /* Ignore interrupt if there's nothing in NIC to service.
1662 * This may be due to IRQ shared with another device,
1663 * or due to sporadic interrupts thrown from our NIC. */
1664 if (!inta && !inta_fh) {
1665 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
1666 goto none;
1667 }
1668
1669 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
Oliver Neukum66fbb542007-11-15 09:31:10 +08001670 /* Hardware disappeared. It might have already raised
1671 * an interrupt */
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001672 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
Oliver Neukum66fbb542007-11-15 09:31:10 +08001673 goto unplugged;
Zhu Yib481de92007-09-25 17:54:57 -07001674 }
1675
1676 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1677 inta, inta_mask, inta_fh);
1678
Joonwoo Park25c03d82008-01-23 10:15:20 -08001679 inta &= ~CSR_INT_BIT_SCD;
1680
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001681 /* iwl_irq_tasklet() will service interrupts and re-enable them */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001682 if (likely(inta || inta_fh))
1683 tasklet_schedule(&priv->irq_tasklet);
Zhu Yib481de92007-09-25 17:54:57 -07001684
Oliver Neukum66fbb542007-11-15 09:31:10 +08001685 unplugged:
1686 spin_unlock(&priv->lock);
Zhu Yib481de92007-09-25 17:54:57 -07001687 return IRQ_HANDLED;
1688
1689 none:
1690 /* re-enable interrupts here since we don't have anything to service. */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001691 /* only Re-enable if diabled by irq */
1692 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001693 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001694 spin_unlock(&priv->lock);
1695 return IRQ_NONE;
1696}
1697
Zhu Yib481de92007-09-25 17:54:57 -07001698/******************************************************************************
1699 *
1700 * uCode download functions
1701 *
1702 ******************************************************************************/
1703
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001704static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001705{
Tomas Winkler98c92212008-01-14 17:46:20 -08001706 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
1707 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
1708 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1709 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
1710 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1711 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001712}
1713
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001714static void iwl_nic_start(struct iwl_priv *priv)
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08001715{
1716 /* Remove all resets to allow NIC to operate */
1717 iwl_write32(priv, CSR_RESET, 0);
1718}
1719
1720
Zhu Yib481de92007-09-25 17:54:57 -07001721/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001722 * iwl_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07001723 *
1724 * Copy into buffers for card to fetch via bus-mastering
1725 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001726static int iwl_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001727{
Ron Rindjunsky14b3d332008-06-13 15:44:54 +08001728 struct iwl_ucode *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001729 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07001730 const struct firmware *ucode_raw;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001731 const char *name_pre = priv->cfg->fw_name_pre;
1732 const unsigned int api_max = priv->cfg->ucode_api_max;
1733 const unsigned int api_min = priv->cfg->ucode_api_min;
1734 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07001735 u8 *src;
1736 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001737 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07001738
1739 /* Ask kernel firmware_class module to get the boot firmware off disk.
1740 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08001741 for (index = api_max; index >= api_min; index--) {
1742 sprintf(buf, "%s%d%s", name_pre, index, ".ucode");
1743 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
1744 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001745 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001746 buf, ret);
1747 if (ret == -ENOENT)
1748 continue;
1749 else
1750 goto error;
1751 } else {
1752 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08001753 IWL_ERR(priv, "Loaded firmware %s, "
1754 "which is deprecated. "
1755 "Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001756 buf, api_max);
Winkler, Tomas15b16872008-12-19 10:37:33 +08001757
Reinette Chatrea0987a82008-12-02 12:14:06 -08001758 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
1759 buf, ucode_raw->size);
1760 break;
1761 }
Zhu Yib481de92007-09-25 17:54:57 -07001762 }
1763
Reinette Chatrea0987a82008-12-02 12:14:06 -08001764 if (ret < 0)
1765 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07001766
1767 /* Make sure that we got at least our header! */
1768 if (ucode_raw->size < sizeof(*ucode)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001769 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001770 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001771 goto err_release;
1772 }
1773
1774 /* Data from ucode file: header followed by uCode images */
1775 ucode = (void *)ucode_raw->data;
1776
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08001777 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08001778 api_ver = IWL_UCODE_API(priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07001779 inst_size = le32_to_cpu(ucode->inst_size);
1780 data_size = le32_to_cpu(ucode->data_size);
1781 init_size = le32_to_cpu(ucode->init_size);
1782 init_data_size = le32_to_cpu(ucode->init_data_size);
1783 boot_size = le32_to_cpu(ucode->boot_size);
1784
Reinette Chatrea0987a82008-12-02 12:14:06 -08001785 /* api_ver should match the api version forming part of the
1786 * firmware filename ... but we don't check for that and only rely
1787 * on the API version read from firware header from here on forward */
1788
1789 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001790 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08001791 "Driver supports v%u, firmware is v%u.\n",
1792 api_max, api_ver);
1793 priv->ucode_ver = 0;
1794 ret = -EINVAL;
1795 goto err_release;
1796 }
1797 if (api_ver != api_max)
Tomas Winkler978785a2008-12-19 10:37:31 +08001798 IWL_ERR(priv, "Firmware has old API version. Expected v%u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08001799 "got v%u. New firmware can be obtained "
1800 "from http://www.intellinuxwireless.org.\n",
1801 api_max, api_ver);
1802
Tomas Winkler978785a2008-12-19 10:37:31 +08001803 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
1804 IWL_UCODE_MAJOR(priv->ucode_ver),
1805 IWL_UCODE_MINOR(priv->ucode_ver),
1806 IWL_UCODE_API(priv->ucode_ver),
1807 IWL_UCODE_SERIAL(priv->ucode_ver));
Reinette Chatrea0987a82008-12-02 12:14:06 -08001808
1809 IWL_DEBUG_INFO("f/w package hdr ucode version raw = 0x%x\n",
1810 priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07001811 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
1812 inst_size);
1813 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
1814 data_size);
1815 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
1816 init_size);
1817 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
1818 init_data_size);
1819 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
1820 boot_size);
1821
1822 /* Verify size of file vs. image size info in file's header */
1823 if (ucode_raw->size < sizeof(*ucode) +
1824 inst_size + data_size + init_size +
1825 init_data_size + boot_size) {
1826
1827 IWL_DEBUG_INFO("uCode file size %d too small\n",
1828 (int)ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001829 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001830 goto err_release;
1831 }
1832
1833 /* Verify that uCode images will fit in card's SRAM */
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001834 if (inst_size > priv->hw_params.max_inst_size) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08001835 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
1836 inst_size);
1837 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001838 goto err_release;
1839 }
1840
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001841 if (data_size > priv->hw_params.max_data_size) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08001842 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
1843 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 (init_size > priv->hw_params.max_inst_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001848 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001849 ("uCode init instr len %d too large to fit in\n",
1850 init_size);
1851 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001852 goto err_release;
1853 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001854 if (init_data_size > priv->hw_params.max_data_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001855 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001856 ("uCode init data len %d too large to fit in\n",
1857 init_data_size);
1858 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001859 goto err_release;
1860 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001861 if (boot_size > priv->hw_params.max_bsm_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001862 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001863 ("uCode boot instr len %d too large to fit in\n",
1864 boot_size);
1865 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001866 goto err_release;
1867 }
1868
1869 /* Allocate ucode buffers for card's bus-master loading ... */
1870
1871 /* Runtime instructions and 2 copies of data:
1872 * 1) unmodified from disk
1873 * 2) backup cache for save/restore during power-downs */
1874 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001875 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07001876
1877 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001878 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07001879
1880 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001881 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07001882
1883 /* Initialization instructions and data */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001884 if (init_size && init_data_size) {
1885 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001886 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Zhu Yib481de92007-09-25 17:54:57 -07001887
Tomas Winkler90e759d2007-11-29 11:09:41 +08001888 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001889 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001890
1891 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
1892 goto err_pci_alloc;
1893 }
Zhu Yib481de92007-09-25 17:54:57 -07001894
1895 /* Bootstrap (instructions only, no data) */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001896 if (boot_size) {
1897 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001898 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001899
Tomas Winkler90e759d2007-11-29 11:09:41 +08001900 if (!priv->ucode_boot.v_addr)
1901 goto err_pci_alloc;
1902 }
Zhu Yib481de92007-09-25 17:54:57 -07001903
1904 /* Copy images into buffers for card's bus-master reads ... */
1905
1906 /* Runtime instructions (first block of data in file) */
1907 src = &ucode->data[0];
1908 len = priv->ucode_code.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001909 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001910 memcpy(priv->ucode_code.v_addr, src, len);
1911 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
1912 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
1913
1914 /* Runtime data (2nd block)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001915 * NOTE: Copy into backup buffer will be done in iwl_up() */
Zhu Yib481de92007-09-25 17:54:57 -07001916 src = &ucode->data[inst_size];
1917 len = priv->ucode_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001918 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001919 memcpy(priv->ucode_data.v_addr, src, len);
1920 memcpy(priv->ucode_data_backup.v_addr, src, len);
1921
1922 /* Initialization instructions (3rd block) */
1923 if (init_size) {
1924 src = &ucode->data[inst_size + data_size];
1925 len = priv->ucode_init.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001926 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
1927 len);
Zhu Yib481de92007-09-25 17:54:57 -07001928 memcpy(priv->ucode_init.v_addr, src, len);
1929 }
1930
1931 /* Initialization data (4th block) */
1932 if (init_data_size) {
1933 src = &ucode->data[inst_size + data_size + init_size];
1934 len = priv->ucode_init_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001935 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
1936 len);
Zhu Yib481de92007-09-25 17:54:57 -07001937 memcpy(priv->ucode_init_data.v_addr, src, len);
1938 }
1939
1940 /* Bootstrap instructions (5th block) */
1941 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
1942 len = priv->ucode_boot.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001943 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001944 memcpy(priv->ucode_boot.v_addr, src, len);
1945
1946 /* We have our copies now, allow OS release its copies */
1947 release_firmware(ucode_raw);
1948 return 0;
1949
1950 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08001951 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001952 ret = -ENOMEM;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001953 iwl_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001954
1955 err_release:
1956 release_firmware(ucode_raw);
1957
1958 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08001959 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07001960}
1961
Mohamed Abbasada17512008-11-07 09:58:34 -08001962/* temporary */
1963static int iwl_mac_beacon_update(struct ieee80211_hw *hw,
1964 struct sk_buff *skb);
1965
Zhu Yib481de92007-09-25 17:54:57 -07001966/**
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001967 * iwl_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07001968 * from protocol/runtime uCode (initialization uCode's
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001969 * Alive gets handled by iwl_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07001970 */
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001971static void iwl_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001972{
Tomas Winkler57aab752008-04-14 21:16:03 -07001973 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001974
1975 IWL_DEBUG_INFO("Runtime Alive received.\n");
1976
1977 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
1978 /* We had an error bringing up the hardware, so take it
1979 * all the way back down so we can try again */
1980 IWL_DEBUG_INFO("Alive failed.\n");
1981 goto restart;
1982 }
1983
1984 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
1985 * This is a paranoid check, because we would not have gotten the
1986 * "runtime" alive if code weren't properly loaded. */
Emmanuel Grumbachb0692f22008-04-24 11:55:18 -07001987 if (iwl_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001988 /* Runtime instruction load was bad;
1989 * take it all the way back down so we can try again */
1990 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
1991 goto restart;
1992 }
1993
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08001994 iwl_clear_stations_table(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07001995 ret = priv->cfg->ops->lib->alive_notify(priv);
1996 if (ret) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001997 IWL_WARN(priv,
1998 "Could not complete ALIVE transition [ntf]: %d\n", ret);
Zhu Yib481de92007-09-25 17:54:57 -07001999 goto restart;
2000 }
2001
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002002 /* After the ALIVE response, we can send host commands to the uCode */
Zhu Yib481de92007-09-25 17:54:57 -07002003 set_bit(STATUS_ALIVE, &priv->status);
2004
Tomas Winklerfee12472008-04-03 16:05:21 -07002005 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002006 return;
2007
Johannes Berg36d68252008-05-15 12:55:26 +02002008 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002009
2010 priv->active_rate = priv->rates_mask;
2011 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
2012
Tomas Winkler3109ece2008-03-28 16:33:35 -07002013 if (iwl_is_associated(priv)) {
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08002014 struct iwl_rxon_cmd *active_rxon =
2015 (struct iwl_rxon_cmd *)&priv->active_rxon;
Zhu Yib481de92007-09-25 17:54:57 -07002016
2017 memcpy(&priv->staging_rxon, &priv->active_rxon,
2018 sizeof(priv->staging_rxon));
2019 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2020 } else {
2021 /* Initialize our rx_config data */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002022 iwl_connection_init_rx_config(priv, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002023 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2024 }
2025
Ben Cahill9fbab512007-11-29 11:09:47 +08002026 /* Configure Bluetooth device coexistence support */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002027 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002028
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002029 iwl_reset_run_time_calib(priv);
2030
Zhu Yib481de92007-09-25 17:54:57 -07002031 /* Configure the adapter for unassociated operation */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002032 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002033
2034 /* At this point, the NIC is initialized and operational */
Emmanuel Grumbach47f4a582008-06-12 09:47:13 +08002035 iwl_rf_kill_ct_config(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002036
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07002037 iwl_leds_register(priv);
2038
Zhu Yib481de92007-09-25 17:54:57 -07002039 IWL_DEBUG_INFO("ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07002040 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002041 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07002042
2043 if (priv->error_recovering)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002044 iwl_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002045
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08002046 iwl_power_update_mode(priv, 1);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002047
Mohamed Abbasada17512008-11-07 09:58:34 -08002048 /* reassociate for ADHOC mode */
2049 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
2050 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
2051 priv->vif);
2052 if (beacon)
2053 iwl_mac_beacon_update(priv->hw, beacon);
2054 }
2055
2056
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002057 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002058 iwl_set_mode(priv, priv->iw_mode);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002059
Zhu Yib481de92007-09-25 17:54:57 -07002060 return;
2061
2062 restart:
2063 queue_work(priv->workqueue, &priv->restart);
2064}
2065
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002066static void iwl_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07002067
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002068static void __iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002069{
2070 unsigned long flags;
2071 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002072
2073 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
2074
Zhu Yib481de92007-09-25 17:54:57 -07002075 if (!exit_pending)
2076 set_bit(STATUS_EXIT_PENDING, &priv->status);
2077
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07002078 iwl_leds_unregister(priv);
2079
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08002080 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002081
2082 /* Unblock any waiting calls */
2083 wake_up_interruptible_all(&priv->wait_command_queue);
2084
Zhu Yib481de92007-09-25 17:54:57 -07002085 /* Wipe out the EXIT_PENDING status bit if we are not actually
2086 * exiting the module */
2087 if (!exit_pending)
2088 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2089
2090 /* stop and reset the on-board processor */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002091 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07002092
2093 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002094 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002095 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002096 spin_unlock_irqrestore(&priv->lock, flags);
2097 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002098
2099 if (priv->mac80211_registered)
2100 ieee80211_stop_queues(priv->hw);
2101
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002102 /* If we have not previously called iwl_init() then
Zhu Yib481de92007-09-25 17:54:57 -07002103 * clear all bits but the RF Kill and SUSPEND bits and return */
Tomas Winklerfee12472008-04-03 16:05:21 -07002104 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002105 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2106 STATUS_RF_KILL_HW |
2107 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2108 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08002109 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2110 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002111 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002112 STATUS_IN_SUSPEND |
2113 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2114 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002115 goto exit;
2116 }
2117
2118 /* ...otherwise clear out all the status bits but the RF Kill and
2119 * SUSPEND bits and continue taking the NIC down. */
2120 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2121 STATUS_RF_KILL_HW |
2122 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2123 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08002124 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2125 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002126 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
2127 STATUS_IN_SUSPEND |
2128 test_bit(STATUS_FW_ERROR, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002129 STATUS_FW_ERROR |
2130 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2131 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002132
2133 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002134 iwl_clear_bit(priv, CSR_GP_CNTRL,
Ben Cahill9fbab512007-11-29 11:09:47 +08002135 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07002136 spin_unlock_irqrestore(&priv->lock, flags);
2137
Tomas Winklerda1bc452008-05-29 16:35:00 +08002138 iwl_txq_ctx_stop(priv);
Tomas Winklerb3bbacb2008-05-29 16:35:01 +08002139 iwl_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002140
2141 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002142 if (!iwl_grab_nic_access(priv)) {
2143 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002144 APMG_CLK_VAL_DMA_CLK_RQT);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002145 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002146 }
2147 spin_unlock_irqrestore(&priv->lock, flags);
2148
2149 udelay(5);
2150
Tomas Winkler7f066102008-05-29 16:34:57 +08002151 /* FIXME: apm_ops.suspend(priv) */
Gregory Greenmand5353112008-09-03 11:18:49 +08002152 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
2153 priv->cfg->ops->lib->apm_ops.stop(priv);
2154 else
2155 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002156 exit:
Tomas Winkler885ba202008-05-29 16:34:55 +08002157 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07002158
2159 if (priv->ibss_beacon)
2160 dev_kfree_skb(priv->ibss_beacon);
2161 priv->ibss_beacon = NULL;
2162
2163 /* clear out any free frames */
Tomas Winklerfcab4232008-05-15 13:54:01 +08002164 iwl_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002165}
2166
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002167static void iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002168{
2169 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002170 __iwl_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002171 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08002172
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002173 iwl_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002174}
2175
2176#define MAX_HW_RESTARTS 5
2177
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002178static int __iwl_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002179{
Tomas Winkler57aab752008-04-14 21:16:03 -07002180 int i;
2181 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002182
2183 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002184 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07002185 return -EIO;
2186 }
2187
Reinette Chatree903fbd2008-01-30 22:05:15 -08002188 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002189 IWL_ERR(priv, "ucode not available for device bringup\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08002190 return -EIO;
2191 }
2192
Zhu Yie655b9f2008-01-24 02:19:38 -08002193 /* If platform's RF_KILL switch is NOT set to KILL */
Tomas Winklerc1842d62008-08-04 16:00:43 +08002194 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
Zhu Yie655b9f2008-01-24 02:19:38 -08002195 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002196 else
Zhu Yie655b9f2008-01-24 02:19:38 -08002197 set_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002198
Tomas Winklerc1842d62008-08-04 16:00:43 +08002199 if (iwl_is_rfkill(priv)) {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002200 iwl_enable_interrupts(priv);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002201 IWL_WARN(priv, "Radio disabled by %s RF Kill switch\n",
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002202 test_bit(STATUS_RF_KILL_HW, &priv->status) ? "HW" : "SW");
Tomas Winklerc1842d62008-08-04 16:00:43 +08002203 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002204 }
2205
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002206 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07002207
Ron Rindjunsky1053d352008-05-05 10:22:43 +08002208 ret = iwl_hw_nic_init(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07002209 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002210 IWL_ERR(priv, "Unable to init nic\n");
Tomas Winkler57aab752008-04-14 21:16:03 -07002211 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002212 }
2213
2214 /* make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002215 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2216 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07002217 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2218
2219 /* clear (again), then enable host interrupts */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002220 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002221 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002222
2223 /* really make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002224 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2225 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07002226
2227 /* Copy original ucode data image from disk into backup cache.
2228 * This will be used to initialize the on-board processor's
2229 * data SRAM for a clean start when the runtime program first loads. */
2230 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a66926a2008-01-14 17:46:18 -08002231 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07002232
Zhu Yib481de92007-09-25 17:54:57 -07002233 for (i = 0; i < MAX_HW_RESTARTS; i++) {
2234
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08002235 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002236
2237 /* load bootstrap state machine,
2238 * load bootstrap program into processor's memory,
2239 * prepare to load the "initialize" uCode */
Tomas Winkler57aab752008-04-14 21:16:03 -07002240 ret = priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002241
Tomas Winkler57aab752008-04-14 21:16:03 -07002242 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002243 IWL_ERR(priv, "Unable to set up bootstrap uCode: %d\n",
2244 ret);
Zhu Yib481de92007-09-25 17:54:57 -07002245 continue;
2246 }
2247
Emmanuel Grumbachf3d5b452008-06-12 09:47:04 +08002248 /* Clear out the uCode error bit if it is set */
2249 clear_bit(STATUS_FW_ERROR, &priv->status);
2250
Zhu Yib481de92007-09-25 17:54:57 -07002251 /* start card; "initialize" will load runtime ucode */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002252 iwl_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002253
Zhu Yib481de92007-09-25 17:54:57 -07002254 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
2255
2256 return 0;
2257 }
2258
2259 set_bit(STATUS_EXIT_PENDING, &priv->status);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002260 __iwl_down(priv);
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08002261 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002262
2263 /* tried to restart and config the device for as long as our
2264 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002265 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07002266 return -EIO;
2267}
2268
2269
2270/*****************************************************************************
2271 *
2272 * Workqueue callbacks
2273 *
2274 *****************************************************************************/
2275
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002276static void iwl_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002277{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002278 struct iwl_priv *priv =
2279 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002280
2281 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2282 return;
2283
2284 mutex_lock(&priv->mutex);
Emmanuel Grumbachf3ccc082008-05-05 10:22:45 +08002285 priv->cfg->ops->lib->init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002286 mutex_unlock(&priv->mutex);
2287}
2288
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002289static void iwl_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002290{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002291 struct iwl_priv *priv =
2292 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002293
2294 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2295 return;
2296
2297 mutex_lock(&priv->mutex);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002298 iwl_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002299 mutex_unlock(&priv->mutex);
2300}
2301
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08002302static void iwl_bg_run_time_calib_work(struct work_struct *work)
2303{
2304 struct iwl_priv *priv = container_of(work, struct iwl_priv,
2305 run_time_calib_work);
2306
2307 mutex_lock(&priv->mutex);
2308
2309 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
2310 test_bit(STATUS_SCANNING, &priv->status)) {
2311 mutex_unlock(&priv->mutex);
2312 return;
2313 }
2314
2315 if (priv->start_calib) {
2316 iwl_chain_noise_calibration(priv, &priv->statistics);
2317
2318 iwl_sensitivity_calibration(priv, &priv->statistics);
2319 }
2320
2321 mutex_unlock(&priv->mutex);
2322 return;
2323}
2324
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002325static void iwl_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002326{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002327 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07002328
2329 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2330 return;
2331
2332 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002333 __iwl_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002334 mutex_unlock(&priv->mutex);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002335 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002336}
2337
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002338static void iwl_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002339{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002340 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07002341
2342 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2343 return;
2344
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002345 iwl_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002346 queue_work(priv->workqueue, &priv->up);
2347}
2348
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002349static void iwl_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002350{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002351 struct iwl_priv *priv =
2352 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07002353
2354 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2355 return;
2356
2357 mutex_lock(&priv->mutex);
Tomas Winklera55360e2008-05-05 10:22:28 +08002358 iwl_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002359 mutex_unlock(&priv->mutex);
2360}
2361
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002362#define IWL_DELAY_NEXT_SCAN (HZ*2)
2363
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002364static void iwl_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002365{
Zhu Yib481de92007-09-25 17:54:57 -07002366 struct ieee80211_conf *conf = NULL;
Tomas Winkler857485c2008-03-21 13:53:44 -07002367 int ret = 0;
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002368 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07002369
Johannes Berg05c914f2008-09-11 00:01:58 +02002370 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002371 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07002372 return;
2373 }
2374
Johannes Berge1749612008-10-27 15:59:26 -07002375 IWL_DEBUG_ASSOC("Associated as %d to: %pM\n",
2376 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07002377
2378
2379 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2380 return;
2381
Zhu Yib481de92007-09-25 17:54:57 -07002382
Reinette Chatre508e32e2008-04-14 21:16:13 -07002383 if (!priv->vif || !priv->is_open)
Mohamed Abbas948c1712007-10-25 17:15:45 +08002384 return;
Reinette Chatre508e32e2008-04-14 21:16:13 -07002385
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08002386 iwl_power_cancel_timeout(priv);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002387 iwl_scan_cancel_timeout(priv, 200);
mabbas052c4b92007-10-25 17:15:43 +08002388
Zhu Yib481de92007-09-25 17:54:57 -07002389 conf = ieee80211_get_hw_conf(priv->hw);
2390
2391 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002392 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002393
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002394 iwl_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002395 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002396 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002397 if (ret)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002398 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07002399 "Attempting to continue.\n");
2400
2401 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
2402
Emmanuel Grumbach42eb7c62008-09-17 10:10:05 +08002403 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03002404
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07002405 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002406 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2407
2408 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
2409 priv->assoc_id, priv->beacon_int);
2410
2411 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2412 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2413 else
2414 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2415
2416 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2417 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2418 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2419 else
2420 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2421
Johannes Berg05c914f2008-09-11 00:01:58 +02002422 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002423 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2424
2425 }
2426
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002427 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002428
2429 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02002430 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -07002431 break;
2432
Johannes Berg05c914f2008-09-11 00:01:58 +02002433 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07002434
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002435 /* assume default assoc id */
2436 priv->assoc_id = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002437
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002438 iwl_rxon_add_station(priv, priv->bssid, 0);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002439 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002440
2441 break;
2442
2443 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002444 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03002445 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002446 break;
2447 }
2448
Johannes Berg05c914f2008-09-11 00:01:58 +02002449 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002450 priv->assoc_station_added = 1;
2451
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002452 spin_lock_irqsave(&priv->lock, flags);
2453 iwl_activate_qos(priv, 0);
2454 spin_unlock_irqrestore(&priv->lock, flags);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08002455
Grumbach, Emmanuel04816442008-09-03 11:26:53 +08002456 /* the chain noise calibration will enabled PM upon completion
2457 * If chain noise has already been run, then we need to enable
2458 * power management here */
2459 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
2460 iwl_power_enable_management(priv);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08002461
2462 /* Enable Rx differential gain and sensitivity calibrations */
2463 iwl_chain_noise_reset(priv);
2464 priv->start_calib = 1;
2465
Reinette Chatre508e32e2008-04-14 21:16:13 -07002466}
2467
Zhu Yib481de92007-09-25 17:54:57 -07002468/*****************************************************************************
2469 *
2470 * mac80211 entry point functions
2471 *
2472 *****************************************************************************/
2473
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002474#define UCODE_READY_TIMEOUT (4 * HZ)
Zhu Yi5a66926a2008-01-14 17:46:18 -08002475
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002476static int iwl_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002477{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002478 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002479 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002480
2481 IWL_DEBUG_MAC80211("enter\n");
2482
2483 /* we should be verifying the device is ready to be opened */
2484 mutex_lock(&priv->mutex);
2485
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08002486 memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd));
Zhu Yi5a66926a2008-01-14 17:46:18 -08002487 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
2488 * ucode filename and max sizes are card-specific. */
2489
2490 if (!priv->ucode_code.len) {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002491 ret = iwl_read_ucode(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002492 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002493 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002494 mutex_unlock(&priv->mutex);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002495 return ret;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002496 }
2497 }
2498
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002499 ret = __iwl_up(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002500
Zhu Yib481de92007-09-25 17:54:57 -07002501 mutex_unlock(&priv->mutex);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002502
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002503 iwl_rfkill_set_hw_state(priv);
2504
Zhu Yie655b9f2008-01-24 02:19:38 -08002505 if (ret)
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002506 return ret;
Zhu Yie655b9f2008-01-24 02:19:38 -08002507
Tomas Winklerc1842d62008-08-04 16:00:43 +08002508 if (iwl_is_rfkill(priv))
2509 goto out;
2510
Zhu Yie655b9f2008-01-24 02:19:38 -08002511 IWL_DEBUG_INFO("Start UP work done.\n");
2512
2513 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
2514 return 0;
2515
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002516 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
Zhu Yi5a66926a2008-01-14 17:46:18 -08002517 * mac80211 will not be run successfully. */
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002518 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
2519 test_bit(STATUS_READY, &priv->status),
2520 UCODE_READY_TIMEOUT);
2521 if (!ret) {
2522 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002523 IWL_ERR(priv, "START_ALIVE timeout after %dms.\n",
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002524 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002525 return -ETIMEDOUT;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002526 }
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002527 }
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002528
Tomas Winklerc1842d62008-08-04 16:00:43 +08002529out:
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002530 priv->is_open = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002531 IWL_DEBUG_MAC80211("leave\n");
2532 return 0;
2533}
2534
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002535static void iwl_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002536{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002537 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002538
2539 IWL_DEBUG_MAC80211("enter\n");
Mohamed Abbas948c1712007-10-25 17:15:45 +08002540
Zhu Yie655b9f2008-01-24 02:19:38 -08002541 if (!priv->is_open) {
2542 IWL_DEBUG_MAC80211("leave - skip\n");
2543 return;
2544 }
2545
Zhu Yib481de92007-09-25 17:54:57 -07002546 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002547
Tomas Winklerfee12472008-04-03 16:05:21 -07002548 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08002549 /* stop mac, cancel any scan request and clear
2550 * RXON_FILTER_ASSOC_MSK BIT
2551 */
Zhu Yi5a66926a2008-01-14 17:46:18 -08002552 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002553 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002554 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002555 }
2556
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002557 iwl_down(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002558
2559 flush_workqueue(priv->workqueue);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002560
2561 /* enable interrupts again in order to receive rfkill changes */
2562 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
2563 iwl_enable_interrupts(priv);
Mohamed Abbas948c1712007-10-25 17:15:45 +08002564
Zhu Yib481de92007-09-25 17:54:57 -07002565 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002566}
2567
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002568static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07002569{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002570 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002571
Tomas Winklerf3674222008-08-04 16:00:44 +08002572 IWL_DEBUG_MACDUMP("enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002573
Zhu Yib481de92007-09-25 17:54:57 -07002574 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02002575 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07002576
Johannes Berge039fa42008-05-15 12:55:29 +02002577 if (iwl_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07002578 dev_kfree_skb_any(skb);
2579
Tomas Winklerf3674222008-08-04 16:00:44 +08002580 IWL_DEBUG_MACDUMP("leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08002581 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07002582}
2583
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002584static int iwl_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07002585 struct ieee80211_if_init_conf *conf)
2586{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002587 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002588 unsigned long flags;
2589
Johannes Berg32bfd352007-12-19 01:31:26 +01002590 IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07002591
Johannes Berg32bfd352007-12-19 01:31:26 +01002592 if (priv->vif) {
2593 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
Reinette Chatre75849d22008-01-23 10:15:17 -08002594 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07002595 }
2596
2597 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01002598 priv->vif = conf->vif;
Zhu, Yi60294de2008-10-29 14:05:45 -07002599 priv->iw_mode = conf->type;
Zhu Yib481de92007-09-25 17:54:57 -07002600
2601 spin_unlock_irqrestore(&priv->lock, flags);
2602
2603 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02002604
2605 if (conf->mac_addr) {
Johannes Berge1749612008-10-27 15:59:26 -07002606 IWL_DEBUG_MAC80211("Set %pM\n", conf->mac_addr);
Tomas Winkler864792e2007-11-27 21:00:52 +02002607 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
2608 }
Zhu Yib481de92007-09-25 17:54:57 -07002609
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002610 if (iwl_set_mode(priv, conf->type) == -EAGAIN)
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002611 /* we are not ready, will run again when ready */
2612 set_bit(STATUS_MODE_PENDING, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002613
Zhu Yib481de92007-09-25 17:54:57 -07002614 mutex_unlock(&priv->mutex);
2615
Zhu Yi5a66926a2008-01-14 17:46:18 -08002616 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002617 return 0;
2618}
2619
2620/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002621 * iwl_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07002622 *
2623 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
2624 * be set inappropriately and the driver currently sets the hardware up to
2625 * use it whenever needed.
2626 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002627static int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
Zhu Yib481de92007-09-25 17:54:57 -07002628{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002629 struct iwl_priv *priv = hw->priv;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07002630 const struct iwl_channel_info *ch_info;
Johannes Berge8975582008-10-09 12:18:51 +02002631 struct ieee80211_conf *conf = &hw->conf;
Zhu Yib481de92007-09-25 17:54:57 -07002632 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08002633 int ret = 0;
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002634 u16 channel;
Zhu Yib481de92007-09-25 17:54:57 -07002635
2636 mutex_lock(&priv->mutex);
Johannes Berg8318d782008-01-24 19:38:38 +01002637 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07002638
Luis R. Rodriguezde27e642008-12-23 15:58:44 -08002639 priv->current_ht_config.is_ht = conf_is_ht(conf);
Johannes Bergae5eb022008-10-14 16:58:37 +02002640
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +08002641 if (conf->radio_enabled && iwl_radio_kill_sw_enable_radio(priv)) {
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08002642 IWL_DEBUG_MAC80211("leave - RF-KILL - waiting for uCode\n");
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +08002643 goto out;
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08002644 }
2645
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +08002646 if (!conf->radio_enabled)
2647 iwl_radio_kill_sw_disable_radio(priv);
2648
Tomas Winklerfee12472008-04-03 16:05:21 -07002649 if (!iwl_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002650 IWL_DEBUG_MAC80211("leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002651 ret = -EIO;
2652 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002653 }
2654
Assaf Krauss1ea87392008-03-18 14:57:50 -07002655 if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07002656 test_bit(STATUS_SCANNING, &priv->status))) {
Zhu Yia0646472007-12-20 14:10:01 +08002657 IWL_DEBUG_MAC80211("leave - scanning\n");
Zhu Yib481de92007-09-25 17:54:57 -07002658 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08002659 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002660 }
2661
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002662 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2663 ch_info = iwl_get_channel_info(priv, conf->channel->band, channel);
Zhu Yib481de92007-09-25 17:54:57 -07002664 if (!is_channel_valid(ch_info)) {
Zhu Yib481de92007-09-25 17:54:57 -07002665 IWL_DEBUG_MAC80211("leave - invalid channel\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002666 ret = -EINVAL;
2667 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002668 }
2669
Johannes Berg05c914f2008-09-11 00:01:58 +02002670 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Assaf Krauss398f9e72008-06-12 09:47:06 +08002671 !is_channel_ibss(ch_info)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002672 IWL_ERR(priv, "channel %d in band %d not IBSS channel\n",
Assaf Krauss398f9e72008-06-12 09:47:06 +08002673 conf->channel->hw_value, conf->channel->band);
2674 ret = -EINVAL;
2675 goto out;
2676 }
2677
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002678 spin_lock_irqsave(&priv->lock, flags);
2679
Tomas Winklerb5d7be52008-07-19 04:41:24 +03002680
Tomas Winkler78330fd2008-02-06 02:37:18 +02002681 /* if we are switching from ht to 2.4 clear flags
Zhu Yib481de92007-09-25 17:54:57 -07002682 * from any ht related info since 2.4 does not
2683 * support ht */
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002684 if ((le16_to_cpu(priv->staging_rxon.channel) != channel)
Zhu Yib481de92007-09-25 17:54:57 -07002685#ifdef IEEE80211_CONF_CHANNEL_SWITCH
2686 && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
2687#endif
2688 )
2689 priv->staging_rxon.flags = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002690
Tomas Winkler17e72782008-09-03 11:26:26 +08002691 iwl_set_rxon_channel(priv, conf->channel);
Zhu Yib481de92007-09-25 17:54:57 -07002692
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002693 iwl_set_flags_for_band(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07002694
2695 /* The list of supported rates and rate mask can be different
Johannes Berg8318d782008-01-24 19:38:38 +01002696 * for each band; since the band may have changed, reset
Zhu Yib481de92007-09-25 17:54:57 -07002697 * the rate mask to what mac80211 lists */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002698 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002699
2700 spin_unlock_irqrestore(&priv->lock, flags);
2701
2702#ifdef IEEE80211_CONF_CHANNEL_SWITCH
2703 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002704 iwl_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08002705 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002706 }
2707#endif
2708
Zhu Yib481de92007-09-25 17:54:57 -07002709 if (!conf->radio_enabled) {
2710 IWL_DEBUG_MAC80211("leave - radio disabled\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002711 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002712 }
2713
Tomas Winklerfee12472008-04-03 16:05:21 -07002714 if (iwl_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002715 IWL_DEBUG_MAC80211("leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002716 ret = -EIO;
2717 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002718 }
2719
Ester Kummere602cb12008-09-26 15:09:33 +08002720 if (conf->flags & IEEE80211_CONF_PS)
2721 ret = iwl_power_set_user_mode(priv, IWL_POWER_INDEX_3);
2722 else
2723 ret = iwl_power_set_user_mode(priv, IWL_POWER_MODE_CAM);
2724 if (ret)
2725 IWL_DEBUG_MAC80211("Error setting power level\n");
2726
Tomas Winkler630fe9b2008-06-12 09:47:08 +08002727 IWL_DEBUG_MAC80211("TX Power old=%d new=%d\n",
2728 priv->tx_power_user_lmt, conf->power_level);
2729
2730 iwl_set_tx_power(priv, conf->power_level, false);
2731
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002732 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002733
Rick Farrington7b841722009-01-23 13:45:10 -08002734 /* call to ensure that 4965 rx_chain is set properly in monitor mode */
2735 iwl_set_rxon_chain(priv);
2736
Zhu Yib481de92007-09-25 17:54:57 -07002737 if (memcmp(&priv->active_rxon,
2738 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002739 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002740 else
2741 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
2742
2743 IWL_DEBUG_MAC80211("leave\n");
2744
Zhu Yia0646472007-12-20 14:10:01 +08002745out:
Zhu Yi5a66926a2008-01-14 17:46:18 -08002746 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08002747 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002748}
2749
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002750static void iwl_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002751{
Tomas Winkler857485c2008-03-21 13:53:44 -07002752 int ret = 0;
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002753 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07002754
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08002755 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07002756 return;
2757
2758 /* The following should be done only at AP bring up */
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002759 if (!iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002760
2761 /* RXON - unassoc (to set timing command) */
2762 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002763 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002764
2765 /* RXON Timing */
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002766 iwl_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002767 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002768 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002769 if (ret)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002770 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07002771 "Attempting to continue.\n");
2772
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07002773 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002774
2775 /* FIXME: what should be the assoc_id for AP? */
2776 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2777 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2778 priv->staging_rxon.flags |=
2779 RXON_FLG_SHORT_PREAMBLE_MSK;
2780 else
2781 priv->staging_rxon.flags &=
2782 ~RXON_FLG_SHORT_PREAMBLE_MSK;
2783
2784 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2785 if (priv->assoc_capability &
2786 WLAN_CAPABILITY_SHORT_SLOT_TIME)
2787 priv->staging_rxon.flags |=
2788 RXON_FLG_SHORT_SLOT_MSK;
2789 else
2790 priv->staging_rxon.flags &=
2791 ~RXON_FLG_SHORT_SLOT_MSK;
2792
Johannes Berg05c914f2008-09-11 00:01:58 +02002793 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002794 priv->staging_rxon.flags &=
2795 ~RXON_FLG_SHORT_SLOT_MSK;
2796 }
2797 /* restore RXON assoc */
2798 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002799 iwl_commit_rxon(priv);
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002800 spin_lock_irqsave(&priv->lock, flags);
2801 iwl_activate_qos(priv, 1);
2802 spin_unlock_irqrestore(&priv->lock, flags);
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002803 iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
Zhu Yie1493de2007-09-27 11:27:32 +08002804 }
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002805 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002806
2807 /* FIXME - we need to add code here to detect a totally new
2808 * configuration, reset the AP, unassoc, rxon timing, assoc,
2809 * clear sta table, add BCAST sta... */
2810}
2811
Johannes Berg9d139c82008-07-09 14:40:37 +02002812
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002813static int iwl_mac_config_interface(struct ieee80211_hw *hw,
Johannes Berg32bfd352007-12-19 01:31:26 +01002814 struct ieee80211_vif *vif,
Zhu Yib481de92007-09-25 17:54:57 -07002815 struct ieee80211_if_conf *conf)
2816{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002817 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002818 int rc;
2819
2820 if (conf == NULL)
2821 return -EIO;
2822
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08002823 if (priv->vif != vif) {
2824 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08002825 return 0;
2826 }
2827
Johannes Berg05c914f2008-09-11 00:01:58 +02002828 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Johannes Berg9d139c82008-07-09 14:40:37 +02002829 conf->changed & IEEE80211_IFCC_BEACON) {
2830 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
2831 if (!beacon)
2832 return -ENOMEM;
Mohamed Abbasada17512008-11-07 09:58:34 -08002833 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002834 rc = iwl_mac_beacon_update(hw, beacon);
Mohamed Abbasada17512008-11-07 09:58:34 -08002835 mutex_unlock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02002836 if (rc)
2837 return rc;
2838 }
2839
Tomas Winklerfee12472008-04-03 16:05:21 -07002840 if (!iwl_is_alive(priv))
Zhu Yi5a66926a2008-01-14 17:46:18 -08002841 return -EAGAIN;
2842
Zhu Yib481de92007-09-25 17:54:57 -07002843 mutex_lock(&priv->mutex);
2844
Zhu Yib481de92007-09-25 17:54:57 -07002845 if (conf->bssid)
Johannes Berge1749612008-10-27 15:59:26 -07002846 IWL_DEBUG_MAC80211("bssid: %pM\n", conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07002847
Johannes Berg4150c572007-09-17 01:29:23 -04002848/*
2849 * very dubious code was here; the probe filtering flag is never set:
2850 *
Zhu Yib481de92007-09-25 17:54:57 -07002851 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
2852 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04002853 */
Zhu Yib481de92007-09-25 17:54:57 -07002854
Johannes Berg05c914f2008-09-11 00:01:58 +02002855 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07002856 if (!conf->bssid) {
2857 conf->bssid = priv->mac_addr;
2858 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -07002859 IWL_DEBUG_MAC80211("bssid was set to: %pM\n",
2860 conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07002861 }
2862 if (priv->ibss_beacon)
2863 dev_kfree_skb(priv->ibss_beacon);
2864
Johannes Berg9d139c82008-07-09 14:40:37 +02002865 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
Zhu Yib481de92007-09-25 17:54:57 -07002866 }
2867
Tomas Winklerfee12472008-04-03 16:05:21 -07002868 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08002869 goto done;
2870
Zhu Yib481de92007-09-25 17:54:57 -07002871 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
2872 !is_multicast_ether_addr(conf->bssid)) {
2873 /* If there is currently a HW scan going on in the background
2874 * then we need to cancel it else the RXON below will fail. */
Tomas Winkler2a421b92008-06-12 09:47:10 +08002875 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002876 IWL_WARN(priv, "Aborted scan still in progress "
Zhu Yib481de92007-09-25 17:54:57 -07002877 "after 100ms\n");
2878 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2879 mutex_unlock(&priv->mutex);
2880 return -EAGAIN;
2881 }
2882 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
2883
2884 /* TODO: Audit driver for usage of these members and see
2885 * if mac80211 deprecates them (priv->bssid looks like it
2886 * shouldn't be there, but I haven't scanned the IBSS code
2887 * to verify) - jpk */
2888 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
2889
Johannes Berg05c914f2008-09-11 00:01:58 +02002890 if (priv->iw_mode == NL80211_IFTYPE_AP)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002891 iwl_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002892 else {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002893 rc = iwl_commit_rxon(priv);
Johannes Berg05c914f2008-09-11 00:01:58 +02002894 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002895 iwl_rxon_add_station(
Zhu Yib481de92007-09-25 17:54:57 -07002896 priv, priv->active_rxon.bssid_addr, 1);
2897 }
2898
2899 } else {
Tomas Winkler2a421b92008-06-12 09:47:10 +08002900 iwl_scan_cancel_timeout(priv, 100);
Zhu Yib481de92007-09-25 17:54:57 -07002901 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002902 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002903 }
2904
Mohamed Abbasfde35712007-11-29 11:10:15 +08002905 done:
Zhu Yib481de92007-09-25 17:54:57 -07002906 IWL_DEBUG_MAC80211("leave\n");
2907 mutex_unlock(&priv->mutex);
2908
2909 return 0;
2910}
2911
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002912static void iwl_configure_filter(struct ieee80211_hw *hw,
Johannes Berg4150c572007-09-17 01:29:23 -04002913 unsigned int changed_flags,
2914 unsigned int *total_flags,
2915 int mc_count, struct dev_addr_list *mc_list)
2916{
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08002917 struct iwl_priv *priv = hw->priv;
Zhu, Yi352bc8d2008-11-12 13:14:09 -08002918 __le32 *filter_flags = &priv->staging_rxon.filter_flags;
Rick Farrington25b3f572008-06-30 17:23:28 +08002919
Zhu, Yi352bc8d2008-11-12 13:14:09 -08002920 IWL_DEBUG_MAC80211("Enter: changed: 0x%x, total: 0x%x\n",
2921 changed_flags, *total_flags);
2922
2923 if (changed_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) {
2924 if (*total_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS))
2925 *filter_flags |= RXON_FILTER_PROMISC_MSK;
2926 else
2927 *filter_flags &= ~RXON_FILTER_PROMISC_MSK;
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08002928 }
Zhu, Yi352bc8d2008-11-12 13:14:09 -08002929 if (changed_flags & FIF_ALLMULTI) {
2930 if (*total_flags & FIF_ALLMULTI)
2931 *filter_flags |= RXON_FILTER_ACCEPT_GRP_MSK;
2932 else
2933 *filter_flags &= ~RXON_FILTER_ACCEPT_GRP_MSK;
2934 }
2935 if (changed_flags & FIF_CONTROL) {
2936 if (*total_flags & FIF_CONTROL)
2937 *filter_flags |= RXON_FILTER_CTL2HOST_MSK;
2938 else
2939 *filter_flags &= ~RXON_FILTER_CTL2HOST_MSK;
2940 }
2941 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
2942 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
2943 *filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
2944 else
2945 *filter_flags &= ~RXON_FILTER_BCON_AWARE_MSK;
2946 }
2947
2948 /* We avoid iwl_commit_rxon here to commit the new filter flags
2949 * since mac80211 will call ieee80211_hw_config immediately.
2950 * (mc_list is not supported at this time). Otherwise, we need to
2951 * queue a background iwl_commit_rxon work.
2952 */
2953
2954 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
Rick Farrington25b3f572008-06-30 17:23:28 +08002955 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
Johannes Berg4150c572007-09-17 01:29:23 -04002956}
2957
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002958static void iwl_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07002959 struct ieee80211_if_init_conf *conf)
2960{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002961 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002962
2963 IWL_DEBUG_MAC80211("enter\n");
2964
2965 mutex_lock(&priv->mutex);
Mohamed Abbas948c1712007-10-25 17:15:45 +08002966
Tomas Winklerfee12472008-04-03 16:05:21 -07002967 if (iwl_is_ready_rf(priv)) {
Tomas Winkler2a421b92008-06-12 09:47:10 +08002968 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002969 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002970 iwl_commit_rxon(priv);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002971 }
Johannes Berg32bfd352007-12-19 01:31:26 +01002972 if (priv->vif == conf->vif) {
2973 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07002974 memset(priv->bssid, 0, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07002975 }
2976 mutex_unlock(&priv->mutex);
2977
2978 IWL_DEBUG_MAC80211("leave\n");
2979
2980}
Johannes Berg471b3ef2007-12-28 14:32:58 +01002981
Tomas Winkler3109ece2008-03-28 16:33:35 -07002982#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002983static void iwl_bss_info_changed(struct ieee80211_hw *hw,
Johannes Berg471b3ef2007-12-28 14:32:58 +01002984 struct ieee80211_vif *vif,
2985 struct ieee80211_bss_conf *bss_conf,
2986 u32 changes)
Tomas Winkler220173b2007-10-16 00:50:25 +02002987{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002988 struct iwl_priv *priv = hw->priv;
Tomas Winkler220173b2007-10-16 00:50:25 +02002989
Tomas Winkler3109ece2008-03-28 16:33:35 -07002990 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
2991
Johannes Berg471b3ef2007-12-28 14:32:58 +01002992 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07002993 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
2994 bss_conf->use_short_preamble);
Johannes Berg471b3ef2007-12-28 14:32:58 +01002995 if (bss_conf->use_short_preamble)
Tomas Winkler220173b2007-10-16 00:50:25 +02002996 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2997 else
2998 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2999 }
3000
Johannes Berg471b3ef2007-12-28 14:32:58 +01003001 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07003002 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
Johannes Berg8318d782008-01-24 19:38:38 +01003003 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Tomas Winkler220173b2007-10-16 00:50:25 +02003004 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
3005 else
3006 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
3007 }
3008
Tomas Winkler98952d52008-03-28 16:33:33 -07003009 if (changes & BSS_CHANGED_HT) {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003010 iwl_ht_conf(priv, bss_conf);
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003011 iwl_set_rxon_chain(priv);
Tomas Winkler98952d52008-03-28 16:33:33 -07003012 }
3013
Johannes Berg471b3ef2007-12-28 14:32:58 +01003014 if (changes & BSS_CHANGED_ASSOC) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07003015 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
Reinette Chatre508e32e2008-04-14 21:16:13 -07003016 /* This should never happen as this function should
3017 * never be called from interrupt context. */
3018 if (WARN_ON_ONCE(in_interrupt()))
3019 return;
Tomas Winkler3109ece2008-03-28 16:33:35 -07003020 if (bss_conf->assoc) {
3021 priv->assoc_id = bss_conf->aid;
3022 priv->beacon_int = bss_conf->beacon_int;
Tomas Winklerb5d7be52008-07-19 04:41:24 +03003023 priv->power_data.dtim_period = bss_conf->dtim_period;
Tomas Winkler3109ece2008-03-28 16:33:35 -07003024 priv->timestamp = bss_conf->timestamp;
3025 priv->assoc_capability = bss_conf->assoc_capability;
Tomas Winkler9ccacb82008-09-16 14:01:03 +08003026
3027 /* we have just associated, don't start scan too early
3028 * leave time for EAPOL exchange to complete
3029 */
Tomas Winkler3109ece2008-03-28 16:33:35 -07003030 priv->next_scan_jiffies = jiffies +
3031 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
Reinette Chatre508e32e2008-04-14 21:16:13 -07003032 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003033 iwl_post_associate(priv);
Reinette Chatre508e32e2008-04-14 21:16:13 -07003034 mutex_unlock(&priv->mutex);
Tomas Winkler3109ece2008-03-28 16:33:35 -07003035 } else {
3036 priv->assoc_id = 0;
3037 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
3038 }
3039 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
3040 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
Tomas Winkler7e8c5192008-04-15 16:01:43 -07003041 iwl_send_rxon_assoc(priv);
Johannes Berg471b3ef2007-12-28 14:32:58 +01003042 }
3043
Tomas Winkler220173b2007-10-16 00:50:25 +02003044}
Zhu Yib481de92007-09-25 17:54:57 -07003045
Tomas Winklercb43dc22008-09-03 11:26:23 +08003046static int iwl_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t ssid_len)
Zhu Yib481de92007-09-25 17:54:57 -07003047{
Zhu Yib481de92007-09-25 17:54:57 -07003048 unsigned long flags;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003049 struct iwl_priv *priv = hw->priv;
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003050 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003051
3052 IWL_DEBUG_MAC80211("enter\n");
3053
mabbas052c4b92007-10-25 17:15:43 +08003054 mutex_lock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07003055 spin_lock_irqsave(&priv->lock, flags);
3056
Tomas Winklerfee12472008-04-03 16:05:21 -07003057 if (!iwl_is_ready_rf(priv)) {
Tomas Winklercb43dc22008-09-03 11:26:23 +08003058 ret = -EIO;
Zhu Yib481de92007-09-25 17:54:57 -07003059 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
3060 goto out_unlock;
3061 }
3062
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003063 /* We don't schedule scan within next_scan_jiffies period.
3064 * Avoid scanning during possible EAPOL exchange, return
3065 * success immediately.
3066 */
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003067 if (priv->next_scan_jiffies &&
Tomas Winklercb43dc22008-09-03 11:26:23 +08003068 time_after(priv->next_scan_jiffies, jiffies)) {
Ron Rindjunsky681c0052008-09-03 11:26:25 +08003069 IWL_DEBUG_SCAN("scan rejected: within next scan period\n");
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003070 queue_work(priv->workqueue, &priv->scan_completed);
3071 ret = 0;
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003072 goto out_unlock;
3073 }
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003074
Zhu Yib481de92007-09-25 17:54:57 -07003075 /* if we just finished scan ask for delay */
Ron Rindjunsky681c0052008-09-03 11:26:25 +08003076 if (iwl_is_associated(priv) && priv->last_scan_jiffies &&
Tomas Winklercb43dc22008-09-03 11:26:23 +08003077 time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN, jiffies)) {
Ron Rindjunsky681c0052008-09-03 11:26:25 +08003078 IWL_DEBUG_SCAN("scan rejected: within previous scan period\n");
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003079 queue_work(priv->workqueue, &priv->scan_completed);
3080 ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003081 goto out_unlock;
3082 }
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003083
Tomas Winklercb43dc22008-09-03 11:26:23 +08003084 if (ssid_len) {
Zhu Yib481de92007-09-25 17:54:57 -07003085 priv->one_direct_scan = 1;
Tomas Winklercb43dc22008-09-03 11:26:23 +08003086 priv->direct_ssid_len = min_t(u8, ssid_len, IW_ESSID_MAX_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07003087 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
Tomas Winklercb43dc22008-09-03 11:26:23 +08003088 } else {
Mohamed Abbas948c1712007-10-25 17:15:45 +08003089 priv->one_direct_scan = 0;
Tomas Winklercb43dc22008-09-03 11:26:23 +08003090 }
Zhu Yib481de92007-09-25 17:54:57 -07003091
Tomas Winklercb43dc22008-09-03 11:26:23 +08003092 ret = iwl_scan_initiate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003093
3094 IWL_DEBUG_MAC80211("leave\n");
3095
3096out_unlock:
3097 spin_unlock_irqrestore(&priv->lock, flags);
mabbas052c4b92007-10-25 17:15:43 +08003098 mutex_unlock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07003099
Tomas Winklercb43dc22008-09-03 11:26:23 +08003100 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003101}
3102
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003103static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw,
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003104 struct ieee80211_key_conf *keyconf, const u8 *addr,
3105 u32 iv32, u16 *phase1key)
3106{
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003107
Tomas Winkler9f586712008-11-12 13:14:05 -08003108 struct iwl_priv *priv = hw->priv;
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003109 IWL_DEBUG_MAC80211("enter\n");
3110
Tomas Winkler9f586712008-11-12 13:14:05 -08003111 iwl_update_tkip_key(priv, keyconf, addr, iv32, phase1key);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003112
3113 IWL_DEBUG_MAC80211("leave\n");
3114}
3115
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003116static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01003117 struct ieee80211_vif *vif,
3118 struct ieee80211_sta *sta,
Zhu Yib481de92007-09-25 17:54:57 -07003119 struct ieee80211_key_conf *key)
3120{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003121 struct iwl_priv *priv = hw->priv;
Winkler, Tomas42986792009-01-19 15:30:22 -08003122 const u8 *addr;
3123 int ret;
3124 u8 sta_id;
3125 bool is_default_wep_key = false;
Zhu Yib481de92007-09-25 17:54:57 -07003126
3127 IWL_DEBUG_MAC80211("enter\n");
3128
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07003129 if (priv->hw_params.sw_crypto) {
Zhu Yib481de92007-09-25 17:54:57 -07003130 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
3131 return -EOPNOTSUPP;
3132 }
Winkler, Tomas42986792009-01-19 15:30:22 -08003133 addr = sta ? sta->addr : iwl_bcast_addr;
Tomas Winkler947b13a2008-04-16 16:34:48 -07003134 sta_id = iwl_find_station(priv, addr);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003135 if (sta_id == IWL_INVALID_STATION) {
Johannes Berge1749612008-10-27 15:59:26 -07003136 IWL_DEBUG_MAC80211("leave - %pM not in station map.\n",
3137 addr);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003138 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003139
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003140 }
Zhu Yib481de92007-09-25 17:54:57 -07003141
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003142 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08003143 iwl_scan_cancel_timeout(priv, 100);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003144 mutex_unlock(&priv->mutex);
3145
3146 /* If we are getting WEP group key and we didn't receive any key mapping
3147 * so far, we are in legacy wep mode (group key only), otherwise we are
3148 * in 1X mode.
3149 * In legacy wep mode, we use another host command to the uCode */
Tomas Winkler5425e492008-04-15 16:01:38 -07003150 if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
Johannes Berg05c914f2008-09-11 00:01:58 +02003151 priv->iw_mode != NL80211_IFTYPE_AP) {
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003152 if (cmd == SET_KEY)
3153 is_default_wep_key = !priv->key_mapping_key;
3154 else
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +08003155 is_default_wep_key =
3156 (key->hw_key_idx == HW_KEY_DEFAULT);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003157 }
mabbas052c4b92007-10-25 17:15:43 +08003158
Zhu Yib481de92007-09-25 17:54:57 -07003159 switch (cmd) {
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003160 case SET_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003161 if (is_default_wep_key)
3162 ret = iwl_set_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003163 else
Emmanuel Grumbach74805132008-04-14 21:16:09 -07003164 ret = iwl_set_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003165
3166 IWL_DEBUG_MAC80211("enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003167 break;
3168 case DISABLE_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003169 if (is_default_wep_key)
3170 ret = iwl_remove_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003171 else
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07003172 ret = iwl_remove_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003173
3174 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003175 break;
3176 default:
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003177 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003178 }
3179
3180 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003181
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003182 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003183}
3184
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003185static int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
Zhu Yib481de92007-09-25 17:54:57 -07003186 const struct ieee80211_tx_queue_params *params)
3187{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003188 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003189 unsigned long flags;
3190 int q;
Zhu Yib481de92007-09-25 17:54:57 -07003191
3192 IWL_DEBUG_MAC80211("enter\n");
3193
Tomas Winklerfee12472008-04-03 16:05:21 -07003194 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003195 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3196 return -EIO;
3197 }
3198
3199 if (queue >= AC_NUM) {
3200 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
3201 return 0;
3202 }
3203
Zhu Yib481de92007-09-25 17:54:57 -07003204 q = AC_NUM - 1 - queue;
3205
3206 spin_lock_irqsave(&priv->lock, flags);
3207
3208 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
3209 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
3210 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
3211 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7b2008-02-10 16:49:38 +01003212 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07003213
3214 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
3215 priv->qos_data.qos_active = 1;
3216
Johannes Berg05c914f2008-09-11 00:01:58 +02003217 if (priv->iw_mode == NL80211_IFTYPE_AP)
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08003218 iwl_activate_qos(priv, 1);
Tomas Winkler3109ece2008-03-28 16:33:35 -07003219 else if (priv->assoc_id && iwl_is_associated(priv))
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08003220 iwl_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003221
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08003222 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -07003223
Zhu Yib481de92007-09-25 17:54:57 -07003224 IWL_DEBUG_MAC80211("leave\n");
3225 return 0;
3226}
3227
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003228static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
Tomas Winklerd783b062008-07-18 13:53:02 +08003229 enum ieee80211_ampdu_mlme_action action,
Johannes Berg17741cd2008-09-11 00:02:02 +02003230 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
Tomas Winklerd783b062008-07-18 13:53:02 +08003231{
3232 struct iwl_priv *priv = hw->priv;
Tomas Winklerd783b062008-07-18 13:53:02 +08003233
Johannes Berge1749612008-10-27 15:59:26 -07003234 IWL_DEBUG_HT("A-MPDU action on addr %pM tid %d\n",
3235 sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08003236
3237 if (!(priv->cfg->sku & IWL_SKU_N))
3238 return -EACCES;
3239
3240 switch (action) {
3241 case IEEE80211_AMPDU_RX_START:
3242 IWL_DEBUG_HT("start Rx\n");
Tomas Winkler9f586712008-11-12 13:14:05 -08003243 return iwl_sta_rx_agg_start(priv, sta->addr, tid, *ssn);
Tomas Winklerd783b062008-07-18 13:53:02 +08003244 case IEEE80211_AMPDU_RX_STOP:
3245 IWL_DEBUG_HT("stop Rx\n");
Tomas Winkler9f586712008-11-12 13:14:05 -08003246 return iwl_sta_rx_agg_stop(priv, sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08003247 case IEEE80211_AMPDU_TX_START:
3248 IWL_DEBUG_HT("start Tx\n");
Johannes Berg17741cd2008-09-11 00:02:02 +02003249 return iwl_tx_agg_start(priv, sta->addr, tid, ssn);
Tomas Winklerd783b062008-07-18 13:53:02 +08003250 case IEEE80211_AMPDU_TX_STOP:
3251 IWL_DEBUG_HT("stop Tx\n");
Johannes Berg17741cd2008-09-11 00:02:02 +02003252 return iwl_tx_agg_stop(priv, sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08003253 default:
3254 IWL_DEBUG_HT("unknown\n");
3255 return -EINVAL;
3256 break;
3257 }
3258 return 0;
3259}
Tomas Winkler9f586712008-11-12 13:14:05 -08003260
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003261static int iwl_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003262 struct ieee80211_tx_queue_stats *stats)
3263{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003264 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003265 int i, avail;
Ron Rindjunsky16466902008-05-05 10:22:50 +08003266 struct iwl_tx_queue *txq;
Tomas Winkler443cfd42008-05-15 13:53:57 +08003267 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07003268 unsigned long flags;
3269
3270 IWL_DEBUG_MAC80211("enter\n");
3271
Tomas Winklerfee12472008-04-03 16:05:21 -07003272 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003273 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3274 return -EIO;
3275 }
3276
3277 spin_lock_irqsave(&priv->lock, flags);
3278
3279 for (i = 0; i < AC_NUM; i++) {
3280 txq = &priv->txq[i];
3281 q = &txq->q;
Tomas Winkler443cfd42008-05-15 13:53:57 +08003282 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07003283
Johannes Berg57ffc582008-04-29 17:18:59 +02003284 stats[i].len = q->n_window - avail;
3285 stats[i].limit = q->n_window - q->high_mark;
3286 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07003287
3288 }
3289 spin_unlock_irqrestore(&priv->lock, flags);
3290
3291 IWL_DEBUG_MAC80211("leave\n");
3292
3293 return 0;
3294}
3295
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003296static int iwl_mac_get_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003297 struct ieee80211_low_level_stats *stats)
3298{
Ester Kummerbf403db2008-05-05 10:22:40 +08003299 struct iwl_priv *priv = hw->priv;
3300
3301 priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003302 IWL_DEBUG_MAC80211("enter\n");
3303 IWL_DEBUG_MAC80211("leave\n");
3304
3305 return 0;
3306}
3307
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003308static void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003309{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003310 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003311 unsigned long flags;
3312
3313 mutex_lock(&priv->mutex);
3314 IWL_DEBUG_MAC80211("enter\n");
3315
Zhu Yib481de92007-09-25 17:54:57 -07003316 spin_lock_irqsave(&priv->lock, flags);
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02003317 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
Zhu Yib481de92007-09-25 17:54:57 -07003318 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -07003319
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003320 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003321
Zhu Yib481de92007-09-25 17:54:57 -07003322 spin_lock_irqsave(&priv->lock, flags);
3323 priv->assoc_id = 0;
3324 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003325 priv->assoc_station_added = 0;
3326
3327 /* new association get rid of ibss beacon skb */
3328 if (priv->ibss_beacon)
3329 dev_kfree_skb(priv->ibss_beacon);
3330
3331 priv->ibss_beacon = NULL;
3332
3333 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler3109ece2008-03-28 16:33:35 -07003334 priv->timestamp = 0;
Johannes Berg05c914f2008-09-11 00:01:58 +02003335 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
Zhu Yib481de92007-09-25 17:54:57 -07003336 priv->beacon_int = 0;
3337
3338 spin_unlock_irqrestore(&priv->lock, flags);
3339
Tomas Winklerfee12472008-04-03 16:05:21 -07003340 if (!iwl_is_ready_rf(priv)) {
Mohamed Abbasfde35712007-11-29 11:10:15 +08003341 IWL_DEBUG_MAC80211("leave - not ready\n");
3342 mutex_unlock(&priv->mutex);
3343 return;
3344 }
3345
mabbas052c4b92007-10-25 17:15:43 +08003346 /* we are restarting association process
3347 * clear RXON_FILTER_ASSOC_MSK bit
3348 */
Johannes Berg05c914f2008-09-11 00:01:58 +02003349 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Tomas Winkler2a421b92008-06-12 09:47:10 +08003350 iwl_scan_cancel_timeout(priv, 100);
mabbas052c4b92007-10-25 17:15:43 +08003351 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003352 iwl_commit_rxon(priv);
mabbas052c4b92007-10-25 17:15:43 +08003353 }
3354
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003355 iwl_power_update_mode(priv, 0);
3356
Zhu Yib481de92007-09-25 17:54:57 -07003357 /* Per mac80211.h: This is only used in IBSS mode... */
Johannes Berg05c914f2008-09-11 00:01:58 +02003358 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
mabbas052c4b92007-10-25 17:15:43 +08003359
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08003360 /* switch to CAM during association period.
3361 * the ucode will block any association/authentication
3362 * frome during assiciation period if it can not hear
3363 * the AP because of PM. the timer enable PM back is
3364 * association do not complete
3365 */
3366 if (priv->hw->conf.channel->flags & (IEEE80211_CHAN_PASSIVE_SCAN |
3367 IEEE80211_CHAN_RADAR))
3368 iwl_power_disable_management(priv, 3000);
3369
Zhu Yib481de92007-09-25 17:54:57 -07003370 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
3371 mutex_unlock(&priv->mutex);
3372 return;
3373 }
3374
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003375 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003376
3377 mutex_unlock(&priv->mutex);
3378
3379 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003380}
3381
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003382static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003383{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003384 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003385 unsigned long flags;
Assaf Krauss2ff75b72008-06-30 17:23:17 +08003386 __le64 timestamp;
Zhu Yib481de92007-09-25 17:54:57 -07003387
Zhu Yib481de92007-09-25 17:54:57 -07003388 IWL_DEBUG_MAC80211("enter\n");
3389
Tomas Winklerfee12472008-04-03 16:05:21 -07003390 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003391 IWL_DEBUG_MAC80211("leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07003392 return -EIO;
3393 }
3394
Johannes Berg05c914f2008-09-11 00:01:58 +02003395 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Zhu Yib481de92007-09-25 17:54:57 -07003396 IWL_DEBUG_MAC80211("leave - not IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07003397 return -EIO;
3398 }
3399
3400 spin_lock_irqsave(&priv->lock, flags);
3401
3402 if (priv->ibss_beacon)
3403 dev_kfree_skb(priv->ibss_beacon);
3404
3405 priv->ibss_beacon = skb;
3406
3407 priv->assoc_id = 0;
Assaf Krauss2ff75b72008-06-30 17:23:17 +08003408 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
Assaf Kraussb94d8ee2008-09-03 11:18:42 +08003409 priv->timestamp = le64_to_cpu(timestamp);
Zhu Yib481de92007-09-25 17:54:57 -07003410
3411 IWL_DEBUG_MAC80211("leave\n");
3412 spin_unlock_irqrestore(&priv->lock, flags);
3413
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003414 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003415
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003416 iwl_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003417
Zhu Yib481de92007-09-25 17:54:57 -07003418
3419 return 0;
3420}
3421
Zhu Yib481de92007-09-25 17:54:57 -07003422/*****************************************************************************
3423 *
3424 * sysfs attributes
3425 *
3426 *****************************************************************************/
3427
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003428#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07003429
3430/*
3431 * The following adds a new attribute to the sysfs representation
Wu, Fengguangc3a739f2008-12-17 16:52:29 +08003432 * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
Zhu Yib481de92007-09-25 17:54:57 -07003433 * used for controlling the debug level.
3434 *
3435 * See the level definitions in iwl for details.
3436 */
3437
Ester Kummer8cf769c2008-05-06 11:05:11 +08003438static ssize_t show_debug_level(struct device *d,
3439 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07003440{
Ester Kummer8cf769c2008-05-06 11:05:11 +08003441 struct iwl_priv *priv = d->driver_data;
3442
3443 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07003444}
Ester Kummer8cf769c2008-05-06 11:05:11 +08003445static ssize_t store_debug_level(struct device *d,
3446 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07003447 const char *buf, size_t count)
3448{
Ester Kummer8cf769c2008-05-06 11:05:11 +08003449 struct iwl_priv *priv = d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003450 unsigned long val;
3451 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003452
Tomas Winkler9257746f2008-09-03 11:26:32 +08003453 ret = strict_strtoul(buf, 0, &val);
3454 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08003455 IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07003456 else
Ester Kummer8cf769c2008-05-06 11:05:11 +08003457 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07003458
3459 return strnlen(buf, count);
3460}
3461
Ester Kummer8cf769c2008-05-06 11:05:11 +08003462static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
3463 show_debug_level, store_debug_level);
3464
Zhu Yib481de92007-09-25 17:54:57 -07003465
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003466#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07003467
Zhu Yib481de92007-09-25 17:54:57 -07003468
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003469static ssize_t show_version(struct device *d,
3470 struct device_attribute *attr, char *buf)
3471{
3472 struct iwl_priv *priv = d->driver_data;
Tomas Winkler885ba202008-05-29 16:34:55 +08003473 struct iwl_alive_resp *palive = &priv->card_alive;
Tomas Winklerf236a262008-06-30 17:23:02 +08003474 ssize_t pos = 0;
3475 u16 eeprom_ver;
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003476
3477 if (palive->is_valid)
Tomas Winklerf236a262008-06-30 17:23:02 +08003478 pos += sprintf(buf + pos,
3479 "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n"
3480 "fw type: 0x%01X 0x%01X\n",
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003481 palive->ucode_major, palive->ucode_minor,
3482 palive->sw_rev[0], palive->sw_rev[1],
3483 palive->ver_type, palive->ver_subtype);
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003484 else
Tomas Winklerf236a262008-06-30 17:23:02 +08003485 pos += sprintf(buf + pos, "fw not loaded\n");
3486
3487 if (priv->eeprom) {
3488 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
3489 pos += sprintf(buf + pos, "EEPROM version: 0x%x\n",
3490 eeprom_ver);
3491 } else {
3492 pos += sprintf(buf + pos, "EEPROM not initialzed\n");
3493 }
3494
3495 return pos;
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003496}
3497
3498static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL);
3499
Zhu Yib481de92007-09-25 17:54:57 -07003500static ssize_t show_temperature(struct device *d,
3501 struct device_attribute *attr, char *buf)
3502{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003503 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003504
Tomas Winklerfee12472008-04-03 16:05:21 -07003505 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003506 return -EAGAIN;
3507
Emmanuel Grumbach91dbc5b2008-06-12 09:47:14 +08003508 return sprintf(buf, "%d\n", priv->temperature);
Zhu Yib481de92007-09-25 17:54:57 -07003509}
3510
3511static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
3512
Zhu Yib481de92007-09-25 17:54:57 -07003513static ssize_t show_tx_power(struct device *d,
3514 struct device_attribute *attr, char *buf)
3515{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003516 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Jay Sternberg91f39e82008-12-17 16:52:34 +08003517
3518 if (!iwl_is_ready_rf(priv))
3519 return sprintf(buf, "off\n");
3520 else
3521 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07003522}
3523
3524static ssize_t store_tx_power(struct device *d,
3525 struct device_attribute *attr,
3526 const char *buf, size_t count)
3527{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003528 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003529 unsigned long val;
3530 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003531
Tomas Winkler9257746f2008-09-03 11:26:32 +08003532 ret = strict_strtoul(buf, 10, &val);
3533 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08003534 IWL_INFO(priv, "%s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07003535 else
Tomas Winkler630fe9b2008-06-12 09:47:08 +08003536 iwl_set_tx_power(priv, val, false);
Zhu Yib481de92007-09-25 17:54:57 -07003537
3538 return count;
3539}
3540
3541static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
3542
3543static ssize_t show_flags(struct device *d,
3544 struct device_attribute *attr, char *buf)
3545{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003546 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003547
3548 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
3549}
3550
3551static ssize_t store_flags(struct device *d,
3552 struct device_attribute *attr,
3553 const char *buf, size_t count)
3554{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003555 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003556 unsigned long val;
3557 u32 flags;
3558 int ret = strict_strtoul(buf, 0, &val);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08003559 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08003560 return ret;
3561 flags = (u32)val;
Zhu Yib481de92007-09-25 17:54:57 -07003562
3563 mutex_lock(&priv->mutex);
3564 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
3565 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08003566 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003567 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003568 else {
Tomas Winkler9257746f2008-09-03 11:26:32 +08003569 IWL_DEBUG_INFO("Commit rxon.flags = 0x%04X\n", flags);
Zhu Yib481de92007-09-25 17:54:57 -07003570 priv->staging_rxon.flags = cpu_to_le32(flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003571 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003572 }
3573 }
3574 mutex_unlock(&priv->mutex);
3575
3576 return count;
3577}
3578
3579static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
3580
3581static ssize_t show_filter_flags(struct device *d,
3582 struct device_attribute *attr, char *buf)
3583{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003584 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003585
3586 return sprintf(buf, "0x%04X\n",
3587 le32_to_cpu(priv->active_rxon.filter_flags));
3588}
3589
3590static ssize_t store_filter_flags(struct device *d,
3591 struct device_attribute *attr,
3592 const char *buf, size_t count)
3593{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003594 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003595 unsigned long val;
3596 u32 filter_flags;
3597 int ret = strict_strtoul(buf, 0, &val);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08003598 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08003599 return ret;
3600 filter_flags = (u32)val;
Zhu Yib481de92007-09-25 17:54:57 -07003601
3602 mutex_lock(&priv->mutex);
3603 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
3604 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08003605 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003606 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003607 else {
3608 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
3609 "0x%04X\n", filter_flags);
3610 priv->staging_rxon.filter_flags =
3611 cpu_to_le32(filter_flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003612 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003613 }
3614 }
3615 mutex_unlock(&priv->mutex);
3616
3617 return count;
3618}
3619
3620static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
3621 store_filter_flags);
3622
Zhu Yib481de92007-09-25 17:54:57 -07003623static ssize_t store_power_level(struct device *d,
3624 struct device_attribute *attr,
3625 const char *buf, size_t count)
3626{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003627 struct iwl_priv *priv = dev_get_drvdata(d);
Esti Kummer298df1f2008-07-18 13:52:58 +08003628 int ret;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003629 unsigned long mode;
Zhu Yib481de92007-09-25 17:54:57 -07003630
Tomas Winkler9257746f2008-09-03 11:26:32 +08003631
Zhu Yib481de92007-09-25 17:54:57 -07003632 mutex_lock(&priv->mutex);
3633
Tomas Winklerfee12472008-04-03 16:05:21 -07003634 if (!iwl_is_ready(priv)) {
Esti Kummer298df1f2008-07-18 13:52:58 +08003635 ret = -EAGAIN;
Zhu Yib481de92007-09-25 17:54:57 -07003636 goto out;
3637 }
3638
Tomas Winkler9257746f2008-09-03 11:26:32 +08003639 ret = strict_strtoul(buf, 10, &mode);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08003640 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08003641 goto out;
3642
Esti Kummer298df1f2008-07-18 13:52:58 +08003643 ret = iwl_power_set_user_mode(priv, mode);
3644 if (ret) {
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003645 IWL_DEBUG_MAC80211("failed setting power mode.\n");
3646 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003647 }
Esti Kummer298df1f2008-07-18 13:52:58 +08003648 ret = count;
Zhu Yib481de92007-09-25 17:54:57 -07003649
3650 out:
3651 mutex_unlock(&priv->mutex);
Esti Kummer298df1f2008-07-18 13:52:58 +08003652 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003653}
3654
Zhu Yib481de92007-09-25 17:54:57 -07003655static ssize_t show_power_level(struct device *d,
3656 struct device_attribute *attr, char *buf)
3657{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003658 struct iwl_priv *priv = dev_get_drvdata(d);
Esti Kummer298df1f2008-07-18 13:52:58 +08003659 int mode = priv->power_data.user_power_setting;
3660 int system = priv->power_data.system_power_setting;
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003661 int level = priv->power_data.power_mode;
Zhu Yib481de92007-09-25 17:54:57 -07003662 char *p = buf;
3663
Esti Kummer298df1f2008-07-18 13:52:58 +08003664 switch (system) {
3665 case IWL_POWER_SYS_AUTO:
3666 p += sprintf(p, "SYSTEM:auto");
Zhu Yib481de92007-09-25 17:54:57 -07003667 break;
Esti Kummer298df1f2008-07-18 13:52:58 +08003668 case IWL_POWER_SYS_AC:
3669 p += sprintf(p, "SYSTEM:ac");
Zhu Yib481de92007-09-25 17:54:57 -07003670 break;
Esti Kummer298df1f2008-07-18 13:52:58 +08003671 case IWL_POWER_SYS_BATTERY:
3672 p += sprintf(p, "SYSTEM:battery");
3673 break;
Zhu Yib481de92007-09-25 17:54:57 -07003674 }
Esti Kummer298df1f2008-07-18 13:52:58 +08003675
Abhijeet Kolekarc3056062008-11-12 13:14:08 -08003676 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
3677 "fixed" : "auto");
Esti Kummer298df1f2008-07-18 13:52:58 +08003678 p += sprintf(p, "\tINDEX:%d", level);
3679 p += sprintf(p, "\n");
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003680 return p - buf + 1;
Zhu Yib481de92007-09-25 17:54:57 -07003681}
3682
3683static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
3684 store_power_level);
3685
Zhu Yib481de92007-09-25 17:54:57 -07003686
3687static ssize_t show_statistics(struct device *d,
3688 struct device_attribute *attr, char *buf)
3689{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003690 struct iwl_priv *priv = dev_get_drvdata(d);
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08003691 u32 size = sizeof(struct iwl_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07003692 u32 len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003693 u8 *data = (u8 *)&priv->statistics;
Zhu Yib481de92007-09-25 17:54:57 -07003694 int rc = 0;
3695
Tomas Winklerfee12472008-04-03 16:05:21 -07003696 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003697 return -EAGAIN;
3698
3699 mutex_lock(&priv->mutex);
Emmanuel Grumbach49ea8592008-04-15 16:01:37 -07003700 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003701 mutex_unlock(&priv->mutex);
3702
3703 if (rc) {
3704 len = sprintf(buf,
3705 "Error sending statistics request: 0x%08X\n", rc);
3706 return len;
3707 }
3708
3709 while (size && (PAGE_SIZE - len)) {
3710 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
3711 PAGE_SIZE - len, 1);
3712 len = strlen(buf);
3713 if (PAGE_SIZE - len)
3714 buf[len++] = '\n';
3715
3716 ofs += 16;
3717 size -= min(size, 16U);
3718 }
3719
3720 return len;
3721}
3722
3723static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
3724
Zhu Yib481de92007-09-25 17:54:57 -07003725
Zhu Yib481de92007-09-25 17:54:57 -07003726/*****************************************************************************
3727 *
3728 * driver setup and teardown
3729 *
3730 *****************************************************************************/
3731
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003732static void iwl_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003733{
3734 priv->workqueue = create_workqueue(DRV_NAME);
3735
3736 init_waitqueue_head(&priv->wait_command_queue);
3737
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003738 INIT_WORK(&priv->up, iwl_bg_up);
3739 INIT_WORK(&priv->restart, iwl_bg_restart);
3740 INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish);
3741 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
3742 INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08003743 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08003744 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
3745 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
Tomas Winkler2a421b92008-06-12 09:47:10 +08003746
Tomas Winkler2a421b92008-06-12 09:47:10 +08003747 iwl_setup_scan_deferred_work(priv);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08003748 iwl_setup_power_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003749
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003750 if (priv->cfg->ops->lib->setup_deferred_work)
3751 priv->cfg->ops->lib->setup_deferred_work(priv);
3752
3753 init_timer(&priv->statistics_periodic);
3754 priv->statistics_periodic.data = (unsigned long)priv;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003755 priv->statistics_periodic.function = iwl_bg_statistics_periodic;
Zhu Yib481de92007-09-25 17:54:57 -07003756
3757 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003758 iwl_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07003759}
3760
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003761static void iwl_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003762{
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003763 if (priv->cfg->ops->lib->cancel_deferred_work)
3764 priv->cfg->ops->lib->cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003765
Joonwoo Park3ae6a052007-11-29 10:43:16 +09003766 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07003767 cancel_delayed_work(&priv->scan_check);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08003768 cancel_delayed_work_sync(&priv->set_power_save);
Zhu Yib481de92007-09-25 17:54:57 -07003769 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07003770 cancel_work_sync(&priv->beacon_update);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003771 del_timer_sync(&priv->statistics_periodic);
Zhu Yib481de92007-09-25 17:54:57 -07003772}
3773
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003774static struct attribute *iwl_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07003775 &dev_attr_flags.attr,
3776 &dev_attr_filter_flags.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003777 &dev_attr_power_level.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003778 &dev_attr_statistics.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003779 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003780 &dev_attr_tx_power.attr,
Ester Kummer8cf769c2008-05-06 11:05:11 +08003781#ifdef CONFIG_IWLWIFI_DEBUG
3782 &dev_attr_debug_level.attr,
3783#endif
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003784 &dev_attr_version.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003785
3786 NULL
3787};
3788
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003789static struct attribute_group iwl_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07003790 .name = NULL, /* put in device directory */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003791 .attrs = iwl_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07003792};
3793
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003794static struct ieee80211_ops iwl_hw_ops = {
3795 .tx = iwl_mac_tx,
3796 .start = iwl_mac_start,
3797 .stop = iwl_mac_stop,
3798 .add_interface = iwl_mac_add_interface,
3799 .remove_interface = iwl_mac_remove_interface,
3800 .config = iwl_mac_config,
3801 .config_interface = iwl_mac_config_interface,
3802 .configure_filter = iwl_configure_filter,
3803 .set_key = iwl_mac_set_key,
3804 .update_tkip_key = iwl_mac_update_tkip_key,
3805 .get_stats = iwl_mac_get_stats,
3806 .get_tx_stats = iwl_mac_get_tx_stats,
3807 .conf_tx = iwl_mac_conf_tx,
3808 .reset_tsf = iwl_mac_reset_tsf,
3809 .bss_info_changed = iwl_bss_info_changed,
3810 .ampdu_action = iwl_mac_ampdu_action,
Tomas Winklercb43dc22008-09-03 11:26:23 +08003811 .hw_scan = iwl_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07003812};
3813
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003814static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07003815{
3816 int err = 0;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003817 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07003818 struct ieee80211_hw *hw;
Tomas Winkler82b9a122008-03-04 18:09:30 -08003819 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003820 unsigned long flags;
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003821 u16 pci_cmd;
Zhu Yib481de92007-09-25 17:54:57 -07003822
Assaf Krauss316c30d2008-03-14 10:38:46 -07003823 /************************
3824 * 1. Allocating HW data
3825 ************************/
3826
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003827 /* Disabling hardware scan means that mac80211 will perform scans
3828 * "the hard way", rather than using device's scan. */
Assaf Krauss1ea87392008-03-18 14:57:50 -07003829 if (cfg->mod_params->disable_hw_scan) {
Ester Kummerbf403db2008-05-05 10:22:40 +08003830 if (cfg->mod_params->debug & IWL_DL_INFO)
3831 dev_printk(KERN_DEBUG, &(pdev->dev),
3832 "Disabling hw_scan\n");
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003833 iwl_hw_ops.hw_scan = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07003834 }
3835
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003836 hw = iwl_alloc_all(cfg, &iwl_hw_ops);
Assaf Krauss1d0a0822008-03-14 10:38:48 -07003837 if (!hw) {
Zhu Yib481de92007-09-25 17:54:57 -07003838 err = -ENOMEM;
3839 goto out;
3840 }
Assaf Krauss1d0a0822008-03-14 10:38:48 -07003841 priv = hw->priv;
3842 /* At this point both hw and priv are allocated. */
3843
Zhu Yib481de92007-09-25 17:54:57 -07003844 SET_IEEE80211_DEV(hw, &pdev->dev);
3845
3846 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
Tomas Winkler82b9a122008-03-04 18:09:30 -08003847 priv->cfg = cfg;
Zhu Yib481de92007-09-25 17:54:57 -07003848 priv->pci_dev = pdev;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003849
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003850#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08003851 priv->debug_level = priv->cfg->mod_params->debug;
Zhu Yib481de92007-09-25 17:54:57 -07003852 atomic_set(&priv->restrict_refcnt, 0);
3853#endif
Zhu Yib481de92007-09-25 17:54:57 -07003854
Assaf Krauss316c30d2008-03-14 10:38:46 -07003855 /**************************
3856 * 2. Initializing PCI bus
3857 **************************/
3858 if (pci_enable_device(pdev)) {
3859 err = -ENODEV;
3860 goto out_ieee80211_free_hw;
3861 }
3862
3863 pci_set_master(pdev);
3864
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003865 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
Assaf Krauss316c30d2008-03-14 10:38:46 -07003866 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003867 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003868 if (err) {
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003869 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003870 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003871 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003872 /* both attempts failed: */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003873 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08003874 IWL_WARN(priv, "No suitable DMA available.\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07003875 goto out_pci_disable_device;
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003876 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07003877 }
3878
3879 err = pci_request_regions(pdev, DRV_NAME);
3880 if (err)
3881 goto out_pci_disable_device;
3882
3883 pci_set_drvdata(pdev, priv);
3884
Assaf Krauss316c30d2008-03-14 10:38:46 -07003885
3886 /***********************
3887 * 3. Read REV register
3888 ***********************/
3889 priv->hw_base = pci_iomap(pdev, 0, 0);
3890 if (!priv->hw_base) {
3891 err = -ENODEV;
3892 goto out_pci_release_regions;
3893 }
3894
3895 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
3896 (unsigned long long) pci_resource_len(pdev, 0));
3897 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
3898
Tomas Winklerb661c812008-04-23 17:14:54 -07003899 iwl_hw_detect(priv);
Tomas Winkler978785a2008-12-19 10:37:31 +08003900 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s REV=0x%X\n",
Tomas Winklerb661c812008-04-23 17:14:54 -07003901 priv->cfg->name, priv->hw_rev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003902
Tomas Winklere7b63582008-09-03 11:26:49 +08003903 /* We disable the RETRY_TIMEOUT register (0x41) to keep
3904 * PCI Tx retries from interfering with C3 CPU state */
3905 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
3906
Tomas Winkler91238712008-04-23 17:14:53 -07003907 /* amp init */
3908 err = priv->cfg->ops->lib->apm_ops.init(priv);
3909 if (err < 0) {
3910 IWL_DEBUG_INFO("Failed to init APMG\n");
3911 goto out_iounmap;
3912 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07003913 /*****************
3914 * 4. Read EEPROM
3915 *****************/
Assaf Krauss316c30d2008-03-14 10:38:46 -07003916 /* Read the EEPROM */
3917 err = iwl_eeprom_init(priv);
3918 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003919 IWL_ERR(priv, "Unable to init EEPROM\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07003920 goto out_iounmap;
3921 }
Tomas Winkler8614f362008-04-23 17:14:55 -07003922 err = iwl_eeprom_check_version(priv);
3923 if (err)
3924 goto out_iounmap;
3925
Ron Rindjunsky02883012008-05-15 13:53:53 +08003926 /* extract MAC Address */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003927 iwl_eeprom_get_mac(priv, priv->mac_addr);
Johannes Berge1749612008-10-27 15:59:26 -07003928 IWL_DEBUG_INFO("MAC address: %pM\n", priv->mac_addr);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003929 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
3930
3931 /************************
3932 * 5. Setup HW constants
3933 ************************/
Ron Rindjunskyda154e302008-06-30 17:23:20 +08003934 if (iwl_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003935 IWL_ERR(priv, "failed to set hw parameters\n");
Tomas Winkler073d3f52008-04-21 15:41:52 -07003936 goto out_free_eeprom;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003937 }
3938
3939 /*******************
Tomas Winkler6ba87952008-05-15 13:54:17 +08003940 * 6. Setup priv
Assaf Krauss316c30d2008-03-14 10:38:46 -07003941 *******************/
Zhu Yib481de92007-09-25 17:54:57 -07003942
Tomas Winkler6ba87952008-05-15 13:54:17 +08003943 err = iwl_init_drv(priv);
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003944 if (err)
Ron Rindjunsky399f4902008-04-23 17:14:56 -07003945 goto out_free_eeprom;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003946 /* At this point both hw and priv are initialized. */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003947
3948 /**********************************
3949 * 7. Initialize module parameters
3950 **********************************/
3951
3952 /* Disable radio (SW RF KILL) via parameter when loading driver */
Assaf Krauss1ea87392008-03-18 14:57:50 -07003953 if (priv->cfg->mod_params->disable) {
Assaf Krauss316c30d2008-03-14 10:38:46 -07003954 set_bit(STATUS_RF_KILL_SW, &priv->status);
3955 IWL_DEBUG_INFO("Radio disabled.\n");
3956 }
3957
Assaf Krauss316c30d2008-03-14 10:38:46 -07003958 /********************
3959 * 8. Setup services
3960 ********************/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003961 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003962 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003963 spin_unlock_irqrestore(&priv->lock, flags);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003964
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003965 pci_enable_msi(priv->pci_dev);
3966
3967 err = request_irq(priv->pci_dev->irq, iwl_isr, IRQF_SHARED,
3968 DRV_NAME, priv);
3969 if (err) {
3970 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
3971 goto out_disable_msi;
3972 }
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003973 err = sysfs_create_group(&pdev->dev.kobj, &iwl_attribute_group);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003974 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003975 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Tomas Winkler6ba87952008-05-15 13:54:17 +08003976 goto out_uninit_drv;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003977 }
3978
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003979 iwl_setup_deferred_work(priv);
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08003980 iwl_setup_rx_handlers(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003981
Tomas Winkler6ba87952008-05-15 13:54:17 +08003982 /**********************************
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003983 * 9. Setup and register mac80211
Tomas Winkler6ba87952008-05-15 13:54:17 +08003984 **********************************/
3985
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003986 /* enable interrupts if needed: hw bug w/a */
3987 pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd);
3988 if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
3989 pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
3990 pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
3991 }
3992
3993 iwl_enable_interrupts(priv);
3994
Tomas Winkler6ba87952008-05-15 13:54:17 +08003995 err = iwl_setup_mac(priv);
3996 if (err)
3997 goto out_remove_sysfs;
3998
3999 err = iwl_dbgfs_register(priv, DRV_NAME);
4000 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08004001 IWL_ERR(priv, "failed to create debugfs files\n");
Tomas Winkler6ba87952008-05-15 13:54:17 +08004002
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004003 /* If platform's RF_KILL switch is NOT set to KILL */
4004 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
4005 clear_bit(STATUS_RF_KILL_HW, &priv->status);
4006 else
4007 set_bit(STATUS_RF_KILL_HW, &priv->status);
4008
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08004009 err = iwl_rfkill_init(priv);
4010 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08004011 IWL_ERR(priv, "Unable to initialize RFKILL system. "
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08004012 "Ignoring error: %d\n", err);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004013 else
4014 iwl_rfkill_set_hw_state(priv);
4015
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08004016 iwl_power_initialize(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004017 return 0;
4018
Assaf Krauss316c30d2008-03-14 10:38:46 -07004019 out_remove_sysfs:
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004020 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004021 out_disable_msi:
4022 pci_disable_msi(priv->pci_dev);
4023 pci_disable_device(priv->pci_dev);
Tomas Winkler6ba87952008-05-15 13:54:17 +08004024 out_uninit_drv:
4025 iwl_uninit_drv(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07004026 out_free_eeprom:
4027 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004028 out_iounmap:
4029 pci_iounmap(pdev, priv->hw_base);
4030 out_pci_release_regions:
4031 pci_release_regions(pdev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004032 pci_set_drvdata(pdev, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07004033 out_pci_disable_device:
4034 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004035 out_ieee80211_free_hw:
4036 ieee80211_free_hw(priv->hw);
4037 out:
4038 return err;
4039}
4040
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004041static void __devexit iwl_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004042{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004043 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004044 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07004045
4046 if (!priv)
4047 return;
4048
4049 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
4050
Emmanuel Grumbach67249622008-05-29 16:35:26 +08004051 iwl_dbgfs_unregister(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004052 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
Emmanuel Grumbach67249622008-05-29 16:35:26 +08004053
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004054 /* ieee80211_unregister_hw call wil cause iwl_mac_stop to
4055 * to be called and iwl_down since we are removing the device
Gregory Greenman0b124c32008-09-03 11:18:50 +08004056 * we need to set STATUS_EXIT_PENDING bit.
4057 */
4058 set_bit(STATUS_EXIT_PENDING, &priv->status);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07004059 if (priv->mac80211_registered) {
4060 ieee80211_unregister_hw(priv->hw);
4061 priv->mac80211_registered = 0;
Gregory Greenman0b124c32008-09-03 11:18:50 +08004062 } else {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004063 iwl_down(priv);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07004064 }
4065
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004066 /* make sure we flush any pending irq or
4067 * tasklet for the driver
4068 */
4069 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004070 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004071 spin_unlock_irqrestore(&priv->lock, flags);
4072
4073 iwl_synchronize_irq(priv);
4074
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08004075 iwl_rfkill_unregister(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004076 iwl_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004077
4078 if (priv->rxq.bd)
Tomas Winklera55360e2008-05-05 10:22:28 +08004079 iwl_rx_queue_free(priv, &priv->rxq);
Ron Rindjunsky1053d352008-05-05 10:22:43 +08004080 iwl_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004081
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08004082 iwl_clear_stations_table(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07004083 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004084
Zhu Yib481de92007-09-25 17:54:57 -07004085
Mohamed Abbas948c1712007-10-25 17:15:45 +08004086 /*netif_stop_queue(dev); */
4087 flush_workqueue(priv->workqueue);
4088
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004089 /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07004090 * priv->workqueue... so we can't take down the workqueue
4091 * until now... */
4092 destroy_workqueue(priv->workqueue);
4093 priv->workqueue = NULL;
4094
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004095 free_irq(priv->pci_dev->irq, priv);
4096 pci_disable_msi(priv->pci_dev);
Zhu Yib481de92007-09-25 17:54:57 -07004097 pci_iounmap(pdev, priv->hw_base);
4098 pci_release_regions(pdev);
4099 pci_disable_device(pdev);
4100 pci_set_drvdata(pdev, NULL);
4101
Tomas Winkler6ba87952008-05-15 13:54:17 +08004102 iwl_uninit_drv(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004103
4104 if (priv->ibss_beacon)
4105 dev_kfree_skb(priv->ibss_beacon);
4106
4107 ieee80211_free_hw(priv->hw);
4108}
4109
4110#ifdef CONFIG_PM
4111
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004112static int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07004113{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004114 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004115
Zhu Yie655b9f2008-01-24 02:19:38 -08004116 if (priv->is_open) {
4117 set_bit(STATUS_IN_SUSPEND, &priv->status);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004118 iwl_mac_stop(priv->hw);
Zhu Yie655b9f2008-01-24 02:19:38 -08004119 priv->is_open = 1;
4120 }
Zhu Yib481de92007-09-25 17:54:57 -07004121
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004122 pci_save_state(pdev);
4123 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004124 pci_set_power_state(pdev, PCI_D3hot);
4125
Zhu Yib481de92007-09-25 17:54:57 -07004126 return 0;
4127}
4128
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004129static int iwl_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004130{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004131 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004132
Zhu Yib481de92007-09-25 17:54:57 -07004133 pci_set_power_state(pdev, PCI_D0);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004134 pci_enable_device(pdev);
4135 pci_restore_state(pdev);
4136 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004137
Zhu Yie655b9f2008-01-24 02:19:38 -08004138 if (priv->is_open)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004139 iwl_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07004140
Zhu Yie655b9f2008-01-24 02:19:38 -08004141 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004142 return 0;
4143}
4144
4145#endif /* CONFIG_PM */
4146
4147/*****************************************************************************
4148 *
4149 * driver and module entry point
4150 *
4151 *****************************************************************************/
4152
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004153/* Hardware specific file defines the PCI IDs table for that hardware module */
4154static struct pci_device_id iwl_hw_card_ids[] = {
Tomas Winkler4fc22b22008-07-21 18:54:42 +03004155#ifdef CONFIG_IWL4965
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004156 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
4157 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
Tomas Winkler4fc22b22008-07-21 18:54:42 +03004158#endif /* CONFIG_IWL4965 */
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004159#ifdef CONFIG_IWL5000
Esti Kummer47408632008-07-11 11:53:30 +08004160 {IWL_PCI_DEVICE(0x4232, 0x1205, iwl5100_bg_cfg)},
4161 {IWL_PCI_DEVICE(0x4232, 0x1305, iwl5100_bg_cfg)},
4162 {IWL_PCI_DEVICE(0x4232, 0x1206, iwl5100_abg_cfg)},
4163 {IWL_PCI_DEVICE(0x4232, 0x1306, iwl5100_abg_cfg)},
4164 {IWL_PCI_DEVICE(0x4232, 0x1326, iwl5100_abg_cfg)},
4165 {IWL_PCI_DEVICE(0x4237, 0x1216, iwl5100_abg_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004166 {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)},
Esti Kummer47408632008-07-11 11:53:30 +08004167 {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)},
4168 {IWL_PCI_DEVICE(0x4236, PCI_ANY_ID, iwl5300_agn_cfg)},
4169 {IWL_PCI_DEVICE(0x4237, PCI_ANY_ID, iwl5100_agn_cfg)},
Tomas Winklere96a8492008-09-11 11:45:20 +08004170/* 5350 WiFi/WiMax */
4171 {IWL_PCI_DEVICE(0x423A, 0x1001, iwl5350_agn_cfg)},
4172 {IWL_PCI_DEVICE(0x423A, 0x1021, iwl5350_agn_cfg)},
4173 {IWL_PCI_DEVICE(0x423B, 0x1011, iwl5350_agn_cfg)},
Tomas Winkler7100e922008-12-01 16:32:18 -08004174/* 5150 Wifi/WiMax */
4175 {IWL_PCI_DEVICE(0x423C, PCI_ANY_ID, iwl5150_agn_cfg)},
4176 {IWL_PCI_DEVICE(0x423D, PCI_ANY_ID, iwl5150_agn_cfg)},
Jay Sternberge1228372009-01-19 15:30:34 -08004177/* 6000/6050 Series */
4178 {IWL_PCI_DEVICE(0x0082, 0x1102, iwl6000_2ag_cfg)},
4179 {IWL_PCI_DEVICE(0x0085, 0x1112, iwl6000_2ag_cfg)},
4180 {IWL_PCI_DEVICE(0x0082, 0x1122, iwl6000_2ag_cfg)},
4181 {IWL_PCI_DEVICE(0x422B, PCI_ANY_ID, iwl6000_3agn_cfg)},
4182 {IWL_PCI_DEVICE(0x4238, PCI_ANY_ID, iwl6000_3agn_cfg)},
4183 {IWL_PCI_DEVICE(0x0082, PCI_ANY_ID, iwl6000_2agn_cfg)},
4184 {IWL_PCI_DEVICE(0x0085, PCI_ANY_ID, iwl6000_3agn_cfg)},
4185 {IWL_PCI_DEVICE(0x0086, PCI_ANY_ID, iwl6050_3agn_cfg)},
4186 {IWL_PCI_DEVICE(0x0087, PCI_ANY_ID, iwl6050_2agn_cfg)},
4187 {IWL_PCI_DEVICE(0x0088, PCI_ANY_ID, iwl6050_3agn_cfg)},
4188 {IWL_PCI_DEVICE(0x0089, PCI_ANY_ID, iwl6050_2agn_cfg)},
Jay Sternbergc5d05692009-01-19 15:30:35 -08004189/* 100 Series WiFi */
4190 {IWL_PCI_DEVICE(0x0083, PCI_ANY_ID, iwl100_bgn_cfg)},
4191 {IWL_PCI_DEVICE(0x0084, PCI_ANY_ID, iwl100_bgn_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004192#endif /* CONFIG_IWL5000 */
Tomas Winkler7100e922008-12-01 16:32:18 -08004193
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004194 {0}
4195};
4196MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
4197
4198static struct pci_driver iwl_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07004199 .name = DRV_NAME,
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004200 .id_table = iwl_hw_card_ids,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004201 .probe = iwl_pci_probe,
4202 .remove = __devexit_p(iwl_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07004203#ifdef CONFIG_PM
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004204 .suspend = iwl_pci_suspend,
4205 .resume = iwl_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07004206#endif
4207};
4208
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004209static int __init iwl_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07004210{
4211
4212 int ret;
4213 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
4214 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004215
Tomas Winklere227cea2008-07-18 13:53:05 +08004216 ret = iwlagn_rate_control_register();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004217 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08004218 printk(KERN_ERR DRV_NAME
4219 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004220 return ret;
4221 }
4222
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004223 ret = pci_register_driver(&iwl_driver);
Zhu Yib481de92007-09-25 17:54:57 -07004224 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08004225 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004226 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07004227 }
Zhu Yib481de92007-09-25 17:54:57 -07004228
4229 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004230
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004231error_register:
Tomas Winklere227cea2008-07-18 13:53:05 +08004232 iwlagn_rate_control_unregister();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004233 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004234}
4235
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004236static void __exit iwl_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07004237{
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004238 pci_unregister_driver(&iwl_driver);
Tomas Winklere227cea2008-07-18 13:53:05 +08004239 iwlagn_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07004240}
4241
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004242module_exit(iwl_exit);
4243module_init(iwl_init);