blob: 3ecc3198d9bf9f089d567c5afbcaec6bc5068e57 [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Wey-Yi Guy901069c2011-04-05 09:42:00 -07003 * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
Zhu Yib481de92007-09-25 17:54:57 -07004 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
Winkler, Tomas759ef892008-12-09 11:28:58 -080025 * Intel Linux Wireless <ilw@linux.intel.com>
Zhu Yib481de92007-09-25 17:54:57 -070026 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
Joe Perchesc96c31e2010-07-26 14:39:58 -070030#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31
Zhu Yib481de92007-09-25 17:54:57 -070032#include <linux/kernel.h>
33#include <linux/module.h>
Zhu Yib481de92007-09-25 17:54:57 -070034#include <linux/init.h>
35#include <linux/pci.h>
John W. Linville1a7123c2010-08-05 14:39:31 -040036#include <linux/pci-aspm.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090037#include <linux/slab.h>
Zhu Yib481de92007-09-25 17:54:57 -070038#include <linux/dma-mapping.h>
39#include <linux/delay.h>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040040#include <linux/sched.h>
Zhu Yib481de92007-09-25 17:54:57 -070041#include <linux/skbuff.h>
42#include <linux/netdevice.h>
43#include <linux/wireless.h>
44#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070045#include <linux/etherdevice.h>
46#include <linux/if_arp.h>
47
Zhu Yib481de92007-09-25 17:54:57 -070048#include <net/mac80211.h>
49
50#include <asm/div64.h>
51
Samuel Ortiza3139c52008-12-19 10:37:09 +080052#define DRV_NAME "iwlagn"
53
Assaf Krauss6bc913b2008-03-11 16:17:18 -070054#include "iwl-eeprom.h"
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070055#include "iwl-dev.h"
Tomas Winklerfee12472008-04-03 16:05:21 -070056#include "iwl-core.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070057#include "iwl-io.h"
Zhu Yib481de92007-09-25 17:54:57 -070058#include "iwl-helpers.h"
Emmanuel Grumbach6974e362008-04-14 21:16:06 -070059#include "iwl-sta.h"
Johannes Berg0de76732010-09-22 18:02:11 +020060#include "iwl-agn-calib.h"
Johannes Berga1175122010-01-21 06:21:10 -080061#include "iwl-agn.h"
Zhu Yib481de92007-09-25 17:54:57 -070062
Christoph Hellwig416e1432007-10-25 17:15:49 +080063
Zhu Yib481de92007-09-25 17:54:57 -070064/******************************************************************************
65 *
66 * module boiler plate
67 *
68 ******************************************************************************/
69
Zhu Yib481de92007-09-25 17:54:57 -070070/*
71 * module name, copyright, version, etc.
Zhu Yib481de92007-09-25 17:54:57 -070072 */
Tomas Winklerd783b062008-07-18 13:53:02 +080073#define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
Zhu Yib481de92007-09-25 17:54:57 -070074
Tomas Winkler0a6857e2008-03-12 16:58:49 -070075#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070076#define VD "d"
77#else
78#define VD
79#endif
80
Reinette Chatre81963d62010-01-22 14:22:57 -080081#define DRV_VERSION IWLWIFI_VERSION VD
Zhu Yib481de92007-09-25 17:54:57 -070082
Zhu Yib481de92007-09-25 17:54:57 -070083
84MODULE_DESCRIPTION(DRV_DESCRIPTION);
85MODULE_VERSION(DRV_VERSION);
Tomas Winklera7b75202008-12-11 10:33:41 -080086MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
Zhu Yib481de92007-09-25 17:54:57 -070087MODULE_LICENSE("GPL");
88
Wey-Yi Guybee008b2010-08-23 07:57:04 -070089static int iwlagn_ant_coupling;
Wey-Yi Guyf37837c2010-08-23 07:57:12 -070090static bool iwlagn_bt_ch_announce = 1;
Wey-Yi Guybee008b2010-08-23 07:57:04 -070091
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -070092void iwl_update_chain_flags(struct iwl_priv *priv)
Mohamed Abbas5da4b552008-04-21 15:41:51 -070093{
Johannes Berg246ed352010-08-23 10:46:32 +020094 struct iwl_rxon_context *ctx;
Mohamed Abbas5da4b552008-04-21 15:41:51 -070095
Johannes Berg246ed352010-08-23 10:46:32 +020096 if (priv->cfg->ops->hcmd->set_rxon_chain) {
97 for_each_context(priv, ctx) {
98 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
Shanyu Zhao6163a372010-11-12 13:48:13 -080099 if (ctx->active.rx_chain != ctx->staging.rx_chain)
100 iwlcore_commit_rxon(priv, ctx);
Johannes Berg246ed352010-08-23 10:46:32 +0200101 }
102 }
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700103}
104
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800105/* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
106static void iwl_set_beacon_tim(struct iwl_priv *priv,
Johannes Berg77834542010-10-04 05:50:36 -0700107 struct iwl_tx_beacon_cmd *tx_beacon_cmd,
108 u8 *beacon, u32 frame_size)
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800109{
110 u16 tim_idx;
111 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
112
113 /*
114 * The index is relative to frame start but we start looking at the
115 * variable-length part of the beacon.
116 */
117 tim_idx = mgmt->u.beacon.variable - beacon;
118
119 /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
120 while ((tim_idx < (frame_size - 2)) &&
121 (beacon[tim_idx] != WLAN_EID_TIM))
122 tim_idx += beacon[tim_idx+1] + 2;
123
124 /* If TIM field was found, set variables */
125 if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
126 tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
127 tx_beacon_cmd->tim_size = beacon[tim_idx+1];
128 } else
129 IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
130}
131
Johannes Berg8a98d492011-04-29 09:48:14 -0700132int iwlagn_send_beacon_cmd(struct iwl_priv *priv)
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800133{
134 struct iwl_tx_beacon_cmd *tx_beacon_cmd;
Johannes Berg8a98d492011-04-29 09:48:14 -0700135 struct iwl_host_cmd cmd = {
136 .id = REPLY_TX_BEACON,
137 .flags = CMD_SIZE_HUGE,
138 };
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800139 u32 frame_size;
140 u32 rate_flags;
141 u32 rate;
Johannes Berg8a98d492011-04-29 09:48:14 -0700142 int err;
143
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800144 /*
145 * We have to set up the TX command, the TX Beacon command, and the
146 * beacon contents.
147 */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800148
Johannes Berg76d04812010-08-23 10:46:47 +0200149 lockdep_assert_held(&priv->mutex);
150
151 if (!priv->beacon_ctx) {
152 IWL_ERR(priv, "trying to build beacon w/o beacon context!\n");
Julia Lawall950094c2010-09-05 21:00:26 +0200153 return 0;
Johannes Berg76d04812010-08-23 10:46:47 +0200154 }
155
Johannes Berg8a98d492011-04-29 09:48:14 -0700156 if (WARN_ON(!priv->beacon_skb))
157 return -EINVAL;
158
159 /* Allocate beacon memory */
160 tx_beacon_cmd = kzalloc(sizeof(*tx_beacon_cmd) + priv->beacon_skb->len,
161 GFP_KERNEL);
162 if (!tx_beacon_cmd)
163 return -ENOMEM;
164
165 frame_size = priv->beacon_skb->len;
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800166
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800167 /* Set up TX beacon contents */
Johannes Berg8a98d492011-04-29 09:48:14 -0700168 memcpy(tx_beacon_cmd->frame, priv->beacon_skb->data, frame_size);
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800169
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800170 /* Set up TX command fields */
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800171 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
Johannes Berg76d04812010-08-23 10:46:47 +0200172 tx_beacon_cmd->tx.sta_id = priv->beacon_ctx->bcast_sta_id;
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800173 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800174 tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800175 TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
176
177 /* Set up TX beacon command fields */
178 iwl_set_beacon_tim(priv, tx_beacon_cmd, (u8 *)tx_beacon_cmd->frame,
Johannes Berg77834542010-10-04 05:50:36 -0700179 frame_size);
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800180
181 /* Set up packet rate and flags */
Johannes Berg76d04812010-08-23 10:46:47 +0200182 rate = iwl_rate_get_lowest_plcp(priv, priv->beacon_ctx);
Johannes Berg0e1654f2010-05-18 02:48:36 -0700183 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
184 priv->hw_params.valid_tx_ant);
Daniel C Halperin47ff65c2009-11-13 11:56:33 -0800185 rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
186 if ((rate >= IWL_FIRST_CCK_RATE) && (rate <= IWL_LAST_CCK_RATE))
187 rate_flags |= RATE_MCS_CCK_MSK;
188 tx_beacon_cmd->tx.rate_n_flags = iwl_hw_set_rate_n_flags(rate,
189 rate_flags);
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800190
Johannes Berg8a98d492011-04-29 09:48:14 -0700191 /* Submit command */
192 cmd.len = sizeof(*tx_beacon_cmd) + frame_size;
193 cmd.data = tx_beacon_cmd;
Johannes Berg2295c662010-10-23 09:15:41 -0700194
Johannes Berg8a98d492011-04-29 09:48:14 -0700195 err = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700196
Johannes Berg8a98d492011-04-29 09:48:14 -0700197 /* Free temporary storage */
198 kfree(tx_beacon_cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700199
Johannes Berg8a98d492011-04-29 09:48:14 -0700200 return err;
Zhu Yib481de92007-09-25 17:54:57 -0700201}
202
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800203static inline dma_addr_t iwl_tfd_tb_get_addr(struct iwl_tfd *tfd, u8 idx)
204{
205 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
206
207 dma_addr_t addr = get_unaligned_le32(&tb->lo);
208 if (sizeof(dma_addr_t) > sizeof(u32))
209 addr |=
210 ((dma_addr_t)(le16_to_cpu(tb->hi_n_len) & 0xF) << 16) << 16;
211
212 return addr;
213}
214
215static inline u16 iwl_tfd_tb_get_len(struct iwl_tfd *tfd, u8 idx)
216{
217 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
218
219 return le16_to_cpu(tb->hi_n_len) >> 4;
220}
221
222static inline void iwl_tfd_set_tb(struct iwl_tfd *tfd, u8 idx,
223 dma_addr_t addr, u16 len)
224{
225 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
226 u16 hi_n_len = len << 4;
227
228 put_unaligned_le32(addr, &tb->lo);
229 if (sizeof(dma_addr_t) > sizeof(u32))
230 hi_n_len |= ((addr >> 16) >> 16) & 0xF;
231
232 tb->hi_n_len = cpu_to_le16(hi_n_len);
233
234 tfd->num_tbs = idx + 1;
235}
236
237static inline u8 iwl_tfd_get_num_tbs(struct iwl_tfd *tfd)
238{
239 return tfd->num_tbs & 0x1f;
240}
241
242/**
243 * iwl_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
244 * @priv - driver private data
245 * @txq - tx queue
246 *
247 * Does NOT advance any TFD circular buffer read/write indexes
248 * Does NOT free the TFD itself (which is within circular buffer)
249 */
250void iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq)
251{
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800252 struct iwl_tfd *tfd_tmp = (struct iwl_tfd *)txq->tfds;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800253 struct iwl_tfd *tfd;
254 struct pci_dev *dev = priv->pci_dev;
255 int index = txq->q.read_ptr;
256 int i;
257 int num_tbs;
258
259 tfd = &tfd_tmp[index];
260
261 /* Sanity check on number of chunks */
262 num_tbs = iwl_tfd_get_num_tbs(tfd);
263
264 if (num_tbs >= IWL_NUM_OF_TBS) {
265 IWL_ERR(priv, "Too many chunks: %i\n", num_tbs);
266 /* @todo issue fatal error, it is quite serious situation */
267 return;
268 }
269
270 /* Unmap tx_cmd */
271 if (num_tbs)
272 pci_unmap_single(dev,
FUJITA Tomonori2e724442010-06-03 14:19:20 +0900273 dma_unmap_addr(&txq->meta[index], mapping),
274 dma_unmap_len(&txq->meta[index], len),
Fenghua Yu96891ce2009-02-18 15:54:33 -0800275 PCI_DMA_BIDIRECTIONAL);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800276
277 /* Unmap chunks, if any. */
Johannes Bergff0d91c2010-05-17 02:37:34 -0700278 for (i = 1; i < num_tbs; i++)
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800279 pci_unmap_single(dev, iwl_tfd_tb_get_addr(tfd, i),
280 iwl_tfd_tb_get_len(tfd, i), PCI_DMA_TODEVICE);
281
Johannes Bergff0d91c2010-05-17 02:37:34 -0700282 /* free SKB */
283 if (txq->txb) {
284 struct sk_buff *skb;
Johannes Berg6f802402010-05-17 02:37:32 -0700285
Johannes Bergff0d91c2010-05-17 02:37:34 -0700286 skb = txq->txb[txq->q.read_ptr].skb;
Johannes Berg6f802402010-05-17 02:37:32 -0700287
Johannes Bergff0d91c2010-05-17 02:37:34 -0700288 /* can be called from irqs-disabled context */
289 if (skb) {
290 dev_kfree_skb_any(skb);
291 txq->txb[txq->q.read_ptr].skb = NULL;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800292 }
293 }
294}
295
296int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv,
297 struct iwl_tx_queue *txq,
298 dma_addr_t addr, u16 len,
299 u8 reset, u8 pad)
300{
301 struct iwl_queue *q;
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800302 struct iwl_tfd *tfd, *tfd_tmp;
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800303 u32 num_tbs;
304
305 q = &txq->q;
Samuel Ortiz59606ff2009-01-23 13:45:13 -0800306 tfd_tmp = (struct iwl_tfd *)txq->tfds;
307 tfd = &tfd_tmp[q->write_ptr];
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800308
309 if (reset)
310 memset(tfd, 0, sizeof(*tfd));
311
312 num_tbs = iwl_tfd_get_num_tbs(tfd);
313
314 /* Each TFD can point to a maximum 20 Tx buffers */
315 if (num_tbs >= IWL_NUM_OF_TBS) {
316 IWL_ERR(priv, "Error can not send more than %d chunks\n",
317 IWL_NUM_OF_TBS);
318 return -EINVAL;
319 }
320
Johannes Berg3e41ace2011-04-18 09:12:37 -0700321 if (WARN_ON(addr & ~DMA_BIT_MASK(36)))
322 return -EINVAL;
323
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800324 if (unlikely(addr & ~IWL_TX_DMA_MASK))
325 IWL_ERR(priv, "Unaligned address = %llx\n",
326 (unsigned long long)addr);
327
328 iwl_tfd_set_tb(tfd, num_tbs, addr, len);
329
330 return 0;
331}
332
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800333/*
334 * Tell nic where to find circular buffer of Tx Frame Descriptors for
335 * given Tx queue, and enable the DMA channel used for that queue.
336 *
Wey-Yi Guyf7d046f2011-03-22 08:05:37 -0700337 * supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800338 * channels supported in hardware.
339 */
340int iwl_hw_tx_queue_init(struct iwl_priv *priv,
341 struct iwl_tx_queue *txq)
342{
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800343 int txq_id = txq->q.id;
344
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800345 /* Circular buffer (TFD queue in DRAM) physical base address */
346 iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
347 txq->q.dma_addr >> 8);
348
Samuel Ortiza8e74e272009-01-23 13:45:14 -0800349 return 0;
350}
351
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700352static void iwl_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -0700353{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700354 struct iwl_priv *priv =
355 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -0700356 struct sk_buff *beacon;
357
Johannes Berg76d04812010-08-23 10:46:47 +0200358 mutex_lock(&priv->mutex);
359 if (!priv->beacon_ctx) {
360 IWL_ERR(priv, "updating beacon w/o beacon context!\n");
361 goto out;
Zhu Yib481de92007-09-25 17:54:57 -0700362 }
363
Johannes Berg60744f62010-08-23 10:46:50 +0200364 if (priv->beacon_ctx->vif->type != NL80211_IFTYPE_AP) {
365 /*
366 * The ucode will send beacon notifications even in
367 * IBSS mode, but we don't want to process them. But
368 * we need to defer the type check to here due to
369 * requiring locking around the beacon_ctx access.
370 */
371 goto out;
372 }
373
Johannes Berg76d04812010-08-23 10:46:47 +0200374 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
375 beacon = ieee80211_beacon_get(priv->hw, priv->beacon_ctx->vif);
376 if (!beacon) {
Johannes Berg77834542010-10-04 05:50:36 -0700377 IWL_ERR(priv, "update beacon failed -- keeping old\n");
Johannes Berg76d04812010-08-23 10:46:47 +0200378 goto out;
379 }
380
Zhu Yib481de92007-09-25 17:54:57 -0700381 /* new beacon skb is allocated every time; dispose previous.*/
Johannes Berg77834542010-10-04 05:50:36 -0700382 dev_kfree_skb(priv->beacon_skb);
Zhu Yib481de92007-09-25 17:54:57 -0700383
Johannes Berg12e934d2010-10-04 05:50:06 -0700384 priv->beacon_skb = beacon;
Zhu Yib481de92007-09-25 17:54:57 -0700385
Johannes Berg2295c662010-10-23 09:15:41 -0700386 iwlagn_send_beacon_cmd(priv);
Johannes Berg76d04812010-08-23 10:46:47 +0200387 out:
388 mutex_unlock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -0700389}
390
Wey-Yi Guyfbba9412010-08-23 07:57:10 -0700391static void iwl_bg_bt_runtime_config(struct work_struct *work)
392{
393 struct iwl_priv *priv =
394 container_of(work, struct iwl_priv, bt_runtime_config);
395
396 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
397 return;
398
399 /* dont send host command if rf-kill is on */
400 if (!iwl_is_ready_rf(priv))
401 return;
402 priv->cfg->ops->hcmd->send_bt_config(priv);
403}
404
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700405static void iwl_bg_bt_full_concurrency(struct work_struct *work)
406{
407 struct iwl_priv *priv =
408 container_of(work, struct iwl_priv, bt_full_concurrency);
Johannes Berg246ed352010-08-23 10:46:32 +0200409 struct iwl_rxon_context *ctx;
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700410
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +0200411 mutex_lock(&priv->mutex);
412
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700413 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +0200414 goto out;
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700415
416 /* dont send host command if rf-kill is on */
417 if (!iwl_is_ready_rf(priv))
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +0200418 goto out;
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700419
420 IWL_DEBUG_INFO(priv, "BT coex in %s mode\n",
421 priv->bt_full_concurrent ?
422 "full concurrency" : "3-wire");
423
424 /*
425 * LQ & RXON updated cmds must be sent before BT Config cmd
426 * to avoid 3-wire collisions
427 */
Johannes Berg246ed352010-08-23 10:46:32 +0200428 for_each_context(priv, ctx) {
429 if (priv->cfg->ops->hcmd->set_rxon_chain)
430 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
431 iwlcore_commit_rxon(priv, ctx);
432 }
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700433
434 priv->cfg->ops->hcmd->send_bt_config(priv);
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +0200435out:
436 mutex_unlock(&priv->mutex);
Wey-Yi Guybee008b2010-08-23 07:57:04 -0700437}
438
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800439/**
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700440 * iwl_bg_statistics_periodic - Timer callback to queue statistics
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800441 *
442 * This callback is provided in order to send a statistics request.
443 *
444 * This timer function is continually reset to execute within
445 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
446 * was received. We need to ensure we receive the statistics in order
447 * to update the temperature used for calibrating the TXPOWER.
448 */
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700449static void iwl_bg_statistics_periodic(unsigned long data)
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800450{
451 struct iwl_priv *priv = (struct iwl_priv *)data;
452
453 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
454 return;
455
Mohamed Abbas61780ee2008-10-29 14:05:49 -0700456 /* dont send host command if rf-kill is on */
457 if (!iwl_is_ready_rf(priv))
458 return;
459
Wey-Yi Guyef8d5522009-11-13 11:56:28 -0800460 iwl_send_statistics_request(priv, CMD_ASYNC, false);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +0800461}
462
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800463
464static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base,
465 u32 start_idx, u32 num_events,
466 u32 mode)
467{
468 u32 i;
469 u32 ptr; /* SRAM byte address of log data */
470 u32 ev, time, data; /* event log data */
471 unsigned long reg_flags;
472
473 if (mode == 0)
474 ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32));
475 else
476 ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32));
477
478 /* Make sure device is powered up for SRAM reads */
479 spin_lock_irqsave(&priv->reg_lock, reg_flags);
480 if (iwl_grab_nic_access(priv)) {
481 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
482 return;
483 }
484
485 /* Set starting address; reads will auto-increment */
Johannes Berg02a7fa02011-04-05 09:42:12 -0700486 iwl_write32(priv, HBUS_TARG_MEM_RADDR, ptr);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800487 rmb();
488
489 /*
490 * "time" is actually "data" for mode 0 (no timestamp).
491 * place event id # at far right for easier visual parsing.
492 */
493 for (i = 0; i < num_events; i++) {
Johannes Berg02a7fa02011-04-05 09:42:12 -0700494 ev = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
495 time = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800496 if (mode == 0) {
497 trace_iwlwifi_dev_ucode_cont_event(priv,
498 0, time, ev);
499 } else {
Johannes Berg02a7fa02011-04-05 09:42:12 -0700500 data = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800501 trace_iwlwifi_dev_ucode_cont_event(priv,
502 time, data, ev);
503 }
504 }
505 /* Allow device to power down */
506 iwl_release_nic_access(priv);
507 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
508}
509
Johannes Berg875295f2010-01-22 14:22:55 -0800510static void iwl_continuous_event_trace(struct iwl_priv *priv)
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800511{
512 u32 capacity; /* event log capacity in # entries */
513 u32 base; /* SRAM byte address of event log header */
514 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
515 u32 num_wraps; /* # times uCode wrapped to top of log */
516 u32 next_entry; /* index of next entry to be written by uCode */
517
Johannes Bergd7d57832011-04-05 09:42:04 -0700518 base = priv->device_pointers.error_event_table;
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -0800519 if (priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
520 capacity = iwl_read_targ_mem(priv, base);
521 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
522 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
523 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
524 } else
525 return;
526
527 if (num_wraps == priv->event_log.num_wraps) {
528 iwl_print_cont_event_trace(priv,
529 base, priv->event_log.next_entry,
530 next_entry - priv->event_log.next_entry,
531 mode);
532 priv->event_log.non_wraps_count++;
533 } else {
534 if ((num_wraps - priv->event_log.num_wraps) > 1)
535 priv->event_log.wraps_more_count++;
536 else
537 priv->event_log.wraps_once_count++;
538 trace_iwlwifi_dev_ucode_wrap_event(priv,
539 num_wraps - priv->event_log.num_wraps,
540 next_entry, priv->event_log.next_entry);
541 if (next_entry < priv->event_log.next_entry) {
542 iwl_print_cont_event_trace(priv, base,
543 priv->event_log.next_entry,
544 capacity - priv->event_log.next_entry,
545 mode);
546
547 iwl_print_cont_event_trace(priv, base, 0,
548 next_entry, mode);
549 } else {
550 iwl_print_cont_event_trace(priv, base,
551 next_entry, capacity - next_entry,
552 mode);
553
554 iwl_print_cont_event_trace(priv, base, 0,
555 next_entry, mode);
556 }
557 }
558 priv->event_log.num_wraps = num_wraps;
559 priv->event_log.next_entry = next_entry;
560}
561
562/**
563 * iwl_bg_ucode_trace - Timer callback to log ucode event
564 *
565 * The timer is continually set to execute every
566 * UCODE_TRACE_PERIOD milliseconds after the last timer expired
567 * this function is to perform continuous uCode event logging operation
568 * if enabled
569 */
570static void iwl_bg_ucode_trace(unsigned long data)
571{
572 struct iwl_priv *priv = (struct iwl_priv *)data;
573
574 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
575 return;
576
577 if (priv->event_log.ucode_trace) {
578 iwl_continuous_event_trace(priv);
579 /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
580 mod_timer(&priv->ucode_trace,
581 jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
582 }
583}
584
Wey-Yi Guy65550632010-06-24 13:18:35 -0700585static void iwl_bg_tx_flush(struct work_struct *work)
586{
587 struct iwl_priv *priv =
588 container_of(work, struct iwl_priv, tx_flush);
589
590 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
591 return;
592
593 /* do nothing if rf-kill is on */
594 if (!iwl_is_ready_rf(priv))
595 return;
596
597 if (priv->cfg->ops->lib->txfifo_flush) {
598 IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n");
599 iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
600 }
601}
602
Zhu Yib481de92007-09-25 17:54:57 -0700603/**
Tomas Winklera55360e2008-05-05 10:22:28 +0800604 * iwl_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -0700605 *
606 * Uses the priv->rx_handlers callback function array to invoke
607 * the appropriate handlers, including command responses,
608 * frame-received notifications, and other notifications.
609 */
Johannes Bergf945f102011-01-04 16:21:59 -0800610static void iwl_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700611{
Tomas Winklera55360e2008-05-05 10:22:28 +0800612 struct iwl_rx_mem_buffer *rxb;
Tomas Winklerdb11d632008-05-05 10:22:33 +0800613 struct iwl_rx_packet *pkt;
Tomas Winklera55360e2008-05-05 10:22:28 +0800614 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -0700615 u32 r, i;
616 int reclaim;
617 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800618 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -0800619 u32 count = 8;
Mohamed Abbas4752c932009-05-22 11:01:51 -0700620 int total_empty;
Zhu Yib481de92007-09-25 17:54:57 -0700621
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800622 /* uCode's read index (stored in shared DRAM) indicates the last Rx
623 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8d864222008-11-07 09:58:39 -0800624 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -0700625 i = rxq->read;
626
627 /* Rx interrupt, but nothing sent from uCode */
628 if (i == r)
Tomas Winklere1623442009-01-27 14:27:56 -0800629 IWL_DEBUG_RX(priv, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -0700630
Mohamed Abbas4752c932009-05-22 11:01:51 -0700631 /* calculate total frames need to be restock after handling RX */
Zhu Yi73005152009-10-23 13:42:32 -0700632 total_empty = r - rxq->write_actual;
Mohamed Abbas4752c932009-05-22 11:01:51 -0700633 if (total_empty < 0)
634 total_empty += RX_QUEUE_SIZE;
635
636 if (total_empty > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800637 fill_rx = 1;
638
Zhu Yib481de92007-09-25 17:54:57 -0700639 while (i != r) {
Johannes Bergf4989d92010-05-28 04:08:30 -0700640 int len;
641
Zhu Yib481de92007-09-25 17:54:57 -0700642 rxb = rxq->queue[i];
643
Ben Cahill9fbab512007-11-29 11:09:47 +0800644 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -0700645 * then a bug has been introduced in the queue refilling
646 * routines -- catch it here */
Johannes Berg3e41ace2011-04-18 09:12:37 -0700647 if (WARN_ON(rxb == NULL)) {
648 i = (i + 1) & RX_QUEUE_MASK;
649 continue;
650 }
Zhu Yib481de92007-09-25 17:54:57 -0700651
652 rxq->queue[i] = NULL;
653
Zhu Yi2f301222009-10-09 17:19:45 +0800654 pci_unmap_page(priv->pci_dev, rxb->page_dma,
655 PAGE_SIZE << priv->hw_params.rx_page_order,
656 PCI_DMA_FROMDEVICE);
657 pkt = rxb_addr(rxb);
Zhu Yib481de92007-09-25 17:54:57 -0700658
Johannes Bergf4989d92010-05-28 04:08:30 -0700659 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
660 len += sizeof(u32); /* account for status word */
661 trace_iwlwifi_dev_rx(priv, pkt, len);
Johannes Bergbe1a71a2009-10-02 13:44:02 -0700662
Zhu Yib481de92007-09-25 17:54:57 -0700663 /* Reclaim a command buffer only if this packet is a response
664 * to a (driver-originated) command.
665 * If the packet (e.g. Rx frame) originated from uCode,
666 * there is no command buffer to reclaim.
667 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
668 * but apparently a few don't get set; catch them here. */
669 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
670 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
Tomas Winkler857485c2008-03-21 13:53:44 -0700671 (pkt->hdr.cmd != REPLY_RX) &&
Daniel Halperin7dddaf12008-10-23 23:48:58 -0700672 (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) &&
Zhu Yicfe01702007-09-27 11:27:31 +0800673 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
Zhu Yib481de92007-09-25 17:54:57 -0700674 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
675 (pkt->hdr.cmd != REPLY_TX);
676
Johannes Berg7194207c2011-01-04 16:22:00 -0800677 /*
678 * Do the notification wait before RX handlers so
679 * even if the RX handler consumes the RXB we have
680 * access to it in the notification wait entry.
681 */
682 if (!list_empty(&priv->_agn.notif_waits)) {
683 struct iwl_notification_wait *w;
684
685 spin_lock(&priv->_agn.notif_wait_lock);
686 list_for_each_entry(w, &priv->_agn.notif_waits, list) {
687 if (w->cmd == pkt->hdr.cmd) {
688 w->triggered = true;
689 if (w->fn)
Johannes Berg09f18af2011-04-13 03:14:47 -0700690 w->fn(priv, pkt, w->fn_data);
Johannes Berg7194207c2011-01-04 16:22:00 -0800691 }
692 }
693 spin_unlock(&priv->_agn.notif_wait_lock);
694
695 wake_up_all(&priv->_agn.notif_waitq);
696 }
Cindy H. Kao4613e722011-05-06 10:40:15 -0700697 if (priv->pre_rx_handler)
698 priv->pre_rx_handler(priv, rxb);
Johannes Berg7194207c2011-01-04 16:22:00 -0800699
Zhu Yib481de92007-09-25 17:54:57 -0700700 /* Based on type of command response or notification,
701 * handle those that need handling via function in
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -0700702 * rx_handlers table. See iwl_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -0700703 if (priv->rx_handlers[pkt->hdr.cmd]) {
Tomas Winklere1623442009-01-27 14:27:56 -0800704 IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r,
Ester Kummerf3d67992008-05-06 11:05:12 +0800705 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
Wey-Yi Guya83b9142009-04-08 11:39:32 -0700706 priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
Zhu Yi29b1b262009-10-23 13:42:25 -0700707 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -0700708 } else {
709 /* No handling needed */
Tomas Winklere1623442009-01-27 14:27:56 -0800710 IWL_DEBUG_RX(priv,
Zhu Yib481de92007-09-25 17:54:57 -0700711 "r %d i %d No handler needed for %s, 0x%02x\n",
712 r, i, get_cmd_string(pkt->hdr.cmd),
713 pkt->hdr.cmd);
714 }
715
Zhu Yi29b1b262009-10-23 13:42:25 -0700716 /*
717 * XXX: After here, we should always check rxb->page
718 * against NULL before touching it or its virtual
719 * memory (pkt). Because some rx_handler might have
720 * already taken or freed the pages.
721 */
722
Zhu Yib481de92007-09-25 17:54:57 -0700723 if (reclaim) {
Zhu Yi2f301222009-10-09 17:19:45 +0800724 /* Invoke any callbacks, transfer the buffer to caller,
725 * and fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -0700726 * as we reclaim the driver command queue */
Zhu Yi29b1b262009-10-23 13:42:25 -0700727 if (rxb->page)
Tomas Winkler17b88922008-05-29 16:35:12 +0800728 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -0700729 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800730 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -0700731 }
732
Zhu Yi73005152009-10-23 13:42:32 -0700733 /* Reuse the page if possible. For notification packets and
734 * SKBs that fail to Rx correctly, add them back into the
735 * rx_free list for reuse later. */
Zhu Yib481de92007-09-25 17:54:57 -0700736 spin_lock_irqsave(&rxq->lock, flags);
Zhu Yi73005152009-10-23 13:42:32 -0700737 if (rxb->page != NULL) {
738 rxb->page_dma = pci_map_page(priv->pci_dev, rxb->page,
739 0, PAGE_SIZE << priv->hw_params.rx_page_order,
740 PCI_DMA_FROMDEVICE);
741 list_add_tail(&rxb->list, &rxq->rx_free);
742 rxq->free_count++;
743 } else
744 list_add_tail(&rxb->list, &rxq->rx_used);
745
Zhu Yib481de92007-09-25 17:54:57 -0700746 spin_unlock_irqrestore(&rxq->lock, flags);
Zhu Yi73005152009-10-23 13:42:32 -0700747
Zhu Yib481de92007-09-25 17:54:57 -0700748 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800749 /* If there are a lot of unused frames,
750 * restock the Rx queue so ucode wont assert. */
751 if (fill_rx) {
752 count++;
753 if (count >= 8) {
Zhu Yi73005152009-10-23 13:42:32 -0700754 rxq->read = i;
Wey-Yi Guy54b81552010-03-17 13:34:35 -0700755 iwlagn_rx_replenish_now(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +0800756 count = 0;
757 }
758 }
Zhu Yib481de92007-09-25 17:54:57 -0700759 }
760
761 /* Backtrack one entry */
Zhu Yi73005152009-10-23 13:42:32 -0700762 rxq->read = i;
Mohamed Abbas4752c932009-05-22 11:01:51 -0700763 if (fill_rx)
Wey-Yi Guy54b81552010-03-17 13:34:35 -0700764 iwlagn_rx_replenish_now(priv);
Mohamed Abbas4752c932009-05-22 11:01:51 -0700765 else
Wey-Yi Guy54b81552010-03-17 13:34:35 -0700766 iwlagn_rx_queue_restock(priv);
Tomas Winklera55360e2008-05-05 10:22:28 +0800767}
Tomas Winklera55360e2008-05-05 10:22:28 +0800768
Mohamed Abbasef850d72009-05-22 11:01:50 -0700769/* tasklet for iwlagn interrupt */
770static void iwl_irq_tasklet(struct iwl_priv *priv)
771{
772 u32 inta = 0;
773 u32 handled = 0;
774 unsigned long flags;
Ben Cahill87569902009-11-06 14:53:01 -0800775 u32 i;
Mohamed Abbasef850d72009-05-22 11:01:50 -0700776#ifdef CONFIG_IWLWIFI_DEBUG
777 u32 inta_mask;
778#endif
779
780 spin_lock_irqsave(&priv->lock, flags);
781
782 /* Ack/clear/reset pending uCode interrupts.
783 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
784 */
Shanyu Zhao48a6be62010-03-16 10:22:26 -0700785 /* There is a hardware bug in the interrupt mask function that some
786 * interrupts (i.e. CSR_INT_BIT_SCD) can still be generated even if
787 * they are disabled in the CSR_INT_MASK register. Furthermore the
788 * ICT interrupt handling mechanism has another bug that might cause
789 * these unmasked interrupts fail to be detected. We workaround the
790 * hardware bugs here by ACKing all the possible interrupts so that
791 * interrupt coalescing can still be achieved.
792 */
David S. Miller4a35ecf2010-04-06 23:53:30 -0700793 iwl_write32(priv, CSR_INT, priv->_agn.inta | ~priv->inta_mask);
Mohamed Abbasef850d72009-05-22 11:01:50 -0700794
Johannes Berga4c8b2a2010-01-21 06:25:54 -0800795 inta = priv->_agn.inta;
Mohamed Abbasef850d72009-05-22 11:01:50 -0700796
797#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -0700798 if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
Mohamed Abbasef850d72009-05-22 11:01:50 -0700799 /* just for debug */
800 inta_mask = iwl_read32(priv, CSR_INT_MASK);
801 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x\n ",
802 inta, inta_mask);
803 }
804#endif
Zhu Yi2f301222009-10-09 17:19:45 +0800805
806 spin_unlock_irqrestore(&priv->lock, flags);
807
Johannes Berga4c8b2a2010-01-21 06:25:54 -0800808 /* saved interrupt in inta variable now we can reset priv->_agn.inta */
809 priv->_agn.inta = 0;
Mohamed Abbasef850d72009-05-22 11:01:50 -0700810
811 /* Now service all interrupt bits discovered above. */
812 if (inta & CSR_INT_BIT_HW_ERR) {
Reinette Chatre58dba722009-07-17 09:30:25 -0700813 IWL_ERR(priv, "Hardware error detected. Restarting.\n");
Mohamed Abbasef850d72009-05-22 11:01:50 -0700814
815 /* Tell the device to stop sending interrupts */
816 iwl_disable_interrupts(priv);
817
818 priv->isr_stats.hw++;
819 iwl_irq_handle_error(priv);
820
821 handled |= CSR_INT_BIT_HW_ERR;
822
Mohamed Abbasef850d72009-05-22 11:01:50 -0700823 return;
824 }
825
826#ifdef CONFIG_IWLWIFI_DEBUG
Reinette Chatre3d816c72009-08-07 15:41:37 -0700827 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
Mohamed Abbasef850d72009-05-22 11:01:50 -0700828 /* NIC fires this, but we don't use it, redundant with WAKEUP */
829 if (inta & CSR_INT_BIT_SCD) {
830 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
831 "the frame/frames.\n");
832 priv->isr_stats.sch++;
833 }
834
835 /* Alive notification via Rx interrupt will do the real work */
836 if (inta & CSR_INT_BIT_ALIVE) {
837 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
838 priv->isr_stats.alive++;
839 }
840 }
841#endif
842 /* Safely ignore these bits for debug checks below */
843 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
844
845 /* HW RF KILL switch toggled */
846 if (inta & CSR_INT_BIT_RF_KILL) {
847 int hw_rf_kill = 0;
848 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
849 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
850 hw_rf_kill = 1;
851
Reinette Chatre4c423a22009-07-17 09:30:26 -0700852 IWL_WARN(priv, "RF_KILL bit toggled to %s.\n",
Mohamed Abbasef850d72009-05-22 11:01:50 -0700853 hw_rf_kill ? "disable radio" : "enable radio");
854
855 priv->isr_stats.rfkill++;
856
857 /* driver only loads ucode once setting the interface up.
858 * the driver allows loading the ucode even if the radio
859 * is killed. Hence update the killswitch state here. The
860 * rfkill handler will care about restarting if needed.
861 */
862 if (!test_bit(STATUS_ALIVE, &priv->status)) {
863 if (hw_rf_kill)
864 set_bit(STATUS_RF_KILL_HW, &priv->status);
865 else
866 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Johannes Berga60e77e2009-06-04 18:26:06 +0200867 wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
Mohamed Abbasef850d72009-05-22 11:01:50 -0700868 }
869
870 handled |= CSR_INT_BIT_RF_KILL;
871 }
872
873 /* Chip got too hot and stopped itself */
874 if (inta & CSR_INT_BIT_CT_KILL) {
875 IWL_ERR(priv, "Microcode CT kill error detected.\n");
876 priv->isr_stats.ctkill++;
877 handled |= CSR_INT_BIT_CT_KILL;
878 }
879
880 /* Error detected by uCode */
881 if (inta & CSR_INT_BIT_SW_ERR) {
882 IWL_ERR(priv, "Microcode SW error detected. "
883 " Restarting 0x%X.\n", inta);
884 priv->isr_stats.sw++;
Mohamed Abbasef850d72009-05-22 11:01:50 -0700885 iwl_irq_handle_error(priv);
886 handled |= CSR_INT_BIT_SW_ERR;
887 }
888
889 /* uCode wakes up after power-down sleep */
890 if (inta & CSR_INT_BIT_WAKEUP) {
891 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
892 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Ben Cahill87569902009-11-06 14:53:01 -0800893 for (i = 0; i < priv->hw_params.max_txq_num; i++)
894 iwl_txq_update_write_ptr(priv, &priv->txq[i]);
Mohamed Abbasef850d72009-05-22 11:01:50 -0700895
896 priv->isr_stats.wakeup++;
897
898 handled |= CSR_INT_BIT_WAKEUP;
899 }
900
901 /* All uCode command responses, including Tx command responses,
902 * Rx "responses" (frame-received notification), and other
903 * notifications from uCode come through here*/
Mohamed Abbas40cefda2009-05-22 11:01:52 -0700904 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX |
905 CSR_INT_BIT_RX_PERIODIC)) {
Mohamed Abbasef850d72009-05-22 11:01:50 -0700906 IWL_DEBUG_ISR(priv, "Rx interrupt\n");
Mohamed Abbas40cefda2009-05-22 11:01:52 -0700907 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
908 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
909 iwl_write32(priv, CSR_FH_INT_STATUS,
Wey-Yi Guyf7d046f2011-03-22 08:05:37 -0700910 CSR_FH_INT_RX_MASK);
Mohamed Abbas40cefda2009-05-22 11:01:52 -0700911 }
912 if (inta & CSR_INT_BIT_RX_PERIODIC) {
913 handled |= CSR_INT_BIT_RX_PERIODIC;
914 iwl_write32(priv, CSR_INT, CSR_INT_BIT_RX_PERIODIC);
915 }
916 /* Sending RX interrupt require many steps to be done in the
917 * the device:
918 * 1- write interrupt to current index in ICT table.
919 * 2- dma RX frame.
920 * 3- update RX shared data to indicate last write index.
921 * 4- send interrupt.
922 * This could lead to RX race, driver could receive RX interrupt
Ben Cahill74ba67e2009-11-20 12:04:53 -0800923 * but the shared data changes does not reflect this;
924 * periodic interrupt will detect any dangling Rx activity.
Mohamed Abbas40cefda2009-05-22 11:01:52 -0700925 */
Ben Cahill74ba67e2009-11-20 12:04:53 -0800926
927 /* Disable periodic interrupt; we use it as just a one-shot. */
928 iwl_write8(priv, CSR_INT_PERIODIC_REG,
Mohamed Abbas40cefda2009-05-22 11:01:52 -0700929 CSR_INT_PERIODIC_DIS);
Mohamed Abbasef850d72009-05-22 11:01:50 -0700930 iwl_rx_handle(priv);
Ben Cahill74ba67e2009-11-20 12:04:53 -0800931
932 /*
933 * Enable periodic interrupt in 8 msec only if we received
934 * real RX interrupt (instead of just periodic int), to catch
935 * any dangling Rx interrupt. If it was just the periodic
936 * interrupt, there was no dangling Rx activity, and no need
937 * to extend the periodic interrupt; one-shot is enough.
938 */
Mohamed Abbas40cefda2009-05-22 11:01:52 -0700939 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX))
Ben Cahill74ba67e2009-11-20 12:04:53 -0800940 iwl_write8(priv, CSR_INT_PERIODIC_REG,
Mohamed Abbas40cefda2009-05-22 11:01:52 -0700941 CSR_INT_PERIODIC_ENA);
942
Mohamed Abbasef850d72009-05-22 11:01:50 -0700943 priv->isr_stats.rx++;
Mohamed Abbasef850d72009-05-22 11:01:50 -0700944 }
945
Ben Cahillc72cd192009-10-30 14:36:08 -0700946 /* This "Tx" DMA channel is used only for loading uCode */
Mohamed Abbasef850d72009-05-22 11:01:50 -0700947 if (inta & CSR_INT_BIT_FH_TX) {
Wey-Yi Guyf7d046f2011-03-22 08:05:37 -0700948 iwl_write32(priv, CSR_FH_INT_STATUS, CSR_FH_INT_TX_MASK);
Ben Cahillc72cd192009-10-30 14:36:08 -0700949 IWL_DEBUG_ISR(priv, "uCode load interrupt\n");
Mohamed Abbasef850d72009-05-22 11:01:50 -0700950 priv->isr_stats.tx++;
951 handled |= CSR_INT_BIT_FH_TX;
Ben Cahillc72cd192009-10-30 14:36:08 -0700952 /* Wake up uCode load routine, now that load is complete */
Mohamed Abbasef850d72009-05-22 11:01:50 -0700953 priv->ucode_write_complete = 1;
954 wake_up_interruptible(&priv->wait_command_queue);
955 }
956
957 if (inta & ~handled) {
958 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
959 priv->isr_stats.unhandled++;
960 }
961
Mohamed Abbas40cefda2009-05-22 11:01:52 -0700962 if (inta & ~(priv->inta_mask)) {
Mohamed Abbasef850d72009-05-22 11:01:50 -0700963 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Mohamed Abbas40cefda2009-05-22 11:01:52 -0700964 inta & ~priv->inta_mask);
Mohamed Abbasef850d72009-05-22 11:01:50 -0700965 }
966
Mohamed Abbasef850d72009-05-22 11:01:50 -0700967 /* Re-enable all interrupts */
Justin P. Mattock62e45c12010-12-30 15:07:56 -0800968 /* only Re-enable if disabled by irq */
Mohamed Abbasef850d72009-05-22 11:01:50 -0700969 if (test_bit(STATUS_INT_ENABLED, &priv->status))
970 iwl_enable_interrupts(priv);
Don Fry3dd823e2011-02-06 09:29:45 -0800971 /* Re-enable RF_KILL if it occurred */
972 else if (handled & CSR_INT_BIT_RF_KILL)
973 iwl_enable_rfkill_int(priv);
Mohamed Abbasef850d72009-05-22 11:01:50 -0700974}
975
Emmanuel Grumbach7d476182010-05-23 00:14:08 -0700976/*****************************************************************************
977 *
978 * sysfs attributes
979 *
980 *****************************************************************************/
981
982#ifdef CONFIG_IWLWIFI_DEBUG
983
984/*
985 * The following adds a new attribute to the sysfs representation
986 * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
987 * used for controlling the debug level.
988 *
989 * See the level definitions in iwl for details.
990 *
991 * The debug_level being managed using sysfs below is a per device debug
992 * level that is used instead of the global debug level if it (the per
993 * device debug level) is set.
994 */
995static ssize_t show_debug_level(struct device *d,
996 struct device_attribute *attr, char *buf)
997{
998 struct iwl_priv *priv = dev_get_drvdata(d);
999 return sprintf(buf, "0x%08X\n", iwl_get_debug_level(priv));
1000}
1001static ssize_t store_debug_level(struct device *d,
1002 struct device_attribute *attr,
1003 const char *buf, size_t count)
1004{
1005 struct iwl_priv *priv = dev_get_drvdata(d);
1006 unsigned long val;
1007 int ret;
1008
1009 ret = strict_strtoul(buf, 0, &val);
1010 if (ret)
1011 IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf);
1012 else {
1013 priv->debug_level = val;
1014 if (iwl_alloc_traffic_mem(priv))
1015 IWL_ERR(priv,
1016 "Not enough memory to generate traffic log\n");
1017 }
1018 return strnlen(buf, count);
1019}
1020
1021static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
1022 show_debug_level, store_debug_level);
1023
1024
1025#endif /* CONFIG_IWLWIFI_DEBUG */
1026
1027
1028static ssize_t show_temperature(struct device *d,
1029 struct device_attribute *attr, char *buf)
1030{
1031 struct iwl_priv *priv = dev_get_drvdata(d);
1032
1033 if (!iwl_is_alive(priv))
1034 return -EAGAIN;
1035
1036 return sprintf(buf, "%d\n", priv->temperature);
1037}
1038
1039static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
1040
1041static ssize_t show_tx_power(struct device *d,
1042 struct device_attribute *attr, char *buf)
1043{
1044 struct iwl_priv *priv = dev_get_drvdata(d);
1045
1046 if (!iwl_is_ready_rf(priv))
1047 return sprintf(buf, "off\n");
1048 else
1049 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
1050}
1051
1052static ssize_t store_tx_power(struct device *d,
1053 struct device_attribute *attr,
1054 const char *buf, size_t count)
1055{
1056 struct iwl_priv *priv = dev_get_drvdata(d);
1057 unsigned long val;
1058 int ret;
1059
1060 ret = strict_strtoul(buf, 10, &val);
1061 if (ret)
1062 IWL_INFO(priv, "%s is not in decimal form.\n", buf);
1063 else {
1064 ret = iwl_set_tx_power(priv, val, false);
1065 if (ret)
1066 IWL_ERR(priv, "failed setting tx power (0x%d).\n",
1067 ret);
1068 else
1069 ret = count;
1070 }
1071 return ret;
1072}
1073
1074static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
1075
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07001076static struct attribute *iwl_sysfs_entries[] = {
1077 &dev_attr_temperature.attr,
1078 &dev_attr_tx_power.attr,
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07001079#ifdef CONFIG_IWLWIFI_DEBUG
1080 &dev_attr_debug_level.attr,
1081#endif
1082 NULL
1083};
1084
1085static struct attribute_group iwl_attribute_group = {
1086 .name = NULL, /* put in device directory */
1087 .attrs = iwl_sysfs_entries,
1088};
1089
Zhu Yib481de92007-09-25 17:54:57 -07001090/******************************************************************************
1091 *
1092 * uCode download functions
1093 *
1094 ******************************************************************************/
1095
Johannes Bergdbf28e212011-04-16 08:29:24 -07001096static void iwl_free_fw_desc(struct pci_dev *pci_dev, struct fw_desc *desc)
1097{
1098 if (desc->v_addr)
1099 dma_free_coherent(&pci_dev->dev, desc->len,
1100 desc->v_addr, desc->p_addr);
1101 desc->v_addr = NULL;
1102 desc->len = 0;
1103}
1104
1105static void iwl_free_fw_img(struct pci_dev *pci_dev, struct fw_img *img)
1106{
1107 iwl_free_fw_desc(pci_dev, &img->code);
1108 iwl_free_fw_desc(pci_dev, &img->data);
1109}
1110
1111static int iwl_alloc_fw_desc(struct pci_dev *pci_dev, struct fw_desc *desc,
1112 const void *data, size_t len)
1113{
1114 if (!len) {
1115 desc->v_addr = NULL;
1116 return -EINVAL;
1117 }
1118
1119 desc->v_addr = dma_alloc_coherent(&pci_dev->dev, len,
1120 &desc->p_addr, GFP_KERNEL);
1121 if (!desc->v_addr)
1122 return -ENOMEM;
1123 desc->len = len;
1124 memcpy(desc->v_addr, data, len);
1125 return 0;
1126}
1127
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001128static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001129{
Johannes Bergdbf28e212011-04-16 08:29:24 -07001130 iwl_free_fw_img(priv->pci_dev, &priv->ucode_rt);
1131 iwl_free_fw_img(priv->pci_dev, &priv->ucode_init);
Zhu Yib481de92007-09-25 17:54:57 -07001132}
1133
Johannes Bergdd7a2502010-04-28 23:33:10 -07001134struct iwlagn_ucode_capabilities {
1135 u32 max_probe_length;
Wey-Yi Guy6a822d02010-07-13 17:13:15 -07001136 u32 standard_phy_calibration_size;
Johannes Berg3997ff32011-04-05 09:42:02 -07001137 u32 flags;
Johannes Bergdd7a2502010-04-28 23:33:10 -07001138};
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08001139
Johannes Bergb08dfd02010-01-29 11:54:56 -08001140static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context);
Johannes Bergdd7a2502010-04-28 23:33:10 -07001141static int iwl_mac_setup_register(struct iwl_priv *priv,
1142 struct iwlagn_ucode_capabilities *capa);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001143
Jay Sternberg39396082010-08-12 10:24:07 -07001144#define UCODE_EXPERIMENTAL_INDEX 100
1145#define UCODE_EXPERIMENTAL_TAG "exp"
1146
Johannes Bergb08dfd02010-01-29 11:54:56 -08001147static int __must_check iwl_request_firmware(struct iwl_priv *priv, bool first)
Zhu Yib481de92007-09-25 17:54:57 -07001148{
Reinette Chatrea0987a82008-12-02 12:14:06 -08001149 const char *name_pre = priv->cfg->fw_name_pre;
Jay Sternberg39396082010-08-12 10:24:07 -07001150 char tag[8];
Johannes Bergb08dfd02010-01-29 11:54:56 -08001151
Jay Sternberg39396082010-08-12 10:24:07 -07001152 if (first) {
1153#ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE
1154 priv->fw_index = UCODE_EXPERIMENTAL_INDEX;
1155 strcpy(tag, UCODE_EXPERIMENTAL_TAG);
1156 } else if (priv->fw_index == UCODE_EXPERIMENTAL_INDEX) {
1157#endif
Johannes Bergb08dfd02010-01-29 11:54:56 -08001158 priv->fw_index = priv->cfg->ucode_api_max;
Jay Sternberg39396082010-08-12 10:24:07 -07001159 sprintf(tag, "%d", priv->fw_index);
1160 } else {
Johannes Bergb08dfd02010-01-29 11:54:56 -08001161 priv->fw_index--;
Jay Sternberg39396082010-08-12 10:24:07 -07001162 sprintf(tag, "%d", priv->fw_index);
1163 }
Johannes Bergb08dfd02010-01-29 11:54:56 -08001164
1165 if (priv->fw_index < priv->cfg->ucode_api_min) {
1166 IWL_ERR(priv, "no suitable firmware found!\n");
1167 return -ENOENT;
1168 }
1169
Jay Sternberg39396082010-08-12 10:24:07 -07001170 sprintf(priv->firmware_name, "%s%s%s", name_pre, tag, ".ucode");
Johannes Bergb08dfd02010-01-29 11:54:56 -08001171
Jay Sternberg39396082010-08-12 10:24:07 -07001172 IWL_DEBUG_INFO(priv, "attempting to load firmware %s'%s'\n",
1173 (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
1174 ? "EXPERIMENTAL " : "",
Johannes Bergb08dfd02010-01-29 11:54:56 -08001175 priv->firmware_name);
1176
1177 return request_firmware_nowait(THIS_MODULE, 1, priv->firmware_name,
1178 &priv->pci_dev->dev, GFP_KERNEL, priv,
1179 iwl_ucode_callback);
1180}
1181
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001182struct iwlagn_firmware_pieces {
Johannes Berg1fc35272011-04-05 09:41:57 -07001183 const void *inst, *data, *init, *init_data;
1184 size_t inst_size, data_size, init_size, init_data_size;
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001185
1186 u32 build;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001187
1188 u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
1189 u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001190};
1191
1192static int iwlagn_load_legacy_firmware(struct iwl_priv *priv,
1193 const struct firmware *ucode_raw,
1194 struct iwlagn_firmware_pieces *pieces)
1195{
1196 struct iwl_ucode_header *ucode = (void *)ucode_raw->data;
1197 u32 api_ver, hdr_size;
1198 const u8 *src;
1199
1200 priv->ucode_ver = le32_to_cpu(ucode->ver);
1201 api_ver = IWL_UCODE_API(priv->ucode_ver);
1202
1203 switch (api_ver) {
1204 default:
Wey-Yi Guyf7d046f2011-03-22 08:05:37 -07001205 hdr_size = 28;
1206 if (ucode_raw->size < hdr_size) {
1207 IWL_ERR(priv, "File size too small!\n");
1208 return -EINVAL;
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001209 }
Wey-Yi Guyf7d046f2011-03-22 08:05:37 -07001210 pieces->build = le32_to_cpu(ucode->u.v2.build);
1211 pieces->inst_size = le32_to_cpu(ucode->u.v2.inst_size);
1212 pieces->data_size = le32_to_cpu(ucode->u.v2.data_size);
1213 pieces->init_size = le32_to_cpu(ucode->u.v2.init_size);
1214 pieces->init_data_size = le32_to_cpu(ucode->u.v2.init_data_size);
Wey-Yi Guyf7d046f2011-03-22 08:05:37 -07001215 src = ucode->u.v2.data;
1216 break;
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001217 case 0:
1218 case 1:
1219 case 2:
1220 hdr_size = 24;
1221 if (ucode_raw->size < hdr_size) {
1222 IWL_ERR(priv, "File size too small!\n");
1223 return -EINVAL;
1224 }
1225 pieces->build = 0;
1226 pieces->inst_size = le32_to_cpu(ucode->u.v1.inst_size);
1227 pieces->data_size = le32_to_cpu(ucode->u.v1.data_size);
1228 pieces->init_size = le32_to_cpu(ucode->u.v1.init_size);
1229 pieces->init_data_size = le32_to_cpu(ucode->u.v1.init_data_size);
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001230 src = ucode->u.v1.data;
1231 break;
1232 }
1233
1234 /* Verify size of file vs. image size info in file's header */
1235 if (ucode_raw->size != hdr_size + pieces->inst_size +
1236 pieces->data_size + pieces->init_size +
Johannes Berg1fc35272011-04-05 09:41:57 -07001237 pieces->init_data_size) {
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001238
1239 IWL_ERR(priv,
1240 "uCode file size %d does not match expected size\n",
1241 (int)ucode_raw->size);
1242 return -EINVAL;
1243 }
1244
1245 pieces->inst = src;
1246 src += pieces->inst_size;
1247 pieces->data = src;
1248 src += pieces->data_size;
1249 pieces->init = src;
1250 src += pieces->init_size;
1251 pieces->init_data = src;
1252 src += pieces->init_data_size;
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001253
1254 return 0;
1255}
1256
Johannes Bergdd7a2502010-04-28 23:33:10 -07001257static int iwlagn_wanted_ucode_alternative = 1;
1258
1259static int iwlagn_load_firmware(struct iwl_priv *priv,
1260 const struct firmware *ucode_raw,
1261 struct iwlagn_firmware_pieces *pieces,
1262 struct iwlagn_ucode_capabilities *capa)
1263{
1264 struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data;
1265 struct iwl_ucode_tlv *tlv;
1266 size_t len = ucode_raw->size;
1267 const u8 *data;
1268 int wanted_alternative = iwlagn_wanted_ucode_alternative, tmp;
1269 u64 alternatives;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001270 u32 tlv_len;
1271 enum iwl_ucode_tlv_type tlv_type;
1272 const u8 *tlv_data;
Johannes Bergdd7a2502010-04-28 23:33:10 -07001273
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001274 if (len < sizeof(*ucode)) {
1275 IWL_ERR(priv, "uCode has invalid length: %zd\n", len);
Johannes Bergdd7a2502010-04-28 23:33:10 -07001276 return -EINVAL;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001277 }
Johannes Bergdd7a2502010-04-28 23:33:10 -07001278
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001279 if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) {
1280 IWL_ERR(priv, "invalid uCode magic: 0X%x\n",
1281 le32_to_cpu(ucode->magic));
Johannes Bergdd7a2502010-04-28 23:33:10 -07001282 return -EINVAL;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001283 }
Johannes Bergdd7a2502010-04-28 23:33:10 -07001284
1285 /*
1286 * Check which alternatives are present, and "downgrade"
1287 * when the chosen alternative is not present, warning
1288 * the user when that happens. Some files may not have
1289 * any alternatives, so don't warn in that case.
1290 */
1291 alternatives = le64_to_cpu(ucode->alternatives);
1292 tmp = wanted_alternative;
1293 if (wanted_alternative > 63)
1294 wanted_alternative = 63;
1295 while (wanted_alternative && !(alternatives & BIT(wanted_alternative)))
1296 wanted_alternative--;
1297 if (wanted_alternative && wanted_alternative != tmp)
1298 IWL_WARN(priv,
1299 "uCode alternative %d not available, choosing %d\n",
1300 tmp, wanted_alternative);
1301
1302 priv->ucode_ver = le32_to_cpu(ucode->ver);
1303 pieces->build = le32_to_cpu(ucode->build);
1304 data = ucode->data;
1305
1306 len -= sizeof(*ucode);
1307
Johannes Berg704da532010-07-14 09:34:50 -07001308 while (len >= sizeof(*tlv)) {
Johannes Bergdd7a2502010-04-28 23:33:10 -07001309 u16 tlv_alt;
Johannes Bergdd7a2502010-04-28 23:33:10 -07001310
1311 len -= sizeof(*tlv);
1312 tlv = (void *)data;
1313
1314 tlv_len = le32_to_cpu(tlv->length);
1315 tlv_type = le16_to_cpu(tlv->type);
1316 tlv_alt = le16_to_cpu(tlv->alternative);
1317 tlv_data = tlv->data;
1318
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001319 if (len < tlv_len) {
1320 IWL_ERR(priv, "invalid TLV len: %zd/%u\n",
1321 len, tlv_len);
Johannes Bergdd7a2502010-04-28 23:33:10 -07001322 return -EINVAL;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001323 }
Johannes Bergdd7a2502010-04-28 23:33:10 -07001324 len -= ALIGN(tlv_len, 4);
1325 data += sizeof(*tlv) + ALIGN(tlv_len, 4);
1326
1327 /*
1328 * Alternative 0 is always valid.
1329 *
1330 * Skip alternative TLVs that are not selected.
1331 */
1332 if (tlv_alt != 0 && tlv_alt != wanted_alternative)
1333 continue;
1334
1335 switch (tlv_type) {
1336 case IWL_UCODE_TLV_INST:
1337 pieces->inst = tlv_data;
1338 pieces->inst_size = tlv_len;
1339 break;
1340 case IWL_UCODE_TLV_DATA:
1341 pieces->data = tlv_data;
1342 pieces->data_size = tlv_len;
1343 break;
1344 case IWL_UCODE_TLV_INIT:
1345 pieces->init = tlv_data;
1346 pieces->init_size = tlv_len;
1347 break;
1348 case IWL_UCODE_TLV_INIT_DATA:
1349 pieces->init_data = tlv_data;
1350 pieces->init_data_size = tlv_len;
1351 break;
1352 case IWL_UCODE_TLV_BOOT:
Johannes Berg1fc35272011-04-05 09:41:57 -07001353 IWL_ERR(priv, "Found unexpected BOOT ucode\n");
Johannes Bergdd7a2502010-04-28 23:33:10 -07001354 break;
1355 case IWL_UCODE_TLV_PROBE_MAX_LEN:
Johannes Berg704da532010-07-14 09:34:50 -07001356 if (tlv_len != sizeof(u32))
1357 goto invalid_tlv_len;
1358 capa->max_probe_length =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001359 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergdd7a2502010-04-28 23:33:10 -07001360 break;
Johannes Bergece9c4e2010-08-23 10:46:49 +02001361 case IWL_UCODE_TLV_PAN:
1362 if (tlv_len)
1363 goto invalid_tlv_len;
Johannes Berg3997ff32011-04-05 09:42:02 -07001364 capa->flags |= IWL_UCODE_TLV_FLAGS_PAN;
1365 break;
1366 case IWL_UCODE_TLV_FLAGS:
1367 /* must be at least one u32 */
1368 if (tlv_len < sizeof(u32))
1369 goto invalid_tlv_len;
1370 /* and a proper number of u32s */
1371 if (tlv_len % sizeof(u32))
1372 goto invalid_tlv_len;
1373 /*
1374 * This driver only reads the first u32 as
1375 * right now no more features are defined,
1376 * if that changes then either the driver
1377 * will not work with the new firmware, or
1378 * it'll not take advantage of new features.
1379 */
1380 capa->flags = le32_to_cpup((__le32 *)tlv_data);
Johannes Bergece9c4e2010-08-23 10:46:49 +02001381 break;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001382 case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
Johannes Berg704da532010-07-14 09:34:50 -07001383 if (tlv_len != sizeof(u32))
1384 goto invalid_tlv_len;
1385 pieces->init_evtlog_ptr =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001386 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -07001387 break;
1388 case IWL_UCODE_TLV_INIT_EVTLOG_SIZE:
Johannes Berg704da532010-07-14 09:34:50 -07001389 if (tlv_len != sizeof(u32))
1390 goto invalid_tlv_len;
1391 pieces->init_evtlog_size =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001392 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -07001393 break;
1394 case IWL_UCODE_TLV_INIT_ERRLOG_PTR:
Johannes Berg704da532010-07-14 09:34:50 -07001395 if (tlv_len != sizeof(u32))
1396 goto invalid_tlv_len;
1397 pieces->init_errlog_ptr =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001398 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -07001399 break;
1400 case IWL_UCODE_TLV_RUNT_EVTLOG_PTR:
Johannes Berg704da532010-07-14 09:34:50 -07001401 if (tlv_len != sizeof(u32))
1402 goto invalid_tlv_len;
1403 pieces->inst_evtlog_ptr =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001404 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -07001405 break;
1406 case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE:
Johannes Berg704da532010-07-14 09:34:50 -07001407 if (tlv_len != sizeof(u32))
1408 goto invalid_tlv_len;
1409 pieces->inst_evtlog_size =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001410 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -07001411 break;
1412 case IWL_UCODE_TLV_RUNT_ERRLOG_PTR:
Johannes Berg704da532010-07-14 09:34:50 -07001413 if (tlv_len != sizeof(u32))
1414 goto invalid_tlv_len;
1415 pieces->inst_errlog_ptr =
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001416 le32_to_cpup((__le32 *)tlv_data);
Johannes Bergb2e640d2010-05-05 23:24:54 -07001417 break;
Wey-Yi Guyc8312fa2010-06-28 13:05:17 -07001418 case IWL_UCODE_TLV_ENHANCE_SENS_TBL:
1419 if (tlv_len)
Johannes Berg704da532010-07-14 09:34:50 -07001420 goto invalid_tlv_len;
1421 priv->enhance_sensitivity_table = true;
Wey-Yi Guyc8312fa2010-06-28 13:05:17 -07001422 break;
Wey-Yi Guy6a822d02010-07-13 17:13:15 -07001423 case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE:
Johannes Berg704da532010-07-14 09:34:50 -07001424 if (tlv_len != sizeof(u32))
1425 goto invalid_tlv_len;
1426 capa->standard_phy_calibration_size =
Wey-Yi Guy6a822d02010-07-13 17:13:15 -07001427 le32_to_cpup((__le32 *)tlv_data);
1428 break;
Johannes Bergdd7a2502010-04-28 23:33:10 -07001429 default:
Johannes Berg6fc3ba92011-04-04 06:16:29 -07001430 IWL_DEBUG_INFO(priv, "unknown TLV: %d\n", tlv_type);
Johannes Bergdd7a2502010-04-28 23:33:10 -07001431 break;
1432 }
1433 }
1434
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001435 if (len) {
1436 IWL_ERR(priv, "invalid TLV after parsing: %zd\n", len);
1437 iwl_print_hex_dump(priv, IWL_DL_FW, (u8 *)data, len);
Johannes Berg704da532010-07-14 09:34:50 -07001438 return -EINVAL;
Wey-Yi Guyad8d8332010-06-22 14:31:45 -07001439 }
Johannes Bergdd7a2502010-04-28 23:33:10 -07001440
Johannes Berg704da532010-07-14 09:34:50 -07001441 return 0;
1442
1443 invalid_tlv_len:
1444 IWL_ERR(priv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len);
1445 iwl_print_hex_dump(priv, IWL_DL_FW, tlv_data, tlv_len);
1446
1447 return -EINVAL;
Johannes Bergdd7a2502010-04-28 23:33:10 -07001448}
1449
Johannes Bergb08dfd02010-01-29 11:54:56 -08001450/**
1451 * iwl_ucode_callback - callback when firmware was loaded
1452 *
1453 * If loaded successfully, copies the firmware into buffers
1454 * for the card to fetch (via DMA).
1455 */
1456static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
1457{
1458 struct iwl_priv *priv = context;
1459 struct iwl_ucode_header *ucode;
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001460 int err;
1461 struct iwlagn_firmware_pieces pieces;
Reinette Chatrea0987a82008-12-02 12:14:06 -08001462 const unsigned int api_max = priv->cfg->ucode_api_max;
1463 const unsigned int api_min = priv->cfg->ucode_api_min;
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001464 u32 api_ver;
Johannes Berg3e4de762010-04-28 12:09:12 -07001465 char buildstr[25];
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001466 u32 build;
Johannes Bergdd7a2502010-04-28 23:33:10 -07001467 struct iwlagn_ucode_capabilities ucode_capa = {
1468 .max_probe_length = 200,
Wey-Yi Guy6a822d02010-07-13 17:13:15 -07001469 .standard_phy_calibration_size =
Shanyu Zhao642454c2010-09-21 12:06:18 -07001470 IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE,
Johannes Bergdd7a2502010-04-28 23:33:10 -07001471 };
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001472
1473 memset(&pieces, 0, sizeof(pieces));
Zhu Yib481de92007-09-25 17:54:57 -07001474
Johannes Bergb08dfd02010-01-29 11:54:56 -08001475 if (!ucode_raw) {
Jay Sternberg39396082010-08-12 10:24:07 -07001476 if (priv->fw_index <= priv->cfg->ucode_api_max)
1477 IWL_ERR(priv,
1478 "request for firmware file '%s' failed.\n",
1479 priv->firmware_name);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001480 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07001481 }
1482
Johannes Bergb08dfd02010-01-29 11:54:56 -08001483 IWL_DEBUG_INFO(priv, "Loaded firmware file '%s' (%zd bytes).\n",
1484 priv->firmware_name, ucode_raw->size);
Zhu Yib481de92007-09-25 17:54:57 -07001485
Johannes Berg22adba22010-04-28 12:09:14 -07001486 /* Make sure that we got at least the API version number */
1487 if (ucode_raw->size < 4) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001488 IWL_ERR(priv, "File size way too small!\n");
Johannes Bergb08dfd02010-01-29 11:54:56 -08001489 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07001490 }
1491
1492 /* Data from ucode file: header followed by uCode images */
Jay Sternbergcc0f5552009-07-17 09:30:16 -07001493 ucode = (struct iwl_ucode_header *)ucode_raw->data;
Zhu Yib481de92007-09-25 17:54:57 -07001494
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001495 if (ucode->ver)
1496 err = iwlagn_load_legacy_firmware(priv, ucode_raw, &pieces);
1497 else
Johannes Bergdd7a2502010-04-28 23:33:10 -07001498 err = iwlagn_load_firmware(priv, ucode_raw, &pieces,
1499 &ucode_capa);
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001500
1501 if (err)
1502 goto try_again;
1503
Reinette Chatrea0987a82008-12-02 12:14:06 -08001504 api_ver = IWL_UCODE_API(priv->ucode_ver);
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001505 build = pieces.build;
Zhu Yib481de92007-09-25 17:54:57 -07001506
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001507 /*
1508 * api_ver should match the api version forming part of the
Reinette Chatrea0987a82008-12-02 12:14:06 -08001509 * firmware filename ... but we don't check for that and only rely
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001510 * on the API version read from firmware header from here on forward
1511 */
Wey-Yi Guy65cccfb2010-09-21 16:15:58 -07001512 /* no api version check required for experimental uCode */
1513 if (priv->fw_index != UCODE_EXPERIMENTAL_INDEX) {
1514 if (api_ver < api_min || api_ver > api_max) {
1515 IWL_ERR(priv,
1516 "Driver unable to support your firmware API. "
1517 "Driver supports v%u, firmware is v%u.\n",
1518 api_max, api_ver);
1519 goto try_again;
1520 }
Johannes Bergb08dfd02010-01-29 11:54:56 -08001521
Wey-Yi Guy65cccfb2010-09-21 16:15:58 -07001522 if (api_ver != api_max)
1523 IWL_ERR(priv,
1524 "Firmware has old API version. Expected v%u, "
1525 "got v%u. New firmware can be obtained "
1526 "from http://www.intellinuxwireless.org.\n",
1527 api_max, api_ver);
1528 }
Reinette Chatrea0987a82008-12-02 12:14:06 -08001529
Johannes Berg3e4de762010-04-28 12:09:12 -07001530 if (build)
Jay Sternberg39396082010-08-12 10:24:07 -07001531 sprintf(buildstr, " build %u%s", build,
1532 (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
1533 ? " (EXP)" : "");
Johannes Berg3e4de762010-04-28 12:09:12 -07001534 else
1535 buildstr[0] = '\0';
Reinette Chatrea0987a82008-12-02 12:14:06 -08001536
Johannes Berg3e4de762010-04-28 12:09:12 -07001537 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u%s\n",
Reinette Chatre5ebeb5a2009-10-30 14:36:04 -07001538 IWL_UCODE_MAJOR(priv->ucode_ver),
1539 IWL_UCODE_MINOR(priv->ucode_ver),
1540 IWL_UCODE_API(priv->ucode_ver),
Johannes Berg3e4de762010-04-28 12:09:12 -07001541 IWL_UCODE_SERIAL(priv->ucode_ver),
1542 buildstr);
Reinette Chatre5ebeb5a2009-10-30 14:36:04 -07001543
Johannes Berg3e4de762010-04-28 12:09:12 -07001544 snprintf(priv->hw->wiphy->fw_version,
1545 sizeof(priv->hw->wiphy->fw_version),
1546 "%u.%u.%u.%u%s",
1547 IWL_UCODE_MAJOR(priv->ucode_ver),
1548 IWL_UCODE_MINOR(priv->ucode_ver),
1549 IWL_UCODE_API(priv->ucode_ver),
1550 IWL_UCODE_SERIAL(priv->ucode_ver),
1551 buildstr);
Zhu Yib481de92007-09-25 17:54:57 -07001552
Johannes Bergb08dfd02010-01-29 11:54:56 -08001553 /*
1554 * For any of the failures below (before allocating pci memory)
1555 * we will try to load a version with a smaller API -- maybe the
1556 * user just got a corrupted version of the latest API.
1557 */
1558
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001559 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
1560 priv->ucode_ver);
1561 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %Zd\n",
1562 pieces.inst_size);
1563 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %Zd\n",
1564 pieces.data_size);
1565 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %Zd\n",
1566 pieces.init_size);
1567 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %Zd\n",
1568 pieces.init_data_size);
Zhu Yib481de92007-09-25 17:54:57 -07001569
1570 /* Verify that uCode images will fit in card's SRAM */
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001571 if (pieces.inst_size > priv->hw_params.max_inst_size) {
1572 IWL_ERR(priv, "uCode instr len %Zd too large to fit in\n",
1573 pieces.inst_size);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001574 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07001575 }
1576
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001577 if (pieces.data_size > priv->hw_params.max_data_size) {
1578 IWL_ERR(priv, "uCode data len %Zd too large to fit in\n",
1579 pieces.data_size);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001580 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07001581 }
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001582
1583 if (pieces.init_size > priv->hw_params.max_inst_size) {
1584 IWL_ERR(priv, "uCode init instr len %Zd too large to fit in\n",
1585 pieces.init_size);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001586 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07001587 }
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001588
1589 if (pieces.init_data_size > priv->hw_params.max_data_size) {
1590 IWL_ERR(priv, "uCode init data len %Zd too large to fit in\n",
1591 pieces.init_data_size);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001592 goto try_again;
Zhu Yib481de92007-09-25 17:54:57 -07001593 }
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001594
Zhu Yib481de92007-09-25 17:54:57 -07001595 /* Allocate ucode buffers for card's bus-master loading ... */
1596
1597 /* Runtime instructions and 2 copies of data:
1598 * 1) unmodified from disk
1599 * 2) backup cache for save/restore during power-downs */
Johannes Bergdbf28e212011-04-16 08:29:24 -07001600 if (iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_rt.code,
1601 pieces.inst, pieces.inst_size))
1602 goto err_pci_alloc;
1603 if (iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_rt.data,
1604 pieces.data, pieces.data_size))
Zhu, Yi1f304e42009-01-23 13:45:22 -08001605 goto err_pci_alloc;
1606
Zhu Yib481de92007-09-25 17:54:57 -07001607 /* Initialization instructions and data */
Johannes Berg0e9a44d2010-04-28 12:09:16 -07001608 if (pieces.init_size && pieces.init_data_size) {
Johannes Bergdbf28e212011-04-16 08:29:24 -07001609 if (iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init.code,
1610 pieces.init, pieces.init_size))
1611 goto err_pci_alloc;
1612 if (iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init.data,
1613 pieces.init_data, pieces.init_data_size))
Tomas Winkler90e759d2007-11-29 11:09:41 +08001614 goto err_pci_alloc;
1615 }
Zhu Yib481de92007-09-25 17:54:57 -07001616
Johannes Bergb2e640d2010-05-05 23:24:54 -07001617 /* Now that we can no longer fail, copy information */
1618
1619 /*
1620 * The (size - 16) / 12 formula is based on the information recorded
1621 * for each event, which is of mode 1 (including timestamp) for all
1622 * new microcodes that include this information.
1623 */
1624 priv->_agn.init_evtlog_ptr = pieces.init_evtlog_ptr;
1625 if (pieces.init_evtlog_size)
1626 priv->_agn.init_evtlog_size = (pieces.init_evtlog_size - 16)/12;
1627 else
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07001628 priv->_agn.init_evtlog_size =
1629 priv->cfg->base_params->max_event_log_size;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001630 priv->_agn.init_errlog_ptr = pieces.init_errlog_ptr;
1631 priv->_agn.inst_evtlog_ptr = pieces.inst_evtlog_ptr;
1632 if (pieces.inst_evtlog_size)
1633 priv->_agn.inst_evtlog_size = (pieces.inst_evtlog_size - 16)/12;
1634 else
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07001635 priv->_agn.inst_evtlog_size =
1636 priv->cfg->base_params->max_event_log_size;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001637 priv->_agn.inst_errlog_ptr = pieces.inst_errlog_ptr;
1638
Johannes Bergd2690c02011-04-20 09:10:39 -07001639 priv->new_scan_threshold_behaviour =
1640 !!(ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NEWSCAN);
1641
Johannes Berg3997ff32011-04-05 09:42:02 -07001642 if (ucode_capa.flags & IWL_UCODE_TLV_FLAGS_PAN) {
Johannes Bergece9c4e2010-08-23 10:46:49 +02001643 priv->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
Johannes Bergc10afb62010-08-23 10:46:43 +02001644 priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
Johannes Bergece9c4e2010-08-23 10:46:49 +02001645 } else
1646 priv->sta_key_max_num = STA_KEY_MAX_NUM;
Johannes Bergc10afb62010-08-23 10:46:43 +02001647
Johannes Berg17445b82011-04-05 09:42:05 -07001648 if (priv->valid_contexts != BIT(IWL_RXON_CTX_BSS))
1649 priv->cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
1650 else
1651 priv->cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
1652
Wey-Yi Guy6a822d02010-07-13 17:13:15 -07001653 /*
1654 * figure out the offset of chain noise reset and gain commands
1655 * base on the size of standard phy calibration commands table size
1656 */
1657 if (ucode_capa.standard_phy_calibration_size >
1658 IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
1659 ucode_capa.standard_phy_calibration_size =
1660 IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
1661
1662 priv->_agn.phy_calib_chain_noise_reset_cmd =
1663 ucode_capa.standard_phy_calibration_size;
1664 priv->_agn.phy_calib_chain_noise_gain_cmd =
1665 ucode_capa.standard_phy_calibration_size + 1;
1666
Johannes Bergb08dfd02010-01-29 11:54:56 -08001667 /**************************************************
1668 * This is still part of probe() in a sense...
1669 *
1670 * 9. Setup and register with mac80211 and debugfs
1671 **************************************************/
Johannes Bergdd7a2502010-04-28 23:33:10 -07001672 err = iwl_mac_setup_register(priv, &ucode_capa);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001673 if (err)
1674 goto out_unbind;
1675
1676 err = iwl_dbgfs_register(priv, DRV_NAME);
1677 if (err)
1678 IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
1679
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07001680 err = sysfs_create_group(&priv->pci_dev->dev.kobj,
1681 &iwl_attribute_group);
1682 if (err) {
1683 IWL_ERR(priv, "failed to create sysfs device attributes\n");
1684 goto out_unbind;
1685 }
1686
Zhu Yib481de92007-09-25 17:54:57 -07001687 /* We have our copies now, allow OS release its copies */
1688 release_firmware(ucode_raw);
Reinette Chatrea15707d2010-05-10 15:08:11 -07001689 complete(&priv->_agn.firmware_loading_complete);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001690 return;
1691
1692 try_again:
1693 /* try next, if any */
1694 if (iwl_request_firmware(priv, false))
1695 goto out_unbind;
1696 release_firmware(ucode_raw);
1697 return;
Zhu Yib481de92007-09-25 17:54:57 -07001698
1699 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08001700 IWL_ERR(priv, "failed to allocate pci memory\n");
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07001701 iwl_dealloc_ucode_pci(priv);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001702 out_unbind:
Reinette Chatrea15707d2010-05-10 15:08:11 -07001703 complete(&priv->_agn.firmware_loading_complete);
Johannes Bergb08dfd02010-01-29 11:54:56 -08001704 device_release_driver(&priv->pci_dev->dev);
Zhu Yib481de92007-09-25 17:54:57 -07001705 release_firmware(ucode_raw);
Zhu Yib481de92007-09-25 17:54:57 -07001706}
1707
Reinette Chatreb7a79402009-09-25 14:24:23 -07001708static const char *desc_lookup_text[] = {
1709 "OK",
1710 "FAIL",
1711 "BAD_PARAM",
1712 "BAD_CHECKSUM",
1713 "NMI_INTERRUPT_WDG",
1714 "SYSASSERT",
1715 "FATAL_ERROR",
1716 "BAD_COMMAND",
1717 "HW_ERROR_TUNE_LOCK",
1718 "HW_ERROR_TEMPERATURE",
1719 "ILLEGAL_CHAN_FREQ",
1720 "VCC_NOT_STABLE",
1721 "FH_ERROR",
1722 "NMI_INTERRUPT_HOST",
1723 "NMI_INTERRUPT_ACTION_PT",
1724 "NMI_INTERRUPT_UNKNOWN",
1725 "UCODE_VERSION_MISMATCH",
1726 "HW_ERROR_ABS_LOCK",
1727 "HW_ERROR_CAL_LOCK_FAIL",
1728 "NMI_INTERRUPT_INST_ACTION_PT",
1729 "NMI_INTERRUPT_DATA_ACTION_PT",
1730 "NMI_TRM_HW_ER",
1731 "NMI_INTERRUPT_TRM",
1732 "NMI_INTERRUPT_BREAK_POINT"
1733 "DEBUG_0",
1734 "DEBUG_1",
1735 "DEBUG_2",
1736 "DEBUG_3",
Reinette Chatreb7a79402009-09-25 14:24:23 -07001737};
1738
Jay Sternberg4b586452010-07-02 15:49:10 -07001739static struct { char *name; u8 num; } advanced_lookup[] = {
1740 { "NMI_INTERRUPT_WDG", 0x34 },
1741 { "SYSASSERT", 0x35 },
1742 { "UCODE_VERSION_MISMATCH", 0x37 },
1743 { "BAD_COMMAND", 0x38 },
1744 { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
1745 { "FATAL_ERROR", 0x3D },
1746 { "NMI_TRM_HW_ERR", 0x46 },
1747 { "NMI_INTERRUPT_TRM", 0x4C },
1748 { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
1749 { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
1750 { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
1751 { "NMI_INTERRUPT_HOST", 0x66 },
1752 { "NMI_INTERRUPT_ACTION_PT", 0x7C },
1753 { "NMI_INTERRUPT_UNKNOWN", 0x84 },
1754 { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
1755 { "ADVANCED_SYSASSERT", 0 },
1756};
1757
1758static const char *desc_lookup(u32 num)
Reinette Chatreb7a79402009-09-25 14:24:23 -07001759{
Jay Sternberg4b586452010-07-02 15:49:10 -07001760 int i;
1761 int max = ARRAY_SIZE(desc_lookup_text);
Reinette Chatreb7a79402009-09-25 14:24:23 -07001762
Jay Sternberg4b586452010-07-02 15:49:10 -07001763 if (num < max)
1764 return desc_lookup_text[num];
Reinette Chatreb7a79402009-09-25 14:24:23 -07001765
Jay Sternberg4b586452010-07-02 15:49:10 -07001766 max = ARRAY_SIZE(advanced_lookup) - 1;
1767 for (i = 0; i < max; i++) {
1768 if (advanced_lookup[i].num == num)
1769 break;;
1770 }
1771 return advanced_lookup[i].name;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001772}
1773
1774#define ERROR_START_OFFSET (1 * sizeof(u32))
1775#define ERROR_ELEM_SIZE (7 * sizeof(u32))
1776
1777void iwl_dump_nic_error_log(struct iwl_priv *priv)
1778{
1779 u32 data2, line;
1780 u32 desc, time, count, base, data1;
1781 u32 blink1, blink2, ilink1, ilink2;
Wey-Yi Guy461ef382010-03-30 17:57:53 -07001782 u32 pc, hcmd;
Johannes Berge46f6532011-04-13 03:14:43 -07001783 struct iwl_error_event_table table;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001784
Johannes Bergd7d57832011-04-05 09:42:04 -07001785 base = priv->device_pointers.error_event_table;
Johannes Bergca7966c2011-04-22 10:15:23 -07001786 if (priv->ucode_type == UCODE_SUBTYPE_INIT) {
Johannes Bergb2e640d2010-05-05 23:24:54 -07001787 if (!base)
1788 base = priv->_agn.init_errlog_ptr;
1789 } else {
Johannes Bergb2e640d2010-05-05 23:24:54 -07001790 if (!base)
1791 base = priv->_agn.inst_errlog_ptr;
1792 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07001793
1794 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
Wey-Yi Guy212fb572009-12-02 12:53:00 -08001795 IWL_ERR(priv,
1796 "Not valid error log pointer 0x%08X for %s uCode\n",
Johannes Bergca7966c2011-04-22 10:15:23 -07001797 base,
1798 (priv->ucode_type == UCODE_SUBTYPE_INIT)
1799 ? "Init" : "RT");
Reinette Chatreb7a79402009-09-25 14:24:23 -07001800 return;
1801 }
1802
Johannes Berge46f6532011-04-13 03:14:43 -07001803 iwl_read_targ_mem_words(priv, base, &table, sizeof(table));
1804
1805 count = table.valid;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001806
1807 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
1808 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
1809 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
1810 priv->status, count);
1811 }
1812
Johannes Berge46f6532011-04-13 03:14:43 -07001813 desc = table.error_id;
Wey-Yi Guy6e6ebf42010-08-27 10:41:37 -07001814 priv->isr_stats.err_code = desc;
Johannes Berge46f6532011-04-13 03:14:43 -07001815 pc = table.pc;
1816 blink1 = table.blink1;
1817 blink2 = table.blink2;
1818 ilink1 = table.ilink1;
1819 ilink2 = table.ilink2;
1820 data1 = table.data1;
1821 data2 = table.data2;
1822 line = table.line;
1823 time = table.tsf_low;
1824 hcmd = table.hcmd;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001825
Johannes Bergbe1a71a2009-10-02 13:44:02 -07001826 trace_iwlwifi_dev_ucode_error(priv, desc, time, data1, data2, line,
1827 blink1, blink2, ilink1, ilink2);
1828
Jay Sternberg87563712010-06-14 14:40:40 -07001829 IWL_ERR(priv, "Desc Time "
Reinette Chatreb7a79402009-09-25 14:24:23 -07001830 "data1 data2 line\n");
Jay Sternberg87563712010-06-14 14:40:40 -07001831 IWL_ERR(priv, "%-28s (0x%04X) %010u 0x%08X 0x%08X %u\n",
Reinette Chatreb7a79402009-09-25 14:24:23 -07001832 desc_lookup(desc), desc, time, data1, data2, line);
Wey-Yi Guy461ef382010-03-30 17:57:53 -07001833 IWL_ERR(priv, "pc blink1 blink2 ilink1 ilink2 hcmd\n");
1834 IWL_ERR(priv, "0x%05X 0x%05X 0x%05X 0x%05X 0x%05X 0x%05X\n",
1835 pc, blink1, blink2, ilink1, ilink2, hcmd);
Reinette Chatreb7a79402009-09-25 14:24:23 -07001836}
1837
1838#define EVENT_START_OFFSET (4 * sizeof(u32))
1839
1840/**
1841 * iwl_print_event_log - Dump error event log to syslog
1842 *
1843 */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001844static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
1845 u32 num_events, u32 mode,
1846 int pos, char **buf, size_t bufsz)
Reinette Chatreb7a79402009-09-25 14:24:23 -07001847{
1848 u32 i;
1849 u32 base; /* SRAM byte address of event log header */
1850 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
1851 u32 ptr; /* SRAM byte address of log data */
1852 u32 ev, time, data; /* event log data */
Ben Cahille5854472009-11-06 14:52:58 -08001853 unsigned long reg_flags;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001854
1855 if (num_events == 0)
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001856 return pos;
Johannes Bergb2e640d2010-05-05 23:24:54 -07001857
Johannes Bergd7d57832011-04-05 09:42:04 -07001858 base = priv->device_pointers.log_event_table;
Johannes Bergca7966c2011-04-22 10:15:23 -07001859 if (priv->ucode_type == UCODE_SUBTYPE_INIT) {
Johannes Bergb2e640d2010-05-05 23:24:54 -07001860 if (!base)
1861 base = priv->_agn.init_evtlog_ptr;
1862 } else {
Johannes Bergb2e640d2010-05-05 23:24:54 -07001863 if (!base)
1864 base = priv->_agn.inst_evtlog_ptr;
1865 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07001866
1867 if (mode == 0)
1868 event_size = 2 * sizeof(u32);
1869 else
1870 event_size = 3 * sizeof(u32);
1871
1872 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
1873
Ben Cahille5854472009-11-06 14:52:58 -08001874 /* Make sure device is powered up for SRAM reads */
1875 spin_lock_irqsave(&priv->reg_lock, reg_flags);
1876 iwl_grab_nic_access(priv);
1877
1878 /* Set starting address; reads will auto-increment */
Johannes Berg02a7fa02011-04-05 09:42:12 -07001879 iwl_write32(priv, HBUS_TARG_MEM_RADDR, ptr);
Ben Cahille5854472009-11-06 14:52:58 -08001880 rmb();
1881
Reinette Chatreb7a79402009-09-25 14:24:23 -07001882 /* "time" is actually "data" for mode 0 (no timestamp).
1883 * place event id # at far right for easier visual parsing. */
1884 for (i = 0; i < num_events; i++) {
Johannes Berg02a7fa02011-04-05 09:42:12 -07001885 ev = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
1886 time = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
Reinette Chatreb7a79402009-09-25 14:24:23 -07001887 if (mode == 0) {
1888 /* data, ev */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001889 if (bufsz) {
1890 pos += scnprintf(*buf + pos, bufsz - pos,
1891 "EVT_LOG:0x%08x:%04u\n",
1892 time, ev);
1893 } else {
1894 trace_iwlwifi_dev_ucode_event(priv, 0,
1895 time, ev);
1896 IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n",
1897 time, ev);
1898 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07001899 } else {
Johannes Berg02a7fa02011-04-05 09:42:12 -07001900 data = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001901 if (bufsz) {
1902 pos += scnprintf(*buf + pos, bufsz - pos,
1903 "EVT_LOGT:%010u:0x%08x:%04u\n",
1904 time, data, ev);
1905 } else {
1906 IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
Reinette Chatreb7a79402009-09-25 14:24:23 -07001907 time, data, ev);
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001908 trace_iwlwifi_dev_ucode_event(priv, time,
1909 data, ev);
1910 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07001911 }
1912 }
Ben Cahille5854472009-11-06 14:52:58 -08001913
1914 /* Allow device to power down */
1915 iwl_release_nic_access(priv);
1916 spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001917 return pos;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001918}
1919
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001920/**
1921 * iwl_print_last_event_logs - Dump the newest # of event log to syslog
1922 */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001923static int iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
1924 u32 num_wraps, u32 next_entry,
1925 u32 size, u32 mode,
1926 int pos, char **buf, size_t bufsz)
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001927{
1928 /*
1929 * display the newest DEFAULT_LOG_ENTRIES entries
1930 * i.e the entries just before the next ont that uCode would fill.
1931 */
1932 if (num_wraps) {
1933 if (next_entry < size) {
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001934 pos = iwl_print_event_log(priv,
1935 capacity - (size - next_entry),
1936 size - next_entry, mode,
1937 pos, buf, bufsz);
1938 pos = iwl_print_event_log(priv, 0,
1939 next_entry, mode,
1940 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001941 } else
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001942 pos = iwl_print_event_log(priv, next_entry - size,
1943 size, mode, pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001944 } else {
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001945 if (next_entry < size) {
1946 pos = iwl_print_event_log(priv, 0, next_entry,
1947 mode, pos, buf, bufsz);
1948 } else {
1949 pos = iwl_print_event_log(priv, next_entry - size,
1950 size, mode, pos, buf, bufsz);
1951 }
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001952 }
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001953 return pos;
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001954}
1955
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08001956#define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
1957
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001958int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
1959 char **buf, bool display)
Reinette Chatreb7a79402009-09-25 14:24:23 -07001960{
1961 u32 base; /* SRAM byte address of event log header */
1962 u32 capacity; /* event log capacity in # entries */
1963 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
1964 u32 num_wraps; /* # times uCode wrapped to top of log */
1965 u32 next_entry; /* index of next entry to be written by uCode */
1966 u32 size; /* # entries that we'll print */
Johannes Bergb2e640d2010-05-05 23:24:54 -07001967 u32 logsize;
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08001968 int pos = 0;
1969 size_t bufsz = 0;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001970
Johannes Bergd7d57832011-04-05 09:42:04 -07001971 base = priv->device_pointers.log_event_table;
Johannes Bergca7966c2011-04-22 10:15:23 -07001972 if (priv->ucode_type == UCODE_SUBTYPE_INIT) {
Johannes Bergb2e640d2010-05-05 23:24:54 -07001973 logsize = priv->_agn.init_evtlog_size;
1974 if (!base)
1975 base = priv->_agn.init_evtlog_ptr;
1976 } else {
Johannes Bergb2e640d2010-05-05 23:24:54 -07001977 logsize = priv->_agn.inst_evtlog_size;
1978 if (!base)
1979 base = priv->_agn.inst_evtlog_ptr;
1980 }
Reinette Chatreb7a79402009-09-25 14:24:23 -07001981
1982 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
Wey-Yi Guy212fb572009-12-02 12:53:00 -08001983 IWL_ERR(priv,
1984 "Invalid event log pointer 0x%08X for %s uCode\n",
Johannes Bergca7966c2011-04-22 10:15:23 -07001985 base,
1986 (priv->ucode_type == UCODE_SUBTYPE_INIT)
1987 ? "Init" : "RT");
Wey-Yi Guy937c3972010-01-15 13:43:36 -08001988 return -EINVAL;
Reinette Chatreb7a79402009-09-25 14:24:23 -07001989 }
1990
1991 /* event log header */
1992 capacity = iwl_read_targ_mem(priv, base);
1993 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
1994 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
1995 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
1996
Johannes Bergb2e640d2010-05-05 23:24:54 -07001997 if (capacity > logsize) {
Ben Cahill84c40692009-11-06 14:52:57 -08001998 IWL_ERR(priv, "Log capacity %d is bogus, limit to %d entries\n",
Johannes Bergb2e640d2010-05-05 23:24:54 -07001999 capacity, logsize);
2000 capacity = logsize;
Ben Cahill84c40692009-11-06 14:52:57 -08002001 }
2002
Johannes Bergb2e640d2010-05-05 23:24:54 -07002003 if (next_entry > logsize) {
Ben Cahill84c40692009-11-06 14:52:57 -08002004 IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
Johannes Bergb2e640d2010-05-05 23:24:54 -07002005 next_entry, logsize);
2006 next_entry = logsize;
Ben Cahill84c40692009-11-06 14:52:57 -08002007 }
2008
Reinette Chatreb7a79402009-09-25 14:24:23 -07002009 size = num_wraps ? capacity : next_entry;
2010
2011 /* bail out if nothing in log */
2012 if (size == 0) {
2013 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002014 return pos;
Reinette Chatreb7a79402009-09-25 14:24:23 -07002015 }
2016
Wey-Yi Guy9f28ebc2010-11-26 13:24:19 -08002017 /* enable/disable bt channel inhibition */
Wey-Yi Guyf37837c2010-08-23 07:57:12 -07002018 priv->bt_ch_announce = iwlagn_bt_ch_announce;
2019
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002020#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guy521d9bc2009-12-10 14:37:23 -08002021 if (!(iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) && !full_log)
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002022 size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
2023 ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
2024#else
2025 size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
2026 ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
Reinette Chatreb7a79402009-09-25 14:24:23 -07002027#endif
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002028 IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n",
2029 size);
2030
2031#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002032 if (display) {
2033 if (full_log)
2034 bufsz = capacity * 48;
2035 else
2036 bufsz = size * 48;
2037 *buf = kmalloc(bufsz, GFP_KERNEL);
2038 if (!*buf)
Wey-Yi Guy937c3972010-01-15 13:43:36 -08002039 return -ENOMEM;
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002040 }
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002041 if ((iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) || full_log) {
2042 /*
2043 * if uCode has wrapped back to top of log,
2044 * start at the oldest entry,
2045 * i.e the next one that uCode would fill.
2046 */
2047 if (num_wraps)
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002048 pos = iwl_print_event_log(priv, next_entry,
2049 capacity - next_entry, mode,
2050 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002051 /* (then/else) start at top of log */
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002052 pos = iwl_print_event_log(priv, 0,
2053 next_entry, mode, pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002054 } else
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002055 pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
2056 next_entry, size, mode,
2057 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002058#else
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002059 pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
2060 next_entry, size, mode,
2061 pos, buf, bufsz);
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002062#endif
Wey-Yi Guyb03d7d02009-12-14 14:12:20 -08002063 return pos;
Wey-Yi Guyc341ddb2009-11-20 12:05:07 -08002064}
Reinette Chatreb7a79402009-09-25 14:24:23 -07002065
Wey-Yi Guy0975cc82010-07-31 08:34:07 -07002066static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
2067{
2068 struct iwl_ct_kill_config cmd;
2069 struct iwl_ct_kill_throttling_config adv_cmd;
2070 unsigned long flags;
2071 int ret = 0;
2072
2073 spin_lock_irqsave(&priv->lock, flags);
2074 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
2075 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
2076 spin_unlock_irqrestore(&priv->lock, flags);
2077 priv->thermal_throttle.ct_kill_toggle = false;
2078
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002079 if (priv->cfg->base_params->support_ct_kill_exit) {
Wey-Yi Guy0975cc82010-07-31 08:34:07 -07002080 adv_cmd.critical_temperature_enter =
2081 cpu_to_le32(priv->hw_params.ct_kill_threshold);
2082 adv_cmd.critical_temperature_exit =
2083 cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
2084
2085 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
2086 sizeof(adv_cmd), &adv_cmd);
2087 if (ret)
2088 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
2089 else
2090 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
2091 "succeeded, "
2092 "critical temperature enter is %d,"
2093 "exit is %d\n",
2094 priv->hw_params.ct_kill_threshold,
2095 priv->hw_params.ct_kill_exit_threshold);
2096 } else {
2097 cmd.critical_temperature_R =
2098 cpu_to_le32(priv->hw_params.ct_kill_threshold);
2099
2100 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
2101 sizeof(cmd), &cmd);
2102 if (ret)
2103 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
2104 else
2105 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
2106 "succeeded, "
2107 "critical temperature is %d\n",
2108 priv->hw_params.ct_kill_threshold);
2109 }
2110}
2111
Shanyu Zhao6d6a1af2010-09-14 18:13:31 -07002112static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
2113{
2114 struct iwl_calib_cfg_cmd calib_cfg_cmd;
2115 struct iwl_host_cmd cmd = {
2116 .id = CALIBRATION_CFG_CMD,
2117 .len = sizeof(struct iwl_calib_cfg_cmd),
2118 .data = &calib_cfg_cmd,
2119 };
2120
2121 memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
2122 calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL;
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002123 calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg);
Shanyu Zhao6d6a1af2010-09-14 18:13:31 -07002124
2125 return iwl_send_cmd(priv, &cmd);
2126}
2127
2128
Zhu Yib481de92007-09-25 17:54:57 -07002129/**
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002130 * iwl_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002131 * from protocol/runtime uCode (initialization uCode's
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002132 * Alive gets handled by iwl_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07002133 */
Cindy H. Kao4613e722011-05-06 10:40:15 -07002134int iwl_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002135{
Tomas Winkler57aab752008-04-14 21:16:03 -07002136 int ret = 0;
Johannes Berg246ed352010-08-23 10:46:32 +02002137 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Zhu Yib481de92007-09-25 17:54:57 -07002138
Johannes Bergca7966c2011-04-22 10:15:23 -07002139 iwl_reset_ict(priv);
2140
Tomas Winklere1623442009-01-27 14:27:56 -08002141 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002142
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002143 /* After the ALIVE response, we can send host commands to the uCode */
Zhu Yib481de92007-09-25 17:54:57 -07002144 set_bit(STATUS_ALIVE, &priv->status);
2145
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002146 /* Enable watchdog to monitor the driver tx queues */
2147 iwl_setup_watchdog(priv);
Wey-Yi Guyb74e31a2010-03-01 17:23:50 -08002148
Tomas Winklerfee12472008-04-03 16:05:21 -07002149 if (iwl_is_rfkill(priv))
Johannes Bergca7966c2011-04-22 10:15:23 -07002150 return -ERFKILL;
Zhu Yib481de92007-09-25 17:54:57 -07002151
Wey-Yi Guybc795df2010-10-11 14:24:05 -07002152 /* download priority table before any calibration request */
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002153 if (priv->cfg->bt_params &&
2154 priv->cfg->bt_params->advanced_bt_coexist) {
Wey-Yi Guyf7322f82010-08-23 15:24:49 -07002155 /* Configure Bluetooth device coexistence support */
2156 priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
2157 priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
2158 priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
2159 priv->cfg->ops->hcmd->send_bt_config(priv);
2160 priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS;
Wey-Yi Guya5901cb2010-09-23 09:56:51 -07002161 iwlagn_send_prio_tbl(priv);
Wey-Yi Guyf7322f82010-08-23 15:24:49 -07002162
2163 /* FIXME: w/a to force change uCode BT state machine */
Johannes Bergca7966c2011-04-22 10:15:23 -07002164 ret = iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
2165 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
2166 if (ret)
2167 return ret;
2168 ret = iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
2169 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
2170 if (ret)
2171 return ret;
Wey-Yi Guyf7322f82010-08-23 15:24:49 -07002172 }
Wey-Yi Guybc795df2010-10-11 14:24:05 -07002173 if (priv->hw_params.calib_rt_cfg)
2174 iwlagn_send_calib_cfg_rt(priv, priv->hw_params.calib_rt_cfg);
2175
Johannes Berg36d68252008-05-15 12:55:26 +02002176 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002177
Johannes Berg470ab2d2010-01-21 11:23:30 -08002178 priv->active_rate = IWL_RATES_MASK;
Zhu Yib481de92007-09-25 17:54:57 -07002179
Wey-Yi Guy2f748de2009-09-17 10:43:51 -07002180 /* Configure Tx antenna selection based on H/W config */
2181 if (priv->cfg->ops->hcmd->set_tx_ant)
2182 priv->cfg->ops->hcmd->set_tx_ant(priv, priv->cfg->valid_tx_ant);
2183
Johannes Berg246ed352010-08-23 10:46:32 +02002184 if (iwl_is_associated_ctx(ctx)) {
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08002185 struct iwl_rxon_cmd *active_rxon =
Johannes Berg246ed352010-08-23 10:46:32 +02002186 (struct iwl_rxon_cmd *)&ctx->active;
Mohamed Abbas019fb972009-03-17 21:59:18 -07002187 /* apply any changes in staging */
Johannes Berg246ed352010-08-23 10:46:32 +02002188 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07002189 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2190 } else {
Johannes Bergd0fe4782010-08-23 10:46:58 +02002191 struct iwl_rxon_context *tmp;
Zhu Yib481de92007-09-25 17:54:57 -07002192 /* Initialize our rx_config data */
Johannes Bergd0fe4782010-08-23 10:46:58 +02002193 for_each_context(priv, tmp)
2194 iwl_connection_init_rx_config(priv, tmp);
Abhijeet Kolekar45823532009-04-08 11:26:44 -07002195
2196 if (priv->cfg->ops->hcmd->set_rxon_chain)
Johannes Berg246ed352010-08-23 10:46:32 +02002197 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
Zhu Yib481de92007-09-25 17:54:57 -07002198 }
2199
Wey-Yi Guy73b78a22011-02-11 08:13:14 -08002200 if (!priv->cfg->bt_params || (priv->cfg->bt_params &&
2201 !priv->cfg->bt_params->advanced_bt_coexist)) {
2202 /*
2203 * default is 2-wire BT coexexistence support
2204 */
Wey-Yi Guyaeb4a2e2010-08-23 07:57:05 -07002205 priv->cfg->ops->hcmd->send_bt_config(priv);
2206 }
Zhu Yib481de92007-09-25 17:54:57 -07002207
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002208 iwl_reset_run_time_calib(priv);
2209
Wey-Yi Guy9e2e7422010-11-12 13:52:37 -08002210 set_bit(STATUS_READY, &priv->status);
2211
Zhu Yib481de92007-09-25 17:54:57 -07002212 /* Configure the adapter for unassociated operation */
Johannes Bergca7966c2011-04-22 10:15:23 -07002213 ret = iwlcore_commit_rxon(priv, ctx);
2214 if (ret)
2215 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002216
2217 /* At this point, the NIC is initialized and operational */
Emmanuel Grumbach47f4a582008-06-12 09:47:13 +08002218 iwl_rf_kill_ct_config(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002219
Tomas Winklere1623442009-01-27 14:27:56 -08002220 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002221
Johannes Bergca7966c2011-04-22 10:15:23 -07002222 return iwl_power_update_mode(priv, true);
Zhu Yib481de92007-09-25 17:54:57 -07002223}
2224
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002225static void iwl_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07002226
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002227static void __iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002228{
Dan Carpenter22dd2fd2011-03-15 10:03:24 +03002229 int exit_pending;
Zhu Yib481de92007-09-25 17:54:57 -07002230
Tomas Winklere1623442009-01-27 14:27:56 -08002231 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07002232
Stanislaw Gruszkad745d472010-09-13 14:46:35 +02002233 iwl_scan_cancel_timeout(priv, 200);
2234
2235 exit_pending = test_and_set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002236
Stanislaw Gruszkab62177a2010-08-20 15:23:47 +02002237 /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
2238 * to prevent rearm timer */
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01002239 del_timer_sync(&priv->watchdog);
Stanislaw Gruszkab62177a2010-08-20 15:23:47 +02002240
Johannes Bergdcef7322010-08-27 08:55:52 -07002241 iwl_clear_ucode_stations(priv, NULL);
Johannes Berga194e322010-08-27 08:53:46 -07002242 iwl_dealloc_bcast_stations(priv);
Johannes Bergdb125c72010-05-07 01:49:15 -07002243 iwl_clear_driver_stations(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002244
Johannes Berga1174132010-08-23 07:56:59 -07002245 /* reset BT coex data */
Wey-Yi Guyda5dbb92010-08-23 07:57:13 -07002246 priv->bt_status = 0;
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002247 if (priv->cfg->bt_params)
2248 priv->bt_traffic_load =
2249 priv->cfg->bt_params->bt_init_traffic_load;
2250 else
2251 priv->bt_traffic_load = 0;
Wey-Yi Guybee008b2010-08-23 07:57:04 -07002252 priv->bt_full_concurrent = false;
2253 priv->bt_ci_compliance = 0;
Johannes Berga1174132010-08-23 07:56:59 -07002254
Zhu Yib481de92007-09-25 17:54:57 -07002255 /* Wipe out the EXIT_PENDING status bit if we are not actually
2256 * exiting the module */
2257 if (!exit_pending)
2258 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2259
Zhu Yib481de92007-09-25 17:54:57 -07002260 if (priv->mac80211_registered)
2261 ieee80211_stop_queues(priv->hw);
2262
Johannes Berg1a10f432011-04-13 03:14:44 -07002263 /* Clear out all status bits but a few that are stable across reset */
Zhu Yib481de92007-09-25 17:54:57 -07002264 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2265 STATUS_RF_KILL_HW |
Reinette Chatre97888642008-02-06 11:20:38 -08002266 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2267 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002268 test_bit(STATUS_FW_ERROR, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002269 STATUS_FW_ERROR |
2270 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2271 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002272
Johannes Bergbc4f8ad2011-04-13 03:14:45 -07002273 iwlagn_stop_device(priv);
Ben Cahill4d2ccdb2009-10-09 13:20:20 -07002274
Johannes Berg77834542010-10-04 05:50:36 -07002275 dev_kfree_skb(priv->beacon_skb);
Johannes Berg12e934d2010-10-04 05:50:06 -07002276 priv->beacon_skb = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07002277}
2278
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002279static void iwl_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002280{
2281 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002282 __iwl_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002283 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08002284
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002285 iwl_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002286}
2287
Mohamed Abbas086ed112009-05-22 11:01:54 -07002288#define HW_READY_TIMEOUT (50)
2289
Johannes Berg4cd2bf72011-04-13 03:14:52 -07002290/* Note: returns poll_bit return value, which is >= 0 if success */
Mohamed Abbas086ed112009-05-22 11:01:54 -07002291static int iwl_set_hw_ready(struct iwl_priv *priv)
2292{
Johannes Berg4cd2bf72011-04-13 03:14:52 -07002293 int ret;
Mohamed Abbas086ed112009-05-22 11:01:54 -07002294
2295 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
2296 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
2297
2298 /* See if we got it */
2299 ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
2300 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
2301 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
2302 HW_READY_TIMEOUT);
Mohamed Abbas086ed112009-05-22 11:01:54 -07002303
Johannes Berg4cd2bf72011-04-13 03:14:52 -07002304 IWL_DEBUG_INFO(priv, "hardware%s ready\n", ret < 0 ? " not" : "");
Mohamed Abbas086ed112009-05-22 11:01:54 -07002305 return ret;
2306}
2307
Johannes Berg4cd2bf72011-04-13 03:14:52 -07002308/* Note: returns standard 0/-ERROR code */
Johannes Berg3e14c1f2011-04-13 03:14:46 -07002309int iwl_prepare_card_hw(struct iwl_priv *priv)
Mohamed Abbas086ed112009-05-22 11:01:54 -07002310{
Johannes Berg4cd2bf72011-04-13 03:14:52 -07002311 int ret;
Mohamed Abbas086ed112009-05-22 11:01:54 -07002312
Frans Pop91dd6c22010-03-24 14:19:58 -07002313 IWL_DEBUG_INFO(priv, "iwl_prepare_card_hw enter\n");
Mohamed Abbas086ed112009-05-22 11:01:54 -07002314
Mohamed Abbas3354a0f2009-06-19 13:52:41 -07002315 ret = iwl_set_hw_ready(priv);
Johannes Berg4cd2bf72011-04-13 03:14:52 -07002316 if (ret >= 0)
2317 return 0;
Mohamed Abbas3354a0f2009-06-19 13:52:41 -07002318
2319 /* If HW is not ready, prepare the conditions to check again */
Mohamed Abbas086ed112009-05-22 11:01:54 -07002320 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
2321 CSR_HW_IF_CONFIG_REG_PREPARE);
2322
2323 ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
2324 ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE,
2325 CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000);
2326
Johannes Berg4cd2bf72011-04-13 03:14:52 -07002327 if (ret < 0)
2328 return ret;
Mohamed Abbas086ed112009-05-22 11:01:54 -07002329
Johannes Berg4cd2bf72011-04-13 03:14:52 -07002330 /* HW should be ready by now, check again. */
2331 ret = iwl_set_hw_ready(priv);
2332 if (ret >= 0)
2333 return 0;
Mohamed Abbas086ed112009-05-22 11:01:54 -07002334 return ret;
2335}
2336
Zhu Yib481de92007-09-25 17:54:57 -07002337#define MAX_HW_RESTARTS 5
2338
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002339static int __iwl_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002340{
Johannes Berga194e322010-08-27 08:53:46 -07002341 struct iwl_rxon_context *ctx;
Tomas Winkler57aab752008-04-14 21:16:03 -07002342 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002343
Johannes Bergca7966c2011-04-22 10:15:23 -07002344 lockdep_assert_held(&priv->mutex);
2345
Zhu Yib481de92007-09-25 17:54:57 -07002346 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002347 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07002348 return -EIO;
2349 }
2350
Johannes Berga194e322010-08-27 08:53:46 -07002351 for_each_context(priv, ctx) {
Johannes Berga30e3112010-09-22 18:02:01 +02002352 ret = iwlagn_alloc_bcast_station(priv, ctx);
Johannes Berga194e322010-08-27 08:53:46 -07002353 if (ret) {
2354 iwl_dealloc_bcast_stations(priv);
2355 return ret;
2356 }
2357 }
Johannes Berg2c810cc2010-04-29 00:53:29 -07002358
Johannes Bergca7966c2011-04-22 10:15:23 -07002359 ret = iwlagn_run_init_ucode(priv);
2360 if (ret) {
2361 IWL_ERR(priv, "Failed to run INIT ucode: %d\n", ret);
2362 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07002363 }
2364
Johannes Bergca7966c2011-04-22 10:15:23 -07002365 ret = iwlagn_load_ucode_wait_alive(priv,
Johannes Bergdbf28e212011-04-16 08:29:24 -07002366 &priv->ucode_rt,
Johannes Bergca7966c2011-04-22 10:15:23 -07002367 UCODE_SUBTYPE_REGULAR,
2368 UCODE_SUBTYPE_REGULAR_NEW);
2369 if (ret) {
2370 IWL_ERR(priv, "Failed to start RT ucode: %d\n", ret);
2371 goto error;
2372 }
2373
2374 ret = iwl_alive_start(priv);
2375 if (ret)
2376 goto error;
2377 return 0;
2378
2379 error:
Zhu Yib481de92007-09-25 17:54:57 -07002380 set_bit(STATUS_EXIT_PENDING, &priv->status);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002381 __iwl_down(priv);
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08002382 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002383
Johannes Bergca7966c2011-04-22 10:15:23 -07002384 IWL_ERR(priv, "Unable to initialize device.\n");
2385 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002386}
2387
2388
2389/*****************************************************************************
2390 *
2391 * Workqueue callbacks
2392 *
2393 *****************************************************************************/
2394
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08002395static void iwl_bg_run_time_calib_work(struct work_struct *work)
2396{
2397 struct iwl_priv *priv = container_of(work, struct iwl_priv,
2398 run_time_calib_work);
2399
2400 mutex_lock(&priv->mutex);
2401
2402 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
2403 test_bit(STATUS_SCANNING, &priv->status)) {
2404 mutex_unlock(&priv->mutex);
2405 return;
2406 }
2407
2408 if (priv->start_calib) {
Johannes Berg0da0e5b2011-04-08 08:14:56 -07002409 iwl_chain_noise_calibration(priv);
2410 iwl_sensitivity_calibration(priv);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08002411 }
2412
2413 mutex_unlock(&priv->mutex);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08002414}
2415
Johannes Berge43e85c2011-04-19 07:45:16 -07002416static void iwlagn_prepare_restart(struct iwl_priv *priv)
2417{
2418 struct iwl_rxon_context *ctx;
2419 bool bt_full_concurrent;
2420 u8 bt_ci_compliance;
2421 u8 bt_load;
2422 u8 bt_status;
2423
2424 lockdep_assert_held(&priv->mutex);
2425
2426 for_each_context(priv, ctx)
2427 ctx->vif = NULL;
2428 priv->is_open = 0;
2429
2430 /*
2431 * __iwl_down() will clear the BT status variables,
2432 * which is correct, but when we restart we really
2433 * want to keep them so restore them afterwards.
2434 *
2435 * The restart process will later pick them up and
2436 * re-configure the hw when we reconfigure the BT
2437 * command.
2438 */
2439 bt_full_concurrent = priv->bt_full_concurrent;
2440 bt_ci_compliance = priv->bt_ci_compliance;
2441 bt_load = priv->bt_traffic_load;
2442 bt_status = priv->bt_status;
2443
2444 __iwl_down(priv);
2445
2446 priv->bt_full_concurrent = bt_full_concurrent;
2447 priv->bt_ci_compliance = bt_ci_compliance;
2448 priv->bt_traffic_load = bt_load;
2449 priv->bt_status = bt_status;
2450}
2451
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002452static void iwl_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002453{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002454 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07002455
2456 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2457 return;
2458
Johannes Berg19cc1082009-05-08 13:44:36 -07002459 if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
2460 mutex_lock(&priv->mutex);
Johannes Berge43e85c2011-04-19 07:45:16 -07002461 iwlagn_prepare_restart(priv);
Johannes Berg19cc1082009-05-08 13:44:36 -07002462 mutex_unlock(&priv->mutex);
Johannes Berga1174132010-08-23 07:56:59 -07002463 iwl_cancel_deferred_work(priv);
Johannes Berg19cc1082009-05-08 13:44:36 -07002464 ieee80211_restart_hw(priv->hw);
2465 } else {
Johannes Bergca7966c2011-04-22 10:15:23 -07002466 WARN_ON(1);
Johannes Berg19cc1082009-05-08 13:44:36 -07002467 }
Zhu Yib481de92007-09-25 17:54:57 -07002468}
2469
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002470static void iwl_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002471{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002472 struct iwl_priv *priv =
2473 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07002474
2475 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2476 return;
2477
2478 mutex_lock(&priv->mutex);
Wey-Yi Guy54b81552010-03-17 13:34:35 -07002479 iwlagn_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002480 mutex_unlock(&priv->mutex);
2481}
2482
Johannes Berg266af4c72011-03-10 20:13:26 -08002483static int iwl_mac_offchannel_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
2484 struct ieee80211_channel *chan,
2485 enum nl80211_channel_type channel_type,
2486 unsigned int wait)
2487{
2488 struct iwl_priv *priv = hw->priv;
2489 int ret;
2490
2491 /* Not supported if we don't have PAN */
2492 if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN))) {
2493 ret = -EOPNOTSUPP;
2494 goto free;
2495 }
2496
2497 /* Not supported on pre-P2P firmware */
2498 if (!(priv->contexts[IWL_RXON_CTX_PAN].interface_modes &
2499 BIT(NL80211_IFTYPE_P2P_CLIENT))) {
2500 ret = -EOPNOTSUPP;
2501 goto free;
2502 }
2503
2504 mutex_lock(&priv->mutex);
2505
2506 if (!priv->contexts[IWL_RXON_CTX_PAN].is_active) {
2507 /*
2508 * If the PAN context is free, use the normal
2509 * way of doing remain-on-channel offload + TX.
2510 */
2511 ret = 1;
2512 goto out;
2513 }
2514
2515 /* TODO: queue up if scanning? */
2516 if (test_bit(STATUS_SCANNING, &priv->status) ||
2517 priv->_agn.offchan_tx_skb) {
2518 ret = -EBUSY;
2519 goto out;
2520 }
2521
2522 /*
2523 * max_scan_ie_len doesn't include the blank SSID or the header,
2524 * so need to add that again here.
2525 */
2526 if (skb->len > hw->wiphy->max_scan_ie_len + 24 + 2) {
2527 ret = -ENOBUFS;
2528 goto out;
2529 }
2530
2531 priv->_agn.offchan_tx_skb = skb;
2532 priv->_agn.offchan_tx_timeout = wait;
2533 priv->_agn.offchan_tx_chan = chan;
2534
2535 ret = iwl_scan_initiate(priv, priv->contexts[IWL_RXON_CTX_PAN].vif,
2536 IWL_SCAN_OFFCH_TX, chan->band);
2537 if (ret)
2538 priv->_agn.offchan_tx_skb = NULL;
2539 out:
2540 mutex_unlock(&priv->mutex);
2541 free:
2542 if (ret < 0)
2543 kfree_skb(skb);
2544
2545 return ret;
2546}
2547
2548static int iwl_mac_offchannel_tx_cancel_wait(struct ieee80211_hw *hw)
2549{
2550 struct iwl_priv *priv = hw->priv;
2551 int ret;
2552
2553 mutex_lock(&priv->mutex);
2554
Dan Carpenterf8a22a22011-03-15 10:01:58 +03002555 if (!priv->_agn.offchan_tx_skb) {
2556 ret = -EINVAL;
2557 goto unlock;
2558 }
Johannes Berg266af4c72011-03-10 20:13:26 -08002559
2560 priv->_agn.offchan_tx_skb = NULL;
2561
2562 ret = iwl_scan_cancel_timeout(priv, 200);
2563 if (ret)
2564 ret = -EIO;
Dan Carpenterf8a22a22011-03-15 10:01:58 +03002565unlock:
Johannes Berg266af4c72011-03-10 20:13:26 -08002566 mutex_unlock(&priv->mutex);
2567
2568 return ret;
2569}
2570
Zhu Yib481de92007-09-25 17:54:57 -07002571/*****************************************************************************
2572 *
2573 * mac80211 entry point functions
2574 *
2575 *****************************************************************************/
2576
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002577/*
2578 * Not a mac80211 entry point function, but it fits in with all the
2579 * other mac80211 functions grouped here.
2580 */
Johannes Bergdd7a2502010-04-28 23:33:10 -07002581static int iwl_mac_setup_register(struct iwl_priv *priv,
2582 struct iwlagn_ucode_capabilities *capa)
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002583{
2584 int ret;
2585 struct ieee80211_hw *hw = priv->hw;
Johannes Bergd0fe4782010-08-23 10:46:58 +02002586 struct iwl_rxon_context *ctx;
2587
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002588 hw->rate_control_algorithm = "iwl-agn-rs";
2589
2590 /* Tell mac80211 our characteristics */
2591 hw->flags = IEEE80211_HW_SIGNAL_DBM |
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002592 IEEE80211_HW_AMPDU_AGGREGATION |
Johannes Berg2491fa42010-08-23 10:46:52 +02002593 IEEE80211_HW_NEED_DTIM_PERIOD |
Johannes Berg6fb55112010-11-16 11:55:02 -08002594 IEEE80211_HW_SPECTRUM_MGMT |
2595 IEEE80211_HW_REPORTS_TX_ACK_STATUS;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002596
Johannes Berg9b768832011-01-19 02:54:18 -08002597 hw->max_tx_aggregation_subframes = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
2598
Wey-Yi Guy23c0fcc2011-04-01 16:29:53 -07002599 hw->flags |= IEEE80211_HW_SUPPORTS_PS |
2600 IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002601
Johannes Bergba37a3d2009-12-10 14:37:27 -08002602 if (priv->cfg->sku & IWL_SKU_N)
2603 hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
2604 IEEE80211_HW_SUPPORTS_STATIC_SMPS;
2605
Johannes Berg3997ff32011-04-05 09:42:02 -07002606 if (capa->flags & IWL_UCODE_TLV_FLAGS_MFP)
2607 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
2608
Reinette Chatre8d9698b2009-10-16 14:25:55 -07002609 hw->sta_data_size = sizeof(struct iwl_station_priv);
Johannes Bergfd1af152010-04-30 11:30:43 -07002610 hw->vif_data_size = sizeof(struct iwl_vif_priv);
2611
Johannes Bergd0fe4782010-08-23 10:46:58 +02002612 for_each_context(priv, ctx) {
2613 hw->wiphy->interface_modes |= ctx->interface_modes;
2614 hw->wiphy->interface_modes |= ctx->exclusive_interface_modes;
2615 }
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002616
Johannes Berg9b9190d2011-01-06 08:07:10 -08002617 hw->wiphy->max_remain_on_channel_duration = 1000;
2618
Reinette Chatref6c8f152010-03-12 11:13:26 -08002619 hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
Johannes Berg274102a2011-01-18 04:44:03 -08002620 WIPHY_FLAG_DISABLE_BEACON_HINTS |
2621 WIPHY_FLAG_IBSS_RSN;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002622
2623 /*
2624 * For now, disable PS by default because it affects
2625 * RX performance significantly.
2626 */
Johannes Berg5be83de2009-11-19 00:56:28 +01002627 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002628
Reinette Chatre1382c712010-02-25 10:02:19 -08002629 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002630 /* we create the 802.11 header and a zero-length SSID element */
Johannes Bergdd7a2502010-04-28 23:33:10 -07002631 hw->wiphy->max_scan_ie_len = capa->max_probe_length - 24 - 2;
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002632
2633 /* Default value; 4 EDCA QOS priorities */
2634 hw->queues = 4;
2635
2636 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
2637
2638 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
2639 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
2640 &priv->bands[IEEE80211_BAND_2GHZ];
2641 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
2642 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
2643 &priv->bands[IEEE80211_BAND_5GHZ];
2644
Wey-Yi Guy5ed540a2011-01-21 15:26:39 -08002645 iwl_leds_init(priv);
2646
Reinette Chatref0b6e2e2009-10-16 14:25:53 -07002647 ret = ieee80211_register_hw(priv->hw);
2648 if (ret) {
2649 IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
2650 return ret;
2651 }
2652 priv->mac80211_registered = 1;
2653
2654 return 0;
2655}
2656
2657
Johannes Berg2dedbf52011-04-05 09:41:50 -07002658static int iwlagn_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002659{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002660 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002661 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002662
Tomas Winklere1623442009-01-27 14:27:56 -08002663 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002664
2665 /* we should be verifying the device is ready to be opened */
2666 mutex_lock(&priv->mutex);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002667 ret = __iwl_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002668 mutex_unlock(&priv->mutex);
Zhu Yie655b9f2008-01-24 02:19:38 -08002669 if (ret)
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002670 return ret;
Zhu Yie655b9f2008-01-24 02:19:38 -08002671
Tomas Winklere1623442009-01-27 14:27:56 -08002672 IWL_DEBUG_INFO(priv, "Start UP work done.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08002673
Johannes Bergca7966c2011-04-22 10:15:23 -07002674 /* Now we should be done, and the READY bit should be set. */
2675 if (WARN_ON(!test_bit(STATUS_READY, &priv->status)))
2676 ret = -EIO;
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002677
Wey-Yi Guy5ed540a2011-01-21 15:26:39 -08002678 iwlagn_led_enable(priv);
Johannes Berge932a602009-10-02 13:44:03 -07002679
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002680 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08002681 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002682 return 0;
2683}
2684
Johannes Berg2dedbf52011-04-05 09:41:50 -07002685static void iwlagn_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002686{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002687 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002688
Tomas Winklere1623442009-01-27 14:27:56 -08002689 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas948c1712007-10-25 17:15:45 +08002690
Johannes Berg19cc1082009-05-08 13:44:36 -07002691 if (!priv->is_open)
Zhu Yie655b9f2008-01-24 02:19:38 -08002692 return;
Zhu Yie655b9f2008-01-24 02:19:38 -08002693
Zhu Yib481de92007-09-25 17:54:57 -07002694 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002695
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07002696 iwl_down(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002697
2698 flush_workqueue(priv->workqueue);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002699
Stanislaw Gruszka554d1d02010-12-23 12:38:21 +01002700 /* User space software may expect getting rfkill changes
2701 * even if interface is down */
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01002702 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Stanislaw Gruszka554d1d02010-12-23 12:38:21 +01002703 iwl_enable_rfkill_int(priv);
Mohamed Abbas948c1712007-10-25 17:15:45 +08002704
Tomas Winklere1623442009-01-27 14:27:56 -08002705 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002706}
2707
Johannes Berg2dedbf52011-04-05 09:41:50 -07002708static void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07002709{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002710 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002711
Tomas Winklere1623442009-01-27 14:27:56 -08002712 IWL_DEBUG_MACDUMP(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002713
Tomas Winklere1623442009-01-27 14:27:56 -08002714 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02002715 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07002716
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -07002717 if (iwlagn_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07002718 dev_kfree_skb_any(skb);
2719
Tomas Winklere1623442009-01-27 14:27:56 -08002720 IWL_DEBUG_MACDUMP(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002721}
2722
Johannes Berg2dedbf52011-04-05 09:41:50 -07002723static void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw,
2724 struct ieee80211_vif *vif,
2725 struct ieee80211_key_conf *keyconf,
2726 struct ieee80211_sta *sta,
2727 u32 iv32, u16 *phase1key)
Zhu Yib481de92007-09-25 17:54:57 -07002728{
Tomas Winkler9f586712008-11-12 13:14:05 -08002729 struct iwl_priv *priv = hw->priv;
Johannes Berga194e322010-08-27 08:53:46 -07002730 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
2731
Tomas Winklere1623442009-01-27 14:27:56 -08002732 IWL_DEBUG_MAC80211(priv, "enter\n");
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002733
Johannes Berga194e322010-08-27 08:53:46 -07002734 iwl_update_tkip_key(priv, vif_priv->ctx, keyconf, sta,
Johannes Bergb3fbdcf2010-01-21 11:40:47 +01002735 iv32, phase1key);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002736
Tomas Winklere1623442009-01-27 14:27:56 -08002737 IWL_DEBUG_MAC80211(priv, "leave\n");
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02002738}
2739
Johannes Berg2dedbf52011-04-05 09:41:50 -07002740static int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2741 struct ieee80211_vif *vif,
2742 struct ieee80211_sta *sta,
2743 struct ieee80211_key_conf *key)
Zhu Yib481de92007-09-25 17:54:57 -07002744{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002745 struct iwl_priv *priv = hw->priv;
Johannes Berga194e322010-08-27 08:53:46 -07002746 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
Johannes Bergc10afb62010-08-23 10:46:43 +02002747 struct iwl_rxon_context *ctx = vif_priv->ctx;
Winkler, Tomas42986792009-01-19 15:30:22 -08002748 int ret;
2749 u8 sta_id;
2750 bool is_default_wep_key = false;
Zhu Yib481de92007-09-25 17:54:57 -07002751
Tomas Winklere1623442009-01-27 14:27:56 -08002752 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002753
Don Fry9d143e92011-04-20 15:23:57 -07002754 if (iwlagn_mod_params.sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08002755 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07002756 return -EOPNOTSUPP;
2757 }
Zhu Yib481de92007-09-25 17:54:57 -07002758
Johannes Berg274102a2011-01-18 04:44:03 -08002759 /*
2760 * To support IBSS RSN, don't program group keys in IBSS, the
2761 * hardware will then not attempt to decrypt the frames.
2762 */
2763 if (vif->type == NL80211_IFTYPE_ADHOC &&
2764 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
2765 return -EOPNOTSUPP;
2766
Johannes Berga194e322010-08-27 08:53:46 -07002767 sta_id = iwl_sta_id_or_broadcast(priv, vif_priv->ctx, sta);
Johannes Berg0af8bca2010-04-30 14:08:00 -07002768 if (sta_id == IWL_INVALID_STATION)
2769 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002770
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002771 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002772 iwl_scan_cancel_timeout(priv, 100);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002773
Johannes Berga90178fa2010-03-30 02:44:16 -07002774 /*
2775 * If we are getting WEP group key and we didn't receive any key mapping
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002776 * so far, we are in legacy wep mode (group key only), otherwise we are
2777 * in 1X mode.
Johannes Berga90178fa2010-03-30 02:44:16 -07002778 * In legacy wep mode, we use another host command to the uCode.
2779 */
Johannes Berg97359d12010-08-10 09:46:38 +02002780 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2781 key->cipher == WLAN_CIPHER_SUITE_WEP104) &&
Johannes Berg54c80672010-08-18 09:35:21 -07002782 !sta) {
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002783 if (cmd == SET_KEY)
Johannes Bergc10afb62010-08-23 10:46:43 +02002784 is_default_wep_key = !ctx->key_mapping_keys;
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002785 else
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +08002786 is_default_wep_key =
2787 (key->hw_key_idx == HW_KEY_DEFAULT);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002788 }
mabbas052c4b92007-10-25 17:15:43 +08002789
Zhu Yib481de92007-09-25 17:54:57 -07002790 switch (cmd) {
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002791 case SET_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002792 if (is_default_wep_key)
Johannes Berg2995baf2010-08-23 10:46:42 +02002793 ret = iwl_set_default_wep_key(priv, vif_priv->ctx, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002794 else
Johannes Berga194e322010-08-27 08:53:46 -07002795 ret = iwl_set_dynamic_key(priv, vif_priv->ctx,
2796 key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002797
Tomas Winklere1623442009-01-27 14:27:56 -08002798 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07002799 break;
2800 case DISABLE_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07002801 if (is_default_wep_key)
Johannes Bergc10afb62010-08-23 10:46:43 +02002802 ret = iwl_remove_default_wep_key(priv, ctx, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002803 else
Johannes Bergc10afb62010-08-23 10:46:43 +02002804 ret = iwl_remove_dynamic_key(priv, ctx, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002805
Tomas Winklere1623442009-01-27 14:27:56 -08002806 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07002807 break;
2808 default:
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002809 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002810 }
2811
Johannes Berg72e15d72010-02-19 11:42:32 -08002812 mutex_unlock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08002813 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002814
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07002815 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002816}
2817
Johannes Berg2dedbf52011-04-05 09:41:50 -07002818static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
2819 struct ieee80211_vif *vif,
2820 enum ieee80211_ampdu_mlme_action action,
2821 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
2822 u8 buf_size)
Tomas Winklerd783b062008-07-18 13:53:02 +08002823{
2824 struct iwl_priv *priv = hw->priv;
Johannes Berg4620fef2010-06-16 03:30:27 -07002825 int ret = -EINVAL;
Johannes Berg7b090682011-01-19 02:53:54 -08002826 struct iwl_station_priv *sta_priv = (void *) sta->drv_priv;
Tomas Winklerd783b062008-07-18 13:53:02 +08002827
Tomas Winklere1623442009-01-27 14:27:56 -08002828 IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
Johannes Berge1749612008-10-27 15:59:26 -07002829 sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08002830
2831 if (!(priv->cfg->sku & IWL_SKU_N))
2832 return -EACCES;
2833
Johannes Berg4620fef2010-06-16 03:30:27 -07002834 mutex_lock(&priv->mutex);
2835
Tomas Winklerd783b062008-07-18 13:53:02 +08002836 switch (action) {
2837 case IEEE80211_AMPDU_RX_START:
Tomas Winklere1623442009-01-27 14:27:56 -08002838 IWL_DEBUG_HT(priv, "start Rx\n");
Johannes Berg4620fef2010-06-16 03:30:27 -07002839 ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn);
2840 break;
Tomas Winklerd783b062008-07-18 13:53:02 +08002841 case IEEE80211_AMPDU_RX_STOP:
Tomas Winklere1623442009-01-27 14:27:56 -08002842 IWL_DEBUG_HT(priv, "stop Rx\n");
Johannes Berg619753f2010-04-30 11:30:46 -07002843 ret = iwl_sta_rx_agg_stop(priv, sta, tid);
Wey-Yi Guy5c2207c2009-03-17 21:51:43 -07002844 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Johannes Berg4620fef2010-06-16 03:30:27 -07002845 ret = 0;
2846 break;
Tomas Winklerd783b062008-07-18 13:53:02 +08002847 case IEEE80211_AMPDU_TX_START:
Tomas Winklere1623442009-01-27 14:27:56 -08002848 IWL_DEBUG_HT(priv, "start Tx\n");
Johannes Berg619753f2010-04-30 11:30:46 -07002849 ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn);
Wey-Yi Guyd5a0ffa2010-03-04 13:38:59 -08002850 if (ret == 0) {
2851 priv->_agn.agg_tids_count++;
2852 IWL_DEBUG_HT(priv, "priv->_agn.agg_tids_count = %u\n",
2853 priv->_agn.agg_tids_count);
2854 }
Johannes Berg4620fef2010-06-16 03:30:27 -07002855 break;
Tomas Winklerd783b062008-07-18 13:53:02 +08002856 case IEEE80211_AMPDU_TX_STOP:
Tomas Winklere1623442009-01-27 14:27:56 -08002857 IWL_DEBUG_HT(priv, "stop Tx\n");
Johannes Berg619753f2010-04-30 11:30:46 -07002858 ret = iwlagn_tx_agg_stop(priv, vif, sta, tid);
Wey-Yi Guyd5a0ffa2010-03-04 13:38:59 -08002859 if ((ret == 0) && (priv->_agn.agg_tids_count > 0)) {
2860 priv->_agn.agg_tids_count--;
2861 IWL_DEBUG_HT(priv, "priv->_agn.agg_tids_count = %u\n",
2862 priv->_agn.agg_tids_count);
2863 }
Wey-Yi Guy5c2207c2009-03-17 21:51:43 -07002864 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Johannes Berg4620fef2010-06-16 03:30:27 -07002865 ret = 0;
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002866 if (priv->cfg->ht_params &&
2867 priv->cfg->ht_params->use_rts_for_aggregation) {
Johannes Berg94597ab2010-08-09 10:57:02 -07002868 struct iwl_station_priv *sta_priv =
2869 (void *) sta->drv_priv;
2870 /*
2871 * switch off RTS/CTS if it was previously enabled
2872 */
2873
2874 sta_priv->lq_sta.lq.general_params.flags &=
2875 ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
Johannes Berg7e6a5882010-08-23 10:46:46 +02002876 iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
2877 &sta_priv->lq_sta.lq, CMD_ASYNC, false);
Johannes Berg94597ab2010-08-09 10:57:02 -07002878 }
Johannes Berg4620fef2010-06-16 03:30:27 -07002879 break;
Wey-Yi Guyf0527972010-01-08 10:04:41 -08002880 case IEEE80211_AMPDU_TX_OPERATIONAL:
Johannes Bergc8823ec2011-03-15 11:33:03 -07002881 buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF);
2882
2883 iwlagn_txq_agg_queue_setup(priv, sta, tid, buf_size);
2884
Johannes Berg7b090682011-01-19 02:53:54 -08002885 /*
2886 * If the limit is 0, then it wasn't initialised yet,
2887 * use the default. We can do that since we take the
2888 * minimum below, and we don't want to go above our
2889 * default due to hardware restrictions.
2890 */
2891 if (sta_priv->max_agg_bufsize == 0)
2892 sta_priv->max_agg_bufsize =
2893 LINK_QUAL_AGG_FRAME_LIMIT_DEF;
2894
2895 /*
2896 * Even though in theory the peer could have different
2897 * aggregation reorder buffer sizes for different sessions,
2898 * our ucode doesn't allow for that and has a global limit
2899 * for each station. Therefore, use the minimum of all the
2900 * aggregation sessions and our default value.
2901 */
2902 sta_priv->max_agg_bufsize =
2903 min(sta_priv->max_agg_bufsize, buf_size);
2904
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07002905 if (priv->cfg->ht_params &&
2906 priv->cfg->ht_params->use_rts_for_aggregation) {
Wey-Yi Guycfecc6b2010-06-18 11:33:15 -07002907 /*
2908 * switch to RTS/CTS if it is the prefer protection
2909 * method for HT traffic
2910 */
Johannes Berg94597ab2010-08-09 10:57:02 -07002911
2912 sta_priv->lq_sta.lq.general_params.flags |=
2913 LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
Wey-Yi Guycfecc6b2010-06-18 11:33:15 -07002914 }
Johannes Berg7b090682011-01-19 02:53:54 -08002915
2916 sta_priv->lq_sta.lq.agg_params.agg_frame_cnt_limit =
2917 sta_priv->max_agg_bufsize;
2918
2919 iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
2920 &sta_priv->lq_sta.lq, CMD_ASYNC, false);
Wey-Yi Guycfecc6b2010-06-18 11:33:15 -07002921 ret = 0;
Tomas Winklerd783b062008-07-18 13:53:02 +08002922 break;
2923 }
Johannes Berg4620fef2010-06-16 03:30:27 -07002924 mutex_unlock(&priv->mutex);
2925
2926 return ret;
Tomas Winklerd783b062008-07-18 13:53:02 +08002927}
Tomas Winkler9f586712008-11-12 13:14:05 -08002928
Johannes Berg2dedbf52011-04-05 09:41:50 -07002929static int iwlagn_mac_sta_add(struct ieee80211_hw *hw,
2930 struct ieee80211_vif *vif,
2931 struct ieee80211_sta *sta)
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002932{
2933 struct iwl_priv *priv = hw->priv;
2934 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
Johannes Berga194e322010-08-27 08:53:46 -07002935 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
Johannes Bergeafdfbd32010-04-29 04:43:04 -07002936 bool is_ap = vif->type == NL80211_IFTYPE_STATION;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002937 int ret;
2938 u8 sta_id;
2939
2940 IWL_DEBUG_INFO(priv, "received request to add station %pM\n",
2941 sta->addr);
Reinette Chatreda5ae1c2010-05-28 09:28:39 -07002942 mutex_lock(&priv->mutex);
2943 IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
2944 sta->addr);
2945 sta_priv->common.sta_id = IWL_INVALID_STATION;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002946
2947 atomic_set(&sta_priv->pending_frames, 0);
2948 if (vif->type == NL80211_IFTYPE_AP)
2949 sta_priv->client = true;
2950
Johannes Berga194e322010-08-27 08:53:46 -07002951 ret = iwl_add_station_common(priv, vif_priv->ctx, sta->addr,
Johannes Berg238d7812010-08-23 10:46:45 +02002952 is_ap, sta, &sta_id);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002953 if (ret) {
2954 IWL_ERR(priv, "Unable to add station %pM (%d)\n",
2955 sta->addr, ret);
2956 /* Should we return success if return code is EEXIST ? */
Reinette Chatreda5ae1c2010-05-28 09:28:39 -07002957 mutex_unlock(&priv->mutex);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002958 return ret;
2959 }
2960
Johannes Bergfd1af152010-04-30 11:30:43 -07002961 sta_priv->common.sta_id = sta_id;
2962
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002963 /* Initialize rate scaling */
Frans Pop91dd6c22010-03-24 14:19:58 -07002964 IWL_DEBUG_INFO(priv, "Initializing rate scaling for station %pM\n",
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002965 sta->addr);
2966 iwl_rs_rate_init(priv, sta, sta_id);
Reinette Chatreda5ae1c2010-05-28 09:28:39 -07002967 mutex_unlock(&priv->mutex);
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002968
Johannes Bergfd1af152010-04-30 11:30:43 -07002969 return 0;
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08002970}
2971
Johannes Berg2dedbf52011-04-05 09:41:50 -07002972static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
2973 struct ieee80211_channel_switch *ch_switch)
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002974{
2975 struct iwl_priv *priv = hw->priv;
2976 const struct iwl_channel_info *ch_info;
2977 struct ieee80211_conf *conf = &hw->conf;
Shanyu Zhaoaa2dc6b2010-07-28 13:40:39 -07002978 struct ieee80211_channel *channel = ch_switch->channel;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002979 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
Johannes Berg246ed352010-08-23 10:46:32 +02002980 /*
2981 * MULTI-FIXME
2982 * When we add support for multiple interfaces, we need to
2983 * revisit this. The channel switch command in the device
2984 * only affects the BSS context, but what does that really
2985 * mean? And what if we get a CSA on the second interface?
2986 * This needs a lot of work.
2987 */
2988 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002989 u16 ch;
2990 unsigned long flags = 0;
2991
2992 IWL_DEBUG_MAC80211(priv, "enter\n");
2993
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +02002994 mutex_lock(&priv->mutex);
2995
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002996 if (iwl_is_rfkill(priv))
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +02002997 goto out;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07002998
2999 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
3000 test_bit(STATUS_SCANNING, &priv->status))
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +02003001 goto out;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003002
Johannes Berg246ed352010-08-23 10:46:32 +02003003 if (!iwl_is_associated_ctx(ctx))
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +02003004 goto out;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003005
3006 /* channel switch in progress */
3007 if (priv->switch_rxon.switch_in_progress == true)
Stanislaw Gruszkadc1a4062011-03-31 17:36:27 +02003008 goto out;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003009
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003010 if (priv->cfg->ops->lib->set_channel_switch) {
3011
Shanyu Zhaoaa2dc6b2010-07-28 13:40:39 -07003012 ch = channel->hw_value;
Johannes Berg246ed352010-08-23 10:46:32 +02003013 if (le16_to_cpu(ctx->active.channel) != ch) {
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003014 ch_info = iwl_get_channel_info(priv,
Shanyu Zhaoaa2dc6b2010-07-28 13:40:39 -07003015 channel->band,
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003016 ch);
3017 if (!is_channel_valid(ch_info)) {
3018 IWL_DEBUG_MAC80211(priv, "invalid channel\n");
3019 goto out;
3020 }
3021 spin_lock_irqsave(&priv->lock, flags);
3022
3023 priv->current_ht_config.smps = conf->smps_mode;
3024
3025 /* Configure HT40 channels */
Johannes Berg7e6a5882010-08-23 10:46:46 +02003026 ctx->ht.enabled = conf_is_ht(conf);
3027 if (ctx->ht.enabled) {
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003028 if (conf_is_ht40_minus(conf)) {
Johannes Berg7e6a5882010-08-23 10:46:46 +02003029 ctx->ht.extension_chan_offset =
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003030 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
Johannes Berg7e6a5882010-08-23 10:46:46 +02003031 ctx->ht.is_40mhz = true;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003032 } else if (conf_is_ht40_plus(conf)) {
Johannes Berg7e6a5882010-08-23 10:46:46 +02003033 ctx->ht.extension_chan_offset =
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003034 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
Johannes Berg7e6a5882010-08-23 10:46:46 +02003035 ctx->ht.is_40mhz = true;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003036 } else {
Johannes Berg7e6a5882010-08-23 10:46:46 +02003037 ctx->ht.extension_chan_offset =
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003038 IEEE80211_HT_PARAM_CHA_SEC_NONE;
Johannes Berg7e6a5882010-08-23 10:46:46 +02003039 ctx->ht.is_40mhz = false;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003040 }
3041 } else
Johannes Berg7e6a5882010-08-23 10:46:46 +02003042 ctx->ht.is_40mhz = false;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003043
Johannes Berg246ed352010-08-23 10:46:32 +02003044 if ((le16_to_cpu(ctx->staging.channel) != ch))
3045 ctx->staging.flags = 0;
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003046
Johannes Berg246ed352010-08-23 10:46:32 +02003047 iwl_set_rxon_channel(priv, channel, ctx);
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003048 iwl_set_rxon_ht(priv, ht_conf);
Johannes Berg246ed352010-08-23 10:46:32 +02003049 iwl_set_flags_for_band(priv, ctx, channel->band,
Johannes Berg8bd413e2010-08-23 10:46:40 +02003050 ctx->vif);
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003051 spin_unlock_irqrestore(&priv->lock, flags);
3052
3053 iwl_set_rate(priv);
3054 /*
3055 * at this point, staging_rxon has the
3056 * configuration for channel switch
3057 */
3058 if (priv->cfg->ops->lib->set_channel_switch(priv,
3059 ch_switch))
3060 priv->switch_rxon.switch_in_progress = false;
3061 }
3062 }
3063out:
3064 mutex_unlock(&priv->mutex);
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003065 if (!priv->switch_rxon.switch_in_progress)
Johannes Berg8bd413e2010-08-23 10:46:40 +02003066 ieee80211_chswitch_done(ctx->vif, false);
Wey-Yi Guy79d07322010-05-06 08:54:11 -07003067 IWL_DEBUG_MAC80211(priv, "leave\n");
3068}
3069
Johannes Berg2dedbf52011-04-05 09:41:50 -07003070static void iwlagn_configure_filter(struct ieee80211_hw *hw,
3071 unsigned int changed_flags,
3072 unsigned int *total_flags,
3073 u64 multicast)
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02003074{
3075 struct iwl_priv *priv = hw->priv;
3076 __le32 filter_or = 0, filter_nand = 0;
Johannes Berg246ed352010-08-23 10:46:32 +02003077 struct iwl_rxon_context *ctx;
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02003078
3079#define CHK(test, flag) do { \
3080 if (*total_flags & (test)) \
3081 filter_or |= (flag); \
3082 else \
3083 filter_nand |= (flag); \
3084 } while (0)
3085
3086 IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
3087 changed_flags, *total_flags);
3088
3089 CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
Johannes Bergbdb84fe2010-12-15 06:07:56 -08003090 /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */
3091 CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK);
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02003092 CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
3093
3094#undef CHK
3095
3096 mutex_lock(&priv->mutex);
3097
Johannes Berg246ed352010-08-23 10:46:32 +02003098 for_each_context(priv, ctx) {
3099 ctx->staging.filter_flags &= ~filter_nand;
3100 ctx->staging.filter_flags |= filter_or;
Stanislaw Gruszka749ff4ef2010-10-22 17:04:27 +02003101
3102 /*
3103 * Not committing directly because hardware can perform a scan,
3104 * but we'll eventually commit the filter flags change anyway.
3105 */
Johannes Berg246ed352010-08-23 10:46:32 +02003106 }
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02003107
3108 mutex_unlock(&priv->mutex);
3109
3110 /*
3111 * Receiving all multicast frames is always enabled by the
3112 * default flags setup in iwl_connection_init_rx_config()
3113 * since we currently do not support programming multicast
3114 * filters into the device.
3115 */
3116 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
3117 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
3118}
3119
Johannes Berg2dedbf52011-04-05 09:41:50 -07003120static void iwlagn_mac_flush(struct ieee80211_hw *hw, bool drop)
Wey-Yi Guy716c74b2010-06-24 13:22:36 -07003121{
3122 struct iwl_priv *priv = hw->priv;
3123
3124 mutex_lock(&priv->mutex);
3125 IWL_DEBUG_MAC80211(priv, "enter\n");
3126
3127 /* do not support "flush" */
3128 if (!priv->cfg->ops->lib->txfifo_flush)
3129 goto done;
3130
3131 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
3132 IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n");
3133 goto done;
3134 }
3135 if (iwl_is_rfkill(priv)) {
3136 IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n");
3137 goto done;
3138 }
3139
3140 /*
3141 * mac80211 will not push any more frames for transmit
3142 * until the flush is completed
3143 */
3144 if (drop) {
3145 IWL_DEBUG_MAC80211(priv, "send flush command\n");
3146 if (priv->cfg->ops->lib->txfifo_flush(priv, IWL_DROP_ALL)) {
3147 IWL_ERR(priv, "flush request fail\n");
3148 goto done;
3149 }
3150 }
3151 IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n");
3152 iwlagn_wait_tx_queue_empty(priv);
3153done:
3154 mutex_unlock(&priv->mutex);
3155 IWL_DEBUG_MAC80211(priv, "leave\n");
3156}
3157
Johannes Berg9b9190d2011-01-06 08:07:10 -08003158static void iwlagn_disable_roc(struct iwl_priv *priv)
3159{
3160 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
3161 struct ieee80211_channel *chan = ACCESS_ONCE(priv->hw->conf.channel);
3162
3163 lockdep_assert_held(&priv->mutex);
3164
3165 if (!ctx->is_active)
3166 return;
3167
3168 ctx->staging.dev_type = RXON_DEV_TYPE_2STA;
3169 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3170 iwl_set_rxon_channel(priv, chan, ctx);
3171 iwl_set_flags_for_band(priv, ctx, chan->band, NULL);
3172
3173 priv->_agn.hw_roc_channel = NULL;
3174
Wey-Yi Guy80b38ff2011-02-04 10:46:41 -08003175 iwlcore_commit_rxon(priv, ctx);
Johannes Berg9b9190d2011-01-06 08:07:10 -08003176
3177 ctx->is_active = false;
3178}
3179
3180static void iwlagn_bg_roc_done(struct work_struct *work)
3181{
3182 struct iwl_priv *priv = container_of(work, struct iwl_priv,
3183 _agn.hw_roc_work.work);
3184
3185 mutex_lock(&priv->mutex);
3186 ieee80211_remain_on_channel_expired(priv->hw);
3187 iwlagn_disable_roc(priv);
3188 mutex_unlock(&priv->mutex);
3189}
3190
3191static int iwl_mac_remain_on_channel(struct ieee80211_hw *hw,
3192 struct ieee80211_channel *channel,
3193 enum nl80211_channel_type channel_type,
3194 int duration)
3195{
3196 struct iwl_priv *priv = hw->priv;
3197 int err = 0;
3198
3199 if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
3200 return -EOPNOTSUPP;
3201
3202 if (!(priv->contexts[IWL_RXON_CTX_PAN].interface_modes &
3203 BIT(NL80211_IFTYPE_P2P_CLIENT)))
3204 return -EOPNOTSUPP;
3205
3206 mutex_lock(&priv->mutex);
3207
3208 if (priv->contexts[IWL_RXON_CTX_PAN].is_active ||
3209 test_bit(STATUS_SCAN_HW, &priv->status)) {
3210 err = -EBUSY;
3211 goto out;
3212 }
3213
3214 priv->contexts[IWL_RXON_CTX_PAN].is_active = true;
3215 priv->_agn.hw_roc_channel = channel;
3216 priv->_agn.hw_roc_chantype = channel_type;
3217 priv->_agn.hw_roc_duration = DIV_ROUND_UP(duration * 1000, 1024);
Wey-Yi Guy80b38ff2011-02-04 10:46:41 -08003218 iwlcore_commit_rxon(priv, &priv->contexts[IWL_RXON_CTX_PAN]);
Johannes Berg9b9190d2011-01-06 08:07:10 -08003219 queue_delayed_work(priv->workqueue, &priv->_agn.hw_roc_work,
3220 msecs_to_jiffies(duration + 20));
3221
Johannes Berg94073912011-01-06 08:07:11 -08003222 msleep(IWL_MIN_SLOT_TIME); /* TU is almost ms */
Johannes Berg9b9190d2011-01-06 08:07:10 -08003223 ieee80211_ready_on_channel(priv->hw);
3224
3225 out:
3226 mutex_unlock(&priv->mutex);
3227
3228 return err;
3229}
3230
3231static int iwl_mac_cancel_remain_on_channel(struct ieee80211_hw *hw)
3232{
3233 struct iwl_priv *priv = hw->priv;
3234
3235 if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
3236 return -EOPNOTSUPP;
3237
3238 cancel_delayed_work_sync(&priv->_agn.hw_roc_work);
3239
3240 mutex_lock(&priv->mutex);
3241 iwlagn_disable_roc(priv);
3242 mutex_unlock(&priv->mutex);
3243
3244 return 0;
3245}
3246
Zhu Yib481de92007-09-25 17:54:57 -07003247/*****************************************************************************
3248 *
Zhu Yib481de92007-09-25 17:54:57 -07003249 * driver setup and teardown
3250 *
3251 *****************************************************************************/
3252
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003253static void iwl_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003254{
Reinette Chatred21050c2009-02-13 11:51:18 -08003255 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07003256
3257 init_waitqueue_head(&priv->wait_command_queue);
3258
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003259 INIT_WORK(&priv->restart, iwl_bg_restart);
3260 INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003261 INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08003262 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
Wey-Yi Guy65550632010-06-24 13:18:35 -07003263 INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
Wey-Yi Guybee008b2010-08-23 07:57:04 -07003264 INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
Wey-Yi Guyfbba9412010-08-23 07:57:10 -07003265 INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
Johannes Berg9b9190d2011-01-06 08:07:10 -08003266 INIT_DELAYED_WORK(&priv->_agn.hw_roc_work, iwlagn_bg_roc_done);
Tomas Winkler2a421b92008-06-12 09:47:10 +08003267
Tomas Winkler2a421b92008-06-12 09:47:10 +08003268 iwl_setup_scan_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003269
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003270 if (priv->cfg->ops->lib->setup_deferred_work)
3271 priv->cfg->ops->lib->setup_deferred_work(priv);
3272
3273 init_timer(&priv->statistics_periodic);
3274 priv->statistics_periodic.data = (unsigned long)priv;
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003275 priv->statistics_periodic.function = iwl_bg_statistics_periodic;
Zhu Yib481de92007-09-25 17:54:57 -07003276
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08003277 init_timer(&priv->ucode_trace);
3278 priv->ucode_trace.data = (unsigned long)priv;
3279 priv->ucode_trace.function = iwl_bg_ucode_trace;
3280
Stanislaw Gruszka22de94d2010-12-03 15:41:48 +01003281 init_timer(&priv->watchdog);
3282 priv->watchdog.data = (unsigned long)priv;
3283 priv->watchdog.function = iwl_bg_watchdog;
Wey-Yi Guyb74e31a2010-03-01 17:23:50 -08003284
Wey-Yi Guyd6b80612011-03-21 16:53:38 -07003285 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
3286 iwl_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07003287}
3288
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003289static void iwl_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003290{
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003291 if (priv->cfg->ops->lib->cancel_deferred_work)
3292 priv->cfg->ops->lib->cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003293
Wey-Yi Guy815e6292010-06-03 10:14:01 -07003294 cancel_work_sync(&priv->run_time_calib_work);
Zhu Yib481de92007-09-25 17:54:57 -07003295 cancel_work_sync(&priv->beacon_update);
Stanislaw Gruszkae7e16b92010-09-13 14:46:41 +02003296
3297 iwl_cancel_scan_deferred_work(priv);
3298
Wey-Yi Guybee008b2010-08-23 07:57:04 -07003299 cancel_work_sync(&priv->bt_full_concurrency);
Wey-Yi Guyfbba9412010-08-23 07:57:10 -07003300 cancel_work_sync(&priv->bt_runtime_config);
Stanislaw Gruszkae7e16b92010-09-13 14:46:41 +02003301
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003302 del_timer_sync(&priv->statistics_periodic);
Wey-Yi Guya9e1cb62009-12-10 14:37:26 -08003303 del_timer_sync(&priv->ucode_trace);
Zhu Yib481de92007-09-25 17:54:57 -07003304}
3305
Reinette Chatre89f186a2009-10-30 14:36:11 -07003306static void iwl_init_hw_rates(struct iwl_priv *priv,
3307 struct ieee80211_rate *rates)
3308{
3309 int i;
3310
3311 for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
3312 rates[i].bitrate = iwl_rates[i].ieee * 5;
3313 rates[i].hw_value = i; /* Rate scaling will work on indexes */
3314 rates[i].hw_value_short = i;
3315 rates[i].flags = 0;
3316 if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
3317 /*
3318 * If CCK != 1M then set short preamble rate flag.
3319 */
3320 rates[i].flags |=
3321 (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
3322 0 : IEEE80211_RATE_SHORT_PREAMBLE;
3323 }
3324 }
3325}
3326
3327static int iwl_init_drv(struct iwl_priv *priv)
3328{
3329 int ret;
3330
Reinette Chatre89f186a2009-10-30 14:36:11 -07003331 spin_lock_init(&priv->sta_lock);
3332 spin_lock_init(&priv->hcmd_lock);
3333
Reinette Chatre89f186a2009-10-30 14:36:11 -07003334 mutex_init(&priv->mutex);
3335
Reinette Chatre89f186a2009-10-30 14:36:11 -07003336 priv->ieee_channels = NULL;
3337 priv->ieee_rates = NULL;
3338 priv->band = IEEE80211_BAND_2GHZ;
3339
3340 priv->iw_mode = NL80211_IFTYPE_STATION;
Johannes Bergba37a3d2009-12-10 14:37:27 -08003341 priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
Wey-Yi Guya13d2762010-01-22 14:22:42 -08003342 priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
Wey-Yi Guyd5a0ffa2010-03-04 13:38:59 -08003343 priv->_agn.agg_tids_count = 0;
Reinette Chatre89f186a2009-10-30 14:36:11 -07003344
Wey-Yi Guy8a472da2010-02-18 22:03:06 -08003345 /* initialize force reset */
3346 priv->force_reset[IWL_RF_RESET].reset_duration =
3347 IWL_DELAY_NEXT_FORCE_RF_RESET;
3348 priv->force_reset[IWL_FW_RESET].reset_duration =
3349 IWL_DELAY_NEXT_FORCE_FW_RELOAD;
Reinette Chatre89f186a2009-10-30 14:36:11 -07003350
Stanislaw Gruszka410f2bb2011-03-04 17:51:51 +01003351 priv->rx_statistics_jiffies = jiffies;
3352
Reinette Chatre89f186a2009-10-30 14:36:11 -07003353 /* Choose which receivers/antennas to use */
3354 if (priv->cfg->ops->hcmd->set_rxon_chain)
Johannes Berg246ed352010-08-23 10:46:32 +02003355 priv->cfg->ops->hcmd->set_rxon_chain(priv,
3356 &priv->contexts[IWL_RXON_CTX_BSS]);
Reinette Chatre89f186a2009-10-30 14:36:11 -07003357
3358 iwl_init_scan_params(priv);
3359
Wey-Yi Guy22bf59a2010-08-23 07:57:11 -07003360 /* init bt coex */
Wey-Yi Guy7cb1b082010-10-06 08:10:00 -07003361 if (priv->cfg->bt_params &&
3362 priv->cfg->bt_params->advanced_bt_coexist) {
Wey-Yi Guyb6e116e2010-08-23 07:57:14 -07003363 priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
3364 priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
3365 priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
Wey-Yi Guy22bf59a2010-08-23 07:57:11 -07003366 priv->bt_on_thresh = BT_ON_THRESHOLD_DEF;
3367 priv->bt_duration = BT_DURATION_LIMIT_DEF;
3368 priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
Wey-Yi Guy22bf59a2010-08-23 07:57:11 -07003369 }
3370
Reinette Chatre89f186a2009-10-30 14:36:11 -07003371 ret = iwl_init_channel_map(priv);
3372 if (ret) {
3373 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
3374 goto err;
3375 }
3376
3377 ret = iwlcore_init_geos(priv);
3378 if (ret) {
3379 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
3380 goto err_free_channel_map;
3381 }
3382 iwl_init_hw_rates(priv, priv->ieee_rates);
3383
3384 return 0;
3385
3386err_free_channel_map:
3387 iwl_free_channel_map(priv);
3388err:
3389 return ret;
3390}
3391
3392static void iwl_uninit_drv(struct iwl_priv *priv)
3393{
3394 iwl_calib_free_results(priv);
3395 iwlcore_free_geos(priv);
3396 iwl_free_channel_map(priv);
Johannes Berg811ecc92010-04-06 04:12:41 -07003397 kfree(priv->scan_cmd);
Reinette Chatre89f186a2009-10-30 14:36:11 -07003398}
3399
Johannes Bergdc21b542010-10-23 09:15:39 -07003400struct ieee80211_ops iwlagn_hw_ops = {
Johannes Berg2295c662010-10-23 09:15:41 -07003401 .tx = iwlagn_mac_tx,
3402 .start = iwlagn_mac_start,
3403 .stop = iwlagn_mac_stop,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003404 .add_interface = iwl_mac_add_interface,
3405 .remove_interface = iwl_mac_remove_interface,
Johannes Bergd4daaea2010-10-23 09:15:43 -07003406 .change_interface = iwl_mac_change_interface,
Johannes Berg2295c662010-10-23 09:15:41 -07003407 .config = iwlagn_mac_config,
Johannes Berg8b8ab9d2010-08-17 11:24:01 +02003408 .configure_filter = iwlagn_configure_filter,
Johannes Berg2295c662010-10-23 09:15:41 -07003409 .set_key = iwlagn_mac_set_key,
3410 .update_tkip_key = iwlagn_mac_update_tkip_key,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003411 .conf_tx = iwl_mac_conf_tx,
Johannes Berg2295c662010-10-23 09:15:41 -07003412 .bss_info_changed = iwlagn_bss_info_changed,
3413 .ampdu_action = iwlagn_mac_ampdu_action,
Johannes Berg6ab10ff2009-11-13 11:56:37 -08003414 .hw_scan = iwl_mac_hw_scan,
Johannes Berg2295c662010-10-23 09:15:41 -07003415 .sta_notify = iwlagn_mac_sta_notify,
Reinette Chatrefe6b23d2010-02-22 16:24:47 -08003416 .sta_add = iwlagn_mac_sta_add,
3417 .sta_remove = iwl_mac_sta_remove,
Johannes Berg2295c662010-10-23 09:15:41 -07003418 .channel_switch = iwlagn_mac_channel_switch,
3419 .flush = iwlagn_mac_flush,
Johannes Berga85d7cc2010-07-31 08:34:10 -07003420 .tx_last_beacon = iwl_mac_tx_last_beacon,
Johannes Berg9b9190d2011-01-06 08:07:10 -08003421 .remain_on_channel = iwl_mac_remain_on_channel,
3422 .cancel_remain_on_channel = iwl_mac_cancel_remain_on_channel,
Johannes Berg266af4c72011-03-10 20:13:26 -08003423 .offchannel_tx = iwl_mac_offchannel_tx,
3424 .offchannel_tx_cancel_wait = iwl_mac_offchannel_tx_cancel_wait,
Cindy H. Kao4613e722011-05-06 10:40:15 -07003425 CFG80211_TESTMODE_CMD(iwl_testmode_cmd)
Zhu Yib481de92007-09-25 17:54:57 -07003426};
3427
Johannes Berge98a1302011-04-05 09:42:08 -07003428static u32 iwl_hw_detect(struct iwl_priv *priv)
Wey-Yi Guy3867fe02010-07-31 08:34:05 -07003429{
Johannes Bergc2974a12011-04-05 09:42:09 -07003430 u8 rev_id;
3431
3432 pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &rev_id);
3433 IWL_DEBUG_INFO(priv, "HW Revision ID = 0x%X\n", rev_id);
Johannes Berg02a7fa02011-04-05 09:42:12 -07003434 return iwl_read32(priv, CSR_HW_REV);
Wey-Yi Guy3867fe02010-07-31 08:34:05 -07003435}
3436
Wey-Yi Guy07d4f1a2010-07-31 08:34:08 -07003437static int iwl_set_hw_params(struct iwl_priv *priv)
3438{
3439 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
3440 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
Don Fry9d143e92011-04-20 15:23:57 -07003441 if (iwlagn_mod_params.amsdu_size_8K)
Wey-Yi Guy07d4f1a2010-07-31 08:34:08 -07003442 priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_8K);
3443 else
3444 priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_4K);
3445
3446 priv->hw_params.max_beacon_itrvl = IWL_MAX_UCODE_BEACON_INTERVAL;
3447
Don Fry9d143e92011-04-20 15:23:57 -07003448 if (iwlagn_mod_params.disable_11n)
Wey-Yi Guy07d4f1a2010-07-31 08:34:08 -07003449 priv->cfg->sku &= ~IWL_SKU_N;
3450
3451 /* Device-specific setup */
3452 return priv->cfg->ops->lib->set_hw_params(priv);
3453}
3454
Johannes Berge72f3682010-08-23 10:46:51 +02003455static const u8 iwlagn_bss_ac_to_fifo[] = {
3456 IWL_TX_FIFO_VO,
3457 IWL_TX_FIFO_VI,
3458 IWL_TX_FIFO_BE,
3459 IWL_TX_FIFO_BK,
3460};
3461
3462static const u8 iwlagn_bss_ac_to_queue[] = {
3463 0, 1, 2, 3,
3464};
3465
3466static const u8 iwlagn_pan_ac_to_fifo[] = {
3467 IWL_TX_FIFO_VO_IPAN,
3468 IWL_TX_FIFO_VI_IPAN,
3469 IWL_TX_FIFO_BE_IPAN,
3470 IWL_TX_FIFO_BK_IPAN,
3471};
3472
3473static const u8 iwlagn_pan_ac_to_queue[] = {
3474 7, 6, 5, 4,
3475};
3476
Wey-Yi Guy119ea182011-04-18 09:34:06 -07003477/* This function both allocates and initializes hw and priv. */
3478static struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg)
3479{
3480 struct iwl_priv *priv;
3481 /* mac80211 allocates memory for this device instance, including
3482 * space for this driver's private structure */
3483 struct ieee80211_hw *hw;
3484
3485 hw = ieee80211_alloc_hw(sizeof(struct iwl_priv), &iwlagn_hw_ops);
3486 if (hw == NULL) {
3487 pr_err("%s: Can not allocate network device\n",
3488 cfg->name);
3489 goto out;
3490 }
3491
3492 priv = hw->priv;
3493 priv->hw = hw;
3494
3495out:
3496 return hw;
3497}
3498
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003499static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07003500{
Johannes Berg246ed352010-08-23 10:46:32 +02003501 int err = 0, i;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003502 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07003503 struct ieee80211_hw *hw;
Tomas Winkler82b9a122008-03-04 18:09:30 -08003504 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003505 unsigned long flags;
Wey-Yi Guyc6fa17e2010-07-15 05:58:30 -07003506 u16 pci_cmd, num_mac;
Johannes Berge98a1302011-04-05 09:42:08 -07003507 u32 hw_rev;
Zhu Yib481de92007-09-25 17:54:57 -07003508
Assaf Krauss316c30d2008-03-14 10:38:46 -07003509 /************************
3510 * 1. Allocating HW data
3511 ************************/
3512
Johannes Bergdc21b542010-10-23 09:15:39 -07003513 hw = iwl_alloc_all(cfg);
Assaf Krauss1d0a0822008-03-14 10:38:48 -07003514 if (!hw) {
Zhu Yib481de92007-09-25 17:54:57 -07003515 err = -ENOMEM;
3516 goto out;
3517 }
Assaf Krauss1d0a0822008-03-14 10:38:48 -07003518 priv = hw->priv;
3519 /* At this point both hw and priv are allocated. */
3520
Johannes Bergca7966c2011-04-22 10:15:23 -07003521 priv->ucode_type = UCODE_SUBTYPE_NONE_LOADED;
3522
Johannes Berg246ed352010-08-23 10:46:32 +02003523 /*
3524 * The default context is always valid,
3525 * more may be discovered when firmware
3526 * is loaded.
3527 */
3528 priv->valid_contexts = BIT(IWL_RXON_CTX_BSS);
3529
3530 for (i = 0; i < NUM_IWL_RXON_CTX; i++)
3531 priv->contexts[i].ctxid = i;
3532
Johannes Berg763cc3b2010-09-03 06:32:21 -07003533 priv->contexts[IWL_RXON_CTX_BSS].always_active = true;
3534 priv->contexts[IWL_RXON_CTX_BSS].is_active = true;
Johannes Berg8f2d3d22010-08-23 10:46:37 +02003535 priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
3536 priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
3537 priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
Johannes Berg8dfdb9d2010-08-23 10:46:38 +02003538 priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
Johannes Berg2995baf2010-08-23 10:46:42 +02003539 priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
Johannes Bergc10afb62010-08-23 10:46:43 +02003540 priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
Johannes Berge72f3682010-08-23 10:46:51 +02003541 priv->contexts[IWL_RXON_CTX_BSS].ac_to_fifo = iwlagn_bss_ac_to_fifo;
3542 priv->contexts[IWL_RXON_CTX_BSS].ac_to_queue = iwlagn_bss_ac_to_queue;
Johannes Bergd0fe4782010-08-23 10:46:58 +02003543 priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
3544 BIT(NL80211_IFTYPE_ADHOC);
3545 priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
3546 BIT(NL80211_IFTYPE_STATION);
Johannes Berg2295c662010-10-23 09:15:41 -07003547 priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP;
Johannes Bergd0fe4782010-08-23 10:46:58 +02003548 priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
3549 priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
3550 priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
Johannes Bergece9c4e2010-08-23 10:46:49 +02003551
3552 priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON;
3553 priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd = REPLY_WIPAN_RXON_TIMING;
3554 priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd = REPLY_WIPAN_RXON_ASSOC;
3555 priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM;
3556 priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN;
3557 priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY;
3558 priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID;
3559 priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION;
Johannes Berge72f3682010-08-23 10:46:51 +02003560 priv->contexts[IWL_RXON_CTX_PAN].ac_to_fifo = iwlagn_pan_ac_to_fifo;
3561 priv->contexts[IWL_RXON_CTX_PAN].ac_to_queue = iwlagn_pan_ac_to_queue;
3562 priv->contexts[IWL_RXON_CTX_PAN].mcast_queue = IWL_IPAN_MCAST_QUEUE;
Johannes Bergd0fe4782010-08-23 10:46:58 +02003563 priv->contexts[IWL_RXON_CTX_PAN].interface_modes =
3564 BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
Wey-Yi Guyf35c0c52011-01-13 17:09:29 -08003565#ifdef CONFIG_IWL_P2P
3566 priv->contexts[IWL_RXON_CTX_PAN].interface_modes |=
3567 BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO);
3568#endif
Johannes Bergd0fe4782010-08-23 10:46:58 +02003569 priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP;
3570 priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA;
3571 priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P;
Johannes Bergece9c4e2010-08-23 10:46:49 +02003572
3573 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
Johannes Berg8f2d3d22010-08-23 10:46:37 +02003574
Zhu Yib481de92007-09-25 17:54:57 -07003575 SET_IEEE80211_DEV(hw, &pdev->dev);
3576
Tomas Winklere1623442009-01-27 14:27:56 -08003577 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Tomas Winkler82b9a122008-03-04 18:09:30 -08003578 priv->cfg = cfg;
Zhu Yib481de92007-09-25 17:54:57 -07003579 priv->pci_dev = pdev;
Mohamed Abbas40cefda2009-05-22 11:01:52 -07003580 priv->inta_mask = CSR_INI_SET_MASK;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003581
Wey-Yi Guybee008b2010-08-23 07:57:04 -07003582 /* is antenna coupling more than 35dB ? */
3583 priv->bt_ant_couple_ok =
3584 (iwlagn_ant_coupling > IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
3585 true : false;
3586
Wey-Yi Guy9f28ebc2010-11-26 13:24:19 -08003587 /* enable/disable bt channel inhibition */
Wey-Yi Guyf37837c2010-08-23 07:57:12 -07003588 priv->bt_ch_announce = iwlagn_bt_ch_announce;
Wey-Yi Guy9f28ebc2010-11-26 13:24:19 -08003589 IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n",
3590 (priv->bt_ch_announce) ? "On" : "Off");
Wey-Yi Guyf37837c2010-08-23 07:57:12 -07003591
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003592 if (iwl_alloc_traffic_mem(priv))
3593 IWL_ERR(priv, "Not enough memory to generate traffic log\n");
Zhu Yib481de92007-09-25 17:54:57 -07003594
Assaf Krauss316c30d2008-03-14 10:38:46 -07003595 /**************************
3596 * 2. Initializing PCI bus
3597 **************************/
John W. Linville1a7123c2010-08-05 14:39:31 -04003598 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
3599 PCIE_LINK_STATE_CLKPM);
3600
Assaf Krauss316c30d2008-03-14 10:38:46 -07003601 if (pci_enable_device(pdev)) {
3602 err = -ENODEV;
3603 goto out_ieee80211_free_hw;
3604 }
3605
3606 pci_set_master(pdev);
3607
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003608 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
Assaf Krauss316c30d2008-03-14 10:38:46 -07003609 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003610 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003611 if (err) {
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003612 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003613 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08003614 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003615 /* both attempts failed: */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003616 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08003617 IWL_WARN(priv, "No suitable DMA available.\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07003618 goto out_pci_disable_device;
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07003619 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07003620 }
3621
3622 err = pci_request_regions(pdev, DRV_NAME);
3623 if (err)
3624 goto out_pci_disable_device;
3625
3626 pci_set_drvdata(pdev, priv);
3627
Assaf Krauss316c30d2008-03-14 10:38:46 -07003628
3629 /***********************
3630 * 3. Read REV register
3631 ***********************/
3632 priv->hw_base = pci_iomap(pdev, 0, 0);
3633 if (!priv->hw_base) {
3634 err = -ENODEV;
3635 goto out_pci_release_regions;
3636 }
3637
Tomas Winklere1623442009-01-27 14:27:56 -08003638 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Assaf Krauss316c30d2008-03-14 10:38:46 -07003639 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08003640 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003641
Reinette Chatre731a29b2009-12-14 14:12:11 -08003642 /* these spin locks will be used in apm_ops.init and EEPROM access
Mohamed Abbasa8b50a02009-05-22 11:01:47 -07003643 * we should init now
3644 */
3645 spin_lock_init(&priv->reg_lock);
Reinette Chatre731a29b2009-12-14 14:12:11 -08003646 spin_lock_init(&priv->lock);
Reinette Chatre4843b5a2010-02-03 09:38:59 -08003647
3648 /*
3649 * stop and reset the on-board processor just in case it is in a
3650 * strange state ... like being left stranded by a primary kernel
3651 * and this is now the kdump kernel trying to start up
3652 */
3653 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
3654
Johannes Berge98a1302011-04-05 09:42:08 -07003655 hw_rev = iwl_hw_detect(priv);
Shanyu Zhaoc11362c2010-03-05 17:05:20 -08003656 IWL_INFO(priv, "Detected %s, REV=0x%X\n",
Johannes Berge98a1302011-04-05 09:42:08 -07003657 priv->cfg->name, hw_rev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003658
Tomas Winklere7b63582008-09-03 11:26:49 +08003659 /* We disable the RETRY_TIMEOUT register (0x41) to keep
3660 * PCI Tx retries from interfering with C3 CPU state */
3661 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
3662
Johannes Berg4cd2bf72011-04-13 03:14:52 -07003663 if (iwl_prepare_card_hw(priv)) {
Mohamed Abbas086ed112009-05-22 11:01:54 -07003664 IWL_WARN(priv, "Failed, HW not ready\n");
3665 goto out_iounmap;
3666 }
3667
Assaf Krauss316c30d2008-03-14 10:38:46 -07003668 /*****************
3669 * 4. Read EEPROM
3670 *****************/
Assaf Krauss316c30d2008-03-14 10:38:46 -07003671 /* Read the EEPROM */
Johannes Berge98a1302011-04-05 09:42:08 -07003672 err = iwl_eeprom_init(priv, hw_rev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003673 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003674 IWL_ERR(priv, "Unable to init EEPROM\n");
Assaf Krauss316c30d2008-03-14 10:38:46 -07003675 goto out_iounmap;
3676 }
Tomas Winkler8614f362008-04-23 17:14:55 -07003677 err = iwl_eeprom_check_version(priv);
3678 if (err)
Reinette Chatrec8f16132009-02-27 16:21:22 -08003679 goto out_free_eeprom;
Tomas Winkler8614f362008-04-23 17:14:55 -07003680
Wey-Yi Guy21a5b3c2010-11-10 13:32:59 -08003681 err = iwl_eeprom_check_sku(priv);
3682 if (err)
3683 goto out_free_eeprom;
3684
Ron Rindjunsky02883012008-05-15 13:53:53 +08003685 /* extract MAC Address */
Wey-Yi Guyc6fa17e2010-07-15 05:58:30 -07003686 iwl_eeprom_get_mac(priv, priv->addresses[0].addr);
3687 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
3688 priv->hw->wiphy->addresses = priv->addresses;
3689 priv->hw->wiphy->n_addresses = 1;
3690 num_mac = iwl_eeprom_query16(priv, EEPROM_NUM_MAC_ADDRESS);
3691 if (num_mac > 1) {
3692 memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
3693 ETH_ALEN);
3694 priv->addresses[1].addr[5]++;
3695 priv->hw->wiphy->n_addresses++;
3696 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07003697
3698 /************************
3699 * 5. Setup HW constants
3700 ************************/
Ron Rindjunskyda154e302008-06-30 17:23:20 +08003701 if (iwl_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003702 IWL_ERR(priv, "failed to set hw parameters\n");
Tomas Winkler073d3f52008-04-21 15:41:52 -07003703 goto out_free_eeprom;
Assaf Krauss316c30d2008-03-14 10:38:46 -07003704 }
3705
3706 /*******************
Tomas Winkler6ba87952008-05-15 13:54:17 +08003707 * 6. Setup priv
Assaf Krauss316c30d2008-03-14 10:38:46 -07003708 *******************/
Zhu Yib481de92007-09-25 17:54:57 -07003709
Tomas Winkler6ba87952008-05-15 13:54:17 +08003710 err = iwl_init_drv(priv);
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003711 if (err)
Ron Rindjunsky399f4902008-04-23 17:14:56 -07003712 goto out_free_eeprom;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07003713 /* At this point both hw and priv are initialized. */
Assaf Krauss316c30d2008-03-14 10:38:46 -07003714
Assaf Krauss316c30d2008-03-14 10:38:46 -07003715 /********************
Abhijeet Kolekar09f9bf72009-04-20 14:37:03 -07003716 * 7. Setup services
Assaf Krauss316c30d2008-03-14 10:38:46 -07003717 ********************/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003718 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003719 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003720 spin_unlock_irqrestore(&priv->lock, flags);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003721
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003722 pci_enable_msi(priv->pci_dev);
3723
Johannes Berg519d8ab2011-04-05 09:42:11 -07003724 iwl_alloc_isr_ict(priv);
Wey-Yi Guye39fdee2010-11-10 09:56:40 -08003725
Johannes Berg519d8ab2011-04-05 09:42:11 -07003726 err = request_irq(priv->pci_dev->irq, iwl_isr_ict,
Mohamed Abbasef850d72009-05-22 11:01:50 -07003727 IRQF_SHARED, DRV_NAME, priv);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003728 if (err) {
3729 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
3730 goto out_disable_msi;
3731 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07003732
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08003733 iwl_setup_deferred_work(priv);
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08003734 iwl_setup_rx_handlers(priv);
Cindy H. Kao4613e722011-05-06 10:40:15 -07003735 iwl_testmode_init(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07003736
Johannes Berg158bea02010-01-22 14:22:53 -08003737 /*********************************************
3738 * 8. Enable interrupts and read RFKILL state
3739 *********************************************/
Tomas Winkler6ba87952008-05-15 13:54:17 +08003740
Stanislaw Gruszka554d1d02010-12-23 12:38:21 +01003741 /* enable rfkill interrupt: hw bug w/a */
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003742 pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd);
3743 if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
3744 pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
3745 pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
3746 }
3747
Stanislaw Gruszka554d1d02010-12-23 12:38:21 +01003748 iwl_enable_rfkill_int(priv);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003749
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003750 /* If platform's RF_KILL switch is NOT set to KILL */
3751 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3752 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3753 else
3754 set_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winkler6ba87952008-05-15 13:54:17 +08003755
Johannes Berga60e77e2009-06-04 18:26:06 +02003756 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
3757 test_bit(STATUS_RF_KILL_HW, &priv->status));
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003758
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08003759 iwl_power_initialize(priv);
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -07003760 iwl_tt_initialize(priv);
Johannes Berg158bea02010-01-22 14:22:53 -08003761
Reinette Chatrea15707d2010-05-10 15:08:11 -07003762 init_completion(&priv->_agn.firmware_loading_complete);
Johannes Berg562db532010-04-29 07:41:53 -07003763
Johannes Bergb08dfd02010-01-29 11:54:56 -08003764 err = iwl_request_firmware(priv, true);
Johannes Berg158bea02010-01-22 14:22:53 -08003765 if (err)
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07003766 goto out_destroy_workqueue;
Johannes Berg158bea02010-01-22 14:22:53 -08003767
Zhu Yib481de92007-09-25 17:54:57 -07003768 return 0;
3769
Emmanuel Grumbach7d476182010-05-23 00:14:08 -07003770 out_destroy_workqueue:
Reinette Chatrec8f16132009-02-27 16:21:22 -08003771 destroy_workqueue(priv->workqueue);
3772 priv->workqueue = NULL;
Helmut Schaa795cc0a2009-02-12 18:51:03 +01003773 free_irq(priv->pci_dev->irq, priv);
Johannes Berg519d8ab2011-04-05 09:42:11 -07003774 iwl_free_isr_ict(priv);
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003775 out_disable_msi:
3776 pci_disable_msi(priv->pci_dev);
Tomas Winkler6ba87952008-05-15 13:54:17 +08003777 iwl_uninit_drv(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07003778 out_free_eeprom:
3779 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003780 out_iounmap:
3781 pci_iounmap(pdev, priv->hw_base);
3782 out_pci_release_regions:
Assaf Krauss316c30d2008-03-14 10:38:46 -07003783 pci_set_drvdata(pdev, NULL);
Reinette Chatre623d5632009-03-03 11:37:04 -08003784 pci_release_regions(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07003785 out_pci_disable_device:
3786 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07003787 out_ieee80211_free_hw:
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003788 iwl_free_traffic_mem(priv);
Wey-Yi Guyd7c76f42009-10-09 13:20:17 -07003789 ieee80211_free_hw(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07003790 out:
3791 return err;
3792}
3793
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003794static void __devexit iwl_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07003795{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003796 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003797 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07003798
3799 if (!priv)
3800 return;
3801
Reinette Chatrea15707d2010-05-10 15:08:11 -07003802 wait_for_completion(&priv->_agn.firmware_loading_complete);
Johannes Berg562db532010-04-29 07:41:53 -07003803
Tomas Winklere1623442009-01-27 14:27:56 -08003804 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07003805
Emmanuel Grumbach67249622008-05-29 16:35:26 +08003806 iwl_dbgfs_unregister(priv);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003807 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
Emmanuel Grumbach67249622008-05-29 16:35:26 +08003808
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003809 /* ieee80211_unregister_hw call wil cause iwl_mac_stop to
3810 * to be called and iwl_down since we are removing the device
Gregory Greenman0b124c32008-09-03 11:18:50 +08003811 * we need to set STATUS_EXIT_PENDING bit.
3812 */
3813 set_bit(STATUS_EXIT_PENDING, &priv->status);
Wey-Yi Guy5ed540a2011-01-21 15:26:39 -08003814
3815 iwl_leds_exit(priv);
3816
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07003817 if (priv->mac80211_registered) {
3818 ieee80211_unregister_hw(priv->hw);
3819 priv->mac80211_registered = 0;
3820 }
3821
Johannes Berg1a10f432011-04-13 03:14:44 -07003822 /* Reset to low power before unloading driver. */
Johannes Berg14e8e4a2010-09-22 18:02:10 +02003823 iwl_apm_stop(priv);
Ben Cahillc166b252009-10-23 13:42:35 -07003824
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -07003825 iwl_tt_exit(priv);
3826
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003827 /* make sure we flush any pending irq or
3828 * tasklet for the driver
3829 */
3830 spin_lock_irqsave(&priv->lock, flags);
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003831 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003832 spin_unlock_irqrestore(&priv->lock, flags);
3833
3834 iwl_synchronize_irq(priv);
3835
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003836 iwl_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003837
3838 if (priv->rxq.bd)
Wey-Yi Guy54b81552010-03-17 13:34:35 -07003839 iwlagn_rx_queue_free(priv, &priv->rxq);
Wey-Yi Guy74bcdb32010-03-17 13:34:34 -07003840 iwlagn_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003841
Tomas Winkler073d3f52008-04-21 15:41:52 -07003842 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003843
Zhu Yib481de92007-09-25 17:54:57 -07003844
Mohamed Abbas948c1712007-10-25 17:15:45 +08003845 /*netif_stop_queue(dev); */
3846 flush_workqueue(priv->workqueue);
3847
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07003848 /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07003849 * priv->workqueue... so we can't take down the workqueue
3850 * until now... */
3851 destroy_workqueue(priv->workqueue);
3852 priv->workqueue = NULL;
Wey-Yi Guy20594eb2009-08-07 15:41:39 -07003853 iwl_free_traffic_mem(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003854
Helmut Schaa6cd0b1c2009-01-19 13:10:07 +01003855 free_irq(priv->pci_dev->irq, priv);
3856 pci_disable_msi(priv->pci_dev);
Zhu Yib481de92007-09-25 17:54:57 -07003857 pci_iounmap(pdev, priv->hw_base);
3858 pci_release_regions(pdev);
3859 pci_disable_device(pdev);
3860 pci_set_drvdata(pdev, NULL);
3861
Tomas Winkler6ba87952008-05-15 13:54:17 +08003862 iwl_uninit_drv(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003863
Johannes Berg519d8ab2011-04-05 09:42:11 -07003864 iwl_free_isr_ict(priv);
Mohamed Abbasef850d72009-05-22 11:01:50 -07003865
Johannes Berg77834542010-10-04 05:50:36 -07003866 dev_kfree_skb(priv->beacon_skb);
Zhu Yib481de92007-09-25 17:54:57 -07003867
3868 ieee80211_free_hw(priv->hw);
3869}
3870
Zhu Yib481de92007-09-25 17:54:57 -07003871
3872/*****************************************************************************
3873 *
3874 * driver and module entry point
3875 *
3876 *****************************************************************************/
3877
Ron Rindjunskyfed90172008-04-15 16:01:41 -07003878/* Hardware specific file defines the PCI IDs table for that hardware module */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00003879static DEFINE_PCI_DEVICE_TABLE(iwl_hw_card_ids) = {
Wey-Yi Guyac592572009-11-20 12:05:03 -08003880 {IWL_PCI_DEVICE(0x4232, 0x1201, iwl5100_agn_cfg)}, /* Mini Card */
3881 {IWL_PCI_DEVICE(0x4232, 0x1301, iwl5100_agn_cfg)}, /* Half Mini Card */
3882 {IWL_PCI_DEVICE(0x4232, 0x1204, iwl5100_agn_cfg)}, /* Mini Card */
3883 {IWL_PCI_DEVICE(0x4232, 0x1304, iwl5100_agn_cfg)}, /* Half Mini Card */
3884 {IWL_PCI_DEVICE(0x4232, 0x1205, iwl5100_bgn_cfg)}, /* Mini Card */
3885 {IWL_PCI_DEVICE(0x4232, 0x1305, iwl5100_bgn_cfg)}, /* Half Mini Card */
3886 {IWL_PCI_DEVICE(0x4232, 0x1206, iwl5100_abg_cfg)}, /* Mini Card */
3887 {IWL_PCI_DEVICE(0x4232, 0x1306, iwl5100_abg_cfg)}, /* Half Mini Card */
3888 {IWL_PCI_DEVICE(0x4232, 0x1221, iwl5100_agn_cfg)}, /* Mini Card */
3889 {IWL_PCI_DEVICE(0x4232, 0x1321, iwl5100_agn_cfg)}, /* Half Mini Card */
3890 {IWL_PCI_DEVICE(0x4232, 0x1224, iwl5100_agn_cfg)}, /* Mini Card */
3891 {IWL_PCI_DEVICE(0x4232, 0x1324, iwl5100_agn_cfg)}, /* Half Mini Card */
3892 {IWL_PCI_DEVICE(0x4232, 0x1225, iwl5100_bgn_cfg)}, /* Mini Card */
3893 {IWL_PCI_DEVICE(0x4232, 0x1325, iwl5100_bgn_cfg)}, /* Half Mini Card */
3894 {IWL_PCI_DEVICE(0x4232, 0x1226, iwl5100_abg_cfg)}, /* Mini Card */
3895 {IWL_PCI_DEVICE(0x4232, 0x1326, iwl5100_abg_cfg)}, /* Half Mini Card */
3896 {IWL_PCI_DEVICE(0x4237, 0x1211, iwl5100_agn_cfg)}, /* Mini Card */
3897 {IWL_PCI_DEVICE(0x4237, 0x1311, iwl5100_agn_cfg)}, /* Half Mini Card */
3898 {IWL_PCI_DEVICE(0x4237, 0x1214, iwl5100_agn_cfg)}, /* Mini Card */
3899 {IWL_PCI_DEVICE(0x4237, 0x1314, iwl5100_agn_cfg)}, /* Half Mini Card */
3900 {IWL_PCI_DEVICE(0x4237, 0x1215, iwl5100_bgn_cfg)}, /* Mini Card */
3901 {IWL_PCI_DEVICE(0x4237, 0x1315, iwl5100_bgn_cfg)}, /* Half Mini Card */
3902 {IWL_PCI_DEVICE(0x4237, 0x1216, iwl5100_abg_cfg)}, /* Mini Card */
3903 {IWL_PCI_DEVICE(0x4237, 0x1316, iwl5100_abg_cfg)}, /* Half Mini Card */
3904
3905/* 5300 Series WiFi */
3906 {IWL_PCI_DEVICE(0x4235, 0x1021, iwl5300_agn_cfg)}, /* Mini Card */
3907 {IWL_PCI_DEVICE(0x4235, 0x1121, iwl5300_agn_cfg)}, /* Half Mini Card */
3908 {IWL_PCI_DEVICE(0x4235, 0x1024, iwl5300_agn_cfg)}, /* Mini Card */
3909 {IWL_PCI_DEVICE(0x4235, 0x1124, iwl5300_agn_cfg)}, /* Half Mini Card */
3910 {IWL_PCI_DEVICE(0x4235, 0x1001, iwl5300_agn_cfg)}, /* Mini Card */
3911 {IWL_PCI_DEVICE(0x4235, 0x1101, iwl5300_agn_cfg)}, /* Half Mini Card */
3912 {IWL_PCI_DEVICE(0x4235, 0x1004, iwl5300_agn_cfg)}, /* Mini Card */
3913 {IWL_PCI_DEVICE(0x4235, 0x1104, iwl5300_agn_cfg)}, /* Half Mini Card */
3914 {IWL_PCI_DEVICE(0x4236, 0x1011, iwl5300_agn_cfg)}, /* Mini Card */
3915 {IWL_PCI_DEVICE(0x4236, 0x1111, iwl5300_agn_cfg)}, /* Half Mini Card */
3916 {IWL_PCI_DEVICE(0x4236, 0x1014, iwl5300_agn_cfg)}, /* Mini Card */
3917 {IWL_PCI_DEVICE(0x4236, 0x1114, iwl5300_agn_cfg)}, /* Half Mini Card */
3918
3919/* 5350 Series WiFi/WiMax */
3920 {IWL_PCI_DEVICE(0x423A, 0x1001, iwl5350_agn_cfg)}, /* Mini Card */
3921 {IWL_PCI_DEVICE(0x423A, 0x1021, iwl5350_agn_cfg)}, /* Mini Card */
3922 {IWL_PCI_DEVICE(0x423B, 0x1011, iwl5350_agn_cfg)}, /* Mini Card */
3923
3924/* 5150 Series Wifi/WiMax */
3925 {IWL_PCI_DEVICE(0x423C, 0x1201, iwl5150_agn_cfg)}, /* Mini Card */
3926 {IWL_PCI_DEVICE(0x423C, 0x1301, iwl5150_agn_cfg)}, /* Half Mini Card */
3927 {IWL_PCI_DEVICE(0x423C, 0x1206, iwl5150_abg_cfg)}, /* Mini Card */
3928 {IWL_PCI_DEVICE(0x423C, 0x1306, iwl5150_abg_cfg)}, /* Half Mini Card */
3929 {IWL_PCI_DEVICE(0x423C, 0x1221, iwl5150_agn_cfg)}, /* Mini Card */
3930 {IWL_PCI_DEVICE(0x423C, 0x1321, iwl5150_agn_cfg)}, /* Half Mini Card */
3931
3932 {IWL_PCI_DEVICE(0x423D, 0x1211, iwl5150_agn_cfg)}, /* Mini Card */
3933 {IWL_PCI_DEVICE(0x423D, 0x1311, iwl5150_agn_cfg)}, /* Half Mini Card */
3934 {IWL_PCI_DEVICE(0x423D, 0x1216, iwl5150_abg_cfg)}, /* Mini Card */
3935 {IWL_PCI_DEVICE(0x423D, 0x1316, iwl5150_abg_cfg)}, /* Half Mini Card */
Wey-Yi Guy5953a622009-09-17 10:43:53 -07003936
3937/* 6x00 Series */
Wey-Yi Guy5953a622009-09-17 10:43:53 -07003938 {IWL_PCI_DEVICE(0x422B, 0x1101, iwl6000_3agn_cfg)},
3939 {IWL_PCI_DEVICE(0x422B, 0x1121, iwl6000_3agn_cfg)},
3940 {IWL_PCI_DEVICE(0x422C, 0x1301, iwl6000i_2agn_cfg)},
3941 {IWL_PCI_DEVICE(0x422C, 0x1306, iwl6000i_2abg_cfg)},
3942 {IWL_PCI_DEVICE(0x422C, 0x1307, iwl6000i_2bg_cfg)},
3943 {IWL_PCI_DEVICE(0x422C, 0x1321, iwl6000i_2agn_cfg)},
3944 {IWL_PCI_DEVICE(0x422C, 0x1326, iwl6000i_2abg_cfg)},
3945 {IWL_PCI_DEVICE(0x4238, 0x1111, iwl6000_3agn_cfg)},
3946 {IWL_PCI_DEVICE(0x4239, 0x1311, iwl6000i_2agn_cfg)},
3947 {IWL_PCI_DEVICE(0x4239, 0x1316, iwl6000i_2abg_cfg)},
Shanyu Zhao4b3e8062010-04-07 18:06:36 -07003948
Wey-Yi Guy003ea982010-12-15 08:06:23 -08003949/* 6x05 Series */
Wey-Yi Guy8b3ee292010-11-18 11:41:48 -08003950 {IWL_PCI_DEVICE(0x0082, 0x1301, iwl6005_2agn_cfg)},
3951 {IWL_PCI_DEVICE(0x0082, 0x1306, iwl6005_2abg_cfg)},
3952 {IWL_PCI_DEVICE(0x0082, 0x1307, iwl6005_2bg_cfg)},
3953 {IWL_PCI_DEVICE(0x0082, 0x1321, iwl6005_2agn_cfg)},
3954 {IWL_PCI_DEVICE(0x0082, 0x1326, iwl6005_2abg_cfg)},
3955 {IWL_PCI_DEVICE(0x0085, 0x1311, iwl6005_2agn_cfg)},
3956 {IWL_PCI_DEVICE(0x0085, 0x1316, iwl6005_2abg_cfg)},
Shanyu Zhao18089722010-05-06 10:15:21 -07003957
Wey-Yi Guy003ea982010-12-15 08:06:23 -08003958/* 6x30 Series */
Wey-Yi Guy8b3ee292010-11-18 11:41:48 -08003959 {IWL_PCI_DEVICE(0x008A, 0x5305, iwl1030_bgn_cfg)},
3960 {IWL_PCI_DEVICE(0x008A, 0x5307, iwl1030_bg_cfg)},
3961 {IWL_PCI_DEVICE(0x008A, 0x5325, iwl1030_bgn_cfg)},
3962 {IWL_PCI_DEVICE(0x008A, 0x5327, iwl1030_bg_cfg)},
3963 {IWL_PCI_DEVICE(0x008B, 0x5315, iwl1030_bgn_cfg)},
3964 {IWL_PCI_DEVICE(0x008B, 0x5317, iwl1030_bg_cfg)},
3965 {IWL_PCI_DEVICE(0x0090, 0x5211, iwl6030_2agn_cfg)},
3966 {IWL_PCI_DEVICE(0x0090, 0x5215, iwl6030_2bgn_cfg)},
3967 {IWL_PCI_DEVICE(0x0090, 0x5216, iwl6030_2abg_cfg)},
3968 {IWL_PCI_DEVICE(0x0091, 0x5201, iwl6030_2agn_cfg)},
3969 {IWL_PCI_DEVICE(0x0091, 0x5205, iwl6030_2bgn_cfg)},
3970 {IWL_PCI_DEVICE(0x0091, 0x5206, iwl6030_2abg_cfg)},
3971 {IWL_PCI_DEVICE(0x0091, 0x5207, iwl6030_2bg_cfg)},
3972 {IWL_PCI_DEVICE(0x0091, 0x5221, iwl6030_2agn_cfg)},
3973 {IWL_PCI_DEVICE(0x0091, 0x5225, iwl6030_2bgn_cfg)},
3974 {IWL_PCI_DEVICE(0x0091, 0x5226, iwl6030_2abg_cfg)},
Wey-Yi Guy5953a622009-09-17 10:43:53 -07003975
3976/* 6x50 WiFi/WiMax Series */
Wey-Yi Guy5953a622009-09-17 10:43:53 -07003977 {IWL_PCI_DEVICE(0x0087, 0x1301, iwl6050_2agn_cfg)},
3978 {IWL_PCI_DEVICE(0x0087, 0x1306, iwl6050_2abg_cfg)},
3979 {IWL_PCI_DEVICE(0x0087, 0x1321, iwl6050_2agn_cfg)},
3980 {IWL_PCI_DEVICE(0x0087, 0x1326, iwl6050_2abg_cfg)},
Wey-Yi Guy5953a622009-09-17 10:43:53 -07003981 {IWL_PCI_DEVICE(0x0089, 0x1311, iwl6050_2agn_cfg)},
3982 {IWL_PCI_DEVICE(0x0089, 0x1316, iwl6050_2abg_cfg)},
3983
Wey-Yi Guy003ea982010-12-15 08:06:23 -08003984/* 6150 WiFi/WiMax Series */
Wey-Yi Guy8b3ee292010-11-18 11:41:48 -08003985 {IWL_PCI_DEVICE(0x0885, 0x1305, iwl6150_bgn_cfg)},
3986 {IWL_PCI_DEVICE(0x0885, 0x1306, iwl6150_bgn_cfg)},
3987 {IWL_PCI_DEVICE(0x0885, 0x1325, iwl6150_bgn_cfg)},
3988 {IWL_PCI_DEVICE(0x0885, 0x1326, iwl6150_bgn_cfg)},
3989 {IWL_PCI_DEVICE(0x0886, 0x1315, iwl6150_bgn_cfg)},
3990 {IWL_PCI_DEVICE(0x0886, 0x1316, iwl6150_bgn_cfg)},
Shanyu Zhao03264332010-06-29 17:27:27 -07003991
Jay Sternberg77dcb6a2009-03-06 13:52:55 -08003992/* 1000 Series WiFi */
Wey-Yi Guy4bd0914f2009-09-17 10:43:52 -07003993 {IWL_PCI_DEVICE(0x0083, 0x1205, iwl1000_bgn_cfg)},
3994 {IWL_PCI_DEVICE(0x0083, 0x1305, iwl1000_bgn_cfg)},
3995 {IWL_PCI_DEVICE(0x0083, 0x1225, iwl1000_bgn_cfg)},
3996 {IWL_PCI_DEVICE(0x0083, 0x1325, iwl1000_bgn_cfg)},
3997 {IWL_PCI_DEVICE(0x0084, 0x1215, iwl1000_bgn_cfg)},
3998 {IWL_PCI_DEVICE(0x0084, 0x1315, iwl1000_bgn_cfg)},
3999 {IWL_PCI_DEVICE(0x0083, 0x1206, iwl1000_bg_cfg)},
4000 {IWL_PCI_DEVICE(0x0083, 0x1306, iwl1000_bg_cfg)},
4001 {IWL_PCI_DEVICE(0x0083, 0x1226, iwl1000_bg_cfg)},
4002 {IWL_PCI_DEVICE(0x0083, 0x1326, iwl1000_bg_cfg)},
4003 {IWL_PCI_DEVICE(0x0084, 0x1216, iwl1000_bg_cfg)},
4004 {IWL_PCI_DEVICE(0x0084, 0x1316, iwl1000_bg_cfg)},
Jay Sternberg1de19ec2010-09-14 15:21:20 -07004005
Wey-Yi Guy58a39092010-10-06 08:14:21 -07004006/* 100 Series WiFi */
Jay Sternberg1de19ec2010-09-14 15:21:20 -07004007 {IWL_PCI_DEVICE(0x08AE, 0x1005, iwl100_bgn_cfg)},
Jay Sternberg1de19ec2010-09-14 15:21:20 -07004008 {IWL_PCI_DEVICE(0x08AE, 0x1007, iwl100_bg_cfg)},
Wey-Yi Guy2a21ff42010-11-10 09:56:37 -08004009 {IWL_PCI_DEVICE(0x08AF, 0x1015, iwl100_bgn_cfg)},
4010 {IWL_PCI_DEVICE(0x08AF, 0x1017, iwl100_bg_cfg)},
4011 {IWL_PCI_DEVICE(0x08AE, 0x1025, iwl100_bgn_cfg)},
4012 {IWL_PCI_DEVICE(0x08AE, 0x1027, iwl100_bg_cfg)},
Wey-Yi Guy58a39092010-10-06 08:14:21 -07004013
4014/* 130 Series WiFi */
4015 {IWL_PCI_DEVICE(0x0896, 0x5005, iwl130_bgn_cfg)},
4016 {IWL_PCI_DEVICE(0x0896, 0x5007, iwl130_bg_cfg)},
4017 {IWL_PCI_DEVICE(0x0897, 0x5015, iwl130_bgn_cfg)},
4018 {IWL_PCI_DEVICE(0x0897, 0x5017, iwl130_bg_cfg)},
4019 {IWL_PCI_DEVICE(0x0896, 0x5025, iwl130_bgn_cfg)},
4020 {IWL_PCI_DEVICE(0x0896, 0x5027, iwl130_bg_cfg)},
4021
Wey-Yi Guy04b8e752011-01-08 11:47:56 -08004022/* 2x00 Series */
4023 {IWL_PCI_DEVICE(0x0890, 0x4022, iwl2000_2bgn_cfg)},
4024 {IWL_PCI_DEVICE(0x0891, 0x4222, iwl2000_2bgn_cfg)},
4025 {IWL_PCI_DEVICE(0x0890, 0x4422, iwl2000_2bgn_cfg)},
4026 {IWL_PCI_DEVICE(0x0890, 0x4026, iwl2000_2bg_cfg)},
4027 {IWL_PCI_DEVICE(0x0891, 0x4226, iwl2000_2bg_cfg)},
4028 {IWL_PCI_DEVICE(0x0890, 0x4426, iwl2000_2bg_cfg)},
4029
4030/* 2x30 Series */
4031 {IWL_PCI_DEVICE(0x0887, 0x4062, iwl2030_2bgn_cfg)},
4032 {IWL_PCI_DEVICE(0x0888, 0x4262, iwl2030_2bgn_cfg)},
4033 {IWL_PCI_DEVICE(0x0887, 0x4462, iwl2030_2bgn_cfg)},
4034 {IWL_PCI_DEVICE(0x0887, 0x4066, iwl2030_2bg_cfg)},
4035 {IWL_PCI_DEVICE(0x0888, 0x4266, iwl2030_2bg_cfg)},
4036 {IWL_PCI_DEVICE(0x0887, 0x4466, iwl2030_2bg_cfg)},
4037
4038/* 6x35 Series */
4039 {IWL_PCI_DEVICE(0x088E, 0x4060, iwl6035_2agn_cfg)},
4040 {IWL_PCI_DEVICE(0x088F, 0x4260, iwl6035_2agn_cfg)},
4041 {IWL_PCI_DEVICE(0x088E, 0x4460, iwl6035_2agn_cfg)},
4042 {IWL_PCI_DEVICE(0x088E, 0x4064, iwl6035_2abg_cfg)},
4043 {IWL_PCI_DEVICE(0x088F, 0x4264, iwl6035_2abg_cfg)},
4044 {IWL_PCI_DEVICE(0x088E, 0x4464, iwl6035_2abg_cfg)},
4045 {IWL_PCI_DEVICE(0x088E, 0x4066, iwl6035_2bg_cfg)},
4046 {IWL_PCI_DEVICE(0x088F, 0x4266, iwl6035_2bg_cfg)},
4047 {IWL_PCI_DEVICE(0x088E, 0x4466, iwl6035_2bg_cfg)},
4048
Wey-Yi Guyb4ed2212011-04-30 08:55:16 -07004049/* 105 Series */
4050 {IWL_PCI_DEVICE(0x0894, 0x0022, iwl105_bgn_cfg)},
4051 {IWL_PCI_DEVICE(0x0895, 0x0222, iwl105_bgn_cfg)},
4052 {IWL_PCI_DEVICE(0x0894, 0x0422, iwl105_bgn_cfg)},
4053 {IWL_PCI_DEVICE(0x0894, 0x0026, iwl105_bg_cfg)},
4054 {IWL_PCI_DEVICE(0x0895, 0x0226, iwl105_bg_cfg)},
4055 {IWL_PCI_DEVICE(0x0894, 0x0426, iwl105_bg_cfg)},
Wey-Yi Guy04b8e752011-01-08 11:47:56 -08004056
Wey-Yi Guyb4ed2212011-04-30 08:55:16 -07004057/* 135 Series */
4058 {IWL_PCI_DEVICE(0x0892, 0x0062, iwl135_bgn_cfg)},
4059 {IWL_PCI_DEVICE(0x0893, 0x0262, iwl135_bgn_cfg)},
4060 {IWL_PCI_DEVICE(0x0892, 0x0462, iwl135_bgn_cfg)},
4061 {IWL_PCI_DEVICE(0x0892, 0x0066, iwl135_bg_cfg)},
4062 {IWL_PCI_DEVICE(0x0893, 0x0266, iwl135_bg_cfg)},
4063 {IWL_PCI_DEVICE(0x0892, 0x0466, iwl135_bg_cfg)},
Wey-Yi Guy04b8e752011-01-08 11:47:56 -08004064
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004065 {0}
4066};
4067MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
4068
4069static struct pci_driver iwl_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07004070 .name = DRV_NAME,
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004071 .id_table = iwl_hw_card_ids,
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004072 .probe = iwl_pci_probe,
4073 .remove = __devexit_p(iwl_pci_remove),
John W. Linvillef60dc012010-10-25 16:12:37 -04004074 .driver.pm = IWL_PM_OPS,
Zhu Yib481de92007-09-25 17:54:57 -07004075};
4076
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004077static int __init iwl_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07004078{
4079
4080 int ret;
Joe Perchesc96c31e2010-07-26 14:39:58 -07004081 pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
4082 pr_info(DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004083
Tomas Winklere227cea2008-07-18 13:53:05 +08004084 ret = iwlagn_rate_control_register();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004085 if (ret) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07004086 pr_err("Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004087 return ret;
4088 }
4089
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004090 ret = pci_register_driver(&iwl_driver);
Zhu Yib481de92007-09-25 17:54:57 -07004091 if (ret) {
Joe Perchesc96c31e2010-07-26 14:39:58 -07004092 pr_err("Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004093 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07004094 }
Zhu Yib481de92007-09-25 17:54:57 -07004095
4096 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004097
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004098error_register:
Tomas Winklere227cea2008-07-18 13:53:05 +08004099 iwlagn_rate_control_unregister();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004100 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004101}
4102
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004103static void __exit iwl_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07004104{
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004105 pci_unregister_driver(&iwl_driver);
Tomas Winklere227cea2008-07-18 13:53:05 +08004106 iwlagn_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07004107}
4108
Emmanuel Grumbach5b9f8cd2008-10-29 14:05:46 -07004109module_exit(iwl_exit);
4110module_init(iwl_init);
Reinette Chatrea562a9d2009-07-17 09:30:24 -07004111
4112#ifdef CONFIG_IWLWIFI_DEBUG
Wey-Yi Guy4e30cb62009-09-17 10:43:47 -07004113module_param_named(debug, iwl_debug_level, uint, S_IRUGO | S_IWUSR);
Reinette Chatrea562a9d2009-07-17 09:30:24 -07004114MODULE_PARM_DESC(debug, "debug output mask");
4115#endif
4116
Wey-Yi Guy2b068612010-03-22 09:17:39 -07004117module_param_named(swcrypto, iwlagn_mod_params.sw_crypto, int, S_IRUGO);
4118MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
Wey-Yi Guy2b068612010-03-22 09:17:39 -07004119module_param_named(queues_num, iwlagn_mod_params.num_of_queues, int, S_IRUGO);
4120MODULE_PARM_DESC(queues_num, "number of hw queues.");
Wey-Yi Guy2b068612010-03-22 09:17:39 -07004121module_param_named(11n_disable, iwlagn_mod_params.disable_11n, int, S_IRUGO);
4122MODULE_PARM_DESC(11n_disable, "disable 11n functionality");
Wey-Yi Guy2b068612010-03-22 09:17:39 -07004123module_param_named(amsdu_size_8K, iwlagn_mod_params.amsdu_size_8K,
4124 int, S_IRUGO);
4125MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
Wey-Yi Guy2b068612010-03-22 09:17:39 -07004126module_param_named(fw_restart, iwlagn_mod_params.restart_fw, int, S_IRUGO);
4127MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");
Johannes Bergdd7a2502010-04-28 23:33:10 -07004128
4129module_param_named(ucode_alternative, iwlagn_wanted_ucode_alternative, int,
4130 S_IRUGO);
4131MODULE_PARM_DESC(ucode_alternative,
4132 "specify ucode alternative to use from ucode file");
Wey-Yi Guybee008b2010-08-23 07:57:04 -07004133
4134module_param_named(antenna_coupling, iwlagn_ant_coupling, int, S_IRUGO);
4135MODULE_PARM_DESC(antenna_coupling,
4136 "specify antenna coupling in dB (defualt: 0 dB)");
Wey-Yi Guyf37837c2010-08-23 07:57:12 -07004137
Wey-Yi Guy9f28ebc2010-11-26 13:24:19 -08004138module_param_named(bt_ch_inhibition, iwlagn_bt_ch_announce, bool, S_IRUGO);
4139MODULE_PARM_DESC(bt_ch_inhibition,
4140 "Disable BT channel inhibition (default: enable)");
Stanislaw Gruszkab7977ff2011-02-28 14:33:15 +01004141
4142module_param_named(plcp_check, iwlagn_mod_params.plcp_check, bool, S_IRUGO);
4143MODULE_PARM_DESC(plcp_check, "Check plcp health (default: 1 [enabled])");
4144
4145module_param_named(ack_check, iwlagn_mod_params.ack_check, bool, S_IRUGO);
4146MODULE_PARM_DESC(ack_check, "Check ack health (default: 0 [disabled])");