blob: c7bb9c19a902dcfff1ad9b86c27f5b4cb5016981 [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Reinette Chatre01f81622009-01-08 10:20:02 -08003 * Copyright(c) 2003 - 2009 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
Zhu Yib481de92007-09-25 17:54:57 -070030#include <linux/kernel.h>
31#include <linux/module.h>
Zhu Yib481de92007-09-25 17:54:57 -070032#include <linux/init.h>
33#include <linux/pci.h>
34#include <linux/dma-mapping.h>
35#include <linux/delay.h>
36#include <linux/skbuff.h>
37#include <linux/netdevice.h>
38#include <linux/wireless.h>
39#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070040#include <linux/etherdevice.h>
41#include <linux/if_arp.h>
42
43#include <net/ieee80211_radiotap.h>
John W. Linville7e272fc2008-09-24 18:13:14 -040044#include <net/lib80211.h>
Zhu Yib481de92007-09-25 17:54:57 -070045#include <net/mac80211.h>
46
47#include <asm/div64.h>
48
Samuel Ortiza3139c52008-12-19 10:37:09 +080049#define DRV_NAME "iwl3945"
50
Winkler, Tomasdbb66542008-12-22 11:31:14 +080051#include "iwl-fh.h"
52#include "iwl-3945-fh.h"
Tomas Winkler600c0e12008-12-19 10:37:04 +080053#include "iwl-commands.h"
Zhu Yib481de92007-09-25 17:54:57 -070054#include "iwl-3945.h"
55#include "iwl-helpers.h"
Kolekar, Abhijeet5747d472008-12-19 10:37:18 +080056#include "iwl-core.h"
Samuel Ortizd20b3c62008-12-19 10:37:15 +080057#include "iwl-dev.h"
Zhu Yib481de92007-09-25 17:54:57 -070058
Zhu Yib481de92007-09-25 17:54:57 -070059/*
60 * module name, copyright, version, etc.
Zhu Yib481de92007-09-25 17:54:57 -070061 */
62
63#define DRV_DESCRIPTION \
64"Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
65
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080066#ifdef CONFIG_IWL3945_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070067#define VD "d"
68#else
69#define VD
70#endif
71
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080072#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070073#define VS "s"
74#else
75#define VS
76#endif
77
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080078#define IWL39_VERSION "1.2.26k" VD VS
Reinette Chatre01f81622009-01-08 10:20:02 -080079#define DRV_COPYRIGHT "Copyright(c) 2003-2009 Intel Corporation"
Tomas Winklera7b75202008-12-11 10:33:41 -080080#define DRV_AUTHOR "<ilw@linux.intel.com>"
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080081#define DRV_VERSION IWL39_VERSION
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
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080089 /* module parameters */
90struct iwl_mod_params iwl3945_mod_params = {
91 .num_of_queues = IWL39_MAX_NUM_QUEUES,
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -080092 .sw_crypto = 1,
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080093 /* the rest are 0 by default */
94};
95
Zhu Yib481de92007-09-25 17:54:57 -070096/*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
97 * DMA services
98 *
99 * Theory of operation
100 *
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800101 * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
102 * of buffer descriptors, each of which points to one or more data buffers for
103 * the device to read from or fill. Driver and device exchange status of each
104 * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
105 * entries in each circular buffer, to protect against confusing empty and full
106 * queue states.
107 *
108 * The device reads or writes the data in the queues via the device's several
109 * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
Zhu Yib481de92007-09-25 17:54:57 -0700110 *
111 * For Tx queue, there are low mark and high mark limits. If, after queuing
112 * the packet for Tx, free space become < low mark, Tx queue stopped. When
113 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
114 * Tx queue resumed.
115 *
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800116 * The 3945 operates with six queues: One receive queue, one transmit queue
117 * (#4) for sending commands to the device firmware, and four transmit queues
118 * (#0-3) for data tx via EDCA. An additional 2 HCCA queues are unused.
Zhu Yib481de92007-09-25 17:54:57 -0700119 ***************************************************/
120
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800121/**
122 * iwl3945_queue_init - Initialize queue's high/low-water and read/write indexes
123 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800124static int iwl3945_queue_init(struct iwl_priv *priv, struct iwl_queue *q,
Zhu Yib481de92007-09-25 17:54:57 -0700125 int count, int slots_num, u32 id)
126{
127 q->n_bd = count;
128 q->n_window = slots_num;
129 q->id = id;
130
Tomas Winklerc54b6792008-03-06 17:36:53 -0800131 /* count must be power-of-two size, otherwise iwl_queue_inc_wrap
132 * and iwl_queue_dec_wrap are broken. */
Zhu Yib481de92007-09-25 17:54:57 -0700133 BUG_ON(!is_power_of_2(count));
134
135 /* slots_num must be power-of-two size, otherwise
136 * get_cmd_index is broken. */
137 BUG_ON(!is_power_of_2(slots_num));
138
139 q->low_mark = q->n_window / 4;
140 if (q->low_mark < 4)
141 q->low_mark = 4;
142
143 q->high_mark = q->n_window / 8;
144 if (q->high_mark < 2)
145 q->high_mark = 2;
146
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800147 q->write_ptr = q->read_ptr = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700148
149 return 0;
150}
151
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800152/**
153 * iwl3945_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
154 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800155static int iwl3945_tx_queue_alloc(struct iwl_priv *priv,
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800156 struct iwl_tx_queue *txq, u32 id)
Zhu Yib481de92007-09-25 17:54:57 -0700157{
158 struct pci_dev *dev = priv->pci_dev;
159
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800160 /* Driver private data, only for Tx (not command) queues,
161 * not shared with device. */
Zhu Yib481de92007-09-25 17:54:57 -0700162 if (id != IWL_CMD_QUEUE_NUM) {
163 txq->txb = kmalloc(sizeof(txq->txb[0]) *
164 TFD_QUEUE_SIZE_MAX, GFP_KERNEL);
165 if (!txq->txb) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800166 IWL_ERR(priv, "kmalloc for auxiliary BD "
Zhu Yib481de92007-09-25 17:54:57 -0700167 "structures failed\n");
168 goto error;
169 }
170 } else
171 txq->txb = NULL;
172
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800173 /* Circular buffer of transmit frame descriptors (TFDs),
174 * shared with device */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800175 txq->tfds39 = pci_alloc_consistent(dev,
176 sizeof(txq->tfds39[0]) * TFD_QUEUE_SIZE_MAX,
Zhu Yib481de92007-09-25 17:54:57 -0700177 &txq->q.dma_addr);
178
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800179 if (!txq->tfds39) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800180 IWL_ERR(priv, "pci_alloc_consistent(%zd) failed\n",
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800181 sizeof(txq->tfds39[0]) * TFD_QUEUE_SIZE_MAX);
Zhu Yib481de92007-09-25 17:54:57 -0700182 goto error;
183 }
184 txq->q.id = id;
185
186 return 0;
187
188 error:
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300189 kfree(txq->txb);
190 txq->txb = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700191
192 return -ENOMEM;
193}
194
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800195/**
196 * iwl3945_tx_queue_init - Allocate and initialize one tx/cmd queue
197 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800198int iwl3945_tx_queue_init(struct iwl_priv *priv,
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800199 struct iwl_tx_queue *txq, int slots_num, u32 txq_id)
Zhu Yib481de92007-09-25 17:54:57 -0700200{
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800201 int len, i;
Zhu Yib481de92007-09-25 17:54:57 -0700202 int rc = 0;
203
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800204 /*
205 * Alloc buffer array for commands (Tx or other types of commands).
206 * For the command queue (#4), allocate command space + one big
207 * command for scan, since scan command is very huge; the system will
208 * not have two scans at the same time, so only one is needed.
209 * For data Tx queues (all other queues), no super-size command
210 * space is needed.
211 */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800212 len = sizeof(struct iwl_cmd);
213 for (i = 0; i <= slots_num; i++) {
214 if (i == slots_num) {
215 if (txq_id == IWL_CMD_QUEUE_NUM)
216 len += IWL_MAX_SCAN_SIZE;
217 else
218 continue;
219 }
220
221 txq->cmd[i] = kmalloc(len, GFP_KERNEL);
222 if (!txq->cmd[i])
223 goto err;
224 }
Zhu Yib481de92007-09-25 17:54:57 -0700225
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800226 /* Alloc driver data array and TFD circular buffer */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800227 rc = iwl3945_tx_queue_alloc(priv, txq, txq_id);
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800228 if (rc)
229 goto err;
Zhu Yib481de92007-09-25 17:54:57 -0700230
Zhu Yib481de92007-09-25 17:54:57 -0700231 txq->need_update = 0;
232
233 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
Tomas Winklerc54b6792008-03-06 17:36:53 -0800234 * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */
Zhu Yib481de92007-09-25 17:54:57 -0700235 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800236
237 /* Initialize queue high/low-water, head/tail indexes */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800238 iwl3945_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id);
Zhu Yib481de92007-09-25 17:54:57 -0700239
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800240 /* Tell device where to find queue, enable DMA channel. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800241 iwl3945_hw_tx_queue_init(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -0700242
243 return 0;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800244err:
245 for (i = 0; i < slots_num; i++) {
246 kfree(txq->cmd[i]);
247 txq->cmd[i] = NULL;
248 }
249
250 if (txq_id == IWL_CMD_QUEUE_NUM) {
251 kfree(txq->cmd[slots_num]);
252 txq->cmd[slots_num] = NULL;
253 }
254 return -ENOMEM;
Zhu Yib481de92007-09-25 17:54:57 -0700255}
256
257/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800258 * iwl3945_tx_queue_free - Deallocate DMA queue.
Zhu Yib481de92007-09-25 17:54:57 -0700259 * @txq: Transmit queue to deallocate.
260 *
261 * Empty queue by removing and destroying all BD's.
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800262 * Free all buffers.
263 * 0-fill, but do not free "txq" descriptor structure.
Zhu Yib481de92007-09-25 17:54:57 -0700264 */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800265void iwl3945_tx_queue_free(struct iwl_priv *priv, struct iwl_tx_queue *txq)
Zhu Yib481de92007-09-25 17:54:57 -0700266{
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800267 struct iwl_queue *q = &txq->q;
Zhu Yib481de92007-09-25 17:54:57 -0700268 struct pci_dev *dev = priv->pci_dev;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800269 int len, i;
Zhu Yib481de92007-09-25 17:54:57 -0700270
271 if (q->n_bd == 0)
272 return;
273
274 /* first, empty all BD's */
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800275 for (; q->write_ptr != q->read_ptr;
Tomas Winklerc54b6792008-03-06 17:36:53 -0800276 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd))
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -0800277 priv->cfg->ops->lib->txq_free_tfd(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -0700278
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800279 len = sizeof(struct iwl_cmd) * q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -0700280 if (q->id == IWL_CMD_QUEUE_NUM)
281 len += IWL_MAX_SCAN_SIZE;
282
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800283 /* De-alloc array of command/tx buffers */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800284 for (i = 0; i < TFD_TX_CMD_SLOTS; i++)
285 kfree(txq->cmd[i]);
Zhu Yib481de92007-09-25 17:54:57 -0700286
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800287 /* De-alloc circular buffer of TFDs */
Zhu Yib481de92007-09-25 17:54:57 -0700288 if (txq->q.n_bd)
Winkler, Tomasdbb66542008-12-22 11:31:14 +0800289 pci_free_consistent(dev, sizeof(struct iwl3945_tfd) *
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800290 txq->q.n_bd, txq->tfds39, txq->q.dma_addr);
Zhu Yib481de92007-09-25 17:54:57 -0700291
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800292 /* De-alloc array of per-TFD driver data */
Tomas Winkler3ac7f142008-07-21 02:40:14 +0300293 kfree(txq->txb);
294 txq->txb = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700295
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800296 /* 0-fill queue descriptor structure */
Zhu Yib481de92007-09-25 17:54:57 -0700297 memset(txq, 0, sizeof(*txq));
298}
299
Zhu Yib481de92007-09-25 17:54:57 -0700300/*************** STATION TABLE MANAGEMENT ****
Ben Cahill9fbab512007-11-29 11:09:47 +0800301 * mac80211 should be examined to determine if sta_info is duplicating
Zhu Yib481de92007-09-25 17:54:57 -0700302 * the functionality provided here
303 */
304
305/**************************************************************/
Ian Schram01ebd062007-10-25 17:15:22 +0800306#if 0 /* temporary disable till we add real remove station */
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800307/**
308 * iwl3945_remove_station - Remove driver's knowledge of station.
309 *
310 * NOTE: This does not remove station from device's station table.
311 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800312static u8 iwl3945_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
Zhu Yib481de92007-09-25 17:54:57 -0700313{
314 int index = IWL_INVALID_STATION;
315 int i;
316 unsigned long flags;
317
318 spin_lock_irqsave(&priv->sta_lock, flags);
319
320 if (is_ap)
321 index = IWL_AP_ID;
322 else if (is_broadcast_ether_addr(addr))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800323 index = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700324 else
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800325 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800326 if (priv->stations_39[i].used &&
327 !compare_ether_addr(priv->stations_39[i].sta.sta.addr,
Zhu Yib481de92007-09-25 17:54:57 -0700328 addr)) {
329 index = i;
330 break;
331 }
332
333 if (unlikely(index == IWL_INVALID_STATION))
334 goto out;
335
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800336 if (priv->stations_39[index].used) {
337 priv->stations_39[index].used = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700338 priv->num_stations--;
339 }
340
341 BUG_ON(priv->num_stations < 0);
342
343out:
344 spin_unlock_irqrestore(&priv->sta_lock, flags);
345 return 0;
346}
Zhu Yi556f8db2007-09-27 11:27:33 +0800347#endif
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800348
349/**
350 * iwl3945_clear_stations_table - Clear the driver's station table
351 *
352 * NOTE: This does not clear or otherwise alter the device's station table.
353 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800354static void iwl3945_clear_stations_table(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700355{
356 unsigned long flags;
357
358 spin_lock_irqsave(&priv->sta_lock, flags);
359
360 priv->num_stations = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800361 memset(priv->stations_39, 0, sizeof(priv->stations_39));
Zhu Yib481de92007-09-25 17:54:57 -0700362
363 spin_unlock_irqrestore(&priv->sta_lock, flags);
364}
365
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800366/**
367 * iwl3945_add_station - Add station to station tables in driver and device
368 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800369u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags)
Zhu Yib481de92007-09-25 17:54:57 -0700370{
371 int i;
372 int index = IWL_INVALID_STATION;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800373 struct iwl3945_station_entry *station;
Zhu Yib481de92007-09-25 17:54:57 -0700374 unsigned long flags_spin;
Zhu Yic14c5212007-09-27 11:27:35 +0800375 u8 rate;
Zhu Yib481de92007-09-25 17:54:57 -0700376
377 spin_lock_irqsave(&priv->sta_lock, flags_spin);
378 if (is_ap)
379 index = IWL_AP_ID;
380 else if (is_broadcast_ether_addr(addr))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800381 index = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700382 else
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800383 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800384 if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr,
Zhu Yib481de92007-09-25 17:54:57 -0700385 addr)) {
386 index = i;
387 break;
388 }
389
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800390 if (!priv->stations_39[i].used &&
Zhu Yib481de92007-09-25 17:54:57 -0700391 index == IWL_INVALID_STATION)
392 index = i;
393 }
394
Ian Schram01ebd062007-10-25 17:15:22 +0800395 /* These two conditions has the same outcome but keep them separate
Zhu Yib481de92007-09-25 17:54:57 -0700396 since they have different meaning */
397 if (unlikely(index == IWL_INVALID_STATION)) {
398 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
399 return index;
400 }
401
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800402 if (priv->stations_39[index].used &&
403 !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) {
Zhu Yib481de92007-09-25 17:54:57 -0700404 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
405 return index;
406 }
407
Johannes Berge1749612008-10-27 15:59:26 -0700408 IWL_DEBUG_ASSOC("Add STA ID %d: %pM\n", index, addr);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800409 station = &priv->stations_39[index];
Zhu Yib481de92007-09-25 17:54:57 -0700410 station->used = 1;
411 priv->num_stations++;
412
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800413 /* Set up the REPLY_ADD_STA command to send to device */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800414 memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd));
Zhu Yib481de92007-09-25 17:54:57 -0700415 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
416 station->sta.mode = 0;
417 station->sta.sta.sta_id = index;
418 station->sta.station_flags = 0;
419
Johannes Berg8318d782008-01-24 19:38:38 +0100420 if (priv->band == IEEE80211_BAND_5GHZ)
Tomas Winkler69946332007-10-25 17:15:27 +0800421 rate = IWL_RATE_6M_PLCP;
422 else
423 rate = IWL_RATE_1M_PLCP;
Zhu Yic14c5212007-09-27 11:27:35 +0800424
425 /* Turn on both antennas for the station... */
426 station->sta.rate_n_flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800427 iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK);
Zhu Yic14c5212007-09-27 11:27:35 +0800428
Zhu Yib481de92007-09-25 17:54:57 -0700429 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800430
431 /* Add station to device's station table */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800432 iwl3945_send_add_station(priv, &station->sta, flags);
Zhu Yib481de92007-09-25 17:54:57 -0700433 return index;
434
435}
436
Samuel Ortiz518099a2009-01-19 15:30:27 -0800437int iwl3945_send_statistics_request(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700438{
Samuel Ortiz518099a2009-01-19 15:30:27 -0800439 u32 val = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700440
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800441 struct iwl_host_cmd cmd = {
Samuel Ortiz518099a2009-01-19 15:30:27 -0800442 .id = REPLY_STATISTICS_CMD,
Zhu Yib481de92007-09-25 17:54:57 -0700443 .len = sizeof(val),
444 .data = &val,
445 };
446
Samuel Ortiz518099a2009-01-19 15:30:27 -0800447 return iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700448}
449
450/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800451 * iwl3945_set_rxon_channel - Set the phymode and channel values in staging RXON
Johannes Berg8318d782008-01-24 19:38:38 +0100452 * @band: 2.4 or 5 GHz band
453 * @channel: Any channel valid for the requested band
Zhu Yib481de92007-09-25 17:54:57 -0700454
Johannes Berg8318d782008-01-24 19:38:38 +0100455 * In addition to setting the staging RXON, priv->band is also set.
Zhu Yib481de92007-09-25 17:54:57 -0700456 *
457 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
Johannes Berg8318d782008-01-24 19:38:38 +0100458 * in the staging RXON flag structure based on the band
Zhu Yib481de92007-09-25 17:54:57 -0700459 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800460static int iwl3945_set_rxon_channel(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +0100461 enum ieee80211_band band,
462 u16 channel)
Zhu Yib481de92007-09-25 17:54:57 -0700463{
Johannes Berg8318d782008-01-24 19:38:38 +0100464 if (!iwl3945_get_channel_info(priv, band, channel)) {
Zhu Yib481de92007-09-25 17:54:57 -0700465 IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
Johannes Berg8318d782008-01-24 19:38:38 +0100466 channel, band);
Zhu Yib481de92007-09-25 17:54:57 -0700467 return -EINVAL;
468 }
469
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800470 if ((le16_to_cpu(priv->staging39_rxon.channel) == channel) &&
Johannes Berg8318d782008-01-24 19:38:38 +0100471 (priv->band == band))
Zhu Yib481de92007-09-25 17:54:57 -0700472 return 0;
473
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800474 priv->staging39_rxon.channel = cpu_to_le16(channel);
Johannes Berg8318d782008-01-24 19:38:38 +0100475 if (band == IEEE80211_BAND_5GHZ)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800476 priv->staging39_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700477 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800478 priv->staging39_rxon.flags |= RXON_FLG_BAND_24G_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700479
Johannes Berg8318d782008-01-24 19:38:38 +0100480 priv->band = band;
Zhu Yib481de92007-09-25 17:54:57 -0700481
Johannes Berg8318d782008-01-24 19:38:38 +0100482 IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band);
Zhu Yib481de92007-09-25 17:54:57 -0700483
484 return 0;
485}
486
487/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800488 * iwl3945_check_rxon_cmd - validate RXON structure is valid
Zhu Yib481de92007-09-25 17:54:57 -0700489 *
490 * NOTE: This is really only useful during development and can eventually
491 * be #ifdef'd out once the driver is stable and folks aren't actively
492 * making changes
493 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800494static int iwl3945_check_rxon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700495{
496 int error = 0;
497 int counter = 1;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800498 struct iwl3945_rxon_cmd *rxon = &priv->staging39_rxon;
Zhu Yib481de92007-09-25 17:54:57 -0700499
500 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
501 error |= le32_to_cpu(rxon->flags &
502 (RXON_FLG_TGJ_NARROW_BAND_MSK |
503 RXON_FLG_RADAR_DETECT_MSK));
504 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800505 IWL_WARN(priv, "check 24G fields %d | %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700506 counter++, error);
507 } else {
508 error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
509 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
510 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800511 IWL_WARN(priv, "check 52 fields %d | %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700512 counter++, error);
513 error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
514 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800515 IWL_WARN(priv, "check 52 CCK %d | %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700516 counter++, error);
517 }
518 error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
519 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800520 IWL_WARN(priv, "check mac addr %d | %d\n", counter++, error);
Zhu Yib481de92007-09-25 17:54:57 -0700521
522 /* make sure basic rates 6Mbps and 1Mbps are supported */
523 error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
524 ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
525 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800526 IWL_WARN(priv, "check basic rate %d | %d\n", counter++, error);
Zhu Yib481de92007-09-25 17:54:57 -0700527
528 error |= (le16_to_cpu(rxon->assoc_id) > 2007);
529 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800530 IWL_WARN(priv, "check assoc id %d | %d\n", counter++, error);
Zhu Yib481de92007-09-25 17:54:57 -0700531
532 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
533 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
534 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800535 IWL_WARN(priv, "check CCK and short slot %d | %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700536 counter++, error);
537
538 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
539 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
540 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800541 IWL_WARN(priv, "check CCK & auto detect %d | %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700542 counter++, error);
543
544 error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
545 RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
546 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800547 IWL_WARN(priv, "check TGG and auto detect %d | %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700548 counter++, error);
549
550 if ((rxon->flags & RXON_FLG_DIS_DIV_MSK))
551 error |= ((rxon->flags & (RXON_FLG_ANT_B_MSK |
552 RXON_FLG_ANT_A_MSK)) == 0);
553 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800554 IWL_WARN(priv, "check antenna %d %d\n", counter++, error);
Zhu Yib481de92007-09-25 17:54:57 -0700555
556 if (error)
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800557 IWL_WARN(priv, "Tuning to channel %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700558 le16_to_cpu(rxon->channel));
559
560 if (error) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800561 IWL_ERR(priv, "Not a valid rxon_assoc_cmd field values\n");
Zhu Yib481de92007-09-25 17:54:57 -0700562 return -1;
563 }
564 return 0;
565}
566
567/**
Ben Cahill9fbab512007-11-29 11:09:47 +0800568 * iwl3945_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
Ian Schram01ebd062007-10-25 17:15:22 +0800569 * @priv: staging_rxon is compared to active_rxon
Zhu Yib481de92007-09-25 17:54:57 -0700570 *
Ben Cahill9fbab512007-11-29 11:09:47 +0800571 * If the RXON structure is changing enough to require a new tune,
572 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
573 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
Zhu Yib481de92007-09-25 17:54:57 -0700574 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800575static int iwl3945_full_rxon_required(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700576{
577
578 /* These items are only settable from the full RXON command */
Ron Rindjunsky5d1e2322008-06-30 17:23:04 +0800579 if (!(iwl3945_is_associated(priv)) ||
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800580 compare_ether_addr(priv->staging39_rxon.bssid_addr,
581 priv->active39_rxon.bssid_addr) ||
582 compare_ether_addr(priv->staging39_rxon.node_addr,
583 priv->active39_rxon.node_addr) ||
584 compare_ether_addr(priv->staging39_rxon.wlap_bssid_addr,
585 priv->active39_rxon.wlap_bssid_addr) ||
586 (priv->staging39_rxon.dev_type != priv->active39_rxon.dev_type) ||
587 (priv->staging39_rxon.channel != priv->active39_rxon.channel) ||
588 (priv->staging39_rxon.air_propagation !=
589 priv->active39_rxon.air_propagation) ||
590 (priv->staging39_rxon.assoc_id != priv->active39_rxon.assoc_id))
Zhu Yib481de92007-09-25 17:54:57 -0700591 return 1;
592
593 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
594 * be updated with the RXON_ASSOC command -- however only some
595 * flag transitions are allowed using RXON_ASSOC */
596
597 /* Check if we are not switching bands */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800598 if ((priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
599 (priv->active39_rxon.flags & RXON_FLG_BAND_24G_MSK))
Zhu Yib481de92007-09-25 17:54:57 -0700600 return 1;
601
602 /* Check if we are switching association toggle */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800603 if ((priv->staging39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
604 (priv->active39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
Zhu Yib481de92007-09-25 17:54:57 -0700605 return 1;
606
607 return 0;
608}
609
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800610static int iwl3945_send_rxon_assoc(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700611{
612 int rc = 0;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800613 struct iwl_rx_packet *res = NULL;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800614 struct iwl3945_rxon_assoc_cmd rxon_assoc;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800615 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700616 .id = REPLY_RXON_ASSOC,
617 .len = sizeof(rxon_assoc),
618 .meta.flags = CMD_WANT_SKB,
619 .data = &rxon_assoc,
620 };
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800621 const struct iwl3945_rxon_cmd *rxon1 = &priv->staging39_rxon;
622 const struct iwl3945_rxon_cmd *rxon2 = &priv->active39_rxon;
Zhu Yib481de92007-09-25 17:54:57 -0700623
624 if ((rxon1->flags == rxon2->flags) &&
625 (rxon1->filter_flags == rxon2->filter_flags) &&
626 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
627 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
628 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
629 return 0;
630 }
631
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800632 rxon_assoc.flags = priv->staging39_rxon.flags;
633 rxon_assoc.filter_flags = priv->staging39_rxon.filter_flags;
634 rxon_assoc.ofdm_basic_rates = priv->staging39_rxon.ofdm_basic_rates;
635 rxon_assoc.cck_basic_rates = priv->staging39_rxon.cck_basic_rates;
Zhu Yib481de92007-09-25 17:54:57 -0700636 rxon_assoc.reserved = 0;
637
Samuel Ortiz518099a2009-01-19 15:30:27 -0800638 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700639 if (rc)
640 return rc;
641
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800642 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700643 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800644 IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -0700645 rc = -EIO;
646 }
647
648 priv->alloc_rxb_skb--;
649 dev_kfree_skb_any(cmd.meta.u.skb);
650
651 return rc;
652}
653
654/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800655 * iwl3945_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -0700656 *
Ian Schram01ebd062007-10-25 17:15:22 +0800657 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -0700658 * the active_rxon structure is updated with the new data. This
659 * function correctly transitions out of the RXON_ASSOC_MSK state if
660 * a HW tune is required based on the RXON structure changes.
661 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800662static int iwl3945_commit_rxon(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700663{
664 /* cast away the const for active_rxon in this function */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800665 struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active39_rxon;
Zhu Yib481de92007-09-25 17:54:57 -0700666 int rc = 0;
667
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800668 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700669 return -1;
670
671 /* always get timestamp with Rx frame */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800672 priv->staging39_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700673
674 /* select antenna */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800675 priv->staging39_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -0700676 ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800677 priv->staging39_rxon.flags |= iwl3945_get_antenna_flags(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700678
Samuel Ortiza3139c52008-12-19 10:37:09 +0800679 rc = iwl3945_check_rxon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700680 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800681 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700682 return -EINVAL;
683 }
684
685 /* If we don't need to send a full RXON, we can use
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800686 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -0700687 * and other flags for the current radio configuration. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800688 if (!iwl3945_full_rxon_required(priv)) {
689 rc = iwl3945_send_rxon_assoc(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700690 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800691 IWL_ERR(priv, "Error setting RXON_ASSOC "
Zhu Yib481de92007-09-25 17:54:57 -0700692 "configuration (%d).\n", rc);
693 return rc;
694 }
695
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800696 memcpy(active_rxon, &priv->staging39_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700697
698 return 0;
699 }
700
701 /* If we are currently associated and the new config requires
702 * an RXON_ASSOC and the new config wants the associated mask enabled,
703 * we must clear the associated from the active configuration
704 * before we apply the new config */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800705 if (iwl3945_is_associated(priv) &&
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800706 (priv->staging39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
Zhu Yib481de92007-09-25 17:54:57 -0700707 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
708 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
709
Samuel Ortiz518099a2009-01-19 15:30:27 -0800710 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800711 sizeof(struct iwl3945_rxon_cmd),
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800712 &priv->active39_rxon);
Zhu Yib481de92007-09-25 17:54:57 -0700713
714 /* If the mask clearing failed then we set
715 * active_rxon back to what it was previously */
716 if (rc) {
717 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
Winkler, Tomas15b16872008-12-19 10:37:33 +0800718 IWL_ERR(priv, "Error clearing ASSOC_MSK on current "
Zhu Yib481de92007-09-25 17:54:57 -0700719 "configuration (%d).\n", rc);
720 return rc;
721 }
Zhu Yib481de92007-09-25 17:54:57 -0700722 }
723
724 IWL_DEBUG_INFO("Sending RXON\n"
725 "* with%s RXON_FILTER_ASSOC_MSK\n"
726 "* channel = %d\n"
Johannes Berge1749612008-10-27 15:59:26 -0700727 "* bssid = %pM\n",
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800728 ((priv->staging39_rxon.filter_flags &
Zhu Yib481de92007-09-25 17:54:57 -0700729 RXON_FILTER_ASSOC_MSK) ? "" : "out"),
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800730 le16_to_cpu(priv->staging39_rxon.channel),
Johannes Berge1749612008-10-27 15:59:26 -0700731 priv->staging_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -0700732
733 /* Apply the new configuration */
Samuel Ortiz518099a2009-01-19 15:30:27 -0800734 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800735 sizeof(struct iwl3945_rxon_cmd), &priv->staging39_rxon);
Zhu Yib481de92007-09-25 17:54:57 -0700736 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800737 IWL_ERR(priv, "Error setting new configuration (%d).\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700738 return rc;
739 }
740
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800741 memcpy(active_rxon, &priv->staging39_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700742
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800743 iwl3945_clear_stations_table(priv);
Zhu Yi556f8db2007-09-27 11:27:33 +0800744
Zhu Yib481de92007-09-25 17:54:57 -0700745 /* If we issue a new RXON command which required a tune then we must
746 * send a new TXPOWER command or we won't be able to Tx any frames */
Samuel Ortiz75bcfae2009-01-23 13:45:11 -0800747 rc = priv->cfg->ops->lib->send_tx_power(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700748 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800749 IWL_ERR(priv, "Error setting Tx power (%d).\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700750 return rc;
751 }
752
753 /* Add the broadcast address so we can send broadcast frames */
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +0800754 if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) ==
Zhu Yib481de92007-09-25 17:54:57 -0700755 IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800756 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700757 return -EIO;
758 }
759
760 /* If we have set the ASSOC_MSK and we are in BSS mode then
761 * add the IWL_AP_ID to the station rate table */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800762 if (iwl3945_is_associated(priv) &&
Johannes Berg05c914f2008-09-11 00:01:58 +0200763 (priv->iw_mode == NL80211_IFTYPE_STATION))
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800764 if (iwl3945_add_station(priv, priv->active39_rxon.bssid_addr, 1, 0)
Zhu Yib481de92007-09-25 17:54:57 -0700765 == IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800766 IWL_ERR(priv, "Error adding AP address for transmit\n");
Zhu Yib481de92007-09-25 17:54:57 -0700767 return -EIO;
768 }
769
Johannes Berg8318d782008-01-24 19:38:38 +0100770 /* Init the hardware's rate fallback order based on the band */
Zhu Yib481de92007-09-25 17:54:57 -0700771 rc = iwl3945_init_hw_rate_table(priv);
772 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800773 IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700774 return -EIO;
775 }
776
777 return 0;
778}
779
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800780static int iwl3945_send_bt_config(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700781{
Tomas Winkler4c897252008-12-19 10:37:05 +0800782 struct iwl_bt_cmd bt_cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700783 .flags = 3,
784 .lead_time = 0xAA,
785 .max_kill = 1,
786 .kill_ack_mask = 0,
787 .kill_cts_mask = 0,
788 };
789
Samuel Ortiz518099a2009-01-19 15:30:27 -0800790 return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
Tomas Winkler4c897252008-12-19 10:37:05 +0800791 sizeof(bt_cmd), &bt_cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700792}
793
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800794static int iwl3945_add_sta_sync_callback(struct iwl_priv *priv,
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800795 struct iwl_cmd *cmd, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -0700796{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800797 struct iwl_rx_packet *res = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700798
799 if (!skb) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800800 IWL_ERR(priv, "Error: Response NULL in REPLY_ADD_STA.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700801 return 1;
802 }
803
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800804 res = (struct iwl_rx_packet *)skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700805 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800806 IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n",
Zhu Yib481de92007-09-25 17:54:57 -0700807 res->hdr.flags);
808 return 1;
809 }
810
811 switch (res->u.add_sta.status) {
812 case ADD_STA_SUCCESS_MSK:
813 break;
814 default:
815 break;
816 }
817
818 /* We didn't cache the SKB; let the caller free it */
819 return 1;
820}
821
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800822int iwl3945_send_add_station(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800823 struct iwl3945_addsta_cmd *sta, u8 flags)
Zhu Yib481de92007-09-25 17:54:57 -0700824{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800825 struct iwl_rx_packet *res = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700826 int rc = 0;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800827 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700828 .id = REPLY_ADD_STA,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800829 .len = sizeof(struct iwl3945_addsta_cmd),
Zhu Yib481de92007-09-25 17:54:57 -0700830 .meta.flags = flags,
831 .data = sta,
832 };
833
834 if (flags & CMD_ASYNC)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800835 cmd.meta.u.callback = iwl3945_add_sta_sync_callback;
Zhu Yib481de92007-09-25 17:54:57 -0700836 else
837 cmd.meta.flags |= CMD_WANT_SKB;
838
Samuel Ortiz518099a2009-01-19 15:30:27 -0800839 rc = iwl_send_cmd(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700840
841 if (rc || (flags & CMD_ASYNC))
842 return rc;
843
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800844 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700845 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800846 IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n",
Zhu Yib481de92007-09-25 17:54:57 -0700847 res->hdr.flags);
848 rc = -EIO;
849 }
850
851 if (rc == 0) {
852 switch (res->u.add_sta.status) {
853 case ADD_STA_SUCCESS_MSK:
854 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
855 break;
856 default:
857 rc = -EIO;
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800858 IWL_WARN(priv, "REPLY_ADD_STA failed\n");
Zhu Yib481de92007-09-25 17:54:57 -0700859 break;
860 }
861 }
862
863 priv->alloc_rxb_skb--;
864 dev_kfree_skb_any(cmd.meta.u.skb);
865
866 return rc;
867}
868
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800869static int iwl3945_update_sta_key_info(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700870 struct ieee80211_key_conf *keyconf,
871 u8 sta_id)
872{
873 unsigned long flags;
874 __le16 key_flags = 0;
875
876 switch (keyconf->alg) {
877 case ALG_CCMP:
878 key_flags |= STA_KEY_FLG_CCMP;
879 key_flags |= cpu_to_le16(
880 keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
881 key_flags &= ~STA_KEY_FLG_INVALID;
882 break;
883 case ALG_TKIP:
884 case ALG_WEP:
Zhu Yib481de92007-09-25 17:54:57 -0700885 default:
886 return -EINVAL;
887 }
888 spin_lock_irqsave(&priv->sta_lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800889 priv->stations_39[sta_id].keyinfo.alg = keyconf->alg;
890 priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen;
891 memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700892 keyconf->keylen);
893
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800894 memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700895 keyconf->keylen);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800896 priv->stations_39[sta_id].sta.key.key_flags = key_flags;
897 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
898 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700899
900 spin_unlock_irqrestore(&priv->sta_lock, flags);
901
902 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800903 iwl3945_send_add_station(priv, &priv->stations_39[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700904 return 0;
905}
906
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800907static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
Zhu Yib481de92007-09-25 17:54:57 -0700908{
909 unsigned long flags;
910
911 spin_lock_irqsave(&priv->sta_lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800912 memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key));
913 memset(&priv->stations_39[sta_id].sta.key, 0,
Tomas Winkler4c897252008-12-19 10:37:05 +0800914 sizeof(struct iwl4965_keyinfo));
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800915 priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
916 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
917 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700918 spin_unlock_irqrestore(&priv->sta_lock, flags);
919
920 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800921 iwl3945_send_add_station(priv, &priv->stations_39[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700922 return 0;
923}
924
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800925static void iwl3945_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700926{
927 struct list_head *element;
928
929 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
930 priv->frames_count);
931
932 while (!list_empty(&priv->free_frames)) {
933 element = priv->free_frames.next;
934 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800935 kfree(list_entry(element, struct iwl3945_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700936 priv->frames_count--;
937 }
938
939 if (priv->frames_count) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800940 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
Zhu Yib481de92007-09-25 17:54:57 -0700941 priv->frames_count);
942 priv->frames_count = 0;
943 }
944}
945
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800946static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700947{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800948 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700949 struct list_head *element;
950 if (list_empty(&priv->free_frames)) {
951 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
952 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800953 IWL_ERR(priv, "Could not allocate frame!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700954 return NULL;
955 }
956
957 priv->frames_count++;
958 return frame;
959 }
960
961 element = priv->free_frames.next;
962 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800963 return list_entry(element, struct iwl3945_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700964}
965
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800966static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700967{
968 memset(frame, 0, sizeof(*frame));
969 list_add(&frame->list, &priv->free_frames);
970}
971
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800972unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700973 struct ieee80211_hdr *hdr,
Rami Rosen73ec1cc2008-12-16 09:37:07 +0200974 int left)
Zhu Yib481de92007-09-25 17:54:57 -0700975{
976
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800977 if (!iwl3945_is_associated(priv) || !priv->ibss_beacon ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200978 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
979 (priv->iw_mode != NL80211_IFTYPE_AP)))
Zhu Yib481de92007-09-25 17:54:57 -0700980 return 0;
981
982 if (priv->ibss_beacon->len > left)
983 return 0;
984
985 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
986
987 return priv->ibss_beacon->len;
988}
989
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800990static u8 iwl3945_rate_get_lowest_plcp(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700991{
992 u8 i;
Kolekar, Abhijeetc24f0812008-11-07 09:58:44 -0800993 int rate_mask;
994
995 /* Set rate mask*/
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800996 if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK)
Chatre, Reinettedbce56a2008-11-12 13:14:07 -0800997 rate_mask = priv->active_rate_basic & IWL_CCK_RATES_MASK;
Kolekar, Abhijeetc24f0812008-11-07 09:58:44 -0800998 else
Chatre, Reinettedbce56a2008-11-12 13:14:07 -0800999 rate_mask = priv->active_rate_basic & IWL_OFDM_RATES_MASK;
Zhu Yib481de92007-09-25 17:54:57 -07001000
1001 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001002 i = iwl3945_rates[i].next_ieee) {
Zhu Yib481de92007-09-25 17:54:57 -07001003 if (rate_mask & (1 << i))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001004 return iwl3945_rates[i].plcp;
Zhu Yib481de92007-09-25 17:54:57 -07001005 }
1006
Kolekar, Abhijeetc24f0812008-11-07 09:58:44 -08001007 /* No valid rate was found. Assign the lowest one */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001008 if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK)
Kolekar, Abhijeetc24f0812008-11-07 09:58:44 -08001009 return IWL_RATE_1M_PLCP;
1010 else
1011 return IWL_RATE_6M_PLCP;
Zhu Yib481de92007-09-25 17:54:57 -07001012}
1013
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001014static int iwl3945_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001015{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001016 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -07001017 unsigned int frame_size;
1018 int rc;
1019 u8 rate;
1020
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001021 frame = iwl3945_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001022
1023 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001024 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
Zhu Yib481de92007-09-25 17:54:57 -07001025 "command.\n");
1026 return -ENOMEM;
1027 }
1028
Kolekar, Abhijeetc24f0812008-11-07 09:58:44 -08001029 rate = iwl3945_rate_get_lowest_plcp(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001030
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001031 frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -07001032
Samuel Ortiz518099a2009-01-19 15:30:27 -08001033 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -07001034 &frame->u.cmd[0]);
1035
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001036 iwl3945_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -07001037
1038 return rc;
1039}
1040
1041/******************************************************************************
1042 *
1043 * EEPROM related functions
1044 *
1045 ******************************************************************************/
1046
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001047static void get_eeprom_mac(struct iwl_priv *priv, u8 *mac)
Zhu Yib481de92007-09-25 17:54:57 -07001048{
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001049 memcpy(mac, priv->eeprom39.mac_address, 6);
Zhu Yib481de92007-09-25 17:54:57 -07001050}
1051
Reinette Chatre74a3a252008-01-23 10:15:19 -08001052/*
1053 * Clear the OWNER_MSK, to establish driver (instead of uCode running on
1054 * embedded controller) as EEPROM reader; each read is a series of pulses
1055 * to/from the EEPROM chip, not a single event, so even reads could conflict
1056 * if they weren't arbitrated by some ownership mechanism. Here, the driver
1057 * simply claims ownership, which should be safe when this function is called
1058 * (i.e. before loading uCode!).
1059 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001060static inline int iwl3945_eeprom_acquire_semaphore(struct iwl_priv *priv)
Reinette Chatre74a3a252008-01-23 10:15:19 -08001061{
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001062 _iwl_clear_bit(priv, CSR_EEPROM_GP, CSR_EEPROM_GP_IF_OWNER_MSK);
Reinette Chatre74a3a252008-01-23 10:15:19 -08001063 return 0;
1064}
1065
Zhu Yib481de92007-09-25 17:54:57 -07001066/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001067 * iwl3945_eeprom_init - read EEPROM contents
Zhu Yib481de92007-09-25 17:54:57 -07001068 *
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001069 * Load the EEPROM contents from adapter into priv->eeprom39
Zhu Yib481de92007-09-25 17:54:57 -07001070 *
1071 * NOTE: This routine uses the non-debug IO access functions.
1072 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001073int iwl3945_eeprom_init(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001074{
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001075 u16 *e = (u16 *)&priv->eeprom39;
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001076 u32 gp = iwl_read32(priv, CSR_EEPROM_GP);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001077 int sz = sizeof(priv->eeprom39);
Zhu, Yi3d5717a2008-12-11 10:33:36 -08001078 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07001079 u16 addr;
1080
1081 /* The EEPROM structure has several padding buffers within it
1082 * and when adding new EEPROM maps is subject to programmer errors
1083 * which may be very difficult to identify without explicitly
1084 * checking the resulting size of the eeprom map. */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001085 BUILD_BUG_ON(sizeof(priv->eeprom39) != IWL_EEPROM_IMAGE_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07001086
1087 if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001088 IWL_ERR(priv, "EEPROM not found, EEPROM_GP=0x%08x\n", gp);
Zhu Yib481de92007-09-25 17:54:57 -07001089 return -ENOENT;
1090 }
1091
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001092 /* Make sure driver (instead of uCode) is allowed to read EEPROM */
Zhu, Yi3d5717a2008-12-11 10:33:36 -08001093 ret = iwl3945_eeprom_acquire_semaphore(priv);
1094 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001095 IWL_ERR(priv, "Failed to acquire EEPROM semaphore.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001096 return -ENOENT;
1097 }
1098
1099 /* eeprom is an array of 16bit values */
1100 for (addr = 0; addr < sz; addr += sizeof(u16)) {
Zhu, Yi3d5717a2008-12-11 10:33:36 -08001101 u32 r;
1102
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001103 _iwl_write32(priv, CSR_EEPROM_REG,
Zhu, Yi3d5717a2008-12-11 10:33:36 -08001104 CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001105 _iwl_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD);
1106 ret = iwl_poll_direct_bit(priv, CSR_EEPROM_REG,
Zhu, Yi3d5717a2008-12-11 10:33:36 -08001107 CSR_EEPROM_REG_READ_VALID_MSK,
1108 IWL_EEPROM_ACCESS_TIMEOUT);
1109 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001110 IWL_ERR(priv, "Time out reading EEPROM[%d]\n", addr);
Zhu, Yi3d5717a2008-12-11 10:33:36 -08001111 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07001112 }
Zhu, Yi3d5717a2008-12-11 10:33:36 -08001113
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001114 r = _iwl_read_direct32(priv, CSR_EEPROM_REG);
Tomas Winkler58ff6d42008-02-13 02:47:54 +02001115 e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16));
Zhu Yib481de92007-09-25 17:54:57 -07001116 }
1117
1118 return 0;
1119}
1120
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001121static void iwl3945_unset_hw_params(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001122{
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001123 if (priv->shared_virt)
Zhu Yib481de92007-09-25 17:54:57 -07001124 pci_free_consistent(priv->pci_dev,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001125 sizeof(struct iwl3945_shared),
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001126 priv->shared_virt,
1127 priv->shared_phys);
Zhu Yib481de92007-09-25 17:54:57 -07001128}
1129
Zhu Yib481de92007-09-25 17:54:57 -07001130/*
1131 * QoS support
1132*/
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001133static int iwl3945_send_qos_params_command(struct iwl_priv *priv,
Tomas Winkler4c897252008-12-19 10:37:05 +08001134 struct iwl_qosparam_cmd *qos)
Zhu Yib481de92007-09-25 17:54:57 -07001135{
1136
Samuel Ortiz518099a2009-01-19 15:30:27 -08001137 return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
Tomas Winkler4c897252008-12-19 10:37:05 +08001138 sizeof(struct iwl_qosparam_cmd), qos);
Zhu Yib481de92007-09-25 17:54:57 -07001139}
1140
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001141static void iwl3945_activate_qos(struct iwl_priv *priv, u8 force)
Zhu Yib481de92007-09-25 17:54:57 -07001142{
1143 unsigned long flags;
1144
Zhu Yib481de92007-09-25 17:54:57 -07001145 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1146 return;
1147
Zhu Yib481de92007-09-25 17:54:57 -07001148 spin_lock_irqsave(&priv->lock, flags);
1149 priv->qos_data.def_qos_parm.qos_flags = 0;
1150
1151 if (priv->qos_data.qos_cap.q_AP.queue_request &&
1152 !priv->qos_data.qos_cap.q_AP.txop_request)
1153 priv->qos_data.def_qos_parm.qos_flags |=
1154 QOS_PARAM_FLG_TXOP_TYPE_MSK;
1155
1156 if (priv->qos_data.qos_active)
1157 priv->qos_data.def_qos_parm.qos_flags |=
1158 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
1159
1160 spin_unlock_irqrestore(&priv->lock, flags);
1161
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001162 if (force || iwl3945_is_associated(priv)) {
Tomas Winklera96a27f2008-10-23 23:48:56 -07001163 IWL_DEBUG_QOS("send QoS cmd with QoS active %d \n",
Zhu Yib481de92007-09-25 17:54:57 -07001164 priv->qos_data.qos_active);
1165
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001166 iwl3945_send_qos_params_command(priv,
Zhu Yib481de92007-09-25 17:54:57 -07001167 &(priv->qos_data.def_qos_parm));
1168 }
1169}
1170
Zhu Yib481de92007-09-25 17:54:57 -07001171/*
1172 * Power management (not Tx power!) functions
1173 */
1174#define MSEC_TO_USEC 1024
1175
Tomas Winkler600c0e12008-12-19 10:37:04 +08001176
Zhu Yib481de92007-09-25 17:54:57 -07001177/* default power management (not Tx power) table values */
Tomas Winklera96a27f2008-10-23 23:48:56 -07001178/* for TIM 0-10 */
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08001179static struct iwl_power_vec_entry range_0[IWL_POWER_MAX] = {
1180 {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1181 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
1182 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
1183 {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
1184 {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
1185 {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
Zhu Yib481de92007-09-25 17:54:57 -07001186};
1187
Tomas Winklera96a27f2008-10-23 23:48:56 -07001188/* for TIM > 10 */
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08001189static struct iwl_power_vec_entry range_1[IWL_POWER_MAX] = {
1190 {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1191 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
1192 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
1193 {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
1194 {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
1195 {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
Zhu Yib481de92007-09-25 17:54:57 -07001196};
1197
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001198int iwl3945_power_init_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001199{
1200 int rc = 0, i;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08001201 struct iwl_power_mgr *pow_data;
1202 int size = sizeof(struct iwl_power_vec_entry) * IWL_POWER_MAX;
Zhu Yib481de92007-09-25 17:54:57 -07001203 u16 pci_pm;
1204
1205 IWL_DEBUG_POWER("Initialize power \n");
1206
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08001207 pow_data = &priv->power_data;
Zhu Yib481de92007-09-25 17:54:57 -07001208
1209 memset(pow_data, 0, sizeof(*pow_data));
1210
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08001211 pow_data->dtim_period = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001212
1213 memcpy(&pow_data->pwr_range_0[0], &range_0[0], size);
1214 memcpy(&pow_data->pwr_range_1[0], &range_1[0], size);
1215
1216 rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm);
1217 if (rc != 0)
1218 return 0;
1219 else {
Tomas Winkler600c0e12008-12-19 10:37:04 +08001220 struct iwl_powertable_cmd *cmd;
Zhu Yib481de92007-09-25 17:54:57 -07001221
1222 IWL_DEBUG_POWER("adjust power command flags\n");
1223
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08001224 for (i = 0; i < IWL_POWER_MAX; i++) {
Zhu Yib481de92007-09-25 17:54:57 -07001225 cmd = &pow_data->pwr_range_0[i].cmd;
1226
1227 if (pci_pm & 0x1)
1228 cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
1229 else
1230 cmd->flags |= IWL_POWER_PCI_PM_MSK;
1231 }
1232 }
1233 return rc;
1234}
1235
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001236static int iwl3945_update_power_cmd(struct iwl_priv *priv,
Tomas Winkler600c0e12008-12-19 10:37:04 +08001237 struct iwl_powertable_cmd *cmd, u32 mode)
Zhu Yib481de92007-09-25 17:54:57 -07001238{
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08001239 struct iwl_power_mgr *pow_data;
Samuel Ortiz1125eff2008-12-19 10:37:14 +08001240 struct iwl_power_vec_entry *range;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08001241 u32 max_sleep = 0;
1242 int i;
Zhu Yib481de92007-09-25 17:54:57 -07001243 u8 period = 0;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08001244 bool skip;
Zhu Yib481de92007-09-25 17:54:57 -07001245
1246 if (mode > IWL_POWER_INDEX_5) {
1247 IWL_DEBUG_POWER("Error invalid power mode \n");
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08001248 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001249 }
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08001250 pow_data = &priv->power_data;
Zhu Yib481de92007-09-25 17:54:57 -07001251
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08001252 if (pow_data->dtim_period < 10)
Zhu Yib481de92007-09-25 17:54:57 -07001253 range = &pow_data->pwr_range_0[0];
1254 else
1255 range = &pow_data->pwr_range_1[1];
1256
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001257 memcpy(cmd, &range[mode].cmd, sizeof(struct iwl3945_powertable_cmd));
Zhu Yib481de92007-09-25 17:54:57 -07001258
Zhu Yib481de92007-09-25 17:54:57 -07001259
1260 if (period == 0) {
1261 period = 1;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08001262 skip = false;
1263 } else {
1264 skip = !!range[mode].no_dtim;
Zhu Yib481de92007-09-25 17:54:57 -07001265 }
1266
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08001267 if (skip) {
Zhu Yib481de92007-09-25 17:54:57 -07001268 __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
1269 max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
1270 cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08001271 } else {
1272 max_sleep = period;
1273 cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001274 }
1275
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08001276 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
Zhu Yib481de92007-09-25 17:54:57 -07001277 if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
1278 cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
Zhu Yib481de92007-09-25 17:54:57 -07001279
1280 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags);
1281 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
1282 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
1283 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
1284 le32_to_cpu(cmd->sleep_interval[0]),
1285 le32_to_cpu(cmd->sleep_interval[1]),
1286 le32_to_cpu(cmd->sleep_interval[2]),
1287 le32_to_cpu(cmd->sleep_interval[3]),
1288 le32_to_cpu(cmd->sleep_interval[4]));
1289
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08001290 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07001291}
1292
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001293static int iwl3945_send_power_mode(struct iwl_priv *priv, u32 mode)
Zhu Yib481de92007-09-25 17:54:57 -07001294{
John W. Linville9a62f732007-11-15 16:27:36 -05001295 u32 uninitialized_var(final_mode);
Zhu Yib481de92007-09-25 17:54:57 -07001296 int rc;
Tomas Winkler600c0e12008-12-19 10:37:04 +08001297 struct iwl_powertable_cmd cmd;
Zhu Yib481de92007-09-25 17:54:57 -07001298
1299 /* If on battery, set to 3,
Ian Schram01ebd062007-10-25 17:15:22 +08001300 * if plugged into AC power, set to CAM ("continuously aware mode"),
Zhu Yib481de92007-09-25 17:54:57 -07001301 * else user level */
1302 switch (mode) {
Samuel Ortiz1125eff2008-12-19 10:37:14 +08001303 case IWL39_POWER_BATTERY:
Zhu Yib481de92007-09-25 17:54:57 -07001304 final_mode = IWL_POWER_INDEX_3;
1305 break;
Samuel Ortiz1125eff2008-12-19 10:37:14 +08001306 case IWL39_POWER_AC:
Zhu Yib481de92007-09-25 17:54:57 -07001307 final_mode = IWL_POWER_MODE_CAM;
1308 break;
1309 default:
1310 final_mode = mode;
1311 break;
1312 }
1313
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001314 iwl3945_update_power_cmd(priv, &cmd, final_mode);
Zhu Yib481de92007-09-25 17:54:57 -07001315
Tomas Winkler600c0e12008-12-19 10:37:04 +08001316 /* FIXME use get_hcmd_size 3945 command is 4 bytes shorter */
Samuel Ortiz518099a2009-01-19 15:30:27 -08001317 rc = iwl_send_cmd_pdu(priv, POWER_TABLE_CMD,
1318 sizeof(struct iwl3945_powertable_cmd), &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001319
1320 if (final_mode == IWL_POWER_MODE_CAM)
1321 clear_bit(STATUS_POWER_PMI, &priv->status);
1322 else
1323 set_bit(STATUS_POWER_PMI, &priv->status);
1324
1325 return rc;
1326}
1327
Zhu Yib481de92007-09-25 17:54:57 -07001328#define MAX_UCODE_BEACON_INTERVAL 1024
1329#define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
1330
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001331static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -07001332{
1333 u16 new_val = 0;
1334 u16 beacon_factor = 0;
1335
1336 beacon_factor =
1337 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
1338 / MAX_UCODE_BEACON_INTERVAL;
1339 new_val = beacon_val / beacon_factor;
1340
1341 return cpu_to_le16(new_val);
1342}
1343
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001344static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001345{
1346 u64 interval_tm_unit;
1347 u64 tsf, result;
1348 unsigned long flags;
1349 struct ieee80211_conf *conf = NULL;
1350 u16 beacon_int = 0;
1351
1352 conf = ieee80211_get_hw_conf(priv->hw);
1353
1354 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler28afaf92008-12-19 10:37:06 +08001355 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
Zhu Yib481de92007-09-25 17:54:57 -07001356 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
1357
Tomas Winkler28afaf92008-12-19 10:37:06 +08001358 tsf = priv->timestamp;
Zhu Yib481de92007-09-25 17:54:57 -07001359
1360 beacon_int = priv->beacon_int;
1361 spin_unlock_irqrestore(&priv->lock, flags);
1362
Johannes Berg05c914f2008-09-11 00:01:58 +02001363 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Zhu Yib481de92007-09-25 17:54:57 -07001364 if (beacon_int == 0) {
1365 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
1366 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
1367 } else {
1368 priv->rxon_timing.beacon_interval =
1369 cpu_to_le16(beacon_int);
1370 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001371 iwl3945_adjust_beacon_interval(
Zhu Yib481de92007-09-25 17:54:57 -07001372 le16_to_cpu(priv->rxon_timing.beacon_interval));
1373 }
1374
1375 priv->rxon_timing.atim_window = 0;
1376 } else {
1377 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001378 iwl3945_adjust_beacon_interval(conf->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -07001379 /* TODO: we need to get atim_window from upper stack
1380 * for now we set to 0 */
1381 priv->rxon_timing.atim_window = 0;
1382 }
1383
1384 interval_tm_unit =
1385 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
1386 result = do_div(tsf, interval_tm_unit);
1387 priv->rxon_timing.beacon_init_val =
1388 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
1389
1390 IWL_DEBUG_ASSOC
1391 ("beacon interval %d beacon timer %d beacon tim %d\n",
1392 le16_to_cpu(priv->rxon_timing.beacon_interval),
1393 le32_to_cpu(priv->rxon_timing.beacon_init_val),
1394 le16_to_cpu(priv->rxon_timing.atim_window));
1395}
1396
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001397static int iwl3945_scan_initiate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001398{
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08001399 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001400 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
1401 return -EIO;
1402 }
1403
1404 if (test_bit(STATUS_SCANNING, &priv->status)) {
1405 IWL_DEBUG_SCAN("Scan already in progress.\n");
1406 return -EAGAIN;
1407 }
1408
1409 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
1410 IWL_DEBUG_SCAN("Scan request while abort pending. "
1411 "Queuing.\n");
1412 return -EAGAIN;
1413 }
1414
1415 IWL_DEBUG_INFO("Starting scan...\n");
Ron Rindjunsky66b50042008-06-25 16:46:31 +08001416 if (priv->cfg->sku & IWL_SKU_G)
1417 priv->scan_bands |= BIT(IEEE80211_BAND_2GHZ);
1418 if (priv->cfg->sku & IWL_SKU_A)
1419 priv->scan_bands |= BIT(IEEE80211_BAND_5GHZ);
Zhu Yib481de92007-09-25 17:54:57 -07001420 set_bit(STATUS_SCANNING, &priv->status);
1421 priv->scan_start = jiffies;
1422 priv->scan_pass_start = priv->scan_start;
1423
1424 queue_work(priv->workqueue, &priv->request_scan);
1425
1426 return 0;
1427}
1428
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001429static int iwl3945_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
Zhu Yib481de92007-09-25 17:54:57 -07001430{
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001431 struct iwl3945_rxon_cmd *rxon = &priv->staging39_rxon;
Zhu Yib481de92007-09-25 17:54:57 -07001432
1433 if (hw_decrypt)
1434 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
1435 else
1436 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
1437
1438 return 0;
1439}
1440
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001441static void iwl3945_set_flags_for_phymode(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01001442 enum ieee80211_band band)
Zhu Yib481de92007-09-25 17:54:57 -07001443{
Johannes Berg8318d782008-01-24 19:38:38 +01001444 if (band == IEEE80211_BAND_5GHZ) {
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001445 priv->staging39_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07001446 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
1447 | RXON_FLG_CCK_MSK);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001448 priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001449 } else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001450 /* Copied from iwl3945_bg_post_associate() */
Zhu Yib481de92007-09-25 17:54:57 -07001451 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001452 priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001453 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001454 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001455
Johannes Berg05c914f2008-09-11 00:01:58 +02001456 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001457 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001458
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001459 priv->staging39_rxon.flags |= RXON_FLG_BAND_24G_MSK;
1460 priv->staging39_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
1461 priv->staging39_rxon.flags &= ~RXON_FLG_CCK_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001462 }
1463}
1464
1465/*
Ian Schram01ebd062007-10-25 17:15:22 +08001466 * initialize rxon structure with default values from eeprom
Zhu Yib481de92007-09-25 17:54:57 -07001467 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001468static void iwl3945_connection_init_rx_config(struct iwl_priv *priv,
Zhu, Yi60294de2008-10-29 14:05:45 -07001469 int mode)
Zhu Yib481de92007-09-25 17:54:57 -07001470{
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001471 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07001472
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001473 memset(&priv->staging39_rxon, 0, sizeof(priv->staging39_rxon));
Zhu Yib481de92007-09-25 17:54:57 -07001474
Zhu, Yi60294de2008-10-29 14:05:45 -07001475 switch (mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02001476 case NL80211_IFTYPE_AP:
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001477 priv->staging39_rxon.dev_type = RXON_DEV_TYPE_AP;
Zhu Yib481de92007-09-25 17:54:57 -07001478 break;
1479
Johannes Berg05c914f2008-09-11 00:01:58 +02001480 case NL80211_IFTYPE_STATION:
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001481 priv->staging39_rxon.dev_type = RXON_DEV_TYPE_ESS;
1482 priv->staging39_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001483 break;
1484
Johannes Berg05c914f2008-09-11 00:01:58 +02001485 case NL80211_IFTYPE_ADHOC:
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001486 priv->staging39_rxon.dev_type = RXON_DEV_TYPE_IBSS;
1487 priv->staging39_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
1488 priv->staging39_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
Zhu Yib481de92007-09-25 17:54:57 -07001489 RXON_FILTER_ACCEPT_GRP_MSK;
1490 break;
1491
Johannes Berg05c914f2008-09-11 00:01:58 +02001492 case NL80211_IFTYPE_MONITOR:
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001493 priv->staging39_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
1494 priv->staging39_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
Zhu Yib481de92007-09-25 17:54:57 -07001495 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
1496 break;
Tomas Winkler69dc5d92008-03-25 16:33:41 -07001497 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08001498 IWL_ERR(priv, "Unsupported interface type %d\n", mode);
Tomas Winkler69dc5d92008-03-25 16:33:41 -07001499 break;
Zhu Yib481de92007-09-25 17:54:57 -07001500 }
1501
1502#if 0
1503 /* TODO: Figure out when short_preamble would be set and cache from
1504 * that */
1505 if (!hw_to_local(priv->hw)->short_preamble)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001506 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001507 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001508 priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001509#endif
1510
Johannes Berg8318d782008-01-24 19:38:38 +01001511 ch_info = iwl3945_get_channel_info(priv, priv->band,
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001512 le16_to_cpu(priv->active39_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -07001513
1514 if (!ch_info)
1515 ch_info = &priv->channel_info[0];
1516
1517 /*
1518 * in some case A channels are all non IBSS
1519 * in this case force B/G channel
1520 */
Zhu, Yi60294de2008-10-29 14:05:45 -07001521 if ((mode == NL80211_IFTYPE_ADHOC) && !(is_channel_ibss(ch_info)))
Zhu Yib481de92007-09-25 17:54:57 -07001522 ch_info = &priv->channel_info[0];
1523
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001524 priv->staging39_rxon.channel = cpu_to_le16(ch_info->channel);
Zhu Yib481de92007-09-25 17:54:57 -07001525 if (is_channel_a_band(ch_info))
Johannes Berg8318d782008-01-24 19:38:38 +01001526 priv->band = IEEE80211_BAND_5GHZ;
Zhu Yib481de92007-09-25 17:54:57 -07001527 else
Johannes Berg8318d782008-01-24 19:38:38 +01001528 priv->band = IEEE80211_BAND_2GHZ;
Zhu Yib481de92007-09-25 17:54:57 -07001529
Johannes Berg8318d782008-01-24 19:38:38 +01001530 iwl3945_set_flags_for_phymode(priv, priv->band);
Zhu Yib481de92007-09-25 17:54:57 -07001531
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001532 priv->staging39_rxon.ofdm_basic_rates =
Zhu Yib481de92007-09-25 17:54:57 -07001533 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001534 priv->staging39_rxon.cck_basic_rates =
Zhu Yib481de92007-09-25 17:54:57 -07001535 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
1536}
1537
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001538static int iwl3945_set_mode(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -07001539{
Johannes Berg05c914f2008-09-11 00:01:58 +02001540 if (mode == NL80211_IFTYPE_ADHOC) {
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001541 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07001542
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001543 ch_info = iwl3945_get_channel_info(priv,
Johannes Berg8318d782008-01-24 19:38:38 +01001544 priv->band,
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001545 le16_to_cpu(priv->staging39_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -07001546
1547 if (!ch_info || !is_channel_ibss(ch_info)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001548 IWL_ERR(priv, "channel %d not IBSS channel\n",
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001549 le16_to_cpu(priv->staging39_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -07001550 return -EINVAL;
1551 }
1552 }
1553
Zhu, Yi60294de2008-10-29 14:05:45 -07001554 iwl3945_connection_init_rx_config(priv, mode);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001555 memcpy(priv->staging39_rxon.node_addr, priv->mac_addr, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07001556
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001557 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001558
Tomas Winklera96a27f2008-10-23 23:48:56 -07001559 /* don't commit rxon if rf-kill is on*/
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08001560 if (!iwl_is_ready_rf(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08001561 return -EAGAIN;
1562
1563 cancel_delayed_work(&priv->scan_check);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08001564 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001565 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +08001566 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
1567 return -EAGAIN;
1568 }
1569
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001570 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001571
1572 return 0;
1573}
1574
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001575static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
Johannes Berge039fa42008-05-15 12:55:29 +02001576 struct ieee80211_tx_info *info,
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08001577 struct iwl_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -07001578 struct sk_buff *skb_frag,
1579 int last_frag)
1580{
Winkler, Tomase52119c2008-12-22 11:31:19 +08001581 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
Ivo van Doorn1c014422008-04-17 19:41:02 +02001582 struct iwl3945_hw_key *keyinfo =
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001583 &priv->stations_39[info->control.hw_key->hw_key_idx].keyinfo;
Zhu Yib481de92007-09-25 17:54:57 -07001584
1585 switch (keyinfo->alg) {
1586 case ALG_CCMP:
Winkler, Tomase52119c2008-12-22 11:31:19 +08001587 tx->sec_ctl = TX_CMD_SEC_CCM;
1588 memcpy(tx->key, keyinfo->key, keyinfo->keylen);
Tomas Winklera96a27f2008-10-23 23:48:56 -07001589 IWL_DEBUG_TX("tx_cmd with AES hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -07001590 break;
1591
1592 case ALG_TKIP:
1593#if 0
Winkler, Tomase52119c2008-12-22 11:31:19 +08001594 tx->sec_ctl = TX_CMD_SEC_TKIP;
Zhu Yib481de92007-09-25 17:54:57 -07001595
1596 if (last_frag)
Winkler, Tomase52119c2008-12-22 11:31:19 +08001597 memcpy(tx->tkip_mic.byte, skb_frag->tail - 8,
Zhu Yib481de92007-09-25 17:54:57 -07001598 8);
1599 else
Winkler, Tomase52119c2008-12-22 11:31:19 +08001600 memset(tx->tkip_mic.byte, 0, 8);
Zhu Yib481de92007-09-25 17:54:57 -07001601#endif
1602 break;
1603
1604 case ALG_WEP:
Winkler, Tomase52119c2008-12-22 11:31:19 +08001605 tx->sec_ctl = TX_CMD_SEC_WEP |
Johannes Berge039fa42008-05-15 12:55:29 +02001606 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
Zhu Yib481de92007-09-25 17:54:57 -07001607
1608 if (keyinfo->keylen == 13)
Winkler, Tomase52119c2008-12-22 11:31:19 +08001609 tx->sec_ctl |= TX_CMD_SEC_KEY128;
Zhu Yib481de92007-09-25 17:54:57 -07001610
Winkler, Tomase52119c2008-12-22 11:31:19 +08001611 memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen);
Zhu Yib481de92007-09-25 17:54:57 -07001612
1613 IWL_DEBUG_TX("Configuring packet for WEP encryption "
Johannes Berge039fa42008-05-15 12:55:29 +02001614 "with key %d\n", info->control.hw_key->hw_key_idx);
Zhu Yib481de92007-09-25 17:54:57 -07001615 break;
1616
Zhu Yib481de92007-09-25 17:54:57 -07001617 default:
Tomas Winkler978785a2008-12-19 10:37:31 +08001618 IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg);
Zhu Yib481de92007-09-25 17:54:57 -07001619 break;
1620 }
1621}
1622
1623/*
1624 * handle build REPLY_TX command notification.
1625 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001626static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08001627 struct iwl_cmd *cmd,
Johannes Berge039fa42008-05-15 12:55:29 +02001628 struct ieee80211_tx_info *info,
Winkler, Tomase52119c2008-12-22 11:31:19 +08001629 struct ieee80211_hdr *hdr, u8 std_id)
Zhu Yib481de92007-09-25 17:54:57 -07001630{
Winkler, Tomase52119c2008-12-22 11:31:19 +08001631 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
1632 __le32 tx_flags = tx->tx_flags;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001633 __le16 fc = hdr->frame_control;
Johannes Berge6a98542008-10-21 12:40:02 +02001634 u8 rc_flags = info->control.rates[0].flags;
Zhu Yib481de92007-09-25 17:54:57 -07001635
Winkler, Tomase52119c2008-12-22 11:31:19 +08001636 tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Johannes Berge039fa42008-05-15 12:55:29 +02001637 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
Zhu Yib481de92007-09-25 17:54:57 -07001638 tx_flags |= TX_CMD_FLG_ACK_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001639 if (ieee80211_is_mgmt(fc))
Zhu Yib481de92007-09-25 17:54:57 -07001640 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001641 if (ieee80211_is_probe_resp(fc) &&
Zhu Yib481de92007-09-25 17:54:57 -07001642 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
1643 tx_flags |= TX_CMD_FLG_TSF_MSK;
1644 } else {
1645 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
1646 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
1647 }
1648
Winkler, Tomase52119c2008-12-22 11:31:19 +08001649 tx->sta_id = std_id;
Harvey Harrison8b7b1e02008-06-11 14:21:56 -07001650 if (ieee80211_has_morefrags(fc))
Zhu Yib481de92007-09-25 17:54:57 -07001651 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
1652
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001653 if (ieee80211_is_data_qos(fc)) {
1654 u8 *qc = ieee80211_get_qos_ctl(hdr);
Winkler, Tomase52119c2008-12-22 11:31:19 +08001655 tx->tid_tspec = qc[0] & 0xf;
Zhu Yib481de92007-09-25 17:54:57 -07001656 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +08001657 } else {
Zhu Yib481de92007-09-25 17:54:57 -07001658 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +08001659 }
Zhu Yib481de92007-09-25 17:54:57 -07001660
Johannes Berge6a98542008-10-21 12:40:02 +02001661 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
Zhu Yib481de92007-09-25 17:54:57 -07001662 tx_flags |= TX_CMD_FLG_RTS_MSK;
1663 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
Johannes Berge6a98542008-10-21 12:40:02 +02001664 } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
Zhu Yib481de92007-09-25 17:54:57 -07001665 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
1666 tx_flags |= TX_CMD_FLG_CTS_MSK;
1667 }
1668
1669 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
1670 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
1671
1672 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001673 if (ieee80211_is_mgmt(fc)) {
1674 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
Winkler, Tomase52119c2008-12-22 11:31:19 +08001675 tx->timeout.pm_frame_timeout = cpu_to_le16(3);
Zhu Yib481de92007-09-25 17:54:57 -07001676 else
Winkler, Tomase52119c2008-12-22 11:31:19 +08001677 tx->timeout.pm_frame_timeout = cpu_to_le16(2);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07001678 } else {
Winkler, Tomase52119c2008-12-22 11:31:19 +08001679 tx->timeout.pm_frame_timeout = 0;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07001680#ifdef CONFIG_IWL3945_LEDS
1681 priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
1682#endif
1683 }
Zhu Yib481de92007-09-25 17:54:57 -07001684
Winkler, Tomase52119c2008-12-22 11:31:19 +08001685 tx->driver_txop = 0;
1686 tx->tx_flags = tx_flags;
1687 tx->next_frame_len = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001688}
1689
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001690/**
1691 * iwl3945_get_sta_id - Find station's index within station table
1692 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001693static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
Zhu Yib481de92007-09-25 17:54:57 -07001694{
1695 int sta_id;
1696 u16 fc = le16_to_cpu(hdr->frame_control);
1697
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001698 /* If this frame is broadcast or management, use broadcast station id */
Zhu Yib481de92007-09-25 17:54:57 -07001699 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
1700 is_multicast_ether_addr(hdr->addr1))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001701 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07001702
1703 switch (priv->iw_mode) {
1704
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001705 /* If we are a client station in a BSS network, use the special
1706 * AP station entry (that's the only station we communicate with) */
Johannes Berg05c914f2008-09-11 00:01:58 +02001707 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -07001708 return IWL_AP_ID;
1709
1710 /* If we are an AP, then find the station, or use BCAST */
Johannes Berg05c914f2008-09-11 00:01:58 +02001711 case NL80211_IFTYPE_AP:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001712 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07001713 if (sta_id != IWL_INVALID_STATION)
1714 return sta_id;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001715 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07001716
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001717 /* If this frame is going out to an IBSS network, find the station,
1718 * or create a new station table entry */
Johannes Berg05c914f2008-09-11 00:01:58 +02001719 case NL80211_IFTYPE_ADHOC: {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001720 /* Create new station table entry */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001721 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07001722 if (sta_id != IWL_INVALID_STATION)
1723 return sta_id;
1724
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001725 sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -07001726
1727 if (sta_id != IWL_INVALID_STATION)
1728 return sta_id;
1729
Johannes Berge1749612008-10-27 15:59:26 -07001730 IWL_DEBUG_DROP("Station %pM not in station map. "
Zhu Yib481de92007-09-25 17:54:57 -07001731 "Defaulting to broadcast...\n",
Johannes Berge1749612008-10-27 15:59:26 -07001732 hdr->addr1);
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08001733 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001734 return priv->hw_params.bcast_sta_id;
Joe Perches0795af52007-10-03 17:59:30 -07001735 }
Stefanik Gábor914233d2008-06-30 17:23:30 +08001736 /* If we are in monitor mode, use BCAST. This is required for
1737 * packet injection. */
Johannes Berg05c914f2008-09-11 00:01:58 +02001738 case NL80211_IFTYPE_MONITOR:
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001739 return priv->hw_params.bcast_sta_id;
Stefanik Gábor914233d2008-06-30 17:23:30 +08001740
Zhu Yib481de92007-09-25 17:54:57 -07001741 default:
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001742 IWL_WARN(priv, "Unknown mode of operation: %d\n",
1743 priv->iw_mode);
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001744 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07001745 }
1746}
1747
1748/*
1749 * start REPLY_TX command process
1750 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001751static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07001752{
1753 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berge039fa42008-05-15 12:55:29 +02001754 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Winkler, Tomase52119c2008-12-22 11:31:19 +08001755 struct iwl3945_tx_cmd *tx;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001756 struct iwl_tx_queue *txq = NULL;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001757 struct iwl_queue *q = NULL;
Winkler, Tomase52119c2008-12-22 11:31:19 +08001758 struct iwl_cmd *out_cmd = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001759 dma_addr_t phys_addr;
1760 dma_addr_t txcmd_phys;
Winkler, Tomase52119c2008-12-22 11:31:19 +08001761 int txq_id = skb_get_queue_mapping(skb);
Tomas Winkler54dbb522008-05-15 13:54:06 +08001762 u16 len, idx, len_org, hdr_len;
1763 u8 id;
1764 u8 unicast;
Zhu Yib481de92007-09-25 17:54:57 -07001765 u8 sta_id;
Tomas Winkler54dbb522008-05-15 13:54:06 +08001766 u8 tid = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001767 u16 seq_number = 0;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001768 __le16 fc;
Zhu Yib481de92007-09-25 17:54:57 -07001769 u8 wait_write_ptr = 0;
Tomas Winkler54dbb522008-05-15 13:54:06 +08001770 u8 *qc = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001771 unsigned long flags;
1772 int rc;
1773
1774 spin_lock_irqsave(&priv->lock, flags);
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08001775 if (iwl_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001776 IWL_DEBUG_DROP("Dropping - RF KILL\n");
1777 goto drop_unlock;
1778 }
1779
Johannes Berge039fa42008-05-15 12:55:29 +02001780 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001781 IWL_ERR(priv, "ERROR: No TX rate available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001782 goto drop_unlock;
1783 }
1784
1785 unicast = !is_multicast_ether_addr(hdr->addr1);
1786 id = 0;
1787
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001788 fc = hdr->frame_control;
Zhu Yib481de92007-09-25 17:54:57 -07001789
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001790#ifdef CONFIG_IWL3945_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001791 if (ieee80211_is_auth(fc))
1792 IWL_DEBUG_TX("Sending AUTH frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001793 else if (ieee80211_is_assoc_req(fc))
Zhu Yib481de92007-09-25 17:54:57 -07001794 IWL_DEBUG_TX("Sending ASSOC frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001795 else if (ieee80211_is_reassoc_req(fc))
Zhu Yib481de92007-09-25 17:54:57 -07001796 IWL_DEBUG_TX("Sending REASSOC frame\n");
1797#endif
1798
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08001799 /* drop all data frame if we are not associated */
Stefanik Gábor914233d2008-06-30 17:23:30 +08001800 if (ieee80211_is_data(fc) &&
Johannes Berg05c914f2008-09-11 00:01:58 +02001801 (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */
Stefanik Gábor914233d2008-06-30 17:23:30 +08001802 (!iwl3945_is_associated(priv) ||
Johannes Berg05c914f2008-09-11 00:01:58 +02001803 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001804 IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n");
Zhu Yib481de92007-09-25 17:54:57 -07001805 goto drop_unlock;
1806 }
1807
1808 spin_unlock_irqrestore(&priv->lock, flags);
1809
Harvey Harrison7294ec92008-07-15 18:43:59 -07001810 hdr_len = ieee80211_hdrlen(fc);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001811
1812 /* Find (or create) index into station table for destination station */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001813 sta_id = iwl3945_get_sta_id(priv, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001814 if (sta_id == IWL_INVALID_STATION) {
Johannes Berge1749612008-10-27 15:59:26 -07001815 IWL_DEBUG_DROP("Dropping - INVALID STATION: %pM\n",
1816 hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07001817 goto drop;
1818 }
1819
1820 IWL_DEBUG_RATE("station Id %d\n", sta_id);
1821
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001822 if (ieee80211_is_data_qos(fc)) {
1823 qc = ieee80211_get_qos_ctl(hdr);
Harvey Harrison7294ec92008-07-15 18:43:59 -07001824 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001825 seq_number = priv->stations_39[sta_id].tid[tid].seq_number &
Zhu Yib481de92007-09-25 17:54:57 -07001826 IEEE80211_SCTL_SEQ;
1827 hdr->seq_ctrl = cpu_to_le16(seq_number) |
1828 (hdr->seq_ctrl &
1829 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG));
1830 seq_number += 0x10;
1831 }
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001832
1833 /* Descriptor for chosen Tx queue */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001834 txq = &priv->txq[txq_id];
Zhu Yib481de92007-09-25 17:54:57 -07001835 q = &txq->q;
1836
1837 spin_lock_irqsave(&priv->lock, flags);
1838
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001839 idx = get_cmd_index(q, q->write_ptr, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001840
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001841 /* Set up driver data for this TFD */
Winkler, Tomasdbb66542008-12-22 11:31:14 +08001842 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001843 txq->txb[q->write_ptr].skb[0] = skb;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001844
1845 /* Init first empty entry in queue's array of Tx/cmd buffers */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001846 out_cmd = txq->cmd[idx];
Winkler, Tomase52119c2008-12-22 11:31:19 +08001847 tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
Zhu Yib481de92007-09-25 17:54:57 -07001848 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
Winkler, Tomase52119c2008-12-22 11:31:19 +08001849 memset(tx, 0, sizeof(*tx));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001850
1851 /*
1852 * Set up the Tx-command (not MAC!) header.
1853 * Store the chosen Tx queue and TFD index within the sequence field;
1854 * after Tx, uCode's Tx response will return this value so driver can
1855 * locate the frame within the tx queue and do post-tx processing.
1856 */
Zhu Yib481de92007-09-25 17:54:57 -07001857 out_cmd->hdr.cmd = REPLY_TX;
1858 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001859 INDEX_TO_SEQ(q->write_ptr)));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001860
1861 /* Copy MAC header from skb into command buffer */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001862 memcpy(tx->hdr, hdr, hdr_len);
Zhu Yib481de92007-09-25 17:54:57 -07001863
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001864 /*
1865 * Use the first empty entry in this queue's command buffer array
1866 * to contain the Tx command and MAC header concatenated together
1867 * (payload data will be in another buffer).
1868 * Size of this varies, due to varying MAC header length.
1869 * If end is not dword aligned, we'll have 2 extra bytes at the end
1870 * of the MAC header (device reads on dword boundaries).
1871 * We'll tell device about this padding later.
1872 */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001873 len = sizeof(struct iwl3945_tx_cmd) +
Tomas Winkler4c897252008-12-19 10:37:05 +08001874 sizeof(struct iwl_cmd_header) + hdr_len;
Zhu Yib481de92007-09-25 17:54:57 -07001875
1876 len_org = len;
1877 len = (len + 3) & ~3;
1878
1879 if (len_org != len)
1880 len_org = 1;
1881 else
1882 len_org = 0;
1883
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001884 /* Physical address of this Tx command's header (not MAC header!),
1885 * within command buffer array. */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001886 txcmd_phys = pci_map_single(priv->pci_dev,
1887 out_cmd, sizeof(struct iwl_cmd),
1888 PCI_DMA_TODEVICE);
1889 pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys);
1890 pci_unmap_len_set(&out_cmd->meta, len, sizeof(struct iwl_cmd));
1891 /* Add buffer containing Tx command and MAC(!) header to TFD's
1892 * first entry */
1893 txcmd_phys += offsetof(struct iwl_cmd, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001894
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001895 /* Add buffer containing Tx command and MAC(!) header to TFD's
1896 * first entry */
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001897 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1898 txcmd_phys, len, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001899
Johannes Bergd0f09802008-07-29 11:32:07 +02001900 if (info->control.hw_key)
Johannes Berge039fa42008-05-15 12:55:29 +02001901 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001902
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001903 /* Set up TFD's 2nd entry to point directly to remainder of skb,
1904 * if any (802.11 null frames have no payload). */
Zhu Yib481de92007-09-25 17:54:57 -07001905 len = skb->len - hdr_len;
1906 if (len) {
1907 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
1908 len, PCI_DMA_TODEVICE);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001909 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1910 phys_addr, len,
1911 0, U32_PAD(len));
Zhu Yib481de92007-09-25 17:54:57 -07001912 }
1913
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001914 /* Total # bytes to be transmitted */
Zhu Yib481de92007-09-25 17:54:57 -07001915 len = (u16)skb->len;
Winkler, Tomase52119c2008-12-22 11:31:19 +08001916 tx->len = cpu_to_le16(len);
Zhu Yib481de92007-09-25 17:54:57 -07001917
1918 /* TODO need this for burst mode later on */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001919 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001920
1921 /* set is_hcca to 0; it probably will never be implemented */
Johannes Berge039fa42008-05-15 12:55:29 +02001922 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001923
Winkler, Tomase52119c2008-12-22 11:31:19 +08001924 tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
1925 tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001926
Harvey Harrison8b7b1e02008-06-11 14:21:56 -07001927 if (!ieee80211_has_morefrags(hdr->frame_control)) {
Zhu Yib481de92007-09-25 17:54:57 -07001928 txq->need_update = 1;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001929 if (qc)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001930 priv->stations_39[sta_id].tid[tid].seq_number = seq_number;
Zhu Yib481de92007-09-25 17:54:57 -07001931 } else {
1932 wait_write_ptr = 1;
1933 txq->need_update = 0;
1934 }
1935
Winkler, Tomase52119c2008-12-22 11:31:19 +08001936 iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx));
Zhu Yib481de92007-09-25 17:54:57 -07001937
Winkler, Tomase52119c2008-12-22 11:31:19 +08001938 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr,
Harvey Harrison7294ec92008-07-15 18:43:59 -07001939 ieee80211_hdrlen(fc));
Zhu Yib481de92007-09-25 17:54:57 -07001940
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001941 /* Tell device the write index *just past* this latest filled TFD */
Tomas Winklerc54b6792008-03-06 17:36:53 -08001942 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001943 rc = iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001944 spin_unlock_irqrestore(&priv->lock, flags);
1945
1946 if (rc)
1947 return rc;
1948
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001949 if ((iwl_queue_space(q) < q->high_mark)
Zhu Yib481de92007-09-25 17:54:57 -07001950 && priv->mac80211_registered) {
1951 if (wait_write_ptr) {
1952 spin_lock_irqsave(&priv->lock, flags);
1953 txq->need_update = 1;
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001954 iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001955 spin_unlock_irqrestore(&priv->lock, flags);
1956 }
1957
Johannes Berge2530082008-05-17 00:57:14 +02001958 ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb));
Zhu Yib481de92007-09-25 17:54:57 -07001959 }
1960
1961 return 0;
1962
1963drop_unlock:
1964 spin_unlock_irqrestore(&priv->lock, flags);
1965drop:
1966 return -1;
1967}
1968
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001969static void iwl3945_set_rate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001970{
Johannes Berg8318d782008-01-24 19:38:38 +01001971 const struct ieee80211_supported_band *sband = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001972 struct ieee80211_rate *rate;
1973 int i;
1974
Kolekar, Abhijeetcbba18c2008-12-19 10:37:42 +08001975 sband = iwl_get_hw_mode(priv, priv->band);
Johannes Berg8318d782008-01-24 19:38:38 +01001976 if (!sband) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001977 IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
Saleem Abdulrasoolc4ba9622007-11-18 23:59:08 -08001978 return;
1979 }
Zhu Yib481de92007-09-25 17:54:57 -07001980
1981 priv->active_rate = 0;
1982 priv->active_rate_basic = 0;
1983
Johannes Berg8318d782008-01-24 19:38:38 +01001984 IWL_DEBUG_RATE("Setting rates for %s GHz\n",
1985 sband->band == IEEE80211_BAND_2GHZ ? "2.4" : "5");
Zhu Yib481de92007-09-25 17:54:57 -07001986
Johannes Berg8318d782008-01-24 19:38:38 +01001987 for (i = 0; i < sband->n_bitrates; i++) {
1988 rate = &sband->bitrates[i];
1989 if ((rate->hw_value < IWL_RATE_COUNT) &&
1990 !(rate->flags & IEEE80211_CHAN_DISABLED)) {
1991 IWL_DEBUG_RATE("Adding rate index %d (plcp %d)\n",
1992 rate->hw_value, iwl3945_rates[rate->hw_value].plcp);
1993 priv->active_rate |= (1 << rate->hw_value);
1994 }
Zhu Yib481de92007-09-25 17:54:57 -07001995 }
1996
1997 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
1998 priv->active_rate, priv->active_rate_basic);
1999
2000 /*
2001 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
2002 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
2003 * OFDM
2004 */
2005 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08002006 priv->staging39_rxon.cck_basic_rates =
Zhu Yib481de92007-09-25 17:54:57 -07002007 ((priv->active_rate_basic &
2008 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
2009 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08002010 priv->staging39_rxon.cck_basic_rates =
Zhu Yib481de92007-09-25 17:54:57 -07002011 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
2012
2013 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08002014 priv->staging39_rxon.ofdm_basic_rates =
Zhu Yib481de92007-09-25 17:54:57 -07002015 ((priv->active_rate_basic &
2016 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
2017 IWL_FIRST_OFDM_RATE) & 0xFF;
2018 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08002019 priv->staging39_rxon.ofdm_basic_rates =
Zhu Yib481de92007-09-25 17:54:57 -07002020 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
2021}
2022
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002023static void iwl3945_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
Zhu Yib481de92007-09-25 17:54:57 -07002024{
2025 unsigned long flags;
2026
2027 if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
2028 return;
2029
2030 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
2031 disable_radio ? "OFF" : "ON");
2032
2033 if (disable_radio) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08002034 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002035 /* FIXME: This is a workaround for AP */
Johannes Berg05c914f2008-09-11 00:01:58 +02002036 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07002037 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002038 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07002039 CSR_UCODE_SW_BIT_RFKILL);
2040 spin_unlock_irqrestore(&priv->lock, flags);
Samuel Ortizc4962942008-12-22 11:31:18 +08002041 iwl_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002042 set_bit(STATUS_RF_KILL_SW, &priv->status);
2043 }
2044 return;
2045 }
2046
2047 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002048 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07002049
2050 clear_bit(STATUS_RF_KILL_SW, &priv->status);
2051 spin_unlock_irqrestore(&priv->lock, flags);
2052
2053 /* wake up ucode */
2054 msleep(10);
2055
2056 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002057 iwl_read32(priv, CSR_UCODE_DRV_GP1);
2058 if (!iwl_grab_nic_access(priv))
2059 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002060 spin_unlock_irqrestore(&priv->lock, flags);
2061
2062 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
2063 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2064 "disabled by HW switch\n");
2065 return;
2066 }
2067
Zhu Yi808e72a2008-06-12 09:47:17 +08002068 if (priv->is_open)
2069 queue_work(priv->workqueue, &priv->restart);
Zhu Yib481de92007-09-25 17:54:57 -07002070 return;
2071}
2072
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002073void iwl3945_set_decrypted_flag(struct iwl_priv *priv, struct sk_buff *skb,
Zhu Yib481de92007-09-25 17:54:57 -07002074 u32 decrypt_res, struct ieee80211_rx_status *stats)
2075{
2076 u16 fc =
2077 le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control);
2078
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08002079 if (priv->active39_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
Zhu Yib481de92007-09-25 17:54:57 -07002080 return;
2081
2082 if (!(fc & IEEE80211_FCTL_PROTECTED))
2083 return;
2084
2085 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
2086 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
2087 case RX_RES_STATUS_SEC_TYPE_TKIP:
2088 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2089 RX_RES_STATUS_BAD_ICV_MIC)
2090 stats->flag |= RX_FLAG_MMIC_ERROR;
2091 case RX_RES_STATUS_SEC_TYPE_WEP:
2092 case RX_RES_STATUS_SEC_TYPE_CCMP:
2093 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2094 RX_RES_STATUS_DECRYPT_OK) {
2095 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
2096 stats->flag |= RX_FLAG_DECRYPTED;
2097 }
2098 break;
2099
2100 default:
2101 break;
2102 }
2103}
2104
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002105#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07002106
2107#include "iwl-spectrum.h"
2108
2109#define BEACON_TIME_MASK_LOW 0x00FFFFFF
2110#define BEACON_TIME_MASK_HIGH 0xFF000000
2111#define TIME_UNIT 1024
2112
2113/*
2114 * extended beacon time format
2115 * time in usec will be changed into a 32-bit value in 8:24 format
2116 * the high 1 byte is the beacon counts
2117 * the lower 3 bytes is the time in usec within one beacon interval
2118 */
2119
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002120static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07002121{
2122 u32 quot;
2123 u32 rem;
2124 u32 interval = beacon_interval * 1024;
2125
2126 if (!interval || !usec)
2127 return 0;
2128
2129 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
2130 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
2131
2132 return (quot << 24) + rem;
2133}
2134
2135/* base is usually what we get from ucode with each received frame,
2136 * the same as HW timer counter counting down
2137 */
2138
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002139static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07002140{
2141 u32 base_low = base & BEACON_TIME_MASK_LOW;
2142 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
2143 u32 interval = beacon_interval * TIME_UNIT;
2144 u32 res = (base & BEACON_TIME_MASK_HIGH) +
2145 (addon & BEACON_TIME_MASK_HIGH);
2146
2147 if (base_low > addon_low)
2148 res += base_low - addon_low;
2149 else if (base_low < addon_low) {
2150 res += interval + base_low - addon_low;
2151 res += (1 << 24);
2152 } else
2153 res += (1 << 24);
2154
2155 return cpu_to_le32(res);
2156}
2157
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002158static int iwl3945_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002159 struct ieee80211_measurement_params *params,
2160 u8 type)
2161{
Tomas Winkler600c0e12008-12-19 10:37:04 +08002162 struct iwl_spectrum_cmd spectrum;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002163 struct iwl_rx_packet *res;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08002164 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07002165 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
2166 .data = (void *)&spectrum,
2167 .meta.flags = CMD_WANT_SKB,
2168 };
2169 u32 add_time = le64_to_cpu(params->start_time);
2170 int rc;
2171 int spectrum_resp_status;
2172 int duration = le16_to_cpu(params->duration);
2173
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002174 if (iwl3945_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002175 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002176 iwl3945_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -07002177 le64_to_cpu(params->start_time) - priv->last_tsf,
2178 le16_to_cpu(priv->rxon_timing.beacon_interval));
2179
2180 memset(&spectrum, 0, sizeof(spectrum));
2181
2182 spectrum.channel_count = cpu_to_le16(1);
2183 spectrum.flags =
2184 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
2185 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
2186 cmd.len = sizeof(spectrum);
2187 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
2188
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002189 if (iwl3945_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002190 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002191 iwl3945_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -07002192 add_time,
2193 le16_to_cpu(priv->rxon_timing.beacon_interval));
2194 else
2195 spectrum.start_time = 0;
2196
2197 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
2198 spectrum.channels[0].channel = params->channel;
2199 spectrum.channels[0].type = type;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08002200 if (priv->active39_rxon.flags & RXON_FLG_BAND_24G_MSK)
Zhu Yib481de92007-09-25 17:54:57 -07002201 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
2202 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
2203
Samuel Ortiz518099a2009-01-19 15:30:27 -08002204 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07002205 if (rc)
2206 return rc;
2207
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002208 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002209 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002210 IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -07002211 rc = -EIO;
2212 }
2213
2214 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
2215 switch (spectrum_resp_status) {
2216 case 0: /* Command will be handled */
2217 if (res->u.spectrum.id != 0xff) {
Ian Schrambc434dd2007-10-25 17:15:29 +08002218 IWL_DEBUG_INFO("Replaced existing measurement: %d\n",
2219 res->u.spectrum.id);
Zhu Yib481de92007-09-25 17:54:57 -07002220 priv->measurement_status &= ~MEASUREMENT_READY;
2221 }
2222 priv->measurement_status |= MEASUREMENT_ACTIVE;
2223 rc = 0;
2224 break;
2225
2226 case 1: /* Command will not be handled */
2227 rc = -EAGAIN;
2228 break;
2229 }
2230
2231 dev_kfree_skb_any(cmd.meta.u.skb);
2232
2233 return rc;
2234}
2235#endif
2236
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002237static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002238 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002239{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002240 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
2241 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -07002242 struct delayed_work *pwork;
2243
2244 palive = &pkt->u.alive_frame;
2245
2246 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
2247 "0x%01X 0x%01X\n",
2248 palive->is_valid, palive->ver_type,
2249 palive->ver_subtype);
2250
2251 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
2252 IWL_DEBUG_INFO("Initialization Alive received.\n");
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002253 memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
2254 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07002255 pwork = &priv->init_alive_start;
2256 } else {
2257 IWL_DEBUG_INFO("Runtime Alive received.\n");
2258 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002259 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07002260 pwork = &priv->alive_start;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002261 iwl3945_disable_events(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002262 }
2263
2264 /* We delay the ALIVE response by 5ms to
2265 * give the HW RF Kill time to activate... */
2266 if (palive->is_valid == UCODE_VALID_OK)
2267 queue_delayed_work(priv->workqueue, pwork,
2268 msecs_to_jiffies(5));
2269 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002270 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002271}
2272
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002273static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002274 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002275{
Helmut Schaac7e035a2009-01-19 13:02:15 +01002276#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002277 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Helmut Schaac7e035a2009-01-19 13:02:15 +01002278#endif
Zhu Yib481de92007-09-25 17:54:57 -07002279
2280 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
2281 return;
2282}
2283
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002284static void iwl3945_rx_reply_error(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002285 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002286{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002287 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002288
Winkler, Tomas15b16872008-12-19 10:37:33 +08002289 IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
Zhu Yib481de92007-09-25 17:54:57 -07002290 "seq 0x%04X ser 0x%08X\n",
2291 le32_to_cpu(pkt->u.err_resp.error_type),
2292 get_cmd_string(pkt->u.err_resp.cmd_id),
2293 pkt->u.err_resp.cmd_id,
2294 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
2295 le32_to_cpu(pkt->u.err_resp.error_info));
2296}
2297
2298#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
2299
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002300static void iwl3945_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002301{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002302 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08002303 struct iwl3945_rxon_cmd *rxon = (void *)&priv->active39_rxon;
Tomas Winkler600c0e12008-12-19 10:37:04 +08002304 struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
Zhu Yib481de92007-09-25 17:54:57 -07002305 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
2306 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
2307 rxon->channel = csa->channel;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08002308 priv->staging39_rxon.channel = csa->channel;
Zhu Yib481de92007-09-25 17:54:57 -07002309}
2310
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002311static void iwl3945_rx_spectrum_measure_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002312 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002313{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002314#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002315 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler600c0e12008-12-19 10:37:04 +08002316 struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif);
Zhu Yib481de92007-09-25 17:54:57 -07002317
2318 if (!report->state) {
2319 IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO,
2320 "Spectrum Measure Notification: Start\n");
2321 return;
2322 }
2323
2324 memcpy(&priv->measure_report, report, sizeof(*report));
2325 priv->measurement_status |= MEASUREMENT_READY;
2326#endif
2327}
2328
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002329static void iwl3945_rx_pm_sleep_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002330 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002331{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002332#ifdef CONFIG_IWL3945_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002333 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler600c0e12008-12-19 10:37:04 +08002334 struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
Zhu Yib481de92007-09-25 17:54:57 -07002335 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
2336 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
2337#endif
2338}
2339
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002340static void iwl3945_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002341 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002342{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002343 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002344 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
2345 "notification for %s:\n",
2346 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002347 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw,
2348 le32_to_cpu(pkt->len));
Zhu Yib481de92007-09-25 17:54:57 -07002349}
2350
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002351static void iwl3945_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07002352{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002353 struct iwl_priv *priv =
2354 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07002355 struct sk_buff *beacon;
2356
2357 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02002358 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07002359
2360 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002361 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07002362 return;
2363 }
2364
2365 mutex_lock(&priv->mutex);
2366 /* new beacon skb is allocated every time; dispose previous.*/
2367 if (priv->ibss_beacon)
2368 dev_kfree_skb(priv->ibss_beacon);
2369
2370 priv->ibss_beacon = beacon;
2371 mutex_unlock(&priv->mutex);
2372
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002373 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002374}
2375
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002376static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002377 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002378{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002379#ifdef CONFIG_IWL3945_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002380 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002381 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
Zhu Yib481de92007-09-25 17:54:57 -07002382 u8 rate = beacon->beacon_notify_hdr.rate;
2383
2384 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
2385 "tsf %d %d rate %d\n",
2386 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
2387 beacon->beacon_notify_hdr.failure_frame,
2388 le32_to_cpu(beacon->ibss_mgr_status),
2389 le32_to_cpu(beacon->high_tsf),
2390 le32_to_cpu(beacon->low_tsf), rate);
2391#endif
2392
Johannes Berg05c914f2008-09-11 00:01:58 +02002393 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -07002394 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
2395 queue_work(priv->workqueue, &priv->beacon_update);
2396}
2397
2398/* Service response to REPLY_SCAN_CMD (0x80) */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002399static void iwl3945_rx_reply_scan(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002400 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002401{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002402#ifdef CONFIG_IWL3945_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002403 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler4c897252008-12-19 10:37:05 +08002404 struct iwl_scanreq_notification *notif =
2405 (struct iwl_scanreq_notification *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07002406
2407 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status);
2408#endif
2409}
2410
2411/* Service SCAN_START_NOTIFICATION (0x82) */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002412static void iwl3945_rx_scan_start_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002413 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002414{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002415 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler4c897252008-12-19 10:37:05 +08002416 struct iwl_scanstart_notification *notif =
2417 (struct iwl_scanstart_notification *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07002418 priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
2419 IWL_DEBUG_SCAN("Scan start: "
2420 "%d [802.11%s] "
2421 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
2422 notif->channel,
2423 notif->band ? "bg" : "a",
2424 notif->tsf_high,
2425 notif->tsf_low, notif->status, notif->beacon_timer);
2426}
2427
2428/* Service SCAN_RESULTS_NOTIFICATION (0x83) */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002429static void iwl3945_rx_scan_results_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002430 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002431{
Helmut Schaac7e035a2009-01-19 13:02:15 +01002432#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002433 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler4c897252008-12-19 10:37:05 +08002434 struct iwl_scanresults_notification *notif =
2435 (struct iwl_scanresults_notification *)pkt->u.raw;
Helmut Schaac7e035a2009-01-19 13:02:15 +01002436#endif
Zhu Yib481de92007-09-25 17:54:57 -07002437
2438 IWL_DEBUG_SCAN("Scan ch.res: "
2439 "%d [802.11%s] "
2440 "(TSF: 0x%08X:%08X) - %d "
2441 "elapsed=%lu usec (%dms since last)\n",
2442 notif->channel,
2443 notif->band ? "bg" : "a",
2444 le32_to_cpu(notif->tsf_high),
2445 le32_to_cpu(notif->tsf_low),
2446 le32_to_cpu(notif->statistics[0]),
2447 le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
2448 jiffies_to_msecs(elapsed_jiffies
2449 (priv->last_scan_jiffies, jiffies)));
2450
2451 priv->last_scan_jiffies = jiffies;
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002452 priv->next_scan_jiffies = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002453}
2454
2455/* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002456static void iwl3945_rx_scan_complete_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002457 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002458{
Helmut Schaac7e035a2009-01-19 13:02:15 +01002459#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002460 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler4c897252008-12-19 10:37:05 +08002461 struct iwl_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
Helmut Schaac7e035a2009-01-19 13:02:15 +01002462#endif
Zhu Yib481de92007-09-25 17:54:57 -07002463
2464 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
2465 scan_notif->scanned_channels,
2466 scan_notif->tsf_low,
2467 scan_notif->tsf_high, scan_notif->status);
2468
2469 /* The HW is no longer scanning */
2470 clear_bit(STATUS_SCAN_HW, &priv->status);
2471
2472 /* The scan completion notification came in, so kill that timer... */
2473 cancel_delayed_work(&priv->scan_check);
2474
2475 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
Ron Rindjunsky66b50042008-06-25 16:46:31 +08002476 (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) ?
2477 "2.4" : "5.2",
Zhu Yib481de92007-09-25 17:54:57 -07002478 jiffies_to_msecs(elapsed_jiffies
2479 (priv->scan_pass_start, jiffies)));
2480
Ron Rindjunsky66b50042008-06-25 16:46:31 +08002481 /* Remove this scanned band from the list of pending
2482 * bands to scan, band G precedes A in order of scanning
2483 * as seen in iwl3945_bg_request_scan */
2484 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ))
2485 priv->scan_bands &= ~BIT(IEEE80211_BAND_2GHZ);
2486 else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ))
2487 priv->scan_bands &= ~BIT(IEEE80211_BAND_5GHZ);
Zhu Yib481de92007-09-25 17:54:57 -07002488
2489 /* If a request to abort was given, or the scan did not succeed
2490 * then we reset the scan state machine and terminate,
2491 * re-queuing another scan if one has been requested */
2492 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
2493 IWL_DEBUG_INFO("Aborted scan completed.\n");
2494 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
2495 } else {
2496 /* If there are more bands on this scan pass reschedule */
2497 if (priv->scan_bands > 0)
2498 goto reschedule;
2499 }
2500
2501 priv->last_scan_jiffies = jiffies;
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002502 priv->next_scan_jiffies = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002503 IWL_DEBUG_INFO("Setting scan to off\n");
2504
2505 clear_bit(STATUS_SCANNING, &priv->status);
2506
2507 IWL_DEBUG_INFO("Scan took %dms\n",
2508 jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
2509
2510 queue_work(priv->workqueue, &priv->scan_completed);
2511
2512 return;
2513
2514reschedule:
2515 priv->scan_pass_start = jiffies;
2516 queue_work(priv->workqueue, &priv->request_scan);
2517}
2518
2519/* Handle notification from uCode that card's power state is changing
2520 * due to software, hardware, or critical temperature RFKILL */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002521static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002522 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002523{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002524 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002525 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
2526 unsigned long status = priv->status;
2527
2528 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
2529 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
2530 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
2531
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002532 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07002533 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2534
2535 if (flags & HW_CARD_DISABLED)
2536 set_bit(STATUS_RF_KILL_HW, &priv->status);
2537 else
2538 clear_bit(STATUS_RF_KILL_HW, &priv->status);
2539
2540
2541 if (flags & SW_CARD_DISABLED)
2542 set_bit(STATUS_RF_KILL_SW, &priv->status);
2543 else
2544 clear_bit(STATUS_RF_KILL_SW, &priv->status);
2545
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08002546 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002547
2548 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
2549 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
2550 (test_bit(STATUS_RF_KILL_SW, &status) !=
2551 test_bit(STATUS_RF_KILL_SW, &priv->status)))
2552 queue_work(priv->workqueue, &priv->rf_kill);
2553 else
2554 wake_up_interruptible(&priv->wait_command_queue);
2555}
2556
2557/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002558 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07002559 *
2560 * Setup the RX handlers for each of the reply types sent from the uCode
2561 * to the host.
2562 *
2563 * This function chains into the hardware specific files for them to setup
2564 * any hardware specific handlers as well.
2565 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002566static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002567{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002568 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
2569 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
2570 priv->rx_handlers[REPLY_ERROR] = iwl3945_rx_reply_error;
2571 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl3945_rx_csa;
Zhu Yib481de92007-09-25 17:54:57 -07002572 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002573 iwl3945_rx_spectrum_measure_notif;
2574 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl3945_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07002575 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002576 iwl3945_rx_pm_debug_statistics_notif;
2577 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07002578
Ben Cahill9fbab512007-11-29 11:09:47 +08002579 /*
2580 * The same handler is used for both the REPLY to a discrete
2581 * statistics request from the host as well as for the periodic
2582 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07002583 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002584 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
2585 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -07002586
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002587 priv->rx_handlers[REPLY_SCAN_CMD] = iwl3945_rx_reply_scan;
2588 priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl3945_rx_scan_start_notif;
Zhu Yib481de92007-09-25 17:54:57 -07002589 priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002590 iwl3945_rx_scan_results_notif;
Zhu Yib481de92007-09-25 17:54:57 -07002591 priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002592 iwl3945_rx_scan_complete_notif;
2593 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07002594
Ben Cahill9fbab512007-11-29 11:09:47 +08002595 /* Set up hardware specific Rx handlers */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002596 iwl3945_hw_rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002597}
2598
2599/**
Tomas Winkler91c066f2008-03-06 17:36:55 -08002600 * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries
2601 * When FW advances 'R' index, all entries between old and new 'R' index
2602 * need to be reclaimed.
2603 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002604static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv,
Tomas Winkler91c066f2008-03-06 17:36:55 -08002605 int txq_id, int index)
2606{
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08002607 struct iwl_tx_queue *txq = &priv->txq[txq_id];
Samuel Ortizd20b3c62008-12-19 10:37:15 +08002608 struct iwl_queue *q = &txq->q;
Tomas Winkler91c066f2008-03-06 17:36:55 -08002609 int nfreed = 0;
2610
Winkler, Tomas625a3812009-01-08 10:19:55 -08002611 if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002612 IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, "
Tomas Winkler91c066f2008-03-06 17:36:55 -08002613 "is out of range [0-%d] %d %d.\n", txq_id,
2614 index, q->n_bd, q->write_ptr, q->read_ptr);
2615 return;
2616 }
2617
2618 for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
2619 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
2620 if (nfreed > 1) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002621 IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index,
Tomas Winkler91c066f2008-03-06 17:36:55 -08002622 q->write_ptr, q->read_ptr);
2623 queue_work(priv->workqueue, &priv->restart);
2624 break;
2625 }
2626 nfreed++;
2627 }
2628}
2629
2630
2631/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002632 * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
Zhu Yib481de92007-09-25 17:54:57 -07002633 * @rxb: Rx buffer to reclaim
2634 *
2635 * If an Rx buffer has an async callback associated with it the callback
2636 * will be executed. The attached skb (if present) will only be freed
2637 * if the callback returns 1
2638 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002639static void iwl3945_tx_cmd_complete(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002640 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07002641{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002642 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002643 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
2644 int txq_id = SEQ_TO_QUEUE(sequence);
2645 int index = SEQ_TO_INDEX(sequence);
Tomas Winkler600c0e12008-12-19 10:37:04 +08002646 int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
Zhu Yib481de92007-09-25 17:54:57 -07002647 int cmd_index;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08002648 struct iwl_cmd *cmd;
Zhu Yib481de92007-09-25 17:54:57 -07002649
Chatre, Reinette638d0eb2009-01-19 15:30:24 -08002650 if (WARN(txq_id != IWL_CMD_QUEUE_NUM,
2651 "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n",
2652 txq_id, sequence,
2653 priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr,
2654 priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) {
2655 iwl_print_hex_dump(priv, IWL_DL_INFO , rxb, 32);
2656 return;
2657 }
Zhu Yib481de92007-09-25 17:54:57 -07002658
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08002659 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
2660 cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
Zhu Yib481de92007-09-25 17:54:57 -07002661
2662 /* Input error checking is done when commands are added to queue. */
2663 if (cmd->meta.flags & CMD_WANT_SKB) {
2664 cmd->meta.source->u.skb = rxb->skb;
2665 rxb->skb = NULL;
2666 } else if (cmd->meta.u.callback &&
2667 !cmd->meta.u.callback(priv, cmd, rxb->skb))
2668 rxb->skb = NULL;
2669
Tomas Winkler91c066f2008-03-06 17:36:55 -08002670 iwl3945_cmd_queue_reclaim(priv, txq_id, index);
Zhu Yib481de92007-09-25 17:54:57 -07002671
2672 if (!(cmd->meta.flags & CMD_ASYNC)) {
2673 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
2674 wake_up_interruptible(&priv->wait_command_queue);
2675 }
2676}
2677
2678/************************** RX-FUNCTIONS ****************************/
2679/*
2680 * Rx theory of operation
2681 *
2682 * The host allocates 32 DMA target addresses and passes the host address
2683 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
2684 * 0 to 31
2685 *
2686 * Rx Queue Indexes
2687 * The host/firmware share two index registers for managing the Rx buffers.
2688 *
2689 * The READ index maps to the first position that the firmware may be writing
2690 * to -- the driver can read up to (but not including) this position and get
2691 * good data.
2692 * The READ index is managed by the firmware once the card is enabled.
2693 *
2694 * The WRITE index maps to the last position the driver has read from -- the
2695 * position preceding WRITE is the last slot the firmware can place a packet.
2696 *
2697 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
2698 * WRITE = READ.
2699 *
Ben Cahill9fbab512007-11-29 11:09:47 +08002700 * During initialization, the host sets up the READ queue position to the first
Zhu Yib481de92007-09-25 17:54:57 -07002701 * INDEX position, and WRITE to the last (READ - 1 wrapped)
2702 *
Ben Cahill9fbab512007-11-29 11:09:47 +08002703 * When the firmware places a packet in a buffer, it will advance the READ index
Zhu Yib481de92007-09-25 17:54:57 -07002704 * and fire the RX interrupt. The driver can then query the READ index and
2705 * process as many packets as possible, moving the WRITE index forward as it
2706 * resets the Rx queue buffers with new memory.
2707 *
2708 * The management in the driver is as follows:
2709 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
2710 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Ian Schram01ebd062007-10-25 17:15:22 +08002711 * to replenish the iwl->rxq->rx_free.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002712 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
Zhu Yib481de92007-09-25 17:54:57 -07002713 * iwl->rxq is replenished and the READ INDEX is updated (updating the
2714 * 'processed' and 'read' driver indexes as well)
2715 * + A received packet is processed and handed to the kernel network stack,
2716 * detached from the iwl->rxq. The driver 'processed' index is updated.
2717 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
2718 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
2719 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
2720 * were enough free buffers and RX_STALLED is set it is cleared.
2721 *
2722 *
2723 * Driver sequence:
2724 *
Ben Cahill9fbab512007-11-29 11:09:47 +08002725 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002726 * iwl3945_rx_queue_restock
Ben Cahill9fbab512007-11-29 11:09:47 +08002727 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
Zhu Yib481de92007-09-25 17:54:57 -07002728 * queue, updates firmware pointers, and updates
2729 * the WRITE index. If insufficient rx_free buffers
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002730 * are available, schedules iwl3945_rx_replenish
Zhu Yib481de92007-09-25 17:54:57 -07002731 *
2732 * -- enable interrupts --
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002733 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
Zhu Yib481de92007-09-25 17:54:57 -07002734 * READ INDEX, detaching the SKB from the pool.
2735 * Moves the packet buffer from queue to rx_used.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002736 * Calls iwl3945_rx_queue_restock to refill any empty
Zhu Yib481de92007-09-25 17:54:57 -07002737 * slots.
2738 * ...
2739 *
2740 */
2741
2742/**
Ben Cahill9fbab512007-11-29 11:09:47 +08002743 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
Zhu Yib481de92007-09-25 17:54:57 -07002744 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002745static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002746 dma_addr_t dma_addr)
2747{
2748 return cpu_to_le32((u32)dma_addr);
2749}
2750
2751/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002752 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
Zhu Yib481de92007-09-25 17:54:57 -07002753 *
Ben Cahill9fbab512007-11-29 11:09:47 +08002754 * If there are slots in the RX queue that need to be restocked,
Zhu Yib481de92007-09-25 17:54:57 -07002755 * and we have free pre-allocated buffers, fill the ranks as much
Ben Cahill9fbab512007-11-29 11:09:47 +08002756 * as we can, pulling from rx_free.
Zhu Yib481de92007-09-25 17:54:57 -07002757 *
2758 * This moves the 'write' index forward to catch up with 'processed', and
2759 * also updates the memory address in the firmware to reference the new
2760 * target buffer.
2761 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002762static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002763{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08002764 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07002765 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002766 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07002767 unsigned long flags;
2768 int write, rc;
2769
2770 spin_lock_irqsave(&rxq->lock, flags);
2771 write = rxq->write & ~0x7;
Winkler, Tomas37d68312009-01-08 10:19:54 -08002772 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002773 /* Get next free Rx buffer, remove from free list */
Zhu Yib481de92007-09-25 17:54:57 -07002774 element = rxq->rx_free.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002775 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07002776 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002777
2778 /* Point to Rx buffer via next RBD in circular buffer */
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002779 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
Zhu Yib481de92007-09-25 17:54:57 -07002780 rxq->queue[rxq->write] = rxb;
2781 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
2782 rxq->free_count--;
2783 }
2784 spin_unlock_irqrestore(&rxq->lock, flags);
2785 /* If the pre-allocated buffer pool is dropping low, schedule to
2786 * refill it */
2787 if (rxq->free_count <= RX_LOW_WATERMARK)
2788 queue_work(priv->workqueue, &priv->rx_replenish);
2789
2790
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002791 /* If we've added more space for the firmware to place data, tell it.
2792 * Increment device's write pointer in multiples of 8. */
Zhu Yib481de92007-09-25 17:54:57 -07002793 if ((write != (rxq->write & ~0x7))
2794 || (abs(rxq->write - rxq->read) > 7)) {
2795 spin_lock_irqsave(&rxq->lock, flags);
2796 rxq->need_update = 1;
2797 spin_unlock_irqrestore(&rxq->lock, flags);
Winkler, Tomas141c43a2009-01-08 10:19:53 -08002798 rc = iwl_rx_queue_update_write_ptr(priv, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07002799 if (rc)
2800 return rc;
2801 }
2802
2803 return 0;
2804}
2805
2806/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002807 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
Zhu Yib481de92007-09-25 17:54:57 -07002808 *
2809 * When moving to rx_free an SKB is allocated for the slot.
2810 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002811 * Also restock the Rx queue via iwl3945_rx_queue_restock.
Ian Schram01ebd062007-10-25 17:15:22 +08002812 * This is called as a scheduled work item (except for during initialization)
Zhu Yib481de92007-09-25 17:54:57 -07002813 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002814static void iwl3945_rx_allocate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002815{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08002816 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07002817 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002818 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07002819 unsigned long flags;
2820 spin_lock_irqsave(&rxq->lock, flags);
2821 while (!list_empty(&rxq->rx_used)) {
2822 element = rxq->rx_used.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002823 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002824
2825 /* Alloc a new receive buffer */
Zhu Yib481de92007-09-25 17:54:57 -07002826 rxb->skb =
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08002827 alloc_skb(priv->hw_params.rx_buf_size,
2828 __GFP_NOWARN | GFP_ATOMIC);
Zhu Yib481de92007-09-25 17:54:57 -07002829 if (!rxb->skb) {
2830 if (net_ratelimit())
Tomas Winkler978785a2008-12-19 10:37:31 +08002831 IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
Zhu Yib481de92007-09-25 17:54:57 -07002832 /* We don't reschedule replenish work here -- we will
2833 * call the restock method and if it still needs
2834 * more buffers it will schedule replenish */
2835 break;
2836 }
Zhu Yi12342c42007-12-20 11:27:32 +08002837
2838 /* If radiotap head is required, reserve some headroom here.
2839 * The physical head count is a variable rx_stats->phy_count.
2840 * We reserve 4 bytes here. Plus these extra bytes, the
2841 * headroom of the physical head should be enough for the
2842 * radiotap head that iwl3945 supported. See iwl3945_rt.
2843 */
2844 skb_reserve(rxb->skb, 4);
2845
Zhu Yib481de92007-09-25 17:54:57 -07002846 priv->alloc_rxb_skb++;
2847 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002848
2849 /* Get physical address of RB/SKB */
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08002850 rxb->real_dma_addr = pci_map_single(priv->pci_dev,
2851 rxb->skb->data,
2852 priv->hw_params.rx_buf_size,
2853 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07002854 list_add_tail(&rxb->list, &rxq->rx_free);
2855 rxq->free_count++;
2856 }
2857 spin_unlock_irqrestore(&rxq->lock, flags);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002858}
2859
2860/*
2861 * this should be called while priv->lock is locked
2862 */
Tomas Winkler4fd1f842007-12-05 20:59:58 +02002863static void __iwl3945_rx_replenish(void *data)
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002864{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002865 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002866
2867 iwl3945_rx_allocate(priv);
2868 iwl3945_rx_queue_restock(priv);
2869}
2870
2871
2872void iwl3945_rx_replenish(void *data)
2873{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002874 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002875 unsigned long flags;
2876
2877 iwl3945_rx_allocate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002878
2879 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002880 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002881 spin_unlock_irqrestore(&priv->lock, flags);
2882}
2883
Zhu Yib481de92007-09-25 17:54:57 -07002884/* Convert linear signal-to-noise ratio into dB */
2885static u8 ratio2dB[100] = {
2886/* 0 1 2 3 4 5 6 7 8 9 */
2887 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
2888 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
2889 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
2890 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
2891 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
2892 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
2893 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
2894 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
2895 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
2896 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
2897};
2898
2899/* Calculates a relative dB value from a ratio of linear
2900 * (i.e. not dB) signal levels.
2901 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002902int iwl3945_calc_db_from_ratio(int sig_ratio)
Zhu Yib481de92007-09-25 17:54:57 -07002903{
Adrian Bunk221c80c2008-02-02 23:19:01 +02002904 /* 1000:1 or higher just report as 60 dB */
2905 if (sig_ratio >= 1000)
Zhu Yib481de92007-09-25 17:54:57 -07002906 return 60;
2907
Adrian Bunk221c80c2008-02-02 23:19:01 +02002908 /* 100:1 or higher, divide by 10 and use table,
Zhu Yib481de92007-09-25 17:54:57 -07002909 * add 20 dB to make up for divide by 10 */
Adrian Bunk221c80c2008-02-02 23:19:01 +02002910 if (sig_ratio >= 100)
Tomas Winkler3ac7f142008-07-21 02:40:14 +03002911 return 20 + (int)ratio2dB[sig_ratio/10];
Zhu Yib481de92007-09-25 17:54:57 -07002912
2913 /* We shouldn't see this */
2914 if (sig_ratio < 1)
2915 return 0;
2916
2917 /* Use table for ratios 1:1 - 99:1 */
2918 return (int)ratio2dB[sig_ratio];
2919}
2920
2921#define PERFECT_RSSI (-20) /* dBm */
2922#define WORST_RSSI (-95) /* dBm */
2923#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
2924
2925/* Calculate an indication of rx signal quality (a percentage, not dBm!).
2926 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
2927 * about formulas used below. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002928int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
Zhu Yib481de92007-09-25 17:54:57 -07002929{
2930 int sig_qual;
2931 int degradation = PERFECT_RSSI - rssi_dbm;
2932
2933 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
2934 * as indicator; formula is (signal dbm - noise dbm).
2935 * SNR at or above 40 is a great signal (100%).
2936 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
2937 * Weakest usable signal is usually 10 - 15 dB SNR. */
2938 if (noise_dbm) {
2939 if (rssi_dbm - noise_dbm >= 40)
2940 return 100;
2941 else if (rssi_dbm < noise_dbm)
2942 return 0;
2943 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
2944
2945 /* Else use just the signal level.
2946 * This formula is a least squares fit of data points collected and
2947 * compared with a reference system that had a percentage (%) display
2948 * for signal quality. */
2949 } else
2950 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
2951 (15 * RSSI_RANGE + 62 * degradation)) /
2952 (RSSI_RANGE * RSSI_RANGE);
2953
2954 if (sig_qual > 100)
2955 sig_qual = 100;
2956 else if (sig_qual < 1)
2957 sig_qual = 0;
2958
2959 return sig_qual;
2960}
2961
2962/**
Ben Cahill9fbab512007-11-29 11:09:47 +08002963 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07002964 *
2965 * Uses the priv->rx_handlers callback function array to invoke
2966 * the appropriate handlers, including command responses,
2967 * frame-received notifications, and other notifications.
2968 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002969static void iwl3945_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002970{
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002971 struct iwl_rx_mem_buffer *rxb;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002972 struct iwl_rx_packet *pkt;
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08002973 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07002974 u32 r, i;
2975 int reclaim;
2976 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002977 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08002978 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07002979
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002980 /* uCode's read index (stored in shared DRAM) indicates the last Rx
2981 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8cd812b2008-12-19 10:37:43 +08002982 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07002983 i = rxq->read;
2984
Winkler, Tomas37d68312009-01-08 10:19:54 -08002985 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002986 fill_rx = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002987 /* Rx interrupt, but nothing sent from uCode */
2988 if (i == r)
2989 IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
2990
2991 while (i != r) {
2992 rxb = rxq->queue[i];
2993
Ben Cahill9fbab512007-11-29 11:09:47 +08002994 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07002995 * then a bug has been introduced in the queue refilling
2996 * routines -- catch it here */
2997 BUG_ON(rxb == NULL);
2998
2999 rxq->queue[i] = NULL;
3000
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08003001 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08003002 priv->hw_params.rx_buf_size,
Zhu Yib481de92007-09-25 17:54:57 -07003003 PCI_DMA_FROMDEVICE);
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08003004 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07003005
3006 /* Reclaim a command buffer only if this packet is a response
3007 * to a (driver-originated) command.
3008 * If the packet (e.g. Rx frame) originated from uCode,
3009 * there is no command buffer to reclaim.
3010 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
3011 * but apparently a few don't get set; catch them here. */
3012 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
3013 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
3014 (pkt->hdr.cmd != REPLY_TX);
3015
3016 /* Based on type of command response or notification,
3017 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003018 * rx_handlers table. See iwl3945_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07003019 if (priv->rx_handlers[pkt->hdr.cmd]) {
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003020 IWL_DEBUG(IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07003021 "r = %d, i = %d, %s, 0x%02x\n", r, i,
3022 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
3023 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
3024 } else {
3025 /* No handling needed */
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003026 IWL_DEBUG(IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07003027 "r %d i %d No handler needed for %s, 0x%02x\n",
3028 r, i, get_cmd_string(pkt->hdr.cmd),
3029 pkt->hdr.cmd);
3030 }
3031
3032 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08003033 /* Invoke any callbacks, transfer the skb to caller, and
Samuel Ortiz518099a2009-01-19 15:30:27 -08003034 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07003035 * as we reclaim the driver command queue */
3036 if (rxb && rxb->skb)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003037 iwl3945_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07003038 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003039 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07003040 }
3041
3042 /* For now we just don't re-use anything. We can tweak this
3043 * later to try and re-use notification packets and SKBs that
3044 * fail to Rx correctly */
3045 if (rxb->skb != NULL) {
3046 priv->alloc_rxb_skb--;
3047 dev_kfree_skb_any(rxb->skb);
3048 rxb->skb = NULL;
3049 }
3050
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08003051 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08003052 priv->hw_params.rx_buf_size,
3053 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07003054 spin_lock_irqsave(&rxq->lock, flags);
3055 list_add_tail(&rxb->list, &priv->rxq.rx_used);
3056 spin_unlock_irqrestore(&rxq->lock, flags);
3057 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08003058 /* If there are a lot of unused frames,
3059 * restock the Rx queue so ucode won't assert. */
3060 if (fill_rx) {
3061 count++;
3062 if (count >= 8) {
3063 priv->rxq.read = i;
3064 __iwl3945_rx_replenish(priv);
3065 count = 0;
3066 }
3067 }
Zhu Yib481de92007-09-25 17:54:57 -07003068 }
3069
3070 /* Backtrack one entry */
3071 priv->rxq.read = i;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003072 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003073}
3074
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003075#ifdef CONFIG_IWL3945_DEBUG
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003076static void iwl3945_print_rx_config_cmd(struct iwl_priv *priv,
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003077 struct iwl3945_rxon_cmd *rxon)
Zhu Yib481de92007-09-25 17:54:57 -07003078{
3079 IWL_DEBUG_RADIO("RX CONFIG:\n");
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003080 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
Zhu Yib481de92007-09-25 17:54:57 -07003081 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
3082 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
3083 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
3084 le32_to_cpu(rxon->filter_flags));
3085 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
3086 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
3087 rxon->ofdm_basic_rates);
3088 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
Johannes Berge1749612008-10-27 15:59:26 -07003089 IWL_DEBUG_RADIO("u8[6] node_addr: %pM\n", rxon->node_addr);
3090 IWL_DEBUG_RADIO("u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07003091 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
3092}
3093#endif
3094
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003095static void iwl3945_enable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003096{
3097 IWL_DEBUG_ISR("Enabling interrupts\n");
3098 set_bit(STATUS_INT_ENABLED, &priv->status);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003099 iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07003100}
3101
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003102
3103/* call this function to flush any scheduled tasklet */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003104static inline void iwl_synchronize_irq(struct iwl_priv *priv)
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003105{
Tomas Winklera96a27f2008-10-23 23:48:56 -07003106 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003107 synchronize_irq(priv->pci_dev->irq);
3108 tasklet_kill(&priv->irq_tasklet);
3109}
3110
3111
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003112static inline void iwl3945_disable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003113{
3114 clear_bit(STATUS_INT_ENABLED, &priv->status);
3115
3116 /* disable interrupts from uCode/NIC to host */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003117 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07003118
3119 /* acknowledge/clear/reset any interrupts still pending
3120 * from uCode or flow handler (Rx/Tx DMA) */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003121 iwl_write32(priv, CSR_INT, 0xffffffff);
3122 iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
Zhu Yib481de92007-09-25 17:54:57 -07003123 IWL_DEBUG_ISR("Disabled interrupts\n");
3124}
3125
3126static const char *desc_lookup(int i)
3127{
3128 switch (i) {
3129 case 1:
3130 return "FAIL";
3131 case 2:
3132 return "BAD_PARAM";
3133 case 3:
3134 return "BAD_CHECKSUM";
3135 case 4:
3136 return "NMI_INTERRUPT";
3137 case 5:
3138 return "SYSASSERT";
3139 case 6:
3140 return "FATAL_ERROR";
3141 }
3142
3143 return "UNKNOWN";
3144}
3145
3146#define ERROR_START_OFFSET (1 * sizeof(u32))
3147#define ERROR_ELEM_SIZE (7 * sizeof(u32))
3148
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003149static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003150{
3151 u32 i;
3152 u32 desc, time, count, base, data1;
3153 u32 blink1, blink2, ilink1, ilink2;
3154 int rc;
3155
3156 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
3157
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003158 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003159 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07003160 return;
3161 }
3162
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003163 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003164 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003165 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003166 return;
3167 }
3168
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003169 count = iwl_read_targ_mem(priv, base);
Zhu Yib481de92007-09-25 17:54:57 -07003170
3171 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003172 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
3173 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
3174 priv->status, count);
Zhu Yib481de92007-09-25 17:54:57 -07003175 }
3176
Winkler, Tomas15b16872008-12-19 10:37:33 +08003177 IWL_ERR(priv, "Desc Time asrtPC blink2 "
Zhu Yib481de92007-09-25 17:54:57 -07003178 "ilink1 nmiPC Line\n");
3179 for (i = ERROR_START_OFFSET;
3180 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
3181 i += ERROR_ELEM_SIZE) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003182 desc = iwl_read_targ_mem(priv, base + i);
Zhu Yib481de92007-09-25 17:54:57 -07003183 time =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003184 iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07003185 blink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003186 iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07003187 blink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003188 iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07003189 ilink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003190 iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07003191 ilink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003192 iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07003193 data1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003194 iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07003195
Winkler, Tomas15b16872008-12-19 10:37:33 +08003196 IWL_ERR(priv,
3197 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
3198 desc_lookup(desc), desc, time, blink1, blink2,
3199 ilink1, ilink2, data1);
Zhu Yib481de92007-09-25 17:54:57 -07003200 }
3201
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003202 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003203
3204}
3205
Ben Cahillf58177b2007-11-29 11:09:43 +08003206#define EVENT_START_OFFSET (6 * sizeof(u32))
Zhu Yib481de92007-09-25 17:54:57 -07003207
3208/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003209 * iwl3945_print_event_log - Dump error event log to syslog
Zhu Yib481de92007-09-25 17:54:57 -07003210 *
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003211 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
Zhu Yib481de92007-09-25 17:54:57 -07003212 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003213static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
Zhu Yib481de92007-09-25 17:54:57 -07003214 u32 num_events, u32 mode)
3215{
3216 u32 i;
3217 u32 base; /* SRAM byte address of event log header */
3218 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
3219 u32 ptr; /* SRAM byte address of log data */
3220 u32 ev, time, data; /* event log data */
3221
3222 if (num_events == 0)
3223 return;
3224
3225 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
3226
3227 if (mode == 0)
3228 event_size = 2 * sizeof(u32);
3229 else
3230 event_size = 3 * sizeof(u32);
3231
3232 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
3233
3234 /* "time" is actually "data" for mode 0 (no timestamp).
3235 * place event id # at far right for easier visual parsing. */
3236 for (i = 0; i < num_events; i++) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003237 ev = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07003238 ptr += sizeof(u32);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003239 time = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07003240 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08003241 if (mode == 0) {
3242 /* data, ev */
3243 IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
3244 } else {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003245 data = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07003246 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08003247 IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
Zhu Yib481de92007-09-25 17:54:57 -07003248 }
3249 }
3250}
3251
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003252static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003253{
3254 int rc;
3255 u32 base; /* SRAM byte address of event log header */
3256 u32 capacity; /* event log capacity in # entries */
3257 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
3258 u32 num_wraps; /* # times uCode wrapped to top of log */
3259 u32 next_entry; /* index of next entry to be written by uCode */
3260 u32 size; /* # entries that we'll print */
3261
3262 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003263 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003264 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07003265 return;
3266 }
3267
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003268 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003269 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003270 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003271 return;
3272 }
3273
3274 /* event log header */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003275 capacity = iwl_read_targ_mem(priv, base);
3276 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
3277 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
3278 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -07003279
3280 size = num_wraps ? capacity : next_entry;
3281
3282 /* bail out if nothing in log */
3283 if (size == 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003284 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003285 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003286 return;
3287 }
3288
Winkler, Tomas15b16872008-12-19 10:37:33 +08003289 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003290 size, num_wraps);
3291
3292 /* if uCode has wrapped back to top of log, start at the oldest entry,
3293 * i.e the next one that uCode would fill. */
3294 if (num_wraps)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003295 iwl3945_print_event_log(priv, next_entry,
Zhu Yib481de92007-09-25 17:54:57 -07003296 capacity - next_entry, mode);
3297
3298 /* (then/else) start at top of log */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003299 iwl3945_print_event_log(priv, 0, next_entry, mode);
Zhu Yib481de92007-09-25 17:54:57 -07003300
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003301 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003302}
3303
3304/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003305 * iwl3945_irq_handle_error - called for HW or SW error interrupt from card
Zhu Yib481de92007-09-25 17:54:57 -07003306 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003307static void iwl3945_irq_handle_error(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003308{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003309 /* Set the FW error flag -- cleared on iwl3945_down */
Zhu Yib481de92007-09-25 17:54:57 -07003310 set_bit(STATUS_FW_ERROR, &priv->status);
3311
3312 /* Cancel currently queued command. */
3313 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
3314
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003315#ifdef CONFIG_IWL3945_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003316 if (priv->debug_level & IWL_DL_FW_ERRORS) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003317 iwl3945_dump_nic_error_log(priv);
3318 iwl3945_dump_nic_event_log(priv);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003319 iwl3945_print_rx_config_cmd(priv, &priv->staging39_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07003320 }
3321#endif
3322
3323 wake_up_interruptible(&priv->wait_command_queue);
3324
3325 /* Keep the restart process from trying to send host
3326 * commands by clearing the INIT status bit */
3327 clear_bit(STATUS_READY, &priv->status);
3328
3329 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
3330 IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS,
3331 "Restarting adapter due to uCode error.\n");
3332
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003333 if (iwl3945_is_associated(priv)) {
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003334 memcpy(&priv->recovery39_rxon, &priv->active39_rxon,
3335 sizeof(priv->recovery39_rxon));
Zhu Yib481de92007-09-25 17:54:57 -07003336 priv->error_recovering = 1;
3337 }
3338 queue_work(priv->workqueue, &priv->restart);
3339 }
3340}
3341
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003342static void iwl3945_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003343{
3344 unsigned long flags;
3345
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003346 memcpy(&priv->staging39_rxon, &priv->recovery39_rxon,
3347 sizeof(priv->staging39_rxon));
3348 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003349 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003350
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003351 iwl3945_add_station(priv, priv->bssid, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003352
3353 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003354 priv->assoc_id = le16_to_cpu(priv->staging39_rxon.assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003355 priv->error_recovering = 0;
3356 spin_unlock_irqrestore(&priv->lock, flags);
3357}
3358
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003359static void iwl3945_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003360{
3361 u32 inta, handled = 0;
3362 u32 inta_fh;
3363 unsigned long flags;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003364#ifdef CONFIG_IWL3945_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07003365 u32 inta_mask;
3366#endif
3367
3368 spin_lock_irqsave(&priv->lock, flags);
3369
3370 /* Ack/clear/reset pending uCode interrupts.
3371 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
3372 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003373 inta = iwl_read32(priv, CSR_INT);
3374 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07003375
3376 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
3377 * Any new interrupts that happen after this, either while we're
3378 * in this tasklet, or later, will show up in next ISR/tasklet. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003379 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
3380 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07003381
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003382#ifdef CONFIG_IWL3945_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003383 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08003384 /* just for debug */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003385 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07003386 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
3387 inta, inta_mask, inta_fh);
3388 }
3389#endif
3390
3391 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
3392 * atomic, make sure that inta covers all the interrupts that
3393 * we've discovered, even if FH interrupt came in just after
3394 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08003395 if (inta_fh & CSR39_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07003396 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08003397 if (inta_fh & CSR39_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07003398 inta |= CSR_INT_BIT_FH_TX;
3399
3400 /* Now service all interrupt bits discovered above. */
3401 if (inta & CSR_INT_BIT_HW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003402 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003403
3404 /* Tell the device to stop sending interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003405 iwl3945_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003406
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003407 iwl3945_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003408
3409 handled |= CSR_INT_BIT_HW_ERR;
3410
3411 spin_unlock_irqrestore(&priv->lock, flags);
3412
3413 return;
3414 }
3415
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003416#ifdef CONFIG_IWL3945_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003417 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07003418 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08003419 if (inta & CSR_INT_BIT_SCD)
3420 IWL_DEBUG_ISR("Scheduler finished to transmit "
3421 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003422
3423 /* Alive notification via Rx interrupt will do the real work */
3424 if (inta & CSR_INT_BIT_ALIVE)
3425 IWL_DEBUG_ISR("Alive interrupt\n");
3426 }
3427#endif
3428 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08003429 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07003430
Zhu Yib481de92007-09-25 17:54:57 -07003431 /* Error detected by uCode */
3432 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003433 IWL_ERR(priv, "Microcode SW error detected. "
3434 "Restarting 0x%X.\n", inta);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003435 iwl3945_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003436 handled |= CSR_INT_BIT_SW_ERR;
3437 }
3438
3439 /* uCode wakes up after power-down sleep */
3440 if (inta & CSR_INT_BIT_WAKEUP) {
3441 IWL_DEBUG_ISR("Wakeup interrupt\n");
Winkler, Tomas141c43a2009-01-08 10:19:53 -08003442 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08003443 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
3444 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
3445 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
3446 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
3447 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
3448 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07003449
3450 handled |= CSR_INT_BIT_WAKEUP;
3451 }
3452
3453 /* All uCode command responses, including Tx command responses,
3454 * Rx "responses" (frame-received notification), and other
3455 * notifications from uCode come through here*/
3456 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003457 iwl3945_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003458 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
3459 }
3460
3461 if (inta & CSR_INT_BIT_FH_TX) {
3462 IWL_DEBUG_ISR("Tx interrupt\n");
3463
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003464 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
3465 if (!iwl_grab_nic_access(priv)) {
3466 iwl_write_direct32(priv, FH39_TCSR_CREDIT
Tomas Winklerbddadf82008-12-19 10:37:01 +08003467 (FH39_SRVC_CHNL), 0x0);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003468 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003469 }
3470 handled |= CSR_INT_BIT_FH_TX;
3471 }
3472
3473 if (inta & ~handled)
Winkler, Tomas15b16872008-12-19 10:37:33 +08003474 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Zhu Yib481de92007-09-25 17:54:57 -07003475
3476 if (inta & ~CSR_INI_SET_MASK) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003477 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Zhu Yib481de92007-09-25 17:54:57 -07003478 inta & ~CSR_INI_SET_MASK);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003479 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07003480 }
3481
3482 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003483 /* only Re-enable if disabled by irq */
3484 if (test_bit(STATUS_INT_ENABLED, &priv->status))
3485 iwl3945_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003486
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003487#ifdef CONFIG_IWL3945_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08003488 if (priv->debug_level & (IWL_DL_ISR)) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003489 inta = iwl_read32(priv, CSR_INT);
3490 inta_mask = iwl_read32(priv, CSR_INT_MASK);
3491 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07003492 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
3493 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
3494 }
3495#endif
3496 spin_unlock_irqrestore(&priv->lock, flags);
3497}
3498
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003499static irqreturn_t iwl3945_isr(int irq, void *data)
Zhu Yib481de92007-09-25 17:54:57 -07003500{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003501 struct iwl_priv *priv = data;
Zhu Yib481de92007-09-25 17:54:57 -07003502 u32 inta, inta_mask;
3503 u32 inta_fh;
3504 if (!priv)
3505 return IRQ_NONE;
3506
3507 spin_lock(&priv->lock);
3508
3509 /* Disable (but don't clear!) interrupts here to avoid
3510 * back-to-back ISRs and sporadic interrupts from our NIC.
3511 * If we have something to service, the tasklet will re-enable ints.
3512 * If we *don't* have something, we'll re-enable before leaving here. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003513 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
3514 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07003515
3516 /* Discover which interrupts are active/pending */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003517 inta = iwl_read32(priv, CSR_INT);
3518 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07003519
3520 /* Ignore interrupt if there's nothing in NIC to service.
3521 * This may be due to IRQ shared with another device,
3522 * or due to sporadic interrupts thrown from our NIC. */
3523 if (!inta && !inta_fh) {
3524 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
3525 goto none;
3526 }
3527
3528 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
3529 /* Hardware disappeared */
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003530 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
Oliver Neukumcb4da1a2007-11-13 21:10:32 -08003531 goto unplugged;
Zhu Yib481de92007-09-25 17:54:57 -07003532 }
3533
3534 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
3535 inta, inta_mask, inta_fh);
3536
Joonwoo Park25c03d82008-01-23 10:15:20 -08003537 inta &= ~CSR_INT_BIT_SCD;
3538
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003539 /* iwl3945_irq_tasklet() will service interrupts and re-enable them */
Joonwoo Park25c03d82008-01-23 10:15:20 -08003540 if (likely(inta || inta_fh))
3541 tasklet_schedule(&priv->irq_tasklet);
Oliver Neukumcb4da1a2007-11-13 21:10:32 -08003542unplugged:
Zhu Yib481de92007-09-25 17:54:57 -07003543 spin_unlock(&priv->lock);
3544
3545 return IRQ_HANDLED;
3546
3547 none:
3548 /* re-enable interrupts here since we don't have anything to service. */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003549 /* only Re-enable if disabled by irq */
3550 if (test_bit(STATUS_INT_ENABLED, &priv->status))
3551 iwl3945_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003552 spin_unlock(&priv->lock);
3553 return IRQ_NONE;
3554}
3555
3556/************************** EEPROM BANDS ****************************
3557 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003558 * The iwl3945_eeprom_band definitions below provide the mapping from the
Zhu Yib481de92007-09-25 17:54:57 -07003559 * EEPROM contents to the specific channel number supported for each
3560 * band.
3561 *
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003562 * For example, iwl3945_priv->eeprom39.band_3_channels[4] from the band_3
Zhu Yib481de92007-09-25 17:54:57 -07003563 * definition below maps to physical channel 42 in the 5.2GHz spectrum.
3564 * The specific geography and calibration information for that channel
3565 * is contained in the eeprom map itself.
3566 *
3567 * During init, we copy the eeprom information and channel map
3568 * information into priv->channel_info_24/52 and priv->channel_map_24/52
3569 *
3570 * channel_map_24/52 provides the index in the channel_info array for a
3571 * given channel. We have to have two separate maps as there is channel
3572 * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
3573 * band_2
3574 *
3575 * A value of 0xff stored in the channel_map indicates that the channel
3576 * is not supported by the hardware at all.
3577 *
3578 * A value of 0xfe in the channel_map indicates that the channel is not
3579 * valid for Tx with the current hardware. This means that
3580 * while the system can tune and receive on a given channel, it may not
3581 * be able to associate or transmit any frames on that
3582 * channel. There is no corresponding channel information for that
3583 * entry.
3584 *
3585 *********************************************************************/
3586
3587/* 2.4 GHz */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003588static const u8 iwl3945_eeprom_band_1[14] = {
Zhu Yib481de92007-09-25 17:54:57 -07003589 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
3590};
3591
3592/* 5.2 GHz bands */
Ben Cahill9fbab512007-11-29 11:09:47 +08003593static const u8 iwl3945_eeprom_band_2[] = { /* 4915-5080MHz */
Zhu Yib481de92007-09-25 17:54:57 -07003594 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
3595};
3596
Ben Cahill9fbab512007-11-29 11:09:47 +08003597static const u8 iwl3945_eeprom_band_3[] = { /* 5170-5320MHz */
Zhu Yib481de92007-09-25 17:54:57 -07003598 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
3599};
3600
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003601static const u8 iwl3945_eeprom_band_4[] = { /* 5500-5700MHz */
Zhu Yib481de92007-09-25 17:54:57 -07003602 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
3603};
3604
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003605static const u8 iwl3945_eeprom_band_5[] = { /* 5725-5825MHz */
Zhu Yib481de92007-09-25 17:54:57 -07003606 145, 149, 153, 157, 161, 165
3607};
3608
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003609static void iwl3945_init_band_reference(const struct iwl_priv *priv, int band,
Zhu Yib481de92007-09-25 17:54:57 -07003610 int *eeprom_ch_count,
Samuel Ortiz0f741d92008-12-19 10:37:10 +08003611 const struct iwl_eeprom_channel
Zhu Yib481de92007-09-25 17:54:57 -07003612 **eeprom_ch_info,
3613 const u8 **eeprom_ch_index)
3614{
3615 switch (band) {
3616 case 1: /* 2.4GHz band */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003617 *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_1);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003618 *eeprom_ch_info = priv->eeprom39.band_1_channels;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003619 *eeprom_ch_index = iwl3945_eeprom_band_1;
Zhu Yib481de92007-09-25 17:54:57 -07003620 break;
Ben Cahill9fbab512007-11-29 11:09:47 +08003621 case 2: /* 4.9GHz band */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003622 *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_2);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003623 *eeprom_ch_info = priv->eeprom39.band_2_channels;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003624 *eeprom_ch_index = iwl3945_eeprom_band_2;
Zhu Yib481de92007-09-25 17:54:57 -07003625 break;
3626 case 3: /* 5.2GHz band */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003627 *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_3);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003628 *eeprom_ch_info = priv->eeprom39.band_3_channels;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003629 *eeprom_ch_index = iwl3945_eeprom_band_3;
Zhu Yib481de92007-09-25 17:54:57 -07003630 break;
Ben Cahill9fbab512007-11-29 11:09:47 +08003631 case 4: /* 5.5GHz band */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003632 *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_4);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003633 *eeprom_ch_info = priv->eeprom39.band_4_channels;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003634 *eeprom_ch_index = iwl3945_eeprom_band_4;
Zhu Yib481de92007-09-25 17:54:57 -07003635 break;
Ben Cahill9fbab512007-11-29 11:09:47 +08003636 case 5: /* 5.7GHz band */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003637 *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_5);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003638 *eeprom_ch_info = priv->eeprom39.band_5_channels;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003639 *eeprom_ch_index = iwl3945_eeprom_band_5;
Zhu Yib481de92007-09-25 17:54:57 -07003640 break;
3641 default:
3642 BUG();
3643 return;
3644 }
3645}
3646
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003647/**
3648 * iwl3945_get_channel_info - Find driver's private channel info
3649 *
3650 * Based on band and channel number.
3651 */
Samuel Ortizd20b3c62008-12-19 10:37:15 +08003652const struct iwl_channel_info *
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003653iwl3945_get_channel_info(const struct iwl_priv *priv,
Samuel Ortizd20b3c62008-12-19 10:37:15 +08003654 enum ieee80211_band band, u16 channel)
Zhu Yib481de92007-09-25 17:54:57 -07003655{
3656 int i;
3657
Johannes Berg8318d782008-01-24 19:38:38 +01003658 switch (band) {
3659 case IEEE80211_BAND_5GHZ:
Zhu Yib481de92007-09-25 17:54:57 -07003660 for (i = 14; i < priv->channel_count; i++) {
3661 if (priv->channel_info[i].channel == channel)
3662 return &priv->channel_info[i];
3663 }
3664 break;
3665
Johannes Berg8318d782008-01-24 19:38:38 +01003666 case IEEE80211_BAND_2GHZ:
Zhu Yib481de92007-09-25 17:54:57 -07003667 if (channel >= 1 && channel <= 14)
3668 return &priv->channel_info[channel - 1];
3669 break;
Johannes Berg8318d782008-01-24 19:38:38 +01003670 case IEEE80211_NUM_BANDS:
3671 WARN_ON(1);
Zhu Yib481de92007-09-25 17:54:57 -07003672 }
3673
3674 return NULL;
3675}
3676
3677#define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
3678 ? # x " " : "")
3679
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003680/**
3681 * iwl3945_init_channel_map - Set up driver's info for all possible channels
3682 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003683static int iwl3945_init_channel_map(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003684{
3685 int eeprom_ch_count = 0;
3686 const u8 *eeprom_ch_index = NULL;
Samuel Ortiz0f741d92008-12-19 10:37:10 +08003687 const struct iwl_eeprom_channel *eeprom_ch_info = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07003688 int band, ch;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08003689 struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07003690
3691 if (priv->channel_count) {
3692 IWL_DEBUG_INFO("Channel map already initialized.\n");
3693 return 0;
3694 }
3695
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003696 if (priv->eeprom39.version < 0x2f) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003697 IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08003698 priv->eeprom39.version);
Zhu Yib481de92007-09-25 17:54:57 -07003699 return -EINVAL;
3700 }
3701
3702 IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n");
3703
3704 priv->channel_count =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003705 ARRAY_SIZE(iwl3945_eeprom_band_1) +
3706 ARRAY_SIZE(iwl3945_eeprom_band_2) +
3707 ARRAY_SIZE(iwl3945_eeprom_band_3) +
3708 ARRAY_SIZE(iwl3945_eeprom_band_4) +
3709 ARRAY_SIZE(iwl3945_eeprom_band_5);
Zhu Yib481de92007-09-25 17:54:57 -07003710
3711 IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count);
3712
Samuel Ortizd20b3c62008-12-19 10:37:15 +08003713 priv->channel_info = kzalloc(sizeof(struct iwl_channel_info) *
Zhu Yib481de92007-09-25 17:54:57 -07003714 priv->channel_count, GFP_KERNEL);
3715 if (!priv->channel_info) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003716 IWL_ERR(priv, "Could not allocate channel_info\n");
Zhu Yib481de92007-09-25 17:54:57 -07003717 priv->channel_count = 0;
3718 return -ENOMEM;
3719 }
3720
3721 ch_info = priv->channel_info;
3722
3723 /* Loop through the 5 EEPROM bands adding them in order to the
3724 * channel map we maintain (that contains additional information than
3725 * what just in the EEPROM) */
3726 for (band = 1; band <= 5; band++) {
3727
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003728 iwl3945_init_band_reference(priv, band, &eeprom_ch_count,
Zhu Yib481de92007-09-25 17:54:57 -07003729 &eeprom_ch_info, &eeprom_ch_index);
3730
3731 /* Loop through each band adding each of the channels */
3732 for (ch = 0; ch < eeprom_ch_count; ch++) {
3733 ch_info->channel = eeprom_ch_index[ch];
Johannes Berg8318d782008-01-24 19:38:38 +01003734 ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ :
3735 IEEE80211_BAND_5GHZ;
Zhu Yib481de92007-09-25 17:54:57 -07003736
3737 /* permanently store EEPROM's channel regulatory flags
3738 * and max power in channel info database. */
3739 ch_info->eeprom = eeprom_ch_info[ch];
3740
3741 /* Copy the run-time flags so they are there even on
3742 * invalid channels */
3743 ch_info->flags = eeprom_ch_info[ch].flags;
3744
3745 if (!(is_channel_valid(ch_info))) {
3746 IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - "
3747 "No traffic\n",
3748 ch_info->channel,
3749 ch_info->flags,
3750 is_channel_a_band(ch_info) ?
3751 "5.2" : "2.4");
3752 ch_info++;
3753 continue;
3754 }
3755
3756 /* Initialize regulatory-based run-time data */
3757 ch_info->max_power_avg = ch_info->curr_txpow =
3758 eeprom_ch_info[ch].max_power_avg;
3759 ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
3760 ch_info->min_power = 0;
3761
Guy Cohenfe7c4042008-04-21 15:41:56 -07003762 IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x"
Zhu Yib481de92007-09-25 17:54:57 -07003763 " %ddBm): Ad-Hoc %ssupported\n",
3764 ch_info->channel,
3765 is_channel_a_band(ch_info) ?
3766 "5.2" : "2.4",
Tomas Winkler8211ef72008-03-02 01:36:04 +02003767 CHECK_AND_PRINT(VALID),
Zhu Yib481de92007-09-25 17:54:57 -07003768 CHECK_AND_PRINT(IBSS),
3769 CHECK_AND_PRINT(ACTIVE),
3770 CHECK_AND_PRINT(RADAR),
3771 CHECK_AND_PRINT(WIDE),
Zhu Yib481de92007-09-25 17:54:57 -07003772 CHECK_AND_PRINT(DFS),
3773 eeprom_ch_info[ch].flags,
3774 eeprom_ch_info[ch].max_power_avg,
3775 ((eeprom_ch_info[ch].
3776 flags & EEPROM_CHANNEL_IBSS)
3777 && !(eeprom_ch_info[ch].
3778 flags & EEPROM_CHANNEL_RADAR))
3779 ? "" : "not ");
3780
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08003781 /* Set the tx_power_user_lmt to the highest power
Zhu Yib481de92007-09-25 17:54:57 -07003782 * supported by any channel */
3783 if (eeprom_ch_info[ch].max_power_avg >
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08003784 priv->tx_power_user_lmt)
3785 priv->tx_power_user_lmt =
Zhu Yib481de92007-09-25 17:54:57 -07003786 eeprom_ch_info[ch].max_power_avg;
3787
3788 ch_info++;
3789 }
3790 }
3791
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003792 /* Set up txpower settings in driver for all channels */
Zhu Yib481de92007-09-25 17:54:57 -07003793 if (iwl3945_txpower_set_from_eeprom(priv))
3794 return -EIO;
3795
3796 return 0;
3797}
3798
Reinette Chatre849e0dc2008-01-23 10:15:18 -08003799/*
3800 * iwl3945_free_channel_map - undo allocations in iwl3945_init_channel_map
3801 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003802static void iwl3945_free_channel_map(struct iwl_priv *priv)
Reinette Chatre849e0dc2008-01-23 10:15:18 -08003803{
3804 kfree(priv->channel_info);
3805 priv->channel_count = 0;
3806}
3807
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003808static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01003809 enum ieee80211_band band,
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003810 u8 is_active, u8 n_probes,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003811 struct iwl3945_scan_channel *scan_ch)
Zhu Yib481de92007-09-25 17:54:57 -07003812{
3813 const struct ieee80211_channel *channels = NULL;
Johannes Berg8318d782008-01-24 19:38:38 +01003814 const struct ieee80211_supported_band *sband;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08003815 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07003816 u16 passive_dwell = 0;
3817 u16 active_dwell = 0;
3818 int added, i;
3819
Kolekar, Abhijeetcbba18c2008-12-19 10:37:42 +08003820 sband = iwl_get_hw_mode(priv, band);
Johannes Berg8318d782008-01-24 19:38:38 +01003821 if (!sband)
Zhu Yib481de92007-09-25 17:54:57 -07003822 return 0;
3823
Johannes Berg8318d782008-01-24 19:38:38 +01003824 channels = sband->channels;
Zhu Yib481de92007-09-25 17:54:57 -07003825
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08003826 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
3827 passive_dwell = iwl_get_passive_dwell_time(priv, band);
Zhu Yib481de92007-09-25 17:54:57 -07003828
Abhijeet Kolekar8f4807a2008-09-03 11:26:31 +08003829 if (passive_dwell <= active_dwell)
3830 passive_dwell = active_dwell + 1;
3831
Johannes Berg8318d782008-01-24 19:38:38 +01003832 for (i = 0, added = 0; i < sband->n_channels; i++) {
Johannes Berg182e2e62008-04-04 10:41:56 +02003833 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
3834 continue;
3835
Johannes Berg8318d782008-01-24 19:38:38 +01003836 scan_ch->channel = channels[i].hw_value;
Zhu Yib481de92007-09-25 17:54:57 -07003837
Johannes Berg8318d782008-01-24 19:38:38 +01003838 ch_info = iwl3945_get_channel_info(priv, band, scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07003839 if (!is_channel_valid(ch_info)) {
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003840 IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n",
Zhu Yib481de92007-09-25 17:54:57 -07003841 scan_ch->channel);
3842 continue;
3843 }
3844
Zhu Yib481de92007-09-25 17:54:57 -07003845 scan_ch->active_dwell = cpu_to_le16(active_dwell);
3846 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08003847 /* If passive , set up for auto-switch
3848 * and use long active_dwell time.
3849 */
3850 if (!is_active || is_channel_passive(ch_info) ||
3851 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
3852 scan_ch->type = 0; /* passive */
3853 if (IWL_UCODE_API(priv->ucode_ver) == 1)
3854 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
3855 } else {
3856 scan_ch->type = 1; /* active */
3857 }
3858
3859 /* Set direct probe bits. These may be used both for active
3860 * scan channels (probes gets sent right away),
3861 * or for passive channels (probes get se sent only after
3862 * hearing clear Rx packet).*/
3863 if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
3864 if (n_probes)
3865 scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes);
3866 } else {
3867 /* uCode v1 does not allow setting direct probe bits on
3868 * passive channel. */
3869 if ((scan_ch->type & 1) && n_probes)
3870 scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes);
3871 }
Zhu Yib481de92007-09-25 17:54:57 -07003872
Ben Cahill9fbab512007-11-29 11:09:47 +08003873 /* Set txpower levels to defaults */
Zhu Yib481de92007-09-25 17:54:57 -07003874 scan_ch->tpc.dsp_atten = 110;
3875 /* scan_pwr_info->tpc.dsp_atten; */
3876
3877 /*scan_pwr_info->tpc.tx_gain; */
Johannes Berg8318d782008-01-24 19:38:38 +01003878 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07003879 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
3880 else {
3881 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
3882 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
Ben Cahill9fbab512007-11-29 11:09:47 +08003883 * power level:
Reinette Chatre8a1b0242008-01-14 17:46:25 -08003884 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
Zhu Yib481de92007-09-25 17:54:57 -07003885 */
3886 }
3887
3888 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
3889 scan_ch->channel,
3890 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
3891 (scan_ch->type & 1) ?
3892 active_dwell : passive_dwell);
3893
3894 scan_ch++;
3895 added++;
3896 }
3897
3898 IWL_DEBUG_SCAN("total channels to scan %d \n", added);
3899 return added;
3900}
3901
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003902static void iwl3945_init_hw_rates(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07003903 struct ieee80211_rate *rates)
3904{
3905 int i;
3906
3907 for (i = 0; i < IWL_RATE_COUNT; i++) {
Johannes Berg8318d782008-01-24 19:38:38 +01003908 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
3909 rates[i].hw_value = i; /* Rate scaling will work on indexes */
3910 rates[i].hw_value_short = i;
3911 rates[i].flags = 0;
Samuel Ortizd9829a62008-12-19 10:37:12 +08003912 if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
Zhu Yib481de92007-09-25 17:54:57 -07003913 /*
Johannes Berg8318d782008-01-24 19:38:38 +01003914 * If CCK != 1M then set short preamble rate flag.
Zhu Yib481de92007-09-25 17:54:57 -07003915 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003916 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
Johannes Berg8318d782008-01-24 19:38:38 +01003917 0 : IEEE80211_RATE_SHORT_PREAMBLE;
Zhu Yib481de92007-09-25 17:54:57 -07003918 }
Zhu Yib481de92007-09-25 17:54:57 -07003919 }
3920}
3921
3922/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003923 * iwl3945_init_geos - Initialize mac80211's geo/channel info based from eeprom
Zhu Yib481de92007-09-25 17:54:57 -07003924 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003925static int iwl3945_init_geos(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003926{
Samuel Ortizd20b3c62008-12-19 10:37:15 +08003927 struct iwl_channel_info *ch;
Tomas Winkler8211ef72008-03-02 01:36:04 +02003928 struct ieee80211_supported_band *sband;
Zhu Yib481de92007-09-25 17:54:57 -07003929 struct ieee80211_channel *channels;
3930 struct ieee80211_channel *geo_ch;
3931 struct ieee80211_rate *rates;
3932 int i = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003933
Johannes Berg8318d782008-01-24 19:38:38 +01003934 if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
3935 priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
Zhu Yib481de92007-09-25 17:54:57 -07003936 IWL_DEBUG_INFO("Geography modes already initialized.\n");
3937 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
3938 return 0;
3939 }
3940
Zhu Yib481de92007-09-25 17:54:57 -07003941 channels = kzalloc(sizeof(struct ieee80211_channel) *
3942 priv->channel_count, GFP_KERNEL);
Johannes Berg8318d782008-01-24 19:38:38 +01003943 if (!channels)
Zhu Yib481de92007-09-25 17:54:57 -07003944 return -ENOMEM;
Zhu Yib481de92007-09-25 17:54:57 -07003945
Tomas Winkler8211ef72008-03-02 01:36:04 +02003946 rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)),
Zhu Yib481de92007-09-25 17:54:57 -07003947 GFP_KERNEL);
3948 if (!rates) {
Zhu Yib481de92007-09-25 17:54:57 -07003949 kfree(channels);
3950 return -ENOMEM;
3951 }
3952
Zhu Yib481de92007-09-25 17:54:57 -07003953 /* 5.2GHz channels start after the 2.4GHz channels */
Tomas Winkler8211ef72008-03-02 01:36:04 +02003954 sband = &priv->bands[IEEE80211_BAND_5GHZ];
3955 sband->channels = &channels[ARRAY_SIZE(iwl3945_eeprom_band_1)];
3956 /* just OFDM */
3957 sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
3958 sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE;
Zhu Yib481de92007-09-25 17:54:57 -07003959
Tomas Winkler8211ef72008-03-02 01:36:04 +02003960 sband = &priv->bands[IEEE80211_BAND_2GHZ];
3961 sband->channels = channels;
3962 /* OFDM & CCK */
3963 sband->bitrates = rates;
3964 sband->n_bitrates = IWL_RATE_COUNT;
Zhu Yib481de92007-09-25 17:54:57 -07003965
3966 priv->ieee_channels = channels;
3967 priv->ieee_rates = rates;
3968
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003969 iwl3945_init_hw_rates(priv, rates);
Zhu Yib481de92007-09-25 17:54:57 -07003970
Tomas Winkler8211ef72008-03-02 01:36:04 +02003971 for (i = 0; i < priv->channel_count; i++) {
Zhu Yib481de92007-09-25 17:54:57 -07003972 ch = &priv->channel_info[i];
3973
Tomas Winkler8211ef72008-03-02 01:36:04 +02003974 /* FIXME: might be removed if scan is OK*/
3975 if (!is_channel_valid(ch))
Zhu Yib481de92007-09-25 17:54:57 -07003976 continue;
Zhu Yib481de92007-09-25 17:54:57 -07003977
3978 if (is_channel_a_band(ch))
Tomas Winkler8211ef72008-03-02 01:36:04 +02003979 sband = &priv->bands[IEEE80211_BAND_5GHZ];
Johannes Berg8318d782008-01-24 19:38:38 +01003980 else
Tomas Winkler8211ef72008-03-02 01:36:04 +02003981 sband = &priv->bands[IEEE80211_BAND_2GHZ];
Zhu Yib481de92007-09-25 17:54:57 -07003982
Tomas Winkler8211ef72008-03-02 01:36:04 +02003983 geo_ch = &sband->channels[sband->n_channels++];
3984
3985 geo_ch->center_freq = ieee80211_channel_to_frequency(ch->channel);
Johannes Berg8318d782008-01-24 19:38:38 +01003986 geo_ch->max_power = ch->max_power_avg;
3987 geo_ch->max_antenna_gain = 0xff;
Mohamed Abbas7b723042008-01-31 21:46:40 -08003988 geo_ch->hw_value = ch->channel;
Zhu Yib481de92007-09-25 17:54:57 -07003989
3990 if (is_channel_valid(ch)) {
Johannes Berg8318d782008-01-24 19:38:38 +01003991 if (!(ch->flags & EEPROM_CHANNEL_IBSS))
3992 geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
Zhu Yib481de92007-09-25 17:54:57 -07003993
Johannes Berg8318d782008-01-24 19:38:38 +01003994 if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
3995 geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
Zhu Yib481de92007-09-25 17:54:57 -07003996
3997 if (ch->flags & EEPROM_CHANNEL_RADAR)
Johannes Berg8318d782008-01-24 19:38:38 +01003998 geo_ch->flags |= IEEE80211_CHAN_RADAR;
Zhu Yib481de92007-09-25 17:54:57 -07003999
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08004000 if (ch->max_power_avg > priv->tx_power_channel_lmt)
4001 priv->tx_power_channel_lmt =
Zhu Yib481de92007-09-25 17:54:57 -07004002 ch->max_power_avg;
Tomas Winkler8211ef72008-03-02 01:36:04 +02004003 } else {
Johannes Berg8318d782008-01-24 19:38:38 +01004004 geo_ch->flags |= IEEE80211_CHAN_DISABLED;
Tomas Winkler8211ef72008-03-02 01:36:04 +02004005 }
4006
4007 /* Save flags for reg domain usage */
4008 geo_ch->orig_flags = geo_ch->flags;
4009
4010 IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n",
4011 ch->channel, geo_ch->center_freq,
4012 is_channel_a_band(ch) ? "5.2" : "2.4",
4013 geo_ch->flags & IEEE80211_CHAN_DISABLED ?
4014 "restricted" : "valid",
4015 geo_ch->flags);
Zhu Yib481de92007-09-25 17:54:57 -07004016 }
4017
Tomas Winkler82b9a122008-03-04 18:09:30 -08004018 if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
4019 priv->cfg->sku & IWL_SKU_A) {
Tomas Winkler978785a2008-12-19 10:37:31 +08004020 IWL_INFO(priv, "Incorrectly detected BG card as ABG. "
4021 "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n",
4022 priv->pci_dev->device, priv->pci_dev->subsystem_device);
Tomas Winkler82b9a122008-03-04 18:09:30 -08004023 priv->cfg->sku &= ~IWL_SKU_A;
Zhu Yib481de92007-09-25 17:54:57 -07004024 }
4025
Tomas Winkler978785a2008-12-19 10:37:31 +08004026 IWL_INFO(priv, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
Johannes Berg8318d782008-01-24 19:38:38 +01004027 priv->bands[IEEE80211_BAND_2GHZ].n_channels,
4028 priv->bands[IEEE80211_BAND_5GHZ].n_channels);
Zhu Yib481de92007-09-25 17:54:57 -07004029
John W. Linvillee0e0a672008-03-25 15:58:40 -04004030 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
4031 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
4032 &priv->bands[IEEE80211_BAND_2GHZ];
4033 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
4034 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
4035 &priv->bands[IEEE80211_BAND_5GHZ];
Zhu Yib481de92007-09-25 17:54:57 -07004036
Zhu Yib481de92007-09-25 17:54:57 -07004037 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
4038
4039 return 0;
4040}
4041
Reinette Chatre849e0dc2008-01-23 10:15:18 -08004042/*
4043 * iwl3945_free_geos - undo allocations in iwl3945_init_geos
4044 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004045static void iwl3945_free_geos(struct iwl_priv *priv)
Reinette Chatre849e0dc2008-01-23 10:15:18 -08004046{
Reinette Chatre849e0dc2008-01-23 10:15:18 -08004047 kfree(priv->ieee_channels);
4048 kfree(priv->ieee_rates);
4049 clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
4050}
4051
Zhu Yib481de92007-09-25 17:54:57 -07004052/******************************************************************************
4053 *
4054 * uCode download functions
4055 *
4056 ******************************************************************************/
4057
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004058static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004059{
Tomas Winkler98c92212008-01-14 17:46:20 -08004060 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
4061 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
4062 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
4063 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
4064 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
4065 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07004066}
4067
4068/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004069 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07004070 * looking at all data.
4071 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004072static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07004073{
4074 u32 val;
4075 u32 save_len = len;
4076 int rc = 0;
4077 u32 errcnt;
4078
4079 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
4080
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004081 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004082 if (rc)
4083 return rc;
4084
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004085 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08004086 IWL39_RTC_INST_LOWER_BOUND);
Zhu Yib481de92007-09-25 17:54:57 -07004087
4088 errcnt = 0;
4089 for (; len > 0; len -= sizeof(u32), image++) {
4090 /* read data comes through single port, auto-incr addr */
4091 /* NOTE: Use the debugless read so we don't flood kernel log
4092 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004093 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07004094 if (val != le32_to_cpu(*image)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004095 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07004096 "offset 0x%x, is 0x%x, s/b 0x%x\n",
4097 save_len - len, val, le32_to_cpu(*image));
4098 rc = -EIO;
4099 errcnt++;
4100 if (errcnt >= 20)
4101 break;
4102 }
4103 }
4104
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004105 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004106
4107 if (!errcnt)
Ian Schrambc434dd2007-10-25 17:15:29 +08004108 IWL_DEBUG_INFO("ucode image in INSTRUCTION memory is good\n");
Zhu Yib481de92007-09-25 17:54:57 -07004109
4110 return rc;
4111}
4112
4113
4114/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004115 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07004116 * using sample data 100 bytes apart. If these sample points are good,
4117 * it's a pretty good bet that everything between them is good, too.
4118 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004119static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07004120{
4121 u32 val;
4122 int rc = 0;
4123 u32 errcnt = 0;
4124 u32 i;
4125
4126 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
4127
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004128 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004129 if (rc)
4130 return rc;
4131
4132 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
4133 /* read data comes through single port, auto-incr addr */
4134 /* NOTE: Use the debugless read so we don't flood kernel log
4135 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004136 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08004137 i + IWL39_RTC_INST_LOWER_BOUND);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004138 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07004139 if (val != le32_to_cpu(*image)) {
4140#if 0 /* Enable this if you want to see details */
Winkler, Tomas15b16872008-12-19 10:37:33 +08004141 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07004142 "offset 0x%x, is 0x%x, s/b 0x%x\n",
4143 i, val, *image);
4144#endif
4145 rc = -EIO;
4146 errcnt++;
4147 if (errcnt >= 3)
4148 break;
4149 }
4150 }
4151
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004152 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004153
4154 return rc;
4155}
4156
4157
4158/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004159 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
Zhu Yib481de92007-09-25 17:54:57 -07004160 * and verify its contents
4161 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004162static int iwl3945_verify_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004163{
4164 __le32 *image;
4165 u32 len;
4166 int rc = 0;
4167
4168 /* Try bootstrap */
4169 image = (__le32 *)priv->ucode_boot.v_addr;
4170 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004171 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07004172 if (rc == 0) {
4173 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
4174 return 0;
4175 }
4176
4177 /* Try initialize */
4178 image = (__le32 *)priv->ucode_init.v_addr;
4179 len = priv->ucode_init.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004180 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07004181 if (rc == 0) {
4182 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
4183 return 0;
4184 }
4185
4186 /* Try runtime/protocol */
4187 image = (__le32 *)priv->ucode_code.v_addr;
4188 len = priv->ucode_code.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004189 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07004190 if (rc == 0) {
4191 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
4192 return 0;
4193 }
4194
Winkler, Tomas15b16872008-12-19 10:37:33 +08004195 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
Zhu Yib481de92007-09-25 17:54:57 -07004196
Ben Cahill9fbab512007-11-29 11:09:47 +08004197 /* Since nothing seems to match, show first several data entries in
4198 * instruction SRAM, so maybe visual inspection will give a clue.
4199 * Selection of bootstrap image (vs. other images) is arbitrary. */
Zhu Yib481de92007-09-25 17:54:57 -07004200 image = (__le32 *)priv->ucode_boot.v_addr;
4201 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004202 rc = iwl3945_verify_inst_full(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07004203
4204 return rc;
4205}
4206
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004207static void iwl3945_nic_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004208{
4209 /* Remove all resets to allow NIC to operate */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004210 iwl_write32(priv, CSR_RESET, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004211}
4212
4213/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004214 * iwl3945_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07004215 *
4216 * Copy into buffers for card to fetch via bus-mastering
4217 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004218static int iwl3945_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004219{
Kolekar, Abhijeeta78fe752008-12-19 10:37:21 +08004220 struct iwl_ucode *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08004221 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07004222 const struct firmware *ucode_raw;
4223 /* firmware file name contains uCode/driver compatibility version */
Reinette Chatrea0987a82008-12-02 12:14:06 -08004224 const char *name_pre = priv->cfg->fw_name_pre;
4225 const unsigned int api_max = priv->cfg->ucode_api_max;
4226 const unsigned int api_min = priv->cfg->ucode_api_min;
4227 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07004228 u8 *src;
4229 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08004230 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07004231
4232 /* Ask kernel firmware_class module to get the boot firmware off disk.
4233 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08004234 for (index = api_max; index >= api_min; index--) {
4235 sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
4236 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
4237 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004238 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08004239 buf, ret);
4240 if (ret == -ENOENT)
4241 continue;
4242 else
4243 goto error;
4244 } else {
4245 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08004246 IWL_ERR(priv, "Loaded firmware %s, "
4247 "which is deprecated. "
4248 " Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08004249 buf, api_max);
4250 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
4251 buf, ucode_raw->size);
4252 break;
4253 }
Zhu Yib481de92007-09-25 17:54:57 -07004254 }
4255
Reinette Chatrea0987a82008-12-02 12:14:06 -08004256 if (ret < 0)
4257 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07004258
4259 /* Make sure that we got at least our header! */
4260 if (ucode_raw->size < sizeof(*ucode)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004261 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08004262 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07004263 goto err_release;
4264 }
4265
4266 /* Data from ucode file: header followed by uCode images */
4267 ucode = (void *)ucode_raw->data;
4268
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08004269 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08004270 api_ver = IWL_UCODE_API(priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07004271 inst_size = le32_to_cpu(ucode->inst_size);
4272 data_size = le32_to_cpu(ucode->data_size);
4273 init_size = le32_to_cpu(ucode->init_size);
4274 init_data_size = le32_to_cpu(ucode->init_data_size);
4275 boot_size = le32_to_cpu(ucode->boot_size);
4276
Reinette Chatrea0987a82008-12-02 12:14:06 -08004277 /* api_ver should match the api version forming part of the
4278 * firmware filename ... but we don't check for that and only rely
4279 * on the API version read from firware header from here on forward */
4280
4281 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004282 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08004283 "Driver supports v%u, firmware is v%u.\n",
4284 api_max, api_ver);
4285 priv->ucode_ver = 0;
4286 ret = -EINVAL;
4287 goto err_release;
4288 }
4289 if (api_ver != api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08004290 IWL_ERR(priv, "Firmware has old API version. Expected %u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08004291 "got %u. New firmware can be obtained "
4292 "from http://www.intellinuxwireless.org.\n",
4293 api_max, api_ver);
4294
Tomas Winkler978785a2008-12-19 10:37:31 +08004295 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
4296 IWL_UCODE_MAJOR(priv->ucode_ver),
4297 IWL_UCODE_MINOR(priv->ucode_ver),
4298 IWL_UCODE_API(priv->ucode_ver),
4299 IWL_UCODE_SERIAL(priv->ucode_ver));
4300
Reinette Chatrea0987a82008-12-02 12:14:06 -08004301 IWL_DEBUG_INFO("f/w package hdr ucode version raw = 0x%x\n",
4302 priv->ucode_ver);
Ian Schrambc434dd2007-10-25 17:15:29 +08004303 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", inst_size);
4304 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", data_size);
4305 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", init_size);
4306 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", init_data_size);
4307 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07004308
Reinette Chatrea0987a82008-12-02 12:14:06 -08004309
Zhu Yib481de92007-09-25 17:54:57 -07004310 /* Verify size of file vs. image size info in file's header */
4311 if (ucode_raw->size < sizeof(*ucode) +
4312 inst_size + data_size + init_size +
4313 init_data_size + boot_size) {
4314
4315 IWL_DEBUG_INFO("uCode file size %d too small\n",
4316 (int)ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08004317 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07004318 goto err_release;
4319 }
4320
4321 /* Verify that uCode images will fit in card's SRAM */
Samuel Ortiz250bdd22008-12-19 10:37:11 +08004322 if (inst_size > IWL39_MAX_INST_SIZE) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08004323 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
4324 inst_size);
4325 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07004326 goto err_release;
4327 }
4328
Samuel Ortiz250bdd22008-12-19 10:37:11 +08004329 if (data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08004330 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
4331 data_size);
4332 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07004333 goto err_release;
4334 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08004335 if (init_size > IWL39_MAX_INST_SIZE) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08004336 IWL_DEBUG_INFO("uCode init instr len %d too large to fit in\n",
4337 init_size);
4338 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07004339 goto err_release;
4340 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08004341 if (init_data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08004342 IWL_DEBUG_INFO("uCode init data len %d too large to fit in\n",
4343 init_data_size);
4344 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07004345 goto err_release;
4346 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08004347 if (boot_size > IWL39_MAX_BSM_SIZE) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08004348 IWL_DEBUG_INFO("uCode boot instr len %d too large to fit in\n",
4349 boot_size);
4350 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07004351 goto err_release;
4352 }
4353
4354 /* Allocate ucode buffers for card's bus-master loading ... */
4355
4356 /* Runtime instructions and 2 copies of data:
4357 * 1) unmodified from disk
4358 * 2) backup cache for save/restore during power-downs */
4359 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08004360 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07004361
4362 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08004363 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07004364
4365 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08004366 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07004367
4368 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
Tomas Winkler90e759d2007-11-29 11:09:41 +08004369 !priv->ucode_data_backup.v_addr)
Zhu Yib481de92007-09-25 17:54:57 -07004370 goto err_pci_alloc;
4371
Tomas Winkler90e759d2007-11-29 11:09:41 +08004372 /* Initialization instructions and data */
4373 if (init_size && init_data_size) {
4374 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08004375 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Tomas Winkler90e759d2007-11-29 11:09:41 +08004376
4377 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08004378 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08004379
4380 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
4381 goto err_pci_alloc;
4382 }
4383
4384 /* Bootstrap (instructions only, no data) */
4385 if (boot_size) {
4386 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08004387 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Tomas Winkler90e759d2007-11-29 11:09:41 +08004388
4389 if (!priv->ucode_boot.v_addr)
4390 goto err_pci_alloc;
4391 }
4392
Zhu Yib481de92007-09-25 17:54:57 -07004393 /* Copy images into buffers for card's bus-master reads ... */
4394
4395 /* Runtime instructions (first block of data in file) */
4396 src = &ucode->data[0];
4397 len = priv->ucode_code.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08004398 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07004399 memcpy(priv->ucode_code.v_addr, src, len);
4400 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
4401 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
4402
4403 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004404 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
Zhu Yib481de92007-09-25 17:54:57 -07004405 src = &ucode->data[inst_size];
4406 len = priv->ucode_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08004407 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07004408 memcpy(priv->ucode_data.v_addr, src, len);
4409 memcpy(priv->ucode_data_backup.v_addr, src, len);
4410
4411 /* Initialization instructions (3rd block) */
4412 if (init_size) {
4413 src = &ucode->data[inst_size + data_size];
4414 len = priv->ucode_init.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08004415 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
4416 len);
Zhu Yib481de92007-09-25 17:54:57 -07004417 memcpy(priv->ucode_init.v_addr, src, len);
4418 }
4419
4420 /* Initialization data (4th block) */
4421 if (init_data_size) {
4422 src = &ucode->data[inst_size + data_size + init_size];
4423 len = priv->ucode_init_data.len;
4424 IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n",
4425 (int)len);
4426 memcpy(priv->ucode_init_data.v_addr, src, len);
4427 }
4428
4429 /* Bootstrap instructions (5th block) */
4430 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
4431 len = priv->ucode_boot.len;
4432 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n",
4433 (int)len);
4434 memcpy(priv->ucode_boot.v_addr, src, len);
4435
4436 /* We have our copies now, allow OS release its copies */
4437 release_firmware(ucode_raw);
4438 return 0;
4439
4440 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08004441 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08004442 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004443 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004444
4445 err_release:
4446 release_firmware(ucode_raw);
4447
4448 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08004449 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004450}
4451
4452
4453/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004454 * iwl3945_set_ucode_ptrs - Set uCode address location
Zhu Yib481de92007-09-25 17:54:57 -07004455 *
4456 * Tell initialization uCode where to find runtime uCode.
4457 *
4458 * BSM registers initially contain pointers to initialization uCode.
4459 * We need to replace them to load runtime uCode inst and data,
4460 * and to save runtime data when powering down.
4461 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004462static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004463{
4464 dma_addr_t pinst;
4465 dma_addr_t pdata;
4466 int rc = 0;
4467 unsigned long flags;
4468
4469 /* bits 31:0 for 3945 */
4470 pinst = priv->ucode_code.p_addr;
4471 pdata = priv->ucode_data_backup.p_addr;
4472
4473 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004474 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004475 if (rc) {
4476 spin_unlock_irqrestore(&priv->lock, flags);
4477 return rc;
4478 }
4479
4480 /* Tell bootstrap uCode where to find image to load */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004481 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
4482 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
4483 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07004484 priv->ucode_data.len);
4485
Tomas Winklera96a27f2008-10-23 23:48:56 -07004486 /* Inst byte count must be last to set up, bit 31 signals uCode
Zhu Yib481de92007-09-25 17:54:57 -07004487 * that all new ptr/size info is in place */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004488 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07004489 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
4490
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004491 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004492
4493 spin_unlock_irqrestore(&priv->lock, flags);
4494
4495 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
4496
4497 return rc;
4498}
4499
4500/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004501 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07004502 *
4503 * Called after REPLY_ALIVE notification received from "initialize" uCode.
4504 *
Zhu Yib481de92007-09-25 17:54:57 -07004505 * Tell "initialize" uCode to go ahead and load the runtime uCode.
Ben Cahill9fbab512007-11-29 11:09:47 +08004506 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004507static void iwl3945_init_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004508{
4509 /* Check alive response for "valid" sign from uCode */
4510 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
4511 /* We had an error bringing up the hardware, so take it
4512 * all the way back down so we can try again */
4513 IWL_DEBUG_INFO("Initialize Alive failed.\n");
4514 goto restart;
4515 }
4516
4517 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
4518 * This is a paranoid check, because we would not have gotten the
4519 * "initialize" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004520 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004521 /* Runtime instruction load was bad;
4522 * take it all the way back down so we can try again */
4523 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
4524 goto restart;
4525 }
4526
4527 /* Send pointers to protocol/runtime uCode image ... init code will
4528 * load and launch runtime uCode, which will send us another "Alive"
4529 * notification. */
4530 IWL_DEBUG_INFO("Initialization Alive received.\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004531 if (iwl3945_set_ucode_ptrs(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004532 /* Runtime instruction load won't happen;
4533 * take it all the way back down so we can try again */
4534 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
4535 goto restart;
4536 }
4537 return;
4538
4539 restart:
4540 queue_work(priv->workqueue, &priv->restart);
4541}
4542
4543
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08004544/* temporary */
4545static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw,
4546 struct sk_buff *skb);
4547
Zhu Yib481de92007-09-25 17:54:57 -07004548/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004549 * iwl3945_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07004550 * from protocol/runtime uCode (initialization uCode's
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004551 * Alive gets handled by iwl3945_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07004552 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004553static void iwl3945_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004554{
4555 int rc = 0;
4556 int thermal_spin = 0;
4557 u32 rfkill;
4558
4559 IWL_DEBUG_INFO("Runtime Alive received.\n");
4560
4561 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
4562 /* We had an error bringing up the hardware, so take it
4563 * all the way back down so we can try again */
4564 IWL_DEBUG_INFO("Alive failed.\n");
4565 goto restart;
4566 }
4567
4568 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
4569 * This is a paranoid check, because we would not have gotten the
4570 * "runtime" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004571 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004572 /* Runtime instruction load was bad;
4573 * take it all the way back down so we can try again */
4574 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
4575 goto restart;
4576 }
4577
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004578 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004579
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004580 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004581 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004582 IWL_WARN(priv, "Can not read RFKILL status from adapter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004583 return;
4584 }
4585
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004586 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
Zhu Yib481de92007-09-25 17:54:57 -07004587 IWL_DEBUG_INFO("RFKILL status: 0x%x\n", rfkill);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004588 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004589
4590 if (rfkill & 0x1) {
4591 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winklera96a27f2008-10-23 23:48:56 -07004592 /* if RFKILL is not on, then wait for thermal
Zhu Yib481de92007-09-25 17:54:57 -07004593 * sensor in adapter to kick in */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004594 while (iwl3945_hw_get_temperature(priv) == 0) {
Zhu Yib481de92007-09-25 17:54:57 -07004595 thermal_spin++;
4596 udelay(10);
4597 }
4598
4599 if (thermal_spin)
4600 IWL_DEBUG_INFO("Thermal calibration took %dus\n",
4601 thermal_spin * 10);
4602 } else
4603 set_bit(STATUS_RF_KILL_HW, &priv->status);
4604
Ben Cahill9fbab512007-11-29 11:09:47 +08004605 /* After the ALIVE response, we can send commands to 3945 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07004606 set_bit(STATUS_ALIVE, &priv->status);
4607
4608 /* Clear out the uCode error bit if it is set */
4609 clear_bit(STATUS_FW_ERROR, &priv->status);
4610
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004611 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004612 return;
4613
Johannes Berg36d68252008-05-15 12:55:26 +02004614 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07004615
4616 priv->active_rate = priv->rates_mask;
4617 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
4618
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004619 iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode));
Zhu Yib481de92007-09-25 17:54:57 -07004620
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004621 if (iwl3945_is_associated(priv)) {
4622 struct iwl3945_rxon_cmd *active_rxon =
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004623 (struct iwl3945_rxon_cmd *)(&priv->active39_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07004624
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004625 memcpy(&priv->staging39_rxon, &priv->active39_rxon,
4626 sizeof(priv->staging39_rxon));
Zhu Yib481de92007-09-25 17:54:57 -07004627 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
4628 } else {
4629 /* Initialize our rx_config data */
Zhu, Yi60294de2008-10-29 14:05:45 -07004630 iwl3945_connection_init_rx_config(priv, priv->iw_mode);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004631 memcpy(priv->staging39_rxon.node_addr, priv->mac_addr, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07004632 }
4633
Ben Cahill9fbab512007-11-29 11:09:47 +08004634 /* Configure Bluetooth device coexistence support */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004635 iwl3945_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004636
4637 /* Configure the adapter for unassociated operation */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004638 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004639
Zhu Yib481de92007-09-25 17:54:57 -07004640 iwl3945_reg_txpower_periodic(priv);
4641
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07004642 iwl3945_led_register(priv);
4643
Zhu Yib481de92007-09-25 17:54:57 -07004644 IWL_DEBUG_INFO("ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07004645 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a669262008-01-14 17:46:18 -08004646 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07004647
4648 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004649 iwl3945_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004650
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08004651 /* reassociate for ADHOC mode */
4652 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
4653 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
4654 priv->vif);
4655 if (beacon)
4656 iwl3945_mac_beacon_update(priv->hw, beacon);
4657 }
4658
Zhu Yib481de92007-09-25 17:54:57 -07004659 return;
4660
4661 restart:
4662 queue_work(priv->workqueue, &priv->restart);
4663}
4664
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004665static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07004666
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004667static void __iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004668{
4669 unsigned long flags;
4670 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
4671 struct ieee80211_conf *conf = NULL;
4672
4673 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
4674
4675 conf = ieee80211_get_hw_conf(priv->hw);
4676
4677 if (!exit_pending)
4678 set_bit(STATUS_EXIT_PENDING, &priv->status);
4679
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07004680 iwl3945_led_unregister(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004681 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004682
4683 /* Unblock any waiting calls */
4684 wake_up_interruptible_all(&priv->wait_command_queue);
4685
Zhu Yib481de92007-09-25 17:54:57 -07004686 /* Wipe out the EXIT_PENDING status bit if we are not actually
4687 * exiting the module */
4688 if (!exit_pending)
4689 clear_bit(STATUS_EXIT_PENDING, &priv->status);
4690
4691 /* stop and reset the on-board processor */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004692 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07004693
4694 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004695 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004696 iwl3945_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004697 spin_unlock_irqrestore(&priv->lock, flags);
4698 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004699
4700 if (priv->mac80211_registered)
4701 ieee80211_stop_queues(priv->hw);
4702
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004703 /* If we have not previously called iwl3945_init() then
Zhu Yib481de92007-09-25 17:54:57 -07004704 * clear all bits but the RF Kill and SUSPEND bits and return */
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004705 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004706 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
4707 STATUS_RF_KILL_HW |
4708 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
4709 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08004710 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
4711 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07004712 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08004713 STATUS_IN_SUSPEND |
4714 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
4715 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07004716 goto exit;
4717 }
4718
4719 /* ...otherwise clear out all the status bits but the RF Kill and
4720 * SUSPEND bits and continue taking the NIC down. */
4721 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
4722 STATUS_RF_KILL_HW |
4723 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
4724 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08004725 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
4726 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07004727 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
4728 STATUS_IN_SUSPEND |
4729 test_bit(STATUS_FW_ERROR, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08004730 STATUS_FW_ERROR |
4731 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
4732 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07004733
Abbas, Mohamede9414b62009-01-20 21:33:55 -08004734 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004735 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004736 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07004737 spin_unlock_irqrestore(&priv->lock, flags);
4738
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004739 iwl3945_hw_txq_ctx_stop(priv);
4740 iwl3945_hw_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004741
4742 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004743 if (!iwl_grab_nic_access(priv)) {
4744 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07004745 APMG_CLK_VAL_DMA_CLK_RQT);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004746 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004747 }
4748 spin_unlock_irqrestore(&priv->lock, flags);
4749
4750 udelay(5);
4751
Abbas, Mohamede9414b62009-01-20 21:33:55 -08004752 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
4753 priv->cfg->ops->lib->apm_ops.stop(priv);
4754 else
4755 priv->cfg->ops->lib->apm_ops.reset(priv);
4756
Zhu Yib481de92007-09-25 17:54:57 -07004757 exit:
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08004758 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07004759
4760 if (priv->ibss_beacon)
4761 dev_kfree_skb(priv->ibss_beacon);
4762 priv->ibss_beacon = NULL;
4763
4764 /* clear out any free frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004765 iwl3945_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004766}
4767
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004768static void iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004769{
4770 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004771 __iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004772 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08004773
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004774 iwl3945_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004775}
4776
4777#define MAX_HW_RESTARTS 5
4778
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004779static int __iwl3945_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004780{
4781 int rc, i;
4782
4783 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004784 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07004785 return -EIO;
4786 }
4787
4788 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004789 IWL_WARN(priv, "Radio disabled by SW RF kill (module "
Zhu Yib481de92007-09-25 17:54:57 -07004790 "parameter)\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08004791 return -ENODEV;
4792 }
4793
Reinette Chatree903fbd2008-01-30 22:05:15 -08004794 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004795 IWL_ERR(priv, "ucode not available for device bring up\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08004796 return -EIO;
4797 }
4798
Zhu Yie655b9f2008-01-24 02:19:38 -08004799 /* If platform's RF_KILL switch is NOT set to KILL */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004800 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08004801 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
4802 clear_bit(STATUS_RF_KILL_HW, &priv->status);
4803 else {
4804 set_bit(STATUS_RF_KILL_HW, &priv->status);
4805 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004806 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08004807 return -ENODEV;
4808 }
Zhu Yib481de92007-09-25 17:54:57 -07004809 }
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02004810
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004811 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07004812
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004813 rc = iwl3945_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004814 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004815 IWL_ERR(priv, "Unable to int nic\n");
Zhu Yib481de92007-09-25 17:54:57 -07004816 return rc;
4817 }
4818
4819 /* make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004820 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
4821 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07004822 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
4823
4824 /* clear (again), then enable host interrupts */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004825 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004826 iwl3945_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004827
4828 /* really make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08004829 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
4830 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07004831
4832 /* Copy original ucode data image from disk into backup cache.
4833 * This will be used to initialize the on-board processor's
4834 * data SRAM for a clean start when the runtime program first loads. */
4835 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a669262008-01-14 17:46:18 -08004836 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07004837
Zhu Yie655b9f2008-01-24 02:19:38 -08004838 /* We return success when we resume from suspend and rf_kill is on. */
4839 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
4840 return 0;
4841
Zhu Yib481de92007-09-25 17:54:57 -07004842 for (i = 0; i < MAX_HW_RESTARTS; i++) {
4843
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004844 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004845
4846 /* load bootstrap state machine,
4847 * load bootstrap program into processor's memory,
4848 * prepare to load the "initialize" uCode */
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08004849 priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004850
4851 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004852 IWL_ERR(priv,
4853 "Unable to set up bootstrap uCode: %d\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -07004854 continue;
4855 }
4856
4857 /* start card; "initialize" will load runtime ucode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004858 iwl3945_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004859
Zhu Yib481de92007-09-25 17:54:57 -07004860 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
4861
4862 return 0;
4863 }
4864
4865 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004866 __iwl3945_down(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08004867 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004868
4869 /* tried to restart and config the device for as long as our
4870 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08004871 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07004872 return -EIO;
4873}
4874
4875
4876/*****************************************************************************
4877 *
4878 * Workqueue callbacks
4879 *
4880 *****************************************************************************/
4881
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004882static void iwl3945_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07004883{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004884 struct iwl_priv *priv =
4885 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07004886
4887 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
4888 return;
4889
4890 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004891 iwl3945_init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004892 mutex_unlock(&priv->mutex);
4893}
4894
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004895static void iwl3945_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07004896{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004897 struct iwl_priv *priv =
4898 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07004899
4900 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
4901 return;
4902
4903 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004904 iwl3945_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004905 mutex_unlock(&priv->mutex);
4906}
4907
Helmut Schaa26635162009-01-15 09:38:44 +01004908static void iwl3945_rfkill_poll(struct work_struct *data)
4909{
4910 struct iwl_priv *priv =
4911 container_of(data, struct iwl_priv, rfkill_poll.work);
4912 unsigned long status = priv->status;
4913
4914 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
4915 clear_bit(STATUS_RF_KILL_HW, &priv->status);
4916 else
4917 set_bit(STATUS_RF_KILL_HW, &priv->status);
4918
4919 if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status))
4920 queue_work(priv->workqueue, &priv->rf_kill);
4921
4922 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
4923 round_jiffies_relative(2 * HZ));
4924
4925}
4926
Zhu Yib481de92007-09-25 17:54:57 -07004927#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004928static void iwl3945_bg_request_scan(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07004929{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004930 struct iwl_priv *priv =
4931 container_of(data, struct iwl_priv, request_scan);
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08004932 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07004933 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004934 .len = sizeof(struct iwl3945_scan_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07004935 .meta.flags = CMD_SIZE_HUGE,
4936 };
4937 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004938 struct iwl3945_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07004939 struct ieee80211_conf *conf = NULL;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08004940 u8 n_probes = 2;
Johannes Berg8318d782008-01-24 19:38:38 +01004941 enum ieee80211_band band;
John W. Linville9387b7c2008-09-30 20:59:05 -04004942 DECLARE_SSID_BUF(ssid);
Zhu Yib481de92007-09-25 17:54:57 -07004943
4944 conf = ieee80211_get_hw_conf(priv->hw);
4945
4946 mutex_lock(&priv->mutex);
4947
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004948 if (!iwl_is_ready(priv)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004949 IWL_WARN(priv, "request scan called when driver not ready.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004950 goto done;
4951 }
4952
Tomas Winklera96a27f2008-10-23 23:48:56 -07004953 /* Make sure the scan wasn't canceled before this queued work
Zhu Yib481de92007-09-25 17:54:57 -07004954 * was given the chance to run... */
4955 if (!test_bit(STATUS_SCANNING, &priv->status))
4956 goto done;
4957
4958 /* This should never be called or scheduled if there is currently
4959 * a scan active in the hardware. */
4960 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
4961 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
4962 "Ignoring second request.\n");
4963 rc = -EIO;
4964 goto done;
4965 }
4966
4967 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
4968 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
4969 goto done;
4970 }
4971
4972 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
4973 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
4974 goto done;
4975 }
4976
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004977 if (iwl_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004978 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
4979 goto done;
4980 }
4981
4982 if (!test_bit(STATUS_READY, &priv->status)) {
4983 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
4984 goto done;
4985 }
4986
4987 if (!priv->scan_bands) {
4988 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
4989 goto done;
4990 }
4991
Winkler, Tomas805cee52009-01-19 15:30:28 -08004992 if (!priv->scan) {
4993 priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
Zhu Yib481de92007-09-25 17:54:57 -07004994 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
Winkler, Tomas805cee52009-01-19 15:30:28 -08004995 if (!priv->scan) {
Zhu Yib481de92007-09-25 17:54:57 -07004996 rc = -ENOMEM;
4997 goto done;
4998 }
4999 }
Winkler, Tomas805cee52009-01-19 15:30:28 -08005000 scan = priv->scan;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005001 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07005002
5003 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
5004 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
5005
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005006 if (iwl3945_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005007 u16 interval = 0;
5008 u32 extra;
5009 u32 suspend_time = 100;
5010 u32 scan_suspend_time = 100;
5011 unsigned long flags;
5012
5013 IWL_DEBUG_INFO("Scanning while associated...\n");
5014
5015 spin_lock_irqsave(&priv->lock, flags);
5016 interval = priv->beacon_int;
5017 spin_unlock_irqrestore(&priv->lock, flags);
5018
5019 scan->suspend_time = 0;
Mohamed Abbas15e869d2007-10-25 17:15:46 +08005020 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07005021 if (!interval)
5022 interval = suspend_time;
5023 /*
5024 * suspend time format:
5025 * 0-19: beacon interval in usec (time before exec.)
5026 * 20-23: 0
5027 * 24-31: number of beacons (suspend between channels)
5028 */
5029
5030 extra = (suspend_time / interval) << 24;
5031 scan_suspend_time = 0xFF0FFFFF &
5032 (extra | ((suspend_time % interval) * 1024));
5033
5034 scan->suspend_time = cpu_to_le32(scan_suspend_time);
5035 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
5036 scan_suspend_time, interval);
5037 }
5038
5039 /* We should add the ability for user to lock to PASSIVE ONLY */
5040 if (priv->one_direct_scan) {
5041 IWL_DEBUG_SCAN
5042 ("Kicking off one direct scan for '%s'\n",
John W. Linville9387b7c2008-09-30 20:59:05 -04005043 print_ssid(ssid, priv->direct_ssid,
5044 priv->direct_ssid_len));
Zhu Yib481de92007-09-25 17:54:57 -07005045 scan->direct_scan[0].id = WLAN_EID_SSID;
5046 scan->direct_scan[0].len = priv->direct_ssid_len;
5047 memcpy(scan->direct_scan[0].ssid,
5048 priv->direct_ssid, priv->direct_ssid_len);
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08005049 n_probes++;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08005050 } else
Bill Moss786b4552008-04-17 16:03:40 -07005051 IWL_DEBUG_SCAN("Kicking off one indirect scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07005052
5053 /* We don't build a direct scan probe request; the uCode will do
5054 * that based on the direct_mask added to each channel entry */
Zhu Yib481de92007-09-25 17:54:57 -07005055 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005056 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07005057 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
5058
5059 /* flags + rate selection */
5060
Ron Rindjunsky66b50042008-06-25 16:46:31 +08005061 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07005062 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
5063 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
5064 scan->good_CRC_th = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01005065 band = IEEE80211_BAND_2GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08005066 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07005067 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
5068 scan->good_CRC_th = IWL_GOOD_CRC_TH;
Johannes Berg8318d782008-01-24 19:38:38 +01005069 band = IEEE80211_BAND_5GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08005070 } else {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08005071 IWL_WARN(priv, "Invalid scan band count\n");
Zhu Yib481de92007-09-25 17:54:57 -07005072 goto done;
5073 }
5074
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08005075 scan->tx_cmd.len = cpu_to_le16(
5076 iwl_fill_probe_req(priv, band,
5077 (struct ieee80211_mgmt *)scan->data,
5078 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
5079
Zhu Yib481de92007-09-25 17:54:57 -07005080 /* select Rx antennas */
5081 scan->flags |= iwl3945_get_antenna_flags(priv);
5082
Johannes Berg05c914f2008-09-11 00:01:58 +02005083 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
Zhu Yib481de92007-09-25 17:54:57 -07005084 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
5085
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08005086 scan->channel_count =
5087 iwl3945_get_channels_for_scan(priv, band, 1, /* active */
5088 n_probes,
5089 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
Zhu Yib481de92007-09-25 17:54:57 -07005090
Reinette Chatre14b54332008-11-04 12:21:35 -08005091 if (scan->channel_count == 0) {
5092 IWL_DEBUG_SCAN("channel count %d\n", scan->channel_count);
5093 goto done;
5094 }
5095
Zhu Yib481de92007-09-25 17:54:57 -07005096 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005097 scan->channel_count * sizeof(struct iwl3945_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07005098 cmd.data = scan;
5099 scan->len = cpu_to_le16(cmd.len);
5100
5101 set_bit(STATUS_SCAN_HW, &priv->status);
Samuel Ortiz518099a2009-01-19 15:30:27 -08005102 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07005103 if (rc)
5104 goto done;
5105
5106 queue_delayed_work(priv->workqueue, &priv->scan_check,
5107 IWL_SCAN_CHECK_WATCHDOG);
5108
5109 mutex_unlock(&priv->mutex);
5110 return;
5111
5112 done:
Mohamed Abbas2420ebc2008-11-04 12:21:34 -08005113 /* can not perform scan make sure we clear scanning
5114 * bits from status so next scan request can be performed.
5115 * if we dont clear scanning status bit here all next scan
5116 * will fail
5117 */
5118 clear_bit(STATUS_SCAN_HW, &priv->status);
5119 clear_bit(STATUS_SCANNING, &priv->status);
5120
Ian Schram01ebd062007-10-25 17:15:22 +08005121 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07005122 queue_work(priv->workqueue, &priv->scan_completed);
5123 mutex_unlock(&priv->mutex);
5124}
5125
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005126static void iwl3945_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07005127{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005128 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07005129
5130 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5131 return;
5132
5133 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005134 __iwl3945_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005135 mutex_unlock(&priv->mutex);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005136 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005137}
5138
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005139static void iwl3945_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07005140{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005141 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07005142
5143 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5144 return;
5145
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005146 iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005147 queue_work(priv->workqueue, &priv->up);
5148}
5149
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005150static void iwl3945_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07005151{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005152 struct iwl_priv *priv =
5153 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07005154
5155 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5156 return;
5157
5158 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005159 iwl3945_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005160 mutex_unlock(&priv->mutex);
5161}
5162
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08005163#define IWL_DELAY_NEXT_SCAN (HZ*2)
5164
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005165static void iwl3945_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005166{
Zhu Yib481de92007-09-25 17:54:57 -07005167 int rc = 0;
5168 struct ieee80211_conf *conf = NULL;
5169
Johannes Berg05c914f2008-09-11 00:01:58 +02005170 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005171 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07005172 return;
5173 }
5174
5175
Johannes Berge1749612008-10-27 15:59:26 -07005176 IWL_DEBUG_ASSOC("Associated as %d to: %pM\n",
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005177 priv->assoc_id, priv->active39_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07005178
5179 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
5180 return;
5181
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08005182 if (!priv->vif || !priv->is_open)
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08005183 return;
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08005184
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08005185 iwl_scan_cancel_timeout(priv, 200);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08005186
Zhu Yib481de92007-09-25 17:54:57 -07005187 conf = ieee80211_get_hw_conf(priv->hw);
5188
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005189 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005190 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005191
Tomas Winkler28afaf92008-12-19 10:37:06 +08005192 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005193 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08005194 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07005195 sizeof(priv->rxon_timing), &priv->rxon_timing);
5196 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08005197 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07005198 "Attempting to continue.\n");
5199
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005200 priv->staging39_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07005201
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005202 priv->staging39_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07005203
5204 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
5205 priv->assoc_id, priv->beacon_int);
5206
5207 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005208 priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07005209 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005210 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07005211
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005212 if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07005213 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005214 priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07005215 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005216 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07005217
Johannes Berg05c914f2008-09-11 00:01:58 +02005218 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005219 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07005220
5221 }
5222
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005223 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005224
5225 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02005226 case NL80211_IFTYPE_STATION:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005227 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07005228 break;
5229
Johannes Berg05c914f2008-09-11 00:01:58 +02005230 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07005231
Abhijeet Kolekarce546fd2008-11-19 15:32:22 -08005232 priv->assoc_id = 1;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005233 iwl3945_add_station(priv, priv->bssid, 0, 0);
Zhu Yib481de92007-09-25 17:54:57 -07005234 iwl3945_sync_sta(priv, IWL_STA_ID,
Johannes Berg8318d782008-01-24 19:38:38 +01005235 (priv->band == IEEE80211_BAND_5GHZ) ?
Zhu Yib481de92007-09-25 17:54:57 -07005236 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
5237 CMD_ASYNC);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005238 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
5239 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005240
5241 break;
5242
5243 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08005244 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005245 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07005246 break;
5247 }
5248
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005249 iwl3945_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08005250
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08005251 /* we have just associated, don't start scan too early */
5252 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005253}
5254
Johannes Berge8975582008-10-09 12:18:51 +02005255static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
Zhu Yi76bb77e2007-11-22 10:53:22 +08005256
Zhu Yib481de92007-09-25 17:54:57 -07005257/*****************************************************************************
5258 *
5259 * mac80211 entry point functions
5260 *
5261 *****************************************************************************/
5262
Zhu Yi5a669262008-01-14 17:46:18 -08005263#define UCODE_READY_TIMEOUT (2 * HZ)
5264
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005265static int iwl3945_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07005266{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005267 struct iwl_priv *priv = hw->priv;
Zhu Yi5a669262008-01-14 17:46:18 -08005268 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07005269
5270 IWL_DEBUG_MAC80211("enter\n");
5271
5272 /* we should be verifying the device is ready to be opened */
5273 mutex_lock(&priv->mutex);
5274
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005275 memset(&priv->staging39_rxon, 0, sizeof(struct iwl3945_rxon_cmd));
Zhu Yi5a669262008-01-14 17:46:18 -08005276 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
5277 * ucode filename and max sizes are card-specific. */
5278
5279 if (!priv->ucode_code.len) {
5280 ret = iwl3945_read_ucode(priv);
5281 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005282 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a669262008-01-14 17:46:18 -08005283 mutex_unlock(&priv->mutex);
5284 goto out_release_irq;
5285 }
5286 }
5287
Zhu Yie655b9f2008-01-24 02:19:38 -08005288 ret = __iwl3945_up(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08005289
Zhu Yib481de92007-09-25 17:54:57 -07005290 mutex_unlock(&priv->mutex);
Zhu Yi5a669262008-01-14 17:46:18 -08005291
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005292 iwl_rfkill_set_hw_state(priv);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02005293
Zhu Yie655b9f2008-01-24 02:19:38 -08005294 if (ret)
5295 goto out_release_irq;
5296
5297 IWL_DEBUG_INFO("Start UP work.\n");
5298
5299 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
5300 return 0;
5301
Zhu Yi5a669262008-01-14 17:46:18 -08005302 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
5303 * mac80211 will not be run successfully. */
5304 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
5305 test_bit(STATUS_READY, &priv->status),
5306 UCODE_READY_TIMEOUT);
5307 if (!ret) {
5308 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005309 IWL_ERR(priv,
5310 "Wait for START_ALIVE timeout after %dms.\n",
5311 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Zhu Yi5a669262008-01-14 17:46:18 -08005312 ret = -ETIMEDOUT;
5313 goto out_release_irq;
5314 }
5315 }
5316
Helmut Schaa26635162009-01-15 09:38:44 +01005317 /* ucode is running and will send rfkill notifications,
5318 * no need to poll the killswitch state anymore */
5319 cancel_delayed_work(&priv->rfkill_poll);
5320
Zhu Yie655b9f2008-01-24 02:19:38 -08005321 priv->is_open = 1;
Zhu Yib481de92007-09-25 17:54:57 -07005322 IWL_DEBUG_MAC80211("leave\n");
5323 return 0;
Zhu Yi5a669262008-01-14 17:46:18 -08005324
5325out_release_irq:
Zhu Yie655b9f2008-01-24 02:19:38 -08005326 priv->is_open = 0;
5327 IWL_DEBUG_MAC80211("leave - failed\n");
Zhu Yi5a669262008-01-14 17:46:18 -08005328 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07005329}
5330
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005331static void iwl3945_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07005332{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005333 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07005334
5335 IWL_DEBUG_MAC80211("enter\n");
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08005336
Zhu Yie655b9f2008-01-24 02:19:38 -08005337 if (!priv->is_open) {
5338 IWL_DEBUG_MAC80211("leave - skip\n");
5339 return;
5340 }
5341
Zhu Yib481de92007-09-25 17:54:57 -07005342 priv->is_open = 0;
Zhu Yi5a669262008-01-14 17:46:18 -08005343
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005344 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08005345 /* stop mac, cancel any scan request and clear
5346 * RXON_FILTER_ASSOC_MSK BIT
5347 */
Zhu Yi5a669262008-01-14 17:46:18 -08005348 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08005349 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08005350 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08005351 }
5352
Zhu Yi5a669262008-01-14 17:46:18 -08005353 iwl3945_down(priv);
5354
5355 flush_workqueue(priv->workqueue);
Helmut Schaa26635162009-01-15 09:38:44 +01005356
5357 /* start polling the killswitch state again */
5358 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
5359 round_jiffies_relative(2 * HZ));
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08005360
Zhu Yib481de92007-09-25 17:54:57 -07005361 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07005362}
5363
Johannes Berge039fa42008-05-15 12:55:29 +02005364static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07005365{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005366 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07005367
5368 IWL_DEBUG_MAC80211("enter\n");
5369
Zhu Yib481de92007-09-25 17:54:57 -07005370 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02005371 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07005372
Johannes Berge039fa42008-05-15 12:55:29 +02005373 if (iwl3945_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07005374 dev_kfree_skb_any(skb);
5375
5376 IWL_DEBUG_MAC80211("leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08005377 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07005378}
5379
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005380static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07005381 struct ieee80211_if_init_conf *conf)
5382{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005383 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07005384 unsigned long flags;
5385
Johannes Berg32bfd352007-12-19 01:31:26 +01005386 IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07005387
Johannes Berg32bfd352007-12-19 01:31:26 +01005388 if (priv->vif) {
5389 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
Tomas Winkler864792e2007-11-27 21:00:52 +02005390 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07005391 }
5392
5393 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01005394 priv->vif = conf->vif;
Zhu, Yi60294de2008-10-29 14:05:45 -07005395 priv->iw_mode = conf->type;
Zhu Yib481de92007-09-25 17:54:57 -07005396
5397 spin_unlock_irqrestore(&priv->lock, flags);
5398
5399 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02005400
5401 if (conf->mac_addr) {
Johannes Berge1749612008-10-27 15:59:26 -07005402 IWL_DEBUG_MAC80211("Set: %pM\n", conf->mac_addr);
Tomas Winkler864792e2007-11-27 21:00:52 +02005403 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
5404 }
5405
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005406 if (iwl_is_ready(priv))
Zhu Yi5a669262008-01-14 17:46:18 -08005407 iwl3945_set_mode(priv, conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07005408
Zhu Yib481de92007-09-25 17:54:57 -07005409 mutex_unlock(&priv->mutex);
5410
Zhu Yi5a669262008-01-14 17:46:18 -08005411 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07005412 return 0;
5413}
5414
5415/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005416 * iwl3945_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07005417 *
5418 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
5419 * be set inappropriately and the driver currently sets the hardware up to
5420 * use it whenever needed.
5421 */
Johannes Berge8975582008-10-09 12:18:51 +02005422static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
Zhu Yib481de92007-09-25 17:54:57 -07005423{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005424 struct iwl_priv *priv = hw->priv;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08005425 const struct iwl_channel_info *ch_info;
Johannes Berge8975582008-10-09 12:18:51 +02005426 struct ieee80211_conf *conf = &hw->conf;
Zhu Yib481de92007-09-25 17:54:57 -07005427 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08005428 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07005429
5430 mutex_lock(&priv->mutex);
Johannes Berg8318d782008-01-24 19:38:38 +01005431 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07005432
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005433 if (!iwl_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005434 IWL_DEBUG_MAC80211("leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08005435 ret = -EIO;
5436 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07005437 }
5438
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005439 if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07005440 test_bit(STATUS_SCANNING, &priv->status))) {
Zhu Yia0646472007-12-20 14:10:01 +08005441 IWL_DEBUG_MAC80211("leave - scanning\n");
5442 set_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07005443 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08005444 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07005445 }
5446
5447 spin_lock_irqsave(&priv->lock, flags);
5448
Johannes Berg8318d782008-01-24 19:38:38 +01005449 ch_info = iwl3945_get_channel_info(priv, conf->channel->band,
5450 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07005451 if (!is_channel_valid(ch_info)) {
Ron Rindjunsky66b50042008-06-25 16:46:31 +08005452 IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this band.\n",
Johannes Berg8318d782008-01-24 19:38:38 +01005453 conf->channel->hw_value, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07005454 IWL_DEBUG_MAC80211("leave - invalid channel\n");
5455 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yi76bb77e2007-11-22 10:53:22 +08005456 ret = -EINVAL;
5457 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07005458 }
5459
Johannes Berg8318d782008-01-24 19:38:38 +01005460 iwl3945_set_rxon_channel(priv, conf->channel->band, conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07005461
Johannes Berg8318d782008-01-24 19:38:38 +01005462 iwl3945_set_flags_for_phymode(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07005463
5464 /* The list of supported rates and rate mask can be different
5465 * for each phymode; since the phymode may have changed, reset
5466 * the rate mask to what mac80211 lists */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005467 iwl3945_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005468
5469 spin_unlock_irqrestore(&priv->lock, flags);
5470
5471#ifdef IEEE80211_CONF_CHANNEL_SWITCH
5472 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005473 iwl3945_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08005474 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07005475 }
5476#endif
5477
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005478 iwl3945_radio_kill_sw(priv, !conf->radio_enabled);
Zhu Yib481de92007-09-25 17:54:57 -07005479
5480 if (!conf->radio_enabled) {
5481 IWL_DEBUG_MAC80211("leave - radio disabled\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08005482 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07005483 }
5484
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005485 if (iwl_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005486 IWL_DEBUG_MAC80211("leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08005487 ret = -EIO;
5488 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07005489 }
5490
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005491 iwl3945_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005492
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005493 if (memcmp(&priv->active39_rxon,
5494 &priv->staging39_rxon, sizeof(priv->staging39_rxon)))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005495 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005496 else
5497 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
5498
5499 IWL_DEBUG_MAC80211("leave\n");
5500
Zhu Yi76bb77e2007-11-22 10:53:22 +08005501out:
Zhu Yia0646472007-12-20 14:10:01 +08005502 clear_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07005503 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08005504 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07005505}
5506
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005507static void iwl3945_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005508{
5509 int rc = 0;
5510
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08005511 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07005512 return;
5513
5514 /* The following should be done only at AP bring up */
Ron Rindjunsky5d1e2322008-06-30 17:23:04 +08005515 if (!(iwl3945_is_associated(priv))) {
Zhu Yib481de92007-09-25 17:54:57 -07005516
5517 /* RXON - unassoc (to set timing command) */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005518 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005519 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005520
5521 /* RXON Timing */
Tomas Winkler28afaf92008-12-19 10:37:06 +08005522 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005523 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08005524 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
5525 sizeof(priv->rxon_timing),
5526 &priv->rxon_timing);
Zhu Yib481de92007-09-25 17:54:57 -07005527 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08005528 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07005529 "Attempting to continue.\n");
5530
5531 /* FIXME: what should be the assoc_id for AP? */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005532 priv->staging39_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07005533 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005534 priv->staging39_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07005535 RXON_FLG_SHORT_PREAMBLE_MSK;
5536 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005537 priv->staging39_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07005538 ~RXON_FLG_SHORT_PREAMBLE_MSK;
5539
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005540 if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07005541 if (priv->assoc_capability &
5542 WLAN_CAPABILITY_SHORT_SLOT_TIME)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005543 priv->staging39_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07005544 RXON_FLG_SHORT_SLOT_MSK;
5545 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005546 priv->staging39_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07005547 ~RXON_FLG_SHORT_SLOT_MSK;
5548
Johannes Berg05c914f2008-09-11 00:01:58 +02005549 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005550 priv->staging39_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07005551 ~RXON_FLG_SHORT_SLOT_MSK;
5552 }
5553 /* restore RXON assoc */
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005554 priv->staging39_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005555 iwl3945_commit_rxon(priv);
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +08005556 iwl3945_add_station(priv, iwl_bcast_addr, 0, 0);
Zhu Yi556f8db2007-09-27 11:27:33 +08005557 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005558 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005559
5560 /* FIXME - we need to add code here to detect a totally new
5561 * configuration, reset the AP, unassoc, rxon timing, assoc,
5562 * clear sta table, add BCAST sta... */
5563}
5564
Johannes Berg32bfd352007-12-19 01:31:26 +01005565static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
5566 struct ieee80211_vif *vif,
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005567 struct ieee80211_if_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07005568{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005569 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07005570 int rc;
5571
5572 if (conf == NULL)
5573 return -EIO;
5574
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08005575 if (priv->vif != vif) {
5576 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08005577 return 0;
5578 }
5579
Johannes Berg9d139c82008-07-09 14:40:37 +02005580 /* handle this temporarily here */
Johannes Berg05c914f2008-09-11 00:01:58 +02005581 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Johannes Berg9d139c82008-07-09 14:40:37 +02005582 conf->changed & IEEE80211_IFCC_BEACON) {
5583 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
5584 if (!beacon)
5585 return -ENOMEM;
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08005586 mutex_lock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02005587 rc = iwl3945_mac_beacon_update(hw, beacon);
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08005588 mutex_unlock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02005589 if (rc)
5590 return rc;
5591 }
5592
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005593 if (!iwl_is_alive(priv))
Zhu Yi5a669262008-01-14 17:46:18 -08005594 return -EAGAIN;
5595
Zhu Yib481de92007-09-25 17:54:57 -07005596 mutex_lock(&priv->mutex);
5597
Zhu Yib481de92007-09-25 17:54:57 -07005598 if (conf->bssid)
Johannes Berge1749612008-10-27 15:59:26 -07005599 IWL_DEBUG_MAC80211("bssid: %pM\n", conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07005600
Johannes Berg4150c572007-09-17 01:29:23 -04005601/*
5602 * very dubious code was here; the probe filtering flag is never set:
5603 *
Zhu Yib481de92007-09-25 17:54:57 -07005604 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
5605 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04005606 */
Zhu Yib481de92007-09-25 17:54:57 -07005607
Johannes Berg05c914f2008-09-11 00:01:58 +02005608 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07005609 if (!conf->bssid) {
5610 conf->bssid = priv->mac_addr;
5611 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -07005612 IWL_DEBUG_MAC80211("bssid was set to: %pM\n",
5613 conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07005614 }
5615 if (priv->ibss_beacon)
5616 dev_kfree_skb(priv->ibss_beacon);
5617
Johannes Berg9d139c82008-07-09 14:40:37 +02005618 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
Zhu Yib481de92007-09-25 17:54:57 -07005619 }
5620
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005621 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08005622 goto done;
5623
Zhu Yib481de92007-09-25 17:54:57 -07005624 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
5625 !is_multicast_ether_addr(conf->bssid)) {
5626 /* If there is currently a HW scan going on in the background
5627 * then we need to cancel it else the RXON below will fail. */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08005628 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08005629 IWL_WARN(priv, "Aborted scan still in progress "
Zhu Yib481de92007-09-25 17:54:57 -07005630 "after 100ms\n");
5631 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
5632 mutex_unlock(&priv->mutex);
5633 return -EAGAIN;
5634 }
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005635 memcpy(priv->staging39_rxon.bssid_addr, conf->bssid, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07005636
5637 /* TODO: Audit driver for usage of these members and see
5638 * if mac80211 deprecates them (priv->bssid looks like it
5639 * shouldn't be there, but I haven't scanned the IBSS code
5640 * to verify) - jpk */
5641 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
5642
Johannes Berg05c914f2008-09-11 00:01:58 +02005643 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005644 iwl3945_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005645 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005646 rc = iwl3945_commit_rxon(priv);
Johannes Berg05c914f2008-09-11 00:01:58 +02005647 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005648 iwl3945_add_station(priv,
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005649 priv->active39_rxon.bssid_addr, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07005650 }
5651
5652 } else {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08005653 iwl_scan_cancel_timeout(priv, 100);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005654 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005655 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005656 }
5657
Mohamed Abbasfde35712007-11-29 11:10:15 +08005658 done:
Zhu Yib481de92007-09-25 17:54:57 -07005659 IWL_DEBUG_MAC80211("leave\n");
5660 mutex_unlock(&priv->mutex);
5661
5662 return 0;
5663}
5664
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005665static void iwl3945_configure_filter(struct ieee80211_hw *hw,
Johannes Berg4150c572007-09-17 01:29:23 -04005666 unsigned int changed_flags,
5667 unsigned int *total_flags,
5668 int mc_count, struct dev_addr_list *mc_list)
5669{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005670 struct iwl_priv *priv = hw->priv;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005671 __le32 *filter_flags = &priv->staging39_rxon.filter_flags;
Rick Farrington25b3f572008-06-30 17:23:28 +08005672
Zhu, Yi352bc8d2008-11-12 13:14:09 -08005673 IWL_DEBUG_MAC80211("Enter: changed: 0x%x, total: 0x%x\n",
5674 changed_flags, *total_flags);
5675
5676 if (changed_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) {
5677 if (*total_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS))
5678 *filter_flags |= RXON_FILTER_PROMISC_MSK;
5679 else
5680 *filter_flags &= ~RXON_FILTER_PROMISC_MSK;
Abhijeet Kolekar5ec03972008-05-05 10:22:48 +08005681 }
Zhu, Yi352bc8d2008-11-12 13:14:09 -08005682 if (changed_flags & FIF_ALLMULTI) {
5683 if (*total_flags & FIF_ALLMULTI)
5684 *filter_flags |= RXON_FILTER_ACCEPT_GRP_MSK;
5685 else
5686 *filter_flags &= ~RXON_FILTER_ACCEPT_GRP_MSK;
5687 }
5688 if (changed_flags & FIF_CONTROL) {
5689 if (*total_flags & FIF_CONTROL)
5690 *filter_flags |= RXON_FILTER_CTL2HOST_MSK;
5691 else
5692 *filter_flags &= ~RXON_FILTER_CTL2HOST_MSK;
5693 }
5694 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
5695 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
5696 *filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
5697 else
5698 *filter_flags &= ~RXON_FILTER_BCON_AWARE_MSK;
5699 }
5700
5701 /* We avoid iwl_commit_rxon here to commit the new filter flags
5702 * since mac80211 will call ieee80211_hw_config immediately.
5703 * (mc_list is not supported at this time). Otherwise, we need to
5704 * queue a background iwl_commit_rxon work.
5705 */
5706
5707 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
Rick Farrington25b3f572008-06-30 17:23:28 +08005708 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
Johannes Berg4150c572007-09-17 01:29:23 -04005709}
5710
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005711static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07005712 struct ieee80211_if_init_conf *conf)
5713{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005714 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07005715
5716 IWL_DEBUG_MAC80211("enter\n");
5717
5718 mutex_lock(&priv->mutex);
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08005719
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005720 if (iwl_is_ready_rf(priv)) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08005721 iwl_scan_cancel_timeout(priv, 100);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005722 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Mohamed Abbasfde35712007-11-29 11:10:15 +08005723 iwl3945_commit_rxon(priv);
5724 }
Johannes Berg32bfd352007-12-19 01:31:26 +01005725 if (priv->vif == conf->vif) {
5726 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07005727 memset(priv->bssid, 0, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07005728 }
5729 mutex_unlock(&priv->mutex);
5730
5731 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07005732}
5733
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005734#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
5735
5736static void iwl3945_bss_info_changed(struct ieee80211_hw *hw,
5737 struct ieee80211_vif *vif,
5738 struct ieee80211_bss_conf *bss_conf,
5739 u32 changes)
5740{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005741 struct iwl_priv *priv = hw->priv;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005742
5743 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
5744
5745 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
5746 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
5747 bss_conf->use_short_preamble);
5748 if (bss_conf->use_short_preamble)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005749 priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005750 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005751 priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005752 }
5753
5754 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
5755 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
5756 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005757 priv->staging39_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005758 else
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08005759 priv->staging39_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005760 }
5761
5762 if (changes & BSS_CHANGED_ASSOC) {
5763 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
5764 /* This should never happen as this function should
5765 * never be called from interrupt context. */
5766 if (WARN_ON_ONCE(in_interrupt()))
5767 return;
5768 if (bss_conf->assoc) {
5769 priv->assoc_id = bss_conf->aid;
5770 priv->beacon_int = bss_conf->beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08005771 priv->timestamp = bss_conf->timestamp;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005772 priv->assoc_capability = bss_conf->assoc_capability;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08005773 priv->power_data.dtim_period = bss_conf->dtim_period;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005774 priv->next_scan_jiffies = jiffies +
5775 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
5776 mutex_lock(&priv->mutex);
5777 iwl3945_post_associate(priv);
5778 mutex_unlock(&priv->mutex);
5779 } else {
5780 priv->assoc_id = 0;
5781 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
5782 }
5783 } else if (changes && iwl3945_is_associated(priv) && priv->assoc_id) {
5784 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
5785 iwl3945_send_rxon_assoc(priv);
5786 }
5787
5788}
5789
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005790static int iwl3945_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
Zhu Yib481de92007-09-25 17:54:57 -07005791{
5792 int rc = 0;
5793 unsigned long flags;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005794 struct iwl_priv *priv = hw->priv;
John W. Linville9387b7c2008-09-30 20:59:05 -04005795 DECLARE_SSID_BUF(ssid_buf);
Zhu Yib481de92007-09-25 17:54:57 -07005796
5797 IWL_DEBUG_MAC80211("enter\n");
5798
Mohamed Abbas15e869d2007-10-25 17:15:46 +08005799 mutex_lock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07005800 spin_lock_irqsave(&priv->lock, flags);
5801
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005802 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005803 rc = -EIO;
5804 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
5805 goto out_unlock;
5806 }
5807
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08005808 /* we don't schedule scan within next_scan_jiffies period */
5809 if (priv->next_scan_jiffies &&
5810 time_after(priv->next_scan_jiffies, jiffies)) {
5811 rc = -EAGAIN;
5812 goto out_unlock;
5813 }
Bill Moss15dbf1b2008-05-06 11:05:15 +08005814 /* if we just finished scan ask for delay for a broadcast scan */
5815 if ((len == 0) && priv->last_scan_jiffies &&
5816 time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN,
5817 jiffies)) {
Zhu Yib481de92007-09-25 17:54:57 -07005818 rc = -EAGAIN;
5819 goto out_unlock;
5820 }
5821 if (len) {
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08005822 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
John W. Linville9387b7c2008-09-30 20:59:05 -04005823 print_ssid(ssid_buf, ssid, len), (int)len);
Zhu Yib481de92007-09-25 17:54:57 -07005824
5825 priv->one_direct_scan = 1;
5826 priv->direct_ssid_len = (u8)
5827 min((u8) len, (u8) IW_ESSID_MAX_SIZE);
5828 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08005829 } else
5830 priv->one_direct_scan = 0;
Zhu Yib481de92007-09-25 17:54:57 -07005831
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005832 rc = iwl3945_scan_initiate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005833
5834 IWL_DEBUG_MAC80211("leave\n");
5835
5836out_unlock:
5837 spin_unlock_irqrestore(&priv->lock, flags);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08005838 mutex_unlock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07005839
5840 return rc;
5841}
5842
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005843static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01005844 struct ieee80211_vif *vif,
5845 struct ieee80211_sta *sta,
5846 struct ieee80211_key_conf *key)
Zhu Yib481de92007-09-25 17:54:57 -07005847{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005848 struct iwl_priv *priv = hw->priv;
Johannes Bergdc822b52008-12-29 12:55:09 +01005849 const u8 *addr;
Winkler, Tomas42986792009-01-19 15:30:22 -08005850 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07005851 u8 sta_id;
5852
5853 IWL_DEBUG_MAC80211("enter\n");
5854
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005855 if (iwl3945_mod_params.sw_crypto) {
Zhu Yib481de92007-09-25 17:54:57 -07005856 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
5857 return -EOPNOTSUPP;
5858 }
5859
Winkler, Tomas42986792009-01-19 15:30:22 -08005860 addr = sta ? sta->addr : iwl_bcast_addr;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005861 sta_id = iwl3945_hw_find_station(priv, addr);
Zhu Yib481de92007-09-25 17:54:57 -07005862 if (sta_id == IWL_INVALID_STATION) {
Johannes Berge1749612008-10-27 15:59:26 -07005863 IWL_DEBUG_MAC80211("leave - %pM not in station map.\n",
5864 addr);
Zhu Yib481de92007-09-25 17:54:57 -07005865 return -EINVAL;
5866 }
5867
5868 mutex_lock(&priv->mutex);
5869
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08005870 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08005871
Zhu Yib481de92007-09-25 17:54:57 -07005872 switch (cmd) {
5873 case SET_KEY:
Winkler, Tomas42986792009-01-19 15:30:22 -08005874 ret = iwl3945_update_sta_key_info(priv, key, sta_id);
5875 if (!ret) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005876 iwl3945_set_rxon_hwcrypto(priv, 1);
5877 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005878 key->hw_key_idx = sta_id;
5879 IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n");
5880 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
5881 }
5882 break;
5883 case DISABLE_KEY:
Winkler, Tomas42986792009-01-19 15:30:22 -08005884 ret = iwl3945_clear_sta_key_info(priv, sta_id);
5885 if (!ret) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005886 iwl3945_set_rxon_hwcrypto(priv, 0);
5887 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005888 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
5889 }
5890 break;
5891 default:
Winkler, Tomas42986792009-01-19 15:30:22 -08005892 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07005893 }
5894
5895 IWL_DEBUG_MAC80211("leave\n");
5896 mutex_unlock(&priv->mutex);
5897
Winkler, Tomas42986792009-01-19 15:30:22 -08005898 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07005899}
5900
Johannes Berge100bb62008-04-30 18:51:21 +02005901static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
Zhu Yib481de92007-09-25 17:54:57 -07005902 const struct ieee80211_tx_queue_params *params)
5903{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005904 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07005905 unsigned long flags;
5906 int q;
Zhu Yib481de92007-09-25 17:54:57 -07005907
5908 IWL_DEBUG_MAC80211("enter\n");
5909
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005910 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005911 IWL_DEBUG_MAC80211("leave - RF not ready\n");
5912 return -EIO;
5913 }
5914
5915 if (queue >= AC_NUM) {
5916 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
5917 return 0;
5918 }
5919
Zhu Yib481de92007-09-25 17:54:57 -07005920 q = AC_NUM - 1 - queue;
5921
5922 spin_lock_irqsave(&priv->lock, flags);
5923
5924 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
5925 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
5926 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
5927 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7be2008-02-10 16:49:38 +01005928 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07005929
5930 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
5931 priv->qos_data.qos_active = 1;
5932
5933 spin_unlock_irqrestore(&priv->lock, flags);
5934
5935 mutex_lock(&priv->mutex);
Johannes Berg05c914f2008-09-11 00:01:58 +02005936 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005937 iwl3945_activate_qos(priv, 1);
5938 else if (priv->assoc_id && iwl3945_is_associated(priv))
5939 iwl3945_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07005940
5941 mutex_unlock(&priv->mutex);
5942
Zhu Yib481de92007-09-25 17:54:57 -07005943 IWL_DEBUG_MAC80211("leave\n");
5944 return 0;
5945}
5946
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005947static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07005948 struct ieee80211_tx_queue_stats *stats)
5949{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005950 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07005951 int i, avail;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08005952 struct iwl_tx_queue *txq;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08005953 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07005954 unsigned long flags;
5955
5956 IWL_DEBUG_MAC80211("enter\n");
5957
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005958 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005959 IWL_DEBUG_MAC80211("leave - RF not ready\n");
5960 return -EIO;
5961 }
5962
5963 spin_lock_irqsave(&priv->lock, flags);
5964
5965 for (i = 0; i < AC_NUM; i++) {
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08005966 txq = &priv->txq[i];
Zhu Yib481de92007-09-25 17:54:57 -07005967 q = &txq->q;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08005968 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07005969
Johannes Berg57ffc582008-04-29 17:18:59 +02005970 stats[i].len = q->n_window - avail;
5971 stats[i].limit = q->n_window - q->high_mark;
5972 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07005973
5974 }
5975 spin_unlock_irqrestore(&priv->lock, flags);
5976
5977 IWL_DEBUG_MAC80211("leave\n");
5978
5979 return 0;
5980}
5981
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005982static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07005983{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005984 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07005985 unsigned long flags;
5986
5987 mutex_lock(&priv->mutex);
5988 IWL_DEBUG_MAC80211("enter\n");
5989
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005990 iwl_reset_qos(priv);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08005991
Zhu Yib481de92007-09-25 17:54:57 -07005992 spin_lock_irqsave(&priv->lock, flags);
5993 priv->assoc_id = 0;
5994 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07005995
5996 /* new association get rid of ibss beacon skb */
5997 if (priv->ibss_beacon)
5998 dev_kfree_skb(priv->ibss_beacon);
5999
6000 priv->ibss_beacon = NULL;
6001
6002 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08006003 priv->timestamp = 0;
Johannes Berg05c914f2008-09-11 00:01:58 +02006004 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
Zhu Yib481de92007-09-25 17:54:57 -07006005 priv->beacon_int = 0;
6006
6007 spin_unlock_irqrestore(&priv->lock, flags);
6008
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08006009 if (!iwl_is_ready_rf(priv)) {
Mohamed Abbasfde35712007-11-29 11:10:15 +08006010 IWL_DEBUG_MAC80211("leave - not ready\n");
6011 mutex_unlock(&priv->mutex);
6012 return;
6013 }
6014
Mohamed Abbas15e869d2007-10-25 17:15:46 +08006015 /* we are restarting association process
6016 * clear RXON_FILTER_ASSOC_MSK bit
6017 */
Johannes Berg05c914f2008-09-11 00:01:58 +02006018 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08006019 iwl_scan_cancel_timeout(priv, 100);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08006020 priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006021 iwl3945_commit_rxon(priv);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08006022 }
6023
Zhu Yib481de92007-09-25 17:54:57 -07006024 /* Per mac80211.h: This is only used in IBSS mode... */
Johannes Berg05c914f2008-09-11 00:01:58 +02006025 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Mohamed Abbas15e869d2007-10-25 17:15:46 +08006026
Zhu Yib481de92007-09-25 17:54:57 -07006027 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
6028 mutex_unlock(&priv->mutex);
6029 return;
6030 }
6031
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006032 iwl3945_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006033
6034 mutex_unlock(&priv->mutex);
6035
6036 IWL_DEBUG_MAC80211("leave\n");
6037
6038}
6039
Johannes Berge039fa42008-05-15 12:55:29 +02006040static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07006041{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006042 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07006043 unsigned long flags;
6044
Zhu Yib481de92007-09-25 17:54:57 -07006045 IWL_DEBUG_MAC80211("enter\n");
6046
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08006047 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006048 IWL_DEBUG_MAC80211("leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07006049 return -EIO;
6050 }
6051
Johannes Berg05c914f2008-09-11 00:01:58 +02006052 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Zhu Yib481de92007-09-25 17:54:57 -07006053 IWL_DEBUG_MAC80211("leave - not IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07006054 return -EIO;
6055 }
6056
6057 spin_lock_irqsave(&priv->lock, flags);
6058
6059 if (priv->ibss_beacon)
6060 dev_kfree_skb(priv->ibss_beacon);
6061
6062 priv->ibss_beacon = skb;
6063
6064 priv->assoc_id = 0;
6065
6066 IWL_DEBUG_MAC80211("leave\n");
6067 spin_unlock_irqrestore(&priv->lock, flags);
6068
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08006069 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006070
Abhijeet Kolekardc4b1e72008-09-03 11:26:30 +08006071 iwl3945_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006072
Zhu Yib481de92007-09-25 17:54:57 -07006073
6074 return 0;
6075}
6076
6077/*****************************************************************************
6078 *
6079 * sysfs attributes
6080 *
6081 *****************************************************************************/
6082
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08006083#ifdef CONFIG_IWL3945_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07006084
6085/*
6086 * The following adds a new attribute to the sysfs representation
6087 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
6088 * used for controlling the debug level.
6089 *
6090 * See the level definitions in iwl for details.
6091 */
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08006092static ssize_t show_debug_level(struct device *d,
6093 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07006094{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006095 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08006096
6097 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07006098}
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08006099static ssize_t store_debug_level(struct device *d,
6100 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07006101 const char *buf, size_t count)
6102{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006103 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08006104 unsigned long val;
6105 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07006106
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08006107 ret = strict_strtoul(buf, 0, &val);
6108 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08006109 IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07006110 else
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08006111 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07006112
6113 return strnlen(buf, count);
6114}
6115
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08006116static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
6117 show_debug_level, store_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07006118
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08006119#endif /* CONFIG_IWL3945_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07006120
Zhu Yib481de92007-09-25 17:54:57 -07006121static ssize_t show_temperature(struct device *d,
6122 struct device_attribute *attr, char *buf)
6123{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006124 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07006125
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08006126 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07006127 return -EAGAIN;
6128
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006129 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07006130}
6131
6132static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
6133
Zhu Yib481de92007-09-25 17:54:57 -07006134static ssize_t show_tx_power(struct device *d,
6135 struct device_attribute *attr, char *buf)
6136{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006137 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08006138 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07006139}
6140
6141static ssize_t store_tx_power(struct device *d,
6142 struct device_attribute *attr,
6143 const char *buf, size_t count)
6144{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006145 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07006146 char *p = (char *)buf;
6147 u32 val;
6148
6149 val = simple_strtoul(p, &p, 10);
6150 if (p == buf)
Tomas Winkler978785a2008-12-19 10:37:31 +08006151 IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07006152 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006153 iwl3945_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07006154
6155 return count;
6156}
6157
6158static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
6159
6160static ssize_t show_flags(struct device *d,
6161 struct device_attribute *attr, char *buf)
6162{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006163 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07006164
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08006165 return sprintf(buf, "0x%04X\n", priv->active39_rxon.flags);
Zhu Yib481de92007-09-25 17:54:57 -07006166}
6167
6168static ssize_t store_flags(struct device *d,
6169 struct device_attribute *attr,
6170 const char *buf, size_t count)
6171{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006172 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07006173 u32 flags = simple_strtoul(buf, NULL, 0);
6174
6175 mutex_lock(&priv->mutex);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08006176 if (le32_to_cpu(priv->staging39_rxon.flags) != flags) {
Zhu Yib481de92007-09-25 17:54:57 -07006177 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08006178 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08006179 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07006180 else {
6181 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
6182 flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08006183 priv->staging39_rxon.flags = cpu_to_le32(flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006184 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006185 }
6186 }
6187 mutex_unlock(&priv->mutex);
6188
6189 return count;
6190}
6191
6192static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
6193
6194static ssize_t show_filter_flags(struct device *d,
6195 struct device_attribute *attr, char *buf)
6196{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006197 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07006198
6199 return sprintf(buf, "0x%04X\n",
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08006200 le32_to_cpu(priv->active39_rxon.filter_flags));
Zhu Yib481de92007-09-25 17:54:57 -07006201}
6202
6203static ssize_t store_filter_flags(struct device *d,
6204 struct device_attribute *attr,
6205 const char *buf, size_t count)
6206{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006207 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07006208 u32 filter_flags = simple_strtoul(buf, NULL, 0);
6209
6210 mutex_lock(&priv->mutex);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08006211 if (le32_to_cpu(priv->staging39_rxon.filter_flags) != filter_flags) {
Zhu Yib481de92007-09-25 17:54:57 -07006212 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08006213 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08006214 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07006215 else {
6216 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
6217 "0x%04X\n", filter_flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08006218 priv->staging39_rxon.filter_flags =
Zhu Yib481de92007-09-25 17:54:57 -07006219 cpu_to_le32(filter_flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006220 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006221 }
6222 }
6223 mutex_unlock(&priv->mutex);
6224
6225 return count;
6226}
6227
6228static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
6229 store_filter_flags);
6230
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08006231#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07006232
6233static ssize_t show_measurement(struct device *d,
6234 struct device_attribute *attr, char *buf)
6235{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006236 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler600c0e12008-12-19 10:37:04 +08006237 struct iwl_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07006238 u32 size = sizeof(measure_report), len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03006239 u8 *data = (u8 *)&measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07006240 unsigned long flags;
6241
6242 spin_lock_irqsave(&priv->lock, flags);
6243 if (!(priv->measurement_status & MEASUREMENT_READY)) {
6244 spin_unlock_irqrestore(&priv->lock, flags);
6245 return 0;
6246 }
6247 memcpy(&measure_report, &priv->measure_report, size);
6248 priv->measurement_status = 0;
6249 spin_unlock_irqrestore(&priv->lock, flags);
6250
6251 while (size && (PAGE_SIZE - len)) {
6252 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
6253 PAGE_SIZE - len, 1);
6254 len = strlen(buf);
6255 if (PAGE_SIZE - len)
6256 buf[len++] = '\n';
6257
6258 ofs += 16;
6259 size -= min(size, 16U);
6260 }
6261
6262 return len;
6263}
6264
6265static ssize_t store_measurement(struct device *d,
6266 struct device_attribute *attr,
6267 const char *buf, size_t count)
6268{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006269 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07006270 struct ieee80211_measurement_params params = {
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08006271 .channel = le16_to_cpu(priv->active39_rxon.channel),
Zhu Yib481de92007-09-25 17:54:57 -07006272 .start_time = cpu_to_le64(priv->last_tsf),
6273 .duration = cpu_to_le16(1),
6274 };
6275 u8 type = IWL_MEASURE_BASIC;
6276 u8 buffer[32];
6277 u8 channel;
6278
6279 if (count) {
6280 char *p = buffer;
6281 strncpy(buffer, buf, min(sizeof(buffer), count));
6282 channel = simple_strtoul(p, NULL, 0);
6283 if (channel)
6284 params.channel = channel;
6285
6286 p = buffer;
6287 while (*p && *p != ' ')
6288 p++;
6289 if (*p)
6290 type = simple_strtoul(p + 1, NULL, 0);
6291 }
6292
6293 IWL_DEBUG_INFO("Invoking measurement of type %d on "
6294 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006295 iwl3945_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07006296
6297 return count;
6298}
6299
6300static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
6301 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08006302#endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07006303
Zhu Yib481de92007-09-25 17:54:57 -07006304static ssize_t store_retry_rate(struct device *d,
6305 struct device_attribute *attr,
6306 const char *buf, size_t count)
6307{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006308 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07006309
6310 priv->retry_rate = simple_strtoul(buf, NULL, 0);
6311 if (priv->retry_rate <= 0)
6312 priv->retry_rate = 1;
6313
6314 return count;
6315}
6316
6317static ssize_t show_retry_rate(struct device *d,
6318 struct device_attribute *attr, char *buf)
6319{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006320 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07006321 return sprintf(buf, "%d", priv->retry_rate);
6322}
6323
6324static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
6325 store_retry_rate);
6326
6327static ssize_t store_power_level(struct device *d,
6328 struct device_attribute *attr,
6329 const char *buf, size_t count)
6330{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006331 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07006332 int rc;
6333 int mode;
6334
6335 mode = simple_strtoul(buf, NULL, 0);
6336 mutex_lock(&priv->mutex);
6337
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08006338 if (!iwl_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006339 rc = -EAGAIN;
6340 goto out;
6341 }
6342
Samuel Ortiz1125eff2008-12-19 10:37:14 +08006343 if ((mode < 1) || (mode > IWL39_POWER_LIMIT) ||
6344 (mode == IWL39_POWER_AC))
6345 mode = IWL39_POWER_AC;
Zhu Yib481de92007-09-25 17:54:57 -07006346 else
6347 mode |= IWL_POWER_ENABLED;
6348
6349 if (mode != priv->power_mode) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006350 rc = iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(mode));
Zhu Yib481de92007-09-25 17:54:57 -07006351 if (rc) {
6352 IWL_DEBUG_MAC80211("failed setting power mode.\n");
6353 goto out;
6354 }
6355 priv->power_mode = mode;
6356 }
6357
6358 rc = count;
6359
6360 out:
6361 mutex_unlock(&priv->mutex);
6362 return rc;
6363}
6364
6365#define MAX_WX_STRING 80
6366
6367/* Values are in microsecond */
6368static const s32 timeout_duration[] = {
6369 350000,
6370 250000,
6371 75000,
6372 37000,
6373 25000,
6374};
6375static const s32 period_duration[] = {
6376 400000,
6377 700000,
6378 1000000,
6379 1000000,
6380 1000000
6381};
6382
6383static ssize_t show_power_level(struct device *d,
6384 struct device_attribute *attr, char *buf)
6385{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006386 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07006387 int level = IWL_POWER_LEVEL(priv->power_mode);
6388 char *p = buf;
6389
6390 p += sprintf(p, "%d ", level);
6391 switch (level) {
6392 case IWL_POWER_MODE_CAM:
Samuel Ortiz1125eff2008-12-19 10:37:14 +08006393 case IWL39_POWER_AC:
Zhu Yib481de92007-09-25 17:54:57 -07006394 p += sprintf(p, "(AC)");
6395 break;
Samuel Ortiz1125eff2008-12-19 10:37:14 +08006396 case IWL39_POWER_BATTERY:
Zhu Yib481de92007-09-25 17:54:57 -07006397 p += sprintf(p, "(BATTERY)");
6398 break;
6399 default:
6400 p += sprintf(p,
6401 "(Timeout %dms, Period %dms)",
6402 timeout_duration[level - 1] / 1000,
6403 period_duration[level - 1] / 1000);
6404 }
6405
6406 if (!(priv->power_mode & IWL_POWER_ENABLED))
6407 p += sprintf(p, " OFF\n");
6408 else
6409 p += sprintf(p, " \n");
6410
Tomas Winkler3ac7f142008-07-21 02:40:14 +03006411 return p - buf + 1;
Zhu Yib481de92007-09-25 17:54:57 -07006412
6413}
6414
6415static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
6416 store_power_level);
6417
6418static ssize_t show_channels(struct device *d,
6419 struct device_attribute *attr, char *buf)
6420{
Johannes Berg8318d782008-01-24 19:38:38 +01006421 /* all this shit doesn't belong into sysfs anyway */
6422 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07006423}
6424
6425static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
6426
6427static ssize_t show_statistics(struct device *d,
6428 struct device_attribute *attr, char *buf)
6429{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006430 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006431 u32 size = sizeof(struct iwl3945_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07006432 u32 len = 0, ofs = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08006433 u8 *data = (u8 *)&priv->statistics_39;
Zhu Yib481de92007-09-25 17:54:57 -07006434 int rc = 0;
6435
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08006436 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07006437 return -EAGAIN;
6438
6439 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006440 rc = iwl3945_send_statistics_request(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006441 mutex_unlock(&priv->mutex);
6442
6443 if (rc) {
6444 len = sprintf(buf,
6445 "Error sending statistics request: 0x%08X\n", rc);
6446 return len;
6447 }
6448
6449 while (size && (PAGE_SIZE - len)) {
6450 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
6451 PAGE_SIZE - len, 1);
6452 len = strlen(buf);
6453 if (PAGE_SIZE - len)
6454 buf[len++] = '\n';
6455
6456 ofs += 16;
6457 size -= min(size, 16U);
6458 }
6459
6460 return len;
6461}
6462
6463static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
6464
6465static ssize_t show_antenna(struct device *d,
6466 struct device_attribute *attr, char *buf)
6467{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006468 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07006469
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08006470 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07006471 return -EAGAIN;
6472
6473 return sprintf(buf, "%d\n", priv->antenna);
6474}
6475
6476static ssize_t store_antenna(struct device *d,
6477 struct device_attribute *attr,
6478 const char *buf, size_t count)
6479{
6480 int ant;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006481 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07006482
6483 if (count == 0)
6484 return 0;
6485
6486 if (sscanf(buf, "%1i", &ant) != 1) {
6487 IWL_DEBUG_INFO("not in hex or decimal form.\n");
6488 return count;
6489 }
6490
6491 if ((ant >= 0) && (ant <= 2)) {
6492 IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006493 priv->antenna = (enum iwl3945_antenna)ant;
Zhu Yib481de92007-09-25 17:54:57 -07006494 } else
6495 IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant);
6496
6497
6498 return count;
6499}
6500
6501static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
6502
6503static ssize_t show_status(struct device *d,
6504 struct device_attribute *attr, char *buf)
6505{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006506 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08006507 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07006508 return -EAGAIN;
6509 return sprintf(buf, "0x%08x\n", (int)priv->status);
6510}
6511
6512static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
6513
6514static ssize_t dump_error_log(struct device *d,
6515 struct device_attribute *attr,
6516 const char *buf, size_t count)
6517{
6518 char *p = (char *)buf;
6519
6520 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006521 iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07006522
6523 return strnlen(buf, count);
6524}
6525
6526static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
6527
6528static ssize_t dump_event_log(struct device *d,
6529 struct device_attribute *attr,
6530 const char *buf, size_t count)
6531{
6532 char *p = (char *)buf;
6533
6534 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006535 iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07006536
6537 return strnlen(buf, count);
6538}
6539
6540static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
6541
6542/*****************************************************************************
6543 *
Tomas Winklera96a27f2008-10-23 23:48:56 -07006544 * driver setup and tear down
Zhu Yib481de92007-09-25 17:54:57 -07006545 *
6546 *****************************************************************************/
6547
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006548static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006549{
6550 priv->workqueue = create_workqueue(DRV_NAME);
6551
6552 init_waitqueue_head(&priv->wait_command_queue);
6553
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006554 INIT_WORK(&priv->up, iwl3945_bg_up);
6555 INIT_WORK(&priv->restart, iwl3945_bg_restart);
6556 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01006557 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006558 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006559 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
6560 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
Helmut Schaa26635162009-01-15 09:38:44 +01006561 INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08006562 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
6563 INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
6564 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
6565 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
Zhu Yib481de92007-09-25 17:54:57 -07006566
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006567 iwl3945_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006568
6569 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006570 iwl3945_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07006571}
6572
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006573static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006574{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006575 iwl3945_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006576
Joonwoo Parke47eb6a2007-11-29 10:42:49 +09006577 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07006578 cancel_delayed_work(&priv->scan_check);
6579 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07006580 cancel_work_sync(&priv->beacon_update);
6581}
6582
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006583static struct attribute *iwl3945_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07006584 &dev_attr_antenna.attr,
6585 &dev_attr_channels.attr,
6586 &dev_attr_dump_errors.attr,
6587 &dev_attr_dump_events.attr,
6588 &dev_attr_flags.attr,
6589 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08006590#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07006591 &dev_attr_measurement.attr,
6592#endif
6593 &dev_attr_power_level.attr,
Zhu Yib481de92007-09-25 17:54:57 -07006594 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07006595 &dev_attr_statistics.attr,
6596 &dev_attr_status.attr,
6597 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07006598 &dev_attr_tx_power.attr,
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08006599#ifdef CONFIG_IWL3945_DEBUG
6600 &dev_attr_debug_level.attr,
6601#endif
Zhu Yib481de92007-09-25 17:54:57 -07006602 NULL
6603};
6604
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006605static struct attribute_group iwl3945_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07006606 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006607 .attrs = iwl3945_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07006608};
6609
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006610static struct ieee80211_ops iwl3945_hw_ops = {
6611 .tx = iwl3945_mac_tx,
6612 .start = iwl3945_mac_start,
6613 .stop = iwl3945_mac_stop,
6614 .add_interface = iwl3945_mac_add_interface,
6615 .remove_interface = iwl3945_mac_remove_interface,
6616 .config = iwl3945_mac_config,
6617 .config_interface = iwl3945_mac_config_interface,
6618 .configure_filter = iwl3945_configure_filter,
6619 .set_key = iwl3945_mac_set_key,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006620 .get_tx_stats = iwl3945_mac_get_tx_stats,
6621 .conf_tx = iwl3945_mac_conf_tx,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006622 .reset_tsf = iwl3945_mac_reset_tsf,
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08006623 .bss_info_changed = iwl3945_bss_info_changed,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006624 .hw_scan = iwl3945_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07006625};
6626
Winkler, Tomase52119c2008-12-22 11:31:19 +08006627static int iwl3945_init_drv(struct iwl_priv *priv)
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006628{
6629 int ret;
6630
6631 priv->retry_rate = 1;
6632 priv->ibss_beacon = NULL;
6633
6634 spin_lock_init(&priv->lock);
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08006635 spin_lock_init(&priv->power_data.lock);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006636 spin_lock_init(&priv->sta_lock);
6637 spin_lock_init(&priv->hcmd_lock);
6638
6639 INIT_LIST_HEAD(&priv->free_frames);
6640
6641 mutex_init(&priv->mutex);
6642
6643 /* Clear the driver's (not device's) station table */
6644 iwl3945_clear_stations_table(priv);
6645
6646 priv->data_retry_limit = -1;
6647 priv->ieee_channels = NULL;
6648 priv->ieee_rates = NULL;
6649 priv->band = IEEE80211_BAND_2GHZ;
6650
6651 priv->iw_mode = NL80211_IFTYPE_STATION;
6652
6653 iwl_reset_qos(priv);
6654
6655 priv->qos_data.qos_active = 0;
6656 priv->qos_data.qos_cap.val = 0;
6657
6658 priv->rates_mask = IWL_RATES_MASK;
6659 /* If power management is turned on, default to AC mode */
Samuel Ortizc7a7c8e2009-01-08 10:20:01 -08006660 priv->power_mode = IWL39_POWER_AC;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08006661 priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006662
6663 ret = iwl3945_init_channel_map(priv);
6664 if (ret) {
6665 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
6666 goto err;
6667 }
6668
6669 ret = iwl3945_init_geos(priv);
6670 if (ret) {
6671 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
6672 goto err_free_channel_map;
6673 }
6674
6675 return 0;
6676
6677err_free_channel_map:
6678 iwl3945_free_channel_map(priv);
6679err:
6680 return ret;
6681}
6682
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006683static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07006684{
6685 int err = 0;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006686 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07006687 struct ieee80211_hw *hw;
Kolekar, Abhijeetc0f20d92008-12-19 10:37:19 +08006688 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07006689 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07006690
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006691 /***********************
6692 * 1. Allocating HW data
6693 * ********************/
6694
Zhu Yib481de92007-09-25 17:54:57 -07006695 /* mac80211 allocates memory for this device instance, including
6696 * space for this driver's private structure */
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006697 hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
Zhu Yib481de92007-09-25 17:54:57 -07006698 if (hw == NULL) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08006699 printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
Zhu Yib481de92007-09-25 17:54:57 -07006700 err = -ENOMEM;
6701 goto out;
6702 }
Zhu Yib481de92007-09-25 17:54:57 -07006703 priv = hw->priv;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006704 SET_IEEE80211_DEV(hw, &pdev->dev);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08006705
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08006706 if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) ||
6707 (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08006708 IWL_ERR(priv,
6709 "invalid queues_num, should be between %d and %d\n",
6710 IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
Samuel Ortiza3139c52008-12-19 10:37:09 +08006711 err = -EINVAL;
6712 goto out;
6713 }
6714
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006715 /*
6716 * Disabling hardware scan means that mac80211 will perform scans
6717 * "the hard way", rather than using device's scan.
6718 */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08006719 if (iwl3945_mod_params.disable_hw_scan) {
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08006720 IWL_DEBUG_INFO("Disabling hw_scan\n");
6721 iwl3945_hw_ops.hw_scan = NULL;
6722 }
6723
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006724
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006725 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006726 priv->cfg = cfg;
6727 priv->pci_dev = pdev;
6728
6729#ifdef CONFIG_IWL3945_DEBUG
6730 priv->debug_level = iwl3945_mod_params.debug;
6731 atomic_set(&priv->restrict_refcnt, 0);
6732#endif
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006733 hw->rate_control_algorithm = "iwl-3945-rs";
6734 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
6735
Cahill, Ben M6440adb2007-11-29 11:09:55 +08006736 /* Select antenna (may be helpful if only one antenna is connected) */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08006737 priv->antenna = (enum iwl3945_antenna)iwl3945_mod_params.antenna;
Zhu Yib481de92007-09-25 17:54:57 -07006738
Bruno Randolf566bfe52008-05-08 19:15:40 +02006739 /* Tell mac80211 our characteristics */
Johannes Berg605a0bd2008-07-15 10:10:01 +02006740 hw->flags = IEEE80211_HW_SIGNAL_DBM |
Bruno Randolf566bfe52008-05-08 19:15:40 +02006741 IEEE80211_HW_NOISE_DBM;
Zhu Yib481de92007-09-25 17:54:57 -07006742
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07006743 hw->wiphy->interface_modes =
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07006744 BIT(NL80211_IFTYPE_STATION) |
6745 BIT(NL80211_IFTYPE_ADHOC);
6746
Luis R. Rodriguez2a44f912009-01-22 15:05:49 -08006747 hw->wiphy->custom_regulatory = true;
Luis R. Rodriguezea4a82dc2008-11-12 14:22:04 -08006748
Cahill, Ben M6440adb2007-11-29 11:09:55 +08006749 /* 4 EDCA QOS priorities */
Zhu Yib481de92007-09-25 17:54:57 -07006750 hw->queues = 4;
6751
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006752 /***************************
6753 * 2. Initializing PCI bus
6754 * *************************/
Zhu Yib481de92007-09-25 17:54:57 -07006755 if (pci_enable_device(pdev)) {
6756 err = -ENODEV;
6757 goto out_ieee80211_free_hw;
6758 }
6759
6760 pci_set_master(pdev);
6761
Zhu Yib481de92007-09-25 17:54:57 -07006762 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
6763 if (!err)
6764 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
6765 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08006766 IWL_WARN(priv, "No suitable DMA available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07006767 goto out_pci_disable_device;
6768 }
6769
6770 pci_set_drvdata(pdev, priv);
6771 err = pci_request_regions(pdev, DRV_NAME);
6772 if (err)
6773 goto out_pci_disable_device;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08006774
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006775 /***********************
6776 * 3. Read REV Register
6777 * ********************/
Zhu Yib481de92007-09-25 17:54:57 -07006778 priv->hw_base = pci_iomap(pdev, 0, 0);
6779 if (!priv->hw_base) {
6780 err = -ENODEV;
6781 goto out_pci_release_regions;
6782 }
6783
6784 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
6785 (unsigned long long) pci_resource_len(pdev, 0));
6786 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
6787
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006788 /* We disable the RETRY_TIMEOUT register (0x41) to keep
6789 * PCI Tx retries from interfering with C3 CPU state */
6790 pci_write_config_byte(pdev, 0x41, 0x00);
Zhu Yib481de92007-09-25 17:54:57 -07006791
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006792 /* amp init */
6793 err = priv->cfg->ops->lib->apm_ops.init(priv);
Tomas Winkler3ac7f142008-07-21 02:40:14 +03006794 if (err < 0) {
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006795 IWL_DEBUG_INFO("Failed to init APMG\n");
6796 goto out_iounmap;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03006797 }
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006798
6799 /***********************
6800 * 4. Read EEPROM
6801 * ********************/
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006802
Zhu Yi5a669262008-01-14 17:46:18 -08006803 /* Read the EEPROM */
6804 err = iwl3945_eeprom_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006805 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08006806 IWL_ERR(priv, "Unable to init EEPROM\n");
Zhu Yi5a669262008-01-14 17:46:18 -08006807 goto out_remove_sysfs;
6808 }
6809 /* MAC Address location in EEPROM same for 3945/4965 */
6810 get_eeprom_mac(priv, priv->mac_addr);
Johannes Berge1749612008-10-27 15:59:26 -07006811 IWL_DEBUG_INFO("MAC address: %pM\n", priv->mac_addr);
Zhu Yi5a669262008-01-14 17:46:18 -08006812 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
6813
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006814 /***********************
6815 * 5. Setup HW Constants
6816 * ********************/
6817 /* Device-specific setup */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08006818 if (iwl3945_hw_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08006819 IWL_ERR(priv, "failed to set hw settings\n");
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006820 goto out_iounmap;
6821 }
6822
6823 /***********************
6824 * 6. Setup priv
6825 * ********************/
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006826
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006827 err = iwl3945_init_drv(priv);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08006828 if (err) {
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006829 IWL_ERR(priv, "initializing driver failed\n");
6830 goto out_free_geos;
Reinette Chatre849e0dc2008-01-23 10:15:18 -08006831 }
Reinette Chatre849e0dc2008-01-23 10:15:18 -08006832
Tomas Winkler978785a2008-12-19 10:37:31 +08006833 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
6834 priv->cfg->name);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006835
6836 /***********************************
6837 * 7. Initialize Module Parameters
6838 * **********************************/
6839
6840 /* Initialize module parameter values here */
6841 /* Disable radio (SW RF KILL) via parameter when loading driver */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08006842 if (iwl3945_mod_params.disable) {
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006843 set_bit(STATUS_RF_KILL_SW, &priv->status);
6844 IWL_DEBUG_INFO("Radio disabled.\n");
6845 }
6846
6847
6848 /***********************
6849 * 8. Setup Services
6850 * ********************/
6851
6852 spin_lock_irqsave(&priv->lock, flags);
6853 iwl3945_disable_interrupts(priv);
6854 spin_unlock_irqrestore(&priv->lock, flags);
6855
Helmut Schaa26635162009-01-15 09:38:44 +01006856 pci_enable_msi(priv->pci_dev);
6857
6858 err = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED,
6859 DRV_NAME, priv);
6860 if (err) {
6861 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
6862 goto out_disable_msi;
6863 }
6864
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006865 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
6866 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08006867 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08006868 goto out_release_irq;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006869 }
6870
6871 iwl3945_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
6872 iwl3945_setup_deferred_work(priv);
6873 iwl3945_setup_rx_handlers(priv);
6874
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006875 /*********************************
Helmut Schaa26635162009-01-15 09:38:44 +01006876 * 9. Setup and Register mac80211
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006877 * *******************************/
6878
Zhu Yi5a669262008-01-14 17:46:18 -08006879 err = ieee80211_register_hw(priv->hw);
6880 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08006881 IWL_ERR(priv, "Failed to register network device: %d\n", err);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006882 goto out_remove_sysfs;
Zhu Yib481de92007-09-25 17:54:57 -07006883 }
6884
Zhu Yi5a669262008-01-14 17:46:18 -08006885 priv->hw->conf.beacon_int = 100;
6886 priv->mac80211_registered = 1;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006887
Samuel Ortizc0af96a2009-01-21 18:27:54 +01006888 err = iwl_rfkill_init(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08006889 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08006890 IWL_ERR(priv, "Unable to initialize RFKILL system. "
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08006891 "Ignoring error: %d\n", err);
6892
Helmut Schaa26635162009-01-15 09:38:44 +01006893 /* Start monitoring the killswitch */
6894 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
6895 2 * HZ);
6896
Zhu Yib481de92007-09-25 17:54:57 -07006897 return 0;
6898
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08006899 out_remove_sysfs:
6900 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08006901 out_free_geos:
6902 iwl3945_free_geos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006903
6904 out_release_irq:
Helmut Schaa26635162009-01-15 09:38:44 +01006905 free_irq(priv->pci_dev->irq, priv);
Zhu Yib481de92007-09-25 17:54:57 -07006906 destroy_workqueue(priv->workqueue);
6907 priv->workqueue = NULL;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08006908 iwl3945_unset_hw_params(priv);
Helmut Schaa26635162009-01-15 09:38:44 +01006909 out_disable_msi:
6910 pci_disable_msi(priv->pci_dev);
Zhu Yib481de92007-09-25 17:54:57 -07006911 out_iounmap:
6912 pci_iounmap(pdev, priv->hw_base);
6913 out_pci_release_regions:
6914 pci_release_regions(pdev);
6915 out_pci_disable_device:
6916 pci_disable_device(pdev);
6917 pci_set_drvdata(pdev, NULL);
6918 out_ieee80211_free_hw:
6919 ieee80211_free_hw(priv->hw);
6920 out:
6921 return err;
6922}
6923
Reinette Chatrec83dbf62008-03-21 13:53:41 -07006924static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07006925{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006926 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07006927 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07006928
6929 if (!priv)
6930 return;
6931
6932 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
6933
Zhu Yib481de92007-09-25 17:54:57 -07006934 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08006935
Kolekar, Abhijeetd552bfb2008-12-19 10:37:41 +08006936 if (priv->mac80211_registered) {
6937 ieee80211_unregister_hw(priv->hw);
6938 priv->mac80211_registered = 0;
6939 } else {
6940 iwl3945_down(priv);
6941 }
Zhu Yib481de92007-09-25 17:54:57 -07006942
Mohamed Abbas0359fac2008-03-28 16:21:08 -07006943 /* make sure we flush any pending irq or
6944 * tasklet for the driver
6945 */
6946 spin_lock_irqsave(&priv->lock, flags);
6947 iwl3945_disable_interrupts(priv);
6948 spin_unlock_irqrestore(&priv->lock, flags);
6949
6950 iwl_synchronize_irq(priv);
6951
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006952 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07006953
Samuel Ortizc0af96a2009-01-21 18:27:54 +01006954 iwl_rfkill_unregister(priv);
Helmut Schaa26635162009-01-15 09:38:44 +01006955 cancel_delayed_work(&priv->rfkill_poll);
6956
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006957 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006958
6959 if (priv->rxq.bd)
Winkler, Tomas51af3d32008-12-22 11:31:23 +08006960 iwl_rx_queue_free(priv, &priv->rxq);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006961 iwl3945_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006962
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08006963 iwl3945_unset_hw_params(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006964 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006965
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08006966 /*netif_stop_queue(dev); */
6967 flush_workqueue(priv->workqueue);
6968
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006969 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07006970 * priv->workqueue... so we can't take down the workqueue
6971 * until now... */
6972 destroy_workqueue(priv->workqueue);
6973 priv->workqueue = NULL;
6974
Helmut Schaa26635162009-01-15 09:38:44 +01006975 free_irq(pdev->irq, priv);
6976 pci_disable_msi(pdev);
6977
Zhu Yib481de92007-09-25 17:54:57 -07006978 pci_iounmap(pdev, priv->hw_base);
6979 pci_release_regions(pdev);
6980 pci_disable_device(pdev);
6981 pci_set_drvdata(pdev, NULL);
6982
Reinette Chatre849e0dc2008-01-23 10:15:18 -08006983 iwl3945_free_channel_map(priv);
6984 iwl3945_free_geos(priv);
Winkler, Tomas805cee52009-01-19 15:30:28 -08006985 kfree(priv->scan);
Zhu Yib481de92007-09-25 17:54:57 -07006986 if (priv->ibss_beacon)
6987 dev_kfree_skb(priv->ibss_beacon);
6988
6989 ieee80211_free_hw(priv->hw);
6990}
6991
6992#ifdef CONFIG_PM
6993
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006994static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07006995{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08006996 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07006997
Zhu Yie655b9f2008-01-24 02:19:38 -08006998 if (priv->is_open) {
6999 set_bit(STATUS_IN_SUSPEND, &priv->status);
7000 iwl3945_mac_stop(priv->hw);
7001 priv->is_open = 1;
7002 }
Helmut Schaa26635162009-01-15 09:38:44 +01007003 pci_save_state(pdev);
7004 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07007005 pci_set_power_state(pdev, PCI_D3hot);
7006
Zhu Yib481de92007-09-25 17:54:57 -07007007 return 0;
7008}
7009
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007010static int iwl3945_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07007011{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08007012 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07007013
Zhu Yib481de92007-09-25 17:54:57 -07007014 pci_set_power_state(pdev, PCI_D0);
Helmut Schaa26635162009-01-15 09:38:44 +01007015 pci_enable_device(pdev);
7016 pci_restore_state(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07007017
Zhu Yie655b9f2008-01-24 02:19:38 -08007018 if (priv->is_open)
7019 iwl3945_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07007020
Zhu Yie655b9f2008-01-24 02:19:38 -08007021 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07007022 return 0;
7023}
7024
7025#endif /* CONFIG_PM */
7026
7027/*****************************************************************************
7028 *
7029 * driver and module entry point
7030 *
7031 *****************************************************************************/
7032
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007033static struct pci_driver iwl3945_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07007034 .name = DRV_NAME,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007035 .id_table = iwl3945_hw_card_ids,
7036 .probe = iwl3945_pci_probe,
7037 .remove = __devexit_p(iwl3945_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07007038#ifdef CONFIG_PM
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007039 .suspend = iwl3945_pci_suspend,
7040 .resume = iwl3945_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07007041#endif
7042};
7043
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007044static int __init iwl3945_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07007045{
7046
7047 int ret;
7048 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
7049 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07007050
7051 ret = iwl3945_rate_control_register();
7052 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08007053 printk(KERN_ERR DRV_NAME
7054 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07007055 return ret;
7056 }
7057
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007058 ret = pci_register_driver(&iwl3945_driver);
Zhu Yib481de92007-09-25 17:54:57 -07007059 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08007060 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07007061 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07007062 }
Zhu Yib481de92007-09-25 17:54:57 -07007063
7064 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07007065
Reinette Chatre897e1cf2008-03-28 16:21:09 -07007066error_register:
7067 iwl3945_rate_control_unregister();
7068 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07007069}
7070
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007071static void __exit iwl3945_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07007072{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007073 pci_unregister_driver(&iwl3945_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07007074 iwl3945_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07007075}
7076
Reinette Chatrea0987a82008-12-02 12:14:06 -08007077MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
Zhu Yi25cb6ca2008-09-11 11:45:22 +08007078
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08007079module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07007080MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08007081module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07007082MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -08007083module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
7084MODULE_PARM_DESC(swcrypto,
7085 "using software crypto (default 1 [software])\n");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08007086module_param_named(debug, iwl3945_mod_params.debug, uint, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07007087MODULE_PARM_DESC(debug, "debug output mask");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08007088module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07007089MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
7090
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08007091module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07007092MODULE_PARM_DESC(queues_num, "number of hw queues.");
7093
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007094module_exit(iwl3945_exit);
7095module_init(iwl3945_init);