blob: 807d697f62396b171a211f37547b5498542ecf7d [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Reinette Chatre1f447802010-01-15 13:43:41 -08003 * Copyright(c) 2003 - 2010 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
Joe Perchesc96c31e2010-07-26 14:39:58 -070030#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31
Zhu Yib481de92007-09-25 17:54:57 -070032#include <linux/kernel.h>
33#include <linux/module.h>
Zhu Yib481de92007-09-25 17:54:57 -070034#include <linux/init.h>
35#include <linux/pci.h>
John W. Linville1a7123c2010-08-05 14:39:31 -040036#include <linux/pci-aspm.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090037#include <linux/slab.h>
Zhu Yib481de92007-09-25 17:54:57 -070038#include <linux/dma-mapping.h>
39#include <linux/delay.h>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040040#include <linux/sched.h>
Zhu Yib481de92007-09-25 17:54:57 -070041#include <linux/skbuff.h>
42#include <linux/netdevice.h>
43#include <linux/wireless.h>
44#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070045#include <linux/etherdevice.h>
46#include <linux/if_arp.h>
47
Zhu Yib481de92007-09-25 17:54:57 -070048#include <net/mac80211.h>
49
50#include <asm/div64.h>
51
Samuel Ortiza3139c52008-12-19 10:37:09 +080052#define DRV_NAME "iwlagn"
53
Assaf Krauss6bc913b2008-03-11 16:17:18 -070054#include "iwl-eeprom.h"
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070055#include "iwl-dev.h"
Tomas Winklerfee12472008-04-03 16:05:21 -070056#include "iwl-core.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070057#include "iwl-io.h"
Zhu Yib481de92007-09-25 17:54:57 -070058#include "iwl-helpers.h"
Emmanuel Grumbach6974e362008-04-14 21:16:06 -070059#include "iwl-sta.h"
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -070060#include "iwl-calib.h"
Johannes Berga1175122010-01-21 06:21:10 -080061#include "iwl-agn.h"
Zhu Yib481de92007-09-25 17:54:57 -070062
Christoph Hellwig416e1432007-10-25 17:15:49 +080063
Zhu Yib481de92007-09-25 17:54:57 -070064/******************************************************************************
65 *
66 * module boiler plate
67 *
68 ******************************************************************************/
69
Zhu Yib481de92007-09-25 17:54:57 -070070/*
71 * module name, copyright, version, etc.
Zhu Yib481de92007-09-25 17:54:57 -070072 */
Tomas Winklerd783b062008-07-18 13:53:02 +080073#define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
Zhu Yib481de92007-09-25 17:54:57 -070074
Tomas Winkler0a6857e2008-03-12 16:58:49 -070075#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070076#define VD "d"
77#else
78#define VD
79#endif
80
Reinette Chatre81963d62010-01-22 14:22:57 -080081#define DRV_VERSION IWLWIFI_VERSION VD
Zhu Yib481de92007-09-25 17:54:57 -070082
Zhu Yib481de92007-09-25 17:54:57 -070083
84MODULE_DESCRIPTION(DRV_DESCRIPTION);
85MODULE_VERSION(DRV_VERSION);
Tomas Winklera7b75202008-12-11 10:33:41 -080086MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
Zhu Yib481de92007-09-25 17:54:57 -070087MODULE_LICENSE("GPL");
Tomas Winkler4fc22b22008-07-21 18:54:42 +030088MODULE_ALIAS("iwl4965");
Zhu Yib481de92007-09-25 17:54:57 -070089
Wey-Yi Guybee008b2010-08-23 07:57:04 -070090static int iwlagn_ant_coupling;
91
Zhu Yib481de92007-09-25 17:54:57 -070092/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -070093 * iwl_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -070094 *
Ian Schram01ebd062007-10-25 17:15:22 +080095 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -070096 * the active_rxon structure is updated with the new data. This
97 * function correctly transitions out of the RXON_ASSOC_MSK state if
98 * a HW tune is required based on the RXON structure changes.
99 */
Abhijeet Kolekare0158e62009-04-08 11:26:37 -0700100int iwl_commit_rxon(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700101{
102 /* cast away the const for active_rxon in this function */
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800103 struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800104 int ret;
105 bool new_assoc =
106 !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK);
Zhu Yib481de92007-09-25 17:54:57 -0700107
Tomas Winklerfee12472008-04-03 16:05:21 -0700108 if (!iwl_is_alive(priv))
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800109 return -EBUSY;
Zhu Yib481de92007-09-25 17:54:57 -0700110
111 /* always get timestamp with Rx frame */
112 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
113
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800114 ret = iwl_check_rxon_cmd(priv);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800115 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800116 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700117 return -EINVAL;
118 }
119
Wey-Yi Guy0924e5192009-11-06 14:52:54 -0800120 /*
121 * receive commit_rxon request
122 * abort any previous channel switch if still in process
123 */
124 if (priv->switch_rxon.switch_in_progress &&
125 (priv->switch_rxon.channel != priv->staging_rxon.channel)) {
126 IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
127 le16_to_cpu(priv->switch_rxon.channel));
Wey-Yi Guy79d07322010-05-06 08:54:11 -0700128 iwl_chswitch_done(priv, false);
Wey-Yi Guy0924e5192009-11-06 14:52:54 -0800129 }
130
Zhu Yib481de92007-09-25 17:54:57 -0700131 /* If we don't need to send a full RXON, we can use
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700132 * iwl_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -0700133 * and other flags for the current radio configuration. */
Mohamed Abbas54559702008-09-03 11:18:44 +0800134 if (!iwl_full_rxon_required(priv)) {
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800135 ret = iwl_send_rxon_assoc(priv);
136 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800137 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800138 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700139 }
140
141 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Wey-Yi Guya6435652009-11-06 14:52:46 -0800142 iwl_print_rx_config_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700143 return 0;
144 }
145
Zhu Yib481de92007-09-25 17:54:57 -0700146 /* If we are currently associated and the new config requires
147 * an RXON_ASSOC and the new config wants the associated mask enabled,
148 * we must clear the associated from the active configuration
149 * before we apply the new config */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800150 if (iwl_is_associated(priv) && new_assoc) {
Tomas Winklere1623442009-01-27 14:27:56 -0800151 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
Zhu Yib481de92007-09-25 17:54:57 -0700152 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
153
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800154 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800155 sizeof(struct iwl_rxon_cmd),
Zhu Yib481de92007-09-25 17:54:57 -0700156 &priv->active_rxon);
157
158 /* If the mask clearing failed then we set
159 * active_rxon back to what it was previously */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800160 if (ret) {
Zhu Yib481de92007-09-25 17:54:57 -0700161 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
Winkler, Tomas15b16872008-12-19 10:37:33 +0800162 IWL_ERR(priv, "Error clearing ASSOC_MSK (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800163 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700164 }
Johannes Berg2c810cc2010-04-29 00:53:29 -0700165 iwl_clear_ucode_stations(priv);
Reinette Chatre7e246192010-02-18 22:58:32 -0800166 iwl_restore_stations(priv);
Johannes Berg335348b2010-03-30 10:11:46 -0700167 ret = iwl_restore_default_wep_keys(priv);
168 if (ret) {
169 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
170 return ret;
171 }
Zhu Yib481de92007-09-25 17:54:57 -0700172 }
173
Tomas Winklere1623442009-01-27 14:27:56 -0800174 IWL_DEBUG_INFO(priv, "Sending RXON\n"
Zhu Yib481de92007-09-25 17:54:57 -0700175 "* with%s RXON_FILTER_ASSOC_MSK\n"
176 "* channel = %d\n"
Johannes Berge1749612008-10-27 15:59:26 -0700177 "* bssid = %pM\n",
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800178 (new_assoc ? "" : "out"),
Zhu Yib481de92007-09-25 17:54:57 -0700179 le16_to_cpu(priv->staging_rxon.channel),
Johannes Berge1749612008-10-27 15:59:26 -0700180 priv->staging_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -0700181
Tomas Winkler90e8e422009-06-19 13:52:42 -0700182 iwl_set_rxon_hwcrypto(priv, !priv->cfg->mod_params->sw_crypto);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800183
184 /* Apply the new configuration
Reinette Chatre7e246192010-02-18 22:58:32 -0800185 * RXON unassoc clears the station table in uCode so restoration of
186 * stations is needed after it (the RXON command) completes
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800187 */
188 if (!new_assoc) {
189 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800190 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800191 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800192 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800193 return ret;
194 }
Frans Pop91dd6c22010-03-24 14:19:58 -0700195 IWL_DEBUG_INFO(priv, "Return from !new_assoc RXON.\n");
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800196 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Johannes Berg2c810cc2010-04-29 00:53:29 -0700197 iwl_clear_ucode_stations(priv);
Reinette Chatre7e246192010-02-18 22:58:32 -0800198 iwl_restore_stations(priv);
Johannes Berg335348b2010-03-30 10:11:46 -0700199 ret = iwl_restore_default_wep_keys(priv);
200 if (ret) {
201 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
202 return ret;
203 }
Zhu Yib481de92007-09-25 17:54:57 -0700204 }
205
Johannes Berg19cc1082009-05-08 13:44:36 -0700206 priv->start_calib = 0;
Tomas Winkler91851592008-06-30 17:23:14 +0800207 if (new_assoc) {
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800208 /* Apply the new configuration
209 * RXON assoc doesn't clear the station table in uCode,
210 */
211 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
212 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
213 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800214 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800215 return ret;
216 }
217 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700218 }
Wey-Yi Guya6435652009-11-06 14:52:46 -0800219 iwl_print_rx_config_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700220
Zhu Yi36da7d72008-07-11 11:53:40 +0800221 iwl_init_sensitivity(priv);
222
223 /* If we issue a new RXON command which required a tune then we must
224 * send a new TXPOWER command or we won't be able to Tx any frames */
225 ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
226 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800227 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
Zhu Yi36da7d72008-07-11 11:53:40 +0800228 return ret;
229 }
230
Zhu Yib481de92007-09-25 17:54:57 -0700231 return 0;
232}
233
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700234void iwl_update_chain_flags(struct iwl_priv *priv)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700235{
236
Abhijeet Kolekar45823532009-04-08 11:26:44 -0700237 if (priv->cfg->ops->hcmd->set_rxon_chain)
238 priv->cfg->ops->hcmd->set_rxon_chain(priv);
Abhijeet Kolekare0158e62009-04-08 11:26:37 -0700239 iwlcore_commit_rxon(priv);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700240}
241
Tomas Winklerfcab4232008-05-15 13:54:01 +0800242static void iwl_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700243{
244 struct list_head *element;
245
Tomas Winklere1623442009-01-27 14:27:56 -0800246 IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
Zhu Yib481de92007-09-25 17:54:57 -0700247 priv->frames_count);
248
249 while (!list_empty(&priv->free_frames)) {
250 element = priv->free_frames.next;
251 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800252 kfree(list_entry(element, struct iwl_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700253 priv->frames_count--;
254 }
255
256 if (priv->frames_count) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800257 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
Zhu Yib481de92007-09-25 17:54:57 -0700258 priv->frames_count);
259 priv->frames_count = 0;
260 }
261}
262
Tomas Winklerfcab4232008-05-15 13:54:01 +0800263static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700264{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800265 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700266 struct list_head *element;
267 if (list_empty(&priv->free_frames)) {
268 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
269 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800270 IWL_ERR(priv, "Could not allocate frame!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700271 return NULL;
272 }
273
274 priv->frames_count++;
275 return frame;
276 }
277
278 element = priv->free_frames.next;
279 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800280 return list_entry(element, struct iwl_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700281}
282
Tomas Winklerfcab4232008-05-15 13:54:01 +0800283static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700284{
285 memset(frame, 0, sizeof(*frame));
286 list_add(&frame->list, &priv->free_frames);
287}
288
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800289static u32 iwl_fill_beacon_frame(struct iwl_priv *priv,
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800290 struct ieee80211_hdr *hdr,
Rami Rosen73ec1cc2008-12-16 09:37:07 +0200291 int left)
Zhu Yib481de92007-09-25 17:54:57 -0700292{
Johannes Berg6abbe552010-07-15 05:59:07 -0700293 if (!priv->ibss_beacon)
Zhu Yib481de92007-09-25 17:54:57 -0700294 return 0;
295
296 if (priv->ibss_beacon->len > left)
297 return 0;
298
299 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
300
301 return priv->ibss_beacon->len;
302}
303
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800304/* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
305static void iwl_set_beacon_tim(struct iwl_priv *priv,
306 struct iwl_tx_beacon_cmd *tx_beacon_cmd,
307 u8 *beacon, u32 frame_size)
308{
309 u16 tim_idx;
310 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
311
312 /*
313 * The index is relative to frame start but we start looking at the
314 * variable-length part of the beacon.
315 */
316 tim_idx = mgmt->u.beacon.variable - beacon;
317
318 /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
319 while ((tim_idx < (frame_size - 2)) &&
320 (beacon[tim_idx] != WLAN_EID_TIM))
321 tim_idx += beacon[tim_idx+1] + 2;
322
323 /* If TIM field was found, set variables */
324 if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
325 tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
326 tx_beacon_cmd->tim_size = beacon[tim_idx+1];
327 } else
328 IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
329}
330
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700331static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800332 struct iwl_frame *frame)
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800333{
334 struct iwl_tx_beacon_cmd *tx_beacon_cmd;
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800335 u32 frame_size;
336 u32 rate_flags;
337 u32 rate;
338 /*
339 * We have to set up the TX command, the TX Beacon command, and the
340 * beacon contents.
341 */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800342
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800343 /* Initialize memory */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800344 tx_beacon_cmd = &frame->u.beacon;
345 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
346
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800347 /* Set up TX beacon contents */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800348 frame_size = iwl_fill_beacon_frame(priv, tx_beacon_cmd->frame,
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800349 sizeof(frame->u) - sizeof(*tx_beacon_cmd));
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800350 if (WARN_ON_ONCE(frame_size > MAX_MPDU_SIZE))
351 return 0;
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800352
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800353 /* Set up TX command fields */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800354 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800355 tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
356 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800357 tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800358 TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
359
360 /* Set up TX beacon command fields */
361 iwl_set_beacon_tim(priv, tx_beacon_cmd, (u8 *)tx_beacon_cmd->frame,
362 frame_size);
363
364 /* Set up packet rate and flags */
365 rate = iwl_rate_get_lowest_plcp(priv);
Johannes Berg0e1654f2010-05-18 02:48:36 -0700366 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
367 priv->hw_params.valid_tx_ant);
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800368 rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
369 if ((rate >= IWL_FIRST_CCK_RATE) && (rate <= IWL_LAST_CCK_RATE))
370 rate_flags |= RATE_MCS_CCK_MSK;
371 tx_beacon_cmd->tx.rate_n_flags = iwl_hw_set_rate_n_flags(rate,
372 rate_flags);
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800373
374 return sizeof(*tx_beacon_cmd) + frame_size;
375}
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700376static int iwl_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700377{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800378 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700379 unsigned int frame_size;
380 int rc;
Zhu Yib481de92007-09-25 17:54:57 -0700381
Tomas Winklerfcab4232008-05-15 13:54:01 +0800382 frame = iwl_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700383 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800384 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
Zhu Yib481de92007-09-25 17:54:57 -0700385 "command.\n");
386 return -ENOMEM;
387 }
388
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800389 frame_size = iwl_hw_get_beacon_cmd(priv, frame);
390 if (!frame_size) {
391 IWL_ERR(priv, "Error configuring the beacon command\n");
392 iwl_free_frame(priv, frame);
393 return -EINVAL;
394 }
Zhu Yib481de92007-09-25 17:54:57 -0700395
Tomas Winkler857485c2008-03-21 13:53:44 -0700396 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700397 &frame->u.cmd[0]);
398
Tomas Winklerfcab4232008-05-15 13:54:01 +0800399 iwl_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700400
401 return rc;
402}
403
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800404static inline dma_addr_t iwl_tfd_tb_get_addr(struct iwl_tfd *tfd, u8 idx)
405{
406 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
407
408 dma_addr_t addr = get_unaligned_le32(&tb->lo);
409 if (sizeof(dma_addr_t) > sizeof(u32))
410 addr |=
411 ((dma_addr_t)(le16_to_cpu(tb->hi_n_len) & 0xF) << 16) << 16;
412
413 return addr;
414}
415
416static inline u16 iwl_tfd_tb_get_len(struct iwl_tfd *tfd, u8 idx)
417{
418 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
419
420 return le16_to_cpu(tb->hi_n_len) >> 4;
421}
422
423static inline void iwl_tfd_set_tb(struct iwl_tfd *tfd, u8 idx,
424 dma_addr_t addr, u16 len)
425{
426 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
427 u16 hi_n_len = len << 4;
428
429 put_unaligned_le32(addr, &tb->lo);
430 if (sizeof(dma_addr_t) > sizeof(u32))
431 hi_n_len |= ((addr >> 16) >> 16) & 0xF;
432
433 tb->hi_n_len = cpu_to_le16(hi_n_len);
434
435 tfd->num_tbs = idx + 1;
436}
437
438static inline u8 iwl_tfd_get_num_tbs(struct iwl_tfd *tfd)
439{
440 return tfd->num_tbs & 0x1f;
441}
442
443/**
444 * iwl_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
445 * @priv - driver private data
446 * @txq - tx queue
447 *
448 * Does NOT advance any TFD circular buffer read/write indexes
449 * Does NOT free the TFD itself (which is within circular buffer)
450 */
451void iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq)
452{
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800453 struct iwl_tfd *tfd_tmp = (struct iwl_tfd *)txq->tfds;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800454 struct iwl_tfd *tfd;
455 struct pci_dev *dev = priv->pci_dev;
456 int index = txq->q.read_ptr;
457 int i;
458 int num_tbs;
459
460 tfd = &tfd_tmp[index];
461
462 /* Sanity check on number of chunks */
463 num_tbs = iwl_tfd_get_num_tbs(tfd);
464
465 if (num_tbs >= IWL_NUM_OF_TBS) {
466 IWL_ERR(priv, "Too many chunks: %i\n", num_tbs);
467 /* @todo issue fatal error, it is quite serious situation */
468 return;
469 }
470
471 /* Unmap tx_cmd */
472 if (num_tbs)
473 pci_unmap_single(dev,
FUJITA Tomonori2e724442010-06-03 14:19:20 +0900474 dma_unmap_addr(&txq->meta[index], mapping),
475 dma_unmap_len(&txq->meta[index], len),
Fenghua Yu96891ce2009-02-18 15:54:33 -0800476 PCI_DMA_BIDIRECTIONAL);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800477
478 /* Unmap chunks, if any. */
Johannes Bergff0d91c2010-05-17 02:37:34 -0700479 for (i = 1; i < num_tbs; i++)
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800480 pci_unmap_single(dev, iwl_tfd_tb_get_addr(tfd, i),
481 iwl_tfd_tb_get_len(tfd, i), PCI_DMA_TODEVICE);
482
Johannes Bergff0d91c2010-05-17 02:37:34 -0700483 /* free SKB */
484 if (txq->txb) {
485 struct sk_buff *skb;
Johannes Berg6f802402010-05-17 02:37:32 -0700486
Johannes Bergff0d91c2010-05-17 02:37:34 -0700487 skb = txq->txb[txq->q.read_ptr].skb;
Johannes Berg6f802402010-05-17 02:37:32 -0700488
Johannes Bergff0d91c2010-05-17 02:37:34 -0700489 /* can be called from irqs-disabled context */
490 if (skb) {
491 dev_kfree_skb_any(skb);
492 txq->txb[txq->q.read_ptr].skb = NULL;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800493 }
494 }
495}
496
497int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv,
498 struct iwl_tx_queue *txq,
499 dma_addr_t addr, u16 len,
500 u8 reset, u8 pad)
501{
502 struct iwl_queue *q;
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800503 struct iwl_tfd *tfd, *tfd_tmp;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800504 u32 num_tbs;
505
506 q = &txq->q;
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800507 tfd_tmp = (struct iwl_tfd *)txq->tfds;
508 tfd = &tfd_tmp[q->write_ptr];
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800509
510 if (reset)
511 memset(tfd, 0, sizeof(*tfd));
512
513 num_tbs = iwl_tfd_get_num_tbs(tfd);
514
515 /* Each TFD can point to a maximum 20 Tx buffers */
516 if (num_tbs >= IWL_NUM_OF_TBS) {
517 IWL_ERR(priv, "Error can not send more than %d chunks\n",
518 IWL_NUM_OF_TBS);
519 return -EINVAL;
520 }
521
522 BUG_ON(addr & ~DMA_BIT_MASK(36));
523 if (unlikely(addr & ~IWL_TX_DMA_MASK))
524 IWL_ERR(priv, "Unaligned address = %llx\n",
525 (unsigned long long)addr);
526
527 iwl_tfd_set_tb(tfd, num_tbs, addr, len);
528
529 return 0;
530}
531
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800532/*
533 * Tell nic where to find circular buffer of Tx Frame Descriptors for
534 * given Tx queue, and enable the DMA channel used for that queue.
535 *
536 * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
537 * channels supported in hardware.
538 */
539int iwl_hw_tx_queue_init(struct iwl_priv *priv,
540 struct iwl_tx_queue *txq)
541{
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800542 int txq_id = txq->q.id;
543
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800544 /* Circular buffer (TFD queue in DRAM) physical base address */
545 iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
546 txq->q.dma_addr >> 8);
547
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800548 return 0;
549}
550
Zhu Yib481de92007-09-25 17:54:57 -0700551/******************************************************************************
552 *
553 * Generic RX handler implementations
554 *
555 ******************************************************************************/
Tomas Winkler885ba202008-05-29 16:34:55 +0800556static void iwl_rx_reply_alive(struct iwl_priv *priv,
557 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700558{
Zhu Yi2f301222009-10-09 17:19:45 +0800559 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Tomas Winkler885ba202008-05-29 16:34:55 +0800560 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -0700561 struct delayed_work *pwork;
562
563 palive = &pkt->u.alive_frame;
564
Tomas Winklere1623442009-01-27 14:27:56 -0800565 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
Zhu Yib481de92007-09-25 17:54:57 -0700566 "0x%01X 0x%01X\n",
567 palive->is_valid, palive->ver_type,
568 palive->ver_subtype);
569
570 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
Tomas Winklere1623442009-01-27 14:27:56 -0800571 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700572 memcpy(&priv->card_alive_init,
573 &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +0800574 sizeof(struct iwl_init_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700575 pwork = &priv->init_alive_start;
576 } else {
Tomas Winklere1623442009-01-27 14:27:56 -0800577 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700578 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +0800579 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700580 pwork = &priv->alive_start;
581 }
582
583 /* We delay the ALIVE response by 5ms to
584 * give the HW RF Kill time to activate... */
585 if (palive->is_valid == UCODE_VALID_OK)
586 queue_delayed_work(priv->workqueue, pwork,
587 msecs_to_jiffies(5));
588 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800589 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700590}
591
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700592static void iwl_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -0700593{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700594 struct iwl_priv *priv =
595 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -0700596 struct sk_buff *beacon;
597
598 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +0200599 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -0700600
601 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800602 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -0700603 return;
604 }
605
606 mutex_lock(&priv->mutex);
607 /* new beacon skb is allocated every time; dispose previous.*/
608 if (priv->ibss_beacon)
609 dev_kfree_skb(priv->ibss_beacon);
610
611 priv->ibss_beacon = beacon;
612 mutex_unlock(&priv->mutex);
613
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700614 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700615}
616
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700617static void iwl_bg_bt_full_concurrency(struct work_struct *work)
618{
619 struct iwl_priv *priv =
620 container_of(work, struct iwl_priv, bt_full_concurrency);
621
622 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
623 return;
624
625 /* dont send host command if rf-kill is on */
626 if (!iwl_is_ready_rf(priv))
627 return;
628
629 IWL_DEBUG_INFO(priv, "BT coex in %s mode\n",
630 priv->bt_full_concurrent ?
631 "full concurrency" : "3-wire");
632
633 /*
634 * LQ & RXON updated cmds must be sent before BT Config cmd
635 * to avoid 3-wire collisions
636 */
637 if (priv->cfg->ops->hcmd->set_rxon_chain)
638 priv->cfg->ops->hcmd->set_rxon_chain(priv);
639 iwlcore_commit_rxon(priv);
640
641 priv->cfg->ops->hcmd->send_bt_config(priv);
642}
643
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800644/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700645 * iwl_bg_statistics_periodic - Timer callback to queue statistics
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800646 *
647 * This callback is provided in order to send a statistics request.
648 *
649 * This timer function is continually reset to execute within
650 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
651 * was received. We need to ensure we receive the statistics in order
652 * to update the temperature used for calibrating the TXPOWER.
653 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700654static void iwl_bg_statistics_periodic(unsigned long data)
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800655{
656 struct iwl_priv *priv = (struct iwl_priv *)data;
657
658 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
659 return;
660
Mohamed Abbas61780ee2008-10-29 14:05:49 -0700661 /* dont send host command if rf-kill is on */
662 if (!iwl_is_ready_rf(priv))
663 return;
664
Wey-Yi Guyef8d5522009-11-13 11:56:28 -0800665 iwl_send_statistics_request(priv, CMD_ASYNC, false);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800666}
667
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800668
669static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base,
670 u32 start_idx, u32 num_events,
671 u32 mode)
672{
673 u32 i;
674 u32 ptr; /* SRAM byte address of log data */
675 u32 ev, time, data; /* event log data */
676 unsigned long reg_flags;
677
678 if (mode == 0)
679 ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32));
680 else
681 ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32));
682
683 /* Make sure device is powered up for SRAM reads */
684 spin_lock_irqsave(&priv->reg_lock, reg_flags);
685 if (iwl_grab_nic_access(priv)) {
686 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
687 return;
688 }
689
690 /* Set starting address; reads will auto-increment */
691 _iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, ptr);
692 rmb();
693
694 /*
695 * "time" is actually "data" for mode 0 (no timestamp).
696 * place event id # at far right for easier visual parsing.
697 */
698 for (i = 0; i < num_events; i++) {
699 ev = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
700 time = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
701 if (mode == 0) {
702 trace_iwlwifi_dev_ucode_cont_event(priv,
703 0, time, ev);
704 } else {
705 data = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
706 trace_iwlwifi_dev_ucode_cont_event(priv,
707 time, data, ev);
708 }
709 }
710 /* Allow device to power down */
711 iwl_release_nic_access(priv);
712 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
713}
714
Johannes Berg875295f2010-01-22 14:22:55 -0800715static void iwl_continuous_event_trace(struct iwl_priv *priv)
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800716{
717 u32 capacity; /* event log capacity in # entries */
718 u32 base; /* SRAM byte address of event log header */
719 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
720 u32 num_wraps; /* # times uCode wrapped to top of log */
721 u32 next_entry; /* index of next entry to be written by uCode */
722
723 if (priv->ucode_type == UCODE_INIT)
724 base = le32_to_cpu(priv->card_alive_init.error_event_table_ptr);
725 else
726 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
727 if (priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
728 capacity = iwl_read_targ_mem(priv, base);
729 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
730 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
731 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
732 } else
733 return;
734
735 if (num_wraps == priv->event_log.num_wraps) {
736 iwl_print_cont_event_trace(priv,
737 base, priv->event_log.next_entry,
738 next_entry - priv->event_log.next_entry,
739 mode);
740 priv->event_log.non_wraps_count++;
741 } else {
742 if ((num_wraps - priv->event_log.num_wraps) > 1)
743 priv->event_log.wraps_more_count++;
744 else
745 priv->event_log.wraps_once_count++;
746 trace_iwlwifi_dev_ucode_wrap_event(priv,
747 num_wraps - priv->event_log.num_wraps,
748 next_entry, priv->event_log.next_entry);
749 if (next_entry < priv->event_log.next_entry) {
750 iwl_print_cont_event_trace(priv, base,
751 priv->event_log.next_entry,
752 capacity - priv->event_log.next_entry,
753 mode);
754
755 iwl_print_cont_event_trace(priv, base, 0,
756 next_entry, mode);
757 } else {
758 iwl_print_cont_event_trace(priv, base,
759 next_entry, capacity - next_entry,
760 mode);
761
762 iwl_print_cont_event_trace(priv, base, 0,
763 next_entry, mode);
764 }
765 }
766 priv->event_log.num_wraps = num_wraps;
767 priv->event_log.next_entry = next_entry;
768}
769
770/**
771 * iwl_bg_ucode_trace - Timer callback to log ucode event
772 *
773 * The timer is continually set to execute every
774 * UCODE_TRACE_PERIOD milliseconds after the last timer expired
775 * this function is to perform continuous uCode event logging operation
776 * if enabled
777 */
778static void iwl_bg_ucode_trace(unsigned long data)
779{
780 struct iwl_priv *priv = (struct iwl_priv *)data;
781
782 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
783 return;
784
785 if (priv->event_log.ucode_trace) {
786 iwl_continuous_event_trace(priv);
787 /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
788 mod_timer(&priv->ucode_trace,
789 jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
790 }
791}
792
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700793static void iwl_rx_beacon_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +0800794 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700795{
Zhu Yi2f301222009-10-09 17:19:45 +0800796 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Tomas Winkler2aa6ab82008-12-11 10:33:40 -0800797 struct iwl4965_beacon_notif *beacon =
798 (struct iwl4965_beacon_notif *)pkt->u.raw;
Johannes Berga85d7cc2010-07-31 08:34:10 -0700799#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklere7d326a2008-06-12 09:47:11 +0800800 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -0700801
Tomas Winklere1623442009-01-27 14:27:56 -0800802 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
Zhu Yib481de92007-09-25 17:54:57 -0700803 "tsf %d %d rate %d\n",
Tomas Winkler25a65722008-06-12 09:47:07 +0800804 le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
Zhu Yib481de92007-09-25 17:54:57 -0700805 beacon->beacon_notify_hdr.failure_frame,
806 le32_to_cpu(beacon->ibss_mgr_status),
807 le32_to_cpu(beacon->high_tsf),
808 le32_to_cpu(beacon->low_tsf), rate);
809#endif
810
Johannes Berga85d7cc2010-07-31 08:34:10 -0700811 priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
812
Johannes Berg05c914f2008-09-11 00:01:58 +0200813 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -0700814 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
815 queue_work(priv->workqueue, &priv->beacon_update);
816}
817
Zhu Yib481de92007-09-25 17:54:57 -0700818/* Handle notification from uCode that card's power state is changing
819 * due to software, hardware, or critical temperature RFKILL */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700820static void iwl_rx_card_state_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +0800821 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700822{
Zhu Yi2f301222009-10-09 17:19:45 +0800823 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Zhu Yib481de92007-09-25 17:54:57 -0700824 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
825 unsigned long status = priv->status;
826
Wey-Yi Guy3a41bbd2009-12-10 14:37:24 -0800827 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s CT:%s\n",
Zhu Yib481de92007-09-25 17:54:57 -0700828 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
Wey-Yi Guy3a41bbd2009-12-10 14:37:24 -0800829 (flags & SW_CARD_DISABLED) ? "Kill" : "On",
830 (flags & CT_CARD_DISABLED) ?
831 "Reached" : "Not reached");
Zhu Yib481de92007-09-25 17:54:57 -0700832
833 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
Wey-Yi Guy3a41bbd2009-12-10 14:37:24 -0800834 CT_CARD_DISABLED)) {
Zhu Yib481de92007-09-25 17:54:57 -0700835
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700836 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -0700837 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
838
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700839 iwl_write_direct32(priv, HBUS_TARG_MBX_C,
840 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
Zhu Yib481de92007-09-25 17:54:57 -0700841
842 if (!(flags & RXON_CARD_DISABLED)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700843 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -0700844 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700845 iwl_write_direct32(priv, HBUS_TARG_MBX_C,
Zhu Yib481de92007-09-25 17:54:57 -0700846 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
Zhu Yib481de92007-09-25 17:54:57 -0700847 }
Wey-Yi Guy3a41bbd2009-12-10 14:37:24 -0800848 if (flags & CT_CARD_DISABLED)
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -0700849 iwl_tt_enter_ct_kill(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700850 }
Wey-Yi Guy3a41bbd2009-12-10 14:37:24 -0800851 if (!(flags & CT_CARD_DISABLED))
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -0700852 iwl_tt_exit_ct_kill(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700853
854 if (flags & HW_CARD_DISABLED)
855 set_bit(STATUS_RF_KILL_HW, &priv->status);
856 else
857 clear_bit(STATUS_RF_KILL_HW, &priv->status);
858
859
Zhu Yib481de92007-09-25 17:54:57 -0700860 if (!(flags & RXON_CARD_DISABLED))
Tomas Winkler2a421b92008-06-12 09:47:10 +0800861 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700862
863 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
Johannes Berga60e77e2009-06-04 18:26:06 +0200864 test_bit(STATUS_RF_KILL_HW, &priv->status)))
865 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
866 test_bit(STATUS_RF_KILL_HW, &priv->status));
Zhu Yib481de92007-09-25 17:54:57 -0700867 else
868 wake_up_interruptible(&priv->wait_command_queue);
869}
870
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700871int iwl_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
Tomas Winklere2e3c572008-07-18 13:53:04 +0800872{
Tomas Winklere2e3c572008-07-18 13:53:04 +0800873 if (src == IWL_PWR_SRC_VAUX) {
Tomas Winkler3fdb68d2009-02-10 15:19:02 -0800874 if (pci_pme_capable(priv->pci_dev, PCI_D3cold))
Tomas Winklere2e3c572008-07-18 13:53:04 +0800875 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
876 APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
877 ~APMG_PS_CTRL_MSK_PWR_SRC);
878 } else {
879 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
880 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
881 ~APMG_PS_CTRL_MSK_PWR_SRC);
882 }
883
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700884 return 0;
Tomas Winklere2e3c572008-07-18 13:53:04 +0800885}
886
Wey-Yi Guy65550632010-06-24 13:18:35 -0700887static void iwl_bg_tx_flush(struct work_struct *work)
888{
889 struct iwl_priv *priv =
890 container_of(work, struct iwl_priv, tx_flush);
891
892 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
893 return;
894
895 /* do nothing if rf-kill is on */
896 if (!iwl_is_ready_rf(priv))
897 return;
898
899 if (priv->cfg->ops->lib->txfifo_flush) {
900 IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n");
901 iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
902 }
903}
904
Zhu Yib481de92007-09-25 17:54:57 -0700905/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700906 * iwl_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -0700907 *
908 * Setup the RX handlers for each of the reply types sent from the uCode
909 * to the host.
910 *
911 * This function chains into the hardware specific files for them to setup
912 * any hardware specific handlers as well.
913 */
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +0800914static void iwl_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700915{
Tomas Winkler885ba202008-05-29 16:34:55 +0800916 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700917 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
918 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Reinette Chatre81963d62010-01-22 14:22:57 -0800919 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
920 iwl_rx_spectrum_measure_notif;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700921 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700922 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700923 iwl_rx_pm_debug_statistics_notif;
924 priv->rx_handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700925
Ben Cahill9fbab512007-11-29 11:09:47 +0800926 /*
927 * The same handler is used for both the REPLY to a discrete
928 * statistics request from the host as well as for the periodic
929 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -0700930 */
Wey-Yi Guyef8d5522009-11-13 11:56:28 -0800931 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_reply_statistics;
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +0800932 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
Tomas Winkler2a421b92008-06-12 09:47:10 +0800933
934 iwl_setup_rx_scan_handlers(priv);
935
Ron Rindjunsky37a44212008-05-29 16:35:18 +0800936 /* status change handler */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700937 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700938
Tomas Winklerc1354752008-05-29 16:35:04 +0800939 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
940 iwl_rx_missed_beacon_notif;
Ron Rindjunsky37a44212008-05-29 16:35:18 +0800941 /* Rx handlers */
Wey-Yi Guy8d801082010-03-17 13:34:36 -0700942 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwlagn_rx_reply_rx_phy;
943 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwlagn_rx_reply_rx;
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +0800944 /* block ack */
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700945 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwlagn_rx_reply_compressed_ba;
Ben Cahill9fbab512007-11-29 11:09:47 +0800946 /* Set up hardware specific Rx handlers */
Emmanuel Grumbachd4789ef2008-04-24 11:55:20 -0700947 priv->cfg->ops->lib->rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700948}
949
Zhu Yib481de92007-09-25 17:54:57 -0700950/**
Tomas Winklera55360e2008-05-05 10:22:28 +0800951 * iwl_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -0700952 *
953 * Uses the priv->rx_handlers callback function array to invoke
954 * the appropriate handlers, including command responses,
955 * frame-received notifications, and other notifications.
956 */
Tomas Winklera55360e2008-05-05 10:22:28 +0800957void iwl_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700958{
Tomas Winklera55360e2008-05-05 10:22:28 +0800959 struct iwl_rx_mem_buffer *rxb;
Tomas Winklerdb11d632008-05-05 10:22:33 +0800960 struct iwl_rx_packet *pkt;
Tomas Winklera55360e2008-05-05 10:22:28 +0800961 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -0700962 u32 r, i;
963 int reclaim;
964 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800965 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -0800966 u32 count = 8;
Mohamed Abbas4752c932009-05-22 11:01:51 -0700967 int total_empty;
Zhu Yib481de92007-09-25 17:54:57 -0700968
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800969 /* uCode's read index (stored in shared DRAM) indicates the last Rx
970 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8d864222008-11-07 09:58:39 -0800971 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -0700972 i = rxq->read;
973
974 /* Rx interrupt, but nothing sent from uCode */
975 if (i == r)
Tomas Winklere1623442009-01-27 14:27:56 -0800976 IWL_DEBUG_RX(priv, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -0700977
Mohamed Abbas4752c932009-05-22 11:01:51 -0700978 /* calculate total frames need to be restock after handling RX */
Zhu Yi73005152009-10-23 13:42:32 -0700979 total_empty = r - rxq->write_actual;
Mohamed Abbas4752c932009-05-22 11:01:51 -0700980 if (total_empty < 0)
981 total_empty += RX_QUEUE_SIZE;
982
983 if (total_empty > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800984 fill_rx = 1;
985
Zhu Yib481de92007-09-25 17:54:57 -0700986 while (i != r) {
Johannes Bergf4989d92010-05-28 04:08:30 -0700987 int len;
988
Zhu Yib481de92007-09-25 17:54:57 -0700989 rxb = rxq->queue[i];
990
Ben Cahill9fbab512007-11-29 11:09:47 +0800991 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -0700992 * then a bug has been introduced in the queue refilling
993 * routines -- catch it here */
994 BUG_ON(rxb == NULL);
995
996 rxq->queue[i] = NULL;
997
Zhu Yi2f301222009-10-09 17:19:45 +0800998 pci_unmap_page(priv->pci_dev, rxb->page_dma,
999 PAGE_SIZE << priv->hw_params.rx_page_order,
1000 PCI_DMA_FROMDEVICE);
1001 pkt = rxb_addr(rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001002
Johannes Bergf4989d92010-05-28 04:08:30 -07001003 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
1004 len += sizeof(u32); /* account for status word */
1005 trace_iwlwifi_dev_rx(priv, pkt, len);
Johannes Bergbe1a71a2009-10-02 13:44:02 -07001006
Zhu Yib481de92007-09-25 17:54:57 -07001007 /* Reclaim a command buffer only if this packet is a response
1008 * to a (driver-originated) command.
1009 * If the packet (e.g. Rx frame) originated from uCode,
1010 * there is no command buffer to reclaim.
1011 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1012 * but apparently a few don't get set; catch them here. */
1013 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1014 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
Tomas Winkler857485c2008-03-21 13:53:44 -07001015 (pkt->hdr.cmd != REPLY_RX) &&
Daniel Halperin7dddaf12008-10-23 23:48:58 -07001016 (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) &&
Zhu Yicfe01702007-09-27 11:27:31 +08001017 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
Zhu Yib481de92007-09-25 17:54:57 -07001018 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1019 (pkt->hdr.cmd != REPLY_TX);
1020
1021 /* Based on type of command response or notification,
1022 * handle those that need handling via function in
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001023 * rx_handlers table. See iwl_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001024 if (priv->rx_handlers[pkt->hdr.cmd]) {
Tomas Winklere1623442009-01-27 14:27:56 -08001025 IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r,
Ester Kummerf3d67992008-05-06 11:05:12 +08001026 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001027 priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
Zhu Yi29b1b262009-10-23 13:42:25 -07001028 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001029 } else {
1030 /* No handling needed */
Tomas Winklere1623442009-01-27 14:27:56 -08001031 IWL_DEBUG_RX(priv,
Zhu Yib481de92007-09-25 17:54:57 -07001032 "r %d i %d No handler needed for %s, 0x%02x\n",
1033 r, i, get_cmd_string(pkt->hdr.cmd),
1034 pkt->hdr.cmd);
1035 }
1036
Zhu Yi29b1b262009-10-23 13:42:25 -07001037 /*
1038 * XXX: After here, we should always check rxb->page
1039 * against NULL before touching it or its virtual
1040 * memory (pkt). Because some rx_handler might have
1041 * already taken or freed the pages.
1042 */
1043
Zhu Yib481de92007-09-25 17:54:57 -07001044 if (reclaim) {
Zhu Yi2f301222009-10-09 17:19:45 +08001045 /* Invoke any callbacks, transfer the buffer to caller,
1046 * and fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001047 * as we reclaim the driver command queue */
Zhu Yi29b1b262009-10-23 13:42:25 -07001048 if (rxb->page)
Tomas Winkler17b88922008-05-29 16:35:12 +08001049 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001050 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001051 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07001052 }
1053
Zhu Yi73005152009-10-23 13:42:32 -07001054 /* Reuse the page if possible. For notification packets and
1055 * SKBs that fail to Rx correctly, add them back into the
1056 * rx_free list for reuse later. */
Zhu Yib481de92007-09-25 17:54:57 -07001057 spin_lock_irqsave(&rxq->lock, flags);
Zhu Yi73005152009-10-23 13:42:32 -07001058 if (rxb->page != NULL) {
1059 rxb->page_dma = pci_map_page(priv->pci_dev, rxb->page,
1060 0, PAGE_SIZE << priv->hw_params.rx_page_order,
1061 PCI_DMA_FROMDEVICE);
1062 list_add_tail(&rxb->list, &rxq->rx_free);
1063 rxq->free_count++;
1064 } else
1065 list_add_tail(&rxb->list, &rxq->rx_used);
1066
Zhu Yib481de92007-09-25 17:54:57 -07001067 spin_unlock_irqrestore(&rxq->lock, flags);
Zhu Yi73005152009-10-23 13:42:32 -07001068
Zhu Yib481de92007-09-25 17:54:57 -07001069 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001070 /* If there are a lot of unused frames,
1071 * restock the Rx queue so ucode wont assert. */
1072 if (fill_rx) {
1073 count++;
1074 if (count >= 8) {
Zhu Yi73005152009-10-23 13:42:32 -07001075 rxq->read = i;
Wey-Yi Guy54b81552010-03-17 13:34:35 -07001076 iwlagn_rx_replenish_now(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001077 count = 0;
1078 }
1079 }
Zhu Yib481de92007-09-25 17:54:57 -07001080 }
1081
1082 /* Backtrack one entry */
Zhu Yi73005152009-10-23 13:42:32 -07001083 rxq->read = i;
Mohamed Abbas4752c932009-05-22 11:01:51 -07001084 if (fill_rx)
Wey-Yi Guy54b81552010-03-17 13:34:35 -07001085 iwlagn_rx_replenish_now(priv);
Mohamed Abbas4752c932009-05-22 11:01:51 -07001086 else
Wey-Yi Guy54b81552010-03-17 13:34:35 -07001087 iwlagn_rx_queue_restock(priv);
Tomas Winklera55360e2008-05-05 10:22:28 +08001088}
Tomas Winklera55360e2008-05-05 10:22:28 +08001089
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001090/* call this function to flush any scheduled tasklet */
1091static inline void iwl_synchronize_irq(struct iwl_priv *priv)
1092{
Tomas Winklera96a27f2008-10-23 23:48:56 -07001093 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001094 synchronize_irq(priv->pci_dev->irq);
1095 tasklet_kill(&priv->irq_tasklet);
1096}
1097
Mohamed Abbasef850d72009-05-22 11:01:50 -07001098static void iwl_irq_tasklet_legacy(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001099{
1100 u32 inta, handled = 0;
1101 u32 inta_fh;
1102 unsigned long flags;
Ben Cahillc2e61da2009-10-30 14:36:09 -07001103 u32 i;
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001104#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001105 u32 inta_mask;
1106#endif
1107
1108 spin_lock_irqsave(&priv->lock, flags);
1109
1110 /* Ack/clear/reset pending uCode interrupts.
1111 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1112 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001113 inta = iwl_read32(priv, CSR_INT);
1114 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07001115
1116 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1117 * Any new interrupts that happen after this, either while we're
1118 * in this tasklet, or later, will show up in next ISR/tasklet. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001119 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1120 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001121
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001122#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001123 if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001124 /* just for debug */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001125 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Tomas Winklere1623442009-01-27 14:27:56 -08001126 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07001127 inta, inta_mask, inta_fh);
1128 }
1129#endif
1130
Zhu Yi2f301222009-10-09 17:19:45 +08001131 spin_unlock_irqrestore(&priv->lock, flags);
1132
Zhu Yib481de92007-09-25 17:54:57 -07001133 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1134 * atomic, make sure that inta covers all the interrupts that
1135 * we've discovered, even if FH interrupt came in just after
1136 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001137 if (inta_fh & CSR49_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001138 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001139 if (inta_fh & CSR49_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001140 inta |= CSR_INT_BIT_FH_TX;
1141
1142 /* Now service all interrupt bits discovered above. */
1143 if (inta & CSR_INT_BIT_HW_ERR) {
Reinette Chatre58dba722009-07-17 09:30:25 -07001144 IWL_ERR(priv, "Hardware error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001145
1146 /* Tell the device to stop sending interrupts */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001147 iwl_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001148
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001149 priv->isr_stats.hw++;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001150 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001151
1152 handled |= CSR_INT_BIT_HW_ERR;
1153
Zhu Yib481de92007-09-25 17:54:57 -07001154 return;
1155 }
1156
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001157#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001158 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07001159 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001160 if (inta & CSR_INT_BIT_SCD) {
Tomas Winklere1623442009-01-27 14:27:56 -08001161 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
Joonwoo Park25c03d82008-01-23 10:15:20 -08001162 "the frame/frames.\n");
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001163 priv->isr_stats.sch++;
1164 }
Zhu Yib481de92007-09-25 17:54:57 -07001165
1166 /* Alive notification via Rx interrupt will do the real work */
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001167 if (inta & CSR_INT_BIT_ALIVE) {
Tomas Winklere1623442009-01-27 14:27:56 -08001168 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001169 priv->isr_stats.alive++;
1170 }
Zhu Yib481de92007-09-25 17:54:57 -07001171 }
1172#endif
1173 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001174 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07001175
Ben Cahill9fbab512007-11-29 11:09:47 +08001176 /* HW RF KILL switch toggled */
Zhu Yib481de92007-09-25 17:54:57 -07001177 if (inta & CSR_INT_BIT_RF_KILL) {
1178 int hw_rf_kill = 0;
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001179 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yib481de92007-09-25 17:54:57 -07001180 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
1181 hw_rf_kill = 1;
1182
Reinette Chatre4c423a22009-07-17 09:30:26 -07001183 IWL_WARN(priv, "RF_KILL bit toggled to %s.\n",
Abhijeet Kolekarc3056062008-11-12 13:14:08 -08001184 hw_rf_kill ? "disable radio" : "enable radio");
Zhu Yib481de92007-09-25 17:54:57 -07001185
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001186 priv->isr_stats.rfkill++;
1187
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +08001188 /* driver only loads ucode once setting the interface up.
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01001189 * the driver allows loading the ucode even if the radio
1190 * is killed. Hence update the killswitch state here. The
1191 * rfkill handler will care about restarting if needed.
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +08001192 */
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01001193 if (!test_bit(STATUS_ALIVE, &priv->status)) {
1194 if (hw_rf_kill)
1195 set_bit(STATUS_RF_KILL_HW, &priv->status);
1196 else
1197 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Johannes Berga60e77e2009-06-04 18:26:06 +02001198 wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
Mohamed Abbasedb34222008-12-11 10:33:37 -08001199 }
Zhu Yib481de92007-09-25 17:54:57 -07001200
1201 handled |= CSR_INT_BIT_RF_KILL;
1202 }
1203
Ben Cahill9fbab512007-11-29 11:09:47 +08001204 /* Chip got too hot and stopped itself */
Zhu Yib481de92007-09-25 17:54:57 -07001205 if (inta & CSR_INT_BIT_CT_KILL) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001206 IWL_ERR(priv, "Microcode CT kill error detected.\n");
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001207 priv->isr_stats.ctkill++;
Zhu Yib481de92007-09-25 17:54:57 -07001208 handled |= CSR_INT_BIT_CT_KILL;
1209 }
1210
1211 /* Error detected by uCode */
1212 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001213 IWL_ERR(priv, "Microcode SW error detected. "
1214 " Restarting 0x%X.\n", inta);
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001215 priv->isr_stats.sw++;
1216 priv->isr_stats.sw_err = inta;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001217 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001218 handled |= CSR_INT_BIT_SW_ERR;
1219 }
1220
Ben Cahillc2e61da2009-10-30 14:36:09 -07001221 /*
1222 * uCode wakes up after power-down sleep.
1223 * Tell device about any new tx or host commands enqueued,
1224 * and about any Rx buffers made available while asleep.
1225 */
Zhu Yib481de92007-09-25 17:54:57 -07001226 if (inta & CSR_INT_BIT_WAKEUP) {
Tomas Winklere1623442009-01-27 14:27:56 -08001227 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
Tomas Winklera55360e2008-05-05 10:22:28 +08001228 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Ben Cahillc2e61da2009-10-30 14:36:09 -07001229 for (i = 0; i < priv->hw_params.max_txq_num; i++)
1230 iwl_txq_update_write_ptr(priv, &priv->txq[i]);
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001231 priv->isr_stats.wakeup++;
Zhu Yib481de92007-09-25 17:54:57 -07001232 handled |= CSR_INT_BIT_WAKEUP;
1233 }
1234
1235 /* All uCode command responses, including Tx command responses,
1236 * Rx "responses" (frame-received notification), and other
1237 * notifications from uCode come through here*/
1238 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Tomas Winklera55360e2008-05-05 10:22:28 +08001239 iwl_rx_handle(priv);
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001240 priv->isr_stats.rx++;
Zhu Yib481de92007-09-25 17:54:57 -07001241 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1242 }
1243
Ben Cahillc72cd192009-10-30 14:36:08 -07001244 /* This "Tx" DMA channel is used only for loading uCode */
Zhu Yib481de92007-09-25 17:54:57 -07001245 if (inta & CSR_INT_BIT_FH_TX) {
Ben Cahillc72cd192009-10-30 14:36:08 -07001246 IWL_DEBUG_ISR(priv, "uCode load interrupt\n");
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001247 priv->isr_stats.tx++;
Zhu Yib481de92007-09-25 17:54:57 -07001248 handled |= CSR_INT_BIT_FH_TX;
Ben Cahillc72cd192009-10-30 14:36:08 -07001249 /* Wake up uCode load routine, now that load is complete */
Ron Rindjunskydbb983b2008-05-15 13:54:12 +08001250 priv->ucode_write_complete = 1;
1251 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07001252 }
1253
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001254 if (inta & ~handled) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001255 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001256 priv->isr_stats.unhandled++;
1257 }
Zhu Yib481de92007-09-25 17:54:57 -07001258
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001259 if (inta & ~(priv->inta_mask)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001260 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001261 inta & ~priv->inta_mask);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001262 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001263 }
1264
1265 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001266 /* only Re-enable if diabled by irq */
1267 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001268 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001269
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001270#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001271 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001272 inta = iwl_read32(priv, CSR_INT);
1273 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1274 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Tomas Winklere1623442009-01-27 14:27:56 -08001275 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
Zhu Yib481de92007-09-25 17:54:57 -07001276 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
1277 }
1278#endif
Zhu Yib481de92007-09-25 17:54:57 -07001279}
1280
Mohamed Abbasef850d72009-05-22 11:01:50 -07001281/* tasklet for iwlagn interrupt */
1282static void iwl_irq_tasklet(struct iwl_priv *priv)
1283{
1284 u32 inta = 0;
1285 u32 handled = 0;
1286 unsigned long flags;
Ben Cahill87569902009-11-06 14:53:01 -08001287 u32 i;
Mohamed Abbasef850d72009-05-22 11:01:50 -07001288#ifdef CONFIG_IWLWIFI_DEBUG
1289 u32 inta_mask;
1290#endif
1291
1292 spin_lock_irqsave(&priv->lock, flags);
1293
1294 /* Ack/clear/reset pending uCode interrupts.
1295 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1296 */
Shanyu Zhao48a6be62010-03-16 10:22:26 -07001297 /* There is a hardware bug in the interrupt mask function that some
1298 * interrupts (i.e. CSR_INT_BIT_SCD) can still be generated even if
1299 * they are disabled in the CSR_INT_MASK register. Furthermore the
1300 * ICT interrupt handling mechanism has another bug that might cause
1301 * these unmasked interrupts fail to be detected. We workaround the
1302 * hardware bugs here by ACKing all the possible interrupts so that
1303 * interrupt coalescing can still be achieved.
1304 */
David S. Miller4a35ecf2010-04-06 23:53:30 -07001305 iwl_write32(priv, CSR_INT, priv->_agn.inta | ~priv->inta_mask);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001306
Johannes Berga4c8b2a2010-01-21 06:25:54 -08001307 inta = priv->_agn.inta;
Mohamed Abbasef850d72009-05-22 11:01:50 -07001308
1309#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001310 if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
Mohamed Abbasef850d72009-05-22 11:01:50 -07001311 /* just for debug */
1312 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1313 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x\n ",
1314 inta, inta_mask);
1315 }
1316#endif
Zhu Yi2f301222009-10-09 17:19:45 +08001317
1318 spin_unlock_irqrestore(&priv->lock, flags);
1319
Johannes Berga4c8b2a2010-01-21 06:25:54 -08001320 /* saved interrupt in inta variable now we can reset priv->_agn.inta */
1321 priv->_agn.inta = 0;
Mohamed Abbasef850d72009-05-22 11:01:50 -07001322
1323 /* Now service all interrupt bits discovered above. */
1324 if (inta & CSR_INT_BIT_HW_ERR) {
Reinette Chatre58dba722009-07-17 09:30:25 -07001325 IWL_ERR(priv, "Hardware error detected. Restarting.\n");
Mohamed Abbasef850d72009-05-22 11:01:50 -07001326
1327 /* Tell the device to stop sending interrupts */
1328 iwl_disable_interrupts(priv);
1329
1330 priv->isr_stats.hw++;
1331 iwl_irq_handle_error(priv);
1332
1333 handled |= CSR_INT_BIT_HW_ERR;
1334
Mohamed Abbasef850d72009-05-22 11:01:50 -07001335 return;
1336 }
1337
1338#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001339 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Mohamed Abbasef850d72009-05-22 11:01:50 -07001340 /* NIC fires this, but we don't use it, redundant with WAKEUP */
1341 if (inta & CSR_INT_BIT_SCD) {
1342 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
1343 "the frame/frames.\n");
1344 priv->isr_stats.sch++;
1345 }
1346
1347 /* Alive notification via Rx interrupt will do the real work */
1348 if (inta & CSR_INT_BIT_ALIVE) {
1349 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
1350 priv->isr_stats.alive++;
1351 }
1352 }
1353#endif
1354 /* Safely ignore these bits for debug checks below */
1355 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
1356
1357 /* HW RF KILL switch toggled */
1358 if (inta & CSR_INT_BIT_RF_KILL) {
1359 int hw_rf_kill = 0;
1360 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
1361 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
1362 hw_rf_kill = 1;
1363
Reinette Chatre4c423a22009-07-17 09:30:26 -07001364 IWL_WARN(priv, "RF_KILL bit toggled to %s.\n",
Mohamed Abbasef850d72009-05-22 11:01:50 -07001365 hw_rf_kill ? "disable radio" : "enable radio");
1366
1367 priv->isr_stats.rfkill++;
1368
1369 /* driver only loads ucode once setting the interface up.
1370 * the driver allows loading the ucode even if the radio
1371 * is killed. Hence update the killswitch state here. The
1372 * rfkill handler will care about restarting if needed.
1373 */
1374 if (!test_bit(STATUS_ALIVE, &priv->status)) {
1375 if (hw_rf_kill)
1376 set_bit(STATUS_RF_KILL_HW, &priv->status);
1377 else
1378 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Johannes Berga60e77e2009-06-04 18:26:06 +02001379 wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001380 }
1381
1382 handled |= CSR_INT_BIT_RF_KILL;
1383 }
1384
1385 /* Chip got too hot and stopped itself */
1386 if (inta & CSR_INT_BIT_CT_KILL) {
1387 IWL_ERR(priv, "Microcode CT kill error detected.\n");
1388 priv->isr_stats.ctkill++;
1389 handled |= CSR_INT_BIT_CT_KILL;
1390 }
1391
1392 /* Error detected by uCode */
1393 if (inta & CSR_INT_BIT_SW_ERR) {
1394 IWL_ERR(priv, "Microcode SW error detected. "
1395 " Restarting 0x%X.\n", inta);
1396 priv->isr_stats.sw++;
1397 priv->isr_stats.sw_err = inta;
1398 iwl_irq_handle_error(priv);
1399 handled |= CSR_INT_BIT_SW_ERR;
1400 }
1401
1402 /* uCode wakes up after power-down sleep */
1403 if (inta & CSR_INT_BIT_WAKEUP) {
1404 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
1405 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Ben Cahill87569902009-11-06 14:53:01 -08001406 for (i = 0; i < priv->hw_params.max_txq_num; i++)
1407 iwl_txq_update_write_ptr(priv, &priv->txq[i]);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001408
1409 priv->isr_stats.wakeup++;
1410
1411 handled |= CSR_INT_BIT_WAKEUP;
1412 }
1413
1414 /* All uCode command responses, including Tx command responses,
1415 * Rx "responses" (frame-received notification), and other
1416 * notifications from uCode come through here*/
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001417 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX |
1418 CSR_INT_BIT_RX_PERIODIC)) {
Mohamed Abbasef850d72009-05-22 11:01:50 -07001419 IWL_DEBUG_ISR(priv, "Rx interrupt\n");
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001420 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
1421 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1422 iwl_write32(priv, CSR_FH_INT_STATUS,
1423 CSR49_FH_INT_RX_MASK);
1424 }
1425 if (inta & CSR_INT_BIT_RX_PERIODIC) {
1426 handled |= CSR_INT_BIT_RX_PERIODIC;
1427 iwl_write32(priv, CSR_INT, CSR_INT_BIT_RX_PERIODIC);
1428 }
1429 /* Sending RX interrupt require many steps to be done in the
1430 * the device:
1431 * 1- write interrupt to current index in ICT table.
1432 * 2- dma RX frame.
1433 * 3- update RX shared data to indicate last write index.
1434 * 4- send interrupt.
1435 * This could lead to RX race, driver could receive RX interrupt
Ben Cahill74ba67e2009-11-20 12:04:53 -08001436 * but the shared data changes does not reflect this;
1437 * periodic interrupt will detect any dangling Rx activity.
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001438 */
Ben Cahill74ba67e2009-11-20 12:04:53 -08001439
1440 /* Disable periodic interrupt; we use it as just a one-shot. */
1441 iwl_write8(priv, CSR_INT_PERIODIC_REG,
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001442 CSR_INT_PERIODIC_DIS);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001443 iwl_rx_handle(priv);
Ben Cahill74ba67e2009-11-20 12:04:53 -08001444
1445 /*
1446 * Enable periodic interrupt in 8 msec only if we received
1447 * real RX interrupt (instead of just periodic int), to catch
1448 * any dangling Rx interrupt. If it was just the periodic
1449 * interrupt, there was no dangling Rx activity, and no need
1450 * to extend the periodic interrupt; one-shot is enough.
1451 */
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001452 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX))
Ben Cahill74ba67e2009-11-20 12:04:53 -08001453 iwl_write8(priv, CSR_INT_PERIODIC_REG,
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001454 CSR_INT_PERIODIC_ENA);
1455
Mohamed Abbasef850d72009-05-22 11:01:50 -07001456 priv->isr_stats.rx++;
Mohamed Abbasef850d72009-05-22 11:01:50 -07001457 }
1458
Ben Cahillc72cd192009-10-30 14:36:08 -07001459 /* This "Tx" DMA channel is used only for loading uCode */
Mohamed Abbasef850d72009-05-22 11:01:50 -07001460 if (inta & CSR_INT_BIT_FH_TX) {
1461 iwl_write32(priv, CSR_FH_INT_STATUS, CSR49_FH_INT_TX_MASK);
Ben Cahillc72cd192009-10-30 14:36:08 -07001462 IWL_DEBUG_ISR(priv, "uCode load interrupt\n");
Mohamed Abbasef850d72009-05-22 11:01:50 -07001463 priv->isr_stats.tx++;
1464 handled |= CSR_INT_BIT_FH_TX;
Ben Cahillc72cd192009-10-30 14:36:08 -07001465 /* Wake up uCode load routine, now that load is complete */
Mohamed Abbasef850d72009-05-22 11:01:50 -07001466 priv->ucode_write_complete = 1;
1467 wake_up_interruptible(&priv->wait_command_queue);
1468 }
1469
1470 if (inta & ~handled) {
1471 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
1472 priv->isr_stats.unhandled++;
1473 }
1474
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001475 if (inta & ~(priv->inta_mask)) {
Mohamed Abbasef850d72009-05-22 11:01:50 -07001476 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001477 inta & ~priv->inta_mask);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001478 }
1479
Mohamed Abbasef850d72009-05-22 11:01:50 -07001480 /* Re-enable all interrupts */
1481 /* only Re-enable if diabled by irq */
1482 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1483 iwl_enable_interrupts(priv);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001484}
1485
Wey-Yi Guy872c8dd2010-03-16 10:46:31 -07001486/* the threshold ratio of actual_ack_cnt to expected_ack_cnt in percent */
1487#define ACK_CNT_RATIO (50)
1488#define BA_TIMEOUT_CNT (5)
1489#define BA_TIMEOUT_MAX (16)
1490
1491/**
1492 * iwl_good_ack_health - checks for ACK count ratios, BA timeout retries.
1493 *
1494 * When the ACK count ratio is 0 and aggregated BA timeout retries exceeding
1495 * the BA_TIMEOUT_MAX, reload firmware and bring system back to normal
1496 * operation state.
1497 */
1498bool iwl_good_ack_health(struct iwl_priv *priv,
1499 struct iwl_rx_packet *pkt)
1500{
1501 bool rc = true;
1502 int actual_ack_cnt_delta, expected_ack_cnt_delta;
1503 int ba_timeout_delta;
1504
1505 actual_ack_cnt_delta =
1506 le32_to_cpu(pkt->u.stats.tx.actual_ack_cnt) -
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -07001507 le32_to_cpu(priv->_agn.statistics.tx.actual_ack_cnt);
Wey-Yi Guy872c8dd2010-03-16 10:46:31 -07001508 expected_ack_cnt_delta =
1509 le32_to_cpu(pkt->u.stats.tx.expected_ack_cnt) -
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -07001510 le32_to_cpu(priv->_agn.statistics.tx.expected_ack_cnt);
Wey-Yi Guy872c8dd2010-03-16 10:46:31 -07001511 ba_timeout_delta =
1512 le32_to_cpu(pkt->u.stats.tx.agg.ba_timeout) -
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -07001513 le32_to_cpu(priv->_agn.statistics.tx.agg.ba_timeout);
Wey-Yi Guy872c8dd2010-03-16 10:46:31 -07001514 if ((priv->_agn.agg_tids_count > 0) &&
1515 (expected_ack_cnt_delta > 0) &&
1516 (((actual_ack_cnt_delta * 100) / expected_ack_cnt_delta)
1517 < ACK_CNT_RATIO) &&
1518 (ba_timeout_delta > BA_TIMEOUT_CNT)) {
1519 IWL_DEBUG_RADIO(priv, "actual_ack_cnt delta = %d,"
1520 " expected_ack_cnt = %d\n",
1521 actual_ack_cnt_delta, expected_ack_cnt_delta);
1522
Johannes Bergd73e4922010-05-06 12:18:41 -07001523#ifdef CONFIG_IWLWIFI_DEBUGFS
1524 /*
1525 * This is ifdef'ed on DEBUGFS because otherwise the
1526 * statistics aren't available. If DEBUGFS is set but
1527 * DEBUG is not, these will just compile out.
1528 */
Wey-Yi Guy872c8dd2010-03-16 10:46:31 -07001529 IWL_DEBUG_RADIO(priv, "rx_detected_cnt delta = %d\n",
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -07001530 priv->_agn.delta_statistics.tx.rx_detected_cnt);
Wey-Yi Guy872c8dd2010-03-16 10:46:31 -07001531 IWL_DEBUG_RADIO(priv,
1532 "ack_or_ba_timeout_collision delta = %d\n",
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -07001533 priv->_agn.delta_statistics.tx.
Wey-Yi Guy872c8dd2010-03-16 10:46:31 -07001534 ack_or_ba_timeout_collision);
1535#endif
1536 IWL_DEBUG_RADIO(priv, "agg ba_timeout delta = %d\n",
1537 ba_timeout_delta);
1538 if (!actual_ack_cnt_delta &&
1539 (ba_timeout_delta >= BA_TIMEOUT_MAX))
1540 rc = false;
1541 }
1542 return rc;
1543}
1544
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001545
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07001546/*****************************************************************************
1547 *
1548 * sysfs attributes
1549 *
1550 *****************************************************************************/
1551
1552#ifdef CONFIG_IWLWIFI_DEBUG
1553
1554/*
1555 * The following adds a new attribute to the sysfs representation
1556 * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
1557 * used for controlling the debug level.
1558 *
1559 * See the level definitions in iwl for details.
1560 *
1561 * The debug_level being managed using sysfs below is a per device debug
1562 * level that is used instead of the global debug level if it (the per
1563 * device debug level) is set.
1564 */
1565static ssize_t show_debug_level(struct device *d,
1566 struct device_attribute *attr, char *buf)
1567{
1568 struct iwl_priv *priv = dev_get_drvdata(d);
1569 return sprintf(buf, "0x%08X\n", iwl_get_debug_level(priv));
1570}
1571static ssize_t store_debug_level(struct device *d,
1572 struct device_attribute *attr,
1573 const char *buf, size_t count)
1574{
1575 struct iwl_priv *priv = dev_get_drvdata(d);
1576 unsigned long val;
1577 int ret;
1578
1579 ret = strict_strtoul(buf, 0, &val);
1580 if (ret)
1581 IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf);
1582 else {
1583 priv->debug_level = val;
1584 if (iwl_alloc_traffic_mem(priv))
1585 IWL_ERR(priv,
1586 "Not enough memory to generate traffic log\n");
1587 }
1588 return strnlen(buf, count);
1589}
1590
1591static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
1592 show_debug_level, store_debug_level);
1593
1594
1595#endif /* CONFIG_IWLWIFI_DEBUG */
1596
1597
1598static ssize_t show_temperature(struct device *d,
1599 struct device_attribute *attr, char *buf)
1600{
1601 struct iwl_priv *priv = dev_get_drvdata(d);
1602
1603 if (!iwl_is_alive(priv))
1604 return -EAGAIN;
1605
1606 return sprintf(buf, "%d\n", priv->temperature);
1607}
1608
1609static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
1610
1611static ssize_t show_tx_power(struct device *d,
1612 struct device_attribute *attr, char *buf)
1613{
1614 struct iwl_priv *priv = dev_get_drvdata(d);
1615
1616 if (!iwl_is_ready_rf(priv))
1617 return sprintf(buf, "off\n");
1618 else
1619 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
1620}
1621
1622static ssize_t store_tx_power(struct device *d,
1623 struct device_attribute *attr,
1624 const char *buf, size_t count)
1625{
1626 struct iwl_priv *priv = dev_get_drvdata(d);
1627 unsigned long val;
1628 int ret;
1629
1630 ret = strict_strtoul(buf, 10, &val);
1631 if (ret)
1632 IWL_INFO(priv, "%s is not in decimal form.\n", buf);
1633 else {
1634 ret = iwl_set_tx_power(priv, val, false);
1635 if (ret)
1636 IWL_ERR(priv, "failed setting tx power (0x%d).\n",
1637 ret);
1638 else
1639 ret = count;
1640 }
1641 return ret;
1642}
1643
1644static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
1645
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07001646static struct attribute *iwl_sysfs_entries[] = {
1647 &dev_attr_temperature.attr,
1648 &dev_attr_tx_power.attr,
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07001649#ifdef CONFIG_IWLWIFI_DEBUG
1650 &dev_attr_debug_level.attr,
1651#endif
1652 NULL
1653};
1654
1655static struct attribute_group iwl_attribute_group = {
1656 .name = NULL, /* put in device directory */
1657 .attrs = iwl_sysfs_entries,
1658};
1659
Zhu Yib481de92007-09-25 17:54:57 -07001660/******************************************************************************
1661 *
1662 * uCode download functions
1663 *
1664 ******************************************************************************/
1665
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001666static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001667{
Tomas Winkler98c92212008-01-14 17:46:20 -08001668 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
1669 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
1670 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1671 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
1672 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1673 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001674}
1675
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001676static void iwl_nic_start(struct iwl_priv *priv)
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08001677{
1678 /* Remove all resets to allow NIC to operate */
1679 iwl_write32(priv, CSR_RESET, 0);
1680}
1681
Johannes Bergdd7a2502010-04-28 23:33:10 -07001682struct iwlagn_ucode_capabilities {
1683 u32 max_probe_length;
Wey-Yi Guy6a822d02010-07-13 17:13:15 -07001684 u32 standard_phy_calibration_size;
Johannes Bergdd7a2502010-04-28 23:33:10 -07001685};
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08001686
Johannes Bergb08dfd02010-01-29 11:54:56 -08001687static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context);
Johannes Bergdd7a2502010-04-28 23:33:10 -07001688static int iwl_mac_setup_register(struct iwl_priv *priv,
1689 struct iwlagn_ucode_capabilities *capa);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001690
Jay Sternberg39396082010-08-12 10:24:07 -07001691#define UCODE_EXPERIMENTAL_INDEX 100
1692#define UCODE_EXPERIMENTAL_TAG "exp"
1693
Johannes Bergb08dfd02010-01-29 11:54:56 -08001694static int __must_check iwl_request_firmware(struct iwl_priv *priv, bool first)
Zhu Yib481de92007-09-25 17:54:57 -07001695{
Reinette Chatrea0987a82008-12-02 12:14:06 -08001696 const char *name_pre = priv->cfg->fw_name_pre;
Jay Sternberg39396082010-08-12 10:24:07 -07001697 char tag[8];
Johannes Bergb08dfd02010-01-29 11:54:56 -08001698
Jay Sternberg39396082010-08-12 10:24:07 -07001699 if (first) {
1700#ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE
1701 priv->fw_index = UCODE_EXPERIMENTAL_INDEX;
1702 strcpy(tag, UCODE_EXPERIMENTAL_TAG);
1703 } else if (priv->fw_index == UCODE_EXPERIMENTAL_INDEX) {
1704#endif
Johannes Bergb08dfd02010-01-29 11:54:56 -08001705 priv->fw_index = priv->cfg->ucode_api_max;
Jay Sternberg39396082010-08-12 10:24:07 -07001706 sprintf(tag, "%d", priv->fw_index);
1707 } else {
Johannes Bergb08dfd02010-01-29 11:54:56 -08001708 priv->fw_index--;
Jay Sternberg39396082010-08-12 10:24:07 -07001709 sprintf(tag, "%d", priv->fw_index);
1710 }
Johannes Bergb08dfd02010-01-29 11:54:56 -08001711
1712 if (priv->fw_index < priv->cfg->ucode_api_min) {
1713 IWL_ERR(priv, "no suitable firmware found!\n");
1714 return -ENOENT;
1715 }
1716
Jay Sternberg39396082010-08-12 10:24:07 -07001717 sprintf(priv->firmware_name, "%s%s%s", name_pre, tag, ".ucode");
Johannes Bergb08dfd02010-01-29 11:54:56 -08001718
Jay Sternberg39396082010-08-12 10:24:07 -07001719 IWL_DEBUG_INFO(priv, "attempting to load firmware %s'%s'\n",
1720 (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
1721 ? "EXPERIMENTAL " : "",
Johannes Bergb08dfd02010-01-29 11:54:56 -08001722 priv->firmware_name);
1723
1724 return request_firmware_nowait(THIS_MODULE, 1, priv->firmware_name,
1725 &priv->pci_dev->dev, GFP_KERNEL, priv,
1726 iwl_ucode_callback);
1727}
1728
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001729struct iwlagn_firmware_pieces {
1730 const void *inst, *data, *init, *init_data, *boot;
1731 size_t inst_size, data_size, init_size, init_data_size, boot_size;
1732
1733 u32 build;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001734
1735 u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
1736 u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001737};
1738
1739static int iwlagn_load_legacy_firmware(struct iwl_priv *priv,
1740 const struct firmware *ucode_raw,
1741 struct iwlagn_firmware_pieces *pieces)
1742{
1743 struct iwl_ucode_header *ucode = (void *)ucode_raw->data;
1744 u32 api_ver, hdr_size;
1745 const u8 *src;
1746
1747 priv->ucode_ver = le32_to_cpu(ucode->ver);
1748 api_ver = IWL_UCODE_API(priv->ucode_ver);
1749
1750 switch (api_ver) {
1751 default:
1752 /*
1753 * 4965 doesn't revision the firmware file format
1754 * along with the API version, it always uses v1
1755 * file format.
1756 */
1757 if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) !=
1758 CSR_HW_REV_TYPE_4965) {
1759 hdr_size = 28;
1760 if (ucode_raw->size < hdr_size) {
1761 IWL_ERR(priv, "File size too small!\n");
1762 return -EINVAL;
1763 }
1764 pieces->build = le32_to_cpu(ucode->u.v2.build);
1765 pieces->inst_size = le32_to_cpu(ucode->u.v2.inst_size);
1766 pieces->data_size = le32_to_cpu(ucode->u.v2.data_size);
1767 pieces->init_size = le32_to_cpu(ucode->u.v2.init_size);
1768 pieces->init_data_size = le32_to_cpu(ucode->u.v2.init_data_size);
1769 pieces->boot_size = le32_to_cpu(ucode->u.v2.boot_size);
1770 src = ucode->u.v2.data;
1771 break;
1772 }
1773 /* fall through for 4965 */
1774 case 0:
1775 case 1:
1776 case 2:
1777 hdr_size = 24;
1778 if (ucode_raw->size < hdr_size) {
1779 IWL_ERR(priv, "File size too small!\n");
1780 return -EINVAL;
1781 }
1782 pieces->build = 0;
1783 pieces->inst_size = le32_to_cpu(ucode->u.v1.inst_size);
1784 pieces->data_size = le32_to_cpu(ucode->u.v1.data_size);
1785 pieces->init_size = le32_to_cpu(ucode->u.v1.init_size);
1786 pieces->init_data_size = le32_to_cpu(ucode->u.v1.init_data_size);
1787 pieces->boot_size = le32_to_cpu(ucode->u.v1.boot_size);
1788 src = ucode->u.v1.data;
1789 break;
1790 }
1791
1792 /* Verify size of file vs. image size info in file's header */
1793 if (ucode_raw->size != hdr_size + pieces->inst_size +
1794 pieces->data_size + pieces->init_size +
1795 pieces->init_data_size + pieces->boot_size) {
1796
1797 IWL_ERR(priv,
1798 "uCode file size %d does not match expected size\n",
1799 (int)ucode_raw->size);
1800 return -EINVAL;
1801 }
1802
1803 pieces->inst = src;
1804 src += pieces->inst_size;
1805 pieces->data = src;
1806 src += pieces->data_size;
1807 pieces->init = src;
1808 src += pieces->init_size;
1809 pieces->init_data = src;
1810 src += pieces->init_data_size;
1811 pieces->boot = src;
1812 src += pieces->boot_size;
1813
1814 return 0;
1815}
1816
Johannes Bergdd7a2502010-04-28 23:33:10 -07001817static int iwlagn_wanted_ucode_alternative = 1;
1818
1819static int iwlagn_load_firmware(struct iwl_priv *priv,
1820 const struct firmware *ucode_raw,
1821 struct iwlagn_firmware_pieces *pieces,
1822 struct iwlagn_ucode_capabilities *capa)
1823{
1824 struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data;
1825 struct iwl_ucode_tlv *tlv;
1826 size_t len = ucode_raw->size;
1827 const u8 *data;
1828 int wanted_alternative = iwlagn_wanted_ucode_alternative, tmp;
1829 u64 alternatives;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001830 u32 tlv_len;
1831 enum iwl_ucode_tlv_type tlv_type;
1832 const u8 *tlv_data;
Johannes Bergdd7a2502010-04-28 23:33:10 -07001833
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001834 if (len < sizeof(*ucode)) {
1835 IWL_ERR(priv, "uCode has invalid length: %zd\n", len);
Johannes Bergdd7a2502010-04-28 23:33:10 -07001836 return -EINVAL;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001837 }
Johannes Bergdd7a2502010-04-28 23:33:10 -07001838
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001839 if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) {
1840 IWL_ERR(priv, "invalid uCode magic: 0X%x\n",
1841 le32_to_cpu(ucode->magic));
Johannes Bergdd7a2502010-04-28 23:33:10 -07001842 return -EINVAL;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001843 }
Johannes Bergdd7a2502010-04-28 23:33:10 -07001844
1845 /*
1846 * Check which alternatives are present, and "downgrade"
1847 * when the chosen alternative is not present, warning
1848 * the user when that happens. Some files may not have
1849 * any alternatives, so don't warn in that case.
1850 */
1851 alternatives = le64_to_cpu(ucode->alternatives);
1852 tmp = wanted_alternative;
1853 if (wanted_alternative > 63)
1854 wanted_alternative = 63;
1855 while (wanted_alternative && !(alternatives & BIT(wanted_alternative)))
1856 wanted_alternative--;
1857 if (wanted_alternative && wanted_alternative != tmp)
1858 IWL_WARN(priv,
1859 "uCode alternative %d not available, choosing %d\n",
1860 tmp, wanted_alternative);
1861
1862 priv->ucode_ver = le32_to_cpu(ucode->ver);
1863 pieces->build = le32_to_cpu(ucode->build);
1864 data = ucode->data;
1865
1866 len -= sizeof(*ucode);
1867
Johannes Berg704da532010-07-14 09:34:50 -07001868 while (len >= sizeof(*tlv)) {
Johannes Bergdd7a2502010-04-28 23:33:10 -07001869 u16 tlv_alt;
Johannes Bergdd7a2502010-04-28 23:33:10 -07001870
1871 len -= sizeof(*tlv);
1872 tlv = (void *)data;
1873
1874 tlv_len = le32_to_cpu(tlv->length);
1875 tlv_type = le16_to_cpu(tlv->type);
1876 tlv_alt = le16_to_cpu(tlv->alternative);
1877 tlv_data = tlv->data;
1878
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001879 if (len < tlv_len) {
1880 IWL_ERR(priv, "invalid TLV len: %zd/%u\n",
1881 len, tlv_len);
Johannes Bergdd7a2502010-04-28 23:33:10 -07001882 return -EINVAL;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001883 }
Johannes Bergdd7a2502010-04-28 23:33:10 -07001884 len -= ALIGN(tlv_len, 4);
1885 data += sizeof(*tlv) + ALIGN(tlv_len, 4);
1886
1887 /*
1888 * Alternative 0 is always valid.
1889 *
1890 * Skip alternative TLVs that are not selected.
1891 */
1892 if (tlv_alt != 0 && tlv_alt != wanted_alternative)
1893 continue;
1894
1895 switch (tlv_type) {
1896 case IWL_UCODE_TLV_INST:
1897 pieces->inst = tlv_data;
1898 pieces->inst_size = tlv_len;
1899 break;
1900 case IWL_UCODE_TLV_DATA:
1901 pieces->data = tlv_data;
1902 pieces->data_size = tlv_len;
1903 break;
1904 case IWL_UCODE_TLV_INIT:
1905 pieces->init = tlv_data;
1906 pieces->init_size = tlv_len;
1907 break;
1908 case IWL_UCODE_TLV_INIT_DATA:
1909 pieces->init_data = tlv_data;
1910 pieces->init_data_size = tlv_len;
1911 break;
1912 case IWL_UCODE_TLV_BOOT:
1913 pieces->boot = tlv_data;
1914 pieces->boot_size = tlv_len;
1915 break;
1916 case IWL_UCODE_TLV_PROBE_MAX_LEN:
Johannes Berg704da532010-07-14 09:34:50 -07001917 if (tlv_len != sizeof(u32))
1918 goto invalid_tlv_len;
1919 capa->max_probe_length =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001920 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergdd7a2502010-04-28 23:33:10 -07001921 break;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001922 case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
Johannes Berg704da532010-07-14 09:34:50 -07001923 if (tlv_len != sizeof(u32))
1924 goto invalid_tlv_len;
1925 pieces->init_evtlog_ptr =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001926 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -07001927 break;
1928 case IWL_UCODE_TLV_INIT_EVTLOG_SIZE:
Johannes Berg704da532010-07-14 09:34:50 -07001929 if (tlv_len != sizeof(u32))
1930 goto invalid_tlv_len;
1931 pieces->init_evtlog_size =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001932 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -07001933 break;
1934 case IWL_UCODE_TLV_INIT_ERRLOG_PTR:
Johannes Berg704da532010-07-14 09:34:50 -07001935 if (tlv_len != sizeof(u32))
1936 goto invalid_tlv_len;
1937 pieces->init_errlog_ptr =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001938 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -07001939 break;
1940 case IWL_UCODE_TLV_RUNT_EVTLOG_PTR:
Johannes Berg704da532010-07-14 09:34:50 -07001941 if (tlv_len != sizeof(u32))
1942 goto invalid_tlv_len;
1943 pieces->inst_evtlog_ptr =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001944 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -07001945 break;
1946 case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE:
Johannes Berg704da532010-07-14 09:34:50 -07001947 if (tlv_len != sizeof(u32))
1948 goto invalid_tlv_len;
1949 pieces->inst_evtlog_size =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001950 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -07001951 break;
1952 case IWL_UCODE_TLV_RUNT_ERRLOG_PTR:
Johannes Berg704da532010-07-14 09:34:50 -07001953 if (tlv_len != sizeof(u32))
1954 goto invalid_tlv_len;
1955 pieces->inst_errlog_ptr =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001956 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -07001957 break;
Wey-Yi Guyc8312fa2010-06-28 13:05:17 -07001958 case IWL_UCODE_TLV_ENHANCE_SENS_TBL:
1959 if (tlv_len)
Johannes Berg704da532010-07-14 09:34:50 -07001960 goto invalid_tlv_len;
1961 priv->enhance_sensitivity_table = true;
Wey-Yi Guyc8312fa2010-06-28 13:05:17 -07001962 break;
Wey-Yi Guy6a822d02010-07-13 17:13:15 -07001963 case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE:
Johannes Berg704da532010-07-14 09:34:50 -07001964 if (tlv_len != sizeof(u32))
1965 goto invalid_tlv_len;
1966 capa->standard_phy_calibration_size =
Wey-Yi Guy6a822d02010-07-13 17:13:15 -07001967 le32_to_cpup((__le32 *)tlv_data);
1968 break;
Johannes Bergdd7a2502010-04-28 23:33:10 -07001969 default:
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001970 IWL_WARN(priv, "unknown TLV: %d\n", tlv_type);
Johannes Bergdd7a2502010-04-28 23:33:10 -07001971 break;
1972 }
1973 }
1974
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001975 if (len) {
1976 IWL_ERR(priv, "invalid TLV after parsing: %zd\n", len);
1977 iwl_print_hex_dump(priv, IWL_DL_FW, (u8 *)data, len);
Johannes Berg704da532010-07-14 09:34:50 -07001978 return -EINVAL;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001979 }
Johannes Bergdd7a2502010-04-28 23:33:10 -07001980
Johannes Berg704da532010-07-14 09:34:50 -07001981 return 0;
1982
1983 invalid_tlv_len:
1984 IWL_ERR(priv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len);
1985 iwl_print_hex_dump(priv, IWL_DL_FW, tlv_data, tlv_len);
1986
1987 return -EINVAL;
Johannes Bergdd7a2502010-04-28 23:33:10 -07001988}
1989
Johannes Bergb08dfd02010-01-29 11:54:56 -08001990/**
1991 * iwl_ucode_callback - callback when firmware was loaded
1992 *
1993 * If loaded successfully, copies the firmware into buffers
1994 * for the card to fetch (via DMA).
1995 */
1996static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
1997{
1998 struct iwl_priv *priv = context;
1999 struct iwl_ucode_header *ucode;
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002000 int err;
2001 struct iwlagn_firmware_pieces pieces;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002002 const unsigned int api_max = priv->cfg->ucode_api_max;
2003 const unsigned int api_min = priv->cfg->ucode_api_min;
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002004 u32 api_ver;
Johannes Berg3e4de762010-04-28 12:09:12 -07002005 char buildstr[25];
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002006 u32 build;
Johannes Bergdd7a2502010-04-28 23:33:10 -07002007 struct iwlagn_ucode_capabilities ucode_capa = {
2008 .max_probe_length = 200,
Wey-Yi Guy6a822d02010-07-13 17:13:15 -07002009 .standard_phy_calibration_size =
2010 IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE,
Johannes Bergdd7a2502010-04-28 23:33:10 -07002011 };
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002012
2013 memset(&pieces, 0, sizeof(pieces));
Zhu Yib481de92007-09-25 17:54:57 -07002014
Johannes Bergb08dfd02010-01-29 11:54:56 -08002015 if (!ucode_raw) {
Jay Sternberg39396082010-08-12 10:24:07 -07002016 if (priv->fw_index <= priv->cfg->ucode_api_max)
2017 IWL_ERR(priv,
2018 "request for firmware file '%s' failed.\n",
2019 priv->firmware_name);
Johannes Bergb08dfd02010-01-29 11:54:56 -08002020 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07002021 }
2022
Johannes Bergb08dfd02010-01-29 11:54:56 -08002023 IWL_DEBUG_INFO(priv, "Loaded firmware file '%s' (%zd bytes).\n",
2024 priv->firmware_name, ucode_raw->size);
Zhu Yib481de92007-09-25 17:54:57 -07002025
Johannes Berg22adba22010-04-28 12:09:14 -07002026 /* Make sure that we got at least the API version number */
2027 if (ucode_raw->size < 4) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002028 IWL_ERR(priv, "File size way too small!\n");
Johannes Bergb08dfd02010-01-29 11:54:56 -08002029 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07002030 }
2031
2032 /* Data from ucode file: header followed by uCode images */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002033 ucode = (struct iwl_ucode_header *)ucode_raw->data;
Zhu Yib481de92007-09-25 17:54:57 -07002034
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002035 if (ucode->ver)
2036 err = iwlagn_load_legacy_firmware(priv, ucode_raw, &pieces);
2037 else
Johannes Bergdd7a2502010-04-28 23:33:10 -07002038 err = iwlagn_load_firmware(priv, ucode_raw, &pieces,
2039 &ucode_capa);
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002040
2041 if (err)
2042 goto try_again;
2043
Reinette Chatrea0987a82008-12-02 12:14:06 -08002044 api_ver = IWL_UCODE_API(priv->ucode_ver);
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002045 build = pieces.build;
Zhu Yib481de92007-09-25 17:54:57 -07002046
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002047 /*
2048 * api_ver should match the api version forming part of the
Reinette Chatrea0987a82008-12-02 12:14:06 -08002049 * firmware filename ... but we don't check for that and only rely
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002050 * on the API version read from firmware header from here on forward
2051 */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002052 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002053 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002054 "Driver supports v%u, firmware is v%u.\n",
2055 api_max, api_ver);
Johannes Bergb08dfd02010-01-29 11:54:56 -08002056 goto try_again;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002057 }
Johannes Bergb08dfd02010-01-29 11:54:56 -08002058
Reinette Chatrea0987a82008-12-02 12:14:06 -08002059 if (api_ver != api_max)
Tomas Winkler978785a2008-12-19 10:37:31 +08002060 IWL_ERR(priv, "Firmware has old API version. Expected v%u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002061 "got v%u. New firmware can be obtained "
2062 "from http://www.intellinuxwireless.org.\n",
2063 api_max, api_ver);
2064
Johannes Berg3e4de762010-04-28 12:09:12 -07002065 if (build)
Jay Sternberg39396082010-08-12 10:24:07 -07002066 sprintf(buildstr, " build %u%s", build,
2067 (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
2068 ? " (EXP)" : "");
Johannes Berg3e4de762010-04-28 12:09:12 -07002069 else
2070 buildstr[0] = '\0';
Reinette Chatrea0987a82008-12-02 12:14:06 -08002071
Johannes Berg3e4de762010-04-28 12:09:12 -07002072 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u%s\n",
Reinette Chatre5ebeb5a2009-10-30 14:36:04 -07002073 IWL_UCODE_MAJOR(priv->ucode_ver),
2074 IWL_UCODE_MINOR(priv->ucode_ver),
2075 IWL_UCODE_API(priv->ucode_ver),
Johannes Berg3e4de762010-04-28 12:09:12 -07002076 IWL_UCODE_SERIAL(priv->ucode_ver),
2077 buildstr);
Reinette Chatre5ebeb5a2009-10-30 14:36:04 -07002078
Johannes Berg3e4de762010-04-28 12:09:12 -07002079 snprintf(priv->hw->wiphy->fw_version,
2080 sizeof(priv->hw->wiphy->fw_version),
2081 "%u.%u.%u.%u%s",
2082 IWL_UCODE_MAJOR(priv->ucode_ver),
2083 IWL_UCODE_MINOR(priv->ucode_ver),
2084 IWL_UCODE_API(priv->ucode_ver),
2085 IWL_UCODE_SERIAL(priv->ucode_ver),
2086 buildstr);
Zhu Yib481de92007-09-25 17:54:57 -07002087
Johannes Bergb08dfd02010-01-29 11:54:56 -08002088 /*
2089 * For any of the failures below (before allocating pci memory)
2090 * we will try to load a version with a smaller API -- maybe the
2091 * user just got a corrupted version of the latest API.
2092 */
2093
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002094 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
2095 priv->ucode_ver);
2096 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %Zd\n",
2097 pieces.inst_size);
2098 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %Zd\n",
2099 pieces.data_size);
2100 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %Zd\n",
2101 pieces.init_size);
2102 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %Zd\n",
2103 pieces.init_data_size);
2104 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %Zd\n",
2105 pieces.boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07002106
2107 /* Verify that uCode images will fit in card's SRAM */
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002108 if (pieces.inst_size > priv->hw_params.max_inst_size) {
2109 IWL_ERR(priv, "uCode instr len %Zd too large to fit in\n",
2110 pieces.inst_size);
Johannes Bergb08dfd02010-01-29 11:54:56 -08002111 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07002112 }
2113
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002114 if (pieces.data_size > priv->hw_params.max_data_size) {
2115 IWL_ERR(priv, "uCode data len %Zd too large to fit in\n",
2116 pieces.data_size);
Johannes Bergb08dfd02010-01-29 11:54:56 -08002117 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07002118 }
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002119
2120 if (pieces.init_size > priv->hw_params.max_inst_size) {
2121 IWL_ERR(priv, "uCode init instr len %Zd too large to fit in\n",
2122 pieces.init_size);
Johannes Bergb08dfd02010-01-29 11:54:56 -08002123 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07002124 }
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002125
2126 if (pieces.init_data_size > priv->hw_params.max_data_size) {
2127 IWL_ERR(priv, "uCode init data len %Zd too large to fit in\n",
2128 pieces.init_data_size);
Johannes Bergb08dfd02010-01-29 11:54:56 -08002129 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07002130 }
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002131
2132 if (pieces.boot_size > priv->hw_params.max_bsm_size) {
2133 IWL_ERR(priv, "uCode boot instr len %Zd too large to fit in\n",
2134 pieces.boot_size);
Johannes Bergb08dfd02010-01-29 11:54:56 -08002135 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07002136 }
2137
2138 /* Allocate ucode buffers for card's bus-master loading ... */
2139
2140 /* Runtime instructions and 2 copies of data:
2141 * 1) unmodified from disk
2142 * 2) backup cache for save/restore during power-downs */
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002143 priv->ucode_code.len = pieces.inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002144 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07002145
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002146 priv->ucode_data.len = pieces.data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002147 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07002148
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002149 priv->ucode_data_backup.len = pieces.data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002150 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07002151
Zhu, Yi1f304e42009-01-23 13:45:22 -08002152 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
2153 !priv->ucode_data_backup.v_addr)
2154 goto err_pci_alloc;
2155
Zhu Yib481de92007-09-25 17:54:57 -07002156 /* Initialization instructions and data */
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002157 if (pieces.init_size && pieces.init_data_size) {
2158 priv->ucode_init.len = pieces.init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002159 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Zhu Yib481de92007-09-25 17:54:57 -07002160
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002161 priv->ucode_init_data.len = pieces.init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002162 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002163
2164 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
2165 goto err_pci_alloc;
2166 }
Zhu Yib481de92007-09-25 17:54:57 -07002167
2168 /* Bootstrap (instructions only, no data) */
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002169 if (pieces.boot_size) {
2170 priv->ucode_boot.len = pieces.boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002171 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07002172
Tomas Winkler90e759d2007-11-29 11:09:41 +08002173 if (!priv->ucode_boot.v_addr)
2174 goto err_pci_alloc;
2175 }
Zhu Yib481de92007-09-25 17:54:57 -07002176
Johannes Bergb2e640d2010-05-05 23:24:54 -07002177 /* Now that we can no longer fail, copy information */
2178
2179 /*
2180 * The (size - 16) / 12 formula is based on the information recorded
2181 * for each event, which is of mode 1 (including timestamp) for all
2182 * new microcodes that include this information.
2183 */
2184 priv->_agn.init_evtlog_ptr = pieces.init_evtlog_ptr;
2185 if (pieces.init_evtlog_size)
2186 priv->_agn.init_evtlog_size = (pieces.init_evtlog_size - 16)/12;
2187 else
2188 priv->_agn.init_evtlog_size = priv->cfg->max_event_log_size;
2189 priv->_agn.init_errlog_ptr = pieces.init_errlog_ptr;
2190 priv->_agn.inst_evtlog_ptr = pieces.inst_evtlog_ptr;
2191 if (pieces.inst_evtlog_size)
2192 priv->_agn.inst_evtlog_size = (pieces.inst_evtlog_size - 16)/12;
2193 else
2194 priv->_agn.inst_evtlog_size = priv->cfg->max_event_log_size;
2195 priv->_agn.inst_errlog_ptr = pieces.inst_errlog_ptr;
2196
Zhu Yib481de92007-09-25 17:54:57 -07002197 /* Copy images into buffers for card's bus-master reads ... */
2198
2199 /* Runtime instructions (first block of data in file) */
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002200 IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode instr len %Zd\n",
2201 pieces.inst_size);
2202 memcpy(priv->ucode_code.v_addr, pieces.inst, pieces.inst_size);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002203
Tomas Winklere1623442009-01-27 14:27:56 -08002204 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002205 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
2206
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002207 /*
2208 * Runtime data
2209 * NOTE: Copy into backup buffer will be done in iwl_up()
2210 */
2211 IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode data len %Zd\n",
2212 pieces.data_size);
2213 memcpy(priv->ucode_data.v_addr, pieces.data, pieces.data_size);
2214 memcpy(priv->ucode_data_backup.v_addr, pieces.data, pieces.data_size);
Zhu Yib481de92007-09-25 17:54:57 -07002215
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002216 /* Initialization instructions */
2217 if (pieces.init_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08002218 IWL_DEBUG_INFO(priv, "Copying (but not loading) init instr len %Zd\n",
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002219 pieces.init_size);
2220 memcpy(priv->ucode_init.v_addr, pieces.init, pieces.init_size);
Zhu Yib481de92007-09-25 17:54:57 -07002221 }
2222
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002223 /* Initialization data */
2224 if (pieces.init_data_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08002225 IWL_DEBUG_INFO(priv, "Copying (but not loading) init data len %Zd\n",
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002226 pieces.init_data_size);
2227 memcpy(priv->ucode_init_data.v_addr, pieces.init_data,
2228 pieces.init_data_size);
Zhu Yib481de92007-09-25 17:54:57 -07002229 }
2230
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002231 /* Bootstrap instructions */
2232 IWL_DEBUG_INFO(priv, "Copying (but not loading) boot instr len %Zd\n",
2233 pieces.boot_size);
2234 memcpy(priv->ucode_boot.v_addr, pieces.boot, pieces.boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07002235
Wey-Yi Guy6a822d02010-07-13 17:13:15 -07002236 /*
2237 * figure out the offset of chain noise reset and gain commands
2238 * base on the size of standard phy calibration commands table size
2239 */
2240 if (ucode_capa.standard_phy_calibration_size >
2241 IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
2242 ucode_capa.standard_phy_calibration_size =
2243 IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
2244
2245 priv->_agn.phy_calib_chain_noise_reset_cmd =
2246 ucode_capa.standard_phy_calibration_size;
2247 priv->_agn.phy_calib_chain_noise_gain_cmd =
2248 ucode_capa.standard_phy_calibration_size + 1;
2249
Johannes Bergb08dfd02010-01-29 11:54:56 -08002250 /**************************************************
2251 * This is still part of probe() in a sense...
2252 *
2253 * 9. Setup and register with mac80211 and debugfs
2254 **************************************************/
Johannes Bergdd7a2502010-04-28 23:33:10 -07002255 err = iwl_mac_setup_register(priv, &ucode_capa);
Johannes Bergb08dfd02010-01-29 11:54:56 -08002256 if (err)
2257 goto out_unbind;
2258
2259 err = iwl_dbgfs_register(priv, DRV_NAME);
2260 if (err)
2261 IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
2262
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07002263 err = sysfs_create_group(&priv->pci_dev->dev.kobj,
2264 &iwl_attribute_group);
2265 if (err) {
2266 IWL_ERR(priv, "failed to create sysfs device attributes\n");
2267 goto out_unbind;
2268 }
2269
Zhu Yib481de92007-09-25 17:54:57 -07002270 /* We have our copies now, allow OS release its copies */
2271 release_firmware(ucode_raw);
Reinette Chatrea15707d2010-05-10 15:08:11 -07002272 complete(&priv->_agn.firmware_loading_complete);
Johannes Bergb08dfd02010-01-29 11:54:56 -08002273 return;
2274
2275 try_again:
2276 /* try next, if any */
2277 if (iwl_request_firmware(priv, false))
2278 goto out_unbind;
2279 release_firmware(ucode_raw);
2280 return;
Zhu Yib481de92007-09-25 17:54:57 -07002281
2282 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002283 IWL_ERR(priv, "failed to allocate pci memory\n");
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002284 iwl_dealloc_ucode_pci(priv);
Johannes Bergb08dfd02010-01-29 11:54:56 -08002285 out_unbind:
Reinette Chatrea15707d2010-05-10 15:08:11 -07002286 complete(&priv->_agn.firmware_loading_complete);
Johannes Bergb08dfd02010-01-29 11:54:56 -08002287 device_release_driver(&priv->pci_dev->dev);
Zhu Yib481de92007-09-25 17:54:57 -07002288 release_firmware(ucode_raw);
Zhu Yib481de92007-09-25 17:54:57 -07002289}
2290
Reinette Chatreb7a79402009-09-25 14:24:23 -07002291static const char *desc_lookup_text[] = {
2292 "OK",
2293 "FAIL",
2294 "BAD_PARAM",
2295 "BAD_CHECKSUM",
2296 "NMI_INTERRUPT_WDG",
2297 "SYSASSERT",
2298 "FATAL_ERROR",
2299 "BAD_COMMAND",
2300 "HW_ERROR_TUNE_LOCK",
2301 "HW_ERROR_TEMPERATURE",
2302 "ILLEGAL_CHAN_FREQ",
2303 "VCC_NOT_STABLE",
2304 "FH_ERROR",
2305 "NMI_INTERRUPT_HOST",
2306 "NMI_INTERRUPT_ACTION_PT",
2307 "NMI_INTERRUPT_UNKNOWN",
2308 "UCODE_VERSION_MISMATCH",
2309 "HW_ERROR_ABS_LOCK",
2310 "HW_ERROR_CAL_LOCK_FAIL",
2311 "NMI_INTERRUPT_INST_ACTION_PT",
2312 "NMI_INTERRUPT_DATA_ACTION_PT",
2313 "NMI_TRM_HW_ER",
2314 "NMI_INTERRUPT_TRM",
2315 "NMI_INTERRUPT_BREAK_POINT"
2316 "DEBUG_0",
2317 "DEBUG_1",
2318 "DEBUG_2",
2319 "DEBUG_3",
Reinette Chatreb7a79402009-09-25 14:24:23 -07002320};
2321
Jay Sternberg4b586452010-07-02 15:49:10 -07002322static struct { char *name; u8 num; } advanced_lookup[] = {
2323 { "NMI_INTERRUPT_WDG", 0x34 },
2324 { "SYSASSERT", 0x35 },
2325 { "UCODE_VERSION_MISMATCH", 0x37 },
2326 { "BAD_COMMAND", 0x38 },
2327 { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
2328 { "FATAL_ERROR", 0x3D },
2329 { "NMI_TRM_HW_ERR", 0x46 },
2330 { "NMI_INTERRUPT_TRM", 0x4C },
2331 { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
2332 { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
2333 { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
2334 { "NMI_INTERRUPT_HOST", 0x66 },
2335 { "NMI_INTERRUPT_ACTION_PT", 0x7C },
2336 { "NMI_INTERRUPT_UNKNOWN", 0x84 },
2337 { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
2338 { "ADVANCED_SYSASSERT", 0 },
2339};
2340
2341static const char *desc_lookup(u32 num)
Reinette Chatreb7a79402009-09-25 14:24:23 -07002342{
Jay Sternberg4b586452010-07-02 15:49:10 -07002343 int i;
2344 int max = ARRAY_SIZE(desc_lookup_text);
Reinette Chatreb7a79402009-09-25 14:24:23 -07002345
Jay Sternberg4b586452010-07-02 15:49:10 -07002346 if (num < max)
2347 return desc_lookup_text[num];
Reinette Chatreb7a79402009-09-25 14:24:23 -07002348
Jay Sternberg4b586452010-07-02 15:49:10 -07002349 max = ARRAY_SIZE(advanced_lookup) - 1;
2350 for (i = 0; i < max; i++) {
2351 if (advanced_lookup[i].num == num)
2352 break;;
2353 }
2354 return advanced_lookup[i].name;
Reinette Chatreb7a79402009-09-25 14:24:23 -07002355}
2356
2357#define ERROR_START_OFFSET (1 * sizeof(u32))
2358#define ERROR_ELEM_SIZE (7 * sizeof(u32))
2359
2360void iwl_dump_nic_error_log(struct iwl_priv *priv)
2361{
2362 u32 data2, line;
2363 u32 desc, time, count, base, data1;
2364 u32 blink1, blink2, ilink1, ilink2;
Wey-Yi Guy461ef382010-03-30 17:57:53 -07002365 u32 pc, hcmd;
Reinette Chatreb7a79402009-09-25 14:24:23 -07002366
Johannes Bergb2e640d2010-05-05 23:24:54 -07002367 if (priv->ucode_type == UCODE_INIT) {
Reinette Chatreb7a79402009-09-25 14:24:23 -07002368 base = le32_to_cpu(priv->card_alive_init.error_event_table_ptr);
Johannes Bergb2e640d2010-05-05 23:24:54 -07002369 if (!base)
2370 base = priv->_agn.init_errlog_ptr;
2371 } else {
Reinette Chatreb7a79402009-09-25 14:24:23 -07002372 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
Johannes Bergb2e640d2010-05-05 23:24:54 -07002373 if (!base)
2374 base = priv->_agn.inst_errlog_ptr;
2375 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07002376
2377 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
Wey-Yi Guy212fb572009-12-02 12:53:00 -08002378 IWL_ERR(priv,
2379 "Not valid error log pointer 0x%08X for %s uCode\n",
2380 base, (priv->ucode_type == UCODE_INIT) ? "Init" : "RT");
Reinette Chatreb7a79402009-09-25 14:24:23 -07002381 return;
2382 }
2383
2384 count = iwl_read_targ_mem(priv, base);
2385
2386 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
2387 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
2388 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
2389 priv->status, count);
2390 }
2391
2392 desc = iwl_read_targ_mem(priv, base + 1 * sizeof(u32));
Wey-Yi Guy461ef382010-03-30 17:57:53 -07002393 pc = iwl_read_targ_mem(priv, base + 2 * sizeof(u32));
Reinette Chatreb7a79402009-09-25 14:24:23 -07002394 blink1 = iwl_read_targ_mem(priv, base + 3 * sizeof(u32));
2395 blink2 = iwl_read_targ_mem(priv, base + 4 * sizeof(u32));
2396 ilink1 = iwl_read_targ_mem(priv, base + 5 * sizeof(u32));
2397 ilink2 = iwl_read_targ_mem(priv, base + 6 * sizeof(u32));
2398 data1 = iwl_read_targ_mem(priv, base + 7 * sizeof(u32));
2399 data2 = iwl_read_targ_mem(priv, base + 8 * sizeof(u32));
2400 line = iwl_read_targ_mem(priv, base + 9 * sizeof(u32));
2401 time = iwl_read_targ_mem(priv, base + 11 * sizeof(u32));
Wey-Yi Guy461ef382010-03-30 17:57:53 -07002402 hcmd = iwl_read_targ_mem(priv, base + 22 * sizeof(u32));
Reinette Chatreb7a79402009-09-25 14:24:23 -07002403
Johannes Bergbe1a71a2009-10-02 13:44:02 -07002404 trace_iwlwifi_dev_ucode_error(priv, desc, time, data1, data2, line,
2405 blink1, blink2, ilink1, ilink2);
2406
Jay Sternberg87563712010-06-14 14:40:40 -07002407 IWL_ERR(priv, "Desc Time "
Reinette Chatreb7a79402009-09-25 14:24:23 -07002408 "data1 data2 line\n");
Jay Sternberg87563712010-06-14 14:40:40 -07002409 IWL_ERR(priv, "%-28s (0x%04X) %010u 0x%08X 0x%08X %u\n",
Reinette Chatreb7a79402009-09-25 14:24:23 -07002410 desc_lookup(desc), desc, time, data1, data2, line);
Wey-Yi Guy461ef382010-03-30 17:57:53 -07002411 IWL_ERR(priv, "pc blink1 blink2 ilink1 ilink2 hcmd\n");
2412 IWL_ERR(priv, "0x%05X 0x%05X 0x%05X 0x%05X 0x%05X 0x%05X\n",
2413 pc, blink1, blink2, ilink1, ilink2, hcmd);
Reinette Chatreb7a79402009-09-25 14:24:23 -07002414}
2415
2416#define EVENT_START_OFFSET (4 * sizeof(u32))
2417
2418/**
2419 * iwl_print_event_log - Dump error event log to syslog
2420 *
2421 */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002422static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
2423 u32 num_events, u32 mode,
2424 int pos, char **buf, size_t bufsz)
Reinette Chatreb7a79402009-09-25 14:24:23 -07002425{
2426 u32 i;
2427 u32 base; /* SRAM byte address of event log header */
2428 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
2429 u32 ptr; /* SRAM byte address of log data */
2430 u32 ev, time, data; /* event log data */
Ben Cahille5854472009-11-06 14:52:58 -08002431 unsigned long reg_flags;
Reinette Chatreb7a79402009-09-25 14:24:23 -07002432
2433 if (num_events == 0)
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002434 return pos;
Johannes Bergb2e640d2010-05-05 23:24:54 -07002435
2436 if (priv->ucode_type == UCODE_INIT) {
Reinette Chatreb7a79402009-09-25 14:24:23 -07002437 base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
Johannes Bergb2e640d2010-05-05 23:24:54 -07002438 if (!base)
2439 base = priv->_agn.init_evtlog_ptr;
2440 } else {
Reinette Chatreb7a79402009-09-25 14:24:23 -07002441 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Johannes Bergb2e640d2010-05-05 23:24:54 -07002442 if (!base)
2443 base = priv->_agn.inst_evtlog_ptr;
2444 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07002445
2446 if (mode == 0)
2447 event_size = 2 * sizeof(u32);
2448 else
2449 event_size = 3 * sizeof(u32);
2450
2451 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
2452
Ben Cahille5854472009-11-06 14:52:58 -08002453 /* Make sure device is powered up for SRAM reads */
2454 spin_lock_irqsave(&priv->reg_lock, reg_flags);
2455 iwl_grab_nic_access(priv);
2456
2457 /* Set starting address; reads will auto-increment */
2458 _iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, ptr);
2459 rmb();
2460
Reinette Chatreb7a79402009-09-25 14:24:23 -07002461 /* "time" is actually "data" for mode 0 (no timestamp).
2462 * place event id # at far right for easier visual parsing. */
2463 for (i = 0; i < num_events; i++) {
Ben Cahille5854472009-11-06 14:52:58 -08002464 ev = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
2465 time = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Reinette Chatreb7a79402009-09-25 14:24:23 -07002466 if (mode == 0) {
2467 /* data, ev */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002468 if (bufsz) {
2469 pos += scnprintf(*buf + pos, bufsz - pos,
2470 "EVT_LOG:0x%08x:%04u\n",
2471 time, ev);
2472 } else {
2473 trace_iwlwifi_dev_ucode_event(priv, 0,
2474 time, ev);
2475 IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n",
2476 time, ev);
2477 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07002478 } else {
Ben Cahille5854472009-11-06 14:52:58 -08002479 data = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002480 if (bufsz) {
2481 pos += scnprintf(*buf + pos, bufsz - pos,
2482 "EVT_LOGT:%010u:0x%08x:%04u\n",
2483 time, data, ev);
2484 } else {
2485 IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
Reinette Chatreb7a79402009-09-25 14:24:23 -07002486 time, data, ev);
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002487 trace_iwlwifi_dev_ucode_event(priv, time,
2488 data, ev);
2489 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07002490 }
2491 }
Ben Cahille5854472009-11-06 14:52:58 -08002492
2493 /* Allow device to power down */
2494 iwl_release_nic_access(priv);
2495 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002496 return pos;
Reinette Chatreb7a79402009-09-25 14:24:23 -07002497}
2498
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002499/**
2500 * iwl_print_last_event_logs - Dump the newest # of event log to syslog
2501 */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002502static int iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
2503 u32 num_wraps, u32 next_entry,
2504 u32 size, u32 mode,
2505 int pos, char **buf, size_t bufsz)
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002506{
2507 /*
2508 * display the newest DEFAULT_LOG_ENTRIES entries
2509 * i.e the entries just before the next ont that uCode would fill.
2510 */
2511 if (num_wraps) {
2512 if (next_entry < size) {
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002513 pos = iwl_print_event_log(priv,
2514 capacity - (size - next_entry),
2515 size - next_entry, mode,
2516 pos, buf, bufsz);
2517 pos = iwl_print_event_log(priv, 0,
2518 next_entry, mode,
2519 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002520 } else
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002521 pos = iwl_print_event_log(priv, next_entry - size,
2522 size, mode, pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002523 } else {
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002524 if (next_entry < size) {
2525 pos = iwl_print_event_log(priv, 0, next_entry,
2526 mode, pos, buf, bufsz);
2527 } else {
2528 pos = iwl_print_event_log(priv, next_entry - size,
2529 size, mode, pos, buf, bufsz);
2530 }
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002531 }
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002532 return pos;
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002533}
2534
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002535#define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
2536
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002537int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
2538 char **buf, bool display)
Reinette Chatreb7a79402009-09-25 14:24:23 -07002539{
2540 u32 base; /* SRAM byte address of event log header */
2541 u32 capacity; /* event log capacity in # entries */
2542 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
2543 u32 num_wraps; /* # times uCode wrapped to top of log */
2544 u32 next_entry; /* index of next entry to be written by uCode */
2545 u32 size; /* # entries that we'll print */
Johannes Bergb2e640d2010-05-05 23:24:54 -07002546 u32 logsize;
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002547 int pos = 0;
2548 size_t bufsz = 0;
Reinette Chatreb7a79402009-09-25 14:24:23 -07002549
Johannes Bergb2e640d2010-05-05 23:24:54 -07002550 if (priv->ucode_type == UCODE_INIT) {
Reinette Chatreb7a79402009-09-25 14:24:23 -07002551 base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
Johannes Bergb2e640d2010-05-05 23:24:54 -07002552 logsize = priv->_agn.init_evtlog_size;
2553 if (!base)
2554 base = priv->_agn.init_evtlog_ptr;
2555 } else {
Reinette Chatreb7a79402009-09-25 14:24:23 -07002556 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Johannes Bergb2e640d2010-05-05 23:24:54 -07002557 logsize = priv->_agn.inst_evtlog_size;
2558 if (!base)
2559 base = priv->_agn.inst_evtlog_ptr;
2560 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07002561
2562 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
Wey-Yi Guy212fb572009-12-02 12:53:00 -08002563 IWL_ERR(priv,
2564 "Invalid event log pointer 0x%08X for %s uCode\n",
2565 base, (priv->ucode_type == UCODE_INIT) ? "Init" : "RT");
Wey-Yi Guy937c3972010-01-15 13:43:36 -08002566 return -EINVAL;
Reinette Chatreb7a79402009-09-25 14:24:23 -07002567 }
2568
2569 /* event log header */
2570 capacity = iwl_read_targ_mem(priv, base);
2571 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
2572 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
2573 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
2574
Johannes Bergb2e640d2010-05-05 23:24:54 -07002575 if (capacity > logsize) {
Ben Cahill84c40692009-11-06 14:52:57 -08002576 IWL_ERR(priv, "Log capacity %d is bogus, limit to %d entries\n",
Johannes Bergb2e640d2010-05-05 23:24:54 -07002577 capacity, logsize);
2578 capacity = logsize;
Ben Cahill84c40692009-11-06 14:52:57 -08002579 }
2580
Johannes Bergb2e640d2010-05-05 23:24:54 -07002581 if (next_entry > logsize) {
Ben Cahill84c40692009-11-06 14:52:57 -08002582 IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
Johannes Bergb2e640d2010-05-05 23:24:54 -07002583 next_entry, logsize);
2584 next_entry = logsize;
Ben Cahill84c40692009-11-06 14:52:57 -08002585 }
2586
Reinette Chatreb7a79402009-09-25 14:24:23 -07002587 size = num_wraps ? capacity : next_entry;
2588
2589 /* bail out if nothing in log */
2590 if (size == 0) {
2591 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002592 return pos;
Reinette Chatreb7a79402009-09-25 14:24:23 -07002593 }
2594
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002595#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guy521d9bc2009-12-10 14:37:23 -08002596 if (!(iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) && !full_log)
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002597 size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
2598 ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
2599#else
2600 size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
2601 ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
Reinette Chatreb7a79402009-09-25 14:24:23 -07002602#endif
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002603 IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n",
2604 size);
2605
2606#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002607 if (display) {
2608 if (full_log)
2609 bufsz = capacity * 48;
2610 else
2611 bufsz = size * 48;
2612 *buf = kmalloc(bufsz, GFP_KERNEL);
2613 if (!*buf)
Wey-Yi Guy937c3972010-01-15 13:43:36 -08002614 return -ENOMEM;
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002615 }
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002616 if ((iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) || full_log) {
2617 /*
2618 * if uCode has wrapped back to top of log,
2619 * start at the oldest entry,
2620 * i.e the next one that uCode would fill.
2621 */
2622 if (num_wraps)
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002623 pos = iwl_print_event_log(priv, next_entry,
2624 capacity - next_entry, mode,
2625 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002626 /* (then/else) start at top of log */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002627 pos = iwl_print_event_log(priv, 0,
2628 next_entry, mode, pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002629 } else
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002630 pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
2631 next_entry, size, mode,
2632 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002633#else
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002634 pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
2635 next_entry, size, mode,
2636 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002637#endif
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002638 return pos;
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002639}
Reinette Chatreb7a79402009-09-25 14:24:23 -07002640
Wey-Yi Guy0975cc82010-07-31 08:34:07 -07002641static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
2642{
2643 struct iwl_ct_kill_config cmd;
2644 struct iwl_ct_kill_throttling_config adv_cmd;
2645 unsigned long flags;
2646 int ret = 0;
2647
2648 spin_lock_irqsave(&priv->lock, flags);
2649 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
2650 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
2651 spin_unlock_irqrestore(&priv->lock, flags);
2652 priv->thermal_throttle.ct_kill_toggle = false;
2653
2654 if (priv->cfg->support_ct_kill_exit) {
2655 adv_cmd.critical_temperature_enter =
2656 cpu_to_le32(priv->hw_params.ct_kill_threshold);
2657 adv_cmd.critical_temperature_exit =
2658 cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
2659
2660 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
2661 sizeof(adv_cmd), &adv_cmd);
2662 if (ret)
2663 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
2664 else
2665 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
2666 "succeeded, "
2667 "critical temperature enter is %d,"
2668 "exit is %d\n",
2669 priv->hw_params.ct_kill_threshold,
2670 priv->hw_params.ct_kill_exit_threshold);
2671 } else {
2672 cmd.critical_temperature_R =
2673 cpu_to_le32(priv->hw_params.ct_kill_threshold);
2674
2675 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
2676 sizeof(cmd), &cmd);
2677 if (ret)
2678 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
2679 else
2680 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
2681 "succeeded, "
2682 "critical temperature is %d\n",
2683 priv->hw_params.ct_kill_threshold);
2684 }
2685}
2686
Zhu Yib481de92007-09-25 17:54:57 -07002687/**
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002688 * iwl_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002689 * from protocol/runtime uCode (initialization uCode's
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002690 * Alive gets handled by iwl_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07002691 */
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002692static void iwl_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002693{
Tomas Winkler57aab752008-04-14 21:16:03 -07002694 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002695
Tomas Winklere1623442009-01-27 14:27:56 -08002696 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002697
2698 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
2699 /* We had an error bringing up the hardware, so take it
2700 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002701 IWL_DEBUG_INFO(priv, "Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002702 goto restart;
2703 }
2704
2705 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2706 * This is a paranoid check, because we would not have gotten the
2707 * "runtime" alive if code weren't properly loaded. */
Emmanuel Grumbachb0692f22008-04-24 11:55:18 -07002708 if (iwl_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002709 /* Runtime instruction load was bad;
2710 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002711 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002712 goto restart;
2713 }
2714
Tomas Winkler57aab752008-04-14 21:16:03 -07002715 ret = priv->cfg->ops->lib->alive_notify(priv);
2716 if (ret) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002717 IWL_WARN(priv,
2718 "Could not complete ALIVE transition [ntf]: %d\n", ret);
Zhu Yib481de92007-09-25 17:54:57 -07002719 goto restart;
2720 }
2721
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002722 /* After the ALIVE response, we can send host commands to the uCode */
Zhu Yib481de92007-09-25 17:54:57 -07002723 set_bit(STATUS_ALIVE, &priv->status);
2724
Wey-Yi Guyb74e31a2010-03-01 17:23:50 -08002725 if (priv->cfg->ops->lib->recover_from_tx_stall) {
2726 /* Enable timer to monitor the driver queues */
2727 mod_timer(&priv->monitor_recover,
2728 jiffies +
2729 msecs_to_jiffies(priv->cfg->monitor_recover_period));
2730 }
2731
Tomas Winklerfee12472008-04-03 16:05:21 -07002732 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002733 return;
2734
Johannes Berg36d68252008-05-15 12:55:26 +02002735 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002736
Johannes Berg470ab2d2010-01-21 11:23:30 -08002737 priv->active_rate = IWL_RATES_MASK;
Zhu Yib481de92007-09-25 17:54:57 -07002738
Wey-Yi Guy2f748de2009-09-17 10:43:51 -07002739 /* Configure Tx antenna selection based on H/W config */
2740 if (priv->cfg->ops->hcmd->set_tx_ant)
2741 priv->cfg->ops->hcmd->set_tx_ant(priv, priv->cfg->valid_tx_ant);
2742
Tomas Winkler3109ece2008-03-28 16:33:35 -07002743 if (iwl_is_associated(priv)) {
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08002744 struct iwl_rxon_cmd *active_rxon =
2745 (struct iwl_rxon_cmd *)&priv->active_rxon;
Mohamed Abbas019fb972009-03-17 21:59:18 -07002746 /* apply any changes in staging */
2747 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07002748 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2749 } else {
2750 /* Initialize our rx_config data */
Johannes Berg1dda6d22010-04-29 04:43:06 -07002751 iwl_connection_init_rx_config(priv, NULL);
Abhijeet Kolekar45823532009-04-08 11:26:44 -07002752
2753 if (priv->cfg->ops->hcmd->set_rxon_chain)
2754 priv->cfg->ops->hcmd->set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002755 }
2756
Ben Cahill9fbab512007-11-29 11:09:47 +08002757 /* Configure Bluetooth device coexistence support */
Johannes Berg65b52bd2010-04-13 01:04:31 -07002758 priv->cfg->ops->hcmd->send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002759
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002760 iwl_reset_run_time_calib(priv);
2761
Zhu Yib481de92007-09-25 17:54:57 -07002762 /* Configure the adapter for unassociated operation */
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07002763 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002764
2765 /* At this point, the NIC is initialized and operational */
Emmanuel Grumbach47f4a582008-06-12 09:47:13 +08002766 iwl_rf_kill_ct_config(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002767
Johannes Berge932a602009-10-02 13:44:03 -07002768 iwl_leds_init(priv);
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07002769
Tomas Winklere1623442009-01-27 14:27:56 -08002770 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07002771 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002772 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07002773
Johannes Berge312c242009-08-07 15:41:51 -07002774 iwl_power_update_mode(priv, true);
Reinette Chatre7e246192010-02-18 22:58:32 -08002775 IWL_DEBUG_INFO(priv, "Updated power mode\n");
2776
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002777
Zhu Yib481de92007-09-25 17:54:57 -07002778 return;
2779
2780 restart:
2781 queue_work(priv->workqueue, &priv->restart);
2782}
2783
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002784static void iwl_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07002785
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002786static void __iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002787{
2788 unsigned long flags;
2789 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002790
Tomas Winklere1623442009-01-27 14:27:56 -08002791 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07002792
Zhu Yib481de92007-09-25 17:54:57 -07002793 if (!exit_pending)
2794 set_bit(STATUS_EXIT_PENDING, &priv->status);
2795
Stanislaw Gruszkab62177a2010-08-20 15:23:47 +02002796 /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
2797 * to prevent rearm timer */
2798 if (priv->cfg->ops->lib->recover_from_tx_stall)
2799 del_timer_sync(&priv->monitor_recover);
2800
Johannes Berg2c810cc2010-04-29 00:53:29 -07002801 iwl_clear_ucode_stations(priv);
2802 iwl_dealloc_bcast_station(priv);
Johannes Bergdb125c72010-05-07 01:49:15 -07002803 iwl_clear_driver_stations(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002804
Johannes Berga1174132010-08-23 07:56:59 -07002805 /* reset BT coex data */
2806 priv->bt_traffic_load = 0;
2807 priv->bt_sco_active = false;
Wey-Yi Guybee008b2010-08-23 07:57:04 -07002808 priv->bt_full_concurrent = false;
2809 priv->bt_ci_compliance = 0;
Johannes Berga1174132010-08-23 07:56:59 -07002810
Zhu Yib481de92007-09-25 17:54:57 -07002811 /* Unblock any waiting calls */
2812 wake_up_interruptible_all(&priv->wait_command_queue);
2813
Zhu Yib481de92007-09-25 17:54:57 -07002814 /* Wipe out the EXIT_PENDING status bit if we are not actually
2815 * exiting the module */
2816 if (!exit_pending)
2817 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2818
2819 /* stop and reset the on-board processor */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002820 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07002821
2822 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002823 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002824 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002825 spin_unlock_irqrestore(&priv->lock, flags);
2826 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002827
2828 if (priv->mac80211_registered)
2829 ieee80211_stop_queues(priv->hw);
2830
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002831 /* If we have not previously called iwl_init() then
Johannes Berga60e77e2009-06-04 18:26:06 +02002832 * clear all bits but the RF Kill bit and return */
Tomas Winklerfee12472008-04-03 16:05:21 -07002833 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002834 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2835 STATUS_RF_KILL_HW |
Reinette Chatre97888642008-02-06 11:20:38 -08002836 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2837 STATUS_GEO_CONFIGURED |
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002838 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2839 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002840 goto exit;
2841 }
2842
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002843 /* ...otherwise clear out all the status bits but the RF Kill
Johannes Berga60e77e2009-06-04 18:26:06 +02002844 * bit and continue taking the NIC down. */
Zhu Yib481de92007-09-25 17:54:57 -07002845 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2846 STATUS_RF_KILL_HW |
Reinette Chatre97888642008-02-06 11:20:38 -08002847 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2848 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002849 test_bit(STATUS_FW_ERROR, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002850 STATUS_FW_ERROR |
2851 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2852 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002853
Mohamed Abbasef850d72009-05-22 11:01:50 -07002854 /* device going down, Stop using ICT table */
2855 iwl_disable_ict(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002856
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -07002857 iwlagn_txq_ctx_stop(priv);
Wey-Yi Guy54b81552010-03-17 13:34:35 -07002858 iwlagn_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002859
Ben Cahill309e7312009-11-06 14:53:03 -08002860 /* Power-down device's busmaster DMA clocks */
2861 iwl_write_prph(priv, APMG_CLK_DIS_REG, APMG_CLK_VAL_DMA_CLK_RQT);
Zhu Yib481de92007-09-25 17:54:57 -07002862 udelay(5);
2863
Ben Cahill309e7312009-11-06 14:53:03 -08002864 /* Make sure (redundant) we've released our request to stay awake */
2865 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
2866
Ben Cahill4d2ccdb2009-10-09 13:20:20 -07002867 /* Stop the device, and put it in low power state */
2868 priv->cfg->ops->lib->apm_ops.stop(priv);
2869
Zhu Yib481de92007-09-25 17:54:57 -07002870 exit:
Tomas Winkler885ba202008-05-29 16:34:55 +08002871 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07002872
2873 if (priv->ibss_beacon)
2874 dev_kfree_skb(priv->ibss_beacon);
2875 priv->ibss_beacon = NULL;
2876
2877 /* clear out any free frames */
Tomas Winklerfcab4232008-05-15 13:54:01 +08002878 iwl_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002879}
2880
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002881static void iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002882{
2883 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002884 __iwl_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002885 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08002886
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002887 iwl_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002888}
2889
Mohamed Abbas086ed112009-05-22 11:01:54 -07002890#define HW_READY_TIMEOUT (50)
2891
2892static int iwl_set_hw_ready(struct iwl_priv *priv)
2893{
2894 int ret = 0;
2895
2896 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
2897 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
2898
2899 /* See if we got it */
2900 ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
2901 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
2902 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
2903 HW_READY_TIMEOUT);
2904 if (ret != -ETIMEDOUT)
2905 priv->hw_ready = true;
2906 else
2907 priv->hw_ready = false;
2908
2909 IWL_DEBUG_INFO(priv, "hardware %s\n",
2910 (priv->hw_ready == 1) ? "ready" : "not ready");
2911 return ret;
2912}
2913
2914static int iwl_prepare_card_hw(struct iwl_priv *priv)
2915{
2916 int ret = 0;
2917
Frans Pop91dd6c22010-03-24 14:19:58 -07002918 IWL_DEBUG_INFO(priv, "iwl_prepare_card_hw enter\n");
Mohamed Abbas086ed112009-05-22 11:01:54 -07002919
Mohamed Abbas3354a0f2009-06-19 13:52:41 -07002920 ret = iwl_set_hw_ready(priv);
2921 if (priv->hw_ready)
2922 return ret;
2923
2924 /* If HW is not ready, prepare the conditions to check again */
Mohamed Abbas086ed112009-05-22 11:01:54 -07002925 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
2926 CSR_HW_IF_CONFIG_REG_PREPARE);
2927
2928 ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
2929 ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE,
2930 CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000);
2931
Mohamed Abbas3354a0f2009-06-19 13:52:41 -07002932 /* HW should be ready by now, check again. */
Mohamed Abbas086ed112009-05-22 11:01:54 -07002933 if (ret != -ETIMEDOUT)
2934 iwl_set_hw_ready(priv);
2935
2936 return ret;
2937}
2938
Zhu Yib481de92007-09-25 17:54:57 -07002939#define MAX_HW_RESTARTS 5
2940
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002941static int __iwl_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002942{
Tomas Winkler57aab752008-04-14 21:16:03 -07002943 int i;
2944 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002945
2946 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002947 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07002948 return -EIO;
2949 }
2950
Reinette Chatree903fbd2008-01-30 22:05:15 -08002951 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002952 IWL_ERR(priv, "ucode not available for device bringup\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08002953 return -EIO;
2954 }
2955
Johannes Berg2c810cc2010-04-29 00:53:29 -07002956 ret = iwl_alloc_bcast_station(priv, true);
2957 if (ret)
2958 return ret;
2959
Mohamed Abbas086ed112009-05-22 11:01:54 -07002960 iwl_prepare_card_hw(priv);
2961
2962 if (!priv->hw_ready) {
2963 IWL_WARN(priv, "Exit HW not ready\n");
2964 return -EIO;
2965 }
2966
Zhu Yie655b9f2008-01-24 02:19:38 -08002967 /* If platform's RF_KILL switch is NOT set to KILL */
Tomas Winklerc1842d62008-08-04 16:00:43 +08002968 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
Zhu Yie655b9f2008-01-24 02:19:38 -08002969 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002970 else
Zhu Yie655b9f2008-01-24 02:19:38 -08002971 set_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002972
Tomas Winklerc1842d62008-08-04 16:00:43 +08002973 if (iwl_is_rfkill(priv)) {
Johannes Berga60e77e2009-06-04 18:26:06 +02002974 wiphy_rfkill_set_hw_state(priv->hw->wiphy, true);
2975
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002976 iwl_enable_interrupts(priv);
Johannes Berga60e77e2009-06-04 18:26:06 +02002977 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
Tomas Winklerc1842d62008-08-04 16:00:43 +08002978 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002979 }
2980
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002981 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07002982
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -07002983 ret = iwlagn_hw_nic_init(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07002984 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002985 IWL_ERR(priv, "Unable to init nic\n");
Tomas Winkler57aab752008-04-14 21:16:03 -07002986 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002987 }
2988
2989 /* make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002990 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2991 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07002992 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2993
2994 /* clear (again), then enable host interrupts */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002995 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002996 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002997
2998 /* really make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002999 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3000 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07003001
3002 /* Copy original ucode data image from disk into backup cache.
3003 * This will be used to initialize the on-board processor's
3004 * data SRAM for a clean start when the runtime program first loads. */
3005 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a66926a2008-01-14 17:46:18 -08003006 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07003007
Zhu Yib481de92007-09-25 17:54:57 -07003008 for (i = 0; i < MAX_HW_RESTARTS; i++) {
3009
Zhu Yib481de92007-09-25 17:54:57 -07003010 /* load bootstrap state machine,
3011 * load bootstrap program into processor's memory,
3012 * prepare to load the "initialize" uCode */
Tomas Winkler57aab752008-04-14 21:16:03 -07003013 ret = priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003014
Tomas Winkler57aab752008-04-14 21:16:03 -07003015 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003016 IWL_ERR(priv, "Unable to set up bootstrap uCode: %d\n",
3017 ret);
Zhu Yib481de92007-09-25 17:54:57 -07003018 continue;
3019 }
3020
3021 /* start card; "initialize" will load runtime ucode */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003022 iwl_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003023
Tomas Winklere1623442009-01-27 14:27:56 -08003024 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003025
3026 return 0;
3027 }
3028
3029 set_bit(STATUS_EXIT_PENDING, &priv->status);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003030 __iwl_down(priv);
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08003031 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003032
3033 /* tried to restart and config the device for as long as our
3034 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08003035 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07003036 return -EIO;
3037}
3038
3039
3040/*****************************************************************************
3041 *
3042 * Workqueue callbacks
3043 *
3044 *****************************************************************************/
3045
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08003046static void iwl_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003047{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003048 struct iwl_priv *priv =
3049 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003050
3051 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3052 return;
3053
3054 mutex_lock(&priv->mutex);
Emmanuel Grumbachf3ccc082008-05-05 10:22:45 +08003055 priv->cfg->ops->lib->init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003056 mutex_unlock(&priv->mutex);
3057}
3058
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08003059static void iwl_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003060{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003061 struct iwl_priv *priv =
3062 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003063
3064 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3065 return;
3066
Mohamed Abbas258c44a2009-06-03 11:44:10 -07003067 /* enable dram interrupt */
3068 iwl_reset_ict(priv);
3069
Zhu Yib481de92007-09-25 17:54:57 -07003070 mutex_lock(&priv->mutex);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08003071 iwl_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003072 mutex_unlock(&priv->mutex);
3073}
3074
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08003075static void iwl_bg_run_time_calib_work(struct work_struct *work)
3076{
3077 struct iwl_priv *priv = container_of(work, struct iwl_priv,
3078 run_time_calib_work);
3079
3080 mutex_lock(&priv->mutex);
3081
3082 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
3083 test_bit(STATUS_SCANNING, &priv->status)) {
3084 mutex_unlock(&priv->mutex);
3085 return;
3086 }
3087
3088 if (priv->start_calib) {
Wey-Yi Guy7980fba2010-07-14 08:08:57 -07003089 if (priv->cfg->bt_statistics) {
3090 iwl_chain_noise_calibration(priv,
3091 (void *)&priv->_agn.statistics_bt);
3092 iwl_sensitivity_calibration(priv,
3093 (void *)&priv->_agn.statistics_bt);
3094 } else {
3095 iwl_chain_noise_calibration(priv,
3096 (void *)&priv->_agn.statistics);
3097 iwl_sensitivity_calibration(priv,
3098 (void *)&priv->_agn.statistics);
3099 }
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08003100 }
3101
3102 mutex_unlock(&priv->mutex);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08003103}
3104
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003105static void iwl_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003106{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003107 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07003108
3109 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3110 return;
3111
Johannes Berg19cc1082009-05-08 13:44:36 -07003112 if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
Wey-Yi Guybee008b2010-08-23 07:57:04 -07003113 bool bt_sco, bt_full_concurrent;
3114 u8 bt_ci_compliance;
Johannes Berg511b0822010-08-23 07:57:01 -07003115 u8 bt_load;
3116
Johannes Berg19cc1082009-05-08 13:44:36 -07003117 mutex_lock(&priv->mutex);
3118 priv->vif = NULL;
3119 priv->is_open = 0;
Johannes Berg511b0822010-08-23 07:57:01 -07003120
3121 /*
3122 * __iwl_down() will clear the BT status variables,
3123 * which is correct, but when we restart we really
3124 * want to keep them so restore them afterwards.
3125 *
3126 * The restart process will later pick them up and
3127 * re-configure the hw when we reconfigure the BT
3128 * command.
3129 */
3130 bt_sco = priv->bt_sco_active;
Wey-Yi Guybee008b2010-08-23 07:57:04 -07003131 bt_full_concurrent = priv->bt_full_concurrent;
3132 bt_ci_compliance = priv->bt_ci_compliance;
Johannes Berg511b0822010-08-23 07:57:01 -07003133 bt_load = priv->bt_traffic_load;
3134
Johannes Berga1174132010-08-23 07:56:59 -07003135 __iwl_down(priv);
Johannes Berg511b0822010-08-23 07:57:01 -07003136
3137 priv->bt_sco_active = bt_sco;
Wey-Yi Guybee008b2010-08-23 07:57:04 -07003138 priv->bt_full_concurrent = bt_full_concurrent;
3139 priv->bt_ci_compliance = bt_ci_compliance;
Johannes Berg511b0822010-08-23 07:57:01 -07003140 priv->bt_traffic_load = bt_load;
3141
Johannes Berg19cc1082009-05-08 13:44:36 -07003142 mutex_unlock(&priv->mutex);
Johannes Berga1174132010-08-23 07:56:59 -07003143 iwl_cancel_deferred_work(priv);
Johannes Berg19cc1082009-05-08 13:44:36 -07003144 ieee80211_restart_hw(priv->hw);
3145 } else {
3146 iwl_down(priv);
Johannes Berg80676512010-01-21 06:07:17 -08003147
3148 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3149 return;
3150
3151 mutex_lock(&priv->mutex);
3152 __iwl_up(priv);
3153 mutex_unlock(&priv->mutex);
Johannes Berg19cc1082009-05-08 13:44:36 -07003154 }
Zhu Yib481de92007-09-25 17:54:57 -07003155}
3156
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003157static void iwl_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003158{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003159 struct iwl_priv *priv =
3160 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07003161
3162 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3163 return;
3164
3165 mutex_lock(&priv->mutex);
Wey-Yi Guy54b81552010-03-17 13:34:35 -07003166 iwlagn_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003167 mutex_unlock(&priv->mutex);
3168}
3169
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003170#define IWL_DELAY_NEXT_SCAN (HZ*2)
3171
Johannes Berg1dda6d22010-04-29 04:43:06 -07003172void iwl_post_associate(struct iwl_priv *priv, struct ieee80211_vif *vif)
Zhu Yib481de92007-09-25 17:54:57 -07003173{
Zhu Yib481de92007-09-25 17:54:57 -07003174 struct ieee80211_conf *conf = NULL;
Tomas Winkler857485c2008-03-21 13:53:44 -07003175 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003176
Johannes Berg1dda6d22010-04-29 04:43:06 -07003177 if (!vif || !priv->is_open)
3178 return;
3179
3180 if (vif->type == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003181 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07003182 return;
3183 }
3184
Zhu Yib481de92007-09-25 17:54:57 -07003185 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3186 return;
3187
Tomas Winkler2a421b92008-06-12 09:47:10 +08003188 iwl_scan_cancel_timeout(priv, 200);
mabbas052c4b92007-10-25 17:15:43 +08003189
Zhu Yib481de92007-09-25 17:54:57 -07003190 conf = ieee80211_get_hw_conf(priv->hw);
3191
3192 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003193 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003194
Johannes Berg948f5a22010-07-29 07:07:51 -07003195 ret = iwl_send_rxon_timing(priv, vif);
Tomas Winkler857485c2008-03-21 13:53:44 -07003196 if (ret)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003197 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003198 "Attempting to continue.\n");
3199
3200 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
3201
Emmanuel Grumbach42eb7c62008-09-17 10:10:05 +08003202 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03003203
Abhijeet Kolekar45823532009-04-08 11:26:44 -07003204 if (priv->cfg->ops->hcmd->set_rxon_chain)
3205 priv->cfg->ops->hcmd->set_rxon_chain(priv);
3206
Johannes Berg1dda6d22010-04-29 04:43:06 -07003207 priv->staging_rxon.assoc_id = cpu_to_le16(vif->bss_conf.aid);
Zhu Yib481de92007-09-25 17:54:57 -07003208
Tomas Winklere1623442009-01-27 14:27:56 -08003209 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
Johannes Berg1dda6d22010-04-29 04:43:06 -07003210 vif->bss_conf.aid, vif->bss_conf.beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -07003211
Johannes Bergc213d742010-05-06 12:21:40 -07003212 if (vif->bss_conf.use_short_preamble)
Zhu Yib481de92007-09-25 17:54:57 -07003213 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
3214 else
3215 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
3216
3217 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Johannes Bergc213d742010-05-06 12:21:40 -07003218 if (vif->bss_conf.use_short_slot)
Zhu Yib481de92007-09-25 17:54:57 -07003219 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
3220 else
3221 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003222 }
3223
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003224 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003225
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003226 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
Johannes Berg1dda6d22010-04-29 04:43:06 -07003227 vif->bss_conf.aid, priv->active_rxon.bssid_addr);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003228
Johannes Berg1dda6d22010-04-29 04:43:06 -07003229 switch (vif->type) {
Johannes Berg05c914f2008-09-11 00:01:58 +02003230 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -07003231 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02003232 case NL80211_IFTYPE_ADHOC:
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003233 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003234 break;
Zhu Yib481de92007-09-25 17:54:57 -07003235 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08003236 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Johannes Berg1dda6d22010-04-29 04:43:06 -07003237 __func__, vif->type);
Zhu Yib481de92007-09-25 17:54:57 -07003238 break;
3239 }
3240
Grumbach, Emmanuel04816442008-09-03 11:26:53 +08003241 /* the chain noise calibration will enabled PM upon completion
3242 * If chain noise has already been run, then we need to enable
3243 * power management here */
3244 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
Johannes Berge312c242009-08-07 15:41:51 -07003245 iwl_power_update_mode(priv, false);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08003246
3247 /* Enable Rx differential gain and sensitivity calibrations */
3248 iwl_chain_noise_reset(priv);
3249 priv->start_calib = 1;
3250
Reinette Chatre508e32e2008-04-14 21:16:13 -07003251}
3252
Zhu Yib481de92007-09-25 17:54:57 -07003253/*****************************************************************************
3254 *
3255 * mac80211 entry point functions
3256 *
3257 *****************************************************************************/
3258
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08003259#define UCODE_READY_TIMEOUT (4 * HZ)
Zhu Yi5a66926a2008-01-14 17:46:18 -08003260
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07003261/*
3262 * Not a mac80211 entry point function, but it fits in with all the
3263 * other mac80211 functions grouped here.
3264 */
Johannes Bergdd7a2502010-04-28 23:33:10 -07003265static int iwl_mac_setup_register(struct iwl_priv *priv,
3266 struct iwlagn_ucode_capabilities *capa)
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07003267{
3268 int ret;
3269 struct ieee80211_hw *hw = priv->hw;
3270 hw->rate_control_algorithm = "iwl-agn-rs";
3271
3272 /* Tell mac80211 our characteristics */
3273 hw->flags = IEEE80211_HW_SIGNAL_DBM |
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07003274 IEEE80211_HW_AMPDU_AGGREGATION |
3275 IEEE80211_HW_SPECTRUM_MGMT;
3276
3277 if (!priv->cfg->broken_powersave)
3278 hw->flags |= IEEE80211_HW_SUPPORTS_PS |
3279 IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
3280
Johannes Bergba37a3d2009-12-10 14:37:27 -08003281 if (priv->cfg->sku & IWL_SKU_N)
3282 hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
3283 IEEE80211_HW_SUPPORTS_STATIC_SMPS;
3284
Reinette Chatre8d9698b2009-10-16 14:25:55 -07003285 hw->sta_data_size = sizeof(struct iwl_station_priv);
Johannes Bergfd1af152010-04-30 11:30:43 -07003286 hw->vif_data_size = sizeof(struct iwl_vif_priv);
3287
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07003288 hw->wiphy->interface_modes =
3289 BIT(NL80211_IFTYPE_STATION) |
3290 BIT(NL80211_IFTYPE_ADHOC);
3291
Reinette Chatref6c8f152010-03-12 11:13:26 -08003292 hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
Johannes Berg5be83de2009-11-19 00:56:28 +01003293 WIPHY_FLAG_DISABLE_BEACON_HINTS;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07003294
3295 /*
3296 * For now, disable PS by default because it affects
3297 * RX performance significantly.
3298 */
Johannes Berg5be83de2009-11-19 00:56:28 +01003299 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07003300
Reinette Chatre1382c712010-02-25 10:02:19 -08003301 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07003302 /* we create the 802.11 header and a zero-length SSID element */
Johannes Bergdd7a2502010-04-28 23:33:10 -07003303 hw->wiphy->max_scan_ie_len = capa->max_probe_length - 24 - 2;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07003304
3305 /* Default value; 4 EDCA QOS priorities */
3306 hw->queues = 4;
3307
3308 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
3309
3310 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
3311 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
3312 &priv->bands[IEEE80211_BAND_2GHZ];
3313 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
3314 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
3315 &priv->bands[IEEE80211_BAND_5GHZ];
3316
3317 ret = ieee80211_register_hw(priv->hw);
3318 if (ret) {
3319 IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
3320 return ret;
3321 }
3322 priv->mac80211_registered = 1;
3323
3324 return 0;
3325}
3326
3327
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003328static int iwl_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003329{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003330 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003331 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003332
Tomas Winklere1623442009-01-27 14:27:56 -08003333 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003334
3335 /* we should be verifying the device is ready to be opened */
3336 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003337 ret = __iwl_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003338 mutex_unlock(&priv->mutex);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003339
Zhu Yie655b9f2008-01-24 02:19:38 -08003340 if (ret)
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003341 return ret;
Zhu Yie655b9f2008-01-24 02:19:38 -08003342
Tomas Winklerc1842d62008-08-04 16:00:43 +08003343 if (iwl_is_rfkill(priv))
3344 goto out;
3345
Tomas Winklere1623442009-01-27 14:27:56 -08003346 IWL_DEBUG_INFO(priv, "Start UP work done.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003347
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08003348 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
Zhu Yi5a66926a2008-01-14 17:46:18 -08003349 * mac80211 will not be run successfully. */
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08003350 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
3351 test_bit(STATUS_READY, &priv->status),
3352 UCODE_READY_TIMEOUT);
3353 if (!ret) {
3354 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003355 IWL_ERR(priv, "START_ALIVE timeout after %dms.\n",
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08003356 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003357 return -ETIMEDOUT;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003358 }
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08003359 }
Tomas Winkler0a078ff2008-06-30 17:23:26 +08003360
Johannes Berge932a602009-10-02 13:44:03 -07003361 iwl_led_start(priv);
3362
Tomas Winklerc1842d62008-08-04 16:00:43 +08003363out:
Tomas Winkler0a078ff2008-06-30 17:23:26 +08003364 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08003365 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003366 return 0;
3367}
3368
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003369static void iwl_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003370{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003371 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003372
Tomas Winklere1623442009-01-27 14:27:56 -08003373 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas948c1712007-10-25 17:15:45 +08003374
Johannes Berg19cc1082009-05-08 13:44:36 -07003375 if (!priv->is_open)
Zhu Yie655b9f2008-01-24 02:19:38 -08003376 return;
Zhu Yie655b9f2008-01-24 02:19:38 -08003377
Zhu Yib481de92007-09-25 17:54:57 -07003378 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003379
Wey-Yi Guy5bddf542009-08-21 13:34:25 -07003380 if (iwl_is_ready_rf(priv) || test_bit(STATUS_SCAN_HW, &priv->status)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08003381 /* stop mac, cancel any scan request and clear
3382 * RXON_FILTER_ASSOC_MSK BIT
3383 */
Zhu Yi5a66926a2008-01-14 17:46:18 -08003384 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08003385 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003386 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003387 }
3388
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003389 iwl_down(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003390
3391 flush_workqueue(priv->workqueue);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003392
3393 /* enable interrupts again in order to receive rfkill changes */
3394 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
3395 iwl_enable_interrupts(priv);
Mohamed Abbas948c1712007-10-25 17:15:45 +08003396
Tomas Winklere1623442009-01-27 14:27:56 -08003397 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003398}
3399
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003400static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003401{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003402 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003403
Tomas Winklere1623442009-01-27 14:27:56 -08003404 IWL_DEBUG_MACDUMP(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003405
Tomas Winklere1623442009-01-27 14:27:56 -08003406 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02003407 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07003408
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -07003409 if (iwlagn_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07003410 dev_kfree_skb_any(skb);
3411
Tomas Winklere1623442009-01-27 14:27:56 -08003412 IWL_DEBUG_MACDUMP(priv, "leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08003413 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07003414}
3415
Johannes Berg1dda6d22010-04-29 04:43:06 -07003416void iwl_config_ap(struct iwl_priv *priv, struct ieee80211_vif *vif)
Zhu Yib481de92007-09-25 17:54:57 -07003417{
Tomas Winkler857485c2008-03-21 13:53:44 -07003418 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003419
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08003420 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07003421 return;
3422
3423 /* The following should be done only at AP bring up */
Tomas Winkler3195c1f2008-10-08 09:37:30 +08003424 if (!iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003425
3426 /* RXON - unassoc (to set timing command) */
3427 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003428 iwlcore_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003429
3430 /* RXON Timing */
Johannes Berg948f5a22010-07-29 07:07:51 -07003431 ret = iwl_send_rxon_timing(priv, vif);
Tomas Winkler857485c2008-03-21 13:53:44 -07003432 if (ret)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003433 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003434 "Attempting to continue.\n");
3435
Daniel C Halperinf513dff2009-11-13 11:56:34 -08003436 /* AP has all antennas */
3437 priv->chain_noise_data.active_chains =
3438 priv->hw_params.valid_rx_ant;
3439 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Abhijeet Kolekar45823532009-04-08 11:26:44 -07003440 if (priv->cfg->ops->hcmd->set_rxon_chain)
3441 priv->cfg->ops->hcmd->set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003442
Johannes Berg1dda6d22010-04-29 04:43:06 -07003443 priv->staging_rxon.assoc_id = 0;
3444
Johannes Bergc213d742010-05-06 12:21:40 -07003445 if (vif->bss_conf.use_short_preamble)
Zhu Yib481de92007-09-25 17:54:57 -07003446 priv->staging_rxon.flags |=
3447 RXON_FLG_SHORT_PREAMBLE_MSK;
3448 else
3449 priv->staging_rxon.flags &=
3450 ~RXON_FLG_SHORT_PREAMBLE_MSK;
3451
3452 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Johannes Bergc213d742010-05-06 12:21:40 -07003453 if (vif->bss_conf.use_short_slot)
Zhu Yib481de92007-09-25 17:54:57 -07003454 priv->staging_rxon.flags |=
3455 RXON_FLG_SHORT_SLOT_MSK;
3456 else
3457 priv->staging_rxon.flags &=
3458 ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003459 }
3460 /* restore RXON assoc */
3461 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Abhijeet Kolekare0158e62009-04-08 11:26:37 -07003462 iwlcore_commit_rxon(priv);
Zhu Yie1493de2007-09-27 11:27:32 +08003463 }
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003464 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003465
3466 /* FIXME - we need to add code here to detect a totally new
3467 * configuration, reset the AP, unassoc, rxon timing, assoc,
3468 * clear sta table, add BCAST sta... */
3469}
3470
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003471static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw,
Johannes Bergb3fbdcf2010-01-21 11:40:47 +01003472 struct ieee80211_vif *vif,
3473 struct ieee80211_key_conf *keyconf,
3474 struct ieee80211_sta *sta,
3475 u32 iv32, u16 *phase1key)
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003476{
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003477
Tomas Winkler9f586712008-11-12 13:14:05 -08003478 struct iwl_priv *priv = hw->priv;
Tomas Winklere1623442009-01-27 14:27:56 -08003479 IWL_DEBUG_MAC80211(priv, "enter\n");
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003480
Johannes Bergbdbb6122010-04-30 13:53:37 -07003481 iwl_update_tkip_key(priv, keyconf, sta,
Johannes Bergb3fbdcf2010-01-21 11:40:47 +01003482 iv32, phase1key);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003483
Tomas Winklere1623442009-01-27 14:27:56 -08003484 IWL_DEBUG_MAC80211(priv, "leave\n");
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003485}
3486
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003487static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01003488 struct ieee80211_vif *vif,
3489 struct ieee80211_sta *sta,
Zhu Yib481de92007-09-25 17:54:57 -07003490 struct ieee80211_key_conf *key)
3491{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003492 struct iwl_priv *priv = hw->priv;
Winkler, Tomas42986792009-01-19 15:30:22 -08003493 int ret;
3494 u8 sta_id;
3495 bool is_default_wep_key = false;
Zhu Yib481de92007-09-25 17:54:57 -07003496
Tomas Winklere1623442009-01-27 14:27:56 -08003497 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003498
Tomas Winkler90e8e422009-06-19 13:52:42 -07003499 if (priv->cfg->mod_params->sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08003500 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07003501 return -EOPNOTSUPP;
3502 }
Zhu Yib481de92007-09-25 17:54:57 -07003503
Johannes Berg0af8bca2010-04-30 14:08:00 -07003504 sta_id = iwl_sta_id_or_broadcast(priv, sta);
3505 if (sta_id == IWL_INVALID_STATION)
3506 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003507
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003508 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08003509 iwl_scan_cancel_timeout(priv, 100);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003510
Johannes Berga90178fa2010-03-30 02:44:16 -07003511 /*
3512 * If we are getting WEP group key and we didn't receive any key mapping
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003513 * so far, we are in legacy wep mode (group key only), otherwise we are
3514 * in 1X mode.
Johannes Berga90178fa2010-03-30 02:44:16 -07003515 * In legacy wep mode, we use another host command to the uCode.
3516 */
Johannes Berg97359d12010-08-10 09:46:38 +02003517 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3518 key->cipher == WLAN_CIPHER_SUITE_WEP104) &&
Johannes Berg54c80672010-08-18 09:35:21 -07003519 !sta) {
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003520 if (cmd == SET_KEY)
3521 is_default_wep_key = !priv->key_mapping_key;
3522 else
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +08003523 is_default_wep_key =
3524 (key->hw_key_idx == HW_KEY_DEFAULT);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003525 }
mabbas052c4b92007-10-25 17:15:43 +08003526
Zhu Yib481de92007-09-25 17:54:57 -07003527 switch (cmd) {
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003528 case SET_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003529 if (is_default_wep_key)
3530 ret = iwl_set_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003531 else
Emmanuel Grumbach74805132008-04-14 21:16:09 -07003532 ret = iwl_set_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003533
Tomas Winklere1623442009-01-27 14:27:56 -08003534 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003535 break;
3536 case DISABLE_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003537 if (is_default_wep_key)
3538 ret = iwl_remove_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003539 else
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07003540 ret = iwl_remove_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003541
Tomas Winklere1623442009-01-27 14:27:56 -08003542 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003543 break;
3544 default:
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003545 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003546 }
3547
Johannes Berg72e15d72010-02-19 11:42:32 -08003548 mutex_unlock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08003549 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003550
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003551 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003552}
3553
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003554static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
Johannes Bergc951ad32009-11-16 12:00:38 +01003555 struct ieee80211_vif *vif,
Johannes Berg832f47e2010-04-29 04:43:07 -07003556 enum ieee80211_ampdu_mlme_action action,
3557 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
Tomas Winklerd783b062008-07-18 13:53:02 +08003558{
3559 struct iwl_priv *priv = hw->priv;
Johannes Berg4620fef2010-06-16 03:30:27 -07003560 int ret = -EINVAL;
Tomas Winklerd783b062008-07-18 13:53:02 +08003561
Tomas Winklere1623442009-01-27 14:27:56 -08003562 IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
Johannes Berge1749612008-10-27 15:59:26 -07003563 sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08003564
3565 if (!(priv->cfg->sku & IWL_SKU_N))
3566 return -EACCES;
3567
Johannes Berg4620fef2010-06-16 03:30:27 -07003568 mutex_lock(&priv->mutex);
3569
Tomas Winklerd783b062008-07-18 13:53:02 +08003570 switch (action) {
3571 case IEEE80211_AMPDU_RX_START:
Tomas Winklere1623442009-01-27 14:27:56 -08003572 IWL_DEBUG_HT(priv, "start Rx\n");
Johannes Berg4620fef2010-06-16 03:30:27 -07003573 ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn);
3574 break;
Tomas Winklerd783b062008-07-18 13:53:02 +08003575 case IEEE80211_AMPDU_RX_STOP:
Tomas Winklere1623442009-01-27 14:27:56 -08003576 IWL_DEBUG_HT(priv, "stop Rx\n");
Johannes Berg619753f2010-04-30 11:30:46 -07003577 ret = iwl_sta_rx_agg_stop(priv, sta, tid);
Wey-Yi Guy5c2207c2009-03-17 21:51:43 -07003578 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Johannes Berg4620fef2010-06-16 03:30:27 -07003579 ret = 0;
3580 break;
Tomas Winklerd783b062008-07-18 13:53:02 +08003581 case IEEE80211_AMPDU_TX_START:
Tomas Winklere1623442009-01-27 14:27:56 -08003582 IWL_DEBUG_HT(priv, "start Tx\n");
Johannes Berg619753f2010-04-30 11:30:46 -07003583 ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn);
Wey-Yi Guyd5a0ffa2010-03-04 13:38:59 -08003584 if (ret == 0) {
3585 priv->_agn.agg_tids_count++;
3586 IWL_DEBUG_HT(priv, "priv->_agn.agg_tids_count = %u\n",
3587 priv->_agn.agg_tids_count);
3588 }
Johannes Berg4620fef2010-06-16 03:30:27 -07003589 break;
Tomas Winklerd783b062008-07-18 13:53:02 +08003590 case IEEE80211_AMPDU_TX_STOP:
Tomas Winklere1623442009-01-27 14:27:56 -08003591 IWL_DEBUG_HT(priv, "stop Tx\n");
Johannes Berg619753f2010-04-30 11:30:46 -07003592 ret = iwlagn_tx_agg_stop(priv, vif, sta, tid);
Wey-Yi Guyd5a0ffa2010-03-04 13:38:59 -08003593 if ((ret == 0) && (priv->_agn.agg_tids_count > 0)) {
3594 priv->_agn.agg_tids_count--;
3595 IWL_DEBUG_HT(priv, "priv->_agn.agg_tids_count = %u\n",
3596 priv->_agn.agg_tids_count);
3597 }
Wey-Yi Guy5c2207c2009-03-17 21:51:43 -07003598 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Johannes Berg4620fef2010-06-16 03:30:27 -07003599 ret = 0;
Johannes Berg94597ab2010-08-09 10:57:02 -07003600 if (priv->cfg->use_rts_for_aggregation) {
3601 struct iwl_station_priv *sta_priv =
3602 (void *) sta->drv_priv;
3603 /*
3604 * switch off RTS/CTS if it was previously enabled
3605 */
3606
3607 sta_priv->lq_sta.lq.general_params.flags &=
3608 ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
3609 iwl_send_lq_cmd(priv, &sta_priv->lq_sta.lq,
3610 CMD_ASYNC, false);
3611 }
Johannes Berg4620fef2010-06-16 03:30:27 -07003612 break;
Wey-Yi Guyf0527972010-01-08 10:04:41 -08003613 case IEEE80211_AMPDU_TX_OPERATIONAL:
Johannes Berg94597ab2010-08-09 10:57:02 -07003614 if (priv->cfg->use_rts_for_aggregation) {
3615 struct iwl_station_priv *sta_priv =
3616 (void *) sta->drv_priv;
3617
Wey-Yi Guycfecc6b2010-06-18 11:33:15 -07003618 /*
3619 * switch to RTS/CTS if it is the prefer protection
3620 * method for HT traffic
3621 */
Johannes Berg94597ab2010-08-09 10:57:02 -07003622
3623 sta_priv->lq_sta.lq.general_params.flags |=
3624 LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
3625 iwl_send_lq_cmd(priv, &sta_priv->lq_sta.lq,
3626 CMD_ASYNC, false);
Wey-Yi Guycfecc6b2010-06-18 11:33:15 -07003627 }
3628 ret = 0;
Tomas Winklerd783b062008-07-18 13:53:02 +08003629 break;
3630 }
Johannes Berg4620fef2010-06-16 03:30:27 -07003631 mutex_unlock(&priv->mutex);
3632
3633 return ret;
Tomas Winklerd783b062008-07-18 13:53:02 +08003634}
Tomas Winkler9f586712008-11-12 13:14:05 -08003635
Johannes Berg6ab10ff2009-11-13 11:56:37 -08003636static void iwl_mac_sta_notify(struct ieee80211_hw *hw,
3637 struct ieee80211_vif *vif,
3638 enum sta_notify_cmd cmd,
3639 struct ieee80211_sta *sta)
3640{
3641 struct iwl_priv *priv = hw->priv;
3642 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
3643 int sta_id;
3644
Johannes Berg6ab10ff2009-11-13 11:56:37 -08003645 switch (cmd) {
Johannes Berg6ab10ff2009-11-13 11:56:37 -08003646 case STA_NOTIFY_SLEEP:
3647 WARN_ON(!sta_priv->client);
3648 sta_priv->asleep = true;
3649 if (atomic_read(&sta_priv->pending_frames) > 0)
3650 ieee80211_sta_block_awake(hw, sta, true);
3651 break;
3652 case STA_NOTIFY_AWAKE:
3653 WARN_ON(!sta_priv->client);
Daniel Halperin49dcc812010-01-19 10:22:19 -08003654 if (!sta_priv->asleep)
3655 break;
Johannes Berg6ab10ff2009-11-13 11:56:37 -08003656 sta_priv->asleep = false;
Johannes Berg2a87c262010-04-30 11:30:45 -07003657 sta_id = iwl_sta_id(sta);
Johannes Berg6ab10ff2009-11-13 11:56:37 -08003658 if (sta_id != IWL_INVALID_STATION)
3659 iwl_sta_modify_ps_wake(priv, sta_id);
3660 break;
3661 default:
3662 break;
3663 }
3664}
3665
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003666static int iwlagn_mac_sta_add(struct ieee80211_hw *hw,
3667 struct ieee80211_vif *vif,
3668 struct ieee80211_sta *sta)
3669{
3670 struct iwl_priv *priv = hw->priv;
3671 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
Johannes Bergeafdfbd32010-04-29 04:43:04 -07003672 bool is_ap = vif->type == NL80211_IFTYPE_STATION;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003673 int ret;
3674 u8 sta_id;
3675
3676 IWL_DEBUG_INFO(priv, "received request to add station %pM\n",
3677 sta->addr);
Reinette Chatreda5ae1c2010-05-28 09:28:39 -07003678 mutex_lock(&priv->mutex);
3679 IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
3680 sta->addr);
3681 sta_priv->common.sta_id = IWL_INVALID_STATION;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003682
3683 atomic_set(&sta_priv->pending_frames, 0);
3684 if (vif->type == NL80211_IFTYPE_AP)
3685 sta_priv->client = true;
3686
3687 ret = iwl_add_station_common(priv, sta->addr, is_ap, &sta->ht_cap,
3688 &sta_id);
3689 if (ret) {
3690 IWL_ERR(priv, "Unable to add station %pM (%d)\n",
3691 sta->addr, ret);
3692 /* Should we return success if return code is EEXIST ? */
Reinette Chatreda5ae1c2010-05-28 09:28:39 -07003693 mutex_unlock(&priv->mutex);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003694 return ret;
3695 }
3696
Johannes Bergfd1af152010-04-30 11:30:43 -07003697 sta_priv->common.sta_id = sta_id;
3698
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003699 /* Initialize rate scaling */
Frans Pop91dd6c22010-03-24 14:19:58 -07003700 IWL_DEBUG_INFO(priv, "Initializing rate scaling for station %pM\n",
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003701 sta->addr);
3702 iwl_rs_rate_init(priv, sta, sta_id);
Reinette Chatreda5ae1c2010-05-28 09:28:39 -07003703 mutex_unlock(&priv->mutex);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003704
Johannes Bergfd1af152010-04-30 11:30:43 -07003705 return 0;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003706}
3707
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003708static void iwl_mac_channel_switch(struct ieee80211_hw *hw,
3709 struct ieee80211_channel_switch *ch_switch)
3710{
3711 struct iwl_priv *priv = hw->priv;
3712 const struct iwl_channel_info *ch_info;
3713 struct ieee80211_conf *conf = &hw->conf;
Shanyu Zhaoaa2dc6b2010-07-28 13:40:39 -07003714 struct ieee80211_channel *channel = ch_switch->channel;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003715 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
3716 u16 ch;
3717 unsigned long flags = 0;
3718
3719 IWL_DEBUG_MAC80211(priv, "enter\n");
3720
3721 if (iwl_is_rfkill(priv))
3722 goto out_exit;
3723
3724 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
3725 test_bit(STATUS_SCANNING, &priv->status))
3726 goto out_exit;
3727
3728 if (!iwl_is_associated(priv))
3729 goto out_exit;
3730
3731 /* channel switch in progress */
3732 if (priv->switch_rxon.switch_in_progress == true)
3733 goto out_exit;
3734
3735 mutex_lock(&priv->mutex);
3736 if (priv->cfg->ops->lib->set_channel_switch) {
3737
Shanyu Zhaoaa2dc6b2010-07-28 13:40:39 -07003738 ch = channel->hw_value;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003739 if (le16_to_cpu(priv->active_rxon.channel) != ch) {
3740 ch_info = iwl_get_channel_info(priv,
Shanyu Zhaoaa2dc6b2010-07-28 13:40:39 -07003741 channel->band,
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003742 ch);
3743 if (!is_channel_valid(ch_info)) {
3744 IWL_DEBUG_MAC80211(priv, "invalid channel\n");
3745 goto out;
3746 }
3747 spin_lock_irqsave(&priv->lock, flags);
3748
3749 priv->current_ht_config.smps = conf->smps_mode;
3750
3751 /* Configure HT40 channels */
3752 ht_conf->is_ht = conf_is_ht(conf);
3753 if (ht_conf->is_ht) {
3754 if (conf_is_ht40_minus(conf)) {
3755 ht_conf->extension_chan_offset =
3756 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
3757 ht_conf->is_40mhz = true;
3758 } else if (conf_is_ht40_plus(conf)) {
3759 ht_conf->extension_chan_offset =
3760 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
3761 ht_conf->is_40mhz = true;
3762 } else {
3763 ht_conf->extension_chan_offset =
3764 IEEE80211_HT_PARAM_CHA_SEC_NONE;
3765 ht_conf->is_40mhz = false;
3766 }
3767 } else
3768 ht_conf->is_40mhz = false;
3769
Shanyu Zhaoaa2dc6b2010-07-28 13:40:39 -07003770 if (le16_to_cpu(priv->staging_rxon.channel) != ch)
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003771 priv->staging_rxon.flags = 0;
3772
Shanyu Zhaoaa2dc6b2010-07-28 13:40:39 -07003773 iwl_set_rxon_channel(priv, channel);
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003774 iwl_set_rxon_ht(priv, ht_conf);
Shanyu Zhaoaa2dc6b2010-07-28 13:40:39 -07003775 iwl_set_flags_for_band(priv, channel->band,
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003776 priv->vif);
3777 spin_unlock_irqrestore(&priv->lock, flags);
3778
3779 iwl_set_rate(priv);
3780 /*
3781 * at this point, staging_rxon has the
3782 * configuration for channel switch
3783 */
3784 if (priv->cfg->ops->lib->set_channel_switch(priv,
3785 ch_switch))
3786 priv->switch_rxon.switch_in_progress = false;
3787 }
3788 }
3789out:
3790 mutex_unlock(&priv->mutex);
3791out_exit:
3792 if (!priv->switch_rxon.switch_in_progress)
3793 ieee80211_chswitch_done(priv->vif, false);
3794 IWL_DEBUG_MAC80211(priv, "leave\n");
3795}
3796
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02003797static void iwlagn_configure_filter(struct ieee80211_hw *hw,
3798 unsigned int changed_flags,
3799 unsigned int *total_flags,
3800 u64 multicast)
3801{
3802 struct iwl_priv *priv = hw->priv;
3803 __le32 filter_or = 0, filter_nand = 0;
3804
3805#define CHK(test, flag) do { \
3806 if (*total_flags & (test)) \
3807 filter_or |= (flag); \
3808 else \
3809 filter_nand |= (flag); \
3810 } while (0)
3811
3812 IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
3813 changed_flags, *total_flags);
3814
3815 CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
3816 CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK);
3817 CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
3818
3819#undef CHK
3820
3821 mutex_lock(&priv->mutex);
3822
3823 priv->staging_rxon.filter_flags &= ~filter_nand;
3824 priv->staging_rxon.filter_flags |= filter_or;
3825
3826 iwlcore_commit_rxon(priv);
3827
3828 mutex_unlock(&priv->mutex);
3829
3830 /*
3831 * Receiving all multicast frames is always enabled by the
3832 * default flags setup in iwl_connection_init_rx_config()
3833 * since we currently do not support programming multicast
3834 * filters into the device.
3835 */
3836 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
3837 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
3838}
3839
Wey-Yi Guy716c74b2010-06-24 13:22:36 -07003840static void iwl_mac_flush(struct ieee80211_hw *hw, bool drop)
3841{
3842 struct iwl_priv *priv = hw->priv;
3843
3844 mutex_lock(&priv->mutex);
3845 IWL_DEBUG_MAC80211(priv, "enter\n");
3846
3847 /* do not support "flush" */
3848 if (!priv->cfg->ops->lib->txfifo_flush)
3849 goto done;
3850
3851 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
3852 IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n");
3853 goto done;
3854 }
3855 if (iwl_is_rfkill(priv)) {
3856 IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n");
3857 goto done;
3858 }
3859
3860 /*
3861 * mac80211 will not push any more frames for transmit
3862 * until the flush is completed
3863 */
3864 if (drop) {
3865 IWL_DEBUG_MAC80211(priv, "send flush command\n");
3866 if (priv->cfg->ops->lib->txfifo_flush(priv, IWL_DROP_ALL)) {
3867 IWL_ERR(priv, "flush request fail\n");
3868 goto done;
3869 }
3870 }
3871 IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n");
3872 iwlagn_wait_tx_queue_empty(priv);
3873done:
3874 mutex_unlock(&priv->mutex);
3875 IWL_DEBUG_MAC80211(priv, "leave\n");
3876}
3877
Zhu Yib481de92007-09-25 17:54:57 -07003878/*****************************************************************************
3879 *
Zhu Yib481de92007-09-25 17:54:57 -07003880 * driver setup and teardown
3881 *
3882 *****************************************************************************/
3883
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003884static void iwl_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003885{
Reinette Chatred21050c2009-02-13 11:51:18 -08003886 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07003887
3888 init_waitqueue_head(&priv->wait_command_queue);
3889
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003890 INIT_WORK(&priv->restart, iwl_bg_restart);
3891 INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003892 INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08003893 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
Wey-Yi Guy65550632010-06-24 13:18:35 -07003894 INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
Wey-Yi Guybee008b2010-08-23 07:57:04 -07003895 INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08003896 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
3897 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
Tomas Winkler2a421b92008-06-12 09:47:10 +08003898
Tomas Winkler2a421b92008-06-12 09:47:10 +08003899 iwl_setup_scan_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003900
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003901 if (priv->cfg->ops->lib->setup_deferred_work)
3902 priv->cfg->ops->lib->setup_deferred_work(priv);
3903
3904 init_timer(&priv->statistics_periodic);
3905 priv->statistics_periodic.data = (unsigned long)priv;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003906 priv->statistics_periodic.function = iwl_bg_statistics_periodic;
Zhu Yib481de92007-09-25 17:54:57 -07003907
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08003908 init_timer(&priv->ucode_trace);
3909 priv->ucode_trace.data = (unsigned long)priv;
3910 priv->ucode_trace.function = iwl_bg_ucode_trace;
3911
Wey-Yi Guyb74e31a2010-03-01 17:23:50 -08003912 if (priv->cfg->ops->lib->recover_from_tx_stall) {
3913 init_timer(&priv->monitor_recover);
3914 priv->monitor_recover.data = (unsigned long)priv;
3915 priv->monitor_recover.function =
3916 priv->cfg->ops->lib->recover_from_tx_stall;
3917 }
3918
Mohamed Abbasef850d72009-05-22 11:01:50 -07003919 if (!priv->cfg->use_isr_legacy)
3920 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
3921 iwl_irq_tasklet, (unsigned long)priv);
3922 else
3923 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
3924 iwl_irq_tasklet_legacy, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07003925}
3926
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003927static void iwl_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003928{
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003929 if (priv->cfg->ops->lib->cancel_deferred_work)
3930 priv->cfg->ops->lib->cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003931
Joonwoo Park3ae6a052007-11-29 10:43:16 +09003932 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07003933 cancel_delayed_work(&priv->scan_check);
Johannes Berg88be0262010-04-07 00:21:36 -07003934 cancel_work_sync(&priv->start_internal_scan);
Zhu Yib481de92007-09-25 17:54:57 -07003935 cancel_delayed_work(&priv->alive_start);
Wey-Yi Guy815e6292010-06-03 10:14:01 -07003936 cancel_work_sync(&priv->run_time_calib_work);
Zhu Yib481de92007-09-25 17:54:57 -07003937 cancel_work_sync(&priv->beacon_update);
Wey-Yi Guybee008b2010-08-23 07:57:04 -07003938 cancel_work_sync(&priv->bt_full_concurrency);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003939 del_timer_sync(&priv->statistics_periodic);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08003940 del_timer_sync(&priv->ucode_trace);
Zhu Yib481de92007-09-25 17:54:57 -07003941}
3942
Reinette Chatre89f186a2009-10-30 14:36:11 -07003943static void iwl_init_hw_rates(struct iwl_priv *priv,
3944 struct ieee80211_rate *rates)
3945{
3946 int i;
3947
3948 for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
3949 rates[i].bitrate = iwl_rates[i].ieee * 5;
3950 rates[i].hw_value = i; /* Rate scaling will work on indexes */
3951 rates[i].hw_value_short = i;
3952 rates[i].flags = 0;
3953 if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
3954 /*
3955 * If CCK != 1M then set short preamble rate flag.
3956 */
3957 rates[i].flags |=
3958 (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
3959 0 : IEEE80211_RATE_SHORT_PREAMBLE;
3960 }
3961 }
3962}
3963
3964static int iwl_init_drv(struct iwl_priv *priv)
3965{
3966 int ret;
3967
3968 priv->ibss_beacon = NULL;
3969
Reinette Chatre89f186a2009-10-30 14:36:11 -07003970 spin_lock_init(&priv->sta_lock);
3971 spin_lock_init(&priv->hcmd_lock);
3972
3973 INIT_LIST_HEAD(&priv->free_frames);
3974
3975 mutex_init(&priv->mutex);
Reinette Chatred2dfe6d2010-02-18 22:03:04 -08003976 mutex_init(&priv->sync_cmd_mutex);
Reinette Chatre89f186a2009-10-30 14:36:11 -07003977
Reinette Chatre89f186a2009-10-30 14:36:11 -07003978 priv->ieee_channels = NULL;
3979 priv->ieee_rates = NULL;
3980 priv->band = IEEE80211_BAND_2GHZ;
3981
3982 priv->iw_mode = NL80211_IFTYPE_STATION;
Johannes Bergba37a3d2009-12-10 14:37:27 -08003983 priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
Wey-Yi Guya13d2762010-01-22 14:22:42 -08003984 priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
Wey-Yi Guyd5a0ffa2010-03-04 13:38:59 -08003985 priv->_agn.agg_tids_count = 0;
Reinette Chatre89f186a2009-10-30 14:36:11 -07003986
Wey-Yi Guy8a472da2010-02-18 22:03:06 -08003987 /* initialize force reset */
3988 priv->force_reset[IWL_RF_RESET].reset_duration =
3989 IWL_DELAY_NEXT_FORCE_RF_RESET;
3990 priv->force_reset[IWL_FW_RESET].reset_duration =
3991 IWL_DELAY_NEXT_FORCE_FW_RELOAD;
Reinette Chatre89f186a2009-10-30 14:36:11 -07003992
3993 /* Choose which receivers/antennas to use */
3994 if (priv->cfg->ops->hcmd->set_rxon_chain)
3995 priv->cfg->ops->hcmd->set_rxon_chain(priv);
3996
3997 iwl_init_scan_params(priv);
3998
Reinette Chatre89f186a2009-10-30 14:36:11 -07003999 /* Set the tx_power_user_lmt to the lowest power level
4000 * this value will get overwritten by channel max power avg
4001 * from eeprom */
Wey-Yi Guyb744cb72010-03-23 11:37:59 -07004002 priv->tx_power_user_lmt = IWLAGN_TX_POWER_TARGET_POWER_MIN;
Reinette Chatre89f186a2009-10-30 14:36:11 -07004003
4004 ret = iwl_init_channel_map(priv);
4005 if (ret) {
4006 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
4007 goto err;
4008 }
4009
4010 ret = iwlcore_init_geos(priv);
4011 if (ret) {
4012 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
4013 goto err_free_channel_map;
4014 }
4015 iwl_init_hw_rates(priv, priv->ieee_rates);
4016
4017 return 0;
4018
4019err_free_channel_map:
4020 iwl_free_channel_map(priv);
4021err:
4022 return ret;
4023}
4024
4025static void iwl_uninit_drv(struct iwl_priv *priv)
4026{
4027 iwl_calib_free_results(priv);
4028 iwlcore_free_geos(priv);
4029 iwl_free_channel_map(priv);
Johannes Berg811ecc92010-04-06 04:12:41 -07004030 kfree(priv->scan_cmd);
Reinette Chatre89f186a2009-10-30 14:36:11 -07004031}
4032
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004033static struct ieee80211_ops iwl_hw_ops = {
4034 .tx = iwl_mac_tx,
4035 .start = iwl_mac_start,
4036 .stop = iwl_mac_stop,
4037 .add_interface = iwl_mac_add_interface,
4038 .remove_interface = iwl_mac_remove_interface,
4039 .config = iwl_mac_config,
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02004040 .configure_filter = iwlagn_configure_filter,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004041 .set_key = iwl_mac_set_key,
4042 .update_tkip_key = iwl_mac_update_tkip_key,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004043 .conf_tx = iwl_mac_conf_tx,
4044 .reset_tsf = iwl_mac_reset_tsf,
4045 .bss_info_changed = iwl_bss_info_changed,
4046 .ampdu_action = iwl_mac_ampdu_action,
Johannes Berg6ab10ff2009-11-13 11:56:37 -08004047 .hw_scan = iwl_mac_hw_scan,
4048 .sta_notify = iwl_mac_sta_notify,
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08004049 .sta_add = iwlagn_mac_sta_add,
4050 .sta_remove = iwl_mac_sta_remove,
Wey-Yi Guy79d07322010-05-06 08:54:11 -07004051 .channel_switch = iwl_mac_channel_switch,
Wey-Yi Guy716c74b2010-06-24 13:22:36 -07004052 .flush = iwl_mac_flush,
Johannes Berga85d7cc2010-07-31 08:34:10 -07004053 .tx_last_beacon = iwl_mac_tx_last_beacon,
Zhu Yib481de92007-09-25 17:54:57 -07004054};
4055
Wey-Yi Guy3867fe02010-07-31 08:34:05 -07004056static void iwl_hw_detect(struct iwl_priv *priv)
4057{
4058 priv->hw_rev = _iwl_read32(priv, CSR_HW_REV);
4059 priv->hw_wa_rev = _iwl_read32(priv, CSR_HW_REV_WA_REG);
4060 pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &priv->rev_id);
Wey-Yi Guy49ded762010-07-31 08:34:06 -07004061 IWL_DEBUG_INFO(priv, "HW Revision ID = 0x%X\n", priv->rev_id);
Wey-Yi Guy3867fe02010-07-31 08:34:05 -07004062}
4063
Wey-Yi Guy07d4f1a2010-07-31 08:34:08 -07004064static int iwl_set_hw_params(struct iwl_priv *priv)
4065{
4066 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
4067 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
4068 if (priv->cfg->mod_params->amsdu_size_8K)
4069 priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_8K);
4070 else
4071 priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_4K);
4072
4073 priv->hw_params.max_beacon_itrvl = IWL_MAX_UCODE_BEACON_INTERVAL;
4074
4075 if (priv->cfg->mod_params->disable_11n)
4076 priv->cfg->sku &= ~IWL_SKU_N;
4077
4078 /* Device-specific setup */
4079 return priv->cfg->ops->lib->set_hw_params(priv);
4080}
4081
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004082static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07004083{
4084 int err = 0;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004085 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07004086 struct ieee80211_hw *hw;
Tomas Winkler82b9a122008-03-04 18:09:30 -08004087 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004088 unsigned long flags;
Wey-Yi Guyc6fa17e2010-07-15 05:58:30 -07004089 u16 pci_cmd, num_mac;
Zhu Yib481de92007-09-25 17:54:57 -07004090
Assaf Krauss316c30d2008-03-14 10:38:46 -07004091 /************************
4092 * 1. Allocating HW data
4093 ************************/
4094
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004095 /* Disabling hardware scan means that mac80211 will perform scans
4096 * "the hard way", rather than using device's scan. */
Assaf Krauss1ea87392008-03-18 14:57:50 -07004097 if (cfg->mod_params->disable_hw_scan) {
Reinette Chatrea562a9d2009-07-17 09:30:24 -07004098 if (iwl_debug_level & IWL_DL_INFO)
Ester Kummerbf403db2008-05-05 10:22:40 +08004099 dev_printk(KERN_DEBUG, &(pdev->dev),
4100 "Disabling hw_scan\n");
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004101 iwl_hw_ops.hw_scan = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07004102 }
4103
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004104 hw = iwl_alloc_all(cfg, &iwl_hw_ops);
Assaf Krauss1d0a0822008-03-14 10:38:48 -07004105 if (!hw) {
Zhu Yib481de92007-09-25 17:54:57 -07004106 err = -ENOMEM;
4107 goto out;
4108 }
Assaf Krauss1d0a0822008-03-14 10:38:48 -07004109 priv = hw->priv;
4110 /* At this point both hw and priv are allocated. */
4111
Zhu Yib481de92007-09-25 17:54:57 -07004112 SET_IEEE80211_DEV(hw, &pdev->dev);
4113
Tomas Winklere1623442009-01-27 14:27:56 -08004114 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Tomas Winkler82b9a122008-03-04 18:09:30 -08004115 priv->cfg = cfg;
Zhu Yib481de92007-09-25 17:54:57 -07004116 priv->pci_dev = pdev;
Mohamed Abbas40cefda2009-05-22 11:01:52 -07004117 priv->inta_mask = CSR_INI_SET_MASK;
Assaf Krauss316c30d2008-03-14 10:38:46 -07004118
Wey-Yi Guybee008b2010-08-23 07:57:04 -07004119 /* is antenna coupling more than 35dB ? */
4120 priv->bt_ant_couple_ok =
4121 (iwlagn_ant_coupling > IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
4122 true : false;
4123
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07004124 if (iwl_alloc_traffic_mem(priv))
4125 IWL_ERR(priv, "Not enough memory to generate traffic log\n");
Zhu Yib481de92007-09-25 17:54:57 -07004126
Assaf Krauss316c30d2008-03-14 10:38:46 -07004127 /**************************
4128 * 2. Initializing PCI bus
4129 **************************/
John W. Linville1a7123c2010-08-05 14:39:31 -04004130 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
4131 PCIE_LINK_STATE_CLKPM);
4132
Assaf Krauss316c30d2008-03-14 10:38:46 -07004133 if (pci_enable_device(pdev)) {
4134 err = -ENODEV;
4135 goto out_ieee80211_free_hw;
4136 }
4137
4138 pci_set_master(pdev);
4139
Winkler, Tomas093d874c2008-09-26 15:09:34 +08004140 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
Assaf Krauss316c30d2008-03-14 10:38:46 -07004141 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08004142 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004143 if (err) {
Winkler, Tomas093d874c2008-09-26 15:09:34 +08004144 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004145 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08004146 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004147 /* both attempts failed: */
Assaf Krauss316c30d2008-03-14 10:38:46 -07004148 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08004149 IWL_WARN(priv, "No suitable DMA available.\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07004150 goto out_pci_disable_device;
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004151 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07004152 }
4153
4154 err = pci_request_regions(pdev, DRV_NAME);
4155 if (err)
4156 goto out_pci_disable_device;
4157
4158 pci_set_drvdata(pdev, priv);
4159
Assaf Krauss316c30d2008-03-14 10:38:46 -07004160
4161 /***********************
4162 * 3. Read REV register
4163 ***********************/
4164 priv->hw_base = pci_iomap(pdev, 0, 0);
4165 if (!priv->hw_base) {
4166 err = -ENODEV;
4167 goto out_pci_release_regions;
4168 }
4169
Tomas Winklere1623442009-01-27 14:27:56 -08004170 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Assaf Krauss316c30d2008-03-14 10:38:46 -07004171 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08004172 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004173
Reinette Chatre731a29b2009-12-14 14:12:11 -08004174 /* these spin locks will be used in apm_ops.init and EEPROM access
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07004175 * we should init now
4176 */
4177 spin_lock_init(&priv->reg_lock);
Reinette Chatre731a29b2009-12-14 14:12:11 -08004178 spin_lock_init(&priv->lock);
Reinette Chatre4843b5a2010-02-03 09:38:59 -08004179
4180 /*
4181 * stop and reset the on-board processor just in case it is in a
4182 * strange state ... like being left stranded by a primary kernel
4183 * and this is now the kdump kernel trying to start up
4184 */
4185 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
4186
Tomas Winklerb661c812008-04-23 17:14:54 -07004187 iwl_hw_detect(priv);
Shanyu Zhaoc11362c2010-03-05 17:05:20 -08004188 IWL_INFO(priv, "Detected %s, REV=0x%X\n",
Tomas Winklerb661c812008-04-23 17:14:54 -07004189 priv->cfg->name, priv->hw_rev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004190
Tomas Winklere7b63582008-09-03 11:26:49 +08004191 /* We disable the RETRY_TIMEOUT register (0x41) to keep
4192 * PCI Tx retries from interfering with C3 CPU state */
4193 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
4194
Mohamed Abbas086ed112009-05-22 11:01:54 -07004195 iwl_prepare_card_hw(priv);
4196 if (!priv->hw_ready) {
4197 IWL_WARN(priv, "Failed, HW not ready\n");
4198 goto out_iounmap;
4199 }
4200
Assaf Krauss316c30d2008-03-14 10:38:46 -07004201 /*****************
4202 * 4. Read EEPROM
4203 *****************/
Assaf Krauss316c30d2008-03-14 10:38:46 -07004204 /* Read the EEPROM */
4205 err = iwl_eeprom_init(priv);
4206 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004207 IWL_ERR(priv, "Unable to init EEPROM\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07004208 goto out_iounmap;
4209 }
Tomas Winkler8614f362008-04-23 17:14:55 -07004210 err = iwl_eeprom_check_version(priv);
4211 if (err)
Reinette Chatrec8f16132009-02-27 16:21:22 -08004212 goto out_free_eeprom;
Tomas Winkler8614f362008-04-23 17:14:55 -07004213
Ron Rindjunsky02883012008-05-15 13:53:53 +08004214 /* extract MAC Address */
Wey-Yi Guyc6fa17e2010-07-15 05:58:30 -07004215 iwl_eeprom_get_mac(priv, priv->addresses[0].addr);
4216 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
4217 priv->hw->wiphy->addresses = priv->addresses;
4218 priv->hw->wiphy->n_addresses = 1;
4219 num_mac = iwl_eeprom_query16(priv, EEPROM_NUM_MAC_ADDRESS);
4220 if (num_mac > 1) {
4221 memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
4222 ETH_ALEN);
4223 priv->addresses[1].addr[5]++;
4224 priv->hw->wiphy->n_addresses++;
4225 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07004226
4227 /************************
4228 * 5. Setup HW constants
4229 ************************/
Ron Rindjunskyda154e302008-06-30 17:23:20 +08004230 if (iwl_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004231 IWL_ERR(priv, "failed to set hw parameters\n");
Tomas Winkler073d3f52008-04-21 15:41:52 -07004232 goto out_free_eeprom;
Assaf Krauss316c30d2008-03-14 10:38:46 -07004233 }
4234
4235 /*******************
Tomas Winkler6ba87952008-05-15 13:54:17 +08004236 * 6. Setup priv
Assaf Krauss316c30d2008-03-14 10:38:46 -07004237 *******************/
Zhu Yib481de92007-09-25 17:54:57 -07004238
Tomas Winkler6ba87952008-05-15 13:54:17 +08004239 err = iwl_init_drv(priv);
Assaf Kraussbf85ea42008-03-14 10:38:49 -07004240 if (err)
Ron Rindjunsky399f4902008-04-23 17:14:56 -07004241 goto out_free_eeprom;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07004242 /* At this point both hw and priv are initialized. */
Assaf Krauss316c30d2008-03-14 10:38:46 -07004243
Assaf Krauss316c30d2008-03-14 10:38:46 -07004244 /********************
Abhijeet Kolekar09f9bf72009-04-20 14:37:03 -07004245 * 7. Setup services
Assaf Krauss316c30d2008-03-14 10:38:46 -07004246 ********************/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004247 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004248 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004249 spin_unlock_irqrestore(&priv->lock, flags);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004250
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004251 pci_enable_msi(priv->pci_dev);
4252
Mohamed Abbasef850d72009-05-22 11:01:50 -07004253 iwl_alloc_isr_ict(priv);
4254 err = request_irq(priv->pci_dev->irq, priv->cfg->ops->lib->isr,
4255 IRQF_SHARED, DRV_NAME, priv);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004256 if (err) {
4257 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
4258 goto out_disable_msi;
4259 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07004260
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004261 iwl_setup_deferred_work(priv);
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08004262 iwl_setup_rx_handlers(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004263
Johannes Berg158bea02010-01-22 14:22:53 -08004264 /*********************************************
4265 * 8. Enable interrupts and read RFKILL state
4266 *********************************************/
Tomas Winkler6ba87952008-05-15 13:54:17 +08004267
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004268 /* enable interrupts if needed: hw bug w/a */
4269 pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd);
4270 if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
4271 pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
4272 pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
4273 }
4274
4275 iwl_enable_interrupts(priv);
4276
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004277 /* If platform's RF_KILL switch is NOT set to KILL */
4278 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
4279 clear_bit(STATUS_RF_KILL_HW, &priv->status);
4280 else
4281 set_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winkler6ba87952008-05-15 13:54:17 +08004282
Johannes Berga60e77e2009-06-04 18:26:06 +02004283 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
4284 test_bit(STATUS_RF_KILL_HW, &priv->status));
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004285
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08004286 iwl_power_initialize(priv);
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -07004287 iwl_tt_initialize(priv);
Johannes Berg158bea02010-01-22 14:22:53 -08004288
Reinette Chatrea15707d2010-05-10 15:08:11 -07004289 init_completion(&priv->_agn.firmware_loading_complete);
Johannes Berg562db532010-04-29 07:41:53 -07004290
Johannes Bergb08dfd02010-01-29 11:54:56 -08004291 err = iwl_request_firmware(priv, true);
Johannes Berg158bea02010-01-22 14:22:53 -08004292 if (err)
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07004293 goto out_destroy_workqueue;
Johannes Berg158bea02010-01-22 14:22:53 -08004294
Zhu Yib481de92007-09-25 17:54:57 -07004295 return 0;
4296
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07004297 out_destroy_workqueue:
Reinette Chatrec8f16132009-02-27 16:21:22 -08004298 destroy_workqueue(priv->workqueue);
4299 priv->workqueue = NULL;
Helmut Schaa795cc0a2009-02-12 18:51:03 +01004300 free_irq(priv->pci_dev->irq, priv);
Mohamed Abbasef850d72009-05-22 11:01:50 -07004301 iwl_free_isr_ict(priv);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004302 out_disable_msi:
4303 pci_disable_msi(priv->pci_dev);
Tomas Winkler6ba87952008-05-15 13:54:17 +08004304 iwl_uninit_drv(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07004305 out_free_eeprom:
4306 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004307 out_iounmap:
4308 pci_iounmap(pdev, priv->hw_base);
4309 out_pci_release_regions:
Assaf Krauss316c30d2008-03-14 10:38:46 -07004310 pci_set_drvdata(pdev, NULL);
Reinette Chatre623d5632009-03-03 11:37:04 -08004311 pci_release_regions(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004312 out_pci_disable_device:
4313 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004314 out_ieee80211_free_hw:
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07004315 iwl_free_traffic_mem(priv);
Wey-Yi Guyd7c76f42009-10-09 13:20:17 -07004316 ieee80211_free_hw(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07004317 out:
4318 return err;
4319}
4320
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004321static void __devexit iwl_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004322{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004323 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004324 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07004325
4326 if (!priv)
4327 return;
4328
Reinette Chatrea15707d2010-05-10 15:08:11 -07004329 wait_for_completion(&priv->_agn.firmware_loading_complete);
Johannes Berg562db532010-04-29 07:41:53 -07004330
Tomas Winklere1623442009-01-27 14:27:56 -08004331 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07004332
Emmanuel Grumbach67249622008-05-29 16:35:26 +08004333 iwl_dbgfs_unregister(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004334 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
Emmanuel Grumbach67249622008-05-29 16:35:26 +08004335
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004336 /* ieee80211_unregister_hw call wil cause iwl_mac_stop to
4337 * to be called and iwl_down since we are removing the device
Gregory Greenman0b124c32008-09-03 11:18:50 +08004338 * we need to set STATUS_EXIT_PENDING bit.
4339 */
4340 set_bit(STATUS_EXIT_PENDING, &priv->status);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07004341 if (priv->mac80211_registered) {
4342 ieee80211_unregister_hw(priv->hw);
4343 priv->mac80211_registered = 0;
Gregory Greenman0b124c32008-09-03 11:18:50 +08004344 } else {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004345 iwl_down(priv);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07004346 }
4347
Ben Cahillc166b252009-10-23 13:42:35 -07004348 /*
4349 * Make sure device is reset to low power before unloading driver.
4350 * This may be redundant with iwl_down(), but there are paths to
4351 * run iwl_down() without calling apm_ops.stop(), and there are
4352 * paths to avoid running iwl_down() at all before leaving driver.
4353 * This (inexpensive) call *makes sure* device is reset.
4354 */
4355 priv->cfg->ops->lib->apm_ops.stop(priv);
4356
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -07004357 iwl_tt_exit(priv);
4358
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004359 /* make sure we flush any pending irq or
4360 * tasklet for the driver
4361 */
4362 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004363 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004364 spin_unlock_irqrestore(&priv->lock, flags);
4365
4366 iwl_synchronize_irq(priv);
4367
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004368 iwl_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004369
4370 if (priv->rxq.bd)
Wey-Yi Guy54b81552010-03-17 13:34:35 -07004371 iwlagn_rx_queue_free(priv, &priv->rxq);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -07004372 iwlagn_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004373
Tomas Winkler073d3f52008-04-21 15:41:52 -07004374 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004375
Zhu Yib481de92007-09-25 17:54:57 -07004376
Mohamed Abbas948c1712007-10-25 17:15:45 +08004377 /*netif_stop_queue(dev); */
4378 flush_workqueue(priv->workqueue);
4379
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004380 /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07004381 * priv->workqueue... so we can't take down the workqueue
4382 * until now... */
4383 destroy_workqueue(priv->workqueue);
4384 priv->workqueue = NULL;
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07004385 iwl_free_traffic_mem(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004386
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004387 free_irq(priv->pci_dev->irq, priv);
4388 pci_disable_msi(priv->pci_dev);
Zhu Yib481de92007-09-25 17:54:57 -07004389 pci_iounmap(pdev, priv->hw_base);
4390 pci_release_regions(pdev);
4391 pci_disable_device(pdev);
4392 pci_set_drvdata(pdev, NULL);
4393
Tomas Winkler6ba87952008-05-15 13:54:17 +08004394 iwl_uninit_drv(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004395
Mohamed Abbasef850d72009-05-22 11:01:50 -07004396 iwl_free_isr_ict(priv);
4397
Zhu Yib481de92007-09-25 17:54:57 -07004398 if (priv->ibss_beacon)
4399 dev_kfree_skb(priv->ibss_beacon);
4400
4401 ieee80211_free_hw(priv->hw);
4402}
4403
Zhu Yib481de92007-09-25 17:54:57 -07004404
4405/*****************************************************************************
4406 *
4407 * driver and module entry point
4408 *
4409 *****************************************************************************/
4410
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004411/* Hardware specific file defines the PCI IDs table for that hardware module */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00004412static DEFINE_PCI_DEVICE_TABLE(iwl_hw_card_ids) = {
Tomas Winkler4fc22b22008-07-21 18:54:42 +03004413#ifdef CONFIG_IWL4965
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004414 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
4415 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
Tomas Winkler4fc22b22008-07-21 18:54:42 +03004416#endif /* CONFIG_IWL4965 */
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004417#ifdef CONFIG_IWL5000
Wey-Yi Guyac592572009-11-20 12:05:03 -08004418/* 5100 Series WiFi */
4419 {IWL_PCI_DEVICE(0x4232, 0x1201, iwl5100_agn_cfg)}, /* Mini Card */
4420 {IWL_PCI_DEVICE(0x4232, 0x1301, iwl5100_agn_cfg)}, /* Half Mini Card */
4421 {IWL_PCI_DEVICE(0x4232, 0x1204, iwl5100_agn_cfg)}, /* Mini Card */
4422 {IWL_PCI_DEVICE(0x4232, 0x1304, iwl5100_agn_cfg)}, /* Half Mini Card */
4423 {IWL_PCI_DEVICE(0x4232, 0x1205, iwl5100_bgn_cfg)}, /* Mini Card */
4424 {IWL_PCI_DEVICE(0x4232, 0x1305, iwl5100_bgn_cfg)}, /* Half Mini Card */
4425 {IWL_PCI_DEVICE(0x4232, 0x1206, iwl5100_abg_cfg)}, /* Mini Card */
4426 {IWL_PCI_DEVICE(0x4232, 0x1306, iwl5100_abg_cfg)}, /* Half Mini Card */
4427 {IWL_PCI_DEVICE(0x4232, 0x1221, iwl5100_agn_cfg)}, /* Mini Card */
4428 {IWL_PCI_DEVICE(0x4232, 0x1321, iwl5100_agn_cfg)}, /* Half Mini Card */
4429 {IWL_PCI_DEVICE(0x4232, 0x1224, iwl5100_agn_cfg)}, /* Mini Card */
4430 {IWL_PCI_DEVICE(0x4232, 0x1324, iwl5100_agn_cfg)}, /* Half Mini Card */
4431 {IWL_PCI_DEVICE(0x4232, 0x1225, iwl5100_bgn_cfg)}, /* Mini Card */
4432 {IWL_PCI_DEVICE(0x4232, 0x1325, iwl5100_bgn_cfg)}, /* Half Mini Card */
4433 {IWL_PCI_DEVICE(0x4232, 0x1226, iwl5100_abg_cfg)}, /* Mini Card */
4434 {IWL_PCI_DEVICE(0x4232, 0x1326, iwl5100_abg_cfg)}, /* Half Mini Card */
4435 {IWL_PCI_DEVICE(0x4237, 0x1211, iwl5100_agn_cfg)}, /* Mini Card */
4436 {IWL_PCI_DEVICE(0x4237, 0x1311, iwl5100_agn_cfg)}, /* Half Mini Card */
4437 {IWL_PCI_DEVICE(0x4237, 0x1214, iwl5100_agn_cfg)}, /* Mini Card */
4438 {IWL_PCI_DEVICE(0x4237, 0x1314, iwl5100_agn_cfg)}, /* Half Mini Card */
4439 {IWL_PCI_DEVICE(0x4237, 0x1215, iwl5100_bgn_cfg)}, /* Mini Card */
4440 {IWL_PCI_DEVICE(0x4237, 0x1315, iwl5100_bgn_cfg)}, /* Half Mini Card */
4441 {IWL_PCI_DEVICE(0x4237, 0x1216, iwl5100_abg_cfg)}, /* Mini Card */
4442 {IWL_PCI_DEVICE(0x4237, 0x1316, iwl5100_abg_cfg)}, /* Half Mini Card */
4443
4444/* 5300 Series WiFi */
4445 {IWL_PCI_DEVICE(0x4235, 0x1021, iwl5300_agn_cfg)}, /* Mini Card */
4446 {IWL_PCI_DEVICE(0x4235, 0x1121, iwl5300_agn_cfg)}, /* Half Mini Card */
4447 {IWL_PCI_DEVICE(0x4235, 0x1024, iwl5300_agn_cfg)}, /* Mini Card */
4448 {IWL_PCI_DEVICE(0x4235, 0x1124, iwl5300_agn_cfg)}, /* Half Mini Card */
4449 {IWL_PCI_DEVICE(0x4235, 0x1001, iwl5300_agn_cfg)}, /* Mini Card */
4450 {IWL_PCI_DEVICE(0x4235, 0x1101, iwl5300_agn_cfg)}, /* Half Mini Card */
4451 {IWL_PCI_DEVICE(0x4235, 0x1004, iwl5300_agn_cfg)}, /* Mini Card */
4452 {IWL_PCI_DEVICE(0x4235, 0x1104, iwl5300_agn_cfg)}, /* Half Mini Card */
4453 {IWL_PCI_DEVICE(0x4236, 0x1011, iwl5300_agn_cfg)}, /* Mini Card */
4454 {IWL_PCI_DEVICE(0x4236, 0x1111, iwl5300_agn_cfg)}, /* Half Mini Card */
4455 {IWL_PCI_DEVICE(0x4236, 0x1014, iwl5300_agn_cfg)}, /* Mini Card */
4456 {IWL_PCI_DEVICE(0x4236, 0x1114, iwl5300_agn_cfg)}, /* Half Mini Card */
4457
4458/* 5350 Series WiFi/WiMax */
4459 {IWL_PCI_DEVICE(0x423A, 0x1001, iwl5350_agn_cfg)}, /* Mini Card */
4460 {IWL_PCI_DEVICE(0x423A, 0x1021, iwl5350_agn_cfg)}, /* Mini Card */
4461 {IWL_PCI_DEVICE(0x423B, 0x1011, iwl5350_agn_cfg)}, /* Mini Card */
4462
4463/* 5150 Series Wifi/WiMax */
4464 {IWL_PCI_DEVICE(0x423C, 0x1201, iwl5150_agn_cfg)}, /* Mini Card */
4465 {IWL_PCI_DEVICE(0x423C, 0x1301, iwl5150_agn_cfg)}, /* Half Mini Card */
4466 {IWL_PCI_DEVICE(0x423C, 0x1206, iwl5150_abg_cfg)}, /* Mini Card */
4467 {IWL_PCI_DEVICE(0x423C, 0x1306, iwl5150_abg_cfg)}, /* Half Mini Card */
4468 {IWL_PCI_DEVICE(0x423C, 0x1221, iwl5150_agn_cfg)}, /* Mini Card */
4469 {IWL_PCI_DEVICE(0x423C, 0x1321, iwl5150_agn_cfg)}, /* Half Mini Card */
4470
4471 {IWL_PCI_DEVICE(0x423D, 0x1211, iwl5150_agn_cfg)}, /* Mini Card */
4472 {IWL_PCI_DEVICE(0x423D, 0x1311, iwl5150_agn_cfg)}, /* Half Mini Card */
4473 {IWL_PCI_DEVICE(0x423D, 0x1216, iwl5150_abg_cfg)}, /* Mini Card */
4474 {IWL_PCI_DEVICE(0x423D, 0x1316, iwl5150_abg_cfg)}, /* Half Mini Card */
Wey-Yi Guy5953a622009-09-17 10:43:53 -07004475
4476/* 6x00 Series */
Wey-Yi Guy5953a622009-09-17 10:43:53 -07004477 {IWL_PCI_DEVICE(0x422B, 0x1101, iwl6000_3agn_cfg)},
4478 {IWL_PCI_DEVICE(0x422B, 0x1121, iwl6000_3agn_cfg)},
4479 {IWL_PCI_DEVICE(0x422C, 0x1301, iwl6000i_2agn_cfg)},
4480 {IWL_PCI_DEVICE(0x422C, 0x1306, iwl6000i_2abg_cfg)},
4481 {IWL_PCI_DEVICE(0x422C, 0x1307, iwl6000i_2bg_cfg)},
4482 {IWL_PCI_DEVICE(0x422C, 0x1321, iwl6000i_2agn_cfg)},
4483 {IWL_PCI_DEVICE(0x422C, 0x1326, iwl6000i_2abg_cfg)},
4484 {IWL_PCI_DEVICE(0x4238, 0x1111, iwl6000_3agn_cfg)},
4485 {IWL_PCI_DEVICE(0x4239, 0x1311, iwl6000i_2agn_cfg)},
4486 {IWL_PCI_DEVICE(0x4239, 0x1316, iwl6000i_2abg_cfg)},
Shanyu Zhao4b3e8062010-04-07 18:06:36 -07004487
Shanyu Zhao95b13012010-04-21 11:46:33 -07004488/* 6x00 Series Gen2a */
4489 {IWL_PCI_DEVICE(0x0082, 0x1201, iwl6000g2a_2agn_cfg)},
4490 {IWL_PCI_DEVICE(0x0085, 0x1211, iwl6000g2a_2agn_cfg)},
4491 {IWL_PCI_DEVICE(0x0082, 0x1221, iwl6000g2a_2agn_cfg)},
Shanyu Zhao18089722010-05-06 10:15:21 -07004492 {IWL_PCI_DEVICE(0x0082, 0x1206, iwl6000g2a_2abg_cfg)},
4493 {IWL_PCI_DEVICE(0x0085, 0x1216, iwl6000g2a_2abg_cfg)},
4494 {IWL_PCI_DEVICE(0x0082, 0x1226, iwl6000g2a_2abg_cfg)},
4495 {IWL_PCI_DEVICE(0x0082, 0x1207, iwl6000g2a_2bg_cfg)},
Shanyu Zhao9f6e1ba2010-05-11 15:21:54 -07004496 {IWL_PCI_DEVICE(0x0082, 0x1301, iwl6000g2a_2agn_cfg)},
4497 {IWL_PCI_DEVICE(0x0082, 0x1306, iwl6000g2a_2abg_cfg)},
4498 {IWL_PCI_DEVICE(0x0082, 0x1307, iwl6000g2a_2bg_cfg)},
4499 {IWL_PCI_DEVICE(0x0082, 0x1321, iwl6000g2a_2agn_cfg)},
4500 {IWL_PCI_DEVICE(0x0082, 0x1326, iwl6000g2a_2abg_cfg)},
4501 {IWL_PCI_DEVICE(0x0085, 0x1311, iwl6000g2a_2agn_cfg)},
4502 {IWL_PCI_DEVICE(0x0085, 0x1316, iwl6000g2a_2abg_cfg)},
Shanyu Zhao18089722010-05-06 10:15:21 -07004503
4504/* 6x00 Series Gen2b */
4505 {IWL_PCI_DEVICE(0x008F, 0x5105, iwl6000g2b_bgn_cfg)},
4506 {IWL_PCI_DEVICE(0x0090, 0x5115, iwl6000g2b_bgn_cfg)},
4507 {IWL_PCI_DEVICE(0x008F, 0x5125, iwl6000g2b_bgn_cfg)},
4508 {IWL_PCI_DEVICE(0x008F, 0x5107, iwl6000g2b_bg_cfg)},
4509 {IWL_PCI_DEVICE(0x008F, 0x5201, iwl6000g2b_2agn_cfg)},
4510 {IWL_PCI_DEVICE(0x0090, 0x5211, iwl6000g2b_2agn_cfg)},
4511 {IWL_PCI_DEVICE(0x008F, 0x5221, iwl6000g2b_2agn_cfg)},
4512 {IWL_PCI_DEVICE(0x008F, 0x5206, iwl6000g2b_2abg_cfg)},
4513 {IWL_PCI_DEVICE(0x0090, 0x5216, iwl6000g2b_2abg_cfg)},
4514 {IWL_PCI_DEVICE(0x008F, 0x5226, iwl6000g2b_2abg_cfg)},
4515 {IWL_PCI_DEVICE(0x008F, 0x5207, iwl6000g2b_2bg_cfg)},
Shanyu Zhao9f6e1ba2010-05-11 15:21:54 -07004516 {IWL_PCI_DEVICE(0x008A, 0x5301, iwl6000g2b_bgn_cfg)},
4517 {IWL_PCI_DEVICE(0x008A, 0x5305, iwl6000g2b_bgn_cfg)},
4518 {IWL_PCI_DEVICE(0x008A, 0x5307, iwl6000g2b_bg_cfg)},
4519 {IWL_PCI_DEVICE(0x008A, 0x5321, iwl6000g2b_bgn_cfg)},
4520 {IWL_PCI_DEVICE(0x008A, 0x5325, iwl6000g2b_bgn_cfg)},
4521 {IWL_PCI_DEVICE(0x008B, 0x5311, iwl6000g2b_bgn_cfg)},
4522 {IWL_PCI_DEVICE(0x008B, 0x5315, iwl6000g2b_bgn_cfg)},
4523 {IWL_PCI_DEVICE(0x0090, 0x5211, iwl6000g2b_2agn_cfg)},
4524 {IWL_PCI_DEVICE(0x0090, 0x5215, iwl6000g2b_2bgn_cfg)},
4525 {IWL_PCI_DEVICE(0x0090, 0x5216, iwl6000g2b_2abg_cfg)},
4526 {IWL_PCI_DEVICE(0x0091, 0x5201, iwl6000g2b_2agn_cfg)},
4527 {IWL_PCI_DEVICE(0x0091, 0x5205, iwl6000g2b_2bgn_cfg)},
4528 {IWL_PCI_DEVICE(0x0091, 0x5206, iwl6000g2b_2abg_cfg)},
4529 {IWL_PCI_DEVICE(0x0091, 0x5207, iwl6000g2b_2bg_cfg)},
4530 {IWL_PCI_DEVICE(0x0091, 0x5221, iwl6000g2b_2agn_cfg)},
4531 {IWL_PCI_DEVICE(0x0091, 0x5225, iwl6000g2b_2bgn_cfg)},
4532 {IWL_PCI_DEVICE(0x0091, 0x5226, iwl6000g2b_2abg_cfg)},
Wey-Yi Guy5953a622009-09-17 10:43:53 -07004533
4534/* 6x50 WiFi/WiMax Series */
Wey-Yi Guy5953a622009-09-17 10:43:53 -07004535 {IWL_PCI_DEVICE(0x0087, 0x1301, iwl6050_2agn_cfg)},
4536 {IWL_PCI_DEVICE(0x0087, 0x1306, iwl6050_2abg_cfg)},
4537 {IWL_PCI_DEVICE(0x0087, 0x1321, iwl6050_2agn_cfg)},
4538 {IWL_PCI_DEVICE(0x0087, 0x1326, iwl6050_2abg_cfg)},
Wey-Yi Guy5953a622009-09-17 10:43:53 -07004539 {IWL_PCI_DEVICE(0x0089, 0x1311, iwl6050_2agn_cfg)},
4540 {IWL_PCI_DEVICE(0x0089, 0x1316, iwl6050_2abg_cfg)},
4541
Shanyu Zhao03264332010-06-29 17:27:27 -07004542/* 6x50 WiFi/WiMax Series Gen2 */
4543 {IWL_PCI_DEVICE(0x0885, 0x1305, iwl6050g2_bgn_cfg)},
4544 {IWL_PCI_DEVICE(0x0885, 0x1306, iwl6050g2_bgn_cfg)},
4545 {IWL_PCI_DEVICE(0x0885, 0x1325, iwl6050g2_bgn_cfg)},
4546 {IWL_PCI_DEVICE(0x0885, 0x1326, iwl6050g2_bgn_cfg)},
4547 {IWL_PCI_DEVICE(0x0886, 0x1315, iwl6050g2_bgn_cfg)},
4548 {IWL_PCI_DEVICE(0x0886, 0x1316, iwl6050g2_bgn_cfg)},
4549
Jay Sternberg77dcb6a2009-03-06 13:52:55 -08004550/* 1000 Series WiFi */
Wey-Yi Guy4bd0914f2009-09-17 10:43:52 -07004551 {IWL_PCI_DEVICE(0x0083, 0x1205, iwl1000_bgn_cfg)},
4552 {IWL_PCI_DEVICE(0x0083, 0x1305, iwl1000_bgn_cfg)},
4553 {IWL_PCI_DEVICE(0x0083, 0x1225, iwl1000_bgn_cfg)},
4554 {IWL_PCI_DEVICE(0x0083, 0x1325, iwl1000_bgn_cfg)},
4555 {IWL_PCI_DEVICE(0x0084, 0x1215, iwl1000_bgn_cfg)},
4556 {IWL_PCI_DEVICE(0x0084, 0x1315, iwl1000_bgn_cfg)},
4557 {IWL_PCI_DEVICE(0x0083, 0x1206, iwl1000_bg_cfg)},
4558 {IWL_PCI_DEVICE(0x0083, 0x1306, iwl1000_bg_cfg)},
4559 {IWL_PCI_DEVICE(0x0083, 0x1226, iwl1000_bg_cfg)},
4560 {IWL_PCI_DEVICE(0x0083, 0x1326, iwl1000_bg_cfg)},
4561 {IWL_PCI_DEVICE(0x0084, 0x1216, iwl1000_bg_cfg)},
4562 {IWL_PCI_DEVICE(0x0084, 0x1316, iwl1000_bg_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004563#endif /* CONFIG_IWL5000 */
Tomas Winkler7100e922008-12-01 16:32:18 -08004564
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004565 {0}
4566};
4567MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
4568
4569static struct pci_driver iwl_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07004570 .name = DRV_NAME,
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004571 .id_table = iwl_hw_card_ids,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004572 .probe = iwl_pci_probe,
4573 .remove = __devexit_p(iwl_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07004574#ifdef CONFIG_PM
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004575 .suspend = iwl_pci_suspend,
4576 .resume = iwl_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07004577#endif
4578};
4579
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004580static int __init iwl_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07004581{
4582
4583 int ret;
Joe Perchesc96c31e2010-07-26 14:39:58 -07004584 pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
4585 pr_info(DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004586
Tomas Winklere227cea2008-07-18 13:53:05 +08004587 ret = iwlagn_rate_control_register();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004588 if (ret) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07004589 pr_err("Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004590 return ret;
4591 }
4592
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004593 ret = pci_register_driver(&iwl_driver);
Zhu Yib481de92007-09-25 17:54:57 -07004594 if (ret) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07004595 pr_err("Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004596 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07004597 }
Zhu Yib481de92007-09-25 17:54:57 -07004598
4599 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004600
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004601error_register:
Tomas Winklere227cea2008-07-18 13:53:05 +08004602 iwlagn_rate_control_unregister();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004603 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004604}
4605
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004606static void __exit iwl_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07004607{
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004608 pci_unregister_driver(&iwl_driver);
Tomas Winklere227cea2008-07-18 13:53:05 +08004609 iwlagn_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07004610}
4611
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004612module_exit(iwl_exit);
4613module_init(iwl_init);
Reinette Chatrea562a9d2009-07-17 09:30:24 -07004614
4615#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07004616module_param_named(debug50, iwl_debug_level, uint, S_IRUGO);
Reinette Chatrea562a9d2009-07-17 09:30:24 -07004617MODULE_PARM_DESC(debug50, "50XX debug output mask (deprecated)");
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07004618module_param_named(debug, iwl_debug_level, uint, S_IRUGO | S_IWUSR);
Reinette Chatrea562a9d2009-07-17 09:30:24 -07004619MODULE_PARM_DESC(debug, "debug output mask");
4620#endif
4621
Wey-Yi Guy2b068612010-03-22 09:17:39 -07004622module_param_named(swcrypto50, iwlagn_mod_params.sw_crypto, bool, S_IRUGO);
4623MODULE_PARM_DESC(swcrypto50,
4624 "using crypto in software (default 0 [hardware]) (deprecated)");
4625module_param_named(swcrypto, iwlagn_mod_params.sw_crypto, int, S_IRUGO);
4626MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
4627module_param_named(queues_num50,
4628 iwlagn_mod_params.num_of_queues, int, S_IRUGO);
4629MODULE_PARM_DESC(queues_num50,
4630 "number of hw queues in 50xx series (deprecated)");
4631module_param_named(queues_num, iwlagn_mod_params.num_of_queues, int, S_IRUGO);
4632MODULE_PARM_DESC(queues_num, "number of hw queues.");
4633module_param_named(11n_disable50, iwlagn_mod_params.disable_11n, int, S_IRUGO);
4634MODULE_PARM_DESC(11n_disable50, "disable 50XX 11n functionality (deprecated)");
4635module_param_named(11n_disable, iwlagn_mod_params.disable_11n, int, S_IRUGO);
4636MODULE_PARM_DESC(11n_disable, "disable 11n functionality");
4637module_param_named(amsdu_size_8K50, iwlagn_mod_params.amsdu_size_8K,
4638 int, S_IRUGO);
4639MODULE_PARM_DESC(amsdu_size_8K50,
4640 "enable 8K amsdu size in 50XX series (deprecated)");
4641module_param_named(amsdu_size_8K, iwlagn_mod_params.amsdu_size_8K,
4642 int, S_IRUGO);
4643MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
4644module_param_named(fw_restart50, iwlagn_mod_params.restart_fw, int, S_IRUGO);
4645MODULE_PARM_DESC(fw_restart50,
4646 "restart firmware in case of error (deprecated)");
4647module_param_named(fw_restart, iwlagn_mod_params.restart_fw, int, S_IRUGO);
4648MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");
4649module_param_named(
4650 disable_hw_scan, iwlagn_mod_params.disable_hw_scan, int, S_IRUGO);
4651MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
Johannes Bergdd7a2502010-04-28 23:33:10 -07004652
4653module_param_named(ucode_alternative, iwlagn_wanted_ucode_alternative, int,
4654 S_IRUGO);
4655MODULE_PARM_DESC(ucode_alternative,
4656 "specify ucode alternative to use from ucode file");
Wey-Yi Guybee008b2010-08-23 07:57:04 -07004657
4658module_param_named(antenna_coupling, iwlagn_ant_coupling, int, S_IRUGO);
4659MODULE_PARM_DESC(antenna_coupling,
4660 "specify antenna coupling in dB (defualt: 0 dB)");