blob: e0ec40ed43b7a98bae82a7543827b8b3be53bf1d [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"
Johannes Berg0de76732010-09-22 18:02:11 +020060#include "iwl-agn-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;
Wey-Yi Guyf37837c2010-08-23 07:57:12 -070091static bool iwlagn_bt_ch_announce = 1;
Wey-Yi Guybee008b2010-08-23 07:57:04 -070092
Zhu Yib481de92007-09-25 17:54:57 -070093/**
Johannes Berg7314c2b2010-09-22 18:01:55 +020094 * iwlagn_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -070095 *
Ian Schram01ebd062007-10-25 17:15:22 +080096 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -070097 * the active_rxon structure is updated with the new data. This
98 * function correctly transitions out of the RXON_ASSOC_MSK state if
99 * a HW tune is required based on the RXON structure changes.
100 */
Johannes Berg7314c2b2010-09-22 18:01:55 +0200101int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
Zhu Yib481de92007-09-25 17:54:57 -0700102{
103 /* cast away the const for active_rxon in this function */
Johannes Berg246ed352010-08-23 10:46:32 +0200104 struct iwl_rxon_cmd *active_rxon = (void *)&ctx->active;
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800105 int ret;
106 bool new_assoc =
Johannes Berg246ed352010-08-23 10:46:32 +0200107 !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
Johannes Bergb01efe42010-08-23 10:46:56 +0200108 bool old_assoc = !!(ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK);
Zhu Yib481de92007-09-25 17:54:57 -0700109
Tomas Winklerfee12472008-04-03 16:05:21 -0700110 if (!iwl_is_alive(priv))
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800111 return -EBUSY;
Zhu Yib481de92007-09-25 17:54:57 -0700112
Johannes Berg763cc3b2010-09-03 06:32:21 -0700113 if (!ctx->is_active)
114 return 0;
115
Zhu Yib481de92007-09-25 17:54:57 -0700116 /* always get timestamp with Rx frame */
Johannes Berg246ed352010-08-23 10:46:32 +0200117 ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700118
Johannes Berg246ed352010-08-23 10:46:32 +0200119 ret = iwl_check_rxon_cmd(priv, ctx);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800120 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800121 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700122 return -EINVAL;
123 }
124
Wey-Yi Guy0924e5192009-11-06 14:52:54 -0800125 /*
126 * receive commit_rxon request
127 * abort any previous channel switch if still in process
128 */
129 if (priv->switch_rxon.switch_in_progress &&
Johannes Berg246ed352010-08-23 10:46:32 +0200130 (priv->switch_rxon.channel != ctx->staging.channel)) {
Wey-Yi Guy0924e5192009-11-06 14:52:54 -0800131 IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
132 le16_to_cpu(priv->switch_rxon.channel));
Wey-Yi Guy79d07322010-05-06 08:54:11 -0700133 iwl_chswitch_done(priv, false);
Wey-Yi Guy0924e5192009-11-06 14:52:54 -0800134 }
135
Zhu Yib481de92007-09-25 17:54:57 -0700136 /* If we don't need to send a full RXON, we can use
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700137 * iwl_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -0700138 * and other flags for the current radio configuration. */
Johannes Berg246ed352010-08-23 10:46:32 +0200139 if (!iwl_full_rxon_required(priv, ctx)) {
140 ret = iwl_send_rxon_assoc(priv, ctx);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800141 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800142 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800143 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700144 }
145
Johannes Berg246ed352010-08-23 10:46:32 +0200146 memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon));
147 iwl_print_rx_config_cmd(priv, ctx);
Zhu Yib481de92007-09-25 17:54:57 -0700148 return 0;
149 }
150
Zhu Yib481de92007-09-25 17:54:57 -0700151 /* If we are currently associated and the new config requires
152 * an RXON_ASSOC and the new config wants the associated mask enabled,
153 * we must clear the associated from the active configuration
154 * before we apply the new config */
Johannes Berg246ed352010-08-23 10:46:32 +0200155 if (iwl_is_associated_ctx(ctx) && new_assoc) {
Tomas Winklere1623442009-01-27 14:27:56 -0800156 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
Zhu Yib481de92007-09-25 17:54:57 -0700157 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
158
Johannes Berg8f2d3d22010-08-23 10:46:37 +0200159 ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd,
Johannes Berg246ed352010-08-23 10:46:32 +0200160 sizeof(struct iwl_rxon_cmd),
161 active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -0700162
163 /* If the mask clearing failed then we set
164 * active_rxon back to what it was previously */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800165 if (ret) {
Zhu Yib481de92007-09-25 17:54:57 -0700166 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
Winkler, Tomas15b16872008-12-19 10:37:33 +0800167 IWL_ERR(priv, "Error clearing ASSOC_MSK (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800168 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700169 }
Johannes Bergdcef7322010-08-27 08:55:52 -0700170 iwl_clear_ucode_stations(priv, ctx);
171 iwl_restore_stations(priv, ctx);
Johannes Bergc10afb62010-08-23 10:46:43 +0200172 ret = iwl_restore_default_wep_keys(priv, ctx);
Johannes Berg335348b2010-03-30 10:11:46 -0700173 if (ret) {
174 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
175 return ret;
176 }
Zhu Yib481de92007-09-25 17:54:57 -0700177 }
178
Tomas Winklere1623442009-01-27 14:27:56 -0800179 IWL_DEBUG_INFO(priv, "Sending RXON\n"
Zhu Yib481de92007-09-25 17:54:57 -0700180 "* with%s RXON_FILTER_ASSOC_MSK\n"
181 "* channel = %d\n"
Johannes Berge1749612008-10-27 15:59:26 -0700182 "* bssid = %pM\n",
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800183 (new_assoc ? "" : "out"),
Johannes Berg246ed352010-08-23 10:46:32 +0200184 le16_to_cpu(ctx->staging.channel),
185 ctx->staging.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -0700186
Johannes Berg246ed352010-08-23 10:46:32 +0200187 iwl_set_rxon_hwcrypto(priv, ctx, !priv->cfg->mod_params->sw_crypto);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800188
Johannes Bergb01efe42010-08-23 10:46:56 +0200189 if (!old_assoc) {
Johannes Berg2491fa42010-08-23 10:46:52 +0200190 /*
191 * First of all, before setting associated, we need to
192 * send RXON timing so the device knows about the DTIM
193 * period and other timing values
194 */
Johannes Berg47313e32010-08-23 10:46:55 +0200195 ret = iwl_send_rxon_timing(priv, ctx);
Johannes Berg2491fa42010-08-23 10:46:52 +0200196 if (ret) {
197 IWL_ERR(priv, "Error setting RXON timing!\n");
198 return ret;
199 }
200 }
201
Johannes Berg52a02d12010-08-27 09:44:50 -0700202 if (priv->cfg->ops->hcmd->set_pan_params) {
203 ret = priv->cfg->ops->hcmd->set_pan_params(priv);
204 if (ret)
205 return ret;
206 }
207
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800208 /* Apply the new configuration
Reinette Chatre7e246192010-02-18 22:58:32 -0800209 * RXON unassoc clears the station table in uCode so restoration of
210 * stations is needed after it (the RXON command) completes
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800211 */
212 if (!new_assoc) {
Johannes Berg8f2d3d22010-08-23 10:46:37 +0200213 ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd,
Johannes Berg246ed352010-08-23 10:46:32 +0200214 sizeof(struct iwl_rxon_cmd), &ctx->staging);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800215 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800216 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800217 return ret;
218 }
Frans Pop91dd6c22010-03-24 14:19:58 -0700219 IWL_DEBUG_INFO(priv, "Return from !new_assoc RXON.\n");
Johannes Berg246ed352010-08-23 10:46:32 +0200220 memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon));
Johannes Bergdcef7322010-08-27 08:55:52 -0700221 iwl_clear_ucode_stations(priv, ctx);
222 iwl_restore_stations(priv, ctx);
Johannes Bergc10afb62010-08-23 10:46:43 +0200223 ret = iwl_restore_default_wep_keys(priv, ctx);
Johannes Berg335348b2010-03-30 10:11:46 -0700224 if (ret) {
225 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
226 return ret;
227 }
Zhu Yib481de92007-09-25 17:54:57 -0700228 }
Tomas Winkler91851592008-06-30 17:23:14 +0800229 if (new_assoc) {
Wey-Yi Guy8f1d9682010-09-03 11:42:04 -0700230 priv->start_calib = 0;
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800231 /* Apply the new configuration
232 * RXON assoc doesn't clear the station table in uCode,
233 */
Johannes Berg8f2d3d22010-08-23 10:46:37 +0200234 ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd,
Johannes Berg246ed352010-08-23 10:46:32 +0200235 sizeof(struct iwl_rxon_cmd), &ctx->staging);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800236 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800237 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800238 return ret;
239 }
Johannes Berg246ed352010-08-23 10:46:32 +0200240 memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700241 }
Johannes Berg246ed352010-08-23 10:46:32 +0200242 iwl_print_rx_config_cmd(priv, ctx);
Zhu Yib481de92007-09-25 17:54:57 -0700243
Zhu Yi36da7d72008-07-11 11:53:40 +0800244 iwl_init_sensitivity(priv);
245
246 /* If we issue a new RXON command which required a tune then we must
247 * send a new TXPOWER command or we won't be able to Tx any frames */
248 ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
249 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800250 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
Zhu Yi36da7d72008-07-11 11:53:40 +0800251 return ret;
252 }
253
Zhu Yib481de92007-09-25 17:54:57 -0700254 return 0;
255}
256
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700257void iwl_update_chain_flags(struct iwl_priv *priv)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700258{
Johannes Berg246ed352010-08-23 10:46:32 +0200259 struct iwl_rxon_context *ctx;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700260
Johannes Berg246ed352010-08-23 10:46:32 +0200261 if (priv->cfg->ops->hcmd->set_rxon_chain) {
262 for_each_context(priv, ctx) {
263 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
264 iwlcore_commit_rxon(priv, ctx);
265 }
266 }
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700267}
268
Tomas Winklerfcab4232008-05-15 13:54:01 +0800269static void iwl_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700270{
271 struct list_head *element;
272
Tomas Winklere1623442009-01-27 14:27:56 -0800273 IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
Zhu Yib481de92007-09-25 17:54:57 -0700274 priv->frames_count);
275
276 while (!list_empty(&priv->free_frames)) {
277 element = priv->free_frames.next;
278 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800279 kfree(list_entry(element, struct iwl_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700280 priv->frames_count--;
281 }
282
283 if (priv->frames_count) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800284 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
Zhu Yib481de92007-09-25 17:54:57 -0700285 priv->frames_count);
286 priv->frames_count = 0;
287 }
288}
289
Tomas Winklerfcab4232008-05-15 13:54:01 +0800290static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700291{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800292 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700293 struct list_head *element;
294 if (list_empty(&priv->free_frames)) {
295 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
296 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800297 IWL_ERR(priv, "Could not allocate frame!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700298 return NULL;
299 }
300
301 priv->frames_count++;
302 return frame;
303 }
304
305 element = priv->free_frames.next;
306 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800307 return list_entry(element, struct iwl_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700308}
309
Tomas Winklerfcab4232008-05-15 13:54:01 +0800310static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700311{
312 memset(frame, 0, sizeof(*frame));
313 list_add(&frame->list, &priv->free_frames);
314}
315
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800316static u32 iwl_fill_beacon_frame(struct iwl_priv *priv,
Johannes Berg77834542010-10-04 05:50:36 -0700317 struct ieee80211_hdr *hdr,
318 int left)
Zhu Yib481de92007-09-25 17:54:57 -0700319{
Johannes Berg77834542010-10-04 05:50:36 -0700320 lockdep_assert_held(&priv->mutex);
321
Johannes Berg12e934d2010-10-04 05:50:06 -0700322 if (!priv->beacon_skb)
Zhu Yib481de92007-09-25 17:54:57 -0700323 return 0;
324
Johannes Berg12e934d2010-10-04 05:50:06 -0700325 if (priv->beacon_skb->len > left)
Zhu Yib481de92007-09-25 17:54:57 -0700326 return 0;
327
Johannes Berg12e934d2010-10-04 05:50:06 -0700328 memcpy(hdr, priv->beacon_skb->data, priv->beacon_skb->len);
Zhu Yib481de92007-09-25 17:54:57 -0700329
Johannes Berg12e934d2010-10-04 05:50:06 -0700330 return priv->beacon_skb->len;
Zhu Yib481de92007-09-25 17:54:57 -0700331}
332
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800333/* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
334static void iwl_set_beacon_tim(struct iwl_priv *priv,
Johannes Berg77834542010-10-04 05:50:36 -0700335 struct iwl_tx_beacon_cmd *tx_beacon_cmd,
336 u8 *beacon, u32 frame_size)
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800337{
338 u16 tim_idx;
339 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
340
341 /*
342 * The index is relative to frame start but we start looking at the
343 * variable-length part of the beacon.
344 */
345 tim_idx = mgmt->u.beacon.variable - beacon;
346
347 /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
348 while ((tim_idx < (frame_size - 2)) &&
349 (beacon[tim_idx] != WLAN_EID_TIM))
350 tim_idx += beacon[tim_idx+1] + 2;
351
352 /* If TIM field was found, set variables */
353 if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
354 tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
355 tx_beacon_cmd->tim_size = beacon[tim_idx+1];
356 } else
357 IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
358}
359
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700360static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800361 struct iwl_frame *frame)
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800362{
363 struct iwl_tx_beacon_cmd *tx_beacon_cmd;
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800364 u32 frame_size;
365 u32 rate_flags;
366 u32 rate;
367 /*
368 * We have to set up the TX command, the TX Beacon command, and the
369 * beacon contents.
370 */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800371
Johannes Berg76d04812010-08-23 10:46:47 +0200372 lockdep_assert_held(&priv->mutex);
373
374 if (!priv->beacon_ctx) {
375 IWL_ERR(priv, "trying to build beacon w/o beacon context!\n");
Julia Lawall950094c2010-09-05 21:00:26 +0200376 return 0;
Johannes Berg76d04812010-08-23 10:46:47 +0200377 }
378
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800379 /* Initialize memory */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800380 tx_beacon_cmd = &frame->u.beacon;
381 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
382
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800383 /* Set up TX beacon contents */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800384 frame_size = iwl_fill_beacon_frame(priv, tx_beacon_cmd->frame,
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800385 sizeof(frame->u) - sizeof(*tx_beacon_cmd));
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800386 if (WARN_ON_ONCE(frame_size > MAX_MPDU_SIZE))
387 return 0;
Johannes Berg40bbfd42010-10-07 04:00:33 -0700388 if (!frame_size)
389 return 0;
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800390
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800391 /* Set up TX command fields */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800392 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
Johannes Berg76d04812010-08-23 10:46:47 +0200393 tx_beacon_cmd->tx.sta_id = priv->beacon_ctx->bcast_sta_id;
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800394 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800395 tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800396 TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
397
398 /* Set up TX beacon command fields */
399 iwl_set_beacon_tim(priv, tx_beacon_cmd, (u8 *)tx_beacon_cmd->frame,
Johannes Berg77834542010-10-04 05:50:36 -0700400 frame_size);
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800401
402 /* Set up packet rate and flags */
Johannes Berg76d04812010-08-23 10:46:47 +0200403 rate = iwl_rate_get_lowest_plcp(priv, priv->beacon_ctx);
Johannes Berg0e1654f2010-05-18 02:48:36 -0700404 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
405 priv->hw_params.valid_tx_ant);
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800406 rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
407 if ((rate >= IWL_FIRST_CCK_RATE) && (rate <= IWL_LAST_CCK_RATE))
408 rate_flags |= RATE_MCS_CCK_MSK;
409 tx_beacon_cmd->tx.rate_n_flags = iwl_hw_set_rate_n_flags(rate,
410 rate_flags);
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800411
412 return sizeof(*tx_beacon_cmd) + frame_size;
413}
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700414static int iwl_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700415{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800416 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700417 unsigned int frame_size;
418 int rc;
Zhu Yib481de92007-09-25 17:54:57 -0700419
Tomas Winklerfcab4232008-05-15 13:54:01 +0800420 frame = iwl_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700421 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800422 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
Zhu Yib481de92007-09-25 17:54:57 -0700423 "command.\n");
424 return -ENOMEM;
425 }
426
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800427 frame_size = iwl_hw_get_beacon_cmd(priv, frame);
428 if (!frame_size) {
429 IWL_ERR(priv, "Error configuring the beacon command\n");
430 iwl_free_frame(priv, frame);
431 return -EINVAL;
432 }
Zhu Yib481de92007-09-25 17:54:57 -0700433
Tomas Winkler857485c2008-03-21 13:53:44 -0700434 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700435 &frame->u.cmd[0]);
436
Tomas Winklerfcab4232008-05-15 13:54:01 +0800437 iwl_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700438
439 return rc;
440}
441
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800442static inline dma_addr_t iwl_tfd_tb_get_addr(struct iwl_tfd *tfd, u8 idx)
443{
444 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
445
446 dma_addr_t addr = get_unaligned_le32(&tb->lo);
447 if (sizeof(dma_addr_t) > sizeof(u32))
448 addr |=
449 ((dma_addr_t)(le16_to_cpu(tb->hi_n_len) & 0xF) << 16) << 16;
450
451 return addr;
452}
453
454static inline u16 iwl_tfd_tb_get_len(struct iwl_tfd *tfd, u8 idx)
455{
456 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
457
458 return le16_to_cpu(tb->hi_n_len) >> 4;
459}
460
461static inline void iwl_tfd_set_tb(struct iwl_tfd *tfd, u8 idx,
462 dma_addr_t addr, u16 len)
463{
464 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
465 u16 hi_n_len = len << 4;
466
467 put_unaligned_le32(addr, &tb->lo);
468 if (sizeof(dma_addr_t) > sizeof(u32))
469 hi_n_len |= ((addr >> 16) >> 16) & 0xF;
470
471 tb->hi_n_len = cpu_to_le16(hi_n_len);
472
473 tfd->num_tbs = idx + 1;
474}
475
476static inline u8 iwl_tfd_get_num_tbs(struct iwl_tfd *tfd)
477{
478 return tfd->num_tbs & 0x1f;
479}
480
481/**
482 * iwl_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
483 * @priv - driver private data
484 * @txq - tx queue
485 *
486 * Does NOT advance any TFD circular buffer read/write indexes
487 * Does NOT free the TFD itself (which is within circular buffer)
488 */
489void iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq)
490{
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800491 struct iwl_tfd *tfd_tmp = (struct iwl_tfd *)txq->tfds;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800492 struct iwl_tfd *tfd;
493 struct pci_dev *dev = priv->pci_dev;
494 int index = txq->q.read_ptr;
495 int i;
496 int num_tbs;
497
498 tfd = &tfd_tmp[index];
499
500 /* Sanity check on number of chunks */
501 num_tbs = iwl_tfd_get_num_tbs(tfd);
502
503 if (num_tbs >= IWL_NUM_OF_TBS) {
504 IWL_ERR(priv, "Too many chunks: %i\n", num_tbs);
505 /* @todo issue fatal error, it is quite serious situation */
506 return;
507 }
508
509 /* Unmap tx_cmd */
510 if (num_tbs)
511 pci_unmap_single(dev,
FUJITA Tomonori2e724442010-06-03 14:19:20 +0900512 dma_unmap_addr(&txq->meta[index], mapping),
513 dma_unmap_len(&txq->meta[index], len),
Fenghua Yu96891ce2009-02-18 15:54:33 -0800514 PCI_DMA_BIDIRECTIONAL);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800515
516 /* Unmap chunks, if any. */
Johannes Bergff0d91c2010-05-17 02:37:34 -0700517 for (i = 1; i < num_tbs; i++)
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800518 pci_unmap_single(dev, iwl_tfd_tb_get_addr(tfd, i),
519 iwl_tfd_tb_get_len(tfd, i), PCI_DMA_TODEVICE);
520
Johannes Bergff0d91c2010-05-17 02:37:34 -0700521 /* free SKB */
522 if (txq->txb) {
523 struct sk_buff *skb;
Johannes Berg6f802402010-05-17 02:37:32 -0700524
Johannes Bergff0d91c2010-05-17 02:37:34 -0700525 skb = txq->txb[txq->q.read_ptr].skb;
Johannes Berg6f802402010-05-17 02:37:32 -0700526
Johannes Bergff0d91c2010-05-17 02:37:34 -0700527 /* can be called from irqs-disabled context */
528 if (skb) {
529 dev_kfree_skb_any(skb);
530 txq->txb[txq->q.read_ptr].skb = NULL;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800531 }
532 }
533}
534
535int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv,
536 struct iwl_tx_queue *txq,
537 dma_addr_t addr, u16 len,
538 u8 reset, u8 pad)
539{
540 struct iwl_queue *q;
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800541 struct iwl_tfd *tfd, *tfd_tmp;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800542 u32 num_tbs;
543
544 q = &txq->q;
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800545 tfd_tmp = (struct iwl_tfd *)txq->tfds;
546 tfd = &tfd_tmp[q->write_ptr];
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800547
548 if (reset)
549 memset(tfd, 0, sizeof(*tfd));
550
551 num_tbs = iwl_tfd_get_num_tbs(tfd);
552
553 /* Each TFD can point to a maximum 20 Tx buffers */
554 if (num_tbs >= IWL_NUM_OF_TBS) {
555 IWL_ERR(priv, "Error can not send more than %d chunks\n",
556 IWL_NUM_OF_TBS);
557 return -EINVAL;
558 }
559
560 BUG_ON(addr & ~DMA_BIT_MASK(36));
561 if (unlikely(addr & ~IWL_TX_DMA_MASK))
562 IWL_ERR(priv, "Unaligned address = %llx\n",
563 (unsigned long long)addr);
564
565 iwl_tfd_set_tb(tfd, num_tbs, addr, len);
566
567 return 0;
568}
569
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800570/*
571 * Tell nic where to find circular buffer of Tx Frame Descriptors for
572 * given Tx queue, and enable the DMA channel used for that queue.
573 *
574 * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
575 * channels supported in hardware.
576 */
577int iwl_hw_tx_queue_init(struct iwl_priv *priv,
578 struct iwl_tx_queue *txq)
579{
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800580 int txq_id = txq->q.id;
581
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800582 /* Circular buffer (TFD queue in DRAM) physical base address */
583 iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
584 txq->q.dma_addr >> 8);
585
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800586 return 0;
587}
588
Zhu Yib481de92007-09-25 17:54:57 -0700589/******************************************************************************
590 *
591 * Generic RX handler implementations
592 *
593 ******************************************************************************/
Tomas Winkler885ba202008-05-29 16:34:55 +0800594static void iwl_rx_reply_alive(struct iwl_priv *priv,
595 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700596{
Zhu Yi2f301222009-10-09 17:19:45 +0800597 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Tomas Winkler885ba202008-05-29 16:34:55 +0800598 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -0700599 struct delayed_work *pwork;
600
601 palive = &pkt->u.alive_frame;
602
Tomas Winklere1623442009-01-27 14:27:56 -0800603 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
Zhu Yib481de92007-09-25 17:54:57 -0700604 "0x%01X 0x%01X\n",
605 palive->is_valid, palive->ver_type,
606 palive->ver_subtype);
607
608 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
Tomas Winklere1623442009-01-27 14:27:56 -0800609 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700610 memcpy(&priv->card_alive_init,
611 &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +0800612 sizeof(struct iwl_init_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700613 pwork = &priv->init_alive_start;
614 } else {
Tomas Winklere1623442009-01-27 14:27:56 -0800615 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700616 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +0800617 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -0700618 pwork = &priv->alive_start;
619 }
620
621 /* We delay the ALIVE response by 5ms to
622 * give the HW RF Kill time to activate... */
623 if (palive->is_valid == UCODE_VALID_OK)
624 queue_delayed_work(priv->workqueue, pwork,
625 msecs_to_jiffies(5));
626 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800627 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700628}
629
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700630static void iwl_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -0700631{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700632 struct iwl_priv *priv =
633 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -0700634 struct sk_buff *beacon;
635
Johannes Berg76d04812010-08-23 10:46:47 +0200636 mutex_lock(&priv->mutex);
637 if (!priv->beacon_ctx) {
638 IWL_ERR(priv, "updating beacon w/o beacon context!\n");
639 goto out;
Zhu Yib481de92007-09-25 17:54:57 -0700640 }
641
Johannes Berg60744f62010-08-23 10:46:50 +0200642 if (priv->beacon_ctx->vif->type != NL80211_IFTYPE_AP) {
643 /*
644 * The ucode will send beacon notifications even in
645 * IBSS mode, but we don't want to process them. But
646 * we need to defer the type check to here due to
647 * requiring locking around the beacon_ctx access.
648 */
649 goto out;
650 }
651
Johannes Berg76d04812010-08-23 10:46:47 +0200652 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
653 beacon = ieee80211_beacon_get(priv->hw, priv->beacon_ctx->vif);
654 if (!beacon) {
Johannes Berg77834542010-10-04 05:50:36 -0700655 IWL_ERR(priv, "update beacon failed -- keeping old\n");
Johannes Berg76d04812010-08-23 10:46:47 +0200656 goto out;
657 }
658
Zhu Yib481de92007-09-25 17:54:57 -0700659 /* new beacon skb is allocated every time; dispose previous.*/
Johannes Berg77834542010-10-04 05:50:36 -0700660 dev_kfree_skb(priv->beacon_skb);
Zhu Yib481de92007-09-25 17:54:57 -0700661
Johannes Berg12e934d2010-10-04 05:50:06 -0700662 priv->beacon_skb = beacon;
Zhu Yib481de92007-09-25 17:54:57 -0700663
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700664 iwl_send_beacon_cmd(priv);
Johannes Berg76d04812010-08-23 10:46:47 +0200665 out:
666 mutex_unlock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -0700667}
668
Wey-Yi Guyfbba9412010-08-23 07:57:10 -0700669static void iwl_bg_bt_runtime_config(struct work_struct *work)
670{
671 struct iwl_priv *priv =
672 container_of(work, struct iwl_priv, bt_runtime_config);
673
674 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
675 return;
676
677 /* dont send host command if rf-kill is on */
678 if (!iwl_is_ready_rf(priv))
679 return;
680 priv->cfg->ops->hcmd->send_bt_config(priv);
681}
682
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700683static void iwl_bg_bt_full_concurrency(struct work_struct *work)
684{
685 struct iwl_priv *priv =
686 container_of(work, struct iwl_priv, bt_full_concurrency);
Johannes Berg246ed352010-08-23 10:46:32 +0200687 struct iwl_rxon_context *ctx;
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700688
689 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
690 return;
691
692 /* dont send host command if rf-kill is on */
693 if (!iwl_is_ready_rf(priv))
694 return;
695
696 IWL_DEBUG_INFO(priv, "BT coex in %s mode\n",
697 priv->bt_full_concurrent ?
698 "full concurrency" : "3-wire");
699
700 /*
701 * LQ & RXON updated cmds must be sent before BT Config cmd
702 * to avoid 3-wire collisions
703 */
Johannes Berg246ed352010-08-23 10:46:32 +0200704 mutex_lock(&priv->mutex);
705 for_each_context(priv, ctx) {
706 if (priv->cfg->ops->hcmd->set_rxon_chain)
707 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
708 iwlcore_commit_rxon(priv, ctx);
709 }
710 mutex_unlock(&priv->mutex);
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700711
712 priv->cfg->ops->hcmd->send_bt_config(priv);
713}
714
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800715/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700716 * iwl_bg_statistics_periodic - Timer callback to queue statistics
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800717 *
718 * This callback is provided in order to send a statistics request.
719 *
720 * This timer function is continually reset to execute within
721 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
722 * was received. We need to ensure we receive the statistics in order
723 * to update the temperature used for calibrating the TXPOWER.
724 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700725static void iwl_bg_statistics_periodic(unsigned long data)
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800726{
727 struct iwl_priv *priv = (struct iwl_priv *)data;
728
729 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
730 return;
731
Mohamed Abbas61780ee2008-10-29 14:05:49 -0700732 /* dont send host command if rf-kill is on */
733 if (!iwl_is_ready_rf(priv))
734 return;
735
Wey-Yi Guyef8d5522009-11-13 11:56:28 -0800736 iwl_send_statistics_request(priv, CMD_ASYNC, false);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800737}
738
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800739
740static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base,
741 u32 start_idx, u32 num_events,
742 u32 mode)
743{
744 u32 i;
745 u32 ptr; /* SRAM byte address of log data */
746 u32 ev, time, data; /* event log data */
747 unsigned long reg_flags;
748
749 if (mode == 0)
750 ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32));
751 else
752 ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32));
753
754 /* Make sure device is powered up for SRAM reads */
755 spin_lock_irqsave(&priv->reg_lock, reg_flags);
756 if (iwl_grab_nic_access(priv)) {
757 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
758 return;
759 }
760
761 /* Set starting address; reads will auto-increment */
762 _iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, ptr);
763 rmb();
764
765 /*
766 * "time" is actually "data" for mode 0 (no timestamp).
767 * place event id # at far right for easier visual parsing.
768 */
769 for (i = 0; i < num_events; i++) {
770 ev = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
771 time = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
772 if (mode == 0) {
773 trace_iwlwifi_dev_ucode_cont_event(priv,
774 0, time, ev);
775 } else {
776 data = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
777 trace_iwlwifi_dev_ucode_cont_event(priv,
778 time, data, ev);
779 }
780 }
781 /* Allow device to power down */
782 iwl_release_nic_access(priv);
783 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
784}
785
Johannes Berg875295f2010-01-22 14:22:55 -0800786static void iwl_continuous_event_trace(struct iwl_priv *priv)
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800787{
788 u32 capacity; /* event log capacity in # entries */
789 u32 base; /* SRAM byte address of event log header */
790 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
791 u32 num_wraps; /* # times uCode wrapped to top of log */
792 u32 next_entry; /* index of next entry to be written by uCode */
793
794 if (priv->ucode_type == UCODE_INIT)
795 base = le32_to_cpu(priv->card_alive_init.error_event_table_ptr);
796 else
797 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
798 if (priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
799 capacity = iwl_read_targ_mem(priv, base);
800 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
801 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
802 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
803 } else
804 return;
805
806 if (num_wraps == priv->event_log.num_wraps) {
807 iwl_print_cont_event_trace(priv,
808 base, priv->event_log.next_entry,
809 next_entry - priv->event_log.next_entry,
810 mode);
811 priv->event_log.non_wraps_count++;
812 } else {
813 if ((num_wraps - priv->event_log.num_wraps) > 1)
814 priv->event_log.wraps_more_count++;
815 else
816 priv->event_log.wraps_once_count++;
817 trace_iwlwifi_dev_ucode_wrap_event(priv,
818 num_wraps - priv->event_log.num_wraps,
819 next_entry, priv->event_log.next_entry);
820 if (next_entry < priv->event_log.next_entry) {
821 iwl_print_cont_event_trace(priv, base,
822 priv->event_log.next_entry,
823 capacity - priv->event_log.next_entry,
824 mode);
825
826 iwl_print_cont_event_trace(priv, base, 0,
827 next_entry, mode);
828 } else {
829 iwl_print_cont_event_trace(priv, base,
830 next_entry, capacity - next_entry,
831 mode);
832
833 iwl_print_cont_event_trace(priv, base, 0,
834 next_entry, mode);
835 }
836 }
837 priv->event_log.num_wraps = num_wraps;
838 priv->event_log.next_entry = next_entry;
839}
840
841/**
842 * iwl_bg_ucode_trace - Timer callback to log ucode event
843 *
844 * The timer is continually set to execute every
845 * UCODE_TRACE_PERIOD milliseconds after the last timer expired
846 * this function is to perform continuous uCode event logging operation
847 * if enabled
848 */
849static void iwl_bg_ucode_trace(unsigned long data)
850{
851 struct iwl_priv *priv = (struct iwl_priv *)data;
852
853 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
854 return;
855
856 if (priv->event_log.ucode_trace) {
857 iwl_continuous_event_trace(priv);
858 /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
859 mod_timer(&priv->ucode_trace,
860 jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
861 }
862}
863
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700864static void iwl_rx_beacon_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +0800865 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700866{
Zhu Yi2f301222009-10-09 17:19:45 +0800867 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Tomas Winkler2aa6ab82008-12-11 10:33:40 -0800868 struct iwl4965_beacon_notif *beacon =
869 (struct iwl4965_beacon_notif *)pkt->u.raw;
Johannes Berga85d7cc2010-07-31 08:34:10 -0700870#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklere7d326a2008-06-12 09:47:11 +0800871 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -0700872
Tomas Winklere1623442009-01-27 14:27:56 -0800873 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
Zhu Yib481de92007-09-25 17:54:57 -0700874 "tsf %d %d rate %d\n",
Tomas Winkler25a65722008-06-12 09:47:07 +0800875 le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
Zhu Yib481de92007-09-25 17:54:57 -0700876 beacon->beacon_notify_hdr.failure_frame,
877 le32_to_cpu(beacon->ibss_mgr_status),
878 le32_to_cpu(beacon->high_tsf),
879 le32_to_cpu(beacon->low_tsf), rate);
880#endif
881
Johannes Berga85d7cc2010-07-31 08:34:10 -0700882 priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
883
Johannes Berg60744f62010-08-23 10:46:50 +0200884 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -0700885 queue_work(priv->workqueue, &priv->beacon_update);
886}
887
Zhu Yib481de92007-09-25 17:54:57 -0700888/* Handle notification from uCode that card's power state is changing
889 * due to software, hardware, or critical temperature RFKILL */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700890static void iwl_rx_card_state_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +0800891 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -0700892{
Zhu Yi2f301222009-10-09 17:19:45 +0800893 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Zhu Yib481de92007-09-25 17:54:57 -0700894 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
895 unsigned long status = priv->status;
896
Wey-Yi Guy3a41bbd2009-12-10 14:37:24 -0800897 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s CT:%s\n",
Zhu Yib481de92007-09-25 17:54:57 -0700898 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
Wey-Yi Guy3a41bbd2009-12-10 14:37:24 -0800899 (flags & SW_CARD_DISABLED) ? "Kill" : "On",
900 (flags & CT_CARD_DISABLED) ?
901 "Reached" : "Not reached");
Zhu Yib481de92007-09-25 17:54:57 -0700902
903 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
Wey-Yi Guy3a41bbd2009-12-10 14:37:24 -0800904 CT_CARD_DISABLED)) {
Zhu Yib481de92007-09-25 17:54:57 -0700905
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700906 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -0700907 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
908
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700909 iwl_write_direct32(priv, HBUS_TARG_MBX_C,
910 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
Zhu Yib481de92007-09-25 17:54:57 -0700911
912 if (!(flags & RXON_CARD_DISABLED)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -0700913 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -0700914 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
Mohamed Abbasa8b50a02009-05-22 11:01:47 -0700915 iwl_write_direct32(priv, HBUS_TARG_MBX_C,
Zhu Yib481de92007-09-25 17:54:57 -0700916 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
Zhu Yib481de92007-09-25 17:54:57 -0700917 }
Wey-Yi Guy3a41bbd2009-12-10 14:37:24 -0800918 if (flags & CT_CARD_DISABLED)
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -0700919 iwl_tt_enter_ct_kill(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700920 }
Wey-Yi Guy3a41bbd2009-12-10 14:37:24 -0800921 if (!(flags & CT_CARD_DISABLED))
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -0700922 iwl_tt_exit_ct_kill(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700923
924 if (flags & HW_CARD_DISABLED)
925 set_bit(STATUS_RF_KILL_HW, &priv->status);
926 else
927 clear_bit(STATUS_RF_KILL_HW, &priv->status);
928
929
Zhu Yib481de92007-09-25 17:54:57 -0700930 if (!(flags & RXON_CARD_DISABLED))
Tomas Winkler2a421b92008-06-12 09:47:10 +0800931 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700932
933 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
Johannes Berga60e77e2009-06-04 18:26:06 +0200934 test_bit(STATUS_RF_KILL_HW, &priv->status)))
935 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
936 test_bit(STATUS_RF_KILL_HW, &priv->status));
Zhu Yib481de92007-09-25 17:54:57 -0700937 else
938 wake_up_interruptible(&priv->wait_command_queue);
939}
940
Wey-Yi Guy65550632010-06-24 13:18:35 -0700941static void iwl_bg_tx_flush(struct work_struct *work)
942{
943 struct iwl_priv *priv =
944 container_of(work, struct iwl_priv, tx_flush);
945
946 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
947 return;
948
949 /* do nothing if rf-kill is on */
950 if (!iwl_is_ready_rf(priv))
951 return;
952
953 if (priv->cfg->ops->lib->txfifo_flush) {
954 IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n");
955 iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
956 }
957}
958
Zhu Yib481de92007-09-25 17:54:57 -0700959/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700960 * iwl_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -0700961 *
962 * Setup the RX handlers for each of the reply types sent from the uCode
963 * to the host.
964 *
965 * This function chains into the hardware specific files for them to setup
966 * any hardware specific handlers as well.
967 */
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +0800968static void iwl_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700969{
Tomas Winkler885ba202008-05-29 16:34:55 +0800970 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700971 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
972 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Reinette Chatre81963d62010-01-22 14:22:57 -0800973 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
974 iwl_rx_spectrum_measure_notif;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700975 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700976 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700977 iwl_rx_pm_debug_statistics_notif;
978 priv->rx_handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700979
Ben Cahill9fbab512007-11-29 11:09:47 +0800980 /*
981 * The same handler is used for both the REPLY to a discrete
982 * statistics request from the host as well as for the periodic
983 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -0700984 */
Wey-Yi Guyef8d5522009-11-13 11:56:28 -0800985 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_reply_statistics;
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +0800986 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
Tomas Winkler2a421b92008-06-12 09:47:10 +0800987
988 iwl_setup_rx_scan_handlers(priv);
989
Ron Rindjunsky37a44212008-05-29 16:35:18 +0800990 /* status change handler */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700991 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -0700992
Tomas Winklerc1354752008-05-29 16:35:04 +0800993 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
994 iwl_rx_missed_beacon_notif;
Ron Rindjunsky37a44212008-05-29 16:35:18 +0800995 /* Rx handlers */
Wey-Yi Guy8d801082010-03-17 13:34:36 -0700996 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwlagn_rx_reply_rx_phy;
997 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwlagn_rx_reply_rx;
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +0800998 /* block ack */
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -0700999 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwlagn_rx_reply_compressed_ba;
Ben Cahill9fbab512007-11-29 11:09:47 +08001000 /* Set up hardware specific Rx handlers */
Emmanuel Grumbachd4789ef2008-04-24 11:55:20 -07001001 priv->cfg->ops->lib->rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001002}
1003
Zhu Yib481de92007-09-25 17:54:57 -07001004/**
Tomas Winklera55360e2008-05-05 10:22:28 +08001005 * iwl_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001006 *
1007 * Uses the priv->rx_handlers callback function array to invoke
1008 * the appropriate handlers, including command responses,
1009 * frame-received notifications, and other notifications.
1010 */
Tomas Winklera55360e2008-05-05 10:22:28 +08001011void iwl_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001012{
Tomas Winklera55360e2008-05-05 10:22:28 +08001013 struct iwl_rx_mem_buffer *rxb;
Tomas Winklerdb11d632008-05-05 10:22:33 +08001014 struct iwl_rx_packet *pkt;
Tomas Winklera55360e2008-05-05 10:22:28 +08001015 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001016 u32 r, i;
1017 int reclaim;
1018 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001019 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001020 u32 count = 8;
Mohamed Abbas4752c932009-05-22 11:01:51 -07001021 int total_empty;
Zhu Yib481de92007-09-25 17:54:57 -07001022
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001023 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1024 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8d864222008-11-07 09:58:39 -08001025 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07001026 i = rxq->read;
1027
1028 /* Rx interrupt, but nothing sent from uCode */
1029 if (i == r)
Tomas Winklere1623442009-01-27 14:27:56 -08001030 IWL_DEBUG_RX(priv, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001031
Mohamed Abbas4752c932009-05-22 11:01:51 -07001032 /* calculate total frames need to be restock after handling RX */
Zhu Yi73005152009-10-23 13:42:32 -07001033 total_empty = r - rxq->write_actual;
Mohamed Abbas4752c932009-05-22 11:01:51 -07001034 if (total_empty < 0)
1035 total_empty += RX_QUEUE_SIZE;
1036
1037 if (total_empty > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001038 fill_rx = 1;
1039
Zhu Yib481de92007-09-25 17:54:57 -07001040 while (i != r) {
Johannes Bergf4989d92010-05-28 04:08:30 -07001041 int len;
1042
Zhu Yib481de92007-09-25 17:54:57 -07001043 rxb = rxq->queue[i];
1044
Ben Cahill9fbab512007-11-29 11:09:47 +08001045 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001046 * then a bug has been introduced in the queue refilling
1047 * routines -- catch it here */
1048 BUG_ON(rxb == NULL);
1049
1050 rxq->queue[i] = NULL;
1051
Zhu Yi2f301222009-10-09 17:19:45 +08001052 pci_unmap_page(priv->pci_dev, rxb->page_dma,
1053 PAGE_SIZE << priv->hw_params.rx_page_order,
1054 PCI_DMA_FROMDEVICE);
1055 pkt = rxb_addr(rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001056
Johannes Bergf4989d92010-05-28 04:08:30 -07001057 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
1058 len += sizeof(u32); /* account for status word */
1059 trace_iwlwifi_dev_rx(priv, pkt, len);
Johannes Bergbe1a71a2009-10-02 13:44:02 -07001060
Zhu Yib481de92007-09-25 17:54:57 -07001061 /* Reclaim a command buffer only if this packet is a response
1062 * to a (driver-originated) command.
1063 * If the packet (e.g. Rx frame) originated from uCode,
1064 * there is no command buffer to reclaim.
1065 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1066 * but apparently a few don't get set; catch them here. */
1067 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1068 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
Tomas Winkler857485c2008-03-21 13:53:44 -07001069 (pkt->hdr.cmd != REPLY_RX) &&
Daniel Halperin7dddaf12008-10-23 23:48:58 -07001070 (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) &&
Zhu Yicfe01702007-09-27 11:27:31 +08001071 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
Zhu Yib481de92007-09-25 17:54:57 -07001072 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1073 (pkt->hdr.cmd != REPLY_TX);
1074
1075 /* Based on type of command response or notification,
1076 * handle those that need handling via function in
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001077 * rx_handlers table. See iwl_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001078 if (priv->rx_handlers[pkt->hdr.cmd]) {
Tomas Winklere1623442009-01-27 14:27:56 -08001079 IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r,
Ester Kummerf3d67992008-05-06 11:05:12 +08001080 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001081 priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
Zhu Yi29b1b262009-10-23 13:42:25 -07001082 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001083 } else {
1084 /* No handling needed */
Tomas Winklere1623442009-01-27 14:27:56 -08001085 IWL_DEBUG_RX(priv,
Zhu Yib481de92007-09-25 17:54:57 -07001086 "r %d i %d No handler needed for %s, 0x%02x\n",
1087 r, i, get_cmd_string(pkt->hdr.cmd),
1088 pkt->hdr.cmd);
1089 }
1090
Zhu Yi29b1b262009-10-23 13:42:25 -07001091 /*
1092 * XXX: After here, we should always check rxb->page
1093 * against NULL before touching it or its virtual
1094 * memory (pkt). Because some rx_handler might have
1095 * already taken or freed the pages.
1096 */
1097
Zhu Yib481de92007-09-25 17:54:57 -07001098 if (reclaim) {
Zhu Yi2f301222009-10-09 17:19:45 +08001099 /* Invoke any callbacks, transfer the buffer to caller,
1100 * and fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001101 * as we reclaim the driver command queue */
Zhu Yi29b1b262009-10-23 13:42:25 -07001102 if (rxb->page)
Tomas Winkler17b88922008-05-29 16:35:12 +08001103 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001104 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001105 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07001106 }
1107
Zhu Yi73005152009-10-23 13:42:32 -07001108 /* Reuse the page if possible. For notification packets and
1109 * SKBs that fail to Rx correctly, add them back into the
1110 * rx_free list for reuse later. */
Zhu Yib481de92007-09-25 17:54:57 -07001111 spin_lock_irqsave(&rxq->lock, flags);
Zhu Yi73005152009-10-23 13:42:32 -07001112 if (rxb->page != NULL) {
1113 rxb->page_dma = pci_map_page(priv->pci_dev, rxb->page,
1114 0, PAGE_SIZE << priv->hw_params.rx_page_order,
1115 PCI_DMA_FROMDEVICE);
1116 list_add_tail(&rxb->list, &rxq->rx_free);
1117 rxq->free_count++;
1118 } else
1119 list_add_tail(&rxb->list, &rxq->rx_used);
1120
Zhu Yib481de92007-09-25 17:54:57 -07001121 spin_unlock_irqrestore(&rxq->lock, flags);
Zhu Yi73005152009-10-23 13:42:32 -07001122
Zhu Yib481de92007-09-25 17:54:57 -07001123 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001124 /* If there are a lot of unused frames,
1125 * restock the Rx queue so ucode wont assert. */
1126 if (fill_rx) {
1127 count++;
1128 if (count >= 8) {
Zhu Yi73005152009-10-23 13:42:32 -07001129 rxq->read = i;
Wey-Yi Guy54b81552010-03-17 13:34:35 -07001130 iwlagn_rx_replenish_now(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001131 count = 0;
1132 }
1133 }
Zhu Yib481de92007-09-25 17:54:57 -07001134 }
1135
1136 /* Backtrack one entry */
Zhu Yi73005152009-10-23 13:42:32 -07001137 rxq->read = i;
Mohamed Abbas4752c932009-05-22 11:01:51 -07001138 if (fill_rx)
Wey-Yi Guy54b81552010-03-17 13:34:35 -07001139 iwlagn_rx_replenish_now(priv);
Mohamed Abbas4752c932009-05-22 11:01:51 -07001140 else
Wey-Yi Guy54b81552010-03-17 13:34:35 -07001141 iwlagn_rx_queue_restock(priv);
Tomas Winklera55360e2008-05-05 10:22:28 +08001142}
Tomas Winklera55360e2008-05-05 10:22:28 +08001143
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001144/* call this function to flush any scheduled tasklet */
1145static inline void iwl_synchronize_irq(struct iwl_priv *priv)
1146{
Tomas Winklera96a27f2008-10-23 23:48:56 -07001147 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001148 synchronize_irq(priv->pci_dev->irq);
1149 tasklet_kill(&priv->irq_tasklet);
1150}
1151
Mohamed Abbasef850d72009-05-22 11:01:50 -07001152static void iwl_irq_tasklet_legacy(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001153{
1154 u32 inta, handled = 0;
1155 u32 inta_fh;
1156 unsigned long flags;
Ben Cahillc2e61da2009-10-30 14:36:09 -07001157 u32 i;
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001158#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001159 u32 inta_mask;
1160#endif
1161
1162 spin_lock_irqsave(&priv->lock, flags);
1163
1164 /* Ack/clear/reset pending uCode interrupts.
1165 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1166 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001167 inta = iwl_read32(priv, CSR_INT);
1168 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07001169
1170 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1171 * Any new interrupts that happen after this, either while we're
1172 * in this tasklet, or later, will show up in next ISR/tasklet. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001173 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1174 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001175
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001176#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001177 if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001178 /* just for debug */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001179 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Tomas Winklere1623442009-01-27 14:27:56 -08001180 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07001181 inta, inta_mask, inta_fh);
1182 }
1183#endif
1184
Zhu Yi2f301222009-10-09 17:19:45 +08001185 spin_unlock_irqrestore(&priv->lock, flags);
1186
Zhu Yib481de92007-09-25 17:54:57 -07001187 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1188 * atomic, make sure that inta covers all the interrupts that
1189 * we've discovered, even if FH interrupt came in just after
1190 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001191 if (inta_fh & CSR49_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001192 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001193 if (inta_fh & CSR49_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001194 inta |= CSR_INT_BIT_FH_TX;
1195
1196 /* Now service all interrupt bits discovered above. */
1197 if (inta & CSR_INT_BIT_HW_ERR) {
Reinette Chatre58dba722009-07-17 09:30:25 -07001198 IWL_ERR(priv, "Hardware error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001199
1200 /* Tell the device to stop sending interrupts */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001201 iwl_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001202
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001203 priv->isr_stats.hw++;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001204 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001205
1206 handled |= CSR_INT_BIT_HW_ERR;
1207
Zhu Yib481de92007-09-25 17:54:57 -07001208 return;
1209 }
1210
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001211#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001212 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07001213 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001214 if (inta & CSR_INT_BIT_SCD) {
Tomas Winklere1623442009-01-27 14:27:56 -08001215 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
Joonwoo Park25c03d82008-01-23 10:15:20 -08001216 "the frame/frames.\n");
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001217 priv->isr_stats.sch++;
1218 }
Zhu Yib481de92007-09-25 17:54:57 -07001219
1220 /* Alive notification via Rx interrupt will do the real work */
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001221 if (inta & CSR_INT_BIT_ALIVE) {
Tomas Winklere1623442009-01-27 14:27:56 -08001222 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001223 priv->isr_stats.alive++;
1224 }
Zhu Yib481de92007-09-25 17:54:57 -07001225 }
1226#endif
1227 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001228 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07001229
Ben Cahill9fbab512007-11-29 11:09:47 +08001230 /* HW RF KILL switch toggled */
Zhu Yib481de92007-09-25 17:54:57 -07001231 if (inta & CSR_INT_BIT_RF_KILL) {
1232 int hw_rf_kill = 0;
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001233 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yib481de92007-09-25 17:54:57 -07001234 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
1235 hw_rf_kill = 1;
1236
Reinette Chatre4c423a22009-07-17 09:30:26 -07001237 IWL_WARN(priv, "RF_KILL bit toggled to %s.\n",
Abhijeet Kolekarc3056062008-11-12 13:14:08 -08001238 hw_rf_kill ? "disable radio" : "enable radio");
Zhu Yib481de92007-09-25 17:54:57 -07001239
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001240 priv->isr_stats.rfkill++;
1241
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +08001242 /* driver only loads ucode once setting the interface up.
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01001243 * the driver allows loading the ucode even if the radio
1244 * is killed. Hence update the killswitch state here. The
1245 * rfkill handler will care about restarting if needed.
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +08001246 */
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01001247 if (!test_bit(STATUS_ALIVE, &priv->status)) {
1248 if (hw_rf_kill)
1249 set_bit(STATUS_RF_KILL_HW, &priv->status);
1250 else
1251 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Johannes Berga60e77e2009-06-04 18:26:06 +02001252 wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
Mohamed Abbasedb34222008-12-11 10:33:37 -08001253 }
Zhu Yib481de92007-09-25 17:54:57 -07001254
1255 handled |= CSR_INT_BIT_RF_KILL;
1256 }
1257
Ben Cahill9fbab512007-11-29 11:09:47 +08001258 /* Chip got too hot and stopped itself */
Zhu Yib481de92007-09-25 17:54:57 -07001259 if (inta & CSR_INT_BIT_CT_KILL) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001260 IWL_ERR(priv, "Microcode CT kill error detected.\n");
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001261 priv->isr_stats.ctkill++;
Zhu Yib481de92007-09-25 17:54:57 -07001262 handled |= CSR_INT_BIT_CT_KILL;
1263 }
1264
1265 /* Error detected by uCode */
1266 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001267 IWL_ERR(priv, "Microcode SW error detected. "
1268 " Restarting 0x%X.\n", inta);
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001269 priv->isr_stats.sw++;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001270 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001271 handled |= CSR_INT_BIT_SW_ERR;
1272 }
1273
Ben Cahillc2e61da2009-10-30 14:36:09 -07001274 /*
1275 * uCode wakes up after power-down sleep.
1276 * Tell device about any new tx or host commands enqueued,
1277 * and about any Rx buffers made available while asleep.
1278 */
Zhu Yib481de92007-09-25 17:54:57 -07001279 if (inta & CSR_INT_BIT_WAKEUP) {
Tomas Winklere1623442009-01-27 14:27:56 -08001280 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
Tomas Winklera55360e2008-05-05 10:22:28 +08001281 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Ben Cahillc2e61da2009-10-30 14:36:09 -07001282 for (i = 0; i < priv->hw_params.max_txq_num; i++)
1283 iwl_txq_update_write_ptr(priv, &priv->txq[i]);
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001284 priv->isr_stats.wakeup++;
Zhu Yib481de92007-09-25 17:54:57 -07001285 handled |= CSR_INT_BIT_WAKEUP;
1286 }
1287
1288 /* All uCode command responses, including Tx command responses,
1289 * Rx "responses" (frame-received notification), and other
1290 * notifications from uCode come through here*/
1291 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Tomas Winklera55360e2008-05-05 10:22:28 +08001292 iwl_rx_handle(priv);
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001293 priv->isr_stats.rx++;
Zhu Yib481de92007-09-25 17:54:57 -07001294 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1295 }
1296
Ben Cahillc72cd192009-10-30 14:36:08 -07001297 /* This "Tx" DMA channel is used only for loading uCode */
Zhu Yib481de92007-09-25 17:54:57 -07001298 if (inta & CSR_INT_BIT_FH_TX) {
Ben Cahillc72cd192009-10-30 14:36:08 -07001299 IWL_DEBUG_ISR(priv, "uCode load interrupt\n");
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001300 priv->isr_stats.tx++;
Zhu Yib481de92007-09-25 17:54:57 -07001301 handled |= CSR_INT_BIT_FH_TX;
Ben Cahillc72cd192009-10-30 14:36:08 -07001302 /* Wake up uCode load routine, now that load is complete */
Ron Rindjunskydbb983b2008-05-15 13:54:12 +08001303 priv->ucode_write_complete = 1;
1304 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07001305 }
1306
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001307 if (inta & ~handled) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001308 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001309 priv->isr_stats.unhandled++;
1310 }
Zhu Yib481de92007-09-25 17:54:57 -07001311
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001312 if (inta & ~(priv->inta_mask)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001313 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001314 inta & ~priv->inta_mask);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001315 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001316 }
1317
1318 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001319 /* only Re-enable if diabled by irq */
1320 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001321 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001322
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001323#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001324 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001325 inta = iwl_read32(priv, CSR_INT);
1326 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1327 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Tomas Winklere1623442009-01-27 14:27:56 -08001328 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
Zhu Yib481de92007-09-25 17:54:57 -07001329 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
1330 }
1331#endif
Zhu Yib481de92007-09-25 17:54:57 -07001332}
1333
Mohamed Abbasef850d72009-05-22 11:01:50 -07001334/* tasklet for iwlagn interrupt */
1335static void iwl_irq_tasklet(struct iwl_priv *priv)
1336{
1337 u32 inta = 0;
1338 u32 handled = 0;
1339 unsigned long flags;
Ben Cahill87569902009-11-06 14:53:01 -08001340 u32 i;
Mohamed Abbasef850d72009-05-22 11:01:50 -07001341#ifdef CONFIG_IWLWIFI_DEBUG
1342 u32 inta_mask;
1343#endif
1344
1345 spin_lock_irqsave(&priv->lock, flags);
1346
1347 /* Ack/clear/reset pending uCode interrupts.
1348 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1349 */
Shanyu Zhao48a6be62010-03-16 10:22:26 -07001350 /* There is a hardware bug in the interrupt mask function that some
1351 * interrupts (i.e. CSR_INT_BIT_SCD) can still be generated even if
1352 * they are disabled in the CSR_INT_MASK register. Furthermore the
1353 * ICT interrupt handling mechanism has another bug that might cause
1354 * these unmasked interrupts fail to be detected. We workaround the
1355 * hardware bugs here by ACKing all the possible interrupts so that
1356 * interrupt coalescing can still be achieved.
1357 */
David S. Miller4a35ecf2010-04-06 23:53:30 -07001358 iwl_write32(priv, CSR_INT, priv->_agn.inta | ~priv->inta_mask);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001359
Johannes Berga4c8b2a2010-01-21 06:25:54 -08001360 inta = priv->_agn.inta;
Mohamed Abbasef850d72009-05-22 11:01:50 -07001361
1362#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001363 if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
Mohamed Abbasef850d72009-05-22 11:01:50 -07001364 /* just for debug */
1365 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1366 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x\n ",
1367 inta, inta_mask);
1368 }
1369#endif
Zhu Yi2f301222009-10-09 17:19:45 +08001370
1371 spin_unlock_irqrestore(&priv->lock, flags);
1372
Johannes Berga4c8b2a2010-01-21 06:25:54 -08001373 /* saved interrupt in inta variable now we can reset priv->_agn.inta */
1374 priv->_agn.inta = 0;
Mohamed Abbasef850d72009-05-22 11:01:50 -07001375
1376 /* Now service all interrupt bits discovered above. */
1377 if (inta & CSR_INT_BIT_HW_ERR) {
Reinette Chatre58dba722009-07-17 09:30:25 -07001378 IWL_ERR(priv, "Hardware error detected. Restarting.\n");
Mohamed Abbasef850d72009-05-22 11:01:50 -07001379
1380 /* Tell the device to stop sending interrupts */
1381 iwl_disable_interrupts(priv);
1382
1383 priv->isr_stats.hw++;
1384 iwl_irq_handle_error(priv);
1385
1386 handled |= CSR_INT_BIT_HW_ERR;
1387
Mohamed Abbasef850d72009-05-22 11:01:50 -07001388 return;
1389 }
1390
1391#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -07001392 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Mohamed Abbasef850d72009-05-22 11:01:50 -07001393 /* NIC fires this, but we don't use it, redundant with WAKEUP */
1394 if (inta & CSR_INT_BIT_SCD) {
1395 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
1396 "the frame/frames.\n");
1397 priv->isr_stats.sch++;
1398 }
1399
1400 /* Alive notification via Rx interrupt will do the real work */
1401 if (inta & CSR_INT_BIT_ALIVE) {
1402 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
1403 priv->isr_stats.alive++;
1404 }
1405 }
1406#endif
1407 /* Safely ignore these bits for debug checks below */
1408 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
1409
1410 /* HW RF KILL switch toggled */
1411 if (inta & CSR_INT_BIT_RF_KILL) {
1412 int hw_rf_kill = 0;
1413 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
1414 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
1415 hw_rf_kill = 1;
1416
Reinette Chatre4c423a22009-07-17 09:30:26 -07001417 IWL_WARN(priv, "RF_KILL bit toggled to %s.\n",
Mohamed Abbasef850d72009-05-22 11:01:50 -07001418 hw_rf_kill ? "disable radio" : "enable radio");
1419
1420 priv->isr_stats.rfkill++;
1421
1422 /* driver only loads ucode once setting the interface up.
1423 * the driver allows loading the ucode even if the radio
1424 * is killed. Hence update the killswitch state here. The
1425 * rfkill handler will care about restarting if needed.
1426 */
1427 if (!test_bit(STATUS_ALIVE, &priv->status)) {
1428 if (hw_rf_kill)
1429 set_bit(STATUS_RF_KILL_HW, &priv->status);
1430 else
1431 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Johannes Berga60e77e2009-06-04 18:26:06 +02001432 wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001433 }
1434
1435 handled |= CSR_INT_BIT_RF_KILL;
1436 }
1437
1438 /* Chip got too hot and stopped itself */
1439 if (inta & CSR_INT_BIT_CT_KILL) {
1440 IWL_ERR(priv, "Microcode CT kill error detected.\n");
1441 priv->isr_stats.ctkill++;
1442 handled |= CSR_INT_BIT_CT_KILL;
1443 }
1444
1445 /* Error detected by uCode */
1446 if (inta & CSR_INT_BIT_SW_ERR) {
1447 IWL_ERR(priv, "Microcode SW error detected. "
1448 " Restarting 0x%X.\n", inta);
1449 priv->isr_stats.sw++;
Mohamed Abbasef850d72009-05-22 11:01:50 -07001450 iwl_irq_handle_error(priv);
1451 handled |= CSR_INT_BIT_SW_ERR;
1452 }
1453
1454 /* uCode wakes up after power-down sleep */
1455 if (inta & CSR_INT_BIT_WAKEUP) {
1456 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
1457 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Ben Cahill87569902009-11-06 14:53:01 -08001458 for (i = 0; i < priv->hw_params.max_txq_num; i++)
1459 iwl_txq_update_write_ptr(priv, &priv->txq[i]);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001460
1461 priv->isr_stats.wakeup++;
1462
1463 handled |= CSR_INT_BIT_WAKEUP;
1464 }
1465
1466 /* All uCode command responses, including Tx command responses,
1467 * Rx "responses" (frame-received notification), and other
1468 * notifications from uCode come through here*/
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001469 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX |
1470 CSR_INT_BIT_RX_PERIODIC)) {
Mohamed Abbasef850d72009-05-22 11:01:50 -07001471 IWL_DEBUG_ISR(priv, "Rx interrupt\n");
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001472 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
1473 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1474 iwl_write32(priv, CSR_FH_INT_STATUS,
1475 CSR49_FH_INT_RX_MASK);
1476 }
1477 if (inta & CSR_INT_BIT_RX_PERIODIC) {
1478 handled |= CSR_INT_BIT_RX_PERIODIC;
1479 iwl_write32(priv, CSR_INT, CSR_INT_BIT_RX_PERIODIC);
1480 }
1481 /* Sending RX interrupt require many steps to be done in the
1482 * the device:
1483 * 1- write interrupt to current index in ICT table.
1484 * 2- dma RX frame.
1485 * 3- update RX shared data to indicate last write index.
1486 * 4- send interrupt.
1487 * This could lead to RX race, driver could receive RX interrupt
Ben Cahill74ba67e2009-11-20 12:04:53 -08001488 * but the shared data changes does not reflect this;
1489 * periodic interrupt will detect any dangling Rx activity.
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001490 */
Ben Cahill74ba67e2009-11-20 12:04:53 -08001491
1492 /* Disable periodic interrupt; we use it as just a one-shot. */
1493 iwl_write8(priv, CSR_INT_PERIODIC_REG,
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001494 CSR_INT_PERIODIC_DIS);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001495 iwl_rx_handle(priv);
Ben Cahill74ba67e2009-11-20 12:04:53 -08001496
1497 /*
1498 * Enable periodic interrupt in 8 msec only if we received
1499 * real RX interrupt (instead of just periodic int), to catch
1500 * any dangling Rx interrupt. If it was just the periodic
1501 * interrupt, there was no dangling Rx activity, and no need
1502 * to extend the periodic interrupt; one-shot is enough.
1503 */
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001504 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX))
Ben Cahill74ba67e2009-11-20 12:04:53 -08001505 iwl_write8(priv, CSR_INT_PERIODIC_REG,
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001506 CSR_INT_PERIODIC_ENA);
1507
Mohamed Abbasef850d72009-05-22 11:01:50 -07001508 priv->isr_stats.rx++;
Mohamed Abbasef850d72009-05-22 11:01:50 -07001509 }
1510
Ben Cahillc72cd192009-10-30 14:36:08 -07001511 /* This "Tx" DMA channel is used only for loading uCode */
Mohamed Abbasef850d72009-05-22 11:01:50 -07001512 if (inta & CSR_INT_BIT_FH_TX) {
1513 iwl_write32(priv, CSR_FH_INT_STATUS, CSR49_FH_INT_TX_MASK);
Ben Cahillc72cd192009-10-30 14:36:08 -07001514 IWL_DEBUG_ISR(priv, "uCode load interrupt\n");
Mohamed Abbasef850d72009-05-22 11:01:50 -07001515 priv->isr_stats.tx++;
1516 handled |= CSR_INT_BIT_FH_TX;
Ben Cahillc72cd192009-10-30 14:36:08 -07001517 /* Wake up uCode load routine, now that load is complete */
Mohamed Abbasef850d72009-05-22 11:01:50 -07001518 priv->ucode_write_complete = 1;
1519 wake_up_interruptible(&priv->wait_command_queue);
1520 }
1521
1522 if (inta & ~handled) {
1523 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
1524 priv->isr_stats.unhandled++;
1525 }
1526
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001527 if (inta & ~(priv->inta_mask)) {
Mohamed Abbasef850d72009-05-22 11:01:50 -07001528 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Mohamed Abbas40cefda2009-05-22 11:01:52 -07001529 inta & ~priv->inta_mask);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001530 }
1531
Mohamed Abbasef850d72009-05-22 11:01:50 -07001532 /* Re-enable all interrupts */
1533 /* only Re-enable if diabled by irq */
1534 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1535 iwl_enable_interrupts(priv);
Mohamed Abbasef850d72009-05-22 11:01:50 -07001536}
1537
Wey-Yi Guy872c8dd2010-03-16 10:46:31 -07001538/* the threshold ratio of actual_ack_cnt to expected_ack_cnt in percent */
1539#define ACK_CNT_RATIO (50)
1540#define BA_TIMEOUT_CNT (5)
1541#define BA_TIMEOUT_MAX (16)
1542
1543/**
1544 * iwl_good_ack_health - checks for ACK count ratios, BA timeout retries.
1545 *
1546 * When the ACK count ratio is 0 and aggregated BA timeout retries exceeding
1547 * the BA_TIMEOUT_MAX, reload firmware and bring system back to normal
1548 * operation state.
1549 */
1550bool iwl_good_ack_health(struct iwl_priv *priv,
1551 struct iwl_rx_packet *pkt)
1552{
1553 bool rc = true;
1554 int actual_ack_cnt_delta, expected_ack_cnt_delta;
1555 int ba_timeout_delta;
1556
1557 actual_ack_cnt_delta =
1558 le32_to_cpu(pkt->u.stats.tx.actual_ack_cnt) -
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -07001559 le32_to_cpu(priv->_agn.statistics.tx.actual_ack_cnt);
Wey-Yi Guy872c8dd2010-03-16 10:46:31 -07001560 expected_ack_cnt_delta =
1561 le32_to_cpu(pkt->u.stats.tx.expected_ack_cnt) -
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -07001562 le32_to_cpu(priv->_agn.statistics.tx.expected_ack_cnt);
Wey-Yi Guy872c8dd2010-03-16 10:46:31 -07001563 ba_timeout_delta =
1564 le32_to_cpu(pkt->u.stats.tx.agg.ba_timeout) -
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -07001565 le32_to_cpu(priv->_agn.statistics.tx.agg.ba_timeout);
Wey-Yi Guy872c8dd2010-03-16 10:46:31 -07001566 if ((priv->_agn.agg_tids_count > 0) &&
1567 (expected_ack_cnt_delta > 0) &&
1568 (((actual_ack_cnt_delta * 100) / expected_ack_cnt_delta)
1569 < ACK_CNT_RATIO) &&
1570 (ba_timeout_delta > BA_TIMEOUT_CNT)) {
1571 IWL_DEBUG_RADIO(priv, "actual_ack_cnt delta = %d,"
1572 " expected_ack_cnt = %d\n",
1573 actual_ack_cnt_delta, expected_ack_cnt_delta);
1574
Johannes Bergd73e4922010-05-06 12:18:41 -07001575#ifdef CONFIG_IWLWIFI_DEBUGFS
1576 /*
1577 * This is ifdef'ed on DEBUGFS because otherwise the
1578 * statistics aren't available. If DEBUGFS is set but
1579 * DEBUG is not, these will just compile out.
1580 */
Wey-Yi Guy872c8dd2010-03-16 10:46:31 -07001581 IWL_DEBUG_RADIO(priv, "rx_detected_cnt delta = %d\n",
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -07001582 priv->_agn.delta_statistics.tx.rx_detected_cnt);
Wey-Yi Guy872c8dd2010-03-16 10:46:31 -07001583 IWL_DEBUG_RADIO(priv,
1584 "ack_or_ba_timeout_collision delta = %d\n",
Wey-Yi Guyf3aebee2010-06-14 17:09:54 -07001585 priv->_agn.delta_statistics.tx.
Wey-Yi Guy872c8dd2010-03-16 10:46:31 -07001586 ack_or_ba_timeout_collision);
1587#endif
1588 IWL_DEBUG_RADIO(priv, "agg ba_timeout delta = %d\n",
1589 ba_timeout_delta);
1590 if (!actual_ack_cnt_delta &&
1591 (ba_timeout_delta >= BA_TIMEOUT_MAX))
1592 rc = false;
1593 }
1594 return rc;
1595}
1596
Wey-Yi Guya83b9142009-04-08 11:39:32 -07001597
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07001598/*****************************************************************************
1599 *
1600 * sysfs attributes
1601 *
1602 *****************************************************************************/
1603
1604#ifdef CONFIG_IWLWIFI_DEBUG
1605
1606/*
1607 * The following adds a new attribute to the sysfs representation
1608 * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
1609 * used for controlling the debug level.
1610 *
1611 * See the level definitions in iwl for details.
1612 *
1613 * The debug_level being managed using sysfs below is a per device debug
1614 * level that is used instead of the global debug level if it (the per
1615 * device debug level) is set.
1616 */
1617static ssize_t show_debug_level(struct device *d,
1618 struct device_attribute *attr, char *buf)
1619{
1620 struct iwl_priv *priv = dev_get_drvdata(d);
1621 return sprintf(buf, "0x%08X\n", iwl_get_debug_level(priv));
1622}
1623static ssize_t store_debug_level(struct device *d,
1624 struct device_attribute *attr,
1625 const char *buf, size_t count)
1626{
1627 struct iwl_priv *priv = dev_get_drvdata(d);
1628 unsigned long val;
1629 int ret;
1630
1631 ret = strict_strtoul(buf, 0, &val);
1632 if (ret)
1633 IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf);
1634 else {
1635 priv->debug_level = val;
1636 if (iwl_alloc_traffic_mem(priv))
1637 IWL_ERR(priv,
1638 "Not enough memory to generate traffic log\n");
1639 }
1640 return strnlen(buf, count);
1641}
1642
1643static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
1644 show_debug_level, store_debug_level);
1645
1646
1647#endif /* CONFIG_IWLWIFI_DEBUG */
1648
1649
1650static ssize_t show_temperature(struct device *d,
1651 struct device_attribute *attr, char *buf)
1652{
1653 struct iwl_priv *priv = dev_get_drvdata(d);
1654
1655 if (!iwl_is_alive(priv))
1656 return -EAGAIN;
1657
1658 return sprintf(buf, "%d\n", priv->temperature);
1659}
1660
1661static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
1662
1663static ssize_t show_tx_power(struct device *d,
1664 struct device_attribute *attr, char *buf)
1665{
1666 struct iwl_priv *priv = dev_get_drvdata(d);
1667
1668 if (!iwl_is_ready_rf(priv))
1669 return sprintf(buf, "off\n");
1670 else
1671 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
1672}
1673
1674static ssize_t store_tx_power(struct device *d,
1675 struct device_attribute *attr,
1676 const char *buf, size_t count)
1677{
1678 struct iwl_priv *priv = dev_get_drvdata(d);
1679 unsigned long val;
1680 int ret;
1681
1682 ret = strict_strtoul(buf, 10, &val);
1683 if (ret)
1684 IWL_INFO(priv, "%s is not in decimal form.\n", buf);
1685 else {
1686 ret = iwl_set_tx_power(priv, val, false);
1687 if (ret)
1688 IWL_ERR(priv, "failed setting tx power (0x%d).\n",
1689 ret);
1690 else
1691 ret = count;
1692 }
1693 return ret;
1694}
1695
1696static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
1697
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07001698static struct attribute *iwl_sysfs_entries[] = {
1699 &dev_attr_temperature.attr,
1700 &dev_attr_tx_power.attr,
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07001701#ifdef CONFIG_IWLWIFI_DEBUG
1702 &dev_attr_debug_level.attr,
1703#endif
1704 NULL
1705};
1706
1707static struct attribute_group iwl_attribute_group = {
1708 .name = NULL, /* put in device directory */
1709 .attrs = iwl_sysfs_entries,
1710};
1711
Zhu Yib481de92007-09-25 17:54:57 -07001712/******************************************************************************
1713 *
1714 * uCode download functions
1715 *
1716 ******************************************************************************/
1717
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001718static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001719{
Tomas Winkler98c92212008-01-14 17:46:20 -08001720 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
1721 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
1722 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1723 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
1724 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1725 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001726}
1727
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001728static void iwl_nic_start(struct iwl_priv *priv)
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08001729{
1730 /* Remove all resets to allow NIC to operate */
1731 iwl_write32(priv, CSR_RESET, 0);
1732}
1733
Johannes Bergdd7a2502010-04-28 23:33:10 -07001734struct iwlagn_ucode_capabilities {
1735 u32 max_probe_length;
Wey-Yi Guy6a822d02010-07-13 17:13:15 -07001736 u32 standard_phy_calibration_size;
Johannes Bergece9c4e2010-08-23 10:46:49 +02001737 bool pan;
Johannes Bergdd7a2502010-04-28 23:33:10 -07001738};
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08001739
Johannes Bergb08dfd02010-01-29 11:54:56 -08001740static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context);
Johannes Bergdd7a2502010-04-28 23:33:10 -07001741static int iwl_mac_setup_register(struct iwl_priv *priv,
1742 struct iwlagn_ucode_capabilities *capa);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001743
Jay Sternberg39396082010-08-12 10:24:07 -07001744#define UCODE_EXPERIMENTAL_INDEX 100
1745#define UCODE_EXPERIMENTAL_TAG "exp"
1746
Johannes Bergb08dfd02010-01-29 11:54:56 -08001747static int __must_check iwl_request_firmware(struct iwl_priv *priv, bool first)
Zhu Yib481de92007-09-25 17:54:57 -07001748{
Reinette Chatrea0987a82008-12-02 12:14:06 -08001749 const char *name_pre = priv->cfg->fw_name_pre;
Jay Sternberg39396082010-08-12 10:24:07 -07001750 char tag[8];
Johannes Bergb08dfd02010-01-29 11:54:56 -08001751
Jay Sternberg39396082010-08-12 10:24:07 -07001752 if (first) {
1753#ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE
1754 priv->fw_index = UCODE_EXPERIMENTAL_INDEX;
1755 strcpy(tag, UCODE_EXPERIMENTAL_TAG);
1756 } else if (priv->fw_index == UCODE_EXPERIMENTAL_INDEX) {
1757#endif
Johannes Bergb08dfd02010-01-29 11:54:56 -08001758 priv->fw_index = priv->cfg->ucode_api_max;
Jay Sternberg39396082010-08-12 10:24:07 -07001759 sprintf(tag, "%d", priv->fw_index);
1760 } else {
Johannes Bergb08dfd02010-01-29 11:54:56 -08001761 priv->fw_index--;
Jay Sternberg39396082010-08-12 10:24:07 -07001762 sprintf(tag, "%d", priv->fw_index);
1763 }
Johannes Bergb08dfd02010-01-29 11:54:56 -08001764
1765 if (priv->fw_index < priv->cfg->ucode_api_min) {
1766 IWL_ERR(priv, "no suitable firmware found!\n");
1767 return -ENOENT;
1768 }
1769
Jay Sternberg39396082010-08-12 10:24:07 -07001770 sprintf(priv->firmware_name, "%s%s%s", name_pre, tag, ".ucode");
Johannes Bergb08dfd02010-01-29 11:54:56 -08001771
Jay Sternberg39396082010-08-12 10:24:07 -07001772 IWL_DEBUG_INFO(priv, "attempting to load firmware %s'%s'\n",
1773 (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
1774 ? "EXPERIMENTAL " : "",
Johannes Bergb08dfd02010-01-29 11:54:56 -08001775 priv->firmware_name);
1776
1777 return request_firmware_nowait(THIS_MODULE, 1, priv->firmware_name,
1778 &priv->pci_dev->dev, GFP_KERNEL, priv,
1779 iwl_ucode_callback);
1780}
1781
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001782struct iwlagn_firmware_pieces {
1783 const void *inst, *data, *init, *init_data, *boot;
1784 size_t inst_size, data_size, init_size, init_data_size, boot_size;
1785
1786 u32 build;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001787
1788 u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
1789 u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001790};
1791
1792static int iwlagn_load_legacy_firmware(struct iwl_priv *priv,
1793 const struct firmware *ucode_raw,
1794 struct iwlagn_firmware_pieces *pieces)
1795{
1796 struct iwl_ucode_header *ucode = (void *)ucode_raw->data;
1797 u32 api_ver, hdr_size;
1798 const u8 *src;
1799
1800 priv->ucode_ver = le32_to_cpu(ucode->ver);
1801 api_ver = IWL_UCODE_API(priv->ucode_ver);
1802
1803 switch (api_ver) {
1804 default:
1805 /*
1806 * 4965 doesn't revision the firmware file format
1807 * along with the API version, it always uses v1
1808 * file format.
1809 */
1810 if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) !=
1811 CSR_HW_REV_TYPE_4965) {
1812 hdr_size = 28;
1813 if (ucode_raw->size < hdr_size) {
1814 IWL_ERR(priv, "File size too small!\n");
1815 return -EINVAL;
1816 }
1817 pieces->build = le32_to_cpu(ucode->u.v2.build);
1818 pieces->inst_size = le32_to_cpu(ucode->u.v2.inst_size);
1819 pieces->data_size = le32_to_cpu(ucode->u.v2.data_size);
1820 pieces->init_size = le32_to_cpu(ucode->u.v2.init_size);
1821 pieces->init_data_size = le32_to_cpu(ucode->u.v2.init_data_size);
1822 pieces->boot_size = le32_to_cpu(ucode->u.v2.boot_size);
1823 src = ucode->u.v2.data;
1824 break;
1825 }
1826 /* fall through for 4965 */
1827 case 0:
1828 case 1:
1829 case 2:
1830 hdr_size = 24;
1831 if (ucode_raw->size < hdr_size) {
1832 IWL_ERR(priv, "File size too small!\n");
1833 return -EINVAL;
1834 }
1835 pieces->build = 0;
1836 pieces->inst_size = le32_to_cpu(ucode->u.v1.inst_size);
1837 pieces->data_size = le32_to_cpu(ucode->u.v1.data_size);
1838 pieces->init_size = le32_to_cpu(ucode->u.v1.init_size);
1839 pieces->init_data_size = le32_to_cpu(ucode->u.v1.init_data_size);
1840 pieces->boot_size = le32_to_cpu(ucode->u.v1.boot_size);
1841 src = ucode->u.v1.data;
1842 break;
1843 }
1844
1845 /* Verify size of file vs. image size info in file's header */
1846 if (ucode_raw->size != hdr_size + pieces->inst_size +
1847 pieces->data_size + pieces->init_size +
1848 pieces->init_data_size + pieces->boot_size) {
1849
1850 IWL_ERR(priv,
1851 "uCode file size %d does not match expected size\n",
1852 (int)ucode_raw->size);
1853 return -EINVAL;
1854 }
1855
1856 pieces->inst = src;
1857 src += pieces->inst_size;
1858 pieces->data = src;
1859 src += pieces->data_size;
1860 pieces->init = src;
1861 src += pieces->init_size;
1862 pieces->init_data = src;
1863 src += pieces->init_data_size;
1864 pieces->boot = src;
1865 src += pieces->boot_size;
1866
1867 return 0;
1868}
1869
Johannes Bergdd7a2502010-04-28 23:33:10 -07001870static int iwlagn_wanted_ucode_alternative = 1;
1871
1872static int iwlagn_load_firmware(struct iwl_priv *priv,
1873 const struct firmware *ucode_raw,
1874 struct iwlagn_firmware_pieces *pieces,
1875 struct iwlagn_ucode_capabilities *capa)
1876{
1877 struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data;
1878 struct iwl_ucode_tlv *tlv;
1879 size_t len = ucode_raw->size;
1880 const u8 *data;
1881 int wanted_alternative = iwlagn_wanted_ucode_alternative, tmp;
1882 u64 alternatives;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001883 u32 tlv_len;
1884 enum iwl_ucode_tlv_type tlv_type;
1885 const u8 *tlv_data;
Johannes Bergdd7a2502010-04-28 23:33:10 -07001886
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001887 if (len < sizeof(*ucode)) {
1888 IWL_ERR(priv, "uCode has invalid length: %zd\n", len);
Johannes Bergdd7a2502010-04-28 23:33:10 -07001889 return -EINVAL;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001890 }
Johannes Bergdd7a2502010-04-28 23:33:10 -07001891
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001892 if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) {
1893 IWL_ERR(priv, "invalid uCode magic: 0X%x\n",
1894 le32_to_cpu(ucode->magic));
Johannes Bergdd7a2502010-04-28 23:33:10 -07001895 return -EINVAL;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001896 }
Johannes Bergdd7a2502010-04-28 23:33:10 -07001897
1898 /*
1899 * Check which alternatives are present, and "downgrade"
1900 * when the chosen alternative is not present, warning
1901 * the user when that happens. Some files may not have
1902 * any alternatives, so don't warn in that case.
1903 */
1904 alternatives = le64_to_cpu(ucode->alternatives);
1905 tmp = wanted_alternative;
1906 if (wanted_alternative > 63)
1907 wanted_alternative = 63;
1908 while (wanted_alternative && !(alternatives & BIT(wanted_alternative)))
1909 wanted_alternative--;
1910 if (wanted_alternative && wanted_alternative != tmp)
1911 IWL_WARN(priv,
1912 "uCode alternative %d not available, choosing %d\n",
1913 tmp, wanted_alternative);
1914
1915 priv->ucode_ver = le32_to_cpu(ucode->ver);
1916 pieces->build = le32_to_cpu(ucode->build);
1917 data = ucode->data;
1918
1919 len -= sizeof(*ucode);
1920
Johannes Berg704da532010-07-14 09:34:50 -07001921 while (len >= sizeof(*tlv)) {
Johannes Bergdd7a2502010-04-28 23:33:10 -07001922 u16 tlv_alt;
Johannes Bergdd7a2502010-04-28 23:33:10 -07001923
1924 len -= sizeof(*tlv);
1925 tlv = (void *)data;
1926
1927 tlv_len = le32_to_cpu(tlv->length);
1928 tlv_type = le16_to_cpu(tlv->type);
1929 tlv_alt = le16_to_cpu(tlv->alternative);
1930 tlv_data = tlv->data;
1931
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001932 if (len < tlv_len) {
1933 IWL_ERR(priv, "invalid TLV len: %zd/%u\n",
1934 len, tlv_len);
Johannes Bergdd7a2502010-04-28 23:33:10 -07001935 return -EINVAL;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001936 }
Johannes Bergdd7a2502010-04-28 23:33:10 -07001937 len -= ALIGN(tlv_len, 4);
1938 data += sizeof(*tlv) + ALIGN(tlv_len, 4);
1939
1940 /*
1941 * Alternative 0 is always valid.
1942 *
1943 * Skip alternative TLVs that are not selected.
1944 */
1945 if (tlv_alt != 0 && tlv_alt != wanted_alternative)
1946 continue;
1947
1948 switch (tlv_type) {
1949 case IWL_UCODE_TLV_INST:
1950 pieces->inst = tlv_data;
1951 pieces->inst_size = tlv_len;
1952 break;
1953 case IWL_UCODE_TLV_DATA:
1954 pieces->data = tlv_data;
1955 pieces->data_size = tlv_len;
1956 break;
1957 case IWL_UCODE_TLV_INIT:
1958 pieces->init = tlv_data;
1959 pieces->init_size = tlv_len;
1960 break;
1961 case IWL_UCODE_TLV_INIT_DATA:
1962 pieces->init_data = tlv_data;
1963 pieces->init_data_size = tlv_len;
1964 break;
1965 case IWL_UCODE_TLV_BOOT:
1966 pieces->boot = tlv_data;
1967 pieces->boot_size = tlv_len;
1968 break;
1969 case IWL_UCODE_TLV_PROBE_MAX_LEN:
Johannes Berg704da532010-07-14 09:34:50 -07001970 if (tlv_len != sizeof(u32))
1971 goto invalid_tlv_len;
1972 capa->max_probe_length =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001973 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergdd7a2502010-04-28 23:33:10 -07001974 break;
Johannes Bergece9c4e2010-08-23 10:46:49 +02001975 case IWL_UCODE_TLV_PAN:
1976 if (tlv_len)
1977 goto invalid_tlv_len;
1978 capa->pan = true;
1979 break;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001980 case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
Johannes Berg704da532010-07-14 09:34:50 -07001981 if (tlv_len != sizeof(u32))
1982 goto invalid_tlv_len;
1983 pieces->init_evtlog_ptr =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001984 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -07001985 break;
1986 case IWL_UCODE_TLV_INIT_EVTLOG_SIZE:
Johannes Berg704da532010-07-14 09:34:50 -07001987 if (tlv_len != sizeof(u32))
1988 goto invalid_tlv_len;
1989 pieces->init_evtlog_size =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001990 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -07001991 break;
1992 case IWL_UCODE_TLV_INIT_ERRLOG_PTR:
Johannes Berg704da532010-07-14 09:34:50 -07001993 if (tlv_len != sizeof(u32))
1994 goto invalid_tlv_len;
1995 pieces->init_errlog_ptr =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001996 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -07001997 break;
1998 case IWL_UCODE_TLV_RUNT_EVTLOG_PTR:
Johannes Berg704da532010-07-14 09:34:50 -07001999 if (tlv_len != sizeof(u32))
2000 goto invalid_tlv_len;
2001 pieces->inst_evtlog_ptr =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07002002 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -07002003 break;
2004 case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE:
Johannes Berg704da532010-07-14 09:34:50 -07002005 if (tlv_len != sizeof(u32))
2006 goto invalid_tlv_len;
2007 pieces->inst_evtlog_size =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07002008 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -07002009 break;
2010 case IWL_UCODE_TLV_RUNT_ERRLOG_PTR:
Johannes Berg704da532010-07-14 09:34:50 -07002011 if (tlv_len != sizeof(u32))
2012 goto invalid_tlv_len;
2013 pieces->inst_errlog_ptr =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07002014 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -07002015 break;
Wey-Yi Guyc8312fa2010-06-28 13:05:17 -07002016 case IWL_UCODE_TLV_ENHANCE_SENS_TBL:
2017 if (tlv_len)
Johannes Berg704da532010-07-14 09:34:50 -07002018 goto invalid_tlv_len;
2019 priv->enhance_sensitivity_table = true;
Wey-Yi Guyc8312fa2010-06-28 13:05:17 -07002020 break;
Wey-Yi Guy6a822d02010-07-13 17:13:15 -07002021 case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE:
Johannes Berg704da532010-07-14 09:34:50 -07002022 if (tlv_len != sizeof(u32))
2023 goto invalid_tlv_len;
2024 capa->standard_phy_calibration_size =
Wey-Yi Guy6a822d02010-07-13 17:13:15 -07002025 le32_to_cpup((__le32 *)tlv_data);
2026 break;
Johannes Bergdd7a2502010-04-28 23:33:10 -07002027 default:
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07002028 IWL_WARN(priv, "unknown TLV: %d\n", tlv_type);
Johannes Bergdd7a2502010-04-28 23:33:10 -07002029 break;
2030 }
2031 }
2032
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07002033 if (len) {
2034 IWL_ERR(priv, "invalid TLV after parsing: %zd\n", len);
2035 iwl_print_hex_dump(priv, IWL_DL_FW, (u8 *)data, len);
Johannes Berg704da532010-07-14 09:34:50 -07002036 return -EINVAL;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07002037 }
Johannes Bergdd7a2502010-04-28 23:33:10 -07002038
Johannes Berg704da532010-07-14 09:34:50 -07002039 return 0;
2040
2041 invalid_tlv_len:
2042 IWL_ERR(priv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len);
2043 iwl_print_hex_dump(priv, IWL_DL_FW, tlv_data, tlv_len);
2044
2045 return -EINVAL;
Johannes Bergdd7a2502010-04-28 23:33:10 -07002046}
2047
Johannes Bergb08dfd02010-01-29 11:54:56 -08002048/**
2049 * iwl_ucode_callback - callback when firmware was loaded
2050 *
2051 * If loaded successfully, copies the firmware into buffers
2052 * for the card to fetch (via DMA).
2053 */
2054static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
2055{
2056 struct iwl_priv *priv = context;
2057 struct iwl_ucode_header *ucode;
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002058 int err;
2059 struct iwlagn_firmware_pieces pieces;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002060 const unsigned int api_max = priv->cfg->ucode_api_max;
2061 const unsigned int api_min = priv->cfg->ucode_api_min;
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002062 u32 api_ver;
Johannes Berg3e4de762010-04-28 12:09:12 -07002063 char buildstr[25];
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002064 u32 build;
Johannes Bergdd7a2502010-04-28 23:33:10 -07002065 struct iwlagn_ucode_capabilities ucode_capa = {
2066 .max_probe_length = 200,
Wey-Yi Guy6a822d02010-07-13 17:13:15 -07002067 .standard_phy_calibration_size =
Shanyu Zhao642454c2010-09-21 12:06:18 -07002068 IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE,
Johannes Bergdd7a2502010-04-28 23:33:10 -07002069 };
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002070
2071 memset(&pieces, 0, sizeof(pieces));
Zhu Yib481de92007-09-25 17:54:57 -07002072
Johannes Bergb08dfd02010-01-29 11:54:56 -08002073 if (!ucode_raw) {
Jay Sternberg39396082010-08-12 10:24:07 -07002074 if (priv->fw_index <= priv->cfg->ucode_api_max)
2075 IWL_ERR(priv,
2076 "request for firmware file '%s' failed.\n",
2077 priv->firmware_name);
Johannes Bergb08dfd02010-01-29 11:54:56 -08002078 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07002079 }
2080
Johannes Bergb08dfd02010-01-29 11:54:56 -08002081 IWL_DEBUG_INFO(priv, "Loaded firmware file '%s' (%zd bytes).\n",
2082 priv->firmware_name, ucode_raw->size);
Zhu Yib481de92007-09-25 17:54:57 -07002083
Johannes Berg22adba22010-04-28 12:09:14 -07002084 /* Make sure that we got at least the API version number */
2085 if (ucode_raw->size < 4) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002086 IWL_ERR(priv, "File size way too small!\n");
Johannes Bergb08dfd02010-01-29 11:54:56 -08002087 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07002088 }
2089
2090 /* Data from ucode file: header followed by uCode images */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002091 ucode = (struct iwl_ucode_header *)ucode_raw->data;
Zhu Yib481de92007-09-25 17:54:57 -07002092
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002093 if (ucode->ver)
2094 err = iwlagn_load_legacy_firmware(priv, ucode_raw, &pieces);
2095 else
Johannes Bergdd7a2502010-04-28 23:33:10 -07002096 err = iwlagn_load_firmware(priv, ucode_raw, &pieces,
2097 &ucode_capa);
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002098
2099 if (err)
2100 goto try_again;
2101
Reinette Chatrea0987a82008-12-02 12:14:06 -08002102 api_ver = IWL_UCODE_API(priv->ucode_ver);
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002103 build = pieces.build;
Zhu Yib481de92007-09-25 17:54:57 -07002104
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002105 /*
2106 * api_ver should match the api version forming part of the
Reinette Chatrea0987a82008-12-02 12:14:06 -08002107 * firmware filename ... but we don't check for that and only rely
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002108 * on the API version read from firmware header from here on forward
2109 */
Wey-Yi Guy65cccfb2010-09-21 16:15:58 -07002110 /* no api version check required for experimental uCode */
2111 if (priv->fw_index != UCODE_EXPERIMENTAL_INDEX) {
2112 if (api_ver < api_min || api_ver > api_max) {
2113 IWL_ERR(priv,
2114 "Driver unable to support your firmware API. "
2115 "Driver supports v%u, firmware is v%u.\n",
2116 api_max, api_ver);
2117 goto try_again;
2118 }
Johannes Bergb08dfd02010-01-29 11:54:56 -08002119
Wey-Yi Guy65cccfb2010-09-21 16:15:58 -07002120 if (api_ver != api_max)
2121 IWL_ERR(priv,
2122 "Firmware has old API version. Expected v%u, "
2123 "got v%u. New firmware can be obtained "
2124 "from http://www.intellinuxwireless.org.\n",
2125 api_max, api_ver);
2126 }
Reinette Chatrea0987a82008-12-02 12:14:06 -08002127
Johannes Berg3e4de762010-04-28 12:09:12 -07002128 if (build)
Jay Sternberg39396082010-08-12 10:24:07 -07002129 sprintf(buildstr, " build %u%s", build,
2130 (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
2131 ? " (EXP)" : "");
Johannes Berg3e4de762010-04-28 12:09:12 -07002132 else
2133 buildstr[0] = '\0';
Reinette Chatrea0987a82008-12-02 12:14:06 -08002134
Johannes Berg3e4de762010-04-28 12:09:12 -07002135 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u%s\n",
Reinette Chatre5ebeb5a2009-10-30 14:36:04 -07002136 IWL_UCODE_MAJOR(priv->ucode_ver),
2137 IWL_UCODE_MINOR(priv->ucode_ver),
2138 IWL_UCODE_API(priv->ucode_ver),
Johannes Berg3e4de762010-04-28 12:09:12 -07002139 IWL_UCODE_SERIAL(priv->ucode_ver),
2140 buildstr);
Reinette Chatre5ebeb5a2009-10-30 14:36:04 -07002141
Johannes Berg3e4de762010-04-28 12:09:12 -07002142 snprintf(priv->hw->wiphy->fw_version,
2143 sizeof(priv->hw->wiphy->fw_version),
2144 "%u.%u.%u.%u%s",
2145 IWL_UCODE_MAJOR(priv->ucode_ver),
2146 IWL_UCODE_MINOR(priv->ucode_ver),
2147 IWL_UCODE_API(priv->ucode_ver),
2148 IWL_UCODE_SERIAL(priv->ucode_ver),
2149 buildstr);
Zhu Yib481de92007-09-25 17:54:57 -07002150
Johannes Bergb08dfd02010-01-29 11:54:56 -08002151 /*
2152 * For any of the failures below (before allocating pci memory)
2153 * we will try to load a version with a smaller API -- maybe the
2154 * user just got a corrupted version of the latest API.
2155 */
2156
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002157 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
2158 priv->ucode_ver);
2159 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %Zd\n",
2160 pieces.inst_size);
2161 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %Zd\n",
2162 pieces.data_size);
2163 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %Zd\n",
2164 pieces.init_size);
2165 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %Zd\n",
2166 pieces.init_data_size);
2167 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %Zd\n",
2168 pieces.boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07002169
2170 /* Verify that uCode images will fit in card's SRAM */
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002171 if (pieces.inst_size > priv->hw_params.max_inst_size) {
2172 IWL_ERR(priv, "uCode instr len %Zd too large to fit in\n",
2173 pieces.inst_size);
Johannes Bergb08dfd02010-01-29 11:54:56 -08002174 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07002175 }
2176
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002177 if (pieces.data_size > priv->hw_params.max_data_size) {
2178 IWL_ERR(priv, "uCode data len %Zd too large to fit in\n",
2179 pieces.data_size);
Johannes Bergb08dfd02010-01-29 11:54:56 -08002180 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07002181 }
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002182
2183 if (pieces.init_size > priv->hw_params.max_inst_size) {
2184 IWL_ERR(priv, "uCode init instr len %Zd too large to fit in\n",
2185 pieces.init_size);
Johannes Bergb08dfd02010-01-29 11:54:56 -08002186 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07002187 }
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002188
2189 if (pieces.init_data_size > priv->hw_params.max_data_size) {
2190 IWL_ERR(priv, "uCode init data len %Zd too large to fit in\n",
2191 pieces.init_data_size);
Johannes Bergb08dfd02010-01-29 11:54:56 -08002192 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07002193 }
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002194
2195 if (pieces.boot_size > priv->hw_params.max_bsm_size) {
2196 IWL_ERR(priv, "uCode boot instr len %Zd too large to fit in\n",
2197 pieces.boot_size);
Johannes Bergb08dfd02010-01-29 11:54:56 -08002198 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07002199 }
2200
2201 /* Allocate ucode buffers for card's bus-master loading ... */
2202
2203 /* Runtime instructions and 2 copies of data:
2204 * 1) unmodified from disk
2205 * 2) backup cache for save/restore during power-downs */
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002206 priv->ucode_code.len = pieces.inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002207 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07002208
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002209 priv->ucode_data.len = pieces.data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002210 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07002211
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002212 priv->ucode_data_backup.len = pieces.data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002213 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07002214
Zhu, Yi1f304e42009-01-23 13:45:22 -08002215 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
2216 !priv->ucode_data_backup.v_addr)
2217 goto err_pci_alloc;
2218
Zhu Yib481de92007-09-25 17:54:57 -07002219 /* Initialization instructions and data */
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002220 if (pieces.init_size && pieces.init_data_size) {
2221 priv->ucode_init.len = pieces.init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002222 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Zhu Yib481de92007-09-25 17:54:57 -07002223
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002224 priv->ucode_init_data.len = pieces.init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002225 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002226
2227 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
2228 goto err_pci_alloc;
2229 }
Zhu Yib481de92007-09-25 17:54:57 -07002230
2231 /* Bootstrap (instructions only, no data) */
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002232 if (pieces.boot_size) {
2233 priv->ucode_boot.len = pieces.boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002234 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07002235
Tomas Winkler90e759d2007-11-29 11:09:41 +08002236 if (!priv->ucode_boot.v_addr)
2237 goto err_pci_alloc;
2238 }
Zhu Yib481de92007-09-25 17:54:57 -07002239
Johannes Bergb2e640d2010-05-05 23:24:54 -07002240 /* Now that we can no longer fail, copy information */
2241
2242 /*
2243 * The (size - 16) / 12 formula is based on the information recorded
2244 * for each event, which is of mode 1 (including timestamp) for all
2245 * new microcodes that include this information.
2246 */
2247 priv->_agn.init_evtlog_ptr = pieces.init_evtlog_ptr;
2248 if (pieces.init_evtlog_size)
2249 priv->_agn.init_evtlog_size = (pieces.init_evtlog_size - 16)/12;
2250 else
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002251 priv->_agn.init_evtlog_size =
2252 priv->cfg->base_params->max_event_log_size;
Johannes Bergb2e640d2010-05-05 23:24:54 -07002253 priv->_agn.init_errlog_ptr = pieces.init_errlog_ptr;
2254 priv->_agn.inst_evtlog_ptr = pieces.inst_evtlog_ptr;
2255 if (pieces.inst_evtlog_size)
2256 priv->_agn.inst_evtlog_size = (pieces.inst_evtlog_size - 16)/12;
2257 else
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002258 priv->_agn.inst_evtlog_size =
2259 priv->cfg->base_params->max_event_log_size;
Johannes Bergb2e640d2010-05-05 23:24:54 -07002260 priv->_agn.inst_errlog_ptr = pieces.inst_errlog_ptr;
2261
Johannes Bergece9c4e2010-08-23 10:46:49 +02002262 if (ucode_capa.pan) {
2263 priv->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
Johannes Bergc10afb62010-08-23 10:46:43 +02002264 priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
Johannes Bergece9c4e2010-08-23 10:46:49 +02002265 } else
2266 priv->sta_key_max_num = STA_KEY_MAX_NUM;
Johannes Bergc10afb62010-08-23 10:46:43 +02002267
Zhu Yib481de92007-09-25 17:54:57 -07002268 /* Copy images into buffers for card's bus-master reads ... */
2269
2270 /* Runtime instructions (first block of data in file) */
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002271 IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode instr len %Zd\n",
2272 pieces.inst_size);
2273 memcpy(priv->ucode_code.v_addr, pieces.inst, pieces.inst_size);
Jay Sternbergcc0f5552009-07-17 09:30:16 -07002274
Tomas Winklere1623442009-01-27 14:27:56 -08002275 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002276 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
2277
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002278 /*
2279 * Runtime data
2280 * NOTE: Copy into backup buffer will be done in iwl_up()
2281 */
2282 IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode data len %Zd\n",
2283 pieces.data_size);
2284 memcpy(priv->ucode_data.v_addr, pieces.data, pieces.data_size);
2285 memcpy(priv->ucode_data_backup.v_addr, pieces.data, pieces.data_size);
Zhu Yib481de92007-09-25 17:54:57 -07002286
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002287 /* Initialization instructions */
2288 if (pieces.init_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08002289 IWL_DEBUG_INFO(priv, "Copying (but not loading) init instr len %Zd\n",
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002290 pieces.init_size);
2291 memcpy(priv->ucode_init.v_addr, pieces.init, pieces.init_size);
Zhu Yib481de92007-09-25 17:54:57 -07002292 }
2293
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002294 /* Initialization data */
2295 if (pieces.init_data_size) {
Tomas Winklere1623442009-01-27 14:27:56 -08002296 IWL_DEBUG_INFO(priv, "Copying (but not loading) init data len %Zd\n",
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002297 pieces.init_data_size);
2298 memcpy(priv->ucode_init_data.v_addr, pieces.init_data,
2299 pieces.init_data_size);
Zhu Yib481de92007-09-25 17:54:57 -07002300 }
2301
Johannes Berg0e9a44d2010-04-28 12:09:16 -07002302 /* Bootstrap instructions */
2303 IWL_DEBUG_INFO(priv, "Copying (but not loading) boot instr len %Zd\n",
2304 pieces.boot_size);
2305 memcpy(priv->ucode_boot.v_addr, pieces.boot, pieces.boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07002306
Wey-Yi Guy6a822d02010-07-13 17:13:15 -07002307 /*
2308 * figure out the offset of chain noise reset and gain commands
2309 * base on the size of standard phy calibration commands table size
2310 */
2311 if (ucode_capa.standard_phy_calibration_size >
2312 IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
2313 ucode_capa.standard_phy_calibration_size =
2314 IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
2315
2316 priv->_agn.phy_calib_chain_noise_reset_cmd =
2317 ucode_capa.standard_phy_calibration_size;
2318 priv->_agn.phy_calib_chain_noise_gain_cmd =
2319 ucode_capa.standard_phy_calibration_size + 1;
2320
Johannes Bergb08dfd02010-01-29 11:54:56 -08002321 /**************************************************
2322 * This is still part of probe() in a sense...
2323 *
2324 * 9. Setup and register with mac80211 and debugfs
2325 **************************************************/
Johannes Bergdd7a2502010-04-28 23:33:10 -07002326 err = iwl_mac_setup_register(priv, &ucode_capa);
Johannes Bergb08dfd02010-01-29 11:54:56 -08002327 if (err)
2328 goto out_unbind;
2329
2330 err = iwl_dbgfs_register(priv, DRV_NAME);
2331 if (err)
2332 IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
2333
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07002334 err = sysfs_create_group(&priv->pci_dev->dev.kobj,
2335 &iwl_attribute_group);
2336 if (err) {
2337 IWL_ERR(priv, "failed to create sysfs device attributes\n");
2338 goto out_unbind;
2339 }
2340
Zhu Yib481de92007-09-25 17:54:57 -07002341 /* We have our copies now, allow OS release its copies */
2342 release_firmware(ucode_raw);
Reinette Chatrea15707d2010-05-10 15:08:11 -07002343 complete(&priv->_agn.firmware_loading_complete);
Johannes Bergb08dfd02010-01-29 11:54:56 -08002344 return;
2345
2346 try_again:
2347 /* try next, if any */
2348 if (iwl_request_firmware(priv, false))
2349 goto out_unbind;
2350 release_firmware(ucode_raw);
2351 return;
Zhu Yib481de92007-09-25 17:54:57 -07002352
2353 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002354 IWL_ERR(priv, "failed to allocate pci memory\n");
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002355 iwl_dealloc_ucode_pci(priv);
Johannes Bergb08dfd02010-01-29 11:54:56 -08002356 out_unbind:
Reinette Chatrea15707d2010-05-10 15:08:11 -07002357 complete(&priv->_agn.firmware_loading_complete);
Johannes Bergb08dfd02010-01-29 11:54:56 -08002358 device_release_driver(&priv->pci_dev->dev);
Zhu Yib481de92007-09-25 17:54:57 -07002359 release_firmware(ucode_raw);
Zhu Yib481de92007-09-25 17:54:57 -07002360}
2361
Reinette Chatreb7a79402009-09-25 14:24:23 -07002362static const char *desc_lookup_text[] = {
2363 "OK",
2364 "FAIL",
2365 "BAD_PARAM",
2366 "BAD_CHECKSUM",
2367 "NMI_INTERRUPT_WDG",
2368 "SYSASSERT",
2369 "FATAL_ERROR",
2370 "BAD_COMMAND",
2371 "HW_ERROR_TUNE_LOCK",
2372 "HW_ERROR_TEMPERATURE",
2373 "ILLEGAL_CHAN_FREQ",
2374 "VCC_NOT_STABLE",
2375 "FH_ERROR",
2376 "NMI_INTERRUPT_HOST",
2377 "NMI_INTERRUPT_ACTION_PT",
2378 "NMI_INTERRUPT_UNKNOWN",
2379 "UCODE_VERSION_MISMATCH",
2380 "HW_ERROR_ABS_LOCK",
2381 "HW_ERROR_CAL_LOCK_FAIL",
2382 "NMI_INTERRUPT_INST_ACTION_PT",
2383 "NMI_INTERRUPT_DATA_ACTION_PT",
2384 "NMI_TRM_HW_ER",
2385 "NMI_INTERRUPT_TRM",
2386 "NMI_INTERRUPT_BREAK_POINT"
2387 "DEBUG_0",
2388 "DEBUG_1",
2389 "DEBUG_2",
2390 "DEBUG_3",
Reinette Chatreb7a79402009-09-25 14:24:23 -07002391};
2392
Jay Sternberg4b586452010-07-02 15:49:10 -07002393static struct { char *name; u8 num; } advanced_lookup[] = {
2394 { "NMI_INTERRUPT_WDG", 0x34 },
2395 { "SYSASSERT", 0x35 },
2396 { "UCODE_VERSION_MISMATCH", 0x37 },
2397 { "BAD_COMMAND", 0x38 },
2398 { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
2399 { "FATAL_ERROR", 0x3D },
2400 { "NMI_TRM_HW_ERR", 0x46 },
2401 { "NMI_INTERRUPT_TRM", 0x4C },
2402 { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
2403 { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
2404 { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
2405 { "NMI_INTERRUPT_HOST", 0x66 },
2406 { "NMI_INTERRUPT_ACTION_PT", 0x7C },
2407 { "NMI_INTERRUPT_UNKNOWN", 0x84 },
2408 { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
2409 { "ADVANCED_SYSASSERT", 0 },
2410};
2411
2412static const char *desc_lookup(u32 num)
Reinette Chatreb7a79402009-09-25 14:24:23 -07002413{
Jay Sternberg4b586452010-07-02 15:49:10 -07002414 int i;
2415 int max = ARRAY_SIZE(desc_lookup_text);
Reinette Chatreb7a79402009-09-25 14:24:23 -07002416
Jay Sternberg4b586452010-07-02 15:49:10 -07002417 if (num < max)
2418 return desc_lookup_text[num];
Reinette Chatreb7a79402009-09-25 14:24:23 -07002419
Jay Sternberg4b586452010-07-02 15:49:10 -07002420 max = ARRAY_SIZE(advanced_lookup) - 1;
2421 for (i = 0; i < max; i++) {
2422 if (advanced_lookup[i].num == num)
2423 break;;
2424 }
2425 return advanced_lookup[i].name;
Reinette Chatreb7a79402009-09-25 14:24:23 -07002426}
2427
2428#define ERROR_START_OFFSET (1 * sizeof(u32))
2429#define ERROR_ELEM_SIZE (7 * sizeof(u32))
2430
2431void iwl_dump_nic_error_log(struct iwl_priv *priv)
2432{
2433 u32 data2, line;
2434 u32 desc, time, count, base, data1;
2435 u32 blink1, blink2, ilink1, ilink2;
Wey-Yi Guy461ef382010-03-30 17:57:53 -07002436 u32 pc, hcmd;
Reinette Chatreb7a79402009-09-25 14:24:23 -07002437
Johannes Bergb2e640d2010-05-05 23:24:54 -07002438 if (priv->ucode_type == UCODE_INIT) {
Reinette Chatreb7a79402009-09-25 14:24:23 -07002439 base = le32_to_cpu(priv->card_alive_init.error_event_table_ptr);
Johannes Bergb2e640d2010-05-05 23:24:54 -07002440 if (!base)
2441 base = priv->_agn.init_errlog_ptr;
2442 } else {
Reinette Chatreb7a79402009-09-25 14:24:23 -07002443 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
Johannes Bergb2e640d2010-05-05 23:24:54 -07002444 if (!base)
2445 base = priv->_agn.inst_errlog_ptr;
2446 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07002447
2448 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
Wey-Yi Guy212fb572009-12-02 12:53:00 -08002449 IWL_ERR(priv,
2450 "Not valid error log pointer 0x%08X for %s uCode\n",
2451 base, (priv->ucode_type == UCODE_INIT) ? "Init" : "RT");
Reinette Chatreb7a79402009-09-25 14:24:23 -07002452 return;
2453 }
2454
2455 count = iwl_read_targ_mem(priv, base);
2456
2457 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
2458 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
2459 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
2460 priv->status, count);
2461 }
2462
2463 desc = iwl_read_targ_mem(priv, base + 1 * sizeof(u32));
Wey-Yi Guy6e6ebf42010-08-27 10:41:37 -07002464 priv->isr_stats.err_code = desc;
Wey-Yi Guy461ef382010-03-30 17:57:53 -07002465 pc = iwl_read_targ_mem(priv, base + 2 * sizeof(u32));
Reinette Chatreb7a79402009-09-25 14:24:23 -07002466 blink1 = iwl_read_targ_mem(priv, base + 3 * sizeof(u32));
2467 blink2 = iwl_read_targ_mem(priv, base + 4 * sizeof(u32));
2468 ilink1 = iwl_read_targ_mem(priv, base + 5 * sizeof(u32));
2469 ilink2 = iwl_read_targ_mem(priv, base + 6 * sizeof(u32));
2470 data1 = iwl_read_targ_mem(priv, base + 7 * sizeof(u32));
2471 data2 = iwl_read_targ_mem(priv, base + 8 * sizeof(u32));
2472 line = iwl_read_targ_mem(priv, base + 9 * sizeof(u32));
2473 time = iwl_read_targ_mem(priv, base + 11 * sizeof(u32));
Wey-Yi Guy461ef382010-03-30 17:57:53 -07002474 hcmd = iwl_read_targ_mem(priv, base + 22 * sizeof(u32));
Reinette Chatreb7a79402009-09-25 14:24:23 -07002475
Johannes Bergbe1a71a2009-10-02 13:44:02 -07002476 trace_iwlwifi_dev_ucode_error(priv, desc, time, data1, data2, line,
2477 blink1, blink2, ilink1, ilink2);
2478
Jay Sternberg87563712010-06-14 14:40:40 -07002479 IWL_ERR(priv, "Desc Time "
Reinette Chatreb7a79402009-09-25 14:24:23 -07002480 "data1 data2 line\n");
Jay Sternberg87563712010-06-14 14:40:40 -07002481 IWL_ERR(priv, "%-28s (0x%04X) %010u 0x%08X 0x%08X %u\n",
Reinette Chatreb7a79402009-09-25 14:24:23 -07002482 desc_lookup(desc), desc, time, data1, data2, line);
Wey-Yi Guy461ef382010-03-30 17:57:53 -07002483 IWL_ERR(priv, "pc blink1 blink2 ilink1 ilink2 hcmd\n");
2484 IWL_ERR(priv, "0x%05X 0x%05X 0x%05X 0x%05X 0x%05X 0x%05X\n",
2485 pc, blink1, blink2, ilink1, ilink2, hcmd);
Reinette Chatreb7a79402009-09-25 14:24:23 -07002486}
2487
2488#define EVENT_START_OFFSET (4 * sizeof(u32))
2489
2490/**
2491 * iwl_print_event_log - Dump error event log to syslog
2492 *
2493 */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002494static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
2495 u32 num_events, u32 mode,
2496 int pos, char **buf, size_t bufsz)
Reinette Chatreb7a79402009-09-25 14:24:23 -07002497{
2498 u32 i;
2499 u32 base; /* SRAM byte address of event log header */
2500 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
2501 u32 ptr; /* SRAM byte address of log data */
2502 u32 ev, time, data; /* event log data */
Ben Cahille5854472009-11-06 14:52:58 -08002503 unsigned long reg_flags;
Reinette Chatreb7a79402009-09-25 14:24:23 -07002504
2505 if (num_events == 0)
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002506 return pos;
Johannes Bergb2e640d2010-05-05 23:24:54 -07002507
2508 if (priv->ucode_type == UCODE_INIT) {
Reinette Chatreb7a79402009-09-25 14:24:23 -07002509 base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
Johannes Bergb2e640d2010-05-05 23:24:54 -07002510 if (!base)
2511 base = priv->_agn.init_evtlog_ptr;
2512 } else {
Reinette Chatreb7a79402009-09-25 14:24:23 -07002513 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Johannes Bergb2e640d2010-05-05 23:24:54 -07002514 if (!base)
2515 base = priv->_agn.inst_evtlog_ptr;
2516 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07002517
2518 if (mode == 0)
2519 event_size = 2 * sizeof(u32);
2520 else
2521 event_size = 3 * sizeof(u32);
2522
2523 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
2524
Ben Cahille5854472009-11-06 14:52:58 -08002525 /* Make sure device is powered up for SRAM reads */
2526 spin_lock_irqsave(&priv->reg_lock, reg_flags);
2527 iwl_grab_nic_access(priv);
2528
2529 /* Set starting address; reads will auto-increment */
2530 _iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, ptr);
2531 rmb();
2532
Reinette Chatreb7a79402009-09-25 14:24:23 -07002533 /* "time" is actually "data" for mode 0 (no timestamp).
2534 * place event id # at far right for easier visual parsing. */
2535 for (i = 0; i < num_events; i++) {
Ben Cahille5854472009-11-06 14:52:58 -08002536 ev = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
2537 time = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Reinette Chatreb7a79402009-09-25 14:24:23 -07002538 if (mode == 0) {
2539 /* data, ev */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002540 if (bufsz) {
2541 pos += scnprintf(*buf + pos, bufsz - pos,
2542 "EVT_LOG:0x%08x:%04u\n",
2543 time, ev);
2544 } else {
2545 trace_iwlwifi_dev_ucode_event(priv, 0,
2546 time, ev);
2547 IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n",
2548 time, ev);
2549 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07002550 } else {
Ben Cahille5854472009-11-06 14:52:58 -08002551 data = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002552 if (bufsz) {
2553 pos += scnprintf(*buf + pos, bufsz - pos,
2554 "EVT_LOGT:%010u:0x%08x:%04u\n",
2555 time, data, ev);
2556 } else {
2557 IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
Reinette Chatreb7a79402009-09-25 14:24:23 -07002558 time, data, ev);
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002559 trace_iwlwifi_dev_ucode_event(priv, time,
2560 data, ev);
2561 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07002562 }
2563 }
Ben Cahille5854472009-11-06 14:52:58 -08002564
2565 /* Allow device to power down */
2566 iwl_release_nic_access(priv);
2567 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002568 return pos;
Reinette Chatreb7a79402009-09-25 14:24:23 -07002569}
2570
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002571/**
2572 * iwl_print_last_event_logs - Dump the newest # of event log to syslog
2573 */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002574static int iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
2575 u32 num_wraps, u32 next_entry,
2576 u32 size, u32 mode,
2577 int pos, char **buf, size_t bufsz)
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002578{
2579 /*
2580 * display the newest DEFAULT_LOG_ENTRIES entries
2581 * i.e the entries just before the next ont that uCode would fill.
2582 */
2583 if (num_wraps) {
2584 if (next_entry < size) {
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002585 pos = iwl_print_event_log(priv,
2586 capacity - (size - next_entry),
2587 size - next_entry, mode,
2588 pos, buf, bufsz);
2589 pos = iwl_print_event_log(priv, 0,
2590 next_entry, mode,
2591 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002592 } else
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002593 pos = iwl_print_event_log(priv, next_entry - size,
2594 size, mode, pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002595 } else {
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002596 if (next_entry < size) {
2597 pos = iwl_print_event_log(priv, 0, next_entry,
2598 mode, pos, buf, bufsz);
2599 } else {
2600 pos = iwl_print_event_log(priv, next_entry - size,
2601 size, mode, pos, buf, bufsz);
2602 }
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002603 }
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002604 return pos;
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002605}
2606
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002607#define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
2608
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002609int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
2610 char **buf, bool display)
Reinette Chatreb7a79402009-09-25 14:24:23 -07002611{
2612 u32 base; /* SRAM byte address of event log header */
2613 u32 capacity; /* event log capacity in # entries */
2614 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
2615 u32 num_wraps; /* # times uCode wrapped to top of log */
2616 u32 next_entry; /* index of next entry to be written by uCode */
2617 u32 size; /* # entries that we'll print */
Johannes Bergb2e640d2010-05-05 23:24:54 -07002618 u32 logsize;
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002619 int pos = 0;
2620 size_t bufsz = 0;
Reinette Chatreb7a79402009-09-25 14:24:23 -07002621
Johannes Bergb2e640d2010-05-05 23:24:54 -07002622 if (priv->ucode_type == UCODE_INIT) {
Reinette Chatreb7a79402009-09-25 14:24:23 -07002623 base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
Johannes Bergb2e640d2010-05-05 23:24:54 -07002624 logsize = priv->_agn.init_evtlog_size;
2625 if (!base)
2626 base = priv->_agn.init_evtlog_ptr;
2627 } else {
Reinette Chatreb7a79402009-09-25 14:24:23 -07002628 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Johannes Bergb2e640d2010-05-05 23:24:54 -07002629 logsize = priv->_agn.inst_evtlog_size;
2630 if (!base)
2631 base = priv->_agn.inst_evtlog_ptr;
2632 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07002633
2634 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
Wey-Yi Guy212fb572009-12-02 12:53:00 -08002635 IWL_ERR(priv,
2636 "Invalid event log pointer 0x%08X for %s uCode\n",
2637 base, (priv->ucode_type == UCODE_INIT) ? "Init" : "RT");
Wey-Yi Guy937c3972010-01-15 13:43:36 -08002638 return -EINVAL;
Reinette Chatreb7a79402009-09-25 14:24:23 -07002639 }
2640
2641 /* event log header */
2642 capacity = iwl_read_targ_mem(priv, base);
2643 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
2644 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
2645 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
2646
Johannes Bergb2e640d2010-05-05 23:24:54 -07002647 if (capacity > logsize) {
Ben Cahill84c40692009-11-06 14:52:57 -08002648 IWL_ERR(priv, "Log capacity %d is bogus, limit to %d entries\n",
Johannes Bergb2e640d2010-05-05 23:24:54 -07002649 capacity, logsize);
2650 capacity = logsize;
Ben Cahill84c40692009-11-06 14:52:57 -08002651 }
2652
Johannes Bergb2e640d2010-05-05 23:24:54 -07002653 if (next_entry > logsize) {
Ben Cahill84c40692009-11-06 14:52:57 -08002654 IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
Johannes Bergb2e640d2010-05-05 23:24:54 -07002655 next_entry, logsize);
2656 next_entry = logsize;
Ben Cahill84c40692009-11-06 14:52:57 -08002657 }
2658
Reinette Chatreb7a79402009-09-25 14:24:23 -07002659 size = num_wraps ? capacity : next_entry;
2660
2661 /* bail out if nothing in log */
2662 if (size == 0) {
2663 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002664 return pos;
Reinette Chatreb7a79402009-09-25 14:24:23 -07002665 }
2666
Wey-Yi Guyf37837c2010-08-23 07:57:12 -07002667 /* enable/disable bt channel announcement */
2668 priv->bt_ch_announce = iwlagn_bt_ch_announce;
2669
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002670#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guy521d9bc2009-12-10 14:37:23 -08002671 if (!(iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) && !full_log)
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002672 size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
2673 ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
2674#else
2675 size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
2676 ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
Reinette Chatreb7a79402009-09-25 14:24:23 -07002677#endif
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002678 IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n",
2679 size);
2680
2681#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002682 if (display) {
2683 if (full_log)
2684 bufsz = capacity * 48;
2685 else
2686 bufsz = size * 48;
2687 *buf = kmalloc(bufsz, GFP_KERNEL);
2688 if (!*buf)
Wey-Yi Guy937c3972010-01-15 13:43:36 -08002689 return -ENOMEM;
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002690 }
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002691 if ((iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) || full_log) {
2692 /*
2693 * if uCode has wrapped back to top of log,
2694 * start at the oldest entry,
2695 * i.e the next one that uCode would fill.
2696 */
2697 if (num_wraps)
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002698 pos = iwl_print_event_log(priv, next_entry,
2699 capacity - next_entry, mode,
2700 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002701 /* (then/else) start at top of log */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002702 pos = iwl_print_event_log(priv, 0,
2703 next_entry, mode, pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002704 } else
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002705 pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
2706 next_entry, size, mode,
2707 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002708#else
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002709 pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
2710 next_entry, size, mode,
2711 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002712#endif
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002713 return pos;
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002714}
Reinette Chatreb7a79402009-09-25 14:24:23 -07002715
Wey-Yi Guy0975cc82010-07-31 08:34:07 -07002716static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
2717{
2718 struct iwl_ct_kill_config cmd;
2719 struct iwl_ct_kill_throttling_config adv_cmd;
2720 unsigned long flags;
2721 int ret = 0;
2722
2723 spin_lock_irqsave(&priv->lock, flags);
2724 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
2725 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
2726 spin_unlock_irqrestore(&priv->lock, flags);
2727 priv->thermal_throttle.ct_kill_toggle = false;
2728
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002729 if (priv->cfg->base_params->support_ct_kill_exit) {
Wey-Yi Guy0975cc82010-07-31 08:34:07 -07002730 adv_cmd.critical_temperature_enter =
2731 cpu_to_le32(priv->hw_params.ct_kill_threshold);
2732 adv_cmd.critical_temperature_exit =
2733 cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
2734
2735 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
2736 sizeof(adv_cmd), &adv_cmd);
2737 if (ret)
2738 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
2739 else
2740 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
2741 "succeeded, "
2742 "critical temperature enter is %d,"
2743 "exit is %d\n",
2744 priv->hw_params.ct_kill_threshold,
2745 priv->hw_params.ct_kill_exit_threshold);
2746 } else {
2747 cmd.critical_temperature_R =
2748 cpu_to_le32(priv->hw_params.ct_kill_threshold);
2749
2750 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
2751 sizeof(cmd), &cmd);
2752 if (ret)
2753 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
2754 else
2755 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
2756 "succeeded, "
2757 "critical temperature is %d\n",
2758 priv->hw_params.ct_kill_threshold);
2759 }
2760}
2761
Shanyu Zhao6d6a1af2010-09-14 18:13:31 -07002762static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
2763{
2764 struct iwl_calib_cfg_cmd calib_cfg_cmd;
2765 struct iwl_host_cmd cmd = {
2766 .id = CALIBRATION_CFG_CMD,
2767 .len = sizeof(struct iwl_calib_cfg_cmd),
2768 .data = &calib_cfg_cmd,
2769 };
2770
2771 memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
2772 calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL;
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002773 calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg);
Shanyu Zhao6d6a1af2010-09-14 18:13:31 -07002774
2775 return iwl_send_cmd(priv, &cmd);
2776}
2777
2778
Zhu Yib481de92007-09-25 17:54:57 -07002779/**
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002780 * iwl_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002781 * from protocol/runtime uCode (initialization uCode's
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002782 * Alive gets handled by iwl_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07002783 */
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002784static void iwl_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002785{
Tomas Winkler57aab752008-04-14 21:16:03 -07002786 int ret = 0;
Johannes Berg246ed352010-08-23 10:46:32 +02002787 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Zhu Yib481de92007-09-25 17:54:57 -07002788
Tomas Winklere1623442009-01-27 14:27:56 -08002789 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002790
2791 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
2792 /* We had an error bringing up the hardware, so take it
2793 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002794 IWL_DEBUG_INFO(priv, "Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002795 goto restart;
2796 }
2797
2798 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2799 * This is a paranoid check, because we would not have gotten the
2800 * "runtime" alive if code weren't properly loaded. */
Emmanuel Grumbachb0692f22008-04-24 11:55:18 -07002801 if (iwl_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002802 /* Runtime instruction load was bad;
2803 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002804 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002805 goto restart;
2806 }
2807
Tomas Winkler57aab752008-04-14 21:16:03 -07002808 ret = priv->cfg->ops->lib->alive_notify(priv);
2809 if (ret) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002810 IWL_WARN(priv,
2811 "Could not complete ALIVE transition [ntf]: %d\n", ret);
Zhu Yib481de92007-09-25 17:54:57 -07002812 goto restart;
2813 }
2814
Shanyu Zhao6d6a1af2010-09-14 18:13:31 -07002815
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002816 /* After the ALIVE response, we can send host commands to the uCode */
Zhu Yib481de92007-09-25 17:54:57 -07002817 set_bit(STATUS_ALIVE, &priv->status);
2818
Wey-Yi Guyb74e31a2010-03-01 17:23:50 -08002819 if (priv->cfg->ops->lib->recover_from_tx_stall) {
2820 /* Enable timer to monitor the driver queues */
2821 mod_timer(&priv->monitor_recover,
2822 jiffies +
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002823 msecs_to_jiffies(
2824 priv->cfg->base_params->monitor_recover_period));
Wey-Yi Guyb74e31a2010-03-01 17:23:50 -08002825 }
2826
Tomas Winklerfee12472008-04-03 16:05:21 -07002827 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002828 return;
2829
Wey-Yi Guybc795df2010-10-11 14:24:05 -07002830 /* download priority table before any calibration request */
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002831 if (priv->cfg->bt_params &&
2832 priv->cfg->bt_params->advanced_bt_coexist) {
Wey-Yi Guyf7322f82010-08-23 15:24:49 -07002833 /* Configure Bluetooth device coexistence support */
2834 priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
2835 priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
2836 priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
2837 priv->cfg->ops->hcmd->send_bt_config(priv);
2838 priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS;
Wey-Yi Guya5901cb2010-09-23 09:56:51 -07002839 iwlagn_send_prio_tbl(priv);
Wey-Yi Guyf7322f82010-08-23 15:24:49 -07002840
2841 /* FIXME: w/a to force change uCode BT state machine */
2842 iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
2843 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
2844 iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
2845 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
2846 }
Wey-Yi Guybc795df2010-10-11 14:24:05 -07002847 if (priv->hw_params.calib_rt_cfg)
2848 iwlagn_send_calib_cfg_rt(priv, priv->hw_params.calib_rt_cfg);
2849
Johannes Berg36d68252008-05-15 12:55:26 +02002850 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002851
Johannes Berg470ab2d2010-01-21 11:23:30 -08002852 priv->active_rate = IWL_RATES_MASK;
Zhu Yib481de92007-09-25 17:54:57 -07002853
Wey-Yi Guy2f748de2009-09-17 10:43:51 -07002854 /* Configure Tx antenna selection based on H/W config */
2855 if (priv->cfg->ops->hcmd->set_tx_ant)
2856 priv->cfg->ops->hcmd->set_tx_ant(priv, priv->cfg->valid_tx_ant);
2857
Johannes Berg246ed352010-08-23 10:46:32 +02002858 if (iwl_is_associated_ctx(ctx)) {
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08002859 struct iwl_rxon_cmd *active_rxon =
Johannes Berg246ed352010-08-23 10:46:32 +02002860 (struct iwl_rxon_cmd *)&ctx->active;
Mohamed Abbas019fb972009-03-17 21:59:18 -07002861 /* apply any changes in staging */
Johannes Berg246ed352010-08-23 10:46:32 +02002862 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07002863 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2864 } else {
Johannes Bergd0fe4782010-08-23 10:46:58 +02002865 struct iwl_rxon_context *tmp;
Zhu Yib481de92007-09-25 17:54:57 -07002866 /* Initialize our rx_config data */
Johannes Bergd0fe4782010-08-23 10:46:58 +02002867 for_each_context(priv, tmp)
2868 iwl_connection_init_rx_config(priv, tmp);
Abhijeet Kolekar45823532009-04-08 11:26:44 -07002869
2870 if (priv->cfg->ops->hcmd->set_rxon_chain)
Johannes Berg246ed352010-08-23 10:46:32 +02002871 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
Zhu Yib481de92007-09-25 17:54:57 -07002872 }
2873
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002874 if (priv->cfg->bt_params &&
2875 !priv->cfg->bt_params->advanced_bt_coexist) {
Wey-Yi Guyaeb4a2e2010-08-23 07:57:05 -07002876 /* Configure Bluetooth device coexistence support */
2877 priv->cfg->ops->hcmd->send_bt_config(priv);
2878 }
Zhu Yib481de92007-09-25 17:54:57 -07002879
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002880 iwl_reset_run_time_calib(priv);
2881
Zhu Yib481de92007-09-25 17:54:57 -07002882 /* Configure the adapter for unassociated operation */
Johannes Berg246ed352010-08-23 10:46:32 +02002883 iwlcore_commit_rxon(priv, ctx);
Zhu Yib481de92007-09-25 17:54:57 -07002884
2885 /* At this point, the NIC is initialized and operational */
Emmanuel Grumbach47f4a582008-06-12 09:47:13 +08002886 iwl_rf_kill_ct_config(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002887
Johannes Berge932a602009-10-02 13:44:03 -07002888 iwl_leds_init(priv);
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07002889
Tomas Winklere1623442009-01-27 14:27:56 -08002890 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07002891 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002892 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07002893
Johannes Berge312c242009-08-07 15:41:51 -07002894 iwl_power_update_mode(priv, true);
Reinette Chatre7e246192010-02-18 22:58:32 -08002895 IWL_DEBUG_INFO(priv, "Updated power mode\n");
2896
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002897
Zhu Yib481de92007-09-25 17:54:57 -07002898 return;
2899
2900 restart:
2901 queue_work(priv->workqueue, &priv->restart);
2902}
2903
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002904static void iwl_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07002905
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002906static void __iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002907{
2908 unsigned long flags;
2909 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002910
Tomas Winklere1623442009-01-27 14:27:56 -08002911 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07002912
Stanislaw Gruszkad745d472010-09-13 14:46:35 +02002913 iwl_scan_cancel_timeout(priv, 200);
2914
2915 exit_pending = test_and_set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002916
Stanislaw Gruszkab62177a2010-08-20 15:23:47 +02002917 /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
2918 * to prevent rearm timer */
2919 if (priv->cfg->ops->lib->recover_from_tx_stall)
2920 del_timer_sync(&priv->monitor_recover);
2921
Johannes Bergdcef7322010-08-27 08:55:52 -07002922 iwl_clear_ucode_stations(priv, NULL);
Johannes Berga194e322010-08-27 08:53:46 -07002923 iwl_dealloc_bcast_stations(priv);
Johannes Bergdb125c72010-05-07 01:49:15 -07002924 iwl_clear_driver_stations(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002925
Johannes Berga1174132010-08-23 07:56:59 -07002926 /* reset BT coex data */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002927 priv->bt_status = 0;
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002928 if (priv->cfg->bt_params)
2929 priv->bt_traffic_load =
2930 priv->cfg->bt_params->bt_init_traffic_load;
2931 else
2932 priv->bt_traffic_load = 0;
Johannes Berga1174132010-08-23 07:56:59 -07002933 priv->bt_sco_active = false;
Wey-Yi Guybee008b2010-08-23 07:57:04 -07002934 priv->bt_full_concurrent = false;
2935 priv->bt_ci_compliance = 0;
Johannes Berga1174132010-08-23 07:56:59 -07002936
Zhu Yib481de92007-09-25 17:54:57 -07002937 /* Unblock any waiting calls */
2938 wake_up_interruptible_all(&priv->wait_command_queue);
2939
Zhu Yib481de92007-09-25 17:54:57 -07002940 /* Wipe out the EXIT_PENDING status bit if we are not actually
2941 * exiting the module */
2942 if (!exit_pending)
2943 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2944
2945 /* stop and reset the on-board processor */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002946 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07002947
2948 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002949 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002950 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002951 spin_unlock_irqrestore(&priv->lock, flags);
2952 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002953
2954 if (priv->mac80211_registered)
2955 ieee80211_stop_queues(priv->hw);
2956
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002957 /* If we have not previously called iwl_init() then
Johannes Berga60e77e2009-06-04 18:26:06 +02002958 * clear all bits but the RF Kill bit and return */
Tomas Winklerfee12472008-04-03 16:05:21 -07002959 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002960 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2961 STATUS_RF_KILL_HW |
Reinette Chatre97888642008-02-06 11:20:38 -08002962 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2963 STATUS_GEO_CONFIGURED |
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002964 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2965 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002966 goto exit;
2967 }
2968
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002969 /* ...otherwise clear out all the status bits but the RF Kill
Johannes Berga60e77e2009-06-04 18:26:06 +02002970 * bit and continue taking the NIC down. */
Zhu Yib481de92007-09-25 17:54:57 -07002971 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2972 STATUS_RF_KILL_HW |
Reinette Chatre97888642008-02-06 11:20:38 -08002973 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2974 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002975 test_bit(STATUS_FW_ERROR, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002976 STATUS_FW_ERROR |
2977 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2978 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002979
Mohamed Abbasef850d72009-05-22 11:01:50 -07002980 /* device going down, Stop using ICT table */
2981 iwl_disable_ict(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002982
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -07002983 iwlagn_txq_ctx_stop(priv);
Wey-Yi Guy54b81552010-03-17 13:34:35 -07002984 iwlagn_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002985
Ben Cahill309e7312009-11-06 14:53:03 -08002986 /* Power-down device's busmaster DMA clocks */
2987 iwl_write_prph(priv, APMG_CLK_DIS_REG, APMG_CLK_VAL_DMA_CLK_RQT);
Zhu Yib481de92007-09-25 17:54:57 -07002988 udelay(5);
2989
Ben Cahill309e7312009-11-06 14:53:03 -08002990 /* Make sure (redundant) we've released our request to stay awake */
2991 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
2992
Ben Cahill4d2ccdb2009-10-09 13:20:20 -07002993 /* Stop the device, and put it in low power state */
Johannes Berg14e8e4a2010-09-22 18:02:10 +02002994 iwl_apm_stop(priv);
Ben Cahill4d2ccdb2009-10-09 13:20:20 -07002995
Zhu Yib481de92007-09-25 17:54:57 -07002996 exit:
Tomas Winkler885ba202008-05-29 16:34:55 +08002997 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07002998
Johannes Berg77834542010-10-04 05:50:36 -07002999 dev_kfree_skb(priv->beacon_skb);
Johannes Berg12e934d2010-10-04 05:50:06 -07003000 priv->beacon_skb = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07003001
3002 /* clear out any free frames */
Tomas Winklerfcab4232008-05-15 13:54:01 +08003003 iwl_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003004}
3005
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003006static void iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003007{
3008 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003009 __iwl_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003010 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08003011
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003012 iwl_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003013}
3014
Mohamed Abbas086ed112009-05-22 11:01:54 -07003015#define HW_READY_TIMEOUT (50)
3016
3017static int iwl_set_hw_ready(struct iwl_priv *priv)
3018{
3019 int ret = 0;
3020
3021 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
3022 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
3023
3024 /* See if we got it */
3025 ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
3026 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
3027 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
3028 HW_READY_TIMEOUT);
3029 if (ret != -ETIMEDOUT)
3030 priv->hw_ready = true;
3031 else
3032 priv->hw_ready = false;
3033
3034 IWL_DEBUG_INFO(priv, "hardware %s\n",
3035 (priv->hw_ready == 1) ? "ready" : "not ready");
3036 return ret;
3037}
3038
3039static int iwl_prepare_card_hw(struct iwl_priv *priv)
3040{
3041 int ret = 0;
3042
Frans Pop91dd6c22010-03-24 14:19:58 -07003043 IWL_DEBUG_INFO(priv, "iwl_prepare_card_hw enter\n");
Mohamed Abbas086ed112009-05-22 11:01:54 -07003044
Mohamed Abbas3354a0f2009-06-19 13:52:41 -07003045 ret = iwl_set_hw_ready(priv);
3046 if (priv->hw_ready)
3047 return ret;
3048
3049 /* If HW is not ready, prepare the conditions to check again */
Mohamed Abbas086ed112009-05-22 11:01:54 -07003050 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
3051 CSR_HW_IF_CONFIG_REG_PREPARE);
3052
3053 ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
3054 ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE,
3055 CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000);
3056
Mohamed Abbas3354a0f2009-06-19 13:52:41 -07003057 /* HW should be ready by now, check again. */
Mohamed Abbas086ed112009-05-22 11:01:54 -07003058 if (ret != -ETIMEDOUT)
3059 iwl_set_hw_ready(priv);
3060
3061 return ret;
3062}
3063
Zhu Yib481de92007-09-25 17:54:57 -07003064#define MAX_HW_RESTARTS 5
3065
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003066static int __iwl_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003067{
Johannes Berga194e322010-08-27 08:53:46 -07003068 struct iwl_rxon_context *ctx;
Tomas Winkler57aab752008-04-14 21:16:03 -07003069 int i;
3070 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003071
3072 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003073 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003074 return -EIO;
3075 }
3076
Reinette Chatree903fbd2008-01-30 22:05:15 -08003077 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003078 IWL_ERR(priv, "ucode not available for device bringup\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08003079 return -EIO;
3080 }
3081
Johannes Berga194e322010-08-27 08:53:46 -07003082 for_each_context(priv, ctx) {
Johannes Berga30e3112010-09-22 18:02:01 +02003083 ret = iwlagn_alloc_bcast_station(priv, ctx);
Johannes Berga194e322010-08-27 08:53:46 -07003084 if (ret) {
3085 iwl_dealloc_bcast_stations(priv);
3086 return ret;
3087 }
3088 }
Johannes Berg2c810cc2010-04-29 00:53:29 -07003089
Mohamed Abbas086ed112009-05-22 11:01:54 -07003090 iwl_prepare_card_hw(priv);
3091
3092 if (!priv->hw_ready) {
3093 IWL_WARN(priv, "Exit HW not ready\n");
3094 return -EIO;
3095 }
3096
Zhu Yie655b9f2008-01-24 02:19:38 -08003097 /* If platform's RF_KILL switch is NOT set to KILL */
Tomas Winklerc1842d62008-08-04 16:00:43 +08003098 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
Zhu Yie655b9f2008-01-24 02:19:38 -08003099 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08003100 else
Zhu Yie655b9f2008-01-24 02:19:38 -08003101 set_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08003102
Tomas Winklerc1842d62008-08-04 16:00:43 +08003103 if (iwl_is_rfkill(priv)) {
Johannes Berga60e77e2009-06-04 18:26:06 +02003104 wiphy_rfkill_set_hw_state(priv->hw->wiphy, true);
3105
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003106 iwl_enable_interrupts(priv);
Johannes Berga60e77e2009-06-04 18:26:06 +02003107 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
Tomas Winklerc1842d62008-08-04 16:00:43 +08003108 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07003109 }
3110
Tomas Winkler3395f6e2008-03-25 16:33:37 -07003111 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07003112
Johannes Berg13bb9482010-08-23 10:46:33 +02003113 /* must be initialised before iwl_hw_nic_init */
Johannes Berg751ca302010-08-23 10:46:34 +02003114 if (priv->valid_contexts != BIT(IWL_RXON_CTX_BSS))
3115 priv->cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
3116 else
3117 priv->cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
Johannes Berg13bb9482010-08-23 10:46:33 +02003118
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -07003119 ret = iwlagn_hw_nic_init(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07003120 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003121 IWL_ERR(priv, "Unable to init nic\n");
Tomas Winkler57aab752008-04-14 21:16:03 -07003122 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003123 }
3124
3125 /* make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07003126 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3127 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07003128 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3129
3130 /* clear (again), then enable host interrupts */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07003131 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003132 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003133
3134 /* really make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07003135 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3136 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07003137
3138 /* Copy original ucode data image from disk into backup cache.
3139 * This will be used to initialize the on-board processor's
3140 * data SRAM for a clean start when the runtime program first loads. */
3141 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a66926a2008-01-14 17:46:18 -08003142 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07003143
Zhu Yib481de92007-09-25 17:54:57 -07003144 for (i = 0; i < MAX_HW_RESTARTS; i++) {
3145
Zhu Yib481de92007-09-25 17:54:57 -07003146 /* load bootstrap state machine,
3147 * load bootstrap program into processor's memory,
3148 * prepare to load the "initialize" uCode */
Tomas Winkler57aab752008-04-14 21:16:03 -07003149 ret = priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003150
Tomas Winkler57aab752008-04-14 21:16:03 -07003151 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003152 IWL_ERR(priv, "Unable to set up bootstrap uCode: %d\n",
3153 ret);
Zhu Yib481de92007-09-25 17:54:57 -07003154 continue;
3155 }
3156
3157 /* start card; "initialize" will load runtime ucode */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003158 iwl_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003159
Tomas Winklere1623442009-01-27 14:27:56 -08003160 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003161
3162 return 0;
3163 }
3164
3165 set_bit(STATUS_EXIT_PENDING, &priv->status);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003166 __iwl_down(priv);
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08003167 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003168
3169 /* tried to restart and config the device for as long as our
3170 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08003171 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07003172 return -EIO;
3173}
3174
3175
3176/*****************************************************************************
3177 *
3178 * Workqueue callbacks
3179 *
3180 *****************************************************************************/
3181
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08003182static void iwl_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003183{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003184 struct iwl_priv *priv =
3185 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003186
3187 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3188 return;
3189
3190 mutex_lock(&priv->mutex);
Emmanuel Grumbachf3ccc082008-05-05 10:22:45 +08003191 priv->cfg->ops->lib->init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003192 mutex_unlock(&priv->mutex);
3193}
3194
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08003195static void iwl_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003196{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003197 struct iwl_priv *priv =
3198 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003199
3200 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3201 return;
3202
Mohamed Abbas258c44a2009-06-03 11:44:10 -07003203 /* enable dram interrupt */
3204 iwl_reset_ict(priv);
3205
Zhu Yib481de92007-09-25 17:54:57 -07003206 mutex_lock(&priv->mutex);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08003207 iwl_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003208 mutex_unlock(&priv->mutex);
3209}
3210
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08003211static void iwl_bg_run_time_calib_work(struct work_struct *work)
3212{
3213 struct iwl_priv *priv = container_of(work, struct iwl_priv,
3214 run_time_calib_work);
3215
3216 mutex_lock(&priv->mutex);
3217
3218 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
3219 test_bit(STATUS_SCANNING, &priv->status)) {
3220 mutex_unlock(&priv->mutex);
3221 return;
3222 }
3223
3224 if (priv->start_calib) {
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07003225 if (priv->cfg->bt_params &&
3226 priv->cfg->bt_params->bt_statistics) {
Wey-Yi Guy7980fba2010-07-14 08:08:57 -07003227 iwl_chain_noise_calibration(priv,
3228 (void *)&priv->_agn.statistics_bt);
3229 iwl_sensitivity_calibration(priv,
3230 (void *)&priv->_agn.statistics_bt);
3231 } else {
3232 iwl_chain_noise_calibration(priv,
3233 (void *)&priv->_agn.statistics);
3234 iwl_sensitivity_calibration(priv,
3235 (void *)&priv->_agn.statistics);
3236 }
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08003237 }
3238
3239 mutex_unlock(&priv->mutex);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08003240}
3241
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003242static void iwl_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003243{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003244 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07003245
3246 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3247 return;
3248
Johannes Berg19cc1082009-05-08 13:44:36 -07003249 if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
Johannes Berg8bd413e2010-08-23 10:46:40 +02003250 struct iwl_rxon_context *ctx;
Wey-Yi Guybee008b2010-08-23 07:57:04 -07003251 bool bt_sco, bt_full_concurrent;
3252 u8 bt_ci_compliance;
Johannes Berg511b0822010-08-23 07:57:01 -07003253 u8 bt_load;
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07003254 u8 bt_status;
Johannes Berg511b0822010-08-23 07:57:01 -07003255
Johannes Berg19cc1082009-05-08 13:44:36 -07003256 mutex_lock(&priv->mutex);
Johannes Berg8bd413e2010-08-23 10:46:40 +02003257 for_each_context(priv, ctx)
3258 ctx->vif = NULL;
Johannes Berg19cc1082009-05-08 13:44:36 -07003259 priv->is_open = 0;
Johannes Berg511b0822010-08-23 07:57:01 -07003260
3261 /*
3262 * __iwl_down() will clear the BT status variables,
3263 * which is correct, but when we restart we really
3264 * want to keep them so restore them afterwards.
3265 *
3266 * The restart process will later pick them up and
3267 * re-configure the hw when we reconfigure the BT
3268 * command.
3269 */
3270 bt_sco = priv->bt_sco_active;
Wey-Yi Guybee008b2010-08-23 07:57:04 -07003271 bt_full_concurrent = priv->bt_full_concurrent;
3272 bt_ci_compliance = priv->bt_ci_compliance;
Johannes Berg511b0822010-08-23 07:57:01 -07003273 bt_load = priv->bt_traffic_load;
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07003274 bt_status = priv->bt_status;
Johannes Berg511b0822010-08-23 07:57:01 -07003275
Johannes Berga1174132010-08-23 07:56:59 -07003276 __iwl_down(priv);
Johannes Berg511b0822010-08-23 07:57:01 -07003277
3278 priv->bt_sco_active = bt_sco;
Wey-Yi Guybee008b2010-08-23 07:57:04 -07003279 priv->bt_full_concurrent = bt_full_concurrent;
3280 priv->bt_ci_compliance = bt_ci_compliance;
Johannes Berg511b0822010-08-23 07:57:01 -07003281 priv->bt_traffic_load = bt_load;
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07003282 priv->bt_status = bt_status;
Johannes Berg511b0822010-08-23 07:57:01 -07003283
Johannes Berg19cc1082009-05-08 13:44:36 -07003284 mutex_unlock(&priv->mutex);
Johannes Berga1174132010-08-23 07:56:59 -07003285 iwl_cancel_deferred_work(priv);
Johannes Berg19cc1082009-05-08 13:44:36 -07003286 ieee80211_restart_hw(priv->hw);
3287 } else {
3288 iwl_down(priv);
Johannes Berg80676512010-01-21 06:07:17 -08003289
3290 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3291 return;
3292
3293 mutex_lock(&priv->mutex);
3294 __iwl_up(priv);
3295 mutex_unlock(&priv->mutex);
Johannes Berg19cc1082009-05-08 13:44:36 -07003296 }
Zhu Yib481de92007-09-25 17:54:57 -07003297}
3298
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003299static void iwl_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003300{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003301 struct iwl_priv *priv =
3302 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07003303
3304 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3305 return;
3306
3307 mutex_lock(&priv->mutex);
Wey-Yi Guy54b81552010-03-17 13:34:35 -07003308 iwlagn_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003309 mutex_unlock(&priv->mutex);
3310}
3311
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003312#define IWL_DELAY_NEXT_SCAN (HZ*2)
3313
Johannes Berg1dda6d22010-04-29 04:43:06 -07003314void iwl_post_associate(struct iwl_priv *priv, struct ieee80211_vif *vif)
Zhu Yib481de92007-09-25 17:54:57 -07003315{
Johannes Berg246ed352010-08-23 10:46:32 +02003316 struct iwl_rxon_context *ctx;
Zhu Yib481de92007-09-25 17:54:57 -07003317 struct ieee80211_conf *conf = NULL;
Tomas Winkler857485c2008-03-21 13:53:44 -07003318 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003319
Johannes Berg1dda6d22010-04-29 04:43:06 -07003320 if (!vif || !priv->is_open)
3321 return;
3322
Johannes Berg246ed352010-08-23 10:46:32 +02003323 ctx = iwl_rxon_ctx_from_vif(vif);
3324
Johannes Berg1dda6d22010-04-29 04:43:06 -07003325 if (vif->type == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003326 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07003327 return;
3328 }
3329
Zhu Yib481de92007-09-25 17:54:57 -07003330 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3331 return;
3332
Tomas Winkler2a421b92008-06-12 09:47:10 +08003333 iwl_scan_cancel_timeout(priv, 200);
mabbas052c4b92007-10-25 17:15:43 +08003334
Zhu Yib481de92007-09-25 17:54:57 -07003335 conf = ieee80211_get_hw_conf(priv->hw);
3336
Johannes Berg246ed352010-08-23 10:46:32 +02003337 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3338 iwlcore_commit_rxon(priv, ctx);
Zhu Yib481de92007-09-25 17:54:57 -07003339
Johannes Berg47313e32010-08-23 10:46:55 +02003340 ret = iwl_send_rxon_timing(priv, ctx);
Tomas Winkler857485c2008-03-21 13:53:44 -07003341 if (ret)
Johannes Berg8f2d3d22010-08-23 10:46:37 +02003342 IWL_WARN(priv, "RXON timing - "
Zhu Yib481de92007-09-25 17:54:57 -07003343 "Attempting to continue.\n");
3344
Johannes Berg246ed352010-08-23 10:46:32 +02003345 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003346
Emmanuel Grumbach42eb7c62008-09-17 10:10:05 +08003347 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03003348
Abhijeet Kolekar45823532009-04-08 11:26:44 -07003349 if (priv->cfg->ops->hcmd->set_rxon_chain)
Johannes Berg246ed352010-08-23 10:46:32 +02003350 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
Abhijeet Kolekar45823532009-04-08 11:26:44 -07003351
Johannes Berg246ed352010-08-23 10:46:32 +02003352 ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
Zhu Yib481de92007-09-25 17:54:57 -07003353
Tomas Winklere1623442009-01-27 14:27:56 -08003354 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
Johannes Berg1dda6d22010-04-29 04:43:06 -07003355 vif->bss_conf.aid, vif->bss_conf.beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -07003356
Johannes Bergc213d742010-05-06 12:21:40 -07003357 if (vif->bss_conf.use_short_preamble)
Johannes Berg246ed352010-08-23 10:46:32 +02003358 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003359 else
Johannes Berg246ed352010-08-23 10:46:32 +02003360 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003361
Johannes Berg246ed352010-08-23 10:46:32 +02003362 if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) {
Johannes Bergc213d742010-05-06 12:21:40 -07003363 if (vif->bss_conf.use_short_slot)
Johannes Berg246ed352010-08-23 10:46:32 +02003364 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003365 else
Johannes Berg246ed352010-08-23 10:46:32 +02003366 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003367 }
3368
Johannes Berg246ed352010-08-23 10:46:32 +02003369 iwlcore_commit_rxon(priv, ctx);
Zhu Yib481de92007-09-25 17:54:57 -07003370
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003371 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
Johannes Berg246ed352010-08-23 10:46:32 +02003372 vif->bss_conf.aid, ctx->active.bssid_addr);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003373
Johannes Berg1dda6d22010-04-29 04:43:06 -07003374 switch (vif->type) {
Johannes Berg05c914f2008-09-11 00:01:58 +02003375 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -07003376 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02003377 case NL80211_IFTYPE_ADHOC:
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003378 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003379 break;
Zhu Yib481de92007-09-25 17:54:57 -07003380 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08003381 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Johannes Berg1dda6d22010-04-29 04:43:06 -07003382 __func__, vif->type);
Zhu Yib481de92007-09-25 17:54:57 -07003383 break;
3384 }
3385
Grumbach, Emmanuel04816442008-09-03 11:26:53 +08003386 /* the chain noise calibration will enabled PM upon completion
3387 * If chain noise has already been run, then we need to enable
3388 * power management here */
3389 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
Johannes Berge312c242009-08-07 15:41:51 -07003390 iwl_power_update_mode(priv, false);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08003391
3392 /* Enable Rx differential gain and sensitivity calibrations */
3393 iwl_chain_noise_reset(priv);
3394 priv->start_calib = 1;
3395
Reinette Chatre508e32e2008-04-14 21:16:13 -07003396}
3397
Zhu Yib481de92007-09-25 17:54:57 -07003398/*****************************************************************************
3399 *
3400 * mac80211 entry point functions
3401 *
3402 *****************************************************************************/
3403
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08003404#define UCODE_READY_TIMEOUT (4 * HZ)
Zhu Yi5a66926a2008-01-14 17:46:18 -08003405
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07003406/*
3407 * Not a mac80211 entry point function, but it fits in with all the
3408 * other mac80211 functions grouped here.
3409 */
Johannes Bergdd7a2502010-04-28 23:33:10 -07003410static int iwl_mac_setup_register(struct iwl_priv *priv,
3411 struct iwlagn_ucode_capabilities *capa)
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07003412{
3413 int ret;
3414 struct ieee80211_hw *hw = priv->hw;
Johannes Bergd0fe4782010-08-23 10:46:58 +02003415 struct iwl_rxon_context *ctx;
3416
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07003417 hw->rate_control_algorithm = "iwl-agn-rs";
3418
3419 /* Tell mac80211 our characteristics */
3420 hw->flags = IEEE80211_HW_SIGNAL_DBM |
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07003421 IEEE80211_HW_AMPDU_AGGREGATION |
Johannes Berg2491fa42010-08-23 10:46:52 +02003422 IEEE80211_HW_NEED_DTIM_PERIOD |
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07003423 IEEE80211_HW_SPECTRUM_MGMT;
3424
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07003425 if (!priv->cfg->base_params->broken_powersave)
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07003426 hw->flags |= IEEE80211_HW_SUPPORTS_PS |
3427 IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
3428
Johannes Bergba37a3d2009-12-10 14:37:27 -08003429 if (priv->cfg->sku & IWL_SKU_N)
3430 hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
3431 IEEE80211_HW_SUPPORTS_STATIC_SMPS;
3432
Reinette Chatre8d9698b2009-10-16 14:25:55 -07003433 hw->sta_data_size = sizeof(struct iwl_station_priv);
Johannes Bergfd1af152010-04-30 11:30:43 -07003434 hw->vif_data_size = sizeof(struct iwl_vif_priv);
3435
Johannes Bergd0fe4782010-08-23 10:46:58 +02003436 for_each_context(priv, ctx) {
3437 hw->wiphy->interface_modes |= ctx->interface_modes;
3438 hw->wiphy->interface_modes |= ctx->exclusive_interface_modes;
3439 }
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07003440
Reinette Chatref6c8f152010-03-12 11:13:26 -08003441 hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
Johannes Berg5be83de2009-11-19 00:56:28 +01003442 WIPHY_FLAG_DISABLE_BEACON_HINTS;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07003443
3444 /*
3445 * For now, disable PS by default because it affects
3446 * RX performance significantly.
3447 */
Johannes Berg5be83de2009-11-19 00:56:28 +01003448 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07003449
Reinette Chatre1382c712010-02-25 10:02:19 -08003450 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07003451 /* we create the 802.11 header and a zero-length SSID element */
Johannes Bergdd7a2502010-04-28 23:33:10 -07003452 hw->wiphy->max_scan_ie_len = capa->max_probe_length - 24 - 2;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07003453
3454 /* Default value; 4 EDCA QOS priorities */
3455 hw->queues = 4;
3456
3457 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
3458
3459 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
3460 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
3461 &priv->bands[IEEE80211_BAND_2GHZ];
3462 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
3463 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
3464 &priv->bands[IEEE80211_BAND_5GHZ];
3465
3466 ret = ieee80211_register_hw(priv->hw);
3467 if (ret) {
3468 IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
3469 return ret;
3470 }
3471 priv->mac80211_registered = 1;
3472
3473 return 0;
3474}
3475
3476
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003477static int iwl_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003478{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003479 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003480 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003481
Tomas Winklere1623442009-01-27 14:27:56 -08003482 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003483
3484 /* we should be verifying the device is ready to be opened */
3485 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003486 ret = __iwl_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003487 mutex_unlock(&priv->mutex);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003488
Zhu Yie655b9f2008-01-24 02:19:38 -08003489 if (ret)
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003490 return ret;
Zhu Yie655b9f2008-01-24 02:19:38 -08003491
Tomas Winklerc1842d62008-08-04 16:00:43 +08003492 if (iwl_is_rfkill(priv))
3493 goto out;
3494
Tomas Winklere1623442009-01-27 14:27:56 -08003495 IWL_DEBUG_INFO(priv, "Start UP work done.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003496
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08003497 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
Zhu Yi5a66926a2008-01-14 17:46:18 -08003498 * mac80211 will not be run successfully. */
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08003499 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
3500 test_bit(STATUS_READY, &priv->status),
3501 UCODE_READY_TIMEOUT);
3502 if (!ret) {
3503 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003504 IWL_ERR(priv, "START_ALIVE timeout after %dms.\n",
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08003505 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003506 return -ETIMEDOUT;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003507 }
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08003508 }
Tomas Winkler0a078ff2008-06-30 17:23:26 +08003509
Johannes Berge932a602009-10-02 13:44:03 -07003510 iwl_led_start(priv);
3511
Tomas Winklerc1842d62008-08-04 16:00:43 +08003512out:
Tomas Winkler0a078ff2008-06-30 17:23:26 +08003513 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08003514 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003515 return 0;
3516}
3517
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003518static void iwl_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003519{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003520 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003521
Tomas Winklere1623442009-01-27 14:27:56 -08003522 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas948c1712007-10-25 17:15:45 +08003523
Johannes Berg19cc1082009-05-08 13:44:36 -07003524 if (!priv->is_open)
Zhu Yie655b9f2008-01-24 02:19:38 -08003525 return;
Zhu Yie655b9f2008-01-24 02:19:38 -08003526
Zhu Yib481de92007-09-25 17:54:57 -07003527 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003528
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003529 iwl_down(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003530
3531 flush_workqueue(priv->workqueue);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003532
Stanislaw Gruszka554d1d02010-12-23 12:38:21 +01003533 /* User space software may expect getting rfkill changes
3534 * even if interface is down */
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003535 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Stanislaw Gruszka554d1d02010-12-23 12:38:21 +01003536 iwl_enable_rfkill_int(priv);
Mohamed Abbas948c1712007-10-25 17:15:45 +08003537
Tomas Winklere1623442009-01-27 14:27:56 -08003538 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003539}
3540
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003541static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003542{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003543 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003544
Tomas Winklere1623442009-01-27 14:27:56 -08003545 IWL_DEBUG_MACDUMP(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003546
Tomas Winklere1623442009-01-27 14:27:56 -08003547 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02003548 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07003549
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -07003550 if (iwlagn_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07003551 dev_kfree_skb_any(skb);
3552
Tomas Winklere1623442009-01-27 14:27:56 -08003553 IWL_DEBUG_MACDUMP(priv, "leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08003554 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07003555}
3556
Johannes Berg1dda6d22010-04-29 04:43:06 -07003557void iwl_config_ap(struct iwl_priv *priv, struct ieee80211_vif *vif)
Zhu Yib481de92007-09-25 17:54:57 -07003558{
Johannes Berg246ed352010-08-23 10:46:32 +02003559 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
Tomas Winkler857485c2008-03-21 13:53:44 -07003560 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003561
Johannes Berg76d04812010-08-23 10:46:47 +02003562 lockdep_assert_held(&priv->mutex);
3563
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08003564 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07003565 return;
3566
3567 /* The following should be done only at AP bring up */
Johannes Berg246ed352010-08-23 10:46:32 +02003568 if (!iwl_is_associated_ctx(ctx)) {
Zhu Yib481de92007-09-25 17:54:57 -07003569
3570 /* RXON - unassoc (to set timing command) */
Johannes Berg246ed352010-08-23 10:46:32 +02003571 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3572 iwlcore_commit_rxon(priv, ctx);
Zhu Yib481de92007-09-25 17:54:57 -07003573
3574 /* RXON Timing */
Johannes Berg47313e32010-08-23 10:46:55 +02003575 ret = iwl_send_rxon_timing(priv, ctx);
Tomas Winkler857485c2008-03-21 13:53:44 -07003576 if (ret)
Johannes Berg8f2d3d22010-08-23 10:46:37 +02003577 IWL_WARN(priv, "RXON timing failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003578 "Attempting to continue.\n");
3579
Daniel C Halperinf513dff2009-11-13 11:56:34 -08003580 /* AP has all antennas */
3581 priv->chain_noise_data.active_chains =
3582 priv->hw_params.valid_rx_ant;
3583 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Abhijeet Kolekar45823532009-04-08 11:26:44 -07003584 if (priv->cfg->ops->hcmd->set_rxon_chain)
Johannes Berg246ed352010-08-23 10:46:32 +02003585 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
Zhu Yib481de92007-09-25 17:54:57 -07003586
Johannes Berg246ed352010-08-23 10:46:32 +02003587 ctx->staging.assoc_id = 0;
Johannes Berg1dda6d22010-04-29 04:43:06 -07003588
Johannes Bergc213d742010-05-06 12:21:40 -07003589 if (vif->bss_conf.use_short_preamble)
Johannes Berg246ed352010-08-23 10:46:32 +02003590 ctx->staging.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003591 RXON_FLG_SHORT_PREAMBLE_MSK;
3592 else
Johannes Berg246ed352010-08-23 10:46:32 +02003593 ctx->staging.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003594 ~RXON_FLG_SHORT_PREAMBLE_MSK;
3595
Johannes Berg246ed352010-08-23 10:46:32 +02003596 if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) {
Johannes Bergc213d742010-05-06 12:21:40 -07003597 if (vif->bss_conf.use_short_slot)
Johannes Berg246ed352010-08-23 10:46:32 +02003598 ctx->staging.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003599 RXON_FLG_SHORT_SLOT_MSK;
3600 else
Johannes Berg246ed352010-08-23 10:46:32 +02003601 ctx->staging.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003602 ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003603 }
Johannes Berg08abc532010-08-23 10:46:53 +02003604 /* need to send beacon cmd before committing assoc RXON! */
3605 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003606 /* restore RXON assoc */
Johannes Berg246ed352010-08-23 10:46:32 +02003607 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
3608 iwlcore_commit_rxon(priv, ctx);
Zhu Yie1493de2007-09-27 11:27:32 +08003609 }
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003610 iwl_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003611
3612 /* FIXME - we need to add code here to detect a totally new
3613 * configuration, reset the AP, unassoc, rxon timing, assoc,
3614 * clear sta table, add BCAST sta... */
3615}
3616
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003617static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw,
Johannes Bergb3fbdcf2010-01-21 11:40:47 +01003618 struct ieee80211_vif *vif,
3619 struct ieee80211_key_conf *keyconf,
3620 struct ieee80211_sta *sta,
3621 u32 iv32, u16 *phase1key)
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003622{
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003623
Tomas Winkler9f586712008-11-12 13:14:05 -08003624 struct iwl_priv *priv = hw->priv;
Johannes Berga194e322010-08-27 08:53:46 -07003625 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
3626
Tomas Winklere1623442009-01-27 14:27:56 -08003627 IWL_DEBUG_MAC80211(priv, "enter\n");
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003628
Johannes Berga194e322010-08-27 08:53:46 -07003629 iwl_update_tkip_key(priv, vif_priv->ctx, keyconf, sta,
Johannes Bergb3fbdcf2010-01-21 11:40:47 +01003630 iv32, phase1key);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003631
Tomas Winklere1623442009-01-27 14:27:56 -08003632 IWL_DEBUG_MAC80211(priv, "leave\n");
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003633}
3634
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003635static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01003636 struct ieee80211_vif *vif,
3637 struct ieee80211_sta *sta,
Zhu Yib481de92007-09-25 17:54:57 -07003638 struct ieee80211_key_conf *key)
3639{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003640 struct iwl_priv *priv = hw->priv;
Johannes Berga194e322010-08-27 08:53:46 -07003641 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
Johannes Bergc10afb62010-08-23 10:46:43 +02003642 struct iwl_rxon_context *ctx = vif_priv->ctx;
Winkler, Tomas42986792009-01-19 15:30:22 -08003643 int ret;
3644 u8 sta_id;
3645 bool is_default_wep_key = false;
Zhu Yib481de92007-09-25 17:54:57 -07003646
Tomas Winklere1623442009-01-27 14:27:56 -08003647 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003648
Tomas Winkler90e8e422009-06-19 13:52:42 -07003649 if (priv->cfg->mod_params->sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08003650 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07003651 return -EOPNOTSUPP;
3652 }
Zhu Yib481de92007-09-25 17:54:57 -07003653
Johannes Berga194e322010-08-27 08:53:46 -07003654 sta_id = iwl_sta_id_or_broadcast(priv, vif_priv->ctx, sta);
Johannes Berg0af8bca2010-04-30 14:08:00 -07003655 if (sta_id == IWL_INVALID_STATION)
3656 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003657
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003658 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08003659 iwl_scan_cancel_timeout(priv, 100);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003660
Johannes Berga90178fa2010-03-30 02:44:16 -07003661 /*
3662 * If we are getting WEP group key and we didn't receive any key mapping
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003663 * so far, we are in legacy wep mode (group key only), otherwise we are
3664 * in 1X mode.
Johannes Berga90178fa2010-03-30 02:44:16 -07003665 * In legacy wep mode, we use another host command to the uCode.
3666 */
Johannes Berg97359d12010-08-10 09:46:38 +02003667 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3668 key->cipher == WLAN_CIPHER_SUITE_WEP104) &&
Johannes Berg54c80672010-08-18 09:35:21 -07003669 !sta) {
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003670 if (cmd == SET_KEY)
Johannes Bergc10afb62010-08-23 10:46:43 +02003671 is_default_wep_key = !ctx->key_mapping_keys;
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003672 else
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +08003673 is_default_wep_key =
3674 (key->hw_key_idx == HW_KEY_DEFAULT);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003675 }
mabbas052c4b92007-10-25 17:15:43 +08003676
Zhu Yib481de92007-09-25 17:54:57 -07003677 switch (cmd) {
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003678 case SET_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003679 if (is_default_wep_key)
Johannes Berg2995baf2010-08-23 10:46:42 +02003680 ret = iwl_set_default_wep_key(priv, vif_priv->ctx, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003681 else
Johannes Berga194e322010-08-27 08:53:46 -07003682 ret = iwl_set_dynamic_key(priv, vif_priv->ctx,
3683 key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003684
Tomas Winklere1623442009-01-27 14:27:56 -08003685 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003686 break;
3687 case DISABLE_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003688 if (is_default_wep_key)
Johannes Bergc10afb62010-08-23 10:46:43 +02003689 ret = iwl_remove_default_wep_key(priv, ctx, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003690 else
Johannes Bergc10afb62010-08-23 10:46:43 +02003691 ret = iwl_remove_dynamic_key(priv, ctx, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003692
Tomas Winklere1623442009-01-27 14:27:56 -08003693 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003694 break;
3695 default:
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003696 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003697 }
3698
Johannes Berg72e15d72010-02-19 11:42:32 -08003699 mutex_unlock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08003700 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003701
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003702 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003703}
3704
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003705static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
Johannes Bergc951ad32009-11-16 12:00:38 +01003706 struct ieee80211_vif *vif,
Johannes Berg832f47e2010-04-29 04:43:07 -07003707 enum ieee80211_ampdu_mlme_action action,
3708 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
Tomas Winklerd783b062008-07-18 13:53:02 +08003709{
3710 struct iwl_priv *priv = hw->priv;
Johannes Berg4620fef2010-06-16 03:30:27 -07003711 int ret = -EINVAL;
Tomas Winklerd783b062008-07-18 13:53:02 +08003712
Tomas Winklere1623442009-01-27 14:27:56 -08003713 IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
Johannes Berge1749612008-10-27 15:59:26 -07003714 sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08003715
3716 if (!(priv->cfg->sku & IWL_SKU_N))
3717 return -EACCES;
3718
Johannes Berg4620fef2010-06-16 03:30:27 -07003719 mutex_lock(&priv->mutex);
3720
Tomas Winklerd783b062008-07-18 13:53:02 +08003721 switch (action) {
3722 case IEEE80211_AMPDU_RX_START:
Tomas Winklere1623442009-01-27 14:27:56 -08003723 IWL_DEBUG_HT(priv, "start Rx\n");
Johannes Berg4620fef2010-06-16 03:30:27 -07003724 ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn);
3725 break;
Tomas Winklerd783b062008-07-18 13:53:02 +08003726 case IEEE80211_AMPDU_RX_STOP:
Tomas Winklere1623442009-01-27 14:27:56 -08003727 IWL_DEBUG_HT(priv, "stop Rx\n");
Johannes Berg619753f2010-04-30 11:30:46 -07003728 ret = iwl_sta_rx_agg_stop(priv, sta, tid);
Wey-Yi Guy5c2207c2009-03-17 21:51:43 -07003729 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Johannes Berg4620fef2010-06-16 03:30:27 -07003730 ret = 0;
3731 break;
Tomas Winklerd783b062008-07-18 13:53:02 +08003732 case IEEE80211_AMPDU_TX_START:
Tomas Winklere1623442009-01-27 14:27:56 -08003733 IWL_DEBUG_HT(priv, "start Tx\n");
Johannes Berg619753f2010-04-30 11:30:46 -07003734 ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn);
Wey-Yi Guyd5a0ffa2010-03-04 13:38:59 -08003735 if (ret == 0) {
3736 priv->_agn.agg_tids_count++;
3737 IWL_DEBUG_HT(priv, "priv->_agn.agg_tids_count = %u\n",
3738 priv->_agn.agg_tids_count);
3739 }
Johannes Berg4620fef2010-06-16 03:30:27 -07003740 break;
Tomas Winklerd783b062008-07-18 13:53:02 +08003741 case IEEE80211_AMPDU_TX_STOP:
Tomas Winklere1623442009-01-27 14:27:56 -08003742 IWL_DEBUG_HT(priv, "stop Tx\n");
Johannes Berg619753f2010-04-30 11:30:46 -07003743 ret = iwlagn_tx_agg_stop(priv, vif, sta, tid);
Wey-Yi Guyd5a0ffa2010-03-04 13:38:59 -08003744 if ((ret == 0) && (priv->_agn.agg_tids_count > 0)) {
3745 priv->_agn.agg_tids_count--;
3746 IWL_DEBUG_HT(priv, "priv->_agn.agg_tids_count = %u\n",
3747 priv->_agn.agg_tids_count);
3748 }
Wey-Yi Guy5c2207c2009-03-17 21:51:43 -07003749 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Johannes Berg4620fef2010-06-16 03:30:27 -07003750 ret = 0;
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07003751 if (priv->cfg->ht_params &&
3752 priv->cfg->ht_params->use_rts_for_aggregation) {
Johannes Berg94597ab2010-08-09 10:57:02 -07003753 struct iwl_station_priv *sta_priv =
3754 (void *) sta->drv_priv;
3755 /*
3756 * switch off RTS/CTS if it was previously enabled
3757 */
3758
3759 sta_priv->lq_sta.lq.general_params.flags &=
3760 ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
Johannes Berg7e6a5882010-08-23 10:46:46 +02003761 iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
3762 &sta_priv->lq_sta.lq, CMD_ASYNC, false);
Johannes Berg94597ab2010-08-09 10:57:02 -07003763 }
Johannes Berg4620fef2010-06-16 03:30:27 -07003764 break;
Wey-Yi Guyf0527972010-01-08 10:04:41 -08003765 case IEEE80211_AMPDU_TX_OPERATIONAL:
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07003766 if (priv->cfg->ht_params &&
3767 priv->cfg->ht_params->use_rts_for_aggregation) {
Johannes Berg94597ab2010-08-09 10:57:02 -07003768 struct iwl_station_priv *sta_priv =
3769 (void *) sta->drv_priv;
3770
Wey-Yi Guycfecc6b2010-06-18 11:33:15 -07003771 /*
3772 * switch to RTS/CTS if it is the prefer protection
3773 * method for HT traffic
3774 */
Johannes Berg94597ab2010-08-09 10:57:02 -07003775
3776 sta_priv->lq_sta.lq.general_params.flags |=
3777 LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
Johannes Berg7e6a5882010-08-23 10:46:46 +02003778 iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
3779 &sta_priv->lq_sta.lq, CMD_ASYNC, false);
Wey-Yi Guycfecc6b2010-06-18 11:33:15 -07003780 }
3781 ret = 0;
Tomas Winklerd783b062008-07-18 13:53:02 +08003782 break;
3783 }
Johannes Berg4620fef2010-06-16 03:30:27 -07003784 mutex_unlock(&priv->mutex);
3785
3786 return ret;
Tomas Winklerd783b062008-07-18 13:53:02 +08003787}
Tomas Winkler9f586712008-11-12 13:14:05 -08003788
Johannes Berg6ab10ff2009-11-13 11:56:37 -08003789static void iwl_mac_sta_notify(struct ieee80211_hw *hw,
3790 struct ieee80211_vif *vif,
3791 enum sta_notify_cmd cmd,
3792 struct ieee80211_sta *sta)
3793{
3794 struct iwl_priv *priv = hw->priv;
3795 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
3796 int sta_id;
3797
Johannes Berg6ab10ff2009-11-13 11:56:37 -08003798 switch (cmd) {
Johannes Berg6ab10ff2009-11-13 11:56:37 -08003799 case STA_NOTIFY_SLEEP:
3800 WARN_ON(!sta_priv->client);
3801 sta_priv->asleep = true;
3802 if (atomic_read(&sta_priv->pending_frames) > 0)
3803 ieee80211_sta_block_awake(hw, sta, true);
3804 break;
3805 case STA_NOTIFY_AWAKE:
3806 WARN_ON(!sta_priv->client);
Daniel Halperin49dcc812010-01-19 10:22:19 -08003807 if (!sta_priv->asleep)
3808 break;
Johannes Berg6ab10ff2009-11-13 11:56:37 -08003809 sta_priv->asleep = false;
Johannes Berg2a87c262010-04-30 11:30:45 -07003810 sta_id = iwl_sta_id(sta);
Johannes Berg6ab10ff2009-11-13 11:56:37 -08003811 if (sta_id != IWL_INVALID_STATION)
3812 iwl_sta_modify_ps_wake(priv, sta_id);
3813 break;
3814 default:
3815 break;
3816 }
3817}
3818
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003819static int iwlagn_mac_sta_add(struct ieee80211_hw *hw,
3820 struct ieee80211_vif *vif,
3821 struct ieee80211_sta *sta)
3822{
3823 struct iwl_priv *priv = hw->priv;
3824 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
Johannes Berga194e322010-08-27 08:53:46 -07003825 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
Johannes Bergeafdfbd32010-04-29 04:43:04 -07003826 bool is_ap = vif->type == NL80211_IFTYPE_STATION;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003827 int ret;
3828 u8 sta_id;
3829
3830 IWL_DEBUG_INFO(priv, "received request to add station %pM\n",
3831 sta->addr);
Reinette Chatreda5ae1c2010-05-28 09:28:39 -07003832 mutex_lock(&priv->mutex);
3833 IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
3834 sta->addr);
3835 sta_priv->common.sta_id = IWL_INVALID_STATION;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003836
3837 atomic_set(&sta_priv->pending_frames, 0);
3838 if (vif->type == NL80211_IFTYPE_AP)
3839 sta_priv->client = true;
3840
Johannes Berga194e322010-08-27 08:53:46 -07003841 ret = iwl_add_station_common(priv, vif_priv->ctx, sta->addr,
Johannes Berg238d7812010-08-23 10:46:45 +02003842 is_ap, sta, &sta_id);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003843 if (ret) {
3844 IWL_ERR(priv, "Unable to add station %pM (%d)\n",
3845 sta->addr, ret);
3846 /* Should we return success if return code is EEXIST ? */
Reinette Chatreda5ae1c2010-05-28 09:28:39 -07003847 mutex_unlock(&priv->mutex);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003848 return ret;
3849 }
3850
Johannes Bergfd1af152010-04-30 11:30:43 -07003851 sta_priv->common.sta_id = sta_id;
3852
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003853 /* Initialize rate scaling */
Frans Pop91dd6c22010-03-24 14:19:58 -07003854 IWL_DEBUG_INFO(priv, "Initializing rate scaling for station %pM\n",
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003855 sta->addr);
3856 iwl_rs_rate_init(priv, sta, sta_id);
Reinette Chatreda5ae1c2010-05-28 09:28:39 -07003857 mutex_unlock(&priv->mutex);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003858
Johannes Bergfd1af152010-04-30 11:30:43 -07003859 return 0;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003860}
3861
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003862static void iwl_mac_channel_switch(struct ieee80211_hw *hw,
3863 struct ieee80211_channel_switch *ch_switch)
3864{
3865 struct iwl_priv *priv = hw->priv;
3866 const struct iwl_channel_info *ch_info;
3867 struct ieee80211_conf *conf = &hw->conf;
Shanyu Zhaoaa2dc6b2010-07-28 13:40:39 -07003868 struct ieee80211_channel *channel = ch_switch->channel;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003869 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
Johannes Berg246ed352010-08-23 10:46:32 +02003870 /*
3871 * MULTI-FIXME
3872 * When we add support for multiple interfaces, we need to
3873 * revisit this. The channel switch command in the device
3874 * only affects the BSS context, but what does that really
3875 * mean? And what if we get a CSA on the second interface?
3876 * This needs a lot of work.
3877 */
3878 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003879 u16 ch;
3880 unsigned long flags = 0;
3881
3882 IWL_DEBUG_MAC80211(priv, "enter\n");
3883
3884 if (iwl_is_rfkill(priv))
3885 goto out_exit;
3886
3887 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
3888 test_bit(STATUS_SCANNING, &priv->status))
3889 goto out_exit;
3890
Johannes Berg246ed352010-08-23 10:46:32 +02003891 if (!iwl_is_associated_ctx(ctx))
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003892 goto out_exit;
3893
3894 /* channel switch in progress */
3895 if (priv->switch_rxon.switch_in_progress == true)
3896 goto out_exit;
3897
3898 mutex_lock(&priv->mutex);
3899 if (priv->cfg->ops->lib->set_channel_switch) {
3900
Shanyu Zhaoaa2dc6b2010-07-28 13:40:39 -07003901 ch = channel->hw_value;
Johannes Berg246ed352010-08-23 10:46:32 +02003902 if (le16_to_cpu(ctx->active.channel) != ch) {
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003903 ch_info = iwl_get_channel_info(priv,
Shanyu Zhaoaa2dc6b2010-07-28 13:40:39 -07003904 channel->band,
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003905 ch);
3906 if (!is_channel_valid(ch_info)) {
3907 IWL_DEBUG_MAC80211(priv, "invalid channel\n");
3908 goto out;
3909 }
3910 spin_lock_irqsave(&priv->lock, flags);
3911
3912 priv->current_ht_config.smps = conf->smps_mode;
3913
3914 /* Configure HT40 channels */
Johannes Berg7e6a5882010-08-23 10:46:46 +02003915 ctx->ht.enabled = conf_is_ht(conf);
3916 if (ctx->ht.enabled) {
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003917 if (conf_is_ht40_minus(conf)) {
Johannes Berg7e6a5882010-08-23 10:46:46 +02003918 ctx->ht.extension_chan_offset =
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003919 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
Johannes Berg7e6a5882010-08-23 10:46:46 +02003920 ctx->ht.is_40mhz = true;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003921 } else if (conf_is_ht40_plus(conf)) {
Johannes Berg7e6a5882010-08-23 10:46:46 +02003922 ctx->ht.extension_chan_offset =
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003923 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
Johannes Berg7e6a5882010-08-23 10:46:46 +02003924 ctx->ht.is_40mhz = true;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003925 } else {
Johannes Berg7e6a5882010-08-23 10:46:46 +02003926 ctx->ht.extension_chan_offset =
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003927 IEEE80211_HT_PARAM_CHA_SEC_NONE;
Johannes Berg7e6a5882010-08-23 10:46:46 +02003928 ctx->ht.is_40mhz = false;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003929 }
3930 } else
Johannes Berg7e6a5882010-08-23 10:46:46 +02003931 ctx->ht.is_40mhz = false;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003932
Johannes Berg246ed352010-08-23 10:46:32 +02003933 if ((le16_to_cpu(ctx->staging.channel) != ch))
3934 ctx->staging.flags = 0;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003935
Johannes Berg246ed352010-08-23 10:46:32 +02003936 iwl_set_rxon_channel(priv, channel, ctx);
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003937 iwl_set_rxon_ht(priv, ht_conf);
Johannes Berg246ed352010-08-23 10:46:32 +02003938 iwl_set_flags_for_band(priv, ctx, channel->band,
Johannes Berg8bd413e2010-08-23 10:46:40 +02003939 ctx->vif);
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003940 spin_unlock_irqrestore(&priv->lock, flags);
3941
3942 iwl_set_rate(priv);
3943 /*
3944 * at this point, staging_rxon has the
3945 * configuration for channel switch
3946 */
3947 if (priv->cfg->ops->lib->set_channel_switch(priv,
3948 ch_switch))
3949 priv->switch_rxon.switch_in_progress = false;
3950 }
3951 }
3952out:
3953 mutex_unlock(&priv->mutex);
3954out_exit:
3955 if (!priv->switch_rxon.switch_in_progress)
Johannes Berg8bd413e2010-08-23 10:46:40 +02003956 ieee80211_chswitch_done(ctx->vif, false);
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003957 IWL_DEBUG_MAC80211(priv, "leave\n");
3958}
3959
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02003960static void iwlagn_configure_filter(struct ieee80211_hw *hw,
3961 unsigned int changed_flags,
3962 unsigned int *total_flags,
3963 u64 multicast)
3964{
3965 struct iwl_priv *priv = hw->priv;
3966 __le32 filter_or = 0, filter_nand = 0;
Johannes Berg246ed352010-08-23 10:46:32 +02003967 struct iwl_rxon_context *ctx;
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02003968
3969#define CHK(test, flag) do { \
3970 if (*total_flags & (test)) \
3971 filter_or |= (flag); \
3972 else \
3973 filter_nand |= (flag); \
3974 } while (0)
3975
3976 IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
3977 changed_flags, *total_flags);
3978
3979 CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
3980 CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK);
3981 CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
3982
3983#undef CHK
3984
3985 mutex_lock(&priv->mutex);
3986
Johannes Berg246ed352010-08-23 10:46:32 +02003987 for_each_context(priv, ctx) {
3988 ctx->staging.filter_flags &= ~filter_nand;
3989 ctx->staging.filter_flags |= filter_or;
3990 iwlcore_commit_rxon(priv, ctx);
3991 }
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02003992
3993 mutex_unlock(&priv->mutex);
3994
3995 /*
3996 * Receiving all multicast frames is always enabled by the
3997 * default flags setup in iwl_connection_init_rx_config()
3998 * since we currently do not support programming multicast
3999 * filters into the device.
4000 */
4001 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
4002 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
4003}
4004
Wey-Yi Guy716c74b2010-06-24 13:22:36 -07004005static void iwl_mac_flush(struct ieee80211_hw *hw, bool drop)
4006{
4007 struct iwl_priv *priv = hw->priv;
4008
4009 mutex_lock(&priv->mutex);
4010 IWL_DEBUG_MAC80211(priv, "enter\n");
4011
4012 /* do not support "flush" */
4013 if (!priv->cfg->ops->lib->txfifo_flush)
4014 goto done;
4015
4016 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
4017 IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n");
4018 goto done;
4019 }
4020 if (iwl_is_rfkill(priv)) {
4021 IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n");
4022 goto done;
4023 }
4024
4025 /*
4026 * mac80211 will not push any more frames for transmit
4027 * until the flush is completed
4028 */
4029 if (drop) {
4030 IWL_DEBUG_MAC80211(priv, "send flush command\n");
4031 if (priv->cfg->ops->lib->txfifo_flush(priv, IWL_DROP_ALL)) {
4032 IWL_ERR(priv, "flush request fail\n");
4033 goto done;
4034 }
4035 }
4036 IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n");
4037 iwlagn_wait_tx_queue_empty(priv);
4038done:
4039 mutex_unlock(&priv->mutex);
4040 IWL_DEBUG_MAC80211(priv, "leave\n");
4041}
4042
Zhu Yib481de92007-09-25 17:54:57 -07004043/*****************************************************************************
4044 *
Zhu Yib481de92007-09-25 17:54:57 -07004045 * driver setup and teardown
4046 *
4047 *****************************************************************************/
4048
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004049static void iwl_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004050{
Reinette Chatred21050c2009-02-13 11:51:18 -08004051 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07004052
4053 init_waitqueue_head(&priv->wait_command_queue);
4054
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004055 INIT_WORK(&priv->restart, iwl_bg_restart);
4056 INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004057 INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08004058 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
Wey-Yi Guy65550632010-06-24 13:18:35 -07004059 INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
Wey-Yi Guybee008b2010-08-23 07:57:04 -07004060 INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
Wey-Yi Guyfbba9412010-08-23 07:57:10 -07004061 INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08004062 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
4063 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
Tomas Winkler2a421b92008-06-12 09:47:10 +08004064
Tomas Winkler2a421b92008-06-12 09:47:10 +08004065 iwl_setup_scan_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004066
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004067 if (priv->cfg->ops->lib->setup_deferred_work)
4068 priv->cfg->ops->lib->setup_deferred_work(priv);
4069
4070 init_timer(&priv->statistics_periodic);
4071 priv->statistics_periodic.data = (unsigned long)priv;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004072 priv->statistics_periodic.function = iwl_bg_statistics_periodic;
Zhu Yib481de92007-09-25 17:54:57 -07004073
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08004074 init_timer(&priv->ucode_trace);
4075 priv->ucode_trace.data = (unsigned long)priv;
4076 priv->ucode_trace.function = iwl_bg_ucode_trace;
4077
Wey-Yi Guyb74e31a2010-03-01 17:23:50 -08004078 if (priv->cfg->ops->lib->recover_from_tx_stall) {
4079 init_timer(&priv->monitor_recover);
4080 priv->monitor_recover.data = (unsigned long)priv;
4081 priv->monitor_recover.function =
4082 priv->cfg->ops->lib->recover_from_tx_stall;
4083 }
4084
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07004085 if (!priv->cfg->base_params->use_isr_legacy)
Mohamed Abbasef850d72009-05-22 11:01:50 -07004086 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
4087 iwl_irq_tasklet, (unsigned long)priv);
4088 else
4089 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
4090 iwl_irq_tasklet_legacy, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07004091}
4092
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004093static void iwl_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004094{
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004095 if (priv->cfg->ops->lib->cancel_deferred_work)
4096 priv->cfg->ops->lib->cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004097
Joonwoo Park3ae6a052007-11-29 10:43:16 +09004098 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004099 cancel_delayed_work(&priv->alive_start);
Wey-Yi Guy815e6292010-06-03 10:14:01 -07004100 cancel_work_sync(&priv->run_time_calib_work);
Zhu Yib481de92007-09-25 17:54:57 -07004101 cancel_work_sync(&priv->beacon_update);
Stanislaw Gruszkae7e16b92010-09-13 14:46:41 +02004102
4103 iwl_cancel_scan_deferred_work(priv);
4104
Wey-Yi Guybee008b2010-08-23 07:57:04 -07004105 cancel_work_sync(&priv->bt_full_concurrency);
Wey-Yi Guyfbba9412010-08-23 07:57:10 -07004106 cancel_work_sync(&priv->bt_runtime_config);
Stanislaw Gruszkae7e16b92010-09-13 14:46:41 +02004107
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004108 del_timer_sync(&priv->statistics_periodic);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08004109 del_timer_sync(&priv->ucode_trace);
Zhu Yib481de92007-09-25 17:54:57 -07004110}
4111
Reinette Chatre89f186a2009-10-30 14:36:11 -07004112static void iwl_init_hw_rates(struct iwl_priv *priv,
4113 struct ieee80211_rate *rates)
4114{
4115 int i;
4116
4117 for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
4118 rates[i].bitrate = iwl_rates[i].ieee * 5;
4119 rates[i].hw_value = i; /* Rate scaling will work on indexes */
4120 rates[i].hw_value_short = i;
4121 rates[i].flags = 0;
4122 if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
4123 /*
4124 * If CCK != 1M then set short preamble rate flag.
4125 */
4126 rates[i].flags |=
4127 (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
4128 0 : IEEE80211_RATE_SHORT_PREAMBLE;
4129 }
4130 }
4131}
4132
4133static int iwl_init_drv(struct iwl_priv *priv)
4134{
4135 int ret;
4136
Reinette Chatre89f186a2009-10-30 14:36:11 -07004137 spin_lock_init(&priv->sta_lock);
4138 spin_lock_init(&priv->hcmd_lock);
4139
4140 INIT_LIST_HEAD(&priv->free_frames);
4141
4142 mutex_init(&priv->mutex);
Reinette Chatred2dfe6d2010-02-18 22:03:04 -08004143 mutex_init(&priv->sync_cmd_mutex);
Reinette Chatre89f186a2009-10-30 14:36:11 -07004144
Reinette Chatre89f186a2009-10-30 14:36:11 -07004145 priv->ieee_channels = NULL;
4146 priv->ieee_rates = NULL;
4147 priv->band = IEEE80211_BAND_2GHZ;
4148
4149 priv->iw_mode = NL80211_IFTYPE_STATION;
Johannes Bergba37a3d2009-12-10 14:37:27 -08004150 priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
Wey-Yi Guya13d2762010-01-22 14:22:42 -08004151 priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
Wey-Yi Guyd5a0ffa2010-03-04 13:38:59 -08004152 priv->_agn.agg_tids_count = 0;
Reinette Chatre89f186a2009-10-30 14:36:11 -07004153
Wey-Yi Guy8a472da2010-02-18 22:03:06 -08004154 /* initialize force reset */
4155 priv->force_reset[IWL_RF_RESET].reset_duration =
4156 IWL_DELAY_NEXT_FORCE_RF_RESET;
4157 priv->force_reset[IWL_FW_RESET].reset_duration =
4158 IWL_DELAY_NEXT_FORCE_FW_RELOAD;
Reinette Chatre89f186a2009-10-30 14:36:11 -07004159
4160 /* Choose which receivers/antennas to use */
4161 if (priv->cfg->ops->hcmd->set_rxon_chain)
Johannes Berg246ed352010-08-23 10:46:32 +02004162 priv->cfg->ops->hcmd->set_rxon_chain(priv,
4163 &priv->contexts[IWL_RXON_CTX_BSS]);
Reinette Chatre89f186a2009-10-30 14:36:11 -07004164
4165 iwl_init_scan_params(priv);
4166
Wey-Yi Guy22bf59a2010-08-23 07:57:11 -07004167 /* init bt coex */
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07004168 if (priv->cfg->bt_params &&
4169 priv->cfg->bt_params->advanced_bt_coexist) {
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07004170 priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
4171 priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
4172 priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
Wey-Yi Guy22bf59a2010-08-23 07:57:11 -07004173 priv->bt_on_thresh = BT_ON_THRESHOLD_DEF;
4174 priv->bt_duration = BT_DURATION_LIMIT_DEF;
4175 priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
4176 priv->dynamic_agg_thresh = BT_AGG_THRESHOLD_DEF;
4177 }
4178
Reinette Chatre89f186a2009-10-30 14:36:11 -07004179 /* Set the tx_power_user_lmt to the lowest power level
4180 * this value will get overwritten by channel max power avg
4181 * from eeprom */
Wey-Yi Guyb744cb72010-03-23 11:37:59 -07004182 priv->tx_power_user_lmt = IWLAGN_TX_POWER_TARGET_POWER_MIN;
Reinette Chatre89f186a2009-10-30 14:36:11 -07004183
4184 ret = iwl_init_channel_map(priv);
4185 if (ret) {
4186 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
4187 goto err;
4188 }
4189
4190 ret = iwlcore_init_geos(priv);
4191 if (ret) {
4192 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
4193 goto err_free_channel_map;
4194 }
4195 iwl_init_hw_rates(priv, priv->ieee_rates);
4196
4197 return 0;
4198
4199err_free_channel_map:
4200 iwl_free_channel_map(priv);
4201err:
4202 return ret;
4203}
4204
4205static void iwl_uninit_drv(struct iwl_priv *priv)
4206{
4207 iwl_calib_free_results(priv);
4208 iwlcore_free_geos(priv);
4209 iwl_free_channel_map(priv);
Johannes Berg811ecc92010-04-06 04:12:41 -07004210 kfree(priv->scan_cmd);
Reinette Chatre89f186a2009-10-30 14:36:11 -07004211}
4212
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004213static struct ieee80211_ops iwl_hw_ops = {
4214 .tx = iwl_mac_tx,
4215 .start = iwl_mac_start,
4216 .stop = iwl_mac_stop,
4217 .add_interface = iwl_mac_add_interface,
4218 .remove_interface = iwl_mac_remove_interface,
4219 .config = iwl_mac_config,
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02004220 .configure_filter = iwlagn_configure_filter,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004221 .set_key = iwl_mac_set_key,
4222 .update_tkip_key = iwl_mac_update_tkip_key,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004223 .conf_tx = iwl_mac_conf_tx,
4224 .reset_tsf = iwl_mac_reset_tsf,
4225 .bss_info_changed = iwl_bss_info_changed,
4226 .ampdu_action = iwl_mac_ampdu_action,
Johannes Berg6ab10ff2009-11-13 11:56:37 -08004227 .hw_scan = iwl_mac_hw_scan,
4228 .sta_notify = iwl_mac_sta_notify,
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08004229 .sta_add = iwlagn_mac_sta_add,
4230 .sta_remove = iwl_mac_sta_remove,
Wey-Yi Guy79d07322010-05-06 08:54:11 -07004231 .channel_switch = iwl_mac_channel_switch,
Wey-Yi Guy716c74b2010-06-24 13:22:36 -07004232 .flush = iwl_mac_flush,
Johannes Berga85d7cc2010-07-31 08:34:10 -07004233 .tx_last_beacon = iwl_mac_tx_last_beacon,
Zhu Yib481de92007-09-25 17:54:57 -07004234};
4235
Wey-Yi Guy3867fe02010-07-31 08:34:05 -07004236static void iwl_hw_detect(struct iwl_priv *priv)
4237{
4238 priv->hw_rev = _iwl_read32(priv, CSR_HW_REV);
4239 priv->hw_wa_rev = _iwl_read32(priv, CSR_HW_REV_WA_REG);
4240 pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &priv->rev_id);
Wey-Yi Guy49ded762010-07-31 08:34:06 -07004241 IWL_DEBUG_INFO(priv, "HW Revision ID = 0x%X\n", priv->rev_id);
Wey-Yi Guy3867fe02010-07-31 08:34:05 -07004242}
4243
Wey-Yi Guy07d4f1a2010-07-31 08:34:08 -07004244static int iwl_set_hw_params(struct iwl_priv *priv)
4245{
4246 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
4247 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
4248 if (priv->cfg->mod_params->amsdu_size_8K)
4249 priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_8K);
4250 else
4251 priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_4K);
4252
4253 priv->hw_params.max_beacon_itrvl = IWL_MAX_UCODE_BEACON_INTERVAL;
4254
4255 if (priv->cfg->mod_params->disable_11n)
4256 priv->cfg->sku &= ~IWL_SKU_N;
4257
4258 /* Device-specific setup */
4259 return priv->cfg->ops->lib->set_hw_params(priv);
4260}
4261
Johannes Berge72f3682010-08-23 10:46:51 +02004262static const u8 iwlagn_bss_ac_to_fifo[] = {
4263 IWL_TX_FIFO_VO,
4264 IWL_TX_FIFO_VI,
4265 IWL_TX_FIFO_BE,
4266 IWL_TX_FIFO_BK,
4267};
4268
4269static const u8 iwlagn_bss_ac_to_queue[] = {
4270 0, 1, 2, 3,
4271};
4272
4273static const u8 iwlagn_pan_ac_to_fifo[] = {
4274 IWL_TX_FIFO_VO_IPAN,
4275 IWL_TX_FIFO_VI_IPAN,
4276 IWL_TX_FIFO_BE_IPAN,
4277 IWL_TX_FIFO_BK_IPAN,
4278};
4279
4280static const u8 iwlagn_pan_ac_to_queue[] = {
4281 7, 6, 5, 4,
4282};
4283
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004284static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07004285{
Johannes Berg246ed352010-08-23 10:46:32 +02004286 int err = 0, i;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004287 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07004288 struct ieee80211_hw *hw;
Tomas Winkler82b9a122008-03-04 18:09:30 -08004289 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004290 unsigned long flags;
Wey-Yi Guyc6fa17e2010-07-15 05:58:30 -07004291 u16 pci_cmd, num_mac;
Zhu Yib481de92007-09-25 17:54:57 -07004292
Assaf Krauss316c30d2008-03-14 10:38:46 -07004293 /************************
4294 * 1. Allocating HW data
4295 ************************/
4296
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004297 /* Disabling hardware scan means that mac80211 will perform scans
4298 * "the hard way", rather than using device's scan. */
Assaf Krauss1ea87392008-03-18 14:57:50 -07004299 if (cfg->mod_params->disable_hw_scan) {
Wey-Yi Guy72645ef2010-10-06 07:42:43 -07004300 dev_printk(KERN_DEBUG, &(pdev->dev),
4301 "sw scan support is deprecated\n");
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004302 iwl_hw_ops.hw_scan = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07004303 }
4304
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004305 hw = iwl_alloc_all(cfg, &iwl_hw_ops);
Assaf Krauss1d0a0822008-03-14 10:38:48 -07004306 if (!hw) {
Zhu Yib481de92007-09-25 17:54:57 -07004307 err = -ENOMEM;
4308 goto out;
4309 }
Assaf Krauss1d0a0822008-03-14 10:38:48 -07004310 priv = hw->priv;
4311 /* At this point both hw and priv are allocated. */
4312
Johannes Berg246ed352010-08-23 10:46:32 +02004313 /*
4314 * The default context is always valid,
4315 * more may be discovered when firmware
4316 * is loaded.
4317 */
4318 priv->valid_contexts = BIT(IWL_RXON_CTX_BSS);
4319
4320 for (i = 0; i < NUM_IWL_RXON_CTX; i++)
4321 priv->contexts[i].ctxid = i;
4322
Johannes Berg763cc3b2010-09-03 06:32:21 -07004323 priv->contexts[IWL_RXON_CTX_BSS].always_active = true;
4324 priv->contexts[IWL_RXON_CTX_BSS].is_active = true;
Johannes Berg8f2d3d22010-08-23 10:46:37 +02004325 priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
4326 priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
4327 priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
Johannes Berg8dfdb9d2010-08-23 10:46:38 +02004328 priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
Johannes Berg2995baf2010-08-23 10:46:42 +02004329 priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
Johannes Bergc10afb62010-08-23 10:46:43 +02004330 priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
Johannes Berge72f3682010-08-23 10:46:51 +02004331 priv->contexts[IWL_RXON_CTX_BSS].ac_to_fifo = iwlagn_bss_ac_to_fifo;
4332 priv->contexts[IWL_RXON_CTX_BSS].ac_to_queue = iwlagn_bss_ac_to_queue;
Johannes Bergd0fe4782010-08-23 10:46:58 +02004333 priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
4334 BIT(NL80211_IFTYPE_ADHOC);
4335 priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
4336 BIT(NL80211_IFTYPE_STATION);
4337 priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
4338 priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
4339 priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
Johannes Bergece9c4e2010-08-23 10:46:49 +02004340
4341 priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON;
4342 priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd = REPLY_WIPAN_RXON_TIMING;
4343 priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd = REPLY_WIPAN_RXON_ASSOC;
4344 priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM;
4345 priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN;
4346 priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY;
4347 priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID;
4348 priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION;
Johannes Berge72f3682010-08-23 10:46:51 +02004349 priv->contexts[IWL_RXON_CTX_PAN].ac_to_fifo = iwlagn_pan_ac_to_fifo;
4350 priv->contexts[IWL_RXON_CTX_PAN].ac_to_queue = iwlagn_pan_ac_to_queue;
4351 priv->contexts[IWL_RXON_CTX_PAN].mcast_queue = IWL_IPAN_MCAST_QUEUE;
Johannes Bergd0fe4782010-08-23 10:46:58 +02004352 priv->contexts[IWL_RXON_CTX_PAN].interface_modes =
4353 BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
4354 priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP;
4355 priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA;
4356 priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P;
Johannes Bergece9c4e2010-08-23 10:46:49 +02004357
4358 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
Johannes Berg8f2d3d22010-08-23 10:46:37 +02004359
Zhu Yib481de92007-09-25 17:54:57 -07004360 SET_IEEE80211_DEV(hw, &pdev->dev);
4361
Tomas Winklere1623442009-01-27 14:27:56 -08004362 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Tomas Winkler82b9a122008-03-04 18:09:30 -08004363 priv->cfg = cfg;
Zhu Yib481de92007-09-25 17:54:57 -07004364 priv->pci_dev = pdev;
Mohamed Abbas40cefda2009-05-22 11:01:52 -07004365 priv->inta_mask = CSR_INI_SET_MASK;
Assaf Krauss316c30d2008-03-14 10:38:46 -07004366
Wey-Yi Guybee008b2010-08-23 07:57:04 -07004367 /* is antenna coupling more than 35dB ? */
4368 priv->bt_ant_couple_ok =
4369 (iwlagn_ant_coupling > IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
4370 true : false;
4371
Wey-Yi Guyf37837c2010-08-23 07:57:12 -07004372 /* enable/disable bt channel announcement */
4373 priv->bt_ch_announce = iwlagn_bt_ch_announce;
4374
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07004375 if (iwl_alloc_traffic_mem(priv))
4376 IWL_ERR(priv, "Not enough memory to generate traffic log\n");
Zhu Yib481de92007-09-25 17:54:57 -07004377
Assaf Krauss316c30d2008-03-14 10:38:46 -07004378 /**************************
4379 * 2. Initializing PCI bus
4380 **************************/
John W. Linville1a7123c2010-08-05 14:39:31 -04004381 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
4382 PCIE_LINK_STATE_CLKPM);
4383
Assaf Krauss316c30d2008-03-14 10:38:46 -07004384 if (pci_enable_device(pdev)) {
4385 err = -ENODEV;
4386 goto out_ieee80211_free_hw;
4387 }
4388
4389 pci_set_master(pdev);
4390
Winkler, Tomas093d874c2008-09-26 15:09:34 +08004391 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
Assaf Krauss316c30d2008-03-14 10:38:46 -07004392 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08004393 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004394 if (err) {
Winkler, Tomas093d874c2008-09-26 15:09:34 +08004395 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004396 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08004397 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004398 /* both attempts failed: */
Assaf Krauss316c30d2008-03-14 10:38:46 -07004399 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08004400 IWL_WARN(priv, "No suitable DMA available.\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07004401 goto out_pci_disable_device;
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004402 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07004403 }
4404
4405 err = pci_request_regions(pdev, DRV_NAME);
4406 if (err)
4407 goto out_pci_disable_device;
4408
4409 pci_set_drvdata(pdev, priv);
4410
Assaf Krauss316c30d2008-03-14 10:38:46 -07004411
4412 /***********************
4413 * 3. Read REV register
4414 ***********************/
4415 priv->hw_base = pci_iomap(pdev, 0, 0);
4416 if (!priv->hw_base) {
4417 err = -ENODEV;
4418 goto out_pci_release_regions;
4419 }
4420
Tomas Winklere1623442009-01-27 14:27:56 -08004421 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Assaf Krauss316c30d2008-03-14 10:38:46 -07004422 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08004423 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004424
Reinette Chatre731a29b2009-12-14 14:12:11 -08004425 /* these spin locks will be used in apm_ops.init and EEPROM access
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07004426 * we should init now
4427 */
4428 spin_lock_init(&priv->reg_lock);
Reinette Chatre731a29b2009-12-14 14:12:11 -08004429 spin_lock_init(&priv->lock);
Reinette Chatre4843b5a2010-02-03 09:38:59 -08004430
4431 /*
4432 * stop and reset the on-board processor just in case it is in a
4433 * strange state ... like being left stranded by a primary kernel
4434 * and this is now the kdump kernel trying to start up
4435 */
4436 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
4437
Tomas Winklerb661c812008-04-23 17:14:54 -07004438 iwl_hw_detect(priv);
Shanyu Zhaoc11362c2010-03-05 17:05:20 -08004439 IWL_INFO(priv, "Detected %s, REV=0x%X\n",
Tomas Winklerb661c812008-04-23 17:14:54 -07004440 priv->cfg->name, priv->hw_rev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004441
Tomas Winklere7b63582008-09-03 11:26:49 +08004442 /* We disable the RETRY_TIMEOUT register (0x41) to keep
4443 * PCI Tx retries from interfering with C3 CPU state */
4444 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
4445
Mohamed Abbas086ed112009-05-22 11:01:54 -07004446 iwl_prepare_card_hw(priv);
4447 if (!priv->hw_ready) {
4448 IWL_WARN(priv, "Failed, HW not ready\n");
4449 goto out_iounmap;
4450 }
4451
Assaf Krauss316c30d2008-03-14 10:38:46 -07004452 /*****************
4453 * 4. Read EEPROM
4454 *****************/
Assaf Krauss316c30d2008-03-14 10:38:46 -07004455 /* Read the EEPROM */
4456 err = iwl_eeprom_init(priv);
4457 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004458 IWL_ERR(priv, "Unable to init EEPROM\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07004459 goto out_iounmap;
4460 }
Tomas Winkler8614f362008-04-23 17:14:55 -07004461 err = iwl_eeprom_check_version(priv);
4462 if (err)
Reinette Chatrec8f16132009-02-27 16:21:22 -08004463 goto out_free_eeprom;
Tomas Winkler8614f362008-04-23 17:14:55 -07004464
Ron Rindjunsky02883012008-05-15 13:53:53 +08004465 /* extract MAC Address */
Wey-Yi Guyc6fa17e2010-07-15 05:58:30 -07004466 iwl_eeprom_get_mac(priv, priv->addresses[0].addr);
4467 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
4468 priv->hw->wiphy->addresses = priv->addresses;
4469 priv->hw->wiphy->n_addresses = 1;
4470 num_mac = iwl_eeprom_query16(priv, EEPROM_NUM_MAC_ADDRESS);
4471 if (num_mac > 1) {
4472 memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
4473 ETH_ALEN);
4474 priv->addresses[1].addr[5]++;
4475 priv->hw->wiphy->n_addresses++;
4476 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07004477
4478 /************************
4479 * 5. Setup HW constants
4480 ************************/
Ron Rindjunskyda154e302008-06-30 17:23:20 +08004481 if (iwl_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004482 IWL_ERR(priv, "failed to set hw parameters\n");
Tomas Winkler073d3f52008-04-21 15:41:52 -07004483 goto out_free_eeprom;
Assaf Krauss316c30d2008-03-14 10:38:46 -07004484 }
4485
4486 /*******************
Tomas Winkler6ba87952008-05-15 13:54:17 +08004487 * 6. Setup priv
Assaf Krauss316c30d2008-03-14 10:38:46 -07004488 *******************/
Zhu Yib481de92007-09-25 17:54:57 -07004489
Tomas Winkler6ba87952008-05-15 13:54:17 +08004490 err = iwl_init_drv(priv);
Assaf Kraussbf85ea42008-03-14 10:38:49 -07004491 if (err)
Ron Rindjunsky399f4902008-04-23 17:14:56 -07004492 goto out_free_eeprom;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07004493 /* At this point both hw and priv are initialized. */
Assaf Krauss316c30d2008-03-14 10:38:46 -07004494
Assaf Krauss316c30d2008-03-14 10:38:46 -07004495 /********************
Abhijeet Kolekar09f9bf72009-04-20 14:37:03 -07004496 * 7. Setup services
Assaf Krauss316c30d2008-03-14 10:38:46 -07004497 ********************/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004498 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004499 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004500 spin_unlock_irqrestore(&priv->lock, flags);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004501
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004502 pci_enable_msi(priv->pci_dev);
4503
Mohamed Abbasef850d72009-05-22 11:01:50 -07004504 iwl_alloc_isr_ict(priv);
4505 err = request_irq(priv->pci_dev->irq, priv->cfg->ops->lib->isr,
4506 IRQF_SHARED, DRV_NAME, priv);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004507 if (err) {
4508 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
4509 goto out_disable_msi;
4510 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07004511
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004512 iwl_setup_deferred_work(priv);
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08004513 iwl_setup_rx_handlers(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004514
Johannes Berg158bea02010-01-22 14:22:53 -08004515 /*********************************************
4516 * 8. Enable interrupts and read RFKILL state
4517 *********************************************/
Tomas Winkler6ba87952008-05-15 13:54:17 +08004518
Stanislaw Gruszka554d1d02010-12-23 12:38:21 +01004519 /* enable rfkill interrupt: hw bug w/a */
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004520 pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd);
4521 if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
4522 pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
4523 pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
4524 }
4525
Stanislaw Gruszka554d1d02010-12-23 12:38:21 +01004526 iwl_enable_rfkill_int(priv);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004527
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004528 /* If platform's RF_KILL switch is NOT set to KILL */
4529 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
4530 clear_bit(STATUS_RF_KILL_HW, &priv->status);
4531 else
4532 set_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winkler6ba87952008-05-15 13:54:17 +08004533
Johannes Berga60e77e2009-06-04 18:26:06 +02004534 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
4535 test_bit(STATUS_RF_KILL_HW, &priv->status));
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004536
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08004537 iwl_power_initialize(priv);
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -07004538 iwl_tt_initialize(priv);
Johannes Berg158bea02010-01-22 14:22:53 -08004539
Reinette Chatrea15707d2010-05-10 15:08:11 -07004540 init_completion(&priv->_agn.firmware_loading_complete);
Johannes Berg562db532010-04-29 07:41:53 -07004541
Johannes Bergb08dfd02010-01-29 11:54:56 -08004542 err = iwl_request_firmware(priv, true);
Johannes Berg158bea02010-01-22 14:22:53 -08004543 if (err)
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07004544 goto out_destroy_workqueue;
Johannes Berg158bea02010-01-22 14:22:53 -08004545
Zhu Yib481de92007-09-25 17:54:57 -07004546 return 0;
4547
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07004548 out_destroy_workqueue:
Reinette Chatrec8f16132009-02-27 16:21:22 -08004549 destroy_workqueue(priv->workqueue);
4550 priv->workqueue = NULL;
Helmut Schaa795cc0a2009-02-12 18:51:03 +01004551 free_irq(priv->pci_dev->irq, priv);
Mohamed Abbasef850d72009-05-22 11:01:50 -07004552 iwl_free_isr_ict(priv);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004553 out_disable_msi:
4554 pci_disable_msi(priv->pci_dev);
Tomas Winkler6ba87952008-05-15 13:54:17 +08004555 iwl_uninit_drv(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07004556 out_free_eeprom:
4557 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004558 out_iounmap:
4559 pci_iounmap(pdev, priv->hw_base);
4560 out_pci_release_regions:
Assaf Krauss316c30d2008-03-14 10:38:46 -07004561 pci_set_drvdata(pdev, NULL);
Reinette Chatre623d5632009-03-03 11:37:04 -08004562 pci_release_regions(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004563 out_pci_disable_device:
4564 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004565 out_ieee80211_free_hw:
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07004566 iwl_free_traffic_mem(priv);
Wey-Yi Guyd7c76f42009-10-09 13:20:17 -07004567 ieee80211_free_hw(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07004568 out:
4569 return err;
4570}
4571
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004572static void __devexit iwl_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004573{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004574 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004575 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07004576
4577 if (!priv)
4578 return;
4579
Reinette Chatrea15707d2010-05-10 15:08:11 -07004580 wait_for_completion(&priv->_agn.firmware_loading_complete);
Johannes Berg562db532010-04-29 07:41:53 -07004581
Tomas Winklere1623442009-01-27 14:27:56 -08004582 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07004583
Emmanuel Grumbach67249622008-05-29 16:35:26 +08004584 iwl_dbgfs_unregister(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004585 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
Emmanuel Grumbach67249622008-05-29 16:35:26 +08004586
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004587 /* ieee80211_unregister_hw call wil cause iwl_mac_stop to
4588 * to be called and iwl_down since we are removing the device
Gregory Greenman0b124c32008-09-03 11:18:50 +08004589 * we need to set STATUS_EXIT_PENDING bit.
4590 */
4591 set_bit(STATUS_EXIT_PENDING, &priv->status);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07004592 if (priv->mac80211_registered) {
4593 ieee80211_unregister_hw(priv->hw);
4594 priv->mac80211_registered = 0;
Gregory Greenman0b124c32008-09-03 11:18:50 +08004595 } else {
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004596 iwl_down(priv);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07004597 }
4598
Ben Cahillc166b252009-10-23 13:42:35 -07004599 /*
4600 * Make sure device is reset to low power before unloading driver.
4601 * This may be redundant with iwl_down(), but there are paths to
4602 * run iwl_down() without calling apm_ops.stop(), and there are
4603 * paths to avoid running iwl_down() at all before leaving driver.
4604 * This (inexpensive) call *makes sure* device is reset.
4605 */
Johannes Berg14e8e4a2010-09-22 18:02:10 +02004606 iwl_apm_stop(priv);
Ben Cahillc166b252009-10-23 13:42:35 -07004607
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -07004608 iwl_tt_exit(priv);
4609
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004610 /* make sure we flush any pending irq or
4611 * tasklet for the driver
4612 */
4613 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004614 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004615 spin_unlock_irqrestore(&priv->lock, flags);
4616
4617 iwl_synchronize_irq(priv);
4618
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004619 iwl_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004620
4621 if (priv->rxq.bd)
Wey-Yi Guy54b81552010-03-17 13:34:35 -07004622 iwlagn_rx_queue_free(priv, &priv->rxq);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -07004623 iwlagn_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004624
Tomas Winkler073d3f52008-04-21 15:41:52 -07004625 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004626
Zhu Yib481de92007-09-25 17:54:57 -07004627
Mohamed Abbas948c1712007-10-25 17:15:45 +08004628 /*netif_stop_queue(dev); */
4629 flush_workqueue(priv->workqueue);
4630
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004631 /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07004632 * priv->workqueue... so we can't take down the workqueue
4633 * until now... */
4634 destroy_workqueue(priv->workqueue);
4635 priv->workqueue = NULL;
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07004636 iwl_free_traffic_mem(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004637
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01004638 free_irq(priv->pci_dev->irq, priv);
4639 pci_disable_msi(priv->pci_dev);
Zhu Yib481de92007-09-25 17:54:57 -07004640 pci_iounmap(pdev, priv->hw_base);
4641 pci_release_regions(pdev);
4642 pci_disable_device(pdev);
4643 pci_set_drvdata(pdev, NULL);
4644
Tomas Winkler6ba87952008-05-15 13:54:17 +08004645 iwl_uninit_drv(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004646
Mohamed Abbasef850d72009-05-22 11:01:50 -07004647 iwl_free_isr_ict(priv);
4648
Johannes Berg77834542010-10-04 05:50:36 -07004649 dev_kfree_skb(priv->beacon_skb);
Zhu Yib481de92007-09-25 17:54:57 -07004650
4651 ieee80211_free_hw(priv->hw);
4652}
4653
Zhu Yib481de92007-09-25 17:54:57 -07004654
4655/*****************************************************************************
4656 *
4657 * driver and module entry point
4658 *
4659 *****************************************************************************/
4660
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004661/* Hardware specific file defines the PCI IDs table for that hardware module */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00004662static DEFINE_PCI_DEVICE_TABLE(iwl_hw_card_ids) = {
Tomas Winkler4fc22b22008-07-21 18:54:42 +03004663#ifdef CONFIG_IWL4965
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004664 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
4665 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
Tomas Winkler4fc22b22008-07-21 18:54:42 +03004666#endif /* CONFIG_IWL4965 */
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004667#ifdef CONFIG_IWL5000
Wey-Yi Guyac592572009-11-20 12:05:03 -08004668/* 5100 Series WiFi */
4669 {IWL_PCI_DEVICE(0x4232, 0x1201, iwl5100_agn_cfg)}, /* Mini Card */
4670 {IWL_PCI_DEVICE(0x4232, 0x1301, iwl5100_agn_cfg)}, /* Half Mini Card */
4671 {IWL_PCI_DEVICE(0x4232, 0x1204, iwl5100_agn_cfg)}, /* Mini Card */
4672 {IWL_PCI_DEVICE(0x4232, 0x1304, iwl5100_agn_cfg)}, /* Half Mini Card */
4673 {IWL_PCI_DEVICE(0x4232, 0x1205, iwl5100_bgn_cfg)}, /* Mini Card */
4674 {IWL_PCI_DEVICE(0x4232, 0x1305, iwl5100_bgn_cfg)}, /* Half Mini Card */
4675 {IWL_PCI_DEVICE(0x4232, 0x1206, iwl5100_abg_cfg)}, /* Mini Card */
4676 {IWL_PCI_DEVICE(0x4232, 0x1306, iwl5100_abg_cfg)}, /* Half Mini Card */
4677 {IWL_PCI_DEVICE(0x4232, 0x1221, iwl5100_agn_cfg)}, /* Mini Card */
4678 {IWL_PCI_DEVICE(0x4232, 0x1321, iwl5100_agn_cfg)}, /* Half Mini Card */
4679 {IWL_PCI_DEVICE(0x4232, 0x1224, iwl5100_agn_cfg)}, /* Mini Card */
4680 {IWL_PCI_DEVICE(0x4232, 0x1324, iwl5100_agn_cfg)}, /* Half Mini Card */
4681 {IWL_PCI_DEVICE(0x4232, 0x1225, iwl5100_bgn_cfg)}, /* Mini Card */
4682 {IWL_PCI_DEVICE(0x4232, 0x1325, iwl5100_bgn_cfg)}, /* Half Mini Card */
4683 {IWL_PCI_DEVICE(0x4232, 0x1226, iwl5100_abg_cfg)}, /* Mini Card */
4684 {IWL_PCI_DEVICE(0x4232, 0x1326, iwl5100_abg_cfg)}, /* Half Mini Card */
4685 {IWL_PCI_DEVICE(0x4237, 0x1211, iwl5100_agn_cfg)}, /* Mini Card */
4686 {IWL_PCI_DEVICE(0x4237, 0x1311, iwl5100_agn_cfg)}, /* Half Mini Card */
4687 {IWL_PCI_DEVICE(0x4237, 0x1214, iwl5100_agn_cfg)}, /* Mini Card */
4688 {IWL_PCI_DEVICE(0x4237, 0x1314, iwl5100_agn_cfg)}, /* Half Mini Card */
4689 {IWL_PCI_DEVICE(0x4237, 0x1215, iwl5100_bgn_cfg)}, /* Mini Card */
4690 {IWL_PCI_DEVICE(0x4237, 0x1315, iwl5100_bgn_cfg)}, /* Half Mini Card */
4691 {IWL_PCI_DEVICE(0x4237, 0x1216, iwl5100_abg_cfg)}, /* Mini Card */
4692 {IWL_PCI_DEVICE(0x4237, 0x1316, iwl5100_abg_cfg)}, /* Half Mini Card */
4693
4694/* 5300 Series WiFi */
4695 {IWL_PCI_DEVICE(0x4235, 0x1021, iwl5300_agn_cfg)}, /* Mini Card */
4696 {IWL_PCI_DEVICE(0x4235, 0x1121, iwl5300_agn_cfg)}, /* Half Mini Card */
4697 {IWL_PCI_DEVICE(0x4235, 0x1024, iwl5300_agn_cfg)}, /* Mini Card */
4698 {IWL_PCI_DEVICE(0x4235, 0x1124, iwl5300_agn_cfg)}, /* Half Mini Card */
4699 {IWL_PCI_DEVICE(0x4235, 0x1001, iwl5300_agn_cfg)}, /* Mini Card */
4700 {IWL_PCI_DEVICE(0x4235, 0x1101, iwl5300_agn_cfg)}, /* Half Mini Card */
4701 {IWL_PCI_DEVICE(0x4235, 0x1004, iwl5300_agn_cfg)}, /* Mini Card */
4702 {IWL_PCI_DEVICE(0x4235, 0x1104, iwl5300_agn_cfg)}, /* Half Mini Card */
4703 {IWL_PCI_DEVICE(0x4236, 0x1011, iwl5300_agn_cfg)}, /* Mini Card */
4704 {IWL_PCI_DEVICE(0x4236, 0x1111, iwl5300_agn_cfg)}, /* Half Mini Card */
4705 {IWL_PCI_DEVICE(0x4236, 0x1014, iwl5300_agn_cfg)}, /* Mini Card */
4706 {IWL_PCI_DEVICE(0x4236, 0x1114, iwl5300_agn_cfg)}, /* Half Mini Card */
4707
4708/* 5350 Series WiFi/WiMax */
4709 {IWL_PCI_DEVICE(0x423A, 0x1001, iwl5350_agn_cfg)}, /* Mini Card */
4710 {IWL_PCI_DEVICE(0x423A, 0x1021, iwl5350_agn_cfg)}, /* Mini Card */
4711 {IWL_PCI_DEVICE(0x423B, 0x1011, iwl5350_agn_cfg)}, /* Mini Card */
4712
4713/* 5150 Series Wifi/WiMax */
4714 {IWL_PCI_DEVICE(0x423C, 0x1201, iwl5150_agn_cfg)}, /* Mini Card */
4715 {IWL_PCI_DEVICE(0x423C, 0x1301, iwl5150_agn_cfg)}, /* Half Mini Card */
4716 {IWL_PCI_DEVICE(0x423C, 0x1206, iwl5150_abg_cfg)}, /* Mini Card */
4717 {IWL_PCI_DEVICE(0x423C, 0x1306, iwl5150_abg_cfg)}, /* Half Mini Card */
4718 {IWL_PCI_DEVICE(0x423C, 0x1221, iwl5150_agn_cfg)}, /* Mini Card */
4719 {IWL_PCI_DEVICE(0x423C, 0x1321, iwl5150_agn_cfg)}, /* Half Mini Card */
4720
4721 {IWL_PCI_DEVICE(0x423D, 0x1211, iwl5150_agn_cfg)}, /* Mini Card */
4722 {IWL_PCI_DEVICE(0x423D, 0x1311, iwl5150_agn_cfg)}, /* Half Mini Card */
4723 {IWL_PCI_DEVICE(0x423D, 0x1216, iwl5150_abg_cfg)}, /* Mini Card */
4724 {IWL_PCI_DEVICE(0x423D, 0x1316, iwl5150_abg_cfg)}, /* Half Mini Card */
Wey-Yi Guy5953a622009-09-17 10:43:53 -07004725
4726/* 6x00 Series */
Wey-Yi Guy5953a622009-09-17 10:43:53 -07004727 {IWL_PCI_DEVICE(0x422B, 0x1101, iwl6000_3agn_cfg)},
4728 {IWL_PCI_DEVICE(0x422B, 0x1121, iwl6000_3agn_cfg)},
4729 {IWL_PCI_DEVICE(0x422C, 0x1301, iwl6000i_2agn_cfg)},
4730 {IWL_PCI_DEVICE(0x422C, 0x1306, iwl6000i_2abg_cfg)},
4731 {IWL_PCI_DEVICE(0x422C, 0x1307, iwl6000i_2bg_cfg)},
4732 {IWL_PCI_DEVICE(0x422C, 0x1321, iwl6000i_2agn_cfg)},
4733 {IWL_PCI_DEVICE(0x422C, 0x1326, iwl6000i_2abg_cfg)},
4734 {IWL_PCI_DEVICE(0x4238, 0x1111, iwl6000_3agn_cfg)},
4735 {IWL_PCI_DEVICE(0x4239, 0x1311, iwl6000i_2agn_cfg)},
4736 {IWL_PCI_DEVICE(0x4239, 0x1316, iwl6000i_2abg_cfg)},
Shanyu Zhao4b3e8062010-04-07 18:06:36 -07004737
Shanyu Zhao95b13012010-04-21 11:46:33 -07004738/* 6x00 Series Gen2a */
4739 {IWL_PCI_DEVICE(0x0082, 0x1201, iwl6000g2a_2agn_cfg)},
4740 {IWL_PCI_DEVICE(0x0085, 0x1211, iwl6000g2a_2agn_cfg)},
4741 {IWL_PCI_DEVICE(0x0082, 0x1221, iwl6000g2a_2agn_cfg)},
Shanyu Zhao18089722010-05-06 10:15:21 -07004742 {IWL_PCI_DEVICE(0x0082, 0x1206, iwl6000g2a_2abg_cfg)},
4743 {IWL_PCI_DEVICE(0x0085, 0x1216, iwl6000g2a_2abg_cfg)},
4744 {IWL_PCI_DEVICE(0x0082, 0x1226, iwl6000g2a_2abg_cfg)},
4745 {IWL_PCI_DEVICE(0x0082, 0x1207, iwl6000g2a_2bg_cfg)},
Shanyu Zhao9f6e1ba2010-05-11 15:21:54 -07004746 {IWL_PCI_DEVICE(0x0082, 0x1301, iwl6000g2a_2agn_cfg)},
4747 {IWL_PCI_DEVICE(0x0082, 0x1306, iwl6000g2a_2abg_cfg)},
4748 {IWL_PCI_DEVICE(0x0082, 0x1307, iwl6000g2a_2bg_cfg)},
4749 {IWL_PCI_DEVICE(0x0082, 0x1321, iwl6000g2a_2agn_cfg)},
4750 {IWL_PCI_DEVICE(0x0082, 0x1326, iwl6000g2a_2abg_cfg)},
4751 {IWL_PCI_DEVICE(0x0085, 0x1311, iwl6000g2a_2agn_cfg)},
4752 {IWL_PCI_DEVICE(0x0085, 0x1316, iwl6000g2a_2abg_cfg)},
Shanyu Zhao18089722010-05-06 10:15:21 -07004753
4754/* 6x00 Series Gen2b */
4755 {IWL_PCI_DEVICE(0x008F, 0x5105, iwl6000g2b_bgn_cfg)},
4756 {IWL_PCI_DEVICE(0x0090, 0x5115, iwl6000g2b_bgn_cfg)},
4757 {IWL_PCI_DEVICE(0x008F, 0x5125, iwl6000g2b_bgn_cfg)},
4758 {IWL_PCI_DEVICE(0x008F, 0x5107, iwl6000g2b_bg_cfg)},
4759 {IWL_PCI_DEVICE(0x008F, 0x5201, iwl6000g2b_2agn_cfg)},
4760 {IWL_PCI_DEVICE(0x0090, 0x5211, iwl6000g2b_2agn_cfg)},
4761 {IWL_PCI_DEVICE(0x008F, 0x5221, iwl6000g2b_2agn_cfg)},
4762 {IWL_PCI_DEVICE(0x008F, 0x5206, iwl6000g2b_2abg_cfg)},
4763 {IWL_PCI_DEVICE(0x0090, 0x5216, iwl6000g2b_2abg_cfg)},
4764 {IWL_PCI_DEVICE(0x008F, 0x5226, iwl6000g2b_2abg_cfg)},
4765 {IWL_PCI_DEVICE(0x008F, 0x5207, iwl6000g2b_2bg_cfg)},
Shanyu Zhao9f6e1ba2010-05-11 15:21:54 -07004766 {IWL_PCI_DEVICE(0x008A, 0x5301, iwl6000g2b_bgn_cfg)},
4767 {IWL_PCI_DEVICE(0x008A, 0x5305, iwl6000g2b_bgn_cfg)},
4768 {IWL_PCI_DEVICE(0x008A, 0x5307, iwl6000g2b_bg_cfg)},
4769 {IWL_PCI_DEVICE(0x008A, 0x5321, iwl6000g2b_bgn_cfg)},
4770 {IWL_PCI_DEVICE(0x008A, 0x5325, iwl6000g2b_bgn_cfg)},
4771 {IWL_PCI_DEVICE(0x008B, 0x5311, iwl6000g2b_bgn_cfg)},
4772 {IWL_PCI_DEVICE(0x008B, 0x5315, iwl6000g2b_bgn_cfg)},
4773 {IWL_PCI_DEVICE(0x0090, 0x5211, iwl6000g2b_2agn_cfg)},
4774 {IWL_PCI_DEVICE(0x0090, 0x5215, iwl6000g2b_2bgn_cfg)},
4775 {IWL_PCI_DEVICE(0x0090, 0x5216, iwl6000g2b_2abg_cfg)},
4776 {IWL_PCI_DEVICE(0x0091, 0x5201, iwl6000g2b_2agn_cfg)},
4777 {IWL_PCI_DEVICE(0x0091, 0x5205, iwl6000g2b_2bgn_cfg)},
4778 {IWL_PCI_DEVICE(0x0091, 0x5206, iwl6000g2b_2abg_cfg)},
4779 {IWL_PCI_DEVICE(0x0091, 0x5207, iwl6000g2b_2bg_cfg)},
4780 {IWL_PCI_DEVICE(0x0091, 0x5221, iwl6000g2b_2agn_cfg)},
4781 {IWL_PCI_DEVICE(0x0091, 0x5225, iwl6000g2b_2bgn_cfg)},
4782 {IWL_PCI_DEVICE(0x0091, 0x5226, iwl6000g2b_2abg_cfg)},
Wey-Yi Guy5953a622009-09-17 10:43:53 -07004783
4784/* 6x50 WiFi/WiMax Series */
Wey-Yi Guy5953a622009-09-17 10:43:53 -07004785 {IWL_PCI_DEVICE(0x0087, 0x1301, iwl6050_2agn_cfg)},
4786 {IWL_PCI_DEVICE(0x0087, 0x1306, iwl6050_2abg_cfg)},
4787 {IWL_PCI_DEVICE(0x0087, 0x1321, iwl6050_2agn_cfg)},
4788 {IWL_PCI_DEVICE(0x0087, 0x1326, iwl6050_2abg_cfg)},
Wey-Yi Guy5953a622009-09-17 10:43:53 -07004789 {IWL_PCI_DEVICE(0x0089, 0x1311, iwl6050_2agn_cfg)},
4790 {IWL_PCI_DEVICE(0x0089, 0x1316, iwl6050_2abg_cfg)},
4791
Shanyu Zhao03264332010-06-29 17:27:27 -07004792/* 6x50 WiFi/WiMax Series Gen2 */
4793 {IWL_PCI_DEVICE(0x0885, 0x1305, iwl6050g2_bgn_cfg)},
4794 {IWL_PCI_DEVICE(0x0885, 0x1306, iwl6050g2_bgn_cfg)},
4795 {IWL_PCI_DEVICE(0x0885, 0x1325, iwl6050g2_bgn_cfg)},
4796 {IWL_PCI_DEVICE(0x0885, 0x1326, iwl6050g2_bgn_cfg)},
4797 {IWL_PCI_DEVICE(0x0886, 0x1315, iwl6050g2_bgn_cfg)},
4798 {IWL_PCI_DEVICE(0x0886, 0x1316, iwl6050g2_bgn_cfg)},
4799
Jay Sternberg77dcb6a2009-03-06 13:52:55 -08004800/* 1000 Series WiFi */
Wey-Yi Guy4bd0914f2009-09-17 10:43:52 -07004801 {IWL_PCI_DEVICE(0x0083, 0x1205, iwl1000_bgn_cfg)},
4802 {IWL_PCI_DEVICE(0x0083, 0x1305, iwl1000_bgn_cfg)},
4803 {IWL_PCI_DEVICE(0x0083, 0x1225, iwl1000_bgn_cfg)},
4804 {IWL_PCI_DEVICE(0x0083, 0x1325, iwl1000_bgn_cfg)},
4805 {IWL_PCI_DEVICE(0x0084, 0x1215, iwl1000_bgn_cfg)},
4806 {IWL_PCI_DEVICE(0x0084, 0x1315, iwl1000_bgn_cfg)},
4807 {IWL_PCI_DEVICE(0x0083, 0x1206, iwl1000_bg_cfg)},
4808 {IWL_PCI_DEVICE(0x0083, 0x1306, iwl1000_bg_cfg)},
4809 {IWL_PCI_DEVICE(0x0083, 0x1226, iwl1000_bg_cfg)},
4810 {IWL_PCI_DEVICE(0x0083, 0x1326, iwl1000_bg_cfg)},
4811 {IWL_PCI_DEVICE(0x0084, 0x1216, iwl1000_bg_cfg)},
4812 {IWL_PCI_DEVICE(0x0084, 0x1316, iwl1000_bg_cfg)},
Jay Sternberg1de19ec2010-09-14 15:21:20 -07004813
Wey-Yi Guy58a39092010-10-06 08:14:21 -07004814/* 100 Series WiFi */
Jay Sternberg1de19ec2010-09-14 15:21:20 -07004815 {IWL_PCI_DEVICE(0x08AE, 0x1005, iwl100_bgn_cfg)},
4816 {IWL_PCI_DEVICE(0x08AF, 0x1015, iwl100_bgn_cfg)},
4817 {IWL_PCI_DEVICE(0x08AE, 0x1025, iwl100_bgn_cfg)},
4818 {IWL_PCI_DEVICE(0x08AE, 0x1007, iwl100_bg_cfg)},
4819 {IWL_PCI_DEVICE(0x08AE, 0x1017, iwl100_bg_cfg)},
Wey-Yi Guy58a39092010-10-06 08:14:21 -07004820
4821/* 130 Series WiFi */
4822 {IWL_PCI_DEVICE(0x0896, 0x5005, iwl130_bgn_cfg)},
4823 {IWL_PCI_DEVICE(0x0896, 0x5007, iwl130_bg_cfg)},
4824 {IWL_PCI_DEVICE(0x0897, 0x5015, iwl130_bgn_cfg)},
4825 {IWL_PCI_DEVICE(0x0897, 0x5017, iwl130_bg_cfg)},
4826 {IWL_PCI_DEVICE(0x0896, 0x5025, iwl130_bgn_cfg)},
4827 {IWL_PCI_DEVICE(0x0896, 0x5027, iwl130_bg_cfg)},
4828
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004829#endif /* CONFIG_IWL5000 */
Tomas Winkler7100e922008-12-01 16:32:18 -08004830
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004831 {0}
4832};
4833MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
4834
4835static struct pci_driver iwl_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07004836 .name = DRV_NAME,
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004837 .id_table = iwl_hw_card_ids,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004838 .probe = iwl_pci_probe,
4839 .remove = __devexit_p(iwl_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07004840#ifdef CONFIG_PM
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004841 .suspend = iwl_pci_suspend,
4842 .resume = iwl_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07004843#endif
4844};
4845
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004846static int __init iwl_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07004847{
4848
4849 int ret;
Joe Perchesc96c31e2010-07-26 14:39:58 -07004850 pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
4851 pr_info(DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004852
Tomas Winklere227cea2008-07-18 13:53:05 +08004853 ret = iwlagn_rate_control_register();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004854 if (ret) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07004855 pr_err("Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004856 return ret;
4857 }
4858
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004859 ret = pci_register_driver(&iwl_driver);
Zhu Yib481de92007-09-25 17:54:57 -07004860 if (ret) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07004861 pr_err("Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004862 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07004863 }
Zhu Yib481de92007-09-25 17:54:57 -07004864
4865 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004866
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004867error_register:
Tomas Winklere227cea2008-07-18 13:53:05 +08004868 iwlagn_rate_control_unregister();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004869 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004870}
4871
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004872static void __exit iwl_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07004873{
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004874 pci_unregister_driver(&iwl_driver);
Tomas Winklere227cea2008-07-18 13:53:05 +08004875 iwlagn_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07004876}
4877
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004878module_exit(iwl_exit);
4879module_init(iwl_init);
Reinette Chatrea562a9d2009-07-17 09:30:24 -07004880
4881#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07004882module_param_named(debug50, iwl_debug_level, uint, S_IRUGO);
Reinette Chatrea562a9d2009-07-17 09:30:24 -07004883MODULE_PARM_DESC(debug50, "50XX debug output mask (deprecated)");
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07004884module_param_named(debug, iwl_debug_level, uint, S_IRUGO | S_IWUSR);
Reinette Chatrea562a9d2009-07-17 09:30:24 -07004885MODULE_PARM_DESC(debug, "debug output mask");
4886#endif
4887
Wey-Yi Guy2b068612010-03-22 09:17:39 -07004888module_param_named(swcrypto50, iwlagn_mod_params.sw_crypto, bool, S_IRUGO);
4889MODULE_PARM_DESC(swcrypto50,
4890 "using crypto in software (default 0 [hardware]) (deprecated)");
4891module_param_named(swcrypto, iwlagn_mod_params.sw_crypto, int, S_IRUGO);
4892MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
4893module_param_named(queues_num50,
4894 iwlagn_mod_params.num_of_queues, int, S_IRUGO);
4895MODULE_PARM_DESC(queues_num50,
4896 "number of hw queues in 50xx series (deprecated)");
4897module_param_named(queues_num, iwlagn_mod_params.num_of_queues, int, S_IRUGO);
4898MODULE_PARM_DESC(queues_num, "number of hw queues.");
4899module_param_named(11n_disable50, iwlagn_mod_params.disable_11n, int, S_IRUGO);
4900MODULE_PARM_DESC(11n_disable50, "disable 50XX 11n functionality (deprecated)");
4901module_param_named(11n_disable, iwlagn_mod_params.disable_11n, int, S_IRUGO);
4902MODULE_PARM_DESC(11n_disable, "disable 11n functionality");
4903module_param_named(amsdu_size_8K50, iwlagn_mod_params.amsdu_size_8K,
4904 int, S_IRUGO);
4905MODULE_PARM_DESC(amsdu_size_8K50,
4906 "enable 8K amsdu size in 50XX series (deprecated)");
4907module_param_named(amsdu_size_8K, iwlagn_mod_params.amsdu_size_8K,
4908 int, S_IRUGO);
4909MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
4910module_param_named(fw_restart50, iwlagn_mod_params.restart_fw, int, S_IRUGO);
4911MODULE_PARM_DESC(fw_restart50,
4912 "restart firmware in case of error (deprecated)");
4913module_param_named(fw_restart, iwlagn_mod_params.restart_fw, int, S_IRUGO);
4914MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");
4915module_param_named(
4916 disable_hw_scan, iwlagn_mod_params.disable_hw_scan, int, S_IRUGO);
Wey-Yi Guy72645ef2010-10-06 07:42:43 -07004917MODULE_PARM_DESC(disable_hw_scan,
4918 "disable hardware scanning (default 0) (deprecated)");
Johannes Bergdd7a2502010-04-28 23:33:10 -07004919
4920module_param_named(ucode_alternative, iwlagn_wanted_ucode_alternative, int,
4921 S_IRUGO);
4922MODULE_PARM_DESC(ucode_alternative,
4923 "specify ucode alternative to use from ucode file");
Wey-Yi Guybee008b2010-08-23 07:57:04 -07004924
4925module_param_named(antenna_coupling, iwlagn_ant_coupling, int, S_IRUGO);
4926MODULE_PARM_DESC(antenna_coupling,
4927 "specify antenna coupling in dB (defualt: 0 dB)");
Wey-Yi Guyf37837c2010-08-23 07:57:12 -07004928
4929module_param_named(bt_ch_announce, iwlagn_bt_ch_announce, bool, S_IRUGO);
4930MODULE_PARM_DESC(bt_ch_announce,
4931 "Enable BT channel announcement mode (default: enable)");