blob: b8377efb3ba71f873b646ae5020669d1b6c8fb16 [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Reinette Chatre01f81622009-01-08 10:20:02 -08003 * Copyright(c) 2003 - 2009 Intel Corporation. All rights reserved.
Zhu Yib481de92007-09-25 17:54:57 -07004 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
Winkler, Tomas759ef892008-12-09 11:28:58 -080025 * Intel Linux Wireless <ilw@linux.intel.com>
Zhu Yib481de92007-09-25 17:54:57 -070026 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
Zhu Yib481de92007-09-25 17:54:57 -070030#include <linux/kernel.h>
31#include <linux/module.h>
Zhu Yib481de92007-09-25 17:54:57 -070032#include <linux/init.h>
33#include <linux/pci.h>
34#include <linux/dma-mapping.h>
35#include <linux/delay.h>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040036#include <linux/sched.h>
Zhu Yib481de92007-09-25 17:54:57 -070037#include <linux/skbuff.h>
38#include <linux/netdevice.h>
39#include <linux/wireless.h>
40#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070041#include <linux/etherdevice.h>
42#include <linux/if_arp.h>
43
Zhu Yib481de92007-09-25 17:54:57 -070044#include <net/mac80211.h>
45
46#include <asm/div64.h>
47
Samuel Ortiza3139c52008-12-19 10:37:09 +080048#define DRV_NAME "iwlagn"
49
Assaf Krauss6bc913b2008-03-11 16:17:18 -070050#include "iwl-eeprom.h"
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070051#include "iwl-dev.h"
Tomas Winklerfee12472008-04-03 16:05:21 -070052#include "iwl-core.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070053#include "iwl-io.h"
Zhu Yib481de92007-09-25 17:54:57 -070054#include "iwl-helpers.h"
Emmanuel Grumbach6974e362008-04-14 21:16:06 -070055#include "iwl-sta.h"
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -070056#include "iwl-calib.h"
Zhu Yib481de92007-09-25 17:54:57 -070057
Christoph Hellwig416e1432007-10-25 17:15:49 +080058
Zhu Yib481de92007-09-25 17:54:57 -070059/******************************************************************************
60 *
61 * module boiler plate
62 *
63 ******************************************************************************/
64
Zhu Yib481de92007-09-25 17:54:57 -070065/*
66 * module name, copyright, version, etc.
Zhu Yib481de92007-09-25 17:54:57 -070067 */
Tomas Winklerd783b062008-07-18 13:53:02 +080068#define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
Zhu Yib481de92007-09-25 17:54:57 -070069
Tomas Winkler0a6857e2008-03-12 16:58:49 -070070#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070071#define VD "d"
72#else
73#define VD
74#endif
75
Reinette Chatre80bc5392009-02-13 11:51:19 -080076#ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070077#define VS "s"
78#else
79#define VS
80#endif
81
Tomas Winklerdf48c322008-03-06 10:40:19 -080082#define DRV_VERSION IWLWIFI_VERSION VD VS
Zhu Yib481de92007-09-25 17:54:57 -070083
Zhu Yib481de92007-09-25 17:54:57 -070084
85MODULE_DESCRIPTION(DRV_DESCRIPTION);
86MODULE_VERSION(DRV_VERSION);
Tomas Winklera7b75202008-12-11 10:33:41 -080087MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
Zhu Yib481de92007-09-25 17:54:57 -070088MODULE_LICENSE("GPL");
Tomas Winkler4fc22b22008-07-21 18:54:42 +030089MODULE_ALIAS("iwl4965");
Zhu Yib481de92007-09-25 17:54:57 -070090
Zhu Yib481de92007-09-25 17:54:57 -070091/*************** STATION TABLE MANAGEMENT ****
Ben Cahill9fbab512007-11-29 11:09:47 +080092 * mac80211 should be examined to determine if sta_info is duplicating
Zhu Yib481de92007-09-25 17:54:57 -070093 * the functionality provided here
94 */
95
96/**************************************************************/
97
Zhu Yib481de92007-09-25 17:54:57 -070098/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -070099 * iwl_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -0700100 *
Ian Schram01ebd062007-10-25 17:15:22 +0800101 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -0700102 * the active_rxon structure is updated with the new data. This
103 * function correctly transitions out of the RXON_ASSOC_MSK state if
104 * a HW tune is required based on the RXON structure changes.
105 */
Abhijeet Kolekare0158e62009-04-08 11:26:37 -0700106int iwl_commit_rxon(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700107{
108 /* cast away the const for active_rxon in this function */
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800109 struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800110 int ret;
111 bool new_assoc =
112 !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK);
Zhu Yib481de92007-09-25 17:54:57 -0700113
Tomas Winklerfee12472008-04-03 16:05:21 -0700114 if (!iwl_is_alive(priv))
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800115 return -EBUSY;
Zhu Yib481de92007-09-25 17:54:57 -0700116
117 /* always get timestamp with Rx frame */
118 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
119
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800120 ret = iwl_check_rxon_cmd(priv);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800121 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800122 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700123 return -EINVAL;
124 }
125
Wey-Yi Guy0924e5192009-11-06 14:52:54 -0800126 /*
127 * receive commit_rxon request
128 * abort any previous channel switch if still in process
129 */
130 if (priv->switch_rxon.switch_in_progress &&
131 (priv->switch_rxon.channel != priv->staging_rxon.channel)) {
132 IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
133 le16_to_cpu(priv->switch_rxon.channel));
134 priv->switch_rxon.switch_in_progress = false;
135 }
136
Zhu Yib481de92007-09-25 17:54:57 -0700137 /* If we don't need to send a full RXON, we can use
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700138 * iwl_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -0700139 * and other flags for the current radio configuration. */
Mohamed Abbas54559702008-09-03 11:18:44 +0800140 if (!iwl_full_rxon_required(priv)) {
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800141 ret = iwl_send_rxon_assoc(priv);
142 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800143 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800144 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700145 }
146
147 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Wey-Yi Guya6435652009-11-06 14:52:46 -0800148 iwl_print_rx_config_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700149 return 0;
150 }
151
152 /* station table will be cleared */
153 priv->assoc_station_added = 0;
154
Zhu Yib481de92007-09-25 17:54:57 -0700155 /* If we are currently associated and the new config requires
156 * an RXON_ASSOC and the new config wants the associated mask enabled,
157 * we must clear the associated from the active configuration
158 * before we apply the new config */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800159 if (iwl_is_associated(priv) && new_assoc) {
Tomas Winklere1623442009-01-27 14:27:56 -0800160 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
Zhu Yib481de92007-09-25 17:54:57 -0700161 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
162
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800163 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800164 sizeof(struct iwl_rxon_cmd),
Zhu Yib481de92007-09-25 17:54:57 -0700165 &priv->active_rxon);
166
167 /* If the mask clearing failed then we set
168 * active_rxon back to what it was previously */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800169 if (ret) {
Zhu Yib481de92007-09-25 17:54:57 -0700170 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
Winkler, Tomas15b16872008-12-19 10:37:33 +0800171 IWL_ERR(priv, "Error clearing ASSOC_MSK (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800172 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700173 }
Zhu Yib481de92007-09-25 17:54:57 -0700174 }
175
Tomas Winklere1623442009-01-27 14:27:56 -0800176 IWL_DEBUG_INFO(priv, "Sending RXON\n"
Zhu Yib481de92007-09-25 17:54:57 -0700177 "* with%s RXON_FILTER_ASSOC_MSK\n"
178 "* channel = %d\n"
Johannes Berge1749612008-10-27 15:59:26 -0700179 "* bssid = %pM\n",
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800180 (new_assoc ? "" : "out"),
Zhu Yib481de92007-09-25 17:54:57 -0700181 le16_to_cpu(priv->staging_rxon.channel),
Johannes Berge1749612008-10-27 15:59:26 -0700182 priv->staging_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -0700183
Tomas Winkler90e8e422009-06-19 13:52:42 -0700184 iwl_set_rxon_hwcrypto(priv, !priv->cfg->mod_params->sw_crypto);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800185
186 /* Apply the new configuration
187 * RXON unassoc clears the station table in uCode, send it before
188 * we add the bcast station. If assoc bit is set, we will send RXON
189 * after having added the bcast and bssid station.
190 */
191 if (!new_assoc) {
192 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800193 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800194 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800195 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800196 return ret;
197 }
198 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700199 }
200
Tomas Winklerc587de02009-06-03 11:44:07 -0700201 iwl_clear_stations_table(priv);
Zhu Yi556f8db2007-09-27 11:27:33 +0800202
Johannes Berg19cc1082009-05-08 13:44:36 -0700203 priv->start_calib = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700204
Zhu Yib481de92007-09-25 17:54:57 -0700205 /* Add the broadcast address so we can send broadcast frames */
Reinette Chatre9a9ca652009-10-30 14:36:12 -0700206 iwl_add_bcast_station(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700207
208 /* If we have set the ASSOC_MSK and we are in BSS mode then
209 * add the IWL_AP_ID to the station rate table */
Tomas Winkler91851592008-06-30 17:23:14 +0800210 if (new_assoc) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200211 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Tomas Winkler91851592008-06-30 17:23:14 +0800212 ret = iwl_rxon_add_station(priv,
213 priv->active_rxon.bssid_addr, 1);
214 if (ret == IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800215 IWL_ERR(priv,
216 "Error adding AP address for TX.\n");
Tomas Winkler91851592008-06-30 17:23:14 +0800217 return -EIO;
218 }
219 priv->assoc_station_added = 1;
220 if (priv->default_wep_key &&
221 iwl_send_static_wepkey_cmd(priv, 0))
Winkler, Tomas15b16872008-12-19 10:37:33 +0800222 IWL_ERR(priv,
223 "Could not send WEP static key.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700224 }
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800225
Wey-Yi Guy47eef9b2009-09-17 10:43:44 -0700226 /*
227 * allow CTS-to-self if possible for new association.
228 * this is relevant only for 5000 series and up,
229 * but will not damage 4965
230 */
231 priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN;
232
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800233 /* Apply the new configuration
234 * RXON assoc doesn't clear the station table in uCode,
235 */
236 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
237 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
238 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800239 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800240 return ret;
241 }
242 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700243 }
Wey-Yi Guya6435652009-11-06 14:52:46 -0800244 iwl_print_rx_config_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700245
Zhu Yi36da7d72008-07-11 11:53:40 +0800246 iwl_init_sensitivity(priv);
247
248 /* If we issue a new RXON command which required a tune then we must
249 * send a new TXPOWER command or we won't be able to Tx any frames */
250 ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
251 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800252 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
Zhu Yi36da7d72008-07-11 11:53:40 +0800253 return ret;
254 }
255
Zhu Yib481de92007-09-25 17:54:57 -0700256 return 0;
257}
258
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700259void iwl_update_chain_flags(struct iwl_priv *priv)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700260{
261
Abhijeet Kolekar45823532009-04-08 11:26:44 -0700262 if (priv->cfg->ops->hcmd->set_rxon_chain)
263 priv->cfg->ops->hcmd->set_rxon_chain(priv);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -0700264 iwlcore_commit_rxon(priv);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700265}
266
Tomas Winklerfcab4232008-05-15 13:54:01 +0800267static void iwl_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700268{
269 struct list_head *element;
270
Tomas Winklere1623442009-01-27 14:27:56 -0800271 IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
Zhu Yib481de92007-09-25 17:54:57 -0700272 priv->frames_count);
273
274 while (!list_empty(&priv->free_frames)) {
275 element = priv->free_frames.next;
276 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800277 kfree(list_entry(element, struct iwl_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700278 priv->frames_count--;
279 }
280
281 if (priv->frames_count) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800282 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
Zhu Yib481de92007-09-25 17:54:57 -0700283 priv->frames_count);
284 priv->frames_count = 0;
285 }
286}
287
Tomas Winklerfcab4232008-05-15 13:54:01 +0800288static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700289{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800290 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700291 struct list_head *element;
292 if (list_empty(&priv->free_frames)) {
293 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
294 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800295 IWL_ERR(priv, "Could not allocate frame!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700296 return NULL;
297 }
298
299 priv->frames_count++;
300 return frame;
301 }
302
303 element = priv->free_frames.next;
304 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800305 return list_entry(element, struct iwl_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700306}
307
Tomas Winklerfcab4232008-05-15 13:54:01 +0800308static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700309{
310 memset(frame, 0, sizeof(*frame));
311 list_add(&frame->list, &priv->free_frames);
312}
313
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800314static u32 iwl_fill_beacon_frame(struct iwl_priv *priv,
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800315 struct ieee80211_hdr *hdr,
Rami Rosen73ec1cc2008-12-16 09:37:07 +0200316 int left)
Zhu Yib481de92007-09-25 17:54:57 -0700317{
Tomas Winkler3109ece2008-03-28 16:33:35 -0700318 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200319 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
320 (priv->iw_mode != NL80211_IFTYPE_AP)))
Zhu Yib481de92007-09-25 17:54:57 -0700321 return 0;
322
323 if (priv->ibss_beacon->len > left)
324 return 0;
325
326 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
327
328 return priv->ibss_beacon->len;
329}
330
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800331/* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
332static void iwl_set_beacon_tim(struct iwl_priv *priv,
333 struct iwl_tx_beacon_cmd *tx_beacon_cmd,
334 u8 *beacon, u32 frame_size)
335{
336 u16 tim_idx;
337 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
338
339 /*
340 * The index is relative to frame start but we start looking at the
341 * variable-length part of the beacon.
342 */
343 tim_idx = mgmt->u.beacon.variable - beacon;
344
345 /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
346 while ((tim_idx < (frame_size - 2)) &&
347 (beacon[tim_idx] != WLAN_EID_TIM))
348 tim_idx += beacon[tim_idx+1] + 2;
349
350 /* If TIM field was found, set variables */
351 if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
352 tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
353 tx_beacon_cmd->tim_size = beacon[tim_idx+1];
354 } else
355 IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
356}
357
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700358static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800359 struct iwl_frame *frame)
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800360{
361 struct iwl_tx_beacon_cmd *tx_beacon_cmd;
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800362 u32 frame_size;
363 u32 rate_flags;
364 u32 rate;
365 /*
366 * We have to set up the TX command, the TX Beacon command, and the
367 * beacon contents.
368 */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800369
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800370 /* Initialize memory */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800371 tx_beacon_cmd = &frame->u.beacon;
372 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
373
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800374 /* Set up TX beacon contents */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800375 frame_size = iwl_fill_beacon_frame(priv, tx_beacon_cmd->frame,
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800376 sizeof(frame->u) - sizeof(*tx_beacon_cmd));
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800377 if (WARN_ON_ONCE(frame_size > MAX_MPDU_SIZE))
378 return 0;
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800379
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800380 /* Set up TX command fields */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800381 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800382 tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
383 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800384 tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800385 TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
386
387 /* Set up TX beacon command fields */
388 iwl_set_beacon_tim(priv, tx_beacon_cmd, (u8 *)tx_beacon_cmd->frame,
389 frame_size);
390
391 /* Set up packet rate and flags */
392 rate = iwl_rate_get_lowest_plcp(priv);
393 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant);
394 rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
395 if ((rate >= IWL_FIRST_CCK_RATE) && (rate <= IWL_LAST_CCK_RATE))
396 rate_flags |= RATE_MCS_CCK_MSK;
397 tx_beacon_cmd->tx.rate_n_flags = iwl_hw_set_rate_n_flags(rate,
398 rate_flags);
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800399
400 return sizeof(*tx_beacon_cmd) + frame_size;
401}
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700402static int iwl_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700403{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800404 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700405 unsigned int frame_size;
406 int rc;
Zhu Yib481de92007-09-25 17:54:57 -0700407
Tomas Winklerfcab4232008-05-15 13:54:01 +0800408 frame = iwl_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700409 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800410 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
Zhu Yib481de92007-09-25 17:54:57 -0700411 "command.\n");
412 return -ENOMEM;
413 }
414
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800415 frame_size = iwl_hw_get_beacon_cmd(priv, frame);
416 if (!frame_size) {
417 IWL_ERR(priv, "Error configuring the beacon command\n");
418 iwl_free_frame(priv, frame);
419 return -EINVAL;
420 }
Zhu Yib481de92007-09-25 17:54:57 -0700421
Tomas Winkler857485c2008-03-21 13:53:44 -0700422 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700423 &frame->u.cmd[0]);
424
Tomas Winklerfcab4232008-05-15 13:54:01 +0800425 iwl_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700426
427 return rc;
428}
429
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800430static inline dma_addr_t iwl_tfd_tb_get_addr(struct iwl_tfd *tfd, u8 idx)
431{
432 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
433
434 dma_addr_t addr = get_unaligned_le32(&tb->lo);
435 if (sizeof(dma_addr_t) > sizeof(u32))
436 addr |=
437 ((dma_addr_t)(le16_to_cpu(tb->hi_n_len) & 0xF) << 16) << 16;
438
439 return addr;
440}
441
442static inline u16 iwl_tfd_tb_get_len(struct iwl_tfd *tfd, u8 idx)
443{
444 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
445
446 return le16_to_cpu(tb->hi_n_len) >> 4;
447}
448
449static inline void iwl_tfd_set_tb(struct iwl_tfd *tfd, u8 idx,
450 dma_addr_t addr, u16 len)
451{
452 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
453 u16 hi_n_len = len << 4;
454
455 put_unaligned_le32(addr, &tb->lo);
456 if (sizeof(dma_addr_t) > sizeof(u32))
457 hi_n_len |= ((addr >> 16) >> 16) & 0xF;
458
459 tb->hi_n_len = cpu_to_le16(hi_n_len);
460
461 tfd->num_tbs = idx + 1;
462}
463
464static inline u8 iwl_tfd_get_num_tbs(struct iwl_tfd *tfd)
465{
466 return tfd->num_tbs & 0x1f;
467}
468
469/**
470 * iwl_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
471 * @priv - driver private data
472 * @txq - tx queue
473 *
474 * Does NOT advance any TFD circular buffer read/write indexes
475 * Does NOT free the TFD itself (which is within circular buffer)
476 */
477void iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq)
478{
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800479 struct iwl_tfd *tfd_tmp = (struct iwl_tfd *)txq->tfds;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800480 struct iwl_tfd *tfd;
481 struct pci_dev *dev = priv->pci_dev;
482 int index = txq->q.read_ptr;
483 int i;
484 int num_tbs;
485
486 tfd = &tfd_tmp[index];
487
488 /* Sanity check on number of chunks */
489 num_tbs = iwl_tfd_get_num_tbs(tfd);
490
491 if (num_tbs >= IWL_NUM_OF_TBS) {
492 IWL_ERR(priv, "Too many chunks: %i\n", num_tbs);
493 /* @todo issue fatal error, it is quite serious situation */
494 return;
495 }
496
497 /* Unmap tx_cmd */
498 if (num_tbs)
499 pci_unmap_single(dev,
Johannes Bergc2acea82009-07-24 11:13:05 -0700500 pci_unmap_addr(&txq->meta[index], mapping),
501 pci_unmap_len(&txq->meta[index], len),
Fenghua Yu96891ce2009-02-18 15:54:33 -0800502 PCI_DMA_BIDIRECTIONAL);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800503
504 /* Unmap chunks, if any. */
505 for (i = 1; i < num_tbs; i++) {
506 pci_unmap_single(dev, iwl_tfd_tb_get_addr(tfd, i),
507 iwl_tfd_tb_get_len(tfd, i), PCI_DMA_TODEVICE);
508
509 if (txq->txb) {
510 dev_kfree_skb(txq->txb[txq->q.read_ptr].skb[i - 1]);
511 txq->txb[txq->q.read_ptr].skb[i - 1] = NULL;
512 }
513 }
514}
515
516int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv,
517 struct iwl_tx_queue *txq,
518 dma_addr_t addr, u16 len,
519 u8 reset, u8 pad)
520{
521 struct iwl_queue *q;
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800522 struct iwl_tfd *tfd, *tfd_tmp;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800523 u32 num_tbs;
524
525 q = &txq->q;
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800526 tfd_tmp = (struct iwl_tfd *)txq->tfds;
527 tfd = &tfd_tmp[q->write_ptr];
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800528
529 if (reset)
530 memset(tfd, 0, sizeof(*tfd));
531
532 num_tbs = iwl_tfd_get_num_tbs(tfd);
533
534 /* Each TFD can point to a maximum 20 Tx buffers */
535 if (num_tbs >= IWL_NUM_OF_TBS) {
536 IWL_ERR(priv, "Error can not send more than %d chunks\n",
537 IWL_NUM_OF_TBS);
538 return -EINVAL;
539 }
540
541 BUG_ON(addr & ~DMA_BIT_MASK(36));
542 if (unlikely(addr & ~IWL_TX_DMA_MASK))
543 IWL_ERR(priv, "Unaligned address = %llx\n",
544 (unsigned long long)addr);
545
546 iwl_tfd_set_tb(tfd, num_tbs, addr, len);
547
548 return 0;
549}
550
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800551/*
552 * Tell nic where to find circular buffer of Tx Frame Descriptors for
553 * given Tx queue, and enable the DMA channel used for that queue.
554 *
555 * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
556 * channels supported in hardware.
557 */
558int iwl_hw_tx_queue_init(struct iwl_priv *priv,
559 struct iwl_tx_queue *txq)
560{
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800561 int txq_id = txq->q.id;
562
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800563 /* Circular buffer (TFD queue in DRAM) physical base address */
564 iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
565 txq->q.dma_addr >> 8);
566
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800567 return 0;
568}
569
Zhu Yib481de92007-09-25 17:54:57 -0700570/******************************************************************************
571 *
572 * Generic RX handler implementations
573 *
574 ******************************************************************************/
Tomas Winkler885ba202008-05-29 16:34:55 +0800575static void iwl_rx_reply_alive(struct iwl_priv *priv,
576 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700577{
Zhu Yi2f301222009-10-09 17:19:45 +0800578 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Tomas Winkler885ba202008-05-29 16:34:55 +0800579 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -0700580 struct delayed_work *pwork;
581
582 palive = &pkt->u.alive_frame;
583
Tomas Winklere1623442009-01-27 14:27:56 -0800584 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
Zhu Yib481de92007-09-25 17:54:57 -0700585 "0x%01X 0x%01X\n",
586 palive->is_valid, palive->ver_type,
587 palive->ver_subtype);
588
589 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
Tomas Winklere1623442009-01-27 14:27:56 -0800590 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700591 memcpy(&priv->card_alive_init,
592 &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +0800593 sizeof(struct iwl_init_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700594 pwork = &priv->init_alive_start;
595 } else {
Tomas Winklere1623442009-01-27 14:27:56 -0800596 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700597 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +0800598 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700599 pwork = &priv->alive_start;
600 }
601
602 /* We delay the ALIVE response by 5ms to
603 * give the HW RF Kill time to activate... */
604 if (palive->is_valid == UCODE_VALID_OK)
605 queue_delayed_work(priv->workqueue, pwork,
606 msecs_to_jiffies(5));
607 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800608 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700609}
610
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700611static void iwl_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -0700612{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700613 struct iwl_priv *priv =
614 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -0700615 struct sk_buff *beacon;
616
617 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +0200618 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -0700619
620 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800621 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -0700622 return;
623 }
624
625 mutex_lock(&priv->mutex);
626 /* new beacon skb is allocated every time; dispose previous.*/
627 if (priv->ibss_beacon)
628 dev_kfree_skb(priv->ibss_beacon);
629
630 priv->ibss_beacon = beacon;
631 mutex_unlock(&priv->mutex);
632
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700633 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700634}
635
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800636/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700637 * iwl_bg_statistics_periodic - Timer callback to queue statistics
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800638 *
639 * This callback is provided in order to send a statistics request.
640 *
641 * This timer function is continually reset to execute within
642 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
643 * was received. We need to ensure we receive the statistics in order
644 * to update the temperature used for calibrating the TXPOWER.
645 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700646static void iwl_bg_statistics_periodic(unsigned long data)
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800647{
648 struct iwl_priv *priv = (struct iwl_priv *)data;
649
650 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
651 return;
652
Mohamed Abbas61780ee2008-10-29 14:05:49 -0700653 /* dont send host command if rf-kill is on */
654 if (!iwl_is_ready_rf(priv))
655 return;
656
Wey-Yi Guyef8d5522009-11-13 11:56:28 -0800657 iwl_send_statistics_request(priv, CMD_ASYNC, false);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800658}
659
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700660static void iwl_rx_beacon_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +0800661 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700662{
Tomas Winkler0a6857e2008-03-12 16:58:49 -0700663#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yi2f301222009-10-09 17:19:45 +0800664 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Tomas Winkler2aa6ab82008-12-11 10:33:40 -0800665 struct iwl4965_beacon_notif *beacon =
666 (struct iwl4965_beacon_notif *)pkt->u.raw;
Tomas Winklere7d326ac2008-06-12 09:47:11 +0800667 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -0700668
Tomas Winklere1623442009-01-27 14:27:56 -0800669 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
Zhu Yib481de92007-09-25 17:54:57 -0700670 "tsf %d %d rate %d\n",
Tomas Winkler25a65722008-06-12 09:47:07 +0800671 le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
Zhu Yib481de92007-09-25 17:54:57 -0700672 beacon->beacon_notify_hdr.failure_frame,
673 le32_to_cpu(beacon->ibss_mgr_status),
674 le32_to_cpu(beacon->high_tsf),
675 le32_to_cpu(beacon->low_tsf), rate);
676#endif
677
Johannes Berg05c914f2008-09-11 00:01:58 +0200678 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -0700679 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
680 queue_work(priv->workqueue, &priv->beacon_update);
681}
682
Zhu Yib481de92007-09-25 17:54:57 -0700683/* Handle notification from uCode that card's power state is changing
684 * due to software, hardware, or critical temperature RFKILL */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700685static void iwl_rx_card_state_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +0800686 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700687{
Zhu Yi2f301222009-10-09 17:19:45 +0800688 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Zhu Yib481de92007-09-25 17:54:57 -0700689 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
690 unsigned long status = priv->status;
691
Tomas Winklere1623442009-01-27 14:27:56 -0800692 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
Zhu Yib481de92007-09-25 17:54:57 -0700693 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
694 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
695
696 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
697 RF_CARD_DISABLED)) {
698
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700699 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -0700700 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
701
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700702 iwl_write_direct32(priv, HBUS_TARG_MBX_C,
703 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
Zhu Yib481de92007-09-25 17:54:57 -0700704
705 if (!(flags & RXON_CARD_DISABLED)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700706 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -0700707 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700708 iwl_write_direct32(priv, HBUS_TARG_MBX_C,
Zhu Yib481de92007-09-25 17:54:57 -0700709 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
Zhu Yib481de92007-09-25 17:54:57 -0700710 }
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -0700711 if (flags & RF_CARD_DISABLED)
712 iwl_tt_enter_ct_kill(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700713 }
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -0700714 if (!(flags & RF_CARD_DISABLED))
715 iwl_tt_exit_ct_kill(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700716
717 if (flags & HW_CARD_DISABLED)
718 set_bit(STATUS_RF_KILL_HW, &priv->status);
719 else
720 clear_bit(STATUS_RF_KILL_HW, &priv->status);
721
722
Zhu Yib481de92007-09-25 17:54:57 -0700723 if (!(flags & RXON_CARD_DISABLED))
Tomas Winkler2a421b92008-06-12 09:47:10 +0800724 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700725
726 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
Johannes Berga60e77e2009-06-04 18:26:06 +0200727 test_bit(STATUS_RF_KILL_HW, &priv->status)))
728 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
729 test_bit(STATUS_RF_KILL_HW, &priv->status));
Zhu Yib481de92007-09-25 17:54:57 -0700730 else
731 wake_up_interruptible(&priv->wait_command_queue);
732}
733
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700734int iwl_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
Tomas Winklere2e3c572008-07-18 13:53:04 +0800735{
Tomas Winklere2e3c572008-07-18 13:53:04 +0800736 if (src == IWL_PWR_SRC_VAUX) {
Tomas Winkler3fdb68d2009-02-10 15:19:02 -0800737 if (pci_pme_capable(priv->pci_dev, PCI_D3cold))
Tomas Winklere2e3c572008-07-18 13:53:04 +0800738 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
739 APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
740 ~APMG_PS_CTRL_MSK_PWR_SRC);
741 } else {
742 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
743 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
744 ~APMG_PS_CTRL_MSK_PWR_SRC);
745 }
746
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700747 return 0;
Tomas Winklere2e3c572008-07-18 13:53:04 +0800748}
749
Zhu Yib481de92007-09-25 17:54:57 -0700750/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700751 * iwl_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -0700752 *
753 * Setup the RX handlers for each of the reply types sent from the uCode
754 * to the host.
755 *
756 * This function chains into the hardware specific files for them to setup
757 * any hardware specific handlers as well.
758 */
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +0800759static void iwl_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700760{
Tomas Winkler885ba202008-05-29 16:34:55 +0800761 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700762 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
763 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700764 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700765 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700766 iwl_rx_pm_debug_statistics_notif;
767 priv->rx_handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700768
Ben Cahill9fbab512007-11-29 11:09:47 +0800769 /*
770 * The same handler is used for both the REPLY to a discrete
771 * statistics request from the host as well as for the periodic
772 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -0700773 */
Wey-Yi Guyef8d5522009-11-13 11:56:28 -0800774 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_reply_statistics;
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +0800775 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
Tomas Winkler2a421b92008-06-12 09:47:10 +0800776
Tomas Winkler21c339b2008-11-07 09:58:41 -0800777 iwl_setup_spectrum_handlers(priv);
Tomas Winkler2a421b92008-06-12 09:47:10 +0800778 iwl_setup_rx_scan_handlers(priv);
779
Ron Rindjunsky37a44212008-05-29 16:35:18 +0800780 /* status change handler */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700781 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700782
Tomas Winklerc1354752008-05-29 16:35:04 +0800783 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
784 iwl_rx_missed_beacon_notif;
Ron Rindjunsky37a44212008-05-29 16:35:18 +0800785 /* Rx handlers */
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800786 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl_rx_reply_rx_phy;
787 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl_rx_reply_rx;
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +0800788 /* block ack */
789 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl_rx_reply_compressed_ba;
Ben Cahill9fbab512007-11-29 11:09:47 +0800790 /* Set up hardware specific Rx handlers */
Emmanuel Grumbachd4789ef2008-04-24 11:55:20 -0700791 priv->cfg->ops->lib->rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700792}
793
Zhu Yib481de92007-09-25 17:54:57 -0700794/**
Tomas Winklera55360e2008-05-05 10:22:28 +0800795 * iwl_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -0700796 *
797 * Uses the priv->rx_handlers callback function array to invoke
798 * the appropriate handlers, including command responses,
799 * frame-received notifications, and other notifications.
800 */
Tomas Winklera55360e2008-05-05 10:22:28 +0800801void iwl_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700802{
Tomas Winklera55360e2008-05-05 10:22:28 +0800803 struct iwl_rx_mem_buffer *rxb;
Tomas Winklerdb11d632008-05-05 10:22:33 +0800804 struct iwl_rx_packet *pkt;
Tomas Winklera55360e2008-05-05 10:22:28 +0800805 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -0700806 u32 r, i;
807 int reclaim;
808 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800809 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -0800810 u32 count = 8;
Mohamed Abbas4752c932009-05-22 11:01:51 -0700811 int total_empty;
Zhu Yib481de92007-09-25 17:54:57 -0700812
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800813 /* uCode's read index (stored in shared DRAM) indicates the last Rx
814 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8d864222008-11-07 09:58:39 -0800815 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -0700816 i = rxq->read;
817
818 /* Rx interrupt, but nothing sent from uCode */
819 if (i == r)
Tomas Winklere1623442009-01-27 14:27:56 -0800820 IWL_DEBUG_RX(priv, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -0700821
Mohamed Abbas4752c932009-05-22 11:01:51 -0700822 /* calculate total frames need to be restock after handling RX */
Zhu Yi73005152009-10-23 13:42:32 -0700823 total_empty = r - rxq->write_actual;
Mohamed Abbas4752c932009-05-22 11:01:51 -0700824 if (total_empty < 0)
825 total_empty += RX_QUEUE_SIZE;
826
827 if (total_empty > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800828 fill_rx = 1;
829
Zhu Yib481de92007-09-25 17:54:57 -0700830 while (i != r) {
831 rxb = rxq->queue[i];
832
Ben Cahill9fbab512007-11-29 11:09:47 +0800833 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -0700834 * then a bug has been introduced in the queue refilling
835 * routines -- catch it here */
836 BUG_ON(rxb == NULL);
837
838 rxq->queue[i] = NULL;
839
Zhu Yi2f301222009-10-09 17:19:45 +0800840 pci_unmap_page(priv->pci_dev, rxb->page_dma,
841 PAGE_SIZE << priv->hw_params.rx_page_order,
842 PCI_DMA_FROMDEVICE);
843 pkt = rxb_addr(rxb);
Zhu Yib481de92007-09-25 17:54:57 -0700844
Johannes Bergbe1a71a2009-10-02 13:44:02 -0700845 trace_iwlwifi_dev_rx(priv, pkt,
846 le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK);
847
Zhu Yib481de92007-09-25 17:54:57 -0700848 /* Reclaim a command buffer only if this packet is a response
849 * to a (driver-originated) command.
850 * If the packet (e.g. Rx frame) originated from uCode,
851 * there is no command buffer to reclaim.
852 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
853 * but apparently a few don't get set; catch them here. */
854 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
855 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
Tomas Winkler857485c2008-03-21 13:53:44 -0700856 (pkt->hdr.cmd != REPLY_RX) &&
Daniel Halperin7dddaf12008-10-23 23:48:58 -0700857 (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) &&
Zhu Yicfe01702007-09-27 11:27:31 +0800858 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
Zhu Yib481de92007-09-25 17:54:57 -0700859 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
860 (pkt->hdr.cmd != REPLY_TX);
861
862 /* Based on type of command response or notification,
863 * handle those that need handling via function in
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700864 * rx_handlers table. See iwl_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -0700865 if (priv->rx_handlers[pkt->hdr.cmd]) {
Tomas Winklere1623442009-01-27 14:27:56 -0800866 IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r,
Ester Kummerf3d67992008-05-06 11:05:12 +0800867 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700868 priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
Zhu Yi29b1b262009-10-23 13:42:25 -0700869 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -0700870 } else {
871 /* No handling needed */
Tomas Winklere1623442009-01-27 14:27:56 -0800872 IWL_DEBUG_RX(priv,
Zhu Yib481de92007-09-25 17:54:57 -0700873 "r %d i %d No handler needed for %s, 0x%02x\n",
874 r, i, get_cmd_string(pkt->hdr.cmd),
875 pkt->hdr.cmd);
876 }
877
Zhu Yi29b1b262009-10-23 13:42:25 -0700878 /*
879 * XXX: After here, we should always check rxb->page
880 * against NULL before touching it or its virtual
881 * memory (pkt). Because some rx_handler might have
882 * already taken or freed the pages.
883 */
884
Zhu Yib481de92007-09-25 17:54:57 -0700885 if (reclaim) {
Zhu Yi2f301222009-10-09 17:19:45 +0800886 /* Invoke any callbacks, transfer the buffer to caller,
887 * and fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -0700888 * as we reclaim the driver command queue */
Zhu Yi29b1b262009-10-23 13:42:25 -0700889 if (rxb->page)
Tomas Winkler17b88922008-05-29 16:35:12 +0800890 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -0700891 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800892 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -0700893 }
894
Zhu Yi73005152009-10-23 13:42:32 -0700895 /* Reuse the page if possible. For notification packets and
896 * SKBs that fail to Rx correctly, add them back into the
897 * rx_free list for reuse later. */
Zhu Yib481de92007-09-25 17:54:57 -0700898 spin_lock_irqsave(&rxq->lock, flags);
Zhu Yi73005152009-10-23 13:42:32 -0700899 if (rxb->page != NULL) {
900 rxb->page_dma = pci_map_page(priv->pci_dev, rxb->page,
901 0, PAGE_SIZE << priv->hw_params.rx_page_order,
902 PCI_DMA_FROMDEVICE);
903 list_add_tail(&rxb->list, &rxq->rx_free);
904 rxq->free_count++;
905 } else
906 list_add_tail(&rxb->list, &rxq->rx_used);
907
Zhu Yib481de92007-09-25 17:54:57 -0700908 spin_unlock_irqrestore(&rxq->lock, flags);
Zhu Yi73005152009-10-23 13:42:32 -0700909
Zhu Yib481de92007-09-25 17:54:57 -0700910 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800911 /* If there are a lot of unused frames,
912 * restock the Rx queue so ucode wont assert. */
913 if (fill_rx) {
914 count++;
915 if (count >= 8) {
Zhu Yi73005152009-10-23 13:42:32 -0700916 rxq->read = i;
Mohamed Abbas4752c932009-05-22 11:01:51 -0700917 iwl_rx_replenish_now(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800918 count = 0;
919 }
920 }
Zhu Yib481de92007-09-25 17:54:57 -0700921 }
922
923 /* Backtrack one entry */
Zhu Yi73005152009-10-23 13:42:32 -0700924 rxq->read = i;
Mohamed Abbas4752c932009-05-22 11:01:51 -0700925 if (fill_rx)
926 iwl_rx_replenish_now(priv);
927 else
928 iwl_rx_queue_restock(priv);
Tomas Winklera55360e2008-05-05 10:22:28 +0800929}
Tomas Winklera55360e2008-05-05 10:22:28 +0800930
Mohamed Abbas0359fac2008-03-28 16:21:08 -0700931/* call this function to flush any scheduled tasklet */
932static inline void iwl_synchronize_irq(struct iwl_priv *priv)
933{
Tomas Winklera96a27f2008-10-23 23:48:56 -0700934 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -0700935 synchronize_irq(priv->pci_dev->irq);
936 tasklet_kill(&priv->irq_tasklet);
937}
938
Mohamed Abbasef850d72009-05-22 11:01:50 -0700939static void iwl_irq_tasklet_legacy(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700940{
941 u32 inta, handled = 0;
942 u32 inta_fh;
943 unsigned long flags;
Ben Cahillc2e61da2009-10-30 14:36:09 -0700944 u32 i;
Tomas Winkler0a6857e2008-03-12 16:58:49 -0700945#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -0700946 u32 inta_mask;
947#endif
948
949 spin_lock_irqsave(&priv->lock, flags);
950
951 /* Ack/clear/reset pending uCode interrupts.
952 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
953 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700954 inta = iwl_read32(priv, CSR_INT);
955 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -0700956
957 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
958 * Any new interrupts that happen after this, either while we're
959 * in this tasklet, or later, will show up in next ISR/tasklet. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700960 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
961 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -0700962
Tomas Winkler0a6857e2008-03-12 16:58:49 -0700963#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -0700964 if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +0800965 /* just for debug */
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700966 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Tomas Winklere1623442009-01-27 14:27:56 -0800967 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -0700968 inta, inta_mask, inta_fh);
969 }
970#endif
971
Zhu Yi2f301222009-10-09 17:19:45 +0800972 spin_unlock_irqrestore(&priv->lock, flags);
973
Zhu Yib481de92007-09-25 17:54:57 -0700974 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
975 * atomic, make sure that inta covers all the interrupts that
976 * we've discovered, even if FH interrupt came in just after
977 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -0800978 if (inta_fh & CSR49_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -0700979 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -0800980 if (inta_fh & CSR49_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -0700981 inta |= CSR_INT_BIT_FH_TX;
982
983 /* Now service all interrupt bits discovered above. */
984 if (inta & CSR_INT_BIT_HW_ERR) {
Reinette Chatre58dba722009-07-17 09:30:25 -0700985 IWL_ERR(priv, "Hardware error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700986
987 /* Tell the device to stop sending interrupts */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700988 iwl_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700989
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700990 priv->isr_stats.hw++;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700991 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700992
993 handled |= CSR_INT_BIT_HW_ERR;
994
Zhu Yib481de92007-09-25 17:54:57 -0700995 return;
996 }
997
Tomas Winkler0a6857e2008-03-12 16:58:49 -0700998#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -0700999 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07001000 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001001 if (inta & CSR_INT_BIT_SCD) {
Tomas Winklere1623442009-01-27 14:27:56 -08001002 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
Joonwoo Park25c03d82008-01-23 10:15:20 -08001003 "the frame/frames.\n");
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001004 priv->isr_stats.sch++;
1005 }
Zhu Yib481de92007-09-25 17:54:57 -07001006
1007 /* Alive notification via Rx interrupt will do the real work */
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001008 if (inta & CSR_INT_BIT_ALIVE) {
Tomas Winklere1623442009-01-27 14:27:56 -08001009 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001010 priv->isr_stats.alive++;
1011 }
Zhu Yib481de92007-09-25 17:54:57 -07001012 }
1013#endif
1014 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001015 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07001016
Ben Cahill9fbab512007-11-29 11:09:47 +08001017 /* HW RF KILL switch toggled */
Zhu Yib481de92007-09-25 17:54:57 -07001018 if (inta & CSR_INT_BIT_RF_KILL) {
1019 int hw_rf_kill = 0;
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001020 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yib481de92007-09-25 17:54:57 -07001021 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
1022 hw_rf_kill = 1;
1023
Reinette Chatre4c423a22009-07-17 09:30:26 -07001024 IWL_WARN(priv, "RF_KILL bit toggled to %s.\n",
Abhijeet Kolekarc3056062008-11-12 13:14:08 -08001025 hw_rf_kill ? "disable radio" : "enable radio");
Zhu Yib481de92007-09-25 17:54:57 -07001026
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001027 priv->isr_stats.rfkill++;
1028
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +08001029 /* driver only loads ucode once setting the interface up.
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01001030 * the driver allows loading the ucode even if the radio
1031 * is killed. Hence update the killswitch state here. The
1032 * rfkill handler will care about restarting if needed.
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +08001033 */
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01001034 if (!test_bit(STATUS_ALIVE, &priv->status)) {
1035 if (hw_rf_kill)
1036 set_bit(STATUS_RF_KILL_HW, &priv->status);
1037 else
1038 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Johannes Berga60e77e2009-06-04 18:26:06 +02001039 wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
Mohamed Abbasedb34222008-12-11 10:33:37 -08001040 }
Zhu Yib481de92007-09-25 17:54:57 -07001041
1042 handled |= CSR_INT_BIT_RF_KILL;
1043 }
1044
Ben Cahill9fbab512007-11-29 11:09:47 +08001045 /* Chip got too hot and stopped itself */
Zhu Yib481de92007-09-25 17:54:57 -07001046 if (inta & CSR_INT_BIT_CT_KILL) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001047 IWL_ERR(priv, "Microcode CT kill error detected.\n");
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001048 priv->isr_stats.ctkill++;
Zhu Yib481de92007-09-25 17:54:57 -07001049 handled |= CSR_INT_BIT_CT_KILL;
1050 }
1051
1052 /* Error detected by uCode */
1053 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001054 IWL_ERR(priv, "Microcode SW error detected. "
1055 " Restarting 0x%X.\n", inta);
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001056 priv->isr_stats.sw++;
1057 priv->isr_stats.sw_err = inta;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001058 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001059 handled |= CSR_INT_BIT_SW_ERR;
1060 }
1061
Ben Cahillc2e61da2009-10-30 14:36:09 -07001062 /*
1063 * uCode wakes up after power-down sleep.
1064 * Tell device about any new tx or host commands enqueued,
1065 * and about any Rx buffers made available while asleep.
1066 */
Zhu Yib481de92007-09-25 17:54:57 -07001067 if (inta & CSR_INT_BIT_WAKEUP) {
Tomas Winklere1623442009-01-27 14:27:56 -08001068 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
Tomas Winklera55360e2008-05-05 10:22:28 +08001069 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Ben Cahillc2e61da2009-10-30 14:36:09 -07001070 for (i = 0; i < priv->hw_params.max_txq_num; i++)
1071 iwl_txq_update_write_ptr(priv, &priv->txq[i]);
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001072 priv->isr_stats.wakeup++;
Zhu Yib481de92007-09-25 17:54:57 -07001073 handled |= CSR_INT_BIT_WAKEUP;
1074 }
1075
1076 /* All uCode command responses, including Tx command responses,
1077 * Rx "responses" (frame-received notification), and other
1078 * notifications from uCode come through here*/
1079 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Tomas Winklera55360e2008-05-05 10:22:28 +08001080 iwl_rx_handle(priv);
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001081 priv->isr_stats.rx++;
Zhu Yib481de92007-09-25 17:54:57 -07001082 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1083 }
1084
Ben Cahillc72cd192009-10-30 14:36:08 -07001085 /* This "Tx" DMA channel is used only for loading uCode */
Zhu Yib481de92007-09-25 17:54:57 -07001086 if (inta & CSR_INT_BIT_FH_TX) {
Ben Cahillc72cd192009-10-30 14:36:08 -07001087 IWL_DEBUG_ISR(priv, "uCode load interrupt\n");
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001088 priv->isr_stats.tx++;
Zhu Yib481de92007-09-25 17:54:57 -07001089 handled |= CSR_INT_BIT_FH_TX;
Ben Cahillc72cd192009-10-30 14:36:08 -07001090 /* Wake up uCode load routine, now that load is complete */
Ron Rindjunskydbb983b2008-05-15 13:54:12 +08001091 priv->ucode_write_complete = 1;
1092 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07001093 }
1094
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001095 if (inta & ~handled) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001096 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001097 priv->isr_stats.unhandled++;
1098 }
Zhu Yib481de92007-09-25 17:54:57 -07001099
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001100 if (inta & ~(priv->inta_mask)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001101 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001102 inta & ~priv->inta_mask);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001103 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001104 }
1105
1106 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001107 /* only Re-enable if diabled by irq */
1108 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001109 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001110
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001111#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001112 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001113 inta = iwl_read32(priv, CSR_INT);
1114 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1115 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Tomas Winklere1623442009-01-27 14:27:56 -08001116 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
Zhu Yib481de92007-09-25 17:54:57 -07001117 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
1118 }
1119#endif
Zhu Yib481de92007-09-25 17:54:57 -07001120}
1121
Mohamed Abbasef850d72009-05-22 11:01:50 -07001122/* tasklet for iwlagn interrupt */
1123static void iwl_irq_tasklet(struct iwl_priv *priv)
1124{
1125 u32 inta = 0;
1126 u32 handled = 0;
1127 unsigned long flags;
Ben Cahill87569902009-11-06 14:53:01 -08001128 u32 i;
Mohamed Abbasef850d72009-05-22 11:01:50 -07001129#ifdef CONFIG_IWLWIFI_DEBUG
1130 u32 inta_mask;
1131#endif
1132
1133 spin_lock_irqsave(&priv->lock, flags);
1134
1135 /* Ack/clear/reset pending uCode interrupts.
1136 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1137 */
1138 iwl_write32(priv, CSR_INT, priv->inta);
1139
1140 inta = priv->inta;
1141
1142#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001143 if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
Mohamed Abbasef850d72009-05-22 11:01:50 -07001144 /* just for debug */
1145 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1146 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x\n ",
1147 inta, inta_mask);
1148 }
1149#endif
Zhu Yi2f301222009-10-09 17:19:45 +08001150
1151 spin_unlock_irqrestore(&priv->lock, flags);
1152
Mohamed Abbasef850d72009-05-22 11:01:50 -07001153 /* saved interrupt in inta variable now we can reset priv->inta */
1154 priv->inta = 0;
1155
1156 /* Now service all interrupt bits discovered above. */
1157 if (inta & CSR_INT_BIT_HW_ERR) {
Reinette Chatre58dba722009-07-17 09:30:25 -07001158 IWL_ERR(priv, "Hardware error detected. Restarting.\n");
Mohamed Abbasef850d72009-05-22 11:01:50 -07001159
1160 /* Tell the device to stop sending interrupts */
1161 iwl_disable_interrupts(priv);
1162
1163 priv->isr_stats.hw++;
1164 iwl_irq_handle_error(priv);
1165
1166 handled |= CSR_INT_BIT_HW_ERR;
1167
Mohamed Abbasef850d72009-05-22 11:01:50 -07001168 return;
1169 }
1170
1171#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001172 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Mohamed Abbasef850d72009-05-22 11:01:50 -07001173 /* NIC fires this, but we don't use it, redundant with WAKEUP */
1174 if (inta & CSR_INT_BIT_SCD) {
1175 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
1176 "the frame/frames.\n");
1177 priv->isr_stats.sch++;
1178 }
1179
1180 /* Alive notification via Rx interrupt will do the real work */
1181 if (inta & CSR_INT_BIT_ALIVE) {
1182 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
1183 priv->isr_stats.alive++;
1184 }
1185 }
1186#endif
1187 /* Safely ignore these bits for debug checks below */
1188 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
1189
1190 /* HW RF KILL switch toggled */
1191 if (inta & CSR_INT_BIT_RF_KILL) {
1192 int hw_rf_kill = 0;
1193 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
1194 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
1195 hw_rf_kill = 1;
1196
Reinette Chatre4c423a22009-07-17 09:30:26 -07001197 IWL_WARN(priv, "RF_KILL bit toggled to %s.\n",
Mohamed Abbasef850d72009-05-22 11:01:50 -07001198 hw_rf_kill ? "disable radio" : "enable radio");
1199
1200 priv->isr_stats.rfkill++;
1201
1202 /* driver only loads ucode once setting the interface up.
1203 * the driver allows loading the ucode even if the radio
1204 * is killed. Hence update the killswitch state here. The
1205 * rfkill handler will care about restarting if needed.
1206 */
1207 if (!test_bit(STATUS_ALIVE, &priv->status)) {
1208 if (hw_rf_kill)
1209 set_bit(STATUS_RF_KILL_HW, &priv->status);
1210 else
1211 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Johannes Berga60e77e2009-06-04 18:26:06 +02001212 wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001213 }
1214
1215 handled |= CSR_INT_BIT_RF_KILL;
1216 }
1217
1218 /* Chip got too hot and stopped itself */
1219 if (inta & CSR_INT_BIT_CT_KILL) {
1220 IWL_ERR(priv, "Microcode CT kill error detected.\n");
1221 priv->isr_stats.ctkill++;
1222 handled |= CSR_INT_BIT_CT_KILL;
1223 }
1224
1225 /* Error detected by uCode */
1226 if (inta & CSR_INT_BIT_SW_ERR) {
1227 IWL_ERR(priv, "Microcode SW error detected. "
1228 " Restarting 0x%X.\n", inta);
1229 priv->isr_stats.sw++;
1230 priv->isr_stats.sw_err = inta;
1231 iwl_irq_handle_error(priv);
1232 handled |= CSR_INT_BIT_SW_ERR;
1233 }
1234
1235 /* uCode wakes up after power-down sleep */
1236 if (inta & CSR_INT_BIT_WAKEUP) {
1237 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
1238 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Ben Cahill87569902009-11-06 14:53:01 -08001239 for (i = 0; i < priv->hw_params.max_txq_num; i++)
1240 iwl_txq_update_write_ptr(priv, &priv->txq[i]);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001241
1242 priv->isr_stats.wakeup++;
1243
1244 handled |= CSR_INT_BIT_WAKEUP;
1245 }
1246
1247 /* All uCode command responses, including Tx command responses,
1248 * Rx "responses" (frame-received notification), and other
1249 * notifications from uCode come through here*/
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001250 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX |
1251 CSR_INT_BIT_RX_PERIODIC)) {
Mohamed Abbasef850d72009-05-22 11:01:50 -07001252 IWL_DEBUG_ISR(priv, "Rx interrupt\n");
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001253 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
1254 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1255 iwl_write32(priv, CSR_FH_INT_STATUS,
1256 CSR49_FH_INT_RX_MASK);
1257 }
1258 if (inta & CSR_INT_BIT_RX_PERIODIC) {
1259 handled |= CSR_INT_BIT_RX_PERIODIC;
1260 iwl_write32(priv, CSR_INT, CSR_INT_BIT_RX_PERIODIC);
1261 }
1262 /* Sending RX interrupt require many steps to be done in the
1263 * the device:
1264 * 1- write interrupt to current index in ICT table.
1265 * 2- dma RX frame.
1266 * 3- update RX shared data to indicate last write index.
1267 * 4- send interrupt.
1268 * This could lead to RX race, driver could receive RX interrupt
Ben Cahill74ba67e2009-11-20 12:04:53 -08001269 * but the shared data changes does not reflect this;
1270 * periodic interrupt will detect any dangling Rx activity.
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001271 */
Ben Cahill74ba67e2009-11-20 12:04:53 -08001272
1273 /* Disable periodic interrupt; we use it as just a one-shot. */
1274 iwl_write8(priv, CSR_INT_PERIODIC_REG,
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001275 CSR_INT_PERIODIC_DIS);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001276 iwl_rx_handle(priv);
Ben Cahill74ba67e2009-11-20 12:04:53 -08001277
1278 /*
1279 * Enable periodic interrupt in 8 msec only if we received
1280 * real RX interrupt (instead of just periodic int), to catch
1281 * any dangling Rx interrupt. If it was just the periodic
1282 * interrupt, there was no dangling Rx activity, and no need
1283 * to extend the periodic interrupt; one-shot is enough.
1284 */
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001285 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX))
Ben Cahill74ba67e2009-11-20 12:04:53 -08001286 iwl_write8(priv, CSR_INT_PERIODIC_REG,
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001287 CSR_INT_PERIODIC_ENA);
1288
Mohamed Abbasef850d72009-05-22 11:01:50 -07001289 priv->isr_stats.rx++;
Mohamed Abbasef850d72009-05-22 11:01:50 -07001290 }
1291
Ben Cahillc72cd192009-10-30 14:36:08 -07001292 /* This "Tx" DMA channel is used only for loading uCode */
Mohamed Abbasef850d72009-05-22 11:01:50 -07001293 if (inta & CSR_INT_BIT_FH_TX) {
1294 iwl_write32(priv, CSR_FH_INT_STATUS, CSR49_FH_INT_TX_MASK);
Ben Cahillc72cd192009-10-30 14:36:08 -07001295 IWL_DEBUG_ISR(priv, "uCode load interrupt\n");
Mohamed Abbasef850d72009-05-22 11:01:50 -07001296 priv->isr_stats.tx++;
1297 handled |= CSR_INT_BIT_FH_TX;
Ben Cahillc72cd192009-10-30 14:36:08 -07001298 /* Wake up uCode load routine, now that load is complete */
Mohamed Abbasef850d72009-05-22 11:01:50 -07001299 priv->ucode_write_complete = 1;
1300 wake_up_interruptible(&priv->wait_command_queue);
1301 }
1302
1303 if (inta & ~handled) {
1304 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
1305 priv->isr_stats.unhandled++;
1306 }
1307
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001308 if (inta & ~(priv->inta_mask)) {
Mohamed Abbasef850d72009-05-22 11:01:50 -07001309 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001310 inta & ~priv->inta_mask);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001311 }
1312
Mohamed Abbasef850d72009-05-22 11:01:50 -07001313 /* Re-enable all interrupts */
1314 /* only Re-enable if diabled by irq */
1315 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1316 iwl_enable_interrupts(priv);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001317}
1318
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001319
Zhu Yib481de92007-09-25 17:54:57 -07001320/******************************************************************************
1321 *
1322 * uCode download functions
1323 *
1324 ******************************************************************************/
1325
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001326static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001327{
Tomas Winkler98c92212008-01-14 17:46:20 -08001328 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
1329 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
1330 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1331 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
1332 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1333 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001334}
1335
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001336static void iwl_nic_start(struct iwl_priv *priv)
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08001337{
1338 /* Remove all resets to allow NIC to operate */
1339 iwl_write32(priv, CSR_RESET, 0);
1340}
1341
1342
Zhu Yib481de92007-09-25 17:54:57 -07001343/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001344 * iwl_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07001345 *
1346 * Copy into buffers for card to fetch via bus-mastering
1347 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001348static int iwl_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001349{
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001350 struct iwl_ucode_header *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001351 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07001352 const struct firmware *ucode_raw;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001353 const char *name_pre = priv->cfg->fw_name_pre;
1354 const unsigned int api_max = priv->cfg->ucode_api_max;
1355 const unsigned int api_min = priv->cfg->ucode_api_min;
1356 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07001357 u8 *src;
1358 size_t len;
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001359 u32 api_ver, build;
1360 u32 inst_size, data_size, init_size, init_data_size, boot_size;
Jay Sternbergabdc2d62009-07-31 14:28:09 -07001361 u16 eeprom_ver;
Zhu Yib481de92007-09-25 17:54:57 -07001362
1363 /* Ask kernel firmware_class module to get the boot firmware off disk.
1364 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08001365 for (index = api_max; index >= api_min; index--) {
1366 sprintf(buf, "%s%d%s", name_pre, index, ".ucode");
1367 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
1368 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001369 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001370 buf, ret);
1371 if (ret == -ENOENT)
1372 continue;
1373 else
1374 goto error;
1375 } else {
1376 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08001377 IWL_ERR(priv, "Loaded firmware %s, "
1378 "which is deprecated. "
1379 "Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001380 buf, api_max);
Winkler, Tomas15b16872008-12-19 10:37:33 +08001381
Tomas Winklere1623442009-01-27 14:27:56 -08001382 IWL_DEBUG_INFO(priv, "Got firmware '%s' file (%zd bytes) from disk\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001383 buf, ucode_raw->size);
1384 break;
1385 }
Zhu Yib481de92007-09-25 17:54:57 -07001386 }
1387
Reinette Chatrea0987a82008-12-02 12:14:06 -08001388 if (ret < 0)
1389 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07001390
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001391 /* Make sure that we got at least the v1 header! */
1392 if (ucode_raw->size < priv->cfg->ops->ucode->get_header_size(1)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001393 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001394 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001395 goto err_release;
1396 }
1397
1398 /* Data from ucode file: header followed by uCode images */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001399 ucode = (struct iwl_ucode_header *)ucode_raw->data;
Zhu Yib481de92007-09-25 17:54:57 -07001400
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08001401 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08001402 api_ver = IWL_UCODE_API(priv->ucode_ver);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001403 build = priv->cfg->ops->ucode->get_build(ucode, api_ver);
1404 inst_size = priv->cfg->ops->ucode->get_inst_size(ucode, api_ver);
1405 data_size = priv->cfg->ops->ucode->get_data_size(ucode, api_ver);
1406 init_size = priv->cfg->ops->ucode->get_init_size(ucode, api_ver);
1407 init_data_size =
1408 priv->cfg->ops->ucode->get_init_data_size(ucode, api_ver);
1409 boot_size = priv->cfg->ops->ucode->get_boot_size(ucode, api_ver);
1410 src = priv->cfg->ops->ucode->get_data(ucode, api_ver);
Zhu Yib481de92007-09-25 17:54:57 -07001411
Reinette Chatrea0987a82008-12-02 12:14:06 -08001412 /* api_ver should match the api version forming part of the
1413 * firmware filename ... but we don't check for that and only rely
Nick Andrew877d0312009-01-26 11:06:57 +01001414 * on the API version read from firmware header from here on forward */
Reinette Chatrea0987a82008-12-02 12:14:06 -08001415
1416 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001417 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08001418 "Driver supports v%u, firmware is v%u.\n",
1419 api_max, api_ver);
1420 priv->ucode_ver = 0;
1421 ret = -EINVAL;
1422 goto err_release;
1423 }
1424 if (api_ver != api_max)
Tomas Winkler978785a2008-12-19 10:37:31 +08001425 IWL_ERR(priv, "Firmware has old API version. Expected v%u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08001426 "got v%u. New firmware can be obtained "
1427 "from http://www.intellinuxwireless.org.\n",
1428 api_max, api_ver);
1429
Tomas Winkler978785a2008-12-19 10:37:31 +08001430 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
1431 IWL_UCODE_MAJOR(priv->ucode_ver),
1432 IWL_UCODE_MINOR(priv->ucode_ver),
1433 IWL_UCODE_API(priv->ucode_ver),
1434 IWL_UCODE_SERIAL(priv->ucode_ver));
Reinette Chatrea0987a82008-12-02 12:14:06 -08001435
Reinette Chatre5ebeb5a2009-10-30 14:36:04 -07001436 snprintf(priv->hw->wiphy->fw_version,
1437 sizeof(priv->hw->wiphy->fw_version),
1438 "%u.%u.%u.%u",
1439 IWL_UCODE_MAJOR(priv->ucode_ver),
1440 IWL_UCODE_MINOR(priv->ucode_ver),
1441 IWL_UCODE_API(priv->ucode_ver),
1442 IWL_UCODE_SERIAL(priv->ucode_ver));
1443
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001444 if (build)
1445 IWL_DEBUG_INFO(priv, "Build %u\n", build);
1446
Jay Sternbergabdc2d62009-07-31 14:28:09 -07001447 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
1448 IWL_DEBUG_INFO(priv, "NVM Type: %s, version: 0x%x\n",
1449 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
1450 ? "OTP" : "EEPROM", eeprom_ver);
1451
Tomas Winklere1623442009-01-27 14:27:56 -08001452 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08001453 priv->ucode_ver);
Tomas Winklere1623442009-01-27 14:27:56 -08001454 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
Zhu Yib481de92007-09-25 17:54:57 -07001455 inst_size);
Tomas Winklere1623442009-01-27 14:27:56 -08001456 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
Zhu Yib481de92007-09-25 17:54:57 -07001457 data_size);
Tomas Winklere1623442009-01-27 14:27:56 -08001458 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
Zhu Yib481de92007-09-25 17:54:57 -07001459 init_size);
Tomas Winklere1623442009-01-27 14:27:56 -08001460 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
Zhu Yib481de92007-09-25 17:54:57 -07001461 init_data_size);
Tomas Winklere1623442009-01-27 14:27:56 -08001462 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
Zhu Yib481de92007-09-25 17:54:57 -07001463 boot_size);
1464
1465 /* Verify size of file vs. image size info in file's header */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001466 if (ucode_raw->size !=
1467 priv->cfg->ops->ucode->get_header_size(api_ver) +
Zhu Yib481de92007-09-25 17:54:57 -07001468 inst_size + data_size + init_size +
1469 init_data_size + boot_size) {
1470
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001471 IWL_DEBUG_INFO(priv,
1472 "uCode file size %d does not match expected size\n",
1473 (int)ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001474 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001475 goto err_release;
1476 }
1477
1478 /* Verify that uCode images will fit in card's SRAM */
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001479 if (inst_size > priv->hw_params.max_inst_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08001480 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08001481 inst_size);
1482 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001483 goto err_release;
1484 }
1485
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001486 if (data_size > priv->hw_params.max_data_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08001487 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08001488 data_size);
1489 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001490 goto err_release;
1491 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001492 if (init_size > priv->hw_params.max_inst_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08001493 IWL_INFO(priv, "uCode init instr len %d too large to fit in\n",
1494 init_size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001495 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001496 goto err_release;
1497 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001498 if (init_data_size > priv->hw_params.max_data_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08001499 IWL_INFO(priv, "uCode init data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08001500 init_data_size);
1501 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001502 goto err_release;
1503 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001504 if (boot_size > priv->hw_params.max_bsm_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08001505 IWL_INFO(priv, "uCode boot instr len %d too large to fit in\n",
1506 boot_size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001507 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001508 goto err_release;
1509 }
1510
1511 /* Allocate ucode buffers for card's bus-master loading ... */
1512
1513 /* Runtime instructions and 2 copies of data:
1514 * 1) unmodified from disk
1515 * 2) backup cache for save/restore during power-downs */
1516 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001517 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07001518
1519 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001520 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07001521
1522 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001523 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07001524
Zhu, Yi1f304e42009-01-23 13:45:22 -08001525 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
1526 !priv->ucode_data_backup.v_addr)
1527 goto err_pci_alloc;
1528
Zhu Yib481de92007-09-25 17:54:57 -07001529 /* Initialization instructions and data */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001530 if (init_size && init_data_size) {
1531 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001532 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Zhu Yib481de92007-09-25 17:54:57 -07001533
Tomas Winkler90e759d2007-11-29 11:09:41 +08001534 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001535 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001536
1537 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
1538 goto err_pci_alloc;
1539 }
Zhu Yib481de92007-09-25 17:54:57 -07001540
1541 /* Bootstrap (instructions only, no data) */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001542 if (boot_size) {
1543 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001544 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001545
Tomas Winkler90e759d2007-11-29 11:09:41 +08001546 if (!priv->ucode_boot.v_addr)
1547 goto err_pci_alloc;
1548 }
Zhu Yib481de92007-09-25 17:54:57 -07001549
1550 /* Copy images into buffers for card's bus-master reads ... */
1551
1552 /* Runtime instructions (first block of data in file) */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001553 len = inst_size;
Tomas Winklere1623442009-01-27 14:27:56 -08001554 IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001555 memcpy(priv->ucode_code.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001556 src += len;
1557
Tomas Winklere1623442009-01-27 14:27:56 -08001558 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07001559 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
1560
1561 /* Runtime data (2nd block)
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001562 * NOTE: Copy into backup buffer will be done in iwl_up() */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001563 len = data_size;
Tomas Winklere1623442009-01-27 14:27:56 -08001564 IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode data len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001565 memcpy(priv->ucode_data.v_addr, src, len);
1566 memcpy(priv->ucode_data_backup.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001567 src += len;
Zhu Yib481de92007-09-25 17:54:57 -07001568
1569 /* Initialization instructions (3rd block) */
1570 if (init_size) {
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001571 len = init_size;
Tomas Winklere1623442009-01-27 14:27:56 -08001572 IWL_DEBUG_INFO(priv, "Copying (but not loading) init instr len %Zd\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08001573 len);
Zhu Yib481de92007-09-25 17:54:57 -07001574 memcpy(priv->ucode_init.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001575 src += len;
Zhu Yib481de92007-09-25 17:54:57 -07001576 }
1577
1578 /* Initialization data (4th block) */
1579 if (init_data_size) {
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001580 len = init_data_size;
Tomas Winklere1623442009-01-27 14:27:56 -08001581 IWL_DEBUG_INFO(priv, "Copying (but not loading) init data len %Zd\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08001582 len);
Zhu Yib481de92007-09-25 17:54:57 -07001583 memcpy(priv->ucode_init_data.v_addr, src, len);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001584 src += len;
Zhu Yib481de92007-09-25 17:54:57 -07001585 }
1586
1587 /* Bootstrap instructions (5th block) */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001588 len = boot_size;
Tomas Winklere1623442009-01-27 14:27:56 -08001589 IWL_DEBUG_INFO(priv, "Copying (but not loading) boot instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001590 memcpy(priv->ucode_boot.v_addr, src, len);
1591
1592 /* We have our copies now, allow OS release its copies */
1593 release_firmware(ucode_raw);
1594 return 0;
1595
1596 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08001597 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001598 ret = -ENOMEM;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001599 iwl_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001600
1601 err_release:
1602 release_firmware(ucode_raw);
1603
1604 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08001605 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07001606}
1607
Reinette Chatreb7a79402009-09-25 14:24:23 -07001608static const char *desc_lookup_text[] = {
1609 "OK",
1610 "FAIL",
1611 "BAD_PARAM",
1612 "BAD_CHECKSUM",
1613 "NMI_INTERRUPT_WDG",
1614 "SYSASSERT",
1615 "FATAL_ERROR",
1616 "BAD_COMMAND",
1617 "HW_ERROR_TUNE_LOCK",
1618 "HW_ERROR_TEMPERATURE",
1619 "ILLEGAL_CHAN_FREQ",
1620 "VCC_NOT_STABLE",
1621 "FH_ERROR",
1622 "NMI_INTERRUPT_HOST",
1623 "NMI_INTERRUPT_ACTION_PT",
1624 "NMI_INTERRUPT_UNKNOWN",
1625 "UCODE_VERSION_MISMATCH",
1626 "HW_ERROR_ABS_LOCK",
1627 "HW_ERROR_CAL_LOCK_FAIL",
1628 "NMI_INTERRUPT_INST_ACTION_PT",
1629 "NMI_INTERRUPT_DATA_ACTION_PT",
1630 "NMI_TRM_HW_ER",
1631 "NMI_INTERRUPT_TRM",
1632 "NMI_INTERRUPT_BREAK_POINT"
1633 "DEBUG_0",
1634 "DEBUG_1",
1635 "DEBUG_2",
1636 "DEBUG_3",
1637 "UNKNOWN"
1638};
1639
1640static const char *desc_lookup(int i)
1641{
1642 int max = ARRAY_SIZE(desc_lookup_text) - 1;
1643
1644 if (i < 0 || i > max)
1645 i = max;
1646
1647 return desc_lookup_text[i];
1648}
1649
1650#define ERROR_START_OFFSET (1 * sizeof(u32))
1651#define ERROR_ELEM_SIZE (7 * sizeof(u32))
1652
1653void iwl_dump_nic_error_log(struct iwl_priv *priv)
1654{
1655 u32 data2, line;
1656 u32 desc, time, count, base, data1;
1657 u32 blink1, blink2, ilink1, ilink2;
1658
1659 if (priv->ucode_type == UCODE_INIT)
1660 base = le32_to_cpu(priv->card_alive_init.error_event_table_ptr);
1661 else
1662 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
1663
1664 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
Wey-Yi Guy212fb572009-12-02 12:53:00 -08001665 IWL_ERR(priv,
1666 "Not valid error log pointer 0x%08X for %s uCode\n",
1667 base, (priv->ucode_type == UCODE_INIT) ? "Init" : "RT");
Reinette Chatreb7a79402009-09-25 14:24:23 -07001668 return;
1669 }
1670
1671 count = iwl_read_targ_mem(priv, base);
1672
1673 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
1674 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
1675 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
1676 priv->status, count);
1677 }
1678
1679 desc = iwl_read_targ_mem(priv, base + 1 * sizeof(u32));
1680 blink1 = iwl_read_targ_mem(priv, base + 3 * sizeof(u32));
1681 blink2 = iwl_read_targ_mem(priv, base + 4 * sizeof(u32));
1682 ilink1 = iwl_read_targ_mem(priv, base + 5 * sizeof(u32));
1683 ilink2 = iwl_read_targ_mem(priv, base + 6 * sizeof(u32));
1684 data1 = iwl_read_targ_mem(priv, base + 7 * sizeof(u32));
1685 data2 = iwl_read_targ_mem(priv, base + 8 * sizeof(u32));
1686 line = iwl_read_targ_mem(priv, base + 9 * sizeof(u32));
1687 time = iwl_read_targ_mem(priv, base + 11 * sizeof(u32));
1688
Johannes Bergbe1a71a2009-10-02 13:44:02 -07001689 trace_iwlwifi_dev_ucode_error(priv, desc, time, data1, data2, line,
1690 blink1, blink2, ilink1, ilink2);
1691
Reinette Chatreb7a79402009-09-25 14:24:23 -07001692 IWL_ERR(priv, "Desc Time "
1693 "data1 data2 line\n");
1694 IWL_ERR(priv, "%-28s (#%02d) %010u 0x%08X 0x%08X %u\n",
1695 desc_lookup(desc), desc, time, data1, data2, line);
1696 IWL_ERR(priv, "blink1 blink2 ilink1 ilink2\n");
1697 IWL_ERR(priv, "0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2,
1698 ilink1, ilink2);
1699
1700}
1701
1702#define EVENT_START_OFFSET (4 * sizeof(u32))
1703
1704/**
1705 * iwl_print_event_log - Dump error event log to syslog
1706 *
1707 */
1708static void iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
1709 u32 num_events, u32 mode)
1710{
1711 u32 i;
1712 u32 base; /* SRAM byte address of event log header */
1713 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
1714 u32 ptr; /* SRAM byte address of log data */
1715 u32 ev, time, data; /* event log data */
Ben Cahille5854472009-11-06 14:52:58 -08001716 unsigned long reg_flags;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001717
1718 if (num_events == 0)
1719 return;
1720 if (priv->ucode_type == UCODE_INIT)
1721 base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
1722 else
1723 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
1724
1725 if (mode == 0)
1726 event_size = 2 * sizeof(u32);
1727 else
1728 event_size = 3 * sizeof(u32);
1729
1730 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
1731
Ben Cahille5854472009-11-06 14:52:58 -08001732 /* Make sure device is powered up for SRAM reads */
1733 spin_lock_irqsave(&priv->reg_lock, reg_flags);
1734 iwl_grab_nic_access(priv);
1735
1736 /* Set starting address; reads will auto-increment */
1737 _iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, ptr);
1738 rmb();
1739
Reinette Chatreb7a79402009-09-25 14:24:23 -07001740 /* "time" is actually "data" for mode 0 (no timestamp).
1741 * place event id # at far right for easier visual parsing. */
1742 for (i = 0; i < num_events; i++) {
Ben Cahille5854472009-11-06 14:52:58 -08001743 ev = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
1744 time = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Reinette Chatreb7a79402009-09-25 14:24:23 -07001745 if (mode == 0) {
1746 /* data, ev */
Johannes Bergbe1a71a2009-10-02 13:44:02 -07001747 trace_iwlwifi_dev_ucode_event(priv, 0, time, ev);
Reinette Chatreb7a79402009-09-25 14:24:23 -07001748 IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n", time, ev);
1749 } else {
Ben Cahille5854472009-11-06 14:52:58 -08001750 data = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Reinette Chatreb7a79402009-09-25 14:24:23 -07001751 IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
1752 time, data, ev);
Johannes Bergbe1a71a2009-10-02 13:44:02 -07001753 trace_iwlwifi_dev_ucode_event(priv, time, data, ev);
Reinette Chatreb7a79402009-09-25 14:24:23 -07001754 }
1755 }
Ben Cahille5854472009-11-06 14:52:58 -08001756
1757 /* Allow device to power down */
1758 iwl_release_nic_access(priv);
1759 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Reinette Chatreb7a79402009-09-25 14:24:23 -07001760}
1761
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001762/**
1763 * iwl_print_last_event_logs - Dump the newest # of event log to syslog
1764 */
1765static void iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
1766 u32 num_wraps, u32 next_entry,
1767 u32 size, u32 mode)
1768{
1769 /*
1770 * display the newest DEFAULT_LOG_ENTRIES entries
1771 * i.e the entries just before the next ont that uCode would fill.
1772 */
1773 if (num_wraps) {
1774 if (next_entry < size) {
1775 iwl_print_event_log(priv,
1776 capacity - (size - next_entry),
1777 size - next_entry, mode);
1778 iwl_print_event_log(priv, 0,
1779 next_entry, mode);
1780 } else
1781 iwl_print_event_log(priv, next_entry - size,
1782 size, mode);
1783 } else {
1784 if (next_entry < size)
1785 iwl_print_event_log(priv, 0, next_entry, mode);
1786 else
1787 iwl_print_event_log(priv, next_entry - size,
1788 size, mode);
1789 }
1790}
1791
Ben Cahill84c40692009-11-06 14:52:57 -08001792/* For sanity check only. Actual size is determined by uCode, typ. 512 */
1793#define MAX_EVENT_LOG_SIZE (512)
1794
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001795#define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
1796
1797void iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log)
Reinette Chatreb7a79402009-09-25 14:24:23 -07001798{
1799 u32 base; /* SRAM byte address of event log header */
1800 u32 capacity; /* event log capacity in # entries */
1801 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
1802 u32 num_wraps; /* # times uCode wrapped to top of log */
1803 u32 next_entry; /* index of next entry to be written by uCode */
1804 u32 size; /* # entries that we'll print */
1805
1806 if (priv->ucode_type == UCODE_INIT)
1807 base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
1808 else
1809 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
1810
1811 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
Wey-Yi Guy212fb572009-12-02 12:53:00 -08001812 IWL_ERR(priv,
1813 "Invalid event log pointer 0x%08X for %s uCode\n",
1814 base, (priv->ucode_type == UCODE_INIT) ? "Init" : "RT");
Reinette Chatreb7a79402009-09-25 14:24:23 -07001815 return;
1816 }
1817
1818 /* event log header */
1819 capacity = iwl_read_targ_mem(priv, base);
1820 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
1821 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
1822 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
1823
Ben Cahill84c40692009-11-06 14:52:57 -08001824 if (capacity > MAX_EVENT_LOG_SIZE) {
1825 IWL_ERR(priv, "Log capacity %d is bogus, limit to %d entries\n",
1826 capacity, MAX_EVENT_LOG_SIZE);
1827 capacity = MAX_EVENT_LOG_SIZE;
1828 }
1829
1830 if (next_entry > MAX_EVENT_LOG_SIZE) {
1831 IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
1832 next_entry, MAX_EVENT_LOG_SIZE);
1833 next_entry = MAX_EVENT_LOG_SIZE;
1834 }
1835
Reinette Chatreb7a79402009-09-25 14:24:23 -07001836 size = num_wraps ? capacity : next_entry;
1837
1838 /* bail out if nothing in log */
1839 if (size == 0) {
1840 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
1841 return;
1842 }
1843
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001844#ifdef CONFIG_IWLWIFI_DEBUG
1845 if (!(iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS))
1846 size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
1847 ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
1848#else
1849 size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
1850 ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001851#endif
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001852 IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n",
1853 size);
1854
1855#ifdef CONFIG_IWLWIFI_DEBUG
1856 if ((iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) || full_log) {
1857 /*
1858 * if uCode has wrapped back to top of log,
1859 * start at the oldest entry,
1860 * i.e the next one that uCode would fill.
1861 */
1862 if (num_wraps)
1863 iwl_print_event_log(priv, next_entry,
1864 capacity - next_entry, mode);
1865 /* (then/else) start at top of log */
1866 iwl_print_event_log(priv, 0, next_entry, mode);
1867 } else
1868 iwl_print_last_event_logs(priv, capacity, num_wraps,
1869 next_entry, size, mode);
1870#else
1871 iwl_print_last_event_logs(priv, capacity, num_wraps,
1872 next_entry, size, mode);
1873#endif
1874}
Reinette Chatreb7a79402009-09-25 14:24:23 -07001875
Zhu Yib481de92007-09-25 17:54:57 -07001876/**
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001877 * iwl_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07001878 * from protocol/runtime uCode (initialization uCode's
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001879 * Alive gets handled by iwl_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07001880 */
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001881static void iwl_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001882{
Tomas Winkler57aab752008-04-14 21:16:03 -07001883 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001884
Tomas Winklere1623442009-01-27 14:27:56 -08001885 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001886
1887 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
1888 /* We had an error bringing up the hardware, so take it
1889 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08001890 IWL_DEBUG_INFO(priv, "Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001891 goto restart;
1892 }
1893
1894 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
1895 * This is a paranoid check, because we would not have gotten the
1896 * "runtime" alive if code weren't properly loaded. */
Emmanuel Grumbachb0692f22008-04-24 11:55:18 -07001897 if (iwl_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001898 /* Runtime instruction load was bad;
1899 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08001900 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001901 goto restart;
1902 }
1903
Tomas Winklerc587de02009-06-03 11:44:07 -07001904 iwl_clear_stations_table(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07001905 ret = priv->cfg->ops->lib->alive_notify(priv);
1906 if (ret) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001907 IWL_WARN(priv,
1908 "Could not complete ALIVE transition [ntf]: %d\n", ret);
Zhu Yib481de92007-09-25 17:54:57 -07001909 goto restart;
1910 }
1911
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001912 /* After the ALIVE response, we can send host commands to the uCode */
Zhu Yib481de92007-09-25 17:54:57 -07001913 set_bit(STATUS_ALIVE, &priv->status);
1914
Tomas Winklerfee12472008-04-03 16:05:21 -07001915 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001916 return;
1917
Johannes Berg36d68252008-05-15 12:55:26 +02001918 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07001919
1920 priv->active_rate = priv->rates_mask;
1921 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
1922
Wey-Yi Guy2f748de2009-09-17 10:43:51 -07001923 /* Configure Tx antenna selection based on H/W config */
1924 if (priv->cfg->ops->hcmd->set_tx_ant)
1925 priv->cfg->ops->hcmd->set_tx_ant(priv, priv->cfg->valid_tx_ant);
1926
Tomas Winkler3109ece2008-03-28 16:33:35 -07001927 if (iwl_is_associated(priv)) {
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001928 struct iwl_rxon_cmd *active_rxon =
1929 (struct iwl_rxon_cmd *)&priv->active_rxon;
Mohamed Abbas019fb972009-03-17 21:59:18 -07001930 /* apply any changes in staging */
1931 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001932 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1933 } else {
1934 /* Initialize our rx_config data */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001935 iwl_connection_init_rx_config(priv, priv->iw_mode);
Abhijeet Kolekar45823532009-04-08 11:26:44 -07001936
1937 if (priv->cfg->ops->hcmd->set_rxon_chain)
1938 priv->cfg->ops->hcmd->set_rxon_chain(priv);
1939
Zhu Yib481de92007-09-25 17:54:57 -07001940 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
1941 }
1942
Ben Cahill9fbab512007-11-29 11:09:47 +08001943 /* Configure Bluetooth device coexistence support */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001944 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001945
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001946 iwl_reset_run_time_calib(priv);
1947
Zhu Yib481de92007-09-25 17:54:57 -07001948 /* Configure the adapter for unassociated operation */
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07001949 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001950
1951 /* At this point, the NIC is initialized and operational */
Emmanuel Grumbach47f4a582008-06-12 09:47:13 +08001952 iwl_rf_kill_ct_config(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08001953
Johannes Berge932a602009-10-02 13:44:03 -07001954 iwl_leds_init(priv);
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07001955
Tomas Winklere1623442009-01-27 14:27:56 -08001956 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07001957 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08001958 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07001959
Johannes Berge312c242009-08-07 15:41:51 -07001960 iwl_power_update_mode(priv, true);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08001961
Mohamed Abbasada17512008-11-07 09:58:34 -08001962 /* reassociate for ADHOC mode */
1963 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
1964 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
1965 priv->vif);
1966 if (beacon)
1967 iwl_mac_beacon_update(priv->hw, beacon);
1968 }
1969
1970
Assaf Kraussc46fbef2008-06-12 09:47:05 +08001971 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001972 iwl_set_mode(priv, priv->iw_mode);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08001973
Zhu Yib481de92007-09-25 17:54:57 -07001974 return;
1975
1976 restart:
1977 queue_work(priv->workqueue, &priv->restart);
1978}
1979
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001980static void iwl_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07001981
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001982static void __iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001983{
1984 unsigned long flags;
1985 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07001986
Tomas Winklere1623442009-01-27 14:27:56 -08001987 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07001988
Zhu Yib481de92007-09-25 17:54:57 -07001989 if (!exit_pending)
1990 set_bit(STATUS_EXIT_PENDING, &priv->status);
1991
Tomas Winklerc587de02009-06-03 11:44:07 -07001992 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001993
1994 /* Unblock any waiting calls */
1995 wake_up_interruptible_all(&priv->wait_command_queue);
1996
Zhu Yib481de92007-09-25 17:54:57 -07001997 /* Wipe out the EXIT_PENDING status bit if we are not actually
1998 * exiting the module */
1999 if (!exit_pending)
2000 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2001
2002 /* stop and reset the on-board processor */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002003 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07002004
2005 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002006 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002007 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002008 spin_unlock_irqrestore(&priv->lock, flags);
2009 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002010
2011 if (priv->mac80211_registered)
2012 ieee80211_stop_queues(priv->hw);
2013
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002014 /* If we have not previously called iwl_init() then
Johannes Berga60e77e2009-06-04 18:26:06 +02002015 * clear all bits but the RF Kill bit and return */
Tomas Winklerfee12472008-04-03 16:05:21 -07002016 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002017 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2018 STATUS_RF_KILL_HW |
Reinette Chatre97888642008-02-06 11:20:38 -08002019 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2020 STATUS_GEO_CONFIGURED |
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002021 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2022 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002023 goto exit;
2024 }
2025
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002026 /* ...otherwise clear out all the status bits but the RF Kill
Johannes Berga60e77e2009-06-04 18:26:06 +02002027 * bit and continue taking the NIC down. */
Zhu Yib481de92007-09-25 17:54:57 -07002028 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2029 STATUS_RF_KILL_HW |
Reinette Chatre97888642008-02-06 11:20:38 -08002030 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2031 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002032 test_bit(STATUS_FW_ERROR, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002033 STATUS_FW_ERROR |
2034 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2035 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002036
Mohamed Abbasef850d72009-05-22 11:01:50 -07002037 /* device going down, Stop using ICT table */
2038 iwl_disable_ict(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002039
Tomas Winklerda1bc452008-05-29 16:35:00 +08002040 iwl_txq_ctx_stop(priv);
Tomas Winklerb3bbacb2008-05-29 16:35:01 +08002041 iwl_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002042
Ben Cahill309e7312009-11-06 14:53:03 -08002043 /* Power-down device's busmaster DMA clocks */
2044 iwl_write_prph(priv, APMG_CLK_DIS_REG, APMG_CLK_VAL_DMA_CLK_RQT);
Zhu Yib481de92007-09-25 17:54:57 -07002045 udelay(5);
2046
Ben Cahill309e7312009-11-06 14:53:03 -08002047 /* Make sure (redundant) we've released our request to stay awake */
2048 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
2049
Ben Cahill4d2ccdb2009-10-09 13:20:20 -07002050 /* Stop the device, and put it in low power state */
2051 priv->cfg->ops->lib->apm_ops.stop(priv);
2052
Zhu Yib481de92007-09-25 17:54:57 -07002053 exit:
Tomas Winkler885ba202008-05-29 16:34:55 +08002054 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07002055
2056 if (priv->ibss_beacon)
2057 dev_kfree_skb(priv->ibss_beacon);
2058 priv->ibss_beacon = NULL;
2059
2060 /* clear out any free frames */
Tomas Winklerfcab4232008-05-15 13:54:01 +08002061 iwl_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002062}
2063
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002064static void iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002065{
2066 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002067 __iwl_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002068 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08002069
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002070 iwl_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002071}
2072
Mohamed Abbas086ed112009-05-22 11:01:54 -07002073#define HW_READY_TIMEOUT (50)
2074
2075static int iwl_set_hw_ready(struct iwl_priv *priv)
2076{
2077 int ret = 0;
2078
2079 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
2080 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
2081
2082 /* See if we got it */
2083 ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
2084 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
2085 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
2086 HW_READY_TIMEOUT);
2087 if (ret != -ETIMEDOUT)
2088 priv->hw_ready = true;
2089 else
2090 priv->hw_ready = false;
2091
2092 IWL_DEBUG_INFO(priv, "hardware %s\n",
2093 (priv->hw_ready == 1) ? "ready" : "not ready");
2094 return ret;
2095}
2096
2097static int iwl_prepare_card_hw(struct iwl_priv *priv)
2098{
2099 int ret = 0;
2100
2101 IWL_DEBUG_INFO(priv, "iwl_prepare_card_hw enter \n");
2102
Mohamed Abbas3354a0f2009-06-19 13:52:41 -07002103 ret = iwl_set_hw_ready(priv);
2104 if (priv->hw_ready)
2105 return ret;
2106
2107 /* If HW is not ready, prepare the conditions to check again */
Mohamed Abbas086ed112009-05-22 11:01:54 -07002108 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
2109 CSR_HW_IF_CONFIG_REG_PREPARE);
2110
2111 ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
2112 ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE,
2113 CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000);
2114
Mohamed Abbas3354a0f2009-06-19 13:52:41 -07002115 /* HW should be ready by now, check again. */
Mohamed Abbas086ed112009-05-22 11:01:54 -07002116 if (ret != -ETIMEDOUT)
2117 iwl_set_hw_ready(priv);
2118
2119 return ret;
2120}
2121
Zhu Yib481de92007-09-25 17:54:57 -07002122#define MAX_HW_RESTARTS 5
2123
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002124static int __iwl_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002125{
Tomas Winkler57aab752008-04-14 21:16:03 -07002126 int i;
2127 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002128
2129 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002130 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07002131 return -EIO;
2132 }
2133
Reinette Chatree903fbd2008-01-30 22:05:15 -08002134 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002135 IWL_ERR(priv, "ucode not available for device bringup\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08002136 return -EIO;
2137 }
2138
Mohamed Abbas086ed112009-05-22 11:01:54 -07002139 iwl_prepare_card_hw(priv);
2140
2141 if (!priv->hw_ready) {
2142 IWL_WARN(priv, "Exit HW not ready\n");
2143 return -EIO;
2144 }
2145
Zhu Yie655b9f2008-01-24 02:19:38 -08002146 /* If platform's RF_KILL switch is NOT set to KILL */
Tomas Winklerc1842d62008-08-04 16:00:43 +08002147 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
Zhu Yie655b9f2008-01-24 02:19:38 -08002148 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002149 else
Zhu Yie655b9f2008-01-24 02:19:38 -08002150 set_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002151
Tomas Winklerc1842d62008-08-04 16:00:43 +08002152 if (iwl_is_rfkill(priv)) {
Johannes Berga60e77e2009-06-04 18:26:06 +02002153 wiphy_rfkill_set_hw_state(priv->hw->wiphy, true);
2154
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002155 iwl_enable_interrupts(priv);
Johannes Berga60e77e2009-06-04 18:26:06 +02002156 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
Tomas Winklerc1842d62008-08-04 16:00:43 +08002157 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002158 }
2159
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002160 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07002161
Ron Rindjunsky1053d352008-05-05 10:22:43 +08002162 ret = iwl_hw_nic_init(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07002163 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002164 IWL_ERR(priv, "Unable to init nic\n");
Tomas Winkler57aab752008-04-14 21:16:03 -07002165 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002166 }
2167
2168 /* make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002169 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2170 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07002171 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2172
2173 /* clear (again), then enable host interrupts */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002174 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002175 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002176
2177 /* really make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002178 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2179 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07002180
2181 /* Copy original ucode data image from disk into backup cache.
2182 * This will be used to initialize the on-board processor's
2183 * data SRAM for a clean start when the runtime program first loads. */
2184 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a66926a2008-01-14 17:46:18 -08002185 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07002186
Zhu Yib481de92007-09-25 17:54:57 -07002187 for (i = 0; i < MAX_HW_RESTARTS; i++) {
2188
Tomas Winklerc587de02009-06-03 11:44:07 -07002189 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002190
2191 /* load bootstrap state machine,
2192 * load bootstrap program into processor's memory,
2193 * prepare to load the "initialize" uCode */
Tomas Winkler57aab752008-04-14 21:16:03 -07002194 ret = priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002195
Tomas Winkler57aab752008-04-14 21:16:03 -07002196 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002197 IWL_ERR(priv, "Unable to set up bootstrap uCode: %d\n",
2198 ret);
Zhu Yib481de92007-09-25 17:54:57 -07002199 continue;
2200 }
2201
2202 /* start card; "initialize" will load runtime ucode */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002203 iwl_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002204
Tomas Winklere1623442009-01-27 14:27:56 -08002205 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
Zhu Yib481de92007-09-25 17:54:57 -07002206
2207 return 0;
2208 }
2209
2210 set_bit(STATUS_EXIT_PENDING, &priv->status);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002211 __iwl_down(priv);
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08002212 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002213
2214 /* tried to restart and config the device for as long as our
2215 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002216 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07002217 return -EIO;
2218}
2219
2220
2221/*****************************************************************************
2222 *
2223 * Workqueue callbacks
2224 *
2225 *****************************************************************************/
2226
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002227static void iwl_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002228{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002229 struct iwl_priv *priv =
2230 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002231
2232 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2233 return;
2234
2235 mutex_lock(&priv->mutex);
Emmanuel Grumbachf3ccc082008-05-05 10:22:45 +08002236 priv->cfg->ops->lib->init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002237 mutex_unlock(&priv->mutex);
2238}
2239
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002240static void iwl_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002241{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002242 struct iwl_priv *priv =
2243 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002244
2245 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2246 return;
2247
Mohamed Abbas258c44a2009-06-03 11:44:10 -07002248 /* enable dram interrupt */
2249 iwl_reset_ict(priv);
2250
Zhu Yib481de92007-09-25 17:54:57 -07002251 mutex_lock(&priv->mutex);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002252 iwl_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002253 mutex_unlock(&priv->mutex);
2254}
2255
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08002256static void iwl_bg_run_time_calib_work(struct work_struct *work)
2257{
2258 struct iwl_priv *priv = container_of(work, struct iwl_priv,
2259 run_time_calib_work);
2260
2261 mutex_lock(&priv->mutex);
2262
2263 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
2264 test_bit(STATUS_SCANNING, &priv->status)) {
2265 mutex_unlock(&priv->mutex);
2266 return;
2267 }
2268
2269 if (priv->start_calib) {
2270 iwl_chain_noise_calibration(priv, &priv->statistics);
2271
2272 iwl_sensitivity_calibration(priv, &priv->statistics);
2273 }
2274
2275 mutex_unlock(&priv->mutex);
2276 return;
2277}
2278
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002279static void iwl_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002280{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002281 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07002282
2283 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2284 return;
2285
2286 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002287 __iwl_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002288 mutex_unlock(&priv->mutex);
2289}
2290
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002291static void iwl_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002292{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002293 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07002294
2295 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2296 return;
2297
Johannes Berg19cc1082009-05-08 13:44:36 -07002298 if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
2299 mutex_lock(&priv->mutex);
2300 priv->vif = NULL;
2301 priv->is_open = 0;
2302 mutex_unlock(&priv->mutex);
2303 iwl_down(priv);
2304 ieee80211_restart_hw(priv->hw);
2305 } else {
2306 iwl_down(priv);
2307 queue_work(priv->workqueue, &priv->up);
2308 }
Zhu Yib481de92007-09-25 17:54:57 -07002309}
2310
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002311static void iwl_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002312{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002313 struct iwl_priv *priv =
2314 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07002315
2316 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2317 return;
2318
2319 mutex_lock(&priv->mutex);
Tomas Winklera55360e2008-05-05 10:22:28 +08002320 iwl_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002321 mutex_unlock(&priv->mutex);
2322}
2323
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002324#define IWL_DELAY_NEXT_SCAN (HZ*2)
2325
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07002326void iwl_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002327{
Zhu Yib481de92007-09-25 17:54:57 -07002328 struct ieee80211_conf *conf = NULL;
Tomas Winkler857485c2008-03-21 13:53:44 -07002329 int ret = 0;
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002330 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07002331
Johannes Berg05c914f2008-09-11 00:01:58 +02002332 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002333 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07002334 return;
2335 }
2336
Tomas Winklere1623442009-01-27 14:27:56 -08002337 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07002338 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07002339
2340
2341 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2342 return;
2343
Zhu Yib481de92007-09-25 17:54:57 -07002344
Reinette Chatre508e32e2008-04-14 21:16:13 -07002345 if (!priv->vif || !priv->is_open)
Mohamed Abbas948c1712007-10-25 17:15:45 +08002346 return;
Reinette Chatre508e32e2008-04-14 21:16:13 -07002347
Tomas Winkler2a421b92008-06-12 09:47:10 +08002348 iwl_scan_cancel_timeout(priv, 200);
mabbas052c4b92007-10-25 17:15:43 +08002349
Zhu Yib481de92007-09-25 17:54:57 -07002350 conf = ieee80211_get_hw_conf(priv->hw);
2351
2352 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002353 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002354
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002355 iwl_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002356 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002357 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002358 if (ret)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002359 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07002360 "Attempting to continue.\n");
2361
2362 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
2363
Emmanuel Grumbach42eb7c62008-09-17 10:10:05 +08002364 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03002365
Abhijeet Kolekar45823532009-04-08 11:26:44 -07002366 if (priv->cfg->ops->hcmd->set_rxon_chain)
2367 priv->cfg->ops->hcmd->set_rxon_chain(priv);
2368
Zhu Yib481de92007-09-25 17:54:57 -07002369 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2370
Tomas Winklere1623442009-01-27 14:27:56 -08002371 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07002372 priv->assoc_id, priv->beacon_int);
2373
2374 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2375 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2376 else
2377 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2378
2379 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2380 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2381 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2382 else
2383 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2384
Johannes Berg05c914f2008-09-11 00:01:58 +02002385 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002386 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2387
2388 }
2389
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002390 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002391
2392 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02002393 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -07002394 break;
2395
Johannes Berg05c914f2008-09-11 00:01:58 +02002396 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07002397
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002398 /* assume default assoc id */
2399 priv->assoc_id = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002400
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002401 iwl_rxon_add_station(priv, priv->bssid, 0);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002402 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002403
2404 break;
2405
2406 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002407 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03002408 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002409 break;
2410 }
2411
Johannes Berg05c914f2008-09-11 00:01:58 +02002412 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002413 priv->assoc_station_added = 1;
2414
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002415 spin_lock_irqsave(&priv->lock, flags);
2416 iwl_activate_qos(priv, 0);
2417 spin_unlock_irqrestore(&priv->lock, flags);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08002418
Grumbach, Emmanuel04816442008-09-03 11:26:53 +08002419 /* the chain noise calibration will enabled PM upon completion
2420 * If chain noise has already been run, then we need to enable
2421 * power management here */
2422 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
Johannes Berge312c242009-08-07 15:41:51 -07002423 iwl_power_update_mode(priv, false);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08002424
2425 /* Enable Rx differential gain and sensitivity calibrations */
2426 iwl_chain_noise_reset(priv);
2427 priv->start_calib = 1;
2428
Reinette Chatre508e32e2008-04-14 21:16:13 -07002429}
2430
Zhu Yib481de92007-09-25 17:54:57 -07002431/*****************************************************************************
2432 *
2433 * mac80211 entry point functions
2434 *
2435 *****************************************************************************/
2436
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002437#define UCODE_READY_TIMEOUT (4 * HZ)
Zhu Yi5a66926a2008-01-14 17:46:18 -08002438
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002439/*
2440 * Not a mac80211 entry point function, but it fits in with all the
2441 * other mac80211 functions grouped here.
2442 */
2443static int iwl_setup_mac(struct iwl_priv *priv)
2444{
2445 int ret;
2446 struct ieee80211_hw *hw = priv->hw;
2447 hw->rate_control_algorithm = "iwl-agn-rs";
2448
2449 /* Tell mac80211 our characteristics */
2450 hw->flags = IEEE80211_HW_SIGNAL_DBM |
2451 IEEE80211_HW_NOISE_DBM |
2452 IEEE80211_HW_AMPDU_AGGREGATION |
2453 IEEE80211_HW_SPECTRUM_MGMT;
2454
2455 if (!priv->cfg->broken_powersave)
2456 hw->flags |= IEEE80211_HW_SUPPORTS_PS |
2457 IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
2458
Reinette Chatre8d9698b2009-10-16 14:25:55 -07002459 hw->sta_data_size = sizeof(struct iwl_station_priv);
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002460 hw->wiphy->interface_modes =
2461 BIT(NL80211_IFTYPE_STATION) |
2462 BIT(NL80211_IFTYPE_ADHOC);
2463
Johannes Berg5be83de2009-11-19 00:56:28 +01002464 hw->wiphy->flags |= WIPHY_FLAG_STRICT_REGULATORY |
2465 WIPHY_FLAG_DISABLE_BEACON_HINTS;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002466
2467 /*
2468 * For now, disable PS by default because it affects
2469 * RX performance significantly.
2470 */
Johannes Berg5be83de2009-11-19 00:56:28 +01002471 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002472
2473 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
2474 /* we create the 802.11 header and a zero-length SSID element */
2475 hw->wiphy->max_scan_ie_len = IWL_MAX_PROBE_REQUEST - 24 - 2;
2476
2477 /* Default value; 4 EDCA QOS priorities */
2478 hw->queues = 4;
2479
2480 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
2481
2482 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
2483 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
2484 &priv->bands[IEEE80211_BAND_2GHZ];
2485 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
2486 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
2487 &priv->bands[IEEE80211_BAND_5GHZ];
2488
2489 ret = ieee80211_register_hw(priv->hw);
2490 if (ret) {
2491 IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
2492 return ret;
2493 }
2494 priv->mac80211_registered = 1;
2495
2496 return 0;
2497}
2498
2499
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002500static int iwl_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002501{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002502 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002503 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002504
Tomas Winklere1623442009-01-27 14:27:56 -08002505 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002506
2507 /* we should be verifying the device is ready to be opened */
2508 mutex_lock(&priv->mutex);
2509
Zhu Yi5a66926a2008-01-14 17:46:18 -08002510 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
2511 * ucode filename and max sizes are card-specific. */
2512
2513 if (!priv->ucode_code.len) {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002514 ret = iwl_read_ucode(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002515 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002516 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002517 mutex_unlock(&priv->mutex);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002518 return ret;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002519 }
2520 }
2521
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002522 ret = __iwl_up(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002523
Zhu Yib481de92007-09-25 17:54:57 -07002524 mutex_unlock(&priv->mutex);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002525
Zhu Yie655b9f2008-01-24 02:19:38 -08002526 if (ret)
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002527 return ret;
Zhu Yie655b9f2008-01-24 02:19:38 -08002528
Tomas Winklerc1842d62008-08-04 16:00:43 +08002529 if (iwl_is_rfkill(priv))
2530 goto out;
2531
Tomas Winklere1623442009-01-27 14:27:56 -08002532 IWL_DEBUG_INFO(priv, "Start UP work done.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08002533
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002534 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
Zhu Yi5a66926a2008-01-14 17:46:18 -08002535 * mac80211 will not be run successfully. */
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002536 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
2537 test_bit(STATUS_READY, &priv->status),
2538 UCODE_READY_TIMEOUT);
2539 if (!ret) {
2540 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002541 IWL_ERR(priv, "START_ALIVE timeout after %dms.\n",
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002542 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002543 return -ETIMEDOUT;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002544 }
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002545 }
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002546
Johannes Berge932a602009-10-02 13:44:03 -07002547 iwl_led_start(priv);
2548
Tomas Winklerc1842d62008-08-04 16:00:43 +08002549out:
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002550 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08002551 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002552 return 0;
2553}
2554
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002555static void iwl_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002556{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002557 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002558
Tomas Winklere1623442009-01-27 14:27:56 -08002559 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas948c1712007-10-25 17:15:45 +08002560
Johannes Berg19cc1082009-05-08 13:44:36 -07002561 if (!priv->is_open)
Zhu Yie655b9f2008-01-24 02:19:38 -08002562 return;
Zhu Yie655b9f2008-01-24 02:19:38 -08002563
Zhu Yib481de92007-09-25 17:54:57 -07002564 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002565
Wey-Yi Guy5bddf542009-08-21 13:34:25 -07002566 if (iwl_is_ready_rf(priv) || test_bit(STATUS_SCAN_HW, &priv->status)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08002567 /* stop mac, cancel any scan request and clear
2568 * RXON_FILTER_ASSOC_MSK BIT
2569 */
Zhu Yi5a66926a2008-01-14 17:46:18 -08002570 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002571 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002572 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002573 }
2574
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002575 iwl_down(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002576
2577 flush_workqueue(priv->workqueue);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002578
2579 /* enable interrupts again in order to receive rfkill changes */
2580 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
2581 iwl_enable_interrupts(priv);
Mohamed Abbas948c1712007-10-25 17:15:45 +08002582
Tomas Winklere1623442009-01-27 14:27:56 -08002583 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002584}
2585
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002586static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07002587{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002588 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002589
Tomas Winklere1623442009-01-27 14:27:56 -08002590 IWL_DEBUG_MACDUMP(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002591
Tomas Winklere1623442009-01-27 14:27:56 -08002592 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02002593 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07002594
Johannes Berge039fa42008-05-15 12:55:29 +02002595 if (iwl_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07002596 dev_kfree_skb_any(skb);
2597
Tomas Winklere1623442009-01-27 14:27:56 -08002598 IWL_DEBUG_MACDUMP(priv, "leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08002599 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07002600}
2601
Abhijeet Kolekar60690a62009-04-08 11:26:49 -07002602void iwl_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002603{
Tomas Winkler857485c2008-03-21 13:53:44 -07002604 int ret = 0;
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002605 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07002606
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08002607 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07002608 return;
2609
2610 /* The following should be done only at AP bring up */
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002611 if (!iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002612
2613 /* RXON - unassoc (to set timing command) */
2614 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002615 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002616
2617 /* RXON Timing */
Tomas Winkler3195c1f2008-10-08 09:37:30 +08002618 iwl_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002619 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002620 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002621 if (ret)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002622 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07002623 "Attempting to continue.\n");
2624
Daniel C Halperinf513dff2009-11-13 11:56:34 -08002625 /* AP has all antennas */
2626 priv->chain_noise_data.active_chains =
2627 priv->hw_params.valid_rx_ant;
2628 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Abhijeet Kolekar45823532009-04-08 11:26:44 -07002629 if (priv->cfg->ops->hcmd->set_rxon_chain)
2630 priv->cfg->ops->hcmd->set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002631
2632 /* FIXME: what should be the assoc_id for AP? */
2633 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2634 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2635 priv->staging_rxon.flags |=
2636 RXON_FLG_SHORT_PREAMBLE_MSK;
2637 else
2638 priv->staging_rxon.flags &=
2639 ~RXON_FLG_SHORT_PREAMBLE_MSK;
2640
2641 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2642 if (priv->assoc_capability &
2643 WLAN_CAPABILITY_SHORT_SLOT_TIME)
2644 priv->staging_rxon.flags |=
2645 RXON_FLG_SHORT_SLOT_MSK;
2646 else
2647 priv->staging_rxon.flags &=
2648 ~RXON_FLG_SHORT_SLOT_MSK;
2649
Johannes Berg05c914f2008-09-11 00:01:58 +02002650 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002651 priv->staging_rxon.flags &=
2652 ~RXON_FLG_SHORT_SLOT_MSK;
2653 }
2654 /* restore RXON assoc */
2655 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002656 iwlcore_commit_rxon(priv);
Daniel C Halperinf513dff2009-11-13 11:56:34 -08002657 iwl_reset_qos(priv);
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002658 spin_lock_irqsave(&priv->lock, flags);
2659 iwl_activate_qos(priv, 1);
2660 spin_unlock_irqrestore(&priv->lock, flags);
Reinette Chatre9a9ca652009-10-30 14:36:12 -07002661 iwl_add_bcast_station(priv);
Zhu Yie1493de2007-09-27 11:27:32 +08002662 }
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002663 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002664
2665 /* FIXME - we need to add code here to detect a totally new
2666 * configuration, reset the AP, unassoc, rxon timing, assoc,
2667 * clear sta table, add BCAST sta... */
2668}
2669
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002670static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw,
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002671 struct ieee80211_key_conf *keyconf, const u8 *addr,
2672 u32 iv32, u16 *phase1key)
2673{
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002674
Tomas Winkler9f586712008-11-12 13:14:05 -08002675 struct iwl_priv *priv = hw->priv;
Tomas Winklere1623442009-01-27 14:27:56 -08002676 IWL_DEBUG_MAC80211(priv, "enter\n");
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002677
Tomas Winkler9f586712008-11-12 13:14:05 -08002678 iwl_update_tkip_key(priv, keyconf, addr, iv32, phase1key);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002679
Tomas Winklere1623442009-01-27 14:27:56 -08002680 IWL_DEBUG_MAC80211(priv, "leave\n");
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002681}
2682
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002683static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01002684 struct ieee80211_vif *vif,
2685 struct ieee80211_sta *sta,
Zhu Yib481de92007-09-25 17:54:57 -07002686 struct ieee80211_key_conf *key)
2687{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002688 struct iwl_priv *priv = hw->priv;
Winkler, Tomas42986792009-01-19 15:30:22 -08002689 const u8 *addr;
2690 int ret;
2691 u8 sta_id;
2692 bool is_default_wep_key = false;
Zhu Yib481de92007-09-25 17:54:57 -07002693
Tomas Winklere1623442009-01-27 14:27:56 -08002694 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002695
Tomas Winkler90e8e422009-06-19 13:52:42 -07002696 if (priv->cfg->mod_params->sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08002697 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07002698 return -EOPNOTSUPP;
2699 }
Winkler, Tomas42986792009-01-19 15:30:22 -08002700 addr = sta ? sta->addr : iwl_bcast_addr;
Tomas Winklerc587de02009-06-03 11:44:07 -07002701 sta_id = iwl_find_station(priv, addr);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002702 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -08002703 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
Johannes Berge1749612008-10-27 15:59:26 -07002704 addr);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002705 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002706
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002707 }
Zhu Yib481de92007-09-25 17:54:57 -07002708
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002709 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002710 iwl_scan_cancel_timeout(priv, 100);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002711 mutex_unlock(&priv->mutex);
2712
2713 /* If we are getting WEP group key and we didn't receive any key mapping
2714 * so far, we are in legacy wep mode (group key only), otherwise we are
2715 * in 1X mode.
2716 * In legacy wep mode, we use another host command to the uCode */
Tomas Winkler5425e492008-04-15 16:01:38 -07002717 if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
Johannes Berg05c914f2008-09-11 00:01:58 +02002718 priv->iw_mode != NL80211_IFTYPE_AP) {
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002719 if (cmd == SET_KEY)
2720 is_default_wep_key = !priv->key_mapping_key;
2721 else
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +08002722 is_default_wep_key =
2723 (key->hw_key_idx == HW_KEY_DEFAULT);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002724 }
mabbas052c4b92007-10-25 17:15:43 +08002725
Zhu Yib481de92007-09-25 17:54:57 -07002726 switch (cmd) {
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002727 case SET_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002728 if (is_default_wep_key)
2729 ret = iwl_set_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002730 else
Emmanuel Grumbach74805132008-04-14 21:16:09 -07002731 ret = iwl_set_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002732
Tomas Winklere1623442009-01-27 14:27:56 -08002733 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07002734 break;
2735 case DISABLE_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002736 if (is_default_wep_key)
2737 ret = iwl_remove_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002738 else
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07002739 ret = iwl_remove_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002740
Tomas Winklere1623442009-01-27 14:27:56 -08002741 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07002742 break;
2743 default:
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002744 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002745 }
2746
Tomas Winklere1623442009-01-27 14:27:56 -08002747 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002748
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002749 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002750}
2751
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002752static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
Johannes Bergc951ad32009-11-16 12:00:38 +01002753 struct ieee80211_vif *vif,
Tomas Winklerd783b062008-07-18 13:53:02 +08002754 enum ieee80211_ampdu_mlme_action action,
Johannes Berg17741cd2008-09-11 00:02:02 +02002755 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
Tomas Winklerd783b062008-07-18 13:53:02 +08002756{
2757 struct iwl_priv *priv = hw->priv;
Wey-Yi Guy5c2207c2009-03-17 21:51:43 -07002758 int ret;
Tomas Winklerd783b062008-07-18 13:53:02 +08002759
Tomas Winklere1623442009-01-27 14:27:56 -08002760 IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
Johannes Berge1749612008-10-27 15:59:26 -07002761 sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08002762
2763 if (!(priv->cfg->sku & IWL_SKU_N))
2764 return -EACCES;
2765
2766 switch (action) {
2767 case IEEE80211_AMPDU_RX_START:
Tomas Winklere1623442009-01-27 14:27:56 -08002768 IWL_DEBUG_HT(priv, "start Rx\n");
Tomas Winkler9f586712008-11-12 13:14:05 -08002769 return iwl_sta_rx_agg_start(priv, sta->addr, tid, *ssn);
Tomas Winklerd783b062008-07-18 13:53:02 +08002770 case IEEE80211_AMPDU_RX_STOP:
Tomas Winklere1623442009-01-27 14:27:56 -08002771 IWL_DEBUG_HT(priv, "stop Rx\n");
Wey-Yi Guy5c2207c2009-03-17 21:51:43 -07002772 ret = iwl_sta_rx_agg_stop(priv, sta->addr, tid);
2773 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2774 return 0;
2775 else
2776 return ret;
Tomas Winklerd783b062008-07-18 13:53:02 +08002777 case IEEE80211_AMPDU_TX_START:
Tomas Winklere1623442009-01-27 14:27:56 -08002778 IWL_DEBUG_HT(priv, "start Tx\n");
Johannes Berg17741cd2008-09-11 00:02:02 +02002779 return iwl_tx_agg_start(priv, sta->addr, tid, ssn);
Tomas Winklerd783b062008-07-18 13:53:02 +08002780 case IEEE80211_AMPDU_TX_STOP:
Tomas Winklere1623442009-01-27 14:27:56 -08002781 IWL_DEBUG_HT(priv, "stop Tx\n");
Wey-Yi Guy5c2207c2009-03-17 21:51:43 -07002782 ret = iwl_tx_agg_stop(priv, sta->addr, tid);
2783 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2784 return 0;
2785 else
2786 return ret;
Tomas Winklerd783b062008-07-18 13:53:02 +08002787 default:
Tomas Winklere1623442009-01-27 14:27:56 -08002788 IWL_DEBUG_HT(priv, "unknown\n");
Tomas Winklerd783b062008-07-18 13:53:02 +08002789 return -EINVAL;
2790 break;
2791 }
2792 return 0;
2793}
Tomas Winkler9f586712008-11-12 13:14:05 -08002794
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002795static int iwl_mac_get_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07002796 struct ieee80211_low_level_stats *stats)
2797{
Ester Kummerbf403db2008-05-05 10:22:40 +08002798 struct iwl_priv *priv = hw->priv;
2799
2800 priv = hw->priv;
Tomas Winklere1623442009-01-27 14:27:56 -08002801 IWL_DEBUG_MAC80211(priv, "enter\n");
2802 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002803
2804 return 0;
2805}
2806
Johannes Berg6ab10ff2009-11-13 11:56:37 -08002807static void iwl_mac_sta_notify(struct ieee80211_hw *hw,
2808 struct ieee80211_vif *vif,
2809 enum sta_notify_cmd cmd,
2810 struct ieee80211_sta *sta)
2811{
2812 struct iwl_priv *priv = hw->priv;
2813 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
2814 int sta_id;
2815
2816 /*
2817 * TODO: We really should use this callback to
2818 * actually maintain the station table in
2819 * the device.
2820 */
2821
2822 switch (cmd) {
2823 case STA_NOTIFY_ADD:
2824 atomic_set(&sta_priv->pending_frames, 0);
2825 if (vif->type == NL80211_IFTYPE_AP)
2826 sta_priv->client = true;
2827 break;
2828 case STA_NOTIFY_SLEEP:
2829 WARN_ON(!sta_priv->client);
2830 sta_priv->asleep = true;
2831 if (atomic_read(&sta_priv->pending_frames) > 0)
2832 ieee80211_sta_block_awake(hw, sta, true);
2833 break;
2834 case STA_NOTIFY_AWAKE:
2835 WARN_ON(!sta_priv->client);
2836 sta_priv->asleep = false;
2837 sta_id = iwl_find_station(priv, sta->addr);
2838 if (sta_id != IWL_INVALID_STATION)
2839 iwl_sta_modify_ps_wake(priv, sta_id);
2840 break;
2841 default:
2842 break;
2843 }
2844}
2845
Zhu Yib481de92007-09-25 17:54:57 -07002846/*****************************************************************************
2847 *
2848 * sysfs attributes
2849 *
2850 *****************************************************************************/
2851
Tomas Winkler0a6857e2008-03-12 16:58:49 -07002852#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07002853
2854/*
2855 * The following adds a new attribute to the sysfs representation
Wu, Fengguangc3a739f2008-12-17 16:52:29 +08002856 * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
Zhu Yib481de92007-09-25 17:54:57 -07002857 * used for controlling the debug level.
2858 *
2859 * See the level definitions in iwl for details.
Reinette Chatrea562a9d2009-07-17 09:30:24 -07002860 *
Reinette Chatre3d816c72009-08-07 15:41:37 -07002861 * The debug_level being managed using sysfs below is a per device debug
2862 * level that is used instead of the global debug level if it (the per
2863 * device debug level) is set.
Zhu Yib481de92007-09-25 17:54:57 -07002864 */
Ester Kummer8cf769c2008-05-06 11:05:11 +08002865static ssize_t show_debug_level(struct device *d,
2866 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07002867{
Reinette Chatre3d816c72009-08-07 15:41:37 -07002868 struct iwl_priv *priv = dev_get_drvdata(d);
2869 return sprintf(buf, "0x%08X\n", iwl_get_debug_level(priv));
Zhu Yib481de92007-09-25 17:54:57 -07002870}
Ester Kummer8cf769c2008-05-06 11:05:11 +08002871static ssize_t store_debug_level(struct device *d,
2872 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07002873 const char *buf, size_t count)
2874{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07002875 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler9257746f2008-09-03 11:26:32 +08002876 unsigned long val;
2877 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002878
Tomas Winkler9257746f2008-09-03 11:26:32 +08002879 ret = strict_strtoul(buf, 0, &val);
2880 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08002881 IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf);
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07002882 else {
Reinette Chatre3d816c72009-08-07 15:41:37 -07002883 priv->debug_level = val;
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07002884 if (iwl_alloc_traffic_mem(priv))
2885 IWL_ERR(priv,
2886 "Not enough memory to generate traffic log\n");
2887 }
Zhu Yib481de92007-09-25 17:54:57 -07002888 return strnlen(buf, count);
2889}
2890
Ester Kummer8cf769c2008-05-06 11:05:11 +08002891static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
2892 show_debug_level, store_debug_level);
2893
Zhu Yib481de92007-09-25 17:54:57 -07002894
Tomas Winkler0a6857e2008-03-12 16:58:49 -07002895#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07002896
Zhu Yib481de92007-09-25 17:54:57 -07002897
2898static ssize_t show_temperature(struct device *d,
2899 struct device_attribute *attr, char *buf)
2900{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07002901 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07002902
Tomas Winklerfee12472008-04-03 16:05:21 -07002903 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002904 return -EAGAIN;
2905
Emmanuel Grumbach91dbc5b2008-06-12 09:47:14 +08002906 return sprintf(buf, "%d\n", priv->temperature);
Zhu Yib481de92007-09-25 17:54:57 -07002907}
2908
2909static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
2910
Zhu Yib481de92007-09-25 17:54:57 -07002911static ssize_t show_tx_power(struct device *d,
2912 struct device_attribute *attr, char *buf)
2913{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07002914 struct iwl_priv *priv = dev_get_drvdata(d);
Jay Sternberg91f39e82008-12-17 16:52:34 +08002915
2916 if (!iwl_is_ready_rf(priv))
2917 return sprintf(buf, "off\n");
2918 else
2919 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07002920}
2921
2922static ssize_t store_tx_power(struct device *d,
2923 struct device_attribute *attr,
2924 const char *buf, size_t count)
2925{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07002926 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler9257746f2008-09-03 11:26:32 +08002927 unsigned long val;
2928 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002929
Tomas Winkler9257746f2008-09-03 11:26:32 +08002930 ret = strict_strtoul(buf, 10, &val);
2931 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08002932 IWL_INFO(priv, "%s is not in decimal form.\n", buf);
Wey-Yi Guy5eadd942009-08-21 13:34:17 -07002933 else {
2934 ret = iwl_set_tx_power(priv, val, false);
2935 if (ret)
2936 IWL_ERR(priv, "failed setting tx power (0x%d).\n",
2937 ret);
2938 else
2939 ret = count;
2940 }
2941 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002942}
2943
2944static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
2945
2946static ssize_t show_flags(struct device *d,
2947 struct device_attribute *attr, char *buf)
2948{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07002949 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07002950
2951 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
2952}
2953
2954static ssize_t store_flags(struct device *d,
2955 struct device_attribute *attr,
2956 const char *buf, size_t count)
2957{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07002958 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler9257746f2008-09-03 11:26:32 +08002959 unsigned long val;
2960 u32 flags;
2961 int ret = strict_strtoul(buf, 0, &val);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08002962 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08002963 return ret;
2964 flags = (u32)val;
Zhu Yib481de92007-09-25 17:54:57 -07002965
2966 mutex_lock(&priv->mutex);
2967 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
2968 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08002969 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002970 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002971 else {
Tomas Winklere1623442009-01-27 14:27:56 -08002972 IWL_DEBUG_INFO(priv, "Commit rxon.flags = 0x%04X\n", flags);
Zhu Yib481de92007-09-25 17:54:57 -07002973 priv->staging_rxon.flags = cpu_to_le32(flags);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002974 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002975 }
2976 }
2977 mutex_unlock(&priv->mutex);
2978
2979 return count;
2980}
2981
2982static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
2983
2984static ssize_t show_filter_flags(struct device *d,
2985 struct device_attribute *attr, char *buf)
2986{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07002987 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07002988
2989 return sprintf(buf, "0x%04X\n",
2990 le32_to_cpu(priv->active_rxon.filter_flags));
2991}
2992
2993static ssize_t store_filter_flags(struct device *d,
2994 struct device_attribute *attr,
2995 const char *buf, size_t count)
2996{
Greg Kroah-Hartman928841b2009-04-30 23:02:47 -07002997 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler9257746f2008-09-03 11:26:32 +08002998 unsigned long val;
2999 u32 filter_flags;
3000 int ret = strict_strtoul(buf, 0, &val);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08003001 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08003002 return ret;
3003 filter_flags = (u32)val;
Zhu Yib481de92007-09-25 17:54:57 -07003004
3005 mutex_lock(&priv->mutex);
3006 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
3007 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08003008 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003009 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003010 else {
Tomas Winklere1623442009-01-27 14:27:56 -08003011 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
Zhu Yib481de92007-09-25 17:54:57 -07003012 "0x%04X\n", filter_flags);
3013 priv->staging_rxon.filter_flags =
3014 cpu_to_le32(filter_flags);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003015 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003016 }
3017 }
3018 mutex_unlock(&priv->mutex);
3019
3020 return count;
3021}
3022
3023static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
3024 store_filter_flags);
3025
Zhu Yib481de92007-09-25 17:54:57 -07003026
3027static ssize_t show_statistics(struct device *d,
3028 struct device_attribute *attr, char *buf)
3029{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003030 struct iwl_priv *priv = dev_get_drvdata(d);
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08003031 u32 size = sizeof(struct iwl_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07003032 u32 len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003033 u8 *data = (u8 *)&priv->statistics;
Zhu Yib481de92007-09-25 17:54:57 -07003034 int rc = 0;
3035
Tomas Winklerfee12472008-04-03 16:05:21 -07003036 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003037 return -EAGAIN;
3038
3039 mutex_lock(&priv->mutex);
Wey-Yi Guyef8d5522009-11-13 11:56:28 -08003040 rc = iwl_send_statistics_request(priv, CMD_SYNC, false);
Zhu Yib481de92007-09-25 17:54:57 -07003041 mutex_unlock(&priv->mutex);
3042
3043 if (rc) {
3044 len = sprintf(buf,
3045 "Error sending statistics request: 0x%08X\n", rc);
3046 return len;
3047 }
3048
3049 while (size && (PAGE_SIZE - len)) {
3050 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
3051 PAGE_SIZE - len, 1);
3052 len = strlen(buf);
3053 if (PAGE_SIZE - len)
3054 buf[len++] = '\n';
3055
3056 ofs += 16;
3057 size -= min(size, 16U);
3058 }
3059
3060 return len;
3061}
3062
3063static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
3064
Wey-Yi Guy01abfbb2009-09-17 10:43:45 -07003065static ssize_t show_rts_ht_protection(struct device *d,
3066 struct device_attribute *attr, char *buf)
3067{
3068 struct iwl_priv *priv = dev_get_drvdata(d);
3069
3070 return sprintf(buf, "%s\n",
3071 priv->cfg->use_rts_for_ht ? "RTS/CTS" : "CTS-to-self");
3072}
3073
3074static ssize_t store_rts_ht_protection(struct device *d,
3075 struct device_attribute *attr,
3076 const char *buf, size_t count)
3077{
3078 struct iwl_priv *priv = dev_get_drvdata(d);
3079 unsigned long val;
3080 int ret;
3081
3082 ret = strict_strtoul(buf, 10, &val);
3083 if (ret)
3084 IWL_INFO(priv, "Input is not in decimal form.\n");
3085 else {
3086 if (!iwl_is_associated(priv))
3087 priv->cfg->use_rts_for_ht = val ? true : false;
3088 else
3089 IWL_ERR(priv, "Sta associated with AP - "
3090 "Change protection mechanism is not allowed\n");
3091 ret = count;
3092 }
3093 return ret;
3094}
3095
3096static DEVICE_ATTR(rts_ht_protection, S_IWUSR | S_IRUGO,
3097 show_rts_ht_protection, store_rts_ht_protection);
3098
Zhu Yib481de92007-09-25 17:54:57 -07003099
Zhu Yib481de92007-09-25 17:54:57 -07003100/*****************************************************************************
3101 *
3102 * driver setup and teardown
3103 *
3104 *****************************************************************************/
3105
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003106static void iwl_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003107{
Reinette Chatred21050c2009-02-13 11:51:18 -08003108 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07003109
3110 init_waitqueue_head(&priv->wait_command_queue);
3111
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003112 INIT_WORK(&priv->up, iwl_bg_up);
3113 INIT_WORK(&priv->restart, iwl_bg_restart);
3114 INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003115 INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08003116 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08003117 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
3118 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
Tomas Winkler2a421b92008-06-12 09:47:10 +08003119
Tomas Winkler2a421b92008-06-12 09:47:10 +08003120 iwl_setup_scan_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003121
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003122 if (priv->cfg->ops->lib->setup_deferred_work)
3123 priv->cfg->ops->lib->setup_deferred_work(priv);
3124
3125 init_timer(&priv->statistics_periodic);
3126 priv->statistics_periodic.data = (unsigned long)priv;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003127 priv->statistics_periodic.function = iwl_bg_statistics_periodic;
Zhu Yib481de92007-09-25 17:54:57 -07003128
Mohamed Abbasef850d72009-05-22 11:01:50 -07003129 if (!priv->cfg->use_isr_legacy)
3130 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
3131 iwl_irq_tasklet, (unsigned long)priv);
3132 else
3133 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
3134 iwl_irq_tasklet_legacy, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07003135}
3136
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003137static void iwl_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003138{
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003139 if (priv->cfg->ops->lib->cancel_deferred_work)
3140 priv->cfg->ops->lib->cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003141
Joonwoo Park3ae6a052007-11-29 10:43:16 +09003142 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07003143 cancel_delayed_work(&priv->scan_check);
3144 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07003145 cancel_work_sync(&priv->beacon_update);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003146 del_timer_sync(&priv->statistics_periodic);
Zhu Yib481de92007-09-25 17:54:57 -07003147}
3148
Reinette Chatre89f186a2009-10-30 14:36:11 -07003149static void iwl_init_hw_rates(struct iwl_priv *priv,
3150 struct ieee80211_rate *rates)
3151{
3152 int i;
3153
3154 for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
3155 rates[i].bitrate = iwl_rates[i].ieee * 5;
3156 rates[i].hw_value = i; /* Rate scaling will work on indexes */
3157 rates[i].hw_value_short = i;
3158 rates[i].flags = 0;
3159 if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
3160 /*
3161 * If CCK != 1M then set short preamble rate flag.
3162 */
3163 rates[i].flags |=
3164 (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
3165 0 : IEEE80211_RATE_SHORT_PREAMBLE;
3166 }
3167 }
3168}
3169
3170static int iwl_init_drv(struct iwl_priv *priv)
3171{
3172 int ret;
3173
3174 priv->ibss_beacon = NULL;
3175
3176 spin_lock_init(&priv->lock);
3177 spin_lock_init(&priv->sta_lock);
3178 spin_lock_init(&priv->hcmd_lock);
3179
3180 INIT_LIST_HEAD(&priv->free_frames);
3181
3182 mutex_init(&priv->mutex);
3183
3184 /* Clear the driver's (not device's) station table */
3185 iwl_clear_stations_table(priv);
3186
3187 priv->ieee_channels = NULL;
3188 priv->ieee_rates = NULL;
3189 priv->band = IEEE80211_BAND_2GHZ;
3190
3191 priv->iw_mode = NL80211_IFTYPE_STATION;
3192
3193 /* Choose which receivers/antennas to use */
3194 if (priv->cfg->ops->hcmd->set_rxon_chain)
3195 priv->cfg->ops->hcmd->set_rxon_chain(priv);
3196
3197 iwl_init_scan_params(priv);
3198
3199 iwl_reset_qos(priv);
3200
3201 priv->qos_data.qos_active = 0;
3202 priv->qos_data.qos_cap.val = 0;
3203
3204 priv->rates_mask = IWL_RATES_MASK;
3205 /* Set the tx_power_user_lmt to the lowest power level
3206 * this value will get overwritten by channel max power avg
3207 * from eeprom */
3208 priv->tx_power_user_lmt = IWL_TX_POWER_TARGET_POWER_MIN;
3209
3210 ret = iwl_init_channel_map(priv);
3211 if (ret) {
3212 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
3213 goto err;
3214 }
3215
3216 ret = iwlcore_init_geos(priv);
3217 if (ret) {
3218 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
3219 goto err_free_channel_map;
3220 }
3221 iwl_init_hw_rates(priv, priv->ieee_rates);
3222
3223 return 0;
3224
3225err_free_channel_map:
3226 iwl_free_channel_map(priv);
3227err:
3228 return ret;
3229}
3230
3231static void iwl_uninit_drv(struct iwl_priv *priv)
3232{
3233 iwl_calib_free_results(priv);
3234 iwlcore_free_geos(priv);
3235 iwl_free_channel_map(priv);
3236 kfree(priv->scan);
3237}
3238
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003239static struct attribute *iwl_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07003240 &dev_attr_flags.attr,
3241 &dev_attr_filter_flags.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003242 &dev_attr_statistics.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003243 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07003244 &dev_attr_tx_power.attr,
Wey-Yi Guy01abfbb2009-09-17 10:43:45 -07003245 &dev_attr_rts_ht_protection.attr,
Ester Kummer8cf769c2008-05-06 11:05:11 +08003246#ifdef CONFIG_IWLWIFI_DEBUG
3247 &dev_attr_debug_level.attr,
3248#endif
Zhu Yib481de92007-09-25 17:54:57 -07003249 NULL
3250};
3251
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003252static struct attribute_group iwl_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07003253 .name = NULL, /* put in device directory */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003254 .attrs = iwl_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07003255};
3256
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003257static struct ieee80211_ops iwl_hw_ops = {
3258 .tx = iwl_mac_tx,
3259 .start = iwl_mac_start,
3260 .stop = iwl_mac_stop,
3261 .add_interface = iwl_mac_add_interface,
3262 .remove_interface = iwl_mac_remove_interface,
3263 .config = iwl_mac_config,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003264 .configure_filter = iwl_configure_filter,
3265 .set_key = iwl_mac_set_key,
3266 .update_tkip_key = iwl_mac_update_tkip_key,
3267 .get_stats = iwl_mac_get_stats,
3268 .get_tx_stats = iwl_mac_get_tx_stats,
3269 .conf_tx = iwl_mac_conf_tx,
3270 .reset_tsf = iwl_mac_reset_tsf,
3271 .bss_info_changed = iwl_bss_info_changed,
3272 .ampdu_action = iwl_mac_ampdu_action,
Johannes Berg6ab10ff2009-11-13 11:56:37 -08003273 .hw_scan = iwl_mac_hw_scan,
3274 .sta_notify = iwl_mac_sta_notify,
Zhu Yib481de92007-09-25 17:54:57 -07003275};
3276
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003277static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07003278{
3279 int err = 0;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003280 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07003281 struct ieee80211_hw *hw;
Tomas Winkler82b9a122008-03-04 18:09:30 -08003282 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003283 unsigned long flags;
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003284 u16 pci_cmd;
Zhu Yib481de92007-09-25 17:54:57 -07003285
Assaf Krauss316c30d2008-03-14 10:38:46 -07003286 /************************
3287 * 1. Allocating HW data
3288 ************************/
3289
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003290 /* Disabling hardware scan means that mac80211 will perform scans
3291 * "the hard way", rather than using device's scan. */
Assaf Krauss1ea87392008-03-18 14:57:50 -07003292 if (cfg->mod_params->disable_hw_scan) {
Reinette Chatrea562a9d2009-07-17 09:30:24 -07003293 if (iwl_debug_level & IWL_DL_INFO)
Ester Kummerbf403db2008-05-05 10:22:40 +08003294 dev_printk(KERN_DEBUG, &(pdev->dev),
3295 "Disabling hw_scan\n");
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003296 iwl_hw_ops.hw_scan = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07003297 }
3298
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003299 hw = iwl_alloc_all(cfg, &iwl_hw_ops);
Assaf Krauss1d0a0822008-03-14 10:38:48 -07003300 if (!hw) {
Zhu Yib481de92007-09-25 17:54:57 -07003301 err = -ENOMEM;
3302 goto out;
3303 }
Assaf Krauss1d0a0822008-03-14 10:38:48 -07003304 priv = hw->priv;
3305 /* At this point both hw and priv are allocated. */
3306
Zhu Yib481de92007-09-25 17:54:57 -07003307 SET_IEEE80211_DEV(hw, &pdev->dev);
3308
Tomas Winklere1623442009-01-27 14:27:56 -08003309 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Tomas Winkler82b9a122008-03-04 18:09:30 -08003310 priv->cfg = cfg;
Zhu Yib481de92007-09-25 17:54:57 -07003311 priv->pci_dev = pdev;
Mohamed Abbas40cefda2009-05-22 11:01:52 -07003312 priv->inta_mask = CSR_INI_SET_MASK;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003313
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003314#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07003315 atomic_set(&priv->restrict_refcnt, 0);
3316#endif
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003317 if (iwl_alloc_traffic_mem(priv))
3318 IWL_ERR(priv, "Not enough memory to generate traffic log\n");
Zhu Yib481de92007-09-25 17:54:57 -07003319
Assaf Krauss316c30d2008-03-14 10:38:46 -07003320 /**************************
3321 * 2. Initializing PCI bus
3322 **************************/
3323 if (pci_enable_device(pdev)) {
3324 err = -ENODEV;
3325 goto out_ieee80211_free_hw;
3326 }
3327
3328 pci_set_master(pdev);
3329
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003330 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
Assaf Krauss316c30d2008-03-14 10:38:46 -07003331 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003332 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003333 if (err) {
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003334 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003335 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003336 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003337 /* both attempts failed: */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003338 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08003339 IWL_WARN(priv, "No suitable DMA available.\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07003340 goto out_pci_disable_device;
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003341 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07003342 }
3343
3344 err = pci_request_regions(pdev, DRV_NAME);
3345 if (err)
3346 goto out_pci_disable_device;
3347
3348 pci_set_drvdata(pdev, priv);
3349
Assaf Krauss316c30d2008-03-14 10:38:46 -07003350
3351 /***********************
3352 * 3. Read REV register
3353 ***********************/
3354 priv->hw_base = pci_iomap(pdev, 0, 0);
3355 if (!priv->hw_base) {
3356 err = -ENODEV;
3357 goto out_pci_release_regions;
3358 }
3359
Tomas Winklere1623442009-01-27 14:27:56 -08003360 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Assaf Krauss316c30d2008-03-14 10:38:46 -07003361 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08003362 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003363
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07003364 /* this spin lock will be used in apm_ops.init and EEPROM access
3365 * we should init now
3366 */
3367 spin_lock_init(&priv->reg_lock);
Tomas Winklerb661c812008-04-23 17:14:54 -07003368 iwl_hw_detect(priv);
Tomas Winkler978785a2008-12-19 10:37:31 +08003369 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s REV=0x%X\n",
Tomas Winklerb661c812008-04-23 17:14:54 -07003370 priv->cfg->name, priv->hw_rev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003371
Tomas Winklere7b63582008-09-03 11:26:49 +08003372 /* We disable the RETRY_TIMEOUT register (0x41) to keep
3373 * PCI Tx retries from interfering with C3 CPU state */
3374 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
3375
Mohamed Abbas086ed112009-05-22 11:01:54 -07003376 iwl_prepare_card_hw(priv);
3377 if (!priv->hw_ready) {
3378 IWL_WARN(priv, "Failed, HW not ready\n");
3379 goto out_iounmap;
3380 }
3381
Assaf Krauss316c30d2008-03-14 10:38:46 -07003382 /*****************
3383 * 4. Read EEPROM
3384 *****************/
Assaf Krauss316c30d2008-03-14 10:38:46 -07003385 /* Read the EEPROM */
3386 err = iwl_eeprom_init(priv);
3387 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003388 IWL_ERR(priv, "Unable to init EEPROM\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07003389 goto out_iounmap;
3390 }
Tomas Winkler8614f362008-04-23 17:14:55 -07003391 err = iwl_eeprom_check_version(priv);
3392 if (err)
Reinette Chatrec8f16132009-02-27 16:21:22 -08003393 goto out_free_eeprom;
Tomas Winkler8614f362008-04-23 17:14:55 -07003394
Ron Rindjunsky02883012008-05-15 13:53:53 +08003395 /* extract MAC Address */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003396 iwl_eeprom_get_mac(priv, priv->mac_addr);
Tomas Winklere1623442009-01-27 14:27:56 -08003397 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003398 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
3399
3400 /************************
3401 * 5. Setup HW constants
3402 ************************/
Ron Rindjunskyda154e302008-06-30 17:23:20 +08003403 if (iwl_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003404 IWL_ERR(priv, "failed to set hw parameters\n");
Tomas Winkler073d3f52008-04-21 15:41:52 -07003405 goto out_free_eeprom;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003406 }
3407
3408 /*******************
Tomas Winkler6ba87952008-05-15 13:54:17 +08003409 * 6. Setup priv
Assaf Krauss316c30d2008-03-14 10:38:46 -07003410 *******************/
Zhu Yib481de92007-09-25 17:54:57 -07003411
Tomas Winkler6ba87952008-05-15 13:54:17 +08003412 err = iwl_init_drv(priv);
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003413 if (err)
Ron Rindjunsky399f4902008-04-23 17:14:56 -07003414 goto out_free_eeprom;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003415 /* At this point both hw and priv are initialized. */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003416
Assaf Krauss316c30d2008-03-14 10:38:46 -07003417 /********************
Abhijeet Kolekar09f9bf72009-04-20 14:37:03 -07003418 * 7. Setup services
Assaf Krauss316c30d2008-03-14 10:38:46 -07003419 ********************/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003420 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003421 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003422 spin_unlock_irqrestore(&priv->lock, flags);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003423
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003424 pci_enable_msi(priv->pci_dev);
3425
Mohamed Abbasef850d72009-05-22 11:01:50 -07003426 iwl_alloc_isr_ict(priv);
3427 err = request_irq(priv->pci_dev->irq, priv->cfg->ops->lib->isr,
3428 IRQF_SHARED, DRV_NAME, priv);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003429 if (err) {
3430 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
3431 goto out_disable_msi;
3432 }
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003433 err = sysfs_create_group(&pdev->dev.kobj, &iwl_attribute_group);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003434 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003435 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Helmut Schaa795cc0a2009-02-12 18:51:03 +01003436 goto out_free_irq;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003437 }
3438
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003439 iwl_setup_deferred_work(priv);
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08003440 iwl_setup_rx_handlers(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003441
Tomas Winkler6ba87952008-05-15 13:54:17 +08003442 /**********************************
Abhijeet Kolekar09f9bf72009-04-20 14:37:03 -07003443 * 8. Setup and register mac80211
Tomas Winkler6ba87952008-05-15 13:54:17 +08003444 **********************************/
3445
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003446 /* enable interrupts if needed: hw bug w/a */
3447 pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd);
3448 if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
3449 pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
3450 pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
3451 }
3452
3453 iwl_enable_interrupts(priv);
3454
Tomas Winkler6ba87952008-05-15 13:54:17 +08003455 err = iwl_setup_mac(priv);
3456 if (err)
3457 goto out_remove_sysfs;
3458
3459 err = iwl_dbgfs_register(priv, DRV_NAME);
3460 if (err)
Abhijeet Kolekara75fbe82009-04-20 14:36:58 -07003461 IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
Tomas Winkler6ba87952008-05-15 13:54:17 +08003462
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003463 /* If platform's RF_KILL switch is NOT set to KILL */
3464 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3465 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3466 else
3467 set_bit(STATUS_RF_KILL_HW, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003468
Johannes Berga60e77e2009-06-04 18:26:06 +02003469 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
3470 test_bit(STATUS_RF_KILL_HW, &priv->status));
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003471
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08003472 iwl_power_initialize(priv);
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -07003473 iwl_tt_initialize(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003474 return 0;
3475
Assaf Krauss316c30d2008-03-14 10:38:46 -07003476 out_remove_sysfs:
Reinette Chatrec8f16132009-02-27 16:21:22 -08003477 destroy_workqueue(priv->workqueue);
3478 priv->workqueue = NULL;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003479 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
Helmut Schaa795cc0a2009-02-12 18:51:03 +01003480 out_free_irq:
3481 free_irq(priv->pci_dev->irq, priv);
Mohamed Abbasef850d72009-05-22 11:01:50 -07003482 iwl_free_isr_ict(priv);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003483 out_disable_msi:
3484 pci_disable_msi(priv->pci_dev);
Tomas Winkler6ba87952008-05-15 13:54:17 +08003485 iwl_uninit_drv(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07003486 out_free_eeprom:
3487 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003488 out_iounmap:
3489 pci_iounmap(pdev, priv->hw_base);
3490 out_pci_release_regions:
Assaf Krauss316c30d2008-03-14 10:38:46 -07003491 pci_set_drvdata(pdev, NULL);
Reinette Chatre623d5632009-03-03 11:37:04 -08003492 pci_release_regions(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07003493 out_pci_disable_device:
3494 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07003495 out_ieee80211_free_hw:
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003496 iwl_free_traffic_mem(priv);
Wey-Yi Guyd7c76f42009-10-09 13:20:17 -07003497 ieee80211_free_hw(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07003498 out:
3499 return err;
3500}
3501
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003502static void __devexit iwl_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07003503{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003504 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003505 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07003506
3507 if (!priv)
3508 return;
3509
Tomas Winklere1623442009-01-27 14:27:56 -08003510 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07003511
Emmanuel Grumbach67249622008-05-29 16:35:26 +08003512 iwl_dbgfs_unregister(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003513 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
Emmanuel Grumbach67249622008-05-29 16:35:26 +08003514
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003515 /* ieee80211_unregister_hw call wil cause iwl_mac_stop to
3516 * to be called and iwl_down since we are removing the device
Gregory Greenman0b124c32008-09-03 11:18:50 +08003517 * we need to set STATUS_EXIT_PENDING bit.
3518 */
3519 set_bit(STATUS_EXIT_PENDING, &priv->status);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07003520 if (priv->mac80211_registered) {
3521 ieee80211_unregister_hw(priv->hw);
3522 priv->mac80211_registered = 0;
Gregory Greenman0b124c32008-09-03 11:18:50 +08003523 } else {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003524 iwl_down(priv);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07003525 }
3526
Ben Cahillc166b252009-10-23 13:42:35 -07003527 /*
3528 * Make sure device is reset to low power before unloading driver.
3529 * This may be redundant with iwl_down(), but there are paths to
3530 * run iwl_down() without calling apm_ops.stop(), and there are
3531 * paths to avoid running iwl_down() at all before leaving driver.
3532 * This (inexpensive) call *makes sure* device is reset.
3533 */
3534 priv->cfg->ops->lib->apm_ops.stop(priv);
3535
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -07003536 iwl_tt_exit(priv);
3537
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003538 /* make sure we flush any pending irq or
3539 * tasklet for the driver
3540 */
3541 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003542 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003543 spin_unlock_irqrestore(&priv->lock, flags);
3544
3545 iwl_synchronize_irq(priv);
3546
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003547 iwl_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003548
3549 if (priv->rxq.bd)
Tomas Winklera55360e2008-05-05 10:22:28 +08003550 iwl_rx_queue_free(priv, &priv->rxq);
Ron Rindjunsky1053d352008-05-05 10:22:43 +08003551 iwl_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003552
Tomas Winklerc587de02009-06-03 11:44:07 -07003553 iwl_clear_stations_table(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07003554 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003555
Zhu Yib481de92007-09-25 17:54:57 -07003556
Mohamed Abbas948c1712007-10-25 17:15:45 +08003557 /*netif_stop_queue(dev); */
3558 flush_workqueue(priv->workqueue);
3559
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003560 /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07003561 * priv->workqueue... so we can't take down the workqueue
3562 * until now... */
3563 destroy_workqueue(priv->workqueue);
3564 priv->workqueue = NULL;
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003565 iwl_free_traffic_mem(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003566
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003567 free_irq(priv->pci_dev->irq, priv);
3568 pci_disable_msi(priv->pci_dev);
Zhu Yib481de92007-09-25 17:54:57 -07003569 pci_iounmap(pdev, priv->hw_base);
3570 pci_release_regions(pdev);
3571 pci_disable_device(pdev);
3572 pci_set_drvdata(pdev, NULL);
3573
Tomas Winkler6ba87952008-05-15 13:54:17 +08003574 iwl_uninit_drv(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003575
Mohamed Abbasef850d72009-05-22 11:01:50 -07003576 iwl_free_isr_ict(priv);
3577
Zhu Yib481de92007-09-25 17:54:57 -07003578 if (priv->ibss_beacon)
3579 dev_kfree_skb(priv->ibss_beacon);
3580
3581 ieee80211_free_hw(priv->hw);
3582}
3583
Zhu Yib481de92007-09-25 17:54:57 -07003584
3585/*****************************************************************************
3586 *
3587 * driver and module entry point
3588 *
3589 *****************************************************************************/
3590
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003591/* Hardware specific file defines the PCI IDs table for that hardware module */
3592static struct pci_device_id iwl_hw_card_ids[] = {
Tomas Winkler4fc22b22008-07-21 18:54:42 +03003593#ifdef CONFIG_IWL4965
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003594 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
3595 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
Tomas Winkler4fc22b22008-07-21 18:54:42 +03003596#endif /* CONFIG_IWL4965 */
Tomas Winkler5a6a2562008-04-24 11:55:23 -07003597#ifdef CONFIG_IWL5000
Wey-Yi Guyac592572009-11-20 12:05:03 -08003598/* 5100 Series WiFi */
3599 {IWL_PCI_DEVICE(0x4232, 0x1201, iwl5100_agn_cfg)}, /* Mini Card */
3600 {IWL_PCI_DEVICE(0x4232, 0x1301, iwl5100_agn_cfg)}, /* Half Mini Card */
3601 {IWL_PCI_DEVICE(0x4232, 0x1204, iwl5100_agn_cfg)}, /* Mini Card */
3602 {IWL_PCI_DEVICE(0x4232, 0x1304, iwl5100_agn_cfg)}, /* Half Mini Card */
3603 {IWL_PCI_DEVICE(0x4232, 0x1205, iwl5100_bgn_cfg)}, /* Mini Card */
3604 {IWL_PCI_DEVICE(0x4232, 0x1305, iwl5100_bgn_cfg)}, /* Half Mini Card */
3605 {IWL_PCI_DEVICE(0x4232, 0x1206, iwl5100_abg_cfg)}, /* Mini Card */
3606 {IWL_PCI_DEVICE(0x4232, 0x1306, iwl5100_abg_cfg)}, /* Half Mini Card */
3607 {IWL_PCI_DEVICE(0x4232, 0x1221, iwl5100_agn_cfg)}, /* Mini Card */
3608 {IWL_PCI_DEVICE(0x4232, 0x1321, iwl5100_agn_cfg)}, /* Half Mini Card */
3609 {IWL_PCI_DEVICE(0x4232, 0x1224, iwl5100_agn_cfg)}, /* Mini Card */
3610 {IWL_PCI_DEVICE(0x4232, 0x1324, iwl5100_agn_cfg)}, /* Half Mini Card */
3611 {IWL_PCI_DEVICE(0x4232, 0x1225, iwl5100_bgn_cfg)}, /* Mini Card */
3612 {IWL_PCI_DEVICE(0x4232, 0x1325, iwl5100_bgn_cfg)}, /* Half Mini Card */
3613 {IWL_PCI_DEVICE(0x4232, 0x1226, iwl5100_abg_cfg)}, /* Mini Card */
3614 {IWL_PCI_DEVICE(0x4232, 0x1326, iwl5100_abg_cfg)}, /* Half Mini Card */
3615 {IWL_PCI_DEVICE(0x4237, 0x1211, iwl5100_agn_cfg)}, /* Mini Card */
3616 {IWL_PCI_DEVICE(0x4237, 0x1311, iwl5100_agn_cfg)}, /* Half Mini Card */
3617 {IWL_PCI_DEVICE(0x4237, 0x1214, iwl5100_agn_cfg)}, /* Mini Card */
3618 {IWL_PCI_DEVICE(0x4237, 0x1314, iwl5100_agn_cfg)}, /* Half Mini Card */
3619 {IWL_PCI_DEVICE(0x4237, 0x1215, iwl5100_bgn_cfg)}, /* Mini Card */
3620 {IWL_PCI_DEVICE(0x4237, 0x1315, iwl5100_bgn_cfg)}, /* Half Mini Card */
3621 {IWL_PCI_DEVICE(0x4237, 0x1216, iwl5100_abg_cfg)}, /* Mini Card */
3622 {IWL_PCI_DEVICE(0x4237, 0x1316, iwl5100_abg_cfg)}, /* Half Mini Card */
3623
3624/* 5300 Series WiFi */
3625 {IWL_PCI_DEVICE(0x4235, 0x1021, iwl5300_agn_cfg)}, /* Mini Card */
3626 {IWL_PCI_DEVICE(0x4235, 0x1121, iwl5300_agn_cfg)}, /* Half Mini Card */
3627 {IWL_PCI_DEVICE(0x4235, 0x1024, iwl5300_agn_cfg)}, /* Mini Card */
3628 {IWL_PCI_DEVICE(0x4235, 0x1124, iwl5300_agn_cfg)}, /* Half Mini Card */
3629 {IWL_PCI_DEVICE(0x4235, 0x1001, iwl5300_agn_cfg)}, /* Mini Card */
3630 {IWL_PCI_DEVICE(0x4235, 0x1101, iwl5300_agn_cfg)}, /* Half Mini Card */
3631 {IWL_PCI_DEVICE(0x4235, 0x1004, iwl5300_agn_cfg)}, /* Mini Card */
3632 {IWL_PCI_DEVICE(0x4235, 0x1104, iwl5300_agn_cfg)}, /* Half Mini Card */
3633 {IWL_PCI_DEVICE(0x4236, 0x1011, iwl5300_agn_cfg)}, /* Mini Card */
3634 {IWL_PCI_DEVICE(0x4236, 0x1111, iwl5300_agn_cfg)}, /* Half Mini Card */
3635 {IWL_PCI_DEVICE(0x4236, 0x1014, iwl5300_agn_cfg)}, /* Mini Card */
3636 {IWL_PCI_DEVICE(0x4236, 0x1114, iwl5300_agn_cfg)}, /* Half Mini Card */
3637
3638/* 5350 Series WiFi/WiMax */
3639 {IWL_PCI_DEVICE(0x423A, 0x1001, iwl5350_agn_cfg)}, /* Mini Card */
3640 {IWL_PCI_DEVICE(0x423A, 0x1021, iwl5350_agn_cfg)}, /* Mini Card */
3641 {IWL_PCI_DEVICE(0x423B, 0x1011, iwl5350_agn_cfg)}, /* Mini Card */
3642
3643/* 5150 Series Wifi/WiMax */
3644 {IWL_PCI_DEVICE(0x423C, 0x1201, iwl5150_agn_cfg)}, /* Mini Card */
3645 {IWL_PCI_DEVICE(0x423C, 0x1301, iwl5150_agn_cfg)}, /* Half Mini Card */
3646 {IWL_PCI_DEVICE(0x423C, 0x1206, iwl5150_abg_cfg)}, /* Mini Card */
3647 {IWL_PCI_DEVICE(0x423C, 0x1306, iwl5150_abg_cfg)}, /* Half Mini Card */
3648 {IWL_PCI_DEVICE(0x423C, 0x1221, iwl5150_agn_cfg)}, /* Mini Card */
3649 {IWL_PCI_DEVICE(0x423C, 0x1321, iwl5150_agn_cfg)}, /* Half Mini Card */
3650
3651 {IWL_PCI_DEVICE(0x423D, 0x1211, iwl5150_agn_cfg)}, /* Mini Card */
3652 {IWL_PCI_DEVICE(0x423D, 0x1311, iwl5150_agn_cfg)}, /* Half Mini Card */
3653 {IWL_PCI_DEVICE(0x423D, 0x1216, iwl5150_abg_cfg)}, /* Mini Card */
3654 {IWL_PCI_DEVICE(0x423D, 0x1316, iwl5150_abg_cfg)}, /* Half Mini Card */
Wey-Yi Guy5953a622009-09-17 10:43:53 -07003655
3656/* 6x00 Series */
Wey-Yi Guy5953a622009-09-17 10:43:53 -07003657 {IWL_PCI_DEVICE(0x422B, 0x1101, iwl6000_3agn_cfg)},
3658 {IWL_PCI_DEVICE(0x422B, 0x1121, iwl6000_3agn_cfg)},
3659 {IWL_PCI_DEVICE(0x422C, 0x1301, iwl6000i_2agn_cfg)},
3660 {IWL_PCI_DEVICE(0x422C, 0x1306, iwl6000i_2abg_cfg)},
3661 {IWL_PCI_DEVICE(0x422C, 0x1307, iwl6000i_2bg_cfg)},
3662 {IWL_PCI_DEVICE(0x422C, 0x1321, iwl6000i_2agn_cfg)},
3663 {IWL_PCI_DEVICE(0x422C, 0x1326, iwl6000i_2abg_cfg)},
3664 {IWL_PCI_DEVICE(0x4238, 0x1111, iwl6000_3agn_cfg)},
3665 {IWL_PCI_DEVICE(0x4239, 0x1311, iwl6000i_2agn_cfg)},
3666 {IWL_PCI_DEVICE(0x4239, 0x1316, iwl6000i_2abg_cfg)},
3667
3668/* 6x50 WiFi/WiMax Series */
Wey-Yi Guy5953a622009-09-17 10:43:53 -07003669 {IWL_PCI_DEVICE(0x0087, 0x1301, iwl6050_2agn_cfg)},
3670 {IWL_PCI_DEVICE(0x0087, 0x1306, iwl6050_2abg_cfg)},
3671 {IWL_PCI_DEVICE(0x0087, 0x1321, iwl6050_2agn_cfg)},
3672 {IWL_PCI_DEVICE(0x0087, 0x1326, iwl6050_2abg_cfg)},
Wey-Yi Guy5953a622009-09-17 10:43:53 -07003673 {IWL_PCI_DEVICE(0x0089, 0x1311, iwl6050_2agn_cfg)},
3674 {IWL_PCI_DEVICE(0x0089, 0x1316, iwl6050_2abg_cfg)},
3675
Jay Sternberg77dcb6a2009-03-06 13:52:55 -08003676/* 1000 Series WiFi */
Wey-Yi Guy4bd0914f2009-09-17 10:43:52 -07003677 {IWL_PCI_DEVICE(0x0083, 0x1205, iwl1000_bgn_cfg)},
3678 {IWL_PCI_DEVICE(0x0083, 0x1305, iwl1000_bgn_cfg)},
3679 {IWL_PCI_DEVICE(0x0083, 0x1225, iwl1000_bgn_cfg)},
3680 {IWL_PCI_DEVICE(0x0083, 0x1325, iwl1000_bgn_cfg)},
3681 {IWL_PCI_DEVICE(0x0084, 0x1215, iwl1000_bgn_cfg)},
3682 {IWL_PCI_DEVICE(0x0084, 0x1315, iwl1000_bgn_cfg)},
3683 {IWL_PCI_DEVICE(0x0083, 0x1206, iwl1000_bg_cfg)},
3684 {IWL_PCI_DEVICE(0x0083, 0x1306, iwl1000_bg_cfg)},
3685 {IWL_PCI_DEVICE(0x0083, 0x1226, iwl1000_bg_cfg)},
3686 {IWL_PCI_DEVICE(0x0083, 0x1326, iwl1000_bg_cfg)},
3687 {IWL_PCI_DEVICE(0x0084, 0x1216, iwl1000_bg_cfg)},
3688 {IWL_PCI_DEVICE(0x0084, 0x1316, iwl1000_bg_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07003689#endif /* CONFIG_IWL5000 */
Tomas Winkler7100e922008-12-01 16:32:18 -08003690
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003691 {0}
3692};
3693MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
3694
3695static struct pci_driver iwl_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07003696 .name = DRV_NAME,
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003697 .id_table = iwl_hw_card_ids,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003698 .probe = iwl_pci_probe,
3699 .remove = __devexit_p(iwl_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07003700#ifdef CONFIG_PM
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003701 .suspend = iwl_pci_suspend,
3702 .resume = iwl_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07003703#endif
3704};
3705
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003706static int __init iwl_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07003707{
3708
3709 int ret;
3710 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
3711 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003712
Tomas Winklere227cea2008-07-18 13:53:05 +08003713 ret = iwlagn_rate_control_register();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003714 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08003715 printk(KERN_ERR DRV_NAME
3716 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003717 return ret;
3718 }
3719
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003720 ret = pci_register_driver(&iwl_driver);
Zhu Yib481de92007-09-25 17:54:57 -07003721 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08003722 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003723 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07003724 }
Zhu Yib481de92007-09-25 17:54:57 -07003725
3726 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003727
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003728error_register:
Tomas Winklere227cea2008-07-18 13:53:05 +08003729 iwlagn_rate_control_unregister();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003730 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003731}
3732
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003733static void __exit iwl_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07003734{
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003735 pci_unregister_driver(&iwl_driver);
Tomas Winklere227cea2008-07-18 13:53:05 +08003736 iwlagn_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07003737}
3738
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003739module_exit(iwl_exit);
3740module_init(iwl_init);
Reinette Chatrea562a9d2009-07-17 09:30:24 -07003741
3742#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07003743module_param_named(debug50, iwl_debug_level, uint, S_IRUGO);
Reinette Chatrea562a9d2009-07-17 09:30:24 -07003744MODULE_PARM_DESC(debug50, "50XX debug output mask (deprecated)");
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07003745module_param_named(debug, iwl_debug_level, uint, S_IRUGO | S_IWUSR);
Reinette Chatrea562a9d2009-07-17 09:30:24 -07003746MODULE_PARM_DESC(debug, "debug output mask");
3747#endif
3748