blob: 4d85c28e38e2944b2e14578100c1d1c2f65adc92 [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>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040036#include <linux/sched.h>
Zhu Yib481de92007-09-25 17:54:57 -070037#include <linux/skbuff.h>
38#include <linux/netdevice.h>
39#include <linux/wireless.h>
40#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070041#include <linux/etherdevice.h>
42#include <linux/if_arp.h>
43
Zhu Yib481de92007-09-25 17:54:57 -070044#include <net/mac80211.h>
45
46#include <asm/div64.h>
47
Samuel Ortiza3139c52008-12-19 10:37:09 +080048#define DRV_NAME "iwlagn"
49
Assaf Krauss6bc913b2008-03-11 16:17:18 -070050#include "iwl-eeprom.h"
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070051#include "iwl-dev.h"
Tomas Winklerfee12472008-04-03 16:05:21 -070052#include "iwl-core.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070053#include "iwl-io.h"
Zhu Yib481de92007-09-25 17:54:57 -070054#include "iwl-helpers.h"
Emmanuel Grumbach6974e362008-04-14 21:16:06 -070055#include "iwl-sta.h"
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -070056#include "iwl-calib.h"
Zhu Yib481de92007-09-25 17:54:57 -070057
Christoph Hellwig416e1432007-10-25 17:15:49 +080058
Zhu Yib481de92007-09-25 17:54:57 -070059/******************************************************************************
60 *
61 * module boiler plate
62 *
63 ******************************************************************************/
64
Zhu Yib481de92007-09-25 17:54:57 -070065/*
66 * module name, copyright, version, etc.
Zhu Yib481de92007-09-25 17:54:57 -070067 */
Tomas Winklerd783b062008-07-18 13:53:02 +080068#define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
Zhu Yib481de92007-09-25 17:54:57 -070069
Tomas Winkler0a6857e2008-03-12 16:58:49 -070070#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070071#define VD "d"
72#else
73#define VD
74#endif
75
Reinette Chatre80bc5392009-02-13 11:51:19 -080076#ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070077#define VS "s"
78#else
79#define VS
80#endif
81
Tomas Winklerdf48c322008-03-06 10:40:19 -080082#define DRV_VERSION IWLWIFI_VERSION VD VS
Zhu Yib481de92007-09-25 17:54:57 -070083
Zhu Yib481de92007-09-25 17:54:57 -070084
85MODULE_DESCRIPTION(DRV_DESCRIPTION);
86MODULE_VERSION(DRV_VERSION);
Tomas Winklera7b75202008-12-11 10:33:41 -080087MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
Zhu Yib481de92007-09-25 17:54:57 -070088MODULE_LICENSE("GPL");
Tomas Winkler4fc22b22008-07-21 18:54:42 +030089MODULE_ALIAS("iwl4965");
Zhu Yib481de92007-09-25 17:54:57 -070090
Zhu Yib481de92007-09-25 17:54:57 -070091/*************** STATION TABLE MANAGEMENT ****
Ben Cahill9fbab512007-11-29 11:09:47 +080092 * mac80211 should be examined to determine if sta_info is duplicating
Zhu Yib481de92007-09-25 17:54:57 -070093 * the functionality provided here
94 */
95
96/**************************************************************/
97
Zhu Yib481de92007-09-25 17:54:57 -070098/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -070099 * iwl_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -0700100 *
Ian Schram01ebd062007-10-25 17:15:22 +0800101 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -0700102 * the active_rxon structure is updated with the new data. This
103 * function correctly transitions out of the RXON_ASSOC_MSK state if
104 * a HW tune is required based on the RXON structure changes.
105 */
Abhijeet Kolekare0158e62009-04-08 11:26:37 -0700106int iwl_commit_rxon(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700107{
108 /* cast away the const for active_rxon in this function */
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800109 struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800110 int ret;
111 bool new_assoc =
112 !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK);
Zhu Yib481de92007-09-25 17:54:57 -0700113
Tomas Winklerfee12472008-04-03 16:05:21 -0700114 if (!iwl_is_alive(priv))
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800115 return -EBUSY;
Zhu Yib481de92007-09-25 17:54:57 -0700116
117 /* always get timestamp with Rx frame */
118 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
119
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800120 ret = iwl_check_rxon_cmd(priv);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800121 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800122 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700123 return -EINVAL;
124 }
125
Wey-Yi Guy0924e5192009-11-06 14:52:54 -0800126 /*
127 * receive commit_rxon request
128 * abort any previous channel switch if still in process
129 */
130 if (priv->switch_rxon.switch_in_progress &&
131 (priv->switch_rxon.channel != priv->staging_rxon.channel)) {
132 IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
133 le16_to_cpu(priv->switch_rxon.channel));
134 priv->switch_rxon.switch_in_progress = false;
135 }
136
Zhu Yib481de92007-09-25 17:54:57 -0700137 /* If we don't need to send a full RXON, we can use
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700138 * iwl_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -0700139 * and other flags for the current radio configuration. */
Mohamed Abbas54559702008-09-03 11:18:44 +0800140 if (!iwl_full_rxon_required(priv)) {
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800141 ret = iwl_send_rxon_assoc(priv);
142 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800143 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800144 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700145 }
146
147 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Wey-Yi Guya6435652009-11-06 14:52:46 -0800148 iwl_print_rx_config_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700149 return 0;
150 }
151
152 /* station table will be cleared */
153 priv->assoc_station_added = 0;
154
Zhu Yib481de92007-09-25 17:54:57 -0700155 /* If we are currently associated and the new config requires
156 * an RXON_ASSOC and the new config wants the associated mask enabled,
157 * we must clear the associated from the active configuration
158 * before we apply the new config */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800159 if (iwl_is_associated(priv) && new_assoc) {
Tomas Winklere1623442009-01-27 14:27:56 -0800160 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
Zhu Yib481de92007-09-25 17:54:57 -0700161 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
162
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800163 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800164 sizeof(struct iwl_rxon_cmd),
Zhu Yib481de92007-09-25 17:54:57 -0700165 &priv->active_rxon);
166
167 /* If the mask clearing failed then we set
168 * active_rxon back to what it was previously */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800169 if (ret) {
Zhu Yib481de92007-09-25 17:54:57 -0700170 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
Winkler, Tomas15b16872008-12-19 10:37:33 +0800171 IWL_ERR(priv, "Error clearing ASSOC_MSK (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800172 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700173 }
Zhu Yib481de92007-09-25 17:54:57 -0700174 }
175
Tomas Winklere1623442009-01-27 14:27:56 -0800176 IWL_DEBUG_INFO(priv, "Sending RXON\n"
Zhu Yib481de92007-09-25 17:54:57 -0700177 "* with%s RXON_FILTER_ASSOC_MSK\n"
178 "* channel = %d\n"
Johannes Berge1749612008-10-27 15:59:26 -0700179 "* bssid = %pM\n",
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800180 (new_assoc ? "" : "out"),
Zhu Yib481de92007-09-25 17:54:57 -0700181 le16_to_cpu(priv->staging_rxon.channel),
Johannes Berge1749612008-10-27 15:59:26 -0700182 priv->staging_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -0700183
Tomas Winkler90e8e422009-06-19 13:52:42 -0700184 iwl_set_rxon_hwcrypto(priv, !priv->cfg->mod_params->sw_crypto);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800185
186 /* Apply the new configuration
187 * RXON unassoc clears the station table in uCode, send it before
188 * we add the bcast station. If assoc bit is set, we will send RXON
189 * after having added the bcast and bssid station.
190 */
191 if (!new_assoc) {
192 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800193 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800194 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800195 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800196 return ret;
197 }
198 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700199 }
200
Tomas Winklerc587de02009-06-03 11:44:07 -0700201 iwl_clear_stations_table(priv);
Zhu Yi556f8db2007-09-27 11:27:33 +0800202
Johannes Berg19cc1082009-05-08 13:44:36 -0700203 priv->start_calib = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700204
Zhu Yib481de92007-09-25 17:54:57 -0700205 /* Add the broadcast address so we can send broadcast frames */
Reinette Chatre9a9ca652009-10-30 14:36:12 -0700206 iwl_add_bcast_station(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700207
208 /* If we have set the ASSOC_MSK and we are in BSS mode then
209 * add the IWL_AP_ID to the station rate table */
Tomas Winkler91851592008-06-30 17:23:14 +0800210 if (new_assoc) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200211 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Tomas Winkler91851592008-06-30 17:23:14 +0800212 ret = iwl_rxon_add_station(priv,
213 priv->active_rxon.bssid_addr, 1);
214 if (ret == IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800215 IWL_ERR(priv,
216 "Error adding AP address for TX.\n");
Tomas Winkler91851592008-06-30 17:23:14 +0800217 return -EIO;
218 }
219 priv->assoc_station_added = 1;
220 if (priv->default_wep_key &&
221 iwl_send_static_wepkey_cmd(priv, 0))
Winkler, Tomas15b16872008-12-19 10:37:33 +0800222 IWL_ERR(priv,
223 "Could not send WEP static key.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700224 }
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800225
Wey-Yi Guy47eef9b2009-09-17 10:43:44 -0700226 /*
227 * allow CTS-to-self if possible for new association.
228 * this is relevant only for 5000 series and up,
229 * but will not damage 4965
230 */
231 priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN;
232
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800233 /* Apply the new configuration
234 * RXON assoc doesn't clear the station table in uCode,
235 */
236 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
237 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
238 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800239 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800240 return ret;
241 }
242 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700243 }
Wey-Yi Guya6435652009-11-06 14:52:46 -0800244 iwl_print_rx_config_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700245
Zhu Yi36da7d72008-07-11 11:53:40 +0800246 iwl_init_sensitivity(priv);
247
248 /* If we issue a new RXON command which required a tune then we must
249 * send a new TXPOWER command or we won't be able to Tx any frames */
250 ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
251 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800252 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
Zhu Yi36da7d72008-07-11 11:53:40 +0800253 return ret;
254 }
255
Zhu Yib481de92007-09-25 17:54:57 -0700256 return 0;
257}
258
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700259void iwl_update_chain_flags(struct iwl_priv *priv)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700260{
261
Abhijeet Kolekar45823532009-04-08 11:26:44 -0700262 if (priv->cfg->ops->hcmd->set_rxon_chain)
263 priv->cfg->ops->hcmd->set_rxon_chain(priv);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -0700264 iwlcore_commit_rxon(priv);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700265}
266
Tomas Winklerfcab4232008-05-15 13:54:01 +0800267static void iwl_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700268{
269 struct list_head *element;
270
Tomas Winklere1623442009-01-27 14:27:56 -0800271 IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
Zhu Yib481de92007-09-25 17:54:57 -0700272 priv->frames_count);
273
274 while (!list_empty(&priv->free_frames)) {
275 element = priv->free_frames.next;
276 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800277 kfree(list_entry(element, struct iwl_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700278 priv->frames_count--;
279 }
280
281 if (priv->frames_count) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800282 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
Zhu Yib481de92007-09-25 17:54:57 -0700283 priv->frames_count);
284 priv->frames_count = 0;
285 }
286}
287
Tomas Winklerfcab4232008-05-15 13:54:01 +0800288static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700289{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800290 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700291 struct list_head *element;
292 if (list_empty(&priv->free_frames)) {
293 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
294 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800295 IWL_ERR(priv, "Could not allocate frame!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700296 return NULL;
297 }
298
299 priv->frames_count++;
300 return frame;
301 }
302
303 element = priv->free_frames.next;
304 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800305 return list_entry(element, struct iwl_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700306}
307
Tomas Winklerfcab4232008-05-15 13:54:01 +0800308static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700309{
310 memset(frame, 0, sizeof(*frame));
311 list_add(&frame->list, &priv->free_frames);
312}
313
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800314static u32 iwl_fill_beacon_frame(struct iwl_priv *priv,
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800315 struct ieee80211_hdr *hdr,
Rami Rosen73ec1cc2008-12-16 09:37:07 +0200316 int left)
Zhu Yib481de92007-09-25 17:54:57 -0700317{
Tomas Winkler3109ece2008-03-28 16:33:35 -0700318 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200319 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
320 (priv->iw_mode != NL80211_IFTYPE_AP)))
Zhu Yib481de92007-09-25 17:54:57 -0700321 return 0;
322
323 if (priv->ibss_beacon->len > left)
324 return 0;
325
326 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
327
328 return priv->ibss_beacon->len;
329}
330
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800331/* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
332static void iwl_set_beacon_tim(struct iwl_priv *priv,
333 struct iwl_tx_beacon_cmd *tx_beacon_cmd,
334 u8 *beacon, u32 frame_size)
335{
336 u16 tim_idx;
337 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
338
339 /*
340 * The index is relative to frame start but we start looking at the
341 * variable-length part of the beacon.
342 */
343 tim_idx = mgmt->u.beacon.variable - beacon;
344
345 /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
346 while ((tim_idx < (frame_size - 2)) &&
347 (beacon[tim_idx] != WLAN_EID_TIM))
348 tim_idx += beacon[tim_idx+1] + 2;
349
350 /* If TIM field was found, set variables */
351 if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
352 tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
353 tx_beacon_cmd->tim_size = beacon[tim_idx+1];
354 } else
355 IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
356}
357
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700358static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800359 struct iwl_frame *frame)
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800360{
361 struct iwl_tx_beacon_cmd *tx_beacon_cmd;
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800362 u32 frame_size;
363 u32 rate_flags;
364 u32 rate;
365 /*
366 * We have to set up the TX command, the TX Beacon command, and the
367 * beacon contents.
368 */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800369
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800370 /* Initialize memory */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800371 tx_beacon_cmd = &frame->u.beacon;
372 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
373
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800374 /* Set up TX beacon contents */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800375 frame_size = iwl_fill_beacon_frame(priv, tx_beacon_cmd->frame,
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800376 sizeof(frame->u) - sizeof(*tx_beacon_cmd));
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800377 if (WARN_ON_ONCE(frame_size > MAX_MPDU_SIZE))
378 return 0;
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800379
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800380 /* Set up TX command fields */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800381 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800382 tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
383 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800384 tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800385 TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
386
387 /* Set up TX beacon command fields */
388 iwl_set_beacon_tim(priv, tx_beacon_cmd, (u8 *)tx_beacon_cmd->frame,
389 frame_size);
390
391 /* Set up packet rate and flags */
392 rate = iwl_rate_get_lowest_plcp(priv);
393 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant);
394 rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
395 if ((rate >= IWL_FIRST_CCK_RATE) && (rate <= IWL_LAST_CCK_RATE))
396 rate_flags |= RATE_MCS_CCK_MSK;
397 tx_beacon_cmd->tx.rate_n_flags = iwl_hw_set_rate_n_flags(rate,
398 rate_flags);
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800399
400 return sizeof(*tx_beacon_cmd) + frame_size;
401}
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700402static int iwl_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700403{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800404 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700405 unsigned int frame_size;
406 int rc;
Zhu Yib481de92007-09-25 17:54:57 -0700407
Tomas Winklerfcab4232008-05-15 13:54:01 +0800408 frame = iwl_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700409 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800410 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
Zhu Yib481de92007-09-25 17:54:57 -0700411 "command.\n");
412 return -ENOMEM;
413 }
414
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800415 frame_size = iwl_hw_get_beacon_cmd(priv, frame);
416 if (!frame_size) {
417 IWL_ERR(priv, "Error configuring the beacon command\n");
418 iwl_free_frame(priv, frame);
419 return -EINVAL;
420 }
Zhu Yib481de92007-09-25 17:54:57 -0700421
Tomas Winkler857485c2008-03-21 13:53:44 -0700422 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700423 &frame->u.cmd[0]);
424
Tomas Winklerfcab4232008-05-15 13:54:01 +0800425 iwl_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700426
427 return rc;
428}
429
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800430static inline dma_addr_t iwl_tfd_tb_get_addr(struct iwl_tfd *tfd, u8 idx)
431{
432 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
433
434 dma_addr_t addr = get_unaligned_le32(&tb->lo);
435 if (sizeof(dma_addr_t) > sizeof(u32))
436 addr |=
437 ((dma_addr_t)(le16_to_cpu(tb->hi_n_len) & 0xF) << 16) << 16;
438
439 return addr;
440}
441
442static inline u16 iwl_tfd_tb_get_len(struct iwl_tfd *tfd, u8 idx)
443{
444 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
445
446 return le16_to_cpu(tb->hi_n_len) >> 4;
447}
448
449static inline void iwl_tfd_set_tb(struct iwl_tfd *tfd, u8 idx,
450 dma_addr_t addr, u16 len)
451{
452 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
453 u16 hi_n_len = len << 4;
454
455 put_unaligned_le32(addr, &tb->lo);
456 if (sizeof(dma_addr_t) > sizeof(u32))
457 hi_n_len |= ((addr >> 16) >> 16) & 0xF;
458
459 tb->hi_n_len = cpu_to_le16(hi_n_len);
460
461 tfd->num_tbs = idx + 1;
462}
463
464static inline u8 iwl_tfd_get_num_tbs(struct iwl_tfd *tfd)
465{
466 return tfd->num_tbs & 0x1f;
467}
468
469/**
470 * iwl_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
471 * @priv - driver private data
472 * @txq - tx queue
473 *
474 * Does NOT advance any TFD circular buffer read/write indexes
475 * Does NOT free the TFD itself (which is within circular buffer)
476 */
477void iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq)
478{
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800479 struct iwl_tfd *tfd_tmp = (struct iwl_tfd *)txq->tfds;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800480 struct iwl_tfd *tfd;
481 struct pci_dev *dev = priv->pci_dev;
482 int index = txq->q.read_ptr;
483 int i;
484 int num_tbs;
485
486 tfd = &tfd_tmp[index];
487
488 /* Sanity check on number of chunks */
489 num_tbs = iwl_tfd_get_num_tbs(tfd);
490
491 if (num_tbs >= IWL_NUM_OF_TBS) {
492 IWL_ERR(priv, "Too many chunks: %i\n", num_tbs);
493 /* @todo issue fatal error, it is quite serious situation */
494 return;
495 }
496
497 /* Unmap tx_cmd */
498 if (num_tbs)
499 pci_unmap_single(dev,
Johannes Bergc2acea82009-07-24 11:13:05 -0700500 pci_unmap_addr(&txq->meta[index], mapping),
501 pci_unmap_len(&txq->meta[index], len),
Fenghua Yu96891ce2009-02-18 15:54:33 -0800502 PCI_DMA_BIDIRECTIONAL);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800503
504 /* Unmap chunks, if any. */
505 for (i = 1; i < num_tbs; i++) {
506 pci_unmap_single(dev, iwl_tfd_tb_get_addr(tfd, i),
507 iwl_tfd_tb_get_len(tfd, i), PCI_DMA_TODEVICE);
508
509 if (txq->txb) {
510 dev_kfree_skb(txq->txb[txq->q.read_ptr].skb[i - 1]);
511 txq->txb[txq->q.read_ptr].skb[i - 1] = NULL;
512 }
513 }
514}
515
516int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv,
517 struct iwl_tx_queue *txq,
518 dma_addr_t addr, u16 len,
519 u8 reset, u8 pad)
520{
521 struct iwl_queue *q;
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800522 struct iwl_tfd *tfd, *tfd_tmp;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800523 u32 num_tbs;
524
525 q = &txq->q;
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800526 tfd_tmp = (struct iwl_tfd *)txq->tfds;
527 tfd = &tfd_tmp[q->write_ptr];
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800528
529 if (reset)
530 memset(tfd, 0, sizeof(*tfd));
531
532 num_tbs = iwl_tfd_get_num_tbs(tfd);
533
534 /* Each TFD can point to a maximum 20 Tx buffers */
535 if (num_tbs >= IWL_NUM_OF_TBS) {
536 IWL_ERR(priv, "Error can not send more than %d chunks\n",
537 IWL_NUM_OF_TBS);
538 return -EINVAL;
539 }
540
541 BUG_ON(addr & ~DMA_BIT_MASK(36));
542 if (unlikely(addr & ~IWL_TX_DMA_MASK))
543 IWL_ERR(priv, "Unaligned address = %llx\n",
544 (unsigned long long)addr);
545
546 iwl_tfd_set_tb(tfd, num_tbs, addr, len);
547
548 return 0;
549}
550
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800551/*
552 * Tell nic where to find circular buffer of Tx Frame Descriptors for
553 * given Tx queue, and enable the DMA channel used for that queue.
554 *
555 * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
556 * channels supported in hardware.
557 */
558int iwl_hw_tx_queue_init(struct iwl_priv *priv,
559 struct iwl_tx_queue *txq)
560{
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800561 int txq_id = txq->q.id;
562
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800563 /* Circular buffer (TFD queue in DRAM) physical base address */
564 iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
565 txq->q.dma_addr >> 8);
566
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800567 return 0;
568}
569
Zhu Yib481de92007-09-25 17:54:57 -0700570/******************************************************************************
571 *
572 * Generic RX handler implementations
573 *
574 ******************************************************************************/
Tomas Winkler885ba202008-05-29 16:34:55 +0800575static void iwl_rx_reply_alive(struct iwl_priv *priv,
576 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700577{
Zhu Yi2f301222009-10-09 17:19:45 +0800578 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Tomas Winkler885ba202008-05-29 16:34:55 +0800579 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -0700580 struct delayed_work *pwork;
581
582 palive = &pkt->u.alive_frame;
583
Tomas Winklere1623442009-01-27 14:27:56 -0800584 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
Zhu Yib481de92007-09-25 17:54:57 -0700585 "0x%01X 0x%01X\n",
586 palive->is_valid, palive->ver_type,
587 palive->ver_subtype);
588
589 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
Tomas Winklere1623442009-01-27 14:27:56 -0800590 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700591 memcpy(&priv->card_alive_init,
592 &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +0800593 sizeof(struct iwl_init_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700594 pwork = &priv->init_alive_start;
595 } else {
Tomas Winklere1623442009-01-27 14:27:56 -0800596 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700597 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +0800598 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700599 pwork = &priv->alive_start;
600 }
601
602 /* We delay the ALIVE response by 5ms to
603 * give the HW RF Kill time to activate... */
604 if (palive->is_valid == UCODE_VALID_OK)
605 queue_delayed_work(priv->workqueue, pwork,
606 msecs_to_jiffies(5));
607 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800608 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700609}
610
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700611static void iwl_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -0700612{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700613 struct iwl_priv *priv =
614 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -0700615 struct sk_buff *beacon;
616
617 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +0200618 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -0700619
620 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800621 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -0700622 return;
623 }
624
625 mutex_lock(&priv->mutex);
626 /* new beacon skb is allocated every time; dispose previous.*/
627 if (priv->ibss_beacon)
628 dev_kfree_skb(priv->ibss_beacon);
629
630 priv->ibss_beacon = beacon;
631 mutex_unlock(&priv->mutex);
632
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700633 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700634}
635
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800636/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700637 * iwl_bg_statistics_periodic - Timer callback to queue statistics
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800638 *
639 * This callback is provided in order to send a statistics request.
640 *
641 * This timer function is continually reset to execute within
642 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
643 * was received. We need to ensure we receive the statistics in order
644 * to update the temperature used for calibrating the TXPOWER.
645 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700646static void iwl_bg_statistics_periodic(unsigned long data)
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800647{
648 struct iwl_priv *priv = (struct iwl_priv *)data;
649
650 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
651 return;
652
Mohamed Abbas61780ee2008-10-29 14:05:49 -0700653 /* dont send host command if rf-kill is on */
654 if (!iwl_is_ready_rf(priv))
655 return;
656
Wey-Yi Guyef8d5522009-11-13 11:56:28 -0800657 iwl_send_statistics_request(priv, CMD_ASYNC, false);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800658}
659
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800660
661static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base,
662 u32 start_idx, u32 num_events,
663 u32 mode)
664{
665 u32 i;
666 u32 ptr; /* SRAM byte address of log data */
667 u32 ev, time, data; /* event log data */
668 unsigned long reg_flags;
669
670 if (mode == 0)
671 ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32));
672 else
673 ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32));
674
675 /* Make sure device is powered up for SRAM reads */
676 spin_lock_irqsave(&priv->reg_lock, reg_flags);
677 if (iwl_grab_nic_access(priv)) {
678 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
679 return;
680 }
681
682 /* Set starting address; reads will auto-increment */
683 _iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, ptr);
684 rmb();
685
686 /*
687 * "time" is actually "data" for mode 0 (no timestamp).
688 * place event id # at far right for easier visual parsing.
689 */
690 for (i = 0; i < num_events; i++) {
691 ev = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
692 time = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
693 if (mode == 0) {
694 trace_iwlwifi_dev_ucode_cont_event(priv,
695 0, time, ev);
696 } else {
697 data = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
698 trace_iwlwifi_dev_ucode_cont_event(priv,
699 time, data, ev);
700 }
701 }
702 /* Allow device to power down */
703 iwl_release_nic_access(priv);
704 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
705}
706
707void iwl_continuous_event_trace(struct iwl_priv *priv)
708{
709 u32 capacity; /* event log capacity in # entries */
710 u32 base; /* SRAM byte address of event log header */
711 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
712 u32 num_wraps; /* # times uCode wrapped to top of log */
713 u32 next_entry; /* index of next entry to be written by uCode */
714
715 if (priv->ucode_type == UCODE_INIT)
716 base = le32_to_cpu(priv->card_alive_init.error_event_table_ptr);
717 else
718 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
719 if (priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
720 capacity = iwl_read_targ_mem(priv, base);
721 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
722 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
723 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
724 } else
725 return;
726
727 if (num_wraps == priv->event_log.num_wraps) {
728 iwl_print_cont_event_trace(priv,
729 base, priv->event_log.next_entry,
730 next_entry - priv->event_log.next_entry,
731 mode);
732 priv->event_log.non_wraps_count++;
733 } else {
734 if ((num_wraps - priv->event_log.num_wraps) > 1)
735 priv->event_log.wraps_more_count++;
736 else
737 priv->event_log.wraps_once_count++;
738 trace_iwlwifi_dev_ucode_wrap_event(priv,
739 num_wraps - priv->event_log.num_wraps,
740 next_entry, priv->event_log.next_entry);
741 if (next_entry < priv->event_log.next_entry) {
742 iwl_print_cont_event_trace(priv, base,
743 priv->event_log.next_entry,
744 capacity - priv->event_log.next_entry,
745 mode);
746
747 iwl_print_cont_event_trace(priv, base, 0,
748 next_entry, mode);
749 } else {
750 iwl_print_cont_event_trace(priv, base,
751 next_entry, capacity - next_entry,
752 mode);
753
754 iwl_print_cont_event_trace(priv, base, 0,
755 next_entry, mode);
756 }
757 }
758 priv->event_log.num_wraps = num_wraps;
759 priv->event_log.next_entry = next_entry;
760}
761
762/**
763 * iwl_bg_ucode_trace - Timer callback to log ucode event
764 *
765 * The timer is continually set to execute every
766 * UCODE_TRACE_PERIOD milliseconds after the last timer expired
767 * this function is to perform continuous uCode event logging operation
768 * if enabled
769 */
770static void iwl_bg_ucode_trace(unsigned long data)
771{
772 struct iwl_priv *priv = (struct iwl_priv *)data;
773
774 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
775 return;
776
777 if (priv->event_log.ucode_trace) {
778 iwl_continuous_event_trace(priv);
779 /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
780 mod_timer(&priv->ucode_trace,
781 jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
782 }
783}
784
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700785static void iwl_rx_beacon_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +0800786 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700787{
Tomas Winkler0a6857e2008-03-12 16:58:49 -0700788#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yi2f301222009-10-09 17:19:45 +0800789 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Tomas Winkler2aa6ab82008-12-11 10:33:40 -0800790 struct iwl4965_beacon_notif *beacon =
791 (struct iwl4965_beacon_notif *)pkt->u.raw;
Tomas Winklere7d326a2008-06-12 09:47:11 +0800792 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -0700793
Tomas Winklere1623442009-01-27 14:27:56 -0800794 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
Zhu Yib481de92007-09-25 17:54:57 -0700795 "tsf %d %d rate %d\n",
Tomas Winkler25a65722008-06-12 09:47:07 +0800796 le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
Zhu Yib481de92007-09-25 17:54:57 -0700797 beacon->beacon_notify_hdr.failure_frame,
798 le32_to_cpu(beacon->ibss_mgr_status),
799 le32_to_cpu(beacon->high_tsf),
800 le32_to_cpu(beacon->low_tsf), rate);
801#endif
802
Johannes Berg05c914f2008-09-11 00:01:58 +0200803 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -0700804 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
805 queue_work(priv->workqueue, &priv->beacon_update);
806}
807
Zhu Yib481de92007-09-25 17:54:57 -0700808/* Handle notification from uCode that card's power state is changing
809 * due to software, hardware, or critical temperature RFKILL */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700810static void iwl_rx_card_state_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +0800811 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700812{
Zhu Yi2f301222009-10-09 17:19:45 +0800813 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Zhu Yib481de92007-09-25 17:54:57 -0700814 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
815 unsigned long status = priv->status;
816
Wey-Yi Guy3a41bbd2009-12-10 14:37:24 -0800817 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s CT:%s\n",
Zhu Yib481de92007-09-25 17:54:57 -0700818 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
Wey-Yi Guy3a41bbd2009-12-10 14:37:24 -0800819 (flags & SW_CARD_DISABLED) ? "Kill" : "On",
820 (flags & CT_CARD_DISABLED) ?
821 "Reached" : "Not reached");
Zhu Yib481de92007-09-25 17:54:57 -0700822
823 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
Wey-Yi Guy3a41bbd2009-12-10 14:37:24 -0800824 CT_CARD_DISABLED)) {
Zhu Yib481de92007-09-25 17:54:57 -0700825
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700826 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -0700827 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
828
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700829 iwl_write_direct32(priv, HBUS_TARG_MBX_C,
830 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
Zhu Yib481de92007-09-25 17:54:57 -0700831
832 if (!(flags & RXON_CARD_DISABLED)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700833 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -0700834 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700835 iwl_write_direct32(priv, HBUS_TARG_MBX_C,
Zhu Yib481de92007-09-25 17:54:57 -0700836 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
Zhu Yib481de92007-09-25 17:54:57 -0700837 }
Wey-Yi Guy3a41bbd2009-12-10 14:37:24 -0800838 if (flags & CT_CARD_DISABLED)
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -0700839 iwl_tt_enter_ct_kill(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700840 }
Wey-Yi Guy3a41bbd2009-12-10 14:37:24 -0800841 if (!(flags & CT_CARD_DISABLED))
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -0700842 iwl_tt_exit_ct_kill(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700843
844 if (flags & HW_CARD_DISABLED)
845 set_bit(STATUS_RF_KILL_HW, &priv->status);
846 else
847 clear_bit(STATUS_RF_KILL_HW, &priv->status);
848
849
Zhu Yib481de92007-09-25 17:54:57 -0700850 if (!(flags & RXON_CARD_DISABLED))
Tomas Winkler2a421b92008-06-12 09:47:10 +0800851 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700852
853 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
Johannes Berga60e77e2009-06-04 18:26:06 +0200854 test_bit(STATUS_RF_KILL_HW, &priv->status)))
855 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
856 test_bit(STATUS_RF_KILL_HW, &priv->status));
Zhu Yib481de92007-09-25 17:54:57 -0700857 else
858 wake_up_interruptible(&priv->wait_command_queue);
859}
860
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700861int iwl_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
Tomas Winklere2e3c572008-07-18 13:53:04 +0800862{
Tomas Winklere2e3c572008-07-18 13:53:04 +0800863 if (src == IWL_PWR_SRC_VAUX) {
Tomas Winkler3fdb68d2009-02-10 15:19:02 -0800864 if (pci_pme_capable(priv->pci_dev, PCI_D3cold))
Tomas Winklere2e3c572008-07-18 13:53:04 +0800865 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
866 APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
867 ~APMG_PS_CTRL_MSK_PWR_SRC);
868 } else {
869 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
870 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
871 ~APMG_PS_CTRL_MSK_PWR_SRC);
872 }
873
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700874 return 0;
Tomas Winklere2e3c572008-07-18 13:53:04 +0800875}
876
Zhu Yib481de92007-09-25 17:54:57 -0700877/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700878 * iwl_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -0700879 *
880 * Setup the RX handlers for each of the reply types sent from the uCode
881 * to the host.
882 *
883 * This function chains into the hardware specific files for them to setup
884 * any hardware specific handlers as well.
885 */
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +0800886static void iwl_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700887{
Tomas Winkler885ba202008-05-29 16:34:55 +0800888 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700889 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
890 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700891 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700892 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700893 iwl_rx_pm_debug_statistics_notif;
894 priv->rx_handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700895
Ben Cahill9fbab512007-11-29 11:09:47 +0800896 /*
897 * The same handler is used for both the REPLY to a discrete
898 * statistics request from the host as well as for the periodic
899 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -0700900 */
Wey-Yi Guyef8d5522009-11-13 11:56:28 -0800901 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_reply_statistics;
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +0800902 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
Tomas Winkler2a421b92008-06-12 09:47:10 +0800903
Tomas Winkler21c339b2008-11-07 09:58:41 -0800904 iwl_setup_spectrum_handlers(priv);
Tomas Winkler2a421b92008-06-12 09:47:10 +0800905 iwl_setup_rx_scan_handlers(priv);
906
Ron Rindjunsky37a44212008-05-29 16:35:18 +0800907 /* status change handler */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700908 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700909
Tomas Winklerc1354752008-05-29 16:35:04 +0800910 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
911 iwl_rx_missed_beacon_notif;
Ron Rindjunsky37a44212008-05-29 16:35:18 +0800912 /* Rx handlers */
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800913 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl_rx_reply_rx_phy;
914 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl_rx_reply_rx;
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +0800915 /* block ack */
916 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl_rx_reply_compressed_ba;
Ben Cahill9fbab512007-11-29 11:09:47 +0800917 /* Set up hardware specific Rx handlers */
Emmanuel Grumbachd4789ef2008-04-24 11:55:20 -0700918 priv->cfg->ops->lib->rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700919}
920
Zhu Yib481de92007-09-25 17:54:57 -0700921/**
Tomas Winklera55360e2008-05-05 10:22:28 +0800922 * iwl_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -0700923 *
924 * Uses the priv->rx_handlers callback function array to invoke
925 * the appropriate handlers, including command responses,
926 * frame-received notifications, and other notifications.
927 */
Tomas Winklera55360e2008-05-05 10:22:28 +0800928void iwl_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700929{
Tomas Winklera55360e2008-05-05 10:22:28 +0800930 struct iwl_rx_mem_buffer *rxb;
Tomas Winklerdb11d632008-05-05 10:22:33 +0800931 struct iwl_rx_packet *pkt;
Tomas Winklera55360e2008-05-05 10:22:28 +0800932 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -0700933 u32 r, i;
934 int reclaim;
935 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800936 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -0800937 u32 count = 8;
Mohamed Abbas4752c932009-05-22 11:01:51 -0700938 int total_empty;
Zhu Yib481de92007-09-25 17:54:57 -0700939
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800940 /* uCode's read index (stored in shared DRAM) indicates the last Rx
941 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8d864222008-11-07 09:58:39 -0800942 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -0700943 i = rxq->read;
944
945 /* Rx interrupt, but nothing sent from uCode */
946 if (i == r)
Tomas Winklere1623442009-01-27 14:27:56 -0800947 IWL_DEBUG_RX(priv, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -0700948
Mohamed Abbas4752c932009-05-22 11:01:51 -0700949 /* calculate total frames need to be restock after handling RX */
Zhu Yi73005152009-10-23 13:42:32 -0700950 total_empty = r - rxq->write_actual;
Mohamed Abbas4752c932009-05-22 11:01:51 -0700951 if (total_empty < 0)
952 total_empty += RX_QUEUE_SIZE;
953
954 if (total_empty > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800955 fill_rx = 1;
956
Zhu Yib481de92007-09-25 17:54:57 -0700957 while (i != r) {
958 rxb = rxq->queue[i];
959
Ben Cahill9fbab512007-11-29 11:09:47 +0800960 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -0700961 * then a bug has been introduced in the queue refilling
962 * routines -- catch it here */
963 BUG_ON(rxb == NULL);
964
965 rxq->queue[i] = NULL;
966
Zhu Yi2f301222009-10-09 17:19:45 +0800967 pci_unmap_page(priv->pci_dev, rxb->page_dma,
968 PAGE_SIZE << priv->hw_params.rx_page_order,
969 PCI_DMA_FROMDEVICE);
970 pkt = rxb_addr(rxb);
Zhu Yib481de92007-09-25 17:54:57 -0700971
Johannes Bergbe1a71a2009-10-02 13:44:02 -0700972 trace_iwlwifi_dev_rx(priv, pkt,
973 le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK);
974
Zhu Yib481de92007-09-25 17:54:57 -0700975 /* Reclaim a command buffer only if this packet is a response
976 * to a (driver-originated) command.
977 * If the packet (e.g. Rx frame) originated from uCode,
978 * there is no command buffer to reclaim.
979 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
980 * but apparently a few don't get set; catch them here. */
981 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
982 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
Tomas Winkler857485c2008-03-21 13:53:44 -0700983 (pkt->hdr.cmd != REPLY_RX) &&
Daniel Halperin7dddaf12008-10-23 23:48:58 -0700984 (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) &&
Zhu Yicfe01702007-09-27 11:27:31 +0800985 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
Zhu Yib481de92007-09-25 17:54:57 -0700986 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
987 (pkt->hdr.cmd != REPLY_TX);
988
989 /* Based on type of command response or notification,
990 * handle those that need handling via function in
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700991 * rx_handlers table. See iwl_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -0700992 if (priv->rx_handlers[pkt->hdr.cmd]) {
Tomas Winklere1623442009-01-27 14:27:56 -0800993 IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r,
Ester Kummerf3d67992008-05-06 11:05:12 +0800994 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700995 priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
Zhu Yi29b1b262009-10-23 13:42:25 -0700996 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -0700997 } else {
998 /* No handling needed */
Tomas Winklere1623442009-01-27 14:27:56 -0800999 IWL_DEBUG_RX(priv,
Zhu Yib481de92007-09-25 17:54:57 -07001000 "r %d i %d No handler needed for %s, 0x%02x\n",
1001 r, i, get_cmd_string(pkt->hdr.cmd),
1002 pkt->hdr.cmd);
1003 }
1004
Zhu Yi29b1b262009-10-23 13:42:25 -07001005 /*
1006 * XXX: After here, we should always check rxb->page
1007 * against NULL before touching it or its virtual
1008 * memory (pkt). Because some rx_handler might have
1009 * already taken or freed the pages.
1010 */
1011
Zhu Yib481de92007-09-25 17:54:57 -07001012 if (reclaim) {
Zhu Yi2f301222009-10-09 17:19:45 +08001013 /* Invoke any callbacks, transfer the buffer to caller,
1014 * and fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001015 * as we reclaim the driver command queue */
Zhu Yi29b1b262009-10-23 13:42:25 -07001016 if (rxb->page)
Tomas Winkler17b88922008-05-29 16:35:12 +08001017 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001018 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001019 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07001020 }
1021
Zhu Yi73005152009-10-23 13:42:32 -07001022 /* Reuse the page if possible. For notification packets and
1023 * SKBs that fail to Rx correctly, add them back into the
1024 * rx_free list for reuse later. */
Zhu Yib481de92007-09-25 17:54:57 -07001025 spin_lock_irqsave(&rxq->lock, flags);
Zhu Yi73005152009-10-23 13:42:32 -07001026 if (rxb->page != NULL) {
1027 rxb->page_dma = pci_map_page(priv->pci_dev, rxb->page,
1028 0, PAGE_SIZE << priv->hw_params.rx_page_order,
1029 PCI_DMA_FROMDEVICE);
1030 list_add_tail(&rxb->list, &rxq->rx_free);
1031 rxq->free_count++;
1032 } else
1033 list_add_tail(&rxb->list, &rxq->rx_used);
1034
Zhu Yib481de92007-09-25 17:54:57 -07001035 spin_unlock_irqrestore(&rxq->lock, flags);
Zhu Yi73005152009-10-23 13:42:32 -07001036
Zhu Yib481de92007-09-25 17:54:57 -07001037 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001038 /* If there are a lot of unused frames,
1039 * restock the Rx queue so ucode wont assert. */
1040 if (fill_rx) {
1041 count++;
1042 if (count >= 8) {
Zhu Yi73005152009-10-23 13:42:32 -07001043 rxq->read = i;
Mohamed Abbas4752c932009-05-22 11:01:51 -07001044 iwl_rx_replenish_now(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001045 count = 0;
1046 }
1047 }
Zhu Yib481de92007-09-25 17:54:57 -07001048 }
1049
1050 /* Backtrack one entry */
Zhu Yi73005152009-10-23 13:42:32 -07001051 rxq->read = i;
Mohamed Abbas4752c932009-05-22 11:01:51 -07001052 if (fill_rx)
1053 iwl_rx_replenish_now(priv);
1054 else
1055 iwl_rx_queue_restock(priv);
Tomas Winklera55360e2008-05-05 10:22:28 +08001056}
Tomas Winklera55360e2008-05-05 10:22:28 +08001057
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001058/* call this function to flush any scheduled tasklet */
1059static inline void iwl_synchronize_irq(struct iwl_priv *priv)
1060{
Tomas Winklera96a27f2008-10-23 23:48:56 -07001061 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001062 synchronize_irq(priv->pci_dev->irq);
1063 tasklet_kill(&priv->irq_tasklet);
1064}
1065
Mohamed Abbasef850d72009-05-22 11:01:50 -07001066static void iwl_irq_tasklet_legacy(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001067{
1068 u32 inta, handled = 0;
1069 u32 inta_fh;
1070 unsigned long flags;
Ben Cahillc2e61da2009-10-30 14:36:09 -07001071 u32 i;
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001072#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001073 u32 inta_mask;
1074#endif
1075
1076 spin_lock_irqsave(&priv->lock, flags);
1077
1078 /* Ack/clear/reset pending uCode interrupts.
1079 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1080 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001081 inta = iwl_read32(priv, CSR_INT);
1082 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07001083
1084 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1085 * Any new interrupts that happen after this, either while we're
1086 * in this tasklet, or later, will show up in next ISR/tasklet. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001087 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1088 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001089
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001090#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001091 if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001092 /* just for debug */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001093 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Tomas Winklere1623442009-01-27 14:27:56 -08001094 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07001095 inta, inta_mask, inta_fh);
1096 }
1097#endif
1098
Zhu Yi2f301222009-10-09 17:19:45 +08001099 spin_unlock_irqrestore(&priv->lock, flags);
1100
Zhu Yib481de92007-09-25 17:54:57 -07001101 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1102 * atomic, make sure that inta covers all the interrupts that
1103 * we've discovered, even if FH interrupt came in just after
1104 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001105 if (inta_fh & CSR49_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001106 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001107 if (inta_fh & CSR49_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001108 inta |= CSR_INT_BIT_FH_TX;
1109
1110 /* Now service all interrupt bits discovered above. */
1111 if (inta & CSR_INT_BIT_HW_ERR) {
Reinette Chatre58dba722009-07-17 09:30:25 -07001112 IWL_ERR(priv, "Hardware error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001113
1114 /* Tell the device to stop sending interrupts */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001115 iwl_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001116
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001117 priv->isr_stats.hw++;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001118 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001119
1120 handled |= CSR_INT_BIT_HW_ERR;
1121
Zhu Yib481de92007-09-25 17:54:57 -07001122 return;
1123 }
1124
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001125#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001126 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07001127 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001128 if (inta & CSR_INT_BIT_SCD) {
Tomas Winklere1623442009-01-27 14:27:56 -08001129 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
Joonwoo Park25c03d82008-01-23 10:15:20 -08001130 "the frame/frames.\n");
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001131 priv->isr_stats.sch++;
1132 }
Zhu Yib481de92007-09-25 17:54:57 -07001133
1134 /* Alive notification via Rx interrupt will do the real work */
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001135 if (inta & CSR_INT_BIT_ALIVE) {
Tomas Winklere1623442009-01-27 14:27:56 -08001136 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001137 priv->isr_stats.alive++;
1138 }
Zhu Yib481de92007-09-25 17:54:57 -07001139 }
1140#endif
1141 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001142 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07001143
Ben Cahill9fbab512007-11-29 11:09:47 +08001144 /* HW RF KILL switch toggled */
Zhu Yib481de92007-09-25 17:54:57 -07001145 if (inta & CSR_INT_BIT_RF_KILL) {
1146 int hw_rf_kill = 0;
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001147 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yib481de92007-09-25 17:54:57 -07001148 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
1149 hw_rf_kill = 1;
1150
Reinette Chatre4c423a22009-07-17 09:30:26 -07001151 IWL_WARN(priv, "RF_KILL bit toggled to %s.\n",
Abhijeet Kolekarc3056062008-11-12 13:14:08 -08001152 hw_rf_kill ? "disable radio" : "enable radio");
Zhu Yib481de92007-09-25 17:54:57 -07001153
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001154 priv->isr_stats.rfkill++;
1155
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +08001156 /* driver only loads ucode once setting the interface up.
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01001157 * the driver allows loading the ucode even if the radio
1158 * is killed. Hence update the killswitch state here. The
1159 * rfkill handler will care about restarting if needed.
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +08001160 */
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01001161 if (!test_bit(STATUS_ALIVE, &priv->status)) {
1162 if (hw_rf_kill)
1163 set_bit(STATUS_RF_KILL_HW, &priv->status);
1164 else
1165 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Johannes Berga60e77e2009-06-04 18:26:06 +02001166 wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
Mohamed Abbasedb34222008-12-11 10:33:37 -08001167 }
Zhu Yib481de92007-09-25 17:54:57 -07001168
1169 handled |= CSR_INT_BIT_RF_KILL;
1170 }
1171
Ben Cahill9fbab512007-11-29 11:09:47 +08001172 /* Chip got too hot and stopped itself */
Zhu Yib481de92007-09-25 17:54:57 -07001173 if (inta & CSR_INT_BIT_CT_KILL) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001174 IWL_ERR(priv, "Microcode CT kill error detected.\n");
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001175 priv->isr_stats.ctkill++;
Zhu Yib481de92007-09-25 17:54:57 -07001176 handled |= CSR_INT_BIT_CT_KILL;
1177 }
1178
1179 /* Error detected by uCode */
1180 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001181 IWL_ERR(priv, "Microcode SW error detected. "
1182 " Restarting 0x%X.\n", inta);
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001183 priv->isr_stats.sw++;
1184 priv->isr_stats.sw_err = inta;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001185 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001186 handled |= CSR_INT_BIT_SW_ERR;
1187 }
1188
Ben Cahillc2e61da2009-10-30 14:36:09 -07001189 /*
1190 * uCode wakes up after power-down sleep.
1191 * Tell device about any new tx or host commands enqueued,
1192 * and about any Rx buffers made available while asleep.
1193 */
Zhu Yib481de92007-09-25 17:54:57 -07001194 if (inta & CSR_INT_BIT_WAKEUP) {
Tomas Winklere1623442009-01-27 14:27:56 -08001195 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
Tomas Winklera55360e2008-05-05 10:22:28 +08001196 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Ben Cahillc2e61da2009-10-30 14:36:09 -07001197 for (i = 0; i < priv->hw_params.max_txq_num; i++)
1198 iwl_txq_update_write_ptr(priv, &priv->txq[i]);
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001199 priv->isr_stats.wakeup++;
Zhu Yib481de92007-09-25 17:54:57 -07001200 handled |= CSR_INT_BIT_WAKEUP;
1201 }
1202
1203 /* All uCode command responses, including Tx command responses,
1204 * Rx "responses" (frame-received notification), and other
1205 * notifications from uCode come through here*/
1206 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Tomas Winklera55360e2008-05-05 10:22:28 +08001207 iwl_rx_handle(priv);
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001208 priv->isr_stats.rx++;
Zhu Yib481de92007-09-25 17:54:57 -07001209 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1210 }
1211
Ben Cahillc72cd192009-10-30 14:36:08 -07001212 /* This "Tx" DMA channel is used only for loading uCode */
Zhu Yib481de92007-09-25 17:54:57 -07001213 if (inta & CSR_INT_BIT_FH_TX) {
Ben Cahillc72cd192009-10-30 14:36:08 -07001214 IWL_DEBUG_ISR(priv, "uCode load interrupt\n");
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001215 priv->isr_stats.tx++;
Zhu Yib481de92007-09-25 17:54:57 -07001216 handled |= CSR_INT_BIT_FH_TX;
Ben Cahillc72cd192009-10-30 14:36:08 -07001217 /* Wake up uCode load routine, now that load is complete */
Ron Rindjunskydbb983b2008-05-15 13:54:12 +08001218 priv->ucode_write_complete = 1;
1219 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07001220 }
1221
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001222 if (inta & ~handled) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001223 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001224 priv->isr_stats.unhandled++;
1225 }
Zhu Yib481de92007-09-25 17:54:57 -07001226
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001227 if (inta & ~(priv->inta_mask)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001228 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001229 inta & ~priv->inta_mask);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001230 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001231 }
1232
1233 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001234 /* only Re-enable if diabled by irq */
1235 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001236 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001237
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001238#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001239 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001240 inta = iwl_read32(priv, CSR_INT);
1241 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1242 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Tomas Winklere1623442009-01-27 14:27:56 -08001243 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
Zhu Yib481de92007-09-25 17:54:57 -07001244 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
1245 }
1246#endif
Zhu Yib481de92007-09-25 17:54:57 -07001247}
1248
Mohamed Abbasef850d72009-05-22 11:01:50 -07001249/* tasklet for iwlagn interrupt */
1250static void iwl_irq_tasklet(struct iwl_priv *priv)
1251{
1252 u32 inta = 0;
1253 u32 handled = 0;
1254 unsigned long flags;
Ben Cahill87569902009-11-06 14:53:01 -08001255 u32 i;
Mohamed Abbasef850d72009-05-22 11:01:50 -07001256#ifdef CONFIG_IWLWIFI_DEBUG
1257 u32 inta_mask;
1258#endif
1259
1260 spin_lock_irqsave(&priv->lock, flags);
1261
1262 /* Ack/clear/reset pending uCode interrupts.
1263 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1264 */
1265 iwl_write32(priv, CSR_INT, priv->inta);
1266
1267 inta = priv->inta;
1268
1269#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001270 if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
Mohamed Abbasef850d72009-05-22 11:01:50 -07001271 /* just for debug */
1272 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1273 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x\n ",
1274 inta, inta_mask);
1275 }
1276#endif
Zhu Yi2f301222009-10-09 17:19:45 +08001277
1278 spin_unlock_irqrestore(&priv->lock, flags);
1279
Mohamed Abbasef850d72009-05-22 11:01:50 -07001280 /* saved interrupt in inta variable now we can reset priv->inta */
1281 priv->inta = 0;
1282
1283 /* Now service all interrupt bits discovered above. */
1284 if (inta & CSR_INT_BIT_HW_ERR) {
Reinette Chatre58dba722009-07-17 09:30:25 -07001285 IWL_ERR(priv, "Hardware error detected. Restarting.\n");
Mohamed Abbasef850d72009-05-22 11:01:50 -07001286
1287 /* Tell the device to stop sending interrupts */
1288 iwl_disable_interrupts(priv);
1289
1290 priv->isr_stats.hw++;
1291 iwl_irq_handle_error(priv);
1292
1293 handled |= CSR_INT_BIT_HW_ERR;
1294
Mohamed Abbasef850d72009-05-22 11:01:50 -07001295 return;
1296 }
1297
1298#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001299 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Mohamed Abbasef850d72009-05-22 11:01:50 -07001300 /* NIC fires this, but we don't use it, redundant with WAKEUP */
1301 if (inta & CSR_INT_BIT_SCD) {
1302 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
1303 "the frame/frames.\n");
1304 priv->isr_stats.sch++;
1305 }
1306
1307 /* Alive notification via Rx interrupt will do the real work */
1308 if (inta & CSR_INT_BIT_ALIVE) {
1309 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
1310 priv->isr_stats.alive++;
1311 }
1312 }
1313#endif
1314 /* Safely ignore these bits for debug checks below */
1315 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
1316
1317 /* HW RF KILL switch toggled */
1318 if (inta & CSR_INT_BIT_RF_KILL) {
1319 int hw_rf_kill = 0;
1320 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
1321 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
1322 hw_rf_kill = 1;
1323
Reinette Chatre4c423a22009-07-17 09:30:26 -07001324 IWL_WARN(priv, "RF_KILL bit toggled to %s.\n",
Mohamed Abbasef850d72009-05-22 11:01:50 -07001325 hw_rf_kill ? "disable radio" : "enable radio");
1326
1327 priv->isr_stats.rfkill++;
1328
1329 /* driver only loads ucode once setting the interface up.
1330 * the driver allows loading the ucode even if the radio
1331 * is killed. Hence update the killswitch state here. The
1332 * rfkill handler will care about restarting if needed.
1333 */
1334 if (!test_bit(STATUS_ALIVE, &priv->status)) {
1335 if (hw_rf_kill)
1336 set_bit(STATUS_RF_KILL_HW, &priv->status);
1337 else
1338 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Johannes Berga60e77e2009-06-04 18:26:06 +02001339 wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001340 }
1341
1342 handled |= CSR_INT_BIT_RF_KILL;
1343 }
1344
1345 /* Chip got too hot and stopped itself */
1346 if (inta & CSR_INT_BIT_CT_KILL) {
1347 IWL_ERR(priv, "Microcode CT kill error detected.\n");
1348 priv->isr_stats.ctkill++;
1349 handled |= CSR_INT_BIT_CT_KILL;
1350 }
1351
1352 /* Error detected by uCode */
1353 if (inta & CSR_INT_BIT_SW_ERR) {
1354 IWL_ERR(priv, "Microcode SW error detected. "
1355 " Restarting 0x%X.\n", inta);
1356 priv->isr_stats.sw++;
1357 priv->isr_stats.sw_err = inta;
1358 iwl_irq_handle_error(priv);
1359 handled |= CSR_INT_BIT_SW_ERR;
1360 }
1361
1362 /* uCode wakes up after power-down sleep */
1363 if (inta & CSR_INT_BIT_WAKEUP) {
1364 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
1365 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Ben Cahill87569902009-11-06 14:53:01 -08001366 for (i = 0; i < priv->hw_params.max_txq_num; i++)
1367 iwl_txq_update_write_ptr(priv, &priv->txq[i]);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001368
1369 priv->isr_stats.wakeup++;
1370
1371 handled |= CSR_INT_BIT_WAKEUP;
1372 }
1373
1374 /* All uCode command responses, including Tx command responses,
1375 * Rx "responses" (frame-received notification), and other
1376 * notifications from uCode come through here*/
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001377 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX |
1378 CSR_INT_BIT_RX_PERIODIC)) {
Mohamed Abbasef850d72009-05-22 11:01:50 -07001379 IWL_DEBUG_ISR(priv, "Rx interrupt\n");
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001380 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
1381 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1382 iwl_write32(priv, CSR_FH_INT_STATUS,
1383 CSR49_FH_INT_RX_MASK);
1384 }
1385 if (inta & CSR_INT_BIT_RX_PERIODIC) {
1386 handled |= CSR_INT_BIT_RX_PERIODIC;
1387 iwl_write32(priv, CSR_INT, CSR_INT_BIT_RX_PERIODIC);
1388 }
1389 /* Sending RX interrupt require many steps to be done in the
1390 * the device:
1391 * 1- write interrupt to current index in ICT table.
1392 * 2- dma RX frame.
1393 * 3- update RX shared data to indicate last write index.
1394 * 4- send interrupt.
1395 * This could lead to RX race, driver could receive RX interrupt
Ben Cahill74ba67e2009-11-20 12:04:53 -08001396 * but the shared data changes does not reflect this;
1397 * periodic interrupt will detect any dangling Rx activity.
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001398 */
Ben Cahill74ba67e2009-11-20 12:04:53 -08001399
1400 /* Disable periodic interrupt; we use it as just a one-shot. */
1401 iwl_write8(priv, CSR_INT_PERIODIC_REG,
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001402 CSR_INT_PERIODIC_DIS);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001403 iwl_rx_handle(priv);
Ben Cahill74ba67e2009-11-20 12:04:53 -08001404
1405 /*
1406 * Enable periodic interrupt in 8 msec only if we received
1407 * real RX interrupt (instead of just periodic int), to catch
1408 * any dangling Rx interrupt. If it was just the periodic
1409 * interrupt, there was no dangling Rx activity, and no need
1410 * to extend the periodic interrupt; one-shot is enough.
1411 */
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001412 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX))
Ben Cahill74ba67e2009-11-20 12:04:53 -08001413 iwl_write8(priv, CSR_INT_PERIODIC_REG,
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001414 CSR_INT_PERIODIC_ENA);
1415
Mohamed Abbasef850d72009-05-22 11:01:50 -07001416 priv->isr_stats.rx++;
Mohamed Abbasef850d72009-05-22 11:01:50 -07001417 }
1418
Ben Cahillc72cd192009-10-30 14:36:08 -07001419 /* This "Tx" DMA channel is used only for loading uCode */
Mohamed Abbasef850d72009-05-22 11:01:50 -07001420 if (inta & CSR_INT_BIT_FH_TX) {
1421 iwl_write32(priv, CSR_FH_INT_STATUS, CSR49_FH_INT_TX_MASK);
Ben Cahillc72cd192009-10-30 14:36:08 -07001422 IWL_DEBUG_ISR(priv, "uCode load interrupt\n");
Mohamed Abbasef850d72009-05-22 11:01:50 -07001423 priv->isr_stats.tx++;
1424 handled |= CSR_INT_BIT_FH_TX;
Ben Cahillc72cd192009-10-30 14:36:08 -07001425 /* Wake up uCode load routine, now that load is complete */
Mohamed Abbasef850d72009-05-22 11:01:50 -07001426 priv->ucode_write_complete = 1;
1427 wake_up_interruptible(&priv->wait_command_queue);
1428 }
1429
1430 if (inta & ~handled) {
1431 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
1432 priv->isr_stats.unhandled++;
1433 }
1434
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001435 if (inta & ~(priv->inta_mask)) {
Mohamed Abbasef850d72009-05-22 11:01:50 -07001436 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001437 inta & ~priv->inta_mask);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001438 }
1439
Mohamed Abbasef850d72009-05-22 11:01:50 -07001440 /* Re-enable all interrupts */
1441 /* only Re-enable if diabled by irq */
1442 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1443 iwl_enable_interrupts(priv);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001444}
1445
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001446
Zhu Yib481de92007-09-25 17:54:57 -07001447/******************************************************************************
1448 *
1449 * uCode download functions
1450 *
1451 ******************************************************************************/
1452
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001453static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001454{
Tomas Winkler98c92212008-01-14 17:46:20 -08001455 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
1456 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
1457 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1458 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
1459 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1460 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001461}
1462
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001463static void iwl_nic_start(struct iwl_priv *priv)
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08001464{
1465 /* Remove all resets to allow NIC to operate */
1466 iwl_write32(priv, CSR_RESET, 0);
1467}
1468
1469
Zhu Yib481de92007-09-25 17:54:57 -07001470/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001471 * iwl_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07001472 *
1473 * Copy into buffers for card to fetch via bus-mastering
1474 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001475static int iwl_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001476{
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001477 struct iwl_ucode_header *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001478 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07001479 const struct firmware *ucode_raw;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001480 const char *name_pre = priv->cfg->fw_name_pre;
1481 const unsigned int api_max = priv->cfg->ucode_api_max;
1482 const unsigned int api_min = priv->cfg->ucode_api_min;
1483 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07001484 u8 *src;
1485 size_t len;
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001486 u32 api_ver, build;
1487 u32 inst_size, data_size, init_size, init_data_size, boot_size;
Jay Sternbergabdc2d62009-07-31 14:28:09 -07001488 u16 eeprom_ver;
Zhu Yib481de92007-09-25 17:54:57 -07001489
1490 /* Ask kernel firmware_class module to get the boot firmware off disk.
1491 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08001492 for (index = api_max; index >= api_min; index--) {
1493 sprintf(buf, "%s%d%s", name_pre, index, ".ucode");
1494 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
1495 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001496 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001497 buf, ret);
1498 if (ret == -ENOENT)
1499 continue;
1500 else
1501 goto error;
1502 } else {
1503 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08001504 IWL_ERR(priv, "Loaded firmware %s, "
1505 "which is deprecated. "
1506 "Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001507 buf, api_max);
Winkler, Tomas15b16872008-12-19 10:37:33 +08001508
Tomas Winklere1623442009-01-27 14:27:56 -08001509 IWL_DEBUG_INFO(priv, "Got firmware '%s' file (%zd bytes) from disk\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001510 buf, ucode_raw->size);
1511 break;
1512 }
Zhu Yib481de92007-09-25 17:54:57 -07001513 }
1514
Reinette Chatrea0987a82008-12-02 12:14:06 -08001515 if (ret < 0)
1516 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07001517
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001518 /* Make sure that we got at least the v1 header! */
1519 if (ucode_raw->size < priv->cfg->ops->ucode->get_header_size(1)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001520 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001521 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001522 goto err_release;
1523 }
1524
1525 /* Data from ucode file: header followed by uCode images */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001526 ucode = (struct iwl_ucode_header *)ucode_raw->data;
Zhu Yib481de92007-09-25 17:54:57 -07001527
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08001528 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08001529 api_ver = IWL_UCODE_API(priv->ucode_ver);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001530 build = priv->cfg->ops->ucode->get_build(ucode, api_ver);
1531 inst_size = priv->cfg->ops->ucode->get_inst_size(ucode, api_ver);
1532 data_size = priv->cfg->ops->ucode->get_data_size(ucode, api_ver);
1533 init_size = priv->cfg->ops->ucode->get_init_size(ucode, api_ver);
1534 init_data_size =
1535 priv->cfg->ops->ucode->get_init_data_size(ucode, api_ver);
1536 boot_size = priv->cfg->ops->ucode->get_boot_size(ucode, api_ver);
1537 src = priv->cfg->ops->ucode->get_data(ucode, api_ver);
Zhu Yib481de92007-09-25 17:54:57 -07001538
Reinette Chatrea0987a82008-12-02 12:14:06 -08001539 /* api_ver should match the api version forming part of the
1540 * firmware filename ... but we don't check for that and only rely
Nick Andrew877d0312009-01-26 11:06:57 +01001541 * on the API version read from firmware header from here on forward */
Reinette Chatrea0987a82008-12-02 12:14:06 -08001542
1543 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001544 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08001545 "Driver supports v%u, firmware is v%u.\n",
1546 api_max, api_ver);
1547 priv->ucode_ver = 0;
1548 ret = -EINVAL;
1549 goto err_release;
1550 }
1551 if (api_ver != api_max)
Tomas Winkler978785a2008-12-19 10:37:31 +08001552 IWL_ERR(priv, "Firmware has old API version. Expected v%u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08001553 "got v%u. New firmware can be obtained "
1554 "from http://www.intellinuxwireless.org.\n",
1555 api_max, api_ver);
1556
Tomas Winkler978785a2008-12-19 10:37:31 +08001557 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
1558 IWL_UCODE_MAJOR(priv->ucode_ver),
1559 IWL_UCODE_MINOR(priv->ucode_ver),
1560 IWL_UCODE_API(priv->ucode_ver),
1561 IWL_UCODE_SERIAL(priv->ucode_ver));
Reinette Chatrea0987a82008-12-02 12:14:06 -08001562
Reinette Chatre5ebeb5a2009-10-30 14:36:04 -07001563 snprintf(priv->hw->wiphy->fw_version,
1564 sizeof(priv->hw->wiphy->fw_version),
1565 "%u.%u.%u.%u",
1566 IWL_UCODE_MAJOR(priv->ucode_ver),
1567 IWL_UCODE_MINOR(priv->ucode_ver),
1568 IWL_UCODE_API(priv->ucode_ver),
1569 IWL_UCODE_SERIAL(priv->ucode_ver));
1570
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001571 if (build)
1572 IWL_DEBUG_INFO(priv, "Build %u\n", build);
1573
Jay Sternbergabdc2d62009-07-31 14:28:09 -07001574 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
1575 IWL_DEBUG_INFO(priv, "NVM Type: %s, version: 0x%x\n",
1576 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
1577 ? "OTP" : "EEPROM", eeprom_ver);
1578
Tomas Winklere1623442009-01-27 14:27:56 -08001579 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001580 priv->ucode_ver);
Tomas Winklere1623442009-01-27 14:27:56 -08001581 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
Zhu Yib481de92007-09-25 17:54:57 -07001582 inst_size);
Tomas Winklere1623442009-01-27 14:27:56 -08001583 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
Zhu Yib481de92007-09-25 17:54:57 -07001584 data_size);
Tomas Winklere1623442009-01-27 14:27:56 -08001585 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
Zhu Yib481de92007-09-25 17:54:57 -07001586 init_size);
Tomas Winklere1623442009-01-27 14:27:56 -08001587 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
Zhu Yib481de92007-09-25 17:54:57 -07001588 init_data_size);
Tomas Winklere1623442009-01-27 14:27:56 -08001589 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
Zhu Yib481de92007-09-25 17:54:57 -07001590 boot_size);
1591
1592 /* Verify size of file vs. image size info in file's header */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001593 if (ucode_raw->size !=
1594 priv->cfg->ops->ucode->get_header_size(api_ver) +
Zhu Yib481de92007-09-25 17:54:57 -07001595 inst_size + data_size + init_size +
1596 init_data_size + boot_size) {
1597
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001598 IWL_DEBUG_INFO(priv,
1599 "uCode file size %d does not match expected size\n",
1600 (int)ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001601 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001602 goto err_release;
1603 }
1604
1605 /* Verify that uCode images will fit in card's SRAM */
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001606 if (inst_size > priv->hw_params.max_inst_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08001607 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08001608 inst_size);
1609 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001610 goto err_release;
1611 }
1612
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001613 if (data_size > priv->hw_params.max_data_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08001614 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08001615 data_size);
1616 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001617 goto err_release;
1618 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001619 if (init_size > priv->hw_params.max_inst_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08001620 IWL_INFO(priv, "uCode init instr len %d too large to fit in\n",
1621 init_size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001622 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001623 goto err_release;
1624 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001625 if (init_data_size > priv->hw_params.max_data_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08001626 IWL_INFO(priv, "uCode init data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08001627 init_data_size);
1628 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001629 goto err_release;
1630 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001631 if (boot_size > priv->hw_params.max_bsm_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08001632 IWL_INFO(priv, "uCode boot instr len %d too large to fit in\n",
1633 boot_size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001634 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001635 goto err_release;
1636 }
1637
1638 /* Allocate ucode buffers for card's bus-master loading ... */
1639
1640 /* Runtime instructions and 2 copies of data:
1641 * 1) unmodified from disk
1642 * 2) backup cache for save/restore during power-downs */
1643 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001644 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07001645
1646 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001647 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07001648
1649 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001650 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07001651
Zhu, Yi1f304e42009-01-23 13:45:22 -08001652 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
1653 !priv->ucode_data_backup.v_addr)
1654 goto err_pci_alloc;
1655
Zhu Yib481de92007-09-25 17:54:57 -07001656 /* Initialization instructions and data */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001657 if (init_size && init_data_size) {
1658 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001659 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Zhu Yib481de92007-09-25 17:54:57 -07001660
Tomas Winkler90e759d2007-11-29 11:09:41 +08001661 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001662 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001663
1664 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
1665 goto err_pci_alloc;
1666 }
Zhu Yib481de92007-09-25 17:54:57 -07001667
1668 /* Bootstrap (instructions only, no data) */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001669 if (boot_size) {
1670 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001671 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001672
Tomas Winkler90e759d2007-11-29 11:09:41 +08001673 if (!priv->ucode_boot.v_addr)
1674 goto err_pci_alloc;
1675 }
Zhu Yib481de92007-09-25 17:54:57 -07001676
1677 /* Copy images into buffers for card's bus-master reads ... */
1678
1679 /* Runtime instructions (first block of data in file) */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001680 len = inst_size;
Tomas Winklere1623442009-01-27 14:27:56 -08001681 IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001682 memcpy(priv->ucode_code.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001683 src += len;
1684
Tomas Winklere1623442009-01-27 14:27:56 -08001685 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07001686 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
1687
1688 /* Runtime data (2nd block)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001689 * NOTE: Copy into backup buffer will be done in iwl_up() */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001690 len = data_size;
Tomas Winklere1623442009-01-27 14:27:56 -08001691 IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode data len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001692 memcpy(priv->ucode_data.v_addr, src, len);
1693 memcpy(priv->ucode_data_backup.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001694 src += len;
Zhu Yib481de92007-09-25 17:54:57 -07001695
1696 /* Initialization instructions (3rd block) */
1697 if (init_size) {
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001698 len = init_size;
Tomas Winklere1623442009-01-27 14:27:56 -08001699 IWL_DEBUG_INFO(priv, "Copying (but not loading) init instr len %Zd\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08001700 len);
Zhu Yib481de92007-09-25 17:54:57 -07001701 memcpy(priv->ucode_init.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001702 src += len;
Zhu Yib481de92007-09-25 17:54:57 -07001703 }
1704
1705 /* Initialization data (4th block) */
1706 if (init_data_size) {
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001707 len = init_data_size;
Tomas Winklere1623442009-01-27 14:27:56 -08001708 IWL_DEBUG_INFO(priv, "Copying (but not loading) init data len %Zd\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08001709 len);
Zhu Yib481de92007-09-25 17:54:57 -07001710 memcpy(priv->ucode_init_data.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001711 src += len;
Zhu Yib481de92007-09-25 17:54:57 -07001712 }
1713
1714 /* Bootstrap instructions (5th block) */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001715 len = boot_size;
Tomas Winklere1623442009-01-27 14:27:56 -08001716 IWL_DEBUG_INFO(priv, "Copying (but not loading) boot instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001717 memcpy(priv->ucode_boot.v_addr, src, len);
1718
1719 /* We have our copies now, allow OS release its copies */
1720 release_firmware(ucode_raw);
1721 return 0;
1722
1723 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08001724 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001725 ret = -ENOMEM;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001726 iwl_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001727
1728 err_release:
1729 release_firmware(ucode_raw);
1730
1731 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08001732 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07001733}
1734
Reinette Chatreb7a79402009-09-25 14:24:23 -07001735static const char *desc_lookup_text[] = {
1736 "OK",
1737 "FAIL",
1738 "BAD_PARAM",
1739 "BAD_CHECKSUM",
1740 "NMI_INTERRUPT_WDG",
1741 "SYSASSERT",
1742 "FATAL_ERROR",
1743 "BAD_COMMAND",
1744 "HW_ERROR_TUNE_LOCK",
1745 "HW_ERROR_TEMPERATURE",
1746 "ILLEGAL_CHAN_FREQ",
1747 "VCC_NOT_STABLE",
1748 "FH_ERROR",
1749 "NMI_INTERRUPT_HOST",
1750 "NMI_INTERRUPT_ACTION_PT",
1751 "NMI_INTERRUPT_UNKNOWN",
1752 "UCODE_VERSION_MISMATCH",
1753 "HW_ERROR_ABS_LOCK",
1754 "HW_ERROR_CAL_LOCK_FAIL",
1755 "NMI_INTERRUPT_INST_ACTION_PT",
1756 "NMI_INTERRUPT_DATA_ACTION_PT",
1757 "NMI_TRM_HW_ER",
1758 "NMI_INTERRUPT_TRM",
1759 "NMI_INTERRUPT_BREAK_POINT"
1760 "DEBUG_0",
1761 "DEBUG_1",
1762 "DEBUG_2",
1763 "DEBUG_3",
1764 "UNKNOWN"
1765};
1766
1767static const char *desc_lookup(int i)
1768{
1769 int max = ARRAY_SIZE(desc_lookup_text) - 1;
1770
1771 if (i < 0 || i > max)
1772 i = max;
1773
1774 return desc_lookup_text[i];
1775}
1776
1777#define ERROR_START_OFFSET (1 * sizeof(u32))
1778#define ERROR_ELEM_SIZE (7 * sizeof(u32))
1779
1780void iwl_dump_nic_error_log(struct iwl_priv *priv)
1781{
1782 u32 data2, line;
1783 u32 desc, time, count, base, data1;
1784 u32 blink1, blink2, ilink1, ilink2;
1785
1786 if (priv->ucode_type == UCODE_INIT)
1787 base = le32_to_cpu(priv->card_alive_init.error_event_table_ptr);
1788 else
1789 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
1790
1791 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
Wey-Yi Guy212fb572009-12-02 12:53:00 -08001792 IWL_ERR(priv,
1793 "Not valid error log pointer 0x%08X for %s uCode\n",
1794 base, (priv->ucode_type == UCODE_INIT) ? "Init" : "RT");
Reinette Chatreb7a79402009-09-25 14:24:23 -07001795 return;
1796 }
1797
1798 count = iwl_read_targ_mem(priv, base);
1799
1800 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
1801 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
1802 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
1803 priv->status, count);
1804 }
1805
1806 desc = iwl_read_targ_mem(priv, base + 1 * sizeof(u32));
1807 blink1 = iwl_read_targ_mem(priv, base + 3 * sizeof(u32));
1808 blink2 = iwl_read_targ_mem(priv, base + 4 * sizeof(u32));
1809 ilink1 = iwl_read_targ_mem(priv, base + 5 * sizeof(u32));
1810 ilink2 = iwl_read_targ_mem(priv, base + 6 * sizeof(u32));
1811 data1 = iwl_read_targ_mem(priv, base + 7 * sizeof(u32));
1812 data2 = iwl_read_targ_mem(priv, base + 8 * sizeof(u32));
1813 line = iwl_read_targ_mem(priv, base + 9 * sizeof(u32));
1814 time = iwl_read_targ_mem(priv, base + 11 * sizeof(u32));
1815
Johannes Bergbe1a71a2009-10-02 13:44:02 -07001816 trace_iwlwifi_dev_ucode_error(priv, desc, time, data1, data2, line,
1817 blink1, blink2, ilink1, ilink2);
1818
Reinette Chatreb7a79402009-09-25 14:24:23 -07001819 IWL_ERR(priv, "Desc Time "
1820 "data1 data2 line\n");
1821 IWL_ERR(priv, "%-28s (#%02d) %010u 0x%08X 0x%08X %u\n",
1822 desc_lookup(desc), desc, time, data1, data2, line);
1823 IWL_ERR(priv, "blink1 blink2 ilink1 ilink2\n");
1824 IWL_ERR(priv, "0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2,
1825 ilink1, ilink2);
1826
1827}
1828
1829#define EVENT_START_OFFSET (4 * sizeof(u32))
1830
1831/**
1832 * iwl_print_event_log - Dump error event log to syslog
1833 *
1834 */
1835static void iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
1836 u32 num_events, u32 mode)
1837{
1838 u32 i;
1839 u32 base; /* SRAM byte address of event log header */
1840 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
1841 u32 ptr; /* SRAM byte address of log data */
1842 u32 ev, time, data; /* event log data */
Ben Cahille5854472009-11-06 14:52:58 -08001843 unsigned long reg_flags;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001844
1845 if (num_events == 0)
1846 return;
1847 if (priv->ucode_type == UCODE_INIT)
1848 base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
1849 else
1850 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
1851
1852 if (mode == 0)
1853 event_size = 2 * sizeof(u32);
1854 else
1855 event_size = 3 * sizeof(u32);
1856
1857 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
1858
Ben Cahille5854472009-11-06 14:52:58 -08001859 /* Make sure device is powered up for SRAM reads */
1860 spin_lock_irqsave(&priv->reg_lock, reg_flags);
1861 iwl_grab_nic_access(priv);
1862
1863 /* Set starting address; reads will auto-increment */
1864 _iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, ptr);
1865 rmb();
1866
Reinette Chatreb7a79402009-09-25 14:24:23 -07001867 /* "time" is actually "data" for mode 0 (no timestamp).
1868 * place event id # at far right for easier visual parsing. */
1869 for (i = 0; i < num_events; i++) {
Ben Cahille5854472009-11-06 14:52:58 -08001870 ev = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
1871 time = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Reinette Chatreb7a79402009-09-25 14:24:23 -07001872 if (mode == 0) {
1873 /* data, ev */
Johannes Bergbe1a71a2009-10-02 13:44:02 -07001874 trace_iwlwifi_dev_ucode_event(priv, 0, time, ev);
Reinette Chatreb7a79402009-09-25 14:24:23 -07001875 IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n", time, ev);
1876 } else {
Ben Cahille5854472009-11-06 14:52:58 -08001877 data = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Reinette Chatreb7a79402009-09-25 14:24:23 -07001878 IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
1879 time, data, ev);
Johannes Bergbe1a71a2009-10-02 13:44:02 -07001880 trace_iwlwifi_dev_ucode_event(priv, time, data, ev);
Reinette Chatreb7a79402009-09-25 14:24:23 -07001881 }
1882 }
Ben Cahille5854472009-11-06 14:52:58 -08001883
1884 /* Allow device to power down */
1885 iwl_release_nic_access(priv);
1886 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Reinette Chatreb7a79402009-09-25 14:24:23 -07001887}
1888
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001889/**
1890 * iwl_print_last_event_logs - Dump the newest # of event log to syslog
1891 */
1892static void iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
1893 u32 num_wraps, u32 next_entry,
1894 u32 size, u32 mode)
1895{
1896 /*
1897 * display the newest DEFAULT_LOG_ENTRIES entries
1898 * i.e the entries just before the next ont that uCode would fill.
1899 */
1900 if (num_wraps) {
1901 if (next_entry < size) {
1902 iwl_print_event_log(priv,
1903 capacity - (size - next_entry),
1904 size - next_entry, mode);
1905 iwl_print_event_log(priv, 0,
1906 next_entry, mode);
1907 } else
1908 iwl_print_event_log(priv, next_entry - size,
1909 size, mode);
1910 } else {
1911 if (next_entry < size)
1912 iwl_print_event_log(priv, 0, next_entry, mode);
1913 else
1914 iwl_print_event_log(priv, next_entry - size,
1915 size, mode);
1916 }
1917}
1918
Ben Cahill84c40692009-11-06 14:52:57 -08001919/* For sanity check only. Actual size is determined by uCode, typ. 512 */
1920#define MAX_EVENT_LOG_SIZE (512)
1921
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001922#define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
1923
1924void iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log)
Reinette Chatreb7a79402009-09-25 14:24:23 -07001925{
1926 u32 base; /* SRAM byte address of event log header */
1927 u32 capacity; /* event log capacity in # entries */
1928 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
1929 u32 num_wraps; /* # times uCode wrapped to top of log */
1930 u32 next_entry; /* index of next entry to be written by uCode */
1931 u32 size; /* # entries that we'll print */
1932
1933 if (priv->ucode_type == UCODE_INIT)
1934 base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
1935 else
1936 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
1937
1938 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
Wey-Yi Guy212fb572009-12-02 12:53:00 -08001939 IWL_ERR(priv,
1940 "Invalid event log pointer 0x%08X for %s uCode\n",
1941 base, (priv->ucode_type == UCODE_INIT) ? "Init" : "RT");
Reinette Chatreb7a79402009-09-25 14:24:23 -07001942 return;
1943 }
1944
1945 /* event log header */
1946 capacity = iwl_read_targ_mem(priv, base);
1947 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
1948 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
1949 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
1950
Ben Cahill84c40692009-11-06 14:52:57 -08001951 if (capacity > MAX_EVENT_LOG_SIZE) {
1952 IWL_ERR(priv, "Log capacity %d is bogus, limit to %d entries\n",
1953 capacity, MAX_EVENT_LOG_SIZE);
1954 capacity = MAX_EVENT_LOG_SIZE;
1955 }
1956
1957 if (next_entry > MAX_EVENT_LOG_SIZE) {
1958 IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
1959 next_entry, MAX_EVENT_LOG_SIZE);
1960 next_entry = MAX_EVENT_LOG_SIZE;
1961 }
1962
Reinette Chatreb7a79402009-09-25 14:24:23 -07001963 size = num_wraps ? capacity : next_entry;
1964
1965 /* bail out if nothing in log */
1966 if (size == 0) {
1967 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
1968 return;
1969 }
1970
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001971#ifdef CONFIG_IWLWIFI_DEBUG
1972 if (!(iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS))
1973 size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
1974 ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
1975#else
1976 size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
1977 ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001978#endif
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001979 IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n",
1980 size);
1981
1982#ifdef CONFIG_IWLWIFI_DEBUG
1983 if ((iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) || full_log) {
1984 /*
1985 * if uCode has wrapped back to top of log,
1986 * start at the oldest entry,
1987 * i.e the next one that uCode would fill.
1988 */
1989 if (num_wraps)
1990 iwl_print_event_log(priv, next_entry,
1991 capacity - next_entry, mode);
1992 /* (then/else) start at top of log */
1993 iwl_print_event_log(priv, 0, next_entry, mode);
1994 } else
1995 iwl_print_last_event_logs(priv, capacity, num_wraps,
1996 next_entry, size, mode);
1997#else
1998 iwl_print_last_event_logs(priv, capacity, num_wraps,
1999 next_entry, size, mode);
2000#endif
2001}
Reinette Chatreb7a79402009-09-25 14:24:23 -07002002
Zhu Yib481de92007-09-25 17:54:57 -07002003/**
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002004 * iwl_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002005 * from protocol/runtime uCode (initialization uCode's
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002006 * Alive gets handled by iwl_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07002007 */
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002008static void iwl_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002009{
Tomas Winkler57aab752008-04-14 21:16:03 -07002010 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002011
Tomas Winklere1623442009-01-27 14:27:56 -08002012 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002013
2014 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
2015 /* We had an error bringing up the hardware, so take it
2016 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002017 IWL_DEBUG_INFO(priv, "Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002018 goto restart;
2019 }
2020
2021 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2022 * This is a paranoid check, because we would not have gotten the
2023 * "runtime" alive if code weren't properly loaded. */
Emmanuel Grumbachb0692f22008-04-24 11:55:18 -07002024 if (iwl_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002025 /* Runtime instruction load was bad;
2026 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002027 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002028 goto restart;
2029 }
2030
Tomas Winklerc587de02009-06-03 11:44:07 -07002031 iwl_clear_stations_table(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07002032 ret = priv->cfg->ops->lib->alive_notify(priv);
2033 if (ret) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002034 IWL_WARN(priv,
2035 "Could not complete ALIVE transition [ntf]: %d\n", ret);
Zhu Yib481de92007-09-25 17:54:57 -07002036 goto restart;
2037 }
2038
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002039 /* After the ALIVE response, we can send host commands to the uCode */
Zhu Yib481de92007-09-25 17:54:57 -07002040 set_bit(STATUS_ALIVE, &priv->status);
2041
Tomas Winklerfee12472008-04-03 16:05:21 -07002042 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002043 return;
2044
Johannes Berg36d68252008-05-15 12:55:26 +02002045 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002046
2047 priv->active_rate = priv->rates_mask;
2048 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
2049
Wey-Yi Guy2f748de2009-09-17 10:43:51 -07002050 /* Configure Tx antenna selection based on H/W config */
2051 if (priv->cfg->ops->hcmd->set_tx_ant)
2052 priv->cfg->ops->hcmd->set_tx_ant(priv, priv->cfg->valid_tx_ant);
2053
Tomas Winkler3109ece2008-03-28 16:33:35 -07002054 if (iwl_is_associated(priv)) {
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08002055 struct iwl_rxon_cmd *active_rxon =
2056 (struct iwl_rxon_cmd *)&priv->active_rxon;
Mohamed Abbas019fb972009-03-17 21:59:18 -07002057 /* apply any changes in staging */
2058 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07002059 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2060 } else {
2061 /* Initialize our rx_config data */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002062 iwl_connection_init_rx_config(priv, priv->iw_mode);
Abhijeet Kolekar45823532009-04-08 11:26:44 -07002063
2064 if (priv->cfg->ops->hcmd->set_rxon_chain)
2065 priv->cfg->ops->hcmd->set_rxon_chain(priv);
2066
Zhu Yib481de92007-09-25 17:54:57 -07002067 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2068 }
2069
Ben Cahill9fbab512007-11-29 11:09:47 +08002070 /* Configure Bluetooth device coexistence support */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002071 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002072
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002073 iwl_reset_run_time_calib(priv);
2074
Zhu Yib481de92007-09-25 17:54:57 -07002075 /* Configure the adapter for unassociated operation */
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002076 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002077
2078 /* At this point, the NIC is initialized and operational */
Emmanuel Grumbach47f4a582008-06-12 09:47:13 +08002079 iwl_rf_kill_ct_config(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002080
Johannes Berge932a602009-10-02 13:44:03 -07002081 iwl_leds_init(priv);
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07002082
Tomas Winklere1623442009-01-27 14:27:56 -08002083 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07002084 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002085 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07002086
Johannes Berge312c242009-08-07 15:41:51 -07002087 iwl_power_update_mode(priv, true);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002088
Mohamed Abbasada17512008-11-07 09:58:34 -08002089 /* reassociate for ADHOC mode */
2090 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
2091 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
2092 priv->vif);
2093 if (beacon)
2094 iwl_mac_beacon_update(priv->hw, beacon);
2095 }
2096
2097
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002098 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002099 iwl_set_mode(priv, priv->iw_mode);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002100
Zhu Yib481de92007-09-25 17:54:57 -07002101 return;
2102
2103 restart:
2104 queue_work(priv->workqueue, &priv->restart);
2105}
2106
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002107static void iwl_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07002108
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002109static void __iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002110{
2111 unsigned long flags;
2112 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002113
Tomas Winklere1623442009-01-27 14:27:56 -08002114 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07002115
Zhu Yib481de92007-09-25 17:54:57 -07002116 if (!exit_pending)
2117 set_bit(STATUS_EXIT_PENDING, &priv->status);
2118
Tomas Winklerc587de02009-06-03 11:44:07 -07002119 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002120
2121 /* Unblock any waiting calls */
2122 wake_up_interruptible_all(&priv->wait_command_queue);
2123
Zhu Yib481de92007-09-25 17:54:57 -07002124 /* Wipe out the EXIT_PENDING status bit if we are not actually
2125 * exiting the module */
2126 if (!exit_pending)
2127 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2128
2129 /* stop and reset the on-board processor */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002130 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07002131
2132 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002133 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002134 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002135 spin_unlock_irqrestore(&priv->lock, flags);
2136 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002137
2138 if (priv->mac80211_registered)
2139 ieee80211_stop_queues(priv->hw);
2140
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002141 /* If we have not previously called iwl_init() then
Johannes Berga60e77e2009-06-04 18:26:06 +02002142 * clear all bits but the RF Kill bit and return */
Tomas Winklerfee12472008-04-03 16:05:21 -07002143 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002144 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2145 STATUS_RF_KILL_HW |
Reinette Chatre97888642008-02-06 11:20:38 -08002146 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2147 STATUS_GEO_CONFIGURED |
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002148 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2149 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002150 goto exit;
2151 }
2152
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002153 /* ...otherwise clear out all the status bits but the RF Kill
Johannes Berga60e77e2009-06-04 18:26:06 +02002154 * bit and continue taking the NIC down. */
Zhu Yib481de92007-09-25 17:54:57 -07002155 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2156 STATUS_RF_KILL_HW |
Reinette Chatre97888642008-02-06 11:20:38 -08002157 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2158 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002159 test_bit(STATUS_FW_ERROR, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002160 STATUS_FW_ERROR |
2161 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2162 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002163
Mohamed Abbasef850d72009-05-22 11:01:50 -07002164 /* device going down, Stop using ICT table */
2165 iwl_disable_ict(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002166
Tomas Winklerda1bc452008-05-29 16:35:00 +08002167 iwl_txq_ctx_stop(priv);
Tomas Winklerb3bbacb2008-05-29 16:35:01 +08002168 iwl_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002169
Ben Cahill309e7312009-11-06 14:53:03 -08002170 /* Power-down device's busmaster DMA clocks */
2171 iwl_write_prph(priv, APMG_CLK_DIS_REG, APMG_CLK_VAL_DMA_CLK_RQT);
Zhu Yib481de92007-09-25 17:54:57 -07002172 udelay(5);
2173
Ben Cahill309e7312009-11-06 14:53:03 -08002174 /* Make sure (redundant) we've released our request to stay awake */
2175 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
2176
Ben Cahill4d2ccdb2009-10-09 13:20:20 -07002177 /* Stop the device, and put it in low power state */
2178 priv->cfg->ops->lib->apm_ops.stop(priv);
2179
Zhu Yib481de92007-09-25 17:54:57 -07002180 exit:
Tomas Winkler885ba202008-05-29 16:34:55 +08002181 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07002182
2183 if (priv->ibss_beacon)
2184 dev_kfree_skb(priv->ibss_beacon);
2185 priv->ibss_beacon = NULL;
2186
2187 /* clear out any free frames */
Tomas Winklerfcab4232008-05-15 13:54:01 +08002188 iwl_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002189}
2190
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002191static void iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002192{
2193 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002194 __iwl_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002195 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08002196
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002197 iwl_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002198}
2199
Mohamed Abbas086ed112009-05-22 11:01:54 -07002200#define HW_READY_TIMEOUT (50)
2201
2202static int iwl_set_hw_ready(struct iwl_priv *priv)
2203{
2204 int ret = 0;
2205
2206 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
2207 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
2208
2209 /* See if we got it */
2210 ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
2211 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
2212 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
2213 HW_READY_TIMEOUT);
2214 if (ret != -ETIMEDOUT)
2215 priv->hw_ready = true;
2216 else
2217 priv->hw_ready = false;
2218
2219 IWL_DEBUG_INFO(priv, "hardware %s\n",
2220 (priv->hw_ready == 1) ? "ready" : "not ready");
2221 return ret;
2222}
2223
2224static int iwl_prepare_card_hw(struct iwl_priv *priv)
2225{
2226 int ret = 0;
2227
2228 IWL_DEBUG_INFO(priv, "iwl_prepare_card_hw enter \n");
2229
Mohamed Abbas3354a0f2009-06-19 13:52:41 -07002230 ret = iwl_set_hw_ready(priv);
2231 if (priv->hw_ready)
2232 return ret;
2233
2234 /* If HW is not ready, prepare the conditions to check again */
Mohamed Abbas086ed112009-05-22 11:01:54 -07002235 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
2236 CSR_HW_IF_CONFIG_REG_PREPARE);
2237
2238 ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
2239 ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE,
2240 CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000);
2241
Mohamed Abbas3354a0f2009-06-19 13:52:41 -07002242 /* HW should be ready by now, check again. */
Mohamed Abbas086ed112009-05-22 11:01:54 -07002243 if (ret != -ETIMEDOUT)
2244 iwl_set_hw_ready(priv);
2245
2246 return ret;
2247}
2248
Zhu Yib481de92007-09-25 17:54:57 -07002249#define MAX_HW_RESTARTS 5
2250
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002251static int __iwl_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002252{
Tomas Winkler57aab752008-04-14 21:16:03 -07002253 int i;
2254 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002255
2256 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002257 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07002258 return -EIO;
2259 }
2260
Reinette Chatree903fbd2008-01-30 22:05:15 -08002261 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002262 IWL_ERR(priv, "ucode not available for device bringup\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08002263 return -EIO;
2264 }
2265
Mohamed Abbas086ed112009-05-22 11:01:54 -07002266 iwl_prepare_card_hw(priv);
2267
2268 if (!priv->hw_ready) {
2269 IWL_WARN(priv, "Exit HW not ready\n");
2270 return -EIO;
2271 }
2272
Zhu Yie655b9f2008-01-24 02:19:38 -08002273 /* If platform's RF_KILL switch is NOT set to KILL */
Tomas Winklerc1842d62008-08-04 16:00:43 +08002274 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
Zhu Yie655b9f2008-01-24 02:19:38 -08002275 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002276 else
Zhu Yie655b9f2008-01-24 02:19:38 -08002277 set_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002278
Tomas Winklerc1842d62008-08-04 16:00:43 +08002279 if (iwl_is_rfkill(priv)) {
Johannes Berga60e77e2009-06-04 18:26:06 +02002280 wiphy_rfkill_set_hw_state(priv->hw->wiphy, true);
2281
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002282 iwl_enable_interrupts(priv);
Johannes Berga60e77e2009-06-04 18:26:06 +02002283 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
Tomas Winklerc1842d62008-08-04 16:00:43 +08002284 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002285 }
2286
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002287 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07002288
Ron Rindjunsky1053d352008-05-05 10:22:43 +08002289 ret = iwl_hw_nic_init(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07002290 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002291 IWL_ERR(priv, "Unable to init nic\n");
Tomas Winkler57aab752008-04-14 21:16:03 -07002292 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002293 }
2294
2295 /* make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002296 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2297 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07002298 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2299
2300 /* clear (again), then enable host interrupts */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002301 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002302 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002303
2304 /* really make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002305 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2306 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07002307
2308 /* Copy original ucode data image from disk into backup cache.
2309 * This will be used to initialize the on-board processor's
2310 * data SRAM for a clean start when the runtime program first loads. */
2311 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a66926a2008-01-14 17:46:18 -08002312 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07002313
Zhu Yib481de92007-09-25 17:54:57 -07002314 for (i = 0; i < MAX_HW_RESTARTS; i++) {
2315
Tomas Winklerc587de02009-06-03 11:44:07 -07002316 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002317
2318 /* load bootstrap state machine,
2319 * load bootstrap program into processor's memory,
2320 * prepare to load the "initialize" uCode */
Tomas Winkler57aab752008-04-14 21:16:03 -07002321 ret = priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002322
Tomas Winkler57aab752008-04-14 21:16:03 -07002323 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002324 IWL_ERR(priv, "Unable to set up bootstrap uCode: %d\n",
2325 ret);
Zhu Yib481de92007-09-25 17:54:57 -07002326 continue;
2327 }
2328
2329 /* start card; "initialize" will load runtime ucode */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002330 iwl_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002331
Tomas Winklere1623442009-01-27 14:27:56 -08002332 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
Zhu Yib481de92007-09-25 17:54:57 -07002333
2334 return 0;
2335 }
2336
2337 set_bit(STATUS_EXIT_PENDING, &priv->status);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002338 __iwl_down(priv);
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08002339 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002340
2341 /* tried to restart and config the device for as long as our
2342 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002343 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07002344 return -EIO;
2345}
2346
2347
2348/*****************************************************************************
2349 *
2350 * Workqueue callbacks
2351 *
2352 *****************************************************************************/
2353
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002354static void iwl_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002355{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002356 struct iwl_priv *priv =
2357 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002358
2359 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2360 return;
2361
2362 mutex_lock(&priv->mutex);
Emmanuel Grumbachf3ccc082008-05-05 10:22:45 +08002363 priv->cfg->ops->lib->init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002364 mutex_unlock(&priv->mutex);
2365}
2366
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002367static void iwl_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002368{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002369 struct iwl_priv *priv =
2370 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002371
2372 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2373 return;
2374
Mohamed Abbas258c44a2009-06-03 11:44:10 -07002375 /* enable dram interrupt */
2376 iwl_reset_ict(priv);
2377
Zhu Yib481de92007-09-25 17:54:57 -07002378 mutex_lock(&priv->mutex);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002379 iwl_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002380 mutex_unlock(&priv->mutex);
2381}
2382
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08002383static void iwl_bg_run_time_calib_work(struct work_struct *work)
2384{
2385 struct iwl_priv *priv = container_of(work, struct iwl_priv,
2386 run_time_calib_work);
2387
2388 mutex_lock(&priv->mutex);
2389
2390 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
2391 test_bit(STATUS_SCANNING, &priv->status)) {
2392 mutex_unlock(&priv->mutex);
2393 return;
2394 }
2395
2396 if (priv->start_calib) {
2397 iwl_chain_noise_calibration(priv, &priv->statistics);
2398
2399 iwl_sensitivity_calibration(priv, &priv->statistics);
2400 }
2401
2402 mutex_unlock(&priv->mutex);
2403 return;
2404}
2405
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002406static void iwl_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002407{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002408 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07002409
2410 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2411 return;
2412
2413 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002414 __iwl_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002415 mutex_unlock(&priv->mutex);
2416}
2417
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002418static void iwl_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002419{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002420 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07002421
2422 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2423 return;
2424
Johannes Berg19cc1082009-05-08 13:44:36 -07002425 if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
2426 mutex_lock(&priv->mutex);
2427 priv->vif = NULL;
2428 priv->is_open = 0;
2429 mutex_unlock(&priv->mutex);
2430 iwl_down(priv);
2431 ieee80211_restart_hw(priv->hw);
2432 } else {
2433 iwl_down(priv);
2434 queue_work(priv->workqueue, &priv->up);
2435 }
Zhu Yib481de92007-09-25 17:54:57 -07002436}
2437
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002438static void iwl_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002439{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002440 struct iwl_priv *priv =
2441 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07002442
2443 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2444 return;
2445
2446 mutex_lock(&priv->mutex);
Tomas Winklera55360e2008-05-05 10:22:28 +08002447 iwl_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002448 mutex_unlock(&priv->mutex);
2449}
2450
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002451#define IWL_DELAY_NEXT_SCAN (HZ*2)
2452
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07002453void iwl_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002454{
Zhu Yib481de92007-09-25 17:54:57 -07002455 struct ieee80211_conf *conf = NULL;
Tomas Winkler857485c2008-03-21 13:53:44 -07002456 int ret = 0;
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002457 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07002458
Johannes Berg05c914f2008-09-11 00:01:58 +02002459 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002460 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07002461 return;
2462 }
2463
Tomas Winklere1623442009-01-27 14:27:56 -08002464 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07002465 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07002466
2467
2468 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2469 return;
2470
Zhu Yib481de92007-09-25 17:54:57 -07002471
Reinette Chatre508e32e2008-04-14 21:16:13 -07002472 if (!priv->vif || !priv->is_open)
Mohamed Abbas948c1712007-10-25 17:15:45 +08002473 return;
Reinette Chatre508e32e2008-04-14 21:16:13 -07002474
Tomas Winkler2a421b92008-06-12 09:47:10 +08002475 iwl_scan_cancel_timeout(priv, 200);
mabbas052c4b92007-10-25 17:15:43 +08002476
Zhu Yib481de92007-09-25 17:54:57 -07002477 conf = ieee80211_get_hw_conf(priv->hw);
2478
2479 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002480 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002481
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002482 iwl_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002483 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002484 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002485 if (ret)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002486 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07002487 "Attempting to continue.\n");
2488
2489 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
2490
Emmanuel Grumbach42eb7c62008-09-17 10:10:05 +08002491 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03002492
Abhijeet Kolekar45823532009-04-08 11:26:44 -07002493 if (priv->cfg->ops->hcmd->set_rxon_chain)
2494 priv->cfg->ops->hcmd->set_rxon_chain(priv);
2495
Zhu Yib481de92007-09-25 17:54:57 -07002496 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2497
Tomas Winklere1623442009-01-27 14:27:56 -08002498 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07002499 priv->assoc_id, priv->beacon_int);
2500
2501 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2502 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2503 else
2504 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2505
2506 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2507 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2508 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2509 else
2510 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2511
Johannes Berg05c914f2008-09-11 00:01:58 +02002512 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002513 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2514
2515 }
2516
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002517 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002518
2519 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02002520 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -07002521 break;
2522
Johannes Berg05c914f2008-09-11 00:01:58 +02002523 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07002524
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002525 /* assume default assoc id */
2526 priv->assoc_id = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002527
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002528 iwl_rxon_add_station(priv, priv->bssid, 0);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002529 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002530
2531 break;
2532
2533 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002534 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03002535 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002536 break;
2537 }
2538
Johannes Berg05c914f2008-09-11 00:01:58 +02002539 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002540 priv->assoc_station_added = 1;
2541
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002542 spin_lock_irqsave(&priv->lock, flags);
2543 iwl_activate_qos(priv, 0);
2544 spin_unlock_irqrestore(&priv->lock, flags);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08002545
Grumbach, Emmanuel04816442008-09-03 11:26:53 +08002546 /* the chain noise calibration will enabled PM upon completion
2547 * If chain noise has already been run, then we need to enable
2548 * power management here */
2549 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
Johannes Berge312c242009-08-07 15:41:51 -07002550 iwl_power_update_mode(priv, false);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08002551
2552 /* Enable Rx differential gain and sensitivity calibrations */
2553 iwl_chain_noise_reset(priv);
2554 priv->start_calib = 1;
2555
Reinette Chatre508e32e2008-04-14 21:16:13 -07002556}
2557
Zhu Yib481de92007-09-25 17:54:57 -07002558/*****************************************************************************
2559 *
2560 * mac80211 entry point functions
2561 *
2562 *****************************************************************************/
2563
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002564#define UCODE_READY_TIMEOUT (4 * HZ)
Zhu Yi5a66926a2008-01-14 17:46:18 -08002565
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002566/*
2567 * Not a mac80211 entry point function, but it fits in with all the
2568 * other mac80211 functions grouped here.
2569 */
2570static int iwl_setup_mac(struct iwl_priv *priv)
2571{
2572 int ret;
2573 struct ieee80211_hw *hw = priv->hw;
2574 hw->rate_control_algorithm = "iwl-agn-rs";
2575
2576 /* Tell mac80211 our characteristics */
2577 hw->flags = IEEE80211_HW_SIGNAL_DBM |
2578 IEEE80211_HW_NOISE_DBM |
2579 IEEE80211_HW_AMPDU_AGGREGATION |
2580 IEEE80211_HW_SPECTRUM_MGMT;
2581
2582 if (!priv->cfg->broken_powersave)
2583 hw->flags |= IEEE80211_HW_SUPPORTS_PS |
2584 IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
2585
Reinette Chatre8d9698b2009-10-16 14:25:55 -07002586 hw->sta_data_size = sizeof(struct iwl_station_priv);
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002587 hw->wiphy->interface_modes =
2588 BIT(NL80211_IFTYPE_STATION) |
2589 BIT(NL80211_IFTYPE_ADHOC);
2590
Johannes Berg5be83de2009-11-19 00:56:28 +01002591 hw->wiphy->flags |= WIPHY_FLAG_STRICT_REGULATORY |
2592 WIPHY_FLAG_DISABLE_BEACON_HINTS;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002593
2594 /*
2595 * For now, disable PS by default because it affects
2596 * RX performance significantly.
2597 */
Johannes Berg5be83de2009-11-19 00:56:28 +01002598 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002599
2600 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
2601 /* we create the 802.11 header and a zero-length SSID element */
2602 hw->wiphy->max_scan_ie_len = IWL_MAX_PROBE_REQUEST - 24 - 2;
2603
2604 /* Default value; 4 EDCA QOS priorities */
2605 hw->queues = 4;
2606
2607 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
2608
2609 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
2610 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
2611 &priv->bands[IEEE80211_BAND_2GHZ];
2612 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
2613 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
2614 &priv->bands[IEEE80211_BAND_5GHZ];
2615
2616 ret = ieee80211_register_hw(priv->hw);
2617 if (ret) {
2618 IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
2619 return ret;
2620 }
2621 priv->mac80211_registered = 1;
2622
2623 return 0;
2624}
2625
2626
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002627static int iwl_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002628{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002629 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002630 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002631
Tomas Winklere1623442009-01-27 14:27:56 -08002632 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002633
2634 /* we should be verifying the device is ready to be opened */
2635 mutex_lock(&priv->mutex);
2636
Zhu Yi5a66926a2008-01-14 17:46:18 -08002637 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
2638 * ucode filename and max sizes are card-specific. */
2639
2640 if (!priv->ucode_code.len) {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002641 ret = iwl_read_ucode(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002642 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002643 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002644 mutex_unlock(&priv->mutex);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002645 return ret;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002646 }
2647 }
2648
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002649 ret = __iwl_up(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002650
Zhu Yib481de92007-09-25 17:54:57 -07002651 mutex_unlock(&priv->mutex);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002652
Zhu Yie655b9f2008-01-24 02:19:38 -08002653 if (ret)
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002654 return ret;
Zhu Yie655b9f2008-01-24 02:19:38 -08002655
Tomas Winklerc1842d62008-08-04 16:00:43 +08002656 if (iwl_is_rfkill(priv))
2657 goto out;
2658
Tomas Winklere1623442009-01-27 14:27:56 -08002659 IWL_DEBUG_INFO(priv, "Start UP work done.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08002660
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002661 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
Zhu Yi5a66926a2008-01-14 17:46:18 -08002662 * mac80211 will not be run successfully. */
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002663 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
2664 test_bit(STATUS_READY, &priv->status),
2665 UCODE_READY_TIMEOUT);
2666 if (!ret) {
2667 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002668 IWL_ERR(priv, "START_ALIVE timeout after %dms.\n",
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002669 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002670 return -ETIMEDOUT;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002671 }
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002672 }
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002673
Johannes Berge932a602009-10-02 13:44:03 -07002674 iwl_led_start(priv);
2675
Tomas Winklerc1842d62008-08-04 16:00:43 +08002676out:
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002677 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08002678 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002679 return 0;
2680}
2681
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002682static void iwl_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002683{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002684 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002685
Tomas Winklere1623442009-01-27 14:27:56 -08002686 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas948c1712007-10-25 17:15:45 +08002687
Johannes Berg19cc1082009-05-08 13:44:36 -07002688 if (!priv->is_open)
Zhu Yie655b9f2008-01-24 02:19:38 -08002689 return;
Zhu Yie655b9f2008-01-24 02:19:38 -08002690
Zhu Yib481de92007-09-25 17:54:57 -07002691 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002692
Wey-Yi Guy5bddf542009-08-21 13:34:25 -07002693 if (iwl_is_ready_rf(priv) || test_bit(STATUS_SCAN_HW, &priv->status)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08002694 /* stop mac, cancel any scan request and clear
2695 * RXON_FILTER_ASSOC_MSK BIT
2696 */
Zhu Yi5a66926a2008-01-14 17:46:18 -08002697 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002698 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002699 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002700 }
2701
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002702 iwl_down(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002703
2704 flush_workqueue(priv->workqueue);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002705
2706 /* enable interrupts again in order to receive rfkill changes */
2707 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
2708 iwl_enable_interrupts(priv);
Mohamed Abbas948c1712007-10-25 17:15:45 +08002709
Tomas Winklere1623442009-01-27 14:27:56 -08002710 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002711}
2712
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002713static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07002714{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002715 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002716
Tomas Winklere1623442009-01-27 14:27:56 -08002717 IWL_DEBUG_MACDUMP(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002718
Tomas Winklere1623442009-01-27 14:27:56 -08002719 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02002720 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07002721
Johannes Berge039fa42008-05-15 12:55:29 +02002722 if (iwl_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07002723 dev_kfree_skb_any(skb);
2724
Tomas Winklere1623442009-01-27 14:27:56 -08002725 IWL_DEBUG_MACDUMP(priv, "leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08002726 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07002727}
2728
Abhijeet Kolekar60690a62009-04-08 11:26:49 -07002729void iwl_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002730{
Tomas Winkler857485c2008-03-21 13:53:44 -07002731 int ret = 0;
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002732 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07002733
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08002734 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07002735 return;
2736
2737 /* The following should be done only at AP bring up */
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002738 if (!iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002739
2740 /* RXON - unassoc (to set timing command) */
2741 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002742 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002743
2744 /* RXON Timing */
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002745 iwl_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002746 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002747 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002748 if (ret)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002749 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07002750 "Attempting to continue.\n");
2751
Daniel C Halperinf513dff2009-11-13 11:56:34 -08002752 /* AP has all antennas */
2753 priv->chain_noise_data.active_chains =
2754 priv->hw_params.valid_rx_ant;
2755 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Abhijeet Kolekar45823532009-04-08 11:26:44 -07002756 if (priv->cfg->ops->hcmd->set_rxon_chain)
2757 priv->cfg->ops->hcmd->set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002758
2759 /* FIXME: what should be the assoc_id for AP? */
2760 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2761 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2762 priv->staging_rxon.flags |=
2763 RXON_FLG_SHORT_PREAMBLE_MSK;
2764 else
2765 priv->staging_rxon.flags &=
2766 ~RXON_FLG_SHORT_PREAMBLE_MSK;
2767
2768 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2769 if (priv->assoc_capability &
2770 WLAN_CAPABILITY_SHORT_SLOT_TIME)
2771 priv->staging_rxon.flags |=
2772 RXON_FLG_SHORT_SLOT_MSK;
2773 else
2774 priv->staging_rxon.flags &=
2775 ~RXON_FLG_SHORT_SLOT_MSK;
2776
Johannes Berg05c914f2008-09-11 00:01:58 +02002777 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002778 priv->staging_rxon.flags &=
2779 ~RXON_FLG_SHORT_SLOT_MSK;
2780 }
2781 /* restore RXON assoc */
2782 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002783 iwlcore_commit_rxon(priv);
Daniel C Halperinf513dff2009-11-13 11:56:34 -08002784 iwl_reset_qos(priv);
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002785 spin_lock_irqsave(&priv->lock, flags);
2786 iwl_activate_qos(priv, 1);
2787 spin_unlock_irqrestore(&priv->lock, flags);
Reinette Chatre9a9ca652009-10-30 14:36:12 -07002788 iwl_add_bcast_station(priv);
Zhu Yie1493de2007-09-27 11:27:32 +08002789 }
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002790 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002791
2792 /* FIXME - we need to add code here to detect a totally new
2793 * configuration, reset the AP, unassoc, rxon timing, assoc,
2794 * clear sta table, add BCAST sta... */
2795}
2796
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002797static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw,
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002798 struct ieee80211_key_conf *keyconf, const u8 *addr,
2799 u32 iv32, u16 *phase1key)
2800{
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002801
Tomas Winkler9f586712008-11-12 13:14:05 -08002802 struct iwl_priv *priv = hw->priv;
Tomas Winklere1623442009-01-27 14:27:56 -08002803 IWL_DEBUG_MAC80211(priv, "enter\n");
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002804
Tomas Winkler9f586712008-11-12 13:14:05 -08002805 iwl_update_tkip_key(priv, keyconf, addr, iv32, phase1key);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002806
Tomas Winklere1623442009-01-27 14:27:56 -08002807 IWL_DEBUG_MAC80211(priv, "leave\n");
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002808}
2809
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002810static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01002811 struct ieee80211_vif *vif,
2812 struct ieee80211_sta *sta,
Zhu Yib481de92007-09-25 17:54:57 -07002813 struct ieee80211_key_conf *key)
2814{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002815 struct iwl_priv *priv = hw->priv;
Winkler, Tomas42986792009-01-19 15:30:22 -08002816 const u8 *addr;
2817 int ret;
2818 u8 sta_id;
2819 bool is_default_wep_key = false;
Zhu Yib481de92007-09-25 17:54:57 -07002820
Tomas Winklere1623442009-01-27 14:27:56 -08002821 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002822
Tomas Winkler90e8e422009-06-19 13:52:42 -07002823 if (priv->cfg->mod_params->sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08002824 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07002825 return -EOPNOTSUPP;
2826 }
Winkler, Tomas42986792009-01-19 15:30:22 -08002827 addr = sta ? sta->addr : iwl_bcast_addr;
Tomas Winklerc587de02009-06-03 11:44:07 -07002828 sta_id = iwl_find_station(priv, addr);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002829 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -08002830 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
Johannes Berge1749612008-10-27 15:59:26 -07002831 addr);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002832 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002833
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002834 }
Zhu Yib481de92007-09-25 17:54:57 -07002835
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002836 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002837 iwl_scan_cancel_timeout(priv, 100);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002838 mutex_unlock(&priv->mutex);
2839
2840 /* If we are getting WEP group key and we didn't receive any key mapping
2841 * so far, we are in legacy wep mode (group key only), otherwise we are
2842 * in 1X mode.
2843 * In legacy wep mode, we use another host command to the uCode */
Tomas Winkler5425e492008-04-15 16:01:38 -07002844 if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
Johannes Berg05c914f2008-09-11 00:01:58 +02002845 priv->iw_mode != NL80211_IFTYPE_AP) {
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002846 if (cmd == SET_KEY)
2847 is_default_wep_key = !priv->key_mapping_key;
2848 else
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +08002849 is_default_wep_key =
2850 (key->hw_key_idx == HW_KEY_DEFAULT);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002851 }
mabbas052c4b92007-10-25 17:15:43 +08002852
Zhu Yib481de92007-09-25 17:54:57 -07002853 switch (cmd) {
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002854 case SET_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002855 if (is_default_wep_key)
2856 ret = iwl_set_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002857 else
Emmanuel Grumbach74805132008-04-14 21:16:09 -07002858 ret = iwl_set_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002859
Tomas Winklere1623442009-01-27 14:27:56 -08002860 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07002861 break;
2862 case DISABLE_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002863 if (is_default_wep_key)
2864 ret = iwl_remove_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002865 else
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07002866 ret = iwl_remove_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002867
Tomas Winklere1623442009-01-27 14:27:56 -08002868 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07002869 break;
2870 default:
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002871 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002872 }
2873
Tomas Winklere1623442009-01-27 14:27:56 -08002874 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002875
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002876 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002877}
2878
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002879static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
Johannes Bergc951ad32009-11-16 12:00:38 +01002880 struct ieee80211_vif *vif,
Tomas Winklerd783b062008-07-18 13:53:02 +08002881 enum ieee80211_ampdu_mlme_action action,
Johannes Berg17741cd2008-09-11 00:02:02 +02002882 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
Tomas Winklerd783b062008-07-18 13:53:02 +08002883{
2884 struct iwl_priv *priv = hw->priv;
Wey-Yi Guy5c2207c2009-03-17 21:51:43 -07002885 int ret;
Tomas Winklerd783b062008-07-18 13:53:02 +08002886
Tomas Winklere1623442009-01-27 14:27:56 -08002887 IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
Johannes Berge1749612008-10-27 15:59:26 -07002888 sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08002889
2890 if (!(priv->cfg->sku & IWL_SKU_N))
2891 return -EACCES;
2892
2893 switch (action) {
2894 case IEEE80211_AMPDU_RX_START:
Tomas Winklere1623442009-01-27 14:27:56 -08002895 IWL_DEBUG_HT(priv, "start Rx\n");
Tomas Winkler9f586712008-11-12 13:14:05 -08002896 return iwl_sta_rx_agg_start(priv, sta->addr, tid, *ssn);
Tomas Winklerd783b062008-07-18 13:53:02 +08002897 case IEEE80211_AMPDU_RX_STOP:
Tomas Winklere1623442009-01-27 14:27:56 -08002898 IWL_DEBUG_HT(priv, "stop Rx\n");
Wey-Yi Guy5c2207c2009-03-17 21:51:43 -07002899 ret = iwl_sta_rx_agg_stop(priv, sta->addr, tid);
2900 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2901 return 0;
2902 else
2903 return ret;
Tomas Winklerd783b062008-07-18 13:53:02 +08002904 case IEEE80211_AMPDU_TX_START:
Tomas Winklere1623442009-01-27 14:27:56 -08002905 IWL_DEBUG_HT(priv, "start Tx\n");
Johannes Berg17741cd2008-09-11 00:02:02 +02002906 return iwl_tx_agg_start(priv, sta->addr, tid, ssn);
Tomas Winklerd783b062008-07-18 13:53:02 +08002907 case IEEE80211_AMPDU_TX_STOP:
Tomas Winklere1623442009-01-27 14:27:56 -08002908 IWL_DEBUG_HT(priv, "stop Tx\n");
Wey-Yi Guy5c2207c2009-03-17 21:51:43 -07002909 ret = iwl_tx_agg_stop(priv, sta->addr, tid);
2910 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2911 return 0;
2912 else
2913 return ret;
Tomas Winklerd783b062008-07-18 13:53:02 +08002914 default:
Tomas Winklere1623442009-01-27 14:27:56 -08002915 IWL_DEBUG_HT(priv, "unknown\n");
Tomas Winklerd783b062008-07-18 13:53:02 +08002916 return -EINVAL;
2917 break;
2918 }
2919 return 0;
2920}
Tomas Winkler9f586712008-11-12 13:14:05 -08002921
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002922static int iwl_mac_get_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07002923 struct ieee80211_low_level_stats *stats)
2924{
Ester Kummerbf403db2008-05-05 10:22:40 +08002925 struct iwl_priv *priv = hw->priv;
2926
2927 priv = hw->priv;
Tomas Winklere1623442009-01-27 14:27:56 -08002928 IWL_DEBUG_MAC80211(priv, "enter\n");
2929 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002930
2931 return 0;
2932}
2933
Johannes Berg6ab10ff2009-11-13 11:56:37 -08002934static void iwl_mac_sta_notify(struct ieee80211_hw *hw,
2935 struct ieee80211_vif *vif,
2936 enum sta_notify_cmd cmd,
2937 struct ieee80211_sta *sta)
2938{
2939 struct iwl_priv *priv = hw->priv;
2940 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
2941 int sta_id;
2942
2943 /*
2944 * TODO: We really should use this callback to
2945 * actually maintain the station table in
2946 * the device.
2947 */
2948
2949 switch (cmd) {
2950 case STA_NOTIFY_ADD:
2951 atomic_set(&sta_priv->pending_frames, 0);
2952 if (vif->type == NL80211_IFTYPE_AP)
2953 sta_priv->client = true;
2954 break;
2955 case STA_NOTIFY_SLEEP:
2956 WARN_ON(!sta_priv->client);
2957 sta_priv->asleep = true;
2958 if (atomic_read(&sta_priv->pending_frames) > 0)
2959 ieee80211_sta_block_awake(hw, sta, true);
2960 break;
2961 case STA_NOTIFY_AWAKE:
2962 WARN_ON(!sta_priv->client);
2963 sta_priv->asleep = false;
2964 sta_id = iwl_find_station(priv, sta->addr);
2965 if (sta_id != IWL_INVALID_STATION)
2966 iwl_sta_modify_ps_wake(priv, sta_id);
2967 break;
2968 default:
2969 break;
2970 }
2971}
2972
Zhu Yib481de92007-09-25 17:54:57 -07002973/*****************************************************************************
2974 *
2975 * sysfs attributes
2976 *
2977 *****************************************************************************/
2978
Tomas Winkler0a6857e2008-03-12 16:58:49 -07002979#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07002980
2981/*
2982 * The following adds a new attribute to the sysfs representation
Wu, Fengguangc3a739f2008-12-17 16:52:29 +08002983 * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
Zhu Yib481de92007-09-25 17:54:57 -07002984 * used for controlling the debug level.
2985 *
2986 * See the level definitions in iwl for details.
Reinette Chatrea562a9d2009-07-17 09:30:24 -07002987 *
Reinette Chatre3d816c72009-08-07 15:41:37 -07002988 * The debug_level being managed using sysfs below is a per device debug
2989 * level that is used instead of the global debug level if it (the per
2990 * device debug level) is set.
Zhu Yib481de92007-09-25 17:54:57 -07002991 */
Ester Kummer8cf769c2008-05-06 11:05:11 +08002992static ssize_t show_debug_level(struct device *d,
2993 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07002994{
Reinette Chatre3d816c72009-08-07 15:41:37 -07002995 struct iwl_priv *priv = dev_get_drvdata(d);
2996 return sprintf(buf, "0x%08X\n", iwl_get_debug_level(priv));
Zhu Yib481de92007-09-25 17:54:57 -07002997}
Ester Kummer8cf769c2008-05-06 11:05:11 +08002998static ssize_t store_debug_level(struct device *d,
2999 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07003000 const char *buf, size_t count)
3001{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003002 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler9257746f2008-09-03 11:26:32 +08003003 unsigned long val;
3004 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003005
Tomas Winkler9257746f2008-09-03 11:26:32 +08003006 ret = strict_strtoul(buf, 0, &val);
3007 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08003008 IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003009 else {
Reinette Chatre3d816c72009-08-07 15:41:37 -07003010 priv->debug_level = val;
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003011 if (iwl_alloc_traffic_mem(priv))
3012 IWL_ERR(priv,
3013 "Not enough memory to generate traffic log\n");
3014 }
Zhu Yib481de92007-09-25 17:54:57 -07003015 return strnlen(buf, count);
3016}
3017
Ester Kummer8cf769c2008-05-06 11:05:11 +08003018static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
3019 show_debug_level, store_debug_level);
3020
Zhu Yib481de92007-09-25 17:54:57 -07003021
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003022#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07003023
Zhu Yib481de92007-09-25 17:54:57 -07003024
3025static ssize_t show_temperature(struct device *d,
3026 struct device_attribute *attr, char *buf)
3027{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003028 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003029
Tomas Winklerfee12472008-04-03 16:05:21 -07003030 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003031 return -EAGAIN;
3032
Emmanuel Grumbach91dbc5b2008-06-12 09:47:14 +08003033 return sprintf(buf, "%d\n", priv->temperature);
Zhu Yib481de92007-09-25 17:54:57 -07003034}
3035
3036static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
3037
Zhu Yib481de92007-09-25 17:54:57 -07003038static ssize_t show_tx_power(struct device *d,
3039 struct device_attribute *attr, char *buf)
3040{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003041 struct iwl_priv *priv = dev_get_drvdata(d);
Jay Sternberg91f39e82008-12-17 16:52:34 +08003042
3043 if (!iwl_is_ready_rf(priv))
3044 return sprintf(buf, "off\n");
3045 else
3046 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07003047}
3048
3049static ssize_t store_tx_power(struct device *d,
3050 struct device_attribute *attr,
3051 const char *buf, size_t count)
3052{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003053 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler9257746f2008-09-03 11:26:32 +08003054 unsigned long val;
3055 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003056
Tomas Winkler9257746f2008-09-03 11:26:32 +08003057 ret = strict_strtoul(buf, 10, &val);
3058 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08003059 IWL_INFO(priv, "%s is not in decimal form.\n", buf);
Wey-Yi Guy5eadd942009-08-21 13:34:17 -07003060 else {
3061 ret = iwl_set_tx_power(priv, val, false);
3062 if (ret)
3063 IWL_ERR(priv, "failed setting tx power (0x%d).\n",
3064 ret);
3065 else
3066 ret = count;
3067 }
3068 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003069}
3070
3071static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
3072
3073static ssize_t show_flags(struct device *d,
3074 struct device_attribute *attr, char *buf)
3075{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003076 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003077
3078 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
3079}
3080
3081static ssize_t store_flags(struct device *d,
3082 struct device_attribute *attr,
3083 const char *buf, size_t count)
3084{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003085 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler9257746f2008-09-03 11:26:32 +08003086 unsigned long val;
3087 u32 flags;
3088 int ret = strict_strtoul(buf, 0, &val);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08003089 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08003090 return ret;
3091 flags = (u32)val;
Zhu Yib481de92007-09-25 17:54:57 -07003092
3093 mutex_lock(&priv->mutex);
3094 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
3095 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08003096 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003097 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003098 else {
Tomas Winklere1623442009-01-27 14:27:56 -08003099 IWL_DEBUG_INFO(priv, "Commit rxon.flags = 0x%04X\n", flags);
Zhu Yib481de92007-09-25 17:54:57 -07003100 priv->staging_rxon.flags = cpu_to_le32(flags);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003101 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003102 }
3103 }
3104 mutex_unlock(&priv->mutex);
3105
3106 return count;
3107}
3108
3109static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
3110
3111static ssize_t show_filter_flags(struct device *d,
3112 struct device_attribute *attr, char *buf)
3113{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003114 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003115
3116 return sprintf(buf, "0x%04X\n",
3117 le32_to_cpu(priv->active_rxon.filter_flags));
3118}
3119
3120static ssize_t store_filter_flags(struct device *d,
3121 struct device_attribute *attr,
3122 const char *buf, size_t count)
3123{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07003124 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler9257746f2008-09-03 11:26:32 +08003125 unsigned long val;
3126 u32 filter_flags;
3127 int ret = strict_strtoul(buf, 0, &val);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08003128 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08003129 return ret;
3130 filter_flags = (u32)val;
Zhu Yib481de92007-09-25 17:54:57 -07003131
3132 mutex_lock(&priv->mutex);
3133 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
3134 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08003135 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003136 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003137 else {
Tomas Winklere1623442009-01-27 14:27:56 -08003138 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
Zhu Yib481de92007-09-25 17:54:57 -07003139 "0x%04X\n", filter_flags);
3140 priv->staging_rxon.filter_flags =
3141 cpu_to_le32(filter_flags);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003142 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003143 }
3144 }
3145 mutex_unlock(&priv->mutex);
3146
3147 return count;
3148}
3149
3150static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
3151 store_filter_flags);
3152
Zhu Yib481de92007-09-25 17:54:57 -07003153
3154static ssize_t show_statistics(struct device *d,
3155 struct device_attribute *attr, char *buf)
3156{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003157 struct iwl_priv *priv = dev_get_drvdata(d);
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08003158 u32 size = sizeof(struct iwl_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07003159 u32 len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003160 u8 *data = (u8 *)&priv->statistics;
Zhu Yib481de92007-09-25 17:54:57 -07003161 int rc = 0;
3162
Tomas Winklerfee12472008-04-03 16:05:21 -07003163 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003164 return -EAGAIN;
3165
3166 mutex_lock(&priv->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08003167 rc = iwl_send_statistics_request(priv, CMD_SYNC, false);
Zhu Yib481de92007-09-25 17:54:57 -07003168 mutex_unlock(&priv->mutex);
3169
3170 if (rc) {
3171 len = sprintf(buf,
3172 "Error sending statistics request: 0x%08X\n", rc);
3173 return len;
3174 }
3175
3176 while (size && (PAGE_SIZE - len)) {
3177 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
3178 PAGE_SIZE - len, 1);
3179 len = strlen(buf);
3180 if (PAGE_SIZE - len)
3181 buf[len++] = '\n';
3182
3183 ofs += 16;
3184 size -= min(size, 16U);
3185 }
3186
3187 return len;
3188}
3189
3190static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
3191
Wey-Yi Guy01abfbb2009-09-17 10:43:45 -07003192static ssize_t show_rts_ht_protection(struct device *d,
3193 struct device_attribute *attr, char *buf)
3194{
3195 struct iwl_priv *priv = dev_get_drvdata(d);
3196
3197 return sprintf(buf, "%s\n",
3198 priv->cfg->use_rts_for_ht ? "RTS/CTS" : "CTS-to-self");
3199}
3200
3201static ssize_t store_rts_ht_protection(struct device *d,
3202 struct device_attribute *attr,
3203 const char *buf, size_t count)
3204{
3205 struct iwl_priv *priv = dev_get_drvdata(d);
3206 unsigned long val;
3207 int ret;
3208
3209 ret = strict_strtoul(buf, 10, &val);
3210 if (ret)
3211 IWL_INFO(priv, "Input is not in decimal form.\n");
3212 else {
3213 if (!iwl_is_associated(priv))
3214 priv->cfg->use_rts_for_ht = val ? true : false;
3215 else
3216 IWL_ERR(priv, "Sta associated with AP - "
3217 "Change protection mechanism is not allowed\n");
3218 ret = count;
3219 }
3220 return ret;
3221}
3222
3223static DEVICE_ATTR(rts_ht_protection, S_IWUSR | S_IRUGO,
3224 show_rts_ht_protection, store_rts_ht_protection);
3225
Zhu Yib481de92007-09-25 17:54:57 -07003226
Zhu Yib481de92007-09-25 17:54:57 -07003227/*****************************************************************************
3228 *
3229 * driver setup and teardown
3230 *
3231 *****************************************************************************/
3232
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003233static void iwl_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003234{
Reinette Chatred21050c2009-02-13 11:51:18 -08003235 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07003236
3237 init_waitqueue_head(&priv->wait_command_queue);
3238
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003239 INIT_WORK(&priv->up, iwl_bg_up);
3240 INIT_WORK(&priv->restart, iwl_bg_restart);
3241 INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003242 INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08003243 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08003244 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
3245 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
Tomas Winkler2a421b92008-06-12 09:47:10 +08003246
Tomas Winkler2a421b92008-06-12 09:47:10 +08003247 iwl_setup_scan_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003248
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003249 if (priv->cfg->ops->lib->setup_deferred_work)
3250 priv->cfg->ops->lib->setup_deferred_work(priv);
3251
3252 init_timer(&priv->statistics_periodic);
3253 priv->statistics_periodic.data = (unsigned long)priv;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003254 priv->statistics_periodic.function = iwl_bg_statistics_periodic;
Zhu Yib481de92007-09-25 17:54:57 -07003255
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08003256 init_timer(&priv->ucode_trace);
3257 priv->ucode_trace.data = (unsigned long)priv;
3258 priv->ucode_trace.function = iwl_bg_ucode_trace;
3259
Mohamed Abbasef850d72009-05-22 11:01:50 -07003260 if (!priv->cfg->use_isr_legacy)
3261 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
3262 iwl_irq_tasklet, (unsigned long)priv);
3263 else
3264 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
3265 iwl_irq_tasklet_legacy, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07003266}
3267
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003268static void iwl_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003269{
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003270 if (priv->cfg->ops->lib->cancel_deferred_work)
3271 priv->cfg->ops->lib->cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003272
Joonwoo Park3ae6a052007-11-29 10:43:16 +09003273 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07003274 cancel_delayed_work(&priv->scan_check);
3275 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07003276 cancel_work_sync(&priv->beacon_update);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003277 del_timer_sync(&priv->statistics_periodic);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08003278 del_timer_sync(&priv->ucode_trace);
Zhu Yib481de92007-09-25 17:54:57 -07003279}
3280
Reinette Chatre89f186a2009-10-30 14:36:11 -07003281static void iwl_init_hw_rates(struct iwl_priv *priv,
3282 struct ieee80211_rate *rates)
3283{
3284 int i;
3285
3286 for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
3287 rates[i].bitrate = iwl_rates[i].ieee * 5;
3288 rates[i].hw_value = i; /* Rate scaling will work on indexes */
3289 rates[i].hw_value_short = i;
3290 rates[i].flags = 0;
3291 if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
3292 /*
3293 * If CCK != 1M then set short preamble rate flag.
3294 */
3295 rates[i].flags |=
3296 (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
3297 0 : IEEE80211_RATE_SHORT_PREAMBLE;
3298 }
3299 }
3300}
3301
3302static int iwl_init_drv(struct iwl_priv *priv)
3303{
3304 int ret;
3305
3306 priv->ibss_beacon = NULL;
3307
3308 spin_lock_init(&priv->lock);
3309 spin_lock_init(&priv->sta_lock);
3310 spin_lock_init(&priv->hcmd_lock);
3311
3312 INIT_LIST_HEAD(&priv->free_frames);
3313
3314 mutex_init(&priv->mutex);
3315
3316 /* Clear the driver's (not device's) station table */
3317 iwl_clear_stations_table(priv);
3318
3319 priv->ieee_channels = NULL;
3320 priv->ieee_rates = NULL;
3321 priv->band = IEEE80211_BAND_2GHZ;
3322
3323 priv->iw_mode = NL80211_IFTYPE_STATION;
3324
3325 /* Choose which receivers/antennas to use */
3326 if (priv->cfg->ops->hcmd->set_rxon_chain)
3327 priv->cfg->ops->hcmd->set_rxon_chain(priv);
3328
3329 iwl_init_scan_params(priv);
3330
3331 iwl_reset_qos(priv);
3332
3333 priv->qos_data.qos_active = 0;
3334 priv->qos_data.qos_cap.val = 0;
3335
3336 priv->rates_mask = IWL_RATES_MASK;
3337 /* Set the tx_power_user_lmt to the lowest power level
3338 * this value will get overwritten by channel max power avg
3339 * from eeprom */
3340 priv->tx_power_user_lmt = IWL_TX_POWER_TARGET_POWER_MIN;
3341
3342 ret = iwl_init_channel_map(priv);
3343 if (ret) {
3344 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
3345 goto err;
3346 }
3347
3348 ret = iwlcore_init_geos(priv);
3349 if (ret) {
3350 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
3351 goto err_free_channel_map;
3352 }
3353 iwl_init_hw_rates(priv, priv->ieee_rates);
3354
3355 return 0;
3356
3357err_free_channel_map:
3358 iwl_free_channel_map(priv);
3359err:
3360 return ret;
3361}
3362
3363static void iwl_uninit_drv(struct iwl_priv *priv)
3364{
3365 iwl_calib_free_results(priv);
3366 iwlcore_free_geos(priv);
3367 iwl_free_channel_map(priv);
3368 kfree(priv->scan);
3369}
3370
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003371static struct attribute *iwl_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07003372 &dev_attr_flags.attr,
3373 &dev_attr_filter_flags.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003374 &dev_attr_statistics.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003375 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003376 &dev_attr_tx_power.attr,
Wey-Yi Guy01abfbb2009-09-17 10:43:45 -07003377 &dev_attr_rts_ht_protection.attr,
Ester Kummer8cf769c2008-05-06 11:05:11 +08003378#ifdef CONFIG_IWLWIFI_DEBUG
3379 &dev_attr_debug_level.attr,
3380#endif
Zhu Yib481de92007-09-25 17:54:57 -07003381 NULL
3382};
3383
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003384static struct attribute_group iwl_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07003385 .name = NULL, /* put in device directory */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003386 .attrs = iwl_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07003387};
3388
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003389static struct ieee80211_ops iwl_hw_ops = {
3390 .tx = iwl_mac_tx,
3391 .start = iwl_mac_start,
3392 .stop = iwl_mac_stop,
3393 .add_interface = iwl_mac_add_interface,
3394 .remove_interface = iwl_mac_remove_interface,
3395 .config = iwl_mac_config,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003396 .configure_filter = iwl_configure_filter,
3397 .set_key = iwl_mac_set_key,
3398 .update_tkip_key = iwl_mac_update_tkip_key,
3399 .get_stats = iwl_mac_get_stats,
3400 .get_tx_stats = iwl_mac_get_tx_stats,
3401 .conf_tx = iwl_mac_conf_tx,
3402 .reset_tsf = iwl_mac_reset_tsf,
3403 .bss_info_changed = iwl_bss_info_changed,
3404 .ampdu_action = iwl_mac_ampdu_action,
Johannes Berg6ab10ff2009-11-13 11:56:37 -08003405 .hw_scan = iwl_mac_hw_scan,
3406 .sta_notify = iwl_mac_sta_notify,
Zhu Yib481de92007-09-25 17:54:57 -07003407};
3408
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003409static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07003410{
3411 int err = 0;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003412 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07003413 struct ieee80211_hw *hw;
Tomas Winkler82b9a122008-03-04 18:09:30 -08003414 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003415 unsigned long flags;
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003416 u16 pci_cmd;
Zhu Yib481de92007-09-25 17:54:57 -07003417
Assaf Krauss316c30d2008-03-14 10:38:46 -07003418 /************************
3419 * 1. Allocating HW data
3420 ************************/
3421
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003422 /* Disabling hardware scan means that mac80211 will perform scans
3423 * "the hard way", rather than using device's scan. */
Assaf Krauss1ea87392008-03-18 14:57:50 -07003424 if (cfg->mod_params->disable_hw_scan) {
Reinette Chatrea562a9d2009-07-17 09:30:24 -07003425 if (iwl_debug_level & IWL_DL_INFO)
Ester Kummerbf403db2008-05-05 10:22:40 +08003426 dev_printk(KERN_DEBUG, &(pdev->dev),
3427 "Disabling hw_scan\n");
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003428 iwl_hw_ops.hw_scan = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07003429 }
3430
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003431 hw = iwl_alloc_all(cfg, &iwl_hw_ops);
Assaf Krauss1d0a0822008-03-14 10:38:48 -07003432 if (!hw) {
Zhu Yib481de92007-09-25 17:54:57 -07003433 err = -ENOMEM;
3434 goto out;
3435 }
Assaf Krauss1d0a0822008-03-14 10:38:48 -07003436 priv = hw->priv;
3437 /* At this point both hw and priv are allocated. */
3438
Zhu Yib481de92007-09-25 17:54:57 -07003439 SET_IEEE80211_DEV(hw, &pdev->dev);
3440
Tomas Winklere1623442009-01-27 14:27:56 -08003441 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Tomas Winkler82b9a122008-03-04 18:09:30 -08003442 priv->cfg = cfg;
Zhu Yib481de92007-09-25 17:54:57 -07003443 priv->pci_dev = pdev;
Mohamed Abbas40cefda2009-05-22 11:01:52 -07003444 priv->inta_mask = CSR_INI_SET_MASK;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003445
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003446#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07003447 atomic_set(&priv->restrict_refcnt, 0);
3448#endif
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003449 if (iwl_alloc_traffic_mem(priv))
3450 IWL_ERR(priv, "Not enough memory to generate traffic log\n");
Zhu Yib481de92007-09-25 17:54:57 -07003451
Assaf Krauss316c30d2008-03-14 10:38:46 -07003452 /**************************
3453 * 2. Initializing PCI bus
3454 **************************/
3455 if (pci_enable_device(pdev)) {
3456 err = -ENODEV;
3457 goto out_ieee80211_free_hw;
3458 }
3459
3460 pci_set_master(pdev);
3461
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003462 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
Assaf Krauss316c30d2008-03-14 10:38:46 -07003463 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003464 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003465 if (err) {
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003466 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003467 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003468 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003469 /* both attempts failed: */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003470 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08003471 IWL_WARN(priv, "No suitable DMA available.\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07003472 goto out_pci_disable_device;
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003473 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07003474 }
3475
3476 err = pci_request_regions(pdev, DRV_NAME);
3477 if (err)
3478 goto out_pci_disable_device;
3479
3480 pci_set_drvdata(pdev, priv);
3481
Assaf Krauss316c30d2008-03-14 10:38:46 -07003482
3483 /***********************
3484 * 3. Read REV register
3485 ***********************/
3486 priv->hw_base = pci_iomap(pdev, 0, 0);
3487 if (!priv->hw_base) {
3488 err = -ENODEV;
3489 goto out_pci_release_regions;
3490 }
3491
Tomas Winklere1623442009-01-27 14:27:56 -08003492 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Assaf Krauss316c30d2008-03-14 10:38:46 -07003493 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08003494 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003495
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07003496 /* this spin lock will be used in apm_ops.init and EEPROM access
3497 * we should init now
3498 */
3499 spin_lock_init(&priv->reg_lock);
Tomas Winklerb661c812008-04-23 17:14:54 -07003500 iwl_hw_detect(priv);
Tomas Winkler978785a2008-12-19 10:37:31 +08003501 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s REV=0x%X\n",
Tomas Winklerb661c812008-04-23 17:14:54 -07003502 priv->cfg->name, priv->hw_rev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003503
Tomas Winklere7b63582008-09-03 11:26:49 +08003504 /* We disable the RETRY_TIMEOUT register (0x41) to keep
3505 * PCI Tx retries from interfering with C3 CPU state */
3506 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
3507
Mohamed Abbas086ed112009-05-22 11:01:54 -07003508 iwl_prepare_card_hw(priv);
3509 if (!priv->hw_ready) {
3510 IWL_WARN(priv, "Failed, HW not ready\n");
3511 goto out_iounmap;
3512 }
3513
Assaf Krauss316c30d2008-03-14 10:38:46 -07003514 /*****************
3515 * 4. Read EEPROM
3516 *****************/
Assaf Krauss316c30d2008-03-14 10:38:46 -07003517 /* Read the EEPROM */
3518 err = iwl_eeprom_init(priv);
3519 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003520 IWL_ERR(priv, "Unable to init EEPROM\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07003521 goto out_iounmap;
3522 }
Tomas Winkler8614f362008-04-23 17:14:55 -07003523 err = iwl_eeprom_check_version(priv);
3524 if (err)
Reinette Chatrec8f16132009-02-27 16:21:22 -08003525 goto out_free_eeprom;
Tomas Winkler8614f362008-04-23 17:14:55 -07003526
Ron Rindjunsky02883012008-05-15 13:53:53 +08003527 /* extract MAC Address */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003528 iwl_eeprom_get_mac(priv, priv->mac_addr);
Tomas Winklere1623442009-01-27 14:27:56 -08003529 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003530 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
3531
3532 /************************
3533 * 5. Setup HW constants
3534 ************************/
Ron Rindjunskyda154e302008-06-30 17:23:20 +08003535 if (iwl_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003536 IWL_ERR(priv, "failed to set hw parameters\n");
Tomas Winkler073d3f52008-04-21 15:41:52 -07003537 goto out_free_eeprom;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003538 }
3539
3540 /*******************
Tomas Winkler6ba87952008-05-15 13:54:17 +08003541 * 6. Setup priv
Assaf Krauss316c30d2008-03-14 10:38:46 -07003542 *******************/
Zhu Yib481de92007-09-25 17:54:57 -07003543
Tomas Winkler6ba87952008-05-15 13:54:17 +08003544 err = iwl_init_drv(priv);
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003545 if (err)
Ron Rindjunsky399f4902008-04-23 17:14:56 -07003546 goto out_free_eeprom;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003547 /* At this point both hw and priv are initialized. */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003548
Assaf Krauss316c30d2008-03-14 10:38:46 -07003549 /********************
Abhijeet Kolekar09f9bf72009-04-20 14:37:03 -07003550 * 7. Setup services
Assaf Krauss316c30d2008-03-14 10:38:46 -07003551 ********************/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003552 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003553 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003554 spin_unlock_irqrestore(&priv->lock, flags);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003555
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003556 pci_enable_msi(priv->pci_dev);
3557
Mohamed Abbasef850d72009-05-22 11:01:50 -07003558 iwl_alloc_isr_ict(priv);
3559 err = request_irq(priv->pci_dev->irq, priv->cfg->ops->lib->isr,
3560 IRQF_SHARED, DRV_NAME, priv);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003561 if (err) {
3562 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
3563 goto out_disable_msi;
3564 }
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003565 err = sysfs_create_group(&pdev->dev.kobj, &iwl_attribute_group);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003566 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003567 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Helmut Schaa795cc0a2009-02-12 18:51:03 +01003568 goto out_free_irq;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003569 }
3570
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003571 iwl_setup_deferred_work(priv);
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08003572 iwl_setup_rx_handlers(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003573
Tomas Winkler6ba87952008-05-15 13:54:17 +08003574 /**********************************
Abhijeet Kolekar09f9bf72009-04-20 14:37:03 -07003575 * 8. Setup and register mac80211
Tomas Winkler6ba87952008-05-15 13:54:17 +08003576 **********************************/
3577
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003578 /* enable interrupts if needed: hw bug w/a */
3579 pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd);
3580 if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
3581 pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
3582 pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
3583 }
3584
3585 iwl_enable_interrupts(priv);
3586
Tomas Winkler6ba87952008-05-15 13:54:17 +08003587 err = iwl_setup_mac(priv);
3588 if (err)
3589 goto out_remove_sysfs;
3590
3591 err = iwl_dbgfs_register(priv, DRV_NAME);
3592 if (err)
Abhijeet Kolekara75fbe82009-04-20 14:36:58 -07003593 IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
Tomas Winkler6ba87952008-05-15 13:54:17 +08003594
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003595 /* If platform's RF_KILL switch is NOT set to KILL */
3596 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3597 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3598 else
3599 set_bit(STATUS_RF_KILL_HW, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003600
Johannes Berga60e77e2009-06-04 18:26:06 +02003601 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
3602 test_bit(STATUS_RF_KILL_HW, &priv->status));
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003603
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08003604 iwl_power_initialize(priv);
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -07003605 iwl_tt_initialize(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003606 return 0;
3607
Assaf Krauss316c30d2008-03-14 10:38:46 -07003608 out_remove_sysfs:
Reinette Chatrec8f16132009-02-27 16:21:22 -08003609 destroy_workqueue(priv->workqueue);
3610 priv->workqueue = NULL;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003611 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
Helmut Schaa795cc0a2009-02-12 18:51:03 +01003612 out_free_irq:
3613 free_irq(priv->pci_dev->irq, priv);
Mohamed Abbasef850d72009-05-22 11:01:50 -07003614 iwl_free_isr_ict(priv);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003615 out_disable_msi:
3616 pci_disable_msi(priv->pci_dev);
Tomas Winkler6ba87952008-05-15 13:54:17 +08003617 iwl_uninit_drv(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07003618 out_free_eeprom:
3619 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003620 out_iounmap:
3621 pci_iounmap(pdev, priv->hw_base);
3622 out_pci_release_regions:
Assaf Krauss316c30d2008-03-14 10:38:46 -07003623 pci_set_drvdata(pdev, NULL);
Reinette Chatre623d5632009-03-03 11:37:04 -08003624 pci_release_regions(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07003625 out_pci_disable_device:
3626 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07003627 out_ieee80211_free_hw:
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003628 iwl_free_traffic_mem(priv);
Wey-Yi Guyd7c76f42009-10-09 13:20:17 -07003629 ieee80211_free_hw(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07003630 out:
3631 return err;
3632}
3633
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003634static void __devexit iwl_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07003635{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003636 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003637 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07003638
3639 if (!priv)
3640 return;
3641
Tomas Winklere1623442009-01-27 14:27:56 -08003642 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07003643
Emmanuel Grumbach67249622008-05-29 16:35:26 +08003644 iwl_dbgfs_unregister(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003645 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
Emmanuel Grumbach67249622008-05-29 16:35:26 +08003646
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003647 /* ieee80211_unregister_hw call wil cause iwl_mac_stop to
3648 * to be called and iwl_down since we are removing the device
Gregory Greenman0b124c32008-09-03 11:18:50 +08003649 * we need to set STATUS_EXIT_PENDING bit.
3650 */
3651 set_bit(STATUS_EXIT_PENDING, &priv->status);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07003652 if (priv->mac80211_registered) {
3653 ieee80211_unregister_hw(priv->hw);
3654 priv->mac80211_registered = 0;
Gregory Greenman0b124c32008-09-03 11:18:50 +08003655 } else {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003656 iwl_down(priv);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07003657 }
3658
Ben Cahillc166b252009-10-23 13:42:35 -07003659 /*
3660 * Make sure device is reset to low power before unloading driver.
3661 * This may be redundant with iwl_down(), but there are paths to
3662 * run iwl_down() without calling apm_ops.stop(), and there are
3663 * paths to avoid running iwl_down() at all before leaving driver.
3664 * This (inexpensive) call *makes sure* device is reset.
3665 */
3666 priv->cfg->ops->lib->apm_ops.stop(priv);
3667
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -07003668 iwl_tt_exit(priv);
3669
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003670 /* make sure we flush any pending irq or
3671 * tasklet for the driver
3672 */
3673 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003674 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003675 spin_unlock_irqrestore(&priv->lock, flags);
3676
3677 iwl_synchronize_irq(priv);
3678
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003679 iwl_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003680
3681 if (priv->rxq.bd)
Tomas Winklera55360e2008-05-05 10:22:28 +08003682 iwl_rx_queue_free(priv, &priv->rxq);
Ron Rindjunsky1053d352008-05-05 10:22:43 +08003683 iwl_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003684
Tomas Winklerc587de02009-06-03 11:44:07 -07003685 iwl_clear_stations_table(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07003686 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003687
Zhu Yib481de92007-09-25 17:54:57 -07003688
Mohamed Abbas948c1712007-10-25 17:15:45 +08003689 /*netif_stop_queue(dev); */
3690 flush_workqueue(priv->workqueue);
3691
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003692 /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07003693 * priv->workqueue... so we can't take down the workqueue
3694 * until now... */
3695 destroy_workqueue(priv->workqueue);
3696 priv->workqueue = NULL;
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003697 iwl_free_traffic_mem(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003698
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003699 free_irq(priv->pci_dev->irq, priv);
3700 pci_disable_msi(priv->pci_dev);
Zhu Yib481de92007-09-25 17:54:57 -07003701 pci_iounmap(pdev, priv->hw_base);
3702 pci_release_regions(pdev);
3703 pci_disable_device(pdev);
3704 pci_set_drvdata(pdev, NULL);
3705
Tomas Winkler6ba87952008-05-15 13:54:17 +08003706 iwl_uninit_drv(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003707
Mohamed Abbasef850d72009-05-22 11:01:50 -07003708 iwl_free_isr_ict(priv);
3709
Zhu Yib481de92007-09-25 17:54:57 -07003710 if (priv->ibss_beacon)
3711 dev_kfree_skb(priv->ibss_beacon);
3712
3713 ieee80211_free_hw(priv->hw);
3714}
3715
Zhu Yib481de92007-09-25 17:54:57 -07003716
3717/*****************************************************************************
3718 *
3719 * driver and module entry point
3720 *
3721 *****************************************************************************/
3722
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003723/* Hardware specific file defines the PCI IDs table for that hardware module */
3724static struct pci_device_id iwl_hw_card_ids[] = {
Tomas Winkler4fc22b22008-07-21 18:54:42 +03003725#ifdef CONFIG_IWL4965
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003726 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
3727 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
Tomas Winkler4fc22b22008-07-21 18:54:42 +03003728#endif /* CONFIG_IWL4965 */
Tomas Winkler5a6a2562008-04-24 11:55:23 -07003729#ifdef CONFIG_IWL5000
Wey-Yi Guyac592572009-11-20 12:05:03 -08003730/* 5100 Series WiFi */
3731 {IWL_PCI_DEVICE(0x4232, 0x1201, iwl5100_agn_cfg)}, /* Mini Card */
3732 {IWL_PCI_DEVICE(0x4232, 0x1301, iwl5100_agn_cfg)}, /* Half Mini Card */
3733 {IWL_PCI_DEVICE(0x4232, 0x1204, iwl5100_agn_cfg)}, /* Mini Card */
3734 {IWL_PCI_DEVICE(0x4232, 0x1304, iwl5100_agn_cfg)}, /* Half Mini Card */
3735 {IWL_PCI_DEVICE(0x4232, 0x1205, iwl5100_bgn_cfg)}, /* Mini Card */
3736 {IWL_PCI_DEVICE(0x4232, 0x1305, iwl5100_bgn_cfg)}, /* Half Mini Card */
3737 {IWL_PCI_DEVICE(0x4232, 0x1206, iwl5100_abg_cfg)}, /* Mini Card */
3738 {IWL_PCI_DEVICE(0x4232, 0x1306, iwl5100_abg_cfg)}, /* Half Mini Card */
3739 {IWL_PCI_DEVICE(0x4232, 0x1221, iwl5100_agn_cfg)}, /* Mini Card */
3740 {IWL_PCI_DEVICE(0x4232, 0x1321, iwl5100_agn_cfg)}, /* Half Mini Card */
3741 {IWL_PCI_DEVICE(0x4232, 0x1224, iwl5100_agn_cfg)}, /* Mini Card */
3742 {IWL_PCI_DEVICE(0x4232, 0x1324, iwl5100_agn_cfg)}, /* Half Mini Card */
3743 {IWL_PCI_DEVICE(0x4232, 0x1225, iwl5100_bgn_cfg)}, /* Mini Card */
3744 {IWL_PCI_DEVICE(0x4232, 0x1325, iwl5100_bgn_cfg)}, /* Half Mini Card */
3745 {IWL_PCI_DEVICE(0x4232, 0x1226, iwl5100_abg_cfg)}, /* Mini Card */
3746 {IWL_PCI_DEVICE(0x4232, 0x1326, iwl5100_abg_cfg)}, /* Half Mini Card */
3747 {IWL_PCI_DEVICE(0x4237, 0x1211, iwl5100_agn_cfg)}, /* Mini Card */
3748 {IWL_PCI_DEVICE(0x4237, 0x1311, iwl5100_agn_cfg)}, /* Half Mini Card */
3749 {IWL_PCI_DEVICE(0x4237, 0x1214, iwl5100_agn_cfg)}, /* Mini Card */
3750 {IWL_PCI_DEVICE(0x4237, 0x1314, iwl5100_agn_cfg)}, /* Half Mini Card */
3751 {IWL_PCI_DEVICE(0x4237, 0x1215, iwl5100_bgn_cfg)}, /* Mini Card */
3752 {IWL_PCI_DEVICE(0x4237, 0x1315, iwl5100_bgn_cfg)}, /* Half Mini Card */
3753 {IWL_PCI_DEVICE(0x4237, 0x1216, iwl5100_abg_cfg)}, /* Mini Card */
3754 {IWL_PCI_DEVICE(0x4237, 0x1316, iwl5100_abg_cfg)}, /* Half Mini Card */
3755
3756/* 5300 Series WiFi */
3757 {IWL_PCI_DEVICE(0x4235, 0x1021, iwl5300_agn_cfg)}, /* Mini Card */
3758 {IWL_PCI_DEVICE(0x4235, 0x1121, iwl5300_agn_cfg)}, /* Half Mini Card */
3759 {IWL_PCI_DEVICE(0x4235, 0x1024, iwl5300_agn_cfg)}, /* Mini Card */
3760 {IWL_PCI_DEVICE(0x4235, 0x1124, iwl5300_agn_cfg)}, /* Half Mini Card */
3761 {IWL_PCI_DEVICE(0x4235, 0x1001, iwl5300_agn_cfg)}, /* Mini Card */
3762 {IWL_PCI_DEVICE(0x4235, 0x1101, iwl5300_agn_cfg)}, /* Half Mini Card */
3763 {IWL_PCI_DEVICE(0x4235, 0x1004, iwl5300_agn_cfg)}, /* Mini Card */
3764 {IWL_PCI_DEVICE(0x4235, 0x1104, iwl5300_agn_cfg)}, /* Half Mini Card */
3765 {IWL_PCI_DEVICE(0x4236, 0x1011, iwl5300_agn_cfg)}, /* Mini Card */
3766 {IWL_PCI_DEVICE(0x4236, 0x1111, iwl5300_agn_cfg)}, /* Half Mini Card */
3767 {IWL_PCI_DEVICE(0x4236, 0x1014, iwl5300_agn_cfg)}, /* Mini Card */
3768 {IWL_PCI_DEVICE(0x4236, 0x1114, iwl5300_agn_cfg)}, /* Half Mini Card */
3769
3770/* 5350 Series WiFi/WiMax */
3771 {IWL_PCI_DEVICE(0x423A, 0x1001, iwl5350_agn_cfg)}, /* Mini Card */
3772 {IWL_PCI_DEVICE(0x423A, 0x1021, iwl5350_agn_cfg)}, /* Mini Card */
3773 {IWL_PCI_DEVICE(0x423B, 0x1011, iwl5350_agn_cfg)}, /* Mini Card */
3774
3775/* 5150 Series Wifi/WiMax */
3776 {IWL_PCI_DEVICE(0x423C, 0x1201, iwl5150_agn_cfg)}, /* Mini Card */
3777 {IWL_PCI_DEVICE(0x423C, 0x1301, iwl5150_agn_cfg)}, /* Half Mini Card */
3778 {IWL_PCI_DEVICE(0x423C, 0x1206, iwl5150_abg_cfg)}, /* Mini Card */
3779 {IWL_PCI_DEVICE(0x423C, 0x1306, iwl5150_abg_cfg)}, /* Half Mini Card */
3780 {IWL_PCI_DEVICE(0x423C, 0x1221, iwl5150_agn_cfg)}, /* Mini Card */
3781 {IWL_PCI_DEVICE(0x423C, 0x1321, iwl5150_agn_cfg)}, /* Half Mini Card */
3782
3783 {IWL_PCI_DEVICE(0x423D, 0x1211, iwl5150_agn_cfg)}, /* Mini Card */
3784 {IWL_PCI_DEVICE(0x423D, 0x1311, iwl5150_agn_cfg)}, /* Half Mini Card */
3785 {IWL_PCI_DEVICE(0x423D, 0x1216, iwl5150_abg_cfg)}, /* Mini Card */
3786 {IWL_PCI_DEVICE(0x423D, 0x1316, iwl5150_abg_cfg)}, /* Half Mini Card */
Wey-Yi Guy5953a622009-09-17 10:43:53 -07003787
3788/* 6x00 Series */
Wey-Yi Guy5953a622009-09-17 10:43:53 -07003789 {IWL_PCI_DEVICE(0x422B, 0x1101, iwl6000_3agn_cfg)},
3790 {IWL_PCI_DEVICE(0x422B, 0x1121, iwl6000_3agn_cfg)},
3791 {IWL_PCI_DEVICE(0x422C, 0x1301, iwl6000i_2agn_cfg)},
3792 {IWL_PCI_DEVICE(0x422C, 0x1306, iwl6000i_2abg_cfg)},
3793 {IWL_PCI_DEVICE(0x422C, 0x1307, iwl6000i_2bg_cfg)},
3794 {IWL_PCI_DEVICE(0x422C, 0x1321, iwl6000i_2agn_cfg)},
3795 {IWL_PCI_DEVICE(0x422C, 0x1326, iwl6000i_2abg_cfg)},
3796 {IWL_PCI_DEVICE(0x4238, 0x1111, iwl6000_3agn_cfg)},
3797 {IWL_PCI_DEVICE(0x4239, 0x1311, iwl6000i_2agn_cfg)},
3798 {IWL_PCI_DEVICE(0x4239, 0x1316, iwl6000i_2abg_cfg)},
3799
3800/* 6x50 WiFi/WiMax Series */
Wey-Yi Guy5953a622009-09-17 10:43:53 -07003801 {IWL_PCI_DEVICE(0x0087, 0x1301, iwl6050_2agn_cfg)},
3802 {IWL_PCI_DEVICE(0x0087, 0x1306, iwl6050_2abg_cfg)},
3803 {IWL_PCI_DEVICE(0x0087, 0x1321, iwl6050_2agn_cfg)},
3804 {IWL_PCI_DEVICE(0x0087, 0x1326, iwl6050_2abg_cfg)},
Wey-Yi Guy5953a622009-09-17 10:43:53 -07003805 {IWL_PCI_DEVICE(0x0089, 0x1311, iwl6050_2agn_cfg)},
3806 {IWL_PCI_DEVICE(0x0089, 0x1316, iwl6050_2abg_cfg)},
3807
Jay Sternberg77dcb6a2009-03-06 13:52:55 -08003808/* 1000 Series WiFi */
Wey-Yi Guy4bd0914f2009-09-17 10:43:52 -07003809 {IWL_PCI_DEVICE(0x0083, 0x1205, iwl1000_bgn_cfg)},
3810 {IWL_PCI_DEVICE(0x0083, 0x1305, iwl1000_bgn_cfg)},
3811 {IWL_PCI_DEVICE(0x0083, 0x1225, iwl1000_bgn_cfg)},
3812 {IWL_PCI_DEVICE(0x0083, 0x1325, iwl1000_bgn_cfg)},
3813 {IWL_PCI_DEVICE(0x0084, 0x1215, iwl1000_bgn_cfg)},
3814 {IWL_PCI_DEVICE(0x0084, 0x1315, iwl1000_bgn_cfg)},
3815 {IWL_PCI_DEVICE(0x0083, 0x1206, iwl1000_bg_cfg)},
3816 {IWL_PCI_DEVICE(0x0083, 0x1306, iwl1000_bg_cfg)},
3817 {IWL_PCI_DEVICE(0x0083, 0x1226, iwl1000_bg_cfg)},
3818 {IWL_PCI_DEVICE(0x0083, 0x1326, iwl1000_bg_cfg)},
3819 {IWL_PCI_DEVICE(0x0084, 0x1216, iwl1000_bg_cfg)},
3820 {IWL_PCI_DEVICE(0x0084, 0x1316, iwl1000_bg_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07003821#endif /* CONFIG_IWL5000 */
Tomas Winkler7100e922008-12-01 16:32:18 -08003822
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003823 {0}
3824};
3825MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
3826
3827static struct pci_driver iwl_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07003828 .name = DRV_NAME,
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003829 .id_table = iwl_hw_card_ids,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003830 .probe = iwl_pci_probe,
3831 .remove = __devexit_p(iwl_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07003832#ifdef CONFIG_PM
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003833 .suspend = iwl_pci_suspend,
3834 .resume = iwl_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07003835#endif
3836};
3837
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003838static int __init iwl_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07003839{
3840
3841 int ret;
3842 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
3843 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003844
Tomas Winklere227cea2008-07-18 13:53:05 +08003845 ret = iwlagn_rate_control_register();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003846 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08003847 printk(KERN_ERR DRV_NAME
3848 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003849 return ret;
3850 }
3851
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003852 ret = pci_register_driver(&iwl_driver);
Zhu Yib481de92007-09-25 17:54:57 -07003853 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08003854 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003855 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07003856 }
Zhu Yib481de92007-09-25 17:54:57 -07003857
3858 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003859
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003860error_register:
Tomas Winklere227cea2008-07-18 13:53:05 +08003861 iwlagn_rate_control_unregister();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003862 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003863}
3864
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003865static void __exit iwl_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07003866{
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003867 pci_unregister_driver(&iwl_driver);
Tomas Winklere227cea2008-07-18 13:53:05 +08003868 iwlagn_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07003869}
3870
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003871module_exit(iwl_exit);
3872module_init(iwl_init);
Reinette Chatrea562a9d2009-07-17 09:30:24 -07003873
3874#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07003875module_param_named(debug50, iwl_debug_level, uint, S_IRUGO);
Reinette Chatrea562a9d2009-07-17 09:30:24 -07003876MODULE_PARM_DESC(debug50, "50XX debug output mask (deprecated)");
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07003877module_param_named(debug, iwl_debug_level, uint, S_IRUGO | S_IWUSR);
Reinette Chatrea562a9d2009-07-17 09:30:24 -07003878MODULE_PARM_DESC(debug, "debug output mask");
3879#endif
3880