blob: 313d3e5ee84bfe7f26b03dd56fd693168e974c67 [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;
Emmanuel Grumbacha326a5d2008-07-11 11:53:31 +0800119 /* allow CTS-to-self if possible. this is relevant only for
120 * 5000, but will not damage 4965 */
121 priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN;
Zhu Yib481de92007-09-25 17:54:57 -0700122
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800123 ret = iwl_check_rxon_cmd(priv);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800124 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800125 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700126 return -EINVAL;
127 }
128
129 /* If we don't need to send a full RXON, we can use
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700130 * iwl_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -0700131 * and other flags for the current radio configuration. */
Mohamed Abbas54559702008-09-03 11:18:44 +0800132 if (!iwl_full_rxon_required(priv)) {
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800133 ret = iwl_send_rxon_assoc(priv);
134 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800135 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800136 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700137 }
138
139 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700140 return 0;
141 }
142
143 /* station table will be cleared */
144 priv->assoc_station_added = 0;
145
Zhu Yib481de92007-09-25 17:54:57 -0700146 /* If we are currently associated and the new config requires
147 * an RXON_ASSOC and the new config wants the associated mask enabled,
148 * we must clear the associated from the active configuration
149 * before we apply the new config */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800150 if (iwl_is_associated(priv) && new_assoc) {
Tomas Winklere1623442009-01-27 14:27:56 -0800151 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
Zhu Yib481de92007-09-25 17:54:57 -0700152 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
153
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800154 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800155 sizeof(struct iwl_rxon_cmd),
Zhu Yib481de92007-09-25 17:54:57 -0700156 &priv->active_rxon);
157
158 /* If the mask clearing failed then we set
159 * active_rxon back to what it was previously */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800160 if (ret) {
Zhu Yib481de92007-09-25 17:54:57 -0700161 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
Winkler, Tomas15b16872008-12-19 10:37:33 +0800162 IWL_ERR(priv, "Error clearing ASSOC_MSK (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800163 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700164 }
Zhu Yib481de92007-09-25 17:54:57 -0700165 }
166
Tomas Winklere1623442009-01-27 14:27:56 -0800167 IWL_DEBUG_INFO(priv, "Sending RXON\n"
Zhu Yib481de92007-09-25 17:54:57 -0700168 "* with%s RXON_FILTER_ASSOC_MSK\n"
169 "* channel = %d\n"
Johannes Berge1749612008-10-27 15:59:26 -0700170 "* bssid = %pM\n",
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800171 (new_assoc ? "" : "out"),
Zhu Yib481de92007-09-25 17:54:57 -0700172 le16_to_cpu(priv->staging_rxon.channel),
Johannes Berge1749612008-10-27 15:59:26 -0700173 priv->staging_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -0700174
Tomas Winkler90e8e422009-06-19 13:52:42 -0700175 iwl_set_rxon_hwcrypto(priv, !priv->cfg->mod_params->sw_crypto);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800176
177 /* Apply the new configuration
178 * RXON unassoc clears the station table in uCode, send it before
179 * we add the bcast station. If assoc bit is set, we will send RXON
180 * after having added the bcast and bssid station.
181 */
182 if (!new_assoc) {
183 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800184 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800185 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800186 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800187 return ret;
188 }
189 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700190 }
191
Tomas Winklerc587de02009-06-03 11:44:07 -0700192 iwl_clear_stations_table(priv);
Zhu Yi556f8db2007-09-27 11:27:33 +0800193
Johannes Berg19cc1082009-05-08 13:44:36 -0700194 priv->start_calib = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700195
Zhu Yib481de92007-09-25 17:54:57 -0700196 /* Add the broadcast address so we can send broadcast frames */
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800197 if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) ==
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800198 IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800199 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700200 return -EIO;
201 }
202
203 /* If we have set the ASSOC_MSK and we are in BSS mode then
204 * add the IWL_AP_ID to the station rate table */
Tomas Winkler91851592008-06-30 17:23:14 +0800205 if (new_assoc) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200206 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Tomas Winkler91851592008-06-30 17:23:14 +0800207 ret = iwl_rxon_add_station(priv,
208 priv->active_rxon.bssid_addr, 1);
209 if (ret == IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800210 IWL_ERR(priv,
211 "Error adding AP address for TX.\n");
Tomas Winkler91851592008-06-30 17:23:14 +0800212 return -EIO;
213 }
214 priv->assoc_station_added = 1;
215 if (priv->default_wep_key &&
216 iwl_send_static_wepkey_cmd(priv, 0))
Winkler, Tomas15b16872008-12-19 10:37:33 +0800217 IWL_ERR(priv,
218 "Could not send WEP static key.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700219 }
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800220
221 /* Apply the new configuration
222 * RXON assoc doesn't clear the station table in uCode,
223 */
224 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
225 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
226 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800227 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800228 return ret;
229 }
230 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700231 }
232
Zhu Yi36da7d72008-07-11 11:53:40 +0800233 iwl_init_sensitivity(priv);
234
235 /* If we issue a new RXON command which required a tune then we must
236 * send a new TXPOWER command or we won't be able to Tx any frames */
237 ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
238 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800239 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
Zhu Yi36da7d72008-07-11 11:53:40 +0800240 return ret;
241 }
242
Zhu Yib481de92007-09-25 17:54:57 -0700243 return 0;
244}
245
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700246void iwl_update_chain_flags(struct iwl_priv *priv)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700247{
248
Abhijeet Kolekar45823532009-04-08 11:26:44 -0700249 if (priv->cfg->ops->hcmd->set_rxon_chain)
250 priv->cfg->ops->hcmd->set_rxon_chain(priv);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -0700251 iwlcore_commit_rxon(priv);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700252}
253
Tomas Winklerfcab4232008-05-15 13:54:01 +0800254static void iwl_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700255{
256 struct list_head *element;
257
Tomas Winklere1623442009-01-27 14:27:56 -0800258 IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
Zhu Yib481de92007-09-25 17:54:57 -0700259 priv->frames_count);
260
261 while (!list_empty(&priv->free_frames)) {
262 element = priv->free_frames.next;
263 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800264 kfree(list_entry(element, struct iwl_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700265 priv->frames_count--;
266 }
267
268 if (priv->frames_count) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800269 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
Zhu Yib481de92007-09-25 17:54:57 -0700270 priv->frames_count);
271 priv->frames_count = 0;
272 }
273}
274
Tomas Winklerfcab4232008-05-15 13:54:01 +0800275static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700276{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800277 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700278 struct list_head *element;
279 if (list_empty(&priv->free_frames)) {
280 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
281 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800282 IWL_ERR(priv, "Could not allocate frame!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700283 return NULL;
284 }
285
286 priv->frames_count++;
287 return frame;
288 }
289
290 element = priv->free_frames.next;
291 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800292 return list_entry(element, struct iwl_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700293}
294
Tomas Winklerfcab4232008-05-15 13:54:01 +0800295static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700296{
297 memset(frame, 0, sizeof(*frame));
298 list_add(&frame->list, &priv->free_frames);
299}
300
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800301static unsigned int iwl_fill_beacon_frame(struct iwl_priv *priv,
302 struct ieee80211_hdr *hdr,
Rami Rosen73ec1cc2008-12-16 09:37:07 +0200303 int left)
Zhu Yib481de92007-09-25 17:54:57 -0700304{
Tomas Winkler3109ece2008-03-28 16:33:35 -0700305 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200306 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
307 (priv->iw_mode != NL80211_IFTYPE_AP)))
Zhu Yib481de92007-09-25 17:54:57 -0700308 return 0;
309
310 if (priv->ibss_beacon->len > left)
311 return 0;
312
313 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
314
315 return priv->ibss_beacon->len;
316}
317
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700318static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800319 struct iwl_frame *frame, u8 rate)
320{
321 struct iwl_tx_beacon_cmd *tx_beacon_cmd;
322 unsigned int frame_size;
323
324 tx_beacon_cmd = &frame->u.beacon;
325 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
326
327 tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
328 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
329
330 frame_size = iwl_fill_beacon_frame(priv, tx_beacon_cmd->frame,
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800331 sizeof(frame->u) - sizeof(*tx_beacon_cmd));
332
333 BUG_ON(frame_size > MAX_MPDU_SIZE);
334 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
335
336 if ((rate == IWL_RATE_1M_PLCP) || (rate >= IWL_RATE_2M_PLCP))
337 tx_beacon_cmd->tx.rate_n_flags =
338 iwl_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK);
339 else
340 tx_beacon_cmd->tx.rate_n_flags =
341 iwl_hw_set_rate_n_flags(rate, 0);
342
343 tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
344 TX_CMD_FLG_TSF_MSK |
345 TX_CMD_FLG_STA_RATE_MSK;
346
347 return sizeof(*tx_beacon_cmd) + frame_size;
348}
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700349static int iwl_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700350{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800351 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700352 unsigned int frame_size;
353 int rc;
354 u8 rate;
355
Tomas Winklerfcab4232008-05-15 13:54:01 +0800356 frame = iwl_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700357
358 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800359 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
Zhu Yib481de92007-09-25 17:54:57 -0700360 "command.\n");
361 return -ENOMEM;
362 }
363
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700364 rate = iwl_rate_get_lowest_plcp(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700365
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700366 frame_size = iwl_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -0700367
Tomas Winkler857485c2008-03-21 13:53:44 -0700368 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700369 &frame->u.cmd[0]);
370
Tomas Winklerfcab4232008-05-15 13:54:01 +0800371 iwl_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700372
373 return rc;
374}
375
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800376static inline dma_addr_t iwl_tfd_tb_get_addr(struct iwl_tfd *tfd, u8 idx)
377{
378 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
379
380 dma_addr_t addr = get_unaligned_le32(&tb->lo);
381 if (sizeof(dma_addr_t) > sizeof(u32))
382 addr |=
383 ((dma_addr_t)(le16_to_cpu(tb->hi_n_len) & 0xF) << 16) << 16;
384
385 return addr;
386}
387
388static inline u16 iwl_tfd_tb_get_len(struct iwl_tfd *tfd, u8 idx)
389{
390 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
391
392 return le16_to_cpu(tb->hi_n_len) >> 4;
393}
394
395static inline void iwl_tfd_set_tb(struct iwl_tfd *tfd, u8 idx,
396 dma_addr_t addr, u16 len)
397{
398 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
399 u16 hi_n_len = len << 4;
400
401 put_unaligned_le32(addr, &tb->lo);
402 if (sizeof(dma_addr_t) > sizeof(u32))
403 hi_n_len |= ((addr >> 16) >> 16) & 0xF;
404
405 tb->hi_n_len = cpu_to_le16(hi_n_len);
406
407 tfd->num_tbs = idx + 1;
408}
409
410static inline u8 iwl_tfd_get_num_tbs(struct iwl_tfd *tfd)
411{
412 return tfd->num_tbs & 0x1f;
413}
414
415/**
416 * iwl_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
417 * @priv - driver private data
418 * @txq - tx queue
419 *
420 * Does NOT advance any TFD circular buffer read/write indexes
421 * Does NOT free the TFD itself (which is within circular buffer)
422 */
423void iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq)
424{
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800425 struct iwl_tfd *tfd_tmp = (struct iwl_tfd *)txq->tfds;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800426 struct iwl_tfd *tfd;
427 struct pci_dev *dev = priv->pci_dev;
428 int index = txq->q.read_ptr;
429 int i;
430 int num_tbs;
431
432 tfd = &tfd_tmp[index];
433
434 /* Sanity check on number of chunks */
435 num_tbs = iwl_tfd_get_num_tbs(tfd);
436
437 if (num_tbs >= IWL_NUM_OF_TBS) {
438 IWL_ERR(priv, "Too many chunks: %i\n", num_tbs);
439 /* @todo issue fatal error, it is quite serious situation */
440 return;
441 }
442
443 /* Unmap tx_cmd */
444 if (num_tbs)
445 pci_unmap_single(dev,
Johannes Bergc2acea82009-07-24 11:13:05 -0700446 pci_unmap_addr(&txq->meta[index], mapping),
447 pci_unmap_len(&txq->meta[index], len),
Fenghua Yu96891ce2009-02-18 15:54:33 -0800448 PCI_DMA_BIDIRECTIONAL);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800449
450 /* Unmap chunks, if any. */
451 for (i = 1; i < num_tbs; i++) {
452 pci_unmap_single(dev, iwl_tfd_tb_get_addr(tfd, i),
453 iwl_tfd_tb_get_len(tfd, i), PCI_DMA_TODEVICE);
454
455 if (txq->txb) {
456 dev_kfree_skb(txq->txb[txq->q.read_ptr].skb[i - 1]);
457 txq->txb[txq->q.read_ptr].skb[i - 1] = NULL;
458 }
459 }
460}
461
462int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv,
463 struct iwl_tx_queue *txq,
464 dma_addr_t addr, u16 len,
465 u8 reset, u8 pad)
466{
467 struct iwl_queue *q;
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800468 struct iwl_tfd *tfd, *tfd_tmp;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800469 u32 num_tbs;
470
471 q = &txq->q;
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800472 tfd_tmp = (struct iwl_tfd *)txq->tfds;
473 tfd = &tfd_tmp[q->write_ptr];
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800474
475 if (reset)
476 memset(tfd, 0, sizeof(*tfd));
477
478 num_tbs = iwl_tfd_get_num_tbs(tfd);
479
480 /* Each TFD can point to a maximum 20 Tx buffers */
481 if (num_tbs >= IWL_NUM_OF_TBS) {
482 IWL_ERR(priv, "Error can not send more than %d chunks\n",
483 IWL_NUM_OF_TBS);
484 return -EINVAL;
485 }
486
487 BUG_ON(addr & ~DMA_BIT_MASK(36));
488 if (unlikely(addr & ~IWL_TX_DMA_MASK))
489 IWL_ERR(priv, "Unaligned address = %llx\n",
490 (unsigned long long)addr);
491
492 iwl_tfd_set_tb(tfd, num_tbs, addr, len);
493
494 return 0;
495}
496
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800497/*
498 * Tell nic where to find circular buffer of Tx Frame Descriptors for
499 * given Tx queue, and enable the DMA channel used for that queue.
500 *
501 * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
502 * channels supported in hardware.
503 */
504int iwl_hw_tx_queue_init(struct iwl_priv *priv,
505 struct iwl_tx_queue *txq)
506{
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800507 int txq_id = txq->q.id;
508
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800509 /* Circular buffer (TFD queue in DRAM) physical base address */
510 iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
511 txq->q.dma_addr >> 8);
512
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800513 return 0;
514}
515
Zhu Yib481de92007-09-25 17:54:57 -0700516/******************************************************************************
517 *
518 * Generic RX handler implementations
519 *
520 ******************************************************************************/
Tomas Winkler885ba202008-05-29 16:34:55 +0800521static void iwl_rx_reply_alive(struct iwl_priv *priv,
522 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700523{
Tomas Winklerdb11d632008-05-05 10:22:33 +0800524 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Tomas Winkler885ba202008-05-29 16:34:55 +0800525 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -0700526 struct delayed_work *pwork;
527
528 palive = &pkt->u.alive_frame;
529
Tomas Winklere1623442009-01-27 14:27:56 -0800530 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
Zhu Yib481de92007-09-25 17:54:57 -0700531 "0x%01X 0x%01X\n",
532 palive->is_valid, palive->ver_type,
533 palive->ver_subtype);
534
535 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
Tomas Winklere1623442009-01-27 14:27:56 -0800536 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700537 memcpy(&priv->card_alive_init,
538 &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +0800539 sizeof(struct iwl_init_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700540 pwork = &priv->init_alive_start;
541 } else {
Tomas Winklere1623442009-01-27 14:27:56 -0800542 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700543 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +0800544 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700545 pwork = &priv->alive_start;
546 }
547
548 /* We delay the ALIVE response by 5ms to
549 * give the HW RF Kill time to activate... */
550 if (palive->is_valid == UCODE_VALID_OK)
551 queue_delayed_work(priv->workqueue, pwork,
552 msecs_to_jiffies(5));
553 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800554 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700555}
556
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700557static void iwl_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -0700558{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700559 struct iwl_priv *priv =
560 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -0700561 struct sk_buff *beacon;
562
563 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +0200564 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -0700565
566 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800567 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -0700568 return;
569 }
570
571 mutex_lock(&priv->mutex);
572 /* new beacon skb is allocated every time; dispose previous.*/
573 if (priv->ibss_beacon)
574 dev_kfree_skb(priv->ibss_beacon);
575
576 priv->ibss_beacon = beacon;
577 mutex_unlock(&priv->mutex);
578
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700579 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700580}
581
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800582/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700583 * iwl_bg_statistics_periodic - Timer callback to queue statistics
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800584 *
585 * This callback is provided in order to send a statistics request.
586 *
587 * This timer function is continually reset to execute within
588 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
589 * was received. We need to ensure we receive the statistics in order
590 * to update the temperature used for calibrating the TXPOWER.
591 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700592static void iwl_bg_statistics_periodic(unsigned long data)
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800593{
594 struct iwl_priv *priv = (struct iwl_priv *)data;
595
596 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
597 return;
598
Mohamed Abbas61780ee2008-10-29 14:05:49 -0700599 /* dont send host command if rf-kill is on */
600 if (!iwl_is_ready_rf(priv))
601 return;
602
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800603 iwl_send_statistics_request(priv, CMD_ASYNC);
604}
605
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700606static void iwl_rx_beacon_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +0800607 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700608{
Tomas Winkler0a6857e2008-03-12 16:58:49 -0700609#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklerdb11d632008-05-05 10:22:33 +0800610 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Tomas Winkler2aa6ab82008-12-11 10:33:40 -0800611 struct iwl4965_beacon_notif *beacon =
612 (struct iwl4965_beacon_notif *)pkt->u.raw;
Tomas Winklere7d326a2008-06-12 09:47:11 +0800613 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -0700614
Tomas Winklere1623442009-01-27 14:27:56 -0800615 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
Zhu Yib481de92007-09-25 17:54:57 -0700616 "tsf %d %d rate %d\n",
Tomas Winkler25a65722008-06-12 09:47:07 +0800617 le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
Zhu Yib481de92007-09-25 17:54:57 -0700618 beacon->beacon_notify_hdr.failure_frame,
619 le32_to_cpu(beacon->ibss_mgr_status),
620 le32_to_cpu(beacon->high_tsf),
621 le32_to_cpu(beacon->low_tsf), rate);
622#endif
623
Johannes Berg05c914f2008-09-11 00:01:58 +0200624 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -0700625 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
626 queue_work(priv->workqueue, &priv->beacon_update);
627}
628
Zhu Yib481de92007-09-25 17:54:57 -0700629/* Handle notification from uCode that card's power state is changing
630 * due to software, hardware, or critical temperature RFKILL */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700631static void iwl_rx_card_state_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +0800632 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700633{
Tomas Winklerdb11d632008-05-05 10:22:33 +0800634 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700635 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
636 unsigned long status = priv->status;
637
Tomas Winklere1623442009-01-27 14:27:56 -0800638 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
Zhu Yib481de92007-09-25 17:54:57 -0700639 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
640 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
641
642 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
643 RF_CARD_DISABLED)) {
644
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700645 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -0700646 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
647
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700648 iwl_write_direct32(priv, HBUS_TARG_MBX_C,
649 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
Zhu Yib481de92007-09-25 17:54:57 -0700650
651 if (!(flags & RXON_CARD_DISABLED)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700652 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -0700653 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700654 iwl_write_direct32(priv, HBUS_TARG_MBX_C,
Zhu Yib481de92007-09-25 17:54:57 -0700655 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
Zhu Yib481de92007-09-25 17:54:57 -0700656 }
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -0700657 if (flags & RF_CARD_DISABLED)
658 iwl_tt_enter_ct_kill(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700659 }
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -0700660 if (!(flags & RF_CARD_DISABLED))
661 iwl_tt_exit_ct_kill(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700662
663 if (flags & HW_CARD_DISABLED)
664 set_bit(STATUS_RF_KILL_HW, &priv->status);
665 else
666 clear_bit(STATUS_RF_KILL_HW, &priv->status);
667
668
Zhu Yib481de92007-09-25 17:54:57 -0700669 if (!(flags & RXON_CARD_DISABLED))
Tomas Winkler2a421b92008-06-12 09:47:10 +0800670 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700671
672 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
Johannes Berga60e77e2009-06-04 18:26:06 +0200673 test_bit(STATUS_RF_KILL_HW, &priv->status)))
674 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
675 test_bit(STATUS_RF_KILL_HW, &priv->status));
Zhu Yib481de92007-09-25 17:54:57 -0700676 else
677 wake_up_interruptible(&priv->wait_command_queue);
678}
679
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700680int iwl_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
Tomas Winklere2e3c572008-07-18 13:53:04 +0800681{
Tomas Winklere2e3c572008-07-18 13:53:04 +0800682 if (src == IWL_PWR_SRC_VAUX) {
Tomas Winkler3fdb68d2009-02-10 15:19:02 -0800683 if (pci_pme_capable(priv->pci_dev, PCI_D3cold))
Tomas Winklere2e3c572008-07-18 13:53:04 +0800684 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
685 APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
686 ~APMG_PS_CTRL_MSK_PWR_SRC);
687 } else {
688 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
689 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
690 ~APMG_PS_CTRL_MSK_PWR_SRC);
691 }
692
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700693 return 0;
Tomas Winklere2e3c572008-07-18 13:53:04 +0800694}
695
Zhu Yib481de92007-09-25 17:54:57 -0700696/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700697 * iwl_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -0700698 *
699 * Setup the RX handlers for each of the reply types sent from the uCode
700 * to the host.
701 *
702 * This function chains into the hardware specific files for them to setup
703 * any hardware specific handlers as well.
704 */
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +0800705static void iwl_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700706{
Tomas Winkler885ba202008-05-29 16:34:55 +0800707 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700708 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
709 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700710 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700711 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700712 iwl_rx_pm_debug_statistics_notif;
713 priv->rx_handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700714
Ben Cahill9fbab512007-11-29 11:09:47 +0800715 /*
716 * The same handler is used for both the REPLY to a discrete
717 * statistics request from the host as well as for the periodic
718 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -0700719 */
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +0800720 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_rx_statistics;
721 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
Tomas Winkler2a421b92008-06-12 09:47:10 +0800722
Tomas Winkler21c339b2008-11-07 09:58:41 -0800723 iwl_setup_spectrum_handlers(priv);
Tomas Winkler2a421b92008-06-12 09:47:10 +0800724 iwl_setup_rx_scan_handlers(priv);
725
Ron Rindjunsky37a44212008-05-29 16:35:18 +0800726 /* status change handler */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700727 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700728
Tomas Winklerc1354752008-05-29 16:35:04 +0800729 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
730 iwl_rx_missed_beacon_notif;
Ron Rindjunsky37a44212008-05-29 16:35:18 +0800731 /* Rx handlers */
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800732 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl_rx_reply_rx_phy;
733 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl_rx_reply_rx;
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +0800734 /* block ack */
735 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl_rx_reply_compressed_ba;
Ben Cahill9fbab512007-11-29 11:09:47 +0800736 /* Set up hardware specific Rx handlers */
Emmanuel Grumbachd4789ef2008-04-24 11:55:20 -0700737 priv->cfg->ops->lib->rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700738}
739
Zhu Yib481de92007-09-25 17:54:57 -0700740/**
Tomas Winklera55360e2008-05-05 10:22:28 +0800741 * iwl_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -0700742 *
743 * Uses the priv->rx_handlers callback function array to invoke
744 * the appropriate handlers, including command responses,
745 * frame-received notifications, and other notifications.
746 */
Tomas Winklera55360e2008-05-05 10:22:28 +0800747void iwl_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700748{
Tomas Winklera55360e2008-05-05 10:22:28 +0800749 struct iwl_rx_mem_buffer *rxb;
Tomas Winklerdb11d632008-05-05 10:22:33 +0800750 struct iwl_rx_packet *pkt;
Tomas Winklera55360e2008-05-05 10:22:28 +0800751 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -0700752 u32 r, i;
753 int reclaim;
754 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800755 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -0800756 u32 count = 8;
Mohamed Abbas4752c932009-05-22 11:01:51 -0700757 int total_empty;
Zhu Yib481de92007-09-25 17:54:57 -0700758
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800759 /* uCode's read index (stored in shared DRAM) indicates the last Rx
760 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8d864222008-11-07 09:58:39 -0800761 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -0700762 i = rxq->read;
763
764 /* Rx interrupt, but nothing sent from uCode */
765 if (i == r)
Tomas Winklere1623442009-01-27 14:27:56 -0800766 IWL_DEBUG_RX(priv, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -0700767
Mohamed Abbas4752c932009-05-22 11:01:51 -0700768 /* calculate total frames need to be restock after handling RX */
769 total_empty = r - priv->rxq.write_actual;
770 if (total_empty < 0)
771 total_empty += RX_QUEUE_SIZE;
772
773 if (total_empty > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800774 fill_rx = 1;
775
Zhu Yib481de92007-09-25 17:54:57 -0700776 while (i != r) {
777 rxb = rxq->queue[i];
778
Ben Cahill9fbab512007-11-29 11:09:47 +0800779 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -0700780 * then a bug has been introduced in the queue refilling
781 * routines -- catch it here */
782 BUG_ON(rxb == NULL);
783
784 rxq->queue[i] = NULL;
785
Reinette Chatredf833b12009-04-21 10:55:48 -0700786 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
787 priv->hw_params.rx_buf_size + 256,
788 PCI_DMA_FROMDEVICE);
Tomas Winklerdb11d632008-05-05 10:22:33 +0800789 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700790
791 /* Reclaim a command buffer only if this packet is a response
792 * to a (driver-originated) command.
793 * If the packet (e.g. Rx frame) originated from uCode,
794 * there is no command buffer to reclaim.
795 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
796 * but apparently a few don't get set; catch them here. */
797 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
798 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
Tomas Winkler857485c2008-03-21 13:53:44 -0700799 (pkt->hdr.cmd != REPLY_RX) &&
Daniel Halperin7dddaf12008-10-23 23:48:58 -0700800 (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) &&
Zhu Yicfe01702007-09-27 11:27:31 +0800801 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
Zhu Yib481de92007-09-25 17:54:57 -0700802 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
803 (pkt->hdr.cmd != REPLY_TX);
804
805 /* Based on type of command response or notification,
806 * handle those that need handling via function in
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700807 * rx_handlers table. See iwl_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -0700808 if (priv->rx_handlers[pkt->hdr.cmd]) {
Tomas Winklere1623442009-01-27 14:27:56 -0800809 IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r,
Ester Kummerf3d67992008-05-06 11:05:12 +0800810 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700811 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700812 priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
Zhu Yib481de92007-09-25 17:54:57 -0700813 } else {
814 /* No handling needed */
Tomas Winklere1623442009-01-27 14:27:56 -0800815 IWL_DEBUG_RX(priv,
Zhu Yib481de92007-09-25 17:54:57 -0700816 "r %d i %d No handler needed for %s, 0x%02x\n",
817 r, i, get_cmd_string(pkt->hdr.cmd),
818 pkt->hdr.cmd);
819 }
820
821 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +0800822 /* Invoke any callbacks, transfer the skb to caller, and
Tomas Winkler857485c2008-03-21 13:53:44 -0700823 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -0700824 * as we reclaim the driver command queue */
825 if (rxb && rxb->skb)
Tomas Winkler17b88922008-05-29 16:35:12 +0800826 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -0700827 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800828 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -0700829 }
830
831 /* For now we just don't re-use anything. We can tweak this
832 * later to try and re-use notification packets and SKBs that
833 * fail to Rx correctly */
834 if (rxb->skb != NULL) {
835 priv->alloc_rxb_skb--;
836 dev_kfree_skb_any(rxb->skb);
837 rxb->skb = NULL;
838 }
839
Zhu Yib481de92007-09-25 17:54:57 -0700840 spin_lock_irqsave(&rxq->lock, flags);
841 list_add_tail(&rxb->list, &priv->rxq.rx_used);
842 spin_unlock_irqrestore(&rxq->lock, flags);
843 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800844 /* If there are a lot of unused frames,
845 * restock the Rx queue so ucode wont assert. */
846 if (fill_rx) {
847 count++;
848 if (count >= 8) {
849 priv->rxq.read = i;
Mohamed Abbas4752c932009-05-22 11:01:51 -0700850 iwl_rx_replenish_now(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800851 count = 0;
852 }
853 }
Zhu Yib481de92007-09-25 17:54:57 -0700854 }
855
856 /* Backtrack one entry */
857 priv->rxq.read = i;
Mohamed Abbas4752c932009-05-22 11:01:51 -0700858 if (fill_rx)
859 iwl_rx_replenish_now(priv);
860 else
861 iwl_rx_queue_restock(priv);
Tomas Winklera55360e2008-05-05 10:22:28 +0800862}
Tomas Winklera55360e2008-05-05 10:22:28 +0800863
Mohamed Abbas0359fac2008-03-28 16:21:08 -0700864/* call this function to flush any scheduled tasklet */
865static inline void iwl_synchronize_irq(struct iwl_priv *priv)
866{
Tomas Winklera96a27f2008-10-23 23:48:56 -0700867 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -0700868 synchronize_irq(priv->pci_dev->irq);
869 tasklet_kill(&priv->irq_tasklet);
870}
871
Mohamed Abbasef850d72009-05-22 11:01:50 -0700872static void iwl_irq_tasklet_legacy(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700873{
874 u32 inta, handled = 0;
875 u32 inta_fh;
876 unsigned long flags;
Tomas Winkler0a6857e2008-03-12 16:58:49 -0700877#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -0700878 u32 inta_mask;
879#endif
880
881 spin_lock_irqsave(&priv->lock, flags);
882
883 /* Ack/clear/reset pending uCode interrupts.
884 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
885 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700886 inta = iwl_read32(priv, CSR_INT);
887 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -0700888
889 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
890 * Any new interrupts that happen after this, either while we're
891 * in this tasklet, or later, will show up in next ISR/tasklet. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700892 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
893 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -0700894
Tomas Winkler0a6857e2008-03-12 16:58:49 -0700895#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -0700896 if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +0800897 /* just for debug */
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700898 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Tomas Winklere1623442009-01-27 14:27:56 -0800899 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -0700900 inta, inta_mask, inta_fh);
901 }
902#endif
903
904 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
905 * atomic, make sure that inta covers all the interrupts that
906 * we've discovered, even if FH interrupt came in just after
907 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -0800908 if (inta_fh & CSR49_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -0700909 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -0800910 if (inta_fh & CSR49_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -0700911 inta |= CSR_INT_BIT_FH_TX;
912
913 /* Now service all interrupt bits discovered above. */
914 if (inta & CSR_INT_BIT_HW_ERR) {
Reinette Chatre58dba722009-07-17 09:30:25 -0700915 IWL_ERR(priv, "Hardware error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700916
917 /* Tell the device to stop sending interrupts */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700918 iwl_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700919
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700920 priv->isr_stats.hw++;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700921 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700922
923 handled |= CSR_INT_BIT_HW_ERR;
924
925 spin_unlock_irqrestore(&priv->lock, flags);
926
927 return;
928 }
929
Tomas Winkler0a6857e2008-03-12 16:58:49 -0700930#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -0700931 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -0700932 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700933 if (inta & CSR_INT_BIT_SCD) {
Tomas Winklere1623442009-01-27 14:27:56 -0800934 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
Joonwoo Park25c03d82008-01-23 10:15:20 -0800935 "the frame/frames.\n");
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700936 priv->isr_stats.sch++;
937 }
Zhu Yib481de92007-09-25 17:54:57 -0700938
939 /* Alive notification via Rx interrupt will do the real work */
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700940 if (inta & CSR_INT_BIT_ALIVE) {
Tomas Winklere1623442009-01-27 14:27:56 -0800941 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700942 priv->isr_stats.alive++;
943 }
Zhu Yib481de92007-09-25 17:54:57 -0700944 }
945#endif
946 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -0800947 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -0700948
Ben Cahill9fbab512007-11-29 11:09:47 +0800949 /* HW RF KILL switch toggled */
Zhu Yib481de92007-09-25 17:54:57 -0700950 if (inta & CSR_INT_BIT_RF_KILL) {
951 int hw_rf_kill = 0;
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700952 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yib481de92007-09-25 17:54:57 -0700953 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
954 hw_rf_kill = 1;
955
Reinette Chatre4c423a22009-07-17 09:30:26 -0700956 IWL_WARN(priv, "RF_KILL bit toggled to %s.\n",
Abhijeet Kolekarc3056062008-11-12 13:14:08 -0800957 hw_rf_kill ? "disable radio" : "enable radio");
Zhu Yib481de92007-09-25 17:54:57 -0700958
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700959 priv->isr_stats.rfkill++;
960
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +0800961 /* driver only loads ucode once setting the interface up.
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +0100962 * the driver allows loading the ucode even if the radio
963 * is killed. Hence update the killswitch state here. The
964 * rfkill handler will care about restarting if needed.
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +0800965 */
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +0100966 if (!test_bit(STATUS_ALIVE, &priv->status)) {
967 if (hw_rf_kill)
968 set_bit(STATUS_RF_KILL_HW, &priv->status);
969 else
970 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Johannes Berga60e77e2009-06-04 18:26:06 +0200971 wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
Mohamed Abbasedb34222008-12-11 10:33:37 -0800972 }
Zhu Yib481de92007-09-25 17:54:57 -0700973
974 handled |= CSR_INT_BIT_RF_KILL;
975 }
976
Ben Cahill9fbab512007-11-29 11:09:47 +0800977 /* Chip got too hot and stopped itself */
Zhu Yib481de92007-09-25 17:54:57 -0700978 if (inta & CSR_INT_BIT_CT_KILL) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800979 IWL_ERR(priv, "Microcode CT kill error detected.\n");
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700980 priv->isr_stats.ctkill++;
Zhu Yib481de92007-09-25 17:54:57 -0700981 handled |= CSR_INT_BIT_CT_KILL;
982 }
983
984 /* Error detected by uCode */
985 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800986 IWL_ERR(priv, "Microcode SW error detected. "
987 " Restarting 0x%X.\n", inta);
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700988 priv->isr_stats.sw++;
989 priv->isr_stats.sw_err = inta;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700990 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700991 handled |= CSR_INT_BIT_SW_ERR;
992 }
993
994 /* uCode wakes up after power-down sleep */
995 if (inta & CSR_INT_BIT_WAKEUP) {
Tomas Winklere1623442009-01-27 14:27:56 -0800996 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
Tomas Winklera55360e2008-05-05 10:22:28 +0800997 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Tomas Winklerbabcebf2008-05-15 13:54:00 +0800998 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
999 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
1000 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
1001 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
1002 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1003 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07001004
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001005 priv->isr_stats.wakeup++;
1006
Zhu Yib481de92007-09-25 17:54:57 -07001007 handled |= CSR_INT_BIT_WAKEUP;
1008 }
1009
1010 /* All uCode command responses, including Tx command responses,
1011 * Rx "responses" (frame-received notification), and other
1012 * notifications from uCode come through here*/
1013 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Tomas Winklera55360e2008-05-05 10:22:28 +08001014 iwl_rx_handle(priv);
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001015 priv->isr_stats.rx++;
Zhu Yib481de92007-09-25 17:54:57 -07001016 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1017 }
1018
1019 if (inta & CSR_INT_BIT_FH_TX) {
Tomas Winklere1623442009-01-27 14:27:56 -08001020 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001021 priv->isr_stats.tx++;
Zhu Yib481de92007-09-25 17:54:57 -07001022 handled |= CSR_INT_BIT_FH_TX;
Ron Rindjunskydbb983b2008-05-15 13:54:12 +08001023 /* FH finished to write, send event */
1024 priv->ucode_write_complete = 1;
1025 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07001026 }
1027
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001028 if (inta & ~handled) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001029 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001030 priv->isr_stats.unhandled++;
1031 }
Zhu Yib481de92007-09-25 17:54:57 -07001032
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001033 if (inta & ~(priv->inta_mask)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001034 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001035 inta & ~priv->inta_mask);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001036 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001037 }
1038
1039 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001040 /* only Re-enable if diabled by irq */
1041 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001042 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001043
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001044#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001045 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001046 inta = iwl_read32(priv, CSR_INT);
1047 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1048 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Tomas Winklere1623442009-01-27 14:27:56 -08001049 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
Zhu Yib481de92007-09-25 17:54:57 -07001050 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
1051 }
1052#endif
1053 spin_unlock_irqrestore(&priv->lock, flags);
1054}
1055
Mohamed Abbasef850d72009-05-22 11:01:50 -07001056/* tasklet for iwlagn interrupt */
1057static void iwl_irq_tasklet(struct iwl_priv *priv)
1058{
1059 u32 inta = 0;
1060 u32 handled = 0;
1061 unsigned long flags;
1062#ifdef CONFIG_IWLWIFI_DEBUG
1063 u32 inta_mask;
1064#endif
1065
1066 spin_lock_irqsave(&priv->lock, flags);
1067
1068 /* Ack/clear/reset pending uCode interrupts.
1069 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1070 */
1071 iwl_write32(priv, CSR_INT, priv->inta);
1072
1073 inta = priv->inta;
1074
1075#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001076 if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
Mohamed Abbasef850d72009-05-22 11:01:50 -07001077 /* just for debug */
1078 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1079 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x\n ",
1080 inta, inta_mask);
1081 }
1082#endif
1083 /* saved interrupt in inta variable now we can reset priv->inta */
1084 priv->inta = 0;
1085
1086 /* Now service all interrupt bits discovered above. */
1087 if (inta & CSR_INT_BIT_HW_ERR) {
Reinette Chatre58dba722009-07-17 09:30:25 -07001088 IWL_ERR(priv, "Hardware error detected. Restarting.\n");
Mohamed Abbasef850d72009-05-22 11:01:50 -07001089
1090 /* Tell the device to stop sending interrupts */
1091 iwl_disable_interrupts(priv);
1092
1093 priv->isr_stats.hw++;
1094 iwl_irq_handle_error(priv);
1095
1096 handled |= CSR_INT_BIT_HW_ERR;
1097
1098 spin_unlock_irqrestore(&priv->lock, flags);
1099
1100 return;
1101 }
1102
1103#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001104 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Mohamed Abbasef850d72009-05-22 11:01:50 -07001105 /* NIC fires this, but we don't use it, redundant with WAKEUP */
1106 if (inta & CSR_INT_BIT_SCD) {
1107 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
1108 "the frame/frames.\n");
1109 priv->isr_stats.sch++;
1110 }
1111
1112 /* Alive notification via Rx interrupt will do the real work */
1113 if (inta & CSR_INT_BIT_ALIVE) {
1114 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
1115 priv->isr_stats.alive++;
1116 }
1117 }
1118#endif
1119 /* Safely ignore these bits for debug checks below */
1120 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
1121
1122 /* HW RF KILL switch toggled */
1123 if (inta & CSR_INT_BIT_RF_KILL) {
1124 int hw_rf_kill = 0;
1125 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
1126 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
1127 hw_rf_kill = 1;
1128
Reinette Chatre4c423a22009-07-17 09:30:26 -07001129 IWL_WARN(priv, "RF_KILL bit toggled to %s.\n",
Mohamed Abbasef850d72009-05-22 11:01:50 -07001130 hw_rf_kill ? "disable radio" : "enable radio");
1131
1132 priv->isr_stats.rfkill++;
1133
1134 /* driver only loads ucode once setting the interface up.
1135 * the driver allows loading the ucode even if the radio
1136 * is killed. Hence update the killswitch state here. The
1137 * rfkill handler will care about restarting if needed.
1138 */
1139 if (!test_bit(STATUS_ALIVE, &priv->status)) {
1140 if (hw_rf_kill)
1141 set_bit(STATUS_RF_KILL_HW, &priv->status);
1142 else
1143 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Johannes Berga60e77e2009-06-04 18:26:06 +02001144 wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001145 }
1146
1147 handled |= CSR_INT_BIT_RF_KILL;
1148 }
1149
1150 /* Chip got too hot and stopped itself */
1151 if (inta & CSR_INT_BIT_CT_KILL) {
1152 IWL_ERR(priv, "Microcode CT kill error detected.\n");
1153 priv->isr_stats.ctkill++;
1154 handled |= CSR_INT_BIT_CT_KILL;
1155 }
1156
1157 /* Error detected by uCode */
1158 if (inta & CSR_INT_BIT_SW_ERR) {
1159 IWL_ERR(priv, "Microcode SW error detected. "
1160 " Restarting 0x%X.\n", inta);
1161 priv->isr_stats.sw++;
1162 priv->isr_stats.sw_err = inta;
1163 iwl_irq_handle_error(priv);
1164 handled |= CSR_INT_BIT_SW_ERR;
1165 }
1166
1167 /* uCode wakes up after power-down sleep */
1168 if (inta & CSR_INT_BIT_WAKEUP) {
1169 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
1170 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
1171 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
1172 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
1173 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
1174 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
1175 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1176 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
1177
1178 priv->isr_stats.wakeup++;
1179
1180 handled |= CSR_INT_BIT_WAKEUP;
1181 }
1182
1183 /* All uCode command responses, including Tx command responses,
1184 * Rx "responses" (frame-received notification), and other
1185 * notifications from uCode come through here*/
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001186 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX |
1187 CSR_INT_BIT_RX_PERIODIC)) {
Mohamed Abbasef850d72009-05-22 11:01:50 -07001188 IWL_DEBUG_ISR(priv, "Rx interrupt\n");
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001189 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
1190 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1191 iwl_write32(priv, CSR_FH_INT_STATUS,
1192 CSR49_FH_INT_RX_MASK);
1193 }
1194 if (inta & CSR_INT_BIT_RX_PERIODIC) {
1195 handled |= CSR_INT_BIT_RX_PERIODIC;
1196 iwl_write32(priv, CSR_INT, CSR_INT_BIT_RX_PERIODIC);
1197 }
1198 /* Sending RX interrupt require many steps to be done in the
1199 * the device:
1200 * 1- write interrupt to current index in ICT table.
1201 * 2- dma RX frame.
1202 * 3- update RX shared data to indicate last write index.
1203 * 4- send interrupt.
1204 * This could lead to RX race, driver could receive RX interrupt
1205 * but the shared data changes does not reflect this.
1206 * this could lead to RX race, RX periodic will solve this race
1207 */
1208 iwl_write32(priv, CSR_INT_PERIODIC_REG,
1209 CSR_INT_PERIODIC_DIS);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001210 iwl_rx_handle(priv);
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001211 /* Only set RX periodic if real RX is received. */
1212 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX))
1213 iwl_write32(priv, CSR_INT_PERIODIC_REG,
1214 CSR_INT_PERIODIC_ENA);
1215
Mohamed Abbasef850d72009-05-22 11:01:50 -07001216 priv->isr_stats.rx++;
Mohamed Abbasef850d72009-05-22 11:01:50 -07001217 }
1218
1219 if (inta & CSR_INT_BIT_FH_TX) {
1220 iwl_write32(priv, CSR_FH_INT_STATUS, CSR49_FH_INT_TX_MASK);
1221 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
1222 priv->isr_stats.tx++;
1223 handled |= CSR_INT_BIT_FH_TX;
1224 /* FH finished to write, send event */
1225 priv->ucode_write_complete = 1;
1226 wake_up_interruptible(&priv->wait_command_queue);
1227 }
1228
1229 if (inta & ~handled) {
1230 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
1231 priv->isr_stats.unhandled++;
1232 }
1233
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001234 if (inta & ~(priv->inta_mask)) {
Mohamed Abbasef850d72009-05-22 11:01:50 -07001235 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001236 inta & ~priv->inta_mask);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001237 }
1238
1239
1240 /* Re-enable all interrupts */
1241 /* only Re-enable if diabled by irq */
1242 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1243 iwl_enable_interrupts(priv);
1244
1245 spin_unlock_irqrestore(&priv->lock, flags);
1246
1247}
1248
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001249
Zhu Yib481de92007-09-25 17:54:57 -07001250/******************************************************************************
1251 *
1252 * uCode download functions
1253 *
1254 ******************************************************************************/
1255
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001256static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001257{
Tomas Winkler98c92212008-01-14 17:46:20 -08001258 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
1259 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
1260 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1261 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
1262 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1263 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001264}
1265
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001266static void iwl_nic_start(struct iwl_priv *priv)
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08001267{
1268 /* Remove all resets to allow NIC to operate */
1269 iwl_write32(priv, CSR_RESET, 0);
1270}
1271
1272
Zhu Yib481de92007-09-25 17:54:57 -07001273/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001274 * iwl_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07001275 *
1276 * Copy into buffers for card to fetch via bus-mastering
1277 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001278static int iwl_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001279{
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001280 struct iwl_ucode_header *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001281 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07001282 const struct firmware *ucode_raw;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001283 const char *name_pre = priv->cfg->fw_name_pre;
1284 const unsigned int api_max = priv->cfg->ucode_api_max;
1285 const unsigned int api_min = priv->cfg->ucode_api_min;
1286 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07001287 u8 *src;
1288 size_t len;
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001289 u32 api_ver, build;
1290 u32 inst_size, data_size, init_size, init_data_size, boot_size;
Jay Sternbergabdc2d62009-07-31 14:28:09 -07001291 u16 eeprom_ver;
Zhu Yib481de92007-09-25 17:54:57 -07001292
1293 /* Ask kernel firmware_class module to get the boot firmware off disk.
1294 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08001295 for (index = api_max; index >= api_min; index--) {
1296 sprintf(buf, "%s%d%s", name_pre, index, ".ucode");
1297 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
1298 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001299 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001300 buf, ret);
1301 if (ret == -ENOENT)
1302 continue;
1303 else
1304 goto error;
1305 } else {
1306 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08001307 IWL_ERR(priv, "Loaded firmware %s, "
1308 "which is deprecated. "
1309 "Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001310 buf, api_max);
Winkler, Tomas15b16872008-12-19 10:37:33 +08001311
Tomas Winklere1623442009-01-27 14:27:56 -08001312 IWL_DEBUG_INFO(priv, "Got firmware '%s' file (%zd bytes) from disk\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001313 buf, ucode_raw->size);
1314 break;
1315 }
Zhu Yib481de92007-09-25 17:54:57 -07001316 }
1317
Reinette Chatrea0987a82008-12-02 12:14:06 -08001318 if (ret < 0)
1319 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07001320
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001321 /* Make sure that we got at least the v1 header! */
1322 if (ucode_raw->size < priv->cfg->ops->ucode->get_header_size(1)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001323 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001324 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001325 goto err_release;
1326 }
1327
1328 /* Data from ucode file: header followed by uCode images */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001329 ucode = (struct iwl_ucode_header *)ucode_raw->data;
Zhu Yib481de92007-09-25 17:54:57 -07001330
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08001331 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08001332 api_ver = IWL_UCODE_API(priv->ucode_ver);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001333 build = priv->cfg->ops->ucode->get_build(ucode, api_ver);
1334 inst_size = priv->cfg->ops->ucode->get_inst_size(ucode, api_ver);
1335 data_size = priv->cfg->ops->ucode->get_data_size(ucode, api_ver);
1336 init_size = priv->cfg->ops->ucode->get_init_size(ucode, api_ver);
1337 init_data_size =
1338 priv->cfg->ops->ucode->get_init_data_size(ucode, api_ver);
1339 boot_size = priv->cfg->ops->ucode->get_boot_size(ucode, api_ver);
1340 src = priv->cfg->ops->ucode->get_data(ucode, api_ver);
Zhu Yib481de92007-09-25 17:54:57 -07001341
Reinette Chatrea0987a82008-12-02 12:14:06 -08001342 /* api_ver should match the api version forming part of the
1343 * firmware filename ... but we don't check for that and only rely
Nick Andrew877d0312009-01-26 11:06:57 +01001344 * on the API version read from firmware header from here on forward */
Reinette Chatrea0987a82008-12-02 12:14:06 -08001345
1346 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001347 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08001348 "Driver supports v%u, firmware is v%u.\n",
1349 api_max, api_ver);
1350 priv->ucode_ver = 0;
1351 ret = -EINVAL;
1352 goto err_release;
1353 }
1354 if (api_ver != api_max)
Tomas Winkler978785a2008-12-19 10:37:31 +08001355 IWL_ERR(priv, "Firmware has old API version. Expected v%u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08001356 "got v%u. New firmware can be obtained "
1357 "from http://www.intellinuxwireless.org.\n",
1358 api_max, api_ver);
1359
Tomas Winkler978785a2008-12-19 10:37:31 +08001360 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
1361 IWL_UCODE_MAJOR(priv->ucode_ver),
1362 IWL_UCODE_MINOR(priv->ucode_ver),
1363 IWL_UCODE_API(priv->ucode_ver),
1364 IWL_UCODE_SERIAL(priv->ucode_ver));
Reinette Chatrea0987a82008-12-02 12:14:06 -08001365
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001366 if (build)
1367 IWL_DEBUG_INFO(priv, "Build %u\n", build);
1368
Jay Sternbergabdc2d62009-07-31 14:28:09 -07001369 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
1370 IWL_DEBUG_INFO(priv, "NVM Type: %s, version: 0x%x\n",
1371 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
1372 ? "OTP" : "EEPROM", eeprom_ver);
1373
Tomas Winklere1623442009-01-27 14:27:56 -08001374 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001375 priv->ucode_ver);
Tomas Winklere1623442009-01-27 14:27:56 -08001376 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
Zhu Yib481de92007-09-25 17:54:57 -07001377 inst_size);
Tomas Winklere1623442009-01-27 14:27:56 -08001378 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
Zhu Yib481de92007-09-25 17:54:57 -07001379 data_size);
Tomas Winklere1623442009-01-27 14:27:56 -08001380 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
Zhu Yib481de92007-09-25 17:54:57 -07001381 init_size);
Tomas Winklere1623442009-01-27 14:27:56 -08001382 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
Zhu Yib481de92007-09-25 17:54:57 -07001383 init_data_size);
Tomas Winklere1623442009-01-27 14:27:56 -08001384 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
Zhu Yib481de92007-09-25 17:54:57 -07001385 boot_size);
1386
1387 /* Verify size of file vs. image size info in file's header */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001388 if (ucode_raw->size !=
1389 priv->cfg->ops->ucode->get_header_size(api_ver) +
Zhu Yib481de92007-09-25 17:54:57 -07001390 inst_size + data_size + init_size +
1391 init_data_size + boot_size) {
1392
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001393 IWL_DEBUG_INFO(priv,
1394 "uCode file size %d does not match expected size\n",
1395 (int)ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001396 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001397 goto err_release;
1398 }
1399
1400 /* Verify that uCode images will fit in card's SRAM */
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001401 if (inst_size > priv->hw_params.max_inst_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08001402 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08001403 inst_size);
1404 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001405 goto err_release;
1406 }
1407
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001408 if (data_size > priv->hw_params.max_data_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08001409 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08001410 data_size);
1411 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001412 goto err_release;
1413 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001414 if (init_size > priv->hw_params.max_inst_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08001415 IWL_INFO(priv, "uCode init instr len %d too large to fit in\n",
1416 init_size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001417 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001418 goto err_release;
1419 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001420 if (init_data_size > priv->hw_params.max_data_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08001421 IWL_INFO(priv, "uCode init data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08001422 init_data_size);
1423 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001424 goto err_release;
1425 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001426 if (boot_size > priv->hw_params.max_bsm_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08001427 IWL_INFO(priv, "uCode boot instr len %d too large to fit in\n",
1428 boot_size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001429 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001430 goto err_release;
1431 }
1432
1433 /* Allocate ucode buffers for card's bus-master loading ... */
1434
1435 /* Runtime instructions and 2 copies of data:
1436 * 1) unmodified from disk
1437 * 2) backup cache for save/restore during power-downs */
1438 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001439 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07001440
1441 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001442 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07001443
1444 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001445 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07001446
Zhu, Yi1f304e42009-01-23 13:45:22 -08001447 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
1448 !priv->ucode_data_backup.v_addr)
1449 goto err_pci_alloc;
1450
Zhu Yib481de92007-09-25 17:54:57 -07001451 /* Initialization instructions and data */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001452 if (init_size && init_data_size) {
1453 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001454 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Zhu Yib481de92007-09-25 17:54:57 -07001455
Tomas Winkler90e759d2007-11-29 11:09:41 +08001456 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001457 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001458
1459 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
1460 goto err_pci_alloc;
1461 }
Zhu Yib481de92007-09-25 17:54:57 -07001462
1463 /* Bootstrap (instructions only, no data) */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001464 if (boot_size) {
1465 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001466 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001467
Tomas Winkler90e759d2007-11-29 11:09:41 +08001468 if (!priv->ucode_boot.v_addr)
1469 goto err_pci_alloc;
1470 }
Zhu Yib481de92007-09-25 17:54:57 -07001471
1472 /* Copy images into buffers for card's bus-master reads ... */
1473
1474 /* Runtime instructions (first block of data in file) */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001475 len = inst_size;
Tomas Winklere1623442009-01-27 14:27:56 -08001476 IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001477 memcpy(priv->ucode_code.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001478 src += len;
1479
Tomas Winklere1623442009-01-27 14:27:56 -08001480 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07001481 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
1482
1483 /* Runtime data (2nd block)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001484 * NOTE: Copy into backup buffer will be done in iwl_up() */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001485 len = data_size;
Tomas Winklere1623442009-01-27 14:27:56 -08001486 IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode data len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001487 memcpy(priv->ucode_data.v_addr, src, len);
1488 memcpy(priv->ucode_data_backup.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001489 src += len;
Zhu Yib481de92007-09-25 17:54:57 -07001490
1491 /* Initialization instructions (3rd block) */
1492 if (init_size) {
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001493 len = init_size;
Tomas Winklere1623442009-01-27 14:27:56 -08001494 IWL_DEBUG_INFO(priv, "Copying (but not loading) init instr len %Zd\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08001495 len);
Zhu Yib481de92007-09-25 17:54:57 -07001496 memcpy(priv->ucode_init.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001497 src += len;
Zhu Yib481de92007-09-25 17:54:57 -07001498 }
1499
1500 /* Initialization data (4th block) */
1501 if (init_data_size) {
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001502 len = init_data_size;
Tomas Winklere1623442009-01-27 14:27:56 -08001503 IWL_DEBUG_INFO(priv, "Copying (but not loading) init data len %Zd\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08001504 len);
Zhu Yib481de92007-09-25 17:54:57 -07001505 memcpy(priv->ucode_init_data.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001506 src += len;
Zhu Yib481de92007-09-25 17:54:57 -07001507 }
1508
1509 /* Bootstrap instructions (5th block) */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001510 len = boot_size;
Tomas Winklere1623442009-01-27 14:27:56 -08001511 IWL_DEBUG_INFO(priv, "Copying (but not loading) boot instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001512 memcpy(priv->ucode_boot.v_addr, src, len);
1513
1514 /* We have our copies now, allow OS release its copies */
1515 release_firmware(ucode_raw);
1516 return 0;
1517
1518 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08001519 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001520 ret = -ENOMEM;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001521 iwl_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001522
1523 err_release:
1524 release_firmware(ucode_raw);
1525
1526 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08001527 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07001528}
1529
Reinette Chatreb7a79402009-09-25 14:24:23 -07001530#ifdef CONFIG_IWLWIFI_DEBUG
1531static const char *desc_lookup_text[] = {
1532 "OK",
1533 "FAIL",
1534 "BAD_PARAM",
1535 "BAD_CHECKSUM",
1536 "NMI_INTERRUPT_WDG",
1537 "SYSASSERT",
1538 "FATAL_ERROR",
1539 "BAD_COMMAND",
1540 "HW_ERROR_TUNE_LOCK",
1541 "HW_ERROR_TEMPERATURE",
1542 "ILLEGAL_CHAN_FREQ",
1543 "VCC_NOT_STABLE",
1544 "FH_ERROR",
1545 "NMI_INTERRUPT_HOST",
1546 "NMI_INTERRUPT_ACTION_PT",
1547 "NMI_INTERRUPT_UNKNOWN",
1548 "UCODE_VERSION_MISMATCH",
1549 "HW_ERROR_ABS_LOCK",
1550 "HW_ERROR_CAL_LOCK_FAIL",
1551 "NMI_INTERRUPT_INST_ACTION_PT",
1552 "NMI_INTERRUPT_DATA_ACTION_PT",
1553 "NMI_TRM_HW_ER",
1554 "NMI_INTERRUPT_TRM",
1555 "NMI_INTERRUPT_BREAK_POINT"
1556 "DEBUG_0",
1557 "DEBUG_1",
1558 "DEBUG_2",
1559 "DEBUG_3",
1560 "UNKNOWN"
1561};
1562
1563static const char *desc_lookup(int i)
1564{
1565 int max = ARRAY_SIZE(desc_lookup_text) - 1;
1566
1567 if (i < 0 || i > max)
1568 i = max;
1569
1570 return desc_lookup_text[i];
1571}
1572
1573#define ERROR_START_OFFSET (1 * sizeof(u32))
1574#define ERROR_ELEM_SIZE (7 * sizeof(u32))
1575
1576void iwl_dump_nic_error_log(struct iwl_priv *priv)
1577{
1578 u32 data2, line;
1579 u32 desc, time, count, base, data1;
1580 u32 blink1, blink2, ilink1, ilink2;
1581
1582 if (priv->ucode_type == UCODE_INIT)
1583 base = le32_to_cpu(priv->card_alive_init.error_event_table_ptr);
1584 else
1585 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
1586
1587 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
1588 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
1589 return;
1590 }
1591
1592 count = iwl_read_targ_mem(priv, base);
1593
1594 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
1595 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
1596 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
1597 priv->status, count);
1598 }
1599
1600 desc = iwl_read_targ_mem(priv, base + 1 * sizeof(u32));
1601 blink1 = iwl_read_targ_mem(priv, base + 3 * sizeof(u32));
1602 blink2 = iwl_read_targ_mem(priv, base + 4 * sizeof(u32));
1603 ilink1 = iwl_read_targ_mem(priv, base + 5 * sizeof(u32));
1604 ilink2 = iwl_read_targ_mem(priv, base + 6 * sizeof(u32));
1605 data1 = iwl_read_targ_mem(priv, base + 7 * sizeof(u32));
1606 data2 = iwl_read_targ_mem(priv, base + 8 * sizeof(u32));
1607 line = iwl_read_targ_mem(priv, base + 9 * sizeof(u32));
1608 time = iwl_read_targ_mem(priv, base + 11 * sizeof(u32));
1609
1610 IWL_ERR(priv, "Desc Time "
1611 "data1 data2 line\n");
1612 IWL_ERR(priv, "%-28s (#%02d) %010u 0x%08X 0x%08X %u\n",
1613 desc_lookup(desc), desc, time, data1, data2, line);
1614 IWL_ERR(priv, "blink1 blink2 ilink1 ilink2\n");
1615 IWL_ERR(priv, "0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2,
1616 ilink1, ilink2);
1617
1618}
1619
1620#define EVENT_START_OFFSET (4 * sizeof(u32))
1621
1622/**
1623 * iwl_print_event_log - Dump error event log to syslog
1624 *
1625 */
1626static void iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
1627 u32 num_events, u32 mode)
1628{
1629 u32 i;
1630 u32 base; /* SRAM byte address of event log header */
1631 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
1632 u32 ptr; /* SRAM byte address of log data */
1633 u32 ev, time, data; /* event log data */
1634
1635 if (num_events == 0)
1636 return;
1637 if (priv->ucode_type == UCODE_INIT)
1638 base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
1639 else
1640 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
1641
1642 if (mode == 0)
1643 event_size = 2 * sizeof(u32);
1644 else
1645 event_size = 3 * sizeof(u32);
1646
1647 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
1648
1649 /* "time" is actually "data" for mode 0 (no timestamp).
1650 * place event id # at far right for easier visual parsing. */
1651 for (i = 0; i < num_events; i++) {
1652 ev = iwl_read_targ_mem(priv, ptr);
1653 ptr += sizeof(u32);
1654 time = iwl_read_targ_mem(priv, ptr);
1655 ptr += sizeof(u32);
1656 if (mode == 0) {
1657 /* data, ev */
1658 IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n", time, ev);
1659 } else {
1660 data = iwl_read_targ_mem(priv, ptr);
1661 ptr += sizeof(u32);
1662 IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
1663 time, data, ev);
1664 }
1665 }
1666}
1667
1668void iwl_dump_nic_event_log(struct iwl_priv *priv)
1669{
1670 u32 base; /* SRAM byte address of event log header */
1671 u32 capacity; /* event log capacity in # entries */
1672 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
1673 u32 num_wraps; /* # times uCode wrapped to top of log */
1674 u32 next_entry; /* index of next entry to be written by uCode */
1675 u32 size; /* # entries that we'll print */
1676
1677 if (priv->ucode_type == UCODE_INIT)
1678 base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
1679 else
1680 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
1681
1682 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
1683 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
1684 return;
1685 }
1686
1687 /* event log header */
1688 capacity = iwl_read_targ_mem(priv, base);
1689 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
1690 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
1691 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
1692
1693 size = num_wraps ? capacity : next_entry;
1694
1695 /* bail out if nothing in log */
1696 if (size == 0) {
1697 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
1698 return;
1699 }
1700
1701 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
1702 size, num_wraps);
1703
1704 /* if uCode has wrapped back to top of log, start at the oldest entry,
1705 * i.e the next one that uCode would fill. */
1706 if (num_wraps)
1707 iwl_print_event_log(priv, next_entry,
1708 capacity - next_entry, mode);
1709 /* (then/else) start at top of log */
1710 iwl_print_event_log(priv, 0, next_entry, mode);
1711
1712}
1713#endif
1714
Zhu Yib481de92007-09-25 17:54:57 -07001715/**
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001716 * iwl_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07001717 * from protocol/runtime uCode (initialization uCode's
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001718 * Alive gets handled by iwl_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07001719 */
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001720static void iwl_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001721{
Tomas Winkler57aab752008-04-14 21:16:03 -07001722 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001723
Tomas Winklere1623442009-01-27 14:27:56 -08001724 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001725
1726 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
1727 /* We had an error bringing up the hardware, so take it
1728 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08001729 IWL_DEBUG_INFO(priv, "Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001730 goto restart;
1731 }
1732
1733 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
1734 * This is a paranoid check, because we would not have gotten the
1735 * "runtime" alive if code weren't properly loaded. */
Emmanuel Grumbachb0692f22008-04-24 11:55:18 -07001736 if (iwl_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001737 /* Runtime instruction load was bad;
1738 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08001739 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001740 goto restart;
1741 }
1742
Tomas Winklerc587de02009-06-03 11:44:07 -07001743 iwl_clear_stations_table(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07001744 ret = priv->cfg->ops->lib->alive_notify(priv);
1745 if (ret) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001746 IWL_WARN(priv,
1747 "Could not complete ALIVE transition [ntf]: %d\n", ret);
Zhu Yib481de92007-09-25 17:54:57 -07001748 goto restart;
1749 }
1750
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001751 /* After the ALIVE response, we can send host commands to the uCode */
Zhu Yib481de92007-09-25 17:54:57 -07001752 set_bit(STATUS_ALIVE, &priv->status);
1753
Tomas Winklerfee12472008-04-03 16:05:21 -07001754 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001755 return;
1756
Johannes Berg36d68252008-05-15 12:55:26 +02001757 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07001758
1759 priv->active_rate = priv->rates_mask;
1760 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
1761
Tomas Winkler3109ece2008-03-28 16:33:35 -07001762 if (iwl_is_associated(priv)) {
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001763 struct iwl_rxon_cmd *active_rxon =
1764 (struct iwl_rxon_cmd *)&priv->active_rxon;
Mohamed Abbas019fb972009-03-17 21:59:18 -07001765 /* apply any changes in staging */
1766 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001767 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1768 } else {
1769 /* Initialize our rx_config data */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001770 iwl_connection_init_rx_config(priv, priv->iw_mode);
Abhijeet Kolekar45823532009-04-08 11:26:44 -07001771
1772 if (priv->cfg->ops->hcmd->set_rxon_chain)
1773 priv->cfg->ops->hcmd->set_rxon_chain(priv);
1774
Zhu Yib481de92007-09-25 17:54:57 -07001775 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
1776 }
1777
Ben Cahill9fbab512007-11-29 11:09:47 +08001778 /* Configure Bluetooth device coexistence support */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001779 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001780
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001781 iwl_reset_run_time_calib(priv);
1782
Zhu Yib481de92007-09-25 17:54:57 -07001783 /* Configure the adapter for unassociated operation */
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001784 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001785
1786 /* At this point, the NIC is initialized and operational */
Emmanuel Grumbach47f4a582008-06-12 09:47:13 +08001787 iwl_rf_kill_ct_config(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08001788
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07001789 iwl_leds_register(priv);
1790
Tomas Winklere1623442009-01-27 14:27:56 -08001791 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07001792 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08001793 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07001794
Johannes Berge312c242009-08-07 15:41:51 -07001795 iwl_power_update_mode(priv, true);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08001796
Mohamed Abbasada17512008-11-07 09:58:34 -08001797 /* reassociate for ADHOC mode */
1798 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
1799 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
1800 priv->vif);
1801 if (beacon)
1802 iwl_mac_beacon_update(priv->hw, beacon);
1803 }
1804
1805
Assaf Kraussc46fbef2008-06-12 09:47:05 +08001806 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001807 iwl_set_mode(priv, priv->iw_mode);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08001808
Zhu Yib481de92007-09-25 17:54:57 -07001809 return;
1810
1811 restart:
1812 queue_work(priv->workqueue, &priv->restart);
1813}
1814
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001815static void iwl_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07001816
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001817static void __iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001818{
1819 unsigned long flags;
1820 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07001821
Tomas Winklere1623442009-01-27 14:27:56 -08001822 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07001823
Zhu Yib481de92007-09-25 17:54:57 -07001824 if (!exit_pending)
1825 set_bit(STATUS_EXIT_PENDING, &priv->status);
1826
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07001827 iwl_leds_unregister(priv);
1828
Tomas Winklerc587de02009-06-03 11:44:07 -07001829 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001830
1831 /* Unblock any waiting calls */
1832 wake_up_interruptible_all(&priv->wait_command_queue);
1833
Zhu Yib481de92007-09-25 17:54:57 -07001834 /* Wipe out the EXIT_PENDING status bit if we are not actually
1835 * exiting the module */
1836 if (!exit_pending)
1837 clear_bit(STATUS_EXIT_PENDING, &priv->status);
1838
1839 /* stop and reset the on-board processor */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001840 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07001841
1842 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001843 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001844 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001845 spin_unlock_irqrestore(&priv->lock, flags);
1846 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001847
1848 if (priv->mac80211_registered)
1849 ieee80211_stop_queues(priv->hw);
1850
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001851 /* If we have not previously called iwl_init() then
Johannes Berga60e77e2009-06-04 18:26:06 +02001852 * clear all bits but the RF Kill bit and return */
Tomas Winklerfee12472008-04-03 16:05:21 -07001853 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001854 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
1855 STATUS_RF_KILL_HW |
Reinette Chatre97888642008-02-06 11:20:38 -08001856 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
1857 STATUS_GEO_CONFIGURED |
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08001858 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
1859 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07001860 goto exit;
1861 }
1862
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07001863 /* ...otherwise clear out all the status bits but the RF Kill
Johannes Berga60e77e2009-06-04 18:26:06 +02001864 * bit and continue taking the NIC down. */
Zhu Yib481de92007-09-25 17:54:57 -07001865 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
1866 STATUS_RF_KILL_HW |
Reinette Chatre97888642008-02-06 11:20:38 -08001867 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
1868 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07001869 test_bit(STATUS_FW_ERROR, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08001870 STATUS_FW_ERROR |
1871 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
1872 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07001873
Mohamed Abbasef850d72009-05-22 11:01:50 -07001874 /* device going down, Stop using ICT table */
1875 iwl_disable_ict(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001876 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001877 iwl_clear_bit(priv, CSR_GP_CNTRL,
Ben Cahill9fbab512007-11-29 11:09:47 +08001878 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07001879 spin_unlock_irqrestore(&priv->lock, flags);
1880
Tomas Winklerda1bc452008-05-29 16:35:00 +08001881 iwl_txq_ctx_stop(priv);
Tomas Winklerb3bbacb2008-05-29 16:35:01 +08001882 iwl_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001883
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07001884 iwl_write_prph(priv, APMG_CLK_DIS_REG,
1885 APMG_CLK_VAL_DMA_CLK_RQT);
Zhu Yib481de92007-09-25 17:54:57 -07001886
1887 udelay(5);
1888
Tomas Winkler7f066102008-05-29 16:34:57 +08001889 /* FIXME: apm_ops.suspend(priv) */
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07001890 if (exit_pending)
Gregory Greenmand5353112008-09-03 11:18:49 +08001891 priv->cfg->ops->lib->apm_ops.stop(priv);
1892 else
1893 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001894 exit:
Tomas Winkler885ba202008-05-29 16:34:55 +08001895 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001896
1897 if (priv->ibss_beacon)
1898 dev_kfree_skb(priv->ibss_beacon);
1899 priv->ibss_beacon = NULL;
1900
1901 /* clear out any free frames */
Tomas Winklerfcab4232008-05-15 13:54:01 +08001902 iwl_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001903}
1904
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001905static void iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001906{
1907 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001908 __iwl_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001909 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08001910
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001911 iwl_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001912}
1913
Mohamed Abbas086ed112009-05-22 11:01:54 -07001914#define HW_READY_TIMEOUT (50)
1915
1916static int iwl_set_hw_ready(struct iwl_priv *priv)
1917{
1918 int ret = 0;
1919
1920 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
1921 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
1922
1923 /* See if we got it */
1924 ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
1925 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
1926 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
1927 HW_READY_TIMEOUT);
1928 if (ret != -ETIMEDOUT)
1929 priv->hw_ready = true;
1930 else
1931 priv->hw_ready = false;
1932
1933 IWL_DEBUG_INFO(priv, "hardware %s\n",
1934 (priv->hw_ready == 1) ? "ready" : "not ready");
1935 return ret;
1936}
1937
1938static int iwl_prepare_card_hw(struct iwl_priv *priv)
1939{
1940 int ret = 0;
1941
1942 IWL_DEBUG_INFO(priv, "iwl_prepare_card_hw enter \n");
1943
Mohamed Abbas3354a0f2009-06-19 13:52:41 -07001944 ret = iwl_set_hw_ready(priv);
1945 if (priv->hw_ready)
1946 return ret;
1947
1948 /* If HW is not ready, prepare the conditions to check again */
Mohamed Abbas086ed112009-05-22 11:01:54 -07001949 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
1950 CSR_HW_IF_CONFIG_REG_PREPARE);
1951
1952 ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
1953 ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE,
1954 CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000);
1955
Mohamed Abbas3354a0f2009-06-19 13:52:41 -07001956 /* HW should be ready by now, check again. */
Mohamed Abbas086ed112009-05-22 11:01:54 -07001957 if (ret != -ETIMEDOUT)
1958 iwl_set_hw_ready(priv);
1959
1960 return ret;
1961}
1962
Zhu Yib481de92007-09-25 17:54:57 -07001963#define MAX_HW_RESTARTS 5
1964
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001965static int __iwl_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001966{
Tomas Winkler57aab752008-04-14 21:16:03 -07001967 int i;
1968 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07001969
1970 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001971 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07001972 return -EIO;
1973 }
1974
Reinette Chatree903fbd2008-01-30 22:05:15 -08001975 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001976 IWL_ERR(priv, "ucode not available for device bringup\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08001977 return -EIO;
1978 }
1979
Mohamed Abbas086ed112009-05-22 11:01:54 -07001980 iwl_prepare_card_hw(priv);
1981
1982 if (!priv->hw_ready) {
1983 IWL_WARN(priv, "Exit HW not ready\n");
1984 return -EIO;
1985 }
1986
Zhu Yie655b9f2008-01-24 02:19:38 -08001987 /* If platform's RF_KILL switch is NOT set to KILL */
Tomas Winklerc1842d62008-08-04 16:00:43 +08001988 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
Zhu Yie655b9f2008-01-24 02:19:38 -08001989 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08001990 else
Zhu Yie655b9f2008-01-24 02:19:38 -08001991 set_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08001992
Tomas Winklerc1842d62008-08-04 16:00:43 +08001993 if (iwl_is_rfkill(priv)) {
Johannes Berga60e77e2009-06-04 18:26:06 +02001994 wiphy_rfkill_set_hw_state(priv->hw->wiphy, true);
1995
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001996 iwl_enable_interrupts(priv);
Johannes Berga60e77e2009-06-04 18:26:06 +02001997 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
Tomas Winklerc1842d62008-08-04 16:00:43 +08001998 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07001999 }
2000
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002001 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07002002
Ron Rindjunsky1053d352008-05-05 10:22:43 +08002003 ret = iwl_hw_nic_init(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07002004 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002005 IWL_ERR(priv, "Unable to init nic\n");
Tomas Winkler57aab752008-04-14 21:16:03 -07002006 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002007 }
2008
2009 /* make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002010 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2011 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07002012 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2013
2014 /* clear (again), then enable host interrupts */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002015 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002016 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002017
2018 /* really make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002019 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2020 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07002021
2022 /* Copy original ucode data image from disk into backup cache.
2023 * This will be used to initialize the on-board processor's
2024 * data SRAM for a clean start when the runtime program first loads. */
2025 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a66926a2008-01-14 17:46:18 -08002026 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07002027
Zhu Yib481de92007-09-25 17:54:57 -07002028 for (i = 0; i < MAX_HW_RESTARTS; i++) {
2029
Tomas Winklerc587de02009-06-03 11:44:07 -07002030 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002031
2032 /* load bootstrap state machine,
2033 * load bootstrap program into processor's memory,
2034 * prepare to load the "initialize" uCode */
Tomas Winkler57aab752008-04-14 21:16:03 -07002035 ret = priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002036
Tomas Winkler57aab752008-04-14 21:16:03 -07002037 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002038 IWL_ERR(priv, "Unable to set up bootstrap uCode: %d\n",
2039 ret);
Zhu Yib481de92007-09-25 17:54:57 -07002040 continue;
2041 }
2042
2043 /* start card; "initialize" will load runtime ucode */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002044 iwl_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002045
Tomas Winklere1623442009-01-27 14:27:56 -08002046 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
Zhu Yib481de92007-09-25 17:54:57 -07002047
2048 return 0;
2049 }
2050
2051 set_bit(STATUS_EXIT_PENDING, &priv->status);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002052 __iwl_down(priv);
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08002053 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002054
2055 /* tried to restart and config the device for as long as our
2056 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002057 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07002058 return -EIO;
2059}
2060
2061
2062/*****************************************************************************
2063 *
2064 * Workqueue callbacks
2065 *
2066 *****************************************************************************/
2067
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002068static void iwl_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002069{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002070 struct iwl_priv *priv =
2071 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002072
2073 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2074 return;
2075
2076 mutex_lock(&priv->mutex);
Emmanuel Grumbachf3ccc082008-05-05 10:22:45 +08002077 priv->cfg->ops->lib->init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002078 mutex_unlock(&priv->mutex);
2079}
2080
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002081static void iwl_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002082{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002083 struct iwl_priv *priv =
2084 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002085
2086 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2087 return;
2088
Mohamed Abbas258c44a2009-06-03 11:44:10 -07002089 /* enable dram interrupt */
2090 iwl_reset_ict(priv);
2091
Zhu Yib481de92007-09-25 17:54:57 -07002092 mutex_lock(&priv->mutex);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002093 iwl_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002094 mutex_unlock(&priv->mutex);
2095}
2096
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08002097static void iwl_bg_run_time_calib_work(struct work_struct *work)
2098{
2099 struct iwl_priv *priv = container_of(work, struct iwl_priv,
2100 run_time_calib_work);
2101
2102 mutex_lock(&priv->mutex);
2103
2104 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
2105 test_bit(STATUS_SCANNING, &priv->status)) {
2106 mutex_unlock(&priv->mutex);
2107 return;
2108 }
2109
2110 if (priv->start_calib) {
2111 iwl_chain_noise_calibration(priv, &priv->statistics);
2112
2113 iwl_sensitivity_calibration(priv, &priv->statistics);
2114 }
2115
2116 mutex_unlock(&priv->mutex);
2117 return;
2118}
2119
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002120static void iwl_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002121{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002122 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07002123
2124 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2125 return;
2126
2127 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002128 __iwl_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002129 mutex_unlock(&priv->mutex);
2130}
2131
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002132static void iwl_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002133{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002134 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07002135
2136 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2137 return;
2138
Johannes Berg19cc1082009-05-08 13:44:36 -07002139 if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
2140 mutex_lock(&priv->mutex);
2141 priv->vif = NULL;
2142 priv->is_open = 0;
2143 mutex_unlock(&priv->mutex);
2144 iwl_down(priv);
2145 ieee80211_restart_hw(priv->hw);
2146 } else {
2147 iwl_down(priv);
2148 queue_work(priv->workqueue, &priv->up);
2149 }
Zhu Yib481de92007-09-25 17:54:57 -07002150}
2151
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002152static void iwl_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002153{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002154 struct iwl_priv *priv =
2155 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07002156
2157 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2158 return;
2159
2160 mutex_lock(&priv->mutex);
Tomas Winklera55360e2008-05-05 10:22:28 +08002161 iwl_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002162 mutex_unlock(&priv->mutex);
2163}
2164
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002165#define IWL_DELAY_NEXT_SCAN (HZ*2)
2166
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07002167void iwl_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002168{
Zhu Yib481de92007-09-25 17:54:57 -07002169 struct ieee80211_conf *conf = NULL;
Tomas Winkler857485c2008-03-21 13:53:44 -07002170 int ret = 0;
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002171 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07002172
Johannes Berg05c914f2008-09-11 00:01:58 +02002173 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002174 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07002175 return;
2176 }
2177
Tomas Winklere1623442009-01-27 14:27:56 -08002178 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07002179 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07002180
2181
2182 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2183 return;
2184
Zhu Yib481de92007-09-25 17:54:57 -07002185
Reinette Chatre508e32e2008-04-14 21:16:13 -07002186 if (!priv->vif || !priv->is_open)
Mohamed Abbas948c1712007-10-25 17:15:45 +08002187 return;
Reinette Chatre508e32e2008-04-14 21:16:13 -07002188
Tomas Winkler2a421b92008-06-12 09:47:10 +08002189 iwl_scan_cancel_timeout(priv, 200);
mabbas052c4b92007-10-25 17:15:43 +08002190
Zhu Yib481de92007-09-25 17:54:57 -07002191 conf = ieee80211_get_hw_conf(priv->hw);
2192
2193 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002194 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002195
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002196 iwl_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002197 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002198 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002199 if (ret)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002200 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07002201 "Attempting to continue.\n");
2202
2203 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
2204
Emmanuel Grumbach42eb7c62008-09-17 10:10:05 +08002205 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03002206
Abhijeet Kolekar45823532009-04-08 11:26:44 -07002207 if (priv->cfg->ops->hcmd->set_rxon_chain)
2208 priv->cfg->ops->hcmd->set_rxon_chain(priv);
2209
Zhu Yib481de92007-09-25 17:54:57 -07002210 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2211
Tomas Winklere1623442009-01-27 14:27:56 -08002212 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07002213 priv->assoc_id, priv->beacon_int);
2214
2215 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2216 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2217 else
2218 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2219
2220 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2221 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2222 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2223 else
2224 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2225
Johannes Berg05c914f2008-09-11 00:01:58 +02002226 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002227 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2228
2229 }
2230
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002231 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002232
2233 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02002234 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -07002235 break;
2236
Johannes Berg05c914f2008-09-11 00:01:58 +02002237 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07002238
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002239 /* assume default assoc id */
2240 priv->assoc_id = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002241
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002242 iwl_rxon_add_station(priv, priv->bssid, 0);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002243 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002244
2245 break;
2246
2247 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002248 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03002249 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002250 break;
2251 }
2252
Johannes Berg05c914f2008-09-11 00:01:58 +02002253 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002254 priv->assoc_station_added = 1;
2255
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002256 spin_lock_irqsave(&priv->lock, flags);
2257 iwl_activate_qos(priv, 0);
2258 spin_unlock_irqrestore(&priv->lock, flags);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08002259
Grumbach, Emmanuel04816442008-09-03 11:26:53 +08002260 /* the chain noise calibration will enabled PM upon completion
2261 * If chain noise has already been run, then we need to enable
2262 * power management here */
2263 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
Johannes Berge312c242009-08-07 15:41:51 -07002264 iwl_power_update_mode(priv, false);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08002265
2266 /* Enable Rx differential gain and sensitivity calibrations */
2267 iwl_chain_noise_reset(priv);
2268 priv->start_calib = 1;
2269
Reinette Chatre508e32e2008-04-14 21:16:13 -07002270}
2271
Zhu Yib481de92007-09-25 17:54:57 -07002272/*****************************************************************************
2273 *
2274 * mac80211 entry point functions
2275 *
2276 *****************************************************************************/
2277
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002278#define UCODE_READY_TIMEOUT (4 * HZ)
Zhu Yi5a66926a2008-01-14 17:46:18 -08002279
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002280static int iwl_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002281{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002282 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002283 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002284
Tomas Winklere1623442009-01-27 14:27:56 -08002285 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002286
2287 /* we should be verifying the device is ready to be opened */
2288 mutex_lock(&priv->mutex);
2289
Zhu Yi5a66926a2008-01-14 17:46:18 -08002290 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
2291 * ucode filename and max sizes are card-specific. */
2292
2293 if (!priv->ucode_code.len) {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002294 ret = iwl_read_ucode(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002295 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002296 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002297 mutex_unlock(&priv->mutex);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002298 return ret;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002299 }
2300 }
2301
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002302 ret = __iwl_up(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002303
Zhu Yib481de92007-09-25 17:54:57 -07002304 mutex_unlock(&priv->mutex);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002305
Zhu Yie655b9f2008-01-24 02:19:38 -08002306 if (ret)
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002307 return ret;
Zhu Yie655b9f2008-01-24 02:19:38 -08002308
Tomas Winklerc1842d62008-08-04 16:00:43 +08002309 if (iwl_is_rfkill(priv))
2310 goto out;
2311
Tomas Winklere1623442009-01-27 14:27:56 -08002312 IWL_DEBUG_INFO(priv, "Start UP work done.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08002313
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002314 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
Zhu Yi5a66926a2008-01-14 17:46:18 -08002315 * mac80211 will not be run successfully. */
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002316 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
2317 test_bit(STATUS_READY, &priv->status),
2318 UCODE_READY_TIMEOUT);
2319 if (!ret) {
2320 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002321 IWL_ERR(priv, "START_ALIVE timeout after %dms.\n",
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002322 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002323 return -ETIMEDOUT;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002324 }
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002325 }
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002326
Tomas Winklerc1842d62008-08-04 16:00:43 +08002327out:
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002328 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08002329 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002330 return 0;
2331}
2332
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002333static void iwl_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002334{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002335 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002336
Tomas Winklere1623442009-01-27 14:27:56 -08002337 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas948c1712007-10-25 17:15:45 +08002338
Johannes Berg19cc1082009-05-08 13:44:36 -07002339 if (!priv->is_open)
Zhu Yie655b9f2008-01-24 02:19:38 -08002340 return;
Zhu Yie655b9f2008-01-24 02:19:38 -08002341
Zhu Yib481de92007-09-25 17:54:57 -07002342 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002343
Wey-Yi Guy5bddf542009-08-21 13:34:25 -07002344 if (iwl_is_ready_rf(priv) || test_bit(STATUS_SCAN_HW, &priv->status)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08002345 /* stop mac, cancel any scan request and clear
2346 * RXON_FILTER_ASSOC_MSK BIT
2347 */
Zhu Yi5a66926a2008-01-14 17:46:18 -08002348 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002349 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002350 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002351 }
2352
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002353 iwl_down(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002354
2355 flush_workqueue(priv->workqueue);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002356
2357 /* enable interrupts again in order to receive rfkill changes */
2358 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
2359 iwl_enable_interrupts(priv);
Mohamed Abbas948c1712007-10-25 17:15:45 +08002360
Tomas Winklere1623442009-01-27 14:27:56 -08002361 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002362}
2363
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002364static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07002365{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002366 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002367
Tomas Winklere1623442009-01-27 14:27:56 -08002368 IWL_DEBUG_MACDUMP(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002369
Tomas Winklere1623442009-01-27 14:27:56 -08002370 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02002371 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07002372
Johannes Berge039fa42008-05-15 12:55:29 +02002373 if (iwl_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07002374 dev_kfree_skb_any(skb);
2375
Tomas Winklere1623442009-01-27 14:27:56 -08002376 IWL_DEBUG_MACDUMP(priv, "leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08002377 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07002378}
2379
Abhijeet Kolekar60690a62009-04-08 11:26:49 -07002380void iwl_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002381{
Tomas Winkler857485c2008-03-21 13:53:44 -07002382 int ret = 0;
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002383 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07002384
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08002385 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07002386 return;
2387
2388 /* The following should be done only at AP bring up */
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002389 if (!iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002390
2391 /* RXON - unassoc (to set timing command) */
2392 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002393 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002394
2395 /* RXON Timing */
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002396 iwl_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002397 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002398 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002399 if (ret)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002400 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07002401 "Attempting to continue.\n");
2402
Abhijeet Kolekar45823532009-04-08 11:26:44 -07002403 if (priv->cfg->ops->hcmd->set_rxon_chain)
2404 priv->cfg->ops->hcmd->set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002405
2406 /* FIXME: what should be the assoc_id for AP? */
2407 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2408 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2409 priv->staging_rxon.flags |=
2410 RXON_FLG_SHORT_PREAMBLE_MSK;
2411 else
2412 priv->staging_rxon.flags &=
2413 ~RXON_FLG_SHORT_PREAMBLE_MSK;
2414
2415 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2416 if (priv->assoc_capability &
2417 WLAN_CAPABILITY_SHORT_SLOT_TIME)
2418 priv->staging_rxon.flags |=
2419 RXON_FLG_SHORT_SLOT_MSK;
2420 else
2421 priv->staging_rxon.flags &=
2422 ~RXON_FLG_SHORT_SLOT_MSK;
2423
Johannes Berg05c914f2008-09-11 00:01:58 +02002424 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002425 priv->staging_rxon.flags &=
2426 ~RXON_FLG_SHORT_SLOT_MSK;
2427 }
2428 /* restore RXON assoc */
2429 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002430 iwlcore_commit_rxon(priv);
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002431 spin_lock_irqsave(&priv->lock, flags);
2432 iwl_activate_qos(priv, 1);
2433 spin_unlock_irqrestore(&priv->lock, flags);
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002434 iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
Zhu Yie1493de2007-09-27 11:27:32 +08002435 }
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002436 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002437
2438 /* FIXME - we need to add code here to detect a totally new
2439 * configuration, reset the AP, unassoc, rxon timing, assoc,
2440 * clear sta table, add BCAST sta... */
2441}
2442
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002443static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw,
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002444 struct ieee80211_key_conf *keyconf, const u8 *addr,
2445 u32 iv32, u16 *phase1key)
2446{
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002447
Tomas Winkler9f586712008-11-12 13:14:05 -08002448 struct iwl_priv *priv = hw->priv;
Tomas Winklere1623442009-01-27 14:27:56 -08002449 IWL_DEBUG_MAC80211(priv, "enter\n");
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002450
Tomas Winkler9f586712008-11-12 13:14:05 -08002451 iwl_update_tkip_key(priv, keyconf, addr, iv32, phase1key);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002452
Tomas Winklere1623442009-01-27 14:27:56 -08002453 IWL_DEBUG_MAC80211(priv, "leave\n");
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002454}
2455
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002456static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01002457 struct ieee80211_vif *vif,
2458 struct ieee80211_sta *sta,
Zhu Yib481de92007-09-25 17:54:57 -07002459 struct ieee80211_key_conf *key)
2460{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002461 struct iwl_priv *priv = hw->priv;
Winkler, Tomas42986792009-01-19 15:30:22 -08002462 const u8 *addr;
2463 int ret;
2464 u8 sta_id;
2465 bool is_default_wep_key = false;
Zhu Yib481de92007-09-25 17:54:57 -07002466
Tomas Winklere1623442009-01-27 14:27:56 -08002467 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002468
Tomas Winkler90e8e422009-06-19 13:52:42 -07002469 if (priv->cfg->mod_params->sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08002470 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07002471 return -EOPNOTSUPP;
2472 }
Winkler, Tomas42986792009-01-19 15:30:22 -08002473 addr = sta ? sta->addr : iwl_bcast_addr;
Tomas Winklerc587de02009-06-03 11:44:07 -07002474 sta_id = iwl_find_station(priv, addr);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002475 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -08002476 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
Johannes Berge1749612008-10-27 15:59:26 -07002477 addr);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002478 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002479
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002480 }
Zhu Yib481de92007-09-25 17:54:57 -07002481
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002482 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002483 iwl_scan_cancel_timeout(priv, 100);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002484 mutex_unlock(&priv->mutex);
2485
2486 /* If we are getting WEP group key and we didn't receive any key mapping
2487 * so far, we are in legacy wep mode (group key only), otherwise we are
2488 * in 1X mode.
2489 * In legacy wep mode, we use another host command to the uCode */
Tomas Winkler5425e492008-04-15 16:01:38 -07002490 if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
Johannes Berg05c914f2008-09-11 00:01:58 +02002491 priv->iw_mode != NL80211_IFTYPE_AP) {
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002492 if (cmd == SET_KEY)
2493 is_default_wep_key = !priv->key_mapping_key;
2494 else
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +08002495 is_default_wep_key =
2496 (key->hw_key_idx == HW_KEY_DEFAULT);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002497 }
mabbas052c4b92007-10-25 17:15:43 +08002498
Zhu Yib481de92007-09-25 17:54:57 -07002499 switch (cmd) {
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002500 case SET_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002501 if (is_default_wep_key)
2502 ret = iwl_set_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002503 else
Emmanuel Grumbach74805132008-04-14 21:16:09 -07002504 ret = iwl_set_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002505
Tomas Winklere1623442009-01-27 14:27:56 -08002506 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07002507 break;
2508 case DISABLE_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002509 if (is_default_wep_key)
2510 ret = iwl_remove_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002511 else
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07002512 ret = iwl_remove_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002513
Tomas Winklere1623442009-01-27 14:27:56 -08002514 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07002515 break;
2516 default:
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002517 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002518 }
2519
Tomas Winklere1623442009-01-27 14:27:56 -08002520 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002521
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002522 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002523}
2524
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002525static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
Tomas Winklerd783b062008-07-18 13:53:02 +08002526 enum ieee80211_ampdu_mlme_action action,
Johannes Berg17741cd2008-09-11 00:02:02 +02002527 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
Tomas Winklerd783b062008-07-18 13:53:02 +08002528{
2529 struct iwl_priv *priv = hw->priv;
Wey-Yi Guy5c2207c2009-03-17 21:51:43 -07002530 int ret;
Tomas Winklerd783b062008-07-18 13:53:02 +08002531
Tomas Winklere1623442009-01-27 14:27:56 -08002532 IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
Johannes Berge1749612008-10-27 15:59:26 -07002533 sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08002534
2535 if (!(priv->cfg->sku & IWL_SKU_N))
2536 return -EACCES;
2537
2538 switch (action) {
2539 case IEEE80211_AMPDU_RX_START:
Tomas Winklere1623442009-01-27 14:27:56 -08002540 IWL_DEBUG_HT(priv, "start Rx\n");
Tomas Winkler9f586712008-11-12 13:14:05 -08002541 return iwl_sta_rx_agg_start(priv, sta->addr, tid, *ssn);
Tomas Winklerd783b062008-07-18 13:53:02 +08002542 case IEEE80211_AMPDU_RX_STOP:
Tomas Winklere1623442009-01-27 14:27:56 -08002543 IWL_DEBUG_HT(priv, "stop Rx\n");
Wey-Yi Guy5c2207c2009-03-17 21:51:43 -07002544 ret = iwl_sta_rx_agg_stop(priv, sta->addr, tid);
2545 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2546 return 0;
2547 else
2548 return ret;
Tomas Winklerd783b062008-07-18 13:53:02 +08002549 case IEEE80211_AMPDU_TX_START:
Tomas Winklere1623442009-01-27 14:27:56 -08002550 IWL_DEBUG_HT(priv, "start Tx\n");
Johannes Berg17741cd2008-09-11 00:02:02 +02002551 return iwl_tx_agg_start(priv, sta->addr, tid, ssn);
Tomas Winklerd783b062008-07-18 13:53:02 +08002552 case IEEE80211_AMPDU_TX_STOP:
Tomas Winklere1623442009-01-27 14:27:56 -08002553 IWL_DEBUG_HT(priv, "stop Tx\n");
Wey-Yi Guy5c2207c2009-03-17 21:51:43 -07002554 ret = iwl_tx_agg_stop(priv, sta->addr, tid);
2555 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2556 return 0;
2557 else
2558 return ret;
Tomas Winklerd783b062008-07-18 13:53:02 +08002559 default:
Tomas Winklere1623442009-01-27 14:27:56 -08002560 IWL_DEBUG_HT(priv, "unknown\n");
Tomas Winklerd783b062008-07-18 13:53:02 +08002561 return -EINVAL;
2562 break;
2563 }
2564 return 0;
2565}
Tomas Winkler9f586712008-11-12 13:14:05 -08002566
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002567static int iwl_mac_get_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07002568 struct ieee80211_low_level_stats *stats)
2569{
Ester Kummerbf403db2008-05-05 10:22:40 +08002570 struct iwl_priv *priv = hw->priv;
2571
2572 priv = hw->priv;
Tomas Winklere1623442009-01-27 14:27:56 -08002573 IWL_DEBUG_MAC80211(priv, "enter\n");
2574 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002575
2576 return 0;
2577}
2578
Zhu Yib481de92007-09-25 17:54:57 -07002579/*****************************************************************************
2580 *
2581 * sysfs attributes
2582 *
2583 *****************************************************************************/
2584
Tomas Winkler0a6857e2008-03-12 16:58:49 -07002585#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07002586
2587/*
2588 * The following adds a new attribute to the sysfs representation
Wu, Fengguangc3a739f2008-12-17 16:52:29 +08002589 * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
Zhu Yib481de92007-09-25 17:54:57 -07002590 * used for controlling the debug level.
2591 *
2592 * See the level definitions in iwl for details.
Reinette Chatrea562a9d2009-07-17 09:30:24 -07002593 *
Reinette Chatre3d816c72009-08-07 15:41:37 -07002594 * The debug_level being managed using sysfs below is a per device debug
2595 * level that is used instead of the global debug level if it (the per
2596 * device debug level) is set.
Zhu Yib481de92007-09-25 17:54:57 -07002597 */
Ester Kummer8cf769c2008-05-06 11:05:11 +08002598static ssize_t show_debug_level(struct device *d,
2599 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07002600{
Reinette Chatre3d816c72009-08-07 15:41:37 -07002601 struct iwl_priv *priv = dev_get_drvdata(d);
2602 return sprintf(buf, "0x%08X\n", iwl_get_debug_level(priv));
Zhu Yib481de92007-09-25 17:54:57 -07002603}
Ester Kummer8cf769c2008-05-06 11:05:11 +08002604static ssize_t store_debug_level(struct device *d,
2605 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07002606 const char *buf, size_t count)
2607{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07002608 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler9257746f2008-09-03 11:26:32 +08002609 unsigned long val;
2610 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002611
Tomas Winkler9257746f2008-09-03 11:26:32 +08002612 ret = strict_strtoul(buf, 0, &val);
2613 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08002614 IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07002615 else {
Reinette Chatre3d816c72009-08-07 15:41:37 -07002616 priv->debug_level = val;
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07002617 if (iwl_alloc_traffic_mem(priv))
2618 IWL_ERR(priv,
2619 "Not enough memory to generate traffic log\n");
2620 }
Zhu Yib481de92007-09-25 17:54:57 -07002621 return strnlen(buf, count);
2622}
2623
Ester Kummer8cf769c2008-05-06 11:05:11 +08002624static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
2625 show_debug_level, store_debug_level);
2626
Zhu Yib481de92007-09-25 17:54:57 -07002627
Tomas Winkler0a6857e2008-03-12 16:58:49 -07002628#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07002629
Zhu Yib481de92007-09-25 17:54:57 -07002630
2631static ssize_t show_temperature(struct device *d,
2632 struct device_attribute *attr, char *buf)
2633{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07002634 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07002635
Tomas Winklerfee12472008-04-03 16:05:21 -07002636 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002637 return -EAGAIN;
2638
Emmanuel Grumbach91dbc5b2008-06-12 09:47:14 +08002639 return sprintf(buf, "%d\n", priv->temperature);
Zhu Yib481de92007-09-25 17:54:57 -07002640}
2641
2642static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
2643
Zhu Yib481de92007-09-25 17:54:57 -07002644static ssize_t show_tx_power(struct device *d,
2645 struct device_attribute *attr, char *buf)
2646{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07002647 struct iwl_priv *priv = dev_get_drvdata(d);
Jay Sternberg91f39e82008-12-17 16:52:34 +08002648
2649 if (!iwl_is_ready_rf(priv))
2650 return sprintf(buf, "off\n");
2651 else
2652 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07002653}
2654
2655static ssize_t store_tx_power(struct device *d,
2656 struct device_attribute *attr,
2657 const char *buf, size_t count)
2658{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07002659 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler9257746f2008-09-03 11:26:32 +08002660 unsigned long val;
2661 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002662
Tomas Winkler9257746f2008-09-03 11:26:32 +08002663 ret = strict_strtoul(buf, 10, &val);
2664 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08002665 IWL_INFO(priv, "%s is not in decimal form.\n", buf);
Wey-Yi Guy5eadd942009-08-21 13:34:17 -07002666 else {
2667 ret = iwl_set_tx_power(priv, val, false);
2668 if (ret)
2669 IWL_ERR(priv, "failed setting tx power (0x%d).\n",
2670 ret);
2671 else
2672 ret = count;
2673 }
2674 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002675}
2676
2677static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
2678
2679static ssize_t show_flags(struct device *d,
2680 struct device_attribute *attr, char *buf)
2681{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07002682 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07002683
2684 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
2685}
2686
2687static ssize_t store_flags(struct device *d,
2688 struct device_attribute *attr,
2689 const char *buf, size_t count)
2690{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07002691 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler9257746f2008-09-03 11:26:32 +08002692 unsigned long val;
2693 u32 flags;
2694 int ret = strict_strtoul(buf, 0, &val);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08002695 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08002696 return ret;
2697 flags = (u32)val;
Zhu Yib481de92007-09-25 17:54:57 -07002698
2699 mutex_lock(&priv->mutex);
2700 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
2701 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08002702 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002703 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002704 else {
Tomas Winklere1623442009-01-27 14:27:56 -08002705 IWL_DEBUG_INFO(priv, "Commit rxon.flags = 0x%04X\n", flags);
Zhu Yib481de92007-09-25 17:54:57 -07002706 priv->staging_rxon.flags = cpu_to_le32(flags);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002707 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002708 }
2709 }
2710 mutex_unlock(&priv->mutex);
2711
2712 return count;
2713}
2714
2715static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
2716
2717static ssize_t show_filter_flags(struct device *d,
2718 struct device_attribute *attr, char *buf)
2719{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07002720 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07002721
2722 return sprintf(buf, "0x%04X\n",
2723 le32_to_cpu(priv->active_rxon.filter_flags));
2724}
2725
2726static ssize_t store_filter_flags(struct device *d,
2727 struct device_attribute *attr,
2728 const char *buf, size_t count)
2729{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07002730 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler9257746f2008-09-03 11:26:32 +08002731 unsigned long val;
2732 u32 filter_flags;
2733 int ret = strict_strtoul(buf, 0, &val);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08002734 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08002735 return ret;
2736 filter_flags = (u32)val;
Zhu Yib481de92007-09-25 17:54:57 -07002737
2738 mutex_lock(&priv->mutex);
2739 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
2740 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08002741 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002742 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002743 else {
Tomas Winklere1623442009-01-27 14:27:56 -08002744 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
Zhu Yib481de92007-09-25 17:54:57 -07002745 "0x%04X\n", filter_flags);
2746 priv->staging_rxon.filter_flags =
2747 cpu_to_le32(filter_flags);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002748 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002749 }
2750 }
2751 mutex_unlock(&priv->mutex);
2752
2753 return count;
2754}
2755
2756static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
2757 store_filter_flags);
2758
Zhu Yib481de92007-09-25 17:54:57 -07002759
2760static ssize_t show_statistics(struct device *d,
2761 struct device_attribute *attr, char *buf)
2762{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002763 struct iwl_priv *priv = dev_get_drvdata(d);
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08002764 u32 size = sizeof(struct iwl_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07002765 u32 len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03002766 u8 *data = (u8 *)&priv->statistics;
Zhu Yib481de92007-09-25 17:54:57 -07002767 int rc = 0;
2768
Tomas Winklerfee12472008-04-03 16:05:21 -07002769 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002770 return -EAGAIN;
2771
2772 mutex_lock(&priv->mutex);
Emmanuel Grumbach49ea8592008-04-15 16:01:37 -07002773 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002774 mutex_unlock(&priv->mutex);
2775
2776 if (rc) {
2777 len = sprintf(buf,
2778 "Error sending statistics request: 0x%08X\n", rc);
2779 return len;
2780 }
2781
2782 while (size && (PAGE_SIZE - len)) {
2783 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
2784 PAGE_SIZE - len, 1);
2785 len = strlen(buf);
2786 if (PAGE_SIZE - len)
2787 buf[len++] = '\n';
2788
2789 ofs += 16;
2790 size -= min(size, 16U);
2791 }
2792
2793 return len;
2794}
2795
2796static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
2797
Zhu Yib481de92007-09-25 17:54:57 -07002798
Zhu Yib481de92007-09-25 17:54:57 -07002799/*****************************************************************************
2800 *
2801 * driver setup and teardown
2802 *
2803 *****************************************************************************/
2804
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002805static void iwl_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002806{
Reinette Chatred21050c2009-02-13 11:51:18 -08002807 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07002808
2809 init_waitqueue_head(&priv->wait_command_queue);
2810
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002811 INIT_WORK(&priv->up, iwl_bg_up);
2812 INIT_WORK(&priv->restart, iwl_bg_restart);
2813 INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002814 INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08002815 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002816 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
2817 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002818
Tomas Winkler2a421b92008-06-12 09:47:10 +08002819 iwl_setup_scan_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002820
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002821 if (priv->cfg->ops->lib->setup_deferred_work)
2822 priv->cfg->ops->lib->setup_deferred_work(priv);
2823
2824 init_timer(&priv->statistics_periodic);
2825 priv->statistics_periodic.data = (unsigned long)priv;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002826 priv->statistics_periodic.function = iwl_bg_statistics_periodic;
Zhu Yib481de92007-09-25 17:54:57 -07002827
Mohamed Abbasef850d72009-05-22 11:01:50 -07002828 if (!priv->cfg->use_isr_legacy)
2829 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
2830 iwl_irq_tasklet, (unsigned long)priv);
2831 else
2832 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
2833 iwl_irq_tasklet_legacy, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07002834}
2835
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002836static void iwl_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002837{
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002838 if (priv->cfg->ops->lib->cancel_deferred_work)
2839 priv->cfg->ops->lib->cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002840
Joonwoo Park3ae6a052007-11-29 10:43:16 +09002841 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07002842 cancel_delayed_work(&priv->scan_check);
2843 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07002844 cancel_work_sync(&priv->beacon_update);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002845 del_timer_sync(&priv->statistics_periodic);
Zhu Yib481de92007-09-25 17:54:57 -07002846}
2847
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002848static struct attribute *iwl_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07002849 &dev_attr_flags.attr,
2850 &dev_attr_filter_flags.attr,
Zhu Yib481de92007-09-25 17:54:57 -07002851 &dev_attr_statistics.attr,
Zhu Yib481de92007-09-25 17:54:57 -07002852 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07002853 &dev_attr_tx_power.attr,
Ester Kummer8cf769c2008-05-06 11:05:11 +08002854#ifdef CONFIG_IWLWIFI_DEBUG
2855 &dev_attr_debug_level.attr,
2856#endif
Zhu Yib481de92007-09-25 17:54:57 -07002857 NULL
2858};
2859
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002860static struct attribute_group iwl_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07002861 .name = NULL, /* put in device directory */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002862 .attrs = iwl_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07002863};
2864
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002865static struct ieee80211_ops iwl_hw_ops = {
2866 .tx = iwl_mac_tx,
2867 .start = iwl_mac_start,
2868 .stop = iwl_mac_stop,
2869 .add_interface = iwl_mac_add_interface,
2870 .remove_interface = iwl_mac_remove_interface,
2871 .config = iwl_mac_config,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002872 .configure_filter = iwl_configure_filter,
2873 .set_key = iwl_mac_set_key,
2874 .update_tkip_key = iwl_mac_update_tkip_key,
2875 .get_stats = iwl_mac_get_stats,
2876 .get_tx_stats = iwl_mac_get_tx_stats,
2877 .conf_tx = iwl_mac_conf_tx,
2878 .reset_tsf = iwl_mac_reset_tsf,
2879 .bss_info_changed = iwl_bss_info_changed,
2880 .ampdu_action = iwl_mac_ampdu_action,
Tomas Winklercb43dc22008-09-03 11:26:23 +08002881 .hw_scan = iwl_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07002882};
2883
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002884static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07002885{
2886 int err = 0;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002887 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07002888 struct ieee80211_hw *hw;
Tomas Winkler82b9a122008-03-04 18:09:30 -08002889 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002890 unsigned long flags;
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002891 u16 pci_cmd;
Zhu Yib481de92007-09-25 17:54:57 -07002892
Assaf Krauss316c30d2008-03-14 10:38:46 -07002893 /************************
2894 * 1. Allocating HW data
2895 ************************/
2896
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002897 /* Disabling hardware scan means that mac80211 will perform scans
2898 * "the hard way", rather than using device's scan. */
Assaf Krauss1ea87392008-03-18 14:57:50 -07002899 if (cfg->mod_params->disable_hw_scan) {
Reinette Chatrea562a9d2009-07-17 09:30:24 -07002900 if (iwl_debug_level & IWL_DL_INFO)
Ester Kummerbf403db2008-05-05 10:22:40 +08002901 dev_printk(KERN_DEBUG, &(pdev->dev),
2902 "Disabling hw_scan\n");
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002903 iwl_hw_ops.hw_scan = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07002904 }
2905
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002906 hw = iwl_alloc_all(cfg, &iwl_hw_ops);
Assaf Krauss1d0a0822008-03-14 10:38:48 -07002907 if (!hw) {
Zhu Yib481de92007-09-25 17:54:57 -07002908 err = -ENOMEM;
2909 goto out;
2910 }
Assaf Krauss1d0a0822008-03-14 10:38:48 -07002911 priv = hw->priv;
2912 /* At this point both hw and priv are allocated. */
2913
Zhu Yib481de92007-09-25 17:54:57 -07002914 SET_IEEE80211_DEV(hw, &pdev->dev);
2915
Tomas Winklere1623442009-01-27 14:27:56 -08002916 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Tomas Winkler82b9a122008-03-04 18:09:30 -08002917 priv->cfg = cfg;
Zhu Yib481de92007-09-25 17:54:57 -07002918 priv->pci_dev = pdev;
Mohamed Abbas40cefda2009-05-22 11:01:52 -07002919 priv->inta_mask = CSR_INI_SET_MASK;
Assaf Krauss316c30d2008-03-14 10:38:46 -07002920
Tomas Winkler0a6857e2008-03-12 16:58:49 -07002921#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07002922 atomic_set(&priv->restrict_refcnt, 0);
2923#endif
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07002924 if (iwl_alloc_traffic_mem(priv))
2925 IWL_ERR(priv, "Not enough memory to generate traffic log\n");
Zhu Yib481de92007-09-25 17:54:57 -07002926
Assaf Krauss316c30d2008-03-14 10:38:46 -07002927 /**************************
2928 * 2. Initializing PCI bus
2929 **************************/
2930 if (pci_enable_device(pdev)) {
2931 err = -ENODEV;
2932 goto out_ieee80211_free_hw;
2933 }
2934
2935 pci_set_master(pdev);
2936
Winkler, Tomas093d874c2008-09-26 15:09:34 +08002937 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
Assaf Krauss316c30d2008-03-14 10:38:46 -07002938 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08002939 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07002940 if (err) {
Winkler, Tomas093d874c2008-09-26 15:09:34 +08002941 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07002942 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08002943 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07002944 /* both attempts failed: */
Assaf Krauss316c30d2008-03-14 10:38:46 -07002945 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08002946 IWL_WARN(priv, "No suitable DMA available.\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07002947 goto out_pci_disable_device;
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07002948 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07002949 }
2950
2951 err = pci_request_regions(pdev, DRV_NAME);
2952 if (err)
2953 goto out_pci_disable_device;
2954
2955 pci_set_drvdata(pdev, priv);
2956
Assaf Krauss316c30d2008-03-14 10:38:46 -07002957
2958 /***********************
2959 * 3. Read REV register
2960 ***********************/
2961 priv->hw_base = pci_iomap(pdev, 0, 0);
2962 if (!priv->hw_base) {
2963 err = -ENODEV;
2964 goto out_pci_release_regions;
2965 }
2966
Tomas Winklere1623442009-01-27 14:27:56 -08002967 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Assaf Krauss316c30d2008-03-14 10:38:46 -07002968 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08002969 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Assaf Krauss316c30d2008-03-14 10:38:46 -07002970
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07002971 /* this spin lock will be used in apm_ops.init and EEPROM access
2972 * we should init now
2973 */
2974 spin_lock_init(&priv->reg_lock);
Tomas Winklerb661c812008-04-23 17:14:54 -07002975 iwl_hw_detect(priv);
Tomas Winkler978785a2008-12-19 10:37:31 +08002976 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s REV=0x%X\n",
Tomas Winklerb661c812008-04-23 17:14:54 -07002977 priv->cfg->name, priv->hw_rev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07002978
Tomas Winklere7b63582008-09-03 11:26:49 +08002979 /* We disable the RETRY_TIMEOUT register (0x41) to keep
2980 * PCI Tx retries from interfering with C3 CPU state */
2981 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
2982
Mohamed Abbas086ed112009-05-22 11:01:54 -07002983 iwl_prepare_card_hw(priv);
2984 if (!priv->hw_ready) {
2985 IWL_WARN(priv, "Failed, HW not ready\n");
2986 goto out_iounmap;
2987 }
2988
Tomas Winkler91238712008-04-23 17:14:53 -07002989 /* amp init */
2990 err = priv->cfg->ops->lib->apm_ops.init(priv);
2991 if (err < 0) {
Reinette Chatre808ff692009-03-11 11:18:01 -07002992 IWL_ERR(priv, "Failed to init APMG\n");
Tomas Winkler91238712008-04-23 17:14:53 -07002993 goto out_iounmap;
2994 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07002995 /*****************
2996 * 4. Read EEPROM
2997 *****************/
Assaf Krauss316c30d2008-03-14 10:38:46 -07002998 /* Read the EEPROM */
2999 err = iwl_eeprom_init(priv);
3000 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003001 IWL_ERR(priv, "Unable to init EEPROM\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07003002 goto out_iounmap;
3003 }
Tomas Winkler8614f362008-04-23 17:14:55 -07003004 err = iwl_eeprom_check_version(priv);
3005 if (err)
Reinette Chatrec8f16132009-02-27 16:21:22 -08003006 goto out_free_eeprom;
Tomas Winkler8614f362008-04-23 17:14:55 -07003007
Ron Rindjunsky02883012008-05-15 13:53:53 +08003008 /* extract MAC Address */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003009 iwl_eeprom_get_mac(priv, priv->mac_addr);
Tomas Winklere1623442009-01-27 14:27:56 -08003010 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003011 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
3012
3013 /************************
3014 * 5. Setup HW constants
3015 ************************/
Ron Rindjunskyda154e302008-06-30 17:23:20 +08003016 if (iwl_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003017 IWL_ERR(priv, "failed to set hw parameters\n");
Tomas Winkler073d3f52008-04-21 15:41:52 -07003018 goto out_free_eeprom;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003019 }
3020
3021 /*******************
Tomas Winkler6ba87952008-05-15 13:54:17 +08003022 * 6. Setup priv
Assaf Krauss316c30d2008-03-14 10:38:46 -07003023 *******************/
Zhu Yib481de92007-09-25 17:54:57 -07003024
Tomas Winkler6ba87952008-05-15 13:54:17 +08003025 err = iwl_init_drv(priv);
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003026 if (err)
Ron Rindjunsky399f4902008-04-23 17:14:56 -07003027 goto out_free_eeprom;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003028 /* At this point both hw and priv are initialized. */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003029
Assaf Krauss316c30d2008-03-14 10:38:46 -07003030 /********************
Abhijeet Kolekar09f9bf72009-04-20 14:37:03 -07003031 * 7. Setup services
Assaf Krauss316c30d2008-03-14 10:38:46 -07003032 ********************/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003033 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003034 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003035 spin_unlock_irqrestore(&priv->lock, flags);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003036
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003037 pci_enable_msi(priv->pci_dev);
3038
Mohamed Abbasef850d72009-05-22 11:01:50 -07003039 iwl_alloc_isr_ict(priv);
3040 err = request_irq(priv->pci_dev->irq, priv->cfg->ops->lib->isr,
3041 IRQF_SHARED, DRV_NAME, priv);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003042 if (err) {
3043 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
3044 goto out_disable_msi;
3045 }
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003046 err = sysfs_create_group(&pdev->dev.kobj, &iwl_attribute_group);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003047 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003048 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Helmut Schaa795cc0a2009-02-12 18:51:03 +01003049 goto out_free_irq;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003050 }
3051
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003052 iwl_setup_deferred_work(priv);
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08003053 iwl_setup_rx_handlers(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003054
Tomas Winkler6ba87952008-05-15 13:54:17 +08003055 /**********************************
Abhijeet Kolekar09f9bf72009-04-20 14:37:03 -07003056 * 8. Setup and register mac80211
Tomas Winkler6ba87952008-05-15 13:54:17 +08003057 **********************************/
3058
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003059 /* enable interrupts if needed: hw bug w/a */
3060 pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd);
3061 if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
3062 pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
3063 pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
3064 }
3065
3066 iwl_enable_interrupts(priv);
3067
Tomas Winkler6ba87952008-05-15 13:54:17 +08003068 err = iwl_setup_mac(priv);
3069 if (err)
3070 goto out_remove_sysfs;
3071
3072 err = iwl_dbgfs_register(priv, DRV_NAME);
3073 if (err)
Abhijeet Kolekara75fbe82009-04-20 14:36:58 -07003074 IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
Tomas Winkler6ba87952008-05-15 13:54:17 +08003075
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003076 /* If platform's RF_KILL switch is NOT set to KILL */
3077 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3078 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3079 else
3080 set_bit(STATUS_RF_KILL_HW, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003081
Johannes Berga60e77e2009-06-04 18:26:06 +02003082 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
3083 test_bit(STATUS_RF_KILL_HW, &priv->status));
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003084
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08003085 iwl_power_initialize(priv);
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -07003086 iwl_tt_initialize(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003087 return 0;
3088
Assaf Krauss316c30d2008-03-14 10:38:46 -07003089 out_remove_sysfs:
Reinette Chatrec8f16132009-02-27 16:21:22 -08003090 destroy_workqueue(priv->workqueue);
3091 priv->workqueue = NULL;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003092 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
Helmut Schaa795cc0a2009-02-12 18:51:03 +01003093 out_free_irq:
3094 free_irq(priv->pci_dev->irq, priv);
Mohamed Abbasef850d72009-05-22 11:01:50 -07003095 iwl_free_isr_ict(priv);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003096 out_disable_msi:
3097 pci_disable_msi(priv->pci_dev);
Tomas Winkler6ba87952008-05-15 13:54:17 +08003098 iwl_uninit_drv(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07003099 out_free_eeprom:
3100 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003101 out_iounmap:
3102 pci_iounmap(pdev, priv->hw_base);
3103 out_pci_release_regions:
Assaf Krauss316c30d2008-03-14 10:38:46 -07003104 pci_set_drvdata(pdev, NULL);
Reinette Chatre623d5632009-03-03 11:37:04 -08003105 pci_release_regions(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07003106 out_pci_disable_device:
3107 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07003108 out_ieee80211_free_hw:
3109 ieee80211_free_hw(priv->hw);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003110 iwl_free_traffic_mem(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003111 out:
3112 return err;
3113}
3114
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003115static void __devexit iwl_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07003116{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003117 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003118 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07003119
3120 if (!priv)
3121 return;
3122
Tomas Winklere1623442009-01-27 14:27:56 -08003123 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07003124
Emmanuel Grumbach67249622008-05-29 16:35:26 +08003125 iwl_dbgfs_unregister(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003126 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
Emmanuel Grumbach67249622008-05-29 16:35:26 +08003127
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003128 /* ieee80211_unregister_hw call wil cause iwl_mac_stop to
3129 * to be called and iwl_down since we are removing the device
Gregory Greenman0b124c32008-09-03 11:18:50 +08003130 * we need to set STATUS_EXIT_PENDING bit.
3131 */
3132 set_bit(STATUS_EXIT_PENDING, &priv->status);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07003133 if (priv->mac80211_registered) {
3134 ieee80211_unregister_hw(priv->hw);
3135 priv->mac80211_registered = 0;
Gregory Greenman0b124c32008-09-03 11:18:50 +08003136 } else {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003137 iwl_down(priv);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07003138 }
3139
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -07003140 iwl_tt_exit(priv);
3141
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003142 /* make sure we flush any pending irq or
3143 * tasklet for the driver
3144 */
3145 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003146 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003147 spin_unlock_irqrestore(&priv->lock, flags);
3148
3149 iwl_synchronize_irq(priv);
3150
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003151 iwl_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003152
3153 if (priv->rxq.bd)
Tomas Winklera55360e2008-05-05 10:22:28 +08003154 iwl_rx_queue_free(priv, &priv->rxq);
Ron Rindjunsky1053d352008-05-05 10:22:43 +08003155 iwl_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003156
Tomas Winklerc587de02009-06-03 11:44:07 -07003157 iwl_clear_stations_table(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07003158 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003159
Zhu Yib481de92007-09-25 17:54:57 -07003160
Mohamed Abbas948c1712007-10-25 17:15:45 +08003161 /*netif_stop_queue(dev); */
3162 flush_workqueue(priv->workqueue);
3163
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003164 /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07003165 * priv->workqueue... so we can't take down the workqueue
3166 * until now... */
3167 destroy_workqueue(priv->workqueue);
3168 priv->workqueue = NULL;
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003169 iwl_free_traffic_mem(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003170
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003171 free_irq(priv->pci_dev->irq, priv);
3172 pci_disable_msi(priv->pci_dev);
Zhu Yib481de92007-09-25 17:54:57 -07003173 pci_iounmap(pdev, priv->hw_base);
3174 pci_release_regions(pdev);
3175 pci_disable_device(pdev);
3176 pci_set_drvdata(pdev, NULL);
3177
Tomas Winkler6ba87952008-05-15 13:54:17 +08003178 iwl_uninit_drv(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003179
Mohamed Abbasef850d72009-05-22 11:01:50 -07003180 iwl_free_isr_ict(priv);
3181
Zhu Yib481de92007-09-25 17:54:57 -07003182 if (priv->ibss_beacon)
3183 dev_kfree_skb(priv->ibss_beacon);
3184
3185 ieee80211_free_hw(priv->hw);
3186}
3187
Zhu Yib481de92007-09-25 17:54:57 -07003188
3189/*****************************************************************************
3190 *
3191 * driver and module entry point
3192 *
3193 *****************************************************************************/
3194
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003195/* Hardware specific file defines the PCI IDs table for that hardware module */
3196static struct pci_device_id iwl_hw_card_ids[] = {
Tomas Winkler4fc22b22008-07-21 18:54:42 +03003197#ifdef CONFIG_IWL4965
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003198 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
3199 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
Tomas Winkler4fc22b22008-07-21 18:54:42 +03003200#endif /* CONFIG_IWL4965 */
Tomas Winkler5a6a2562008-04-24 11:55:23 -07003201#ifdef CONFIG_IWL5000
Esti Kummer47408632008-07-11 11:53:30 +08003202 {IWL_PCI_DEVICE(0x4232, 0x1205, iwl5100_bg_cfg)},
3203 {IWL_PCI_DEVICE(0x4232, 0x1305, iwl5100_bg_cfg)},
3204 {IWL_PCI_DEVICE(0x4232, 0x1206, iwl5100_abg_cfg)},
3205 {IWL_PCI_DEVICE(0x4232, 0x1306, iwl5100_abg_cfg)},
3206 {IWL_PCI_DEVICE(0x4232, 0x1326, iwl5100_abg_cfg)},
3207 {IWL_PCI_DEVICE(0x4237, 0x1216, iwl5100_abg_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07003208 {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)},
Esti Kummer47408632008-07-11 11:53:30 +08003209 {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)},
3210 {IWL_PCI_DEVICE(0x4236, PCI_ANY_ID, iwl5300_agn_cfg)},
3211 {IWL_PCI_DEVICE(0x4237, PCI_ANY_ID, iwl5100_agn_cfg)},
Tomas Winklere96a8492008-09-11 11:45:20 +08003212/* 5350 WiFi/WiMax */
3213 {IWL_PCI_DEVICE(0x423A, 0x1001, iwl5350_agn_cfg)},
3214 {IWL_PCI_DEVICE(0x423A, 0x1021, iwl5350_agn_cfg)},
3215 {IWL_PCI_DEVICE(0x423B, 0x1011, iwl5350_agn_cfg)},
Tomas Winkler7100e922008-12-01 16:32:18 -08003216/* 5150 Wifi/WiMax */
3217 {IWL_PCI_DEVICE(0x423C, PCI_ANY_ID, iwl5150_agn_cfg)},
3218 {IWL_PCI_DEVICE(0x423D, PCI_ANY_ID, iwl5150_agn_cfg)},
Jay Sternberge1228372009-01-19 15:30:34 -08003219/* 6000/6050 Series */
Wey-Yi Guy65b79982009-07-31 14:28:07 -07003220 {IWL_PCI_DEVICE(0x008D, PCI_ANY_ID, iwl6000h_2agn_cfg)},
3221 {IWL_PCI_DEVICE(0x008E, PCI_ANY_ID, iwl6000h_2agn_cfg)},
Jay Sternberge1228372009-01-19 15:30:34 -08003222 {IWL_PCI_DEVICE(0x422B, PCI_ANY_ID, iwl6000_3agn_cfg)},
Wey-Yi Guy65b79982009-07-31 14:28:07 -07003223 {IWL_PCI_DEVICE(0x422C, PCI_ANY_ID, iwl6000i_2agn_cfg)},
Jay Sternberge1228372009-01-19 15:30:34 -08003224 {IWL_PCI_DEVICE(0x4238, PCI_ANY_ID, iwl6000_3agn_cfg)},
Wey-Yi Guy65b79982009-07-31 14:28:07 -07003225 {IWL_PCI_DEVICE(0x4239, PCI_ANY_ID, iwl6000i_2agn_cfg)},
Jay Sternberge1228372009-01-19 15:30:34 -08003226 {IWL_PCI_DEVICE(0x0086, PCI_ANY_ID, iwl6050_3agn_cfg)},
3227 {IWL_PCI_DEVICE(0x0087, PCI_ANY_ID, iwl6050_2agn_cfg)},
3228 {IWL_PCI_DEVICE(0x0088, PCI_ANY_ID, iwl6050_3agn_cfg)},
3229 {IWL_PCI_DEVICE(0x0089, PCI_ANY_ID, iwl6050_2agn_cfg)},
Jay Sternberg77dcb6a2009-03-06 13:52:55 -08003230/* 1000 Series WiFi */
3231 {IWL_PCI_DEVICE(0x0083, PCI_ANY_ID, iwl1000_bgn_cfg)},
3232 {IWL_PCI_DEVICE(0x0084, PCI_ANY_ID, iwl1000_bgn_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07003233#endif /* CONFIG_IWL5000 */
Tomas Winkler7100e922008-12-01 16:32:18 -08003234
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003235 {0}
3236};
3237MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
3238
3239static struct pci_driver iwl_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07003240 .name = DRV_NAME,
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003241 .id_table = iwl_hw_card_ids,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003242 .probe = iwl_pci_probe,
3243 .remove = __devexit_p(iwl_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07003244#ifdef CONFIG_PM
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003245 .suspend = iwl_pci_suspend,
3246 .resume = iwl_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07003247#endif
3248};
3249
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003250static int __init iwl_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07003251{
3252
3253 int ret;
3254 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
3255 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003256
Tomas Winklere227cea2008-07-18 13:53:05 +08003257 ret = iwlagn_rate_control_register();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003258 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08003259 printk(KERN_ERR DRV_NAME
3260 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003261 return ret;
3262 }
3263
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003264 ret = pci_register_driver(&iwl_driver);
Zhu Yib481de92007-09-25 17:54:57 -07003265 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08003266 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003267 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07003268 }
Zhu Yib481de92007-09-25 17:54:57 -07003269
3270 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003271
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003272error_register:
Tomas Winklere227cea2008-07-18 13:53:05 +08003273 iwlagn_rate_control_unregister();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003274 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003275}
3276
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003277static void __exit iwl_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07003278{
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003279 pci_unregister_driver(&iwl_driver);
Tomas Winklere227cea2008-07-18 13:53:05 +08003280 iwlagn_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07003281}
3282
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003283module_exit(iwl_exit);
3284module_init(iwl_init);
Reinette Chatrea562a9d2009-07-17 09:30:24 -07003285
3286#ifdef CONFIG_IWLWIFI_DEBUG
3287module_param_named(debug50, iwl_debug_level, uint, 0444);
3288MODULE_PARM_DESC(debug50, "50XX debug output mask (deprecated)");
3289module_param_named(debug, iwl_debug_level, uint, 0644);
3290MODULE_PARM_DESC(debug, "debug output mask");
3291#endif
3292