blob: 4ce3d6a63d18bed3df3e3822db1e12d0737feded [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Reinette Chatre01f81622009-01-08 10:20:02 -08003 * Copyright(c) 2003 - 2009 Intel Corporation. All rights reserved.
Zhu Yib481de92007-09-25 17:54:57 -07004 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
Winkler, Tomas759ef892008-12-09 11:28:58 -080025 * Intel Linux Wireless <ilw@linux.intel.com>
Zhu Yib481de92007-09-25 17:54:57 -070026 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
Zhu Yib481de92007-09-25 17:54:57 -070030#include <linux/kernel.h>
31#include <linux/module.h>
Zhu Yib481de92007-09-25 17:54:57 -070032#include <linux/init.h>
33#include <linux/pci.h>
34#include <linux/dma-mapping.h>
35#include <linux/delay.h>
36#include <linux/skbuff.h>
37#include <linux/netdevice.h>
38#include <linux/wireless.h>
39#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070040#include <linux/etherdevice.h>
41#include <linux/if_arp.h>
42
Zhu Yib481de92007-09-25 17:54:57 -070043#include <net/mac80211.h>
44
45#include <asm/div64.h>
46
Samuel Ortiza3139c52008-12-19 10:37:09 +080047#define DRV_NAME "iwlagn"
48
Assaf Krauss6bc913b2008-03-11 16:17:18 -070049#include "iwl-eeprom.h"
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070050#include "iwl-dev.h"
Tomas Winklerfee12472008-04-03 16:05:21 -070051#include "iwl-core.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070052#include "iwl-io.h"
Zhu Yib481de92007-09-25 17:54:57 -070053#include "iwl-helpers.h"
Emmanuel Grumbach6974e362008-04-14 21:16:06 -070054#include "iwl-sta.h"
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -070055#include "iwl-calib.h"
Zhu Yib481de92007-09-25 17:54:57 -070056
Christoph Hellwig416e1432007-10-25 17:15:49 +080057
Zhu Yib481de92007-09-25 17:54:57 -070058/******************************************************************************
59 *
60 * module boiler plate
61 *
62 ******************************************************************************/
63
Zhu Yib481de92007-09-25 17:54:57 -070064/*
65 * module name, copyright, version, etc.
Zhu Yib481de92007-09-25 17:54:57 -070066 */
Tomas Winklerd783b062008-07-18 13:53:02 +080067#define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
Zhu Yib481de92007-09-25 17:54:57 -070068
Tomas Winkler0a6857e2008-03-12 16:58:49 -070069#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070070#define VD "d"
71#else
72#define VD
73#endif
74
Tomas Winkler4fc22b22008-07-21 18:54:42 +030075#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070076#define VS "s"
77#else
78#define VS
79#endif
80
Tomas Winklerdf48c322008-03-06 10:40:19 -080081#define DRV_VERSION IWLWIFI_VERSION VD VS
Zhu Yib481de92007-09-25 17:54:57 -070082
Zhu Yib481de92007-09-25 17:54:57 -070083
84MODULE_DESCRIPTION(DRV_DESCRIPTION);
85MODULE_VERSION(DRV_VERSION);
Tomas Winklera7b75202008-12-11 10:33:41 -080086MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
Zhu Yib481de92007-09-25 17:54:57 -070087MODULE_LICENSE("GPL");
Tomas Winkler4fc22b22008-07-21 18:54:42 +030088MODULE_ALIAS("iwl4965");
Zhu Yib481de92007-09-25 17:54:57 -070089
Zhu Yib481de92007-09-25 17:54:57 -070090/*************** STATION TABLE MANAGEMENT ****
Ben Cahill9fbab512007-11-29 11:09:47 +080091 * mac80211 should be examined to determine if sta_info is duplicating
Zhu Yib481de92007-09-25 17:54:57 -070092 * the functionality provided here
93 */
94
95/**************************************************************/
96
Zhu Yib481de92007-09-25 17:54:57 -070097
Zhu Yib481de92007-09-25 17:54:57 -070098
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -070099static void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -0700100{
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800101 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -0700102
103 if (hw_decrypt)
104 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
105 else
106 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
107
108}
109
Zhu Yib481de92007-09-25 17:54:57 -0700110/**
Mohamed Abbas54559702008-09-03 11:18:44 +0800111 * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
Ian Schram01ebd062007-10-25 17:15:22 +0800112 * @priv: staging_rxon is compared to active_rxon
Zhu Yib481de92007-09-25 17:54:57 -0700113 *
Ben Cahill9fbab512007-11-29 11:09:47 +0800114 * If the RXON structure is changing enough to require a new tune,
115 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
116 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
Zhu Yib481de92007-09-25 17:54:57 -0700117 */
Mohamed Abbas54559702008-09-03 11:18:44 +0800118static int iwl_full_rxon_required(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700119{
120
121 /* These items are only settable from the full RXON command */
Ron Rindjunsky5d1e2322008-06-30 17:23:04 +0800122 if (!(iwl_is_associated(priv)) ||
Zhu Yib481de92007-09-25 17:54:57 -0700123 compare_ether_addr(priv->staging_rxon.bssid_addr,
124 priv->active_rxon.bssid_addr) ||
125 compare_ether_addr(priv->staging_rxon.node_addr,
126 priv->active_rxon.node_addr) ||
127 compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
128 priv->active_rxon.wlap_bssid_addr) ||
129 (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
130 (priv->staging_rxon.channel != priv->active_rxon.channel) ||
131 (priv->staging_rxon.air_propagation !=
132 priv->active_rxon.air_propagation) ||
133 (priv->staging_rxon.ofdm_ht_single_stream_basic_rates !=
134 priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
135 (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
136 priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
Zhu Yib481de92007-09-25 17:54:57 -0700137 (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
138 return 1;
139
140 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
141 * be updated with the RXON_ASSOC command -- however only some
142 * flag transitions are allowed using RXON_ASSOC */
143
144 /* Check if we are not switching bands */
145 if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
146 (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
147 return 1;
148
149 /* Check if we are switching association toggle */
150 if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
151 (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
152 return 1;
153
154 return 0;
155}
156
Zhu Yib481de92007-09-25 17:54:57 -0700157/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700158 * iwl_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -0700159 *
Ian Schram01ebd062007-10-25 17:15:22 +0800160 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -0700161 * the active_rxon structure is updated with the new data. This
162 * function correctly transitions out of the RXON_ASSOC_MSK state if
163 * a HW tune is required based on the RXON structure changes.
164 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700165static int iwl_commit_rxon(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700166{
167 /* cast away the const for active_rxon in this function */
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800168 struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800169 int ret;
170 bool new_assoc =
171 !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK);
Zhu Yib481de92007-09-25 17:54:57 -0700172
Tomas Winklerfee12472008-04-03 16:05:21 -0700173 if (!iwl_is_alive(priv))
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800174 return -EBUSY;
Zhu Yib481de92007-09-25 17:54:57 -0700175
176 /* always get timestamp with Rx frame */
177 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
Emmanuel Grumbacha326a5d2008-07-11 11:53:31 +0800178 /* allow CTS-to-self if possible. this is relevant only for
179 * 5000, but will not damage 4965 */
180 priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN;
Zhu Yib481de92007-09-25 17:54:57 -0700181
Samuel Ortiza3139c52008-12-19 10:37:09 +0800182 ret = iwl_agn_check_rxon_cmd(priv);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800183 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800184 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700185 return -EINVAL;
186 }
187
188 /* If we don't need to send a full RXON, we can use
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700189 * iwl_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -0700190 * and other flags for the current radio configuration. */
Mohamed Abbas54559702008-09-03 11:18:44 +0800191 if (!iwl_full_rxon_required(priv)) {
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800192 ret = iwl_send_rxon_assoc(priv);
193 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800194 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800195 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700196 }
197
198 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700199 return 0;
200 }
201
202 /* station table will be cleared */
203 priv->assoc_station_added = 0;
204
Zhu Yib481de92007-09-25 17:54:57 -0700205 /* If we are currently associated and the new config requires
206 * an RXON_ASSOC and the new config wants the associated mask enabled,
207 * we must clear the associated from the active configuration
208 * before we apply the new config */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800209 if (iwl_is_associated(priv) && new_assoc) {
Zhu Yib481de92007-09-25 17:54:57 -0700210 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
211 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
212
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800213 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800214 sizeof(struct iwl_rxon_cmd),
Zhu Yib481de92007-09-25 17:54:57 -0700215 &priv->active_rxon);
216
217 /* If the mask clearing failed then we set
218 * active_rxon back to what it was previously */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800219 if (ret) {
Zhu Yib481de92007-09-25 17:54:57 -0700220 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
Winkler, Tomas15b16872008-12-19 10:37:33 +0800221 IWL_ERR(priv, "Error clearing ASSOC_MSK (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800222 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700223 }
Zhu Yib481de92007-09-25 17:54:57 -0700224 }
225
226 IWL_DEBUG_INFO("Sending RXON\n"
227 "* with%s RXON_FILTER_ASSOC_MSK\n"
228 "* channel = %d\n"
Johannes Berge1749612008-10-27 15:59:26 -0700229 "* bssid = %pM\n",
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800230 (new_assoc ? "" : "out"),
Zhu Yib481de92007-09-25 17:54:57 -0700231 le16_to_cpu(priv->staging_rxon.channel),
Johannes Berge1749612008-10-27 15:59:26 -0700232 priv->staging_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -0700233
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700234 iwl_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800235
236 /* Apply the new configuration
237 * RXON unassoc clears the station table in uCode, send it before
238 * we add the bcast station. If assoc bit is set, we will send RXON
239 * after having added the bcast and bssid station.
240 */
241 if (!new_assoc) {
242 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800243 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800244 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800245 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800246 return ret;
247 }
248 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700249 }
250
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +0800251 iwl_clear_stations_table(priv);
Zhu Yi556f8db2007-09-27 11:27:33 +0800252
Zhu Yib481de92007-09-25 17:54:57 -0700253 if (!priv->error_recovering)
254 priv->start_calib = 0;
255
Zhu Yib481de92007-09-25 17:54:57 -0700256 /* Add the broadcast address so we can send broadcast frames */
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800257 if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) ==
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800258 IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800259 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700260 return -EIO;
261 }
262
263 /* If we have set the ASSOC_MSK and we are in BSS mode then
264 * add the IWL_AP_ID to the station rate table */
Tomas Winkler91851592008-06-30 17:23:14 +0800265 if (new_assoc) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200266 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Tomas Winkler91851592008-06-30 17:23:14 +0800267 ret = iwl_rxon_add_station(priv,
268 priv->active_rxon.bssid_addr, 1);
269 if (ret == IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800270 IWL_ERR(priv,
271 "Error adding AP address for TX.\n");
Tomas Winkler91851592008-06-30 17:23:14 +0800272 return -EIO;
273 }
274 priv->assoc_station_added = 1;
275 if (priv->default_wep_key &&
276 iwl_send_static_wepkey_cmd(priv, 0))
Winkler, Tomas15b16872008-12-19 10:37:33 +0800277 IWL_ERR(priv,
278 "Could not send WEP static key.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700279 }
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800280
281 /* Apply the new configuration
282 * RXON assoc doesn't clear the station table in uCode,
283 */
284 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
285 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
286 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800287 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800288 return ret;
289 }
290 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700291 }
292
Zhu Yi36da7d72008-07-11 11:53:40 +0800293 iwl_init_sensitivity(priv);
294
295 /* If we issue a new RXON command which required a tune then we must
296 * send a new TXPOWER command or we won't be able to Tx any frames */
297 ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
298 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800299 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
Zhu Yi36da7d72008-07-11 11:53:40 +0800300 return ret;
301 }
302
Zhu Yib481de92007-09-25 17:54:57 -0700303 return 0;
304}
305
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700306void iwl_update_chain_flags(struct iwl_priv *priv)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700307{
308
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -0700309 iwl_set_rxon_chain(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700310 iwl_commit_rxon(priv);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700311}
312
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700313static int iwl_send_bt_config(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700314{
Tomas Winkler2aa6ab82008-12-11 10:33:40 -0800315 struct iwl_bt_cmd bt_cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700316 .flags = 3,
317 .lead_time = 0xAA,
318 .max_kill = 1,
319 .kill_ack_mask = 0,
320 .kill_cts_mask = 0,
321 };
322
Tomas Winkler857485c2008-03-21 13:53:44 -0700323 return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
Tomas Winkler2aa6ab82008-12-11 10:33:40 -0800324 sizeof(struct iwl_bt_cmd), &bt_cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700325}
326
Tomas Winklerfcab4232008-05-15 13:54:01 +0800327static void iwl_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700328{
329 struct list_head *element;
330
331 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
332 priv->frames_count);
333
334 while (!list_empty(&priv->free_frames)) {
335 element = priv->free_frames.next;
336 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800337 kfree(list_entry(element, struct iwl_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700338 priv->frames_count--;
339 }
340
341 if (priv->frames_count) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800342 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
Zhu Yib481de92007-09-25 17:54:57 -0700343 priv->frames_count);
344 priv->frames_count = 0;
345 }
346}
347
Tomas Winklerfcab4232008-05-15 13:54:01 +0800348static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700349{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800350 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700351 struct list_head *element;
352 if (list_empty(&priv->free_frames)) {
353 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
354 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800355 IWL_ERR(priv, "Could not allocate frame!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700356 return NULL;
357 }
358
359 priv->frames_count++;
360 return frame;
361 }
362
363 element = priv->free_frames.next;
364 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800365 return list_entry(element, struct iwl_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700366}
367
Tomas Winklerfcab4232008-05-15 13:54:01 +0800368static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700369{
370 memset(frame, 0, sizeof(*frame));
371 list_add(&frame->list, &priv->free_frames);
372}
373
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800374static unsigned int iwl_fill_beacon_frame(struct iwl_priv *priv,
375 struct ieee80211_hdr *hdr,
Rami Rosen73ec1cc2008-12-16 09:37:07 +0200376 int left)
Zhu Yib481de92007-09-25 17:54:57 -0700377{
Tomas Winkler3109ece2008-03-28 16:33:35 -0700378 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200379 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
380 (priv->iw_mode != NL80211_IFTYPE_AP)))
Zhu Yib481de92007-09-25 17:54:57 -0700381 return 0;
382
383 if (priv->ibss_beacon->len > left)
384 return 0;
385
386 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
387
388 return priv->ibss_beacon->len;
389}
390
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700391static u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700392{
Guy Cohen39e88502008-04-23 17:14:57 -0700393 int i;
394 int rate_mask;
Zhu Yib481de92007-09-25 17:54:57 -0700395
Guy Cohen39e88502008-04-23 17:14:57 -0700396 /* Set rate mask*/
397 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
Chatre, Reinettedbce56a2008-11-12 13:14:07 -0800398 rate_mask = priv->active_rate_basic & IWL_CCK_RATES_MASK;
Guy Cohen39e88502008-04-23 17:14:57 -0700399 else
Chatre, Reinettedbce56a2008-11-12 13:14:07 -0800400 rate_mask = priv->active_rate_basic & IWL_OFDM_RATES_MASK;
Guy Cohen39e88502008-04-23 17:14:57 -0700401
402 /* Find lowest valid rate */
Zhu Yib481de92007-09-25 17:54:57 -0700403 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800404 i = iwl_rates[i].next_ieee) {
Zhu Yib481de92007-09-25 17:54:57 -0700405 if (rate_mask & (1 << i))
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800406 return iwl_rates[i].plcp;
Zhu Yib481de92007-09-25 17:54:57 -0700407 }
408
Guy Cohen39e88502008-04-23 17:14:57 -0700409 /* No valid rate was found. Assign the lowest one */
410 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
411 return IWL_RATE_1M_PLCP;
412 else
413 return IWL_RATE_6M_PLCP;
Zhu Yib481de92007-09-25 17:54:57 -0700414}
415
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700416static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800417 struct iwl_frame *frame, u8 rate)
418{
419 struct iwl_tx_beacon_cmd *tx_beacon_cmd;
420 unsigned int frame_size;
421
422 tx_beacon_cmd = &frame->u.beacon;
423 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
424
425 tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
426 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
427
428 frame_size = iwl_fill_beacon_frame(priv, tx_beacon_cmd->frame,
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800429 sizeof(frame->u) - sizeof(*tx_beacon_cmd));
430
431 BUG_ON(frame_size > MAX_MPDU_SIZE);
432 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
433
434 if ((rate == IWL_RATE_1M_PLCP) || (rate >= IWL_RATE_2M_PLCP))
435 tx_beacon_cmd->tx.rate_n_flags =
436 iwl_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK);
437 else
438 tx_beacon_cmd->tx.rate_n_flags =
439 iwl_hw_set_rate_n_flags(rate, 0);
440
441 tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
442 TX_CMD_FLG_TSF_MSK |
443 TX_CMD_FLG_STA_RATE_MSK;
444
445 return sizeof(*tx_beacon_cmd) + frame_size;
446}
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700447static int iwl_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700448{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800449 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700450 unsigned int frame_size;
451 int rc;
452 u8 rate;
453
Tomas Winklerfcab4232008-05-15 13:54:01 +0800454 frame = iwl_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700455
456 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800457 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
Zhu Yib481de92007-09-25 17:54:57 -0700458 "command.\n");
459 return -ENOMEM;
460 }
461
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700462 rate = iwl_rate_get_lowest_plcp(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700463
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700464 frame_size = iwl_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -0700465
Tomas Winkler857485c2008-03-21 13:53:44 -0700466 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700467 &frame->u.cmd[0]);
468
Tomas Winklerfcab4232008-05-15 13:54:01 +0800469 iwl_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700470
471 return rc;
472}
473
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800474static inline dma_addr_t iwl_tfd_tb_get_addr(struct iwl_tfd *tfd, u8 idx)
475{
476 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
477
478 dma_addr_t addr = get_unaligned_le32(&tb->lo);
479 if (sizeof(dma_addr_t) > sizeof(u32))
480 addr |=
481 ((dma_addr_t)(le16_to_cpu(tb->hi_n_len) & 0xF) << 16) << 16;
482
483 return addr;
484}
485
486static inline u16 iwl_tfd_tb_get_len(struct iwl_tfd *tfd, u8 idx)
487{
488 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
489
490 return le16_to_cpu(tb->hi_n_len) >> 4;
491}
492
493static inline void iwl_tfd_set_tb(struct iwl_tfd *tfd, u8 idx,
494 dma_addr_t addr, u16 len)
495{
496 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
497 u16 hi_n_len = len << 4;
498
499 put_unaligned_le32(addr, &tb->lo);
500 if (sizeof(dma_addr_t) > sizeof(u32))
501 hi_n_len |= ((addr >> 16) >> 16) & 0xF;
502
503 tb->hi_n_len = cpu_to_le16(hi_n_len);
504
505 tfd->num_tbs = idx + 1;
506}
507
508static inline u8 iwl_tfd_get_num_tbs(struct iwl_tfd *tfd)
509{
510 return tfd->num_tbs & 0x1f;
511}
512
513/**
514 * iwl_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
515 * @priv - driver private data
516 * @txq - tx queue
517 *
518 * Does NOT advance any TFD circular buffer read/write indexes
519 * Does NOT free the TFD itself (which is within circular buffer)
520 */
521void iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq)
522{
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800523 struct iwl_tfd *tfd_tmp = (struct iwl_tfd *)txq->tfds;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800524 struct iwl_tfd *tfd;
525 struct pci_dev *dev = priv->pci_dev;
526 int index = txq->q.read_ptr;
527 int i;
528 int num_tbs;
529
530 tfd = &tfd_tmp[index];
531
532 /* Sanity check on number of chunks */
533 num_tbs = iwl_tfd_get_num_tbs(tfd);
534
535 if (num_tbs >= IWL_NUM_OF_TBS) {
536 IWL_ERR(priv, "Too many chunks: %i\n", num_tbs);
537 /* @todo issue fatal error, it is quite serious situation */
538 return;
539 }
540
541 /* Unmap tx_cmd */
542 if (num_tbs)
543 pci_unmap_single(dev,
544 pci_unmap_addr(&txq->cmd[index]->meta, mapping),
545 pci_unmap_len(&txq->cmd[index]->meta, len),
546 PCI_DMA_TODEVICE);
547
548 /* Unmap chunks, if any. */
549 for (i = 1; i < num_tbs; i++) {
550 pci_unmap_single(dev, iwl_tfd_tb_get_addr(tfd, i),
551 iwl_tfd_tb_get_len(tfd, i), PCI_DMA_TODEVICE);
552
553 if (txq->txb) {
554 dev_kfree_skb(txq->txb[txq->q.read_ptr].skb[i - 1]);
555 txq->txb[txq->q.read_ptr].skb[i - 1] = NULL;
556 }
557 }
558}
559
560int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv,
561 struct iwl_tx_queue *txq,
562 dma_addr_t addr, u16 len,
563 u8 reset, u8 pad)
564{
565 struct iwl_queue *q;
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800566 struct iwl_tfd *tfd, *tfd_tmp;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800567 u32 num_tbs;
568
569 q = &txq->q;
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800570 tfd_tmp = (struct iwl_tfd *)txq->tfds;
571 tfd = &tfd_tmp[q->write_ptr];
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800572
573 if (reset)
574 memset(tfd, 0, sizeof(*tfd));
575
576 num_tbs = iwl_tfd_get_num_tbs(tfd);
577
578 /* Each TFD can point to a maximum 20 Tx buffers */
579 if (num_tbs >= IWL_NUM_OF_TBS) {
580 IWL_ERR(priv, "Error can not send more than %d chunks\n",
581 IWL_NUM_OF_TBS);
582 return -EINVAL;
583 }
584
585 BUG_ON(addr & ~DMA_BIT_MASK(36));
586 if (unlikely(addr & ~IWL_TX_DMA_MASK))
587 IWL_ERR(priv, "Unaligned address = %llx\n",
588 (unsigned long long)addr);
589
590 iwl_tfd_set_tb(tfd, num_tbs, addr, len);
591
592 return 0;
593}
594
Zhu Yib481de92007-09-25 17:54:57 -0700595/******************************************************************************
596 *
Zhu Yib481de92007-09-25 17:54:57 -0700597 * Misc. internal state and helper functions
598 *
599 ******************************************************************************/
Zhu Yib481de92007-09-25 17:54:57 -0700600
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700601static void iwl_ht_conf(struct iwl_priv *priv,
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700602 struct ieee80211_bss_conf *bss_conf)
603{
Johannes Bergae5eb022008-10-14 16:58:37 +0200604 struct ieee80211_sta_ht_cap *ht_conf;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700605 struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
Johannes Bergae5eb022008-10-14 16:58:37 +0200606 struct ieee80211_sta *sta;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700607
608 IWL_DEBUG_MAC80211("enter: \n");
609
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700610 if (!iwl_conf->is_ht)
611 return;
612
Johannes Bergae5eb022008-10-14 16:58:37 +0200613
614 /*
615 * It is totally wrong to base global information on something
616 * that is valid only when associated, alas, this driver works
617 * that way and I don't know how to fix it.
618 */
619
620 rcu_read_lock();
621 sta = ieee80211_find_sta(priv->hw, priv->bssid);
622 if (!sta) {
623 rcu_read_unlock();
624 return;
625 }
626 ht_conf = &sta->ht_cap;
627
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700628 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
Emmanuel Grumbacha9841012008-05-15 13:54:08 +0800629 iwl_conf->sgf |= HT_SHORT_GI_20MHZ;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700630 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
Emmanuel Grumbacha9841012008-05-15 13:54:08 +0800631 iwl_conf->sgf |= HT_SHORT_GI_40MHZ;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700632
633 iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
634 iwl_conf->max_amsdu_size =
635 !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
636
637 iwl_conf->supported_chan_width =
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200638 !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40);
Johannes Bergae5eb022008-10-14 16:58:37 +0200639
Sujith094d05d2008-12-12 11:57:43 +0530640 /*
641 * XXX: The HT configuration needs to be moved into iwl_mac_config()
642 * to be done there correctly.
643 */
644
645 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
Luis R. Rodriguezde27e642008-12-23 15:58:44 -0800646 if (conf_is_ht40_minus(&priv->hw->conf))
Sujith094d05d2008-12-12 11:57:43 +0530647 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
Luis R. Rodriguezde27e642008-12-23 15:58:44 -0800648 else if (conf_is_ht40_plus(&priv->hw->conf))
Sujith094d05d2008-12-12 11:57:43 +0530649 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
650
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700651 /* If no above or below channel supplied disable FAT channel */
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200652 if (iwl_conf->extension_chan_offset != IEEE80211_HT_PARAM_CHA_SEC_ABOVE &&
Sujith094d05d2008-12-12 11:57:43 +0530653 iwl_conf->extension_chan_offset != IEEE80211_HT_PARAM_CHA_SEC_BELOW)
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700654 iwl_conf->supported_chan_width = 0;
655
Ron Rindjunsky12837be2008-09-03 11:26:47 +0800656 iwl_conf->sm_ps = (u8)((ht_conf->cap & IEEE80211_HT_CAP_SM_PS) >> 2);
657
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200658 memcpy(&iwl_conf->mcs, &ht_conf->mcs, 16);
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700659
Sujith094d05d2008-12-12 11:57:43 +0530660 iwl_conf->tx_chan_width = iwl_conf->supported_chan_width != 0;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700661 iwl_conf->ht_protection =
Johannes Bergae5eb022008-10-14 16:58:37 +0200662 bss_conf->ht.operation_mode & IEEE80211_HT_OP_MODE_PROTECTION;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700663 iwl_conf->non_GF_STA_present =
Johannes Bergae5eb022008-10-14 16:58:37 +0200664 !!(bss_conf->ht.operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700665
Johannes Bergae5eb022008-10-14 16:58:37 +0200666 rcu_read_unlock();
667
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700668 IWL_DEBUG_MAC80211("leave\n");
669}
670
Zhu Yib481de92007-09-25 17:54:57 -0700671/*
672 * QoS support
673*/
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +0800674static void iwl_activate_qos(struct iwl_priv *priv, u8 force)
Zhu Yib481de92007-09-25 17:54:57 -0700675{
Zhu Yib481de92007-09-25 17:54:57 -0700676 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
677 return;
678
Zhu Yib481de92007-09-25 17:54:57 -0700679 priv->qos_data.def_qos_parm.qos_flags = 0;
680
681 if (priv->qos_data.qos_cap.q_AP.queue_request &&
682 !priv->qos_data.qos_cap.q_AP.txop_request)
683 priv->qos_data.def_qos_parm.qos_flags |=
684 QOS_PARAM_FLG_TXOP_TYPE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700685 if (priv->qos_data.qos_active)
686 priv->qos_data.def_qos_parm.qos_flags |=
687 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
688
Ron Rindjunskyfd105e72007-11-26 16:14:39 +0200689 if (priv->current_ht_config.is_ht)
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800690 priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800691
Tomas Winkler3109ece2008-03-28 16:33:35 -0700692 if (force || iwl_is_associated(priv)) {
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800693 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
694 priv->qos_data.qos_active,
695 priv->qos_data.def_qos_parm.qos_flags);
Zhu Yib481de92007-09-25 17:54:57 -0700696
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +0800697 iwl_send_cmd_pdu_async(priv, REPLY_QOS_PARAM,
698 sizeof(struct iwl_qosparam_cmd),
699 &priv->qos_data.def_qos_parm, NULL);
Zhu Yib481de92007-09-25 17:54:57 -0700700 }
701}
702
Zhu Yib481de92007-09-25 17:54:57 -0700703#define MAX_UCODE_BEACON_INTERVAL 4096
Zhu Yib481de92007-09-25 17:54:57 -0700704
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800705static u16 iwl_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -0700706{
707 u16 new_val = 0;
708 u16 beacon_factor = 0;
709
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800710 beacon_factor = (beacon_val + MAX_UCODE_BEACON_INTERVAL)
711 / MAX_UCODE_BEACON_INTERVAL;
Zhu Yib481de92007-09-25 17:54:57 -0700712 new_val = beacon_val / beacon_factor;
713
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800714 return new_val;
Zhu Yib481de92007-09-25 17:54:57 -0700715}
716
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800717static void iwl_setup_rxon_timing(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700718{
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800719 u64 tsf;
720 s32 interval_tm, rem;
Zhu Yib481de92007-09-25 17:54:57 -0700721 unsigned long flags;
722 struct ieee80211_conf *conf = NULL;
723 u16 beacon_int = 0;
724
725 conf = ieee80211_get_hw_conf(priv->hw);
726
727 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800728 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
Tomas Winklerb5d7be52008-07-19 04:41:24 +0300729 priv->rxon_timing.listen_interval = cpu_to_le16(conf->listen_interval);
Zhu Yib481de92007-09-25 17:54:57 -0700730
Johannes Berg05c914f2008-09-11 00:01:58 +0200731 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800732 beacon_int = iwl_adjust_beacon_interval(priv->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -0700733 priv->rxon_timing.atim_window = 0;
734 } else {
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800735 beacon_int = iwl_adjust_beacon_interval(conf->beacon_int);
736
Zhu Yib481de92007-09-25 17:54:57 -0700737 /* TODO: we need to get atim_window from upper stack
738 * for now we set to 0 */
739 priv->rxon_timing.atim_window = 0;
740 }
741
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800742 priv->rxon_timing.beacon_interval = cpu_to_le16(beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -0700743
Tomas Winkler3195c1f2008-10-08 09:37:30 +0800744 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
745 interval_tm = beacon_int * 1024;
746 rem = do_div(tsf, interval_tm);
747 priv->rxon_timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
748
749 spin_unlock_irqrestore(&priv->lock, flags);
750 IWL_DEBUG_ASSOC("beacon interval %d beacon timer %d beacon tim %d\n",
751 le16_to_cpu(priv->rxon_timing.beacon_interval),
752 le32_to_cpu(priv->rxon_timing.beacon_init_val),
753 le16_to_cpu(priv->rxon_timing.atim_window));
Zhu Yib481de92007-09-25 17:54:57 -0700754}
755
Tomas Winkler82a66bb2008-05-29 16:35:28 +0800756static void iwl_set_flags_for_band(struct iwl_priv *priv,
757 enum ieee80211_band band)
Zhu Yib481de92007-09-25 17:54:57 -0700758{
Johannes Berg8318d782008-01-24 19:38:38 +0100759 if (band == IEEE80211_BAND_5GHZ) {
Zhu Yib481de92007-09-25 17:54:57 -0700760 priv->staging_rxon.flags &=
761 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
762 | RXON_FLG_CCK_MSK);
763 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
764 } else {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700765 /* Copied from iwl_post_associate() */
Zhu Yib481de92007-09-25 17:54:57 -0700766 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
767 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
768 else
769 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
770
Johannes Berg05c914f2008-09-11 00:01:58 +0200771 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -0700772 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
773
774 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
775 priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
776 priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
777 }
778}
779
780/*
Ian Schram01ebd062007-10-25 17:15:22 +0800781 * initialize rxon structure with default values from eeprom
Zhu Yib481de92007-09-25 17:54:57 -0700782 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700783static void iwl_connection_init_rx_config(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700784{
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700785 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -0700786
787 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
788
Zhu, Yi60294de2008-10-29 14:05:45 -0700789 switch (mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200790 case NL80211_IFTYPE_AP:
Zhu Yib481de92007-09-25 17:54:57 -0700791 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
792 break;
793
Johannes Berg05c914f2008-09-11 00:01:58 +0200794 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -0700795 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
796 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
797 break;
798
Johannes Berg05c914f2008-09-11 00:01:58 +0200799 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -0700800 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
801 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
802 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
803 RXON_FILTER_ACCEPT_GRP_MSK;
804 break;
805
Johannes Berg05c914f2008-09-11 00:01:58 +0200806 case NL80211_IFTYPE_MONITOR:
Zhu Yib481de92007-09-25 17:54:57 -0700807 priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
808 priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
809 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
810 break;
Tomas Winkler69dc5d92008-03-25 16:33:41 -0700811 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +0800812 IWL_ERR(priv, "Unsupported interface type %d\n", mode);
Tomas Winkler69dc5d92008-03-25 16:33:41 -0700813 break;
Zhu Yib481de92007-09-25 17:54:57 -0700814 }
815
816#if 0
817 /* TODO: Figure out when short_preamble would be set and cache from
818 * that */
819 if (!hw_to_local(priv->hw)->short_preamble)
820 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
821 else
822 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
823#endif
824
Assaf Krauss8622e702008-03-21 13:53:43 -0700825 ch_info = iwl_get_channel_info(priv, priv->band,
Rick Farrington25b3f572008-06-30 17:23:28 +0800826 le16_to_cpu(priv->active_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700827
828 if (!ch_info)
829 ch_info = &priv->channel_info[0];
830
831 /*
832 * in some case A channels are all non IBSS
833 * in this case force B/G channel
834 */
Johannes Berg05c914f2008-09-11 00:01:58 +0200835 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
Zhu Yib481de92007-09-25 17:54:57 -0700836 !(is_channel_ibss(ch_info)))
837 ch_info = &priv->channel_info[0];
838
839 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
Johannes Berg8318d782008-01-24 19:38:38 +0100840 priv->band = ch_info->band;
Zhu Yib481de92007-09-25 17:54:57 -0700841
Tomas Winkler82a66bb2008-05-29 16:35:28 +0800842 iwl_set_flags_for_band(priv, priv->band);
Zhu Yib481de92007-09-25 17:54:57 -0700843
844 priv->staging_rxon.ofdm_basic_rates =
845 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
846 priv->staging_rxon.cck_basic_rates =
847 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
848
849 priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
850 RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
851 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
852 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
853 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
854 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -0700855 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700856}
857
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700858static int iwl_set_mode(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700859{
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700860 iwl_connection_init_rx_config(priv, mode);
Zhu Yib481de92007-09-25 17:54:57 -0700861 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
862
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +0800863 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700864
Mohamed Abbasfde35712007-11-29 11:10:15 +0800865 /* dont commit rxon if rf-kill is on*/
Tomas Winklerfee12472008-04-03 16:05:21 -0700866 if (!iwl_is_ready_rf(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +0800867 return -EAGAIN;
868
869 cancel_delayed_work(&priv->scan_check);
Tomas Winkler2a421b92008-06-12 09:47:10 +0800870 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800871 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +0800872 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
873 return -EAGAIN;
874 }
875
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700876 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700877
878 return 0;
879}
880
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700881static void iwl_set_rate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700882{
Johannes Berg8318d782008-01-24 19:38:38 +0100883 const struct ieee80211_supported_band *hw = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700884 struct ieee80211_rate *rate;
885 int i;
886
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700887 hw = iwl_get_hw_mode(priv, priv->band);
Saleem Abdulrasoolc4ba9622007-11-18 23:59:08 -0800888 if (!hw) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800889 IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
Saleem Abdulrasoolc4ba9622007-11-18 23:59:08 -0800890 return;
891 }
Zhu Yib481de92007-09-25 17:54:57 -0700892
893 priv->active_rate = 0;
894 priv->active_rate_basic = 0;
895
Johannes Berg8318d782008-01-24 19:38:38 +0100896 for (i = 0; i < hw->n_bitrates; i++) {
897 rate = &(hw->bitrates[i]);
898 if (rate->hw_value < IWL_RATE_COUNT)
899 priv->active_rate |= (1 << rate->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -0700900 }
901
902 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
903 priv->active_rate, priv->active_rate_basic);
904
905 /*
906 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
907 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
908 * OFDM
909 */
910 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
911 priv->staging_rxon.cck_basic_rates =
912 ((priv->active_rate_basic &
913 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
914 else
915 priv->staging_rxon.cck_basic_rates =
916 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
917
918 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
919 priv->staging_rxon.ofdm_basic_rates =
920 ((priv->active_rate_basic &
921 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
922 IWL_FIRST_OFDM_RATE) & 0xFF;
923 else
924 priv->staging_rxon.ofdm_basic_rates =
925 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
926}
927
Zhu Yib481de92007-09-25 17:54:57 -0700928
Zhu Yib481de92007-09-25 17:54:57 -0700929/******************************************************************************
930 *
931 * Generic RX handler implementations
932 *
933 ******************************************************************************/
Tomas Winkler885ba202008-05-29 16:34:55 +0800934static void iwl_rx_reply_alive(struct iwl_priv *priv,
935 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700936{
Tomas Winklerdb11d632008-05-05 10:22:33 +0800937 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Tomas Winkler885ba202008-05-29 16:34:55 +0800938 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -0700939 struct delayed_work *pwork;
940
941 palive = &pkt->u.alive_frame;
942
943 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
944 "0x%01X 0x%01X\n",
945 palive->is_valid, palive->ver_type,
946 palive->ver_subtype);
947
948 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
949 IWL_DEBUG_INFO("Initialization Alive received.\n");
950 memcpy(&priv->card_alive_init,
951 &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +0800952 sizeof(struct iwl_init_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700953 pwork = &priv->init_alive_start;
954 } else {
955 IWL_DEBUG_INFO("Runtime Alive received.\n");
956 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +0800957 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700958 pwork = &priv->alive_start;
959 }
960
961 /* We delay the ALIVE response by 5ms to
962 * give the HW RF Kill time to activate... */
963 if (palive->is_valid == UCODE_VALID_OK)
964 queue_delayed_work(priv->workqueue, pwork,
965 msecs_to_jiffies(5));
966 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800967 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700968}
969
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700970static void iwl_rx_reply_error(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +0800971 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700972{
Tomas Winklerdb11d632008-05-05 10:22:33 +0800973 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700974
Winkler, Tomas15b16872008-12-19 10:37:33 +0800975 IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
Zhu Yib481de92007-09-25 17:54:57 -0700976 "seq 0x%04X ser 0x%08X\n",
977 le32_to_cpu(pkt->u.err_resp.error_type),
978 get_cmd_string(pkt->u.err_resp.cmd_id),
979 pkt->u.err_resp.cmd_id,
980 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
981 le32_to_cpu(pkt->u.err_resp.error_info));
982}
983
984#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
985
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700986static void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700987{
Tomas Winklerdb11d632008-05-05 10:22:33 +0800988 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800989 struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
Tomas Winkler2aa6ab82008-12-11 10:33:40 -0800990 struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
Zhu Yib481de92007-09-25 17:54:57 -0700991 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
992 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
993 rxon->channel = csa->channel;
994 priv->staging_rxon.channel = csa->channel;
995}
996
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700997static void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +0800998 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700999{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001000#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklerdb11d632008-05-05 10:22:33 +08001001 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Tomas Winkler2aa6ab82008-12-11 10:33:40 -08001002 struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001003 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
1004 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
1005#endif
1006}
1007
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001008static void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001009 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001010{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001011 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001012 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
1013 "notification for %s:\n",
1014 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
Ester Kummerbf403db2008-05-05 10:22:40 +08001015 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
Zhu Yib481de92007-09-25 17:54:57 -07001016}
1017
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001018static void iwl_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07001019{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001020 struct iwl_priv *priv =
1021 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07001022 struct sk_buff *beacon;
1023
1024 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02001025 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07001026
1027 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001028 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07001029 return;
1030 }
1031
1032 mutex_lock(&priv->mutex);
1033 /* new beacon skb is allocated every time; dispose previous.*/
1034 if (priv->ibss_beacon)
1035 dev_kfree_skb(priv->ibss_beacon);
1036
1037 priv->ibss_beacon = beacon;
1038 mutex_unlock(&priv->mutex);
1039
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001040 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001041}
1042
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001043/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001044 * iwl_bg_statistics_periodic - Timer callback to queue statistics
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001045 *
1046 * This callback is provided in order to send a statistics request.
1047 *
1048 * This timer function is continually reset to execute within
1049 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
1050 * was received. We need to ensure we receive the statistics in order
1051 * to update the temperature used for calibrating the TXPOWER.
1052 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001053static void iwl_bg_statistics_periodic(unsigned long data)
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001054{
1055 struct iwl_priv *priv = (struct iwl_priv *)data;
1056
1057 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1058 return;
1059
Mohamed Abbas61780ee2008-10-29 14:05:49 -07001060 /* dont send host command if rf-kill is on */
1061 if (!iwl_is_ready_rf(priv))
1062 return;
1063
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001064 iwl_send_statistics_request(priv, CMD_ASYNC);
1065}
1066
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001067static void iwl_rx_beacon_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001068 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001069{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001070#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklerdb11d632008-05-05 10:22:33 +08001071 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Tomas Winkler2aa6ab82008-12-11 10:33:40 -08001072 struct iwl4965_beacon_notif *beacon =
1073 (struct iwl4965_beacon_notif *)pkt->u.raw;
Tomas Winklere7d326a2008-06-12 09:47:11 +08001074 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -07001075
1076 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
1077 "tsf %d %d rate %d\n",
Tomas Winkler25a65722008-06-12 09:47:07 +08001078 le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
Zhu Yib481de92007-09-25 17:54:57 -07001079 beacon->beacon_notify_hdr.failure_frame,
1080 le32_to_cpu(beacon->ibss_mgr_status),
1081 le32_to_cpu(beacon->high_tsf),
1082 le32_to_cpu(beacon->low_tsf), rate);
1083#endif
1084
Johannes Berg05c914f2008-09-11 00:01:58 +02001085 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -07001086 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1087 queue_work(priv->workqueue, &priv->beacon_update);
1088}
1089
Zhu Yib481de92007-09-25 17:54:57 -07001090/* Handle notification from uCode that card's power state is changing
1091 * due to software, hardware, or critical temperature RFKILL */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001092static void iwl_rx_card_state_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001093 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001094{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001095 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001096 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1097 unsigned long status = priv->status;
1098
1099 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
1100 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1101 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1102
1103 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
1104 RF_CARD_DISABLED)) {
1105
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001106 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001107 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1108
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001109 if (!iwl_grab_nic_access(priv)) {
1110 iwl_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07001111 priv, HBUS_TARG_MBX_C,
1112 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
1113
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001114 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001115 }
1116
1117 if (!(flags & RXON_CARD_DISABLED)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001118 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07001119 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001120 if (!iwl_grab_nic_access(priv)) {
1121 iwl_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07001122 priv, HBUS_TARG_MBX_C,
1123 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
1124
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001125 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001126 }
1127 }
1128
1129 if (flags & RF_CARD_DISABLED) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001130 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001131 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001132 iwl_read32(priv, CSR_UCODE_DRV_GP1);
1133 if (!iwl_grab_nic_access(priv))
1134 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001135 }
1136 }
1137
1138 if (flags & HW_CARD_DISABLED)
1139 set_bit(STATUS_RF_KILL_HW, &priv->status);
1140 else
1141 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1142
1143
1144 if (flags & SW_CARD_DISABLED)
1145 set_bit(STATUS_RF_KILL_SW, &priv->status);
1146 else
1147 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1148
1149 if (!(flags & RXON_CARD_DISABLED))
Tomas Winkler2a421b92008-06-12 09:47:10 +08001150 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001151
1152 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1153 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1154 (test_bit(STATUS_RF_KILL_SW, &status) !=
1155 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1156 queue_work(priv->workqueue, &priv->rf_kill);
1157 else
1158 wake_up_interruptible(&priv->wait_command_queue);
1159}
1160
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001161int iwl_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
Tomas Winklere2e3c572008-07-18 13:53:04 +08001162{
1163 int ret;
1164 unsigned long flags;
1165
1166 spin_lock_irqsave(&priv->lock, flags);
1167 ret = iwl_grab_nic_access(priv);
1168 if (ret)
1169 goto err;
1170
1171 if (src == IWL_PWR_SRC_VAUX) {
1172 u32 val;
Tomas Winklere7b63582008-09-03 11:26:49 +08001173 ret = pci_read_config_dword(priv->pci_dev, PCI_CFG_POWER_SOURCE,
Tomas Winklere2e3c572008-07-18 13:53:04 +08001174 &val);
1175
1176 if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT)
1177 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
1178 APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
1179 ~APMG_PS_CTRL_MSK_PWR_SRC);
1180 } else {
1181 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
1182 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
1183 ~APMG_PS_CTRL_MSK_PWR_SRC);
1184 }
1185
1186 iwl_release_nic_access(priv);
1187err:
1188 spin_unlock_irqrestore(&priv->lock, flags);
1189 return ret;
1190}
1191
Zhu Yib481de92007-09-25 17:54:57 -07001192/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001193 * iwl_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07001194 *
1195 * Setup the RX handlers for each of the reply types sent from the uCode
1196 * to the host.
1197 *
1198 * This function chains into the hardware specific files for them to setup
1199 * any hardware specific handlers as well.
1200 */
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08001201static void iwl_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001202{
Tomas Winkler885ba202008-05-29 16:34:55 +08001203 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001204 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
1205 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001206 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001207 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001208 iwl_rx_pm_debug_statistics_notif;
1209 priv->rx_handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001210
Ben Cahill9fbab512007-11-29 11:09:47 +08001211 /*
1212 * The same handler is used for both the REPLY to a discrete
1213 * statistics request from the host as well as for the periodic
1214 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07001215 */
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08001216 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_rx_statistics;
1217 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
Tomas Winkler2a421b92008-06-12 09:47:10 +08001218
Tomas Winkler21c339b2008-11-07 09:58:41 -08001219 iwl_setup_spectrum_handlers(priv);
Tomas Winkler2a421b92008-06-12 09:47:10 +08001220 iwl_setup_rx_scan_handlers(priv);
1221
Ron Rindjunsky37a44212008-05-29 16:35:18 +08001222 /* status change handler */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001223 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001224
Tomas Winklerc1354752008-05-29 16:35:04 +08001225 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
1226 iwl_rx_missed_beacon_notif;
Ron Rindjunsky37a44212008-05-29 16:35:18 +08001227 /* Rx handlers */
Emmanuel Grumbach1781a072008-06-30 17:23:09 +08001228 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl_rx_reply_rx_phy;
1229 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl_rx_reply_rx;
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08001230 /* block ack */
1231 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl_rx_reply_compressed_ba;
Ben Cahill9fbab512007-11-29 11:09:47 +08001232 /* Set up hardware specific Rx handlers */
Emmanuel Grumbachd4789ef2008-04-24 11:55:20 -07001233 priv->cfg->ops->lib->rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001234}
1235
Zhu Yib481de92007-09-25 17:54:57 -07001236/**
Tomas Winklera55360e2008-05-05 10:22:28 +08001237 * iwl_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001238 *
1239 * Uses the priv->rx_handlers callback function array to invoke
1240 * the appropriate handlers, including command responses,
1241 * frame-received notifications, and other notifications.
1242 */
Tomas Winklera55360e2008-05-05 10:22:28 +08001243void iwl_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001244{
Tomas Winklera55360e2008-05-05 10:22:28 +08001245 struct iwl_rx_mem_buffer *rxb;
Tomas Winklerdb11d632008-05-05 10:22:33 +08001246 struct iwl_rx_packet *pkt;
Tomas Winklera55360e2008-05-05 10:22:28 +08001247 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001248 u32 r, i;
1249 int reclaim;
1250 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001251 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001252 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07001253
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001254 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1255 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8d864222008-11-07 09:58:39 -08001256 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07001257 i = rxq->read;
1258
1259 /* Rx interrupt, but nothing sent from uCode */
1260 if (i == r)
Ester Kummerf3d67992008-05-06 11:05:12 +08001261 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001262
Tomas Winklera55360e2008-05-05 10:22:28 +08001263 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001264 fill_rx = 1;
1265
Zhu Yib481de92007-09-25 17:54:57 -07001266 while (i != r) {
1267 rxb = rxq->queue[i];
1268
Ben Cahill9fbab512007-11-29 11:09:47 +08001269 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001270 * then a bug has been introduced in the queue refilling
1271 * routines -- catch it here */
1272 BUG_ON(rxb == NULL);
1273
1274 rxq->queue[i] = NULL;
1275
Johannes Berge91af0a2008-11-19 01:22:51 +01001276 dma_sync_single_range_for_cpu(
1277 &priv->pci_dev->dev, rxb->real_dma_addr,
1278 rxb->aligned_dma_addr - rxb->real_dma_addr,
1279 priv->hw_params.rx_buf_size,
1280 PCI_DMA_FROMDEVICE);
Tomas Winklerdb11d632008-05-05 10:22:33 +08001281 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001282
1283 /* Reclaim a command buffer only if this packet is a response
1284 * to a (driver-originated) command.
1285 * If the packet (e.g. Rx frame) originated from uCode,
1286 * there is no command buffer to reclaim.
1287 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1288 * but apparently a few don't get set; catch them here. */
1289 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1290 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
Tomas Winkler857485c2008-03-21 13:53:44 -07001291 (pkt->hdr.cmd != REPLY_RX) &&
Daniel Halperin7dddaf12008-10-23 23:48:58 -07001292 (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) &&
Zhu Yicfe01702007-09-27 11:27:31 +08001293 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
Zhu Yib481de92007-09-25 17:54:57 -07001294 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1295 (pkt->hdr.cmd != REPLY_TX);
1296
1297 /* Based on type of command response or notification,
1298 * handle those that need handling via function in
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001299 * rx_handlers table. See iwl_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001300 if (priv->rx_handlers[pkt->hdr.cmd]) {
Ester Kummerf3d67992008-05-06 11:05:12 +08001301 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r,
1302 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001303 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1304 } else {
1305 /* No handling needed */
Ester Kummerf3d67992008-05-06 11:05:12 +08001306 IWL_DEBUG(IWL_DL_RX,
Zhu Yib481de92007-09-25 17:54:57 -07001307 "r %d i %d No handler needed for %s, 0x%02x\n",
1308 r, i, get_cmd_string(pkt->hdr.cmd),
1309 pkt->hdr.cmd);
1310 }
1311
1312 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001313 /* Invoke any callbacks, transfer the skb to caller, and
Tomas Winkler857485c2008-03-21 13:53:44 -07001314 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001315 * as we reclaim the driver command queue */
1316 if (rxb && rxb->skb)
Tomas Winkler17b88922008-05-29 16:35:12 +08001317 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001318 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001319 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07001320 }
1321
1322 /* For now we just don't re-use anything. We can tweak this
1323 * later to try and re-use notification packets and SKBs that
1324 * fail to Rx correctly */
1325 if (rxb->skb != NULL) {
1326 priv->alloc_rxb_skb--;
1327 dev_kfree_skb_any(rxb->skb);
1328 rxb->skb = NULL;
1329 }
1330
Johannes Berg40185172008-11-18 01:47:21 +01001331 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
1332 priv->hw_params.rx_buf_size + 256,
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02001333 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001334 spin_lock_irqsave(&rxq->lock, flags);
1335 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1336 spin_unlock_irqrestore(&rxq->lock, flags);
1337 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001338 /* If there are a lot of unused frames,
1339 * restock the Rx queue so ucode wont assert. */
1340 if (fill_rx) {
1341 count++;
1342 if (count >= 8) {
1343 priv->rxq.read = i;
Zhu Yif1bc4ac2008-12-17 16:52:33 +08001344 iwl_rx_queue_restock(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001345 count = 0;
1346 }
1347 }
Zhu Yib481de92007-09-25 17:54:57 -07001348 }
1349
1350 /* Backtrack one entry */
1351 priv->rxq.read = i;
Tomas Winklera55360e2008-05-05 10:22:28 +08001352 iwl_rx_queue_restock(priv);
1353}
Tomas Winklera55360e2008-05-05 10:22:28 +08001354
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001355#ifdef CONFIG_IWLWIFI_DEBUG
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001356static void iwl_print_rx_config_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001357{
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001358 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
Joe Perches0795af52007-10-03 17:59:30 -07001359
Zhu Yib481de92007-09-25 17:54:57 -07001360 IWL_DEBUG_RADIO("RX CONFIG:\n");
Ester Kummerbf403db2008-05-05 10:22:40 +08001361 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
Zhu Yib481de92007-09-25 17:54:57 -07001362 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
1363 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
1364 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
1365 le32_to_cpu(rxon->filter_flags));
1366 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
1367 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
1368 rxon->ofdm_basic_rates);
1369 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
Johannes Berge1749612008-10-27 15:59:26 -07001370 IWL_DEBUG_RADIO("u8[6] node_addr: %pM\n", rxon->node_addr);
1371 IWL_DEBUG_RADIO("u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07001372 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
1373}
1374#endif
1375
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001376/* call this function to flush any scheduled tasklet */
1377static inline void iwl_synchronize_irq(struct iwl_priv *priv)
1378{
Tomas Winklera96a27f2008-10-23 23:48:56 -07001379 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001380 synchronize_irq(priv->pci_dev->irq);
1381 tasklet_kill(&priv->irq_tasklet);
1382}
1383
Zhu Yib481de92007-09-25 17:54:57 -07001384/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001385 * iwl_irq_handle_error - called for HW or SW error interrupt from card
Zhu Yib481de92007-09-25 17:54:57 -07001386 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001387static void iwl_irq_handle_error(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001388{
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001389 /* Set the FW error flag -- cleared on iwl_down */
Zhu Yib481de92007-09-25 17:54:57 -07001390 set_bit(STATUS_FW_ERROR, &priv->status);
1391
1392 /* Cancel currently queued command. */
1393 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1394
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001395#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001396 if (priv->debug_level & IWL_DL_FW_ERRORS) {
Ester Kummerede0cba2008-05-29 16:34:46 +08001397 iwl_dump_nic_error_log(priv);
Ester Kummer189a2b52008-05-15 13:54:18 +08001398 iwl_dump_nic_event_log(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001399 iwl_print_rx_config_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001400 }
1401#endif
1402
1403 wake_up_interruptible(&priv->wait_command_queue);
1404
1405 /* Keep the restart process from trying to send host
1406 * commands by clearing the INIT status bit */
1407 clear_bit(STATUS_READY, &priv->status);
1408
1409 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Ester Kummerf3d67992008-05-06 11:05:12 +08001410 IWL_DEBUG(IWL_DL_FW_ERRORS,
Zhu Yib481de92007-09-25 17:54:57 -07001411 "Restarting adapter due to uCode error.\n");
1412
Tomas Winkler3109ece2008-03-28 16:33:35 -07001413 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001414 memcpy(&priv->recovery_rxon, &priv->active_rxon,
1415 sizeof(priv->recovery_rxon));
1416 priv->error_recovering = 1;
1417 }
Ester Kummer3a1081e2008-05-06 11:05:14 +08001418 if (priv->cfg->mod_params->restart_fw)
1419 queue_work(priv->workqueue, &priv->restart);
Zhu Yib481de92007-09-25 17:54:57 -07001420 }
1421}
1422
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001423static void iwl_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001424{
1425 unsigned long flags;
1426
1427 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
1428 sizeof(priv->staging_rxon));
1429 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001430 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001431
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08001432 iwl_rxon_add_station(priv, priv->bssid, 1);
Zhu Yib481de92007-09-25 17:54:57 -07001433
1434 spin_lock_irqsave(&priv->lock, flags);
1435 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
1436 priv->error_recovering = 0;
1437 spin_unlock_irqrestore(&priv->lock, flags);
1438}
1439
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001440static void iwl_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001441{
1442 u32 inta, handled = 0;
1443 u32 inta_fh;
1444 unsigned long flags;
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001445#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001446 u32 inta_mask;
1447#endif
1448
1449 spin_lock_irqsave(&priv->lock, flags);
1450
1451 /* Ack/clear/reset pending uCode interrupts.
1452 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1453 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001454 inta = iwl_read32(priv, CSR_INT);
1455 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07001456
1457 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1458 * Any new interrupts that happen after this, either while we're
1459 * in this tasklet, or later, will show up in next ISR/tasklet. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001460 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1461 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001462
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001463#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001464 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001465 /* just for debug */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001466 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07001467 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1468 inta, inta_mask, inta_fh);
1469 }
1470#endif
1471
1472 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1473 * atomic, make sure that inta covers all the interrupts that
1474 * we've discovered, even if FH interrupt came in just after
1475 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001476 if (inta_fh & CSR49_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001477 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001478 if (inta_fh & CSR49_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001479 inta |= CSR_INT_BIT_FH_TX;
1480
1481 /* Now service all interrupt bits discovered above. */
1482 if (inta & CSR_INT_BIT_HW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001483 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001484
1485 /* Tell the device to stop sending interrupts */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001486 iwl_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001487
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001488 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001489
1490 handled |= CSR_INT_BIT_HW_ERR;
1491
1492 spin_unlock_irqrestore(&priv->lock, flags);
1493
1494 return;
1495 }
1496
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001497#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001498 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07001499 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001500 if (inta & CSR_INT_BIT_SCD)
1501 IWL_DEBUG_ISR("Scheduler finished to transmit "
1502 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001503
1504 /* Alive notification via Rx interrupt will do the real work */
1505 if (inta & CSR_INT_BIT_ALIVE)
1506 IWL_DEBUG_ISR("Alive interrupt\n");
1507 }
1508#endif
1509 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001510 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07001511
Ben Cahill9fbab512007-11-29 11:09:47 +08001512 /* HW RF KILL switch toggled */
Zhu Yib481de92007-09-25 17:54:57 -07001513 if (inta & CSR_INT_BIT_RF_KILL) {
1514 int hw_rf_kill = 0;
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001515 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yib481de92007-09-25 17:54:57 -07001516 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
1517 hw_rf_kill = 1;
1518
Ester Kummerf3d67992008-05-06 11:05:12 +08001519 IWL_DEBUG(IWL_DL_RF_KILL, "RF_KILL bit toggled to %s.\n",
Abhijeet Kolekarc3056062008-11-12 13:14:08 -08001520 hw_rf_kill ? "disable radio" : "enable radio");
Zhu Yib481de92007-09-25 17:54:57 -07001521
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +08001522 /* driver only loads ucode once setting the interface up.
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01001523 * the driver allows loading the ucode even if the radio
1524 * is killed. Hence update the killswitch state here. The
1525 * rfkill handler will care about restarting if needed.
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +08001526 */
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01001527 if (!test_bit(STATUS_ALIVE, &priv->status)) {
1528 if (hw_rf_kill)
1529 set_bit(STATUS_RF_KILL_HW, &priv->status);
1530 else
1531 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1532 queue_work(priv->workqueue, &priv->rf_kill);
Mohamed Abbasedb34222008-12-11 10:33:37 -08001533 }
Zhu Yib481de92007-09-25 17:54:57 -07001534
1535 handled |= CSR_INT_BIT_RF_KILL;
1536 }
1537
Ben Cahill9fbab512007-11-29 11:09:47 +08001538 /* Chip got too hot and stopped itself */
Zhu Yib481de92007-09-25 17:54:57 -07001539 if (inta & CSR_INT_BIT_CT_KILL) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001540 IWL_ERR(priv, "Microcode CT kill error detected.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001541 handled |= CSR_INT_BIT_CT_KILL;
1542 }
1543
1544 /* Error detected by uCode */
1545 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001546 IWL_ERR(priv, "Microcode SW error detected. "
1547 " Restarting 0x%X.\n", inta);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001548 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001549 handled |= CSR_INT_BIT_SW_ERR;
1550 }
1551
1552 /* uCode wakes up after power-down sleep */
1553 if (inta & CSR_INT_BIT_WAKEUP) {
1554 IWL_DEBUG_ISR("Wakeup interrupt\n");
Tomas Winklera55360e2008-05-05 10:22:28 +08001555 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Tomas Winklerbabcebf2008-05-15 13:54:00 +08001556 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
1557 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
1558 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
1559 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
1560 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1561 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07001562
1563 handled |= CSR_INT_BIT_WAKEUP;
1564 }
1565
1566 /* All uCode command responses, including Tx command responses,
1567 * Rx "responses" (frame-received notification), and other
1568 * notifications from uCode come through here*/
1569 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Tomas Winklera55360e2008-05-05 10:22:28 +08001570 iwl_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001571 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1572 }
1573
1574 if (inta & CSR_INT_BIT_FH_TX) {
1575 IWL_DEBUG_ISR("Tx interrupt\n");
1576 handled |= CSR_INT_BIT_FH_TX;
Ron Rindjunskydbb983b2008-05-15 13:54:12 +08001577 /* FH finished to write, send event */
1578 priv->ucode_write_complete = 1;
1579 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07001580 }
1581
1582 if (inta & ~handled)
Winkler, Tomas15b16872008-12-19 10:37:33 +08001583 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Zhu Yib481de92007-09-25 17:54:57 -07001584
1585 if (inta & ~CSR_INI_SET_MASK) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001586 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Zhu Yib481de92007-09-25 17:54:57 -07001587 inta & ~CSR_INI_SET_MASK);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001588 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001589 }
1590
1591 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001592 /* only Re-enable if diabled by irq */
1593 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001594 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001595
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001596#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001597 if (priv->debug_level & (IWL_DL_ISR)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001598 inta = iwl_read32(priv, CSR_INT);
1599 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1600 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07001601 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
1602 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
1603 }
1604#endif
1605 spin_unlock_irqrestore(&priv->lock, flags);
1606}
1607
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001608static irqreturn_t iwl_isr(int irq, void *data)
Zhu Yib481de92007-09-25 17:54:57 -07001609{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001610 struct iwl_priv *priv = data;
Zhu Yib481de92007-09-25 17:54:57 -07001611 u32 inta, inta_mask;
1612 u32 inta_fh;
1613 if (!priv)
1614 return IRQ_NONE;
1615
1616 spin_lock(&priv->lock);
1617
1618 /* Disable (but don't clear!) interrupts here to avoid
1619 * back-to-back ISRs and sporadic interrupts from our NIC.
1620 * If we have something to service, the tasklet will re-enable ints.
1621 * If we *don't* have something, we'll re-enable before leaving here. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001622 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
1623 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07001624
1625 /* Discover which interrupts are active/pending */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001626 inta = iwl_read32(priv, CSR_INT);
1627 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07001628
1629 /* Ignore interrupt if there's nothing in NIC to service.
1630 * This may be due to IRQ shared with another device,
1631 * or due to sporadic interrupts thrown from our NIC. */
1632 if (!inta && !inta_fh) {
1633 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
1634 goto none;
1635 }
1636
1637 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
Oliver Neukum66fbb542007-11-15 09:31:10 +08001638 /* Hardware disappeared. It might have already raised
1639 * an interrupt */
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001640 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
Oliver Neukum66fbb542007-11-15 09:31:10 +08001641 goto unplugged;
Zhu Yib481de92007-09-25 17:54:57 -07001642 }
1643
1644 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1645 inta, inta_mask, inta_fh);
1646
Joonwoo Park25c03d82008-01-23 10:15:20 -08001647 inta &= ~CSR_INT_BIT_SCD;
1648
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001649 /* iwl_irq_tasklet() will service interrupts and re-enable them */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001650 if (likely(inta || inta_fh))
1651 tasklet_schedule(&priv->irq_tasklet);
Zhu Yib481de92007-09-25 17:54:57 -07001652
Oliver Neukum66fbb542007-11-15 09:31:10 +08001653 unplugged:
1654 spin_unlock(&priv->lock);
Zhu Yib481de92007-09-25 17:54:57 -07001655 return IRQ_HANDLED;
1656
1657 none:
1658 /* re-enable interrupts here since we don't have anything to service. */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001659 /* only Re-enable if diabled by irq */
1660 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001661 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001662 spin_unlock(&priv->lock);
1663 return IRQ_NONE;
1664}
1665
Zhu Yib481de92007-09-25 17:54:57 -07001666/******************************************************************************
1667 *
1668 * uCode download functions
1669 *
1670 ******************************************************************************/
1671
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001672static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001673{
Tomas Winkler98c92212008-01-14 17:46:20 -08001674 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
1675 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
1676 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1677 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
1678 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1679 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001680}
1681
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001682static void iwl_nic_start(struct iwl_priv *priv)
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08001683{
1684 /* Remove all resets to allow NIC to operate */
1685 iwl_write32(priv, CSR_RESET, 0);
1686}
1687
1688
Zhu Yib481de92007-09-25 17:54:57 -07001689/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001690 * iwl_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07001691 *
1692 * Copy into buffers for card to fetch via bus-mastering
1693 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001694static int iwl_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001695{
Ron Rindjunsky14b3d332008-06-13 15:44:54 +08001696 struct iwl_ucode *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001697 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07001698 const struct firmware *ucode_raw;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001699 const char *name_pre = priv->cfg->fw_name_pre;
1700 const unsigned int api_max = priv->cfg->ucode_api_max;
1701 const unsigned int api_min = priv->cfg->ucode_api_min;
1702 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07001703 u8 *src;
1704 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001705 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07001706
1707 /* Ask kernel firmware_class module to get the boot firmware off disk.
1708 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08001709 for (index = api_max; index >= api_min; index--) {
1710 sprintf(buf, "%s%d%s", name_pre, index, ".ucode");
1711 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
1712 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001713 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001714 buf, ret);
1715 if (ret == -ENOENT)
1716 continue;
1717 else
1718 goto error;
1719 } else {
1720 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08001721 IWL_ERR(priv, "Loaded firmware %s, "
1722 "which is deprecated. "
1723 "Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001724 buf, api_max);
Winkler, Tomas15b16872008-12-19 10:37:33 +08001725
Reinette Chatrea0987a82008-12-02 12:14:06 -08001726 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
1727 buf, ucode_raw->size);
1728 break;
1729 }
Zhu Yib481de92007-09-25 17:54:57 -07001730 }
1731
Reinette Chatrea0987a82008-12-02 12:14:06 -08001732 if (ret < 0)
1733 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07001734
1735 /* Make sure that we got at least our header! */
1736 if (ucode_raw->size < sizeof(*ucode)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001737 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001738 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001739 goto err_release;
1740 }
1741
1742 /* Data from ucode file: header followed by uCode images */
1743 ucode = (void *)ucode_raw->data;
1744
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08001745 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08001746 api_ver = IWL_UCODE_API(priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07001747 inst_size = le32_to_cpu(ucode->inst_size);
1748 data_size = le32_to_cpu(ucode->data_size);
1749 init_size = le32_to_cpu(ucode->init_size);
1750 init_data_size = le32_to_cpu(ucode->init_data_size);
1751 boot_size = le32_to_cpu(ucode->boot_size);
1752
Reinette Chatrea0987a82008-12-02 12:14:06 -08001753 /* api_ver should match the api version forming part of the
1754 * firmware filename ... but we don't check for that and only rely
1755 * on the API version read from firware header from here on forward */
1756
1757 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001758 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08001759 "Driver supports v%u, firmware is v%u.\n",
1760 api_max, api_ver);
1761 priv->ucode_ver = 0;
1762 ret = -EINVAL;
1763 goto err_release;
1764 }
1765 if (api_ver != api_max)
Tomas Winkler978785a2008-12-19 10:37:31 +08001766 IWL_ERR(priv, "Firmware has old API version. Expected v%u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08001767 "got v%u. New firmware can be obtained "
1768 "from http://www.intellinuxwireless.org.\n",
1769 api_max, api_ver);
1770
Tomas Winkler978785a2008-12-19 10:37:31 +08001771 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
1772 IWL_UCODE_MAJOR(priv->ucode_ver),
1773 IWL_UCODE_MINOR(priv->ucode_ver),
1774 IWL_UCODE_API(priv->ucode_ver),
1775 IWL_UCODE_SERIAL(priv->ucode_ver));
Reinette Chatrea0987a82008-12-02 12:14:06 -08001776
1777 IWL_DEBUG_INFO("f/w package hdr ucode version raw = 0x%x\n",
1778 priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07001779 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
1780 inst_size);
1781 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
1782 data_size);
1783 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
1784 init_size);
1785 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
1786 init_data_size);
1787 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
1788 boot_size);
1789
1790 /* Verify size of file vs. image size info in file's header */
1791 if (ucode_raw->size < sizeof(*ucode) +
1792 inst_size + data_size + init_size +
1793 init_data_size + boot_size) {
1794
1795 IWL_DEBUG_INFO("uCode file size %d too small\n",
1796 (int)ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001797 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001798 goto err_release;
1799 }
1800
1801 /* Verify that uCode images will fit in card's SRAM */
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001802 if (inst_size > priv->hw_params.max_inst_size) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08001803 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
1804 inst_size);
1805 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001806 goto err_release;
1807 }
1808
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001809 if (data_size > priv->hw_params.max_data_size) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08001810 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
1811 data_size);
1812 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001813 goto err_release;
1814 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001815 if (init_size > priv->hw_params.max_inst_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001816 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001817 ("uCode init instr len %d too large to fit in\n",
1818 init_size);
1819 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001820 goto err_release;
1821 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001822 if (init_data_size > priv->hw_params.max_data_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001823 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001824 ("uCode init data len %d too large to fit in\n",
1825 init_data_size);
1826 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001827 goto err_release;
1828 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001829 if (boot_size > priv->hw_params.max_bsm_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001830 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001831 ("uCode boot instr len %d too large to fit in\n",
1832 boot_size);
1833 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001834 goto err_release;
1835 }
1836
1837 /* Allocate ucode buffers for card's bus-master loading ... */
1838
1839 /* Runtime instructions and 2 copies of data:
1840 * 1) unmodified from disk
1841 * 2) backup cache for save/restore during power-downs */
1842 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001843 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07001844
1845 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001846 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07001847
1848 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001849 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07001850
1851 /* Initialization instructions and data */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001852 if (init_size && init_data_size) {
1853 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001854 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Zhu Yib481de92007-09-25 17:54:57 -07001855
Tomas Winkler90e759d2007-11-29 11:09:41 +08001856 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001857 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001858
1859 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
1860 goto err_pci_alloc;
1861 }
Zhu Yib481de92007-09-25 17:54:57 -07001862
1863 /* Bootstrap (instructions only, no data) */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001864 if (boot_size) {
1865 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001866 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001867
Tomas Winkler90e759d2007-11-29 11:09:41 +08001868 if (!priv->ucode_boot.v_addr)
1869 goto err_pci_alloc;
1870 }
Zhu Yib481de92007-09-25 17:54:57 -07001871
1872 /* Copy images into buffers for card's bus-master reads ... */
1873
1874 /* Runtime instructions (first block of data in file) */
1875 src = &ucode->data[0];
1876 len = priv->ucode_code.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001877 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001878 memcpy(priv->ucode_code.v_addr, src, len);
1879 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
1880 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
1881
1882 /* Runtime data (2nd block)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001883 * NOTE: Copy into backup buffer will be done in iwl_up() */
Zhu Yib481de92007-09-25 17:54:57 -07001884 src = &ucode->data[inst_size];
1885 len = priv->ucode_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001886 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001887 memcpy(priv->ucode_data.v_addr, src, len);
1888 memcpy(priv->ucode_data_backup.v_addr, src, len);
1889
1890 /* Initialization instructions (3rd block) */
1891 if (init_size) {
1892 src = &ucode->data[inst_size + data_size];
1893 len = priv->ucode_init.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001894 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
1895 len);
Zhu Yib481de92007-09-25 17:54:57 -07001896 memcpy(priv->ucode_init.v_addr, src, len);
1897 }
1898
1899 /* Initialization data (4th block) */
1900 if (init_data_size) {
1901 src = &ucode->data[inst_size + data_size + init_size];
1902 len = priv->ucode_init_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001903 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
1904 len);
Zhu Yib481de92007-09-25 17:54:57 -07001905 memcpy(priv->ucode_init_data.v_addr, src, len);
1906 }
1907
1908 /* Bootstrap instructions (5th block) */
1909 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
1910 len = priv->ucode_boot.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001911 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001912 memcpy(priv->ucode_boot.v_addr, src, len);
1913
1914 /* We have our copies now, allow OS release its copies */
1915 release_firmware(ucode_raw);
1916 return 0;
1917
1918 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08001919 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001920 ret = -ENOMEM;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001921 iwl_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001922
1923 err_release:
1924 release_firmware(ucode_raw);
1925
1926 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08001927 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07001928}
1929
Mohamed Abbasada17512008-11-07 09:58:34 -08001930/* temporary */
1931static int iwl_mac_beacon_update(struct ieee80211_hw *hw,
1932 struct sk_buff *skb);
1933
Zhu Yib481de92007-09-25 17:54:57 -07001934/**
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001935 * iwl_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07001936 * from protocol/runtime uCode (initialization uCode's
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001937 * Alive gets handled by iwl_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07001938 */
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001939static void iwl_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001940{
Tomas Winkler57aab752008-04-14 21:16:03 -07001941 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001942
1943 IWL_DEBUG_INFO("Runtime Alive received.\n");
1944
1945 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
1946 /* We had an error bringing up the hardware, so take it
1947 * all the way back down so we can try again */
1948 IWL_DEBUG_INFO("Alive failed.\n");
1949 goto restart;
1950 }
1951
1952 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
1953 * This is a paranoid check, because we would not have gotten the
1954 * "runtime" alive if code weren't properly loaded. */
Emmanuel Grumbachb0692f22008-04-24 11:55:18 -07001955 if (iwl_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001956 /* Runtime instruction load was bad;
1957 * take it all the way back down so we can try again */
1958 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
1959 goto restart;
1960 }
1961
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08001962 iwl_clear_stations_table(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07001963 ret = priv->cfg->ops->lib->alive_notify(priv);
1964 if (ret) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001965 IWL_WARN(priv,
1966 "Could not complete ALIVE transition [ntf]: %d\n", ret);
Zhu Yib481de92007-09-25 17:54:57 -07001967 goto restart;
1968 }
1969
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001970 /* After the ALIVE response, we can send host commands to the uCode */
Zhu Yib481de92007-09-25 17:54:57 -07001971 set_bit(STATUS_ALIVE, &priv->status);
1972
Tomas Winklerfee12472008-04-03 16:05:21 -07001973 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001974 return;
1975
Johannes Berg36d68252008-05-15 12:55:26 +02001976 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07001977
1978 priv->active_rate = priv->rates_mask;
1979 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
1980
Tomas Winkler3109ece2008-03-28 16:33:35 -07001981 if (iwl_is_associated(priv)) {
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001982 struct iwl_rxon_cmd *active_rxon =
1983 (struct iwl_rxon_cmd *)&priv->active_rxon;
Zhu Yib481de92007-09-25 17:54:57 -07001984
1985 memcpy(&priv->staging_rxon, &priv->active_rxon,
1986 sizeof(priv->staging_rxon));
1987 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1988 } else {
1989 /* Initialize our rx_config data */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001990 iwl_connection_init_rx_config(priv, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07001991 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
1992 }
1993
Ben Cahill9fbab512007-11-29 11:09:47 +08001994 /* Configure Bluetooth device coexistence support */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001995 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001996
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001997 iwl_reset_run_time_calib(priv);
1998
Zhu Yib481de92007-09-25 17:54:57 -07001999 /* Configure the adapter for unassociated operation */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002000 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002001
2002 /* At this point, the NIC is initialized and operational */
Emmanuel Grumbach47f4a582008-06-12 09:47:13 +08002003 iwl_rf_kill_ct_config(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08002004
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07002005 iwl_leds_register(priv);
2006
Zhu Yib481de92007-09-25 17:54:57 -07002007 IWL_DEBUG_INFO("ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07002008 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a669262008-01-14 17:46:18 -08002009 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07002010
2011 if (priv->error_recovering)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002012 iwl_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002013
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08002014 iwl_power_update_mode(priv, 1);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002015
Mohamed Abbasada17512008-11-07 09:58:34 -08002016 /* reassociate for ADHOC mode */
2017 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
2018 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
2019 priv->vif);
2020 if (beacon)
2021 iwl_mac_beacon_update(priv->hw, beacon);
2022 }
2023
2024
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002025 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002026 iwl_set_mode(priv, priv->iw_mode);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002027
Zhu Yib481de92007-09-25 17:54:57 -07002028 return;
2029
2030 restart:
2031 queue_work(priv->workqueue, &priv->restart);
2032}
2033
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002034static void iwl_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07002035
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002036static void __iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002037{
2038 unsigned long flags;
2039 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002040
2041 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
2042
Zhu Yib481de92007-09-25 17:54:57 -07002043 if (!exit_pending)
2044 set_bit(STATUS_EXIT_PENDING, &priv->status);
2045
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07002046 iwl_leds_unregister(priv);
2047
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08002048 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002049
2050 /* Unblock any waiting calls */
2051 wake_up_interruptible_all(&priv->wait_command_queue);
2052
Zhu Yib481de92007-09-25 17:54:57 -07002053 /* Wipe out the EXIT_PENDING status bit if we are not actually
2054 * exiting the module */
2055 if (!exit_pending)
2056 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2057
2058 /* stop and reset the on-board processor */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002059 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07002060
2061 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002062 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002063 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002064 spin_unlock_irqrestore(&priv->lock, flags);
2065 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002066
2067 if (priv->mac80211_registered)
2068 ieee80211_stop_queues(priv->hw);
2069
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002070 /* If we have not previously called iwl_init() then
Zhu Yib481de92007-09-25 17:54:57 -07002071 * clear all bits but the RF Kill and SUSPEND bits and return */
Tomas Winklerfee12472008-04-03 16:05:21 -07002072 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002073 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2074 STATUS_RF_KILL_HW |
2075 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2076 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08002077 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2078 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002079 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002080 STATUS_IN_SUSPEND |
2081 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2082 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002083 goto exit;
2084 }
2085
2086 /* ...otherwise clear out all the status bits but the RF Kill and
2087 * SUSPEND bits and continue taking the NIC down. */
2088 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2089 STATUS_RF_KILL_HW |
2090 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2091 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08002092 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2093 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002094 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
2095 STATUS_IN_SUSPEND |
2096 test_bit(STATUS_FW_ERROR, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002097 STATUS_FW_ERROR |
2098 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2099 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002100
2101 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002102 iwl_clear_bit(priv, CSR_GP_CNTRL,
Ben Cahill9fbab512007-11-29 11:09:47 +08002103 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07002104 spin_unlock_irqrestore(&priv->lock, flags);
2105
Tomas Winklerda1bc452008-05-29 16:35:00 +08002106 iwl_txq_ctx_stop(priv);
Tomas Winklerb3bbacb2008-05-29 16:35:01 +08002107 iwl_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002108
2109 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002110 if (!iwl_grab_nic_access(priv)) {
2111 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002112 APMG_CLK_VAL_DMA_CLK_RQT);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002113 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002114 }
2115 spin_unlock_irqrestore(&priv->lock, flags);
2116
2117 udelay(5);
2118
Tomas Winkler7f066102008-05-29 16:34:57 +08002119 /* FIXME: apm_ops.suspend(priv) */
Gregory Greenmand5353112008-09-03 11:18:49 +08002120 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
2121 priv->cfg->ops->lib->apm_ops.stop(priv);
2122 else
2123 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002124 exit:
Tomas Winkler885ba202008-05-29 16:34:55 +08002125 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07002126
2127 if (priv->ibss_beacon)
2128 dev_kfree_skb(priv->ibss_beacon);
2129 priv->ibss_beacon = NULL;
2130
2131 /* clear out any free frames */
Tomas Winklerfcab4232008-05-15 13:54:01 +08002132 iwl_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002133}
2134
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002135static void iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002136{
2137 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002138 __iwl_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002139 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08002140
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002141 iwl_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002142}
2143
2144#define MAX_HW_RESTARTS 5
2145
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002146static int __iwl_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002147{
Tomas Winkler57aab752008-04-14 21:16:03 -07002148 int i;
2149 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002150
2151 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002152 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07002153 return -EIO;
2154 }
2155
Reinette Chatree903fbd2008-01-30 22:05:15 -08002156 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002157 IWL_ERR(priv, "ucode not available for device bringup\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08002158 return -EIO;
2159 }
2160
Zhu Yie655b9f2008-01-24 02:19:38 -08002161 /* If platform's RF_KILL switch is NOT set to KILL */
Tomas Winklerc1842d62008-08-04 16:00:43 +08002162 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
Zhu Yie655b9f2008-01-24 02:19:38 -08002163 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002164 else
Zhu Yie655b9f2008-01-24 02:19:38 -08002165 set_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002166
Tomas Winklerc1842d62008-08-04 16:00:43 +08002167 if (iwl_is_rfkill(priv)) {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002168 iwl_enable_interrupts(priv);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002169 IWL_WARN(priv, "Radio disabled by %s RF Kill switch\n",
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002170 test_bit(STATUS_RF_KILL_HW, &priv->status) ? "HW" : "SW");
Tomas Winklerc1842d62008-08-04 16:00:43 +08002171 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002172 }
2173
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002174 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07002175
Ron Rindjunsky1053d352008-05-05 10:22:43 +08002176 ret = iwl_hw_nic_init(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07002177 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002178 IWL_ERR(priv, "Unable to init nic\n");
Tomas Winkler57aab752008-04-14 21:16:03 -07002179 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002180 }
2181
2182 /* make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002183 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2184 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07002185 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2186
2187 /* clear (again), then enable host interrupts */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002188 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002189 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002190
2191 /* really make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002192 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2193 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07002194
2195 /* Copy original ucode data image from disk into backup cache.
2196 * This will be used to initialize the on-board processor's
2197 * data SRAM for a clean start when the runtime program first loads. */
2198 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a669262008-01-14 17:46:18 -08002199 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07002200
Zhu Yib481de92007-09-25 17:54:57 -07002201 for (i = 0; i < MAX_HW_RESTARTS; i++) {
2202
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08002203 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002204
2205 /* load bootstrap state machine,
2206 * load bootstrap program into processor's memory,
2207 * prepare to load the "initialize" uCode */
Tomas Winkler57aab752008-04-14 21:16:03 -07002208 ret = priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002209
Tomas Winkler57aab752008-04-14 21:16:03 -07002210 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002211 IWL_ERR(priv, "Unable to set up bootstrap uCode: %d\n",
2212 ret);
Zhu Yib481de92007-09-25 17:54:57 -07002213 continue;
2214 }
2215
Emmanuel Grumbachf3d5b452008-06-12 09:47:04 +08002216 /* Clear out the uCode error bit if it is set */
2217 clear_bit(STATUS_FW_ERROR, &priv->status);
2218
Zhu Yib481de92007-09-25 17:54:57 -07002219 /* start card; "initialize" will load runtime ucode */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002220 iwl_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002221
Zhu Yib481de92007-09-25 17:54:57 -07002222 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
2223
2224 return 0;
2225 }
2226
2227 set_bit(STATUS_EXIT_PENDING, &priv->status);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002228 __iwl_down(priv);
Mohamed Abbas64e72c32008-06-12 09:47:03 +08002229 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002230
2231 /* tried to restart and config the device for as long as our
2232 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002233 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07002234 return -EIO;
2235}
2236
2237
2238/*****************************************************************************
2239 *
2240 * Workqueue callbacks
2241 *
2242 *****************************************************************************/
2243
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002244static void iwl_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002245{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002246 struct iwl_priv *priv =
2247 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002248
2249 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2250 return;
2251
2252 mutex_lock(&priv->mutex);
Emmanuel Grumbachf3ccc082008-05-05 10:22:45 +08002253 priv->cfg->ops->lib->init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002254 mutex_unlock(&priv->mutex);
2255}
2256
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002257static void iwl_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002258{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002259 struct iwl_priv *priv =
2260 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002261
2262 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2263 return;
2264
2265 mutex_lock(&priv->mutex);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002266 iwl_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002267 mutex_unlock(&priv->mutex);
2268}
2269
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08002270static void iwl_bg_run_time_calib_work(struct work_struct *work)
2271{
2272 struct iwl_priv *priv = container_of(work, struct iwl_priv,
2273 run_time_calib_work);
2274
2275 mutex_lock(&priv->mutex);
2276
2277 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
2278 test_bit(STATUS_SCANNING, &priv->status)) {
2279 mutex_unlock(&priv->mutex);
2280 return;
2281 }
2282
2283 if (priv->start_calib) {
2284 iwl_chain_noise_calibration(priv, &priv->statistics);
2285
2286 iwl_sensitivity_calibration(priv, &priv->statistics);
2287 }
2288
2289 mutex_unlock(&priv->mutex);
2290 return;
2291}
2292
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002293static void iwl_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002294{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002295 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07002296
2297 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2298 return;
2299
2300 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002301 __iwl_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002302 mutex_unlock(&priv->mutex);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002303 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002304}
2305
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002306static void iwl_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002307{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002308 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07002309
2310 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2311 return;
2312
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002313 iwl_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002314 queue_work(priv->workqueue, &priv->up);
2315}
2316
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002317static void iwl_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002318{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002319 struct iwl_priv *priv =
2320 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07002321
2322 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2323 return;
2324
2325 mutex_lock(&priv->mutex);
Tomas Winklera55360e2008-05-05 10:22:28 +08002326 iwl_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002327 mutex_unlock(&priv->mutex);
2328}
2329
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002330#define IWL_DELAY_NEXT_SCAN (HZ*2)
2331
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002332static void iwl_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002333{
Zhu Yib481de92007-09-25 17:54:57 -07002334 struct ieee80211_conf *conf = NULL;
Tomas Winkler857485c2008-03-21 13:53:44 -07002335 int ret = 0;
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002336 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07002337
Johannes Berg05c914f2008-09-11 00:01:58 +02002338 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002339 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07002340 return;
2341 }
2342
Johannes Berge1749612008-10-27 15:59:26 -07002343 IWL_DEBUG_ASSOC("Associated as %d to: %pM\n",
2344 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07002345
2346
2347 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2348 return;
2349
Zhu Yib481de92007-09-25 17:54:57 -07002350
Reinette Chatre508e32e2008-04-14 21:16:13 -07002351 if (!priv->vif || !priv->is_open)
Mohamed Abbas948c1712007-10-25 17:15:45 +08002352 return;
Reinette Chatre508e32e2008-04-14 21:16:13 -07002353
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08002354 iwl_power_cancel_timeout(priv);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002355 iwl_scan_cancel_timeout(priv, 200);
mabbas052c4b92007-10-25 17:15:43 +08002356
Zhu Yib481de92007-09-25 17:54:57 -07002357 conf = ieee80211_get_hw_conf(priv->hw);
2358
2359 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002360 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002361
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002362 iwl_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002363 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002364 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002365 if (ret)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002366 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07002367 "Attempting to continue.\n");
2368
2369 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
2370
Emmanuel Grumbach42eb7c62008-09-17 10:10:05 +08002371 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03002372
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07002373 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002374 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2375
2376 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
2377 priv->assoc_id, priv->beacon_int);
2378
2379 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2380 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2381 else
2382 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2383
2384 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2385 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2386 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2387 else
2388 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2389
Johannes Berg05c914f2008-09-11 00:01:58 +02002390 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002391 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2392
2393 }
2394
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002395 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002396
2397 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02002398 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -07002399 break;
2400
Johannes Berg05c914f2008-09-11 00:01:58 +02002401 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07002402
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002403 /* assume default assoc id */
2404 priv->assoc_id = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002405
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002406 iwl_rxon_add_station(priv, priv->bssid, 0);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002407 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002408
2409 break;
2410
2411 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002412 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03002413 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002414 break;
2415 }
2416
Johannes Berg05c914f2008-09-11 00:01:58 +02002417 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002418 priv->assoc_station_added = 1;
2419
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002420 spin_lock_irqsave(&priv->lock, flags);
2421 iwl_activate_qos(priv, 0);
2422 spin_unlock_irqrestore(&priv->lock, flags);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08002423
Grumbach, Emmanuel04816442008-09-03 11:26:53 +08002424 /* the chain noise calibration will enabled PM upon completion
2425 * If chain noise has already been run, then we need to enable
2426 * power management here */
2427 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
2428 iwl_power_enable_management(priv);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08002429
2430 /* Enable Rx differential gain and sensitivity calibrations */
2431 iwl_chain_noise_reset(priv);
2432 priv->start_calib = 1;
2433
Reinette Chatre508e32e2008-04-14 21:16:13 -07002434}
2435
Zhu Yib481de92007-09-25 17:54:57 -07002436/*****************************************************************************
2437 *
2438 * mac80211 entry point functions
2439 *
2440 *****************************************************************************/
2441
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002442#define UCODE_READY_TIMEOUT (4 * HZ)
Zhu Yi5a669262008-01-14 17:46:18 -08002443
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002444static int iwl_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002445{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002446 struct iwl_priv *priv = hw->priv;
Zhu Yi5a669262008-01-14 17:46:18 -08002447 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002448
2449 IWL_DEBUG_MAC80211("enter\n");
2450
2451 /* we should be verifying the device is ready to be opened */
2452 mutex_lock(&priv->mutex);
2453
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08002454 memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd));
Zhu Yi5a669262008-01-14 17:46:18 -08002455 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
2456 * ucode filename and max sizes are card-specific. */
2457
2458 if (!priv->ucode_code.len) {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002459 ret = iwl_read_ucode(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08002460 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002461 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a669262008-01-14 17:46:18 -08002462 mutex_unlock(&priv->mutex);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002463 return ret;
Zhu Yi5a669262008-01-14 17:46:18 -08002464 }
2465 }
2466
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002467 ret = __iwl_up(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08002468
Zhu Yib481de92007-09-25 17:54:57 -07002469 mutex_unlock(&priv->mutex);
Zhu Yi5a669262008-01-14 17:46:18 -08002470
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002471 iwl_rfkill_set_hw_state(priv);
2472
Zhu Yie655b9f2008-01-24 02:19:38 -08002473 if (ret)
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002474 return ret;
Zhu Yie655b9f2008-01-24 02:19:38 -08002475
Tomas Winklerc1842d62008-08-04 16:00:43 +08002476 if (iwl_is_rfkill(priv))
2477 goto out;
2478
Zhu Yie655b9f2008-01-24 02:19:38 -08002479 IWL_DEBUG_INFO("Start UP work done.\n");
2480
2481 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
2482 return 0;
2483
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002484 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
Zhu Yi5a669262008-01-14 17:46:18 -08002485 * mac80211 will not be run successfully. */
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002486 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
2487 test_bit(STATUS_READY, &priv->status),
2488 UCODE_READY_TIMEOUT);
2489 if (!ret) {
2490 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002491 IWL_ERR(priv, "START_ALIVE timeout after %dms.\n",
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002492 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002493 return -ETIMEDOUT;
Zhu Yi5a669262008-01-14 17:46:18 -08002494 }
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002495 }
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002496
Tomas Winklerc1842d62008-08-04 16:00:43 +08002497out:
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002498 priv->is_open = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002499 IWL_DEBUG_MAC80211("leave\n");
2500 return 0;
2501}
2502
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002503static void iwl_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002504{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002505 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002506
2507 IWL_DEBUG_MAC80211("enter\n");
Mohamed Abbas948c1712007-10-25 17:15:45 +08002508
Zhu Yie655b9f2008-01-24 02:19:38 -08002509 if (!priv->is_open) {
2510 IWL_DEBUG_MAC80211("leave - skip\n");
2511 return;
2512 }
2513
Zhu Yib481de92007-09-25 17:54:57 -07002514 priv->is_open = 0;
Zhu Yi5a669262008-01-14 17:46:18 -08002515
Tomas Winklerfee12472008-04-03 16:05:21 -07002516 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08002517 /* stop mac, cancel any scan request and clear
2518 * RXON_FILTER_ASSOC_MSK BIT
2519 */
Zhu Yi5a669262008-01-14 17:46:18 -08002520 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002521 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002522 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002523 }
2524
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002525 iwl_down(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08002526
2527 flush_workqueue(priv->workqueue);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002528
2529 /* enable interrupts again in order to receive rfkill changes */
2530 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
2531 iwl_enable_interrupts(priv);
Mohamed Abbas948c1712007-10-25 17:15:45 +08002532
Zhu Yib481de92007-09-25 17:54:57 -07002533 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002534}
2535
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002536static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07002537{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002538 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002539
Tomas Winklerf3674222008-08-04 16:00:44 +08002540 IWL_DEBUG_MACDUMP("enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002541
Zhu Yib481de92007-09-25 17:54:57 -07002542 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02002543 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07002544
Johannes Berge039fa42008-05-15 12:55:29 +02002545 if (iwl_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07002546 dev_kfree_skb_any(skb);
2547
Tomas Winklerf3674222008-08-04 16:00:44 +08002548 IWL_DEBUG_MACDUMP("leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08002549 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07002550}
2551
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002552static int iwl_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07002553 struct ieee80211_if_init_conf *conf)
2554{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002555 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002556 unsigned long flags;
2557
Johannes Berg32bfd352007-12-19 01:31:26 +01002558 IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07002559
Johannes Berg32bfd352007-12-19 01:31:26 +01002560 if (priv->vif) {
2561 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
Reinette Chatre75849d22008-01-23 10:15:17 -08002562 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07002563 }
2564
2565 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01002566 priv->vif = conf->vif;
Zhu, Yi60294de2008-10-29 14:05:45 -07002567 priv->iw_mode = conf->type;
Zhu Yib481de92007-09-25 17:54:57 -07002568
2569 spin_unlock_irqrestore(&priv->lock, flags);
2570
2571 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02002572
2573 if (conf->mac_addr) {
Johannes Berge1749612008-10-27 15:59:26 -07002574 IWL_DEBUG_MAC80211("Set %pM\n", conf->mac_addr);
Tomas Winkler864792e2007-11-27 21:00:52 +02002575 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
2576 }
Zhu Yib481de92007-09-25 17:54:57 -07002577
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002578 if (iwl_set_mode(priv, conf->type) == -EAGAIN)
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002579 /* we are not ready, will run again when ready */
2580 set_bit(STATUS_MODE_PENDING, &priv->status);
Zhu Yi5a669262008-01-14 17:46:18 -08002581
Zhu Yib481de92007-09-25 17:54:57 -07002582 mutex_unlock(&priv->mutex);
2583
Zhu Yi5a669262008-01-14 17:46:18 -08002584 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002585 return 0;
2586}
2587
2588/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002589 * iwl_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07002590 *
2591 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
2592 * be set inappropriately and the driver currently sets the hardware up to
2593 * use it whenever needed.
2594 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002595static int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
Zhu Yib481de92007-09-25 17:54:57 -07002596{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002597 struct iwl_priv *priv = hw->priv;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07002598 const struct iwl_channel_info *ch_info;
Johannes Berge8975582008-10-09 12:18:51 +02002599 struct ieee80211_conf *conf = &hw->conf;
Zhu Yib481de92007-09-25 17:54:57 -07002600 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08002601 int ret = 0;
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002602 u16 channel;
Zhu Yib481de92007-09-25 17:54:57 -07002603
2604 mutex_lock(&priv->mutex);
Johannes Berg8318d782008-01-24 19:38:38 +01002605 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07002606
Luis R. Rodriguezde27e642008-12-23 15:58:44 -08002607 priv->current_ht_config.is_ht = conf_is_ht(conf);
Johannes Bergae5eb022008-10-14 16:58:37 +02002608
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +08002609 if (conf->radio_enabled && iwl_radio_kill_sw_enable_radio(priv)) {
Mohamed Abbas64e72c32008-06-12 09:47:03 +08002610 IWL_DEBUG_MAC80211("leave - RF-KILL - waiting for uCode\n");
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +08002611 goto out;
Mohamed Abbas64e72c32008-06-12 09:47:03 +08002612 }
2613
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +08002614 if (!conf->radio_enabled)
2615 iwl_radio_kill_sw_disable_radio(priv);
2616
Tomas Winklerfee12472008-04-03 16:05:21 -07002617 if (!iwl_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002618 IWL_DEBUG_MAC80211("leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002619 ret = -EIO;
2620 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002621 }
2622
Assaf Krauss1ea87392008-03-18 14:57:50 -07002623 if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07002624 test_bit(STATUS_SCANNING, &priv->status))) {
Zhu Yia0646472007-12-20 14:10:01 +08002625 IWL_DEBUG_MAC80211("leave - scanning\n");
Zhu Yib481de92007-09-25 17:54:57 -07002626 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08002627 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002628 }
2629
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002630 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2631 ch_info = iwl_get_channel_info(priv, conf->channel->band, channel);
Zhu Yib481de92007-09-25 17:54:57 -07002632 if (!is_channel_valid(ch_info)) {
Zhu Yib481de92007-09-25 17:54:57 -07002633 IWL_DEBUG_MAC80211("leave - invalid channel\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002634 ret = -EINVAL;
2635 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002636 }
2637
Johannes Berg05c914f2008-09-11 00:01:58 +02002638 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Assaf Krauss398f9e72008-06-12 09:47:06 +08002639 !is_channel_ibss(ch_info)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002640 IWL_ERR(priv, "channel %d in band %d not IBSS channel\n",
Assaf Krauss398f9e72008-06-12 09:47:06 +08002641 conf->channel->hw_value, conf->channel->band);
2642 ret = -EINVAL;
2643 goto out;
2644 }
2645
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002646 spin_lock_irqsave(&priv->lock, flags);
2647
Tomas Winklerb5d7be52008-07-19 04:41:24 +03002648
Tomas Winkler78330fd2008-02-06 02:37:18 +02002649 /* if we are switching from ht to 2.4 clear flags
Zhu Yib481de92007-09-25 17:54:57 -07002650 * from any ht related info since 2.4 does not
2651 * support ht */
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002652 if ((le16_to_cpu(priv->staging_rxon.channel) != channel)
Zhu Yib481de92007-09-25 17:54:57 -07002653#ifdef IEEE80211_CONF_CHANNEL_SWITCH
2654 && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
2655#endif
2656 )
2657 priv->staging_rxon.flags = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002658
Tomas Winkler17e72782008-09-03 11:26:26 +08002659 iwl_set_rxon_channel(priv, conf->channel);
Zhu Yib481de92007-09-25 17:54:57 -07002660
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002661 iwl_set_flags_for_band(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07002662
2663 /* The list of supported rates and rate mask can be different
Johannes Berg8318d782008-01-24 19:38:38 +01002664 * for each band; since the band may have changed, reset
Zhu Yib481de92007-09-25 17:54:57 -07002665 * the rate mask to what mac80211 lists */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002666 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002667
2668 spin_unlock_irqrestore(&priv->lock, flags);
2669
2670#ifdef IEEE80211_CONF_CHANNEL_SWITCH
2671 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002672 iwl_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08002673 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002674 }
2675#endif
2676
Zhu Yib481de92007-09-25 17:54:57 -07002677 if (!conf->radio_enabled) {
2678 IWL_DEBUG_MAC80211("leave - radio disabled\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002679 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002680 }
2681
Tomas Winklerfee12472008-04-03 16:05:21 -07002682 if (iwl_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002683 IWL_DEBUG_MAC80211("leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002684 ret = -EIO;
2685 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002686 }
2687
Ester Kummere602cb12008-09-26 15:09:33 +08002688 if (conf->flags & IEEE80211_CONF_PS)
2689 ret = iwl_power_set_user_mode(priv, IWL_POWER_INDEX_3);
2690 else
2691 ret = iwl_power_set_user_mode(priv, IWL_POWER_MODE_CAM);
2692 if (ret)
2693 IWL_DEBUG_MAC80211("Error setting power level\n");
2694
Tomas Winkler630fe9b2008-06-12 09:47:08 +08002695 IWL_DEBUG_MAC80211("TX Power old=%d new=%d\n",
2696 priv->tx_power_user_lmt, conf->power_level);
2697
2698 iwl_set_tx_power(priv, conf->power_level, false);
2699
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002700 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002701
Rick Farrington7b841722009-01-23 13:45:10 -08002702 /* call to ensure that 4965 rx_chain is set properly in monitor mode */
2703 iwl_set_rxon_chain(priv);
2704
Zhu Yib481de92007-09-25 17:54:57 -07002705 if (memcmp(&priv->active_rxon,
2706 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002707 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002708 else
2709 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
2710
2711 IWL_DEBUG_MAC80211("leave\n");
2712
Zhu Yia0646472007-12-20 14:10:01 +08002713out:
Zhu Yi5a669262008-01-14 17:46:18 -08002714 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08002715 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002716}
2717
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002718static void iwl_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002719{
Tomas Winkler857485c2008-03-21 13:53:44 -07002720 int ret = 0;
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002721 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07002722
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08002723 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07002724 return;
2725
2726 /* The following should be done only at AP bring up */
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002727 if (!iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002728
2729 /* RXON - unassoc (to set timing command) */
2730 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002731 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002732
2733 /* RXON Timing */
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002734 iwl_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002735 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002736 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002737 if (ret)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002738 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07002739 "Attempting to continue.\n");
2740
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07002741 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002742
2743 /* FIXME: what should be the assoc_id for AP? */
2744 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2745 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2746 priv->staging_rxon.flags |=
2747 RXON_FLG_SHORT_PREAMBLE_MSK;
2748 else
2749 priv->staging_rxon.flags &=
2750 ~RXON_FLG_SHORT_PREAMBLE_MSK;
2751
2752 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2753 if (priv->assoc_capability &
2754 WLAN_CAPABILITY_SHORT_SLOT_TIME)
2755 priv->staging_rxon.flags |=
2756 RXON_FLG_SHORT_SLOT_MSK;
2757 else
2758 priv->staging_rxon.flags &=
2759 ~RXON_FLG_SHORT_SLOT_MSK;
2760
Johannes Berg05c914f2008-09-11 00:01:58 +02002761 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002762 priv->staging_rxon.flags &=
2763 ~RXON_FLG_SHORT_SLOT_MSK;
2764 }
2765 /* restore RXON assoc */
2766 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002767 iwl_commit_rxon(priv);
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002768 spin_lock_irqsave(&priv->lock, flags);
2769 iwl_activate_qos(priv, 1);
2770 spin_unlock_irqrestore(&priv->lock, flags);
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002771 iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
Zhu Yie1493de2007-09-27 11:27:32 +08002772 }
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002773 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002774
2775 /* FIXME - we need to add code here to detect a totally new
2776 * configuration, reset the AP, unassoc, rxon timing, assoc,
2777 * clear sta table, add BCAST sta... */
2778}
2779
Johannes Berg9d139c82008-07-09 14:40:37 +02002780
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002781static int iwl_mac_config_interface(struct ieee80211_hw *hw,
Johannes Berg32bfd352007-12-19 01:31:26 +01002782 struct ieee80211_vif *vif,
Zhu Yib481de92007-09-25 17:54:57 -07002783 struct ieee80211_if_conf *conf)
2784{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002785 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002786 int rc;
2787
2788 if (conf == NULL)
2789 return -EIO;
2790
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08002791 if (priv->vif != vif) {
2792 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08002793 return 0;
2794 }
2795
Johannes Berg05c914f2008-09-11 00:01:58 +02002796 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Johannes Berg9d139c82008-07-09 14:40:37 +02002797 conf->changed & IEEE80211_IFCC_BEACON) {
2798 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
2799 if (!beacon)
2800 return -ENOMEM;
Mohamed Abbasada17512008-11-07 09:58:34 -08002801 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002802 rc = iwl_mac_beacon_update(hw, beacon);
Mohamed Abbasada17512008-11-07 09:58:34 -08002803 mutex_unlock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02002804 if (rc)
2805 return rc;
2806 }
2807
Tomas Winklerfee12472008-04-03 16:05:21 -07002808 if (!iwl_is_alive(priv))
Zhu Yi5a669262008-01-14 17:46:18 -08002809 return -EAGAIN;
2810
Zhu Yib481de92007-09-25 17:54:57 -07002811 mutex_lock(&priv->mutex);
2812
Zhu Yib481de92007-09-25 17:54:57 -07002813 if (conf->bssid)
Johannes Berge1749612008-10-27 15:59:26 -07002814 IWL_DEBUG_MAC80211("bssid: %pM\n", conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07002815
Johannes Berg4150c572007-09-17 01:29:23 -04002816/*
2817 * very dubious code was here; the probe filtering flag is never set:
2818 *
Zhu Yib481de92007-09-25 17:54:57 -07002819 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
2820 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04002821 */
Zhu Yib481de92007-09-25 17:54:57 -07002822
Johannes Berg05c914f2008-09-11 00:01:58 +02002823 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07002824 if (!conf->bssid) {
2825 conf->bssid = priv->mac_addr;
2826 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -07002827 IWL_DEBUG_MAC80211("bssid was set to: %pM\n",
2828 conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07002829 }
2830 if (priv->ibss_beacon)
2831 dev_kfree_skb(priv->ibss_beacon);
2832
Johannes Berg9d139c82008-07-09 14:40:37 +02002833 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
Zhu Yib481de92007-09-25 17:54:57 -07002834 }
2835
Tomas Winklerfee12472008-04-03 16:05:21 -07002836 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08002837 goto done;
2838
Zhu Yib481de92007-09-25 17:54:57 -07002839 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
2840 !is_multicast_ether_addr(conf->bssid)) {
2841 /* If there is currently a HW scan going on in the background
2842 * then we need to cancel it else the RXON below will fail. */
Tomas Winkler2a421b92008-06-12 09:47:10 +08002843 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002844 IWL_WARN(priv, "Aborted scan still in progress "
Zhu Yib481de92007-09-25 17:54:57 -07002845 "after 100ms\n");
2846 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2847 mutex_unlock(&priv->mutex);
2848 return -EAGAIN;
2849 }
2850 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
2851
2852 /* TODO: Audit driver for usage of these members and see
2853 * if mac80211 deprecates them (priv->bssid looks like it
2854 * shouldn't be there, but I haven't scanned the IBSS code
2855 * to verify) - jpk */
2856 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
2857
Johannes Berg05c914f2008-09-11 00:01:58 +02002858 if (priv->iw_mode == NL80211_IFTYPE_AP)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002859 iwl_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002860 else {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002861 rc = iwl_commit_rxon(priv);
Johannes Berg05c914f2008-09-11 00:01:58 +02002862 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002863 iwl_rxon_add_station(
Zhu Yib481de92007-09-25 17:54:57 -07002864 priv, priv->active_rxon.bssid_addr, 1);
2865 }
2866
2867 } else {
Tomas Winkler2a421b92008-06-12 09:47:10 +08002868 iwl_scan_cancel_timeout(priv, 100);
Zhu Yib481de92007-09-25 17:54:57 -07002869 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002870 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002871 }
2872
Mohamed Abbasfde35712007-11-29 11:10:15 +08002873 done:
Zhu Yib481de92007-09-25 17:54:57 -07002874 IWL_DEBUG_MAC80211("leave\n");
2875 mutex_unlock(&priv->mutex);
2876
2877 return 0;
2878}
2879
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002880static void iwl_configure_filter(struct ieee80211_hw *hw,
Johannes Berg4150c572007-09-17 01:29:23 -04002881 unsigned int changed_flags,
2882 unsigned int *total_flags,
2883 int mc_count, struct dev_addr_list *mc_list)
2884{
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08002885 struct iwl_priv *priv = hw->priv;
Zhu, Yi352bc8d2008-11-12 13:14:09 -08002886 __le32 *filter_flags = &priv->staging_rxon.filter_flags;
Rick Farrington25b3f572008-06-30 17:23:28 +08002887
Zhu, Yi352bc8d2008-11-12 13:14:09 -08002888 IWL_DEBUG_MAC80211("Enter: changed: 0x%x, total: 0x%x\n",
2889 changed_flags, *total_flags);
2890
2891 if (changed_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) {
2892 if (*total_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS))
2893 *filter_flags |= RXON_FILTER_PROMISC_MSK;
2894 else
2895 *filter_flags &= ~RXON_FILTER_PROMISC_MSK;
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08002896 }
Zhu, Yi352bc8d2008-11-12 13:14:09 -08002897 if (changed_flags & FIF_ALLMULTI) {
2898 if (*total_flags & FIF_ALLMULTI)
2899 *filter_flags |= RXON_FILTER_ACCEPT_GRP_MSK;
2900 else
2901 *filter_flags &= ~RXON_FILTER_ACCEPT_GRP_MSK;
2902 }
2903 if (changed_flags & FIF_CONTROL) {
2904 if (*total_flags & FIF_CONTROL)
2905 *filter_flags |= RXON_FILTER_CTL2HOST_MSK;
2906 else
2907 *filter_flags &= ~RXON_FILTER_CTL2HOST_MSK;
2908 }
2909 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
2910 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
2911 *filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
2912 else
2913 *filter_flags &= ~RXON_FILTER_BCON_AWARE_MSK;
2914 }
2915
2916 /* We avoid iwl_commit_rxon here to commit the new filter flags
2917 * since mac80211 will call ieee80211_hw_config immediately.
2918 * (mc_list is not supported at this time). Otherwise, we need to
2919 * queue a background iwl_commit_rxon work.
2920 */
2921
2922 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
Rick Farrington25b3f572008-06-30 17:23:28 +08002923 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
Johannes Berg4150c572007-09-17 01:29:23 -04002924}
2925
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002926static void iwl_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07002927 struct ieee80211_if_init_conf *conf)
2928{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002929 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002930
2931 IWL_DEBUG_MAC80211("enter\n");
2932
2933 mutex_lock(&priv->mutex);
Mohamed Abbas948c1712007-10-25 17:15:45 +08002934
Tomas Winklerfee12472008-04-03 16:05:21 -07002935 if (iwl_is_ready_rf(priv)) {
Tomas Winkler2a421b92008-06-12 09:47:10 +08002936 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002937 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002938 iwl_commit_rxon(priv);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002939 }
Johannes Berg32bfd352007-12-19 01:31:26 +01002940 if (priv->vif == conf->vif) {
2941 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07002942 memset(priv->bssid, 0, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07002943 }
2944 mutex_unlock(&priv->mutex);
2945
2946 IWL_DEBUG_MAC80211("leave\n");
2947
2948}
Johannes Berg471b3ef2007-12-28 14:32:58 +01002949
Tomas Winkler3109ece2008-03-28 16:33:35 -07002950#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002951static void iwl_bss_info_changed(struct ieee80211_hw *hw,
Johannes Berg471b3ef2007-12-28 14:32:58 +01002952 struct ieee80211_vif *vif,
2953 struct ieee80211_bss_conf *bss_conf,
2954 u32 changes)
Tomas Winkler220173b2007-10-16 00:50:25 +02002955{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002956 struct iwl_priv *priv = hw->priv;
Tomas Winkler220173b2007-10-16 00:50:25 +02002957
Tomas Winkler3109ece2008-03-28 16:33:35 -07002958 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
2959
Johannes Berg471b3ef2007-12-28 14:32:58 +01002960 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07002961 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
2962 bss_conf->use_short_preamble);
Johannes Berg471b3ef2007-12-28 14:32:58 +01002963 if (bss_conf->use_short_preamble)
Tomas Winkler220173b2007-10-16 00:50:25 +02002964 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2965 else
2966 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2967 }
2968
Johannes Berg471b3ef2007-12-28 14:32:58 +01002969 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07002970 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
Johannes Berg8318d782008-01-24 19:38:38 +01002971 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Tomas Winkler220173b2007-10-16 00:50:25 +02002972 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
2973 else
2974 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
2975 }
2976
Tomas Winkler98952d52008-03-28 16:33:33 -07002977 if (changes & BSS_CHANGED_HT) {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002978 iwl_ht_conf(priv, bss_conf);
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07002979 iwl_set_rxon_chain(priv);
Tomas Winkler98952d52008-03-28 16:33:33 -07002980 }
2981
Johannes Berg471b3ef2007-12-28 14:32:58 +01002982 if (changes & BSS_CHANGED_ASSOC) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07002983 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
Reinette Chatre508e32e2008-04-14 21:16:13 -07002984 /* This should never happen as this function should
2985 * never be called from interrupt context. */
2986 if (WARN_ON_ONCE(in_interrupt()))
2987 return;
Tomas Winkler3109ece2008-03-28 16:33:35 -07002988 if (bss_conf->assoc) {
2989 priv->assoc_id = bss_conf->aid;
2990 priv->beacon_int = bss_conf->beacon_int;
Tomas Winklerb5d7be52008-07-19 04:41:24 +03002991 priv->power_data.dtim_period = bss_conf->dtim_period;
Tomas Winkler3109ece2008-03-28 16:33:35 -07002992 priv->timestamp = bss_conf->timestamp;
2993 priv->assoc_capability = bss_conf->assoc_capability;
Tomas Winkler9ccacb82008-09-16 14:01:03 +08002994
2995 /* we have just associated, don't start scan too early
2996 * leave time for EAPOL exchange to complete
2997 */
Tomas Winkler3109ece2008-03-28 16:33:35 -07002998 priv->next_scan_jiffies = jiffies +
2999 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
Reinette Chatre508e32e2008-04-14 21:16:13 -07003000 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003001 iwl_post_associate(priv);
Reinette Chatre508e32e2008-04-14 21:16:13 -07003002 mutex_unlock(&priv->mutex);
Tomas Winkler3109ece2008-03-28 16:33:35 -07003003 } else {
3004 priv->assoc_id = 0;
3005 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
3006 }
3007 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
3008 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
Tomas Winkler7e8c5192008-04-15 16:01:43 -07003009 iwl_send_rxon_assoc(priv);
Johannes Berg471b3ef2007-12-28 14:32:58 +01003010 }
3011
Tomas Winkler220173b2007-10-16 00:50:25 +02003012}
Zhu Yib481de92007-09-25 17:54:57 -07003013
Tomas Winklercb43dc22008-09-03 11:26:23 +08003014static int iwl_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t ssid_len)
Zhu Yib481de92007-09-25 17:54:57 -07003015{
Zhu Yib481de92007-09-25 17:54:57 -07003016 unsigned long flags;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003017 struct iwl_priv *priv = hw->priv;
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003018 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003019
3020 IWL_DEBUG_MAC80211("enter\n");
3021
mabbas052c4b92007-10-25 17:15:43 +08003022 mutex_lock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07003023 spin_lock_irqsave(&priv->lock, flags);
3024
Tomas Winklerfee12472008-04-03 16:05:21 -07003025 if (!iwl_is_ready_rf(priv)) {
Tomas Winklercb43dc22008-09-03 11:26:23 +08003026 ret = -EIO;
Zhu Yib481de92007-09-25 17:54:57 -07003027 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
3028 goto out_unlock;
3029 }
3030
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003031 /* We don't schedule scan within next_scan_jiffies period.
3032 * Avoid scanning during possible EAPOL exchange, return
3033 * success immediately.
3034 */
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003035 if (priv->next_scan_jiffies &&
Tomas Winklercb43dc22008-09-03 11:26:23 +08003036 time_after(priv->next_scan_jiffies, jiffies)) {
Ron Rindjunsky681c0052008-09-03 11:26:25 +08003037 IWL_DEBUG_SCAN("scan rejected: within next scan period\n");
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003038 queue_work(priv->workqueue, &priv->scan_completed);
3039 ret = 0;
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003040 goto out_unlock;
3041 }
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003042
Zhu Yib481de92007-09-25 17:54:57 -07003043 /* if we just finished scan ask for delay */
Ron Rindjunsky681c0052008-09-03 11:26:25 +08003044 if (iwl_is_associated(priv) && priv->last_scan_jiffies &&
Tomas Winklercb43dc22008-09-03 11:26:23 +08003045 time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN, jiffies)) {
Ron Rindjunsky681c0052008-09-03 11:26:25 +08003046 IWL_DEBUG_SCAN("scan rejected: within previous scan period\n");
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003047 queue_work(priv->workqueue, &priv->scan_completed);
3048 ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003049 goto out_unlock;
3050 }
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003051
Tomas Winklercb43dc22008-09-03 11:26:23 +08003052 if (ssid_len) {
Zhu Yib481de92007-09-25 17:54:57 -07003053 priv->one_direct_scan = 1;
Tomas Winklercb43dc22008-09-03 11:26:23 +08003054 priv->direct_ssid_len = min_t(u8, ssid_len, IW_ESSID_MAX_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07003055 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
Tomas Winklercb43dc22008-09-03 11:26:23 +08003056 } else {
Mohamed Abbas948c1712007-10-25 17:15:45 +08003057 priv->one_direct_scan = 0;
Tomas Winklercb43dc22008-09-03 11:26:23 +08003058 }
Zhu Yib481de92007-09-25 17:54:57 -07003059
Tomas Winklercb43dc22008-09-03 11:26:23 +08003060 ret = iwl_scan_initiate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003061
3062 IWL_DEBUG_MAC80211("leave\n");
3063
3064out_unlock:
3065 spin_unlock_irqrestore(&priv->lock, flags);
mabbas052c4b92007-10-25 17:15:43 +08003066 mutex_unlock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07003067
Tomas Winklercb43dc22008-09-03 11:26:23 +08003068 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003069}
3070
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003071static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw,
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003072 struct ieee80211_key_conf *keyconf, const u8 *addr,
3073 u32 iv32, u16 *phase1key)
3074{
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003075
Tomas Winkler9f586712008-11-12 13:14:05 -08003076 struct iwl_priv *priv = hw->priv;
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003077 IWL_DEBUG_MAC80211("enter\n");
3078
Tomas Winkler9f586712008-11-12 13:14:05 -08003079 iwl_update_tkip_key(priv, keyconf, addr, iv32, phase1key);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003080
3081 IWL_DEBUG_MAC80211("leave\n");
3082}
3083
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003084static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01003085 struct ieee80211_vif *vif,
3086 struct ieee80211_sta *sta,
Zhu Yib481de92007-09-25 17:54:57 -07003087 struct ieee80211_key_conf *key)
3088{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003089 struct iwl_priv *priv = hw->priv;
Winkler, Tomas42986792009-01-19 15:30:22 -08003090 const u8 *addr;
3091 int ret;
3092 u8 sta_id;
3093 bool is_default_wep_key = false;
Zhu Yib481de92007-09-25 17:54:57 -07003094
3095 IWL_DEBUG_MAC80211("enter\n");
3096
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07003097 if (priv->hw_params.sw_crypto) {
Zhu Yib481de92007-09-25 17:54:57 -07003098 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
3099 return -EOPNOTSUPP;
3100 }
Winkler, Tomas42986792009-01-19 15:30:22 -08003101 addr = sta ? sta->addr : iwl_bcast_addr;
Tomas Winkler947b13a2008-04-16 16:34:48 -07003102 sta_id = iwl_find_station(priv, addr);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003103 if (sta_id == IWL_INVALID_STATION) {
Johannes Berge1749612008-10-27 15:59:26 -07003104 IWL_DEBUG_MAC80211("leave - %pM not in station map.\n",
3105 addr);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003106 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003107
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003108 }
Zhu Yib481de92007-09-25 17:54:57 -07003109
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003110 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08003111 iwl_scan_cancel_timeout(priv, 100);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003112 mutex_unlock(&priv->mutex);
3113
3114 /* If we are getting WEP group key and we didn't receive any key mapping
3115 * so far, we are in legacy wep mode (group key only), otherwise we are
3116 * in 1X mode.
3117 * In legacy wep mode, we use another host command to the uCode */
Tomas Winkler5425e492008-04-15 16:01:38 -07003118 if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
Johannes Berg05c914f2008-09-11 00:01:58 +02003119 priv->iw_mode != NL80211_IFTYPE_AP) {
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003120 if (cmd == SET_KEY)
3121 is_default_wep_key = !priv->key_mapping_key;
3122 else
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +08003123 is_default_wep_key =
3124 (key->hw_key_idx == HW_KEY_DEFAULT);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003125 }
mabbas052c4b92007-10-25 17:15:43 +08003126
Zhu Yib481de92007-09-25 17:54:57 -07003127 switch (cmd) {
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003128 case SET_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003129 if (is_default_wep_key)
3130 ret = iwl_set_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003131 else
Emmanuel Grumbach74805132008-04-14 21:16:09 -07003132 ret = iwl_set_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003133
3134 IWL_DEBUG_MAC80211("enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003135 break;
3136 case DISABLE_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003137 if (is_default_wep_key)
3138 ret = iwl_remove_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003139 else
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07003140 ret = iwl_remove_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003141
3142 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003143 break;
3144 default:
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003145 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003146 }
3147
3148 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003149
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003150 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003151}
3152
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003153static int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
Zhu Yib481de92007-09-25 17:54:57 -07003154 const struct ieee80211_tx_queue_params *params)
3155{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003156 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003157 unsigned long flags;
3158 int q;
Zhu Yib481de92007-09-25 17:54:57 -07003159
3160 IWL_DEBUG_MAC80211("enter\n");
3161
Tomas Winklerfee12472008-04-03 16:05:21 -07003162 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003163 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3164 return -EIO;
3165 }
3166
3167 if (queue >= AC_NUM) {
3168 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
3169 return 0;
3170 }
3171
Zhu Yib481de92007-09-25 17:54:57 -07003172 q = AC_NUM - 1 - queue;
3173
3174 spin_lock_irqsave(&priv->lock, flags);
3175
3176 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
3177 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
3178 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
3179 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7b2008-02-10 16:49:38 +01003180 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07003181
3182 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
3183 priv->qos_data.qos_active = 1;
3184
Johannes Berg05c914f2008-09-11 00:01:58 +02003185 if (priv->iw_mode == NL80211_IFTYPE_AP)
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08003186 iwl_activate_qos(priv, 1);
Tomas Winkler3109ece2008-03-28 16:33:35 -07003187 else if (priv->assoc_id && iwl_is_associated(priv))
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08003188 iwl_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003189
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08003190 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -07003191
Zhu Yib481de92007-09-25 17:54:57 -07003192 IWL_DEBUG_MAC80211("leave\n");
3193 return 0;
3194}
3195
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003196static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
Tomas Winklerd783b062008-07-18 13:53:02 +08003197 enum ieee80211_ampdu_mlme_action action,
Johannes Berg17741cd2008-09-11 00:02:02 +02003198 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
Tomas Winklerd783b062008-07-18 13:53:02 +08003199{
3200 struct iwl_priv *priv = hw->priv;
Tomas Winklerd783b062008-07-18 13:53:02 +08003201
Johannes Berge1749612008-10-27 15:59:26 -07003202 IWL_DEBUG_HT("A-MPDU action on addr %pM tid %d\n",
3203 sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08003204
3205 if (!(priv->cfg->sku & IWL_SKU_N))
3206 return -EACCES;
3207
3208 switch (action) {
3209 case IEEE80211_AMPDU_RX_START:
3210 IWL_DEBUG_HT("start Rx\n");
Tomas Winkler9f586712008-11-12 13:14:05 -08003211 return iwl_sta_rx_agg_start(priv, sta->addr, tid, *ssn);
Tomas Winklerd783b062008-07-18 13:53:02 +08003212 case IEEE80211_AMPDU_RX_STOP:
3213 IWL_DEBUG_HT("stop Rx\n");
Tomas Winkler9f586712008-11-12 13:14:05 -08003214 return iwl_sta_rx_agg_stop(priv, sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08003215 case IEEE80211_AMPDU_TX_START:
3216 IWL_DEBUG_HT("start Tx\n");
Johannes Berg17741cd2008-09-11 00:02:02 +02003217 return iwl_tx_agg_start(priv, sta->addr, tid, ssn);
Tomas Winklerd783b062008-07-18 13:53:02 +08003218 case IEEE80211_AMPDU_TX_STOP:
3219 IWL_DEBUG_HT("stop Tx\n");
Johannes Berg17741cd2008-09-11 00:02:02 +02003220 return iwl_tx_agg_stop(priv, sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08003221 default:
3222 IWL_DEBUG_HT("unknown\n");
3223 return -EINVAL;
3224 break;
3225 }
3226 return 0;
3227}
Tomas Winkler9f586712008-11-12 13:14:05 -08003228
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003229static int iwl_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003230 struct ieee80211_tx_queue_stats *stats)
3231{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003232 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003233 int i, avail;
Ron Rindjunsky16466902008-05-05 10:22:50 +08003234 struct iwl_tx_queue *txq;
Tomas Winkler443cfd42008-05-15 13:53:57 +08003235 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07003236 unsigned long flags;
3237
3238 IWL_DEBUG_MAC80211("enter\n");
3239
Tomas Winklerfee12472008-04-03 16:05:21 -07003240 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003241 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3242 return -EIO;
3243 }
3244
3245 spin_lock_irqsave(&priv->lock, flags);
3246
3247 for (i = 0; i < AC_NUM; i++) {
3248 txq = &priv->txq[i];
3249 q = &txq->q;
Tomas Winkler443cfd42008-05-15 13:53:57 +08003250 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07003251
Johannes Berg57ffc582008-04-29 17:18:59 +02003252 stats[i].len = q->n_window - avail;
3253 stats[i].limit = q->n_window - q->high_mark;
3254 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07003255
3256 }
3257 spin_unlock_irqrestore(&priv->lock, flags);
3258
3259 IWL_DEBUG_MAC80211("leave\n");
3260
3261 return 0;
3262}
3263
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003264static int iwl_mac_get_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003265 struct ieee80211_low_level_stats *stats)
3266{
Ester Kummerbf403db2008-05-05 10:22:40 +08003267 struct iwl_priv *priv = hw->priv;
3268
3269 priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003270 IWL_DEBUG_MAC80211("enter\n");
3271 IWL_DEBUG_MAC80211("leave\n");
3272
3273 return 0;
3274}
3275
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003276static void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003277{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003278 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003279 unsigned long flags;
3280
3281 mutex_lock(&priv->mutex);
3282 IWL_DEBUG_MAC80211("enter\n");
3283
Zhu Yib481de92007-09-25 17:54:57 -07003284 spin_lock_irqsave(&priv->lock, flags);
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02003285 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
Zhu Yib481de92007-09-25 17:54:57 -07003286 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -07003287
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003288 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003289
Zhu Yib481de92007-09-25 17:54:57 -07003290 spin_lock_irqsave(&priv->lock, flags);
3291 priv->assoc_id = 0;
3292 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003293 priv->assoc_station_added = 0;
3294
3295 /* new association get rid of ibss beacon skb */
3296 if (priv->ibss_beacon)
3297 dev_kfree_skb(priv->ibss_beacon);
3298
3299 priv->ibss_beacon = NULL;
3300
3301 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler3109ece2008-03-28 16:33:35 -07003302 priv->timestamp = 0;
Johannes Berg05c914f2008-09-11 00:01:58 +02003303 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
Zhu Yib481de92007-09-25 17:54:57 -07003304 priv->beacon_int = 0;
3305
3306 spin_unlock_irqrestore(&priv->lock, flags);
3307
Tomas Winklerfee12472008-04-03 16:05:21 -07003308 if (!iwl_is_ready_rf(priv)) {
Mohamed Abbasfde35712007-11-29 11:10:15 +08003309 IWL_DEBUG_MAC80211("leave - not ready\n");
3310 mutex_unlock(&priv->mutex);
3311 return;
3312 }
3313
mabbas052c4b92007-10-25 17:15:43 +08003314 /* we are restarting association process
3315 * clear RXON_FILTER_ASSOC_MSK bit
3316 */
Johannes Berg05c914f2008-09-11 00:01:58 +02003317 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Tomas Winkler2a421b92008-06-12 09:47:10 +08003318 iwl_scan_cancel_timeout(priv, 100);
mabbas052c4b92007-10-25 17:15:43 +08003319 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003320 iwl_commit_rxon(priv);
mabbas052c4b92007-10-25 17:15:43 +08003321 }
3322
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003323 iwl_power_update_mode(priv, 0);
3324
Zhu Yib481de92007-09-25 17:54:57 -07003325 /* Per mac80211.h: This is only used in IBSS mode... */
Johannes Berg05c914f2008-09-11 00:01:58 +02003326 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
mabbas052c4b92007-10-25 17:15:43 +08003327
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08003328 /* switch to CAM during association period.
3329 * the ucode will block any association/authentication
3330 * frome during assiciation period if it can not hear
3331 * the AP because of PM. the timer enable PM back is
3332 * association do not complete
3333 */
3334 if (priv->hw->conf.channel->flags & (IEEE80211_CHAN_PASSIVE_SCAN |
3335 IEEE80211_CHAN_RADAR))
3336 iwl_power_disable_management(priv, 3000);
3337
Zhu Yib481de92007-09-25 17:54:57 -07003338 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
3339 mutex_unlock(&priv->mutex);
3340 return;
3341 }
3342
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003343 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003344
3345 mutex_unlock(&priv->mutex);
3346
3347 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003348}
3349
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003350static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003351{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003352 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003353 unsigned long flags;
Assaf Krauss2ff75b72008-06-30 17:23:17 +08003354 __le64 timestamp;
Zhu Yib481de92007-09-25 17:54:57 -07003355
Zhu Yib481de92007-09-25 17:54:57 -07003356 IWL_DEBUG_MAC80211("enter\n");
3357
Tomas Winklerfee12472008-04-03 16:05:21 -07003358 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003359 IWL_DEBUG_MAC80211("leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07003360 return -EIO;
3361 }
3362
Johannes Berg05c914f2008-09-11 00:01:58 +02003363 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Zhu Yib481de92007-09-25 17:54:57 -07003364 IWL_DEBUG_MAC80211("leave - not IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07003365 return -EIO;
3366 }
3367
3368 spin_lock_irqsave(&priv->lock, flags);
3369
3370 if (priv->ibss_beacon)
3371 dev_kfree_skb(priv->ibss_beacon);
3372
3373 priv->ibss_beacon = skb;
3374
3375 priv->assoc_id = 0;
Assaf Krauss2ff75b72008-06-30 17:23:17 +08003376 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
Assaf Kraussb94d8ee2008-09-03 11:18:42 +08003377 priv->timestamp = le64_to_cpu(timestamp);
Zhu Yib481de92007-09-25 17:54:57 -07003378
3379 IWL_DEBUG_MAC80211("leave\n");
3380 spin_unlock_irqrestore(&priv->lock, flags);
3381
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003382 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003383
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003384 iwl_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003385
Zhu Yib481de92007-09-25 17:54:57 -07003386
3387 return 0;
3388}
3389
Zhu Yib481de92007-09-25 17:54:57 -07003390/*****************************************************************************
3391 *
3392 * sysfs attributes
3393 *
3394 *****************************************************************************/
3395
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003396#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07003397
3398/*
3399 * The following adds a new attribute to the sysfs representation
Wu, Fengguangc3a739f2008-12-17 16:52:29 +08003400 * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
Zhu Yib481de92007-09-25 17:54:57 -07003401 * used for controlling the debug level.
3402 *
3403 * See the level definitions in iwl for details.
3404 */
3405
Ester Kummer8cf769c2008-05-06 11:05:11 +08003406static ssize_t show_debug_level(struct device *d,
3407 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07003408{
Ester Kummer8cf769c2008-05-06 11:05:11 +08003409 struct iwl_priv *priv = d->driver_data;
3410
3411 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07003412}
Ester Kummer8cf769c2008-05-06 11:05:11 +08003413static ssize_t store_debug_level(struct device *d,
3414 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07003415 const char *buf, size_t count)
3416{
Ester Kummer8cf769c2008-05-06 11:05:11 +08003417 struct iwl_priv *priv = d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003418 unsigned long val;
3419 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003420
Tomas Winkler9257746f2008-09-03 11:26:32 +08003421 ret = strict_strtoul(buf, 0, &val);
3422 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08003423 IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07003424 else
Ester Kummer8cf769c2008-05-06 11:05:11 +08003425 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07003426
3427 return strnlen(buf, count);
3428}
3429
Ester Kummer8cf769c2008-05-06 11:05:11 +08003430static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
3431 show_debug_level, store_debug_level);
3432
Zhu Yib481de92007-09-25 17:54:57 -07003433
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003434#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07003435
Zhu Yib481de92007-09-25 17:54:57 -07003436
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003437static ssize_t show_version(struct device *d,
3438 struct device_attribute *attr, char *buf)
3439{
3440 struct iwl_priv *priv = d->driver_data;
Tomas Winkler885ba202008-05-29 16:34:55 +08003441 struct iwl_alive_resp *palive = &priv->card_alive;
Tomas Winklerf236a262008-06-30 17:23:02 +08003442 ssize_t pos = 0;
3443 u16 eeprom_ver;
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003444
3445 if (palive->is_valid)
Tomas Winklerf236a262008-06-30 17:23:02 +08003446 pos += sprintf(buf + pos,
3447 "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n"
3448 "fw type: 0x%01X 0x%01X\n",
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003449 palive->ucode_major, palive->ucode_minor,
3450 palive->sw_rev[0], palive->sw_rev[1],
3451 palive->ver_type, palive->ver_subtype);
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003452 else
Tomas Winklerf236a262008-06-30 17:23:02 +08003453 pos += sprintf(buf + pos, "fw not loaded\n");
3454
3455 if (priv->eeprom) {
3456 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
3457 pos += sprintf(buf + pos, "EEPROM version: 0x%x\n",
3458 eeprom_ver);
3459 } else {
3460 pos += sprintf(buf + pos, "EEPROM not initialzed\n");
3461 }
3462
3463 return pos;
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003464}
3465
3466static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL);
3467
Zhu Yib481de92007-09-25 17:54:57 -07003468static ssize_t show_temperature(struct device *d,
3469 struct device_attribute *attr, char *buf)
3470{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003471 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003472
Tomas Winklerfee12472008-04-03 16:05:21 -07003473 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003474 return -EAGAIN;
3475
Emmanuel Grumbach91dbc5b2008-06-12 09:47:14 +08003476 return sprintf(buf, "%d\n", priv->temperature);
Zhu Yib481de92007-09-25 17:54:57 -07003477}
3478
3479static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
3480
Zhu Yib481de92007-09-25 17:54:57 -07003481static ssize_t show_tx_power(struct device *d,
3482 struct device_attribute *attr, char *buf)
3483{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003484 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Jay Sternberg91f39e82008-12-17 16:52:34 +08003485
3486 if (!iwl_is_ready_rf(priv))
3487 return sprintf(buf, "off\n");
3488 else
3489 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07003490}
3491
3492static ssize_t store_tx_power(struct device *d,
3493 struct device_attribute *attr,
3494 const char *buf, size_t count)
3495{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003496 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003497 unsigned long val;
3498 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003499
Tomas Winkler9257746f2008-09-03 11:26:32 +08003500 ret = strict_strtoul(buf, 10, &val);
3501 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08003502 IWL_INFO(priv, "%s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07003503 else
Tomas Winkler630fe9b2008-06-12 09:47:08 +08003504 iwl_set_tx_power(priv, val, false);
Zhu Yib481de92007-09-25 17:54:57 -07003505
3506 return count;
3507}
3508
3509static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
3510
3511static ssize_t show_flags(struct device *d,
3512 struct device_attribute *attr, char *buf)
3513{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003514 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003515
3516 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
3517}
3518
3519static ssize_t store_flags(struct device *d,
3520 struct device_attribute *attr,
3521 const char *buf, size_t count)
3522{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003523 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003524 unsigned long val;
3525 u32 flags;
3526 int ret = strict_strtoul(buf, 0, &val);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08003527 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08003528 return ret;
3529 flags = (u32)val;
Zhu Yib481de92007-09-25 17:54:57 -07003530
3531 mutex_lock(&priv->mutex);
3532 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
3533 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08003534 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003535 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003536 else {
Tomas Winkler9257746f2008-09-03 11:26:32 +08003537 IWL_DEBUG_INFO("Commit rxon.flags = 0x%04X\n", flags);
Zhu Yib481de92007-09-25 17:54:57 -07003538 priv->staging_rxon.flags = cpu_to_le32(flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003539 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003540 }
3541 }
3542 mutex_unlock(&priv->mutex);
3543
3544 return count;
3545}
3546
3547static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
3548
3549static ssize_t show_filter_flags(struct device *d,
3550 struct device_attribute *attr, char *buf)
3551{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003552 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003553
3554 return sprintf(buf, "0x%04X\n",
3555 le32_to_cpu(priv->active_rxon.filter_flags));
3556}
3557
3558static ssize_t store_filter_flags(struct device *d,
3559 struct device_attribute *attr,
3560 const char *buf, size_t count)
3561{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003562 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003563 unsigned long val;
3564 u32 filter_flags;
3565 int ret = strict_strtoul(buf, 0, &val);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08003566 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08003567 return ret;
3568 filter_flags = (u32)val;
Zhu Yib481de92007-09-25 17:54:57 -07003569
3570 mutex_lock(&priv->mutex);
3571 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
3572 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08003573 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003574 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003575 else {
3576 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
3577 "0x%04X\n", filter_flags);
3578 priv->staging_rxon.filter_flags =
3579 cpu_to_le32(filter_flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003580 iwl_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003581 }
3582 }
3583 mutex_unlock(&priv->mutex);
3584
3585 return count;
3586}
3587
3588static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
3589 store_filter_flags);
3590
Zhu Yib481de92007-09-25 17:54:57 -07003591static ssize_t store_power_level(struct device *d,
3592 struct device_attribute *attr,
3593 const char *buf, size_t count)
3594{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003595 struct iwl_priv *priv = dev_get_drvdata(d);
Esti Kummer298df1f2008-07-18 13:52:58 +08003596 int ret;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003597 unsigned long mode;
Zhu Yib481de92007-09-25 17:54:57 -07003598
Tomas Winkler9257746f2008-09-03 11:26:32 +08003599
Zhu Yib481de92007-09-25 17:54:57 -07003600 mutex_lock(&priv->mutex);
3601
Tomas Winklerfee12472008-04-03 16:05:21 -07003602 if (!iwl_is_ready(priv)) {
Esti Kummer298df1f2008-07-18 13:52:58 +08003603 ret = -EAGAIN;
Zhu Yib481de92007-09-25 17:54:57 -07003604 goto out;
3605 }
3606
Tomas Winkler9257746f2008-09-03 11:26:32 +08003607 ret = strict_strtoul(buf, 10, &mode);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08003608 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08003609 goto out;
3610
Esti Kummer298df1f2008-07-18 13:52:58 +08003611 ret = iwl_power_set_user_mode(priv, mode);
3612 if (ret) {
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003613 IWL_DEBUG_MAC80211("failed setting power mode.\n");
3614 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003615 }
Esti Kummer298df1f2008-07-18 13:52:58 +08003616 ret = count;
Zhu Yib481de92007-09-25 17:54:57 -07003617
3618 out:
3619 mutex_unlock(&priv->mutex);
Esti Kummer298df1f2008-07-18 13:52:58 +08003620 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003621}
3622
Zhu Yib481de92007-09-25 17:54:57 -07003623static ssize_t show_power_level(struct device *d,
3624 struct device_attribute *attr, char *buf)
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 mode = priv->power_data.user_power_setting;
3628 int system = priv->power_data.system_power_setting;
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003629 int level = priv->power_data.power_mode;
Zhu Yib481de92007-09-25 17:54:57 -07003630 char *p = buf;
3631
Esti Kummer298df1f2008-07-18 13:52:58 +08003632 switch (system) {
3633 case IWL_POWER_SYS_AUTO:
3634 p += sprintf(p, "SYSTEM:auto");
Zhu Yib481de92007-09-25 17:54:57 -07003635 break;
Esti Kummer298df1f2008-07-18 13:52:58 +08003636 case IWL_POWER_SYS_AC:
3637 p += sprintf(p, "SYSTEM:ac");
Zhu Yib481de92007-09-25 17:54:57 -07003638 break;
Esti Kummer298df1f2008-07-18 13:52:58 +08003639 case IWL_POWER_SYS_BATTERY:
3640 p += sprintf(p, "SYSTEM:battery");
3641 break;
Zhu Yib481de92007-09-25 17:54:57 -07003642 }
Esti Kummer298df1f2008-07-18 13:52:58 +08003643
Abhijeet Kolekarc3056062008-11-12 13:14:08 -08003644 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
3645 "fixed" : "auto");
Esti Kummer298df1f2008-07-18 13:52:58 +08003646 p += sprintf(p, "\tINDEX:%d", level);
3647 p += sprintf(p, "\n");
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003648 return p - buf + 1;
Zhu Yib481de92007-09-25 17:54:57 -07003649}
3650
3651static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
3652 store_power_level);
3653
Zhu Yib481de92007-09-25 17:54:57 -07003654
3655static ssize_t show_statistics(struct device *d,
3656 struct device_attribute *attr, char *buf)
3657{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003658 struct iwl_priv *priv = dev_get_drvdata(d);
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08003659 u32 size = sizeof(struct iwl_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07003660 u32 len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003661 u8 *data = (u8 *)&priv->statistics;
Zhu Yib481de92007-09-25 17:54:57 -07003662 int rc = 0;
3663
Tomas Winklerfee12472008-04-03 16:05:21 -07003664 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003665 return -EAGAIN;
3666
3667 mutex_lock(&priv->mutex);
Emmanuel Grumbach49ea8592008-04-15 16:01:37 -07003668 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003669 mutex_unlock(&priv->mutex);
3670
3671 if (rc) {
3672 len = sprintf(buf,
3673 "Error sending statistics request: 0x%08X\n", rc);
3674 return len;
3675 }
3676
3677 while (size && (PAGE_SIZE - len)) {
3678 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
3679 PAGE_SIZE - len, 1);
3680 len = strlen(buf);
3681 if (PAGE_SIZE - len)
3682 buf[len++] = '\n';
3683
3684 ofs += 16;
3685 size -= min(size, 16U);
3686 }
3687
3688 return len;
3689}
3690
3691static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
3692
Zhu Yib481de92007-09-25 17:54:57 -07003693
Zhu Yib481de92007-09-25 17:54:57 -07003694/*****************************************************************************
3695 *
3696 * driver setup and teardown
3697 *
3698 *****************************************************************************/
3699
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003700static void iwl_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003701{
3702 priv->workqueue = create_workqueue(DRV_NAME);
3703
3704 init_waitqueue_head(&priv->wait_command_queue);
3705
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003706 INIT_WORK(&priv->up, iwl_bg_up);
3707 INIT_WORK(&priv->restart, iwl_bg_restart);
3708 INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish);
3709 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
3710 INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08003711 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08003712 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
3713 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
Tomas Winkler2a421b92008-06-12 09:47:10 +08003714
Tomas Winkler2a421b92008-06-12 09:47:10 +08003715 iwl_setup_scan_deferred_work(priv);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08003716 iwl_setup_power_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003717
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003718 if (priv->cfg->ops->lib->setup_deferred_work)
3719 priv->cfg->ops->lib->setup_deferred_work(priv);
3720
3721 init_timer(&priv->statistics_periodic);
3722 priv->statistics_periodic.data = (unsigned long)priv;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003723 priv->statistics_periodic.function = iwl_bg_statistics_periodic;
Zhu Yib481de92007-09-25 17:54:57 -07003724
3725 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003726 iwl_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07003727}
3728
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003729static void iwl_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003730{
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003731 if (priv->cfg->ops->lib->cancel_deferred_work)
3732 priv->cfg->ops->lib->cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003733
Joonwoo Park3ae6a052007-11-29 10:43:16 +09003734 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07003735 cancel_delayed_work(&priv->scan_check);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08003736 cancel_delayed_work_sync(&priv->set_power_save);
Zhu Yib481de92007-09-25 17:54:57 -07003737 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07003738 cancel_work_sync(&priv->beacon_update);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003739 del_timer_sync(&priv->statistics_periodic);
Zhu Yib481de92007-09-25 17:54:57 -07003740}
3741
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003742static struct attribute *iwl_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07003743 &dev_attr_flags.attr,
3744 &dev_attr_filter_flags.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003745 &dev_attr_power_level.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003746 &dev_attr_statistics.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003747 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003748 &dev_attr_tx_power.attr,
Ester Kummer8cf769c2008-05-06 11:05:11 +08003749#ifdef CONFIG_IWLWIFI_DEBUG
3750 &dev_attr_debug_level.attr,
3751#endif
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003752 &dev_attr_version.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003753
3754 NULL
3755};
3756
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003757static struct attribute_group iwl_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07003758 .name = NULL, /* put in device directory */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003759 .attrs = iwl_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07003760};
3761
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003762static struct ieee80211_ops iwl_hw_ops = {
3763 .tx = iwl_mac_tx,
3764 .start = iwl_mac_start,
3765 .stop = iwl_mac_stop,
3766 .add_interface = iwl_mac_add_interface,
3767 .remove_interface = iwl_mac_remove_interface,
3768 .config = iwl_mac_config,
3769 .config_interface = iwl_mac_config_interface,
3770 .configure_filter = iwl_configure_filter,
3771 .set_key = iwl_mac_set_key,
3772 .update_tkip_key = iwl_mac_update_tkip_key,
3773 .get_stats = iwl_mac_get_stats,
3774 .get_tx_stats = iwl_mac_get_tx_stats,
3775 .conf_tx = iwl_mac_conf_tx,
3776 .reset_tsf = iwl_mac_reset_tsf,
3777 .bss_info_changed = iwl_bss_info_changed,
3778 .ampdu_action = iwl_mac_ampdu_action,
Tomas Winklercb43dc22008-09-03 11:26:23 +08003779 .hw_scan = iwl_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07003780};
3781
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003782static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07003783{
3784 int err = 0;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003785 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07003786 struct ieee80211_hw *hw;
Tomas Winkler82b9a122008-03-04 18:09:30 -08003787 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003788 unsigned long flags;
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003789 u16 pci_cmd;
Zhu Yib481de92007-09-25 17:54:57 -07003790
Assaf Krauss316c30d2008-03-14 10:38:46 -07003791 /************************
3792 * 1. Allocating HW data
3793 ************************/
3794
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003795 /* Disabling hardware scan means that mac80211 will perform scans
3796 * "the hard way", rather than using device's scan. */
Assaf Krauss1ea87392008-03-18 14:57:50 -07003797 if (cfg->mod_params->disable_hw_scan) {
Ester Kummerbf403db2008-05-05 10:22:40 +08003798 if (cfg->mod_params->debug & IWL_DL_INFO)
3799 dev_printk(KERN_DEBUG, &(pdev->dev),
3800 "Disabling hw_scan\n");
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003801 iwl_hw_ops.hw_scan = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07003802 }
3803
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003804 hw = iwl_alloc_all(cfg, &iwl_hw_ops);
Assaf Krauss1d0a0822008-03-14 10:38:48 -07003805 if (!hw) {
Zhu Yib481de92007-09-25 17:54:57 -07003806 err = -ENOMEM;
3807 goto out;
3808 }
Assaf Krauss1d0a0822008-03-14 10:38:48 -07003809 priv = hw->priv;
3810 /* At this point both hw and priv are allocated. */
3811
Zhu Yib481de92007-09-25 17:54:57 -07003812 SET_IEEE80211_DEV(hw, &pdev->dev);
3813
3814 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
Tomas Winkler82b9a122008-03-04 18:09:30 -08003815 priv->cfg = cfg;
Zhu Yib481de92007-09-25 17:54:57 -07003816 priv->pci_dev = pdev;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003817
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003818#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08003819 priv->debug_level = priv->cfg->mod_params->debug;
Zhu Yib481de92007-09-25 17:54:57 -07003820 atomic_set(&priv->restrict_refcnt, 0);
3821#endif
Zhu Yib481de92007-09-25 17:54:57 -07003822
Assaf Krauss316c30d2008-03-14 10:38:46 -07003823 /**************************
3824 * 2. Initializing PCI bus
3825 **************************/
3826 if (pci_enable_device(pdev)) {
3827 err = -ENODEV;
3828 goto out_ieee80211_free_hw;
3829 }
3830
3831 pci_set_master(pdev);
3832
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003833 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
Assaf Krauss316c30d2008-03-14 10:38:46 -07003834 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003835 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003836 if (err) {
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003837 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003838 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003839 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003840 /* both attempts failed: */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003841 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08003842 IWL_WARN(priv, "No suitable DMA available.\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07003843 goto out_pci_disable_device;
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003844 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07003845 }
3846
3847 err = pci_request_regions(pdev, DRV_NAME);
3848 if (err)
3849 goto out_pci_disable_device;
3850
3851 pci_set_drvdata(pdev, priv);
3852
Assaf Krauss316c30d2008-03-14 10:38:46 -07003853
3854 /***********************
3855 * 3. Read REV register
3856 ***********************/
3857 priv->hw_base = pci_iomap(pdev, 0, 0);
3858 if (!priv->hw_base) {
3859 err = -ENODEV;
3860 goto out_pci_release_regions;
3861 }
3862
3863 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
3864 (unsigned long long) pci_resource_len(pdev, 0));
3865 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
3866
Tomas Winklerb661c812008-04-23 17:14:54 -07003867 iwl_hw_detect(priv);
Tomas Winkler978785a2008-12-19 10:37:31 +08003868 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s REV=0x%X\n",
Tomas Winklerb661c812008-04-23 17:14:54 -07003869 priv->cfg->name, priv->hw_rev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003870
Tomas Winklere7b63582008-09-03 11:26:49 +08003871 /* We disable the RETRY_TIMEOUT register (0x41) to keep
3872 * PCI Tx retries from interfering with C3 CPU state */
3873 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
3874
Tomas Winkler91238712008-04-23 17:14:53 -07003875 /* amp init */
3876 err = priv->cfg->ops->lib->apm_ops.init(priv);
3877 if (err < 0) {
3878 IWL_DEBUG_INFO("Failed to init APMG\n");
3879 goto out_iounmap;
3880 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07003881 /*****************
3882 * 4. Read EEPROM
3883 *****************/
Assaf Krauss316c30d2008-03-14 10:38:46 -07003884 /* Read the EEPROM */
3885 err = iwl_eeprom_init(priv);
3886 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003887 IWL_ERR(priv, "Unable to init EEPROM\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07003888 goto out_iounmap;
3889 }
Tomas Winkler8614f362008-04-23 17:14:55 -07003890 err = iwl_eeprom_check_version(priv);
3891 if (err)
3892 goto out_iounmap;
3893
Ron Rindjunsky02883012008-05-15 13:53:53 +08003894 /* extract MAC Address */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003895 iwl_eeprom_get_mac(priv, priv->mac_addr);
Johannes Berge1749612008-10-27 15:59:26 -07003896 IWL_DEBUG_INFO("MAC address: %pM\n", priv->mac_addr);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003897 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
3898
3899 /************************
3900 * 5. Setup HW constants
3901 ************************/
Ron Rindjunskyda154e32008-06-30 17:23:20 +08003902 if (iwl_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003903 IWL_ERR(priv, "failed to set hw parameters\n");
Tomas Winkler073d3f52008-04-21 15:41:52 -07003904 goto out_free_eeprom;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003905 }
3906
3907 /*******************
Tomas Winkler6ba87952008-05-15 13:54:17 +08003908 * 6. Setup priv
Assaf Krauss316c30d2008-03-14 10:38:46 -07003909 *******************/
Zhu Yib481de92007-09-25 17:54:57 -07003910
Tomas Winkler6ba87952008-05-15 13:54:17 +08003911 err = iwl_init_drv(priv);
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003912 if (err)
Ron Rindjunsky399f4902008-04-23 17:14:56 -07003913 goto out_free_eeprom;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003914 /* At this point both hw and priv are initialized. */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003915
3916 /**********************************
3917 * 7. Initialize module parameters
3918 **********************************/
3919
3920 /* Disable radio (SW RF KILL) via parameter when loading driver */
Assaf Krauss1ea87392008-03-18 14:57:50 -07003921 if (priv->cfg->mod_params->disable) {
Assaf Krauss316c30d2008-03-14 10:38:46 -07003922 set_bit(STATUS_RF_KILL_SW, &priv->status);
3923 IWL_DEBUG_INFO("Radio disabled.\n");
3924 }
3925
Assaf Krauss316c30d2008-03-14 10:38:46 -07003926 /********************
3927 * 8. Setup services
3928 ********************/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003929 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003930 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003931 spin_unlock_irqrestore(&priv->lock, flags);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003932
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003933 pci_enable_msi(priv->pci_dev);
3934
3935 err = request_irq(priv->pci_dev->irq, iwl_isr, IRQF_SHARED,
3936 DRV_NAME, priv);
3937 if (err) {
3938 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
3939 goto out_disable_msi;
3940 }
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003941 err = sysfs_create_group(&pdev->dev.kobj, &iwl_attribute_group);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003942 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003943 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Tomas Winkler6ba87952008-05-15 13:54:17 +08003944 goto out_uninit_drv;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003945 }
3946
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003947 iwl_setup_deferred_work(priv);
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08003948 iwl_setup_rx_handlers(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003949
Tomas Winkler6ba87952008-05-15 13:54:17 +08003950 /**********************************
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003951 * 9. Setup and register mac80211
Tomas Winkler6ba87952008-05-15 13:54:17 +08003952 **********************************/
3953
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003954 /* enable interrupts if needed: hw bug w/a */
3955 pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd);
3956 if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
3957 pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
3958 pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
3959 }
3960
3961 iwl_enable_interrupts(priv);
3962
Tomas Winkler6ba87952008-05-15 13:54:17 +08003963 err = iwl_setup_mac(priv);
3964 if (err)
3965 goto out_remove_sysfs;
3966
3967 err = iwl_dbgfs_register(priv, DRV_NAME);
3968 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08003969 IWL_ERR(priv, "failed to create debugfs files\n");
Tomas Winkler6ba87952008-05-15 13:54:17 +08003970
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003971 /* If platform's RF_KILL switch is NOT set to KILL */
3972 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3973 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3974 else
3975 set_bit(STATUS_RF_KILL_HW, &priv->status);
3976
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08003977 err = iwl_rfkill_init(priv);
3978 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08003979 IWL_ERR(priv, "Unable to initialize RFKILL system. "
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08003980 "Ignoring error: %d\n", err);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003981 else
3982 iwl_rfkill_set_hw_state(priv);
3983
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08003984 iwl_power_initialize(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003985 return 0;
3986
Assaf Krauss316c30d2008-03-14 10:38:46 -07003987 out_remove_sysfs:
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003988 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003989 out_disable_msi:
3990 pci_disable_msi(priv->pci_dev);
3991 pci_disable_device(priv->pci_dev);
Tomas Winkler6ba87952008-05-15 13:54:17 +08003992 out_uninit_drv:
3993 iwl_uninit_drv(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07003994 out_free_eeprom:
3995 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003996 out_iounmap:
3997 pci_iounmap(pdev, priv->hw_base);
3998 out_pci_release_regions:
3999 pci_release_regions(pdev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004000 pci_set_drvdata(pdev, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07004001 out_pci_disable_device:
4002 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004003 out_ieee80211_free_hw:
4004 ieee80211_free_hw(priv->hw);
4005 out:
4006 return err;
4007}
4008
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004009static void __devexit iwl_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004010{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004011 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004012 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07004013
4014 if (!priv)
4015 return;
4016
4017 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
4018
Emmanuel Grumbach67249622008-05-29 16:35:26 +08004019 iwl_dbgfs_unregister(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004020 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
Emmanuel Grumbach67249622008-05-29 16:35:26 +08004021
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004022 /* ieee80211_unregister_hw call wil cause iwl_mac_stop to
4023 * to be called and iwl_down since we are removing the device
Gregory Greenman0b124c32008-09-03 11:18:50 +08004024 * we need to set STATUS_EXIT_PENDING bit.
4025 */
4026 set_bit(STATUS_EXIT_PENDING, &priv->status);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07004027 if (priv->mac80211_registered) {
4028 ieee80211_unregister_hw(priv->hw);
4029 priv->mac80211_registered = 0;
Gregory Greenman0b124c32008-09-03 11:18:50 +08004030 } else {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004031 iwl_down(priv);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07004032 }
4033
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004034 /* make sure we flush any pending irq or
4035 * tasklet for the driver
4036 */
4037 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004038 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004039 spin_unlock_irqrestore(&priv->lock, flags);
4040
4041 iwl_synchronize_irq(priv);
4042
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08004043 iwl_rfkill_unregister(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004044 iwl_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004045
4046 if (priv->rxq.bd)
Tomas Winklera55360e2008-05-05 10:22:28 +08004047 iwl_rx_queue_free(priv, &priv->rxq);
Ron Rindjunsky1053d352008-05-05 10:22:43 +08004048 iwl_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004049
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08004050 iwl_clear_stations_table(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07004051 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004052
Zhu Yib481de92007-09-25 17:54:57 -07004053
Mohamed Abbas948c1712007-10-25 17:15:45 +08004054 /*netif_stop_queue(dev); */
4055 flush_workqueue(priv->workqueue);
4056
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004057 /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07004058 * priv->workqueue... so we can't take down the workqueue
4059 * until now... */
4060 destroy_workqueue(priv->workqueue);
4061 priv->workqueue = NULL;
4062
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004063 free_irq(priv->pci_dev->irq, priv);
4064 pci_disable_msi(priv->pci_dev);
Zhu Yib481de92007-09-25 17:54:57 -07004065 pci_iounmap(pdev, priv->hw_base);
4066 pci_release_regions(pdev);
4067 pci_disable_device(pdev);
4068 pci_set_drvdata(pdev, NULL);
4069
Tomas Winkler6ba87952008-05-15 13:54:17 +08004070 iwl_uninit_drv(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004071
4072 if (priv->ibss_beacon)
4073 dev_kfree_skb(priv->ibss_beacon);
4074
4075 ieee80211_free_hw(priv->hw);
4076}
4077
4078#ifdef CONFIG_PM
4079
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004080static int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07004081{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004082 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004083
Zhu Yie655b9f2008-01-24 02:19:38 -08004084 if (priv->is_open) {
4085 set_bit(STATUS_IN_SUSPEND, &priv->status);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004086 iwl_mac_stop(priv->hw);
Zhu Yie655b9f2008-01-24 02:19:38 -08004087 priv->is_open = 1;
4088 }
Zhu Yib481de92007-09-25 17:54:57 -07004089
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004090 pci_save_state(pdev);
4091 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004092 pci_set_power_state(pdev, PCI_D3hot);
4093
Zhu Yib481de92007-09-25 17:54:57 -07004094 return 0;
4095}
4096
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004097static int iwl_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004098{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004099 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004100
Zhu Yib481de92007-09-25 17:54:57 -07004101 pci_set_power_state(pdev, PCI_D0);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004102 pci_enable_device(pdev);
4103 pci_restore_state(pdev);
4104 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004105
Zhu Yie655b9f2008-01-24 02:19:38 -08004106 if (priv->is_open)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004107 iwl_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07004108
Zhu Yie655b9f2008-01-24 02:19:38 -08004109 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004110 return 0;
4111}
4112
4113#endif /* CONFIG_PM */
4114
4115/*****************************************************************************
4116 *
4117 * driver and module entry point
4118 *
4119 *****************************************************************************/
4120
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004121/* Hardware specific file defines the PCI IDs table for that hardware module */
4122static struct pci_device_id iwl_hw_card_ids[] = {
Tomas Winkler4fc22b22008-07-21 18:54:42 +03004123#ifdef CONFIG_IWL4965
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004124 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
4125 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
Tomas Winkler4fc22b22008-07-21 18:54:42 +03004126#endif /* CONFIG_IWL4965 */
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004127#ifdef CONFIG_IWL5000
Esti Kummer47408632008-07-11 11:53:30 +08004128 {IWL_PCI_DEVICE(0x4232, 0x1205, iwl5100_bg_cfg)},
4129 {IWL_PCI_DEVICE(0x4232, 0x1305, iwl5100_bg_cfg)},
4130 {IWL_PCI_DEVICE(0x4232, 0x1206, iwl5100_abg_cfg)},
4131 {IWL_PCI_DEVICE(0x4232, 0x1306, iwl5100_abg_cfg)},
4132 {IWL_PCI_DEVICE(0x4232, 0x1326, iwl5100_abg_cfg)},
4133 {IWL_PCI_DEVICE(0x4237, 0x1216, iwl5100_abg_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004134 {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)},
Esti Kummer47408632008-07-11 11:53:30 +08004135 {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)},
4136 {IWL_PCI_DEVICE(0x4236, PCI_ANY_ID, iwl5300_agn_cfg)},
4137 {IWL_PCI_DEVICE(0x4237, PCI_ANY_ID, iwl5100_agn_cfg)},
Tomas Winklere96a8492008-09-11 11:45:20 +08004138/* 5350 WiFi/WiMax */
4139 {IWL_PCI_DEVICE(0x423A, 0x1001, iwl5350_agn_cfg)},
4140 {IWL_PCI_DEVICE(0x423A, 0x1021, iwl5350_agn_cfg)},
4141 {IWL_PCI_DEVICE(0x423B, 0x1011, iwl5350_agn_cfg)},
Tomas Winkler7100e922008-12-01 16:32:18 -08004142/* 5150 Wifi/WiMax */
4143 {IWL_PCI_DEVICE(0x423C, PCI_ANY_ID, iwl5150_agn_cfg)},
4144 {IWL_PCI_DEVICE(0x423D, PCI_ANY_ID, iwl5150_agn_cfg)},
Jay Sternberge1228372009-01-19 15:30:34 -08004145/* 6000/6050 Series */
4146 {IWL_PCI_DEVICE(0x0082, 0x1102, iwl6000_2ag_cfg)},
4147 {IWL_PCI_DEVICE(0x0085, 0x1112, iwl6000_2ag_cfg)},
4148 {IWL_PCI_DEVICE(0x0082, 0x1122, iwl6000_2ag_cfg)},
4149 {IWL_PCI_DEVICE(0x422B, PCI_ANY_ID, iwl6000_3agn_cfg)},
4150 {IWL_PCI_DEVICE(0x4238, PCI_ANY_ID, iwl6000_3agn_cfg)},
4151 {IWL_PCI_DEVICE(0x0082, PCI_ANY_ID, iwl6000_2agn_cfg)},
4152 {IWL_PCI_DEVICE(0x0085, PCI_ANY_ID, iwl6000_3agn_cfg)},
4153 {IWL_PCI_DEVICE(0x0086, PCI_ANY_ID, iwl6050_3agn_cfg)},
4154 {IWL_PCI_DEVICE(0x0087, PCI_ANY_ID, iwl6050_2agn_cfg)},
4155 {IWL_PCI_DEVICE(0x0088, PCI_ANY_ID, iwl6050_3agn_cfg)},
4156 {IWL_PCI_DEVICE(0x0089, PCI_ANY_ID, iwl6050_2agn_cfg)},
Jay Sternbergc5d05692009-01-19 15:30:35 -08004157/* 100 Series WiFi */
4158 {IWL_PCI_DEVICE(0x0083, PCI_ANY_ID, iwl100_bgn_cfg)},
4159 {IWL_PCI_DEVICE(0x0084, PCI_ANY_ID, iwl100_bgn_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004160#endif /* CONFIG_IWL5000 */
Tomas Winkler7100e922008-12-01 16:32:18 -08004161
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004162 {0}
4163};
4164MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
4165
4166static struct pci_driver iwl_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07004167 .name = DRV_NAME,
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004168 .id_table = iwl_hw_card_ids,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004169 .probe = iwl_pci_probe,
4170 .remove = __devexit_p(iwl_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07004171#ifdef CONFIG_PM
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004172 .suspend = iwl_pci_suspend,
4173 .resume = iwl_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07004174#endif
4175};
4176
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004177static int __init iwl_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07004178{
4179
4180 int ret;
4181 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
4182 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004183
Tomas Winklere227cea2008-07-18 13:53:05 +08004184 ret = iwlagn_rate_control_register();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004185 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08004186 printk(KERN_ERR DRV_NAME
4187 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004188 return ret;
4189 }
4190
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004191 ret = pci_register_driver(&iwl_driver);
Zhu Yib481de92007-09-25 17:54:57 -07004192 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08004193 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004194 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07004195 }
Zhu Yib481de92007-09-25 17:54:57 -07004196
4197 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004198
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004199error_register:
Tomas Winklere227cea2008-07-18 13:53:05 +08004200 iwlagn_rate_control_unregister();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004201 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004202}
4203
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004204static void __exit iwl_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07004205{
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004206 pci_unregister_driver(&iwl_driver);
Tomas Winklere227cea2008-07-18 13:53:05 +08004207 iwlagn_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07004208}
4209
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004210module_exit(iwl_exit);
4211module_init(iwl_init);