blob: 44400f9aa7b9930214788c5f69cad3765d75bbb5 [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 *****************************************************************************/
Zhu Yib481de92007-09-25 17:54:57 -070029#include <linux/kernel.h>
30#include <linux/module.h>
Zhu Yib481de92007-09-25 17:54:57 -070031#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
Zhu Yib481de92007-09-25 17:54:57 -070033#include <linux/dma-mapping.h>
34#include <linux/delay.h>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040035#include <linux/sched.h>
Zhu Yib481de92007-09-25 17:54:57 -070036#include <linux/skbuff.h>
37#include <linux/netdevice.h>
Zhu Yib481de92007-09-25 17:54:57 -070038#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070039#include <linux/etherdevice.h>
40#include <linux/if_arp.h>
41
Zhu Yib481de92007-09-25 17:54:57 -070042#include <net/mac80211.h>
43
44#include <asm/div64.h>
45
Assaf Krauss6bc913b2008-03-11 16:17:18 -070046#include "iwl-eeprom.h"
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070047#include "iwl-dev.h"
Tomas Winklerfee12472008-04-03 16:05:21 -070048#include "iwl-core.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070049#include "iwl-io.h"
Zhu Yib481de92007-09-25 17:54:57 -070050#include "iwl-helpers.h"
Emmanuel Grumbach6974e362008-04-14 21:16:06 -070051#include "iwl-sta.h"
Johannes Berg0de76732010-09-22 18:02:11 +020052#include "iwl-agn-calib.h"
Johannes Berga1175122010-01-21 06:21:10 -080053#include "iwl-agn.h"
Emmanuel Grumbachd5934112011-07-11 10:48:51 +030054#include "iwl-bus.h"
Emmanuel Grumbachc85eb612011-06-14 10:13:24 +030055#include "iwl-trans.h"
Christoph Hellwig416e1432007-10-25 17:15:49 +080056
Zhu Yib481de92007-09-25 17:54:57 -070057/******************************************************************************
58 *
59 * module boiler plate
60 *
61 ******************************************************************************/
62
Zhu Yib481de92007-09-25 17:54:57 -070063/*
64 * module name, copyright, version, etc.
Zhu Yib481de92007-09-25 17:54:57 -070065 */
Tomas Winklerd783b062008-07-18 13:53:02 +080066#define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
Zhu Yib481de92007-09-25 17:54:57 -070067
Tomas Winkler0a6857e2008-03-12 16:58:49 -070068#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070069#define VD "d"
70#else
71#define VD
72#endif
73
Reinette Chatre81963d62010-01-22 14:22:57 -080074#define DRV_VERSION IWLWIFI_VERSION VD
Zhu Yib481de92007-09-25 17:54:57 -070075
Zhu Yib481de92007-09-25 17:54:57 -070076
77MODULE_DESCRIPTION(DRV_DESCRIPTION);
78MODULE_VERSION(DRV_VERSION);
Tomas Winklera7b75202008-12-11 10:33:41 -080079MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
Zhu Yib481de92007-09-25 17:54:57 -070080MODULE_LICENSE("GPL");
81
Wey-Yi Guybee008b2010-08-23 07:57:04 -070082static int iwlagn_ant_coupling;
Wey-Yi Guyf37837c2010-08-23 07:57:12 -070083static bool iwlagn_bt_ch_announce = 1;
Wey-Yi Guybee008b2010-08-23 07:57:04 -070084
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -070085void iwl_update_chain_flags(struct iwl_priv *priv)
Mohamed Abbas5da4b552008-04-21 15:41:51 -070086{
Johannes Berg246ed352010-08-23 10:46:32 +020087 struct iwl_rxon_context *ctx;
Mohamed Abbas5da4b552008-04-21 15:41:51 -070088
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -070089 for_each_context(priv, ctx) {
90 iwlagn_set_rxon_chain(priv, ctx);
91 if (ctx->active.rx_chain != ctx->staging.rx_chain)
92 iwlagn_commit_rxon(priv, ctx);
Johannes Berg246ed352010-08-23 10:46:32 +020093 }
Mohamed Abbas5da4b552008-04-21 15:41:51 -070094}
95
Daniel C Halperin47ff65c2009-11-13 11:56:33 -080096/* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
97static void iwl_set_beacon_tim(struct iwl_priv *priv,
Johannes Berg77834542010-10-04 05:50:36 -070098 struct iwl_tx_beacon_cmd *tx_beacon_cmd,
99 u8 *beacon, u32 frame_size)
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800100{
101 u16 tim_idx;
102 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
103
104 /*
105 * The index is relative to frame start but we start looking at the
106 * variable-length part of the beacon.
107 */
108 tim_idx = mgmt->u.beacon.variable - beacon;
109
110 /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
111 while ((tim_idx < (frame_size - 2)) &&
112 (beacon[tim_idx] != WLAN_EID_TIM))
113 tim_idx += beacon[tim_idx+1] + 2;
114
115 /* If TIM field was found, set variables */
116 if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
117 tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
118 tx_beacon_cmd->tim_size = beacon[tim_idx+1];
119 } else
120 IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
121}
122
Johannes Berg8a98d492011-04-29 09:48:14 -0700123int iwlagn_send_beacon_cmd(struct iwl_priv *priv)
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800124{
125 struct iwl_tx_beacon_cmd *tx_beacon_cmd;
Johannes Berg8a98d492011-04-29 09:48:14 -0700126 struct iwl_host_cmd cmd = {
127 .id = REPLY_TX_BEACON,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700128 .flags = CMD_SYNC,
Johannes Berg8a98d492011-04-29 09:48:14 -0700129 };
Johannes Berg0b5b3ff2011-06-22 06:33:43 -0700130 struct ieee80211_tx_info *info;
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800131 u32 frame_size;
132 u32 rate_flags;
133 u32 rate;
Johannes Berg8a98d492011-04-29 09:48:14 -0700134
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800135 /*
136 * We have to set up the TX command, the TX Beacon command, and the
137 * beacon contents.
138 */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800139
Johannes Berg76d04812010-08-23 10:46:47 +0200140 lockdep_assert_held(&priv->mutex);
141
142 if (!priv->beacon_ctx) {
143 IWL_ERR(priv, "trying to build beacon w/o beacon context!\n");
Julia Lawall950094c2010-09-05 21:00:26 +0200144 return 0;
Johannes Berg76d04812010-08-23 10:46:47 +0200145 }
146
Johannes Berg8a98d492011-04-29 09:48:14 -0700147 if (WARN_ON(!priv->beacon_skb))
148 return -EINVAL;
149
Johannes Berg4ce7cc22011-05-13 11:57:40 -0700150 /* Allocate beacon command */
151 if (!priv->beacon_cmd)
152 priv->beacon_cmd = kzalloc(sizeof(*tx_beacon_cmd), GFP_KERNEL);
153 tx_beacon_cmd = priv->beacon_cmd;
Johannes Berg8a98d492011-04-29 09:48:14 -0700154 if (!tx_beacon_cmd)
155 return -ENOMEM;
156
157 frame_size = priv->beacon_skb->len;
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800158
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800159 /* Set up TX command fields */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800160 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
Johannes Berg76d04812010-08-23 10:46:47 +0200161 tx_beacon_cmd->tx.sta_id = priv->beacon_ctx->bcast_sta_id;
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800162 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800163 tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800164 TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
165
166 /* Set up TX beacon command fields */
Johannes Berg4ce7cc22011-05-13 11:57:40 -0700167 iwl_set_beacon_tim(priv, tx_beacon_cmd, priv->beacon_skb->data,
Johannes Berg77834542010-10-04 05:50:36 -0700168 frame_size);
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800169
170 /* Set up packet rate and flags */
Johannes Berg0b5b3ff2011-06-22 06:33:43 -0700171 info = IEEE80211_SKB_CB(priv->beacon_skb);
172
173 /*
174 * Let's set up the rate at least somewhat correctly;
175 * it will currently not actually be used by the uCode,
176 * it uses the broadcast station's rate instead.
177 */
178 if (info->control.rates[0].idx < 0 ||
179 info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
180 rate = 0;
181 else
182 rate = info->control.rates[0].idx;
183
Johannes Berg0e1654f2010-05-18 02:48:36 -0700184 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
185 priv->hw_params.valid_tx_ant);
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800186 rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
Johannes Berg0b5b3ff2011-06-22 06:33:43 -0700187
188 /* In mac80211, rates for 5 GHz start at 0 */
189 if (info->band == IEEE80211_BAND_5GHZ)
190 rate += IWL_FIRST_OFDM_RATE;
191 else if (rate >= IWL_FIRST_CCK_RATE && rate <= IWL_LAST_CCK_RATE)
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800192 rate_flags |= RATE_MCS_CCK_MSK;
Johannes Berg0b5b3ff2011-06-22 06:33:43 -0700193
194 tx_beacon_cmd->tx.rate_n_flags =
195 iwl_hw_set_rate_n_flags(rate, rate_flags);
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800196
Johannes Berg8a98d492011-04-29 09:48:14 -0700197 /* Submit command */
Johannes Berg4ce7cc22011-05-13 11:57:40 -0700198 cmd.len[0] = sizeof(*tx_beacon_cmd);
Johannes Berg3fa50732011-05-04 07:50:38 -0700199 cmd.data[0] = tx_beacon_cmd;
Johannes Berg4ce7cc22011-05-13 11:57:40 -0700200 cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
201 cmd.len[1] = frame_size;
202 cmd.data[1] = priv->beacon_skb->data;
203 cmd.dataflags[1] = IWL_HCMD_DFL_NOCOPY;
Johannes Berg2295c662010-10-23 09:15:41 -0700204
Emmanuel Grumbach41c50542011-07-11 08:51:04 +0300205 return trans_send_cmd(&priv->trans, &cmd);
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800206}
207
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700208static void iwl_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -0700209{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700210 struct iwl_priv *priv =
211 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -0700212 struct sk_buff *beacon;
213
Johannes Berg76d04812010-08-23 10:46:47 +0200214 mutex_lock(&priv->mutex);
215 if (!priv->beacon_ctx) {
216 IWL_ERR(priv, "updating beacon w/o beacon context!\n");
217 goto out;
Zhu Yib481de92007-09-25 17:54:57 -0700218 }
219
Johannes Berg60744f62010-08-23 10:46:50 +0200220 if (priv->beacon_ctx->vif->type != NL80211_IFTYPE_AP) {
221 /*
222 * The ucode will send beacon notifications even in
223 * IBSS mode, but we don't want to process them. But
224 * we need to defer the type check to here due to
225 * requiring locking around the beacon_ctx access.
226 */
227 goto out;
228 }
229
Johannes Berg76d04812010-08-23 10:46:47 +0200230 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
231 beacon = ieee80211_beacon_get(priv->hw, priv->beacon_ctx->vif);
232 if (!beacon) {
Johannes Berg77834542010-10-04 05:50:36 -0700233 IWL_ERR(priv, "update beacon failed -- keeping old\n");
Johannes Berg76d04812010-08-23 10:46:47 +0200234 goto out;
235 }
236
Zhu Yib481de92007-09-25 17:54:57 -0700237 /* new beacon skb is allocated every time; dispose previous.*/
Johannes Berg77834542010-10-04 05:50:36 -0700238 dev_kfree_skb(priv->beacon_skb);
Zhu Yib481de92007-09-25 17:54:57 -0700239
Johannes Berg12e934d2010-10-04 05:50:06 -0700240 priv->beacon_skb = beacon;
Zhu Yib481de92007-09-25 17:54:57 -0700241
Johannes Berg2295c662010-10-23 09:15:41 -0700242 iwlagn_send_beacon_cmd(priv);
Johannes Berg76d04812010-08-23 10:46:47 +0200243 out:
244 mutex_unlock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -0700245}
246
Wey-Yi Guyfbba9412010-08-23 07:57:10 -0700247static void iwl_bg_bt_runtime_config(struct work_struct *work)
248{
249 struct iwl_priv *priv =
250 container_of(work, struct iwl_priv, bt_runtime_config);
251
252 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
253 return;
254
255 /* dont send host command if rf-kill is on */
256 if (!iwl_is_ready_rf(priv))
257 return;
Wey-Yi Guye55b5172011-06-28 11:46:28 -0700258 iwlagn_send_advance_bt_config(priv);
Wey-Yi Guyfbba9412010-08-23 07:57:10 -0700259}
260
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700261static void iwl_bg_bt_full_concurrency(struct work_struct *work)
262{
263 struct iwl_priv *priv =
264 container_of(work, struct iwl_priv, bt_full_concurrency);
Johannes Berg246ed352010-08-23 10:46:32 +0200265 struct iwl_rxon_context *ctx;
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700266
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +0200267 mutex_lock(&priv->mutex);
268
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700269 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +0200270 goto out;
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700271
272 /* dont send host command if rf-kill is on */
273 if (!iwl_is_ready_rf(priv))
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +0200274 goto out;
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700275
276 IWL_DEBUG_INFO(priv, "BT coex in %s mode\n",
277 priv->bt_full_concurrent ?
278 "full concurrency" : "3-wire");
279
280 /*
281 * LQ & RXON updated cmds must be sent before BT Config cmd
282 * to avoid 3-wire collisions
283 */
Johannes Berg246ed352010-08-23 10:46:32 +0200284 for_each_context(priv, ctx) {
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -0700285 iwlagn_set_rxon_chain(priv, ctx);
Wey-Yi Guy805a3b82011-06-03 07:54:16 -0700286 iwlagn_commit_rxon(priv, ctx);
Johannes Berg246ed352010-08-23 10:46:32 +0200287 }
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700288
Wey-Yi Guye55b5172011-06-28 11:46:28 -0700289 iwlagn_send_advance_bt_config(priv);
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +0200290out:
291 mutex_unlock(&priv->mutex);
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700292}
293
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800294/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700295 * iwl_bg_statistics_periodic - Timer callback to queue statistics
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800296 *
297 * This callback is provided in order to send a statistics request.
298 *
299 * This timer function is continually reset to execute within
300 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
301 * was received. We need to ensure we receive the statistics in order
302 * to update the temperature used for calibrating the TXPOWER.
303 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700304static void iwl_bg_statistics_periodic(unsigned long data)
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800305{
306 struct iwl_priv *priv = (struct iwl_priv *)data;
307
308 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
309 return;
310
Mohamed Abbas61780ee2008-10-29 14:05:49 -0700311 /* dont send host command if rf-kill is on */
312 if (!iwl_is_ready_rf(priv))
313 return;
314
Wey-Yi Guyef8d5522009-11-13 11:56:28 -0800315 iwl_send_statistics_request(priv, CMD_ASYNC, false);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800316}
317
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800318
319static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base,
320 u32 start_idx, u32 num_events,
321 u32 mode)
322{
323 u32 i;
324 u32 ptr; /* SRAM byte address of log data */
325 u32 ev, time, data; /* event log data */
326 unsigned long reg_flags;
327
328 if (mode == 0)
329 ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32));
330 else
331 ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32));
332
333 /* Make sure device is powered up for SRAM reads */
334 spin_lock_irqsave(&priv->reg_lock, reg_flags);
335 if (iwl_grab_nic_access(priv)) {
336 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
337 return;
338 }
339
340 /* Set starting address; reads will auto-increment */
Johannes Berg02a7fa02011-04-05 09:42:12 -0700341 iwl_write32(priv, HBUS_TARG_MEM_RADDR, ptr);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800342 rmb();
343
344 /*
345 * "time" is actually "data" for mode 0 (no timestamp).
346 * place event id # at far right for easier visual parsing.
347 */
348 for (i = 0; i < num_events; i++) {
Johannes Berg02a7fa02011-04-05 09:42:12 -0700349 ev = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
350 time = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800351 if (mode == 0) {
352 trace_iwlwifi_dev_ucode_cont_event(priv,
353 0, time, ev);
354 } else {
Johannes Berg02a7fa02011-04-05 09:42:12 -0700355 data = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800356 trace_iwlwifi_dev_ucode_cont_event(priv,
357 time, data, ev);
358 }
359 }
360 /* Allow device to power down */
361 iwl_release_nic_access(priv);
362 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
363}
364
Johannes Berg875295f2010-01-22 14:22:55 -0800365static void iwl_continuous_event_trace(struct iwl_priv *priv)
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800366{
367 u32 capacity; /* event log capacity in # entries */
368 u32 base; /* SRAM byte address of event log header */
369 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
370 u32 num_wraps; /* # times uCode wrapped to top of log */
371 u32 next_entry; /* index of next entry to be written by uCode */
372
Johannes Bergd7d57832011-04-05 09:42:04 -0700373 base = priv->device_pointers.error_event_table;
Fry, Donald H4caab322011-07-07 15:24:07 -0700374 if (iwlagn_hw_valid_rtc_data_addr(base)) {
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800375 capacity = iwl_read_targ_mem(priv, base);
376 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
377 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
378 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
379 } else
380 return;
381
382 if (num_wraps == priv->event_log.num_wraps) {
383 iwl_print_cont_event_trace(priv,
384 base, priv->event_log.next_entry,
385 next_entry - priv->event_log.next_entry,
386 mode);
387 priv->event_log.non_wraps_count++;
388 } else {
389 if ((num_wraps - priv->event_log.num_wraps) > 1)
390 priv->event_log.wraps_more_count++;
391 else
392 priv->event_log.wraps_once_count++;
393 trace_iwlwifi_dev_ucode_wrap_event(priv,
394 num_wraps - priv->event_log.num_wraps,
395 next_entry, priv->event_log.next_entry);
396 if (next_entry < priv->event_log.next_entry) {
397 iwl_print_cont_event_trace(priv, base,
398 priv->event_log.next_entry,
399 capacity - priv->event_log.next_entry,
400 mode);
401
402 iwl_print_cont_event_trace(priv, base, 0,
403 next_entry, mode);
404 } else {
405 iwl_print_cont_event_trace(priv, base,
406 next_entry, capacity - next_entry,
407 mode);
408
409 iwl_print_cont_event_trace(priv, base, 0,
410 next_entry, mode);
411 }
412 }
413 priv->event_log.num_wraps = num_wraps;
414 priv->event_log.next_entry = next_entry;
415}
416
417/**
418 * iwl_bg_ucode_trace - Timer callback to log ucode event
419 *
420 * The timer is continually set to execute every
421 * UCODE_TRACE_PERIOD milliseconds after the last timer expired
422 * this function is to perform continuous uCode event logging operation
423 * if enabled
424 */
425static void iwl_bg_ucode_trace(unsigned long data)
426{
427 struct iwl_priv *priv = (struct iwl_priv *)data;
428
429 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
430 return;
431
432 if (priv->event_log.ucode_trace) {
433 iwl_continuous_event_trace(priv);
434 /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
435 mod_timer(&priv->ucode_trace,
436 jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
437 }
438}
439
Wey-Yi Guy65550632010-06-24 13:18:35 -0700440static void iwl_bg_tx_flush(struct work_struct *work)
441{
442 struct iwl_priv *priv =
443 container_of(work, struct iwl_priv, tx_flush);
444
445 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
446 return;
447
448 /* do nothing if rf-kill is on */
449 if (!iwl_is_ready_rf(priv))
450 return;
451
Wey-Yi Guyc68744f2011-06-18 08:03:18 -0700452 IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n");
453 iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
Wey-Yi Guy65550632010-06-24 13:18:35 -0700454}
455
Emmanuel Grumbach7d476182010-05-23 00:14:08 -0700456/*****************************************************************************
457 *
458 * sysfs attributes
459 *
460 *****************************************************************************/
461
462#ifdef CONFIG_IWLWIFI_DEBUG
463
464/*
465 * The following adds a new attribute to the sysfs representation
466 * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
467 * used for controlling the debug level.
468 *
469 * See the level definitions in iwl for details.
470 *
471 * The debug_level being managed using sysfs below is a per device debug
472 * level that is used instead of the global debug level if it (the per
473 * device debug level) is set.
474 */
475static ssize_t show_debug_level(struct device *d,
476 struct device_attribute *attr, char *buf)
477{
478 struct iwl_priv *priv = dev_get_drvdata(d);
479 return sprintf(buf, "0x%08X\n", iwl_get_debug_level(priv));
480}
481static ssize_t store_debug_level(struct device *d,
482 struct device_attribute *attr,
483 const char *buf, size_t count)
484{
485 struct iwl_priv *priv = dev_get_drvdata(d);
486 unsigned long val;
487 int ret;
488
489 ret = strict_strtoul(buf, 0, &val);
490 if (ret)
491 IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf);
492 else {
493 priv->debug_level = val;
494 if (iwl_alloc_traffic_mem(priv))
495 IWL_ERR(priv,
496 "Not enough memory to generate traffic log\n");
497 }
498 return strnlen(buf, count);
499}
500
501static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
502 show_debug_level, store_debug_level);
503
504
505#endif /* CONFIG_IWLWIFI_DEBUG */
506
507
508static ssize_t show_temperature(struct device *d,
509 struct device_attribute *attr, char *buf)
510{
511 struct iwl_priv *priv = dev_get_drvdata(d);
512
513 if (!iwl_is_alive(priv))
514 return -EAGAIN;
515
516 return sprintf(buf, "%d\n", priv->temperature);
517}
518
519static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
520
521static ssize_t show_tx_power(struct device *d,
522 struct device_attribute *attr, char *buf)
523{
524 struct iwl_priv *priv = dev_get_drvdata(d);
525
526 if (!iwl_is_ready_rf(priv))
527 return sprintf(buf, "off\n");
528 else
529 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
530}
531
532static ssize_t store_tx_power(struct device *d,
533 struct device_attribute *attr,
534 const char *buf, size_t count)
535{
536 struct iwl_priv *priv = dev_get_drvdata(d);
537 unsigned long val;
538 int ret;
539
540 ret = strict_strtoul(buf, 10, &val);
541 if (ret)
542 IWL_INFO(priv, "%s is not in decimal form.\n", buf);
543 else {
544 ret = iwl_set_tx_power(priv, val, false);
545 if (ret)
546 IWL_ERR(priv, "failed setting tx power (0x%d).\n",
547 ret);
548 else
549 ret = count;
550 }
551 return ret;
552}
553
554static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
555
Emmanuel Grumbach7d476182010-05-23 00:14:08 -0700556static struct attribute *iwl_sysfs_entries[] = {
557 &dev_attr_temperature.attr,
558 &dev_attr_tx_power.attr,
Emmanuel Grumbach7d476182010-05-23 00:14:08 -0700559#ifdef CONFIG_IWLWIFI_DEBUG
560 &dev_attr_debug_level.attr,
561#endif
562 NULL
563};
564
565static struct attribute_group iwl_attribute_group = {
566 .name = NULL, /* put in device directory */
567 .attrs = iwl_sysfs_entries,
568};
569
Zhu Yib481de92007-09-25 17:54:57 -0700570/******************************************************************************
571 *
572 * uCode download functions
573 *
574 ******************************************************************************/
575
Emmanuel Grumbach3599d392011-05-31 08:52:10 +0300576static void iwl_free_fw_desc(struct iwl_priv *priv, struct fw_desc *desc)
Johannes Bergdbf28e212011-04-16 08:29:24 -0700577{
578 if (desc->v_addr)
Emmanuel Grumbachd5934112011-07-11 10:48:51 +0300579 dma_free_coherent(priv->bus->dev, desc->len,
Johannes Bergdbf28e212011-04-16 08:29:24 -0700580 desc->v_addr, desc->p_addr);
581 desc->v_addr = NULL;
582 desc->len = 0;
583}
584
Emmanuel Grumbach3599d392011-05-31 08:52:10 +0300585static void iwl_free_fw_img(struct iwl_priv *priv, struct fw_img *img)
Johannes Bergdbf28e212011-04-16 08:29:24 -0700586{
Emmanuel Grumbach3599d392011-05-31 08:52:10 +0300587 iwl_free_fw_desc(priv, &img->code);
588 iwl_free_fw_desc(priv, &img->data);
Johannes Bergdbf28e212011-04-16 08:29:24 -0700589}
590
Emmanuel Grumbach3599d392011-05-31 08:52:10 +0300591static void iwl_dealloc_ucode(struct iwl_priv *priv)
592{
593 iwl_free_fw_img(priv, &priv->ucode_rt);
594 iwl_free_fw_img(priv, &priv->ucode_init);
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700595 iwl_free_fw_img(priv, &priv->ucode_wowlan);
Emmanuel Grumbach3599d392011-05-31 08:52:10 +0300596}
597
598static int iwl_alloc_fw_desc(struct iwl_priv *priv, struct fw_desc *desc,
Johannes Bergdbf28e212011-04-16 08:29:24 -0700599 const void *data, size_t len)
600{
601 if (!len) {
602 desc->v_addr = NULL;
603 return -EINVAL;
604 }
605
Emmanuel Grumbachd5934112011-07-11 10:48:51 +0300606 desc->v_addr = dma_alloc_coherent(priv->bus->dev, len,
Johannes Bergdbf28e212011-04-16 08:29:24 -0700607 &desc->p_addr, GFP_KERNEL);
608 if (!desc->v_addr)
609 return -ENOMEM;
Emmanuel Grumbach3599d392011-05-31 08:52:10 +0300610
Johannes Bergdbf28e212011-04-16 08:29:24 -0700611 desc->len = len;
612 memcpy(desc->v_addr, data, len);
613 return 0;
614}
615
Johannes Bergdd7a2502010-04-28 23:33:10 -0700616struct iwlagn_ucode_capabilities {
617 u32 max_probe_length;
Wey-Yi Guy6a822d02010-07-13 17:13:15 -0700618 u32 standard_phy_calibration_size;
Johannes Berg3997ff32011-04-05 09:42:02 -0700619 u32 flags;
Johannes Bergdd7a2502010-04-28 23:33:10 -0700620};
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +0800621
Johannes Bergb08dfd02010-01-29 11:54:56 -0800622static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context);
Johannes Bergdd7a2502010-04-28 23:33:10 -0700623static int iwl_mac_setup_register(struct iwl_priv *priv,
624 struct iwlagn_ucode_capabilities *capa);
Johannes Bergb08dfd02010-01-29 11:54:56 -0800625
Jay Sternberg39396082010-08-12 10:24:07 -0700626#define UCODE_EXPERIMENTAL_INDEX 100
627#define UCODE_EXPERIMENTAL_TAG "exp"
628
Johannes Bergb08dfd02010-01-29 11:54:56 -0800629static int __must_check iwl_request_firmware(struct iwl_priv *priv, bool first)
Zhu Yib481de92007-09-25 17:54:57 -0700630{
Reinette Chatrea0987a82008-12-02 12:14:06 -0800631 const char *name_pre = priv->cfg->fw_name_pre;
Jay Sternberg39396082010-08-12 10:24:07 -0700632 char tag[8];
Johannes Bergb08dfd02010-01-29 11:54:56 -0800633
Jay Sternberg39396082010-08-12 10:24:07 -0700634 if (first) {
635#ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE
636 priv->fw_index = UCODE_EXPERIMENTAL_INDEX;
637 strcpy(tag, UCODE_EXPERIMENTAL_TAG);
638 } else if (priv->fw_index == UCODE_EXPERIMENTAL_INDEX) {
639#endif
Johannes Bergb08dfd02010-01-29 11:54:56 -0800640 priv->fw_index = priv->cfg->ucode_api_max;
Jay Sternberg39396082010-08-12 10:24:07 -0700641 sprintf(tag, "%d", priv->fw_index);
642 } else {
Johannes Bergb08dfd02010-01-29 11:54:56 -0800643 priv->fw_index--;
Jay Sternberg39396082010-08-12 10:24:07 -0700644 sprintf(tag, "%d", priv->fw_index);
645 }
Johannes Bergb08dfd02010-01-29 11:54:56 -0800646
647 if (priv->fw_index < priv->cfg->ucode_api_min) {
648 IWL_ERR(priv, "no suitable firmware found!\n");
649 return -ENOENT;
650 }
651
Jay Sternberg39396082010-08-12 10:24:07 -0700652 sprintf(priv->firmware_name, "%s%s%s", name_pre, tag, ".ucode");
Johannes Bergb08dfd02010-01-29 11:54:56 -0800653
Jay Sternberg39396082010-08-12 10:24:07 -0700654 IWL_DEBUG_INFO(priv, "attempting to load firmware %s'%s'\n",
655 (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
656 ? "EXPERIMENTAL " : "",
Johannes Bergb08dfd02010-01-29 11:54:56 -0800657 priv->firmware_name);
658
659 return request_firmware_nowait(THIS_MODULE, 1, priv->firmware_name,
Emmanuel Grumbachd5934112011-07-11 10:48:51 +0300660 priv->bus->dev,
Emmanuel Grumbach3599d392011-05-31 08:52:10 +0300661 GFP_KERNEL, priv, iwl_ucode_callback);
Johannes Bergb08dfd02010-01-29 11:54:56 -0800662}
663
Johannes Berg0e9a44d2010-04-28 12:09:16 -0700664struct iwlagn_firmware_pieces {
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700665 const void *inst, *data, *init, *init_data, *wowlan_inst, *wowlan_data;
666 size_t inst_size, data_size, init_size, init_data_size,
667 wowlan_inst_size, wowlan_data_size;
Johannes Berg0e9a44d2010-04-28 12:09:16 -0700668
669 u32 build;
Johannes Bergb2e640d2010-05-05 23:24:54 -0700670
671 u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
672 u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
Johannes Berg0e9a44d2010-04-28 12:09:16 -0700673};
674
675static int iwlagn_load_legacy_firmware(struct iwl_priv *priv,
676 const struct firmware *ucode_raw,
677 struct iwlagn_firmware_pieces *pieces)
678{
679 struct iwl_ucode_header *ucode = (void *)ucode_raw->data;
680 u32 api_ver, hdr_size;
681 const u8 *src;
682
683 priv->ucode_ver = le32_to_cpu(ucode->ver);
684 api_ver = IWL_UCODE_API(priv->ucode_ver);
685
686 switch (api_ver) {
687 default:
Wey-Yi Guyf7d046f2011-03-22 08:05:37 -0700688 hdr_size = 28;
689 if (ucode_raw->size < hdr_size) {
690 IWL_ERR(priv, "File size too small!\n");
691 return -EINVAL;
Johannes Berg0e9a44d2010-04-28 12:09:16 -0700692 }
Wey-Yi Guyf7d046f2011-03-22 08:05:37 -0700693 pieces->build = le32_to_cpu(ucode->u.v2.build);
694 pieces->inst_size = le32_to_cpu(ucode->u.v2.inst_size);
695 pieces->data_size = le32_to_cpu(ucode->u.v2.data_size);
696 pieces->init_size = le32_to_cpu(ucode->u.v2.init_size);
697 pieces->init_data_size = le32_to_cpu(ucode->u.v2.init_data_size);
Wey-Yi Guyf7d046f2011-03-22 08:05:37 -0700698 src = ucode->u.v2.data;
699 break;
Johannes Berg0e9a44d2010-04-28 12:09:16 -0700700 case 0:
701 case 1:
702 case 2:
703 hdr_size = 24;
704 if (ucode_raw->size < hdr_size) {
705 IWL_ERR(priv, "File size too small!\n");
706 return -EINVAL;
707 }
708 pieces->build = 0;
709 pieces->inst_size = le32_to_cpu(ucode->u.v1.inst_size);
710 pieces->data_size = le32_to_cpu(ucode->u.v1.data_size);
711 pieces->init_size = le32_to_cpu(ucode->u.v1.init_size);
712 pieces->init_data_size = le32_to_cpu(ucode->u.v1.init_data_size);
Johannes Berg0e9a44d2010-04-28 12:09:16 -0700713 src = ucode->u.v1.data;
714 break;
715 }
716
717 /* Verify size of file vs. image size info in file's header */
718 if (ucode_raw->size != hdr_size + pieces->inst_size +
719 pieces->data_size + pieces->init_size +
Johannes Berg1fc35272011-04-05 09:41:57 -0700720 pieces->init_data_size) {
Johannes Berg0e9a44d2010-04-28 12:09:16 -0700721
722 IWL_ERR(priv,
723 "uCode file size %d does not match expected size\n",
724 (int)ucode_raw->size);
725 return -EINVAL;
726 }
727
728 pieces->inst = src;
729 src += pieces->inst_size;
730 pieces->data = src;
731 src += pieces->data_size;
732 pieces->init = src;
733 src += pieces->init_size;
734 pieces->init_data = src;
735 src += pieces->init_data_size;
Johannes Berg0e9a44d2010-04-28 12:09:16 -0700736
737 return 0;
738}
739
Johannes Bergdd7a2502010-04-28 23:33:10 -0700740static int iwlagn_wanted_ucode_alternative = 1;
741
742static int iwlagn_load_firmware(struct iwl_priv *priv,
743 const struct firmware *ucode_raw,
744 struct iwlagn_firmware_pieces *pieces,
745 struct iwlagn_ucode_capabilities *capa)
746{
747 struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data;
748 struct iwl_ucode_tlv *tlv;
749 size_t len = ucode_raw->size;
750 const u8 *data;
751 int wanted_alternative = iwlagn_wanted_ucode_alternative, tmp;
752 u64 alternatives;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -0700753 u32 tlv_len;
754 enum iwl_ucode_tlv_type tlv_type;
755 const u8 *tlv_data;
Johannes Bergdd7a2502010-04-28 23:33:10 -0700756
Wey-Yi Guyad8d8332010-06-22 14:31:45 -0700757 if (len < sizeof(*ucode)) {
758 IWL_ERR(priv, "uCode has invalid length: %zd\n", len);
Johannes Bergdd7a2502010-04-28 23:33:10 -0700759 return -EINVAL;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -0700760 }
Johannes Bergdd7a2502010-04-28 23:33:10 -0700761
Wey-Yi Guyad8d8332010-06-22 14:31:45 -0700762 if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) {
763 IWL_ERR(priv, "invalid uCode magic: 0X%x\n",
764 le32_to_cpu(ucode->magic));
Johannes Bergdd7a2502010-04-28 23:33:10 -0700765 return -EINVAL;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -0700766 }
Johannes Bergdd7a2502010-04-28 23:33:10 -0700767
768 /*
769 * Check which alternatives are present, and "downgrade"
770 * when the chosen alternative is not present, warning
771 * the user when that happens. Some files may not have
772 * any alternatives, so don't warn in that case.
773 */
774 alternatives = le64_to_cpu(ucode->alternatives);
775 tmp = wanted_alternative;
776 if (wanted_alternative > 63)
777 wanted_alternative = 63;
778 while (wanted_alternative && !(alternatives & BIT(wanted_alternative)))
779 wanted_alternative--;
780 if (wanted_alternative && wanted_alternative != tmp)
781 IWL_WARN(priv,
782 "uCode alternative %d not available, choosing %d\n",
783 tmp, wanted_alternative);
784
785 priv->ucode_ver = le32_to_cpu(ucode->ver);
786 pieces->build = le32_to_cpu(ucode->build);
787 data = ucode->data;
788
789 len -= sizeof(*ucode);
790
Johannes Berg704da532010-07-14 09:34:50 -0700791 while (len >= sizeof(*tlv)) {
Johannes Bergdd7a2502010-04-28 23:33:10 -0700792 u16 tlv_alt;
Johannes Bergdd7a2502010-04-28 23:33:10 -0700793
794 len -= sizeof(*tlv);
795 tlv = (void *)data;
796
797 tlv_len = le32_to_cpu(tlv->length);
798 tlv_type = le16_to_cpu(tlv->type);
799 tlv_alt = le16_to_cpu(tlv->alternative);
800 tlv_data = tlv->data;
801
Wey-Yi Guyad8d8332010-06-22 14:31:45 -0700802 if (len < tlv_len) {
803 IWL_ERR(priv, "invalid TLV len: %zd/%u\n",
804 len, tlv_len);
Johannes Bergdd7a2502010-04-28 23:33:10 -0700805 return -EINVAL;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -0700806 }
Johannes Bergdd7a2502010-04-28 23:33:10 -0700807 len -= ALIGN(tlv_len, 4);
808 data += sizeof(*tlv) + ALIGN(tlv_len, 4);
809
810 /*
811 * Alternative 0 is always valid.
812 *
813 * Skip alternative TLVs that are not selected.
814 */
815 if (tlv_alt != 0 && tlv_alt != wanted_alternative)
816 continue;
817
818 switch (tlv_type) {
819 case IWL_UCODE_TLV_INST:
820 pieces->inst = tlv_data;
821 pieces->inst_size = tlv_len;
822 break;
823 case IWL_UCODE_TLV_DATA:
824 pieces->data = tlv_data;
825 pieces->data_size = tlv_len;
826 break;
827 case IWL_UCODE_TLV_INIT:
828 pieces->init = tlv_data;
829 pieces->init_size = tlv_len;
830 break;
831 case IWL_UCODE_TLV_INIT_DATA:
832 pieces->init_data = tlv_data;
833 pieces->init_data_size = tlv_len;
834 break;
835 case IWL_UCODE_TLV_BOOT:
Johannes Berg1fc35272011-04-05 09:41:57 -0700836 IWL_ERR(priv, "Found unexpected BOOT ucode\n");
Johannes Bergdd7a2502010-04-28 23:33:10 -0700837 break;
838 case IWL_UCODE_TLV_PROBE_MAX_LEN:
Johannes Berg704da532010-07-14 09:34:50 -0700839 if (tlv_len != sizeof(u32))
840 goto invalid_tlv_len;
841 capa->max_probe_length =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -0700842 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergdd7a2502010-04-28 23:33:10 -0700843 break;
Johannes Bergece9c4e2010-08-23 10:46:49 +0200844 case IWL_UCODE_TLV_PAN:
845 if (tlv_len)
846 goto invalid_tlv_len;
Johannes Berg3997ff32011-04-05 09:42:02 -0700847 capa->flags |= IWL_UCODE_TLV_FLAGS_PAN;
848 break;
849 case IWL_UCODE_TLV_FLAGS:
850 /* must be at least one u32 */
851 if (tlv_len < sizeof(u32))
852 goto invalid_tlv_len;
853 /* and a proper number of u32s */
854 if (tlv_len % sizeof(u32))
855 goto invalid_tlv_len;
856 /*
857 * This driver only reads the first u32 as
858 * right now no more features are defined,
859 * if that changes then either the driver
860 * will not work with the new firmware, or
861 * it'll not take advantage of new features.
862 */
863 capa->flags = le32_to_cpup((__le32 *)tlv_data);
Johannes Bergece9c4e2010-08-23 10:46:49 +0200864 break;
Johannes Bergb2e640d2010-05-05 23:24:54 -0700865 case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
Johannes Berg704da532010-07-14 09:34:50 -0700866 if (tlv_len != sizeof(u32))
867 goto invalid_tlv_len;
868 pieces->init_evtlog_ptr =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -0700869 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -0700870 break;
871 case IWL_UCODE_TLV_INIT_EVTLOG_SIZE:
Johannes Berg704da532010-07-14 09:34:50 -0700872 if (tlv_len != sizeof(u32))
873 goto invalid_tlv_len;
874 pieces->init_evtlog_size =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -0700875 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -0700876 break;
877 case IWL_UCODE_TLV_INIT_ERRLOG_PTR:
Johannes Berg704da532010-07-14 09:34:50 -0700878 if (tlv_len != sizeof(u32))
879 goto invalid_tlv_len;
880 pieces->init_errlog_ptr =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -0700881 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -0700882 break;
883 case IWL_UCODE_TLV_RUNT_EVTLOG_PTR:
Johannes Berg704da532010-07-14 09:34:50 -0700884 if (tlv_len != sizeof(u32))
885 goto invalid_tlv_len;
886 pieces->inst_evtlog_ptr =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -0700887 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -0700888 break;
889 case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE:
Johannes Berg704da532010-07-14 09:34:50 -0700890 if (tlv_len != sizeof(u32))
891 goto invalid_tlv_len;
892 pieces->inst_evtlog_size =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -0700893 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -0700894 break;
895 case IWL_UCODE_TLV_RUNT_ERRLOG_PTR:
Johannes Berg704da532010-07-14 09:34:50 -0700896 if (tlv_len != sizeof(u32))
897 goto invalid_tlv_len;
898 pieces->inst_errlog_ptr =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -0700899 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -0700900 break;
Wey-Yi Guyc8312fa2010-06-28 13:05:17 -0700901 case IWL_UCODE_TLV_ENHANCE_SENS_TBL:
902 if (tlv_len)
Johannes Berg704da532010-07-14 09:34:50 -0700903 goto invalid_tlv_len;
904 priv->enhance_sensitivity_table = true;
Wey-Yi Guyc8312fa2010-06-28 13:05:17 -0700905 break;
Johannes Bergc8ac61c2011-07-15 13:23:45 -0700906 case IWL_UCODE_TLV_WOWLAN_INST:
907 pieces->wowlan_inst = tlv_data;
908 pieces->wowlan_inst_size = tlv_len;
909 break;
910 case IWL_UCODE_TLV_WOWLAN_DATA:
911 pieces->wowlan_data = tlv_data;
912 pieces->wowlan_data_size = tlv_len;
913 break;
Wey-Yi Guy6a822d02010-07-13 17:13:15 -0700914 case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE:
Johannes Berg704da532010-07-14 09:34:50 -0700915 if (tlv_len != sizeof(u32))
916 goto invalid_tlv_len;
917 capa->standard_phy_calibration_size =
Wey-Yi Guy6a822d02010-07-13 17:13:15 -0700918 le32_to_cpup((__le32 *)tlv_data);
919 break;
Johannes Bergdd7a2502010-04-28 23:33:10 -0700920 default:
Johannes Berg6fc3ba92011-04-04 06:16:29 -0700921 IWL_DEBUG_INFO(priv, "unknown TLV: %d\n", tlv_type);
Johannes Bergdd7a2502010-04-28 23:33:10 -0700922 break;
923 }
924 }
925
Wey-Yi Guyad8d8332010-06-22 14:31:45 -0700926 if (len) {
927 IWL_ERR(priv, "invalid TLV after parsing: %zd\n", len);
928 iwl_print_hex_dump(priv, IWL_DL_FW, (u8 *)data, len);
Johannes Berg704da532010-07-14 09:34:50 -0700929 return -EINVAL;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -0700930 }
Johannes Bergdd7a2502010-04-28 23:33:10 -0700931
Johannes Berg704da532010-07-14 09:34:50 -0700932 return 0;
933
934 invalid_tlv_len:
935 IWL_ERR(priv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len);
936 iwl_print_hex_dump(priv, IWL_DL_FW, tlv_data, tlv_len);
937
938 return -EINVAL;
Johannes Bergdd7a2502010-04-28 23:33:10 -0700939}
940
Johannes Bergb08dfd02010-01-29 11:54:56 -0800941/**
942 * iwl_ucode_callback - callback when firmware was loaded
943 *
944 * If loaded successfully, copies the firmware into buffers
945 * for the card to fetch (via DMA).
946 */
947static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
948{
949 struct iwl_priv *priv = context;
950 struct iwl_ucode_header *ucode;
Johannes Berg0e9a44d2010-04-28 12:09:16 -0700951 int err;
952 struct iwlagn_firmware_pieces pieces;
Reinette Chatrea0987a82008-12-02 12:14:06 -0800953 const unsigned int api_max = priv->cfg->ucode_api_max;
Johannes Berg5d7969b2011-07-23 10:24:44 -0700954 unsigned int api_ok = priv->cfg->ucode_api_ok;
Reinette Chatrea0987a82008-12-02 12:14:06 -0800955 const unsigned int api_min = priv->cfg->ucode_api_min;
Johannes Berg0e9a44d2010-04-28 12:09:16 -0700956 u32 api_ver;
Johannes Berg3e4de762010-04-28 12:09:12 -0700957 char buildstr[25];
Johannes Berg0e9a44d2010-04-28 12:09:16 -0700958 u32 build;
Johannes Bergdd7a2502010-04-28 23:33:10 -0700959 struct iwlagn_ucode_capabilities ucode_capa = {
960 .max_probe_length = 200,
Wey-Yi Guy6a822d02010-07-13 17:13:15 -0700961 .standard_phy_calibration_size =
Shanyu Zhao642454c2010-09-21 12:06:18 -0700962 IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE,
Johannes Bergdd7a2502010-04-28 23:33:10 -0700963 };
Johannes Berg0e9a44d2010-04-28 12:09:16 -0700964
Johannes Berg5d7969b2011-07-23 10:24:44 -0700965 if (!api_ok)
966 api_ok = api_max;
967
Johannes Berg0e9a44d2010-04-28 12:09:16 -0700968 memset(&pieces, 0, sizeof(pieces));
Zhu Yib481de92007-09-25 17:54:57 -0700969
Johannes Bergb08dfd02010-01-29 11:54:56 -0800970 if (!ucode_raw) {
Johannes Berg5d7969b2011-07-23 10:24:44 -0700971 if (priv->fw_index <= api_ok)
Jay Sternberg39396082010-08-12 10:24:07 -0700972 IWL_ERR(priv,
973 "request for firmware file '%s' failed.\n",
974 priv->firmware_name);
Johannes Bergb08dfd02010-01-29 11:54:56 -0800975 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -0700976 }
977
Johannes Bergb08dfd02010-01-29 11:54:56 -0800978 IWL_DEBUG_INFO(priv, "Loaded firmware file '%s' (%zd bytes).\n",
979 priv->firmware_name, ucode_raw->size);
Zhu Yib481de92007-09-25 17:54:57 -0700980
Johannes Berg22adba22010-04-28 12:09:14 -0700981 /* Make sure that we got at least the API version number */
982 if (ucode_raw->size < 4) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800983 IWL_ERR(priv, "File size way too small!\n");
Johannes Bergb08dfd02010-01-29 11:54:56 -0800984 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -0700985 }
986
987 /* Data from ucode file: header followed by uCode images */
Jay Sternbergcc0f5552009-07-17 09:30:16 -0700988 ucode = (struct iwl_ucode_header *)ucode_raw->data;
Zhu Yib481de92007-09-25 17:54:57 -0700989
Johannes Berg0e9a44d2010-04-28 12:09:16 -0700990 if (ucode->ver)
991 err = iwlagn_load_legacy_firmware(priv, ucode_raw, &pieces);
992 else
Johannes Bergdd7a2502010-04-28 23:33:10 -0700993 err = iwlagn_load_firmware(priv, ucode_raw, &pieces,
994 &ucode_capa);
Johannes Berg0e9a44d2010-04-28 12:09:16 -0700995
996 if (err)
997 goto try_again;
998
Reinette Chatrea0987a82008-12-02 12:14:06 -0800999 api_ver = IWL_UCODE_API(priv->ucode_ver);
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001000 build = pieces.build;
Zhu Yib481de92007-09-25 17:54:57 -07001001
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001002 /*
1003 * api_ver should match the api version forming part of the
Reinette Chatrea0987a82008-12-02 12:14:06 -08001004 * firmware filename ... but we don't check for that and only rely
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001005 * on the API version read from firmware header from here on forward
1006 */
Wey-Yi Guy65cccfb2010-09-21 16:15:58 -07001007 /* no api version check required for experimental uCode */
1008 if (priv->fw_index != UCODE_EXPERIMENTAL_INDEX) {
1009 if (api_ver < api_min || api_ver > api_max) {
1010 IWL_ERR(priv,
1011 "Driver unable to support your firmware API. "
1012 "Driver supports v%u, firmware is v%u.\n",
1013 api_max, api_ver);
1014 goto try_again;
1015 }
Johannes Bergb08dfd02010-01-29 11:54:56 -08001016
Johannes Berg5d7969b2011-07-23 10:24:44 -07001017 if (api_ver < api_ok) {
1018 if (api_ok != api_max)
1019 IWL_ERR(priv, "Firmware has old API version, "
1020 "expected v%u through v%u, got v%u.\n",
1021 api_ok, api_max, api_ver);
1022 else
1023 IWL_ERR(priv, "Firmware has old API version, "
1024 "expected v%u, got v%u.\n",
1025 api_max, api_ver);
1026 IWL_ERR(priv, "New firmware can be obtained from "
1027 "http://www.intellinuxwireless.org/.\n");
1028 }
Wey-Yi Guy65cccfb2010-09-21 16:15:58 -07001029 }
Reinette Chatrea0987a82008-12-02 12:14:06 -08001030
Johannes Berg3e4de762010-04-28 12:09:12 -07001031 if (build)
Jay Sternberg39396082010-08-12 10:24:07 -07001032 sprintf(buildstr, " build %u%s", build,
1033 (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
1034 ? " (EXP)" : "");
Johannes Berg3e4de762010-04-28 12:09:12 -07001035 else
1036 buildstr[0] = '\0';
Reinette Chatrea0987a82008-12-02 12:14:06 -08001037
Johannes Berg3e4de762010-04-28 12:09:12 -07001038 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u%s\n",
Reinette Chatre5ebeb5a2009-10-30 14:36:04 -07001039 IWL_UCODE_MAJOR(priv->ucode_ver),
1040 IWL_UCODE_MINOR(priv->ucode_ver),
1041 IWL_UCODE_API(priv->ucode_ver),
Johannes Berg3e4de762010-04-28 12:09:12 -07001042 IWL_UCODE_SERIAL(priv->ucode_ver),
1043 buildstr);
Reinette Chatre5ebeb5a2009-10-30 14:36:04 -07001044
Johannes Berg3e4de762010-04-28 12:09:12 -07001045 snprintf(priv->hw->wiphy->fw_version,
1046 sizeof(priv->hw->wiphy->fw_version),
1047 "%u.%u.%u.%u%s",
1048 IWL_UCODE_MAJOR(priv->ucode_ver),
1049 IWL_UCODE_MINOR(priv->ucode_ver),
1050 IWL_UCODE_API(priv->ucode_ver),
1051 IWL_UCODE_SERIAL(priv->ucode_ver),
1052 buildstr);
Zhu Yib481de92007-09-25 17:54:57 -07001053
Johannes Bergb08dfd02010-01-29 11:54:56 -08001054 /*
1055 * For any of the failures below (before allocating pci memory)
1056 * we will try to load a version with a smaller API -- maybe the
1057 * user just got a corrupted version of the latest API.
1058 */
1059
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001060 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
1061 priv->ucode_ver);
1062 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %Zd\n",
1063 pieces.inst_size);
1064 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %Zd\n",
1065 pieces.data_size);
1066 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %Zd\n",
1067 pieces.init_size);
1068 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %Zd\n",
1069 pieces.init_data_size);
Zhu Yib481de92007-09-25 17:54:57 -07001070
1071 /* Verify that uCode images will fit in card's SRAM */
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001072 if (pieces.inst_size > priv->hw_params.max_inst_size) {
1073 IWL_ERR(priv, "uCode instr len %Zd too large to fit in\n",
1074 pieces.inst_size);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001075 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07001076 }
1077
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001078 if (pieces.data_size > priv->hw_params.max_data_size) {
1079 IWL_ERR(priv, "uCode data len %Zd too large to fit in\n",
1080 pieces.data_size);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001081 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07001082 }
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001083
1084 if (pieces.init_size > priv->hw_params.max_inst_size) {
1085 IWL_ERR(priv, "uCode init instr len %Zd too large to fit in\n",
1086 pieces.init_size);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001087 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07001088 }
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001089
1090 if (pieces.init_data_size > priv->hw_params.max_data_size) {
1091 IWL_ERR(priv, "uCode init data len %Zd too large to fit in\n",
1092 pieces.init_data_size);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001093 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07001094 }
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001095
Zhu Yib481de92007-09-25 17:54:57 -07001096 /* Allocate ucode buffers for card's bus-master loading ... */
1097
1098 /* Runtime instructions and 2 copies of data:
1099 * 1) unmodified from disk
1100 * 2) backup cache for save/restore during power-downs */
Emmanuel Grumbach3599d392011-05-31 08:52:10 +03001101 if (iwl_alloc_fw_desc(priv, &priv->ucode_rt.code,
Johannes Bergdbf28e212011-04-16 08:29:24 -07001102 pieces.inst, pieces.inst_size))
1103 goto err_pci_alloc;
Emmanuel Grumbach3599d392011-05-31 08:52:10 +03001104 if (iwl_alloc_fw_desc(priv, &priv->ucode_rt.data,
Johannes Bergdbf28e212011-04-16 08:29:24 -07001105 pieces.data, pieces.data_size))
Zhu, Yi1f304e42009-01-23 13:45:22 -08001106 goto err_pci_alloc;
1107
Zhu Yib481de92007-09-25 17:54:57 -07001108 /* Initialization instructions and data */
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001109 if (pieces.init_size && pieces.init_data_size) {
Emmanuel Grumbach3599d392011-05-31 08:52:10 +03001110 if (iwl_alloc_fw_desc(priv, &priv->ucode_init.code,
Johannes Bergdbf28e212011-04-16 08:29:24 -07001111 pieces.init, pieces.init_size))
1112 goto err_pci_alloc;
Emmanuel Grumbach3599d392011-05-31 08:52:10 +03001113 if (iwl_alloc_fw_desc(priv, &priv->ucode_init.data,
Johannes Bergdbf28e212011-04-16 08:29:24 -07001114 pieces.init_data, pieces.init_data_size))
Tomas Winkler90e759d2007-11-29 11:09:41 +08001115 goto err_pci_alloc;
1116 }
Zhu Yib481de92007-09-25 17:54:57 -07001117
Johannes Bergc8ac61c2011-07-15 13:23:45 -07001118 /* WoWLAN instructions and data */
1119 if (pieces.wowlan_inst_size && pieces.wowlan_data_size) {
1120 if (iwl_alloc_fw_desc(priv, &priv->ucode_wowlan.code,
1121 pieces.wowlan_inst,
1122 pieces.wowlan_inst_size))
1123 goto err_pci_alloc;
1124 if (iwl_alloc_fw_desc(priv, &priv->ucode_wowlan.data,
1125 pieces.wowlan_data,
1126 pieces.wowlan_data_size))
1127 goto err_pci_alloc;
1128 }
1129
Johannes Bergb2e640d2010-05-05 23:24:54 -07001130 /* Now that we can no longer fail, copy information */
1131
1132 /*
1133 * The (size - 16) / 12 formula is based on the information recorded
1134 * for each event, which is of mode 1 (including timestamp) for all
1135 * new microcodes that include this information.
1136 */
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001137 priv->init_evtlog_ptr = pieces.init_evtlog_ptr;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001138 if (pieces.init_evtlog_size)
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001139 priv->init_evtlog_size = (pieces.init_evtlog_size - 16)/12;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001140 else
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001141 priv->init_evtlog_size =
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07001142 priv->cfg->base_params->max_event_log_size;
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001143 priv->init_errlog_ptr = pieces.init_errlog_ptr;
1144 priv->inst_evtlog_ptr = pieces.inst_evtlog_ptr;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001145 if (pieces.inst_evtlog_size)
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001146 priv->inst_evtlog_size = (pieces.inst_evtlog_size - 16)/12;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001147 else
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001148 priv->inst_evtlog_size =
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07001149 priv->cfg->base_params->max_event_log_size;
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001150 priv->inst_errlog_ptr = pieces.inst_errlog_ptr;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001151
Johannes Bergd2690c02011-04-20 09:10:39 -07001152 priv->new_scan_threshold_behaviour =
1153 !!(ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NEWSCAN);
1154
Wey-Yi Guyb2ea3452011-06-07 08:53:14 -07001155 if ((priv->cfg->sku & EEPROM_SKU_CAP_IPAN_ENABLE) &&
1156 (ucode_capa.flags & IWL_UCODE_TLV_FLAGS_PAN)) {
Johannes Bergece9c4e2010-08-23 10:46:49 +02001157 priv->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
Johannes Bergc10afb62010-08-23 10:46:43 +02001158 priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
Johannes Bergece9c4e2010-08-23 10:46:49 +02001159 } else
1160 priv->sta_key_max_num = STA_KEY_MAX_NUM;
Johannes Bergc10afb62010-08-23 10:46:43 +02001161
Johannes Berg17445b82011-04-05 09:42:05 -07001162 if (priv->valid_contexts != BIT(IWL_RXON_CTX_BSS))
1163 priv->cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
1164 else
1165 priv->cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
1166
Wey-Yi Guy6a822d02010-07-13 17:13:15 -07001167 /*
1168 * figure out the offset of chain noise reset and gain commands
1169 * base on the size of standard phy calibration commands table size
1170 */
1171 if (ucode_capa.standard_phy_calibration_size >
1172 IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
1173 ucode_capa.standard_phy_calibration_size =
1174 IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
1175
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001176 priv->phy_calib_chain_noise_reset_cmd =
Wey-Yi Guy6a822d02010-07-13 17:13:15 -07001177 ucode_capa.standard_phy_calibration_size;
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001178 priv->phy_calib_chain_noise_gain_cmd =
Wey-Yi Guy6a822d02010-07-13 17:13:15 -07001179 ucode_capa.standard_phy_calibration_size + 1;
1180
Johannes Bergb08dfd02010-01-29 11:54:56 -08001181 /**************************************************
1182 * This is still part of probe() in a sense...
1183 *
1184 * 9. Setup and register with mac80211 and debugfs
1185 **************************************************/
Johannes Bergdd7a2502010-04-28 23:33:10 -07001186 err = iwl_mac_setup_register(priv, &ucode_capa);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001187 if (err)
1188 goto out_unbind;
1189
1190 err = iwl_dbgfs_register(priv, DRV_NAME);
1191 if (err)
1192 IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
1193
Emmanuel Grumbachd5934112011-07-11 10:48:51 +03001194 err = sysfs_create_group(&(priv->bus->dev->kobj),
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07001195 &iwl_attribute_group);
1196 if (err) {
1197 IWL_ERR(priv, "failed to create sysfs device attributes\n");
1198 goto out_unbind;
1199 }
1200
Zhu Yib481de92007-09-25 17:54:57 -07001201 /* We have our copies now, allow OS release its copies */
1202 release_firmware(ucode_raw);
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001203 complete(&priv->firmware_loading_complete);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001204 return;
1205
1206 try_again:
1207 /* try next, if any */
1208 if (iwl_request_firmware(priv, false))
1209 goto out_unbind;
1210 release_firmware(ucode_raw);
1211 return;
Zhu Yib481de92007-09-25 17:54:57 -07001212
1213 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08001214 IWL_ERR(priv, "failed to allocate pci memory\n");
Emmanuel Grumbach3599d392011-05-31 08:52:10 +03001215 iwl_dealloc_ucode(priv);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001216 out_unbind:
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001217 complete(&priv->firmware_loading_complete);
Emmanuel Grumbachd5934112011-07-11 10:48:51 +03001218 device_release_driver(priv->bus->dev);
Zhu Yib481de92007-09-25 17:54:57 -07001219 release_firmware(ucode_raw);
Zhu Yib481de92007-09-25 17:54:57 -07001220}
1221
Joe Perches2a897d42011-07-08 23:20:25 -07001222static const char * const desc_lookup_text[] = {
Reinette Chatreb7a79402009-09-25 14:24:23 -07001223 "OK",
1224 "FAIL",
1225 "BAD_PARAM",
1226 "BAD_CHECKSUM",
1227 "NMI_INTERRUPT_WDG",
1228 "SYSASSERT",
1229 "FATAL_ERROR",
1230 "BAD_COMMAND",
1231 "HW_ERROR_TUNE_LOCK",
1232 "HW_ERROR_TEMPERATURE",
1233 "ILLEGAL_CHAN_FREQ",
1234 "VCC_NOT_STABLE",
1235 "FH_ERROR",
1236 "NMI_INTERRUPT_HOST",
1237 "NMI_INTERRUPT_ACTION_PT",
1238 "NMI_INTERRUPT_UNKNOWN",
1239 "UCODE_VERSION_MISMATCH",
1240 "HW_ERROR_ABS_LOCK",
1241 "HW_ERROR_CAL_LOCK_FAIL",
1242 "NMI_INTERRUPT_INST_ACTION_PT",
1243 "NMI_INTERRUPT_DATA_ACTION_PT",
1244 "NMI_TRM_HW_ER",
1245 "NMI_INTERRUPT_TRM",
Joe Perches2a897d42011-07-08 23:20:25 -07001246 "NMI_INTERRUPT_BREAK_POINT",
Reinette Chatreb7a79402009-09-25 14:24:23 -07001247 "DEBUG_0",
1248 "DEBUG_1",
1249 "DEBUG_2",
1250 "DEBUG_3",
Reinette Chatreb7a79402009-09-25 14:24:23 -07001251};
1252
Jay Sternberg4b586452010-07-02 15:49:10 -07001253static struct { char *name; u8 num; } advanced_lookup[] = {
1254 { "NMI_INTERRUPT_WDG", 0x34 },
1255 { "SYSASSERT", 0x35 },
1256 { "UCODE_VERSION_MISMATCH", 0x37 },
1257 { "BAD_COMMAND", 0x38 },
1258 { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
1259 { "FATAL_ERROR", 0x3D },
1260 { "NMI_TRM_HW_ERR", 0x46 },
1261 { "NMI_INTERRUPT_TRM", 0x4C },
1262 { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
1263 { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
1264 { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
1265 { "NMI_INTERRUPT_HOST", 0x66 },
1266 { "NMI_INTERRUPT_ACTION_PT", 0x7C },
1267 { "NMI_INTERRUPT_UNKNOWN", 0x84 },
1268 { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
1269 { "ADVANCED_SYSASSERT", 0 },
1270};
1271
1272static const char *desc_lookup(u32 num)
Reinette Chatreb7a79402009-09-25 14:24:23 -07001273{
Jay Sternberg4b586452010-07-02 15:49:10 -07001274 int i;
1275 int max = ARRAY_SIZE(desc_lookup_text);
Reinette Chatreb7a79402009-09-25 14:24:23 -07001276
Jay Sternberg4b586452010-07-02 15:49:10 -07001277 if (num < max)
1278 return desc_lookup_text[num];
Reinette Chatreb7a79402009-09-25 14:24:23 -07001279
Jay Sternberg4b586452010-07-02 15:49:10 -07001280 max = ARRAY_SIZE(advanced_lookup) - 1;
1281 for (i = 0; i < max; i++) {
1282 if (advanced_lookup[i].num == num)
Justin P. Mattock6eab04a2011-04-08 19:49:08 -07001283 break;
Jay Sternberg4b586452010-07-02 15:49:10 -07001284 }
1285 return advanced_lookup[i].name;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001286}
1287
1288#define ERROR_START_OFFSET (1 * sizeof(u32))
1289#define ERROR_ELEM_SIZE (7 * sizeof(u32))
1290
1291void iwl_dump_nic_error_log(struct iwl_priv *priv)
1292{
Wey-Yi Guy50650542011-05-04 16:56:52 -07001293 u32 base;
Johannes Berge46f6532011-04-13 03:14:43 -07001294 struct iwl_error_event_table table;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001295
Johannes Bergd7d57832011-04-05 09:42:04 -07001296 base = priv->device_pointers.error_event_table;
Johannes Berg872907b2011-06-06 09:41:15 -07001297 if (priv->ucode_type == IWL_UCODE_INIT) {
Johannes Bergb2e640d2010-05-05 23:24:54 -07001298 if (!base)
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001299 base = priv->init_errlog_ptr;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001300 } else {
Johannes Bergb2e640d2010-05-05 23:24:54 -07001301 if (!base)
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001302 base = priv->inst_errlog_ptr;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001303 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07001304
Fry, Donald H4caab322011-07-07 15:24:07 -07001305 if (!iwlagn_hw_valid_rtc_data_addr(base)) {
Wey-Yi Guy212fb572009-12-02 12:53:00 -08001306 IWL_ERR(priv,
1307 "Not valid error log pointer 0x%08X for %s uCode\n",
Johannes Bergca7966c2011-04-22 10:15:23 -07001308 base,
Johannes Berg872907b2011-06-06 09:41:15 -07001309 (priv->ucode_type == IWL_UCODE_INIT)
Johannes Bergca7966c2011-04-22 10:15:23 -07001310 ? "Init" : "RT");
Reinette Chatreb7a79402009-09-25 14:24:23 -07001311 return;
1312 }
1313
Johannes Berge46f6532011-04-13 03:14:43 -07001314 iwl_read_targ_mem_words(priv, base, &table, sizeof(table));
1315
Wey-Yi Guy50650542011-05-04 16:56:52 -07001316 if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
Reinette Chatreb7a79402009-09-25 14:24:23 -07001317 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
1318 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
Wey-Yi Guy50650542011-05-04 16:56:52 -07001319 priv->status, table.valid);
Reinette Chatreb7a79402009-09-25 14:24:23 -07001320 }
1321
Wey-Yi Guy50650542011-05-04 16:56:52 -07001322 priv->isr_stats.err_code = table.error_id;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001323
Wey-Yi Guy50650542011-05-04 16:56:52 -07001324 trace_iwlwifi_dev_ucode_error(priv, table.error_id, table.tsf_low,
1325 table.data1, table.data2, table.line,
1326 table.blink1, table.blink2, table.ilink1,
1327 table.ilink2, table.bcon_time, table.gp1,
1328 table.gp2, table.gp3, table.ucode_ver,
1329 table.hw_ver, table.brd_ver);
1330 IWL_ERR(priv, "0x%08X | %-28s\n", table.error_id,
1331 desc_lookup(table.error_id));
1332 IWL_ERR(priv, "0x%08X | uPc\n", table.pc);
1333 IWL_ERR(priv, "0x%08X | branchlink1\n", table.blink1);
1334 IWL_ERR(priv, "0x%08X | branchlink2\n", table.blink2);
1335 IWL_ERR(priv, "0x%08X | interruptlink1\n", table.ilink1);
1336 IWL_ERR(priv, "0x%08X | interruptlink2\n", table.ilink2);
1337 IWL_ERR(priv, "0x%08X | data1\n", table.data1);
1338 IWL_ERR(priv, "0x%08X | data2\n", table.data2);
1339 IWL_ERR(priv, "0x%08X | line\n", table.line);
1340 IWL_ERR(priv, "0x%08X | beacon time\n", table.bcon_time);
1341 IWL_ERR(priv, "0x%08X | tsf low\n", table.tsf_low);
1342 IWL_ERR(priv, "0x%08X | tsf hi\n", table.tsf_hi);
1343 IWL_ERR(priv, "0x%08X | time gp1\n", table.gp1);
1344 IWL_ERR(priv, "0x%08X | time gp2\n", table.gp2);
1345 IWL_ERR(priv, "0x%08X | time gp3\n", table.gp3);
1346 IWL_ERR(priv, "0x%08X | uCode version\n", table.ucode_ver);
1347 IWL_ERR(priv, "0x%08X | hw version\n", table.hw_ver);
1348 IWL_ERR(priv, "0x%08X | board version\n", table.brd_ver);
1349 IWL_ERR(priv, "0x%08X | hcmd\n", table.hcmd);
Reinette Chatreb7a79402009-09-25 14:24:23 -07001350}
1351
1352#define EVENT_START_OFFSET (4 * sizeof(u32))
1353
1354/**
1355 * iwl_print_event_log - Dump error event log to syslog
1356 *
1357 */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001358static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
1359 u32 num_events, u32 mode,
1360 int pos, char **buf, size_t bufsz)
Reinette Chatreb7a79402009-09-25 14:24:23 -07001361{
1362 u32 i;
1363 u32 base; /* SRAM byte address of event log header */
1364 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
1365 u32 ptr; /* SRAM byte address of log data */
1366 u32 ev, time, data; /* event log data */
Ben Cahille5854472009-11-06 14:52:58 -08001367 unsigned long reg_flags;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001368
1369 if (num_events == 0)
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001370 return pos;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001371
Johannes Bergd7d57832011-04-05 09:42:04 -07001372 base = priv->device_pointers.log_event_table;
Johannes Berg872907b2011-06-06 09:41:15 -07001373 if (priv->ucode_type == IWL_UCODE_INIT) {
Johannes Bergb2e640d2010-05-05 23:24:54 -07001374 if (!base)
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001375 base = priv->init_evtlog_ptr;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001376 } else {
Johannes Bergb2e640d2010-05-05 23:24:54 -07001377 if (!base)
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001378 base = priv->inst_evtlog_ptr;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001379 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07001380
1381 if (mode == 0)
1382 event_size = 2 * sizeof(u32);
1383 else
1384 event_size = 3 * sizeof(u32);
1385
1386 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
1387
Ben Cahille5854472009-11-06 14:52:58 -08001388 /* Make sure device is powered up for SRAM reads */
1389 spin_lock_irqsave(&priv->reg_lock, reg_flags);
1390 iwl_grab_nic_access(priv);
1391
1392 /* Set starting address; reads will auto-increment */
Johannes Berg02a7fa02011-04-05 09:42:12 -07001393 iwl_write32(priv, HBUS_TARG_MEM_RADDR, ptr);
Ben Cahille5854472009-11-06 14:52:58 -08001394 rmb();
1395
Reinette Chatreb7a79402009-09-25 14:24:23 -07001396 /* "time" is actually "data" for mode 0 (no timestamp).
1397 * place event id # at far right for easier visual parsing. */
1398 for (i = 0; i < num_events; i++) {
Johannes Berg02a7fa02011-04-05 09:42:12 -07001399 ev = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
1400 time = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
Reinette Chatreb7a79402009-09-25 14:24:23 -07001401 if (mode == 0) {
1402 /* data, ev */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001403 if (bufsz) {
1404 pos += scnprintf(*buf + pos, bufsz - pos,
1405 "EVT_LOG:0x%08x:%04u\n",
1406 time, ev);
1407 } else {
1408 trace_iwlwifi_dev_ucode_event(priv, 0,
1409 time, ev);
1410 IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n",
1411 time, ev);
1412 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07001413 } else {
Johannes Berg02a7fa02011-04-05 09:42:12 -07001414 data = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001415 if (bufsz) {
1416 pos += scnprintf(*buf + pos, bufsz - pos,
1417 "EVT_LOGT:%010u:0x%08x:%04u\n",
1418 time, data, ev);
1419 } else {
1420 IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
Reinette Chatreb7a79402009-09-25 14:24:23 -07001421 time, data, ev);
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001422 trace_iwlwifi_dev_ucode_event(priv, time,
1423 data, ev);
1424 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07001425 }
1426 }
Ben Cahille5854472009-11-06 14:52:58 -08001427
1428 /* Allow device to power down */
1429 iwl_release_nic_access(priv);
1430 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001431 return pos;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001432}
1433
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001434/**
1435 * iwl_print_last_event_logs - Dump the newest # of event log to syslog
1436 */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001437static int iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
1438 u32 num_wraps, u32 next_entry,
1439 u32 size, u32 mode,
1440 int pos, char **buf, size_t bufsz)
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001441{
1442 /*
1443 * display the newest DEFAULT_LOG_ENTRIES entries
1444 * i.e the entries just before the next ont that uCode would fill.
1445 */
1446 if (num_wraps) {
1447 if (next_entry < size) {
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001448 pos = iwl_print_event_log(priv,
1449 capacity - (size - next_entry),
1450 size - next_entry, mode,
1451 pos, buf, bufsz);
1452 pos = iwl_print_event_log(priv, 0,
1453 next_entry, mode,
1454 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001455 } else
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001456 pos = iwl_print_event_log(priv, next_entry - size,
1457 size, mode, pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001458 } else {
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001459 if (next_entry < size) {
1460 pos = iwl_print_event_log(priv, 0, next_entry,
1461 mode, pos, buf, bufsz);
1462 } else {
1463 pos = iwl_print_event_log(priv, next_entry - size,
1464 size, mode, pos, buf, bufsz);
1465 }
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001466 }
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001467 return pos;
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001468}
1469
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001470#define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
1471
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001472int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
1473 char **buf, bool display)
Reinette Chatreb7a79402009-09-25 14:24:23 -07001474{
1475 u32 base; /* SRAM byte address of event log header */
1476 u32 capacity; /* event log capacity in # entries */
1477 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
1478 u32 num_wraps; /* # times uCode wrapped to top of log */
1479 u32 next_entry; /* index of next entry to be written by uCode */
1480 u32 size; /* # entries that we'll print */
Johannes Bergb2e640d2010-05-05 23:24:54 -07001481 u32 logsize;
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001482 int pos = 0;
1483 size_t bufsz = 0;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001484
Johannes Bergd7d57832011-04-05 09:42:04 -07001485 base = priv->device_pointers.log_event_table;
Johannes Berg872907b2011-06-06 09:41:15 -07001486 if (priv->ucode_type == IWL_UCODE_INIT) {
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001487 logsize = priv->init_evtlog_size;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001488 if (!base)
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001489 base = priv->init_evtlog_ptr;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001490 } else {
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001491 logsize = priv->inst_evtlog_size;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001492 if (!base)
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001493 base = priv->inst_evtlog_ptr;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001494 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07001495
Fry, Donald H4caab322011-07-07 15:24:07 -07001496 if (!iwlagn_hw_valid_rtc_data_addr(base)) {
Wey-Yi Guy212fb572009-12-02 12:53:00 -08001497 IWL_ERR(priv,
1498 "Invalid event log pointer 0x%08X for %s uCode\n",
Johannes Bergca7966c2011-04-22 10:15:23 -07001499 base,
Johannes Berg872907b2011-06-06 09:41:15 -07001500 (priv->ucode_type == IWL_UCODE_INIT)
Johannes Bergca7966c2011-04-22 10:15:23 -07001501 ? "Init" : "RT");
Wey-Yi Guy937c3972010-01-15 13:43:36 -08001502 return -EINVAL;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001503 }
1504
1505 /* event log header */
1506 capacity = iwl_read_targ_mem(priv, base);
1507 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
1508 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
1509 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
1510
Johannes Bergb2e640d2010-05-05 23:24:54 -07001511 if (capacity > logsize) {
Ben Cahill84c40692009-11-06 14:52:57 -08001512 IWL_ERR(priv, "Log capacity %d is bogus, limit to %d entries\n",
Johannes Bergb2e640d2010-05-05 23:24:54 -07001513 capacity, logsize);
1514 capacity = logsize;
Ben Cahill84c40692009-11-06 14:52:57 -08001515 }
1516
Johannes Bergb2e640d2010-05-05 23:24:54 -07001517 if (next_entry > logsize) {
Ben Cahill84c40692009-11-06 14:52:57 -08001518 IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
Johannes Bergb2e640d2010-05-05 23:24:54 -07001519 next_entry, logsize);
1520 next_entry = logsize;
Ben Cahill84c40692009-11-06 14:52:57 -08001521 }
1522
Reinette Chatreb7a79402009-09-25 14:24:23 -07001523 size = num_wraps ? capacity : next_entry;
1524
1525 /* bail out if nothing in log */
1526 if (size == 0) {
1527 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001528 return pos;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001529 }
1530
Wey-Yi Guy9f28ebc2010-11-26 13:24:19 -08001531 /* enable/disable bt channel inhibition */
Wey-Yi Guyf37837c2010-08-23 07:57:12 -07001532 priv->bt_ch_announce = iwlagn_bt_ch_announce;
1533
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001534#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guy521d9bc2009-12-10 14:37:23 -08001535 if (!(iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) && !full_log)
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001536 size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
1537 ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
1538#else
1539 size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
1540 ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001541#endif
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001542 IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n",
1543 size);
1544
1545#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001546 if (display) {
1547 if (full_log)
1548 bufsz = capacity * 48;
1549 else
1550 bufsz = size * 48;
1551 *buf = kmalloc(bufsz, GFP_KERNEL);
1552 if (!*buf)
Wey-Yi Guy937c3972010-01-15 13:43:36 -08001553 return -ENOMEM;
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001554 }
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001555 if ((iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) || full_log) {
1556 /*
1557 * if uCode has wrapped back to top of log,
1558 * start at the oldest entry,
1559 * i.e the next one that uCode would fill.
1560 */
1561 if (num_wraps)
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001562 pos = iwl_print_event_log(priv, next_entry,
1563 capacity - next_entry, mode,
1564 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001565 /* (then/else) start at top of log */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001566 pos = iwl_print_event_log(priv, 0,
1567 next_entry, mode, pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001568 } else
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001569 pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
1570 next_entry, size, mode,
1571 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001572#else
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001573 pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
1574 next_entry, size, mode,
1575 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001576#endif
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001577 return pos;
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001578}
Reinette Chatreb7a79402009-09-25 14:24:23 -07001579
Wey-Yi Guy0975cc82010-07-31 08:34:07 -07001580static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
1581{
1582 struct iwl_ct_kill_config cmd;
1583 struct iwl_ct_kill_throttling_config adv_cmd;
1584 unsigned long flags;
1585 int ret = 0;
1586
1587 spin_lock_irqsave(&priv->lock, flags);
1588 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
1589 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
1590 spin_unlock_irqrestore(&priv->lock, flags);
1591 priv->thermal_throttle.ct_kill_toggle = false;
1592
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07001593 if (priv->cfg->base_params->support_ct_kill_exit) {
Wey-Yi Guy0975cc82010-07-31 08:34:07 -07001594 adv_cmd.critical_temperature_enter =
1595 cpu_to_le32(priv->hw_params.ct_kill_threshold);
1596 adv_cmd.critical_temperature_exit =
1597 cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
1598
Emmanuel Grumbach41c50542011-07-11 08:51:04 +03001599 ret = trans_send_cmd_pdu(&priv->trans,
Emmanuel Grumbache419d622011-07-08 08:46:14 -07001600 REPLY_CT_KILL_CONFIG_CMD,
1601 CMD_SYNC, sizeof(adv_cmd), &adv_cmd);
Wey-Yi Guy0975cc82010-07-31 08:34:07 -07001602 if (ret)
1603 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
1604 else
1605 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
1606 "succeeded, "
1607 "critical temperature enter is %d,"
1608 "exit is %d\n",
1609 priv->hw_params.ct_kill_threshold,
1610 priv->hw_params.ct_kill_exit_threshold);
1611 } else {
1612 cmd.critical_temperature_R =
1613 cpu_to_le32(priv->hw_params.ct_kill_threshold);
1614
Emmanuel Grumbach41c50542011-07-11 08:51:04 +03001615 ret = trans_send_cmd_pdu(&priv->trans,
Emmanuel Grumbache419d622011-07-08 08:46:14 -07001616 REPLY_CT_KILL_CONFIG_CMD,
1617 CMD_SYNC, sizeof(cmd), &cmd);
Wey-Yi Guy0975cc82010-07-31 08:34:07 -07001618 if (ret)
1619 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
1620 else
1621 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
1622 "succeeded, "
1623 "critical temperature is %d\n",
1624 priv->hw_params.ct_kill_threshold);
1625 }
1626}
1627
Shanyu Zhao6d6a1af2010-09-14 18:13:31 -07001628static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
1629{
1630 struct iwl_calib_cfg_cmd calib_cfg_cmd;
1631 struct iwl_host_cmd cmd = {
1632 .id = CALIBRATION_CFG_CMD,
Johannes Berg3fa50732011-05-04 07:50:38 -07001633 .len = { sizeof(struct iwl_calib_cfg_cmd), },
1634 .data = { &calib_cfg_cmd, },
Shanyu Zhao6d6a1af2010-09-14 18:13:31 -07001635 };
1636
1637 memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
1638 calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL;
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07001639 calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg);
Shanyu Zhao6d6a1af2010-09-14 18:13:31 -07001640
Emmanuel Grumbach41c50542011-07-11 08:51:04 +03001641 return trans_send_cmd(&priv->trans, &cmd);
Shanyu Zhao6d6a1af2010-09-14 18:13:31 -07001642}
1643
1644
Wey-Yi Guye505c432011-07-07 08:27:41 -07001645static int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant)
1646{
1647 struct iwl_tx_ant_config_cmd tx_ant_cmd = {
1648 .valid = cpu_to_le32(valid_tx_ant),
1649 };
1650
1651 if (IWL_UCODE_API(priv->ucode_ver) > 1) {
1652 IWL_DEBUG_HC(priv, "select valid tx ant: %u\n", valid_tx_ant);
Emmanuel Grumbach41c50542011-07-11 08:51:04 +03001653 return trans_send_cmd_pdu(&priv->trans,
Wey-Yi Guye505c432011-07-07 08:27:41 -07001654 TX_ANT_CONFIGURATION_CMD,
1655 CMD_SYNC,
1656 sizeof(struct iwl_tx_ant_config_cmd),
1657 &tx_ant_cmd);
1658 } else {
1659 IWL_DEBUG_HC(priv, "TX_ANT_CONFIGURATION_CMD not supported\n");
1660 return -EOPNOTSUPP;
1661 }
1662}
1663
Zhu Yib481de92007-09-25 17:54:57 -07001664/**
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001665 * iwl_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07001666 * from protocol/runtime uCode (initialization uCode's
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001667 * Alive gets handled by iwl_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07001668 */
Cindy H. Kao4613e722011-05-06 10:40:15 -07001669int iwl_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001670{
Tomas Winkler57aab752008-04-14 21:16:03 -07001671 int ret = 0;
Johannes Berg246ed352010-08-23 10:46:32 +02001672 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Zhu Yib481de92007-09-25 17:54:57 -07001673
Emmanuel Grumbach1a361cd2011-07-11 07:44:57 -07001674 /*TODO: this should go to the transport layer */
Johannes Bergca7966c2011-04-22 10:15:23 -07001675 iwl_reset_ict(priv);
1676
Tomas Winklere1623442009-01-27 14:27:56 -08001677 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001678
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001679 /* After the ALIVE response, we can send host commands to the uCode */
Zhu Yib481de92007-09-25 17:54:57 -07001680 set_bit(STATUS_ALIVE, &priv->status);
1681
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01001682 /* Enable watchdog to monitor the driver tx queues */
1683 iwl_setup_watchdog(priv);
Wey-Yi Guyb74e31a2010-03-01 17:23:50 -08001684
Tomas Winklerfee12472008-04-03 16:05:21 -07001685 if (iwl_is_rfkill(priv))
Johannes Bergca7966c2011-04-22 10:15:23 -07001686 return -ERFKILL;
Zhu Yib481de92007-09-25 17:54:57 -07001687
Wey-Yi Guybc795df2010-10-11 14:24:05 -07001688 /* download priority table before any calibration request */
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07001689 if (priv->cfg->bt_params &&
1690 priv->cfg->bt_params->advanced_bt_coexist) {
Wey-Yi Guyf7322f82010-08-23 15:24:49 -07001691 /* Configure Bluetooth device coexistence support */
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -07001692 if (priv->cfg->bt_params->bt_sco_disable)
1693 priv->bt_enable_pspoll = false;
1694 else
1695 priv->bt_enable_pspoll = true;
1696
Wey-Yi Guyf7322f82010-08-23 15:24:49 -07001697 priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
1698 priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
1699 priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
Wey-Yi Guye55b5172011-06-28 11:46:28 -07001700 iwlagn_send_advance_bt_config(priv);
Wey-Yi Guyf7322f82010-08-23 15:24:49 -07001701 priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS;
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -07001702 priv->cur_rssi_ctx = NULL;
1703
Wey-Yi Guya5901cb2010-09-23 09:56:51 -07001704 iwlagn_send_prio_tbl(priv);
Wey-Yi Guyf7322f82010-08-23 15:24:49 -07001705
1706 /* FIXME: w/a to force change uCode BT state machine */
Johannes Bergca7966c2011-04-22 10:15:23 -07001707 ret = iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
1708 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
1709 if (ret)
1710 return ret;
1711 ret = iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
1712 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
1713 if (ret)
1714 return ret;
Wey-Yi Guye55b5172011-06-28 11:46:28 -07001715 } else {
1716 /*
1717 * default is 2-wire BT coexexistence support
1718 */
1719 iwl_send_bt_config(priv);
Wey-Yi Guyf7322f82010-08-23 15:24:49 -07001720 }
Wey-Yi Guye55b5172011-06-28 11:46:28 -07001721
Wey-Yi Guybc795df2010-10-11 14:24:05 -07001722 if (priv->hw_params.calib_rt_cfg)
1723 iwlagn_send_calib_cfg_rt(priv, priv->hw_params.calib_rt_cfg);
1724
Johannes Berg36d68252008-05-15 12:55:26 +02001725 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07001726
Johannes Berg470ab2d2010-01-21 11:23:30 -08001727 priv->active_rate = IWL_RATES_MASK;
Zhu Yib481de92007-09-25 17:54:57 -07001728
Wey-Yi Guy2f748de2009-09-17 10:43:51 -07001729 /* Configure Tx antenna selection based on H/W config */
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -07001730 iwlagn_send_tx_ant_config(priv, priv->cfg->valid_tx_ant);
Wey-Yi Guy2f748de2009-09-17 10:43:51 -07001731
Johannes Bergc8ac61c2011-07-15 13:23:45 -07001732 if (iwl_is_associated_ctx(ctx) && !priv->wowlan) {
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001733 struct iwl_rxon_cmd *active_rxon =
Johannes Berg246ed352010-08-23 10:46:32 +02001734 (struct iwl_rxon_cmd *)&ctx->active;
Mohamed Abbas019fb972009-03-17 21:59:18 -07001735 /* apply any changes in staging */
Johannes Berg246ed352010-08-23 10:46:32 +02001736 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001737 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1738 } else {
Johannes Bergd0fe4782010-08-23 10:46:58 +02001739 struct iwl_rxon_context *tmp;
Zhu Yib481de92007-09-25 17:54:57 -07001740 /* Initialize our rx_config data */
Johannes Bergd0fe4782010-08-23 10:46:58 +02001741 for_each_context(priv, tmp)
1742 iwl_connection_init_rx_config(priv, tmp);
Abhijeet Kolekar45823532009-04-08 11:26:44 -07001743
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -07001744 iwlagn_set_rxon_chain(priv, ctx);
Zhu Yib481de92007-09-25 17:54:57 -07001745 }
1746
Johannes Bergc8ac61c2011-07-15 13:23:45 -07001747 if (!priv->wowlan) {
1748 /* WoWLAN ucode will not reply in the same way, skip it */
1749 iwl_reset_run_time_calib(priv);
1750 }
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001751
Wey-Yi Guy9e2e7422010-11-12 13:52:37 -08001752 set_bit(STATUS_READY, &priv->status);
1753
Zhu Yib481de92007-09-25 17:54:57 -07001754 /* Configure the adapter for unassociated operation */
Wey-Yi Guy805a3b82011-06-03 07:54:16 -07001755 ret = iwlagn_commit_rxon(priv, ctx);
Johannes Bergca7966c2011-04-22 10:15:23 -07001756 if (ret)
1757 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07001758
1759 /* At this point, the NIC is initialized and operational */
Emmanuel Grumbach47f4a582008-06-12 09:47:13 +08001760 iwl_rf_kill_ct_config(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08001761
Tomas Winklere1623442009-01-27 14:27:56 -08001762 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001763
Johannes Bergca7966c2011-04-22 10:15:23 -07001764 return iwl_power_update_mode(priv, true);
Zhu Yib481de92007-09-25 17:54:57 -07001765}
1766
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001767static void iwl_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07001768
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001769static void __iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001770{
Dan Carpenter22dd2fd2011-03-15 10:03:24 +03001771 int exit_pending;
Zhu Yib481de92007-09-25 17:54:57 -07001772
Tomas Winklere1623442009-01-27 14:27:56 -08001773 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07001774
Stanislaw Gruszkad745d472010-09-13 14:46:35 +02001775 iwl_scan_cancel_timeout(priv, 200);
1776
1777 exit_pending = test_and_set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07001778
Stanislaw Gruszkab62177a2010-08-20 15:23:47 +02001779 /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
1780 * to prevent rearm timer */
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01001781 del_timer_sync(&priv->watchdog);
Stanislaw Gruszkab62177a2010-08-20 15:23:47 +02001782
Johannes Bergdcef7322010-08-27 08:55:52 -07001783 iwl_clear_ucode_stations(priv, NULL);
Johannes Berga194e322010-08-27 08:53:46 -07001784 iwl_dealloc_bcast_stations(priv);
Johannes Bergdb125c72010-05-07 01:49:15 -07001785 iwl_clear_driver_stations(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001786
Johannes Berga1174132010-08-23 07:56:59 -07001787 /* reset BT coex data */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07001788 priv->bt_status = 0;
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -07001789 priv->cur_rssi_ctx = NULL;
1790 priv->bt_is_sco = 0;
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07001791 if (priv->cfg->bt_params)
1792 priv->bt_traffic_load =
1793 priv->cfg->bt_params->bt_init_traffic_load;
1794 else
1795 priv->bt_traffic_load = 0;
Wey-Yi Guybee008b2010-08-23 07:57:04 -07001796 priv->bt_full_concurrent = false;
1797 priv->bt_ci_compliance = 0;
Johannes Berga1174132010-08-23 07:56:59 -07001798
Zhu Yib481de92007-09-25 17:54:57 -07001799 /* Wipe out the EXIT_PENDING status bit if we are not actually
1800 * exiting the module */
1801 if (!exit_pending)
1802 clear_bit(STATUS_EXIT_PENDING, &priv->status);
1803
Zhu Yib481de92007-09-25 17:54:57 -07001804 if (priv->mac80211_registered)
1805 ieee80211_stop_queues(priv->hw);
1806
Johannes Berg1a10f432011-04-13 03:14:44 -07001807 /* Clear out all status bits but a few that are stable across reset */
Zhu Yib481de92007-09-25 17:54:57 -07001808 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
1809 STATUS_RF_KILL_HW |
Reinette Chatre97888642008-02-06 11:20:38 -08001810 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
1811 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07001812 test_bit(STATUS_FW_ERROR, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08001813 STATUS_FW_ERROR |
1814 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
1815 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07001816
Emmanuel Grumbach41c50542011-07-11 08:51:04 +03001817 trans_stop_device(&priv->trans);
Ben Cahill4d2ccdb2009-10-09 13:20:20 -07001818
Johannes Berg77834542010-10-04 05:50:36 -07001819 dev_kfree_skb(priv->beacon_skb);
Johannes Berg12e934d2010-10-04 05:50:06 -07001820 priv->beacon_skb = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001821}
1822
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001823static void iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001824{
1825 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001826 __iwl_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001827 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08001828
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001829 iwl_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001830}
1831
1832#define MAX_HW_RESTARTS 5
1833
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001834static int __iwl_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001835{
Johannes Berga194e322010-08-27 08:53:46 -07001836 struct iwl_rxon_context *ctx;
Tomas Winkler57aab752008-04-14 21:16:03 -07001837 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07001838
Johannes Bergca7966c2011-04-22 10:15:23 -07001839 lockdep_assert_held(&priv->mutex);
1840
Zhu Yib481de92007-09-25 17:54:57 -07001841 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001842 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07001843 return -EIO;
1844 }
1845
Johannes Berga194e322010-08-27 08:53:46 -07001846 for_each_context(priv, ctx) {
Johannes Berga30e3112010-09-22 18:02:01 +02001847 ret = iwlagn_alloc_bcast_station(priv, ctx);
Johannes Berga194e322010-08-27 08:53:46 -07001848 if (ret) {
1849 iwl_dealloc_bcast_stations(priv);
1850 return ret;
1851 }
1852 }
Johannes Berg2c810cc2010-04-29 00:53:29 -07001853
Johannes Bergca7966c2011-04-22 10:15:23 -07001854 ret = iwlagn_run_init_ucode(priv);
1855 if (ret) {
1856 IWL_ERR(priv, "Failed to run INIT ucode: %d\n", ret);
1857 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07001858 }
1859
Johannes Bergca7966c2011-04-22 10:15:23 -07001860 ret = iwlagn_load_ucode_wait_alive(priv,
Johannes Bergdbf28e212011-04-16 08:29:24 -07001861 &priv->ucode_rt,
Johannes Berg872907b2011-06-06 09:41:15 -07001862 IWL_UCODE_REGULAR);
Johannes Bergca7966c2011-04-22 10:15:23 -07001863 if (ret) {
1864 IWL_ERR(priv, "Failed to start RT ucode: %d\n", ret);
1865 goto error;
1866 }
1867
1868 ret = iwl_alive_start(priv);
1869 if (ret)
1870 goto error;
1871 return 0;
1872
1873 error:
Zhu Yib481de92007-09-25 17:54:57 -07001874 set_bit(STATUS_EXIT_PENDING, &priv->status);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001875 __iwl_down(priv);
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08001876 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07001877
Johannes Bergca7966c2011-04-22 10:15:23 -07001878 IWL_ERR(priv, "Unable to initialize device.\n");
1879 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07001880}
1881
1882
1883/*****************************************************************************
1884 *
1885 * Workqueue callbacks
1886 *
1887 *****************************************************************************/
1888
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08001889static void iwl_bg_run_time_calib_work(struct work_struct *work)
1890{
1891 struct iwl_priv *priv = container_of(work, struct iwl_priv,
1892 run_time_calib_work);
1893
1894 mutex_lock(&priv->mutex);
1895
1896 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
1897 test_bit(STATUS_SCANNING, &priv->status)) {
1898 mutex_unlock(&priv->mutex);
1899 return;
1900 }
1901
1902 if (priv->start_calib) {
Johannes Berg0da0e5b2011-04-08 08:14:56 -07001903 iwl_chain_noise_calibration(priv);
1904 iwl_sensitivity_calibration(priv);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08001905 }
1906
1907 mutex_unlock(&priv->mutex);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08001908}
1909
Johannes Berge43e85c2011-04-19 07:45:16 -07001910static void iwlagn_prepare_restart(struct iwl_priv *priv)
1911{
1912 struct iwl_rxon_context *ctx;
1913 bool bt_full_concurrent;
1914 u8 bt_ci_compliance;
1915 u8 bt_load;
1916 u8 bt_status;
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -07001917 bool bt_is_sco;
Johannes Berge43e85c2011-04-19 07:45:16 -07001918
1919 lockdep_assert_held(&priv->mutex);
1920
1921 for_each_context(priv, ctx)
1922 ctx->vif = NULL;
1923 priv->is_open = 0;
1924
1925 /*
1926 * __iwl_down() will clear the BT status variables,
1927 * which is correct, but when we restart we really
1928 * want to keep them so restore them afterwards.
1929 *
1930 * The restart process will later pick them up and
1931 * re-configure the hw when we reconfigure the BT
1932 * command.
1933 */
1934 bt_full_concurrent = priv->bt_full_concurrent;
1935 bt_ci_compliance = priv->bt_ci_compliance;
1936 bt_load = priv->bt_traffic_load;
1937 bt_status = priv->bt_status;
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -07001938 bt_is_sco = priv->bt_is_sco;
Johannes Berge43e85c2011-04-19 07:45:16 -07001939
1940 __iwl_down(priv);
1941
1942 priv->bt_full_concurrent = bt_full_concurrent;
1943 priv->bt_ci_compliance = bt_ci_compliance;
1944 priv->bt_traffic_load = bt_load;
1945 priv->bt_status = bt_status;
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -07001946 priv->bt_is_sco = bt_is_sco;
Johannes Berge43e85c2011-04-19 07:45:16 -07001947}
1948
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001949static void iwl_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07001950{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001951 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07001952
1953 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1954 return;
1955
Johannes Berg19cc1082009-05-08 13:44:36 -07001956 if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
1957 mutex_lock(&priv->mutex);
Johannes Berge43e85c2011-04-19 07:45:16 -07001958 iwlagn_prepare_restart(priv);
Johannes Berg19cc1082009-05-08 13:44:36 -07001959 mutex_unlock(&priv->mutex);
Johannes Berga1174132010-08-23 07:56:59 -07001960 iwl_cancel_deferred_work(priv);
Johannes Berg19cc1082009-05-08 13:44:36 -07001961 ieee80211_restart_hw(priv->hw);
1962 } else {
Johannes Bergca7966c2011-04-22 10:15:23 -07001963 WARN_ON(1);
Johannes Berg19cc1082009-05-08 13:44:36 -07001964 }
Zhu Yib481de92007-09-25 17:54:57 -07001965}
1966
Johannes Berg266af4c72011-03-10 20:13:26 -08001967static int iwl_mac_offchannel_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
1968 struct ieee80211_channel *chan,
1969 enum nl80211_channel_type channel_type,
1970 unsigned int wait)
1971{
1972 struct iwl_priv *priv = hw->priv;
1973 int ret;
1974
1975 /* Not supported if we don't have PAN */
1976 if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN))) {
1977 ret = -EOPNOTSUPP;
1978 goto free;
1979 }
1980
1981 /* Not supported on pre-P2P firmware */
1982 if (!(priv->contexts[IWL_RXON_CTX_PAN].interface_modes &
1983 BIT(NL80211_IFTYPE_P2P_CLIENT))) {
1984 ret = -EOPNOTSUPP;
1985 goto free;
1986 }
1987
1988 mutex_lock(&priv->mutex);
1989
1990 if (!priv->contexts[IWL_RXON_CTX_PAN].is_active) {
1991 /*
1992 * If the PAN context is free, use the normal
1993 * way of doing remain-on-channel offload + TX.
1994 */
1995 ret = 1;
1996 goto out;
1997 }
1998
1999 /* TODO: queue up if scanning? */
2000 if (test_bit(STATUS_SCANNING, &priv->status) ||
Wey-Yi Guy898ed672011-07-13 08:38:57 -07002001 priv->offchan_tx_skb) {
Johannes Berg266af4c72011-03-10 20:13:26 -08002002 ret = -EBUSY;
2003 goto out;
2004 }
2005
2006 /*
2007 * max_scan_ie_len doesn't include the blank SSID or the header,
2008 * so need to add that again here.
2009 */
2010 if (skb->len > hw->wiphy->max_scan_ie_len + 24 + 2) {
2011 ret = -ENOBUFS;
2012 goto out;
2013 }
2014
Wey-Yi Guy898ed672011-07-13 08:38:57 -07002015 priv->offchan_tx_skb = skb;
2016 priv->offchan_tx_timeout = wait;
2017 priv->offchan_tx_chan = chan;
Johannes Berg266af4c72011-03-10 20:13:26 -08002018
2019 ret = iwl_scan_initiate(priv, priv->contexts[IWL_RXON_CTX_PAN].vif,
2020 IWL_SCAN_OFFCH_TX, chan->band);
2021 if (ret)
Wey-Yi Guy898ed672011-07-13 08:38:57 -07002022 priv->offchan_tx_skb = NULL;
Johannes Berg266af4c72011-03-10 20:13:26 -08002023 out:
2024 mutex_unlock(&priv->mutex);
2025 free:
2026 if (ret < 0)
2027 kfree_skb(skb);
2028
2029 return ret;
2030}
2031
2032static int iwl_mac_offchannel_tx_cancel_wait(struct ieee80211_hw *hw)
2033{
2034 struct iwl_priv *priv = hw->priv;
2035 int ret;
2036
2037 mutex_lock(&priv->mutex);
2038
Wey-Yi Guy898ed672011-07-13 08:38:57 -07002039 if (!priv->offchan_tx_skb) {
Dan Carpenterf8a22a22011-03-15 10:01:58 +03002040 ret = -EINVAL;
2041 goto unlock;
2042 }
Johannes Berg266af4c72011-03-10 20:13:26 -08002043
Wey-Yi Guy898ed672011-07-13 08:38:57 -07002044 priv->offchan_tx_skb = NULL;
Johannes Berg266af4c72011-03-10 20:13:26 -08002045
2046 ret = iwl_scan_cancel_timeout(priv, 200);
2047 if (ret)
2048 ret = -EIO;
Dan Carpenterf8a22a22011-03-15 10:01:58 +03002049unlock:
Johannes Berg266af4c72011-03-10 20:13:26 -08002050 mutex_unlock(&priv->mutex);
2051
2052 return ret;
2053}
2054
Zhu Yib481de92007-09-25 17:54:57 -07002055/*****************************************************************************
2056 *
2057 * mac80211 entry point functions
2058 *
2059 *****************************************************************************/
2060
Johannes Berg0fd09502011-05-27 08:40:30 -07002061static const struct ieee80211_iface_limit iwlagn_sta_ap_limits[] = {
2062 {
2063 .max = 1,
2064 .types = BIT(NL80211_IFTYPE_STATION),
2065 },
2066 {
2067 .max = 1,
2068 .types = BIT(NL80211_IFTYPE_AP),
2069 },
2070};
2071
2072static const struct ieee80211_iface_limit iwlagn_2sta_limits[] = {
2073 {
2074 .max = 2,
2075 .types = BIT(NL80211_IFTYPE_STATION),
2076 },
2077};
2078
2079static const struct ieee80211_iface_limit iwlagn_p2p_sta_go_limits[] = {
2080 {
2081 .max = 1,
2082 .types = BIT(NL80211_IFTYPE_STATION),
2083 },
2084 {
2085 .max = 1,
2086 .types = BIT(NL80211_IFTYPE_P2P_GO) |
2087 BIT(NL80211_IFTYPE_AP),
2088 },
2089};
2090
2091static const struct ieee80211_iface_limit iwlagn_p2p_2sta_limits[] = {
2092 {
2093 .max = 2,
2094 .types = BIT(NL80211_IFTYPE_STATION),
2095 },
2096 {
2097 .max = 1,
2098 .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
2099 },
2100};
2101
2102static const struct ieee80211_iface_combination
2103iwlagn_iface_combinations_dualmode[] = {
2104 { .num_different_channels = 1,
2105 .max_interfaces = 2,
2106 .beacon_int_infra_match = true,
2107 .limits = iwlagn_sta_ap_limits,
2108 .n_limits = ARRAY_SIZE(iwlagn_sta_ap_limits),
2109 },
2110 { .num_different_channels = 1,
2111 .max_interfaces = 2,
2112 .limits = iwlagn_2sta_limits,
2113 .n_limits = ARRAY_SIZE(iwlagn_2sta_limits),
2114 },
2115};
2116
2117static const struct ieee80211_iface_combination
2118iwlagn_iface_combinations_p2p[] = {
2119 { .num_different_channels = 1,
2120 .max_interfaces = 2,
2121 .beacon_int_infra_match = true,
2122 .limits = iwlagn_p2p_sta_go_limits,
2123 .n_limits = ARRAY_SIZE(iwlagn_p2p_sta_go_limits),
2124 },
2125 { .num_different_channels = 1,
2126 .max_interfaces = 2,
2127 .limits = iwlagn_p2p_2sta_limits,
2128 .n_limits = ARRAY_SIZE(iwlagn_p2p_2sta_limits),
2129 },
2130};
2131
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002132/*
2133 * Not a mac80211 entry point function, but it fits in with all the
2134 * other mac80211 functions grouped here.
2135 */
Johannes Bergdd7a2502010-04-28 23:33:10 -07002136static int iwl_mac_setup_register(struct iwl_priv *priv,
2137 struct iwlagn_ucode_capabilities *capa)
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002138{
2139 int ret;
2140 struct ieee80211_hw *hw = priv->hw;
Johannes Bergd0fe4782010-08-23 10:46:58 +02002141 struct iwl_rxon_context *ctx;
2142
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002143 hw->rate_control_algorithm = "iwl-agn-rs";
2144
2145 /* Tell mac80211 our characteristics */
2146 hw->flags = IEEE80211_HW_SIGNAL_DBM |
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002147 IEEE80211_HW_AMPDU_AGGREGATION |
Johannes Berg2491fa42010-08-23 10:46:52 +02002148 IEEE80211_HW_NEED_DTIM_PERIOD |
Johannes Berg6fb55112010-11-16 11:55:02 -08002149 IEEE80211_HW_SPECTRUM_MGMT |
2150 IEEE80211_HW_REPORTS_TX_ACK_STATUS;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002151
Johannes Berg9b768832011-01-19 02:54:18 -08002152 hw->max_tx_aggregation_subframes = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
2153
Wey-Yi Guy23c0fcc2011-04-01 16:29:53 -07002154 hw->flags |= IEEE80211_HW_SUPPORTS_PS |
2155 IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002156
Wey-Yi Guy88950752011-06-06 12:05:46 -07002157 if (priv->cfg->sku & EEPROM_SKU_CAP_11N_ENABLE)
Johannes Bergba37a3d2009-12-10 14:37:27 -08002158 hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
2159 IEEE80211_HW_SUPPORTS_STATIC_SMPS;
2160
Johannes Berg3997ff32011-04-05 09:42:02 -07002161 if (capa->flags & IWL_UCODE_TLV_FLAGS_MFP)
2162 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
2163
Reinette Chatre8d9698b2009-10-16 14:25:55 -07002164 hw->sta_data_size = sizeof(struct iwl_station_priv);
Johannes Bergfd1af152010-04-30 11:30:43 -07002165 hw->vif_data_size = sizeof(struct iwl_vif_priv);
2166
Johannes Bergd0fe4782010-08-23 10:46:58 +02002167 for_each_context(priv, ctx) {
2168 hw->wiphy->interface_modes |= ctx->interface_modes;
2169 hw->wiphy->interface_modes |= ctx->exclusive_interface_modes;
2170 }
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002171
Johannes Berg0fd09502011-05-27 08:40:30 -07002172 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
2173
Johannes Bergf35490f2011-06-02 19:38:43 +02002174 if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)) {
Johannes Berg0fd09502011-05-27 08:40:30 -07002175 hw->wiphy->iface_combinations = iwlagn_iface_combinations_p2p;
2176 hw->wiphy->n_iface_combinations =
2177 ARRAY_SIZE(iwlagn_iface_combinations_p2p);
Johannes Bergf35490f2011-06-02 19:38:43 +02002178 } else if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) {
Johannes Berg0fd09502011-05-27 08:40:30 -07002179 hw->wiphy->iface_combinations = iwlagn_iface_combinations_dualmode;
2180 hw->wiphy->n_iface_combinations =
2181 ARRAY_SIZE(iwlagn_iface_combinations_dualmode);
2182 }
2183
Johannes Berg9b9190d2011-01-06 08:07:10 -08002184 hw->wiphy->max_remain_on_channel_duration = 1000;
2185
Reinette Chatref6c8f152010-03-12 11:13:26 -08002186 hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
Johannes Berg274102a2011-01-18 04:44:03 -08002187 WIPHY_FLAG_DISABLE_BEACON_HINTS |
2188 WIPHY_FLAG_IBSS_RSN;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002189
Johannes Bergc8ac61c2011-07-15 13:23:45 -07002190 if (priv->ucode_wowlan.code.len && device_can_wakeup(priv->bus->dev)) {
2191 hw->wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
2192 WIPHY_WOWLAN_DISCONNECT |
2193 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
2194 WIPHY_WOWLAN_RFKILL_RELEASE;
2195 if (!iwlagn_mod_params.sw_crypto)
2196 hw->wiphy->wowlan.flags |=
2197 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
2198 WIPHY_WOWLAN_GTK_REKEY_FAILURE;
2199
2200 hw->wiphy->wowlan.n_patterns = IWLAGN_WOWLAN_MAX_PATTERNS;
2201 hw->wiphy->wowlan.pattern_min_len =
2202 IWLAGN_WOWLAN_MIN_PATTERN_LEN;
2203 hw->wiphy->wowlan.pattern_max_len =
2204 IWLAGN_WOWLAN_MAX_PATTERN_LEN;
2205 }
2206
Wey-Yi Guy0172b022011-06-11 10:00:05 -07002207 if (iwlagn_mod_params.power_save)
2208 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
2209 else
2210 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002211
Reinette Chatre1382c712010-02-25 10:02:19 -08002212 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002213 /* we create the 802.11 header and a zero-length SSID element */
Johannes Bergdd7a2502010-04-28 23:33:10 -07002214 hw->wiphy->max_scan_ie_len = capa->max_probe_length - 24 - 2;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002215
2216 /* Default value; 4 EDCA QOS priorities */
2217 hw->queues = 4;
2218
2219 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
2220
2221 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
2222 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
2223 &priv->bands[IEEE80211_BAND_2GHZ];
2224 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
2225 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
2226 &priv->bands[IEEE80211_BAND_5GHZ];
2227
Wey-Yi Guy5ed540a2011-01-21 15:26:39 -08002228 iwl_leds_init(priv);
2229
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002230 ret = ieee80211_register_hw(priv->hw);
2231 if (ret) {
2232 IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
2233 return ret;
2234 }
2235 priv->mac80211_registered = 1;
2236
2237 return 0;
2238}
2239
2240
Johannes Berg2dedbf52011-04-05 09:41:50 -07002241static int iwlagn_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002242{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002243 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002244 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002245
Tomas Winklere1623442009-01-27 14:27:56 -08002246 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002247
2248 /* we should be verifying the device is ready to be opened */
2249 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002250 ret = __iwl_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002251 mutex_unlock(&priv->mutex);
Zhu Yie655b9f2008-01-24 02:19:38 -08002252 if (ret)
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002253 return ret;
Zhu Yie655b9f2008-01-24 02:19:38 -08002254
Tomas Winklere1623442009-01-27 14:27:56 -08002255 IWL_DEBUG_INFO(priv, "Start UP work done.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08002256
Johannes Bergca7966c2011-04-22 10:15:23 -07002257 /* Now we should be done, and the READY bit should be set. */
2258 if (WARN_ON(!test_bit(STATUS_READY, &priv->status)))
2259 ret = -EIO;
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002260
Wey-Yi Guy5ed540a2011-01-21 15:26:39 -08002261 iwlagn_led_enable(priv);
Johannes Berge932a602009-10-02 13:44:03 -07002262
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002263 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08002264 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002265 return 0;
2266}
2267
Johannes Berg2dedbf52011-04-05 09:41:50 -07002268static void iwlagn_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002269{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002270 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002271
Tomas Winklere1623442009-01-27 14:27:56 -08002272 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas948c1712007-10-25 17:15:45 +08002273
Johannes Berg19cc1082009-05-08 13:44:36 -07002274 if (!priv->is_open)
Zhu Yie655b9f2008-01-24 02:19:38 -08002275 return;
Zhu Yie655b9f2008-01-24 02:19:38 -08002276
Zhu Yib481de92007-09-25 17:54:57 -07002277 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002278
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002279 iwl_down(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002280
2281 flush_workqueue(priv->workqueue);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002282
Stanislaw Gruszka554d1d02010-12-23 12:38:21 +01002283 /* User space software may expect getting rfkill changes
2284 * even if interface is down */
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002285 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Stanislaw Gruszka554d1d02010-12-23 12:38:21 +01002286 iwl_enable_rfkill_int(priv);
Mohamed Abbas948c1712007-10-25 17:15:45 +08002287
Tomas Winklere1623442009-01-27 14:27:56 -08002288 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002289}
2290
David S. Miller26293132011-07-24 13:09:32 -07002291#ifdef CONFIG_PM
Johannes Bergc8ac61c2011-07-15 13:23:45 -07002292static int iwlagn_send_patterns(struct iwl_priv *priv,
2293 struct cfg80211_wowlan *wowlan)
2294{
2295 struct iwlagn_wowlan_patterns_cmd *pattern_cmd;
2296 struct iwl_host_cmd cmd = {
2297 .id = REPLY_WOWLAN_PATTERNS,
2298 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
2299 .flags = CMD_SYNC,
2300 };
2301 int i, err;
2302
2303 if (!wowlan->n_patterns)
2304 return 0;
2305
2306 cmd.len[0] = sizeof(*pattern_cmd) +
2307 wowlan->n_patterns * sizeof(struct iwlagn_wowlan_pattern);
2308
2309 pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL);
2310 if (!pattern_cmd)
2311 return -ENOMEM;
2312
2313 pattern_cmd->n_patterns = cpu_to_le32(wowlan->n_patterns);
2314
2315 for (i = 0; i < wowlan->n_patterns; i++) {
2316 int mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8);
2317
2318 memcpy(&pattern_cmd->patterns[i].mask,
2319 wowlan->patterns[i].mask, mask_len);
2320 memcpy(&pattern_cmd->patterns[i].pattern,
2321 wowlan->patterns[i].pattern,
2322 wowlan->patterns[i].pattern_len);
2323 pattern_cmd->patterns[i].mask_size = mask_len;
2324 pattern_cmd->patterns[i].pattern_size =
2325 wowlan->patterns[i].pattern_len;
2326 }
2327
2328 cmd.data[0] = pattern_cmd;
2329 err = trans_send_cmd(&priv->trans, &cmd);
2330 kfree(pattern_cmd);
2331 return err;
2332}
David S. Miller26293132011-07-24 13:09:32 -07002333#endif
Johannes Bergc8ac61c2011-07-15 13:23:45 -07002334
2335static void iwlagn_mac_set_rekey_data(struct ieee80211_hw *hw,
2336 struct ieee80211_vif *vif,
2337 struct cfg80211_gtk_rekey_data *data)
2338{
2339 struct iwl_priv *priv = hw->priv;
2340
2341 if (iwlagn_mod_params.sw_crypto)
2342 return;
2343
2344 mutex_lock(&priv->mutex);
2345
2346 if (priv->contexts[IWL_RXON_CTX_BSS].vif != vif)
2347 goto out;
2348
2349 memcpy(priv->kek, data->kek, NL80211_KEK_LEN);
2350 memcpy(priv->kck, data->kck, NL80211_KCK_LEN);
2351 priv->replay_ctr = cpu_to_le64(be64_to_cpup((__be64 *)&data->replay_ctr));
2352 priv->have_rekey_data = true;
2353
2354 out:
2355 mutex_unlock(&priv->mutex);
2356}
2357
2358struct wowlan_key_data {
2359 struct iwl_rxon_context *ctx;
2360 struct iwlagn_wowlan_rsc_tsc_params_cmd *rsc_tsc;
2361 struct iwlagn_wowlan_tkip_params_cmd *tkip;
2362 const u8 *bssid;
2363 bool error, use_rsc_tsc, use_tkip;
2364};
2365
David S. Miller26293132011-07-24 13:09:32 -07002366#ifdef CONFIG_PM
Johannes Bergc8ac61c2011-07-15 13:23:45 -07002367static void iwlagn_convert_p1k(u16 *p1k, __le16 *out)
2368{
2369 int i;
2370
2371 for (i = 0; i < IWLAGN_P1K_SIZE; i++)
2372 out[i] = cpu_to_le16(p1k[i]);
2373}
2374
2375static void iwlagn_wowlan_program_keys(struct ieee80211_hw *hw,
2376 struct ieee80211_vif *vif,
2377 struct ieee80211_sta *sta,
2378 struct ieee80211_key_conf *key,
2379 void *_data)
2380{
2381 struct iwl_priv *priv = hw->priv;
2382 struct wowlan_key_data *data = _data;
2383 struct iwl_rxon_context *ctx = data->ctx;
2384 struct aes_sc *aes_sc, *aes_tx_sc = NULL;
2385 struct tkip_sc *tkip_sc, *tkip_tx_sc = NULL;
2386 struct iwlagn_p1k_cache *rx_p1ks;
2387 u8 *rx_mic_key;
2388 struct ieee80211_key_seq seq;
2389 u32 cur_rx_iv32 = 0;
2390 u16 p1k[IWLAGN_P1K_SIZE];
2391 int ret, i;
2392
2393 mutex_lock(&priv->mutex);
2394
2395 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2396 key->cipher == WLAN_CIPHER_SUITE_WEP104) &&
2397 !sta && !ctx->key_mapping_keys)
2398 ret = iwl_set_default_wep_key(priv, ctx, key);
2399 else
2400 ret = iwl_set_dynamic_key(priv, ctx, key, sta);
2401
2402 if (ret) {
2403 IWL_ERR(priv, "Error setting key during suspend!\n");
2404 data->error = true;
2405 }
2406
2407 switch (key->cipher) {
2408 case WLAN_CIPHER_SUITE_TKIP:
2409 if (sta) {
2410 tkip_sc = data->rsc_tsc->all_tsc_rsc.tkip.unicast_rsc;
2411 tkip_tx_sc = &data->rsc_tsc->all_tsc_rsc.tkip.tsc;
2412
2413 rx_p1ks = data->tkip->rx_uni;
2414
2415 ieee80211_get_key_tx_seq(key, &seq);
2416 tkip_tx_sc->iv16 = cpu_to_le16(seq.tkip.iv16);
2417 tkip_tx_sc->iv32 = cpu_to_le32(seq.tkip.iv32);
2418
2419 ieee80211_get_tkip_p1k_iv(key, seq.tkip.iv32, p1k);
2420 iwlagn_convert_p1k(p1k, data->tkip->tx.p1k);
2421
2422 memcpy(data->tkip->mic_keys.tx,
2423 &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY],
2424 IWLAGN_MIC_KEY_SIZE);
2425
2426 rx_mic_key = data->tkip->mic_keys.rx_unicast;
2427 } else {
2428 tkip_sc = data->rsc_tsc->all_tsc_rsc.tkip.multicast_rsc;
2429 rx_p1ks = data->tkip->rx_multi;
2430 rx_mic_key = data->tkip->mic_keys.rx_mcast;
2431 }
2432
2433 /*
2434 * For non-QoS this relies on the fact that both the uCode and
2435 * mac80211 use TID 0 (as they need to to avoid replay attacks)
2436 * for checking the IV in the frames.
2437 */
2438 for (i = 0; i < IWLAGN_NUM_RSC; i++) {
2439 ieee80211_get_key_rx_seq(key, i, &seq);
2440 tkip_sc[i].iv16 = cpu_to_le16(seq.tkip.iv16);
2441 tkip_sc[i].iv32 = cpu_to_le32(seq.tkip.iv32);
2442 /* wrapping isn't allowed, AP must rekey */
2443 if (seq.tkip.iv32 > cur_rx_iv32)
2444 cur_rx_iv32 = seq.tkip.iv32;
2445 }
2446
2447 ieee80211_get_tkip_rx_p1k(key, data->bssid, cur_rx_iv32, p1k);
2448 iwlagn_convert_p1k(p1k, rx_p1ks[0].p1k);
2449 ieee80211_get_tkip_rx_p1k(key, data->bssid,
2450 cur_rx_iv32 + 1, p1k);
2451 iwlagn_convert_p1k(p1k, rx_p1ks[1].p1k);
2452
2453 memcpy(rx_mic_key,
2454 &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY],
2455 IWLAGN_MIC_KEY_SIZE);
2456
2457 data->use_tkip = true;
2458 data->use_rsc_tsc = true;
2459 break;
2460 case WLAN_CIPHER_SUITE_CCMP:
2461 if (sta) {
2462 u8 *pn = seq.ccmp.pn;
2463
2464 aes_sc = data->rsc_tsc->all_tsc_rsc.aes.unicast_rsc;
2465 aes_tx_sc = &data->rsc_tsc->all_tsc_rsc.aes.tsc;
2466
2467 ieee80211_get_key_tx_seq(key, &seq);
2468 aes_tx_sc->pn = cpu_to_le64(
2469 (u64)pn[5] |
2470 ((u64)pn[4] << 8) |
2471 ((u64)pn[3] << 16) |
2472 ((u64)pn[2] << 24) |
2473 ((u64)pn[1] << 32) |
2474 ((u64)pn[0] << 40));
2475 } else
2476 aes_sc = data->rsc_tsc->all_tsc_rsc.aes.multicast_rsc;
2477
2478 /*
2479 * For non-QoS this relies on the fact that both the uCode and
2480 * mac80211 use TID 0 for checking the IV in the frames.
2481 */
2482 for (i = 0; i < IWLAGN_NUM_RSC; i++) {
2483 u8 *pn = seq.ccmp.pn;
2484
2485 ieee80211_get_key_rx_seq(key, i, &seq);
2486 aes_sc->pn = cpu_to_le64(
2487 (u64)pn[5] |
2488 ((u64)pn[4] << 8) |
2489 ((u64)pn[3] << 16) |
2490 ((u64)pn[2] << 24) |
2491 ((u64)pn[1] << 32) |
2492 ((u64)pn[0] << 40));
2493 }
2494 data->use_rsc_tsc = true;
2495 break;
2496 }
2497
2498 mutex_unlock(&priv->mutex);
2499}
2500
2501static int iwlagn_mac_suspend(struct ieee80211_hw *hw,
2502 struct cfg80211_wowlan *wowlan)
2503{
2504 struct iwl_priv *priv = hw->priv;
2505 struct iwlagn_wowlan_wakeup_filter_cmd wakeup_filter_cmd;
2506 struct iwl_rxon_cmd rxon;
2507 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
2508 struct iwlagn_wowlan_kek_kck_material_cmd kek_kck_cmd;
2509 struct iwlagn_wowlan_tkip_params_cmd tkip_cmd = {};
2510 struct wowlan_key_data key_data = {
2511 .ctx = ctx,
2512 .bssid = ctx->active.bssid_addr,
2513 .use_rsc_tsc = false,
2514 .tkip = &tkip_cmd,
2515 .use_tkip = false,
2516 };
2517 int ret, i;
2518 u16 seq;
2519
2520 if (WARN_ON(!wowlan))
2521 return -EINVAL;
2522
2523 mutex_lock(&priv->mutex);
2524
2525 /* Don't attempt WoWLAN when not associated, tear down instead. */
2526 if (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION ||
2527 !iwl_is_associated_ctx(ctx)) {
2528 ret = 1;
2529 goto out;
2530 }
2531
2532 key_data.rsc_tsc = kzalloc(sizeof(*key_data.rsc_tsc), GFP_KERNEL);
2533 if (!key_data.rsc_tsc) {
2534 ret = -ENOMEM;
2535 goto out;
2536 }
2537
2538 memset(&wakeup_filter_cmd, 0, sizeof(wakeup_filter_cmd));
2539
2540 /*
2541 * We know the last used seqno, and the uCode expects to know that
2542 * one, it will increment before TX.
2543 */
2544 seq = le16_to_cpu(priv->last_seq_ctl) & IEEE80211_SCTL_SEQ;
2545 wakeup_filter_cmd.non_qos_seq = cpu_to_le16(seq);
2546
2547 /*
2548 * For QoS counters, we store the one to use next, so subtract 0x10
2549 * since the uCode will add 0x10 before using the value.
2550 */
2551 for (i = 0; i < 8; i++) {
2552 seq = priv->stations[IWL_AP_ID].tid[i].seq_number;
2553 seq -= 0x10;
2554 wakeup_filter_cmd.qos_seq[i] = cpu_to_le16(seq);
2555 }
2556
2557 if (wowlan->disconnect)
2558 wakeup_filter_cmd.enabled |=
2559 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_BEACON_MISS |
2560 IWLAGN_WOWLAN_WAKEUP_LINK_CHANGE);
2561 if (wowlan->magic_pkt)
2562 wakeup_filter_cmd.enabled |=
2563 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_MAGIC_PACKET);
2564 if (wowlan->gtk_rekey_failure)
2565 wakeup_filter_cmd.enabled |=
2566 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_GTK_REKEY_FAIL);
2567 if (wowlan->eap_identity_req)
2568 wakeup_filter_cmd.enabled |=
2569 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_EAP_IDENT_REQ);
2570 if (wowlan->four_way_handshake)
2571 wakeup_filter_cmd.enabled |=
2572 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_4WAY_HANDSHAKE);
2573 if (wowlan->rfkill_release)
2574 wakeup_filter_cmd.enabled |=
2575 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_RFKILL);
2576 if (wowlan->n_patterns)
2577 wakeup_filter_cmd.enabled |=
2578 cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_PATTERN_MATCH);
2579
2580 iwl_scan_cancel_timeout(priv, 200);
2581
2582 memcpy(&rxon, &ctx->active, sizeof(rxon));
2583
2584 trans_stop_device(&priv->trans);
2585
2586 priv->wowlan = true;
2587
2588 ret = iwlagn_load_ucode_wait_alive(priv, &priv->ucode_wowlan,
2589 IWL_UCODE_WOWLAN);
2590 if (ret)
2591 goto error;
2592
2593 /* now configure WoWLAN ucode */
2594 ret = iwl_alive_start(priv);
2595 if (ret)
2596 goto error;
2597
2598 memcpy(&ctx->staging, &rxon, sizeof(rxon));
2599 ret = iwlagn_commit_rxon(priv, ctx);
2600 if (ret)
2601 goto error;
2602
2603 ret = iwl_power_update_mode(priv, true);
2604 if (ret)
2605 goto error;
2606
2607 if (!iwlagn_mod_params.sw_crypto) {
2608 /* mark all keys clear */
2609 priv->ucode_key_table = 0;
2610 ctx->key_mapping_keys = 0;
2611
2612 /*
2613 * This needs to be unlocked due to lock ordering
2614 * constraints. Since we're in the suspend path
2615 * that isn't really a problem though.
2616 */
2617 mutex_unlock(&priv->mutex);
2618 ieee80211_iter_keys(priv->hw, ctx->vif,
2619 iwlagn_wowlan_program_keys,
2620 &key_data);
2621 mutex_lock(&priv->mutex);
2622 if (key_data.error) {
2623 ret = -EIO;
2624 goto error;
2625 }
2626
2627 if (key_data.use_rsc_tsc) {
2628 struct iwl_host_cmd rsc_tsc_cmd = {
2629 .id = REPLY_WOWLAN_TSC_RSC_PARAMS,
2630 .flags = CMD_SYNC,
2631 .data[0] = key_data.rsc_tsc,
2632 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
2633 .len[0] = sizeof(*key_data.rsc_tsc),
2634 };
2635
2636 ret = trans_send_cmd(&priv->trans, &rsc_tsc_cmd);
2637 if (ret)
2638 goto error;
2639 }
2640
2641 if (key_data.use_tkip) {
2642 ret = trans_send_cmd_pdu(&priv->trans,
2643 REPLY_WOWLAN_TKIP_PARAMS,
2644 CMD_SYNC, sizeof(tkip_cmd),
2645 &tkip_cmd);
2646 if (ret)
2647 goto error;
2648 }
2649
2650 if (priv->have_rekey_data) {
2651 memset(&kek_kck_cmd, 0, sizeof(kek_kck_cmd));
2652 memcpy(kek_kck_cmd.kck, priv->kck, NL80211_KCK_LEN);
2653 kek_kck_cmd.kck_len = cpu_to_le16(NL80211_KCK_LEN);
2654 memcpy(kek_kck_cmd.kek, priv->kek, NL80211_KEK_LEN);
2655 kek_kck_cmd.kek_len = cpu_to_le16(NL80211_KEK_LEN);
2656 kek_kck_cmd.replay_ctr = priv->replay_ctr;
2657
2658 ret = trans_send_cmd_pdu(&priv->trans,
2659 REPLY_WOWLAN_KEK_KCK_MATERIAL,
2660 CMD_SYNC, sizeof(kek_kck_cmd),
2661 &kek_kck_cmd);
2662 if (ret)
2663 goto error;
2664 }
2665 }
2666
2667 ret = trans_send_cmd_pdu(&priv->trans, REPLY_WOWLAN_WAKEUP_FILTER,
2668 CMD_SYNC, sizeof(wakeup_filter_cmd),
2669 &wakeup_filter_cmd);
2670 if (ret)
2671 goto error;
2672
2673 ret = iwlagn_send_patterns(priv, wowlan);
2674 if (ret)
2675 goto error;
2676
2677 device_set_wakeup_enable(priv->bus->dev, true);
2678
2679 /* Now let the ucode operate on its own */
2680 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
2681 CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE);
2682
2683 goto out;
2684
2685 error:
2686 priv->wowlan = false;
2687 iwlagn_prepare_restart(priv);
2688 ieee80211_restart_hw(priv->hw);
2689 out:
2690 mutex_unlock(&priv->mutex);
2691 kfree(key_data.rsc_tsc);
2692 return ret;
2693}
2694
2695static int iwlagn_mac_resume(struct ieee80211_hw *hw)
2696{
2697 struct iwl_priv *priv = hw->priv;
2698 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
2699 struct ieee80211_vif *vif;
2700 unsigned long flags;
2701 u32 base, status = 0xffffffff;
2702 int ret = -EIO;
2703
2704 mutex_lock(&priv->mutex);
2705
2706 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
2707 CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE);
2708
2709 base = priv->device_pointers.error_event_table;
2710 if (iwlagn_hw_valid_rtc_data_addr(base)) {
2711 spin_lock_irqsave(&priv->reg_lock, flags);
2712 ret = iwl_grab_nic_access_silent(priv);
2713 if (ret == 0) {
2714 iwl_write32(priv, HBUS_TARG_MEM_RADDR, base);
2715 status = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
2716 iwl_release_nic_access(priv);
2717 }
2718 spin_unlock_irqrestore(&priv->reg_lock, flags);
2719
2720#ifdef CONFIG_IWLWIFI_DEBUGFS
2721 if (ret == 0) {
2722 if (!priv->wowlan_sram)
2723 priv->wowlan_sram =
2724 kzalloc(priv->ucode_wowlan.data.len,
2725 GFP_KERNEL);
2726
2727 if (priv->wowlan_sram)
2728 _iwl_read_targ_mem_words(
2729 priv, 0x800000, priv->wowlan_sram,
2730 priv->ucode_wowlan.data.len / 4);
2731 }
2732#endif
2733 }
2734
2735 /* we'll clear ctx->vif during iwlagn_prepare_restart() */
2736 vif = ctx->vif;
2737
2738 priv->wowlan = false;
2739
2740 device_set_wakeup_enable(priv->bus->dev, false);
2741
2742 iwlagn_prepare_restart(priv);
2743
2744 memset((void *)&ctx->active, 0, sizeof(ctx->active));
2745 iwl_connection_init_rx_config(priv, ctx);
2746 iwlagn_set_rxon_chain(priv, ctx);
2747
2748 mutex_unlock(&priv->mutex);
2749
2750 ieee80211_resume_disconnect(vif);
2751
2752 return 1;
2753}
David S. Miller26293132011-07-24 13:09:32 -07002754#endif
Johannes Bergc8ac61c2011-07-15 13:23:45 -07002755
Johannes Berg2dedbf52011-04-05 09:41:50 -07002756static void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07002757{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002758 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002759
Tomas Winklere1623442009-01-27 14:27:56 -08002760 IWL_DEBUG_MACDUMP(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002761
Tomas Winklere1623442009-01-27 14:27:56 -08002762 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02002763 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07002764
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -07002765 if (iwlagn_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07002766 dev_kfree_skb_any(skb);
2767
Tomas Winklere1623442009-01-27 14:27:56 -08002768 IWL_DEBUG_MACDUMP(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002769}
2770
Johannes Berg2dedbf52011-04-05 09:41:50 -07002771static void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw,
2772 struct ieee80211_vif *vif,
2773 struct ieee80211_key_conf *keyconf,
2774 struct ieee80211_sta *sta,
2775 u32 iv32, u16 *phase1key)
Zhu Yib481de92007-09-25 17:54:57 -07002776{
Tomas Winkler9f586712008-11-12 13:14:05 -08002777 struct iwl_priv *priv = hw->priv;
Johannes Berga194e322010-08-27 08:53:46 -07002778
Johannes Berg5a3d9882011-07-15 13:03:12 -07002779 iwl_update_tkip_key(priv, vif, keyconf, sta, iv32, phase1key);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002780}
2781
Johannes Berg2dedbf52011-04-05 09:41:50 -07002782static int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2783 struct ieee80211_vif *vif,
2784 struct ieee80211_sta *sta,
2785 struct ieee80211_key_conf *key)
Zhu Yib481de92007-09-25 17:54:57 -07002786{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002787 struct iwl_priv *priv = hw->priv;
Johannes Berga194e322010-08-27 08:53:46 -07002788 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
Johannes Bergc10afb62010-08-23 10:46:43 +02002789 struct iwl_rxon_context *ctx = vif_priv->ctx;
Winkler, Tomas42986792009-01-19 15:30:22 -08002790 int ret;
Winkler, Tomas42986792009-01-19 15:30:22 -08002791 bool is_default_wep_key = false;
Zhu Yib481de92007-09-25 17:54:57 -07002792
Tomas Winklere1623442009-01-27 14:27:56 -08002793 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002794
Don Fry9d143e92011-04-20 15:23:57 -07002795 if (iwlagn_mod_params.sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08002796 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07002797 return -EOPNOTSUPP;
2798 }
Zhu Yib481de92007-09-25 17:54:57 -07002799
Johannes Berg274102a2011-01-18 04:44:03 -08002800 /*
Johannes Berg5a3d9882011-07-15 13:03:12 -07002801 * We could program these keys into the hardware as well, but we
2802 * don't expect much multicast traffic in IBSS and having keys
2803 * for more stations is probably more useful.
2804 *
2805 * Mark key TX-only and return 0.
Johannes Berg274102a2011-01-18 04:44:03 -08002806 */
2807 if (vif->type == NL80211_IFTYPE_ADHOC &&
Johannes Berg5a3d9882011-07-15 13:03:12 -07002808 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
2809 key->hw_key_idx = WEP_INVALID_OFFSET;
2810 return 0;
2811 }
Johannes Berg274102a2011-01-18 04:44:03 -08002812
Johannes Berg5a3d9882011-07-15 13:03:12 -07002813 /* If they key was TX-only, accept deletion */
2814 if (cmd == DISABLE_KEY && key->hw_key_idx == WEP_INVALID_OFFSET)
2815 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002816
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002817 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002818 iwl_scan_cancel_timeout(priv, 100);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002819
Johannes Berg5a3d9882011-07-15 13:03:12 -07002820 BUILD_BUG_ON(WEP_INVALID_OFFSET == IWLAGN_HW_KEY_DEFAULT);
2821
Johannes Berga90178fa2010-03-30 02:44:16 -07002822 /*
2823 * If we are getting WEP group key and we didn't receive any key mapping
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002824 * so far, we are in legacy wep mode (group key only), otherwise we are
2825 * in 1X mode.
Johannes Berga90178fa2010-03-30 02:44:16 -07002826 * In legacy wep mode, we use another host command to the uCode.
2827 */
Johannes Berg97359d12010-08-10 09:46:38 +02002828 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
Johannes Berg5a3d9882011-07-15 13:03:12 -07002829 key->cipher == WLAN_CIPHER_SUITE_WEP104) && !sta) {
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002830 if (cmd == SET_KEY)
Johannes Bergc10afb62010-08-23 10:46:43 +02002831 is_default_wep_key = !ctx->key_mapping_keys;
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002832 else
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +08002833 is_default_wep_key =
Johannes Berg5a3d9882011-07-15 13:03:12 -07002834 key->hw_key_idx == IWLAGN_HW_KEY_DEFAULT;
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002835 }
mabbas052c4b92007-10-25 17:15:43 +08002836
Johannes Berg5a3d9882011-07-15 13:03:12 -07002837
Zhu Yib481de92007-09-25 17:54:57 -07002838 switch (cmd) {
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002839 case SET_KEY:
Johannes Berg5a3d9882011-07-15 13:03:12 -07002840 if (is_default_wep_key) {
Johannes Berg2995baf2010-08-23 10:46:42 +02002841 ret = iwl_set_default_wep_key(priv, vif_priv->ctx, key);
Johannes Berg5a3d9882011-07-15 13:03:12 -07002842 break;
2843 }
2844 ret = iwl_set_dynamic_key(priv, vif_priv->ctx, key, sta);
2845 if (ret) {
2846 /*
2847 * can't add key for RX, but we don't need it
2848 * in the device for TX so still return 0
2849 */
2850 ret = 0;
2851 key->hw_key_idx = WEP_INVALID_OFFSET;
2852 }
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002853
Tomas Winklere1623442009-01-27 14:27:56 -08002854 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07002855 break;
2856 case DISABLE_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002857 if (is_default_wep_key)
Johannes Bergc10afb62010-08-23 10:46:43 +02002858 ret = iwl_remove_default_wep_key(priv, ctx, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002859 else
Johannes Berg5a3d9882011-07-15 13:03:12 -07002860 ret = iwl_remove_dynamic_key(priv, ctx, key, sta);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002861
Tomas Winklere1623442009-01-27 14:27:56 -08002862 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07002863 break;
2864 default:
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002865 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002866 }
2867
Johannes Berg72e15d72010-02-19 11:42:32 -08002868 mutex_unlock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08002869 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002870
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002871 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002872}
2873
Johannes Berg2dedbf52011-04-05 09:41:50 -07002874static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
2875 struct ieee80211_vif *vif,
2876 enum ieee80211_ampdu_mlme_action action,
2877 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
2878 u8 buf_size)
Tomas Winklerd783b062008-07-18 13:53:02 +08002879{
2880 struct iwl_priv *priv = hw->priv;
Johannes Berg4620fef2010-06-16 03:30:27 -07002881 int ret = -EINVAL;
Johannes Berg7b090682011-01-19 02:53:54 -08002882 struct iwl_station_priv *sta_priv = (void *) sta->drv_priv;
Tomas Winklerd783b062008-07-18 13:53:02 +08002883
Tomas Winklere1623442009-01-27 14:27:56 -08002884 IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
Johannes Berge1749612008-10-27 15:59:26 -07002885 sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08002886
Wey-Yi Guy88950752011-06-06 12:05:46 -07002887 if (!(priv->cfg->sku & EEPROM_SKU_CAP_11N_ENABLE))
Tomas Winklerd783b062008-07-18 13:53:02 +08002888 return -EACCES;
2889
Johannes Berg4620fef2010-06-16 03:30:27 -07002890 mutex_lock(&priv->mutex);
2891
Tomas Winklerd783b062008-07-18 13:53:02 +08002892 switch (action) {
2893 case IEEE80211_AMPDU_RX_START:
Tomas Winklere1623442009-01-27 14:27:56 -08002894 IWL_DEBUG_HT(priv, "start Rx\n");
Johannes Berg4620fef2010-06-16 03:30:27 -07002895 ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn);
2896 break;
Tomas Winklerd783b062008-07-18 13:53:02 +08002897 case IEEE80211_AMPDU_RX_STOP:
Tomas Winklere1623442009-01-27 14:27:56 -08002898 IWL_DEBUG_HT(priv, "stop Rx\n");
Johannes Berg619753f2010-04-30 11:30:46 -07002899 ret = iwl_sta_rx_agg_stop(priv, sta, tid);
Wey-Yi Guy5c2207c2009-03-17 21:51:43 -07002900 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Johannes Berg4620fef2010-06-16 03:30:27 -07002901 ret = 0;
2902 break;
Tomas Winklerd783b062008-07-18 13:53:02 +08002903 case IEEE80211_AMPDU_TX_START:
Tomas Winklere1623442009-01-27 14:27:56 -08002904 IWL_DEBUG_HT(priv, "start Tx\n");
Johannes Berg619753f2010-04-30 11:30:46 -07002905 ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn);
Wey-Yi Guyd5a0ffa2010-03-04 13:38:59 -08002906 if (ret == 0) {
Wey-Yi Guy898ed672011-07-13 08:38:57 -07002907 priv->agg_tids_count++;
2908 IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n",
2909 priv->agg_tids_count);
Wey-Yi Guyd5a0ffa2010-03-04 13:38:59 -08002910 }
Johannes Berg4620fef2010-06-16 03:30:27 -07002911 break;
Tomas Winklerd783b062008-07-18 13:53:02 +08002912 case IEEE80211_AMPDU_TX_STOP:
Tomas Winklere1623442009-01-27 14:27:56 -08002913 IWL_DEBUG_HT(priv, "stop Tx\n");
Johannes Berg619753f2010-04-30 11:30:46 -07002914 ret = iwlagn_tx_agg_stop(priv, vif, sta, tid);
Wey-Yi Guy898ed672011-07-13 08:38:57 -07002915 if ((ret == 0) && (priv->agg_tids_count > 0)) {
2916 priv->agg_tids_count--;
2917 IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n",
2918 priv->agg_tids_count);
Wey-Yi Guyd5a0ffa2010-03-04 13:38:59 -08002919 }
Wey-Yi Guy5c2207c2009-03-17 21:51:43 -07002920 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Johannes Berg4620fef2010-06-16 03:30:27 -07002921 ret = 0;
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002922 if (priv->cfg->ht_params &&
2923 priv->cfg->ht_params->use_rts_for_aggregation) {
Johannes Berg94597ab2010-08-09 10:57:02 -07002924 /*
2925 * switch off RTS/CTS if it was previously enabled
2926 */
Johannes Berg94597ab2010-08-09 10:57:02 -07002927 sta_priv->lq_sta.lq.general_params.flags &=
2928 ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
Johannes Berg7e6a5882010-08-23 10:46:46 +02002929 iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
2930 &sta_priv->lq_sta.lq, CMD_ASYNC, false);
Johannes Berg94597ab2010-08-09 10:57:02 -07002931 }
Johannes Berg4620fef2010-06-16 03:30:27 -07002932 break;
Wey-Yi Guyf0527972010-01-08 10:04:41 -08002933 case IEEE80211_AMPDU_TX_OPERATIONAL:
Johannes Bergc8823ec2011-03-15 11:33:03 -07002934 buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF);
2935
Emmanuel Grumbach41c50542011-07-11 08:51:04 +03002936 trans_txq_agg_setup(&priv->trans, iwl_sta_id(sta), tid,
2937 buf_size);
Johannes Bergc8823ec2011-03-15 11:33:03 -07002938
Johannes Berg7b090682011-01-19 02:53:54 -08002939 /*
2940 * If the limit is 0, then it wasn't initialised yet,
2941 * use the default. We can do that since we take the
2942 * minimum below, and we don't want to go above our
2943 * default due to hardware restrictions.
2944 */
2945 if (sta_priv->max_agg_bufsize == 0)
2946 sta_priv->max_agg_bufsize =
2947 LINK_QUAL_AGG_FRAME_LIMIT_DEF;
2948
2949 /*
2950 * Even though in theory the peer could have different
2951 * aggregation reorder buffer sizes for different sessions,
2952 * our ucode doesn't allow for that and has a global limit
2953 * for each station. Therefore, use the minimum of all the
2954 * aggregation sessions and our default value.
2955 */
2956 sta_priv->max_agg_bufsize =
2957 min(sta_priv->max_agg_bufsize, buf_size);
2958
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002959 if (priv->cfg->ht_params &&
2960 priv->cfg->ht_params->use_rts_for_aggregation) {
Wey-Yi Guycfecc6b2010-06-18 11:33:15 -07002961 /*
2962 * switch to RTS/CTS if it is the prefer protection
2963 * method for HT traffic
2964 */
Johannes Berg94597ab2010-08-09 10:57:02 -07002965
2966 sta_priv->lq_sta.lq.general_params.flags |=
2967 LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
Wey-Yi Guycfecc6b2010-06-18 11:33:15 -07002968 }
Johannes Berg7b090682011-01-19 02:53:54 -08002969
2970 sta_priv->lq_sta.lq.agg_params.agg_frame_cnt_limit =
2971 sta_priv->max_agg_bufsize;
2972
2973 iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
2974 &sta_priv->lq_sta.lq, CMD_ASYNC, false);
Wey-Yi Guy5bc98902011-05-27 08:40:32 -07002975
2976 IWL_INFO(priv, "Tx aggregation enabled on ra = %pM tid = %d\n",
2977 sta->addr, tid);
Wey-Yi Guycfecc6b2010-06-18 11:33:15 -07002978 ret = 0;
Tomas Winklerd783b062008-07-18 13:53:02 +08002979 break;
2980 }
Johannes Berg4620fef2010-06-16 03:30:27 -07002981 mutex_unlock(&priv->mutex);
2982
2983 return ret;
Tomas Winklerd783b062008-07-18 13:53:02 +08002984}
Tomas Winkler9f586712008-11-12 13:14:05 -08002985
Johannes Berg2dedbf52011-04-05 09:41:50 -07002986static int iwlagn_mac_sta_add(struct ieee80211_hw *hw,
2987 struct ieee80211_vif *vif,
2988 struct ieee80211_sta *sta)
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002989{
2990 struct iwl_priv *priv = hw->priv;
2991 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
Johannes Berga194e322010-08-27 08:53:46 -07002992 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
Johannes Bergeafdfbd32010-04-29 04:43:04 -07002993 bool is_ap = vif->type == NL80211_IFTYPE_STATION;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002994 int ret;
2995 u8 sta_id;
2996
2997 IWL_DEBUG_INFO(priv, "received request to add station %pM\n",
2998 sta->addr);
Reinette Chatreda5ae1c2010-05-28 09:28:39 -07002999 mutex_lock(&priv->mutex);
3000 IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
3001 sta->addr);
3002 sta_priv->common.sta_id = IWL_INVALID_STATION;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003003
3004 atomic_set(&sta_priv->pending_frames, 0);
3005 if (vif->type == NL80211_IFTYPE_AP)
3006 sta_priv->client = true;
3007
Johannes Berga194e322010-08-27 08:53:46 -07003008 ret = iwl_add_station_common(priv, vif_priv->ctx, sta->addr,
Johannes Berg238d7812010-08-23 10:46:45 +02003009 is_ap, sta, &sta_id);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003010 if (ret) {
3011 IWL_ERR(priv, "Unable to add station %pM (%d)\n",
3012 sta->addr, ret);
3013 /* Should we return success if return code is EEXIST ? */
Reinette Chatreda5ae1c2010-05-28 09:28:39 -07003014 mutex_unlock(&priv->mutex);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003015 return ret;
3016 }
3017
Johannes Bergfd1af152010-04-30 11:30:43 -07003018 sta_priv->common.sta_id = sta_id;
3019
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003020 /* Initialize rate scaling */
Frans Pop91dd6c22010-03-24 14:19:58 -07003021 IWL_DEBUG_INFO(priv, "Initializing rate scaling for station %pM\n",
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003022 sta->addr);
3023 iwl_rs_rate_init(priv, sta, sta_id);
Reinette Chatreda5ae1c2010-05-28 09:28:39 -07003024 mutex_unlock(&priv->mutex);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003025
Johannes Bergfd1af152010-04-30 11:30:43 -07003026 return 0;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003027}
3028
Johannes Berg2dedbf52011-04-05 09:41:50 -07003029static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
3030 struct ieee80211_channel_switch *ch_switch)
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003031{
3032 struct iwl_priv *priv = hw->priv;
3033 const struct iwl_channel_info *ch_info;
3034 struct ieee80211_conf *conf = &hw->conf;
Shanyu Zhaoaa2dc6b2010-07-28 13:40:39 -07003035 struct ieee80211_channel *channel = ch_switch->channel;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003036 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
Johannes Berg246ed352010-08-23 10:46:32 +02003037 /*
3038 * MULTI-FIXME
3039 * When we add support for multiple interfaces, we need to
3040 * revisit this. The channel switch command in the device
3041 * only affects the BSS context, but what does that really
3042 * mean? And what if we get a CSA on the second interface?
3043 * This needs a lot of work.
3044 */
3045 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003046 u16 ch;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003047
3048 IWL_DEBUG_MAC80211(priv, "enter\n");
3049
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +02003050 mutex_lock(&priv->mutex);
3051
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003052 if (iwl_is_rfkill(priv))
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +02003053 goto out;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003054
3055 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
Stanislaw Gruszka6f213ff2011-06-02 18:17:15 +02003056 test_bit(STATUS_SCANNING, &priv->status) ||
3057 test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status))
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +02003058 goto out;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003059
Johannes Berg246ed352010-08-23 10:46:32 +02003060 if (!iwl_is_associated_ctx(ctx))
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +02003061 goto out;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003062
Wey-Yi Guy90c300c2011-07-07 08:33:01 -07003063 if (!priv->cfg->lib->set_channel_switch)
Stanislaw Gruszkaf973f872011-06-02 16:46:20 +02003064 goto out;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003065
Stanislaw Gruszkaf973f872011-06-02 16:46:20 +02003066 ch = channel->hw_value;
3067 if (le16_to_cpu(ctx->active.channel) == ch)
3068 goto out;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003069
Stanislaw Gruszkaf973f872011-06-02 16:46:20 +02003070 ch_info = iwl_get_channel_info(priv, channel->band, ch);
3071 if (!is_channel_valid(ch_info)) {
3072 IWL_DEBUG_MAC80211(priv, "invalid channel\n");
3073 goto out;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003074 }
Stanislaw Gruszkaf973f872011-06-02 16:46:20 +02003075
3076 spin_lock_irq(&priv->lock);
3077
3078 priv->current_ht_config.smps = conf->smps_mode;
3079
3080 /* Configure HT40 channels */
3081 ctx->ht.enabled = conf_is_ht(conf);
3082 if (ctx->ht.enabled) {
3083 if (conf_is_ht40_minus(conf)) {
3084 ctx->ht.extension_chan_offset =
3085 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
3086 ctx->ht.is_40mhz = true;
3087 } else if (conf_is_ht40_plus(conf)) {
3088 ctx->ht.extension_chan_offset =
3089 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
3090 ctx->ht.is_40mhz = true;
3091 } else {
3092 ctx->ht.extension_chan_offset =
3093 IEEE80211_HT_PARAM_CHA_SEC_NONE;
3094 ctx->ht.is_40mhz = false;
3095 }
3096 } else
3097 ctx->ht.is_40mhz = false;
3098
3099 if ((le16_to_cpu(ctx->staging.channel) != ch))
3100 ctx->staging.flags = 0;
3101
3102 iwl_set_rxon_channel(priv, channel, ctx);
3103 iwl_set_rxon_ht(priv, ht_conf);
3104 iwl_set_flags_for_band(priv, ctx, channel->band, ctx->vif);
3105
3106 spin_unlock_irq(&priv->lock);
3107
3108 iwl_set_rate(priv);
3109 /*
3110 * at this point, staging_rxon has the
3111 * configuration for channel switch
3112 */
3113 set_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status);
3114 priv->switch_channel = cpu_to_le16(ch);
Wey-Yi Guy90c300c2011-07-07 08:33:01 -07003115 if (priv->cfg->lib->set_channel_switch(priv, ch_switch)) {
Stanislaw Gruszkaf973f872011-06-02 16:46:20 +02003116 clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status);
3117 priv->switch_channel = 0;
3118 ieee80211_chswitch_done(ctx->vif, false);
3119 }
3120
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003121out:
3122 mutex_unlock(&priv->mutex);
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003123 IWL_DEBUG_MAC80211(priv, "leave\n");
3124}
3125
Johannes Berg2dedbf52011-04-05 09:41:50 -07003126static void iwlagn_configure_filter(struct ieee80211_hw *hw,
3127 unsigned int changed_flags,
3128 unsigned int *total_flags,
3129 u64 multicast)
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02003130{
3131 struct iwl_priv *priv = hw->priv;
3132 __le32 filter_or = 0, filter_nand = 0;
Johannes Berg246ed352010-08-23 10:46:32 +02003133 struct iwl_rxon_context *ctx;
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02003134
3135#define CHK(test, flag) do { \
3136 if (*total_flags & (test)) \
3137 filter_or |= (flag); \
3138 else \
3139 filter_nand |= (flag); \
3140 } while (0)
3141
3142 IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
3143 changed_flags, *total_flags);
3144
3145 CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
Johannes Bergbdb84fe2010-12-15 06:07:56 -08003146 /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */
3147 CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK);
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02003148 CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
3149
3150#undef CHK
3151
3152 mutex_lock(&priv->mutex);
3153
Johannes Berg246ed352010-08-23 10:46:32 +02003154 for_each_context(priv, ctx) {
3155 ctx->staging.filter_flags &= ~filter_nand;
3156 ctx->staging.filter_flags |= filter_or;
Stanislaw Gruszka749ff4ef2010-10-22 17:04:27 +02003157
3158 /*
3159 * Not committing directly because hardware can perform a scan,
3160 * but we'll eventually commit the filter flags change anyway.
3161 */
Johannes Berg246ed352010-08-23 10:46:32 +02003162 }
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02003163
3164 mutex_unlock(&priv->mutex);
3165
3166 /*
3167 * Receiving all multicast frames is always enabled by the
3168 * default flags setup in iwl_connection_init_rx_config()
3169 * since we currently do not support programming multicast
3170 * filters into the device.
3171 */
3172 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
3173 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
3174}
3175
Johannes Berg2dedbf52011-04-05 09:41:50 -07003176static void iwlagn_mac_flush(struct ieee80211_hw *hw, bool drop)
Wey-Yi Guy716c74b2010-06-24 13:22:36 -07003177{
3178 struct iwl_priv *priv = hw->priv;
3179
3180 mutex_lock(&priv->mutex);
3181 IWL_DEBUG_MAC80211(priv, "enter\n");
3182
Wey-Yi Guy716c74b2010-06-24 13:22:36 -07003183 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
3184 IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n");
3185 goto done;
3186 }
3187 if (iwl_is_rfkill(priv)) {
3188 IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n");
3189 goto done;
3190 }
3191
3192 /*
3193 * mac80211 will not push any more frames for transmit
3194 * until the flush is completed
3195 */
3196 if (drop) {
3197 IWL_DEBUG_MAC80211(priv, "send flush command\n");
Wey-Yi Guyc68744f2011-06-18 08:03:18 -07003198 if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) {
Wey-Yi Guy716c74b2010-06-24 13:22:36 -07003199 IWL_ERR(priv, "flush request fail\n");
3200 goto done;
3201 }
3202 }
3203 IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n");
3204 iwlagn_wait_tx_queue_empty(priv);
3205done:
3206 mutex_unlock(&priv->mutex);
3207 IWL_DEBUG_MAC80211(priv, "leave\n");
3208}
3209
Johannes Berg9b9190d2011-01-06 08:07:10 -08003210static void iwlagn_disable_roc(struct iwl_priv *priv)
3211{
3212 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
3213 struct ieee80211_channel *chan = ACCESS_ONCE(priv->hw->conf.channel);
3214
3215 lockdep_assert_held(&priv->mutex);
3216
3217 if (!ctx->is_active)
3218 return;
3219
3220 ctx->staging.dev_type = RXON_DEV_TYPE_2STA;
3221 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3222 iwl_set_rxon_channel(priv, chan, ctx);
3223 iwl_set_flags_for_band(priv, ctx, chan->band, NULL);
3224
Wey-Yi Guy898ed672011-07-13 08:38:57 -07003225 priv->hw_roc_channel = NULL;
Johannes Berg9b9190d2011-01-06 08:07:10 -08003226
Wey-Yi Guy805a3b82011-06-03 07:54:16 -07003227 iwlagn_commit_rxon(priv, ctx);
Johannes Berg9b9190d2011-01-06 08:07:10 -08003228
3229 ctx->is_active = false;
3230}
3231
3232static void iwlagn_bg_roc_done(struct work_struct *work)
3233{
3234 struct iwl_priv *priv = container_of(work, struct iwl_priv,
Wey-Yi Guy898ed672011-07-13 08:38:57 -07003235 hw_roc_work.work);
Johannes Berg9b9190d2011-01-06 08:07:10 -08003236
3237 mutex_lock(&priv->mutex);
3238 ieee80211_remain_on_channel_expired(priv->hw);
3239 iwlagn_disable_roc(priv);
3240 mutex_unlock(&priv->mutex);
3241}
3242
3243static int iwl_mac_remain_on_channel(struct ieee80211_hw *hw,
3244 struct ieee80211_channel *channel,
3245 enum nl80211_channel_type channel_type,
3246 int duration)
3247{
3248 struct iwl_priv *priv = hw->priv;
3249 int err = 0;
3250
3251 if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
3252 return -EOPNOTSUPP;
3253
3254 if (!(priv->contexts[IWL_RXON_CTX_PAN].interface_modes &
3255 BIT(NL80211_IFTYPE_P2P_CLIENT)))
3256 return -EOPNOTSUPP;
3257
3258 mutex_lock(&priv->mutex);
3259
3260 if (priv->contexts[IWL_RXON_CTX_PAN].is_active ||
3261 test_bit(STATUS_SCAN_HW, &priv->status)) {
3262 err = -EBUSY;
3263 goto out;
3264 }
3265
3266 priv->contexts[IWL_RXON_CTX_PAN].is_active = true;
Wey-Yi Guy898ed672011-07-13 08:38:57 -07003267 priv->hw_roc_channel = channel;
3268 priv->hw_roc_chantype = channel_type;
3269 priv->hw_roc_duration = DIV_ROUND_UP(duration * 1000, 1024);
Wey-Yi Guy805a3b82011-06-03 07:54:16 -07003270 iwlagn_commit_rxon(priv, &priv->contexts[IWL_RXON_CTX_PAN]);
Wey-Yi Guy898ed672011-07-13 08:38:57 -07003271 queue_delayed_work(priv->workqueue, &priv->hw_roc_work,
Johannes Berg9b9190d2011-01-06 08:07:10 -08003272 msecs_to_jiffies(duration + 20));
3273
Johannes Berg94073912011-01-06 08:07:11 -08003274 msleep(IWL_MIN_SLOT_TIME); /* TU is almost ms */
Johannes Berg9b9190d2011-01-06 08:07:10 -08003275 ieee80211_ready_on_channel(priv->hw);
3276
3277 out:
3278 mutex_unlock(&priv->mutex);
3279
3280 return err;
3281}
3282
3283static int iwl_mac_cancel_remain_on_channel(struct ieee80211_hw *hw)
3284{
3285 struct iwl_priv *priv = hw->priv;
3286
3287 if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
3288 return -EOPNOTSUPP;
3289
Wey-Yi Guy898ed672011-07-13 08:38:57 -07003290 cancel_delayed_work_sync(&priv->hw_roc_work);
Johannes Berg9b9190d2011-01-06 08:07:10 -08003291
3292 mutex_lock(&priv->mutex);
3293 iwlagn_disable_roc(priv);
3294 mutex_unlock(&priv->mutex);
3295
3296 return 0;
3297}
3298
Zhu Yib481de92007-09-25 17:54:57 -07003299/*****************************************************************************
3300 *
Zhu Yib481de92007-09-25 17:54:57 -07003301 * driver setup and teardown
3302 *
3303 *****************************************************************************/
3304
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003305static void iwl_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003306{
Reinette Chatred21050c2009-02-13 11:51:18 -08003307 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07003308
3309 init_waitqueue_head(&priv->wait_command_queue);
3310
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003311 INIT_WORK(&priv->restart, iwl_bg_restart);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003312 INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08003313 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
Wey-Yi Guy65550632010-06-24 13:18:35 -07003314 INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
Wey-Yi Guybee008b2010-08-23 07:57:04 -07003315 INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
Wey-Yi Guyfbba9412010-08-23 07:57:10 -07003316 INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
Wey-Yi Guy898ed672011-07-13 08:38:57 -07003317 INIT_DELAYED_WORK(&priv->hw_roc_work, iwlagn_bg_roc_done);
Tomas Winkler2a421b92008-06-12 09:47:10 +08003318
Tomas Winkler2a421b92008-06-12 09:47:10 +08003319 iwl_setup_scan_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003320
Emmanuel Grumbach6bd4dba2011-07-03 15:45:34 +03003321 if (priv->cfg->lib->bt_setup_deferred_work)
3322 priv->cfg->lib->bt_setup_deferred_work(priv);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003323
3324 init_timer(&priv->statistics_periodic);
3325 priv->statistics_periodic.data = (unsigned long)priv;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003326 priv->statistics_periodic.function = iwl_bg_statistics_periodic;
Zhu Yib481de92007-09-25 17:54:57 -07003327
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08003328 init_timer(&priv->ucode_trace);
3329 priv->ucode_trace.data = (unsigned long)priv;
3330 priv->ucode_trace.function = iwl_bg_ucode_trace;
3331
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01003332 init_timer(&priv->watchdog);
3333 priv->watchdog.data = (unsigned long)priv;
3334 priv->watchdog.function = iwl_bg_watchdog;
Zhu Yib481de92007-09-25 17:54:57 -07003335}
3336
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003337static void iwl_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003338{
Wey-Yi Guy90c300c2011-07-07 08:33:01 -07003339 if (priv->cfg->lib->cancel_deferred_work)
3340 priv->cfg->lib->cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003341
Wey-Yi Guy815e6292010-06-03 10:14:01 -07003342 cancel_work_sync(&priv->run_time_calib_work);
Zhu Yib481de92007-09-25 17:54:57 -07003343 cancel_work_sync(&priv->beacon_update);
Stanislaw Gruszkae7e16b92010-09-13 14:46:41 +02003344
3345 iwl_cancel_scan_deferred_work(priv);
3346
Wey-Yi Guybee008b2010-08-23 07:57:04 -07003347 cancel_work_sync(&priv->bt_full_concurrency);
Wey-Yi Guyfbba9412010-08-23 07:57:10 -07003348 cancel_work_sync(&priv->bt_runtime_config);
Stanislaw Gruszkae7e16b92010-09-13 14:46:41 +02003349
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003350 del_timer_sync(&priv->statistics_periodic);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08003351 del_timer_sync(&priv->ucode_trace);
Zhu Yib481de92007-09-25 17:54:57 -07003352}
3353
Reinette Chatre89f186a2009-10-30 14:36:11 -07003354static void iwl_init_hw_rates(struct iwl_priv *priv,
3355 struct ieee80211_rate *rates)
3356{
3357 int i;
3358
3359 for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
3360 rates[i].bitrate = iwl_rates[i].ieee * 5;
3361 rates[i].hw_value = i; /* Rate scaling will work on indexes */
3362 rates[i].hw_value_short = i;
3363 rates[i].flags = 0;
3364 if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
3365 /*
3366 * If CCK != 1M then set short preamble rate flag.
3367 */
3368 rates[i].flags |=
3369 (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
3370 0 : IEEE80211_RATE_SHORT_PREAMBLE;
3371 }
3372 }
3373}
3374
3375static int iwl_init_drv(struct iwl_priv *priv)
3376{
3377 int ret;
3378
Reinette Chatre89f186a2009-10-30 14:36:11 -07003379 spin_lock_init(&priv->sta_lock);
3380 spin_lock_init(&priv->hcmd_lock);
3381
Reinette Chatre89f186a2009-10-30 14:36:11 -07003382 mutex_init(&priv->mutex);
3383
Reinette Chatre89f186a2009-10-30 14:36:11 -07003384 priv->ieee_channels = NULL;
3385 priv->ieee_rates = NULL;
3386 priv->band = IEEE80211_BAND_2GHZ;
3387
3388 priv->iw_mode = NL80211_IFTYPE_STATION;
Johannes Bergba37a3d2009-12-10 14:37:27 -08003389 priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
Wey-Yi Guya13d2762010-01-22 14:22:42 -08003390 priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
Wey-Yi Guy898ed672011-07-13 08:38:57 -07003391 priv->agg_tids_count = 0;
Reinette Chatre89f186a2009-10-30 14:36:11 -07003392
Wey-Yi Guy8a472da2010-02-18 22:03:06 -08003393 /* initialize force reset */
3394 priv->force_reset[IWL_RF_RESET].reset_duration =
3395 IWL_DELAY_NEXT_FORCE_RF_RESET;
3396 priv->force_reset[IWL_FW_RESET].reset_duration =
3397 IWL_DELAY_NEXT_FORCE_FW_RELOAD;
Reinette Chatre89f186a2009-10-30 14:36:11 -07003398
Stanislaw Gruszka410f2bb2011-03-04 17:51:51 +01003399 priv->rx_statistics_jiffies = jiffies;
3400
Reinette Chatre89f186a2009-10-30 14:36:11 -07003401 /* Choose which receivers/antennas to use */
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -07003402 iwlagn_set_rxon_chain(priv, &priv->contexts[IWL_RXON_CTX_BSS]);
Reinette Chatre89f186a2009-10-30 14:36:11 -07003403
3404 iwl_init_scan_params(priv);
3405
Wey-Yi Guy22bf59a2010-08-23 07:57:11 -07003406 /* init bt coex */
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07003407 if (priv->cfg->bt_params &&
3408 priv->cfg->bt_params->advanced_bt_coexist) {
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07003409 priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
3410 priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
3411 priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
Wey-Yi Guy22bf59a2010-08-23 07:57:11 -07003412 priv->bt_on_thresh = BT_ON_THRESHOLD_DEF;
3413 priv->bt_duration = BT_DURATION_LIMIT_DEF;
3414 priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
Wey-Yi Guy22bf59a2010-08-23 07:57:11 -07003415 }
3416
Reinette Chatre89f186a2009-10-30 14:36:11 -07003417 ret = iwl_init_channel_map(priv);
3418 if (ret) {
3419 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
3420 goto err;
3421 }
3422
3423 ret = iwlcore_init_geos(priv);
3424 if (ret) {
3425 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
3426 goto err_free_channel_map;
3427 }
3428 iwl_init_hw_rates(priv, priv->ieee_rates);
3429
3430 return 0;
3431
3432err_free_channel_map:
3433 iwl_free_channel_map(priv);
3434err:
3435 return ret;
3436}
3437
3438static void iwl_uninit_drv(struct iwl_priv *priv)
3439{
3440 iwl_calib_free_results(priv);
3441 iwlcore_free_geos(priv);
3442 iwl_free_channel_map(priv);
Johannes Berg811ecc92010-04-06 04:12:41 -07003443 kfree(priv->scan_cmd);
Johannes Berg4ce7cc22011-05-13 11:57:40 -07003444 kfree(priv->beacon_cmd);
Johannes Bergc8ac61c2011-07-15 13:23:45 -07003445#ifdef CONFIG_IWLWIFI_DEBUGFS
3446 kfree(priv->wowlan_sram);
3447#endif
Reinette Chatre89f186a2009-10-30 14:36:11 -07003448}
3449
Wey-Yi Guy3a3b14c2011-07-08 08:46:24 -07003450static void iwl_mac_rssi_callback(struct ieee80211_hw *hw,
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -07003451 enum ieee80211_rssi_event rssi_event)
3452{
3453 struct iwl_priv *priv = hw->priv;
3454
3455 mutex_lock(&priv->mutex);
3456
3457 if (priv->cfg->bt_params &&
3458 priv->cfg->bt_params->advanced_bt_coexist) {
3459 if (rssi_event == RSSI_EVENT_LOW)
3460 priv->bt_enable_pspoll = true;
3461 else if (rssi_event == RSSI_EVENT_HIGH)
3462 priv->bt_enable_pspoll = false;
3463
3464 iwlagn_send_advance_bt_config(priv);
3465 } else {
3466 IWL_DEBUG_MAC80211(priv, "Advanced BT coex disabled,"
3467 "ignoring RSSI callback\n");
3468 }
3469
3470 mutex_unlock(&priv->mutex);
3471}
3472
Johannes Bergdc21b542010-10-23 09:15:39 -07003473struct ieee80211_ops iwlagn_hw_ops = {
Johannes Berg2295c662010-10-23 09:15:41 -07003474 .tx = iwlagn_mac_tx,
3475 .start = iwlagn_mac_start,
3476 .stop = iwlagn_mac_stop,
David S. Miller26293132011-07-24 13:09:32 -07003477#ifdef CONFIG_PM
Johannes Bergc8ac61c2011-07-15 13:23:45 -07003478 .suspend = iwlagn_mac_suspend,
3479 .resume = iwlagn_mac_resume,
David S. Miller26293132011-07-24 13:09:32 -07003480#endif
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003481 .add_interface = iwl_mac_add_interface,
3482 .remove_interface = iwl_mac_remove_interface,
Johannes Bergd4daaea2010-10-23 09:15:43 -07003483 .change_interface = iwl_mac_change_interface,
Johannes Berg2295c662010-10-23 09:15:41 -07003484 .config = iwlagn_mac_config,
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02003485 .configure_filter = iwlagn_configure_filter,
Johannes Berg2295c662010-10-23 09:15:41 -07003486 .set_key = iwlagn_mac_set_key,
3487 .update_tkip_key = iwlagn_mac_update_tkip_key,
Johannes Bergc8ac61c2011-07-15 13:23:45 -07003488 .set_rekey_data = iwlagn_mac_set_rekey_data,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003489 .conf_tx = iwl_mac_conf_tx,
Johannes Berg2295c662010-10-23 09:15:41 -07003490 .bss_info_changed = iwlagn_bss_info_changed,
3491 .ampdu_action = iwlagn_mac_ampdu_action,
Johannes Berg6ab10ff2009-11-13 11:56:37 -08003492 .hw_scan = iwl_mac_hw_scan,
Johannes Berg2295c662010-10-23 09:15:41 -07003493 .sta_notify = iwlagn_mac_sta_notify,
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003494 .sta_add = iwlagn_mac_sta_add,
3495 .sta_remove = iwl_mac_sta_remove,
Johannes Berg2295c662010-10-23 09:15:41 -07003496 .channel_switch = iwlagn_mac_channel_switch,
3497 .flush = iwlagn_mac_flush,
Johannes Berga85d7cc2010-07-31 08:34:10 -07003498 .tx_last_beacon = iwl_mac_tx_last_beacon,
Johannes Berg9b9190d2011-01-06 08:07:10 -08003499 .remain_on_channel = iwl_mac_remain_on_channel,
3500 .cancel_remain_on_channel = iwl_mac_cancel_remain_on_channel,
Johannes Berg266af4c72011-03-10 20:13:26 -08003501 .offchannel_tx = iwl_mac_offchannel_tx,
3502 .offchannel_tx_cancel_wait = iwl_mac_offchannel_tx_cancel_wait,
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -07003503 .rssi_callback = iwl_mac_rssi_callback,
Cindy H. Kao4613e722011-05-06 10:40:15 -07003504 CFG80211_TESTMODE_CMD(iwl_testmode_cmd)
Wey-Yi Guyeb64dca2011-05-31 08:03:02 -07003505 CFG80211_TESTMODE_DUMP(iwl_testmode_dump)
Zhu Yib481de92007-09-25 17:54:57 -07003506};
3507
Johannes Berge98a1302011-04-05 09:42:08 -07003508static u32 iwl_hw_detect(struct iwl_priv *priv)
Wey-Yi Guy3867fe02010-07-31 08:34:05 -07003509{
Johannes Berg02a7fa02011-04-05 09:42:12 -07003510 return iwl_read32(priv, CSR_HW_REV);
Wey-Yi Guy3867fe02010-07-31 08:34:05 -07003511}
3512
Wey-Yi Guy07d4f1a2010-07-31 08:34:08 -07003513static int iwl_set_hw_params(struct iwl_priv *priv)
3514{
3515 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
3516 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
Don Fry9d143e92011-04-20 15:23:57 -07003517 if (iwlagn_mod_params.amsdu_size_8K)
Wey-Yi Guy07d4f1a2010-07-31 08:34:08 -07003518 priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_8K);
3519 else
3520 priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_4K);
3521
3522 priv->hw_params.max_beacon_itrvl = IWL_MAX_UCODE_BEACON_INTERVAL;
3523
Don Fry9d143e92011-04-20 15:23:57 -07003524 if (iwlagn_mod_params.disable_11n)
Wey-Yi Guy88950752011-06-06 12:05:46 -07003525 priv->cfg->sku &= ~EEPROM_SKU_CAP_11N_ENABLE;
Wey-Yi Guy07d4f1a2010-07-31 08:34:08 -07003526
3527 /* Device-specific setup */
Wey-Yi Guy90c300c2011-07-07 08:33:01 -07003528 return priv->cfg->lib->set_hw_params(priv);
Wey-Yi Guy07d4f1a2010-07-31 08:34:08 -07003529}
3530
Johannes Berge72f3682010-08-23 10:46:51 +02003531static const u8 iwlagn_bss_ac_to_fifo[] = {
3532 IWL_TX_FIFO_VO,
3533 IWL_TX_FIFO_VI,
3534 IWL_TX_FIFO_BE,
3535 IWL_TX_FIFO_BK,
3536};
3537
3538static const u8 iwlagn_bss_ac_to_queue[] = {
3539 0, 1, 2, 3,
3540};
3541
3542static const u8 iwlagn_pan_ac_to_fifo[] = {
3543 IWL_TX_FIFO_VO_IPAN,
3544 IWL_TX_FIFO_VI_IPAN,
3545 IWL_TX_FIFO_BE_IPAN,
3546 IWL_TX_FIFO_BK_IPAN,
3547};
3548
3549static const u8 iwlagn_pan_ac_to_queue[] = {
3550 7, 6, 5, 4,
3551};
3552
Wey-Yi Guy119ea182011-04-18 09:34:06 -07003553/* This function both allocates and initializes hw and priv. */
3554static struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg)
3555{
3556 struct iwl_priv *priv;
3557 /* mac80211 allocates memory for this device instance, including
3558 * space for this driver's private structure */
3559 struct ieee80211_hw *hw;
3560
3561 hw = ieee80211_alloc_hw(sizeof(struct iwl_priv), &iwlagn_hw_ops);
3562 if (hw == NULL) {
3563 pr_err("%s: Can not allocate network device\n",
3564 cfg->name);
3565 goto out;
3566 }
3567
3568 priv = hw->priv;
3569 priv->hw = hw;
3570
3571out:
3572 return hw;
3573}
3574
Wey-Yi Guyb2ea3452011-06-07 08:53:14 -07003575static void iwl_init_context(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003576{
Wey-Yi Guyb2ea3452011-06-07 08:53:14 -07003577 int i;
Assaf Krauss1d0a0822008-03-14 10:38:48 -07003578
Johannes Berg246ed352010-08-23 10:46:32 +02003579 /*
3580 * The default context is always valid,
3581 * more may be discovered when firmware
3582 * is loaded.
3583 */
3584 priv->valid_contexts = BIT(IWL_RXON_CTX_BSS);
3585
3586 for (i = 0; i < NUM_IWL_RXON_CTX; i++)
3587 priv->contexts[i].ctxid = i;
3588
Johannes Berg763cc3b2010-09-03 06:32:21 -07003589 priv->contexts[IWL_RXON_CTX_BSS].always_active = true;
3590 priv->contexts[IWL_RXON_CTX_BSS].is_active = true;
Johannes Berg8f2d3d22010-08-23 10:46:37 +02003591 priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
3592 priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
3593 priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
Johannes Berg8dfdb9d2010-08-23 10:46:38 +02003594 priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
Johannes Berg2995baf2010-08-23 10:46:42 +02003595 priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
Johannes Bergc10afb62010-08-23 10:46:43 +02003596 priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
Johannes Berge72f3682010-08-23 10:46:51 +02003597 priv->contexts[IWL_RXON_CTX_BSS].ac_to_fifo = iwlagn_bss_ac_to_fifo;
3598 priv->contexts[IWL_RXON_CTX_BSS].ac_to_queue = iwlagn_bss_ac_to_queue;
Johannes Bergd0fe4782010-08-23 10:46:58 +02003599 priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
3600 BIT(NL80211_IFTYPE_ADHOC);
3601 priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
3602 BIT(NL80211_IFTYPE_STATION);
Johannes Berg2295c662010-10-23 09:15:41 -07003603 priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP;
Johannes Bergd0fe4782010-08-23 10:46:58 +02003604 priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
3605 priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
3606 priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
Johannes Bergece9c4e2010-08-23 10:46:49 +02003607
3608 priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON;
Wey-Yi Guyb2ea3452011-06-07 08:53:14 -07003609 priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd =
3610 REPLY_WIPAN_RXON_TIMING;
3611 priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd =
3612 REPLY_WIPAN_RXON_ASSOC;
Johannes Bergece9c4e2010-08-23 10:46:49 +02003613 priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM;
3614 priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN;
3615 priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY;
3616 priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID;
3617 priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION;
Johannes Berge72f3682010-08-23 10:46:51 +02003618 priv->contexts[IWL_RXON_CTX_PAN].ac_to_fifo = iwlagn_pan_ac_to_fifo;
3619 priv->contexts[IWL_RXON_CTX_PAN].ac_to_queue = iwlagn_pan_ac_to_queue;
3620 priv->contexts[IWL_RXON_CTX_PAN].mcast_queue = IWL_IPAN_MCAST_QUEUE;
Johannes Bergd0fe4782010-08-23 10:46:58 +02003621 priv->contexts[IWL_RXON_CTX_PAN].interface_modes =
3622 BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
Wey-Yi Guyf35c0c52011-01-13 17:09:29 -08003623#ifdef CONFIG_IWL_P2P
3624 priv->contexts[IWL_RXON_CTX_PAN].interface_modes |=
3625 BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO);
3626#endif
Johannes Bergd0fe4782010-08-23 10:46:58 +02003627 priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP;
3628 priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA;
3629 priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P;
Johannes Bergece9c4e2010-08-23 10:46:49 +02003630
3631 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
Wey-Yi Guyb2ea3452011-06-07 08:53:14 -07003632}
3633
Emmanuel Grumbachd5934112011-07-11 10:48:51 +03003634int iwl_probe(struct iwl_bus *bus, struct iwl_cfg *cfg)
Wey-Yi Guyb2ea3452011-06-07 08:53:14 -07003635{
3636 int err = 0;
3637 struct iwl_priv *priv;
3638 struct ieee80211_hw *hw;
Emmanuel Grumbach084dd7912011-05-31 09:07:00 +03003639 u16 num_mac;
Wey-Yi Guyb2ea3452011-06-07 08:53:14 -07003640 u32 hw_rev;
3641
3642 /************************
3643 * 1. Allocating HW data
3644 ************************/
Wey-Yi Guyb2ea3452011-06-07 08:53:14 -07003645 hw = iwl_alloc_all(cfg);
3646 if (!hw) {
3647 err = -ENOMEM;
Emmanuel Grumbach807caf22011-06-09 02:55:55 -07003648 goto out;
3649 }
3650
Wey-Yi Guyb2ea3452011-06-07 08:53:14 -07003651 priv = hw->priv;
Emmanuel Grumbachd5934112011-07-11 10:48:51 +03003652 priv->bus = bus;
3653 bus_set_drv_data(priv->bus, priv);
Emmanuel Grumbacha48709c2011-05-31 08:22:30 +03003654
Wey-Yi Guyb2ea3452011-06-07 08:53:14 -07003655 /* At this point both hw and priv are allocated. */
Johannes Berg8f2d3d22010-08-23 10:46:37 +02003656
Emmanuel Grumbachd5934112011-07-11 10:48:51 +03003657 SET_IEEE80211_DEV(hw, priv->bus->dev);
Zhu Yib481de92007-09-25 17:54:57 -07003658
Tomas Winklere1623442009-01-27 14:27:56 -08003659 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Tomas Winkler82b9a122008-03-04 18:09:30 -08003660 priv->cfg = cfg;
Mohamed Abbas40cefda2009-05-22 11:01:52 -07003661 priv->inta_mask = CSR_INI_SET_MASK;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003662
Wey-Yi Guybee008b2010-08-23 07:57:04 -07003663 /* is antenna coupling more than 35dB ? */
3664 priv->bt_ant_couple_ok =
3665 (iwlagn_ant_coupling > IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
3666 true : false;
3667
Wey-Yi Guy9f28ebc2010-11-26 13:24:19 -08003668 /* enable/disable bt channel inhibition */
Wey-Yi Guyf37837c2010-08-23 07:57:12 -07003669 priv->bt_ch_announce = iwlagn_bt_ch_announce;
Wey-Yi Guy9f28ebc2010-11-26 13:24:19 -08003670 IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n",
3671 (priv->bt_ch_announce) ? "On" : "Off");
Wey-Yi Guyf37837c2010-08-23 07:57:12 -07003672
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003673 if (iwl_alloc_traffic_mem(priv))
3674 IWL_ERR(priv, "Not enough memory to generate traffic log\n");
Zhu Yib481de92007-09-25 17:54:57 -07003675
Reinette Chatre731a29b2009-12-14 14:12:11 -08003676 /* these spin locks will be used in apm_ops.init and EEPROM access
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07003677 * we should init now
3678 */
3679 spin_lock_init(&priv->reg_lock);
Reinette Chatre731a29b2009-12-14 14:12:11 -08003680 spin_lock_init(&priv->lock);
Reinette Chatre4843b5a2010-02-03 09:38:59 -08003681
3682 /*
3683 * stop and reset the on-board processor just in case it is in a
3684 * strange state ... like being left stranded by a primary kernel
3685 * and this is now the kdump kernel trying to start up
3686 */
3687 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
3688
Emmanuel Grumbach084dd7912011-05-31 09:07:00 +03003689 /***********************
3690 * 3. Read REV register
3691 ***********************/
Johannes Berge98a1302011-04-05 09:42:08 -07003692 hw_rev = iwl_hw_detect(priv);
Shanyu Zhaoc11362c2010-03-05 17:05:20 -08003693 IWL_INFO(priv, "Detected %s, REV=0x%X\n",
Johannes Berge98a1302011-04-05 09:42:08 -07003694 priv->cfg->name, hw_rev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003695
Emmanuel Grumbach1e89cbac2011-07-20 17:51:22 -07003696 err = iwl_trans_register(&priv->trans, priv);
3697 if (err)
3698 goto out_free_traffic_mem;
3699
Emmanuel Grumbach41c50542011-07-11 08:51:04 +03003700 if (trans_prepare_card_hw(&priv->trans)) {
Emmanuel Grumbachbcd4fe22011-06-09 02:55:54 -07003701 err = -EIO;
Mohamed Abbas086ed112009-05-22 11:01:54 -07003702 IWL_WARN(priv, "Failed, HW not ready\n");
Emmanuel Grumbach1e89cbac2011-07-20 17:51:22 -07003703 goto out_free_trans;
Mohamed Abbas086ed112009-05-22 11:01:54 -07003704 }
3705
Assaf Krauss316c30d2008-03-14 10:38:46 -07003706 /*****************
3707 * 4. Read EEPROM
3708 *****************/
Assaf Krauss316c30d2008-03-14 10:38:46 -07003709 /* Read the EEPROM */
Johannes Berge98a1302011-04-05 09:42:08 -07003710 err = iwl_eeprom_init(priv, hw_rev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003711 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003712 IWL_ERR(priv, "Unable to init EEPROM\n");
Emmanuel Grumbach1e89cbac2011-07-20 17:51:22 -07003713 goto out_free_trans;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003714 }
Tomas Winkler8614f362008-04-23 17:14:55 -07003715 err = iwl_eeprom_check_version(priv);
3716 if (err)
Reinette Chatrec8f16132009-02-27 16:21:22 -08003717 goto out_free_eeprom;
Tomas Winkler8614f362008-04-23 17:14:55 -07003718
Wey-Yi Guy21a5b3c2010-11-10 13:32:59 -08003719 err = iwl_eeprom_check_sku(priv);
3720 if (err)
3721 goto out_free_eeprom;
3722
Ron Rindjunsky02883012008-05-15 13:53:53 +08003723 /* extract MAC Address */
Wey-Yi Guyc6fa17e2010-07-15 05:58:30 -07003724 iwl_eeprom_get_mac(priv, priv->addresses[0].addr);
3725 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
3726 priv->hw->wiphy->addresses = priv->addresses;
3727 priv->hw->wiphy->n_addresses = 1;
3728 num_mac = iwl_eeprom_query16(priv, EEPROM_NUM_MAC_ADDRESS);
3729 if (num_mac > 1) {
3730 memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
3731 ETH_ALEN);
3732 priv->addresses[1].addr[5]++;
3733 priv->hw->wiphy->n_addresses++;
3734 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07003735
Wey-Yi Guyb2ea3452011-06-07 08:53:14 -07003736 /* initialize all valid contexts */
3737 iwl_init_context(priv);
3738
Assaf Krauss316c30d2008-03-14 10:38:46 -07003739 /************************
3740 * 5. Setup HW constants
3741 ************************/
Ron Rindjunskyda154e302008-06-30 17:23:20 +08003742 if (iwl_set_hw_params(priv)) {
Emmanuel Grumbach084dd7912011-05-31 09:07:00 +03003743 err = -ENOENT;
Winkler, Tomas15b16872008-12-19 10:37:33 +08003744 IWL_ERR(priv, "failed to set hw parameters\n");
Tomas Winkler073d3f52008-04-21 15:41:52 -07003745 goto out_free_eeprom;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003746 }
3747
3748 /*******************
Tomas Winkler6ba87952008-05-15 13:54:17 +08003749 * 6. Setup priv
Assaf Krauss316c30d2008-03-14 10:38:46 -07003750 *******************/
Zhu Yib481de92007-09-25 17:54:57 -07003751
Tomas Winkler6ba87952008-05-15 13:54:17 +08003752 err = iwl_init_drv(priv);
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003753 if (err)
Ron Rindjunsky399f4902008-04-23 17:14:56 -07003754 goto out_free_eeprom;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003755 /* At this point both hw and priv are initialized. */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003756
Assaf Krauss316c30d2008-03-14 10:38:46 -07003757 /********************
Abhijeet Kolekar09f9bf72009-04-20 14:37:03 -07003758 * 7. Setup services
Assaf Krauss316c30d2008-03-14 10:38:46 -07003759 ********************/
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003760 iwl_setup_deferred_work(priv);
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08003761 iwl_setup_rx_handlers(priv);
Cindy H. Kao4613e722011-05-06 10:40:15 -07003762 iwl_testmode_init(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003763
Johannes Berg158bea02010-01-22 14:22:53 -08003764 /*********************************************
Emmanuel Grumbach084dd7912011-05-31 09:07:00 +03003765 * 8. Enable interrupts
Johannes Berg158bea02010-01-22 14:22:53 -08003766 *********************************************/
Tomas Winkler6ba87952008-05-15 13:54:17 +08003767
Stanislaw Gruszka554d1d02010-12-23 12:38:21 +01003768 iwl_enable_rfkill_int(priv);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003769
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003770 /* If platform's RF_KILL switch is NOT set to KILL */
3771 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3772 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3773 else
3774 set_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winkler6ba87952008-05-15 13:54:17 +08003775
Johannes Berga60e77e2009-06-04 18:26:06 +02003776 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
3777 test_bit(STATUS_RF_KILL_HW, &priv->status));
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003778
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08003779 iwl_power_initialize(priv);
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -07003780 iwl_tt_initialize(priv);
Johannes Berg158bea02010-01-22 14:22:53 -08003781
Wey-Yi Guy898ed672011-07-13 08:38:57 -07003782 init_completion(&priv->firmware_loading_complete);
Johannes Berg562db532010-04-29 07:41:53 -07003783
Johannes Bergb08dfd02010-01-29 11:54:56 -08003784 err = iwl_request_firmware(priv, true);
Johannes Berg158bea02010-01-22 14:22:53 -08003785 if (err)
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07003786 goto out_destroy_workqueue;
Johannes Berg158bea02010-01-22 14:22:53 -08003787
Zhu Yib481de92007-09-25 17:54:57 -07003788 return 0;
3789
Emmanuel Grumbach34c1b7b2011-07-04 08:58:19 +03003790out_destroy_workqueue:
Reinette Chatrec8f16132009-02-27 16:21:22 -08003791 destroy_workqueue(priv->workqueue);
3792 priv->workqueue = NULL;
Tomas Winkler6ba87952008-05-15 13:54:17 +08003793 iwl_uninit_drv(priv);
Emmanuel Grumbach34c1b7b2011-07-04 08:58:19 +03003794out_free_eeprom:
Tomas Winkler073d3f52008-04-21 15:41:52 -07003795 iwl_eeprom_free(priv);
Emmanuel Grumbach1e89cbac2011-07-20 17:51:22 -07003796out_free_trans:
3797 trans_free(&priv->trans);
Emmanuel Grumbach34c1b7b2011-07-04 08:58:19 +03003798out_free_traffic_mem:
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003799 iwl_free_traffic_mem(priv);
Wey-Yi Guyd7c76f42009-10-09 13:20:17 -07003800 ieee80211_free_hw(priv->hw);
Emmanuel Grumbach34c1b7b2011-07-04 08:58:19 +03003801out:
Zhu Yib481de92007-09-25 17:54:57 -07003802 return err;
3803}
3804
Emmanuel Grumbacha48709c2011-05-31 08:22:30 +03003805void __devexit iwl_remove(struct iwl_priv * priv)
Zhu Yib481de92007-09-25 17:54:57 -07003806{
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003807 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07003808
Wey-Yi Guy898ed672011-07-13 08:38:57 -07003809 wait_for_completion(&priv->firmware_loading_complete);
Johannes Berg562db532010-04-29 07:41:53 -07003810
Tomas Winklere1623442009-01-27 14:27:56 -08003811 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07003812
Emmanuel Grumbach67249622008-05-29 16:35:26 +08003813 iwl_dbgfs_unregister(priv);
Emmanuel Grumbachd5934112011-07-11 10:48:51 +03003814 sysfs_remove_group(&priv->bus->dev->kobj,
Emmanuel Grumbach3599d392011-05-31 08:52:10 +03003815 &iwl_attribute_group);
Emmanuel Grumbach67249622008-05-29 16:35:26 +08003816
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003817 /* ieee80211_unregister_hw call wil cause iwl_mac_stop to
3818 * to be called and iwl_down since we are removing the device
Gregory Greenman0b124c32008-09-03 11:18:50 +08003819 * we need to set STATUS_EXIT_PENDING bit.
3820 */
3821 set_bit(STATUS_EXIT_PENDING, &priv->status);
Wey-Yi Guy5ed540a2011-01-21 15:26:39 -08003822
Wey-Yi Guy7a4e5282011-05-06 10:21:28 -07003823 iwl_testmode_cleanup(priv);
Wey-Yi Guy5ed540a2011-01-21 15:26:39 -08003824 iwl_leds_exit(priv);
3825
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07003826 if (priv->mac80211_registered) {
3827 ieee80211_unregister_hw(priv->hw);
3828 priv->mac80211_registered = 0;
3829 }
3830
Johannes Berg1a10f432011-04-13 03:14:44 -07003831 /* Reset to low power before unloading driver. */
Johannes Berg14e8e4a2010-09-22 18:02:10 +02003832 iwl_apm_stop(priv);
Ben Cahillc166b252009-10-23 13:42:35 -07003833
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -07003834 iwl_tt_exit(priv);
3835
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003836 /* make sure we flush any pending irq or
3837 * tasklet for the driver
3838 */
3839 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003840 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003841 spin_unlock_irqrestore(&priv->lock, flags);
3842
Emmanuel Grumbach41c50542011-07-11 08:51:04 +03003843 trans_sync_irq(&priv->trans);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003844
Emmanuel Grumbach3599d392011-05-31 08:52:10 +03003845 iwl_dealloc_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003846
Emmanuel Grumbach41c50542011-07-11 08:51:04 +03003847 trans_rx_free(&priv->trans);
3848 trans_tx_free(&priv->trans);
Zhu Yib481de92007-09-25 17:54:57 -07003849
Tomas Winkler073d3f52008-04-21 15:41:52 -07003850 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003851
Mohamed Abbas948c1712007-10-25 17:15:45 +08003852 /*netif_stop_queue(dev); */
3853 flush_workqueue(priv->workqueue);
3854
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003855 /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07003856 * priv->workqueue... so we can't take down the workqueue
3857 * until now... */
3858 destroy_workqueue(priv->workqueue);
3859 priv->workqueue = NULL;
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003860 iwl_free_traffic_mem(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003861
Emmanuel Grumbach41c50542011-07-11 08:51:04 +03003862 trans_free(&priv->trans);
Emmanuel Grumbach34c1b7b2011-07-04 08:58:19 +03003863
Emmanuel Grumbachd5934112011-07-11 10:48:51 +03003864 bus_set_drv_data(priv->bus, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07003865
Tomas Winkler6ba87952008-05-15 13:54:17 +08003866 iwl_uninit_drv(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003867
Johannes Berg77834542010-10-04 05:50:36 -07003868 dev_kfree_skb(priv->beacon_skb);
Zhu Yib481de92007-09-25 17:54:57 -07003869
3870 ieee80211_free_hw(priv->hw);
3871}
3872
Zhu Yib481de92007-09-25 17:54:57 -07003873
3874/*****************************************************************************
3875 *
3876 * driver and module entry point
3877 *
3878 *****************************************************************************/
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003879static int __init iwl_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07003880{
3881
3882 int ret;
Joe Perchesc96c31e2010-07-26 14:39:58 -07003883 pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
3884 pr_info(DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003885
Tomas Winklere227cea2008-07-18 13:53:05 +08003886 ret = iwlagn_rate_control_register();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003887 if (ret) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07003888 pr_err("Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003889 return ret;
3890 }
3891
Emmanuel Grumbach48d1a212011-05-24 11:39:02 +03003892 ret = iwl_pci_register_driver();
Zhu Yib481de92007-09-25 17:54:57 -07003893
Emmanuel Grumbach48d1a212011-05-24 11:39:02 +03003894 if (ret)
3895 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07003896 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003897
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003898error_register:
Tomas Winklere227cea2008-07-18 13:53:05 +08003899 iwlagn_rate_control_unregister();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07003900 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003901}
3902
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003903static void __exit iwl_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07003904{
Emmanuel Grumbach48d1a212011-05-24 11:39:02 +03003905 iwl_pci_unregister_driver();
Tomas Winklere227cea2008-07-18 13:53:05 +08003906 iwlagn_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07003907}
3908
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003909module_exit(iwl_exit);
3910module_init(iwl_init);
Reinette Chatrea562a9d2009-07-17 09:30:24 -07003911
3912#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07003913module_param_named(debug, iwl_debug_level, uint, S_IRUGO | S_IWUSR);
Reinette Chatrea562a9d2009-07-17 09:30:24 -07003914MODULE_PARM_DESC(debug, "debug output mask");
3915#endif
3916
Wey-Yi Guy2b068612010-03-22 09:17:39 -07003917module_param_named(swcrypto, iwlagn_mod_params.sw_crypto, int, S_IRUGO);
3918MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
Wey-Yi Guy2b068612010-03-22 09:17:39 -07003919module_param_named(queues_num, iwlagn_mod_params.num_of_queues, int, S_IRUGO);
3920MODULE_PARM_DESC(queues_num, "number of hw queues.");
Wey-Yi Guy2b068612010-03-22 09:17:39 -07003921module_param_named(11n_disable, iwlagn_mod_params.disable_11n, int, S_IRUGO);
3922MODULE_PARM_DESC(11n_disable, "disable 11n functionality");
Wey-Yi Guy2b068612010-03-22 09:17:39 -07003923module_param_named(amsdu_size_8K, iwlagn_mod_params.amsdu_size_8K,
3924 int, S_IRUGO);
3925MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
Wey-Yi Guy2b068612010-03-22 09:17:39 -07003926module_param_named(fw_restart, iwlagn_mod_params.restart_fw, int, S_IRUGO);
3927MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");
Johannes Bergdd7a2502010-04-28 23:33:10 -07003928
3929module_param_named(ucode_alternative, iwlagn_wanted_ucode_alternative, int,
3930 S_IRUGO);
3931MODULE_PARM_DESC(ucode_alternative,
3932 "specify ucode alternative to use from ucode file");
Wey-Yi Guybee008b2010-08-23 07:57:04 -07003933
3934module_param_named(antenna_coupling, iwlagn_ant_coupling, int, S_IRUGO);
3935MODULE_PARM_DESC(antenna_coupling,
3936 "specify antenna coupling in dB (defualt: 0 dB)");
Wey-Yi Guyf37837c2010-08-23 07:57:12 -07003937
Wey-Yi Guy9f28ebc2010-11-26 13:24:19 -08003938module_param_named(bt_ch_inhibition, iwlagn_bt_ch_announce, bool, S_IRUGO);
3939MODULE_PARM_DESC(bt_ch_inhibition,
3940 "Disable BT channel inhibition (default: enable)");
Stanislaw Gruszkab7977ff2011-02-28 14:33:15 +01003941
3942module_param_named(plcp_check, iwlagn_mod_params.plcp_check, bool, S_IRUGO);
3943MODULE_PARM_DESC(plcp_check, "Check plcp health (default: 1 [enabled])");
3944
3945module_param_named(ack_check, iwlagn_mod_params.ack_check, bool, S_IRUGO);
3946MODULE_PARM_DESC(ack_check, "Check ack health (default: 0 [disabled])");
Wey-Yi Guyb60eec92011-06-03 13:52:38 -07003947
Wey-Yi Guy300d0832011-06-25 09:17:41 -07003948module_param_named(wd_disable, iwlagn_mod_params.wd_disable, bool, S_IRUGO);
3949MODULE_PARM_DESC(wd_disable,
3950 "Disable stuck queue watchdog timer (default: 0 [enabled])");
3951
Wey-Yi Guyb60eec92011-06-03 13:52:38 -07003952/*
3953 * set bt_coex_active to true, uCode will do kill/defer
3954 * every time the priority line is asserted (BT is sending signals on the
3955 * priority line in the PCIx).
3956 * set bt_coex_active to false, uCode will ignore the BT activity and
3957 * perform the normal operation
3958 *
3959 * User might experience transmit issue on some platform due to WiFi/BT
3960 * co-exist problem. The possible behaviors are:
3961 * Able to scan and finding all the available AP
3962 * Not able to associate with any AP
3963 * On those platforms, WiFi communication can be restored by set
3964 * "bt_coex_active" module parameter to "false"
3965 *
3966 * default: bt_coex_active = true (BT_COEX_ENABLE)
3967 */
3968module_param_named(bt_coex_active, iwlagn_mod_params.bt_coex_active,
3969 bool, S_IRUGO);
3970MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)");
Wey-Yi Guy6b0184c2011-06-03 13:52:39 -07003971
3972module_param_named(led_mode, iwlagn_mod_params.led_mode, int, S_IRUGO);
3973MODULE_PARM_DESC(led_mode, "0=system default, "
3974 "1=On(RF On)/Off(RF Off), 2=blinking (default: 0)");
Wey-Yi Guy3f1e5f42011-06-03 13:52:40 -07003975
Wey-Yi Guy0172b022011-06-11 10:00:05 -07003976module_param_named(power_save, iwlagn_mod_params.power_save,
3977 bool, S_IRUGO);
3978MODULE_PARM_DESC(power_save,
3979 "enable WiFi power management (default: disable)");
3980
Wey-Yi Guyf7538162011-06-11 10:00:06 -07003981module_param_named(power_level, iwlagn_mod_params.power_level,
3982 int, S_IRUGO);
3983MODULE_PARM_DESC(power_level,
3984 "default power save level (range from 1 - 5, default: 1)");
3985
Wey-Yi Guy3f1e5f42011-06-03 13:52:40 -07003986/*
3987 * For now, keep using power level 1 instead of automatically
3988 * adjusting ...
3989 */
3990module_param_named(no_sleep_autoadjust, iwlagn_mod_params.no_sleep_autoadjust,
3991 bool, S_IRUGO);
3992MODULE_PARM_DESC(no_sleep_autoadjust,
3993 "don't automatically adjust sleep level "
3994 "according to maximum network latency (default: true)");