blob: 4a15e42ad00a1d24a13771564fef67b6a9afad3e [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{
523 struct iwl_tfd *tfd_tmp = (struct iwl_tfd *)&txq->tfds[0];
524 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;
566 struct iwl_tfd *tfd;
567 u32 num_tbs;
568
569 q = &txq->q;
570 tfd = &txq->tfds[q->write_ptr];
571
572 if (reset)
573 memset(tfd, 0, sizeof(*tfd));
574
575 num_tbs = iwl_tfd_get_num_tbs(tfd);
576
577 /* Each TFD can point to a maximum 20 Tx buffers */
578 if (num_tbs >= IWL_NUM_OF_TBS) {
579 IWL_ERR(priv, "Error can not send more than %d chunks\n",
580 IWL_NUM_OF_TBS);
581 return -EINVAL;
582 }
583
584 BUG_ON(addr & ~DMA_BIT_MASK(36));
585 if (unlikely(addr & ~IWL_TX_DMA_MASK))
586 IWL_ERR(priv, "Unaligned address = %llx\n",
587 (unsigned long long)addr);
588
589 iwl_tfd_set_tb(tfd, num_tbs, addr, len);
590
591 return 0;
592}
593
Zhu Yib481de92007-09-25 17:54:57 -0700594/******************************************************************************
595 *
Zhu Yib481de92007-09-25 17:54:57 -0700596 * Misc. internal state and helper functions
597 *
598 ******************************************************************************/
Zhu Yib481de92007-09-25 17:54:57 -0700599
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700600static void iwl_ht_conf(struct iwl_priv *priv,
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700601 struct ieee80211_bss_conf *bss_conf)
602{
Johannes Bergae5eb022008-10-14 16:58:37 +0200603 struct ieee80211_sta_ht_cap *ht_conf;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700604 struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
Johannes Bergae5eb022008-10-14 16:58:37 +0200605 struct ieee80211_sta *sta;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700606
607 IWL_DEBUG_MAC80211("enter: \n");
608
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700609 if (!iwl_conf->is_ht)
610 return;
611
Johannes Bergae5eb022008-10-14 16:58:37 +0200612
613 /*
614 * It is totally wrong to base global information on something
615 * that is valid only when associated, alas, this driver works
616 * that way and I don't know how to fix it.
617 */
618
619 rcu_read_lock();
620 sta = ieee80211_find_sta(priv->hw, priv->bssid);
621 if (!sta) {
622 rcu_read_unlock();
623 return;
624 }
625 ht_conf = &sta->ht_cap;
626
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700627 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
Emmanuel Grumbacha9841012008-05-15 13:54:08 +0800628 iwl_conf->sgf |= HT_SHORT_GI_20MHZ;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700629 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
Emmanuel Grumbacha9841012008-05-15 13:54:08 +0800630 iwl_conf->sgf |= HT_SHORT_GI_40MHZ;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700631
632 iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
633 iwl_conf->max_amsdu_size =
634 !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
635
636 iwl_conf->supported_chan_width =
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200637 !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40);
Johannes Bergae5eb022008-10-14 16:58:37 +0200638
Sujith094d05d2008-12-12 11:57:43 +0530639 /*
640 * XXX: The HT configuration needs to be moved into iwl_mac_config()
641 * to be done there correctly.
642 */
643
644 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
Luis R. Rodriguezde27e642008-12-23 15:58:44 -0800645 if (conf_is_ht40_minus(&priv->hw->conf))
Sujith094d05d2008-12-12 11:57:43 +0530646 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
Luis R. Rodriguezde27e642008-12-23 15:58:44 -0800647 else if (conf_is_ht40_plus(&priv->hw->conf))
Sujith094d05d2008-12-12 11:57:43 +0530648 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
649
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700650 /* If no above or below channel supplied disable FAT channel */
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200651 if (iwl_conf->extension_chan_offset != IEEE80211_HT_PARAM_CHA_SEC_ABOVE &&
Sujith094d05d2008-12-12 11:57:43 +0530652 iwl_conf->extension_chan_offset != IEEE80211_HT_PARAM_CHA_SEC_BELOW)
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700653 iwl_conf->supported_chan_width = 0;
654
Ron Rindjunsky12837be2008-09-03 11:26:47 +0800655 iwl_conf->sm_ps = (u8)((ht_conf->cap & IEEE80211_HT_CAP_SM_PS) >> 2);
656
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200657 memcpy(&iwl_conf->mcs, &ht_conf->mcs, 16);
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700658
Sujith094d05d2008-12-12 11:57:43 +0530659 iwl_conf->tx_chan_width = iwl_conf->supported_chan_width != 0;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700660 iwl_conf->ht_protection =
Johannes Bergae5eb022008-10-14 16:58:37 +0200661 bss_conf->ht.operation_mode & IEEE80211_HT_OP_MODE_PROTECTION;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700662 iwl_conf->non_GF_STA_present =
Johannes Bergae5eb022008-10-14 16:58:37 +0200663 !!(bss_conf->ht.operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700664
Johannes Bergae5eb022008-10-14 16:58:37 +0200665 rcu_read_unlock();
666
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700667 IWL_DEBUG_MAC80211("leave\n");
668}
669
Zhu Yib481de92007-09-25 17:54:57 -0700670/*
671 * QoS support
672*/
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +0800673static void iwl_activate_qos(struct iwl_priv *priv, u8 force)
Zhu Yib481de92007-09-25 17:54:57 -0700674{
Zhu Yib481de92007-09-25 17:54:57 -0700675 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
676 return;
677
Zhu Yib481de92007-09-25 17:54:57 -0700678 priv->qos_data.def_qos_parm.qos_flags = 0;
679
680 if (priv->qos_data.qos_cap.q_AP.queue_request &&
681 !priv->qos_data.qos_cap.q_AP.txop_request)
682 priv->qos_data.def_qos_parm.qos_flags |=
683 QOS_PARAM_FLG_TXOP_TYPE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700684 if (priv->qos_data.qos_active)
685 priv->qos_data.def_qos_parm.qos_flags |=
686 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
687
Ron Rindjunskyfd105e72007-11-26 16:14:39 +0200688 if (priv->current_ht_config.is_ht)
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800689 priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800690
Tomas Winkler3109ece2008-03-28 16:33:35 -0700691 if (force || iwl_is_associated(priv)) {
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800692 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
693 priv->qos_data.qos_active,
694 priv->qos_data.def_qos_parm.qos_flags);
Zhu Yib481de92007-09-25 17:54:57 -0700695
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +0800696 iwl_send_cmd_pdu_async(priv, REPLY_QOS_PARAM,
697 sizeof(struct iwl_qosparam_cmd),
698 &priv->qos_data.def_qos_parm, NULL);
Zhu Yib481de92007-09-25 17:54:57 -0700699 }
700}
701
Zhu Yib481de92007-09-25 17:54:57 -0700702#define MAX_UCODE_BEACON_INTERVAL 4096
Zhu Yib481de92007-09-25 17:54:57 -0700703
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800704static u16 iwl_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -0700705{
706 u16 new_val = 0;
707 u16 beacon_factor = 0;
708
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800709 beacon_factor = (beacon_val + MAX_UCODE_BEACON_INTERVAL)
710 / MAX_UCODE_BEACON_INTERVAL;
Zhu Yib481de92007-09-25 17:54:57 -0700711 new_val = beacon_val / beacon_factor;
712
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800713 return new_val;
Zhu Yib481de92007-09-25 17:54:57 -0700714}
715
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800716static void iwl_setup_rxon_timing(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700717{
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800718 u64 tsf;
719 s32 interval_tm, rem;
Zhu Yib481de92007-09-25 17:54:57 -0700720 unsigned long flags;
721 struct ieee80211_conf *conf = NULL;
722 u16 beacon_int = 0;
723
724 conf = ieee80211_get_hw_conf(priv->hw);
725
726 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800727 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
Tomas Winklerb5d7be52008-07-19 04:41:24 +0300728 priv->rxon_timing.listen_interval = cpu_to_le16(conf->listen_interval);
Zhu Yib481de92007-09-25 17:54:57 -0700729
Johannes Berg05c914f2008-09-11 00:01:58 +0200730 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800731 beacon_int = iwl_adjust_beacon_interval(priv->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -0700732 priv->rxon_timing.atim_window = 0;
733 } else {
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800734 beacon_int = iwl_adjust_beacon_interval(conf->beacon_int);
735
Zhu Yib481de92007-09-25 17:54:57 -0700736 /* TODO: we need to get atim_window from upper stack
737 * for now we set to 0 */
738 priv->rxon_timing.atim_window = 0;
739 }
740
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800741 priv->rxon_timing.beacon_interval = cpu_to_le16(beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -0700742
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800743 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
744 interval_tm = beacon_int * 1024;
745 rem = do_div(tsf, interval_tm);
746 priv->rxon_timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
747
748 spin_unlock_irqrestore(&priv->lock, flags);
749 IWL_DEBUG_ASSOC("beacon interval %d beacon timer %d beacon tim %d\n",
750 le16_to_cpu(priv->rxon_timing.beacon_interval),
751 le32_to_cpu(priv->rxon_timing.beacon_init_val),
752 le16_to_cpu(priv->rxon_timing.atim_window));
Zhu Yib481de92007-09-25 17:54:57 -0700753}
754
Tomas Winkler82a66bb2008-05-29 16:35:28 +0800755static void iwl_set_flags_for_band(struct iwl_priv *priv,
756 enum ieee80211_band band)
Zhu Yib481de92007-09-25 17:54:57 -0700757{
Johannes Berg8318d782008-01-24 19:38:38 +0100758 if (band == IEEE80211_BAND_5GHZ) {
Zhu Yib481de92007-09-25 17:54:57 -0700759 priv->staging_rxon.flags &=
760 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
761 | RXON_FLG_CCK_MSK);
762 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
763 } else {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700764 /* Copied from iwl_post_associate() */
Zhu Yib481de92007-09-25 17:54:57 -0700765 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
766 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
767 else
768 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
769
Johannes Berg05c914f2008-09-11 00:01:58 +0200770 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -0700771 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
772
773 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
774 priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
775 priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
776 }
777}
778
779/*
Ian Schram01ebd062007-10-25 17:15:22 +0800780 * initialize rxon structure with default values from eeprom
Zhu Yib481de92007-09-25 17:54:57 -0700781 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700782static void iwl_connection_init_rx_config(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700783{
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700784 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -0700785
786 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
787
Zhu, Yi60294de2008-10-29 14:05:45 -0700788 switch (mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200789 case NL80211_IFTYPE_AP:
Zhu Yib481de92007-09-25 17:54:57 -0700790 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
791 break;
792
Johannes Berg05c914f2008-09-11 00:01:58 +0200793 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -0700794 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
795 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
796 break;
797
Johannes Berg05c914f2008-09-11 00:01:58 +0200798 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -0700799 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
800 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
801 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
802 RXON_FILTER_ACCEPT_GRP_MSK;
803 break;
804
Johannes Berg05c914f2008-09-11 00:01:58 +0200805 case NL80211_IFTYPE_MONITOR:
Zhu Yib481de92007-09-25 17:54:57 -0700806 priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
807 priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
808 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
809 break;
Tomas Winkler69dc5d92008-03-25 16:33:41 -0700810 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +0800811 IWL_ERR(priv, "Unsupported interface type %d\n", mode);
Tomas Winkler69dc5d92008-03-25 16:33:41 -0700812 break;
Zhu Yib481de92007-09-25 17:54:57 -0700813 }
814
815#if 0
816 /* TODO: Figure out when short_preamble would be set and cache from
817 * that */
818 if (!hw_to_local(priv->hw)->short_preamble)
819 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
820 else
821 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
822#endif
823
Assaf Krauss8622e702008-03-21 13:53:43 -0700824 ch_info = iwl_get_channel_info(priv, priv->band,
Rick Farrington25b3f572008-06-30 17:23:28 +0800825 le16_to_cpu(priv->active_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700826
827 if (!ch_info)
828 ch_info = &priv->channel_info[0];
829
830 /*
831 * in some case A channels are all non IBSS
832 * in this case force B/G channel
833 */
Johannes Berg05c914f2008-09-11 00:01:58 +0200834 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
Zhu Yib481de92007-09-25 17:54:57 -0700835 !(is_channel_ibss(ch_info)))
836 ch_info = &priv->channel_info[0];
837
838 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
Johannes Berg8318d782008-01-24 19:38:38 +0100839 priv->band = ch_info->band;
Zhu Yib481de92007-09-25 17:54:57 -0700840
Tomas Winkler82a66bb2008-05-29 16:35:28 +0800841 iwl_set_flags_for_band(priv, priv->band);
Zhu Yib481de92007-09-25 17:54:57 -0700842
843 priv->staging_rxon.ofdm_basic_rates =
844 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
845 priv->staging_rxon.cck_basic_rates =
846 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
847
848 priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
849 RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
850 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
851 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
852 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
853 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -0700854 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700855}
856
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700857static int iwl_set_mode(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700858{
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700859 iwl_connection_init_rx_config(priv, mode);
Zhu Yib481de92007-09-25 17:54:57 -0700860 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
861
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +0800862 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700863
Mohamed Abbasfde35712007-11-29 11:10:15 +0800864 /* dont commit rxon if rf-kill is on*/
Tomas Winklerfee12472008-04-03 16:05:21 -0700865 if (!iwl_is_ready_rf(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +0800866 return -EAGAIN;
867
868 cancel_delayed_work(&priv->scan_check);
Tomas Winkler2a421b92008-06-12 09:47:10 +0800869 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800870 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +0800871 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
872 return -EAGAIN;
873 }
874
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700875 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700876
877 return 0;
878}
879
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700880static void iwl_set_rate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700881{
Johannes Berg8318d782008-01-24 19:38:38 +0100882 const struct ieee80211_supported_band *hw = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700883 struct ieee80211_rate *rate;
884 int i;
885
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700886 hw = iwl_get_hw_mode(priv, priv->band);
Saleem Abdulrasoolc4ba9622007-11-18 23:59:08 -0800887 if (!hw) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800888 IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
Saleem Abdulrasoolc4ba9622007-11-18 23:59:08 -0800889 return;
890 }
Zhu Yib481de92007-09-25 17:54:57 -0700891
892 priv->active_rate = 0;
893 priv->active_rate_basic = 0;
894
Johannes Berg8318d782008-01-24 19:38:38 +0100895 for (i = 0; i < hw->n_bitrates; i++) {
896 rate = &(hw->bitrates[i]);
897 if (rate->hw_value < IWL_RATE_COUNT)
898 priv->active_rate |= (1 << rate->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -0700899 }
900
901 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
902 priv->active_rate, priv->active_rate_basic);
903
904 /*
905 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
906 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
907 * OFDM
908 */
909 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
910 priv->staging_rxon.cck_basic_rates =
911 ((priv->active_rate_basic &
912 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
913 else
914 priv->staging_rxon.cck_basic_rates =
915 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
916
917 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
918 priv->staging_rxon.ofdm_basic_rates =
919 ((priv->active_rate_basic &
920 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
921 IWL_FIRST_OFDM_RATE) & 0xFF;
922 else
923 priv->staging_rxon.ofdm_basic_rates =
924 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
925}
926
Zhu Yib481de92007-09-25 17:54:57 -0700927
Zhu Yib481de92007-09-25 17:54:57 -0700928/******************************************************************************
929 *
930 * Generic RX handler implementations
931 *
932 ******************************************************************************/
Tomas Winkler885ba202008-05-29 16:34:55 +0800933static void iwl_rx_reply_alive(struct iwl_priv *priv,
934 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700935{
Tomas Winklerdb11d632008-05-05 10:22:33 +0800936 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Tomas Winkler885ba202008-05-29 16:34:55 +0800937 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -0700938 struct delayed_work *pwork;
939
940 palive = &pkt->u.alive_frame;
941
942 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
943 "0x%01X 0x%01X\n",
944 palive->is_valid, palive->ver_type,
945 palive->ver_subtype);
946
947 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
948 IWL_DEBUG_INFO("Initialization Alive received.\n");
949 memcpy(&priv->card_alive_init,
950 &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +0800951 sizeof(struct iwl_init_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700952 pwork = &priv->init_alive_start;
953 } else {
954 IWL_DEBUG_INFO("Runtime Alive received.\n");
955 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +0800956 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700957 pwork = &priv->alive_start;
958 }
959
960 /* We delay the ALIVE response by 5ms to
961 * give the HW RF Kill time to activate... */
962 if (palive->is_valid == UCODE_VALID_OK)
963 queue_delayed_work(priv->workqueue, pwork,
964 msecs_to_jiffies(5));
965 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800966 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700967}
968
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700969static void iwl_rx_reply_error(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +0800970 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700971{
Tomas Winklerdb11d632008-05-05 10:22:33 +0800972 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700973
Winkler, Tomas15b16872008-12-19 10:37:33 +0800974 IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
Zhu Yib481de92007-09-25 17:54:57 -0700975 "seq 0x%04X ser 0x%08X\n",
976 le32_to_cpu(pkt->u.err_resp.error_type),
977 get_cmd_string(pkt->u.err_resp.cmd_id),
978 pkt->u.err_resp.cmd_id,
979 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
980 le32_to_cpu(pkt->u.err_resp.error_info));
981}
982
983#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
984
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700985static void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700986{
Tomas Winklerdb11d632008-05-05 10:22:33 +0800987 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800988 struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
Tomas Winkler2aa6ab82008-12-11 10:33:40 -0800989 struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
Zhu Yib481de92007-09-25 17:54:57 -0700990 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
991 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
992 rxon->channel = csa->channel;
993 priv->staging_rxon.channel = csa->channel;
994}
995
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700996static void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +0800997 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700998{
Tomas Winkler0a6857e2008-03-12 16:58:49 -0700999#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklerdb11d632008-05-05 10:22:33 +08001000 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Tomas Winkler2aa6ab82008-12-11 10:33:40 -08001001 struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001002 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
1003 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
1004#endif
1005}
1006
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001007static void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001008 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001009{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001010 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001011 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
1012 "notification for %s:\n",
1013 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
Ester Kummerbf403db2008-05-05 10:22:40 +08001014 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
Zhu Yib481de92007-09-25 17:54:57 -07001015}
1016
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001017static void iwl_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07001018{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001019 struct iwl_priv *priv =
1020 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07001021 struct sk_buff *beacon;
1022
1023 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02001024 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07001025
1026 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001027 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07001028 return;
1029 }
1030
1031 mutex_lock(&priv->mutex);
1032 /* new beacon skb is allocated every time; dispose previous.*/
1033 if (priv->ibss_beacon)
1034 dev_kfree_skb(priv->ibss_beacon);
1035
1036 priv->ibss_beacon = beacon;
1037 mutex_unlock(&priv->mutex);
1038
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001039 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001040}
1041
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001042/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001043 * iwl_bg_statistics_periodic - Timer callback to queue statistics
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001044 *
1045 * This callback is provided in order to send a statistics request.
1046 *
1047 * This timer function is continually reset to execute within
1048 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
1049 * was received. We need to ensure we receive the statistics in order
1050 * to update the temperature used for calibrating the TXPOWER.
1051 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001052static void iwl_bg_statistics_periodic(unsigned long data)
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001053{
1054 struct iwl_priv *priv = (struct iwl_priv *)data;
1055
1056 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1057 return;
1058
Mohamed Abbas61780ee2008-10-29 14:05:49 -07001059 /* dont send host command if rf-kill is on */
1060 if (!iwl_is_ready_rf(priv))
1061 return;
1062
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001063 iwl_send_statistics_request(priv, CMD_ASYNC);
1064}
1065
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001066static void iwl_rx_beacon_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001067 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001068{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001069#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklerdb11d632008-05-05 10:22:33 +08001070 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Tomas Winkler2aa6ab82008-12-11 10:33:40 -08001071 struct iwl4965_beacon_notif *beacon =
1072 (struct iwl4965_beacon_notif *)pkt->u.raw;
Tomas Winklere7d326ac2008-06-12 09:47:11 +08001073 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -07001074
1075 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
1076 "tsf %d %d rate %d\n",
Tomas Winkler25a65722008-06-12 09:47:07 +08001077 le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
Zhu Yib481de92007-09-25 17:54:57 -07001078 beacon->beacon_notify_hdr.failure_frame,
1079 le32_to_cpu(beacon->ibss_mgr_status),
1080 le32_to_cpu(beacon->high_tsf),
1081 le32_to_cpu(beacon->low_tsf), rate);
1082#endif
1083
Johannes Berg05c914f2008-09-11 00:01:58 +02001084 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -07001085 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1086 queue_work(priv->workqueue, &priv->beacon_update);
1087}
1088
Zhu Yib481de92007-09-25 17:54:57 -07001089/* Handle notification from uCode that card's power state is changing
1090 * due to software, hardware, or critical temperature RFKILL */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001091static void iwl_rx_card_state_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001092 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001093{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001094 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001095 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1096 unsigned long status = priv->status;
1097
1098 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
1099 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1100 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1101
1102 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
1103 RF_CARD_DISABLED)) {
1104
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001105 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001106 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1107
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001108 if (!iwl_grab_nic_access(priv)) {
1109 iwl_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07001110 priv, HBUS_TARG_MBX_C,
1111 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
1112
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001113 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001114 }
1115
1116 if (!(flags & RXON_CARD_DISABLED)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001117 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07001118 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001119 if (!iwl_grab_nic_access(priv)) {
1120 iwl_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07001121 priv, HBUS_TARG_MBX_C,
1122 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
1123
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001124 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001125 }
1126 }
1127
1128 if (flags & RF_CARD_DISABLED) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001129 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001130 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001131 iwl_read32(priv, CSR_UCODE_DRV_GP1);
1132 if (!iwl_grab_nic_access(priv))
1133 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001134 }
1135 }
1136
1137 if (flags & HW_CARD_DISABLED)
1138 set_bit(STATUS_RF_KILL_HW, &priv->status);
1139 else
1140 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1141
1142
1143 if (flags & SW_CARD_DISABLED)
1144 set_bit(STATUS_RF_KILL_SW, &priv->status);
1145 else
1146 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1147
1148 if (!(flags & RXON_CARD_DISABLED))
Tomas Winkler2a421b92008-06-12 09:47:10 +08001149 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001150
1151 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1152 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1153 (test_bit(STATUS_RF_KILL_SW, &status) !=
1154 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1155 queue_work(priv->workqueue, &priv->rf_kill);
1156 else
1157 wake_up_interruptible(&priv->wait_command_queue);
1158}
1159
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001160int iwl_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
Tomas Winklere2e3c572008-07-18 13:53:04 +08001161{
1162 int ret;
1163 unsigned long flags;
1164
1165 spin_lock_irqsave(&priv->lock, flags);
1166 ret = iwl_grab_nic_access(priv);
1167 if (ret)
1168 goto err;
1169
1170 if (src == IWL_PWR_SRC_VAUX) {
1171 u32 val;
Tomas Winklere7b63582008-09-03 11:26:49 +08001172 ret = pci_read_config_dword(priv->pci_dev, PCI_CFG_POWER_SOURCE,
Tomas Winklere2e3c572008-07-18 13:53:04 +08001173 &val);
1174
1175 if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT)
1176 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
1177 APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
1178 ~APMG_PS_CTRL_MSK_PWR_SRC);
1179 } else {
1180 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
1181 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
1182 ~APMG_PS_CTRL_MSK_PWR_SRC);
1183 }
1184
1185 iwl_release_nic_access(priv);
1186err:
1187 spin_unlock_irqrestore(&priv->lock, flags);
1188 return ret;
1189}
1190
Zhu Yib481de92007-09-25 17:54:57 -07001191/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001192 * iwl_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07001193 *
1194 * Setup the RX handlers for each of the reply types sent from the uCode
1195 * to the host.
1196 *
1197 * This function chains into the hardware specific files for them to setup
1198 * any hardware specific handlers as well.
1199 */
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08001200static void iwl_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001201{
Tomas Winkler885ba202008-05-29 16:34:55 +08001202 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001203 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
1204 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001205 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001206 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001207 iwl_rx_pm_debug_statistics_notif;
1208 priv->rx_handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001209
Ben Cahill9fbab512007-11-29 11:09:47 +08001210 /*
1211 * The same handler is used for both the REPLY to a discrete
1212 * statistics request from the host as well as for the periodic
1213 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07001214 */
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08001215 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_rx_statistics;
1216 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
Tomas Winkler2a421b92008-06-12 09:47:10 +08001217
Tomas Winkler21c339b2008-11-07 09:58:41 -08001218 iwl_setup_spectrum_handlers(priv);
Tomas Winkler2a421b92008-06-12 09:47:10 +08001219 iwl_setup_rx_scan_handlers(priv);
1220
Ron Rindjunsky37a44212008-05-29 16:35:18 +08001221 /* status change handler */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001222 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001223
Tomas Winklerc1354752008-05-29 16:35:04 +08001224 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
1225 iwl_rx_missed_beacon_notif;
Ron Rindjunsky37a44212008-05-29 16:35:18 +08001226 /* Rx handlers */
Emmanuel Grumbach1781a072008-06-30 17:23:09 +08001227 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl_rx_reply_rx_phy;
1228 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl_rx_reply_rx;
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08001229 /* block ack */
1230 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl_rx_reply_compressed_ba;
Ben Cahill9fbab512007-11-29 11:09:47 +08001231 /* Set up hardware specific Rx handlers */
Emmanuel Grumbachd4789ef2008-04-24 11:55:20 -07001232 priv->cfg->ops->lib->rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001233}
1234
Zhu Yib481de92007-09-25 17:54:57 -07001235/**
Tomas Winklera55360e2008-05-05 10:22:28 +08001236 * iwl_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001237 *
1238 * Uses the priv->rx_handlers callback function array to invoke
1239 * the appropriate handlers, including command responses,
1240 * frame-received notifications, and other notifications.
1241 */
Tomas Winklera55360e2008-05-05 10:22:28 +08001242void iwl_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001243{
Tomas Winklera55360e2008-05-05 10:22:28 +08001244 struct iwl_rx_mem_buffer *rxb;
Tomas Winklerdb11d632008-05-05 10:22:33 +08001245 struct iwl_rx_packet *pkt;
Tomas Winklera55360e2008-05-05 10:22:28 +08001246 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001247 u32 r, i;
1248 int reclaim;
1249 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001250 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001251 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07001252
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001253 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1254 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8d864222008-11-07 09:58:39 -08001255 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07001256 i = rxq->read;
1257
1258 /* Rx interrupt, but nothing sent from uCode */
1259 if (i == r)
Ester Kummerf3d67992008-05-06 11:05:12 +08001260 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001261
Tomas Winklera55360e2008-05-05 10:22:28 +08001262 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001263 fill_rx = 1;
1264
Zhu Yib481de92007-09-25 17:54:57 -07001265 while (i != r) {
1266 rxb = rxq->queue[i];
1267
Ben Cahill9fbab512007-11-29 11:09:47 +08001268 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001269 * then a bug has been introduced in the queue refilling
1270 * routines -- catch it here */
1271 BUG_ON(rxb == NULL);
1272
1273 rxq->queue[i] = NULL;
1274
Johannes Berge91af0a2008-11-19 01:22:51 +01001275 dma_sync_single_range_for_cpu(
1276 &priv->pci_dev->dev, rxb->real_dma_addr,
1277 rxb->aligned_dma_addr - rxb->real_dma_addr,
1278 priv->hw_params.rx_buf_size,
1279 PCI_DMA_FROMDEVICE);
Tomas Winklerdb11d632008-05-05 10:22:33 +08001280 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001281
1282 /* Reclaim a command buffer only if this packet is a response
1283 * to a (driver-originated) command.
1284 * If the packet (e.g. Rx frame) originated from uCode,
1285 * there is no command buffer to reclaim.
1286 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1287 * but apparently a few don't get set; catch them here. */
1288 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1289 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
Tomas Winkler857485c2008-03-21 13:53:44 -07001290 (pkt->hdr.cmd != REPLY_RX) &&
Daniel Halperin7dddaf12008-10-23 23:48:58 -07001291 (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) &&
Zhu Yicfe01702007-09-27 11:27:31 +08001292 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
Zhu Yib481de92007-09-25 17:54:57 -07001293 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1294 (pkt->hdr.cmd != REPLY_TX);
1295
1296 /* Based on type of command response or notification,
1297 * handle those that need handling via function in
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001298 * rx_handlers table. See iwl_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001299 if (priv->rx_handlers[pkt->hdr.cmd]) {
Ester Kummerf3d67992008-05-06 11:05:12 +08001300 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r,
1301 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001302 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1303 } else {
1304 /* No handling needed */
Ester Kummerf3d67992008-05-06 11:05:12 +08001305 IWL_DEBUG(IWL_DL_RX,
Zhu Yib481de92007-09-25 17:54:57 -07001306 "r %d i %d No handler needed for %s, 0x%02x\n",
1307 r, i, get_cmd_string(pkt->hdr.cmd),
1308 pkt->hdr.cmd);
1309 }
1310
1311 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001312 /* Invoke any callbacks, transfer the skb to caller, and
Tomas Winkler857485c2008-03-21 13:53:44 -07001313 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001314 * as we reclaim the driver command queue */
1315 if (rxb && rxb->skb)
Tomas Winkler17b88922008-05-29 16:35:12 +08001316 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001317 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001318 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07001319 }
1320
1321 /* For now we just don't re-use anything. We can tweak this
1322 * later to try and re-use notification packets and SKBs that
1323 * fail to Rx correctly */
1324 if (rxb->skb != NULL) {
1325 priv->alloc_rxb_skb--;
1326 dev_kfree_skb_any(rxb->skb);
1327 rxb->skb = NULL;
1328 }
1329
Johannes Berg40185172008-11-18 01:47:21 +01001330 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
1331 priv->hw_params.rx_buf_size + 256,
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02001332 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001333 spin_lock_irqsave(&rxq->lock, flags);
1334 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1335 spin_unlock_irqrestore(&rxq->lock, flags);
1336 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001337 /* If there are a lot of unused frames,
1338 * restock the Rx queue so ucode wont assert. */
1339 if (fill_rx) {
1340 count++;
1341 if (count >= 8) {
1342 priv->rxq.read = i;
Zhu Yif1bc4ac2008-12-17 16:52:33 +08001343 iwl_rx_queue_restock(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001344 count = 0;
1345 }
1346 }
Zhu Yib481de92007-09-25 17:54:57 -07001347 }
1348
1349 /* Backtrack one entry */
1350 priv->rxq.read = i;
Tomas Winklera55360e2008-05-05 10:22:28 +08001351 iwl_rx_queue_restock(priv);
1352}
Tomas Winklera55360e2008-05-05 10:22:28 +08001353
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001354#ifdef CONFIG_IWLWIFI_DEBUG
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001355static void iwl_print_rx_config_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001356{
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001357 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
Joe Perches0795af52007-10-03 17:59:30 -07001358
Zhu Yib481de92007-09-25 17:54:57 -07001359 IWL_DEBUG_RADIO("RX CONFIG:\n");
Ester Kummerbf403db2008-05-05 10:22:40 +08001360 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
Zhu Yib481de92007-09-25 17:54:57 -07001361 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
1362 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
1363 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
1364 le32_to_cpu(rxon->filter_flags));
1365 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
1366 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
1367 rxon->ofdm_basic_rates);
1368 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
Johannes Berge1749612008-10-27 15:59:26 -07001369 IWL_DEBUG_RADIO("u8[6] node_addr: %pM\n", rxon->node_addr);
1370 IWL_DEBUG_RADIO("u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07001371 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
1372}
1373#endif
1374
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001375/* call this function to flush any scheduled tasklet */
1376static inline void iwl_synchronize_irq(struct iwl_priv *priv)
1377{
Tomas Winklera96a27f2008-10-23 23:48:56 -07001378 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001379 synchronize_irq(priv->pci_dev->irq);
1380 tasklet_kill(&priv->irq_tasklet);
1381}
1382
Zhu Yib481de92007-09-25 17:54:57 -07001383/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001384 * iwl_irq_handle_error - called for HW or SW error interrupt from card
Zhu Yib481de92007-09-25 17:54:57 -07001385 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001386static void iwl_irq_handle_error(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001387{
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001388 /* Set the FW error flag -- cleared on iwl_down */
Zhu Yib481de92007-09-25 17:54:57 -07001389 set_bit(STATUS_FW_ERROR, &priv->status);
1390
1391 /* Cancel currently queued command. */
1392 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1393
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001394#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001395 if (priv->debug_level & IWL_DL_FW_ERRORS) {
Ester Kummerede0cba2008-05-29 16:34:46 +08001396 iwl_dump_nic_error_log(priv);
Ester Kummer189a2b52008-05-15 13:54:18 +08001397 iwl_dump_nic_event_log(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001398 iwl_print_rx_config_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001399 }
1400#endif
1401
1402 wake_up_interruptible(&priv->wait_command_queue);
1403
1404 /* Keep the restart process from trying to send host
1405 * commands by clearing the INIT status bit */
1406 clear_bit(STATUS_READY, &priv->status);
1407
1408 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Ester Kummerf3d67992008-05-06 11:05:12 +08001409 IWL_DEBUG(IWL_DL_FW_ERRORS,
Zhu Yib481de92007-09-25 17:54:57 -07001410 "Restarting adapter due to uCode error.\n");
1411
Tomas Winkler3109ece2008-03-28 16:33:35 -07001412 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001413 memcpy(&priv->recovery_rxon, &priv->active_rxon,
1414 sizeof(priv->recovery_rxon));
1415 priv->error_recovering = 1;
1416 }
Ester Kummer3a1081e2008-05-06 11:05:14 +08001417 if (priv->cfg->mod_params->restart_fw)
1418 queue_work(priv->workqueue, &priv->restart);
Zhu Yib481de92007-09-25 17:54:57 -07001419 }
1420}
1421
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001422static void iwl_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001423{
1424 unsigned long flags;
1425
1426 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
1427 sizeof(priv->staging_rxon));
1428 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001429 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001430
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08001431 iwl_rxon_add_station(priv, priv->bssid, 1);
Zhu Yib481de92007-09-25 17:54:57 -07001432
1433 spin_lock_irqsave(&priv->lock, flags);
1434 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
1435 priv->error_recovering = 0;
1436 spin_unlock_irqrestore(&priv->lock, flags);
1437}
1438
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001439static void iwl_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001440{
1441 u32 inta, handled = 0;
1442 u32 inta_fh;
1443 unsigned long flags;
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001444#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001445 u32 inta_mask;
1446#endif
1447
1448 spin_lock_irqsave(&priv->lock, flags);
1449
1450 /* Ack/clear/reset pending uCode interrupts.
1451 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1452 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001453 inta = iwl_read32(priv, CSR_INT);
1454 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07001455
1456 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1457 * Any new interrupts that happen after this, either while we're
1458 * in this tasklet, or later, will show up in next ISR/tasklet. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001459 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1460 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001461
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001462#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001463 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001464 /* just for debug */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001465 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07001466 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1467 inta, inta_mask, inta_fh);
1468 }
1469#endif
1470
1471 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1472 * atomic, make sure that inta covers all the interrupts that
1473 * we've discovered, even if FH interrupt came in just after
1474 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001475 if (inta_fh & CSR49_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001476 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001477 if (inta_fh & CSR49_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001478 inta |= CSR_INT_BIT_FH_TX;
1479
1480 /* Now service all interrupt bits discovered above. */
1481 if (inta & CSR_INT_BIT_HW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001482 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001483
1484 /* Tell the device to stop sending interrupts */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001485 iwl_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001486
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001487 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001488
1489 handled |= CSR_INT_BIT_HW_ERR;
1490
1491 spin_unlock_irqrestore(&priv->lock, flags);
1492
1493 return;
1494 }
1495
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001496#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001497 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07001498 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001499 if (inta & CSR_INT_BIT_SCD)
1500 IWL_DEBUG_ISR("Scheduler finished to transmit "
1501 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001502
1503 /* Alive notification via Rx interrupt will do the real work */
1504 if (inta & CSR_INT_BIT_ALIVE)
1505 IWL_DEBUG_ISR("Alive interrupt\n");
1506 }
1507#endif
1508 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001509 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07001510
Ben Cahill9fbab512007-11-29 11:09:47 +08001511 /* HW RF KILL switch toggled */
Zhu Yib481de92007-09-25 17:54:57 -07001512 if (inta & CSR_INT_BIT_RF_KILL) {
1513 int hw_rf_kill = 0;
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001514 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yib481de92007-09-25 17:54:57 -07001515 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
1516 hw_rf_kill = 1;
1517
Ester Kummerf3d67992008-05-06 11:05:12 +08001518 IWL_DEBUG(IWL_DL_RF_KILL, "RF_KILL bit toggled to %s.\n",
Abhijeet Kolekarc3056062008-11-12 13:14:08 -08001519 hw_rf_kill ? "disable radio" : "enable radio");
Zhu Yib481de92007-09-25 17:54:57 -07001520
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +08001521 /* driver only loads ucode once setting the interface up.
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01001522 * the driver allows loading the ucode even if the radio
1523 * is killed. Hence update the killswitch state here. The
1524 * rfkill handler will care about restarting if needed.
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +08001525 */
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01001526 if (!test_bit(STATUS_ALIVE, &priv->status)) {
1527 if (hw_rf_kill)
1528 set_bit(STATUS_RF_KILL_HW, &priv->status);
1529 else
1530 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1531 queue_work(priv->workqueue, &priv->rf_kill);
Mohamed Abbasedb34222008-12-11 10:33:37 -08001532 }
Zhu Yib481de92007-09-25 17:54:57 -07001533
1534 handled |= CSR_INT_BIT_RF_KILL;
1535 }
1536
Ben Cahill9fbab512007-11-29 11:09:47 +08001537 /* Chip got too hot and stopped itself */
Zhu Yib481de92007-09-25 17:54:57 -07001538 if (inta & CSR_INT_BIT_CT_KILL) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001539 IWL_ERR(priv, "Microcode CT kill error detected.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001540 handled |= CSR_INT_BIT_CT_KILL;
1541 }
1542
1543 /* Error detected by uCode */
1544 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001545 IWL_ERR(priv, "Microcode SW error detected. "
1546 " Restarting 0x%X.\n", inta);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001547 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001548 handled |= CSR_INT_BIT_SW_ERR;
1549 }
1550
1551 /* uCode wakes up after power-down sleep */
1552 if (inta & CSR_INT_BIT_WAKEUP) {
1553 IWL_DEBUG_ISR("Wakeup interrupt\n");
Tomas Winklera55360e2008-05-05 10:22:28 +08001554 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Tomas Winklerbabcebf2008-05-15 13:54:00 +08001555 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
1556 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
1557 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
1558 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
1559 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1560 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07001561
1562 handled |= CSR_INT_BIT_WAKEUP;
1563 }
1564
1565 /* All uCode command responses, including Tx command responses,
1566 * Rx "responses" (frame-received notification), and other
1567 * notifications from uCode come through here*/
1568 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Tomas Winklera55360e2008-05-05 10:22:28 +08001569 iwl_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001570 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1571 }
1572
1573 if (inta & CSR_INT_BIT_FH_TX) {
1574 IWL_DEBUG_ISR("Tx interrupt\n");
1575 handled |= CSR_INT_BIT_FH_TX;
Ron Rindjunskydbb983b2008-05-15 13:54:12 +08001576 /* FH finished to write, send event */
1577 priv->ucode_write_complete = 1;
1578 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07001579 }
1580
1581 if (inta & ~handled)
Winkler, Tomas15b16872008-12-19 10:37:33 +08001582 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Zhu Yib481de92007-09-25 17:54:57 -07001583
1584 if (inta & ~CSR_INI_SET_MASK) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001585 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Zhu Yib481de92007-09-25 17:54:57 -07001586 inta & ~CSR_INI_SET_MASK);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001587 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001588 }
1589
1590 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001591 /* only Re-enable if diabled by irq */
1592 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001593 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001594
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001595#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001596 if (priv->debug_level & (IWL_DL_ISR)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001597 inta = iwl_read32(priv, CSR_INT);
1598 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1599 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07001600 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
1601 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
1602 }
1603#endif
1604 spin_unlock_irqrestore(&priv->lock, flags);
1605}
1606
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001607static irqreturn_t iwl_isr(int irq, void *data)
Zhu Yib481de92007-09-25 17:54:57 -07001608{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001609 struct iwl_priv *priv = data;
Zhu Yib481de92007-09-25 17:54:57 -07001610 u32 inta, inta_mask;
1611 u32 inta_fh;
1612 if (!priv)
1613 return IRQ_NONE;
1614
1615 spin_lock(&priv->lock);
1616
1617 /* Disable (but don't clear!) interrupts here to avoid
1618 * back-to-back ISRs and sporadic interrupts from our NIC.
1619 * If we have something to service, the tasklet will re-enable ints.
1620 * If we *don't* have something, we'll re-enable before leaving here. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001621 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
1622 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07001623
1624 /* Discover which interrupts are active/pending */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001625 inta = iwl_read32(priv, CSR_INT);
1626 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07001627
1628 /* Ignore interrupt if there's nothing in NIC to service.
1629 * This may be due to IRQ shared with another device,
1630 * or due to sporadic interrupts thrown from our NIC. */
1631 if (!inta && !inta_fh) {
1632 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
1633 goto none;
1634 }
1635
1636 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
Oliver Neukum66fbb542007-11-15 09:31:10 +08001637 /* Hardware disappeared. It might have already raised
1638 * an interrupt */
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001639 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
Oliver Neukum66fbb542007-11-15 09:31:10 +08001640 goto unplugged;
Zhu Yib481de92007-09-25 17:54:57 -07001641 }
1642
1643 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1644 inta, inta_mask, inta_fh);
1645
Joonwoo Park25c03d82008-01-23 10:15:20 -08001646 inta &= ~CSR_INT_BIT_SCD;
1647
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001648 /* iwl_irq_tasklet() will service interrupts and re-enable them */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001649 if (likely(inta || inta_fh))
1650 tasklet_schedule(&priv->irq_tasklet);
Zhu Yib481de92007-09-25 17:54:57 -07001651
Oliver Neukum66fbb542007-11-15 09:31:10 +08001652 unplugged:
1653 spin_unlock(&priv->lock);
Zhu Yib481de92007-09-25 17:54:57 -07001654 return IRQ_HANDLED;
1655
1656 none:
1657 /* re-enable interrupts here since we don't have anything to service. */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001658 /* only Re-enable if diabled by irq */
1659 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001660 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001661 spin_unlock(&priv->lock);
1662 return IRQ_NONE;
1663}
1664
Zhu Yib481de92007-09-25 17:54:57 -07001665/******************************************************************************
1666 *
1667 * uCode download functions
1668 *
1669 ******************************************************************************/
1670
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001671static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001672{
Tomas Winkler98c92212008-01-14 17:46:20 -08001673 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
1674 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
1675 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1676 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
1677 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1678 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001679}
1680
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001681static void iwl_nic_start(struct iwl_priv *priv)
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08001682{
1683 /* Remove all resets to allow NIC to operate */
1684 iwl_write32(priv, CSR_RESET, 0);
1685}
1686
1687
Zhu Yib481de92007-09-25 17:54:57 -07001688/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001689 * iwl_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07001690 *
1691 * Copy into buffers for card to fetch via bus-mastering
1692 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001693static int iwl_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001694{
Ron Rindjunsky14b3d332008-06-13 15:44:54 +08001695 struct iwl_ucode *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001696 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07001697 const struct firmware *ucode_raw;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001698 const char *name_pre = priv->cfg->fw_name_pre;
1699 const unsigned int api_max = priv->cfg->ucode_api_max;
1700 const unsigned int api_min = priv->cfg->ucode_api_min;
1701 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07001702 u8 *src;
1703 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001704 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07001705
1706 /* Ask kernel firmware_class module to get the boot firmware off disk.
1707 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08001708 for (index = api_max; index >= api_min; index--) {
1709 sprintf(buf, "%s%d%s", name_pre, index, ".ucode");
1710 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
1711 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001712 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001713 buf, ret);
1714 if (ret == -ENOENT)
1715 continue;
1716 else
1717 goto error;
1718 } else {
1719 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08001720 IWL_ERR(priv, "Loaded firmware %s, "
1721 "which is deprecated. "
1722 "Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001723 buf, api_max);
Winkler, Tomas15b16872008-12-19 10:37:33 +08001724
Reinette Chatrea0987a82008-12-02 12:14:06 -08001725 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
1726 buf, ucode_raw->size);
1727 break;
1728 }
Zhu Yib481de92007-09-25 17:54:57 -07001729 }
1730
Reinette Chatrea0987a82008-12-02 12:14:06 -08001731 if (ret < 0)
1732 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07001733
1734 /* Make sure that we got at least our header! */
1735 if (ucode_raw->size < sizeof(*ucode)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001736 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001737 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001738 goto err_release;
1739 }
1740
1741 /* Data from ucode file: header followed by uCode images */
1742 ucode = (void *)ucode_raw->data;
1743
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08001744 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08001745 api_ver = IWL_UCODE_API(priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07001746 inst_size = le32_to_cpu(ucode->inst_size);
1747 data_size = le32_to_cpu(ucode->data_size);
1748 init_size = le32_to_cpu(ucode->init_size);
1749 init_data_size = le32_to_cpu(ucode->init_data_size);
1750 boot_size = le32_to_cpu(ucode->boot_size);
1751
Reinette Chatrea0987a82008-12-02 12:14:06 -08001752 /* api_ver should match the api version forming part of the
1753 * firmware filename ... but we don't check for that and only rely
1754 * on the API version read from firware header from here on forward */
1755
1756 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001757 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08001758 "Driver supports v%u, firmware is v%u.\n",
1759 api_max, api_ver);
1760 priv->ucode_ver = 0;
1761 ret = -EINVAL;
1762 goto err_release;
1763 }
1764 if (api_ver != api_max)
Tomas Winkler978785a2008-12-19 10:37:31 +08001765 IWL_ERR(priv, "Firmware has old API version. Expected v%u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08001766 "got v%u. New firmware can be obtained "
1767 "from http://www.intellinuxwireless.org.\n",
1768 api_max, api_ver);
1769
Tomas Winkler978785a2008-12-19 10:37:31 +08001770 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
1771 IWL_UCODE_MAJOR(priv->ucode_ver),
1772 IWL_UCODE_MINOR(priv->ucode_ver),
1773 IWL_UCODE_API(priv->ucode_ver),
1774 IWL_UCODE_SERIAL(priv->ucode_ver));
Reinette Chatrea0987a82008-12-02 12:14:06 -08001775
1776 IWL_DEBUG_INFO("f/w package hdr ucode version raw = 0x%x\n",
1777 priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07001778 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
1779 inst_size);
1780 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
1781 data_size);
1782 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
1783 init_size);
1784 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
1785 init_data_size);
1786 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
1787 boot_size);
1788
1789 /* Verify size of file vs. image size info in file's header */
1790 if (ucode_raw->size < sizeof(*ucode) +
1791 inst_size + data_size + init_size +
1792 init_data_size + boot_size) {
1793
1794 IWL_DEBUG_INFO("uCode file size %d too small\n",
1795 (int)ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001796 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001797 goto err_release;
1798 }
1799
1800 /* Verify that uCode images will fit in card's SRAM */
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001801 if (inst_size > priv->hw_params.max_inst_size) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08001802 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
1803 inst_size);
1804 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001805 goto err_release;
1806 }
1807
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001808 if (data_size > priv->hw_params.max_data_size) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08001809 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
1810 data_size);
1811 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001812 goto err_release;
1813 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001814 if (init_size > priv->hw_params.max_inst_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001815 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001816 ("uCode init instr len %d too large to fit in\n",
1817 init_size);
1818 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001819 goto err_release;
1820 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001821 if (init_data_size > priv->hw_params.max_data_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001822 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001823 ("uCode init data len %d too large to fit in\n",
1824 init_data_size);
1825 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001826 goto err_release;
1827 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001828 if (boot_size > priv->hw_params.max_bsm_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001829 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001830 ("uCode boot instr len %d too large to fit in\n",
1831 boot_size);
1832 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001833 goto err_release;
1834 }
1835
1836 /* Allocate ucode buffers for card's bus-master loading ... */
1837
1838 /* Runtime instructions and 2 copies of data:
1839 * 1) unmodified from disk
1840 * 2) backup cache for save/restore during power-downs */
1841 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001842 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07001843
1844 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001845 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07001846
1847 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001848 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07001849
1850 /* Initialization instructions and data */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001851 if (init_size && init_data_size) {
1852 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001853 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Zhu Yib481de92007-09-25 17:54:57 -07001854
Tomas Winkler90e759d2007-11-29 11:09:41 +08001855 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001856 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001857
1858 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
1859 goto err_pci_alloc;
1860 }
Zhu Yib481de92007-09-25 17:54:57 -07001861
1862 /* Bootstrap (instructions only, no data) */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001863 if (boot_size) {
1864 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001865 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001866
Tomas Winkler90e759d2007-11-29 11:09:41 +08001867 if (!priv->ucode_boot.v_addr)
1868 goto err_pci_alloc;
1869 }
Zhu Yib481de92007-09-25 17:54:57 -07001870
1871 /* Copy images into buffers for card's bus-master reads ... */
1872
1873 /* Runtime instructions (first block of data in file) */
1874 src = &ucode->data[0];
1875 len = priv->ucode_code.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001876 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001877 memcpy(priv->ucode_code.v_addr, src, len);
1878 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
1879 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
1880
1881 /* Runtime data (2nd block)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001882 * NOTE: Copy into backup buffer will be done in iwl_up() */
Zhu Yib481de92007-09-25 17:54:57 -07001883 src = &ucode->data[inst_size];
1884 len = priv->ucode_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001885 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001886 memcpy(priv->ucode_data.v_addr, src, len);
1887 memcpy(priv->ucode_data_backup.v_addr, src, len);
1888
1889 /* Initialization instructions (3rd block) */
1890 if (init_size) {
1891 src = &ucode->data[inst_size + data_size];
1892 len = priv->ucode_init.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001893 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
1894 len);
Zhu Yib481de92007-09-25 17:54:57 -07001895 memcpy(priv->ucode_init.v_addr, src, len);
1896 }
1897
1898 /* Initialization data (4th block) */
1899 if (init_data_size) {
1900 src = &ucode->data[inst_size + data_size + init_size];
1901 len = priv->ucode_init_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001902 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
1903 len);
Zhu Yib481de92007-09-25 17:54:57 -07001904 memcpy(priv->ucode_init_data.v_addr, src, len);
1905 }
1906
1907 /* Bootstrap instructions (5th block) */
1908 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
1909 len = priv->ucode_boot.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001910 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001911 memcpy(priv->ucode_boot.v_addr, src, len);
1912
1913 /* We have our copies now, allow OS release its copies */
1914 release_firmware(ucode_raw);
1915 return 0;
1916
1917 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08001918 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001919 ret = -ENOMEM;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001920 iwl_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001921
1922 err_release:
1923 release_firmware(ucode_raw);
1924
1925 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08001926 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07001927}
1928
Mohamed Abbasada17512008-11-07 09:58:34 -08001929/* temporary */
1930static int iwl_mac_beacon_update(struct ieee80211_hw *hw,
1931 struct sk_buff *skb);
1932
Zhu Yib481de92007-09-25 17:54:57 -07001933/**
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001934 * iwl_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07001935 * from protocol/runtime uCode (initialization uCode's
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001936 * Alive gets handled by iwl_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07001937 */
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001938static void iwl_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001939{
Tomas Winkler57aab752008-04-14 21:16:03 -07001940 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001941
1942 IWL_DEBUG_INFO("Runtime Alive received.\n");
1943
1944 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
1945 /* We had an error bringing up the hardware, so take it
1946 * all the way back down so we can try again */
1947 IWL_DEBUG_INFO("Alive failed.\n");
1948 goto restart;
1949 }
1950
1951 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
1952 * This is a paranoid check, because we would not have gotten the
1953 * "runtime" alive if code weren't properly loaded. */
Emmanuel Grumbachb0692f22008-04-24 11:55:18 -07001954 if (iwl_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001955 /* Runtime instruction load was bad;
1956 * take it all the way back down so we can try again */
1957 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
1958 goto restart;
1959 }
1960
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08001961 iwl_clear_stations_table(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07001962 ret = priv->cfg->ops->lib->alive_notify(priv);
1963 if (ret) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001964 IWL_WARN(priv,
1965 "Could not complete ALIVE transition [ntf]: %d\n", ret);
Zhu Yib481de92007-09-25 17:54:57 -07001966 goto restart;
1967 }
1968
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001969 /* After the ALIVE response, we can send host commands to the uCode */
Zhu Yib481de92007-09-25 17:54:57 -07001970 set_bit(STATUS_ALIVE, &priv->status);
1971
Tomas Winklerfee12472008-04-03 16:05:21 -07001972 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001973 return;
1974
Johannes Berg36d68252008-05-15 12:55:26 +02001975 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07001976
1977 priv->active_rate = priv->rates_mask;
1978 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
1979
Tomas Winkler3109ece2008-03-28 16:33:35 -07001980 if (iwl_is_associated(priv)) {
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001981 struct iwl_rxon_cmd *active_rxon =
1982 (struct iwl_rxon_cmd *)&priv->active_rxon;
Zhu Yib481de92007-09-25 17:54:57 -07001983
1984 memcpy(&priv->staging_rxon, &priv->active_rxon,
1985 sizeof(priv->staging_rxon));
1986 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1987 } else {
1988 /* Initialize our rx_config data */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001989 iwl_connection_init_rx_config(priv, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07001990 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
1991 }
1992
Ben Cahill9fbab512007-11-29 11:09:47 +08001993 /* Configure Bluetooth device coexistence support */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001994 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001995
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001996 iwl_reset_run_time_calib(priv);
1997
Zhu Yib481de92007-09-25 17:54:57 -07001998 /* Configure the adapter for unassociated operation */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001999 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002000
2001 /* At this point, the NIC is initialized and operational */
Emmanuel Grumbach47f4a582008-06-12 09:47:13 +08002002 iwl_rf_kill_ct_config(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002003
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07002004 iwl_leds_register(priv);
2005
Zhu Yib481de92007-09-25 17:54:57 -07002006 IWL_DEBUG_INFO("ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07002007 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002008 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07002009
2010 if (priv->error_recovering)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002011 iwl_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002012
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08002013 iwl_power_update_mode(priv, 1);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002014
Mohamed Abbasada17512008-11-07 09:58:34 -08002015 /* reassociate for ADHOC mode */
2016 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
2017 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
2018 priv->vif);
2019 if (beacon)
2020 iwl_mac_beacon_update(priv->hw, beacon);
2021 }
2022
2023
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002024 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002025 iwl_set_mode(priv, priv->iw_mode);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002026
Zhu Yib481de92007-09-25 17:54:57 -07002027 return;
2028
2029 restart:
2030 queue_work(priv->workqueue, &priv->restart);
2031}
2032
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002033static void iwl_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07002034
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002035static void __iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002036{
2037 unsigned long flags;
2038 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002039
2040 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
2041
Zhu Yib481de92007-09-25 17:54:57 -07002042 if (!exit_pending)
2043 set_bit(STATUS_EXIT_PENDING, &priv->status);
2044
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07002045 iwl_leds_unregister(priv);
2046
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08002047 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002048
2049 /* Unblock any waiting calls */
2050 wake_up_interruptible_all(&priv->wait_command_queue);
2051
Zhu Yib481de92007-09-25 17:54:57 -07002052 /* Wipe out the EXIT_PENDING status bit if we are not actually
2053 * exiting the module */
2054 if (!exit_pending)
2055 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2056
2057 /* stop and reset the on-board processor */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002058 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07002059
2060 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002061 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002062 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002063 spin_unlock_irqrestore(&priv->lock, flags);
2064 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002065
2066 if (priv->mac80211_registered)
2067 ieee80211_stop_queues(priv->hw);
2068
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002069 /* If we have not previously called iwl_init() then
Zhu Yib481de92007-09-25 17:54:57 -07002070 * clear all bits but the RF Kill and SUSPEND bits and return */
Tomas Winklerfee12472008-04-03 16:05:21 -07002071 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002072 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2073 STATUS_RF_KILL_HW |
2074 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2075 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08002076 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2077 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002078 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002079 STATUS_IN_SUSPEND |
2080 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2081 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002082 goto exit;
2083 }
2084
2085 /* ...otherwise clear out all the status bits but the RF Kill and
2086 * SUSPEND bits and continue taking the NIC down. */
2087 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2088 STATUS_RF_KILL_HW |
2089 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2090 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08002091 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2092 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002093 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
2094 STATUS_IN_SUSPEND |
2095 test_bit(STATUS_FW_ERROR, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002096 STATUS_FW_ERROR |
2097 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2098 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002099
2100 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002101 iwl_clear_bit(priv, CSR_GP_CNTRL,
Ben Cahill9fbab512007-11-29 11:09:47 +08002102 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07002103 spin_unlock_irqrestore(&priv->lock, flags);
2104
Tomas Winklerda1bc452008-05-29 16:35:00 +08002105 iwl_txq_ctx_stop(priv);
Tomas Winklerb3bbacb2008-05-29 16:35:01 +08002106 iwl_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002107
2108 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002109 if (!iwl_grab_nic_access(priv)) {
2110 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002111 APMG_CLK_VAL_DMA_CLK_RQT);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002112 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002113 }
2114 spin_unlock_irqrestore(&priv->lock, flags);
2115
2116 udelay(5);
2117
Tomas Winkler7f066102008-05-29 16:34:57 +08002118 /* FIXME: apm_ops.suspend(priv) */
Gregory Greenmand5353112008-09-03 11:18:49 +08002119 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
2120 priv->cfg->ops->lib->apm_ops.stop(priv);
2121 else
2122 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002123 exit:
Tomas Winkler885ba202008-05-29 16:34:55 +08002124 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07002125
2126 if (priv->ibss_beacon)
2127 dev_kfree_skb(priv->ibss_beacon);
2128 priv->ibss_beacon = NULL;
2129
2130 /* clear out any free frames */
Tomas Winklerfcab4232008-05-15 13:54:01 +08002131 iwl_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002132}
2133
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002134static void iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002135{
2136 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002137 __iwl_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002138 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08002139
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002140 iwl_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002141}
2142
2143#define MAX_HW_RESTARTS 5
2144
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002145static int __iwl_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002146{
Tomas Winkler57aab752008-04-14 21:16:03 -07002147 int i;
2148 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002149
2150 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002151 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07002152 return -EIO;
2153 }
2154
Reinette Chatree903fbd2008-01-30 22:05:15 -08002155 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002156 IWL_ERR(priv, "ucode not available for device bringup\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08002157 return -EIO;
2158 }
2159
Zhu Yie655b9f2008-01-24 02:19:38 -08002160 /* If platform's RF_KILL switch is NOT set to KILL */
Tomas Winklerc1842d62008-08-04 16:00:43 +08002161 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
Zhu Yie655b9f2008-01-24 02:19:38 -08002162 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002163 else
Zhu Yie655b9f2008-01-24 02:19:38 -08002164 set_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002165
Tomas Winklerc1842d62008-08-04 16:00:43 +08002166 if (iwl_is_rfkill(priv)) {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002167 iwl_enable_interrupts(priv);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002168 IWL_WARN(priv, "Radio disabled by %s RF Kill switch\n",
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002169 test_bit(STATUS_RF_KILL_HW, &priv->status) ? "HW" : "SW");
Tomas Winklerc1842d62008-08-04 16:00:43 +08002170 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002171 }
2172
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002173 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07002174
Ron Rindjunsky1053d352008-05-05 10:22:43 +08002175 ret = iwl_hw_nic_init(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07002176 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002177 IWL_ERR(priv, "Unable to init nic\n");
Tomas Winkler57aab752008-04-14 21:16:03 -07002178 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002179 }
2180
2181 /* make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002182 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2183 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07002184 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2185
2186 /* clear (again), then enable host interrupts */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002187 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002188 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002189
2190 /* really make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002191 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2192 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07002193
2194 /* Copy original ucode data image from disk into backup cache.
2195 * This will be used to initialize the on-board processor's
2196 * data SRAM for a clean start when the runtime program first loads. */
2197 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a66926a2008-01-14 17:46:18 -08002198 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07002199
Zhu Yib481de92007-09-25 17:54:57 -07002200 for (i = 0; i < MAX_HW_RESTARTS; i++) {
2201
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08002202 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002203
2204 /* load bootstrap state machine,
2205 * load bootstrap program into processor's memory,
2206 * prepare to load the "initialize" uCode */
Tomas Winkler57aab752008-04-14 21:16:03 -07002207 ret = priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002208
Tomas Winkler57aab752008-04-14 21:16:03 -07002209 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002210 IWL_ERR(priv, "Unable to set up bootstrap uCode: %d\n",
2211 ret);
Zhu Yib481de92007-09-25 17:54:57 -07002212 continue;
2213 }
2214
Emmanuel Grumbachf3d5b452008-06-12 09:47:04 +08002215 /* Clear out the uCode error bit if it is set */
2216 clear_bit(STATUS_FW_ERROR, &priv->status);
2217
Zhu Yib481de92007-09-25 17:54:57 -07002218 /* start card; "initialize" will load runtime ucode */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002219 iwl_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002220
Zhu Yib481de92007-09-25 17:54:57 -07002221 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
2222
2223 return 0;
2224 }
2225
2226 set_bit(STATUS_EXIT_PENDING, &priv->status);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002227 __iwl_down(priv);
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08002228 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002229
2230 /* tried to restart and config the device for as long as our
2231 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002232 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07002233 return -EIO;
2234}
2235
2236
2237/*****************************************************************************
2238 *
2239 * Workqueue callbacks
2240 *
2241 *****************************************************************************/
2242
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002243static void iwl_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002244{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002245 struct iwl_priv *priv =
2246 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002247
2248 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2249 return;
2250
2251 mutex_lock(&priv->mutex);
Emmanuel Grumbachf3ccc082008-05-05 10:22:45 +08002252 priv->cfg->ops->lib->init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002253 mutex_unlock(&priv->mutex);
2254}
2255
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002256static void iwl_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002257{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002258 struct iwl_priv *priv =
2259 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002260
2261 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2262 return;
2263
2264 mutex_lock(&priv->mutex);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002265 iwl_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002266 mutex_unlock(&priv->mutex);
2267}
2268
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002269static void iwl_bg_rf_kill(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07002270{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002271 struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill);
Zhu Yib481de92007-09-25 17:54:57 -07002272
2273 wake_up_interruptible(&priv->wait_command_queue);
2274
2275 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2276 return;
2277
2278 mutex_lock(&priv->mutex);
2279
Tomas Winklerfee12472008-04-03 16:05:21 -07002280 if (!iwl_is_rfkill(priv)) {
Ester Kummerf3d67992008-05-06 11:05:12 +08002281 IWL_DEBUG(IWL_DL_RF_KILL,
Zhu Yib481de92007-09-25 17:54:57 -07002282 "HW and/or SW RF Kill no longer active, restarting "
2283 "device\n");
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002284 if (!test_bit(STATUS_EXIT_PENDING, &priv->status) &&
2285 test_bit(STATUS_ALIVE, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07002286 queue_work(priv->workqueue, &priv->restart);
2287 } else {
Mohamed Abbasad97edd2008-03-28 16:21:06 -07002288 /* make sure mac80211 stop sending Tx frame */
2289 if (priv->mac80211_registered)
2290 ieee80211_stop_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002291
2292 if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
2293 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2294 "disabled by SW switch\n");
2295 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002296 IWL_WARN(priv, "Radio Frequency Kill Switch is On:\n"
Zhu Yib481de92007-09-25 17:54:57 -07002297 "Kill switch must be turned off for "
2298 "wireless networking to work.\n");
2299 }
2300 mutex_unlock(&priv->mutex);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002301 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002302}
2303
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08002304static void iwl_bg_run_time_calib_work(struct work_struct *work)
2305{
2306 struct iwl_priv *priv = container_of(work, struct iwl_priv,
2307 run_time_calib_work);
2308
2309 mutex_lock(&priv->mutex);
2310
2311 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
2312 test_bit(STATUS_SCANNING, &priv->status)) {
2313 mutex_unlock(&priv->mutex);
2314 return;
2315 }
2316
2317 if (priv->start_calib) {
2318 iwl_chain_noise_calibration(priv, &priv->statistics);
2319
2320 iwl_sensitivity_calibration(priv, &priv->statistics);
2321 }
2322
2323 mutex_unlock(&priv->mutex);
2324 return;
2325}
2326
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002327static void iwl_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002328{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002329 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07002330
2331 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2332 return;
2333
2334 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002335 __iwl_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002336 mutex_unlock(&priv->mutex);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002337 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002338}
2339
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002340static void iwl_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002341{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002342 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07002343
2344 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2345 return;
2346
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002347 iwl_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002348 queue_work(priv->workqueue, &priv->up);
2349}
2350
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002351static void iwl_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002352{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002353 struct iwl_priv *priv =
2354 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07002355
2356 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2357 return;
2358
2359 mutex_lock(&priv->mutex);
Tomas Winklera55360e2008-05-05 10:22:28 +08002360 iwl_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002361 mutex_unlock(&priv->mutex);
2362}
2363
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002364#define IWL_DELAY_NEXT_SCAN (HZ*2)
2365
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002366static void iwl_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002367{
Zhu Yib481de92007-09-25 17:54:57 -07002368 struct ieee80211_conf *conf = NULL;
Tomas Winkler857485c2008-03-21 13:53:44 -07002369 int ret = 0;
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002370 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07002371
Johannes Berg05c914f2008-09-11 00:01:58 +02002372 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002373 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07002374 return;
2375 }
2376
Johannes Berge1749612008-10-27 15:59:26 -07002377 IWL_DEBUG_ASSOC("Associated as %d to: %pM\n",
2378 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07002379
2380
2381 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2382 return;
2383
Zhu Yib481de92007-09-25 17:54:57 -07002384
Reinette Chatre508e32e2008-04-14 21:16:13 -07002385 if (!priv->vif || !priv->is_open)
Mohamed Abbas948c1712007-10-25 17:15:45 +08002386 return;
Reinette Chatre508e32e2008-04-14 21:16:13 -07002387
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08002388 iwl_power_cancel_timeout(priv);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002389 iwl_scan_cancel_timeout(priv, 200);
mabbas052c4b92007-10-25 17:15:43 +08002390
Zhu Yib481de92007-09-25 17:54:57 -07002391 conf = ieee80211_get_hw_conf(priv->hw);
2392
2393 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002394 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002395
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002396 iwl_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002397 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002398 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002399 if (ret)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002400 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07002401 "Attempting to continue.\n");
2402
2403 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
2404
Emmanuel Grumbach42eb7c62008-09-17 10:10:05 +08002405 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03002406
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07002407 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002408 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2409
2410 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
2411 priv->assoc_id, priv->beacon_int);
2412
2413 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2414 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2415 else
2416 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2417
2418 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2419 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2420 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2421 else
2422 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2423
Johannes Berg05c914f2008-09-11 00:01:58 +02002424 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002425 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2426
2427 }
2428
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002429 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002430
2431 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02002432 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -07002433 break;
2434
Johannes Berg05c914f2008-09-11 00:01:58 +02002435 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07002436
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002437 /* assume default assoc id */
2438 priv->assoc_id = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002439
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002440 iwl_rxon_add_station(priv, priv->bssid, 0);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002441 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002442
2443 break;
2444
2445 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002446 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03002447 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002448 break;
2449 }
2450
Johannes Berg05c914f2008-09-11 00:01:58 +02002451 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002452 priv->assoc_station_added = 1;
2453
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002454 spin_lock_irqsave(&priv->lock, flags);
2455 iwl_activate_qos(priv, 0);
2456 spin_unlock_irqrestore(&priv->lock, flags);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08002457
Grumbach, Emmanuel04816442008-09-03 11:26:53 +08002458 /* the chain noise calibration will enabled PM upon completion
2459 * If chain noise has already been run, then we need to enable
2460 * power management here */
2461 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
2462 iwl_power_enable_management(priv);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08002463
2464 /* Enable Rx differential gain and sensitivity calibrations */
2465 iwl_chain_noise_reset(priv);
2466 priv->start_calib = 1;
2467
Reinette Chatre508e32e2008-04-14 21:16:13 -07002468}
2469
Zhu Yib481de92007-09-25 17:54:57 -07002470/*****************************************************************************
2471 *
2472 * mac80211 entry point functions
2473 *
2474 *****************************************************************************/
2475
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002476#define UCODE_READY_TIMEOUT (4 * HZ)
Zhu Yi5a66926a2008-01-14 17:46:18 -08002477
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002478static int iwl_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002479{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002480 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002481 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002482
2483 IWL_DEBUG_MAC80211("enter\n");
2484
2485 /* we should be verifying the device is ready to be opened */
2486 mutex_lock(&priv->mutex);
2487
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08002488 memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd));
Zhu Yi5a66926a2008-01-14 17:46:18 -08002489 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
2490 * ucode filename and max sizes are card-specific. */
2491
2492 if (!priv->ucode_code.len) {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002493 ret = iwl_read_ucode(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002494 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002495 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002496 mutex_unlock(&priv->mutex);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002497 return ret;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002498 }
2499 }
2500
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002501 ret = __iwl_up(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002502
Zhu Yib481de92007-09-25 17:54:57 -07002503 mutex_unlock(&priv->mutex);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002504
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002505 iwl_rfkill_set_hw_state(priv);
2506
Zhu Yie655b9f2008-01-24 02:19:38 -08002507 if (ret)
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002508 return ret;
Zhu Yie655b9f2008-01-24 02:19:38 -08002509
Tomas Winklerc1842d62008-08-04 16:00:43 +08002510 if (iwl_is_rfkill(priv))
2511 goto out;
2512
Zhu Yie655b9f2008-01-24 02:19:38 -08002513 IWL_DEBUG_INFO("Start UP work done.\n");
2514
2515 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
2516 return 0;
2517
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002518 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
Zhu Yi5a66926a2008-01-14 17:46:18 -08002519 * mac80211 will not be run successfully. */
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002520 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
2521 test_bit(STATUS_READY, &priv->status),
2522 UCODE_READY_TIMEOUT);
2523 if (!ret) {
2524 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002525 IWL_ERR(priv, "START_ALIVE timeout after %dms.\n",
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002526 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002527 return -ETIMEDOUT;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002528 }
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002529 }
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002530
Tomas Winklerc1842d62008-08-04 16:00:43 +08002531out:
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002532 priv->is_open = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002533 IWL_DEBUG_MAC80211("leave\n");
2534 return 0;
2535}
2536
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002537static void iwl_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002538{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002539 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002540
2541 IWL_DEBUG_MAC80211("enter\n");
Mohamed Abbas948c1712007-10-25 17:15:45 +08002542
Zhu Yie655b9f2008-01-24 02:19:38 -08002543 if (!priv->is_open) {
2544 IWL_DEBUG_MAC80211("leave - skip\n");
2545 return;
2546 }
2547
Zhu Yib481de92007-09-25 17:54:57 -07002548 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002549
Tomas Winklerfee12472008-04-03 16:05:21 -07002550 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08002551 /* stop mac, cancel any scan request and clear
2552 * RXON_FILTER_ASSOC_MSK BIT
2553 */
Zhu Yi5a66926a2008-01-14 17:46:18 -08002554 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002555 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002556 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002557 }
2558
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002559 iwl_down(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002560
2561 flush_workqueue(priv->workqueue);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002562
2563 /* enable interrupts again in order to receive rfkill changes */
2564 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
2565 iwl_enable_interrupts(priv);
Mohamed Abbas948c1712007-10-25 17:15:45 +08002566
Zhu Yib481de92007-09-25 17:54:57 -07002567 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002568}
2569
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002570static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07002571{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002572 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002573
Tomas Winklerf3674222008-08-04 16:00:44 +08002574 IWL_DEBUG_MACDUMP("enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002575
Zhu Yib481de92007-09-25 17:54:57 -07002576 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02002577 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07002578
Johannes Berge039fa42008-05-15 12:55:29 +02002579 if (iwl_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07002580 dev_kfree_skb_any(skb);
2581
Tomas Winklerf3674222008-08-04 16:00:44 +08002582 IWL_DEBUG_MACDUMP("leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08002583 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07002584}
2585
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002586static int iwl_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07002587 struct ieee80211_if_init_conf *conf)
2588{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002589 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002590 unsigned long flags;
2591
Johannes Berg32bfd352007-12-19 01:31:26 +01002592 IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07002593
Johannes Berg32bfd352007-12-19 01:31:26 +01002594 if (priv->vif) {
2595 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
Reinette Chatre75849d22008-01-23 10:15:17 -08002596 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07002597 }
2598
2599 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01002600 priv->vif = conf->vif;
Zhu, Yi60294de2008-10-29 14:05:45 -07002601 priv->iw_mode = conf->type;
Zhu Yib481de92007-09-25 17:54:57 -07002602
2603 spin_unlock_irqrestore(&priv->lock, flags);
2604
2605 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02002606
2607 if (conf->mac_addr) {
Johannes Berge1749612008-10-27 15:59:26 -07002608 IWL_DEBUG_MAC80211("Set %pM\n", conf->mac_addr);
Tomas Winkler864792e2007-11-27 21:00:52 +02002609 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
2610 }
Zhu Yib481de92007-09-25 17:54:57 -07002611
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002612 if (iwl_set_mode(priv, conf->type) == -EAGAIN)
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002613 /* we are not ready, will run again when ready */
2614 set_bit(STATUS_MODE_PENDING, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002615
Zhu Yib481de92007-09-25 17:54:57 -07002616 mutex_unlock(&priv->mutex);
2617
Zhu Yi5a66926a2008-01-14 17:46:18 -08002618 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002619 return 0;
2620}
2621
2622/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002623 * iwl_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07002624 *
2625 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
2626 * be set inappropriately and the driver currently sets the hardware up to
2627 * use it whenever needed.
2628 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002629static int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
Zhu Yib481de92007-09-25 17:54:57 -07002630{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002631 struct iwl_priv *priv = hw->priv;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07002632 const struct iwl_channel_info *ch_info;
Johannes Berge8975582008-10-09 12:18:51 +02002633 struct ieee80211_conf *conf = &hw->conf;
Zhu Yib481de92007-09-25 17:54:57 -07002634 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08002635 int ret = 0;
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002636 u16 channel;
Zhu Yib481de92007-09-25 17:54:57 -07002637
2638 mutex_lock(&priv->mutex);
Johannes Berg8318d782008-01-24 19:38:38 +01002639 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07002640
Luis R. Rodriguezde27e642008-12-23 15:58:44 -08002641 priv->current_ht_config.is_ht = conf_is_ht(conf);
Johannes Bergae5eb022008-10-14 16:58:37 +02002642
Emmanuel Grumbach14a08a7f2008-06-13 15:44:55 +08002643 if (conf->radio_enabled && iwl_radio_kill_sw_enable_radio(priv)) {
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08002644 IWL_DEBUG_MAC80211("leave - RF-KILL - waiting for uCode\n");
Emmanuel Grumbach14a08a7f2008-06-13 15:44:55 +08002645 goto out;
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08002646 }
2647
Emmanuel Grumbach14a08a7f2008-06-13 15:44:55 +08002648 if (!conf->radio_enabled)
2649 iwl_radio_kill_sw_disable_radio(priv);
2650
Tomas Winklerfee12472008-04-03 16:05:21 -07002651 if (!iwl_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002652 IWL_DEBUG_MAC80211("leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002653 ret = -EIO;
2654 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002655 }
2656
Assaf Krauss1ea87392008-03-18 14:57:50 -07002657 if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07002658 test_bit(STATUS_SCANNING, &priv->status))) {
Zhu Yia0646472007-12-20 14:10:01 +08002659 IWL_DEBUG_MAC80211("leave - scanning\n");
Zhu Yib481de92007-09-25 17:54:57 -07002660 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08002661 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002662 }
2663
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002664 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2665 ch_info = iwl_get_channel_info(priv, conf->channel->band, channel);
Zhu Yib481de92007-09-25 17:54:57 -07002666 if (!is_channel_valid(ch_info)) {
Zhu Yib481de92007-09-25 17:54:57 -07002667 IWL_DEBUG_MAC80211("leave - invalid channel\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002668 ret = -EINVAL;
2669 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002670 }
2671
Johannes Berg05c914f2008-09-11 00:01:58 +02002672 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Assaf Krauss398f9e72008-06-12 09:47:06 +08002673 !is_channel_ibss(ch_info)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002674 IWL_ERR(priv, "channel %d in band %d not IBSS channel\n",
Assaf Krauss398f9e72008-06-12 09:47:06 +08002675 conf->channel->hw_value, conf->channel->band);
2676 ret = -EINVAL;
2677 goto out;
2678 }
2679
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002680 spin_lock_irqsave(&priv->lock, flags);
2681
Tomas Winklerb5d7be52008-07-19 04:41:24 +03002682
Tomas Winkler78330fd2008-02-06 02:37:18 +02002683 /* if we are switching from ht to 2.4 clear flags
Zhu Yib481de92007-09-25 17:54:57 -07002684 * from any ht related info since 2.4 does not
2685 * support ht */
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002686 if ((le16_to_cpu(priv->staging_rxon.channel) != channel)
Zhu Yib481de92007-09-25 17:54:57 -07002687#ifdef IEEE80211_CONF_CHANNEL_SWITCH
2688 && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
2689#endif
2690 )
2691 priv->staging_rxon.flags = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002692
Tomas Winkler17e72782008-09-03 11:26:26 +08002693 iwl_set_rxon_channel(priv, conf->channel);
Zhu Yib481de92007-09-25 17:54:57 -07002694
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002695 iwl_set_flags_for_band(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07002696
2697 /* The list of supported rates and rate mask can be different
Johannes Berg8318d782008-01-24 19:38:38 +01002698 * for each band; since the band may have changed, reset
Zhu Yib481de92007-09-25 17:54:57 -07002699 * the rate mask to what mac80211 lists */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002700 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002701
2702 spin_unlock_irqrestore(&priv->lock, flags);
2703
2704#ifdef IEEE80211_CONF_CHANNEL_SWITCH
2705 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002706 iwl_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08002707 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002708 }
2709#endif
2710
Zhu Yib481de92007-09-25 17:54:57 -07002711 if (!conf->radio_enabled) {
2712 IWL_DEBUG_MAC80211("leave - radio disabled\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002713 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002714 }
2715
Tomas Winklerfee12472008-04-03 16:05:21 -07002716 if (iwl_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002717 IWL_DEBUG_MAC80211("leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002718 ret = -EIO;
2719 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002720 }
2721
Ester Kummere602cb12008-09-26 15:09:33 +08002722 if (conf->flags & IEEE80211_CONF_PS)
2723 ret = iwl_power_set_user_mode(priv, IWL_POWER_INDEX_3);
2724 else
2725 ret = iwl_power_set_user_mode(priv, IWL_POWER_MODE_CAM);
2726 if (ret)
2727 IWL_DEBUG_MAC80211("Error setting power level\n");
2728
Tomas Winkler630fe9b2008-06-12 09:47:08 +08002729 IWL_DEBUG_MAC80211("TX Power old=%d new=%d\n",
2730 priv->tx_power_user_lmt, conf->power_level);
2731
2732 iwl_set_tx_power(priv, conf->power_level, false);
2733
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002734 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002735
2736 if (memcmp(&priv->active_rxon,
2737 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002738 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002739 else
2740 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
2741
2742 IWL_DEBUG_MAC80211("leave\n");
2743
Zhu Yia0646472007-12-20 14:10:01 +08002744out:
Zhu Yi5a66926a2008-01-14 17:46:18 -08002745 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08002746 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002747}
2748
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002749static void iwl_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002750{
Tomas Winkler857485c2008-03-21 13:53:44 -07002751 int ret = 0;
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002752 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07002753
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08002754 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07002755 return;
2756
2757 /* The following should be done only at AP bring up */
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002758 if (!iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002759
2760 /* RXON - unassoc (to set timing command) */
2761 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002762 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002763
2764 /* RXON Timing */
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002765 iwl_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002766 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002767 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002768 if (ret)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002769 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07002770 "Attempting to continue.\n");
2771
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07002772 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002773
2774 /* FIXME: what should be the assoc_id for AP? */
2775 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2776 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2777 priv->staging_rxon.flags |=
2778 RXON_FLG_SHORT_PREAMBLE_MSK;
2779 else
2780 priv->staging_rxon.flags &=
2781 ~RXON_FLG_SHORT_PREAMBLE_MSK;
2782
2783 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2784 if (priv->assoc_capability &
2785 WLAN_CAPABILITY_SHORT_SLOT_TIME)
2786 priv->staging_rxon.flags |=
2787 RXON_FLG_SHORT_SLOT_MSK;
2788 else
2789 priv->staging_rxon.flags &=
2790 ~RXON_FLG_SHORT_SLOT_MSK;
2791
Johannes Berg05c914f2008-09-11 00:01:58 +02002792 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002793 priv->staging_rxon.flags &=
2794 ~RXON_FLG_SHORT_SLOT_MSK;
2795 }
2796 /* restore RXON assoc */
2797 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002798 iwl_commit_rxon(priv);
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002799 spin_lock_irqsave(&priv->lock, flags);
2800 iwl_activate_qos(priv, 1);
2801 spin_unlock_irqrestore(&priv->lock, flags);
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002802 iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
Zhu Yie1493de2007-09-27 11:27:32 +08002803 }
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002804 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002805
2806 /* FIXME - we need to add code here to detect a totally new
2807 * configuration, reset the AP, unassoc, rxon timing, assoc,
2808 * clear sta table, add BCAST sta... */
2809}
2810
Johannes Berg9d139c82008-07-09 14:40:37 +02002811
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002812static int iwl_mac_config_interface(struct ieee80211_hw *hw,
Johannes Berg32bfd352007-12-19 01:31:26 +01002813 struct ieee80211_vif *vif,
Zhu Yib481de92007-09-25 17:54:57 -07002814 struct ieee80211_if_conf *conf)
2815{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002816 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002817 int rc;
2818
2819 if (conf == NULL)
2820 return -EIO;
2821
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08002822 if (priv->vif != vif) {
2823 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08002824 return 0;
2825 }
2826
Johannes Berg05c914f2008-09-11 00:01:58 +02002827 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Johannes Berg9d139c82008-07-09 14:40:37 +02002828 conf->changed & IEEE80211_IFCC_BEACON) {
2829 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
2830 if (!beacon)
2831 return -ENOMEM;
Mohamed Abbasada17512008-11-07 09:58:34 -08002832 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002833 rc = iwl_mac_beacon_update(hw, beacon);
Mohamed Abbasada17512008-11-07 09:58:34 -08002834 mutex_unlock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02002835 if (rc)
2836 return rc;
2837 }
2838
Tomas Winklerfee12472008-04-03 16:05:21 -07002839 if (!iwl_is_alive(priv))
Zhu Yi5a66926a2008-01-14 17:46:18 -08002840 return -EAGAIN;
2841
Zhu Yib481de92007-09-25 17:54:57 -07002842 mutex_lock(&priv->mutex);
2843
Zhu Yib481de92007-09-25 17:54:57 -07002844 if (conf->bssid)
Johannes Berge1749612008-10-27 15:59:26 -07002845 IWL_DEBUG_MAC80211("bssid: %pM\n", conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07002846
Johannes Berg4150c572007-09-17 01:29:23 -04002847/*
2848 * very dubious code was here; the probe filtering flag is never set:
2849 *
Zhu Yib481de92007-09-25 17:54:57 -07002850 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
2851 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04002852 */
Zhu Yib481de92007-09-25 17:54:57 -07002853
Johannes Berg05c914f2008-09-11 00:01:58 +02002854 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07002855 if (!conf->bssid) {
2856 conf->bssid = priv->mac_addr;
2857 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -07002858 IWL_DEBUG_MAC80211("bssid was set to: %pM\n",
2859 conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07002860 }
2861 if (priv->ibss_beacon)
2862 dev_kfree_skb(priv->ibss_beacon);
2863
Johannes Berg9d139c82008-07-09 14:40:37 +02002864 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
Zhu Yib481de92007-09-25 17:54:57 -07002865 }
2866
Tomas Winklerfee12472008-04-03 16:05:21 -07002867 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08002868 goto done;
2869
Zhu Yib481de92007-09-25 17:54:57 -07002870 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
2871 !is_multicast_ether_addr(conf->bssid)) {
2872 /* If there is currently a HW scan going on in the background
2873 * then we need to cancel it else the RXON below will fail. */
Tomas Winkler2a421b92008-06-12 09:47:10 +08002874 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002875 IWL_WARN(priv, "Aborted scan still in progress "
Zhu Yib481de92007-09-25 17:54:57 -07002876 "after 100ms\n");
2877 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2878 mutex_unlock(&priv->mutex);
2879 return -EAGAIN;
2880 }
2881 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
2882
2883 /* TODO: Audit driver for usage of these members and see
2884 * if mac80211 deprecates them (priv->bssid looks like it
2885 * shouldn't be there, but I haven't scanned the IBSS code
2886 * to verify) - jpk */
2887 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
2888
Johannes Berg05c914f2008-09-11 00:01:58 +02002889 if (priv->iw_mode == NL80211_IFTYPE_AP)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002890 iwl_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002891 else {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002892 rc = iwl_commit_rxon(priv);
Johannes Berg05c914f2008-09-11 00:01:58 +02002893 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002894 iwl_rxon_add_station(
Zhu Yib481de92007-09-25 17:54:57 -07002895 priv, priv->active_rxon.bssid_addr, 1);
2896 }
2897
2898 } else {
Tomas Winkler2a421b92008-06-12 09:47:10 +08002899 iwl_scan_cancel_timeout(priv, 100);
Zhu Yib481de92007-09-25 17:54:57 -07002900 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002901 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002902 }
2903
Mohamed Abbasfde35712007-11-29 11:10:15 +08002904 done:
Zhu Yib481de92007-09-25 17:54:57 -07002905 IWL_DEBUG_MAC80211("leave\n");
2906 mutex_unlock(&priv->mutex);
2907
2908 return 0;
2909}
2910
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002911static void iwl_configure_filter(struct ieee80211_hw *hw,
Johannes Berg4150c572007-09-17 01:29:23 -04002912 unsigned int changed_flags,
2913 unsigned int *total_flags,
2914 int mc_count, struct dev_addr_list *mc_list)
2915{
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08002916 struct iwl_priv *priv = hw->priv;
Zhu, Yi352bc8d2008-11-12 13:14:09 -08002917 __le32 *filter_flags = &priv->staging_rxon.filter_flags;
Rick Farrington25b3f572008-06-30 17:23:28 +08002918
Zhu, Yi352bc8d2008-11-12 13:14:09 -08002919 IWL_DEBUG_MAC80211("Enter: changed: 0x%x, total: 0x%x\n",
2920 changed_flags, *total_flags);
2921
2922 if (changed_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) {
2923 if (*total_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS))
2924 *filter_flags |= RXON_FILTER_PROMISC_MSK;
2925 else
2926 *filter_flags &= ~RXON_FILTER_PROMISC_MSK;
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08002927 }
Zhu, Yi352bc8d2008-11-12 13:14:09 -08002928 if (changed_flags & FIF_ALLMULTI) {
2929 if (*total_flags & FIF_ALLMULTI)
2930 *filter_flags |= RXON_FILTER_ACCEPT_GRP_MSK;
2931 else
2932 *filter_flags &= ~RXON_FILTER_ACCEPT_GRP_MSK;
2933 }
2934 if (changed_flags & FIF_CONTROL) {
2935 if (*total_flags & FIF_CONTROL)
2936 *filter_flags |= RXON_FILTER_CTL2HOST_MSK;
2937 else
2938 *filter_flags &= ~RXON_FILTER_CTL2HOST_MSK;
2939 }
2940 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
2941 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
2942 *filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
2943 else
2944 *filter_flags &= ~RXON_FILTER_BCON_AWARE_MSK;
2945 }
2946
2947 /* We avoid iwl_commit_rxon here to commit the new filter flags
2948 * since mac80211 will call ieee80211_hw_config immediately.
2949 * (mc_list is not supported at this time). Otherwise, we need to
2950 * queue a background iwl_commit_rxon work.
2951 */
2952
2953 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
Rick Farrington25b3f572008-06-30 17:23:28 +08002954 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
Johannes Berg4150c572007-09-17 01:29:23 -04002955}
2956
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002957static void iwl_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07002958 struct ieee80211_if_init_conf *conf)
2959{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002960 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002961
2962 IWL_DEBUG_MAC80211("enter\n");
2963
2964 mutex_lock(&priv->mutex);
Mohamed Abbas948c1712007-10-25 17:15:45 +08002965
Tomas Winklerfee12472008-04-03 16:05:21 -07002966 if (iwl_is_ready_rf(priv)) {
Tomas Winkler2a421b92008-06-12 09:47:10 +08002967 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002968 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002969 iwl_commit_rxon(priv);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002970 }
Johannes Berg32bfd352007-12-19 01:31:26 +01002971 if (priv->vif == conf->vif) {
2972 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07002973 memset(priv->bssid, 0, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07002974 }
2975 mutex_unlock(&priv->mutex);
2976
2977 IWL_DEBUG_MAC80211("leave\n");
2978
2979}
Johannes Berg471b3ef2007-12-28 14:32:58 +01002980
Tomas Winkler3109ece2008-03-28 16:33:35 -07002981#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002982static void iwl_bss_info_changed(struct ieee80211_hw *hw,
Johannes Berg471b3ef2007-12-28 14:32:58 +01002983 struct ieee80211_vif *vif,
2984 struct ieee80211_bss_conf *bss_conf,
2985 u32 changes)
Tomas Winkler220173b2007-10-16 00:50:25 +02002986{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002987 struct iwl_priv *priv = hw->priv;
Tomas Winkler220173b2007-10-16 00:50:25 +02002988
Tomas Winkler3109ece2008-03-28 16:33:35 -07002989 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
2990
Johannes Berg471b3ef2007-12-28 14:32:58 +01002991 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07002992 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
2993 bss_conf->use_short_preamble);
Johannes Berg471b3ef2007-12-28 14:32:58 +01002994 if (bss_conf->use_short_preamble)
Tomas Winkler220173b2007-10-16 00:50:25 +02002995 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2996 else
2997 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2998 }
2999
Johannes Berg471b3ef2007-12-28 14:32:58 +01003000 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07003001 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
Johannes Berg8318d782008-01-24 19:38:38 +01003002 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Tomas Winkler220173b2007-10-16 00:50:25 +02003003 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
3004 else
3005 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
3006 }
3007
Tomas Winkler98952d52008-03-28 16:33:33 -07003008 if (changes & BSS_CHANGED_HT) {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003009 iwl_ht_conf(priv, bss_conf);
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003010 iwl_set_rxon_chain(priv);
Tomas Winkler98952d52008-03-28 16:33:33 -07003011 }
3012
Johannes Berg471b3ef2007-12-28 14:32:58 +01003013 if (changes & BSS_CHANGED_ASSOC) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07003014 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
Reinette Chatre508e32e2008-04-14 21:16:13 -07003015 /* This should never happen as this function should
3016 * never be called from interrupt context. */
3017 if (WARN_ON_ONCE(in_interrupt()))
3018 return;
Tomas Winkler3109ece2008-03-28 16:33:35 -07003019 if (bss_conf->assoc) {
3020 priv->assoc_id = bss_conf->aid;
3021 priv->beacon_int = bss_conf->beacon_int;
Tomas Winklerb5d7be52008-07-19 04:41:24 +03003022 priv->power_data.dtim_period = bss_conf->dtim_period;
Tomas Winkler3109ece2008-03-28 16:33:35 -07003023 priv->timestamp = bss_conf->timestamp;
3024 priv->assoc_capability = bss_conf->assoc_capability;
Tomas Winkler9ccacb82008-09-16 14:01:03 +08003025
3026 /* we have just associated, don't start scan too early
3027 * leave time for EAPOL exchange to complete
3028 */
Tomas Winkler3109ece2008-03-28 16:33:35 -07003029 priv->next_scan_jiffies = jiffies +
3030 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
Reinette Chatre508e32e2008-04-14 21:16:13 -07003031 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003032 iwl_post_associate(priv);
Reinette Chatre508e32e2008-04-14 21:16:13 -07003033 mutex_unlock(&priv->mutex);
Tomas Winkler3109ece2008-03-28 16:33:35 -07003034 } else {
3035 priv->assoc_id = 0;
3036 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
3037 }
3038 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
3039 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
Tomas Winkler7e8c5192008-04-15 16:01:43 -07003040 iwl_send_rxon_assoc(priv);
Johannes Berg471b3ef2007-12-28 14:32:58 +01003041 }
3042
Tomas Winkler220173b2007-10-16 00:50:25 +02003043}
Zhu Yib481de92007-09-25 17:54:57 -07003044
Tomas Winklercb43dc22008-09-03 11:26:23 +08003045static int iwl_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t ssid_len)
Zhu Yib481de92007-09-25 17:54:57 -07003046{
Zhu Yib481de92007-09-25 17:54:57 -07003047 unsigned long flags;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003048 struct iwl_priv *priv = hw->priv;
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003049 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003050
3051 IWL_DEBUG_MAC80211("enter\n");
3052
mabbas052c4b92007-10-25 17:15:43 +08003053 mutex_lock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07003054 spin_lock_irqsave(&priv->lock, flags);
3055
Tomas Winklerfee12472008-04-03 16:05:21 -07003056 if (!iwl_is_ready_rf(priv)) {
Tomas Winklercb43dc22008-09-03 11:26:23 +08003057 ret = -EIO;
Zhu Yib481de92007-09-25 17:54:57 -07003058 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
3059 goto out_unlock;
3060 }
3061
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003062 /* We don't schedule scan within next_scan_jiffies period.
3063 * Avoid scanning during possible EAPOL exchange, return
3064 * success immediately.
3065 */
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003066 if (priv->next_scan_jiffies &&
Tomas Winklercb43dc22008-09-03 11:26:23 +08003067 time_after(priv->next_scan_jiffies, jiffies)) {
Ron Rindjunsky681c0052008-09-03 11:26:25 +08003068 IWL_DEBUG_SCAN("scan rejected: within next scan period\n");
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003069 queue_work(priv->workqueue, &priv->scan_completed);
3070 ret = 0;
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003071 goto out_unlock;
3072 }
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003073
Zhu Yib481de92007-09-25 17:54:57 -07003074 /* if we just finished scan ask for delay */
Ron Rindjunsky681c0052008-09-03 11:26:25 +08003075 if (iwl_is_associated(priv) && priv->last_scan_jiffies &&
Tomas Winklercb43dc22008-09-03 11:26:23 +08003076 time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN, jiffies)) {
Ron Rindjunsky681c0052008-09-03 11:26:25 +08003077 IWL_DEBUG_SCAN("scan rejected: within previous scan period\n");
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003078 queue_work(priv->workqueue, &priv->scan_completed);
3079 ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003080 goto out_unlock;
3081 }
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003082
Tomas Winklercb43dc22008-09-03 11:26:23 +08003083 if (ssid_len) {
Zhu Yib481de92007-09-25 17:54:57 -07003084 priv->one_direct_scan = 1;
Tomas Winklercb43dc22008-09-03 11:26:23 +08003085 priv->direct_ssid_len = min_t(u8, ssid_len, IW_ESSID_MAX_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07003086 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
Tomas Winklercb43dc22008-09-03 11:26:23 +08003087 } else {
Mohamed Abbas948c1712007-10-25 17:15:45 +08003088 priv->one_direct_scan = 0;
Tomas Winklercb43dc22008-09-03 11:26:23 +08003089 }
Zhu Yib481de92007-09-25 17:54:57 -07003090
Tomas Winklercb43dc22008-09-03 11:26:23 +08003091 ret = iwl_scan_initiate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003092
3093 IWL_DEBUG_MAC80211("leave\n");
3094
3095out_unlock:
3096 spin_unlock_irqrestore(&priv->lock, flags);
mabbas052c4b92007-10-25 17:15:43 +08003097 mutex_unlock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07003098
Tomas Winklercb43dc22008-09-03 11:26:23 +08003099 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003100}
3101
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003102static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw,
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003103 struct ieee80211_key_conf *keyconf, const u8 *addr,
3104 u32 iv32, u16 *phase1key)
3105{
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003106
Tomas Winkler9f586712008-11-12 13:14:05 -08003107 struct iwl_priv *priv = hw->priv;
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003108 IWL_DEBUG_MAC80211("enter\n");
3109
Tomas Winkler9f586712008-11-12 13:14:05 -08003110 iwl_update_tkip_key(priv, keyconf, addr, iv32, phase1key);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003111
3112 IWL_DEBUG_MAC80211("leave\n");
3113}
3114
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003115static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01003116 struct ieee80211_vif *vif,
3117 struct ieee80211_sta *sta,
Zhu Yib481de92007-09-25 17:54:57 -07003118 struct ieee80211_key_conf *key)
3119{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003120 struct iwl_priv *priv = hw->priv;
Winkler, Tomas42986792009-01-19 15:30:22 -08003121 const u8 *addr;
3122 int ret;
3123 u8 sta_id;
3124 bool is_default_wep_key = false;
Zhu Yib481de92007-09-25 17:54:57 -07003125
3126 IWL_DEBUG_MAC80211("enter\n");
3127
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07003128 if (priv->hw_params.sw_crypto) {
Zhu Yib481de92007-09-25 17:54:57 -07003129 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
3130 return -EOPNOTSUPP;
3131 }
Winkler, Tomas42986792009-01-19 15:30:22 -08003132 addr = sta ? sta->addr : iwl_bcast_addr;
Tomas Winkler947b13a2008-04-16 16:34:48 -07003133 sta_id = iwl_find_station(priv, addr);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003134 if (sta_id == IWL_INVALID_STATION) {
Johannes Berge1749612008-10-27 15:59:26 -07003135 IWL_DEBUG_MAC80211("leave - %pM not in station map.\n",
3136 addr);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003137 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003138
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003139 }
Zhu Yib481de92007-09-25 17:54:57 -07003140
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003141 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08003142 iwl_scan_cancel_timeout(priv, 100);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003143 mutex_unlock(&priv->mutex);
3144
3145 /* If we are getting WEP group key and we didn't receive any key mapping
3146 * so far, we are in legacy wep mode (group key only), otherwise we are
3147 * in 1X mode.
3148 * In legacy wep mode, we use another host command to the uCode */
Tomas Winkler5425e492008-04-15 16:01:38 -07003149 if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
Johannes Berg05c914f2008-09-11 00:01:58 +02003150 priv->iw_mode != NL80211_IFTYPE_AP) {
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003151 if (cmd == SET_KEY)
3152 is_default_wep_key = !priv->key_mapping_key;
3153 else
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +08003154 is_default_wep_key =
3155 (key->hw_key_idx == HW_KEY_DEFAULT);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003156 }
mabbas052c4b92007-10-25 17:15:43 +08003157
Zhu Yib481de92007-09-25 17:54:57 -07003158 switch (cmd) {
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003159 case SET_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003160 if (is_default_wep_key)
3161 ret = iwl_set_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003162 else
Emmanuel Grumbach74805132008-04-14 21:16:09 -07003163 ret = iwl_set_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003164
3165 IWL_DEBUG_MAC80211("enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003166 break;
3167 case DISABLE_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003168 if (is_default_wep_key)
3169 ret = iwl_remove_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003170 else
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07003171 ret = iwl_remove_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003172
3173 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003174 break;
3175 default:
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003176 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003177 }
3178
3179 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003180
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003181 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003182}
3183
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003184static int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
Zhu Yib481de92007-09-25 17:54:57 -07003185 const struct ieee80211_tx_queue_params *params)
3186{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003187 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003188 unsigned long flags;
3189 int q;
Zhu Yib481de92007-09-25 17:54:57 -07003190
3191 IWL_DEBUG_MAC80211("enter\n");
3192
Tomas Winklerfee12472008-04-03 16:05:21 -07003193 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003194 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3195 return -EIO;
3196 }
3197
3198 if (queue >= AC_NUM) {
3199 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
3200 return 0;
3201 }
3202
Zhu Yib481de92007-09-25 17:54:57 -07003203 q = AC_NUM - 1 - queue;
3204
3205 spin_lock_irqsave(&priv->lock, flags);
3206
3207 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
3208 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
3209 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
3210 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7b2008-02-10 16:49:38 +01003211 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07003212
3213 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
3214 priv->qos_data.qos_active = 1;
3215
Johannes Berg05c914f2008-09-11 00:01:58 +02003216 if (priv->iw_mode == NL80211_IFTYPE_AP)
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08003217 iwl_activate_qos(priv, 1);
Tomas Winkler3109ece2008-03-28 16:33:35 -07003218 else if (priv->assoc_id && iwl_is_associated(priv))
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08003219 iwl_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003220
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08003221 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -07003222
Zhu Yib481de92007-09-25 17:54:57 -07003223 IWL_DEBUG_MAC80211("leave\n");
3224 return 0;
3225}
3226
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003227static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
Tomas Winklerd783b062008-07-18 13:53:02 +08003228 enum ieee80211_ampdu_mlme_action action,
Johannes Berg17741cd2008-09-11 00:02:02 +02003229 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
Tomas Winklerd783b062008-07-18 13:53:02 +08003230{
3231 struct iwl_priv *priv = hw->priv;
Tomas Winklerd783b062008-07-18 13:53:02 +08003232
Johannes Berge1749612008-10-27 15:59:26 -07003233 IWL_DEBUG_HT("A-MPDU action on addr %pM tid %d\n",
3234 sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08003235
3236 if (!(priv->cfg->sku & IWL_SKU_N))
3237 return -EACCES;
3238
3239 switch (action) {
3240 case IEEE80211_AMPDU_RX_START:
3241 IWL_DEBUG_HT("start Rx\n");
Tomas Winkler9f586712008-11-12 13:14:05 -08003242 return iwl_sta_rx_agg_start(priv, sta->addr, tid, *ssn);
Tomas Winklerd783b062008-07-18 13:53:02 +08003243 case IEEE80211_AMPDU_RX_STOP:
3244 IWL_DEBUG_HT("stop Rx\n");
Tomas Winkler9f586712008-11-12 13:14:05 -08003245 return iwl_sta_rx_agg_stop(priv, sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08003246 case IEEE80211_AMPDU_TX_START:
3247 IWL_DEBUG_HT("start Tx\n");
Johannes Berg17741cd2008-09-11 00:02:02 +02003248 return iwl_tx_agg_start(priv, sta->addr, tid, ssn);
Tomas Winklerd783b062008-07-18 13:53:02 +08003249 case IEEE80211_AMPDU_TX_STOP:
3250 IWL_DEBUG_HT("stop Tx\n");
Johannes Berg17741cd2008-09-11 00:02:02 +02003251 return iwl_tx_agg_stop(priv, sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08003252 default:
3253 IWL_DEBUG_HT("unknown\n");
3254 return -EINVAL;
3255 break;
3256 }
3257 return 0;
3258}
Tomas Winkler9f586712008-11-12 13:14:05 -08003259
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003260static int iwl_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003261 struct ieee80211_tx_queue_stats *stats)
3262{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003263 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003264 int i, avail;
Ron Rindjunsky16466902008-05-05 10:22:50 +08003265 struct iwl_tx_queue *txq;
Tomas Winkler443cfd42008-05-15 13:53:57 +08003266 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07003267 unsigned long flags;
3268
3269 IWL_DEBUG_MAC80211("enter\n");
3270
Tomas Winklerfee12472008-04-03 16:05:21 -07003271 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003272 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3273 return -EIO;
3274 }
3275
3276 spin_lock_irqsave(&priv->lock, flags);
3277
3278 for (i = 0; i < AC_NUM; i++) {
3279 txq = &priv->txq[i];
3280 q = &txq->q;
Tomas Winkler443cfd42008-05-15 13:53:57 +08003281 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07003282
Johannes Berg57ffc582008-04-29 17:18:59 +02003283 stats[i].len = q->n_window - avail;
3284 stats[i].limit = q->n_window - q->high_mark;
3285 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07003286
3287 }
3288 spin_unlock_irqrestore(&priv->lock, flags);
3289
3290 IWL_DEBUG_MAC80211("leave\n");
3291
3292 return 0;
3293}
3294
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003295static int iwl_mac_get_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003296 struct ieee80211_low_level_stats *stats)
3297{
Ester Kummerbf403db2008-05-05 10:22:40 +08003298 struct iwl_priv *priv = hw->priv;
3299
3300 priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003301 IWL_DEBUG_MAC80211("enter\n");
3302 IWL_DEBUG_MAC80211("leave\n");
3303
3304 return 0;
3305}
3306
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003307static void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003308{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003309 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003310 unsigned long flags;
3311
3312 mutex_lock(&priv->mutex);
3313 IWL_DEBUG_MAC80211("enter\n");
3314
Zhu Yib481de92007-09-25 17:54:57 -07003315 spin_lock_irqsave(&priv->lock, flags);
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02003316 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
Zhu Yib481de92007-09-25 17:54:57 -07003317 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -07003318
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003319 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003320
Zhu Yib481de92007-09-25 17:54:57 -07003321 spin_lock_irqsave(&priv->lock, flags);
3322 priv->assoc_id = 0;
3323 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003324 priv->assoc_station_added = 0;
3325
3326 /* new association get rid of ibss beacon skb */
3327 if (priv->ibss_beacon)
3328 dev_kfree_skb(priv->ibss_beacon);
3329
3330 priv->ibss_beacon = NULL;
3331
3332 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler3109ece2008-03-28 16:33:35 -07003333 priv->timestamp = 0;
Johannes Berg05c914f2008-09-11 00:01:58 +02003334 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
Zhu Yib481de92007-09-25 17:54:57 -07003335 priv->beacon_int = 0;
3336
3337 spin_unlock_irqrestore(&priv->lock, flags);
3338
Tomas Winklerfee12472008-04-03 16:05:21 -07003339 if (!iwl_is_ready_rf(priv)) {
Mohamed Abbasfde35712007-11-29 11:10:15 +08003340 IWL_DEBUG_MAC80211("leave - not ready\n");
3341 mutex_unlock(&priv->mutex);
3342 return;
3343 }
3344
mabbas052c4b92007-10-25 17:15:43 +08003345 /* we are restarting association process
3346 * clear RXON_FILTER_ASSOC_MSK bit
3347 */
Johannes Berg05c914f2008-09-11 00:01:58 +02003348 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Tomas Winkler2a421b92008-06-12 09:47:10 +08003349 iwl_scan_cancel_timeout(priv, 100);
mabbas052c4b92007-10-25 17:15:43 +08003350 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003351 iwl_commit_rxon(priv);
mabbas052c4b92007-10-25 17:15:43 +08003352 }
3353
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003354 iwl_power_update_mode(priv, 0);
3355
Zhu Yib481de92007-09-25 17:54:57 -07003356 /* Per mac80211.h: This is only used in IBSS mode... */
Johannes Berg05c914f2008-09-11 00:01:58 +02003357 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
mabbas052c4b92007-10-25 17:15:43 +08003358
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08003359 /* switch to CAM during association period.
3360 * the ucode will block any association/authentication
3361 * frome during assiciation period if it can not hear
3362 * the AP because of PM. the timer enable PM back is
3363 * association do not complete
3364 */
3365 if (priv->hw->conf.channel->flags & (IEEE80211_CHAN_PASSIVE_SCAN |
3366 IEEE80211_CHAN_RADAR))
3367 iwl_power_disable_management(priv, 3000);
3368
Zhu Yib481de92007-09-25 17:54:57 -07003369 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
3370 mutex_unlock(&priv->mutex);
3371 return;
3372 }
3373
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003374 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003375
3376 mutex_unlock(&priv->mutex);
3377
3378 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003379}
3380
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003381static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003382{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003383 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003384 unsigned long flags;
Assaf Krauss2ff75b72008-06-30 17:23:17 +08003385 __le64 timestamp;
Zhu Yib481de92007-09-25 17:54:57 -07003386
Zhu Yib481de92007-09-25 17:54:57 -07003387 IWL_DEBUG_MAC80211("enter\n");
3388
Tomas Winklerfee12472008-04-03 16:05:21 -07003389 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003390 IWL_DEBUG_MAC80211("leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07003391 return -EIO;
3392 }
3393
Johannes Berg05c914f2008-09-11 00:01:58 +02003394 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Zhu Yib481de92007-09-25 17:54:57 -07003395 IWL_DEBUG_MAC80211("leave - not IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07003396 return -EIO;
3397 }
3398
3399 spin_lock_irqsave(&priv->lock, flags);
3400
3401 if (priv->ibss_beacon)
3402 dev_kfree_skb(priv->ibss_beacon);
3403
3404 priv->ibss_beacon = skb;
3405
3406 priv->assoc_id = 0;
Assaf Krauss2ff75b72008-06-30 17:23:17 +08003407 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
Assaf Kraussb94d8ee2008-09-03 11:18:42 +08003408 priv->timestamp = le64_to_cpu(timestamp);
Zhu Yib481de92007-09-25 17:54:57 -07003409
3410 IWL_DEBUG_MAC80211("leave\n");
3411 spin_unlock_irqrestore(&priv->lock, flags);
3412
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003413 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003414
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003415 iwl_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003416
Zhu Yib481de92007-09-25 17:54:57 -07003417
3418 return 0;
3419}
3420
Zhu Yib481de92007-09-25 17:54:57 -07003421/*****************************************************************************
3422 *
3423 * sysfs attributes
3424 *
3425 *****************************************************************************/
3426
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003427#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07003428
3429/*
3430 * The following adds a new attribute to the sysfs representation
Wu, Fengguangc3a739f2008-12-17 16:52:29 +08003431 * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
Zhu Yib481de92007-09-25 17:54:57 -07003432 * used for controlling the debug level.
3433 *
3434 * See the level definitions in iwl for details.
3435 */
3436
Ester Kummer8cf769c2008-05-06 11:05:11 +08003437static ssize_t show_debug_level(struct device *d,
3438 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07003439{
Ester Kummer8cf769c2008-05-06 11:05:11 +08003440 struct iwl_priv *priv = d->driver_data;
3441
3442 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07003443}
Ester Kummer8cf769c2008-05-06 11:05:11 +08003444static ssize_t store_debug_level(struct device *d,
3445 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07003446 const char *buf, size_t count)
3447{
Ester Kummer8cf769c2008-05-06 11:05:11 +08003448 struct iwl_priv *priv = d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003449 unsigned long val;
3450 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003451
Tomas Winkler9257746f2008-09-03 11:26:32 +08003452 ret = strict_strtoul(buf, 0, &val);
3453 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08003454 IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07003455 else
Ester Kummer8cf769c2008-05-06 11:05:11 +08003456 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07003457
3458 return strnlen(buf, count);
3459}
3460
Ester Kummer8cf769c2008-05-06 11:05:11 +08003461static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
3462 show_debug_level, store_debug_level);
3463
Zhu Yib481de92007-09-25 17:54:57 -07003464
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003465#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07003466
Zhu Yib481de92007-09-25 17:54:57 -07003467
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003468static ssize_t show_version(struct device *d,
3469 struct device_attribute *attr, char *buf)
3470{
3471 struct iwl_priv *priv = d->driver_data;
Tomas Winkler885ba202008-05-29 16:34:55 +08003472 struct iwl_alive_resp *palive = &priv->card_alive;
Tomas Winklerf236a262008-06-30 17:23:02 +08003473 ssize_t pos = 0;
3474 u16 eeprom_ver;
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003475
3476 if (palive->is_valid)
Tomas Winklerf236a262008-06-30 17:23:02 +08003477 pos += sprintf(buf + pos,
3478 "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n"
3479 "fw type: 0x%01X 0x%01X\n",
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003480 palive->ucode_major, palive->ucode_minor,
3481 palive->sw_rev[0], palive->sw_rev[1],
3482 palive->ver_type, palive->ver_subtype);
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003483 else
Tomas Winklerf236a262008-06-30 17:23:02 +08003484 pos += sprintf(buf + pos, "fw not loaded\n");
3485
3486 if (priv->eeprom) {
3487 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
3488 pos += sprintf(buf + pos, "EEPROM version: 0x%x\n",
3489 eeprom_ver);
3490 } else {
3491 pos += sprintf(buf + pos, "EEPROM not initialzed\n");
3492 }
3493
3494 return pos;
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003495}
3496
3497static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL);
3498
Zhu Yib481de92007-09-25 17:54:57 -07003499static ssize_t show_temperature(struct device *d,
3500 struct device_attribute *attr, char *buf)
3501{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003502 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003503
Tomas Winklerfee12472008-04-03 16:05:21 -07003504 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003505 return -EAGAIN;
3506
Emmanuel Grumbach91dbc5b2008-06-12 09:47:14 +08003507 return sprintf(buf, "%d\n", priv->temperature);
Zhu Yib481de92007-09-25 17:54:57 -07003508}
3509
3510static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
3511
Zhu Yib481de92007-09-25 17:54:57 -07003512static ssize_t show_tx_power(struct device *d,
3513 struct device_attribute *attr, char *buf)
3514{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003515 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Jay Sternberg91f39e82008-12-17 16:52:34 +08003516
3517 if (!iwl_is_ready_rf(priv))
3518 return sprintf(buf, "off\n");
3519 else
3520 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07003521}
3522
3523static ssize_t store_tx_power(struct device *d,
3524 struct device_attribute *attr,
3525 const char *buf, size_t count)
3526{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003527 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003528 unsigned long val;
3529 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003530
Tomas Winkler9257746f2008-09-03 11:26:32 +08003531 ret = strict_strtoul(buf, 10, &val);
3532 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08003533 IWL_INFO(priv, "%s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07003534 else
Tomas Winkler630fe9b2008-06-12 09:47:08 +08003535 iwl_set_tx_power(priv, val, false);
Zhu Yib481de92007-09-25 17:54:57 -07003536
3537 return count;
3538}
3539
3540static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
3541
3542static ssize_t show_flags(struct device *d,
3543 struct device_attribute *attr, char *buf)
3544{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003545 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003546
3547 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
3548}
3549
3550static ssize_t store_flags(struct device *d,
3551 struct device_attribute *attr,
3552 const char *buf, size_t count)
3553{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003554 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003555 unsigned long val;
3556 u32 flags;
3557 int ret = strict_strtoul(buf, 0, &val);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08003558 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08003559 return ret;
3560 flags = (u32)val;
Zhu Yib481de92007-09-25 17:54:57 -07003561
3562 mutex_lock(&priv->mutex);
3563 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
3564 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08003565 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003566 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003567 else {
Tomas Winkler9257746f2008-09-03 11:26:32 +08003568 IWL_DEBUG_INFO("Commit rxon.flags = 0x%04X\n", flags);
Zhu Yib481de92007-09-25 17:54:57 -07003569 priv->staging_rxon.flags = cpu_to_le32(flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003570 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003571 }
3572 }
3573 mutex_unlock(&priv->mutex);
3574
3575 return count;
3576}
3577
3578static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
3579
3580static ssize_t show_filter_flags(struct device *d,
3581 struct device_attribute *attr, char *buf)
3582{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003583 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003584
3585 return sprintf(buf, "0x%04X\n",
3586 le32_to_cpu(priv->active_rxon.filter_flags));
3587}
3588
3589static ssize_t store_filter_flags(struct device *d,
3590 struct device_attribute *attr,
3591 const char *buf, size_t count)
3592{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003593 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003594 unsigned long val;
3595 u32 filter_flags;
3596 int ret = strict_strtoul(buf, 0, &val);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08003597 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08003598 return ret;
3599 filter_flags = (u32)val;
Zhu Yib481de92007-09-25 17:54:57 -07003600
3601 mutex_lock(&priv->mutex);
3602 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
3603 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08003604 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003605 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003606 else {
3607 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
3608 "0x%04X\n", filter_flags);
3609 priv->staging_rxon.filter_flags =
3610 cpu_to_le32(filter_flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003611 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003612 }
3613 }
3614 mutex_unlock(&priv->mutex);
3615
3616 return count;
3617}
3618
3619static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
3620 store_filter_flags);
3621
Zhu Yib481de92007-09-25 17:54:57 -07003622static ssize_t store_power_level(struct device *d,
3623 struct device_attribute *attr,
3624 const char *buf, size_t count)
3625{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003626 struct iwl_priv *priv = dev_get_drvdata(d);
Esti Kummer298df1f2008-07-18 13:52:58 +08003627 int ret;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003628 unsigned long mode;
Zhu Yib481de92007-09-25 17:54:57 -07003629
Tomas Winkler9257746f2008-09-03 11:26:32 +08003630
Zhu Yib481de92007-09-25 17:54:57 -07003631 mutex_lock(&priv->mutex);
3632
Tomas Winklerfee12472008-04-03 16:05:21 -07003633 if (!iwl_is_ready(priv)) {
Esti Kummer298df1f2008-07-18 13:52:58 +08003634 ret = -EAGAIN;
Zhu Yib481de92007-09-25 17:54:57 -07003635 goto out;
3636 }
3637
Tomas Winkler9257746f2008-09-03 11:26:32 +08003638 ret = strict_strtoul(buf, 10, &mode);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08003639 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08003640 goto out;
3641
Esti Kummer298df1f2008-07-18 13:52:58 +08003642 ret = iwl_power_set_user_mode(priv, mode);
3643 if (ret) {
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003644 IWL_DEBUG_MAC80211("failed setting power mode.\n");
3645 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003646 }
Esti Kummer298df1f2008-07-18 13:52:58 +08003647 ret = count;
Zhu Yib481de92007-09-25 17:54:57 -07003648
3649 out:
3650 mutex_unlock(&priv->mutex);
Esti Kummer298df1f2008-07-18 13:52:58 +08003651 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003652}
3653
Zhu Yib481de92007-09-25 17:54:57 -07003654static ssize_t show_power_level(struct device *d,
3655 struct device_attribute *attr, char *buf)
3656{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003657 struct iwl_priv *priv = dev_get_drvdata(d);
Esti Kummer298df1f2008-07-18 13:52:58 +08003658 int mode = priv->power_data.user_power_setting;
3659 int system = priv->power_data.system_power_setting;
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003660 int level = priv->power_data.power_mode;
Zhu Yib481de92007-09-25 17:54:57 -07003661 char *p = buf;
3662
Esti Kummer298df1f2008-07-18 13:52:58 +08003663 switch (system) {
3664 case IWL_POWER_SYS_AUTO:
3665 p += sprintf(p, "SYSTEM:auto");
Zhu Yib481de92007-09-25 17:54:57 -07003666 break;
Esti Kummer298df1f2008-07-18 13:52:58 +08003667 case IWL_POWER_SYS_AC:
3668 p += sprintf(p, "SYSTEM:ac");
Zhu Yib481de92007-09-25 17:54:57 -07003669 break;
Esti Kummer298df1f2008-07-18 13:52:58 +08003670 case IWL_POWER_SYS_BATTERY:
3671 p += sprintf(p, "SYSTEM:battery");
3672 break;
Zhu Yib481de92007-09-25 17:54:57 -07003673 }
Esti Kummer298df1f2008-07-18 13:52:58 +08003674
Abhijeet Kolekarc3056062008-11-12 13:14:08 -08003675 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
3676 "fixed" : "auto");
Esti Kummer298df1f2008-07-18 13:52:58 +08003677 p += sprintf(p, "\tINDEX:%d", level);
3678 p += sprintf(p, "\n");
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003679 return p - buf + 1;
Zhu Yib481de92007-09-25 17:54:57 -07003680}
3681
3682static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
3683 store_power_level);
3684
Zhu Yib481de92007-09-25 17:54:57 -07003685
3686static ssize_t show_statistics(struct device *d,
3687 struct device_attribute *attr, char *buf)
3688{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003689 struct iwl_priv *priv = dev_get_drvdata(d);
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08003690 u32 size = sizeof(struct iwl_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07003691 u32 len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003692 u8 *data = (u8 *)&priv->statistics;
Zhu Yib481de92007-09-25 17:54:57 -07003693 int rc = 0;
3694
Tomas Winklerfee12472008-04-03 16:05:21 -07003695 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003696 return -EAGAIN;
3697
3698 mutex_lock(&priv->mutex);
Emmanuel Grumbach49ea8592008-04-15 16:01:37 -07003699 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003700 mutex_unlock(&priv->mutex);
3701
3702 if (rc) {
3703 len = sprintf(buf,
3704 "Error sending statistics request: 0x%08X\n", rc);
3705 return len;
3706 }
3707
3708 while (size && (PAGE_SIZE - len)) {
3709 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
3710 PAGE_SIZE - len, 1);
3711 len = strlen(buf);
3712 if (PAGE_SIZE - len)
3713 buf[len++] = '\n';
3714
3715 ofs += 16;
3716 size -= min(size, 16U);
3717 }
3718
3719 return len;
3720}
3721
3722static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
3723
Zhu Yib481de92007-09-25 17:54:57 -07003724
Zhu Yib481de92007-09-25 17:54:57 -07003725/*****************************************************************************
3726 *
3727 * driver setup and teardown
3728 *
3729 *****************************************************************************/
3730
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003731static void iwl_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003732{
3733 priv->workqueue = create_workqueue(DRV_NAME);
3734
3735 init_waitqueue_head(&priv->wait_command_queue);
3736
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003737 INIT_WORK(&priv->up, iwl_bg_up);
3738 INIT_WORK(&priv->restart, iwl_bg_restart);
3739 INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish);
3740 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
3741 INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08003742 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08003743 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
3744 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
Tomas Winkler2a421b92008-06-12 09:47:10 +08003745
Tomas Winkler2a421b92008-06-12 09:47:10 +08003746 iwl_setup_scan_deferred_work(priv);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08003747 iwl_setup_power_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003748
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003749 if (priv->cfg->ops->lib->setup_deferred_work)
3750 priv->cfg->ops->lib->setup_deferred_work(priv);
3751
3752 init_timer(&priv->statistics_periodic);
3753 priv->statistics_periodic.data = (unsigned long)priv;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003754 priv->statistics_periodic.function = iwl_bg_statistics_periodic;
Zhu Yib481de92007-09-25 17:54:57 -07003755
3756 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003757 iwl_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07003758}
3759
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003760static void iwl_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003761{
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003762 if (priv->cfg->ops->lib->cancel_deferred_work)
3763 priv->cfg->ops->lib->cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003764
Joonwoo Park3ae6a052007-11-29 10:43:16 +09003765 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07003766 cancel_delayed_work(&priv->scan_check);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08003767 cancel_delayed_work_sync(&priv->set_power_save);
Zhu Yib481de92007-09-25 17:54:57 -07003768 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07003769 cancel_work_sync(&priv->beacon_update);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003770 del_timer_sync(&priv->statistics_periodic);
Zhu Yib481de92007-09-25 17:54:57 -07003771}
3772
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003773static struct attribute *iwl_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07003774 &dev_attr_flags.attr,
3775 &dev_attr_filter_flags.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003776 &dev_attr_power_level.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003777 &dev_attr_statistics.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003778 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003779 &dev_attr_tx_power.attr,
Ester Kummer8cf769c2008-05-06 11:05:11 +08003780#ifdef CONFIG_IWLWIFI_DEBUG
3781 &dev_attr_debug_level.attr,
3782#endif
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003783 &dev_attr_version.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003784
3785 NULL
3786};
3787
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003788static struct attribute_group iwl_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07003789 .name = NULL, /* put in device directory */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003790 .attrs = iwl_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07003791};
3792
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003793static struct ieee80211_ops iwl_hw_ops = {
3794 .tx = iwl_mac_tx,
3795 .start = iwl_mac_start,
3796 .stop = iwl_mac_stop,
3797 .add_interface = iwl_mac_add_interface,
3798 .remove_interface = iwl_mac_remove_interface,
3799 .config = iwl_mac_config,
3800 .config_interface = iwl_mac_config_interface,
3801 .configure_filter = iwl_configure_filter,
3802 .set_key = iwl_mac_set_key,
3803 .update_tkip_key = iwl_mac_update_tkip_key,
3804 .get_stats = iwl_mac_get_stats,
3805 .get_tx_stats = iwl_mac_get_tx_stats,
3806 .conf_tx = iwl_mac_conf_tx,
3807 .reset_tsf = iwl_mac_reset_tsf,
3808 .bss_info_changed = iwl_bss_info_changed,
3809 .ampdu_action = iwl_mac_ampdu_action,
Tomas Winklercb43dc22008-09-03 11:26:23 +08003810 .hw_scan = iwl_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07003811};
3812
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003813static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07003814{
3815 int err = 0;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003816 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07003817 struct ieee80211_hw *hw;
Tomas Winkler82b9a122008-03-04 18:09:30 -08003818 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003819 unsigned long flags;
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003820 u16 pci_cmd;
Zhu Yib481de92007-09-25 17:54:57 -07003821
Assaf Krauss316c30d2008-03-14 10:38:46 -07003822 /************************
3823 * 1. Allocating HW data
3824 ************************/
3825
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003826 /* Disabling hardware scan means that mac80211 will perform scans
3827 * "the hard way", rather than using device's scan. */
Assaf Krauss1ea87392008-03-18 14:57:50 -07003828 if (cfg->mod_params->disable_hw_scan) {
Ester Kummerbf403db2008-05-05 10:22:40 +08003829 if (cfg->mod_params->debug & IWL_DL_INFO)
3830 dev_printk(KERN_DEBUG, &(pdev->dev),
3831 "Disabling hw_scan\n");
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003832 iwl_hw_ops.hw_scan = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07003833 }
3834
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003835 hw = iwl_alloc_all(cfg, &iwl_hw_ops);
Assaf Krauss1d0a0822008-03-14 10:38:48 -07003836 if (!hw) {
Zhu Yib481de92007-09-25 17:54:57 -07003837 err = -ENOMEM;
3838 goto out;
3839 }
Assaf Krauss1d0a0822008-03-14 10:38:48 -07003840 priv = hw->priv;
3841 /* At this point both hw and priv are allocated. */
3842
Zhu Yib481de92007-09-25 17:54:57 -07003843 SET_IEEE80211_DEV(hw, &pdev->dev);
3844
3845 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
Tomas Winkler82b9a122008-03-04 18:09:30 -08003846 priv->cfg = cfg;
Zhu Yib481de92007-09-25 17:54:57 -07003847 priv->pci_dev = pdev;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003848
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003849#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08003850 priv->debug_level = priv->cfg->mod_params->debug;
Zhu Yib481de92007-09-25 17:54:57 -07003851 atomic_set(&priv->restrict_refcnt, 0);
3852#endif
Zhu Yib481de92007-09-25 17:54:57 -07003853
Assaf Krauss316c30d2008-03-14 10:38:46 -07003854 /**************************
3855 * 2. Initializing PCI bus
3856 **************************/
3857 if (pci_enable_device(pdev)) {
3858 err = -ENODEV;
3859 goto out_ieee80211_free_hw;
3860 }
3861
3862 pci_set_master(pdev);
3863
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003864 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
Assaf Krauss316c30d2008-03-14 10:38:46 -07003865 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003866 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003867 if (err) {
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003868 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003869 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003870 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003871 /* both attempts failed: */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003872 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08003873 IWL_WARN(priv, "No suitable DMA available.\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07003874 goto out_pci_disable_device;
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003875 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07003876 }
3877
3878 err = pci_request_regions(pdev, DRV_NAME);
3879 if (err)
3880 goto out_pci_disable_device;
3881
3882 pci_set_drvdata(pdev, priv);
3883
Assaf Krauss316c30d2008-03-14 10:38:46 -07003884
3885 /***********************
3886 * 3. Read REV register
3887 ***********************/
3888 priv->hw_base = pci_iomap(pdev, 0, 0);
3889 if (!priv->hw_base) {
3890 err = -ENODEV;
3891 goto out_pci_release_regions;
3892 }
3893
3894 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
3895 (unsigned long long) pci_resource_len(pdev, 0));
3896 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
3897
Tomas Winklerb661c812008-04-23 17:14:54 -07003898 iwl_hw_detect(priv);
Tomas Winkler978785a2008-12-19 10:37:31 +08003899 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s REV=0x%X\n",
Tomas Winklerb661c812008-04-23 17:14:54 -07003900 priv->cfg->name, priv->hw_rev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003901
Tomas Winklere7b63582008-09-03 11:26:49 +08003902 /* We disable the RETRY_TIMEOUT register (0x41) to keep
3903 * PCI Tx retries from interfering with C3 CPU state */
3904 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
3905
Tomas Winkler91238712008-04-23 17:14:53 -07003906 /* amp init */
3907 err = priv->cfg->ops->lib->apm_ops.init(priv);
3908 if (err < 0) {
3909 IWL_DEBUG_INFO("Failed to init APMG\n");
3910 goto out_iounmap;
3911 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07003912 /*****************
3913 * 4. Read EEPROM
3914 *****************/
Assaf Krauss316c30d2008-03-14 10:38:46 -07003915 /* Read the EEPROM */
3916 err = iwl_eeprom_init(priv);
3917 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003918 IWL_ERR(priv, "Unable to init EEPROM\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07003919 goto out_iounmap;
3920 }
Tomas Winkler8614f362008-04-23 17:14:55 -07003921 err = iwl_eeprom_check_version(priv);
3922 if (err)
3923 goto out_iounmap;
3924
Ron Rindjunsky02883012008-05-15 13:53:53 +08003925 /* extract MAC Address */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003926 iwl_eeprom_get_mac(priv, priv->mac_addr);
Johannes Berge1749612008-10-27 15:59:26 -07003927 IWL_DEBUG_INFO("MAC address: %pM\n", priv->mac_addr);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003928 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
3929
3930 /************************
3931 * 5. Setup HW constants
3932 ************************/
Ron Rindjunskyda154e302008-06-30 17:23:20 +08003933 if (iwl_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003934 IWL_ERR(priv, "failed to set hw parameters\n");
Tomas Winkler073d3f52008-04-21 15:41:52 -07003935 goto out_free_eeprom;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003936 }
3937
3938 /*******************
Tomas Winkler6ba87952008-05-15 13:54:17 +08003939 * 6. Setup priv
Assaf Krauss316c30d2008-03-14 10:38:46 -07003940 *******************/
Zhu Yib481de92007-09-25 17:54:57 -07003941
Tomas Winkler6ba87952008-05-15 13:54:17 +08003942 err = iwl_init_drv(priv);
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003943 if (err)
Ron Rindjunsky399f4902008-04-23 17:14:56 -07003944 goto out_free_eeprom;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003945 /* At this point both hw and priv are initialized. */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003946
3947 /**********************************
3948 * 7. Initialize module parameters
3949 **********************************/
3950
3951 /* Disable radio (SW RF KILL) via parameter when loading driver */
Assaf Krauss1ea87392008-03-18 14:57:50 -07003952 if (priv->cfg->mod_params->disable) {
Assaf Krauss316c30d2008-03-14 10:38:46 -07003953 set_bit(STATUS_RF_KILL_SW, &priv->status);
3954 IWL_DEBUG_INFO("Radio disabled.\n");
3955 }
3956
Assaf Krauss316c30d2008-03-14 10:38:46 -07003957 /********************
3958 * 8. Setup services
3959 ********************/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003960 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003961 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003962 spin_unlock_irqrestore(&priv->lock, flags);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003963
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003964 pci_enable_msi(priv->pci_dev);
3965
3966 err = request_irq(priv->pci_dev->irq, iwl_isr, IRQF_SHARED,
3967 DRV_NAME, priv);
3968 if (err) {
3969 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
3970 goto out_disable_msi;
3971 }
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003972 err = sysfs_create_group(&pdev->dev.kobj, &iwl_attribute_group);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003973 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003974 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Tomas Winkler6ba87952008-05-15 13:54:17 +08003975 goto out_uninit_drv;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003976 }
3977
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003978 iwl_setup_deferred_work(priv);
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08003979 iwl_setup_rx_handlers(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003980
Tomas Winkler6ba87952008-05-15 13:54:17 +08003981 /**********************************
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003982 * 9. Setup and register mac80211
Tomas Winkler6ba87952008-05-15 13:54:17 +08003983 **********************************/
3984
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003985 /* enable interrupts if needed: hw bug w/a */
3986 pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd);
3987 if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
3988 pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
3989 pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
3990 }
3991
3992 iwl_enable_interrupts(priv);
3993
Tomas Winkler6ba87952008-05-15 13:54:17 +08003994 err = iwl_setup_mac(priv);
3995 if (err)
3996 goto out_remove_sysfs;
3997
3998 err = iwl_dbgfs_register(priv, DRV_NAME);
3999 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08004000 IWL_ERR(priv, "failed to create debugfs files\n");
Tomas Winkler6ba87952008-05-15 13:54:17 +08004001
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004002 /* If platform's RF_KILL switch is NOT set to KILL */
4003 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
4004 clear_bit(STATUS_RF_KILL_HW, &priv->status);
4005 else
4006 set_bit(STATUS_RF_KILL_HW, &priv->status);
4007
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08004008 err = iwl_rfkill_init(priv);
4009 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08004010 IWL_ERR(priv, "Unable to initialize RFKILL system. "
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08004011 "Ignoring error: %d\n", err);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004012 else
4013 iwl_rfkill_set_hw_state(priv);
4014
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08004015 iwl_power_initialize(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004016 return 0;
4017
Assaf Krauss316c30d2008-03-14 10:38:46 -07004018 out_remove_sysfs:
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004019 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004020 out_disable_msi:
4021 pci_disable_msi(priv->pci_dev);
4022 pci_disable_device(priv->pci_dev);
Tomas Winkler6ba87952008-05-15 13:54:17 +08004023 out_uninit_drv:
4024 iwl_uninit_drv(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07004025 out_free_eeprom:
4026 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004027 out_iounmap:
4028 pci_iounmap(pdev, priv->hw_base);
4029 out_pci_release_regions:
4030 pci_release_regions(pdev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004031 pci_set_drvdata(pdev, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07004032 out_pci_disable_device:
4033 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004034 out_ieee80211_free_hw:
4035 ieee80211_free_hw(priv->hw);
4036 out:
4037 return err;
4038}
4039
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004040static void __devexit iwl_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004041{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004042 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004043 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07004044
4045 if (!priv)
4046 return;
4047
4048 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
4049
Emmanuel Grumbach67249622008-05-29 16:35:26 +08004050 iwl_dbgfs_unregister(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004051 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
Emmanuel Grumbach67249622008-05-29 16:35:26 +08004052
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004053 /* ieee80211_unregister_hw call wil cause iwl_mac_stop to
4054 * to be called and iwl_down since we are removing the device
Gregory Greenman0b124c32008-09-03 11:18:50 +08004055 * we need to set STATUS_EXIT_PENDING bit.
4056 */
4057 set_bit(STATUS_EXIT_PENDING, &priv->status);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07004058 if (priv->mac80211_registered) {
4059 ieee80211_unregister_hw(priv->hw);
4060 priv->mac80211_registered = 0;
Gregory Greenman0b124c32008-09-03 11:18:50 +08004061 } else {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004062 iwl_down(priv);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07004063 }
4064
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004065 /* make sure we flush any pending irq or
4066 * tasklet for the driver
4067 */
4068 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004069 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004070 spin_unlock_irqrestore(&priv->lock, flags);
4071
4072 iwl_synchronize_irq(priv);
4073
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08004074 iwl_rfkill_unregister(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004075 iwl_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004076
4077 if (priv->rxq.bd)
Tomas Winklera55360e2008-05-05 10:22:28 +08004078 iwl_rx_queue_free(priv, &priv->rxq);
Ron Rindjunsky1053d352008-05-05 10:22:43 +08004079 iwl_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004080
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08004081 iwl_clear_stations_table(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07004082 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004083
Zhu Yib481de92007-09-25 17:54:57 -07004084
Mohamed Abbas948c1712007-10-25 17:15:45 +08004085 /*netif_stop_queue(dev); */
4086 flush_workqueue(priv->workqueue);
4087
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004088 /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07004089 * priv->workqueue... so we can't take down the workqueue
4090 * until now... */
4091 destroy_workqueue(priv->workqueue);
4092 priv->workqueue = NULL;
4093
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004094 free_irq(priv->pci_dev->irq, priv);
4095 pci_disable_msi(priv->pci_dev);
Zhu Yib481de92007-09-25 17:54:57 -07004096 pci_iounmap(pdev, priv->hw_base);
4097 pci_release_regions(pdev);
4098 pci_disable_device(pdev);
4099 pci_set_drvdata(pdev, NULL);
4100
Tomas Winkler6ba87952008-05-15 13:54:17 +08004101 iwl_uninit_drv(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004102
4103 if (priv->ibss_beacon)
4104 dev_kfree_skb(priv->ibss_beacon);
4105
4106 ieee80211_free_hw(priv->hw);
4107}
4108
4109#ifdef CONFIG_PM
4110
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004111static int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07004112{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004113 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004114
Zhu Yie655b9f2008-01-24 02:19:38 -08004115 if (priv->is_open) {
4116 set_bit(STATUS_IN_SUSPEND, &priv->status);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004117 iwl_mac_stop(priv->hw);
Zhu Yie655b9f2008-01-24 02:19:38 -08004118 priv->is_open = 1;
4119 }
Zhu Yib481de92007-09-25 17:54:57 -07004120
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004121 pci_save_state(pdev);
4122 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004123 pci_set_power_state(pdev, PCI_D3hot);
4124
Zhu Yib481de92007-09-25 17:54:57 -07004125 return 0;
4126}
4127
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004128static int iwl_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004129{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004130 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004131
Zhu Yib481de92007-09-25 17:54:57 -07004132 pci_set_power_state(pdev, PCI_D0);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004133 pci_enable_device(pdev);
4134 pci_restore_state(pdev);
4135 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004136
Zhu Yie655b9f2008-01-24 02:19:38 -08004137 if (priv->is_open)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004138 iwl_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07004139
Zhu Yie655b9f2008-01-24 02:19:38 -08004140 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004141 return 0;
4142}
4143
4144#endif /* CONFIG_PM */
4145
4146/*****************************************************************************
4147 *
4148 * driver and module entry point
4149 *
4150 *****************************************************************************/
4151
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004152/* Hardware specific file defines the PCI IDs table for that hardware module */
4153static struct pci_device_id iwl_hw_card_ids[] = {
Tomas Winkler4fc22b22008-07-21 18:54:42 +03004154#ifdef CONFIG_IWL4965
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004155 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
4156 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
Tomas Winkler4fc22b22008-07-21 18:54:42 +03004157#endif /* CONFIG_IWL4965 */
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004158#ifdef CONFIG_IWL5000
Esti Kummer47408632008-07-11 11:53:30 +08004159 {IWL_PCI_DEVICE(0x4232, 0x1205, iwl5100_bg_cfg)},
4160 {IWL_PCI_DEVICE(0x4232, 0x1305, iwl5100_bg_cfg)},
4161 {IWL_PCI_DEVICE(0x4232, 0x1206, iwl5100_abg_cfg)},
4162 {IWL_PCI_DEVICE(0x4232, 0x1306, iwl5100_abg_cfg)},
4163 {IWL_PCI_DEVICE(0x4232, 0x1326, iwl5100_abg_cfg)},
4164 {IWL_PCI_DEVICE(0x4237, 0x1216, iwl5100_abg_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004165 {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)},
Esti Kummer47408632008-07-11 11:53:30 +08004166 {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)},
4167 {IWL_PCI_DEVICE(0x4236, PCI_ANY_ID, iwl5300_agn_cfg)},
4168 {IWL_PCI_DEVICE(0x4237, PCI_ANY_ID, iwl5100_agn_cfg)},
Tomas Winklere96a8492008-09-11 11:45:20 +08004169/* 5350 WiFi/WiMax */
4170 {IWL_PCI_DEVICE(0x423A, 0x1001, iwl5350_agn_cfg)},
4171 {IWL_PCI_DEVICE(0x423A, 0x1021, iwl5350_agn_cfg)},
4172 {IWL_PCI_DEVICE(0x423B, 0x1011, iwl5350_agn_cfg)},
Tomas Winkler7100e922008-12-01 16:32:18 -08004173/* 5150 Wifi/WiMax */
4174 {IWL_PCI_DEVICE(0x423C, PCI_ANY_ID, iwl5150_agn_cfg)},
4175 {IWL_PCI_DEVICE(0x423D, PCI_ANY_ID, iwl5150_agn_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004176#endif /* CONFIG_IWL5000 */
Tomas Winkler7100e922008-12-01 16:32:18 -08004177
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004178 {0}
4179};
4180MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
4181
4182static struct pci_driver iwl_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07004183 .name = DRV_NAME,
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004184 .id_table = iwl_hw_card_ids,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004185 .probe = iwl_pci_probe,
4186 .remove = __devexit_p(iwl_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07004187#ifdef CONFIG_PM
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004188 .suspend = iwl_pci_suspend,
4189 .resume = iwl_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07004190#endif
4191};
4192
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004193static int __init iwl_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07004194{
4195
4196 int ret;
4197 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
4198 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004199
Tomas Winklere227cea2008-07-18 13:53:05 +08004200 ret = iwlagn_rate_control_register();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004201 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08004202 printk(KERN_ERR DRV_NAME
4203 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004204 return ret;
4205 }
4206
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004207 ret = pci_register_driver(&iwl_driver);
Zhu Yib481de92007-09-25 17:54:57 -07004208 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08004209 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004210 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07004211 }
Zhu Yib481de92007-09-25 17:54:57 -07004212
4213 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004214
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004215error_register:
Tomas Winklere227cea2008-07-18 13:53:05 +08004216 iwlagn_rate_control_unregister();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004217 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004218}
4219
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004220static void __exit iwl_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07004221{
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004222 pci_unregister_driver(&iwl_driver);
Tomas Winklere227cea2008-07-18 13:53:05 +08004223 iwlagn_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07004224}
4225
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004226module_exit(iwl_exit);
4227module_init(iwl_init);