blob: 2bb08d7e067416a6f23b12212795d89ef21ca4ea [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Wey-Yi Guy901069c2011-04-05 09:42:00 -07003 * Copyright(c) 2003 - 2011 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");
88
Wey-Yi Guybee008b2010-08-23 07:57:04 -070089static int iwlagn_ant_coupling;
Wey-Yi Guyf37837c2010-08-23 07:57:12 -070090static bool iwlagn_bt_ch_announce = 1;
Wey-Yi Guybee008b2010-08-23 07:57:04 -070091
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -070092void iwl_update_chain_flags(struct iwl_priv *priv)
Mohamed Abbas5da4b552008-04-21 15:41:51 -070093{
Johannes Berg246ed352010-08-23 10:46:32 +020094 struct iwl_rxon_context *ctx;
Mohamed Abbas5da4b552008-04-21 15:41:51 -070095
Johannes Berg246ed352010-08-23 10:46:32 +020096 if (priv->cfg->ops->hcmd->set_rxon_chain) {
97 for_each_context(priv, ctx) {
98 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
Shanyu Zhao6163a372010-11-12 13:48:13 -080099 if (ctx->active.rx_chain != ctx->staging.rx_chain)
100 iwlcore_commit_rxon(priv, ctx);
Johannes Berg246ed352010-08-23 10:46:32 +0200101 }
102 }
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700103}
104
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800105/* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
106static void iwl_set_beacon_tim(struct iwl_priv *priv,
Johannes Berg77834542010-10-04 05:50:36 -0700107 struct iwl_tx_beacon_cmd *tx_beacon_cmd,
108 u8 *beacon, u32 frame_size)
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800109{
110 u16 tim_idx;
111 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
112
113 /*
114 * The index is relative to frame start but we start looking at the
115 * variable-length part of the beacon.
116 */
117 tim_idx = mgmt->u.beacon.variable - beacon;
118
119 /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
120 while ((tim_idx < (frame_size - 2)) &&
121 (beacon[tim_idx] != WLAN_EID_TIM))
122 tim_idx += beacon[tim_idx+1] + 2;
123
124 /* If TIM field was found, set variables */
125 if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
126 tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
127 tx_beacon_cmd->tim_size = beacon[tim_idx+1];
128 } else
129 IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
130}
131
Johannes Berg8a98d492011-04-29 09:48:14 -0700132int iwlagn_send_beacon_cmd(struct iwl_priv *priv)
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800133{
134 struct iwl_tx_beacon_cmd *tx_beacon_cmd;
Johannes Berg8a98d492011-04-29 09:48:14 -0700135 struct iwl_host_cmd cmd = {
136 .id = REPLY_TX_BEACON,
137 .flags = CMD_SIZE_HUGE,
138 };
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800139 u32 frame_size;
140 u32 rate_flags;
141 u32 rate;
Johannes Berg8a98d492011-04-29 09:48:14 -0700142 int err;
143
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800144 /*
145 * We have to set up the TX command, the TX Beacon command, and the
146 * beacon contents.
147 */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800148
Johannes Berg76d04812010-08-23 10:46:47 +0200149 lockdep_assert_held(&priv->mutex);
150
151 if (!priv->beacon_ctx) {
152 IWL_ERR(priv, "trying to build beacon w/o beacon context!\n");
Julia Lawall950094c2010-09-05 21:00:26 +0200153 return 0;
Johannes Berg76d04812010-08-23 10:46:47 +0200154 }
155
Johannes Berg8a98d492011-04-29 09:48:14 -0700156 if (WARN_ON(!priv->beacon_skb))
157 return -EINVAL;
158
159 /* Allocate beacon memory */
160 tx_beacon_cmd = kzalloc(sizeof(*tx_beacon_cmd) + priv->beacon_skb->len,
161 GFP_KERNEL);
162 if (!tx_beacon_cmd)
163 return -ENOMEM;
164
165 frame_size = priv->beacon_skb->len;
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800166
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800167 /* Set up TX beacon contents */
Johannes Berg8a98d492011-04-29 09:48:14 -0700168 memcpy(tx_beacon_cmd->frame, priv->beacon_skb->data, frame_size);
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800169
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800170 /* Set up TX command fields */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800171 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
Johannes Berg76d04812010-08-23 10:46:47 +0200172 tx_beacon_cmd->tx.sta_id = priv->beacon_ctx->bcast_sta_id;
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800173 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800174 tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800175 TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
176
177 /* Set up TX beacon command fields */
178 iwl_set_beacon_tim(priv, tx_beacon_cmd, (u8 *)tx_beacon_cmd->frame,
Johannes Berg77834542010-10-04 05:50:36 -0700179 frame_size);
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800180
181 /* Set up packet rate and flags */
Johannes Berg76d04812010-08-23 10:46:47 +0200182 rate = iwl_rate_get_lowest_plcp(priv, priv->beacon_ctx);
Johannes Berg0e1654f2010-05-18 02:48:36 -0700183 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
184 priv->hw_params.valid_tx_ant);
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800185 rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
186 if ((rate >= IWL_FIRST_CCK_RATE) && (rate <= IWL_LAST_CCK_RATE))
187 rate_flags |= RATE_MCS_CCK_MSK;
188 tx_beacon_cmd->tx.rate_n_flags = iwl_hw_set_rate_n_flags(rate,
189 rate_flags);
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800190
Johannes Berg8a98d492011-04-29 09:48:14 -0700191 /* Submit command */
Johannes Berg3fa50732011-05-04 07:50:38 -0700192 cmd.len[0] = sizeof(*tx_beacon_cmd) + frame_size;
193 cmd.data[0] = tx_beacon_cmd;
Johannes Berg2295c662010-10-23 09:15:41 -0700194
Johannes Berg8a98d492011-04-29 09:48:14 -0700195 err = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700196
Johannes Berg8a98d492011-04-29 09:48:14 -0700197 /* Free temporary storage */
198 kfree(tx_beacon_cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700199
Johannes Berg8a98d492011-04-29 09:48:14 -0700200 return err;
Zhu Yib481de92007-09-25 17:54:57 -0700201}
202
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700203static void iwl_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -0700204{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700205 struct iwl_priv *priv =
206 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -0700207 struct sk_buff *beacon;
208
Johannes Berg76d04812010-08-23 10:46:47 +0200209 mutex_lock(&priv->mutex);
210 if (!priv->beacon_ctx) {
211 IWL_ERR(priv, "updating beacon w/o beacon context!\n");
212 goto out;
Zhu Yib481de92007-09-25 17:54:57 -0700213 }
214
Johannes Berg60744f62010-08-23 10:46:50 +0200215 if (priv->beacon_ctx->vif->type != NL80211_IFTYPE_AP) {
216 /*
217 * The ucode will send beacon notifications even in
218 * IBSS mode, but we don't want to process them. But
219 * we need to defer the type check to here due to
220 * requiring locking around the beacon_ctx access.
221 */
222 goto out;
223 }
224
Johannes Berg76d04812010-08-23 10:46:47 +0200225 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
226 beacon = ieee80211_beacon_get(priv->hw, priv->beacon_ctx->vif);
227 if (!beacon) {
Johannes Berg77834542010-10-04 05:50:36 -0700228 IWL_ERR(priv, "update beacon failed -- keeping old\n");
Johannes Berg76d04812010-08-23 10:46:47 +0200229 goto out;
230 }
231
Zhu Yib481de92007-09-25 17:54:57 -0700232 /* new beacon skb is allocated every time; dispose previous.*/
Johannes Berg77834542010-10-04 05:50:36 -0700233 dev_kfree_skb(priv->beacon_skb);
Zhu Yib481de92007-09-25 17:54:57 -0700234
Johannes Berg12e934d2010-10-04 05:50:06 -0700235 priv->beacon_skb = beacon;
Zhu Yib481de92007-09-25 17:54:57 -0700236
Johannes Berg2295c662010-10-23 09:15:41 -0700237 iwlagn_send_beacon_cmd(priv);
Johannes Berg76d04812010-08-23 10:46:47 +0200238 out:
239 mutex_unlock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -0700240}
241
Wey-Yi Guyfbba9412010-08-23 07:57:10 -0700242static void iwl_bg_bt_runtime_config(struct work_struct *work)
243{
244 struct iwl_priv *priv =
245 container_of(work, struct iwl_priv, bt_runtime_config);
246
247 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
248 return;
249
250 /* dont send host command if rf-kill is on */
251 if (!iwl_is_ready_rf(priv))
252 return;
253 priv->cfg->ops->hcmd->send_bt_config(priv);
254}
255
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700256static void iwl_bg_bt_full_concurrency(struct work_struct *work)
257{
258 struct iwl_priv *priv =
259 container_of(work, struct iwl_priv, bt_full_concurrency);
Johannes Berg246ed352010-08-23 10:46:32 +0200260 struct iwl_rxon_context *ctx;
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700261
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +0200262 mutex_lock(&priv->mutex);
263
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700264 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +0200265 goto out;
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700266
267 /* dont send host command if rf-kill is on */
268 if (!iwl_is_ready_rf(priv))
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +0200269 goto out;
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700270
271 IWL_DEBUG_INFO(priv, "BT coex in %s mode\n",
272 priv->bt_full_concurrent ?
273 "full concurrency" : "3-wire");
274
275 /*
276 * LQ & RXON updated cmds must be sent before BT Config cmd
277 * to avoid 3-wire collisions
278 */
Johannes Berg246ed352010-08-23 10:46:32 +0200279 for_each_context(priv, ctx) {
280 if (priv->cfg->ops->hcmd->set_rxon_chain)
281 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
282 iwlcore_commit_rxon(priv, ctx);
283 }
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700284
285 priv->cfg->ops->hcmd->send_bt_config(priv);
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +0200286out:
287 mutex_unlock(&priv->mutex);
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700288}
289
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800290/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700291 * iwl_bg_statistics_periodic - Timer callback to queue statistics
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800292 *
293 * This callback is provided in order to send a statistics request.
294 *
295 * This timer function is continually reset to execute within
296 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
297 * was received. We need to ensure we receive the statistics in order
298 * to update the temperature used for calibrating the TXPOWER.
299 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700300static void iwl_bg_statistics_periodic(unsigned long data)
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800301{
302 struct iwl_priv *priv = (struct iwl_priv *)data;
303
304 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
305 return;
306
Mohamed Abbas61780ee2008-10-29 14:05:49 -0700307 /* dont send host command if rf-kill is on */
308 if (!iwl_is_ready_rf(priv))
309 return;
310
Wey-Yi Guyef8d5522009-11-13 11:56:28 -0800311 iwl_send_statistics_request(priv, CMD_ASYNC, false);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800312}
313
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800314
315static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base,
316 u32 start_idx, u32 num_events,
317 u32 mode)
318{
319 u32 i;
320 u32 ptr; /* SRAM byte address of log data */
321 u32 ev, time, data; /* event log data */
322 unsigned long reg_flags;
323
324 if (mode == 0)
325 ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32));
326 else
327 ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32));
328
329 /* Make sure device is powered up for SRAM reads */
330 spin_lock_irqsave(&priv->reg_lock, reg_flags);
331 if (iwl_grab_nic_access(priv)) {
332 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
333 return;
334 }
335
336 /* Set starting address; reads will auto-increment */
Johannes Berg02a7fa02011-04-05 09:42:12 -0700337 iwl_write32(priv, HBUS_TARG_MEM_RADDR, ptr);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800338 rmb();
339
340 /*
341 * "time" is actually "data" for mode 0 (no timestamp).
342 * place event id # at far right for easier visual parsing.
343 */
344 for (i = 0; i < num_events; i++) {
Johannes Berg02a7fa02011-04-05 09:42:12 -0700345 ev = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
346 time = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800347 if (mode == 0) {
348 trace_iwlwifi_dev_ucode_cont_event(priv,
349 0, time, ev);
350 } else {
Johannes Berg02a7fa02011-04-05 09:42:12 -0700351 data = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800352 trace_iwlwifi_dev_ucode_cont_event(priv,
353 time, data, ev);
354 }
355 }
356 /* Allow device to power down */
357 iwl_release_nic_access(priv);
358 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
359}
360
Johannes Berg875295f2010-01-22 14:22:55 -0800361static void iwl_continuous_event_trace(struct iwl_priv *priv)
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800362{
363 u32 capacity; /* event log capacity in # entries */
364 u32 base; /* SRAM byte address of event log header */
365 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
366 u32 num_wraps; /* # times uCode wrapped to top of log */
367 u32 next_entry; /* index of next entry to be written by uCode */
368
Johannes Bergd7d57832011-04-05 09:42:04 -0700369 base = priv->device_pointers.error_event_table;
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800370 if (priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
371 capacity = iwl_read_targ_mem(priv, base);
372 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
373 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
374 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
375 } else
376 return;
377
378 if (num_wraps == priv->event_log.num_wraps) {
379 iwl_print_cont_event_trace(priv,
380 base, priv->event_log.next_entry,
381 next_entry - priv->event_log.next_entry,
382 mode);
383 priv->event_log.non_wraps_count++;
384 } else {
385 if ((num_wraps - priv->event_log.num_wraps) > 1)
386 priv->event_log.wraps_more_count++;
387 else
388 priv->event_log.wraps_once_count++;
389 trace_iwlwifi_dev_ucode_wrap_event(priv,
390 num_wraps - priv->event_log.num_wraps,
391 next_entry, priv->event_log.next_entry);
392 if (next_entry < priv->event_log.next_entry) {
393 iwl_print_cont_event_trace(priv, base,
394 priv->event_log.next_entry,
395 capacity - priv->event_log.next_entry,
396 mode);
397
398 iwl_print_cont_event_trace(priv, base, 0,
399 next_entry, mode);
400 } else {
401 iwl_print_cont_event_trace(priv, base,
402 next_entry, capacity - next_entry,
403 mode);
404
405 iwl_print_cont_event_trace(priv, base, 0,
406 next_entry, mode);
407 }
408 }
409 priv->event_log.num_wraps = num_wraps;
410 priv->event_log.next_entry = next_entry;
411}
412
413/**
414 * iwl_bg_ucode_trace - Timer callback to log ucode event
415 *
416 * The timer is continually set to execute every
417 * UCODE_TRACE_PERIOD milliseconds after the last timer expired
418 * this function is to perform continuous uCode event logging operation
419 * if enabled
420 */
421static void iwl_bg_ucode_trace(unsigned long data)
422{
423 struct iwl_priv *priv = (struct iwl_priv *)data;
424
425 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
426 return;
427
428 if (priv->event_log.ucode_trace) {
429 iwl_continuous_event_trace(priv);
430 /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
431 mod_timer(&priv->ucode_trace,
432 jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
433 }
434}
435
Wey-Yi Guy65550632010-06-24 13:18:35 -0700436static void iwl_bg_tx_flush(struct work_struct *work)
437{
438 struct iwl_priv *priv =
439 container_of(work, struct iwl_priv, tx_flush);
440
441 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
442 return;
443
444 /* do nothing if rf-kill is on */
445 if (!iwl_is_ready_rf(priv))
446 return;
447
448 if (priv->cfg->ops->lib->txfifo_flush) {
449 IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n");
450 iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
451 }
452}
453
Zhu Yib481de92007-09-25 17:54:57 -0700454/**
Tomas Winklera55360e2008-05-05 10:22:28 +0800455 * iwl_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -0700456 *
457 * Uses the priv->rx_handlers callback function array to invoke
458 * the appropriate handlers, including command responses,
459 * frame-received notifications, and other notifications.
460 */
Johannes Bergf945f102011-01-04 16:21:59 -0800461static void iwl_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700462{
Tomas Winklera55360e2008-05-05 10:22:28 +0800463 struct iwl_rx_mem_buffer *rxb;
Tomas Winklerdb11d632008-05-05 10:22:33 +0800464 struct iwl_rx_packet *pkt;
Tomas Winklera55360e2008-05-05 10:22:28 +0800465 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -0700466 u32 r, i;
467 int reclaim;
468 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800469 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -0800470 u32 count = 8;
Mohamed Abbas4752c932009-05-22 11:01:51 -0700471 int total_empty;
Zhu Yib481de92007-09-25 17:54:57 -0700472
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800473 /* uCode's read index (stored in shared DRAM) indicates the last Rx
474 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8d864222008-11-07 09:58:39 -0800475 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -0700476 i = rxq->read;
477
478 /* Rx interrupt, but nothing sent from uCode */
479 if (i == r)
Tomas Winklere1623442009-01-27 14:27:56 -0800480 IWL_DEBUG_RX(priv, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -0700481
Mohamed Abbas4752c932009-05-22 11:01:51 -0700482 /* calculate total frames need to be restock after handling RX */
Zhu Yi73005152009-10-23 13:42:32 -0700483 total_empty = r - rxq->write_actual;
Mohamed Abbas4752c932009-05-22 11:01:51 -0700484 if (total_empty < 0)
485 total_empty += RX_QUEUE_SIZE;
486
487 if (total_empty > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800488 fill_rx = 1;
489
Zhu Yib481de92007-09-25 17:54:57 -0700490 while (i != r) {
Johannes Bergf4989d92010-05-28 04:08:30 -0700491 int len;
492
Zhu Yib481de92007-09-25 17:54:57 -0700493 rxb = rxq->queue[i];
494
Ben Cahill9fbab512007-11-29 11:09:47 +0800495 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -0700496 * then a bug has been introduced in the queue refilling
497 * routines -- catch it here */
Johannes Berg3e41ace2011-04-18 09:12:37 -0700498 if (WARN_ON(rxb == NULL)) {
499 i = (i + 1) & RX_QUEUE_MASK;
500 continue;
501 }
Zhu Yib481de92007-09-25 17:54:57 -0700502
503 rxq->queue[i] = NULL;
504
Zhu Yi2f301222009-10-09 17:19:45 +0800505 pci_unmap_page(priv->pci_dev, rxb->page_dma,
506 PAGE_SIZE << priv->hw_params.rx_page_order,
507 PCI_DMA_FROMDEVICE);
508 pkt = rxb_addr(rxb);
Zhu Yib481de92007-09-25 17:54:57 -0700509
Johannes Bergf4989d92010-05-28 04:08:30 -0700510 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
511 len += sizeof(u32); /* account for status word */
512 trace_iwlwifi_dev_rx(priv, pkt, len);
Johannes Bergbe1a71a2009-10-02 13:44:02 -0700513
Zhu Yib481de92007-09-25 17:54:57 -0700514 /* Reclaim a command buffer only if this packet is a response
515 * to a (driver-originated) command.
516 * If the packet (e.g. Rx frame) originated from uCode,
517 * there is no command buffer to reclaim.
518 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
519 * but apparently a few don't get set; catch them here. */
520 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
521 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
Tomas Winkler857485c2008-03-21 13:53:44 -0700522 (pkt->hdr.cmd != REPLY_RX) &&
Daniel Halperin7dddaf12008-10-23 23:48:58 -0700523 (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) &&
Zhu Yicfe01702007-09-27 11:27:31 +0800524 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
Zhu Yib481de92007-09-25 17:54:57 -0700525 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
526 (pkt->hdr.cmd != REPLY_TX);
527
Johannes Berg7194207c2011-01-04 16:22:00 -0800528 /*
529 * Do the notification wait before RX handlers so
530 * even if the RX handler consumes the RXB we have
531 * access to it in the notification wait entry.
532 */
533 if (!list_empty(&priv->_agn.notif_waits)) {
534 struct iwl_notification_wait *w;
535
536 spin_lock(&priv->_agn.notif_wait_lock);
537 list_for_each_entry(w, &priv->_agn.notif_waits, list) {
538 if (w->cmd == pkt->hdr.cmd) {
539 w->triggered = true;
540 if (w->fn)
Johannes Berg09f18af2011-04-13 03:14:47 -0700541 w->fn(priv, pkt, w->fn_data);
Johannes Berg7194207c2011-01-04 16:22:00 -0800542 }
543 }
544 spin_unlock(&priv->_agn.notif_wait_lock);
545
546 wake_up_all(&priv->_agn.notif_waitq);
547 }
Cindy H. Kao4613e722011-05-06 10:40:15 -0700548 if (priv->pre_rx_handler)
549 priv->pre_rx_handler(priv, rxb);
Johannes Berg7194207c2011-01-04 16:22:00 -0800550
Zhu Yib481de92007-09-25 17:54:57 -0700551 /* Based on type of command response or notification,
552 * handle those that need handling via function in
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700553 * rx_handlers table. See iwl_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -0700554 if (priv->rx_handlers[pkt->hdr.cmd]) {
Tomas Winklere1623442009-01-27 14:27:56 -0800555 IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r,
Ester Kummerf3d67992008-05-06 11:05:12 +0800556 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700557 priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
Zhu Yi29b1b262009-10-23 13:42:25 -0700558 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -0700559 } else {
560 /* No handling needed */
Tomas Winklere1623442009-01-27 14:27:56 -0800561 IWL_DEBUG_RX(priv,
Zhu Yib481de92007-09-25 17:54:57 -0700562 "r %d i %d No handler needed for %s, 0x%02x\n",
563 r, i, get_cmd_string(pkt->hdr.cmd),
564 pkt->hdr.cmd);
565 }
566
Zhu Yi29b1b262009-10-23 13:42:25 -0700567 /*
568 * XXX: After here, we should always check rxb->page
569 * against NULL before touching it or its virtual
570 * memory (pkt). Because some rx_handler might have
571 * already taken or freed the pages.
572 */
573
Zhu Yib481de92007-09-25 17:54:57 -0700574 if (reclaim) {
Zhu Yi2f301222009-10-09 17:19:45 +0800575 /* Invoke any callbacks, transfer the buffer to caller,
576 * and fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -0700577 * as we reclaim the driver command queue */
Zhu Yi29b1b262009-10-23 13:42:25 -0700578 if (rxb->page)
Tomas Winkler17b88922008-05-29 16:35:12 +0800579 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -0700580 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800581 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -0700582 }
583
Zhu Yi73005152009-10-23 13:42:32 -0700584 /* Reuse the page if possible. For notification packets and
585 * SKBs that fail to Rx correctly, add them back into the
586 * rx_free list for reuse later. */
Zhu Yib481de92007-09-25 17:54:57 -0700587 spin_lock_irqsave(&rxq->lock, flags);
Zhu Yi73005152009-10-23 13:42:32 -0700588 if (rxb->page != NULL) {
589 rxb->page_dma = pci_map_page(priv->pci_dev, rxb->page,
590 0, PAGE_SIZE << priv->hw_params.rx_page_order,
591 PCI_DMA_FROMDEVICE);
592 list_add_tail(&rxb->list, &rxq->rx_free);
593 rxq->free_count++;
594 } else
595 list_add_tail(&rxb->list, &rxq->rx_used);
596
Zhu Yib481de92007-09-25 17:54:57 -0700597 spin_unlock_irqrestore(&rxq->lock, flags);
Zhu Yi73005152009-10-23 13:42:32 -0700598
Zhu Yib481de92007-09-25 17:54:57 -0700599 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800600 /* If there are a lot of unused frames,
601 * restock the Rx queue so ucode wont assert. */
602 if (fill_rx) {
603 count++;
604 if (count >= 8) {
Zhu Yi73005152009-10-23 13:42:32 -0700605 rxq->read = i;
Wey-Yi Guy54b81552010-03-17 13:34:35 -0700606 iwlagn_rx_replenish_now(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800607 count = 0;
608 }
609 }
Zhu Yib481de92007-09-25 17:54:57 -0700610 }
611
612 /* Backtrack one entry */
Zhu Yi73005152009-10-23 13:42:32 -0700613 rxq->read = i;
Mohamed Abbas4752c932009-05-22 11:01:51 -0700614 if (fill_rx)
Wey-Yi Guy54b81552010-03-17 13:34:35 -0700615 iwlagn_rx_replenish_now(priv);
Mohamed Abbas4752c932009-05-22 11:01:51 -0700616 else
Wey-Yi Guy54b81552010-03-17 13:34:35 -0700617 iwlagn_rx_queue_restock(priv);
Tomas Winklera55360e2008-05-05 10:22:28 +0800618}
Tomas Winklera55360e2008-05-05 10:22:28 +0800619
Mohamed Abbasef850d72009-05-22 11:01:50 -0700620/* tasklet for iwlagn interrupt */
621static void iwl_irq_tasklet(struct iwl_priv *priv)
622{
623 u32 inta = 0;
624 u32 handled = 0;
625 unsigned long flags;
Ben Cahill87569902009-11-06 14:53:01 -0800626 u32 i;
Mohamed Abbasef850d72009-05-22 11:01:50 -0700627#ifdef CONFIG_IWLWIFI_DEBUG
628 u32 inta_mask;
629#endif
630
631 spin_lock_irqsave(&priv->lock, flags);
632
633 /* Ack/clear/reset pending uCode interrupts.
634 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
635 */
Shanyu Zhao48a6be62010-03-16 10:22:26 -0700636 /* There is a hardware bug in the interrupt mask function that some
637 * interrupts (i.e. CSR_INT_BIT_SCD) can still be generated even if
638 * they are disabled in the CSR_INT_MASK register. Furthermore the
639 * ICT interrupt handling mechanism has another bug that might cause
640 * these unmasked interrupts fail to be detected. We workaround the
641 * hardware bugs here by ACKing all the possible interrupts so that
642 * interrupt coalescing can still be achieved.
643 */
David S. Miller4a35ecf2010-04-06 23:53:30 -0700644 iwl_write32(priv, CSR_INT, priv->_agn.inta | ~priv->inta_mask);
Mohamed Abbasef850d72009-05-22 11:01:50 -0700645
Johannes Berga4c8b2a2010-01-21 06:25:54 -0800646 inta = priv->_agn.inta;
Mohamed Abbasef850d72009-05-22 11:01:50 -0700647
648#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -0700649 if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
Mohamed Abbasef850d72009-05-22 11:01:50 -0700650 /* just for debug */
651 inta_mask = iwl_read32(priv, CSR_INT_MASK);
652 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x\n ",
653 inta, inta_mask);
654 }
655#endif
Zhu Yi2f301222009-10-09 17:19:45 +0800656
657 spin_unlock_irqrestore(&priv->lock, flags);
658
Johannes Berga4c8b2a2010-01-21 06:25:54 -0800659 /* saved interrupt in inta variable now we can reset priv->_agn.inta */
660 priv->_agn.inta = 0;
Mohamed Abbasef850d72009-05-22 11:01:50 -0700661
662 /* Now service all interrupt bits discovered above. */
663 if (inta & CSR_INT_BIT_HW_ERR) {
Reinette Chatre58dba722009-07-17 09:30:25 -0700664 IWL_ERR(priv, "Hardware error detected. Restarting.\n");
Mohamed Abbasef850d72009-05-22 11:01:50 -0700665
666 /* Tell the device to stop sending interrupts */
667 iwl_disable_interrupts(priv);
668
669 priv->isr_stats.hw++;
670 iwl_irq_handle_error(priv);
671
672 handled |= CSR_INT_BIT_HW_ERR;
673
Mohamed Abbasef850d72009-05-22 11:01:50 -0700674 return;
675 }
676
677#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -0700678 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Mohamed Abbasef850d72009-05-22 11:01:50 -0700679 /* NIC fires this, but we don't use it, redundant with WAKEUP */
680 if (inta & CSR_INT_BIT_SCD) {
681 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
682 "the frame/frames.\n");
683 priv->isr_stats.sch++;
684 }
685
686 /* Alive notification via Rx interrupt will do the real work */
687 if (inta & CSR_INT_BIT_ALIVE) {
688 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
689 priv->isr_stats.alive++;
690 }
691 }
692#endif
693 /* Safely ignore these bits for debug checks below */
694 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
695
696 /* HW RF KILL switch toggled */
697 if (inta & CSR_INT_BIT_RF_KILL) {
698 int hw_rf_kill = 0;
699 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
700 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
701 hw_rf_kill = 1;
702
Reinette Chatre4c423a22009-07-17 09:30:26 -0700703 IWL_WARN(priv, "RF_KILL bit toggled to %s.\n",
Mohamed Abbasef850d72009-05-22 11:01:50 -0700704 hw_rf_kill ? "disable radio" : "enable radio");
705
706 priv->isr_stats.rfkill++;
707
708 /* driver only loads ucode once setting the interface up.
709 * the driver allows loading the ucode even if the radio
710 * is killed. Hence update the killswitch state here. The
711 * rfkill handler will care about restarting if needed.
712 */
713 if (!test_bit(STATUS_ALIVE, &priv->status)) {
714 if (hw_rf_kill)
715 set_bit(STATUS_RF_KILL_HW, &priv->status);
716 else
717 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Johannes Berga60e77e2009-06-04 18:26:06 +0200718 wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
Mohamed Abbasef850d72009-05-22 11:01:50 -0700719 }
720
721 handled |= CSR_INT_BIT_RF_KILL;
722 }
723
724 /* Chip got too hot and stopped itself */
725 if (inta & CSR_INT_BIT_CT_KILL) {
726 IWL_ERR(priv, "Microcode CT kill error detected.\n");
727 priv->isr_stats.ctkill++;
728 handled |= CSR_INT_BIT_CT_KILL;
729 }
730
731 /* Error detected by uCode */
732 if (inta & CSR_INT_BIT_SW_ERR) {
733 IWL_ERR(priv, "Microcode SW error detected. "
734 " Restarting 0x%X.\n", inta);
735 priv->isr_stats.sw++;
Mohamed Abbasef850d72009-05-22 11:01:50 -0700736 iwl_irq_handle_error(priv);
737 handled |= CSR_INT_BIT_SW_ERR;
738 }
739
740 /* uCode wakes up after power-down sleep */
741 if (inta & CSR_INT_BIT_WAKEUP) {
742 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
743 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Ben Cahill87569902009-11-06 14:53:01 -0800744 for (i = 0; i < priv->hw_params.max_txq_num; i++)
745 iwl_txq_update_write_ptr(priv, &priv->txq[i]);
Mohamed Abbasef850d72009-05-22 11:01:50 -0700746
747 priv->isr_stats.wakeup++;
748
749 handled |= CSR_INT_BIT_WAKEUP;
750 }
751
752 /* All uCode command responses, including Tx command responses,
753 * Rx "responses" (frame-received notification), and other
754 * notifications from uCode come through here*/
Mohamed Abbas40cefda2009-05-22 11:01:52 -0700755 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX |
756 CSR_INT_BIT_RX_PERIODIC)) {
Mohamed Abbasef850d72009-05-22 11:01:50 -0700757 IWL_DEBUG_ISR(priv, "Rx interrupt\n");
Mohamed Abbas40cefda2009-05-22 11:01:52 -0700758 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
759 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
760 iwl_write32(priv, CSR_FH_INT_STATUS,
Wey-Yi Guyf7d046f2011-03-22 08:05:37 -0700761 CSR_FH_INT_RX_MASK);
Mohamed Abbas40cefda2009-05-22 11:01:52 -0700762 }
763 if (inta & CSR_INT_BIT_RX_PERIODIC) {
764 handled |= CSR_INT_BIT_RX_PERIODIC;
765 iwl_write32(priv, CSR_INT, CSR_INT_BIT_RX_PERIODIC);
766 }
767 /* Sending RX interrupt require many steps to be done in the
768 * the device:
769 * 1- write interrupt to current index in ICT table.
770 * 2- dma RX frame.
771 * 3- update RX shared data to indicate last write index.
772 * 4- send interrupt.
773 * This could lead to RX race, driver could receive RX interrupt
Ben Cahill74ba67e2009-11-20 12:04:53 -0800774 * but the shared data changes does not reflect this;
775 * periodic interrupt will detect any dangling Rx activity.
Mohamed Abbas40cefda2009-05-22 11:01:52 -0700776 */
Ben Cahill74ba67e2009-11-20 12:04:53 -0800777
778 /* Disable periodic interrupt; we use it as just a one-shot. */
779 iwl_write8(priv, CSR_INT_PERIODIC_REG,
Mohamed Abbas40cefda2009-05-22 11:01:52 -0700780 CSR_INT_PERIODIC_DIS);
Mohamed Abbasef850d72009-05-22 11:01:50 -0700781 iwl_rx_handle(priv);
Ben Cahill74ba67e2009-11-20 12:04:53 -0800782
783 /*
784 * Enable periodic interrupt in 8 msec only if we received
785 * real RX interrupt (instead of just periodic int), to catch
786 * any dangling Rx interrupt. If it was just the periodic
787 * interrupt, there was no dangling Rx activity, and no need
788 * to extend the periodic interrupt; one-shot is enough.
789 */
Mohamed Abbas40cefda2009-05-22 11:01:52 -0700790 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX))
Ben Cahill74ba67e2009-11-20 12:04:53 -0800791 iwl_write8(priv, CSR_INT_PERIODIC_REG,
Mohamed Abbas40cefda2009-05-22 11:01:52 -0700792 CSR_INT_PERIODIC_ENA);
793
Mohamed Abbasef850d72009-05-22 11:01:50 -0700794 priv->isr_stats.rx++;
Mohamed Abbasef850d72009-05-22 11:01:50 -0700795 }
796
Ben Cahillc72cd192009-10-30 14:36:08 -0700797 /* This "Tx" DMA channel is used only for loading uCode */
Mohamed Abbasef850d72009-05-22 11:01:50 -0700798 if (inta & CSR_INT_BIT_FH_TX) {
Wey-Yi Guyf7d046f2011-03-22 08:05:37 -0700799 iwl_write32(priv, CSR_FH_INT_STATUS, CSR_FH_INT_TX_MASK);
Ben Cahillc72cd192009-10-30 14:36:08 -0700800 IWL_DEBUG_ISR(priv, "uCode load interrupt\n");
Mohamed Abbasef850d72009-05-22 11:01:50 -0700801 priv->isr_stats.tx++;
802 handled |= CSR_INT_BIT_FH_TX;
Ben Cahillc72cd192009-10-30 14:36:08 -0700803 /* Wake up uCode load routine, now that load is complete */
Mohamed Abbasef850d72009-05-22 11:01:50 -0700804 priv->ucode_write_complete = 1;
805 wake_up_interruptible(&priv->wait_command_queue);
806 }
807
808 if (inta & ~handled) {
809 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
810 priv->isr_stats.unhandled++;
811 }
812
Mohamed Abbas40cefda2009-05-22 11:01:52 -0700813 if (inta & ~(priv->inta_mask)) {
Mohamed Abbasef850d72009-05-22 11:01:50 -0700814 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Mohamed Abbas40cefda2009-05-22 11:01:52 -0700815 inta & ~priv->inta_mask);
Mohamed Abbasef850d72009-05-22 11:01:50 -0700816 }
817
Mohamed Abbasef850d72009-05-22 11:01:50 -0700818 /* Re-enable all interrupts */
Justin P. Mattock62e45c12010-12-30 15:07:56 -0800819 /* only Re-enable if disabled by irq */
Mohamed Abbasef850d72009-05-22 11:01:50 -0700820 if (test_bit(STATUS_INT_ENABLED, &priv->status))
821 iwl_enable_interrupts(priv);
Don Fry3dd823e2011-02-06 09:29:45 -0800822 /* Re-enable RF_KILL if it occurred */
823 else if (handled & CSR_INT_BIT_RF_KILL)
824 iwl_enable_rfkill_int(priv);
Mohamed Abbasef850d72009-05-22 11:01:50 -0700825}
826
Emmanuel Grumbach7d476182010-05-23 00:14:08 -0700827/*****************************************************************************
828 *
829 * sysfs attributes
830 *
831 *****************************************************************************/
832
833#ifdef CONFIG_IWLWIFI_DEBUG
834
835/*
836 * The following adds a new attribute to the sysfs representation
837 * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
838 * used for controlling the debug level.
839 *
840 * See the level definitions in iwl for details.
841 *
842 * The debug_level being managed using sysfs below is a per device debug
843 * level that is used instead of the global debug level if it (the per
844 * device debug level) is set.
845 */
846static ssize_t show_debug_level(struct device *d,
847 struct device_attribute *attr, char *buf)
848{
849 struct iwl_priv *priv = dev_get_drvdata(d);
850 return sprintf(buf, "0x%08X\n", iwl_get_debug_level(priv));
851}
852static ssize_t store_debug_level(struct device *d,
853 struct device_attribute *attr,
854 const char *buf, size_t count)
855{
856 struct iwl_priv *priv = dev_get_drvdata(d);
857 unsigned long val;
858 int ret;
859
860 ret = strict_strtoul(buf, 0, &val);
861 if (ret)
862 IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf);
863 else {
864 priv->debug_level = val;
865 if (iwl_alloc_traffic_mem(priv))
866 IWL_ERR(priv,
867 "Not enough memory to generate traffic log\n");
868 }
869 return strnlen(buf, count);
870}
871
872static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
873 show_debug_level, store_debug_level);
874
875
876#endif /* CONFIG_IWLWIFI_DEBUG */
877
878
879static ssize_t show_temperature(struct device *d,
880 struct device_attribute *attr, char *buf)
881{
882 struct iwl_priv *priv = dev_get_drvdata(d);
883
884 if (!iwl_is_alive(priv))
885 return -EAGAIN;
886
887 return sprintf(buf, "%d\n", priv->temperature);
888}
889
890static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
891
892static ssize_t show_tx_power(struct device *d,
893 struct device_attribute *attr, char *buf)
894{
895 struct iwl_priv *priv = dev_get_drvdata(d);
896
897 if (!iwl_is_ready_rf(priv))
898 return sprintf(buf, "off\n");
899 else
900 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
901}
902
903static ssize_t store_tx_power(struct device *d,
904 struct device_attribute *attr,
905 const char *buf, size_t count)
906{
907 struct iwl_priv *priv = dev_get_drvdata(d);
908 unsigned long val;
909 int ret;
910
911 ret = strict_strtoul(buf, 10, &val);
912 if (ret)
913 IWL_INFO(priv, "%s is not in decimal form.\n", buf);
914 else {
915 ret = iwl_set_tx_power(priv, val, false);
916 if (ret)
917 IWL_ERR(priv, "failed setting tx power (0x%d).\n",
918 ret);
919 else
920 ret = count;
921 }
922 return ret;
923}
924
925static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
926
Emmanuel Grumbach7d476182010-05-23 00:14:08 -0700927static struct attribute *iwl_sysfs_entries[] = {
928 &dev_attr_temperature.attr,
929 &dev_attr_tx_power.attr,
Emmanuel Grumbach7d476182010-05-23 00:14:08 -0700930#ifdef CONFIG_IWLWIFI_DEBUG
931 &dev_attr_debug_level.attr,
932#endif
933 NULL
934};
935
936static struct attribute_group iwl_attribute_group = {
937 .name = NULL, /* put in device directory */
938 .attrs = iwl_sysfs_entries,
939};
940
Zhu Yib481de92007-09-25 17:54:57 -0700941/******************************************************************************
942 *
943 * uCode download functions
944 *
945 ******************************************************************************/
946
Johannes Bergdbf28e212011-04-16 08:29:24 -0700947static void iwl_free_fw_desc(struct pci_dev *pci_dev, struct fw_desc *desc)
948{
949 if (desc->v_addr)
950 dma_free_coherent(&pci_dev->dev, desc->len,
951 desc->v_addr, desc->p_addr);
952 desc->v_addr = NULL;
953 desc->len = 0;
954}
955
956static void iwl_free_fw_img(struct pci_dev *pci_dev, struct fw_img *img)
957{
958 iwl_free_fw_desc(pci_dev, &img->code);
959 iwl_free_fw_desc(pci_dev, &img->data);
960}
961
962static int iwl_alloc_fw_desc(struct pci_dev *pci_dev, struct fw_desc *desc,
963 const void *data, size_t len)
964{
965 if (!len) {
966 desc->v_addr = NULL;
967 return -EINVAL;
968 }
969
970 desc->v_addr = dma_alloc_coherent(&pci_dev->dev, len,
971 &desc->p_addr, GFP_KERNEL);
972 if (!desc->v_addr)
973 return -ENOMEM;
974 desc->len = len;
975 memcpy(desc->v_addr, data, len);
976 return 0;
977}
978
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700979static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700980{
Johannes Bergdbf28e212011-04-16 08:29:24 -0700981 iwl_free_fw_img(priv->pci_dev, &priv->ucode_rt);
982 iwl_free_fw_img(priv->pci_dev, &priv->ucode_init);
Zhu Yib481de92007-09-25 17:54:57 -0700983}
984
Johannes Bergdd7a2502010-04-28 23:33:10 -0700985struct iwlagn_ucode_capabilities {
986 u32 max_probe_length;
Wey-Yi Guy6a822d02010-07-13 17:13:15 -0700987 u32 standard_phy_calibration_size;
Johannes Berg3997ff32011-04-05 09:42:02 -0700988 u32 flags;
Johannes Bergdd7a2502010-04-28 23:33:10 -0700989};
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +0800990
Johannes Bergb08dfd02010-01-29 11:54:56 -0800991static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context);
Johannes Bergdd7a2502010-04-28 23:33:10 -0700992static int iwl_mac_setup_register(struct iwl_priv *priv,
993 struct iwlagn_ucode_capabilities *capa);
Johannes Bergb08dfd02010-01-29 11:54:56 -0800994
Jay Sternberg39396082010-08-12 10:24:07 -0700995#define UCODE_EXPERIMENTAL_INDEX 100
996#define UCODE_EXPERIMENTAL_TAG "exp"
997
Johannes Bergb08dfd02010-01-29 11:54:56 -0800998static int __must_check iwl_request_firmware(struct iwl_priv *priv, bool first)
Zhu Yib481de92007-09-25 17:54:57 -0700999{
Reinette Chatrea0987a82008-12-02 12:14:06 -08001000 const char *name_pre = priv->cfg->fw_name_pre;
Jay Sternberg39396082010-08-12 10:24:07 -07001001 char tag[8];
Johannes Bergb08dfd02010-01-29 11:54:56 -08001002
Jay Sternberg39396082010-08-12 10:24:07 -07001003 if (first) {
1004#ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE
1005 priv->fw_index = UCODE_EXPERIMENTAL_INDEX;
1006 strcpy(tag, UCODE_EXPERIMENTAL_TAG);
1007 } else if (priv->fw_index == UCODE_EXPERIMENTAL_INDEX) {
1008#endif
Johannes Bergb08dfd02010-01-29 11:54:56 -08001009 priv->fw_index = priv->cfg->ucode_api_max;
Jay Sternberg39396082010-08-12 10:24:07 -07001010 sprintf(tag, "%d", priv->fw_index);
1011 } else {
Johannes Bergb08dfd02010-01-29 11:54:56 -08001012 priv->fw_index--;
Jay Sternberg39396082010-08-12 10:24:07 -07001013 sprintf(tag, "%d", priv->fw_index);
1014 }
Johannes Bergb08dfd02010-01-29 11:54:56 -08001015
1016 if (priv->fw_index < priv->cfg->ucode_api_min) {
1017 IWL_ERR(priv, "no suitable firmware found!\n");
1018 return -ENOENT;
1019 }
1020
Jay Sternberg39396082010-08-12 10:24:07 -07001021 sprintf(priv->firmware_name, "%s%s%s", name_pre, tag, ".ucode");
Johannes Bergb08dfd02010-01-29 11:54:56 -08001022
Jay Sternberg39396082010-08-12 10:24:07 -07001023 IWL_DEBUG_INFO(priv, "attempting to load firmware %s'%s'\n",
1024 (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
1025 ? "EXPERIMENTAL " : "",
Johannes Bergb08dfd02010-01-29 11:54:56 -08001026 priv->firmware_name);
1027
1028 return request_firmware_nowait(THIS_MODULE, 1, priv->firmware_name,
1029 &priv->pci_dev->dev, GFP_KERNEL, priv,
1030 iwl_ucode_callback);
1031}
1032
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001033struct iwlagn_firmware_pieces {
Johannes Berg1fc35272011-04-05 09:41:57 -07001034 const void *inst, *data, *init, *init_data;
1035 size_t inst_size, data_size, init_size, init_data_size;
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001036
1037 u32 build;
Johannes Bergb2e640d42010-05-05 23:24:54 -07001038
1039 u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
1040 u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001041};
1042
1043static int iwlagn_load_legacy_firmware(struct iwl_priv *priv,
1044 const struct firmware *ucode_raw,
1045 struct iwlagn_firmware_pieces *pieces)
1046{
1047 struct iwl_ucode_header *ucode = (void *)ucode_raw->data;
1048 u32 api_ver, hdr_size;
1049 const u8 *src;
1050
1051 priv->ucode_ver = le32_to_cpu(ucode->ver);
1052 api_ver = IWL_UCODE_API(priv->ucode_ver);
1053
1054 switch (api_ver) {
1055 default:
Wey-Yi Guyf7d046f2011-03-22 08:05:37 -07001056 hdr_size = 28;
1057 if (ucode_raw->size < hdr_size) {
1058 IWL_ERR(priv, "File size too small!\n");
1059 return -EINVAL;
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001060 }
Wey-Yi Guyf7d046f2011-03-22 08:05:37 -07001061 pieces->build = le32_to_cpu(ucode->u.v2.build);
1062 pieces->inst_size = le32_to_cpu(ucode->u.v2.inst_size);
1063 pieces->data_size = le32_to_cpu(ucode->u.v2.data_size);
1064 pieces->init_size = le32_to_cpu(ucode->u.v2.init_size);
1065 pieces->init_data_size = le32_to_cpu(ucode->u.v2.init_data_size);
Wey-Yi Guyf7d046f2011-03-22 08:05:37 -07001066 src = ucode->u.v2.data;
1067 break;
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001068 case 0:
1069 case 1:
1070 case 2:
1071 hdr_size = 24;
1072 if (ucode_raw->size < hdr_size) {
1073 IWL_ERR(priv, "File size too small!\n");
1074 return -EINVAL;
1075 }
1076 pieces->build = 0;
1077 pieces->inst_size = le32_to_cpu(ucode->u.v1.inst_size);
1078 pieces->data_size = le32_to_cpu(ucode->u.v1.data_size);
1079 pieces->init_size = le32_to_cpu(ucode->u.v1.init_size);
1080 pieces->init_data_size = le32_to_cpu(ucode->u.v1.init_data_size);
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001081 src = ucode->u.v1.data;
1082 break;
1083 }
1084
1085 /* Verify size of file vs. image size info in file's header */
1086 if (ucode_raw->size != hdr_size + pieces->inst_size +
1087 pieces->data_size + pieces->init_size +
Johannes Berg1fc35272011-04-05 09:41:57 -07001088 pieces->init_data_size) {
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001089
1090 IWL_ERR(priv,
1091 "uCode file size %d does not match expected size\n",
1092 (int)ucode_raw->size);
1093 return -EINVAL;
1094 }
1095
1096 pieces->inst = src;
1097 src += pieces->inst_size;
1098 pieces->data = src;
1099 src += pieces->data_size;
1100 pieces->init = src;
1101 src += pieces->init_size;
1102 pieces->init_data = src;
1103 src += pieces->init_data_size;
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001104
1105 return 0;
1106}
1107
Johannes Bergdd7a2502010-04-28 23:33:10 -07001108static int iwlagn_wanted_ucode_alternative = 1;
1109
1110static int iwlagn_load_firmware(struct iwl_priv *priv,
1111 const struct firmware *ucode_raw,
1112 struct iwlagn_firmware_pieces *pieces,
1113 struct iwlagn_ucode_capabilities *capa)
1114{
1115 struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data;
1116 struct iwl_ucode_tlv *tlv;
1117 size_t len = ucode_raw->size;
1118 const u8 *data;
1119 int wanted_alternative = iwlagn_wanted_ucode_alternative, tmp;
1120 u64 alternatives;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001121 u32 tlv_len;
1122 enum iwl_ucode_tlv_type tlv_type;
1123 const u8 *tlv_data;
Johannes Bergdd7a2502010-04-28 23:33:10 -07001124
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001125 if (len < sizeof(*ucode)) {
1126 IWL_ERR(priv, "uCode has invalid length: %zd\n", len);
Johannes Bergdd7a2502010-04-28 23:33:10 -07001127 return -EINVAL;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001128 }
Johannes Bergdd7a2502010-04-28 23:33:10 -07001129
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001130 if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) {
1131 IWL_ERR(priv, "invalid uCode magic: 0X%x\n",
1132 le32_to_cpu(ucode->magic));
Johannes Bergdd7a2502010-04-28 23:33:10 -07001133 return -EINVAL;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001134 }
Johannes Bergdd7a2502010-04-28 23:33:10 -07001135
1136 /*
1137 * Check which alternatives are present, and "downgrade"
1138 * when the chosen alternative is not present, warning
1139 * the user when that happens. Some files may not have
1140 * any alternatives, so don't warn in that case.
1141 */
1142 alternatives = le64_to_cpu(ucode->alternatives);
1143 tmp = wanted_alternative;
1144 if (wanted_alternative > 63)
1145 wanted_alternative = 63;
1146 while (wanted_alternative && !(alternatives & BIT(wanted_alternative)))
1147 wanted_alternative--;
1148 if (wanted_alternative && wanted_alternative != tmp)
1149 IWL_WARN(priv,
1150 "uCode alternative %d not available, choosing %d\n",
1151 tmp, wanted_alternative);
1152
1153 priv->ucode_ver = le32_to_cpu(ucode->ver);
1154 pieces->build = le32_to_cpu(ucode->build);
1155 data = ucode->data;
1156
1157 len -= sizeof(*ucode);
1158
Johannes Berg704da532010-07-14 09:34:50 -07001159 while (len >= sizeof(*tlv)) {
Johannes Bergdd7a2502010-04-28 23:33:10 -07001160 u16 tlv_alt;
Johannes Bergdd7a2502010-04-28 23:33:10 -07001161
1162 len -= sizeof(*tlv);
1163 tlv = (void *)data;
1164
1165 tlv_len = le32_to_cpu(tlv->length);
1166 tlv_type = le16_to_cpu(tlv->type);
1167 tlv_alt = le16_to_cpu(tlv->alternative);
1168 tlv_data = tlv->data;
1169
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001170 if (len < tlv_len) {
1171 IWL_ERR(priv, "invalid TLV len: %zd/%u\n",
1172 len, tlv_len);
Johannes Bergdd7a2502010-04-28 23:33:10 -07001173 return -EINVAL;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001174 }
Johannes Bergdd7a2502010-04-28 23:33:10 -07001175 len -= ALIGN(tlv_len, 4);
1176 data += sizeof(*tlv) + ALIGN(tlv_len, 4);
1177
1178 /*
1179 * Alternative 0 is always valid.
1180 *
1181 * Skip alternative TLVs that are not selected.
1182 */
1183 if (tlv_alt != 0 && tlv_alt != wanted_alternative)
1184 continue;
1185
1186 switch (tlv_type) {
1187 case IWL_UCODE_TLV_INST:
1188 pieces->inst = tlv_data;
1189 pieces->inst_size = tlv_len;
1190 break;
1191 case IWL_UCODE_TLV_DATA:
1192 pieces->data = tlv_data;
1193 pieces->data_size = tlv_len;
1194 break;
1195 case IWL_UCODE_TLV_INIT:
1196 pieces->init = tlv_data;
1197 pieces->init_size = tlv_len;
1198 break;
1199 case IWL_UCODE_TLV_INIT_DATA:
1200 pieces->init_data = tlv_data;
1201 pieces->init_data_size = tlv_len;
1202 break;
1203 case IWL_UCODE_TLV_BOOT:
Johannes Berg1fc35272011-04-05 09:41:57 -07001204 IWL_ERR(priv, "Found unexpected BOOT ucode\n");
Johannes Bergdd7a2502010-04-28 23:33:10 -07001205 break;
1206 case IWL_UCODE_TLV_PROBE_MAX_LEN:
Johannes Berg704da532010-07-14 09:34:50 -07001207 if (tlv_len != sizeof(u32))
1208 goto invalid_tlv_len;
1209 capa->max_probe_length =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001210 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergdd7a2502010-04-28 23:33:10 -07001211 break;
Johannes Bergece9c4e2010-08-23 10:46:49 +02001212 case IWL_UCODE_TLV_PAN:
1213 if (tlv_len)
1214 goto invalid_tlv_len;
Johannes Berg3997ff32011-04-05 09:42:02 -07001215 capa->flags |= IWL_UCODE_TLV_FLAGS_PAN;
1216 break;
1217 case IWL_UCODE_TLV_FLAGS:
1218 /* must be at least one u32 */
1219 if (tlv_len < sizeof(u32))
1220 goto invalid_tlv_len;
1221 /* and a proper number of u32s */
1222 if (tlv_len % sizeof(u32))
1223 goto invalid_tlv_len;
1224 /*
1225 * This driver only reads the first u32 as
1226 * right now no more features are defined,
1227 * if that changes then either the driver
1228 * will not work with the new firmware, or
1229 * it'll not take advantage of new features.
1230 */
1231 capa->flags = le32_to_cpup((__le32 *)tlv_data);
Johannes Bergece9c4e2010-08-23 10:46:49 +02001232 break;
Johannes Bergb2e640d42010-05-05 23:24:54 -07001233 case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
Johannes Berg704da532010-07-14 09:34:50 -07001234 if (tlv_len != sizeof(u32))
1235 goto invalid_tlv_len;
1236 pieces->init_evtlog_ptr =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001237 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d42010-05-05 23:24:54 -07001238 break;
1239 case IWL_UCODE_TLV_INIT_EVTLOG_SIZE:
Johannes Berg704da532010-07-14 09:34:50 -07001240 if (tlv_len != sizeof(u32))
1241 goto invalid_tlv_len;
1242 pieces->init_evtlog_size =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001243 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d42010-05-05 23:24:54 -07001244 break;
1245 case IWL_UCODE_TLV_INIT_ERRLOG_PTR:
Johannes Berg704da532010-07-14 09:34:50 -07001246 if (tlv_len != sizeof(u32))
1247 goto invalid_tlv_len;
1248 pieces->init_errlog_ptr =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001249 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d42010-05-05 23:24:54 -07001250 break;
1251 case IWL_UCODE_TLV_RUNT_EVTLOG_PTR:
Johannes Berg704da532010-07-14 09:34:50 -07001252 if (tlv_len != sizeof(u32))
1253 goto invalid_tlv_len;
1254 pieces->inst_evtlog_ptr =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001255 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d42010-05-05 23:24:54 -07001256 break;
1257 case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE:
Johannes Berg704da532010-07-14 09:34:50 -07001258 if (tlv_len != sizeof(u32))
1259 goto invalid_tlv_len;
1260 pieces->inst_evtlog_size =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001261 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d42010-05-05 23:24:54 -07001262 break;
1263 case IWL_UCODE_TLV_RUNT_ERRLOG_PTR:
Johannes Berg704da532010-07-14 09:34:50 -07001264 if (tlv_len != sizeof(u32))
1265 goto invalid_tlv_len;
1266 pieces->inst_errlog_ptr =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001267 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d42010-05-05 23:24:54 -07001268 break;
Wey-Yi Guyc8312fa2010-06-28 13:05:17 -07001269 case IWL_UCODE_TLV_ENHANCE_SENS_TBL:
1270 if (tlv_len)
Johannes Berg704da532010-07-14 09:34:50 -07001271 goto invalid_tlv_len;
1272 priv->enhance_sensitivity_table = true;
Wey-Yi Guyc8312fa2010-06-28 13:05:17 -07001273 break;
Wey-Yi Guy6a822d02010-07-13 17:13:15 -07001274 case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE:
Johannes Berg704da532010-07-14 09:34:50 -07001275 if (tlv_len != sizeof(u32))
1276 goto invalid_tlv_len;
1277 capa->standard_phy_calibration_size =
Wey-Yi Guy6a822d02010-07-13 17:13:15 -07001278 le32_to_cpup((__le32 *)tlv_data);
1279 break;
Johannes Bergdd7a2502010-04-28 23:33:10 -07001280 default:
Johannes Berg6fc3ba92011-04-04 06:16:29 -07001281 IWL_DEBUG_INFO(priv, "unknown TLV: %d\n", tlv_type);
Johannes Bergdd7a2502010-04-28 23:33:10 -07001282 break;
1283 }
1284 }
1285
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001286 if (len) {
1287 IWL_ERR(priv, "invalid TLV after parsing: %zd\n", len);
1288 iwl_print_hex_dump(priv, IWL_DL_FW, (u8 *)data, len);
Johannes Berg704da532010-07-14 09:34:50 -07001289 return -EINVAL;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001290 }
Johannes Bergdd7a2502010-04-28 23:33:10 -07001291
Johannes Berg704da532010-07-14 09:34:50 -07001292 return 0;
1293
1294 invalid_tlv_len:
1295 IWL_ERR(priv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len);
1296 iwl_print_hex_dump(priv, IWL_DL_FW, tlv_data, tlv_len);
1297
1298 return -EINVAL;
Johannes Bergdd7a2502010-04-28 23:33:10 -07001299}
1300
Johannes Bergb08dfd02010-01-29 11:54:56 -08001301/**
1302 * iwl_ucode_callback - callback when firmware was loaded
1303 *
1304 * If loaded successfully, copies the firmware into buffers
1305 * for the card to fetch (via DMA).
1306 */
1307static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
1308{
1309 struct iwl_priv *priv = context;
1310 struct iwl_ucode_header *ucode;
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001311 int err;
1312 struct iwlagn_firmware_pieces pieces;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001313 const unsigned int api_max = priv->cfg->ucode_api_max;
1314 const unsigned int api_min = priv->cfg->ucode_api_min;
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001315 u32 api_ver;
Johannes Berg3e4de762010-04-28 12:09:12 -07001316 char buildstr[25];
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001317 u32 build;
Johannes Bergdd7a2502010-04-28 23:33:10 -07001318 struct iwlagn_ucode_capabilities ucode_capa = {
1319 .max_probe_length = 200,
Wey-Yi Guy6a822d02010-07-13 17:13:15 -07001320 .standard_phy_calibration_size =
Shanyu Zhao642454c2010-09-21 12:06:18 -07001321 IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE,
Johannes Bergdd7a2502010-04-28 23:33:10 -07001322 };
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001323
1324 memset(&pieces, 0, sizeof(pieces));
Zhu Yib481de92007-09-25 17:54:57 -07001325
Johannes Bergb08dfd02010-01-29 11:54:56 -08001326 if (!ucode_raw) {
Jay Sternberg39396082010-08-12 10:24:07 -07001327 if (priv->fw_index <= priv->cfg->ucode_api_max)
1328 IWL_ERR(priv,
1329 "request for firmware file '%s' failed.\n",
1330 priv->firmware_name);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001331 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07001332 }
1333
Johannes Bergb08dfd02010-01-29 11:54:56 -08001334 IWL_DEBUG_INFO(priv, "Loaded firmware file '%s' (%zd bytes).\n",
1335 priv->firmware_name, ucode_raw->size);
Zhu Yib481de92007-09-25 17:54:57 -07001336
Johannes Berg22adba22010-04-28 12:09:14 -07001337 /* Make sure that we got at least the API version number */
1338 if (ucode_raw->size < 4) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001339 IWL_ERR(priv, "File size way too small!\n");
Johannes Bergb08dfd02010-01-29 11:54:56 -08001340 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07001341 }
1342
1343 /* Data from ucode file: header followed by uCode images */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001344 ucode = (struct iwl_ucode_header *)ucode_raw->data;
Zhu Yib481de92007-09-25 17:54:57 -07001345
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001346 if (ucode->ver)
1347 err = iwlagn_load_legacy_firmware(priv, ucode_raw, &pieces);
1348 else
Johannes Bergdd7a2502010-04-28 23:33:10 -07001349 err = iwlagn_load_firmware(priv, ucode_raw, &pieces,
1350 &ucode_capa);
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001351
1352 if (err)
1353 goto try_again;
1354
Reinette Chatrea0987a82008-12-02 12:14:06 -08001355 api_ver = IWL_UCODE_API(priv->ucode_ver);
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001356 build = pieces.build;
Zhu Yib481de92007-09-25 17:54:57 -07001357
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001358 /*
1359 * api_ver should match the api version forming part of the
Reinette Chatrea0987a82008-12-02 12:14:06 -08001360 * firmware filename ... but we don't check for that and only rely
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001361 * on the API version read from firmware header from here on forward
1362 */
Wey-Yi Guy65cccfb2010-09-21 16:15:58 -07001363 /* no api version check required for experimental uCode */
1364 if (priv->fw_index != UCODE_EXPERIMENTAL_INDEX) {
1365 if (api_ver < api_min || api_ver > api_max) {
1366 IWL_ERR(priv,
1367 "Driver unable to support your firmware API. "
1368 "Driver supports v%u, firmware is v%u.\n",
1369 api_max, api_ver);
1370 goto try_again;
1371 }
Johannes Bergb08dfd02010-01-29 11:54:56 -08001372
Wey-Yi Guy65cccfb2010-09-21 16:15:58 -07001373 if (api_ver != api_max)
1374 IWL_ERR(priv,
1375 "Firmware has old API version. Expected v%u, "
1376 "got v%u. New firmware can be obtained "
1377 "from http://www.intellinuxwireless.org.\n",
1378 api_max, api_ver);
1379 }
Reinette Chatrea0987a82008-12-02 12:14:06 -08001380
Johannes Berg3e4de762010-04-28 12:09:12 -07001381 if (build)
Jay Sternberg39396082010-08-12 10:24:07 -07001382 sprintf(buildstr, " build %u%s", build,
1383 (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
1384 ? " (EXP)" : "");
Johannes Berg3e4de762010-04-28 12:09:12 -07001385 else
1386 buildstr[0] = '\0';
Reinette Chatrea0987a82008-12-02 12:14:06 -08001387
Johannes Berg3e4de762010-04-28 12:09:12 -07001388 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u%s\n",
Reinette Chatre5ebeb5a2009-10-30 14:36:04 -07001389 IWL_UCODE_MAJOR(priv->ucode_ver),
1390 IWL_UCODE_MINOR(priv->ucode_ver),
1391 IWL_UCODE_API(priv->ucode_ver),
Johannes Berg3e4de762010-04-28 12:09:12 -07001392 IWL_UCODE_SERIAL(priv->ucode_ver),
1393 buildstr);
Reinette Chatre5ebeb5a2009-10-30 14:36:04 -07001394
Johannes Berg3e4de762010-04-28 12:09:12 -07001395 snprintf(priv->hw->wiphy->fw_version,
1396 sizeof(priv->hw->wiphy->fw_version),
1397 "%u.%u.%u.%u%s",
1398 IWL_UCODE_MAJOR(priv->ucode_ver),
1399 IWL_UCODE_MINOR(priv->ucode_ver),
1400 IWL_UCODE_API(priv->ucode_ver),
1401 IWL_UCODE_SERIAL(priv->ucode_ver),
1402 buildstr);
Zhu Yib481de92007-09-25 17:54:57 -07001403
Johannes Bergb08dfd02010-01-29 11:54:56 -08001404 /*
1405 * For any of the failures below (before allocating pci memory)
1406 * we will try to load a version with a smaller API -- maybe the
1407 * user just got a corrupted version of the latest API.
1408 */
1409
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001410 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
1411 priv->ucode_ver);
1412 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %Zd\n",
1413 pieces.inst_size);
1414 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %Zd\n",
1415 pieces.data_size);
1416 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %Zd\n",
1417 pieces.init_size);
1418 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %Zd\n",
1419 pieces.init_data_size);
Zhu Yib481de92007-09-25 17:54:57 -07001420
1421 /* Verify that uCode images will fit in card's SRAM */
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001422 if (pieces.inst_size > priv->hw_params.max_inst_size) {
1423 IWL_ERR(priv, "uCode instr len %Zd too large to fit in\n",
1424 pieces.inst_size);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001425 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07001426 }
1427
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001428 if (pieces.data_size > priv->hw_params.max_data_size) {
1429 IWL_ERR(priv, "uCode data len %Zd too large to fit in\n",
1430 pieces.data_size);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001431 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07001432 }
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001433
1434 if (pieces.init_size > priv->hw_params.max_inst_size) {
1435 IWL_ERR(priv, "uCode init instr len %Zd too large to fit in\n",
1436 pieces.init_size);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001437 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07001438 }
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001439
1440 if (pieces.init_data_size > priv->hw_params.max_data_size) {
1441 IWL_ERR(priv, "uCode init data len %Zd too large to fit in\n",
1442 pieces.init_data_size);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001443 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07001444 }
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001445
Zhu Yib481de92007-09-25 17:54:57 -07001446 /* Allocate ucode buffers for card's bus-master loading ... */
1447
1448 /* Runtime instructions and 2 copies of data:
1449 * 1) unmodified from disk
1450 * 2) backup cache for save/restore during power-downs */
Johannes Bergdbf28e212011-04-16 08:29:24 -07001451 if (iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_rt.code,
1452 pieces.inst, pieces.inst_size))
1453 goto err_pci_alloc;
1454 if (iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_rt.data,
1455 pieces.data, pieces.data_size))
Zhu, Yi1f304e42009-01-23 13:45:22 -08001456 goto err_pci_alloc;
1457
Zhu Yib481de92007-09-25 17:54:57 -07001458 /* Initialization instructions and data */
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001459 if (pieces.init_size && pieces.init_data_size) {
Johannes Bergdbf28e212011-04-16 08:29:24 -07001460 if (iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init.code,
1461 pieces.init, pieces.init_size))
1462 goto err_pci_alloc;
1463 if (iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init.data,
1464 pieces.init_data, pieces.init_data_size))
Tomas Winkler90e759d2007-11-29 11:09:41 +08001465 goto err_pci_alloc;
1466 }
Zhu Yib481de92007-09-25 17:54:57 -07001467
Johannes Bergb2e640d42010-05-05 23:24:54 -07001468 /* Now that we can no longer fail, copy information */
1469
1470 /*
1471 * The (size - 16) / 12 formula is based on the information recorded
1472 * for each event, which is of mode 1 (including timestamp) for all
1473 * new microcodes that include this information.
1474 */
1475 priv->_agn.init_evtlog_ptr = pieces.init_evtlog_ptr;
1476 if (pieces.init_evtlog_size)
1477 priv->_agn.init_evtlog_size = (pieces.init_evtlog_size - 16)/12;
1478 else
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07001479 priv->_agn.init_evtlog_size =
1480 priv->cfg->base_params->max_event_log_size;
Johannes Bergb2e640d42010-05-05 23:24:54 -07001481 priv->_agn.init_errlog_ptr = pieces.init_errlog_ptr;
1482 priv->_agn.inst_evtlog_ptr = pieces.inst_evtlog_ptr;
1483 if (pieces.inst_evtlog_size)
1484 priv->_agn.inst_evtlog_size = (pieces.inst_evtlog_size - 16)/12;
1485 else
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07001486 priv->_agn.inst_evtlog_size =
1487 priv->cfg->base_params->max_event_log_size;
Johannes Bergb2e640d42010-05-05 23:24:54 -07001488 priv->_agn.inst_errlog_ptr = pieces.inst_errlog_ptr;
1489
Johannes Bergd2690c02011-04-20 09:10:39 -07001490 priv->new_scan_threshold_behaviour =
1491 !!(ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NEWSCAN);
1492
Johannes Berg3997ff32011-04-05 09:42:02 -07001493 if (ucode_capa.flags & IWL_UCODE_TLV_FLAGS_PAN) {
Johannes Bergece9c4e2010-08-23 10:46:49 +02001494 priv->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
Johannes Bergc10afb62010-08-23 10:46:43 +02001495 priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
Johannes Bergece9c4e2010-08-23 10:46:49 +02001496 } else
1497 priv->sta_key_max_num = STA_KEY_MAX_NUM;
Johannes Bergc10afb62010-08-23 10:46:43 +02001498
Johannes Berg17445b82011-04-05 09:42:05 -07001499 if (priv->valid_contexts != BIT(IWL_RXON_CTX_BSS))
1500 priv->cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
1501 else
1502 priv->cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
1503
Wey-Yi Guy6a822d02010-07-13 17:13:15 -07001504 /*
1505 * figure out the offset of chain noise reset and gain commands
1506 * base on the size of standard phy calibration commands table size
1507 */
1508 if (ucode_capa.standard_phy_calibration_size >
1509 IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
1510 ucode_capa.standard_phy_calibration_size =
1511 IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
1512
1513 priv->_agn.phy_calib_chain_noise_reset_cmd =
1514 ucode_capa.standard_phy_calibration_size;
1515 priv->_agn.phy_calib_chain_noise_gain_cmd =
1516 ucode_capa.standard_phy_calibration_size + 1;
1517
Johannes Bergb08dfd02010-01-29 11:54:56 -08001518 /**************************************************
1519 * This is still part of probe() in a sense...
1520 *
1521 * 9. Setup and register with mac80211 and debugfs
1522 **************************************************/
Johannes Bergdd7a2502010-04-28 23:33:10 -07001523 err = iwl_mac_setup_register(priv, &ucode_capa);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001524 if (err)
1525 goto out_unbind;
1526
1527 err = iwl_dbgfs_register(priv, DRV_NAME);
1528 if (err)
1529 IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
1530
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07001531 err = sysfs_create_group(&priv->pci_dev->dev.kobj,
1532 &iwl_attribute_group);
1533 if (err) {
1534 IWL_ERR(priv, "failed to create sysfs device attributes\n");
1535 goto out_unbind;
1536 }
1537
Zhu Yib481de92007-09-25 17:54:57 -07001538 /* We have our copies now, allow OS release its copies */
1539 release_firmware(ucode_raw);
Reinette Chatrea15707d2010-05-10 15:08:11 -07001540 complete(&priv->_agn.firmware_loading_complete);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001541 return;
1542
1543 try_again:
1544 /* try next, if any */
1545 if (iwl_request_firmware(priv, false))
1546 goto out_unbind;
1547 release_firmware(ucode_raw);
1548 return;
Zhu Yib481de92007-09-25 17:54:57 -07001549
1550 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08001551 IWL_ERR(priv, "failed to allocate pci memory\n");
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001552 iwl_dealloc_ucode_pci(priv);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001553 out_unbind:
Reinette Chatrea15707d2010-05-10 15:08:11 -07001554 complete(&priv->_agn.firmware_loading_complete);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001555 device_release_driver(&priv->pci_dev->dev);
Zhu Yib481de92007-09-25 17:54:57 -07001556 release_firmware(ucode_raw);
Zhu Yib481de92007-09-25 17:54:57 -07001557}
1558
Reinette Chatreb7a79402009-09-25 14:24:23 -07001559static const char *desc_lookup_text[] = {
1560 "OK",
1561 "FAIL",
1562 "BAD_PARAM",
1563 "BAD_CHECKSUM",
1564 "NMI_INTERRUPT_WDG",
1565 "SYSASSERT",
1566 "FATAL_ERROR",
1567 "BAD_COMMAND",
1568 "HW_ERROR_TUNE_LOCK",
1569 "HW_ERROR_TEMPERATURE",
1570 "ILLEGAL_CHAN_FREQ",
1571 "VCC_NOT_STABLE",
1572 "FH_ERROR",
1573 "NMI_INTERRUPT_HOST",
1574 "NMI_INTERRUPT_ACTION_PT",
1575 "NMI_INTERRUPT_UNKNOWN",
1576 "UCODE_VERSION_MISMATCH",
1577 "HW_ERROR_ABS_LOCK",
1578 "HW_ERROR_CAL_LOCK_FAIL",
1579 "NMI_INTERRUPT_INST_ACTION_PT",
1580 "NMI_INTERRUPT_DATA_ACTION_PT",
1581 "NMI_TRM_HW_ER",
1582 "NMI_INTERRUPT_TRM",
1583 "NMI_INTERRUPT_BREAK_POINT"
1584 "DEBUG_0",
1585 "DEBUG_1",
1586 "DEBUG_2",
1587 "DEBUG_3",
Reinette Chatreb7a79402009-09-25 14:24:23 -07001588};
1589
Jay Sternberg4b586452010-07-02 15:49:10 -07001590static struct { char *name; u8 num; } advanced_lookup[] = {
1591 { "NMI_INTERRUPT_WDG", 0x34 },
1592 { "SYSASSERT", 0x35 },
1593 { "UCODE_VERSION_MISMATCH", 0x37 },
1594 { "BAD_COMMAND", 0x38 },
1595 { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
1596 { "FATAL_ERROR", 0x3D },
1597 { "NMI_TRM_HW_ERR", 0x46 },
1598 { "NMI_INTERRUPT_TRM", 0x4C },
1599 { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
1600 { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
1601 { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
1602 { "NMI_INTERRUPT_HOST", 0x66 },
1603 { "NMI_INTERRUPT_ACTION_PT", 0x7C },
1604 { "NMI_INTERRUPT_UNKNOWN", 0x84 },
1605 { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
1606 { "ADVANCED_SYSASSERT", 0 },
1607};
1608
1609static const char *desc_lookup(u32 num)
Reinette Chatreb7a79402009-09-25 14:24:23 -07001610{
Jay Sternberg4b586452010-07-02 15:49:10 -07001611 int i;
1612 int max = ARRAY_SIZE(desc_lookup_text);
Reinette Chatreb7a79402009-09-25 14:24:23 -07001613
Jay Sternberg4b586452010-07-02 15:49:10 -07001614 if (num < max)
1615 return desc_lookup_text[num];
Reinette Chatreb7a79402009-09-25 14:24:23 -07001616
Jay Sternberg4b586452010-07-02 15:49:10 -07001617 max = ARRAY_SIZE(advanced_lookup) - 1;
1618 for (i = 0; i < max; i++) {
1619 if (advanced_lookup[i].num == num)
1620 break;;
1621 }
1622 return advanced_lookup[i].name;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001623}
1624
1625#define ERROR_START_OFFSET (1 * sizeof(u32))
1626#define ERROR_ELEM_SIZE (7 * sizeof(u32))
1627
1628void iwl_dump_nic_error_log(struct iwl_priv *priv)
1629{
1630 u32 data2, line;
1631 u32 desc, time, count, base, data1;
1632 u32 blink1, blink2, ilink1, ilink2;
Wey-Yi Guy461ef382010-03-30 17:57:53 -07001633 u32 pc, hcmd;
Johannes Berge46f6532011-04-13 03:14:43 -07001634 struct iwl_error_event_table table;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001635
Johannes Bergd7d57832011-04-05 09:42:04 -07001636 base = priv->device_pointers.error_event_table;
Johannes Bergca7966c2011-04-22 10:15:23 -07001637 if (priv->ucode_type == UCODE_SUBTYPE_INIT) {
Johannes Bergb2e640d42010-05-05 23:24:54 -07001638 if (!base)
1639 base = priv->_agn.init_errlog_ptr;
1640 } else {
Johannes Bergb2e640d42010-05-05 23:24:54 -07001641 if (!base)
1642 base = priv->_agn.inst_errlog_ptr;
1643 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07001644
1645 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
Wey-Yi Guy212fb572009-12-02 12:53:00 -08001646 IWL_ERR(priv,
1647 "Not valid error log pointer 0x%08X for %s uCode\n",
Johannes Bergca7966c2011-04-22 10:15:23 -07001648 base,
1649 (priv->ucode_type == UCODE_SUBTYPE_INIT)
1650 ? "Init" : "RT");
Reinette Chatreb7a79402009-09-25 14:24:23 -07001651 return;
1652 }
1653
Johannes Berge46f6532011-04-13 03:14:43 -07001654 iwl_read_targ_mem_words(priv, base, &table, sizeof(table));
1655
1656 count = table.valid;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001657
1658 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
1659 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
1660 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
1661 priv->status, count);
1662 }
1663
Johannes Berge46f6532011-04-13 03:14:43 -07001664 desc = table.error_id;
Wey-Yi Guy6e6ebf42010-08-27 10:41:37 -07001665 priv->isr_stats.err_code = desc;
Johannes Berge46f6532011-04-13 03:14:43 -07001666 pc = table.pc;
1667 blink1 = table.blink1;
1668 blink2 = table.blink2;
1669 ilink1 = table.ilink1;
1670 ilink2 = table.ilink2;
1671 data1 = table.data1;
1672 data2 = table.data2;
1673 line = table.line;
1674 time = table.tsf_low;
1675 hcmd = table.hcmd;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001676
Johannes Bergbe1a71a2009-10-02 13:44:02 -07001677 trace_iwlwifi_dev_ucode_error(priv, desc, time, data1, data2, line,
1678 blink1, blink2, ilink1, ilink2);
1679
Jay Sternberg87563712010-06-14 14:40:40 -07001680 IWL_ERR(priv, "Desc Time "
Reinette Chatreb7a79402009-09-25 14:24:23 -07001681 "data1 data2 line\n");
Jay Sternberg87563712010-06-14 14:40:40 -07001682 IWL_ERR(priv, "%-28s (0x%04X) %010u 0x%08X 0x%08X %u\n",
Reinette Chatreb7a79402009-09-25 14:24:23 -07001683 desc_lookup(desc), desc, time, data1, data2, line);
Wey-Yi Guy461ef382010-03-30 17:57:53 -07001684 IWL_ERR(priv, "pc blink1 blink2 ilink1 ilink2 hcmd\n");
1685 IWL_ERR(priv, "0x%05X 0x%05X 0x%05X 0x%05X 0x%05X 0x%05X\n",
1686 pc, blink1, blink2, ilink1, ilink2, hcmd);
Reinette Chatreb7a79402009-09-25 14:24:23 -07001687}
1688
1689#define EVENT_START_OFFSET (4 * sizeof(u32))
1690
1691/**
1692 * iwl_print_event_log - Dump error event log to syslog
1693 *
1694 */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001695static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
1696 u32 num_events, u32 mode,
1697 int pos, char **buf, size_t bufsz)
Reinette Chatreb7a79402009-09-25 14:24:23 -07001698{
1699 u32 i;
1700 u32 base; /* SRAM byte address of event log header */
1701 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
1702 u32 ptr; /* SRAM byte address of log data */
1703 u32 ev, time, data; /* event log data */
Ben Cahille5854472009-11-06 14:52:58 -08001704 unsigned long reg_flags;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001705
1706 if (num_events == 0)
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001707 return pos;
Johannes Bergb2e640d42010-05-05 23:24:54 -07001708
Johannes Bergd7d57832011-04-05 09:42:04 -07001709 base = priv->device_pointers.log_event_table;
Johannes Bergca7966c2011-04-22 10:15:23 -07001710 if (priv->ucode_type == UCODE_SUBTYPE_INIT) {
Johannes Bergb2e640d42010-05-05 23:24:54 -07001711 if (!base)
1712 base = priv->_agn.init_evtlog_ptr;
1713 } else {
Johannes Bergb2e640d42010-05-05 23:24:54 -07001714 if (!base)
1715 base = priv->_agn.inst_evtlog_ptr;
1716 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07001717
1718 if (mode == 0)
1719 event_size = 2 * sizeof(u32);
1720 else
1721 event_size = 3 * sizeof(u32);
1722
1723 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
1724
Ben Cahille5854472009-11-06 14:52:58 -08001725 /* Make sure device is powered up for SRAM reads */
1726 spin_lock_irqsave(&priv->reg_lock, reg_flags);
1727 iwl_grab_nic_access(priv);
1728
1729 /* Set starting address; reads will auto-increment */
Johannes Berg02a7fa02011-04-05 09:42:12 -07001730 iwl_write32(priv, HBUS_TARG_MEM_RADDR, ptr);
Ben Cahille5854472009-11-06 14:52:58 -08001731 rmb();
1732
Reinette Chatreb7a79402009-09-25 14:24:23 -07001733 /* "time" is actually "data" for mode 0 (no timestamp).
1734 * place event id # at far right for easier visual parsing. */
1735 for (i = 0; i < num_events; i++) {
Johannes Berg02a7fa02011-04-05 09:42:12 -07001736 ev = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
1737 time = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
Reinette Chatreb7a79402009-09-25 14:24:23 -07001738 if (mode == 0) {
1739 /* data, ev */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001740 if (bufsz) {
1741 pos += scnprintf(*buf + pos, bufsz - pos,
1742 "EVT_LOG:0x%08x:%04u\n",
1743 time, ev);
1744 } else {
1745 trace_iwlwifi_dev_ucode_event(priv, 0,
1746 time, ev);
1747 IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n",
1748 time, ev);
1749 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07001750 } else {
Johannes Berg02a7fa02011-04-05 09:42:12 -07001751 data = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001752 if (bufsz) {
1753 pos += scnprintf(*buf + pos, bufsz - pos,
1754 "EVT_LOGT:%010u:0x%08x:%04u\n",
1755 time, data, ev);
1756 } else {
1757 IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
Reinette Chatreb7a79402009-09-25 14:24:23 -07001758 time, data, ev);
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001759 trace_iwlwifi_dev_ucode_event(priv, time,
1760 data, ev);
1761 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07001762 }
1763 }
Ben Cahille5854472009-11-06 14:52:58 -08001764
1765 /* Allow device to power down */
1766 iwl_release_nic_access(priv);
1767 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001768 return pos;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001769}
1770
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001771/**
1772 * iwl_print_last_event_logs - Dump the newest # of event log to syslog
1773 */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001774static int iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
1775 u32 num_wraps, u32 next_entry,
1776 u32 size, u32 mode,
1777 int pos, char **buf, size_t bufsz)
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001778{
1779 /*
1780 * display the newest DEFAULT_LOG_ENTRIES entries
1781 * i.e the entries just before the next ont that uCode would fill.
1782 */
1783 if (num_wraps) {
1784 if (next_entry < size) {
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001785 pos = iwl_print_event_log(priv,
1786 capacity - (size - next_entry),
1787 size - next_entry, mode,
1788 pos, buf, bufsz);
1789 pos = iwl_print_event_log(priv, 0,
1790 next_entry, mode,
1791 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001792 } else
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001793 pos = iwl_print_event_log(priv, next_entry - size,
1794 size, mode, pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001795 } else {
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001796 if (next_entry < size) {
1797 pos = iwl_print_event_log(priv, 0, next_entry,
1798 mode, pos, buf, bufsz);
1799 } else {
1800 pos = iwl_print_event_log(priv, next_entry - size,
1801 size, mode, pos, buf, bufsz);
1802 }
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001803 }
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001804 return pos;
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001805}
1806
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001807#define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
1808
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001809int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
1810 char **buf, bool display)
Reinette Chatreb7a79402009-09-25 14:24:23 -07001811{
1812 u32 base; /* SRAM byte address of event log header */
1813 u32 capacity; /* event log capacity in # entries */
1814 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
1815 u32 num_wraps; /* # times uCode wrapped to top of log */
1816 u32 next_entry; /* index of next entry to be written by uCode */
1817 u32 size; /* # entries that we'll print */
Johannes Bergb2e640d42010-05-05 23:24:54 -07001818 u32 logsize;
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001819 int pos = 0;
1820 size_t bufsz = 0;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001821
Johannes Bergd7d57832011-04-05 09:42:04 -07001822 base = priv->device_pointers.log_event_table;
Johannes Bergca7966c2011-04-22 10:15:23 -07001823 if (priv->ucode_type == UCODE_SUBTYPE_INIT) {
Johannes Bergb2e640d42010-05-05 23:24:54 -07001824 logsize = priv->_agn.init_evtlog_size;
1825 if (!base)
1826 base = priv->_agn.init_evtlog_ptr;
1827 } else {
Johannes Bergb2e640d42010-05-05 23:24:54 -07001828 logsize = priv->_agn.inst_evtlog_size;
1829 if (!base)
1830 base = priv->_agn.inst_evtlog_ptr;
1831 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07001832
1833 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
Wey-Yi Guy212fb572009-12-02 12:53:00 -08001834 IWL_ERR(priv,
1835 "Invalid event log pointer 0x%08X for %s uCode\n",
Johannes Bergca7966c2011-04-22 10:15:23 -07001836 base,
1837 (priv->ucode_type == UCODE_SUBTYPE_INIT)
1838 ? "Init" : "RT");
Wey-Yi Guy937c3972010-01-15 13:43:36 -08001839 return -EINVAL;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001840 }
1841
1842 /* event log header */
1843 capacity = iwl_read_targ_mem(priv, base);
1844 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
1845 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
1846 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
1847
Johannes Bergb2e640d42010-05-05 23:24:54 -07001848 if (capacity > logsize) {
Ben Cahill84c40692009-11-06 14:52:57 -08001849 IWL_ERR(priv, "Log capacity %d is bogus, limit to %d entries\n",
Johannes Bergb2e640d42010-05-05 23:24:54 -07001850 capacity, logsize);
1851 capacity = logsize;
Ben Cahill84c40692009-11-06 14:52:57 -08001852 }
1853
Johannes Bergb2e640d42010-05-05 23:24:54 -07001854 if (next_entry > logsize) {
Ben Cahill84c40692009-11-06 14:52:57 -08001855 IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
Johannes Bergb2e640d42010-05-05 23:24:54 -07001856 next_entry, logsize);
1857 next_entry = logsize;
Ben Cahill84c40692009-11-06 14:52:57 -08001858 }
1859
Reinette Chatreb7a79402009-09-25 14:24:23 -07001860 size = num_wraps ? capacity : next_entry;
1861
1862 /* bail out if nothing in log */
1863 if (size == 0) {
1864 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001865 return pos;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001866 }
1867
Wey-Yi Guy9f28ebc2010-11-26 13:24:19 -08001868 /* enable/disable bt channel inhibition */
Wey-Yi Guyf37837c2010-08-23 07:57:12 -07001869 priv->bt_ch_announce = iwlagn_bt_ch_announce;
1870
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001871#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guy521d9bc2009-12-10 14:37:23 -08001872 if (!(iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) && !full_log)
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001873 size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
1874 ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
1875#else
1876 size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
1877 ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001878#endif
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001879 IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n",
1880 size);
1881
1882#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001883 if (display) {
1884 if (full_log)
1885 bufsz = capacity * 48;
1886 else
1887 bufsz = size * 48;
1888 *buf = kmalloc(bufsz, GFP_KERNEL);
1889 if (!*buf)
Wey-Yi Guy937c3972010-01-15 13:43:36 -08001890 return -ENOMEM;
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001891 }
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001892 if ((iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) || full_log) {
1893 /*
1894 * if uCode has wrapped back to top of log,
1895 * start at the oldest entry,
1896 * i.e the next one that uCode would fill.
1897 */
1898 if (num_wraps)
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001899 pos = iwl_print_event_log(priv, next_entry,
1900 capacity - next_entry, mode,
1901 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001902 /* (then/else) start at top of log */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001903 pos = iwl_print_event_log(priv, 0,
1904 next_entry, mode, pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001905 } else
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001906 pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
1907 next_entry, size, mode,
1908 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001909#else
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001910 pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
1911 next_entry, size, mode,
1912 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001913#endif
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001914 return pos;
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001915}
Reinette Chatreb7a79402009-09-25 14:24:23 -07001916
Wey-Yi Guy0975cc82010-07-31 08:34:07 -07001917static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
1918{
1919 struct iwl_ct_kill_config cmd;
1920 struct iwl_ct_kill_throttling_config adv_cmd;
1921 unsigned long flags;
1922 int ret = 0;
1923
1924 spin_lock_irqsave(&priv->lock, flags);
1925 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
1926 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
1927 spin_unlock_irqrestore(&priv->lock, flags);
1928 priv->thermal_throttle.ct_kill_toggle = false;
1929
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07001930 if (priv->cfg->base_params->support_ct_kill_exit) {
Wey-Yi Guy0975cc82010-07-31 08:34:07 -07001931 adv_cmd.critical_temperature_enter =
1932 cpu_to_le32(priv->hw_params.ct_kill_threshold);
1933 adv_cmd.critical_temperature_exit =
1934 cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
1935
1936 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
1937 sizeof(adv_cmd), &adv_cmd);
1938 if (ret)
1939 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
1940 else
1941 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
1942 "succeeded, "
1943 "critical temperature enter is %d,"
1944 "exit is %d\n",
1945 priv->hw_params.ct_kill_threshold,
1946 priv->hw_params.ct_kill_exit_threshold);
1947 } else {
1948 cmd.critical_temperature_R =
1949 cpu_to_le32(priv->hw_params.ct_kill_threshold);
1950
1951 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
1952 sizeof(cmd), &cmd);
1953 if (ret)
1954 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
1955 else
1956 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
1957 "succeeded, "
1958 "critical temperature is %d\n",
1959 priv->hw_params.ct_kill_threshold);
1960 }
1961}
1962
Shanyu Zhao6d6a1af2010-09-14 18:13:31 -07001963static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
1964{
1965 struct iwl_calib_cfg_cmd calib_cfg_cmd;
1966 struct iwl_host_cmd cmd = {
1967 .id = CALIBRATION_CFG_CMD,
Johannes Berg3fa50732011-05-04 07:50:38 -07001968 .len = { sizeof(struct iwl_calib_cfg_cmd), },
1969 .data = { &calib_cfg_cmd, },
Shanyu Zhao6d6a1af2010-09-14 18:13:31 -07001970 };
1971
1972 memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
1973 calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL;
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07001974 calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg);
Shanyu Zhao6d6a1af2010-09-14 18:13:31 -07001975
1976 return iwl_send_cmd(priv, &cmd);
1977}
1978
1979
Zhu Yib481de92007-09-25 17:54:57 -07001980/**
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001981 * iwl_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07001982 * from protocol/runtime uCode (initialization uCode's
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001983 * Alive gets handled by iwl_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07001984 */
Cindy H. Kao4613e722011-05-06 10:40:15 -07001985int iwl_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001986{
Tomas Winkler57aab752008-04-14 21:16:03 -07001987 int ret = 0;
Johannes Berg246ed352010-08-23 10:46:32 +02001988 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Zhu Yib481de92007-09-25 17:54:57 -07001989
Johannes Bergca7966c2011-04-22 10:15:23 -07001990 iwl_reset_ict(priv);
1991
Tomas Winklere1623442009-01-27 14:27:56 -08001992 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001993
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001994 /* After the ALIVE response, we can send host commands to the uCode */
Zhu Yib481de92007-09-25 17:54:57 -07001995 set_bit(STATUS_ALIVE, &priv->status);
1996
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01001997 /* Enable watchdog to monitor the driver tx queues */
1998 iwl_setup_watchdog(priv);
Wey-Yi Guyb74e31a2010-03-01 17:23:50 -08001999
Tomas Winklerfee12472008-04-03 16:05:21 -07002000 if (iwl_is_rfkill(priv))
Johannes Bergca7966c2011-04-22 10:15:23 -07002001 return -ERFKILL;
Zhu Yib481de92007-09-25 17:54:57 -07002002
Wey-Yi Guybc795df2010-10-11 14:24:05 -07002003 /* download priority table before any calibration request */
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002004 if (priv->cfg->bt_params &&
2005 priv->cfg->bt_params->advanced_bt_coexist) {
Wey-Yi Guyf7322f82010-08-23 15:24:49 -07002006 /* Configure Bluetooth device coexistence support */
2007 priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
2008 priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
2009 priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
2010 priv->cfg->ops->hcmd->send_bt_config(priv);
2011 priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS;
Wey-Yi Guya5901cb2010-09-23 09:56:51 -07002012 iwlagn_send_prio_tbl(priv);
Wey-Yi Guyf7322f82010-08-23 15:24:49 -07002013
2014 /* FIXME: w/a to force change uCode BT state machine */
Johannes Bergca7966c2011-04-22 10:15:23 -07002015 ret = iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
2016 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
2017 if (ret)
2018 return ret;
2019 ret = iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
2020 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
2021 if (ret)
2022 return ret;
Wey-Yi Guyf7322f82010-08-23 15:24:49 -07002023 }
Wey-Yi Guybc795df2010-10-11 14:24:05 -07002024 if (priv->hw_params.calib_rt_cfg)
2025 iwlagn_send_calib_cfg_rt(priv, priv->hw_params.calib_rt_cfg);
2026
Johannes Berg36d68252008-05-15 12:55:26 +02002027 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002028
Johannes Berg470ab2d2010-01-21 11:23:30 -08002029 priv->active_rate = IWL_RATES_MASK;
Zhu Yib481de92007-09-25 17:54:57 -07002030
Wey-Yi Guy2f748de2009-09-17 10:43:51 -07002031 /* Configure Tx antenna selection based on H/W config */
2032 if (priv->cfg->ops->hcmd->set_tx_ant)
2033 priv->cfg->ops->hcmd->set_tx_ant(priv, priv->cfg->valid_tx_ant);
2034
Johannes Berg246ed352010-08-23 10:46:32 +02002035 if (iwl_is_associated_ctx(ctx)) {
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08002036 struct iwl_rxon_cmd *active_rxon =
Johannes Berg246ed352010-08-23 10:46:32 +02002037 (struct iwl_rxon_cmd *)&ctx->active;
Mohamed Abbas019fb972009-03-17 21:59:18 -07002038 /* apply any changes in staging */
Johannes Berg246ed352010-08-23 10:46:32 +02002039 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07002040 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2041 } else {
Johannes Bergd0fe4782010-08-23 10:46:58 +02002042 struct iwl_rxon_context *tmp;
Zhu Yib481de92007-09-25 17:54:57 -07002043 /* Initialize our rx_config data */
Johannes Bergd0fe4782010-08-23 10:46:58 +02002044 for_each_context(priv, tmp)
2045 iwl_connection_init_rx_config(priv, tmp);
Abhijeet Kolekar45823532009-04-08 11:26:44 -07002046
2047 if (priv->cfg->ops->hcmd->set_rxon_chain)
Johannes Berg246ed352010-08-23 10:46:32 +02002048 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
Zhu Yib481de92007-09-25 17:54:57 -07002049 }
2050
Wey-Yi Guy73b78a22011-02-11 08:13:14 -08002051 if (!priv->cfg->bt_params || (priv->cfg->bt_params &&
2052 !priv->cfg->bt_params->advanced_bt_coexist)) {
2053 /*
2054 * default is 2-wire BT coexexistence support
2055 */
Wey-Yi Guyaeb4a2e2010-08-23 07:57:05 -07002056 priv->cfg->ops->hcmd->send_bt_config(priv);
2057 }
Zhu Yib481de92007-09-25 17:54:57 -07002058
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002059 iwl_reset_run_time_calib(priv);
2060
Wey-Yi Guy9e2e7422010-11-12 13:52:37 -08002061 set_bit(STATUS_READY, &priv->status);
2062
Zhu Yib481de92007-09-25 17:54:57 -07002063 /* Configure the adapter for unassociated operation */
Johannes Bergca7966c2011-04-22 10:15:23 -07002064 ret = iwlcore_commit_rxon(priv, ctx);
2065 if (ret)
2066 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002067
2068 /* At this point, the NIC is initialized and operational */
Emmanuel Grumbach47f4a582008-06-12 09:47:13 +08002069 iwl_rf_kill_ct_config(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002070
Tomas Winklere1623442009-01-27 14:27:56 -08002071 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002072
Johannes Bergca7966c2011-04-22 10:15:23 -07002073 return iwl_power_update_mode(priv, true);
Zhu Yib481de92007-09-25 17:54:57 -07002074}
2075
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002076static void iwl_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07002077
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002078static void __iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002079{
Dan Carpenter22dd2fd2011-03-15 10:03:24 +03002080 int exit_pending;
Zhu Yib481de92007-09-25 17:54:57 -07002081
Tomas Winklere1623442009-01-27 14:27:56 -08002082 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07002083
Stanislaw Gruszkad745d472010-09-13 14:46:35 +02002084 iwl_scan_cancel_timeout(priv, 200);
2085
2086 exit_pending = test_and_set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002087
Stanislaw Gruszkab62177a2010-08-20 15:23:47 +02002088 /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
2089 * to prevent rearm timer */
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002090 del_timer_sync(&priv->watchdog);
Stanislaw Gruszkab62177a2010-08-20 15:23:47 +02002091
Johannes Bergdcef7322010-08-27 08:55:52 -07002092 iwl_clear_ucode_stations(priv, NULL);
Johannes Berga194e322010-08-27 08:53:46 -07002093 iwl_dealloc_bcast_stations(priv);
Johannes Bergdb125c72010-05-07 01:49:15 -07002094 iwl_clear_driver_stations(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002095
Johannes Berga1174132010-08-23 07:56:59 -07002096 /* reset BT coex data */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002097 priv->bt_status = 0;
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002098 if (priv->cfg->bt_params)
2099 priv->bt_traffic_load =
2100 priv->cfg->bt_params->bt_init_traffic_load;
2101 else
2102 priv->bt_traffic_load = 0;
Wey-Yi Guybee008b2010-08-23 07:57:04 -07002103 priv->bt_full_concurrent = false;
2104 priv->bt_ci_compliance = 0;
Johannes Berga1174132010-08-23 07:56:59 -07002105
Zhu Yib481de92007-09-25 17:54:57 -07002106 /* Wipe out the EXIT_PENDING status bit if we are not actually
2107 * exiting the module */
2108 if (!exit_pending)
2109 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2110
Zhu Yib481de92007-09-25 17:54:57 -07002111 if (priv->mac80211_registered)
2112 ieee80211_stop_queues(priv->hw);
2113
Johannes Berg1a10f432011-04-13 03:14:44 -07002114 /* Clear out all status bits but a few that are stable across reset */
Zhu Yib481de92007-09-25 17:54:57 -07002115 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2116 STATUS_RF_KILL_HW |
Reinette Chatre97888642008-02-06 11:20:38 -08002117 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2118 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002119 test_bit(STATUS_FW_ERROR, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002120 STATUS_FW_ERROR |
2121 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2122 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002123
Johannes Bergbc4f8ad2011-04-13 03:14:45 -07002124 iwlagn_stop_device(priv);
Ben Cahill4d2ccdb2009-10-09 13:20:20 -07002125
Johannes Berg77834542010-10-04 05:50:36 -07002126 dev_kfree_skb(priv->beacon_skb);
Johannes Berg12e934d2010-10-04 05:50:06 -07002127 priv->beacon_skb = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07002128}
2129
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002130static void iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002131{
2132 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002133 __iwl_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002134 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08002135
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002136 iwl_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002137}
2138
Mohamed Abbas086ed112009-05-22 11:01:54 -07002139#define HW_READY_TIMEOUT (50)
2140
Johannes Berg4cd2bf72011-04-13 03:14:52 -07002141/* Note: returns poll_bit return value, which is >= 0 if success */
Mohamed Abbas086ed112009-05-22 11:01:54 -07002142static int iwl_set_hw_ready(struct iwl_priv *priv)
2143{
Johannes Berg4cd2bf72011-04-13 03:14:52 -07002144 int ret;
Mohamed Abbas086ed112009-05-22 11:01:54 -07002145
2146 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
2147 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
2148
2149 /* See if we got it */
2150 ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
2151 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
2152 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
2153 HW_READY_TIMEOUT);
Mohamed Abbas086ed112009-05-22 11:01:54 -07002154
Johannes Berg4cd2bf72011-04-13 03:14:52 -07002155 IWL_DEBUG_INFO(priv, "hardware%s ready\n", ret < 0 ? " not" : "");
Mohamed Abbas086ed112009-05-22 11:01:54 -07002156 return ret;
2157}
2158
Johannes Berg4cd2bf72011-04-13 03:14:52 -07002159/* Note: returns standard 0/-ERROR code */
Johannes Berg3e14c1f2011-04-13 03:14:46 -07002160int iwl_prepare_card_hw(struct iwl_priv *priv)
Mohamed Abbas086ed112009-05-22 11:01:54 -07002161{
Johannes Berg4cd2bf72011-04-13 03:14:52 -07002162 int ret;
Mohamed Abbas086ed112009-05-22 11:01:54 -07002163
Frans Pop91dd6c22010-03-24 14:19:58 -07002164 IWL_DEBUG_INFO(priv, "iwl_prepare_card_hw enter\n");
Mohamed Abbas086ed112009-05-22 11:01:54 -07002165
Mohamed Abbas3354a0f2009-06-19 13:52:41 -07002166 ret = iwl_set_hw_ready(priv);
Johannes Berg4cd2bf72011-04-13 03:14:52 -07002167 if (ret >= 0)
2168 return 0;
Mohamed Abbas3354a0f2009-06-19 13:52:41 -07002169
2170 /* If HW is not ready, prepare the conditions to check again */
Mohamed Abbas086ed112009-05-22 11:01:54 -07002171 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
2172 CSR_HW_IF_CONFIG_REG_PREPARE);
2173
2174 ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
2175 ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE,
2176 CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000);
2177
Johannes Berg4cd2bf72011-04-13 03:14:52 -07002178 if (ret < 0)
2179 return ret;
Mohamed Abbas086ed112009-05-22 11:01:54 -07002180
Johannes Berg4cd2bf72011-04-13 03:14:52 -07002181 /* HW should be ready by now, check again. */
2182 ret = iwl_set_hw_ready(priv);
2183 if (ret >= 0)
2184 return 0;
Mohamed Abbas086ed112009-05-22 11:01:54 -07002185 return ret;
2186}
2187
Zhu Yib481de92007-09-25 17:54:57 -07002188#define MAX_HW_RESTARTS 5
2189
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002190static int __iwl_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002191{
Johannes Berga194e322010-08-27 08:53:46 -07002192 struct iwl_rxon_context *ctx;
Tomas Winkler57aab752008-04-14 21:16:03 -07002193 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002194
Johannes Bergca7966c2011-04-22 10:15:23 -07002195 lockdep_assert_held(&priv->mutex);
2196
Zhu Yib481de92007-09-25 17:54:57 -07002197 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002198 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07002199 return -EIO;
2200 }
2201
Johannes Berga194e322010-08-27 08:53:46 -07002202 for_each_context(priv, ctx) {
Johannes Berga30e3112010-09-22 18:02:01 +02002203 ret = iwlagn_alloc_bcast_station(priv, ctx);
Johannes Berga194e322010-08-27 08:53:46 -07002204 if (ret) {
2205 iwl_dealloc_bcast_stations(priv);
2206 return ret;
2207 }
2208 }
Johannes Berg2c810cc2010-04-29 00:53:29 -07002209
Johannes Bergca7966c2011-04-22 10:15:23 -07002210 ret = iwlagn_run_init_ucode(priv);
2211 if (ret) {
2212 IWL_ERR(priv, "Failed to run INIT ucode: %d\n", ret);
2213 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07002214 }
2215
Johannes Bergca7966c2011-04-22 10:15:23 -07002216 ret = iwlagn_load_ucode_wait_alive(priv,
Johannes Bergdbf28e212011-04-16 08:29:24 -07002217 &priv->ucode_rt,
Johannes Bergca7966c2011-04-22 10:15:23 -07002218 UCODE_SUBTYPE_REGULAR,
2219 UCODE_SUBTYPE_REGULAR_NEW);
2220 if (ret) {
2221 IWL_ERR(priv, "Failed to start RT ucode: %d\n", ret);
2222 goto error;
2223 }
2224
2225 ret = iwl_alive_start(priv);
2226 if (ret)
2227 goto error;
2228 return 0;
2229
2230 error:
Zhu Yib481de92007-09-25 17:54:57 -07002231 set_bit(STATUS_EXIT_PENDING, &priv->status);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002232 __iwl_down(priv);
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08002233 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002234
Johannes Bergca7966c2011-04-22 10:15:23 -07002235 IWL_ERR(priv, "Unable to initialize device.\n");
2236 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002237}
2238
2239
2240/*****************************************************************************
2241 *
2242 * Workqueue callbacks
2243 *
2244 *****************************************************************************/
2245
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08002246static void iwl_bg_run_time_calib_work(struct work_struct *work)
2247{
2248 struct iwl_priv *priv = container_of(work, struct iwl_priv,
2249 run_time_calib_work);
2250
2251 mutex_lock(&priv->mutex);
2252
2253 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
2254 test_bit(STATUS_SCANNING, &priv->status)) {
2255 mutex_unlock(&priv->mutex);
2256 return;
2257 }
2258
2259 if (priv->start_calib) {
Johannes Berg0da0e5b2011-04-08 08:14:56 -07002260 iwl_chain_noise_calibration(priv);
2261 iwl_sensitivity_calibration(priv);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08002262 }
2263
2264 mutex_unlock(&priv->mutex);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08002265}
2266
Johannes Berge43e85c2011-04-19 07:45:16 -07002267static void iwlagn_prepare_restart(struct iwl_priv *priv)
2268{
2269 struct iwl_rxon_context *ctx;
2270 bool bt_full_concurrent;
2271 u8 bt_ci_compliance;
2272 u8 bt_load;
2273 u8 bt_status;
2274
2275 lockdep_assert_held(&priv->mutex);
2276
2277 for_each_context(priv, ctx)
2278 ctx->vif = NULL;
2279 priv->is_open = 0;
2280
2281 /*
2282 * __iwl_down() will clear the BT status variables,
2283 * which is correct, but when we restart we really
2284 * want to keep them so restore them afterwards.
2285 *
2286 * The restart process will later pick them up and
2287 * re-configure the hw when we reconfigure the BT
2288 * command.
2289 */
2290 bt_full_concurrent = priv->bt_full_concurrent;
2291 bt_ci_compliance = priv->bt_ci_compliance;
2292 bt_load = priv->bt_traffic_load;
2293 bt_status = priv->bt_status;
2294
2295 __iwl_down(priv);
2296
2297 priv->bt_full_concurrent = bt_full_concurrent;
2298 priv->bt_ci_compliance = bt_ci_compliance;
2299 priv->bt_traffic_load = bt_load;
2300 priv->bt_status = bt_status;
2301}
2302
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002303static void iwl_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002304{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002305 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07002306
2307 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2308 return;
2309
Johannes Berg19cc1082009-05-08 13:44:36 -07002310 if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
2311 mutex_lock(&priv->mutex);
Johannes Berge43e85c2011-04-19 07:45:16 -07002312 iwlagn_prepare_restart(priv);
Johannes Berg19cc1082009-05-08 13:44:36 -07002313 mutex_unlock(&priv->mutex);
Johannes Berga1174132010-08-23 07:56:59 -07002314 iwl_cancel_deferred_work(priv);
Johannes Berg19cc1082009-05-08 13:44:36 -07002315 ieee80211_restart_hw(priv->hw);
2316 } else {
Johannes Bergca7966c2011-04-22 10:15:23 -07002317 WARN_ON(1);
Johannes Berg19cc1082009-05-08 13:44:36 -07002318 }
Zhu Yib481de92007-09-25 17:54:57 -07002319}
2320
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002321static void iwl_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002322{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002323 struct iwl_priv *priv =
2324 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07002325
2326 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2327 return;
2328
2329 mutex_lock(&priv->mutex);
Wey-Yi Guy54b81552010-03-17 13:34:35 -07002330 iwlagn_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002331 mutex_unlock(&priv->mutex);
2332}
2333
Johannes Berg266af4c72011-03-10 20:13:26 -08002334static int iwl_mac_offchannel_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
2335 struct ieee80211_channel *chan,
2336 enum nl80211_channel_type channel_type,
2337 unsigned int wait)
2338{
2339 struct iwl_priv *priv = hw->priv;
2340 int ret;
2341
2342 /* Not supported if we don't have PAN */
2343 if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN))) {
2344 ret = -EOPNOTSUPP;
2345 goto free;
2346 }
2347
2348 /* Not supported on pre-P2P firmware */
2349 if (!(priv->contexts[IWL_RXON_CTX_PAN].interface_modes &
2350 BIT(NL80211_IFTYPE_P2P_CLIENT))) {
2351 ret = -EOPNOTSUPP;
2352 goto free;
2353 }
2354
2355 mutex_lock(&priv->mutex);
2356
2357 if (!priv->contexts[IWL_RXON_CTX_PAN].is_active) {
2358 /*
2359 * If the PAN context is free, use the normal
2360 * way of doing remain-on-channel offload + TX.
2361 */
2362 ret = 1;
2363 goto out;
2364 }
2365
2366 /* TODO: queue up if scanning? */
2367 if (test_bit(STATUS_SCANNING, &priv->status) ||
2368 priv->_agn.offchan_tx_skb) {
2369 ret = -EBUSY;
2370 goto out;
2371 }
2372
2373 /*
2374 * max_scan_ie_len doesn't include the blank SSID or the header,
2375 * so need to add that again here.
2376 */
2377 if (skb->len > hw->wiphy->max_scan_ie_len + 24 + 2) {
2378 ret = -ENOBUFS;
2379 goto out;
2380 }
2381
2382 priv->_agn.offchan_tx_skb = skb;
2383 priv->_agn.offchan_tx_timeout = wait;
2384 priv->_agn.offchan_tx_chan = chan;
2385
2386 ret = iwl_scan_initiate(priv, priv->contexts[IWL_RXON_CTX_PAN].vif,
2387 IWL_SCAN_OFFCH_TX, chan->band);
2388 if (ret)
2389 priv->_agn.offchan_tx_skb = NULL;
2390 out:
2391 mutex_unlock(&priv->mutex);
2392 free:
2393 if (ret < 0)
2394 kfree_skb(skb);
2395
2396 return ret;
2397}
2398
2399static int iwl_mac_offchannel_tx_cancel_wait(struct ieee80211_hw *hw)
2400{
2401 struct iwl_priv *priv = hw->priv;
2402 int ret;
2403
2404 mutex_lock(&priv->mutex);
2405
Dan Carpenterf8a22a22011-03-15 10:01:58 +03002406 if (!priv->_agn.offchan_tx_skb) {
2407 ret = -EINVAL;
2408 goto unlock;
2409 }
Johannes Berg266af4c72011-03-10 20:13:26 -08002410
2411 priv->_agn.offchan_tx_skb = NULL;
2412
2413 ret = iwl_scan_cancel_timeout(priv, 200);
2414 if (ret)
2415 ret = -EIO;
Dan Carpenterf8a22a22011-03-15 10:01:58 +03002416unlock:
Johannes Berg266af4c72011-03-10 20:13:26 -08002417 mutex_unlock(&priv->mutex);
2418
2419 return ret;
2420}
2421
Zhu Yib481de92007-09-25 17:54:57 -07002422/*****************************************************************************
2423 *
2424 * mac80211 entry point functions
2425 *
2426 *****************************************************************************/
2427
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002428/*
2429 * Not a mac80211 entry point function, but it fits in with all the
2430 * other mac80211 functions grouped here.
2431 */
Johannes Bergdd7a2502010-04-28 23:33:10 -07002432static int iwl_mac_setup_register(struct iwl_priv *priv,
2433 struct iwlagn_ucode_capabilities *capa)
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002434{
2435 int ret;
2436 struct ieee80211_hw *hw = priv->hw;
Johannes Bergd0fe4782010-08-23 10:46:58 +02002437 struct iwl_rxon_context *ctx;
2438
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002439 hw->rate_control_algorithm = "iwl-agn-rs";
2440
2441 /* Tell mac80211 our characteristics */
2442 hw->flags = IEEE80211_HW_SIGNAL_DBM |
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002443 IEEE80211_HW_AMPDU_AGGREGATION |
Johannes Berg2491fa42010-08-23 10:46:52 +02002444 IEEE80211_HW_NEED_DTIM_PERIOD |
Johannes Berg6fb55112010-11-16 11:55:02 -08002445 IEEE80211_HW_SPECTRUM_MGMT |
2446 IEEE80211_HW_REPORTS_TX_ACK_STATUS;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002447
Johannes Berg9b768832011-01-19 02:54:18 -08002448 hw->max_tx_aggregation_subframes = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
2449
Wey-Yi Guy23c0fcc2011-04-01 16:29:53 -07002450 hw->flags |= IEEE80211_HW_SUPPORTS_PS |
2451 IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002452
Johannes Bergba37a3d2009-12-10 14:37:27 -08002453 if (priv->cfg->sku & IWL_SKU_N)
2454 hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
2455 IEEE80211_HW_SUPPORTS_STATIC_SMPS;
2456
Johannes Berg3997ff32011-04-05 09:42:02 -07002457 if (capa->flags & IWL_UCODE_TLV_FLAGS_MFP)
2458 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
2459
Reinette Chatre8d9698b2009-10-16 14:25:55 -07002460 hw->sta_data_size = sizeof(struct iwl_station_priv);
Johannes Bergfd1af152010-04-30 11:30:43 -07002461 hw->vif_data_size = sizeof(struct iwl_vif_priv);
2462
Johannes Bergd0fe4782010-08-23 10:46:58 +02002463 for_each_context(priv, ctx) {
2464 hw->wiphy->interface_modes |= ctx->interface_modes;
2465 hw->wiphy->interface_modes |= ctx->exclusive_interface_modes;
2466 }
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002467
Johannes Berg9b9190d2011-01-06 08:07:10 -08002468 hw->wiphy->max_remain_on_channel_duration = 1000;
2469
Reinette Chatref6c8f152010-03-12 11:13:26 -08002470 hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
Johannes Berg274102a2011-01-18 04:44:03 -08002471 WIPHY_FLAG_DISABLE_BEACON_HINTS |
2472 WIPHY_FLAG_IBSS_RSN;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002473
2474 /*
2475 * For now, disable PS by default because it affects
2476 * RX performance significantly.
2477 */
Johannes Berg5be83de2009-11-19 00:56:28 +01002478 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002479
Reinette Chatre1382c712010-02-25 10:02:19 -08002480 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002481 /* we create the 802.11 header and a zero-length SSID element */
Johannes Bergdd7a2502010-04-28 23:33:10 -07002482 hw->wiphy->max_scan_ie_len = capa->max_probe_length - 24 - 2;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002483
2484 /* Default value; 4 EDCA QOS priorities */
2485 hw->queues = 4;
2486
2487 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
2488
2489 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
2490 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
2491 &priv->bands[IEEE80211_BAND_2GHZ];
2492 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
2493 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
2494 &priv->bands[IEEE80211_BAND_5GHZ];
2495
Wey-Yi Guy5ed540a2011-01-21 15:26:39 -08002496 iwl_leds_init(priv);
2497
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002498 ret = ieee80211_register_hw(priv->hw);
2499 if (ret) {
2500 IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
2501 return ret;
2502 }
2503 priv->mac80211_registered = 1;
2504
2505 return 0;
2506}
2507
2508
Johannes Berg2dedbf52011-04-05 09:41:50 -07002509static int iwlagn_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002510{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002511 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002512 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002513
Tomas Winklere1623442009-01-27 14:27:56 -08002514 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002515
2516 /* we should be verifying the device is ready to be opened */
2517 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002518 ret = __iwl_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002519 mutex_unlock(&priv->mutex);
Zhu Yie655b9f2008-01-24 02:19:38 -08002520 if (ret)
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002521 return ret;
Zhu Yie655b9f2008-01-24 02:19:38 -08002522
Tomas Winklere1623442009-01-27 14:27:56 -08002523 IWL_DEBUG_INFO(priv, "Start UP work done.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08002524
Johannes Bergca7966c2011-04-22 10:15:23 -07002525 /* Now we should be done, and the READY bit should be set. */
2526 if (WARN_ON(!test_bit(STATUS_READY, &priv->status)))
2527 ret = -EIO;
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002528
Wey-Yi Guy5ed540a2011-01-21 15:26:39 -08002529 iwlagn_led_enable(priv);
Johannes Berge932a602009-10-02 13:44:03 -07002530
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002531 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08002532 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002533 return 0;
2534}
2535
Johannes Berg2dedbf52011-04-05 09:41:50 -07002536static void iwlagn_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002537{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002538 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002539
Tomas Winklere1623442009-01-27 14:27:56 -08002540 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas948c1712007-10-25 17:15:45 +08002541
Johannes Berg19cc1082009-05-08 13:44:36 -07002542 if (!priv->is_open)
Zhu Yie655b9f2008-01-24 02:19:38 -08002543 return;
Zhu Yie655b9f2008-01-24 02:19:38 -08002544
Zhu Yib481de92007-09-25 17:54:57 -07002545 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002546
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002547 iwl_down(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002548
2549 flush_workqueue(priv->workqueue);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002550
Stanislaw Gruszka554d1d02010-12-23 12:38:21 +01002551 /* User space software may expect getting rfkill changes
2552 * even if interface is down */
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002553 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Stanislaw Gruszka554d1d02010-12-23 12:38:21 +01002554 iwl_enable_rfkill_int(priv);
Mohamed Abbas948c1712007-10-25 17:15:45 +08002555
Tomas Winklere1623442009-01-27 14:27:56 -08002556 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002557}
2558
Johannes Berg2dedbf52011-04-05 09:41:50 -07002559static void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07002560{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002561 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002562
Tomas Winklere1623442009-01-27 14:27:56 -08002563 IWL_DEBUG_MACDUMP(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002564
Tomas Winklere1623442009-01-27 14:27:56 -08002565 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02002566 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07002567
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -07002568 if (iwlagn_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07002569 dev_kfree_skb_any(skb);
2570
Tomas Winklere1623442009-01-27 14:27:56 -08002571 IWL_DEBUG_MACDUMP(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002572}
2573
Johannes Berg2dedbf52011-04-05 09:41:50 -07002574static void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw,
2575 struct ieee80211_vif *vif,
2576 struct ieee80211_key_conf *keyconf,
2577 struct ieee80211_sta *sta,
2578 u32 iv32, u16 *phase1key)
Zhu Yib481de92007-09-25 17:54:57 -07002579{
Tomas Winkler9f586712008-11-12 13:14:05 -08002580 struct iwl_priv *priv = hw->priv;
Johannes Berga194e322010-08-27 08:53:46 -07002581 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
2582
Tomas Winklere1623442009-01-27 14:27:56 -08002583 IWL_DEBUG_MAC80211(priv, "enter\n");
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002584
Johannes Berga194e322010-08-27 08:53:46 -07002585 iwl_update_tkip_key(priv, vif_priv->ctx, keyconf, sta,
Johannes Bergb3fbdcf2010-01-21 11:40:47 +01002586 iv32, phase1key);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002587
Tomas Winklere1623442009-01-27 14:27:56 -08002588 IWL_DEBUG_MAC80211(priv, "leave\n");
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002589}
2590
Johannes Berg2dedbf52011-04-05 09:41:50 -07002591static int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2592 struct ieee80211_vif *vif,
2593 struct ieee80211_sta *sta,
2594 struct ieee80211_key_conf *key)
Zhu Yib481de92007-09-25 17:54:57 -07002595{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002596 struct iwl_priv *priv = hw->priv;
Johannes Berga194e322010-08-27 08:53:46 -07002597 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
Johannes Bergc10afb62010-08-23 10:46:43 +02002598 struct iwl_rxon_context *ctx = vif_priv->ctx;
Winkler, Tomas42986792009-01-19 15:30:22 -08002599 int ret;
2600 u8 sta_id;
2601 bool is_default_wep_key = false;
Zhu Yib481de92007-09-25 17:54:57 -07002602
Tomas Winklere1623442009-01-27 14:27:56 -08002603 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002604
Don Fry9d143e92011-04-20 15:23:57 -07002605 if (iwlagn_mod_params.sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08002606 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07002607 return -EOPNOTSUPP;
2608 }
Zhu Yib481de92007-09-25 17:54:57 -07002609
Johannes Berg274102a2011-01-18 04:44:03 -08002610 /*
2611 * To support IBSS RSN, don't program group keys in IBSS, the
2612 * hardware will then not attempt to decrypt the frames.
2613 */
2614 if (vif->type == NL80211_IFTYPE_ADHOC &&
2615 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
2616 return -EOPNOTSUPP;
2617
Johannes Berga194e322010-08-27 08:53:46 -07002618 sta_id = iwl_sta_id_or_broadcast(priv, vif_priv->ctx, sta);
Johannes Berg0af8bca2010-04-30 14:08:00 -07002619 if (sta_id == IWL_INVALID_STATION)
2620 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002621
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002622 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002623 iwl_scan_cancel_timeout(priv, 100);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002624
Johannes Berga90178fa2010-03-30 02:44:16 -07002625 /*
2626 * If we are getting WEP group key and we didn't receive any key mapping
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002627 * so far, we are in legacy wep mode (group key only), otherwise we are
2628 * in 1X mode.
Johannes Berga90178fa2010-03-30 02:44:16 -07002629 * In legacy wep mode, we use another host command to the uCode.
2630 */
Johannes Berg97359d12010-08-10 09:46:38 +02002631 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2632 key->cipher == WLAN_CIPHER_SUITE_WEP104) &&
Johannes Berg54c80672010-08-18 09:35:21 -07002633 !sta) {
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002634 if (cmd == SET_KEY)
Johannes Bergc10afb62010-08-23 10:46:43 +02002635 is_default_wep_key = !ctx->key_mapping_keys;
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002636 else
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +08002637 is_default_wep_key =
2638 (key->hw_key_idx == HW_KEY_DEFAULT);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002639 }
mabbas052c4b92007-10-25 17:15:43 +08002640
Zhu Yib481de92007-09-25 17:54:57 -07002641 switch (cmd) {
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002642 case SET_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002643 if (is_default_wep_key)
Johannes Berg2995baf2010-08-23 10:46:42 +02002644 ret = iwl_set_default_wep_key(priv, vif_priv->ctx, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002645 else
Johannes Berga194e322010-08-27 08:53:46 -07002646 ret = iwl_set_dynamic_key(priv, vif_priv->ctx,
2647 key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002648
Tomas Winklere1623442009-01-27 14:27:56 -08002649 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07002650 break;
2651 case DISABLE_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002652 if (is_default_wep_key)
Johannes Bergc10afb62010-08-23 10:46:43 +02002653 ret = iwl_remove_default_wep_key(priv, ctx, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002654 else
Johannes Bergc10afb62010-08-23 10:46:43 +02002655 ret = iwl_remove_dynamic_key(priv, ctx, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002656
Tomas Winklere1623442009-01-27 14:27:56 -08002657 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07002658 break;
2659 default:
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002660 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002661 }
2662
Johannes Berg72e15d72010-02-19 11:42:32 -08002663 mutex_unlock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08002664 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002665
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002666 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002667}
2668
Johannes Berg2dedbf52011-04-05 09:41:50 -07002669static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
2670 struct ieee80211_vif *vif,
2671 enum ieee80211_ampdu_mlme_action action,
2672 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
2673 u8 buf_size)
Tomas Winklerd783b062008-07-18 13:53:02 +08002674{
2675 struct iwl_priv *priv = hw->priv;
Johannes Berg4620fef2010-06-16 03:30:27 -07002676 int ret = -EINVAL;
Johannes Berg7b090682011-01-19 02:53:54 -08002677 struct iwl_station_priv *sta_priv = (void *) sta->drv_priv;
Tomas Winklerd783b062008-07-18 13:53:02 +08002678
Tomas Winklere1623442009-01-27 14:27:56 -08002679 IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
Johannes Berge1749612008-10-27 15:59:26 -07002680 sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08002681
2682 if (!(priv->cfg->sku & IWL_SKU_N))
2683 return -EACCES;
2684
Johannes Berg4620fef2010-06-16 03:30:27 -07002685 mutex_lock(&priv->mutex);
2686
Tomas Winklerd783b062008-07-18 13:53:02 +08002687 switch (action) {
2688 case IEEE80211_AMPDU_RX_START:
Tomas Winklere1623442009-01-27 14:27:56 -08002689 IWL_DEBUG_HT(priv, "start Rx\n");
Johannes Berg4620fef2010-06-16 03:30:27 -07002690 ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn);
2691 break;
Tomas Winklerd783b062008-07-18 13:53:02 +08002692 case IEEE80211_AMPDU_RX_STOP:
Tomas Winklere1623442009-01-27 14:27:56 -08002693 IWL_DEBUG_HT(priv, "stop Rx\n");
Johannes Berg619753f2010-04-30 11:30:46 -07002694 ret = iwl_sta_rx_agg_stop(priv, sta, tid);
Wey-Yi Guy5c2207c2009-03-17 21:51:43 -07002695 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Johannes Berg4620fef2010-06-16 03:30:27 -07002696 ret = 0;
2697 break;
Tomas Winklerd783b062008-07-18 13:53:02 +08002698 case IEEE80211_AMPDU_TX_START:
Tomas Winklere1623442009-01-27 14:27:56 -08002699 IWL_DEBUG_HT(priv, "start Tx\n");
Johannes Berg619753f2010-04-30 11:30:46 -07002700 ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn);
Wey-Yi Guyd5a0ffa2010-03-04 13:38:59 -08002701 if (ret == 0) {
2702 priv->_agn.agg_tids_count++;
2703 IWL_DEBUG_HT(priv, "priv->_agn.agg_tids_count = %u\n",
2704 priv->_agn.agg_tids_count);
2705 }
Johannes Berg4620fef2010-06-16 03:30:27 -07002706 break;
Tomas Winklerd783b062008-07-18 13:53:02 +08002707 case IEEE80211_AMPDU_TX_STOP:
Tomas Winklere1623442009-01-27 14:27:56 -08002708 IWL_DEBUG_HT(priv, "stop Tx\n");
Johannes Berg619753f2010-04-30 11:30:46 -07002709 ret = iwlagn_tx_agg_stop(priv, vif, sta, tid);
Wey-Yi Guyd5a0ffa2010-03-04 13:38:59 -08002710 if ((ret == 0) && (priv->_agn.agg_tids_count > 0)) {
2711 priv->_agn.agg_tids_count--;
2712 IWL_DEBUG_HT(priv, "priv->_agn.agg_tids_count = %u\n",
2713 priv->_agn.agg_tids_count);
2714 }
Wey-Yi Guy5c2207c2009-03-17 21:51:43 -07002715 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Johannes Berg4620fef2010-06-16 03:30:27 -07002716 ret = 0;
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002717 if (priv->cfg->ht_params &&
2718 priv->cfg->ht_params->use_rts_for_aggregation) {
Johannes Berg94597ab2010-08-09 10:57:02 -07002719 struct iwl_station_priv *sta_priv =
2720 (void *) sta->drv_priv;
2721 /*
2722 * switch off RTS/CTS if it was previously enabled
2723 */
2724
2725 sta_priv->lq_sta.lq.general_params.flags &=
2726 ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
Johannes Berg7e6a5882010-08-23 10:46:46 +02002727 iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
2728 &sta_priv->lq_sta.lq, CMD_ASYNC, false);
Johannes Berg94597ab2010-08-09 10:57:02 -07002729 }
Johannes Berg4620fef2010-06-16 03:30:27 -07002730 break;
Wey-Yi Guyf0527972010-01-08 10:04:41 -08002731 case IEEE80211_AMPDU_TX_OPERATIONAL:
Johannes Bergc8823ec2011-03-15 11:33:03 -07002732 buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF);
2733
2734 iwlagn_txq_agg_queue_setup(priv, sta, tid, buf_size);
2735
Johannes Berg7b090682011-01-19 02:53:54 -08002736 /*
2737 * If the limit is 0, then it wasn't initialised yet,
2738 * use the default. We can do that since we take the
2739 * minimum below, and we don't want to go above our
2740 * default due to hardware restrictions.
2741 */
2742 if (sta_priv->max_agg_bufsize == 0)
2743 sta_priv->max_agg_bufsize =
2744 LINK_QUAL_AGG_FRAME_LIMIT_DEF;
2745
2746 /*
2747 * Even though in theory the peer could have different
2748 * aggregation reorder buffer sizes for different sessions,
2749 * our ucode doesn't allow for that and has a global limit
2750 * for each station. Therefore, use the minimum of all the
2751 * aggregation sessions and our default value.
2752 */
2753 sta_priv->max_agg_bufsize =
2754 min(sta_priv->max_agg_bufsize, buf_size);
2755
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002756 if (priv->cfg->ht_params &&
2757 priv->cfg->ht_params->use_rts_for_aggregation) {
Wey-Yi Guycfecc6b2010-06-18 11:33:15 -07002758 /*
2759 * switch to RTS/CTS if it is the prefer protection
2760 * method for HT traffic
2761 */
Johannes Berg94597ab2010-08-09 10:57:02 -07002762
2763 sta_priv->lq_sta.lq.general_params.flags |=
2764 LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
Wey-Yi Guycfecc6b2010-06-18 11:33:15 -07002765 }
Johannes Berg7b090682011-01-19 02:53:54 -08002766
2767 sta_priv->lq_sta.lq.agg_params.agg_frame_cnt_limit =
2768 sta_priv->max_agg_bufsize;
2769
2770 iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
2771 &sta_priv->lq_sta.lq, CMD_ASYNC, false);
Wey-Yi Guycfecc6b2010-06-18 11:33:15 -07002772 ret = 0;
Tomas Winklerd783b062008-07-18 13:53:02 +08002773 break;
2774 }
Johannes Berg4620fef2010-06-16 03:30:27 -07002775 mutex_unlock(&priv->mutex);
2776
2777 return ret;
Tomas Winklerd783b062008-07-18 13:53:02 +08002778}
Tomas Winkler9f586712008-11-12 13:14:05 -08002779
Johannes Berg2dedbf52011-04-05 09:41:50 -07002780static int iwlagn_mac_sta_add(struct ieee80211_hw *hw,
2781 struct ieee80211_vif *vif,
2782 struct ieee80211_sta *sta)
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002783{
2784 struct iwl_priv *priv = hw->priv;
2785 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
Johannes Berga194e322010-08-27 08:53:46 -07002786 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
Johannes Bergeafdfbd32010-04-29 04:43:04 -07002787 bool is_ap = vif->type == NL80211_IFTYPE_STATION;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002788 int ret;
2789 u8 sta_id;
2790
2791 IWL_DEBUG_INFO(priv, "received request to add station %pM\n",
2792 sta->addr);
Reinette Chatreda5ae1c2010-05-28 09:28:39 -07002793 mutex_lock(&priv->mutex);
2794 IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
2795 sta->addr);
2796 sta_priv->common.sta_id = IWL_INVALID_STATION;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002797
2798 atomic_set(&sta_priv->pending_frames, 0);
2799 if (vif->type == NL80211_IFTYPE_AP)
2800 sta_priv->client = true;
2801
Johannes Berga194e322010-08-27 08:53:46 -07002802 ret = iwl_add_station_common(priv, vif_priv->ctx, sta->addr,
Johannes Berg238d7812010-08-23 10:46:45 +02002803 is_ap, sta, &sta_id);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002804 if (ret) {
2805 IWL_ERR(priv, "Unable to add station %pM (%d)\n",
2806 sta->addr, ret);
2807 /* Should we return success if return code is EEXIST ? */
Reinette Chatreda5ae1c2010-05-28 09:28:39 -07002808 mutex_unlock(&priv->mutex);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002809 return ret;
2810 }
2811
Johannes Bergfd1af152010-04-30 11:30:43 -07002812 sta_priv->common.sta_id = sta_id;
2813
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002814 /* Initialize rate scaling */
Frans Pop91dd6c22010-03-24 14:19:58 -07002815 IWL_DEBUG_INFO(priv, "Initializing rate scaling for station %pM\n",
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002816 sta->addr);
2817 iwl_rs_rate_init(priv, sta, sta_id);
Reinette Chatreda5ae1c2010-05-28 09:28:39 -07002818 mutex_unlock(&priv->mutex);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002819
Johannes Bergfd1af152010-04-30 11:30:43 -07002820 return 0;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002821}
2822
Johannes Berg2dedbf52011-04-05 09:41:50 -07002823static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
2824 struct ieee80211_channel_switch *ch_switch)
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002825{
2826 struct iwl_priv *priv = hw->priv;
2827 const struct iwl_channel_info *ch_info;
2828 struct ieee80211_conf *conf = &hw->conf;
Shanyu Zhaoaa2dc6b2010-07-28 13:40:39 -07002829 struct ieee80211_channel *channel = ch_switch->channel;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002830 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
Johannes Berg246ed352010-08-23 10:46:32 +02002831 /*
2832 * MULTI-FIXME
2833 * When we add support for multiple interfaces, we need to
2834 * revisit this. The channel switch command in the device
2835 * only affects the BSS context, but what does that really
2836 * mean? And what if we get a CSA on the second interface?
2837 * This needs a lot of work.
2838 */
2839 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002840 u16 ch;
2841 unsigned long flags = 0;
2842
2843 IWL_DEBUG_MAC80211(priv, "enter\n");
2844
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +02002845 mutex_lock(&priv->mutex);
2846
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002847 if (iwl_is_rfkill(priv))
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +02002848 goto out;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002849
2850 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
2851 test_bit(STATUS_SCANNING, &priv->status))
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +02002852 goto out;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002853
Johannes Berg246ed352010-08-23 10:46:32 +02002854 if (!iwl_is_associated_ctx(ctx))
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +02002855 goto out;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002856
2857 /* channel switch in progress */
2858 if (priv->switch_rxon.switch_in_progress == true)
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +02002859 goto out;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002860
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002861 if (priv->cfg->ops->lib->set_channel_switch) {
2862
Shanyu Zhaoaa2dc6b2010-07-28 13:40:39 -07002863 ch = channel->hw_value;
Johannes Berg246ed352010-08-23 10:46:32 +02002864 if (le16_to_cpu(ctx->active.channel) != ch) {
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002865 ch_info = iwl_get_channel_info(priv,
Shanyu Zhaoaa2dc6b2010-07-28 13:40:39 -07002866 channel->band,
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002867 ch);
2868 if (!is_channel_valid(ch_info)) {
2869 IWL_DEBUG_MAC80211(priv, "invalid channel\n");
2870 goto out;
2871 }
2872 spin_lock_irqsave(&priv->lock, flags);
2873
2874 priv->current_ht_config.smps = conf->smps_mode;
2875
2876 /* Configure HT40 channels */
Johannes Berg7e6a5882010-08-23 10:46:46 +02002877 ctx->ht.enabled = conf_is_ht(conf);
2878 if (ctx->ht.enabled) {
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002879 if (conf_is_ht40_minus(conf)) {
Johannes Berg7e6a5882010-08-23 10:46:46 +02002880 ctx->ht.extension_chan_offset =
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002881 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
Johannes Berg7e6a5882010-08-23 10:46:46 +02002882 ctx->ht.is_40mhz = true;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002883 } else if (conf_is_ht40_plus(conf)) {
Johannes Berg7e6a5882010-08-23 10:46:46 +02002884 ctx->ht.extension_chan_offset =
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002885 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
Johannes Berg7e6a5882010-08-23 10:46:46 +02002886 ctx->ht.is_40mhz = true;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002887 } else {
Johannes Berg7e6a5882010-08-23 10:46:46 +02002888 ctx->ht.extension_chan_offset =
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002889 IEEE80211_HT_PARAM_CHA_SEC_NONE;
Johannes Berg7e6a5882010-08-23 10:46:46 +02002890 ctx->ht.is_40mhz = false;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002891 }
2892 } else
Johannes Berg7e6a5882010-08-23 10:46:46 +02002893 ctx->ht.is_40mhz = false;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002894
Johannes Berg246ed352010-08-23 10:46:32 +02002895 if ((le16_to_cpu(ctx->staging.channel) != ch))
2896 ctx->staging.flags = 0;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002897
Johannes Berg246ed352010-08-23 10:46:32 +02002898 iwl_set_rxon_channel(priv, channel, ctx);
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002899 iwl_set_rxon_ht(priv, ht_conf);
Johannes Berg246ed352010-08-23 10:46:32 +02002900 iwl_set_flags_for_band(priv, ctx, channel->band,
Johannes Berg8bd413e2010-08-23 10:46:40 +02002901 ctx->vif);
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002902 spin_unlock_irqrestore(&priv->lock, flags);
2903
2904 iwl_set_rate(priv);
2905 /*
2906 * at this point, staging_rxon has the
2907 * configuration for channel switch
2908 */
2909 if (priv->cfg->ops->lib->set_channel_switch(priv,
2910 ch_switch))
2911 priv->switch_rxon.switch_in_progress = false;
2912 }
2913 }
2914out:
2915 mutex_unlock(&priv->mutex);
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002916 if (!priv->switch_rxon.switch_in_progress)
Johannes Berg8bd413e2010-08-23 10:46:40 +02002917 ieee80211_chswitch_done(ctx->vif, false);
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002918 IWL_DEBUG_MAC80211(priv, "leave\n");
2919}
2920
Johannes Berg2dedbf52011-04-05 09:41:50 -07002921static void iwlagn_configure_filter(struct ieee80211_hw *hw,
2922 unsigned int changed_flags,
2923 unsigned int *total_flags,
2924 u64 multicast)
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02002925{
2926 struct iwl_priv *priv = hw->priv;
2927 __le32 filter_or = 0, filter_nand = 0;
Johannes Berg246ed352010-08-23 10:46:32 +02002928 struct iwl_rxon_context *ctx;
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02002929
2930#define CHK(test, flag) do { \
2931 if (*total_flags & (test)) \
2932 filter_or |= (flag); \
2933 else \
2934 filter_nand |= (flag); \
2935 } while (0)
2936
2937 IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
2938 changed_flags, *total_flags);
2939
2940 CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
Johannes Bergbdb84fe2010-12-15 06:07:56 -08002941 /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */
2942 CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK);
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02002943 CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
2944
2945#undef CHK
2946
2947 mutex_lock(&priv->mutex);
2948
Johannes Berg246ed352010-08-23 10:46:32 +02002949 for_each_context(priv, ctx) {
2950 ctx->staging.filter_flags &= ~filter_nand;
2951 ctx->staging.filter_flags |= filter_or;
Stanislaw Gruszka749ff4ef2010-10-22 17:04:27 +02002952
2953 /*
2954 * Not committing directly because hardware can perform a scan,
2955 * but we'll eventually commit the filter flags change anyway.
2956 */
Johannes Berg246ed352010-08-23 10:46:32 +02002957 }
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02002958
2959 mutex_unlock(&priv->mutex);
2960
2961 /*
2962 * Receiving all multicast frames is always enabled by the
2963 * default flags setup in iwl_connection_init_rx_config()
2964 * since we currently do not support programming multicast
2965 * filters into the device.
2966 */
2967 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
2968 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
2969}
2970
Johannes Berg2dedbf52011-04-05 09:41:50 -07002971static void iwlagn_mac_flush(struct ieee80211_hw *hw, bool drop)
Wey-Yi Guy716c74b2010-06-24 13:22:36 -07002972{
2973 struct iwl_priv *priv = hw->priv;
2974
2975 mutex_lock(&priv->mutex);
2976 IWL_DEBUG_MAC80211(priv, "enter\n");
2977
2978 /* do not support "flush" */
2979 if (!priv->cfg->ops->lib->txfifo_flush)
2980 goto done;
2981
2982 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
2983 IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n");
2984 goto done;
2985 }
2986 if (iwl_is_rfkill(priv)) {
2987 IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n");
2988 goto done;
2989 }
2990
2991 /*
2992 * mac80211 will not push any more frames for transmit
2993 * until the flush is completed
2994 */
2995 if (drop) {
2996 IWL_DEBUG_MAC80211(priv, "send flush command\n");
2997 if (priv->cfg->ops->lib->txfifo_flush(priv, IWL_DROP_ALL)) {
2998 IWL_ERR(priv, "flush request fail\n");
2999 goto done;
3000 }
3001 }
3002 IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n");
3003 iwlagn_wait_tx_queue_empty(priv);
3004done:
3005 mutex_unlock(&priv->mutex);
3006 IWL_DEBUG_MAC80211(priv, "leave\n");
3007}
3008
Johannes Berg9b9190d2011-01-06 08:07:10 -08003009static void iwlagn_disable_roc(struct iwl_priv *priv)
3010{
3011 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
3012 struct ieee80211_channel *chan = ACCESS_ONCE(priv->hw->conf.channel);
3013
3014 lockdep_assert_held(&priv->mutex);
3015
3016 if (!ctx->is_active)
3017 return;
3018
3019 ctx->staging.dev_type = RXON_DEV_TYPE_2STA;
3020 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3021 iwl_set_rxon_channel(priv, chan, ctx);
3022 iwl_set_flags_for_band(priv, ctx, chan->band, NULL);
3023
3024 priv->_agn.hw_roc_channel = NULL;
3025
Wey-Yi Guy80b38ff2011-02-04 10:46:41 -08003026 iwlcore_commit_rxon(priv, ctx);
Johannes Berg9b9190d2011-01-06 08:07:10 -08003027
3028 ctx->is_active = false;
3029}
3030
3031static void iwlagn_bg_roc_done(struct work_struct *work)
3032{
3033 struct iwl_priv *priv = container_of(work, struct iwl_priv,
3034 _agn.hw_roc_work.work);
3035
3036 mutex_lock(&priv->mutex);
3037 ieee80211_remain_on_channel_expired(priv->hw);
3038 iwlagn_disable_roc(priv);
3039 mutex_unlock(&priv->mutex);
3040}
3041
3042static int iwl_mac_remain_on_channel(struct ieee80211_hw *hw,
3043 struct ieee80211_channel *channel,
3044 enum nl80211_channel_type channel_type,
3045 int duration)
3046{
3047 struct iwl_priv *priv = hw->priv;
3048 int err = 0;
3049
3050 if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
3051 return -EOPNOTSUPP;
3052
3053 if (!(priv->contexts[IWL_RXON_CTX_PAN].interface_modes &
3054 BIT(NL80211_IFTYPE_P2P_CLIENT)))
3055 return -EOPNOTSUPP;
3056
3057 mutex_lock(&priv->mutex);
3058
3059 if (priv->contexts[IWL_RXON_CTX_PAN].is_active ||
3060 test_bit(STATUS_SCAN_HW, &priv->status)) {
3061 err = -EBUSY;
3062 goto out;
3063 }
3064
3065 priv->contexts[IWL_RXON_CTX_PAN].is_active = true;
3066 priv->_agn.hw_roc_channel = channel;
3067 priv->_agn.hw_roc_chantype = channel_type;
3068 priv->_agn.hw_roc_duration = DIV_ROUND_UP(duration * 1000, 1024);
Wey-Yi Guy80b38ff2011-02-04 10:46:41 -08003069 iwlcore_commit_rxon(priv, &priv->contexts[IWL_RXON_CTX_PAN]);
Johannes Berg9b9190d2011-01-06 08:07:10 -08003070 queue_delayed_work(priv->workqueue, &priv->_agn.hw_roc_work,
3071 msecs_to_jiffies(duration + 20));
3072
Johannes Berg94073912011-01-06 08:07:11 -08003073 msleep(IWL_MIN_SLOT_TIME); /* TU is almost ms */
Johannes Berg9b9190d2011-01-06 08:07:10 -08003074 ieee80211_ready_on_channel(priv->hw);
3075
3076 out:
3077 mutex_unlock(&priv->mutex);
3078
3079 return err;
3080}
3081
3082static int iwl_mac_cancel_remain_on_channel(struct ieee80211_hw *hw)
3083{
3084 struct iwl_priv *priv = hw->priv;
3085
3086 if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
3087 return -EOPNOTSUPP;
3088
3089 cancel_delayed_work_sync(&priv->_agn.hw_roc_work);
3090
3091 mutex_lock(&priv->mutex);
3092 iwlagn_disable_roc(priv);
3093 mutex_unlock(&priv->mutex);
3094
3095 return 0;
3096}
3097
Zhu Yib481de92007-09-25 17:54:57 -07003098/*****************************************************************************
3099 *
Zhu Yib481de92007-09-25 17:54:57 -07003100 * driver setup and teardown
3101 *
3102 *****************************************************************************/
3103
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003104static void iwl_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003105{
Reinette Chatred21050c2009-02-13 11:51:18 -08003106 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07003107
3108 init_waitqueue_head(&priv->wait_command_queue);
3109
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003110 INIT_WORK(&priv->restart, iwl_bg_restart);
3111 INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003112 INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08003113 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
Wey-Yi Guy65550632010-06-24 13:18:35 -07003114 INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
Wey-Yi Guybee008b2010-08-23 07:57:04 -07003115 INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
Wey-Yi Guyfbba9412010-08-23 07:57:10 -07003116 INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
Johannes Berg9b9190d2011-01-06 08:07:10 -08003117 INIT_DELAYED_WORK(&priv->_agn.hw_roc_work, iwlagn_bg_roc_done);
Tomas Winkler2a421b92008-06-12 09:47:10 +08003118
Tomas Winkler2a421b92008-06-12 09:47:10 +08003119 iwl_setup_scan_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003120
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003121 if (priv->cfg->ops->lib->setup_deferred_work)
3122 priv->cfg->ops->lib->setup_deferred_work(priv);
3123
3124 init_timer(&priv->statistics_periodic);
3125 priv->statistics_periodic.data = (unsigned long)priv;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003126 priv->statistics_periodic.function = iwl_bg_statistics_periodic;
Zhu Yib481de92007-09-25 17:54:57 -07003127
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08003128 init_timer(&priv->ucode_trace);
3129 priv->ucode_trace.data = (unsigned long)priv;
3130 priv->ucode_trace.function = iwl_bg_ucode_trace;
3131
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01003132 init_timer(&priv->watchdog);
3133 priv->watchdog.data = (unsigned long)priv;
3134 priv->watchdog.function = iwl_bg_watchdog;
Wey-Yi Guyb74e31a2010-03-01 17:23:50 -08003135
Wey-Yi Guyd6b80612011-03-21 16:53:38 -07003136 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
3137 iwl_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07003138}
3139
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003140static void iwl_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003141{
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003142 if (priv->cfg->ops->lib->cancel_deferred_work)
3143 priv->cfg->ops->lib->cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003144
Wey-Yi Guy815e6292010-06-03 10:14:01 -07003145 cancel_work_sync(&priv->run_time_calib_work);
Zhu Yib481de92007-09-25 17:54:57 -07003146 cancel_work_sync(&priv->beacon_update);
Stanislaw Gruszkae7e16b92010-09-13 14:46:41 +02003147
3148 iwl_cancel_scan_deferred_work(priv);
3149
Wey-Yi Guybee008b2010-08-23 07:57:04 -07003150 cancel_work_sync(&priv->bt_full_concurrency);
Wey-Yi Guyfbba9412010-08-23 07:57:10 -07003151 cancel_work_sync(&priv->bt_runtime_config);
Stanislaw Gruszkae7e16b92010-09-13 14:46:41 +02003152
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003153 del_timer_sync(&priv->statistics_periodic);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08003154 del_timer_sync(&priv->ucode_trace);
Zhu Yib481de92007-09-25 17:54:57 -07003155}
3156
Reinette Chatre89f186a2009-10-30 14:36:11 -07003157static void iwl_init_hw_rates(struct iwl_priv *priv,
3158 struct ieee80211_rate *rates)
3159{
3160 int i;
3161
3162 for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
3163 rates[i].bitrate = iwl_rates[i].ieee * 5;
3164 rates[i].hw_value = i; /* Rate scaling will work on indexes */
3165 rates[i].hw_value_short = i;
3166 rates[i].flags = 0;
3167 if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
3168 /*
3169 * If CCK != 1M then set short preamble rate flag.
3170 */
3171 rates[i].flags |=
3172 (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
3173 0 : IEEE80211_RATE_SHORT_PREAMBLE;
3174 }
3175 }
3176}
3177
3178static int iwl_init_drv(struct iwl_priv *priv)
3179{
3180 int ret;
3181
Reinette Chatre89f186a2009-10-30 14:36:11 -07003182 spin_lock_init(&priv->sta_lock);
3183 spin_lock_init(&priv->hcmd_lock);
3184
Reinette Chatre89f186a2009-10-30 14:36:11 -07003185 mutex_init(&priv->mutex);
3186
Reinette Chatre89f186a2009-10-30 14:36:11 -07003187 priv->ieee_channels = NULL;
3188 priv->ieee_rates = NULL;
3189 priv->band = IEEE80211_BAND_2GHZ;
3190
3191 priv->iw_mode = NL80211_IFTYPE_STATION;
Johannes Bergba37a3d2009-12-10 14:37:27 -08003192 priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
Wey-Yi Guya13d2762010-01-22 14:22:42 -08003193 priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
Wey-Yi Guyd5a0ffa2010-03-04 13:38:59 -08003194 priv->_agn.agg_tids_count = 0;
Reinette Chatre89f186a2009-10-30 14:36:11 -07003195
Wey-Yi Guy8a472da2010-02-18 22:03:06 -08003196 /* initialize force reset */
3197 priv->force_reset[IWL_RF_RESET].reset_duration =
3198 IWL_DELAY_NEXT_FORCE_RF_RESET;
3199 priv->force_reset[IWL_FW_RESET].reset_duration =
3200 IWL_DELAY_NEXT_FORCE_FW_RELOAD;
Reinette Chatre89f186a2009-10-30 14:36:11 -07003201
Stanislaw Gruszka410f2bb2011-03-04 17:51:51 +01003202 priv->rx_statistics_jiffies = jiffies;
3203
Reinette Chatre89f186a2009-10-30 14:36:11 -07003204 /* Choose which receivers/antennas to use */
3205 if (priv->cfg->ops->hcmd->set_rxon_chain)
Johannes Berg246ed352010-08-23 10:46:32 +02003206 priv->cfg->ops->hcmd->set_rxon_chain(priv,
3207 &priv->contexts[IWL_RXON_CTX_BSS]);
Reinette Chatre89f186a2009-10-30 14:36:11 -07003208
3209 iwl_init_scan_params(priv);
3210
Wey-Yi Guy22bf59a2010-08-23 07:57:11 -07003211 /* init bt coex */
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07003212 if (priv->cfg->bt_params &&
3213 priv->cfg->bt_params->advanced_bt_coexist) {
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07003214 priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
3215 priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
3216 priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
Wey-Yi Guy22bf59a2010-08-23 07:57:11 -07003217 priv->bt_on_thresh = BT_ON_THRESHOLD_DEF;
3218 priv->bt_duration = BT_DURATION_LIMIT_DEF;
3219 priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
Wey-Yi Guy22bf59a2010-08-23 07:57:11 -07003220 }
3221
Reinette Chatre89f186a2009-10-30 14:36:11 -07003222 ret = iwl_init_channel_map(priv);
3223 if (ret) {
3224 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
3225 goto err;
3226 }
3227
3228 ret = iwlcore_init_geos(priv);
3229 if (ret) {
3230 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
3231 goto err_free_channel_map;
3232 }
3233 iwl_init_hw_rates(priv, priv->ieee_rates);
3234
3235 return 0;
3236
3237err_free_channel_map:
3238 iwl_free_channel_map(priv);
3239err:
3240 return ret;
3241}
3242
3243static void iwl_uninit_drv(struct iwl_priv *priv)
3244{
3245 iwl_calib_free_results(priv);
3246 iwlcore_free_geos(priv);
3247 iwl_free_channel_map(priv);
Johannes Berg811ecc92010-04-06 04:12:41 -07003248 kfree(priv->scan_cmd);
Reinette Chatre89f186a2009-10-30 14:36:11 -07003249}
3250
Johannes Bergdc21b542010-10-23 09:15:39 -07003251struct ieee80211_ops iwlagn_hw_ops = {
Johannes Berg2295c662010-10-23 09:15:41 -07003252 .tx = iwlagn_mac_tx,
3253 .start = iwlagn_mac_start,
3254 .stop = iwlagn_mac_stop,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003255 .add_interface = iwl_mac_add_interface,
3256 .remove_interface = iwl_mac_remove_interface,
Johannes Bergd4daaea2010-10-23 09:15:43 -07003257 .change_interface = iwl_mac_change_interface,
Johannes Berg2295c662010-10-23 09:15:41 -07003258 .config = iwlagn_mac_config,
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02003259 .configure_filter = iwlagn_configure_filter,
Johannes Berg2295c662010-10-23 09:15:41 -07003260 .set_key = iwlagn_mac_set_key,
3261 .update_tkip_key = iwlagn_mac_update_tkip_key,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003262 .conf_tx = iwl_mac_conf_tx,
Johannes Berg2295c662010-10-23 09:15:41 -07003263 .bss_info_changed = iwlagn_bss_info_changed,
3264 .ampdu_action = iwlagn_mac_ampdu_action,
Johannes Berg6ab10ff2009-11-13 11:56:37 -08003265 .hw_scan = iwl_mac_hw_scan,
Johannes Berg2295c662010-10-23 09:15:41 -07003266 .sta_notify = iwlagn_mac_sta_notify,
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003267 .sta_add = iwlagn_mac_sta_add,
3268 .sta_remove = iwl_mac_sta_remove,
Johannes Berg2295c662010-10-23 09:15:41 -07003269 .channel_switch = iwlagn_mac_channel_switch,
3270 .flush = iwlagn_mac_flush,
Johannes Berga85d7cc2010-07-31 08:34:10 -07003271 .tx_last_beacon = iwl_mac_tx_last_beacon,
Johannes Berg9b9190d2011-01-06 08:07:10 -08003272 .remain_on_channel = iwl_mac_remain_on_channel,
3273 .cancel_remain_on_channel = iwl_mac_cancel_remain_on_channel,
Johannes Berg266af4c72011-03-10 20:13:26 -08003274 .offchannel_tx = iwl_mac_offchannel_tx,
3275 .offchannel_tx_cancel_wait = iwl_mac_offchannel_tx_cancel_wait,
Cindy H. Kao4613e722011-05-06 10:40:15 -07003276 CFG80211_TESTMODE_CMD(iwl_testmode_cmd)
Zhu Yib481de92007-09-25 17:54:57 -07003277};
3278
Johannes Berge98a1302011-04-05 09:42:08 -07003279static u32 iwl_hw_detect(struct iwl_priv *priv)
Wey-Yi Guy3867fe02010-07-31 08:34:05 -07003280{
Johannes Bergc2974a12011-04-05 09:42:09 -07003281 u8 rev_id;
3282
3283 pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &rev_id);
3284 IWL_DEBUG_INFO(priv, "HW Revision ID = 0x%X\n", rev_id);
Johannes Berg02a7fa02011-04-05 09:42:12 -07003285 return iwl_read32(priv, CSR_HW_REV);
Wey-Yi Guy3867fe02010-07-31 08:34:05 -07003286}
3287
Wey-Yi Guy07d4f1a2010-07-31 08:34:08 -07003288static int iwl_set_hw_params(struct iwl_priv *priv)
3289{
3290 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
3291 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
Don Fry9d143e92011-04-20 15:23:57 -07003292 if (iwlagn_mod_params.amsdu_size_8K)
Wey-Yi Guy07d4f1a2010-07-31 08:34:08 -07003293 priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_8K);
3294 else
3295 priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_4K);
3296
3297 priv->hw_params.max_beacon_itrvl = IWL_MAX_UCODE_BEACON_INTERVAL;
3298
Don Fry9d143e92011-04-20 15:23:57 -07003299 if (iwlagn_mod_params.disable_11n)
Wey-Yi Guy07d4f1a2010-07-31 08:34:08 -07003300 priv->cfg->sku &= ~IWL_SKU_N;
3301
3302 /* Device-specific setup */
3303 return priv->cfg->ops->lib->set_hw_params(priv);
3304}
3305
Johannes Berge72f3682010-08-23 10:46:51 +02003306static const u8 iwlagn_bss_ac_to_fifo[] = {
3307 IWL_TX_FIFO_VO,
3308 IWL_TX_FIFO_VI,
3309 IWL_TX_FIFO_BE,
3310 IWL_TX_FIFO_BK,
3311};
3312
3313static const u8 iwlagn_bss_ac_to_queue[] = {
3314 0, 1, 2, 3,
3315};
3316
3317static const u8 iwlagn_pan_ac_to_fifo[] = {
3318 IWL_TX_FIFO_VO_IPAN,
3319 IWL_TX_FIFO_VI_IPAN,
3320 IWL_TX_FIFO_BE_IPAN,
3321 IWL_TX_FIFO_BK_IPAN,
3322};
3323
3324static const u8 iwlagn_pan_ac_to_queue[] = {
3325 7, 6, 5, 4,
3326};
3327
Wey-Yi Guy119ea182011-04-18 09:34:06 -07003328/* This function both allocates and initializes hw and priv. */
3329static struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg)
3330{
3331 struct iwl_priv *priv;
3332 /* mac80211 allocates memory for this device instance, including
3333 * space for this driver's private structure */
3334 struct ieee80211_hw *hw;
3335
3336 hw = ieee80211_alloc_hw(sizeof(struct iwl_priv), &iwlagn_hw_ops);
3337 if (hw == NULL) {
3338 pr_err("%s: Can not allocate network device\n",
3339 cfg->name);
3340 goto out;
3341 }
3342
3343 priv = hw->priv;
3344 priv->hw = hw;
3345
3346out:
3347 return hw;
3348}
3349
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003350static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07003351{
Johannes Berg246ed352010-08-23 10:46:32 +02003352 int err = 0, i;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003353 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07003354 struct ieee80211_hw *hw;
Tomas Winkler82b9a122008-03-04 18:09:30 -08003355 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003356 unsigned long flags;
Wey-Yi Guyc6fa17e2010-07-15 05:58:30 -07003357 u16 pci_cmd, num_mac;
Johannes Berge98a1302011-04-05 09:42:08 -07003358 u32 hw_rev;
Zhu Yib481de92007-09-25 17:54:57 -07003359
Assaf Krauss316c30d2008-03-14 10:38:46 -07003360 /************************
3361 * 1. Allocating HW data
3362 ************************/
3363
Johannes Bergdc21b542010-10-23 09:15:39 -07003364 hw = iwl_alloc_all(cfg);
Assaf Krauss1d0a0822008-03-14 10:38:48 -07003365 if (!hw) {
Zhu Yib481de92007-09-25 17:54:57 -07003366 err = -ENOMEM;
3367 goto out;
3368 }
Assaf Krauss1d0a0822008-03-14 10:38:48 -07003369 priv = hw->priv;
3370 /* At this point both hw and priv are allocated. */
3371
Johannes Bergca7966c2011-04-22 10:15:23 -07003372 priv->ucode_type = UCODE_SUBTYPE_NONE_LOADED;
3373
Johannes Berg246ed352010-08-23 10:46:32 +02003374 /*
3375 * The default context is always valid,
3376 * more may be discovered when firmware
3377 * is loaded.
3378 */
3379 priv->valid_contexts = BIT(IWL_RXON_CTX_BSS);
3380
3381 for (i = 0; i < NUM_IWL_RXON_CTX; i++)
3382 priv->contexts[i].ctxid = i;
3383
Johannes Berg763cc3b2010-09-03 06:32:21 -07003384 priv->contexts[IWL_RXON_CTX_BSS].always_active = true;
3385 priv->contexts[IWL_RXON_CTX_BSS].is_active = true;
Johannes Berg8f2d3d22010-08-23 10:46:37 +02003386 priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
3387 priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
3388 priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
Johannes Berg8dfdb9d2010-08-23 10:46:38 +02003389 priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
Johannes Berg2995baf2010-08-23 10:46:42 +02003390 priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
Johannes Bergc10afb62010-08-23 10:46:43 +02003391 priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
Johannes Berge72f3682010-08-23 10:46:51 +02003392 priv->contexts[IWL_RXON_CTX_BSS].ac_to_fifo = iwlagn_bss_ac_to_fifo;
3393 priv->contexts[IWL_RXON_CTX_BSS].ac_to_queue = iwlagn_bss_ac_to_queue;
Johannes Bergd0fe4782010-08-23 10:46:58 +02003394 priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
3395 BIT(NL80211_IFTYPE_ADHOC);
3396 priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
3397 BIT(NL80211_IFTYPE_STATION);
Johannes Berg2295c662010-10-23 09:15:41 -07003398 priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP;
Johannes Bergd0fe4782010-08-23 10:46:58 +02003399 priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
3400 priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
3401 priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
Johannes Bergece9c4e2010-08-23 10:46:49 +02003402
3403 priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON;
3404 priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd = REPLY_WIPAN_RXON_TIMING;
3405 priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd = REPLY_WIPAN_RXON_ASSOC;
3406 priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM;
3407 priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN;
3408 priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY;
3409 priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID;
3410 priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION;
Johannes Berge72f3682010-08-23 10:46:51 +02003411 priv->contexts[IWL_RXON_CTX_PAN].ac_to_fifo = iwlagn_pan_ac_to_fifo;
3412 priv->contexts[IWL_RXON_CTX_PAN].ac_to_queue = iwlagn_pan_ac_to_queue;
3413 priv->contexts[IWL_RXON_CTX_PAN].mcast_queue = IWL_IPAN_MCAST_QUEUE;
Johannes Bergd0fe4782010-08-23 10:46:58 +02003414 priv->contexts[IWL_RXON_CTX_PAN].interface_modes =
3415 BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
Wey-Yi Guyf35c0c52011-01-13 17:09:29 -08003416#ifdef CONFIG_IWL_P2P
3417 priv->contexts[IWL_RXON_CTX_PAN].interface_modes |=
3418 BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO);
3419#endif
Johannes Bergd0fe4782010-08-23 10:46:58 +02003420 priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP;
3421 priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA;
3422 priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P;
Johannes Bergece9c4e2010-08-23 10:46:49 +02003423
3424 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
Johannes Berg8f2d3d22010-08-23 10:46:37 +02003425
Zhu Yib481de92007-09-25 17:54:57 -07003426 SET_IEEE80211_DEV(hw, &pdev->dev);
3427
Tomas Winklere1623442009-01-27 14:27:56 -08003428 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Tomas Winkler82b9a122008-03-04 18:09:30 -08003429 priv->cfg = cfg;
Zhu Yib481de92007-09-25 17:54:57 -07003430 priv->pci_dev = pdev;
Mohamed Abbas40cefda2009-05-22 11:01:52 -07003431 priv->inta_mask = CSR_INI_SET_MASK;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003432
Wey-Yi Guybee008b2010-08-23 07:57:04 -07003433 /* is antenna coupling more than 35dB ? */
3434 priv->bt_ant_couple_ok =
3435 (iwlagn_ant_coupling > IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
3436 true : false;
3437
Wey-Yi Guy9f28ebc2010-11-26 13:24:19 -08003438 /* enable/disable bt channel inhibition */
Wey-Yi Guyf37837c2010-08-23 07:57:12 -07003439 priv->bt_ch_announce = iwlagn_bt_ch_announce;
Wey-Yi Guy9f28ebc2010-11-26 13:24:19 -08003440 IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n",
3441 (priv->bt_ch_announce) ? "On" : "Off");
Wey-Yi Guyf37837c2010-08-23 07:57:12 -07003442
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003443 if (iwl_alloc_traffic_mem(priv))
3444 IWL_ERR(priv, "Not enough memory to generate traffic log\n");
Zhu Yib481de92007-09-25 17:54:57 -07003445
Assaf Krauss316c30d2008-03-14 10:38:46 -07003446 /**************************
3447 * 2. Initializing PCI bus
3448 **************************/
John W. Linville1a7123c2010-08-05 14:39:31 -04003449 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
3450 PCIE_LINK_STATE_CLKPM);
3451
Assaf Krauss316c30d2008-03-14 10:38:46 -07003452 if (pci_enable_device(pdev)) {
3453 err = -ENODEV;
3454 goto out_ieee80211_free_hw;
3455 }
3456
3457 pci_set_master(pdev);
3458
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003459 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
Assaf Krauss316c30d2008-03-14 10:38:46 -07003460 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003461 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003462 if (err) {
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003463 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003464 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003465 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003466 /* both attempts failed: */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003467 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08003468 IWL_WARN(priv, "No suitable DMA available.\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07003469 goto out_pci_disable_device;
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003470 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07003471 }
3472
3473 err = pci_request_regions(pdev, DRV_NAME);
3474 if (err)
3475 goto out_pci_disable_device;
3476
3477 pci_set_drvdata(pdev, priv);
3478
Assaf Krauss316c30d2008-03-14 10:38:46 -07003479
3480 /***********************
3481 * 3. Read REV register
3482 ***********************/
3483 priv->hw_base = pci_iomap(pdev, 0, 0);
3484 if (!priv->hw_base) {
3485 err = -ENODEV;
3486 goto out_pci_release_regions;
3487 }
3488
Tomas Winklere1623442009-01-27 14:27:56 -08003489 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Assaf Krauss316c30d2008-03-14 10:38:46 -07003490 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08003491 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003492
Reinette Chatre731a29b2009-12-14 14:12:11 -08003493 /* these spin locks will be used in apm_ops.init and EEPROM access
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07003494 * we should init now
3495 */
3496 spin_lock_init(&priv->reg_lock);
Reinette Chatre731a29b2009-12-14 14:12:11 -08003497 spin_lock_init(&priv->lock);
Reinette Chatre4843b5a2010-02-03 09:38:59 -08003498
3499 /*
3500 * stop and reset the on-board processor just in case it is in a
3501 * strange state ... like being left stranded by a primary kernel
3502 * and this is now the kdump kernel trying to start up
3503 */
3504 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
3505
Johannes Berge98a1302011-04-05 09:42:08 -07003506 hw_rev = iwl_hw_detect(priv);
Shanyu Zhaoc11362c2010-03-05 17:05:20 -08003507 IWL_INFO(priv, "Detected %s, REV=0x%X\n",
Johannes Berge98a1302011-04-05 09:42:08 -07003508 priv->cfg->name, hw_rev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003509
Tomas Winklere7b63582008-09-03 11:26:49 +08003510 /* We disable the RETRY_TIMEOUT register (0x41) to keep
3511 * PCI Tx retries from interfering with C3 CPU state */
3512 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
3513
Johannes Berg4cd2bf72011-04-13 03:14:52 -07003514 if (iwl_prepare_card_hw(priv)) {
Mohamed Abbas086ed112009-05-22 11:01:54 -07003515 IWL_WARN(priv, "Failed, HW not ready\n");
3516 goto out_iounmap;
3517 }
3518
Assaf Krauss316c30d2008-03-14 10:38:46 -07003519 /*****************
3520 * 4. Read EEPROM
3521 *****************/
Assaf Krauss316c30d2008-03-14 10:38:46 -07003522 /* Read the EEPROM */
Johannes Berge98a1302011-04-05 09:42:08 -07003523 err = iwl_eeprom_init(priv, hw_rev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003524 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003525 IWL_ERR(priv, "Unable to init EEPROM\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07003526 goto out_iounmap;
3527 }
Tomas Winkler8614f362008-04-23 17:14:55 -07003528 err = iwl_eeprom_check_version(priv);
3529 if (err)
Reinette Chatrec8f16132009-02-27 16:21:22 -08003530 goto out_free_eeprom;
Tomas Winkler8614f362008-04-23 17:14:55 -07003531
Wey-Yi Guy21a5b3c2010-11-10 13:32:59 -08003532 err = iwl_eeprom_check_sku(priv);
3533 if (err)
3534 goto out_free_eeprom;
3535
Ron Rindjunsky02883012008-05-15 13:53:53 +08003536 /* extract MAC Address */
Wey-Yi Guyc6fa17e2010-07-15 05:58:30 -07003537 iwl_eeprom_get_mac(priv, priv->addresses[0].addr);
3538 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
3539 priv->hw->wiphy->addresses = priv->addresses;
3540 priv->hw->wiphy->n_addresses = 1;
3541 num_mac = iwl_eeprom_query16(priv, EEPROM_NUM_MAC_ADDRESS);
3542 if (num_mac > 1) {
3543 memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
3544 ETH_ALEN);
3545 priv->addresses[1].addr[5]++;
3546 priv->hw->wiphy->n_addresses++;
3547 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07003548
3549 /************************
3550 * 5. Setup HW constants
3551 ************************/
Ron Rindjunskyda154e302008-06-30 17:23:20 +08003552 if (iwl_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003553 IWL_ERR(priv, "failed to set hw parameters\n");
Tomas Winkler073d3f52008-04-21 15:41:52 -07003554 goto out_free_eeprom;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003555 }
3556
3557 /*******************
Tomas Winkler6ba87952008-05-15 13:54:17 +08003558 * 6. Setup priv
Assaf Krauss316c30d2008-03-14 10:38:46 -07003559 *******************/
Zhu Yib481de92007-09-25 17:54:57 -07003560
Tomas Winkler6ba87952008-05-15 13:54:17 +08003561 err = iwl_init_drv(priv);
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003562 if (err)
Ron Rindjunsky399f4902008-04-23 17:14:56 -07003563 goto out_free_eeprom;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003564 /* At this point both hw and priv are initialized. */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003565
Assaf Krauss316c30d2008-03-14 10:38:46 -07003566 /********************
Abhijeet Kolekar09f9bf72009-04-20 14:37:03 -07003567 * 7. Setup services
Assaf Krauss316c30d2008-03-14 10:38:46 -07003568 ********************/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003569 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003570 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003571 spin_unlock_irqrestore(&priv->lock, flags);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003572
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003573 pci_enable_msi(priv->pci_dev);
3574
Johannes Berg519d8ab2011-04-05 09:42:11 -07003575 iwl_alloc_isr_ict(priv);
Wey-Yi Guye39fdee2010-11-10 09:56:40 -08003576
Johannes Berg519d8ab2011-04-05 09:42:11 -07003577 err = request_irq(priv->pci_dev->irq, iwl_isr_ict,
Mohamed Abbasef850d72009-05-22 11:01:50 -07003578 IRQF_SHARED, DRV_NAME, priv);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003579 if (err) {
3580 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
3581 goto out_disable_msi;
3582 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07003583
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003584 iwl_setup_deferred_work(priv);
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08003585 iwl_setup_rx_handlers(priv);
Cindy H. Kao4613e722011-05-06 10:40:15 -07003586 iwl_testmode_init(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003587
Johannes Berg158bea02010-01-22 14:22:53 -08003588 /*********************************************
3589 * 8. Enable interrupts and read RFKILL state
3590 *********************************************/
Tomas Winkler6ba87952008-05-15 13:54:17 +08003591
Stanislaw Gruszka554d1d02010-12-23 12:38:21 +01003592 /* enable rfkill interrupt: hw bug w/a */
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003593 pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd);
3594 if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
3595 pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
3596 pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
3597 }
3598
Stanislaw Gruszka554d1d02010-12-23 12:38:21 +01003599 iwl_enable_rfkill_int(priv);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003600
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003601 /* If platform's RF_KILL switch is NOT set to KILL */
3602 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3603 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3604 else
3605 set_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winkler6ba87952008-05-15 13:54:17 +08003606
Johannes Berga60e77e2009-06-04 18:26:06 +02003607 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
3608 test_bit(STATUS_RF_KILL_HW, &priv->status));
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003609
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08003610 iwl_power_initialize(priv);
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -07003611 iwl_tt_initialize(priv);
Johannes Berg158bea02010-01-22 14:22:53 -08003612
Reinette Chatrea15707d2010-05-10 15:08:11 -07003613 init_completion(&priv->_agn.firmware_loading_complete);
Johannes Berg562db532010-04-29 07:41:53 -07003614
Johannes Bergb08dfd02010-01-29 11:54:56 -08003615 err = iwl_request_firmware(priv, true);
Johannes Berg158bea02010-01-22 14:22:53 -08003616 if (err)
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07003617 goto out_destroy_workqueue;
Johannes Berg158bea02010-01-22 14:22:53 -08003618
Zhu Yib481de92007-09-25 17:54:57 -07003619 return 0;
3620
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07003621 out_destroy_workqueue:
Reinette Chatrec8f16132009-02-27 16:21:22 -08003622 destroy_workqueue(priv->workqueue);
3623 priv->workqueue = NULL;
Helmut Schaa795cc0a2009-02-12 18:51:03 +01003624 free_irq(priv->pci_dev->irq, priv);
Johannes Berg519d8ab2011-04-05 09:42:11 -07003625 iwl_free_isr_ict(priv);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003626 out_disable_msi:
3627 pci_disable_msi(priv->pci_dev);
Tomas Winkler6ba87952008-05-15 13:54:17 +08003628 iwl_uninit_drv(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07003629 out_free_eeprom:
3630 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003631 out_iounmap:
3632 pci_iounmap(pdev, priv->hw_base);
3633 out_pci_release_regions:
Assaf Krauss316c30d2008-03-14 10:38:46 -07003634 pci_set_drvdata(pdev, NULL);
Reinette Chatre623d5632009-03-03 11:37:04 -08003635 pci_release_regions(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07003636 out_pci_disable_device:
3637 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07003638 out_ieee80211_free_hw:
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003639 iwl_free_traffic_mem(priv);
Wey-Yi Guyd7c76f42009-10-09 13:20:17 -07003640 ieee80211_free_hw(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07003641 out:
3642 return err;
3643}
3644
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003645static void __devexit iwl_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07003646{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003647 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003648 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07003649
3650 if (!priv)
3651 return;
3652
Reinette Chatrea15707d2010-05-10 15:08:11 -07003653 wait_for_completion(&priv->_agn.firmware_loading_complete);
Johannes Berg562db532010-04-29 07:41:53 -07003654
Tomas Winklere1623442009-01-27 14:27:56 -08003655 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07003656
Emmanuel Grumbach67249622008-05-29 16:35:26 +08003657 iwl_dbgfs_unregister(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003658 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
Emmanuel Grumbach67249622008-05-29 16:35:26 +08003659
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003660 /* ieee80211_unregister_hw call wil cause iwl_mac_stop to
3661 * to be called and iwl_down since we are removing the device
Gregory Greenman0b124c32008-09-03 11:18:50 +08003662 * we need to set STATUS_EXIT_PENDING bit.
3663 */
3664 set_bit(STATUS_EXIT_PENDING, &priv->status);
Wey-Yi Guy5ed540a2011-01-21 15:26:39 -08003665
3666 iwl_leds_exit(priv);
3667
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07003668 if (priv->mac80211_registered) {
3669 ieee80211_unregister_hw(priv->hw);
3670 priv->mac80211_registered = 0;
3671 }
3672
Johannes Berg1a10f432011-04-13 03:14:44 -07003673 /* Reset to low power before unloading driver. */
Johannes Berg14e8e4a2010-09-22 18:02:10 +02003674 iwl_apm_stop(priv);
Ben Cahillc166b252009-10-23 13:42:35 -07003675
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -07003676 iwl_tt_exit(priv);
3677
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003678 /* make sure we flush any pending irq or
3679 * tasklet for the driver
3680 */
3681 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003682 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003683 spin_unlock_irqrestore(&priv->lock, flags);
3684
3685 iwl_synchronize_irq(priv);
3686
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003687 iwl_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003688
3689 if (priv->rxq.bd)
Wey-Yi Guy54b81552010-03-17 13:34:35 -07003690 iwlagn_rx_queue_free(priv, &priv->rxq);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -07003691 iwlagn_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003692
Tomas Winkler073d3f52008-04-21 15:41:52 -07003693 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003694
Zhu Yib481de92007-09-25 17:54:57 -07003695
Mohamed Abbas948c1712007-10-25 17:15:45 +08003696 /*netif_stop_queue(dev); */
3697 flush_workqueue(priv->workqueue);
3698
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003699 /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07003700 * priv->workqueue... so we can't take down the workqueue
3701 * until now... */
3702 destroy_workqueue(priv->workqueue);
3703 priv->workqueue = NULL;
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003704 iwl_free_traffic_mem(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003705
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003706 free_irq(priv->pci_dev->irq, priv);
3707 pci_disable_msi(priv->pci_dev);
Zhu Yib481de92007-09-25 17:54:57 -07003708 pci_iounmap(pdev, priv->hw_base);
3709 pci_release_regions(pdev);
3710 pci_disable_device(pdev);
3711 pci_set_drvdata(pdev, NULL);
3712
Tomas Winkler6ba87952008-05-15 13:54:17 +08003713 iwl_uninit_drv(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003714
Johannes Berg519d8ab2011-04-05 09:42:11 -07003715 iwl_free_isr_ict(priv);
Mohamed Abbasef850d72009-05-22 11:01:50 -07003716
Johannes Berg77834542010-10-04 05:50:36 -07003717 dev_kfree_skb(priv->beacon_skb);
Zhu Yib481de92007-09-25 17:54:57 -07003718
3719 ieee80211_free_hw(priv->hw);
3720}
3721
Zhu Yib481de92007-09-25 17:54:57 -07003722
3723/*****************************************************************************
3724 *
3725 * driver and module entry point
3726 *
3727 *****************************************************************************/
3728
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003729/* Hardware specific file defines the PCI IDs table for that hardware module */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00003730static DEFINE_PCI_DEVICE_TABLE(iwl_hw_card_ids) = {
Wey-Yi Guyac592572009-11-20 12:05:03 -08003731 {IWL_PCI_DEVICE(0x4232, 0x1201, iwl5100_agn_cfg)}, /* Mini Card */
3732 {IWL_PCI_DEVICE(0x4232, 0x1301, iwl5100_agn_cfg)}, /* Half Mini Card */
3733 {IWL_PCI_DEVICE(0x4232, 0x1204, iwl5100_agn_cfg)}, /* Mini Card */
3734 {IWL_PCI_DEVICE(0x4232, 0x1304, iwl5100_agn_cfg)}, /* Half Mini Card */
3735 {IWL_PCI_DEVICE(0x4232, 0x1205, iwl5100_bgn_cfg)}, /* Mini Card */
3736 {IWL_PCI_DEVICE(0x4232, 0x1305, iwl5100_bgn_cfg)}, /* Half Mini Card */
3737 {IWL_PCI_DEVICE(0x4232, 0x1206, iwl5100_abg_cfg)}, /* Mini Card */
3738 {IWL_PCI_DEVICE(0x4232, 0x1306, iwl5100_abg_cfg)}, /* Half Mini Card */
3739 {IWL_PCI_DEVICE(0x4232, 0x1221, iwl5100_agn_cfg)}, /* Mini Card */
3740 {IWL_PCI_DEVICE(0x4232, 0x1321, iwl5100_agn_cfg)}, /* Half Mini Card */
3741 {IWL_PCI_DEVICE(0x4232, 0x1224, iwl5100_agn_cfg)}, /* Mini Card */
3742 {IWL_PCI_DEVICE(0x4232, 0x1324, iwl5100_agn_cfg)}, /* Half Mini Card */
3743 {IWL_PCI_DEVICE(0x4232, 0x1225, iwl5100_bgn_cfg)}, /* Mini Card */
3744 {IWL_PCI_DEVICE(0x4232, 0x1325, iwl5100_bgn_cfg)}, /* Half Mini Card */
3745 {IWL_PCI_DEVICE(0x4232, 0x1226, iwl5100_abg_cfg)}, /* Mini Card */
3746 {IWL_PCI_DEVICE(0x4232, 0x1326, iwl5100_abg_cfg)}, /* Half Mini Card */
3747 {IWL_PCI_DEVICE(0x4237, 0x1211, iwl5100_agn_cfg)}, /* Mini Card */
3748 {IWL_PCI_DEVICE(0x4237, 0x1311, iwl5100_agn_cfg)}, /* Half Mini Card */
3749 {IWL_PCI_DEVICE(0x4237, 0x1214, iwl5100_agn_cfg)}, /* Mini Card */
3750 {IWL_PCI_DEVICE(0x4237, 0x1314, iwl5100_agn_cfg)}, /* Half Mini Card */
3751 {IWL_PCI_DEVICE(0x4237, 0x1215, iwl5100_bgn_cfg)}, /* Mini Card */
3752 {IWL_PCI_DEVICE(0x4237, 0x1315, iwl5100_bgn_cfg)}, /* Half Mini Card */
3753 {IWL_PCI_DEVICE(0x4237, 0x1216, iwl5100_abg_cfg)}, /* Mini Card */
3754 {IWL_PCI_DEVICE(0x4237, 0x1316, iwl5100_abg_cfg)}, /* Half Mini Card */
3755
3756/* 5300 Series WiFi */
3757 {IWL_PCI_DEVICE(0x4235, 0x1021, iwl5300_agn_cfg)}, /* Mini Card */
3758 {IWL_PCI_DEVICE(0x4235, 0x1121, iwl5300_agn_cfg)}, /* Half Mini Card */
3759 {IWL_PCI_DEVICE(0x4235, 0x1024, iwl5300_agn_cfg)}, /* Mini Card */
3760 {IWL_PCI_DEVICE(0x4235, 0x1124, iwl5300_agn_cfg)}, /* Half Mini Card */
3761 {IWL_PCI_DEVICE(0x4235, 0x1001, iwl5300_agn_cfg)}, /* Mini Card */
3762 {IWL_PCI_DEVICE(0x4235, 0x1101, iwl5300_agn_cfg)}, /* Half Mini Card */
3763 {IWL_PCI_DEVICE(0x4235, 0x1004, iwl5300_agn_cfg)}, /* Mini Card */
3764 {IWL_PCI_DEVICE(0x4235, 0x1104, iwl5300_agn_cfg)}, /* Half Mini Card */
3765 {IWL_PCI_DEVICE(0x4236, 0x1011, iwl5300_agn_cfg)}, /* Mini Card */
3766 {IWL_PCI_DEVICE(0x4236, 0x1111, iwl5300_agn_cfg)}, /* Half Mini Card */
3767 {IWL_PCI_DEVICE(0x4236, 0x1014, iwl5300_agn_cfg)}, /* Mini Card */
3768 {IWL_PCI_DEVICE(0x4236, 0x1114, iwl5300_agn_cfg)}, /* Half Mini Card */
3769
3770/* 5350 Series WiFi/WiMax */
3771 {IWL_PCI_DEVICE(0x423A, 0x1001, iwl5350_agn_cfg)}, /* Mini Card */
3772 {IWL_PCI_DEVICE(0x423A, 0x1021, iwl5350_agn_cfg)}, /* Mini Card */
3773 {IWL_PCI_DEVICE(0x423B, 0x1011, iwl5350_agn_cfg)}, /* Mini Card */
3774
3775/* 5150 Series Wifi/WiMax */
3776 {IWL_PCI_DEVICE(0x423C, 0x1201, iwl5150_agn_cfg)}, /* Mini Card */
3777 {IWL_PCI_DEVICE(0x423C, 0x1301, iwl5150_agn_cfg)}, /* Half Mini Card */
3778 {IWL_PCI_DEVICE(0x423C, 0x1206, iwl5150_abg_cfg)}, /* Mini Card */
3779 {IWL_PCI_DEVICE(0x423C, 0x1306, iwl5150_abg_cfg)}, /* Half Mini Card */
3780 {IWL_PCI_DEVICE(0x423C, 0x1221, iwl5150_agn_cfg)}, /* Mini Card */
3781 {IWL_PCI_DEVICE(0x423C, 0x1321, iwl5150_agn_cfg)}, /* Half Mini Card */
3782
3783 {IWL_PCI_DEVICE(0x423D, 0x1211, iwl5150_agn_cfg)}, /* Mini Card */
3784 {IWL_PCI_DEVICE(0x423D, 0x1311, iwl5150_agn_cfg)}, /* Half Mini Card */
3785 {IWL_PCI_DEVICE(0x423D, 0x1216, iwl5150_abg_cfg)}, /* Mini Card */
3786 {IWL_PCI_DEVICE(0x423D, 0x1316, iwl5150_abg_cfg)}, /* Half Mini Card */
Wey-Yi Guy5953a622009-09-17 10:43:53 -07003787
3788/* 6x00 Series */
Wey-Yi Guy5953a622009-09-17 10:43:53 -07003789 {IWL_PCI_DEVICE(0x422B, 0x1101, iwl6000_3agn_cfg)},
3790 {IWL_PCI_DEVICE(0x422B, 0x1121, iwl6000_3agn_cfg)},
3791 {IWL_PCI_DEVICE(0x422C, 0x1301, iwl6000i_2agn_cfg)},
3792 {IWL_PCI_DEVICE(0x422C, 0x1306, iwl6000i_2abg_cfg)},
3793 {IWL_PCI_DEVICE(0x422C, 0x1307, iwl6000i_2bg_cfg)},
3794 {IWL_PCI_DEVICE(0x422C, 0x1321, iwl6000i_2agn_cfg)},
3795 {IWL_PCI_DEVICE(0x422C, 0x1326, iwl6000i_2abg_cfg)},
3796 {IWL_PCI_DEVICE(0x4238, 0x1111, iwl6000_3agn_cfg)},
3797 {IWL_PCI_DEVICE(0x4239, 0x1311, iwl6000i_2agn_cfg)},
3798 {IWL_PCI_DEVICE(0x4239, 0x1316, iwl6000i_2abg_cfg)},
Shanyu Zhao4b3e8062010-04-07 18:06:36 -07003799
Wey-Yi Guy003ea982010-12-15 08:06:23 -08003800/* 6x05 Series */
Wey-Yi Guy8b3ee292010-11-18 11:41:48 -08003801 {IWL_PCI_DEVICE(0x0082, 0x1301, iwl6005_2agn_cfg)},
3802 {IWL_PCI_DEVICE(0x0082, 0x1306, iwl6005_2abg_cfg)},
3803 {IWL_PCI_DEVICE(0x0082, 0x1307, iwl6005_2bg_cfg)},
3804 {IWL_PCI_DEVICE(0x0082, 0x1321, iwl6005_2agn_cfg)},
3805 {IWL_PCI_DEVICE(0x0082, 0x1326, iwl6005_2abg_cfg)},
3806 {IWL_PCI_DEVICE(0x0085, 0x1311, iwl6005_2agn_cfg)},
3807 {IWL_PCI_DEVICE(0x0085, 0x1316, iwl6005_2abg_cfg)},
Shanyu Zhao18089722010-05-06 10:15:21 -07003808
Wey-Yi Guy003ea982010-12-15 08:06:23 -08003809/* 6x30 Series */
Wey-Yi Guy8b3ee292010-11-18 11:41:48 -08003810 {IWL_PCI_DEVICE(0x008A, 0x5305, iwl1030_bgn_cfg)},
3811 {IWL_PCI_DEVICE(0x008A, 0x5307, iwl1030_bg_cfg)},
3812 {IWL_PCI_DEVICE(0x008A, 0x5325, iwl1030_bgn_cfg)},
3813 {IWL_PCI_DEVICE(0x008A, 0x5327, iwl1030_bg_cfg)},
3814 {IWL_PCI_DEVICE(0x008B, 0x5315, iwl1030_bgn_cfg)},
3815 {IWL_PCI_DEVICE(0x008B, 0x5317, iwl1030_bg_cfg)},
3816 {IWL_PCI_DEVICE(0x0090, 0x5211, iwl6030_2agn_cfg)},
3817 {IWL_PCI_DEVICE(0x0090, 0x5215, iwl6030_2bgn_cfg)},
3818 {IWL_PCI_DEVICE(0x0090, 0x5216, iwl6030_2abg_cfg)},
3819 {IWL_PCI_DEVICE(0x0091, 0x5201, iwl6030_2agn_cfg)},
3820 {IWL_PCI_DEVICE(0x0091, 0x5205, iwl6030_2bgn_cfg)},
3821 {IWL_PCI_DEVICE(0x0091, 0x5206, iwl6030_2abg_cfg)},
3822 {IWL_PCI_DEVICE(0x0091, 0x5207, iwl6030_2bg_cfg)},
3823 {IWL_PCI_DEVICE(0x0091, 0x5221, iwl6030_2agn_cfg)},
3824 {IWL_PCI_DEVICE(0x0091, 0x5225, iwl6030_2bgn_cfg)},
3825 {IWL_PCI_DEVICE(0x0091, 0x5226, iwl6030_2abg_cfg)},
Wey-Yi Guy5953a622009-09-17 10:43:53 -07003826
3827/* 6x50 WiFi/WiMax Series */
Wey-Yi Guy5953a622009-09-17 10:43:53 -07003828 {IWL_PCI_DEVICE(0x0087, 0x1301, iwl6050_2agn_cfg)},
3829 {IWL_PCI_DEVICE(0x0087, 0x1306, iwl6050_2abg_cfg)},
3830 {IWL_PCI_DEVICE(0x0087, 0x1321, iwl6050_2agn_cfg)},
3831 {IWL_PCI_DEVICE(0x0087, 0x1326, iwl6050_2abg_cfg)},
Wey-Yi Guy5953a622009-09-17 10:43:53 -07003832 {IWL_PCI_DEVICE(0x0089, 0x1311, iwl6050_2agn_cfg)},
3833 {IWL_PCI_DEVICE(0x0089, 0x1316, iwl6050_2abg_cfg)},
3834
Wey-Yi Guy003ea982010-12-15 08:06:23 -08003835/* 6150 WiFi/WiMax Series */
Wey-Yi Guy8b3ee292010-11-18 11:41:48 -08003836 {IWL_PCI_DEVICE(0x0885, 0x1305, iwl6150_bgn_cfg)},
3837 {IWL_PCI_DEVICE(0x0885, 0x1306, iwl6150_bgn_cfg)},
3838 {IWL_PCI_DEVICE(0x0885, 0x1325, iwl6150_bgn_cfg)},
3839 {IWL_PCI_DEVICE(0x0885, 0x1326, iwl6150_bgn_cfg)},
3840 {IWL_PCI_DEVICE(0x0886, 0x1315, iwl6150_bgn_cfg)},
3841 {IWL_PCI_DEVICE(0x0886, 0x1316, iwl6150_bgn_cfg)},
Shanyu Zhao03264332010-06-29 17:27:27 -07003842
Jay Sternberg77dcb6a2009-03-06 13:52:55 -08003843/* 1000 Series WiFi */
Wey-Yi Guy4bd0914f2009-09-17 10:43:52 -07003844 {IWL_PCI_DEVICE(0x0083, 0x1205, iwl1000_bgn_cfg)},
3845 {IWL_PCI_DEVICE(0x0083, 0x1305, iwl1000_bgn_cfg)},
3846 {IWL_PCI_DEVICE(0x0083, 0x1225, iwl1000_bgn_cfg)},
3847 {IWL_PCI_DEVICE(0x0083, 0x1325, iwl1000_bgn_cfg)},
3848 {IWL_PCI_DEVICE(0x0084, 0x1215, iwl1000_bgn_cfg)},
3849 {IWL_PCI_DEVICE(0x0084, 0x1315, iwl1000_bgn_cfg)},
3850 {IWL_PCI_DEVICE(0x0083, 0x1206, iwl1000_bg_cfg)},
3851 {IWL_PCI_DEVICE(0x0083, 0x1306, iwl1000_bg_cfg)},
3852 {IWL_PCI_DEVICE(0x0083, 0x1226, iwl1000_bg_cfg)},
3853 {IWL_PCI_DEVICE(0x0083, 0x1326, iwl1000_bg_cfg)},
3854 {IWL_PCI_DEVICE(0x0084, 0x1216, iwl1000_bg_cfg)},
3855 {IWL_PCI_DEVICE(0x0084, 0x1316, iwl1000_bg_cfg)},
Jay Sternberg1de19ec2010-09-14 15:21:20 -07003856
Wey-Yi Guy58a39092010-10-06 08:14:21 -07003857/* 100 Series WiFi */
Jay Sternberg1de19ec2010-09-14 15:21:20 -07003858 {IWL_PCI_DEVICE(0x08AE, 0x1005, iwl100_bgn_cfg)},
Jay Sternberg1de19ec2010-09-14 15:21:20 -07003859 {IWL_PCI_DEVICE(0x08AE, 0x1007, iwl100_bg_cfg)},
Wey-Yi Guy2a21ff42010-11-10 09:56:37 -08003860 {IWL_PCI_DEVICE(0x08AF, 0x1015, iwl100_bgn_cfg)},
3861 {IWL_PCI_DEVICE(0x08AF, 0x1017, iwl100_bg_cfg)},
3862 {IWL_PCI_DEVICE(0x08AE, 0x1025, iwl100_bgn_cfg)},
3863 {IWL_PCI_DEVICE(0x08AE, 0x1027, iwl100_bg_cfg)},
Wey-Yi Guy58a39092010-10-06 08:14:21 -07003864
3865/* 130 Series WiFi */
3866 {IWL_PCI_DEVICE(0x0896, 0x5005, iwl130_bgn_cfg)},
3867 {IWL_PCI_DEVICE(0x0896, 0x5007, iwl130_bg_cfg)},
3868 {IWL_PCI_DEVICE(0x0897, 0x5015, iwl130_bgn_cfg)},
3869 {IWL_PCI_DEVICE(0x0897, 0x5017, iwl130_bg_cfg)},
3870 {IWL_PCI_DEVICE(0x0896, 0x5025, iwl130_bgn_cfg)},
3871 {IWL_PCI_DEVICE(0x0896, 0x5027, iwl130_bg_cfg)},
3872
Wey-Yi Guy04b8e752011-01-08 11:47:56 -08003873/* 2x00 Series */
3874 {IWL_PCI_DEVICE(0x0890, 0x4022, iwl2000_2bgn_cfg)},
3875 {IWL_PCI_DEVICE(0x0891, 0x4222, iwl2000_2bgn_cfg)},
3876 {IWL_PCI_DEVICE(0x0890, 0x4422, iwl2000_2bgn_cfg)},
3877 {IWL_PCI_DEVICE(0x0890, 0x4026, iwl2000_2bg_cfg)},
3878 {IWL_PCI_DEVICE(0x0891, 0x4226, iwl2000_2bg_cfg)},
3879 {IWL_PCI_DEVICE(0x0890, 0x4426, iwl2000_2bg_cfg)},
3880
3881/* 2x30 Series */
3882 {IWL_PCI_DEVICE(0x0887, 0x4062, iwl2030_2bgn_cfg)},
3883 {IWL_PCI_DEVICE(0x0888, 0x4262, iwl2030_2bgn_cfg)},
3884 {IWL_PCI_DEVICE(0x0887, 0x4462, iwl2030_2bgn_cfg)},
3885 {IWL_PCI_DEVICE(0x0887, 0x4066, iwl2030_2bg_cfg)},
3886 {IWL_PCI_DEVICE(0x0888, 0x4266, iwl2030_2bg_cfg)},
3887 {IWL_PCI_DEVICE(0x0887, 0x4466, iwl2030_2bg_cfg)},
3888
3889/* 6x35 Series */
3890 {IWL_PCI_DEVICE(0x088E, 0x4060, iwl6035_2agn_cfg)},
3891 {IWL_PCI_DEVICE(0x088F, 0x4260, iwl6035_2agn_cfg)},
3892 {IWL_PCI_DEVICE(0x088E, 0x4460, iwl6035_2agn_cfg)},
3893 {IWL_PCI_DEVICE(0x088E, 0x4064, iwl6035_2abg_cfg)},
3894 {IWL_PCI_DEVICE(0x088F, 0x4264, iwl6035_2abg_cfg)},
3895 {IWL_PCI_DEVICE(0x088E, 0x4464, iwl6035_2abg_cfg)},
3896 {IWL_PCI_DEVICE(0x088E, 0x4066, iwl6035_2bg_cfg)},
3897 {IWL_PCI_DEVICE(0x088F, 0x4266, iwl6035_2bg_cfg)},
3898 {IWL_PCI_DEVICE(0x088E, 0x4466, iwl6035_2bg_cfg)},
3899
Wey-Yi Guyb4ed2212011-04-30 08:55:16 -07003900/* 105 Series */
3901 {IWL_PCI_DEVICE(0x0894, 0x0022, iwl105_bgn_cfg)},
3902 {IWL_PCI_DEVICE(0x0895, 0x0222, iwl105_bgn_cfg)},
3903 {IWL_PCI_DEVICE(0x0894, 0x0422, iwl105_bgn_cfg)},
3904 {IWL_PCI_DEVICE(0x0894, 0x0026, iwl105_bg_cfg)},
3905 {IWL_PCI_DEVICE(0x0895, 0x0226, iwl105_bg_cfg)},
3906 {IWL_PCI_DEVICE(0x0894, 0x0426, iwl105_bg_cfg)},
Wey-Yi Guy04b8e752011-01-08 11:47:56 -08003907
Wey-Yi Guyb4ed2212011-04-30 08:55:16 -07003908/* 135 Series */
3909 {IWL_PCI_DEVICE(0x0892, 0x0062, iwl135_bgn_cfg)},
3910 {IWL_PCI_DEVICE(0x0893, 0x0262, iwl135_bgn_cfg)},
3911 {IWL_PCI_DEVICE(0x0892, 0x0462, iwl135_bgn_cfg)},
3912 {IWL_PCI_DEVICE(0x0892, 0x0066, iwl135_bg_cfg)},
3913 {IWL_PCI_DEVICE(0x0893, 0x0266, iwl135_bg_cfg)},
3914 {IWL_PCI_DEVICE(0x0892, 0x0466, iwl135_bg_cfg)},
Wey-Yi Guy04b8e752011-01-08 11:47:56 -08003915
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003916 {0}
3917};
3918MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
3919
3920static struct pci_driver iwl_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07003921 .name = DRV_NAME,
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003922 .id_table = iwl_hw_card_ids,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003923 .probe = iwl_pci_probe,
3924 .remove = __devexit_p(iwl_pci_remove),
John W. Linvillef60dc012010-10-25 16:12:37 -04003925 .driver.pm = IWL_PM_OPS,
Zhu Yib481de92007-09-25 17:54:57 -07003926};
3927
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003928static int __init iwl_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07003929{
3930
3931 int ret;
Joe Perchesc96c31e2010-07-26 14:39:58 -07003932 pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
3933 pr_info(DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003934
Tomas Winklere227cea2008-07-18 13:53:05 +08003935 ret = iwlagn_rate_control_register();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003936 if (ret) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07003937 pr_err("Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003938 return ret;
3939 }
3940
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003941 ret = pci_register_driver(&iwl_driver);
Zhu Yib481de92007-09-25 17:54:57 -07003942 if (ret) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07003943 pr_err("Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003944 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07003945 }
Zhu Yib481de92007-09-25 17:54:57 -07003946
3947 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003948
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003949error_register:
Tomas Winklere227cea2008-07-18 13:53:05 +08003950 iwlagn_rate_control_unregister();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003951 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003952}
3953
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003954static void __exit iwl_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07003955{
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003956 pci_unregister_driver(&iwl_driver);
Tomas Winklere227cea2008-07-18 13:53:05 +08003957 iwlagn_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07003958}
3959
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003960module_exit(iwl_exit);
3961module_init(iwl_init);
Reinette Chatrea562a9d2009-07-17 09:30:24 -07003962
3963#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07003964module_param_named(debug, iwl_debug_level, uint, S_IRUGO | S_IWUSR);
Reinette Chatrea562a9d2009-07-17 09:30:24 -07003965MODULE_PARM_DESC(debug, "debug output mask");
3966#endif
3967
Wey-Yi Guy2b0686182010-03-22 09:17:39 -07003968module_param_named(swcrypto, iwlagn_mod_params.sw_crypto, int, S_IRUGO);
3969MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
Wey-Yi Guy2b0686182010-03-22 09:17:39 -07003970module_param_named(queues_num, iwlagn_mod_params.num_of_queues, int, S_IRUGO);
3971MODULE_PARM_DESC(queues_num, "number of hw queues.");
Wey-Yi Guy2b0686182010-03-22 09:17:39 -07003972module_param_named(11n_disable, iwlagn_mod_params.disable_11n, int, S_IRUGO);
3973MODULE_PARM_DESC(11n_disable, "disable 11n functionality");
Wey-Yi Guy2b0686182010-03-22 09:17:39 -07003974module_param_named(amsdu_size_8K, iwlagn_mod_params.amsdu_size_8K,
3975 int, S_IRUGO);
3976MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
Wey-Yi Guy2b0686182010-03-22 09:17:39 -07003977module_param_named(fw_restart, iwlagn_mod_params.restart_fw, int, S_IRUGO);
3978MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");
Johannes Bergdd7a2502010-04-28 23:33:10 -07003979
3980module_param_named(ucode_alternative, iwlagn_wanted_ucode_alternative, int,
3981 S_IRUGO);
3982MODULE_PARM_DESC(ucode_alternative,
3983 "specify ucode alternative to use from ucode file");
Wey-Yi Guybee008b2010-08-23 07:57:04 -07003984
3985module_param_named(antenna_coupling, iwlagn_ant_coupling, int, S_IRUGO);
3986MODULE_PARM_DESC(antenna_coupling,
3987 "specify antenna coupling in dB (defualt: 0 dB)");
Wey-Yi Guyf37837c2010-08-23 07:57:12 -07003988
Wey-Yi Guy9f28ebc2010-11-26 13:24:19 -08003989module_param_named(bt_ch_inhibition, iwlagn_bt_ch_announce, bool, S_IRUGO);
3990MODULE_PARM_DESC(bt_ch_inhibition,
3991 "Disable BT channel inhibition (default: enable)");
Stanislaw Gruszkab7977ff2011-02-28 14:33:15 +01003992
3993module_param_named(plcp_check, iwlagn_mod_params.plcp_check, bool, S_IRUGO);
3994MODULE_PARM_DESC(plcp_check, "Check plcp health (default: 1 [enabled])");
3995
3996module_param_named(ack_check, iwlagn_mod_params.ack_check, bool, S_IRUGO);
3997MODULE_PARM_DESC(ack_check, "Check ack health (default: 0 [disabled])");