blob: 9cf1f204666d8d55fce08b1c07f86ec94474254d [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Reinette Chatreeb7ae892008-03-11 16:17:17 -07003 * Copyright(c) 2003 - 2008 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:
25 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
26 * 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>
32#include <linux/version.h>
33#include <linux/init.h>
34#include <linux/pci.h>
35#include <linux/dma-mapping.h>
36#include <linux/delay.h>
37#include <linux/skbuff.h>
38#include <linux/netdevice.h>
39#include <linux/wireless.h>
40#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070041#include <linux/etherdevice.h>
42#include <linux/if_arp.h>
43
Zhu Yib481de92007-09-25 17:54:57 -070044#include <net/mac80211.h>
45
46#include <asm/div64.h>
47
Assaf Krauss6bc913b2008-03-11 16:17:18 -070048#include "iwl-eeprom.h"
Tomas Winkler82b9a122008-03-04 18:09:30 -080049#include "iwl-core.h"
Zhu Yib481de92007-09-25 17:54:57 -070050#include "iwl-4965.h"
51#include "iwl-helpers.h"
52
Tomas Winklerc79dd5b2008-03-12 16:58:50 -070053static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -080054 struct iwl4965_tx_queue *txq);
Christoph Hellwig416e1432007-10-25 17:15:49 +080055
Zhu Yib481de92007-09-25 17:54:57 -070056/******************************************************************************
57 *
58 * module boiler plate
59 *
60 ******************************************************************************/
61
62/* module parameters */
Assaf Krauss00acbc92008-03-14 10:38:47 -070063struct iwl_mod_params iwl4965_mod_params = {
64 .num_of_queues = IWL_MAX_NUM_QUEUES,
65 .enable_qos = 1,
66 .amsdu_size_8K = 1,
67 /* the rest are 0 by default */
68};
Zhu Yib481de92007-09-25 17:54:57 -070069
70/*
71 * module name, copyright, version, etc.
72 * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
73 */
74
75#define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux"
76
Tomas Winkler0a6857e2008-03-12 16:58:49 -070077#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070078#define VD "d"
79#else
80#define VD
81#endif
82
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080083#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070084#define VS "s"
85#else
86#define VS
87#endif
88
Tomas Winklerdf48c322008-03-06 10:40:19 -080089#define DRV_VERSION IWLWIFI_VERSION VD VS
Zhu Yib481de92007-09-25 17:54:57 -070090
Zhu Yib481de92007-09-25 17:54:57 -070091
92MODULE_DESCRIPTION(DRV_DESCRIPTION);
93MODULE_VERSION(DRV_VERSION);
94MODULE_AUTHOR(DRV_COPYRIGHT);
95MODULE_LICENSE("GPL");
96
97__le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr)
98{
99 u16 fc = le16_to_cpu(hdr->frame_control);
100 int hdr_len = ieee80211_get_hdrlen(fc);
101
102 if ((fc & 0x00cc) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA))
103 return (__le16 *) ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN);
104 return NULL;
105}
106
Johannes Berg8318d782008-01-24 19:38:38 +0100107static const struct ieee80211_supported_band *iwl4965_get_hw_mode(
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700108 struct iwl_priv *priv, enum ieee80211_band band)
Zhu Yib481de92007-09-25 17:54:57 -0700109{
Johannes Berg8318d782008-01-24 19:38:38 +0100110 return priv->hw->wiphy->bands[band];
Zhu Yib481de92007-09-25 17:54:57 -0700111}
112
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800113static int iwl4965_is_empty_essid(const char *essid, int essid_len)
Zhu Yib481de92007-09-25 17:54:57 -0700114{
115 /* Single white space is for Linksys APs */
116 if (essid_len == 1 && essid[0] == ' ')
117 return 1;
118
119 /* Otherwise, if the entire essid is 0, we assume it is hidden */
120 while (essid_len) {
121 essid_len--;
122 if (essid[essid_len] != '\0')
123 return 0;
124 }
125
126 return 1;
127}
128
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800129static const char *iwl4965_escape_essid(const char *essid, u8 essid_len)
Zhu Yib481de92007-09-25 17:54:57 -0700130{
131 static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
132 const char *s = essid;
133 char *d = escaped;
134
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800135 if (iwl4965_is_empty_essid(essid, essid_len)) {
Zhu Yib481de92007-09-25 17:54:57 -0700136 memcpy(escaped, "<hidden>", sizeof("<hidden>"));
137 return escaped;
138 }
139
140 essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE);
141 while (essid_len--) {
142 if (*s == '\0') {
143 *d++ = '\\';
144 *d++ = '0';
145 s++;
146 } else
147 *d++ = *s++;
148 }
149 *d = '\0';
150 return escaped;
151}
152
Zhu Yib481de92007-09-25 17:54:57 -0700153/*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
154 * DMA services
155 *
156 * Theory of operation
157 *
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800158 * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
159 * of buffer descriptors, each of which points to one or more data buffers for
160 * the device to read from or fill. Driver and device exchange status of each
161 * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
162 * entries in each circular buffer, to protect against confusing empty and full
163 * queue states.
164 *
165 * The device reads or writes the data in the queues via the device's several
166 * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
Zhu Yib481de92007-09-25 17:54:57 -0700167 *
168 * For Tx queue, there are low mark and high mark limits. If, after queuing
169 * the packet for Tx, free space become < low mark, Tx queue stopped. When
170 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
171 * Tx queue resumed.
172 *
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800173 * The 4965 operates with up to 17 queues: One receive queue, one transmit
174 * queue (#4) for sending commands to the device firmware, and 15 other
175 * Tx queues that may be mapped to prioritized Tx DMA/FIFO channels.
Ben Cahille3851442007-11-29 11:10:07 +0800176 *
177 * See more detailed info in iwl-4965-hw.h.
Zhu Yib481de92007-09-25 17:54:57 -0700178 ***************************************************/
179
Ron Rindjunskyfe01b472008-01-28 14:07:24 +0200180int iwl4965_queue_space(const struct iwl4965_queue *q)
Zhu Yib481de92007-09-25 17:54:57 -0700181{
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800182 int s = q->read_ptr - q->write_ptr;
Zhu Yib481de92007-09-25 17:54:57 -0700183
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800184 if (q->read_ptr > q->write_ptr)
Zhu Yib481de92007-09-25 17:54:57 -0700185 s -= q->n_bd;
186
187 if (s <= 0)
188 s += q->n_window;
189 /* keep some reserve to not confuse empty and full situations */
190 s -= 2;
191 if (s < 0)
192 s = 0;
193 return s;
194}
195
Zhu Yib481de92007-09-25 17:54:57 -0700196
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800197static inline int x2_queue_used(const struct iwl4965_queue *q, int i)
Zhu Yib481de92007-09-25 17:54:57 -0700198{
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800199 return q->write_ptr > q->read_ptr ?
200 (i >= q->read_ptr && i < q->write_ptr) :
201 !(i < q->read_ptr && i >= q->write_ptr);
Zhu Yib481de92007-09-25 17:54:57 -0700202}
203
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800204static inline u8 get_cmd_index(struct iwl4965_queue *q, u32 index, int is_huge)
Zhu Yib481de92007-09-25 17:54:57 -0700205{
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800206 /* This is for scan command, the big buffer at end of command array */
Zhu Yib481de92007-09-25 17:54:57 -0700207 if (is_huge)
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800208 return q->n_window; /* must be power of 2 */
Zhu Yib481de92007-09-25 17:54:57 -0700209
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800210 /* Otherwise, use normal size buffers */
Zhu Yib481de92007-09-25 17:54:57 -0700211 return index & (q->n_window - 1);
212}
213
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800214/**
215 * iwl4965_queue_init - Initialize queue's high/low-water and read/write indexes
216 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700217static int iwl4965_queue_init(struct iwl_priv *priv, struct iwl4965_queue *q,
Zhu Yib481de92007-09-25 17:54:57 -0700218 int count, int slots_num, u32 id)
219{
220 q->n_bd = count;
221 q->n_window = slots_num;
222 q->id = id;
223
Tomas Winklerc54b6792008-03-06 17:36:53 -0800224 /* count must be power-of-two size, otherwise iwl_queue_inc_wrap
225 * and iwl_queue_dec_wrap are broken. */
Zhu Yib481de92007-09-25 17:54:57 -0700226 BUG_ON(!is_power_of_2(count));
227
228 /* slots_num must be power-of-two size, otherwise
229 * get_cmd_index is broken. */
230 BUG_ON(!is_power_of_2(slots_num));
231
232 q->low_mark = q->n_window / 4;
233 if (q->low_mark < 4)
234 q->low_mark = 4;
235
236 q->high_mark = q->n_window / 8;
237 if (q->high_mark < 2)
238 q->high_mark = 2;
239
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800240 q->write_ptr = q->read_ptr = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700241
242 return 0;
243}
244
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800245/**
246 * iwl4965_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
247 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700248static int iwl4965_tx_queue_alloc(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800249 struct iwl4965_tx_queue *txq, u32 id)
Zhu Yib481de92007-09-25 17:54:57 -0700250{
251 struct pci_dev *dev = priv->pci_dev;
252
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800253 /* Driver private data, only for Tx (not command) queues,
254 * not shared with device. */
Zhu Yib481de92007-09-25 17:54:57 -0700255 if (id != IWL_CMD_QUEUE_NUM) {
256 txq->txb = kmalloc(sizeof(txq->txb[0]) *
257 TFD_QUEUE_SIZE_MAX, GFP_KERNEL);
258 if (!txq->txb) {
Ian Schram01ebd062007-10-25 17:15:22 +0800259 IWL_ERROR("kmalloc for auxiliary BD "
Zhu Yib481de92007-09-25 17:54:57 -0700260 "structures failed\n");
261 goto error;
262 }
263 } else
264 txq->txb = NULL;
265
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800266 /* Circular buffer of transmit frame descriptors (TFDs),
267 * shared with device */
Zhu Yib481de92007-09-25 17:54:57 -0700268 txq->bd = pci_alloc_consistent(dev,
269 sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX,
270 &txq->q.dma_addr);
271
272 if (!txq->bd) {
273 IWL_ERROR("pci_alloc_consistent(%zd) failed\n",
274 sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX);
275 goto error;
276 }
277 txq->q.id = id;
278
279 return 0;
280
281 error:
282 if (txq->txb) {
283 kfree(txq->txb);
284 txq->txb = NULL;
285 }
286
287 return -ENOMEM;
288}
289
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800290/**
291 * iwl4965_tx_queue_init - Allocate and initialize one tx/cmd queue
292 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700293int iwl4965_tx_queue_init(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800294 struct iwl4965_tx_queue *txq, int slots_num, u32 txq_id)
Zhu Yib481de92007-09-25 17:54:57 -0700295{
296 struct pci_dev *dev = priv->pci_dev;
297 int len;
298 int rc = 0;
299
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800300 /*
301 * Alloc buffer array for commands (Tx or other types of commands).
302 * For the command queue (#4), allocate command space + one big
303 * command for scan, since scan command is very huge; the system will
304 * not have two scans at the same time, so only one is needed.
Tomas Winklerbb542442007-12-05 20:59:59 +0200305 * For normal Tx queues (all other queues), no super-size command
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800306 * space is needed.
307 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800308 len = sizeof(struct iwl4965_cmd) * slots_num;
Zhu Yib481de92007-09-25 17:54:57 -0700309 if (txq_id == IWL_CMD_QUEUE_NUM)
310 len += IWL_MAX_SCAN_SIZE;
311 txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd);
312 if (!txq->cmd)
313 return -ENOMEM;
314
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800315 /* Alloc driver data array and TFD circular buffer */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800316 rc = iwl4965_tx_queue_alloc(priv, txq, txq_id);
Zhu Yib481de92007-09-25 17:54:57 -0700317 if (rc) {
318 pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
319
320 return -ENOMEM;
321 }
322 txq->need_update = 0;
323
324 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
Tomas Winklerc54b6792008-03-06 17:36:53 -0800325 * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */
Zhu Yib481de92007-09-25 17:54:57 -0700326 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800327
328 /* Initialize queue's high/low-water marks, and head/tail indexes */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800329 iwl4965_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id);
Zhu Yib481de92007-09-25 17:54:57 -0700330
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800331 /* Tell device where to find queue */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800332 iwl4965_hw_tx_queue_init(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -0700333
334 return 0;
335}
336
337/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800338 * iwl4965_tx_queue_free - Deallocate DMA queue.
Zhu Yib481de92007-09-25 17:54:57 -0700339 * @txq: Transmit queue to deallocate.
340 *
341 * Empty queue by removing and destroying all BD's.
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800342 * Free all buffers.
343 * 0-fill, but do not free "txq" descriptor structure.
Zhu Yib481de92007-09-25 17:54:57 -0700344 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700345void iwl4965_tx_queue_free(struct iwl_priv *priv, struct iwl4965_tx_queue *txq)
Zhu Yib481de92007-09-25 17:54:57 -0700346{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800347 struct iwl4965_queue *q = &txq->q;
Zhu Yib481de92007-09-25 17:54:57 -0700348 struct pci_dev *dev = priv->pci_dev;
349 int len;
350
351 if (q->n_bd == 0)
352 return;
353
354 /* first, empty all BD's */
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800355 for (; q->write_ptr != q->read_ptr;
Tomas Winklerc54b6792008-03-06 17:36:53 -0800356 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800357 iwl4965_hw_txq_free_tfd(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -0700358
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800359 len = sizeof(struct iwl4965_cmd) * q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -0700360 if (q->id == IWL_CMD_QUEUE_NUM)
361 len += IWL_MAX_SCAN_SIZE;
362
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800363 /* De-alloc array of command/tx buffers */
Zhu Yib481de92007-09-25 17:54:57 -0700364 pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
365
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800366 /* De-alloc circular buffer of TFDs */
Zhu Yib481de92007-09-25 17:54:57 -0700367 if (txq->q.n_bd)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800368 pci_free_consistent(dev, sizeof(struct iwl4965_tfd_frame) *
Zhu Yib481de92007-09-25 17:54:57 -0700369 txq->q.n_bd, txq->bd, txq->q.dma_addr);
370
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800371 /* De-alloc array of per-TFD driver data */
Zhu Yib481de92007-09-25 17:54:57 -0700372 if (txq->txb) {
373 kfree(txq->txb);
374 txq->txb = NULL;
375 }
376
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800377 /* 0-fill queue descriptor structure */
Zhu Yib481de92007-09-25 17:54:57 -0700378 memset(txq, 0, sizeof(*txq));
379}
380
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800381const u8 iwl4965_broadcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
Zhu Yib481de92007-09-25 17:54:57 -0700382
383/*************** STATION TABLE MANAGEMENT ****
Ben Cahill9fbab512007-11-29 11:09:47 +0800384 * mac80211 should be examined to determine if sta_info is duplicating
Zhu Yib481de92007-09-25 17:54:57 -0700385 * the functionality provided here
386 */
387
388/**************************************************************/
389
Ian Schram01ebd062007-10-25 17:15:22 +0800390#if 0 /* temporary disable till we add real remove station */
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800391/**
392 * iwl4965_remove_station - Remove driver's knowledge of station.
393 *
394 * NOTE: This does not remove station from device's station table.
395 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700396static u8 iwl4965_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
Zhu Yib481de92007-09-25 17:54:57 -0700397{
398 int index = IWL_INVALID_STATION;
399 int i;
400 unsigned long flags;
401
402 spin_lock_irqsave(&priv->sta_lock, flags);
403
404 if (is_ap)
405 index = IWL_AP_ID;
406 else if (is_broadcast_ether_addr(addr))
407 index = priv->hw_setting.bcast_sta_id;
408 else
409 for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++)
410 if (priv->stations[i].used &&
411 !compare_ether_addr(priv->stations[i].sta.sta.addr,
412 addr)) {
413 index = i;
414 break;
415 }
416
417 if (unlikely(index == IWL_INVALID_STATION))
418 goto out;
419
420 if (priv->stations[index].used) {
421 priv->stations[index].used = 0;
422 priv->num_stations--;
423 }
424
425 BUG_ON(priv->num_stations < 0);
426
427out:
428 spin_unlock_irqrestore(&priv->sta_lock, flags);
429 return 0;
430}
Zhu Yi556f8db2007-09-27 11:27:33 +0800431#endif
Zhu Yib481de92007-09-25 17:54:57 -0700432
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800433/**
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800434 * iwl4965_add_station_flags - Add station to tables in driver and device
435 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700436u8 iwl4965_add_station_flags(struct iwl_priv *priv, const u8 *addr,
Ron Rindjunsky67d62032007-11-26 16:14:40 +0200437 int is_ap, u8 flags, void *ht_data)
Zhu Yib481de92007-09-25 17:54:57 -0700438{
439 int i;
440 int index = IWL_INVALID_STATION;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800441 struct iwl4965_station_entry *station;
Zhu Yib481de92007-09-25 17:54:57 -0700442 unsigned long flags_spin;
Joe Perches0795af52007-10-03 17:59:30 -0700443 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -0700444
445 spin_lock_irqsave(&priv->sta_lock, flags_spin);
446 if (is_ap)
447 index = IWL_AP_ID;
448 else if (is_broadcast_ether_addr(addr))
449 index = priv->hw_setting.bcast_sta_id;
450 else
451 for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) {
452 if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
453 addr)) {
454 index = i;
455 break;
456 }
457
458 if (!priv->stations[i].used &&
459 index == IWL_INVALID_STATION)
460 index = i;
461 }
462
463
Ben Cahill9fbab512007-11-29 11:09:47 +0800464 /* These two conditions have the same outcome, but keep them separate
465 since they have different meanings */
Zhu Yib481de92007-09-25 17:54:57 -0700466 if (unlikely(index == IWL_INVALID_STATION)) {
467 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
468 return index;
469 }
470
471 if (priv->stations[index].used &&
472 !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) {
473 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
474 return index;
475 }
476
477
Joe Perches0795af52007-10-03 17:59:30 -0700478 IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index, print_mac(mac, addr));
Zhu Yib481de92007-09-25 17:54:57 -0700479 station = &priv->stations[index];
480 station->used = 1;
481 priv->num_stations++;
482
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800483 /* Set up the REPLY_ADD_STA command to send to device */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800484 memset(&station->sta, 0, sizeof(struct iwl4965_addsta_cmd));
Zhu Yib481de92007-09-25 17:54:57 -0700485 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
486 station->sta.mode = 0;
487 station->sta.sta.sta_id = index;
488 station->sta.station_flags = 0;
489
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800490#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -0700491 /* BCAST station and IBSS stations do not work in HT mode */
492 if (index != priv->hw_setting.bcast_sta_id &&
493 priv->iw_mode != IEEE80211_IF_TYPE_IBSS)
Ron Rindjunsky67d62032007-11-26 16:14:40 +0200494 iwl4965_set_ht_add_station(priv, index,
495 (struct ieee80211_ht_info *) ht_data);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800496#endif /*CONFIG_IWL4965_HT*/
Zhu Yib481de92007-09-25 17:54:57 -0700497
498 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800499
500 /* Add station to device's station table */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800501 iwl4965_send_add_station(priv, &station->sta, flags);
Zhu Yib481de92007-09-25 17:54:57 -0700502 return index;
503
504}
505
506/*************** DRIVER STATUS FUNCTIONS *****/
507
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700508static inline int iwl4965_is_ready(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700509{
510 /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are
511 * set but EXIT_PENDING is not */
512 return test_bit(STATUS_READY, &priv->status) &&
513 test_bit(STATUS_GEO_CONFIGURED, &priv->status) &&
514 !test_bit(STATUS_EXIT_PENDING, &priv->status);
515}
516
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700517static inline int iwl4965_is_alive(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700518{
519 return test_bit(STATUS_ALIVE, &priv->status);
520}
521
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700522static inline int iwl4965_is_init(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700523{
524 return test_bit(STATUS_INIT, &priv->status);
525}
526
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700527static inline int iwl4965_is_rfkill(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700528{
529 return test_bit(STATUS_RF_KILL_HW, &priv->status) ||
530 test_bit(STATUS_RF_KILL_SW, &priv->status);
531}
532
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700533static inline int iwl4965_is_ready_rf(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700534{
535
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800536 if (iwl4965_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700537 return 0;
538
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800539 return iwl4965_is_ready(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700540}
541
542/*************** HOST COMMAND QUEUE FUNCTIONS *****/
543
544#define IWL_CMD(x) case x : return #x
545
546static const char *get_cmd_string(u8 cmd)
547{
548 switch (cmd) {
549 IWL_CMD(REPLY_ALIVE);
550 IWL_CMD(REPLY_ERROR);
551 IWL_CMD(REPLY_RXON);
552 IWL_CMD(REPLY_RXON_ASSOC);
553 IWL_CMD(REPLY_QOS_PARAM);
554 IWL_CMD(REPLY_RXON_TIMING);
555 IWL_CMD(REPLY_ADD_STA);
556 IWL_CMD(REPLY_REMOVE_STA);
557 IWL_CMD(REPLY_REMOVE_ALL_STA);
558 IWL_CMD(REPLY_TX);
559 IWL_CMD(REPLY_RATE_SCALE);
560 IWL_CMD(REPLY_LEDS_CMD);
561 IWL_CMD(REPLY_TX_LINK_QUALITY_CMD);
562 IWL_CMD(RADAR_NOTIFICATION);
563 IWL_CMD(REPLY_QUIET_CMD);
564 IWL_CMD(REPLY_CHANNEL_SWITCH);
565 IWL_CMD(CHANNEL_SWITCH_NOTIFICATION);
566 IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD);
567 IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION);
568 IWL_CMD(POWER_TABLE_CMD);
569 IWL_CMD(PM_SLEEP_NOTIFICATION);
570 IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC);
571 IWL_CMD(REPLY_SCAN_CMD);
572 IWL_CMD(REPLY_SCAN_ABORT_CMD);
573 IWL_CMD(SCAN_START_NOTIFICATION);
574 IWL_CMD(SCAN_RESULTS_NOTIFICATION);
575 IWL_CMD(SCAN_COMPLETE_NOTIFICATION);
576 IWL_CMD(BEACON_NOTIFICATION);
577 IWL_CMD(REPLY_TX_BEACON);
578 IWL_CMD(WHO_IS_AWAKE_NOTIFICATION);
579 IWL_CMD(QUIET_NOTIFICATION);
580 IWL_CMD(REPLY_TX_PWR_TABLE_CMD);
581 IWL_CMD(MEASURE_ABORT_NOTIFICATION);
582 IWL_CMD(REPLY_BT_CONFIG);
583 IWL_CMD(REPLY_STATISTICS_CMD);
584 IWL_CMD(STATISTICS_NOTIFICATION);
585 IWL_CMD(REPLY_CARD_STATE_CMD);
586 IWL_CMD(CARD_STATE_NOTIFICATION);
587 IWL_CMD(MISSED_BEACONS_NOTIFICATION);
588 IWL_CMD(REPLY_CT_KILL_CONFIG_CMD);
589 IWL_CMD(SENSITIVITY_CMD);
590 IWL_CMD(REPLY_PHY_CALIBRATION_CMD);
591 IWL_CMD(REPLY_RX_PHY_CMD);
592 IWL_CMD(REPLY_RX_MPDU_CMD);
593 IWL_CMD(REPLY_4965_RX);
594 IWL_CMD(REPLY_COMPRESSED_BA);
595 default:
596 return "UNKNOWN";
597
598 }
599}
600
601#define HOST_COMPLETE_TIMEOUT (HZ / 2)
602
603/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800604 * iwl4965_enqueue_hcmd - enqueue a uCode command
Zhu Yib481de92007-09-25 17:54:57 -0700605 * @priv: device private data point
606 * @cmd: a point to the ucode command structure
607 *
608 * The function returns < 0 values to indicate the operation is
609 * failed. On success, it turns the index (> 0) of command in the
610 * command queue.
611 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700612static int iwl4965_enqueue_hcmd(struct iwl_priv *priv, struct iwl4965_host_cmd *cmd)
Zhu Yib481de92007-09-25 17:54:57 -0700613{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800614 struct iwl4965_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
615 struct iwl4965_queue *q = &txq->q;
616 struct iwl4965_tfd_frame *tfd;
Zhu Yib481de92007-09-25 17:54:57 -0700617 u32 *control_flags;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800618 struct iwl4965_cmd *out_cmd;
Zhu Yib481de92007-09-25 17:54:57 -0700619 u32 idx;
620 u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
621 dma_addr_t phys_addr;
622 int ret;
623 unsigned long flags;
624
625 /* If any of the command structures end up being larger than
626 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
627 * we will need to increase the size of the TFD entries */
628 BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
629 !(cmd->meta.flags & CMD_SIZE_HUGE));
630
Gregory Greenmanc342a1b2008-02-06 11:20:40 -0800631 if (iwl4965_is_rfkill(priv)) {
632 IWL_DEBUG_INFO("Not sending command - RF KILL");
633 return -EIO;
634 }
635
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800636 if (iwl4965_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) {
Zhu Yib481de92007-09-25 17:54:57 -0700637 IWL_ERROR("No space for Tx\n");
638 return -ENOSPC;
639 }
640
641 spin_lock_irqsave(&priv->hcmd_lock, flags);
642
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800643 tfd = &txq->bd[q->write_ptr];
Zhu Yib481de92007-09-25 17:54:57 -0700644 memset(tfd, 0, sizeof(*tfd));
645
646 control_flags = (u32 *) tfd;
647
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800648 idx = get_cmd_index(q, q->write_ptr, cmd->meta.flags & CMD_SIZE_HUGE);
Zhu Yib481de92007-09-25 17:54:57 -0700649 out_cmd = &txq->cmd[idx];
650
651 out_cmd->hdr.cmd = cmd->id;
652 memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta));
653 memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len);
654
655 /* At this point, the out_cmd now has all of the incoming cmd
656 * information */
657
658 out_cmd->hdr.flags = 0;
659 out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800660 INDEX_TO_SEQ(q->write_ptr));
Zhu Yib481de92007-09-25 17:54:57 -0700661 if (out_cmd->meta.flags & CMD_SIZE_HUGE)
662 out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME);
663
664 phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800665 offsetof(struct iwl4965_cmd, hdr);
666 iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size);
Zhu Yib481de92007-09-25 17:54:57 -0700667
668 IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
669 "%d bytes at %d[%d]:%d\n",
670 get_cmd_string(out_cmd->hdr.cmd),
671 out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence),
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800672 fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM);
Zhu Yib481de92007-09-25 17:54:57 -0700673
674 txq->need_update = 1;
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800675
676 /* Set up entry in queue's byte count circular buffer */
Zhu Yib481de92007-09-25 17:54:57 -0700677 ret = iwl4965_tx_queue_update_wr_ptr(priv, txq, 0);
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800678
679 /* Increment and update queue's write index */
Tomas Winklerc54b6792008-03-06 17:36:53 -0800680 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800681 iwl4965_tx_queue_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -0700682
683 spin_unlock_irqrestore(&priv->hcmd_lock, flags);
684 return ret ? ret : idx;
685}
686
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700687static int iwl4965_send_cmd_async(struct iwl_priv *priv, struct iwl4965_host_cmd *cmd)
Zhu Yib481de92007-09-25 17:54:57 -0700688{
689 int ret;
690
691 BUG_ON(!(cmd->meta.flags & CMD_ASYNC));
692
693 /* An asynchronous command can not expect an SKB to be set. */
694 BUG_ON(cmd->meta.flags & CMD_WANT_SKB);
695
696 /* An asynchronous command MUST have a callback. */
697 BUG_ON(!cmd->meta.u.callback);
698
699 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
700 return -EBUSY;
701
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800702 ret = iwl4965_enqueue_hcmd(priv, cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700703 if (ret < 0) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800704 IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700705 get_cmd_string(cmd->id), ret);
706 return ret;
707 }
708 return 0;
709}
710
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700711static int iwl4965_send_cmd_sync(struct iwl_priv *priv, struct iwl4965_host_cmd *cmd)
Zhu Yib481de92007-09-25 17:54:57 -0700712{
713 int cmd_idx;
714 int ret;
715 static atomic_t entry = ATOMIC_INIT(0); /* reentrance protection */
716
717 BUG_ON(cmd->meta.flags & CMD_ASYNC);
718
719 /* A synchronous command can not have a callback set. */
720 BUG_ON(cmd->meta.u.callback != NULL);
721
722 if (atomic_xchg(&entry, 1)) {
723 IWL_ERROR("Error sending %s: Already sending a host command\n",
724 get_cmd_string(cmd->id));
725 return -EBUSY;
726 }
727
728 set_bit(STATUS_HCMD_ACTIVE, &priv->status);
729
730 if (cmd->meta.flags & CMD_WANT_SKB)
731 cmd->meta.source = &cmd->meta;
732
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800733 cmd_idx = iwl4965_enqueue_hcmd(priv, cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700734 if (cmd_idx < 0) {
735 ret = cmd_idx;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800736 IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700737 get_cmd_string(cmd->id), ret);
738 goto out;
739 }
740
741 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
742 !test_bit(STATUS_HCMD_ACTIVE, &priv->status),
743 HOST_COMPLETE_TIMEOUT);
744 if (!ret) {
745 if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) {
746 IWL_ERROR("Error sending %s: time out after %dms.\n",
747 get_cmd_string(cmd->id),
748 jiffies_to_msecs(HOST_COMPLETE_TIMEOUT));
749
750 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
751 ret = -ETIMEDOUT;
752 goto cancel;
753 }
754 }
755
756 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
757 IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n",
758 get_cmd_string(cmd->id));
759 ret = -ECANCELED;
760 goto fail;
761 }
762 if (test_bit(STATUS_FW_ERROR, &priv->status)) {
763 IWL_DEBUG_INFO("Command %s failed: FW Error\n",
764 get_cmd_string(cmd->id));
765 ret = -EIO;
766 goto fail;
767 }
768 if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) {
769 IWL_ERROR("Error: Response NULL in '%s'\n",
770 get_cmd_string(cmd->id));
771 ret = -EIO;
772 goto out;
773 }
774
775 ret = 0;
776 goto out;
777
778cancel:
779 if (cmd->meta.flags & CMD_WANT_SKB) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800780 struct iwl4965_cmd *qcmd;
Zhu Yib481de92007-09-25 17:54:57 -0700781
782 /* Cancel the CMD_WANT_SKB flag for the cmd in the
783 * TX cmd queue. Otherwise in case the cmd comes
784 * in later, it will possibly set an invalid
785 * address (cmd->meta.source). */
786 qcmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx];
787 qcmd->meta.flags &= ~CMD_WANT_SKB;
788 }
789fail:
790 if (cmd->meta.u.skb) {
791 dev_kfree_skb_any(cmd->meta.u.skb);
792 cmd->meta.u.skb = NULL;
793 }
794out:
795 atomic_set(&entry, 0);
796 return ret;
797}
798
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700799int iwl4965_send_cmd(struct iwl_priv *priv, struct iwl4965_host_cmd *cmd)
Zhu Yib481de92007-09-25 17:54:57 -0700800{
Zhu Yib481de92007-09-25 17:54:57 -0700801 if (cmd->meta.flags & CMD_ASYNC)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800802 return iwl4965_send_cmd_async(priv, cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700803
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800804 return iwl4965_send_cmd_sync(priv, cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700805}
806
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700807int iwl4965_send_cmd_pdu(struct iwl_priv *priv, u8 id, u16 len, const void *data)
Zhu Yib481de92007-09-25 17:54:57 -0700808{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800809 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700810 .id = id,
811 .len = len,
812 .data = data,
813 };
814
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800815 return iwl4965_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700816}
817
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700818static int __must_check iwl4965_send_cmd_u32(struct iwl_priv *priv, u8 id, u32 val)
Zhu Yib481de92007-09-25 17:54:57 -0700819{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800820 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700821 .id = id,
822 .len = sizeof(val),
823 .data = &val,
824 };
825
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800826 return iwl4965_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700827}
828
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700829int iwl4965_send_statistics_request(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700830{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800831 return iwl4965_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700832}
833
834/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800835 * iwl4965_rxon_add_station - add station into station table.
Zhu Yib481de92007-09-25 17:54:57 -0700836 *
837 * there is only one AP station with id= IWL_AP_ID
Ben Cahill9fbab512007-11-29 11:09:47 +0800838 * NOTE: mutex must be held before calling this fnction
839 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700840static int iwl4965_rxon_add_station(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700841 const u8 *addr, int is_ap)
842{
Zhu Yi556f8db2007-09-27 11:27:33 +0800843 u8 sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700844
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800845 /* Add station to device's station table */
Ron Rindjunsky67d62032007-11-26 16:14:40 +0200846#ifdef CONFIG_IWL4965_HT
847 struct ieee80211_conf *conf = &priv->hw->conf;
848 struct ieee80211_ht_info *cur_ht_config = &conf->ht_conf;
849
850 if ((is_ap) &&
851 (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) &&
852 (priv->iw_mode == IEEE80211_IF_TYPE_STA))
853 sta_id = iwl4965_add_station_flags(priv, addr, is_ap,
854 0, cur_ht_config);
855 else
856#endif /* CONFIG_IWL4965_HT */
857 sta_id = iwl4965_add_station_flags(priv, addr, is_ap,
858 0, NULL);
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800859
860 /* Set up default rate scaling table in device's station table */
Zhu Yib481de92007-09-25 17:54:57 -0700861 iwl4965_add_station(priv, addr, is_ap);
862
Zhu Yi556f8db2007-09-27 11:27:33 +0800863 return sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700864}
865
866/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800867 * iwl4965_check_rxon_cmd - validate RXON structure is valid
Zhu Yib481de92007-09-25 17:54:57 -0700868 *
869 * NOTE: This is really only useful during development and can eventually
870 * be #ifdef'd out once the driver is stable and folks aren't actively
871 * making changes
872 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800873static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd *rxon)
Zhu Yib481de92007-09-25 17:54:57 -0700874{
875 int error = 0;
876 int counter = 1;
877
878 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
879 error |= le32_to_cpu(rxon->flags &
880 (RXON_FLG_TGJ_NARROW_BAND_MSK |
881 RXON_FLG_RADAR_DETECT_MSK));
882 if (error)
883 IWL_WARNING("check 24G fields %d | %d\n",
884 counter++, error);
885 } else {
886 error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
887 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
888 if (error)
889 IWL_WARNING("check 52 fields %d | %d\n",
890 counter++, error);
891 error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
892 if (error)
893 IWL_WARNING("check 52 CCK %d | %d\n",
894 counter++, error);
895 }
896 error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
897 if (error)
898 IWL_WARNING("check mac addr %d | %d\n", counter++, error);
899
900 /* make sure basic rates 6Mbps and 1Mbps are supported */
901 error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
902 ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
903 if (error)
904 IWL_WARNING("check basic rate %d | %d\n", counter++, error);
905
906 error |= (le16_to_cpu(rxon->assoc_id) > 2007);
907 if (error)
908 IWL_WARNING("check assoc id %d | %d\n", counter++, error);
909
910 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
911 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
912 if (error)
913 IWL_WARNING("check CCK and short slot %d | %d\n",
914 counter++, error);
915
916 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
917 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
918 if (error)
919 IWL_WARNING("check CCK & auto detect %d | %d\n",
920 counter++, error);
921
922 error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
923 RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
924 if (error)
925 IWL_WARNING("check TGG and auto detect %d | %d\n",
926 counter++, error);
927
928 if (error)
929 IWL_WARNING("Tuning to channel %d\n",
930 le16_to_cpu(rxon->channel));
931
932 if (error) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800933 IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
Zhu Yib481de92007-09-25 17:54:57 -0700934 return -1;
935 }
936 return 0;
937}
938
939/**
Ben Cahill9fbab512007-11-29 11:09:47 +0800940 * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
Ian Schram01ebd062007-10-25 17:15:22 +0800941 * @priv: staging_rxon is compared to active_rxon
Zhu Yib481de92007-09-25 17:54:57 -0700942 *
Ben Cahill9fbab512007-11-29 11:09:47 +0800943 * If the RXON structure is changing enough to require a new tune,
944 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
945 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
Zhu Yib481de92007-09-25 17:54:57 -0700946 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700947static int iwl4965_full_rxon_required(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700948{
949
950 /* These items are only settable from the full RXON command */
951 if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ||
952 compare_ether_addr(priv->staging_rxon.bssid_addr,
953 priv->active_rxon.bssid_addr) ||
954 compare_ether_addr(priv->staging_rxon.node_addr,
955 priv->active_rxon.node_addr) ||
956 compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
957 priv->active_rxon.wlap_bssid_addr) ||
958 (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
959 (priv->staging_rxon.channel != priv->active_rxon.channel) ||
960 (priv->staging_rxon.air_propagation !=
961 priv->active_rxon.air_propagation) ||
962 (priv->staging_rxon.ofdm_ht_single_stream_basic_rates !=
963 priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
964 (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
965 priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
966 (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) ||
967 (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
968 return 1;
969
970 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
971 * be updated with the RXON_ASSOC command -- however only some
972 * flag transitions are allowed using RXON_ASSOC */
973
974 /* Check if we are not switching bands */
975 if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
976 (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
977 return 1;
978
979 /* Check if we are switching association toggle */
980 if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
981 (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
982 return 1;
983
984 return 0;
985}
986
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700987static int iwl4965_send_rxon_assoc(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700988{
989 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800990 struct iwl4965_rx_packet *res = NULL;
991 struct iwl4965_rxon_assoc_cmd rxon_assoc;
992 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700993 .id = REPLY_RXON_ASSOC,
994 .len = sizeof(rxon_assoc),
995 .meta.flags = CMD_WANT_SKB,
996 .data = &rxon_assoc,
997 };
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800998 const struct iwl4965_rxon_cmd *rxon1 = &priv->staging_rxon;
999 const struct iwl4965_rxon_cmd *rxon2 = &priv->active_rxon;
Zhu Yib481de92007-09-25 17:54:57 -07001000
1001 if ((rxon1->flags == rxon2->flags) &&
1002 (rxon1->filter_flags == rxon2->filter_flags) &&
1003 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
1004 (rxon1->ofdm_ht_single_stream_basic_rates ==
1005 rxon2->ofdm_ht_single_stream_basic_rates) &&
1006 (rxon1->ofdm_ht_dual_stream_basic_rates ==
1007 rxon2->ofdm_ht_dual_stream_basic_rates) &&
1008 (rxon1->rx_chain == rxon2->rx_chain) &&
1009 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
1010 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
1011 return 0;
1012 }
1013
1014 rxon_assoc.flags = priv->staging_rxon.flags;
1015 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
1016 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
1017 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
1018 rxon_assoc.reserved = 0;
1019 rxon_assoc.ofdm_ht_single_stream_basic_rates =
1020 priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
1021 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
1022 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
1023 rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
1024
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001025 rc = iwl4965_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001026 if (rc)
1027 return rc;
1028
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001029 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001030 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1031 IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n");
1032 rc = -EIO;
1033 }
1034
1035 priv->alloc_rxb_skb--;
1036 dev_kfree_skb_any(cmd.meta.u.skb);
1037
1038 return rc;
1039}
1040
1041/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001042 * iwl4965_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -07001043 *
Ian Schram01ebd062007-10-25 17:15:22 +08001044 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -07001045 * the active_rxon structure is updated with the new data. This
1046 * function correctly transitions out of the RXON_ASSOC_MSK state if
1047 * a HW tune is required based on the RXON structure changes.
1048 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001049static int iwl4965_commit_rxon(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001050{
1051 /* cast away the const for active_rxon in this function */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001052 struct iwl4965_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
Joe Perches0795af52007-10-03 17:59:30 -07001053 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07001054 int rc = 0;
1055
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001056 if (!iwl4965_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001057 return -1;
1058
1059 /* always get timestamp with Rx frame */
1060 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
1061
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001062 rc = iwl4965_check_rxon_cmd(&priv->staging_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07001063 if (rc) {
1064 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
1065 return -EINVAL;
1066 }
1067
1068 /* If we don't need to send a full RXON, we can use
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001069 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -07001070 * and other flags for the current radio configuration. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001071 if (!iwl4965_full_rxon_required(priv)) {
1072 rc = iwl4965_send_rxon_assoc(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001073 if (rc) {
1074 IWL_ERROR("Error setting RXON_ASSOC "
1075 "configuration (%d).\n", rc);
1076 return rc;
1077 }
1078
1079 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
1080
1081 return 0;
1082 }
1083
1084 /* station table will be cleared */
1085 priv->assoc_station_added = 0;
1086
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001087#ifdef CONFIG_IWL4965_SENSITIVITY
Zhu Yib481de92007-09-25 17:54:57 -07001088 priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT;
1089 if (!priv->error_recovering)
1090 priv->start_calib = 0;
1091
1092 iwl4965_init_sensitivity(priv, CMD_ASYNC, 1);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001093#endif /* CONFIG_IWL4965_SENSITIVITY */
Zhu Yib481de92007-09-25 17:54:57 -07001094
1095 /* If we are currently associated and the new config requires
1096 * an RXON_ASSOC and the new config wants the associated mask enabled,
1097 * we must clear the associated from the active configuration
1098 * before we apply the new config */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001099 if (iwl4965_is_associated(priv) &&
Zhu Yib481de92007-09-25 17:54:57 -07001100 (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
1101 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
1102 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1103
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001104 rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON,
1105 sizeof(struct iwl4965_rxon_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07001106 &priv->active_rxon);
1107
1108 /* If the mask clearing failed then we set
1109 * active_rxon back to what it was previously */
1110 if (rc) {
1111 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
1112 IWL_ERROR("Error clearing ASSOC_MSK on current "
1113 "configuration (%d).\n", rc);
1114 return rc;
1115 }
Zhu Yib481de92007-09-25 17:54:57 -07001116 }
1117
1118 IWL_DEBUG_INFO("Sending RXON\n"
1119 "* with%s RXON_FILTER_ASSOC_MSK\n"
1120 "* channel = %d\n"
Joe Perches0795af52007-10-03 17:59:30 -07001121 "* bssid = %s\n",
Zhu Yib481de92007-09-25 17:54:57 -07001122 ((priv->staging_rxon.filter_flags &
1123 RXON_FILTER_ASSOC_MSK) ? "" : "out"),
1124 le16_to_cpu(priv->staging_rxon.channel),
Joe Perches0795af52007-10-03 17:59:30 -07001125 print_mac(mac, priv->staging_rxon.bssid_addr));
Zhu Yib481de92007-09-25 17:54:57 -07001126
1127 /* Apply the new configuration */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001128 rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON,
1129 sizeof(struct iwl4965_rxon_cmd), &priv->staging_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07001130 if (rc) {
1131 IWL_ERROR("Error setting new configuration (%d).\n", rc);
1132 return rc;
1133 }
1134
Assaf Kraussbf85ea42008-03-14 10:38:49 -07001135 iwlcore_clear_stations_table(priv);
Zhu Yi556f8db2007-09-27 11:27:33 +08001136
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001137#ifdef CONFIG_IWL4965_SENSITIVITY
Zhu Yib481de92007-09-25 17:54:57 -07001138 if (!priv->error_recovering)
1139 priv->start_calib = 0;
1140
1141 priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT;
1142 iwl4965_init_sensitivity(priv, CMD_ASYNC, 1);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001143#endif /* CONFIG_IWL4965_SENSITIVITY */
Zhu Yib481de92007-09-25 17:54:57 -07001144
1145 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
1146
1147 /* If we issue a new RXON command which required a tune then we must
1148 * send a new TXPOWER command or we won't be able to Tx any frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001149 rc = iwl4965_hw_reg_send_txpower(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001150 if (rc) {
1151 IWL_ERROR("Error setting Tx power (%d).\n", rc);
1152 return rc;
1153 }
1154
1155 /* Add the broadcast address so we can send broadcast frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001156 if (iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0) ==
Zhu Yib481de92007-09-25 17:54:57 -07001157 IWL_INVALID_STATION) {
1158 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
1159 return -EIO;
1160 }
1161
1162 /* If we have set the ASSOC_MSK and we are in BSS mode then
1163 * add the IWL_AP_ID to the station rate table */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001164 if (iwl4965_is_associated(priv) &&
Zhu Yib481de92007-09-25 17:54:57 -07001165 (priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001166 if (iwl4965_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1)
Zhu Yib481de92007-09-25 17:54:57 -07001167 == IWL_INVALID_STATION) {
1168 IWL_ERROR("Error adding AP address for transmit.\n");
1169 return -EIO;
1170 }
1171 priv->assoc_station_added = 1;
1172 }
1173
1174 return 0;
1175}
1176
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001177static int iwl4965_send_bt_config(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001178{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001179 struct iwl4965_bt_cmd bt_cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001180 .flags = 3,
1181 .lead_time = 0xAA,
1182 .max_kill = 1,
1183 .kill_ack_mask = 0,
1184 .kill_cts_mask = 0,
1185 };
1186
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001187 return iwl4965_send_cmd_pdu(priv, REPLY_BT_CONFIG,
1188 sizeof(struct iwl4965_bt_cmd), &bt_cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001189}
1190
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001191static int iwl4965_send_scan_abort(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001192{
1193 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001194 struct iwl4965_rx_packet *res;
1195 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001196 .id = REPLY_SCAN_ABORT_CMD,
1197 .meta.flags = CMD_WANT_SKB,
1198 };
1199
1200 /* If there isn't a scan actively going on in the hardware
1201 * then we are in between scan bands and not actually
1202 * actively scanning, so don't send the abort command */
1203 if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
1204 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1205 return 0;
1206 }
1207
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001208 rc = iwl4965_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001209 if (rc) {
1210 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1211 return rc;
1212 }
1213
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001214 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001215 if (res->u.status != CAN_ABORT_STATUS) {
1216 /* The scan abort will return 1 for success or
1217 * 2 for "failure". A failure condition can be
1218 * due to simply not being in an active scan which
1219 * can occur if we send the scan abort before we
1220 * the microcode has notified us that a scan is
1221 * completed. */
1222 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status);
1223 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1224 clear_bit(STATUS_SCAN_HW, &priv->status);
1225 }
1226
1227 dev_kfree_skb_any(cmd.meta.u.skb);
1228
1229 return rc;
1230}
1231
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001232static int iwl4965_card_state_sync_callback(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001233 struct iwl4965_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -07001234 struct sk_buff *skb)
1235{
1236 return 1;
1237}
1238
1239/*
1240 * CARD_STATE_CMD
1241 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001242 * Use: Sets the device's internal card state to enable, disable, or halt
Zhu Yib481de92007-09-25 17:54:57 -07001243 *
1244 * When in the 'enable' state the card operates as normal.
1245 * When in the 'disable' state, the card enters into a low power mode.
1246 * When in the 'halt' state, the card is shut down and must be fully
1247 * restarted to come back on.
1248 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001249static int iwl4965_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag)
Zhu Yib481de92007-09-25 17:54:57 -07001250{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001251 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001252 .id = REPLY_CARD_STATE_CMD,
1253 .len = sizeof(u32),
1254 .data = &flags,
1255 .meta.flags = meta_flag,
1256 };
1257
1258 if (meta_flag & CMD_ASYNC)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001259 cmd.meta.u.callback = iwl4965_card_state_sync_callback;
Zhu Yib481de92007-09-25 17:54:57 -07001260
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001261 return iwl4965_send_cmd(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001262}
1263
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001264static int iwl4965_add_sta_sync_callback(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001265 struct iwl4965_cmd *cmd, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07001266{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001267 struct iwl4965_rx_packet *res = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001268
1269 if (!skb) {
1270 IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
1271 return 1;
1272 }
1273
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001274 res = (struct iwl4965_rx_packet *)skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001275 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1276 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1277 res->hdr.flags);
1278 return 1;
1279 }
1280
1281 switch (res->u.add_sta.status) {
1282 case ADD_STA_SUCCESS_MSK:
1283 break;
1284 default:
1285 break;
1286 }
1287
1288 /* We didn't cache the SKB; let the caller free it */
1289 return 1;
1290}
1291
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001292int iwl4965_send_add_station(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001293 struct iwl4965_addsta_cmd *sta, u8 flags)
Zhu Yib481de92007-09-25 17:54:57 -07001294{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001295 struct iwl4965_rx_packet *res = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001296 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001297 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001298 .id = REPLY_ADD_STA,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001299 .len = sizeof(struct iwl4965_addsta_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07001300 .meta.flags = flags,
1301 .data = sta,
1302 };
1303
1304 if (flags & CMD_ASYNC)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001305 cmd.meta.u.callback = iwl4965_add_sta_sync_callback;
Zhu Yib481de92007-09-25 17:54:57 -07001306 else
1307 cmd.meta.flags |= CMD_WANT_SKB;
1308
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001309 rc = iwl4965_send_cmd(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001310
1311 if (rc || (flags & CMD_ASYNC))
1312 return rc;
1313
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001314 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001315 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1316 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1317 res->hdr.flags);
1318 rc = -EIO;
1319 }
1320
1321 if (rc == 0) {
1322 switch (res->u.add_sta.status) {
1323 case ADD_STA_SUCCESS_MSK:
1324 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
1325 break;
1326 default:
1327 rc = -EIO;
1328 IWL_WARNING("REPLY_ADD_STA failed\n");
1329 break;
1330 }
1331 }
1332
1333 priv->alloc_rxb_skb--;
1334 dev_kfree_skb_any(cmd.meta.u.skb);
1335
1336 return rc;
1337}
1338
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001339static int iwl4965_update_sta_key_info(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001340 struct ieee80211_key_conf *keyconf,
1341 u8 sta_id)
1342{
1343 unsigned long flags;
1344 __le16 key_flags = 0;
1345
1346 switch (keyconf->alg) {
1347 case ALG_CCMP:
1348 key_flags |= STA_KEY_FLG_CCMP;
1349 key_flags |= cpu_to_le16(
1350 keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
1351 key_flags &= ~STA_KEY_FLG_INVALID;
1352 break;
1353 case ALG_TKIP:
1354 case ALG_WEP:
Zhu Yib481de92007-09-25 17:54:57 -07001355 default:
1356 return -EINVAL;
1357 }
1358 spin_lock_irqsave(&priv->sta_lock, flags);
1359 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
1360 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
1361 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
1362 keyconf->keylen);
1363
1364 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
1365 keyconf->keylen);
1366 priv->stations[sta_id].sta.key.key_flags = key_flags;
1367 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1368 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1369
1370 spin_unlock_irqrestore(&priv->sta_lock, flags);
1371
1372 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001373 iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001374 return 0;
1375}
1376
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001377static int iwl4965_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
Zhu Yib481de92007-09-25 17:54:57 -07001378{
1379 unsigned long flags;
1380
1381 spin_lock_irqsave(&priv->sta_lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001382 memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl4965_hw_key));
1383 memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl4965_keyinfo));
Zhu Yib481de92007-09-25 17:54:57 -07001384 priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
1385 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1386 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1387 spin_unlock_irqrestore(&priv->sta_lock, flags);
1388
1389 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001390 iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001391 return 0;
1392}
1393
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001394static void iwl4965_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001395{
1396 struct list_head *element;
1397
1398 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
1399 priv->frames_count);
1400
1401 while (!list_empty(&priv->free_frames)) {
1402 element = priv->free_frames.next;
1403 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001404 kfree(list_entry(element, struct iwl4965_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -07001405 priv->frames_count--;
1406 }
1407
1408 if (priv->frames_count) {
1409 IWL_WARNING("%d frames still in use. Did we lose one?\n",
1410 priv->frames_count);
1411 priv->frames_count = 0;
1412 }
1413}
1414
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001415static struct iwl4965_frame *iwl4965_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001416{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001417 struct iwl4965_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -07001418 struct list_head *element;
1419 if (list_empty(&priv->free_frames)) {
1420 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
1421 if (!frame) {
1422 IWL_ERROR("Could not allocate frame!\n");
1423 return NULL;
1424 }
1425
1426 priv->frames_count++;
1427 return frame;
1428 }
1429
1430 element = priv->free_frames.next;
1431 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001432 return list_entry(element, struct iwl4965_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -07001433}
1434
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001435static void iwl4965_free_frame(struct iwl_priv *priv, struct iwl4965_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -07001436{
1437 memset(frame, 0, sizeof(*frame));
1438 list_add(&frame->list, &priv->free_frames);
1439}
1440
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001441unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001442 struct ieee80211_hdr *hdr,
1443 const u8 *dest, int left)
1444{
1445
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001446 if (!iwl4965_is_associated(priv) || !priv->ibss_beacon ||
Zhu Yib481de92007-09-25 17:54:57 -07001447 ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) &&
1448 (priv->iw_mode != IEEE80211_IF_TYPE_AP)))
1449 return 0;
1450
1451 if (priv->ibss_beacon->len > left)
1452 return 0;
1453
1454 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
1455
1456 return priv->ibss_beacon->len;
1457}
1458
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001459static u8 iwl4965_rate_get_lowest_plcp(int rate_mask)
Zhu Yib481de92007-09-25 17:54:57 -07001460{
1461 u8 i;
1462
1463 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001464 i = iwl4965_rates[i].next_ieee) {
Zhu Yib481de92007-09-25 17:54:57 -07001465 if (rate_mask & (1 << i))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001466 return iwl4965_rates[i].plcp;
Zhu Yib481de92007-09-25 17:54:57 -07001467 }
1468
1469 return IWL_RATE_INVALID;
1470}
1471
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001472static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001473{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001474 struct iwl4965_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -07001475 unsigned int frame_size;
1476 int rc;
1477 u8 rate;
1478
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001479 frame = iwl4965_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001480
1481 if (!frame) {
1482 IWL_ERROR("Could not obtain free frame buffer for beacon "
1483 "command.\n");
1484 return -ENOMEM;
1485 }
1486
1487 if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001488 rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic &
Zhu Yib481de92007-09-25 17:54:57 -07001489 0xFF0);
1490 if (rate == IWL_INVALID_RATE)
1491 rate = IWL_RATE_6M_PLCP;
1492 } else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001493 rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic & 0xF);
Zhu Yib481de92007-09-25 17:54:57 -07001494 if (rate == IWL_INVALID_RATE)
1495 rate = IWL_RATE_1M_PLCP;
1496 }
1497
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001498 frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -07001499
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001500 rc = iwl4965_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -07001501 &frame->u.cmd[0]);
1502
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001503 iwl4965_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -07001504
1505 return rc;
1506}
1507
1508/******************************************************************************
1509 *
Zhu Yib481de92007-09-25 17:54:57 -07001510 * Misc. internal state and helper functions
1511 *
1512 ******************************************************************************/
Zhu Yib481de92007-09-25 17:54:57 -07001513
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001514static void iwl4965_unset_hw_setting(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001515{
1516 if (priv->hw_setting.shared_virt)
1517 pci_free_consistent(priv->pci_dev,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001518 sizeof(struct iwl4965_shared),
Zhu Yib481de92007-09-25 17:54:57 -07001519 priv->hw_setting.shared_virt,
1520 priv->hw_setting.shared_phys);
1521}
1522
1523/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001524 * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field
Zhu Yib481de92007-09-25 17:54:57 -07001525 *
1526 * return : set the bit for each supported rate insert in ie
1527 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001528static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate,
Tomas Winklerc7c46672007-10-18 02:04:15 +02001529 u16 basic_rate, int *left)
Zhu Yib481de92007-09-25 17:54:57 -07001530{
1531 u16 ret_rates = 0, bit;
1532 int i;
Tomas Winklerc7c46672007-10-18 02:04:15 +02001533 u8 *cnt = ie;
1534 u8 *rates = ie + 1;
Zhu Yib481de92007-09-25 17:54:57 -07001535
1536 for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) {
1537 if (bit & supported_rate) {
1538 ret_rates |= bit;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001539 rates[*cnt] = iwl4965_rates[i].ieee |
Tomas Winklerc7c46672007-10-18 02:04:15 +02001540 ((bit & basic_rate) ? 0x80 : 0x00);
1541 (*cnt)++;
1542 (*left)--;
1543 if ((*left <= 0) ||
1544 (*cnt >= IWL_SUPPORTED_RATES_IE_LEN))
Zhu Yib481de92007-09-25 17:54:57 -07001545 break;
1546 }
1547 }
1548
1549 return ret_rates;
1550}
1551
Zhu Yib481de92007-09-25 17:54:57 -07001552/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001553 * iwl4965_fill_probe_req - fill in all required fields and IE for probe request
Zhu Yib481de92007-09-25 17:54:57 -07001554 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001555static u16 iwl4965_fill_probe_req(struct iwl_priv *priv,
Tomas Winkler78330fd2008-02-06 02:37:18 +02001556 enum ieee80211_band band,
1557 struct ieee80211_mgmt *frame,
1558 int left, int is_direct)
Zhu Yib481de92007-09-25 17:54:57 -07001559{
1560 int len = 0;
1561 u8 *pos = NULL;
mabbasbee488d2007-10-25 17:15:42 +08001562 u16 active_rates, ret_rates, cck_rates, active_rate_basic;
Ron Rindjunsky8fb880322007-11-26 16:14:38 +02001563#ifdef CONFIG_IWL4965_HT
Tomas Winkler78330fd2008-02-06 02:37:18 +02001564 const struct ieee80211_supported_band *sband =
1565 iwl4965_get_hw_mode(priv, band);
Ron Rindjunsky8fb880322007-11-26 16:14:38 +02001566#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07001567
1568 /* Make sure there is enough space for the probe request,
1569 * two mandatory IEs and the data */
1570 left -= 24;
1571 if (left < 0)
1572 return 0;
1573 len += 24;
1574
1575 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001576 memcpy(frame->da, iwl4965_broadcast_addr, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07001577 memcpy(frame->sa, priv->mac_addr, ETH_ALEN);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001578 memcpy(frame->bssid, iwl4965_broadcast_addr, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07001579 frame->seq_ctrl = 0;
1580
1581 /* fill in our indirect SSID IE */
1582 /* ...next IE... */
1583
1584 left -= 2;
1585 if (left < 0)
1586 return 0;
1587 len += 2;
1588 pos = &(frame->u.probe_req.variable[0]);
1589 *pos++ = WLAN_EID_SSID;
1590 *pos++ = 0;
1591
1592 /* fill in our direct SSID IE... */
1593 if (is_direct) {
1594 /* ...next IE... */
1595 left -= 2 + priv->essid_len;
1596 if (left < 0)
1597 return 0;
1598 /* ... fill it in... */
1599 *pos++ = WLAN_EID_SSID;
1600 *pos++ = priv->essid_len;
1601 memcpy(pos, priv->essid, priv->essid_len);
1602 pos += priv->essid_len;
1603 len += 2 + priv->essid_len;
1604 }
1605
1606 /* fill in supported rate */
1607 /* ...next IE... */
1608 left -= 2;
1609 if (left < 0)
1610 return 0;
Tomas Winklerc7c46672007-10-18 02:04:15 +02001611
Zhu Yib481de92007-09-25 17:54:57 -07001612 /* ... fill it in... */
1613 *pos++ = WLAN_EID_SUPP_RATES;
1614 *pos = 0;
Tomas Winklerc7c46672007-10-18 02:04:15 +02001615
mabbasbee488d2007-10-25 17:15:42 +08001616 /* exclude 60M rate */
1617 active_rates = priv->rates_mask;
1618 active_rates &= ~IWL_RATE_60M_MASK;
1619
1620 active_rate_basic = active_rates & IWL_BASIC_RATES_MASK;
Zhu Yib481de92007-09-25 17:54:57 -07001621
Tomas Winklerc7c46672007-10-18 02:04:15 +02001622 cck_rates = IWL_CCK_RATES_MASK & active_rates;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001623 ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates,
mabbasbee488d2007-10-25 17:15:42 +08001624 active_rate_basic, &left);
Tomas Winklerc7c46672007-10-18 02:04:15 +02001625 active_rates &= ~ret_rates;
1626
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001627 ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates,
mabbasbee488d2007-10-25 17:15:42 +08001628 active_rate_basic, &left);
Tomas Winklerc7c46672007-10-18 02:04:15 +02001629 active_rates &= ~ret_rates;
1630
Zhu Yib481de92007-09-25 17:54:57 -07001631 len += 2 + *pos;
1632 pos += (*pos) + 1;
Tomas Winklerc7c46672007-10-18 02:04:15 +02001633 if (active_rates == 0)
Zhu Yib481de92007-09-25 17:54:57 -07001634 goto fill_end;
1635
1636 /* fill in supported extended rate */
1637 /* ...next IE... */
1638 left -= 2;
1639 if (left < 0)
1640 return 0;
1641 /* ... fill it in... */
1642 *pos++ = WLAN_EID_EXT_SUPP_RATES;
1643 *pos = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001644 iwl4965_supported_rate_to_ie(pos, active_rates,
mabbasbee488d2007-10-25 17:15:42 +08001645 active_rate_basic, &left);
Zhu Yib481de92007-09-25 17:54:57 -07001646 if (*pos > 0)
1647 len += 2 + *pos;
1648
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001649#ifdef CONFIG_IWL4965_HT
Tomas Winkler78330fd2008-02-06 02:37:18 +02001650 if (sband && sband->ht_info.ht_supported) {
1651 struct ieee80211_ht_cap *ht_cap;
Zhu Yib481de92007-09-25 17:54:57 -07001652 pos += (*pos) + 1;
1653 *pos++ = WLAN_EID_HT_CAPABILITY;
Ron Rindjunsky8fb880322007-11-26 16:14:38 +02001654 *pos++ = sizeof(struct ieee80211_ht_cap);
Tomas Winkler78330fd2008-02-06 02:37:18 +02001655 ht_cap = (struct ieee80211_ht_cap *)pos;
1656 ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap);
1657 memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16);
1658 ht_cap->ampdu_params_info =(sband->ht_info.ampdu_factor &
1659 IEEE80211_HT_CAP_AMPDU_FACTOR) |
1660 ((sband->ht_info.ampdu_density << 2) &
1661 IEEE80211_HT_CAP_AMPDU_DENSITY);
Ron Rindjunsky8fb880322007-11-26 16:14:38 +02001662 len += 2 + sizeof(struct ieee80211_ht_cap);
Zhu Yib481de92007-09-25 17:54:57 -07001663 }
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001664#endif /*CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07001665
1666 fill_end:
1667 return (u16)len;
1668}
1669
1670/*
1671 * QoS support
1672*/
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001673static int iwl4965_send_qos_params_command(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001674 struct iwl4965_qosparam_cmd *qos)
Zhu Yib481de92007-09-25 17:54:57 -07001675{
1676
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001677 return iwl4965_send_cmd_pdu(priv, REPLY_QOS_PARAM,
1678 sizeof(struct iwl4965_qosparam_cmd), qos);
Zhu Yib481de92007-09-25 17:54:57 -07001679}
1680
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001681static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force)
Zhu Yib481de92007-09-25 17:54:57 -07001682{
1683 unsigned long flags;
1684
Zhu Yib481de92007-09-25 17:54:57 -07001685 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1686 return;
1687
1688 if (!priv->qos_data.qos_enable)
1689 return;
1690
1691 spin_lock_irqsave(&priv->lock, flags);
1692 priv->qos_data.def_qos_parm.qos_flags = 0;
1693
1694 if (priv->qos_data.qos_cap.q_AP.queue_request &&
1695 !priv->qos_data.qos_cap.q_AP.txop_request)
1696 priv->qos_data.def_qos_parm.qos_flags |=
1697 QOS_PARAM_FLG_TXOP_TYPE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001698 if (priv->qos_data.qos_active)
1699 priv->qos_data.def_qos_parm.qos_flags |=
1700 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
1701
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001702#ifdef CONFIG_IWL4965_HT
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02001703 if (priv->current_ht_config.is_ht)
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +08001704 priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001705#endif /* CONFIG_IWL4965_HT */
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +08001706
Zhu Yib481de92007-09-25 17:54:57 -07001707 spin_unlock_irqrestore(&priv->lock, flags);
1708
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001709 if (force || iwl4965_is_associated(priv)) {
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +08001710 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
1711 priv->qos_data.qos_active,
1712 priv->qos_data.def_qos_parm.qos_flags);
Zhu Yib481de92007-09-25 17:54:57 -07001713
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001714 iwl4965_send_qos_params_command(priv,
Zhu Yib481de92007-09-25 17:54:57 -07001715 &(priv->qos_data.def_qos_parm));
1716 }
1717}
1718
Zhu Yib481de92007-09-25 17:54:57 -07001719/*
1720 * Power management (not Tx power!) functions
1721 */
1722#define MSEC_TO_USEC 1024
1723
1724#define NOSLP __constant_cpu_to_le16(0), 0, 0
1725#define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0
1726#define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
1727#define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
1728 __constant_cpu_to_le32(X1), \
1729 __constant_cpu_to_le32(X2), \
1730 __constant_cpu_to_le32(X3), \
1731 __constant_cpu_to_le32(X4)}
1732
1733
1734/* default power management (not Tx power) table values */
1735/* for tim 0-10 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001736static struct iwl4965_power_vec_entry range_0[IWL_POWER_AC] = {
Zhu Yib481de92007-09-25 17:54:57 -07001737 {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1738 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
1739 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
1740 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
1741 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
1742 {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
1743};
1744
1745/* for tim > 10 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001746static struct iwl4965_power_vec_entry range_1[IWL_POWER_AC] = {
Zhu Yib481de92007-09-25 17:54:57 -07001747 {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1748 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
1749 SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
1750 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
1751 SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
1752 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
1753 SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
1754 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
1755 {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
1756 SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
1757};
1758
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001759int iwl4965_power_init_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001760{
1761 int rc = 0, i;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001762 struct iwl4965_power_mgr *pow_data;
1763 int size = sizeof(struct iwl4965_power_vec_entry) * IWL_POWER_AC;
Zhu Yib481de92007-09-25 17:54:57 -07001764 u16 pci_pm;
1765
1766 IWL_DEBUG_POWER("Initialize power \n");
1767
1768 pow_data = &(priv->power_data);
1769
1770 memset(pow_data, 0, sizeof(*pow_data));
1771
1772 pow_data->active_index = IWL_POWER_RANGE_0;
1773 pow_data->dtim_val = 0xffff;
1774
1775 memcpy(&pow_data->pwr_range_0[0], &range_0[0], size);
1776 memcpy(&pow_data->pwr_range_1[0], &range_1[0], size);
1777
1778 rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm);
1779 if (rc != 0)
1780 return 0;
1781 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001782 struct iwl4965_powertable_cmd *cmd;
Zhu Yib481de92007-09-25 17:54:57 -07001783
1784 IWL_DEBUG_POWER("adjust power command flags\n");
1785
1786 for (i = 0; i < IWL_POWER_AC; i++) {
1787 cmd = &pow_data->pwr_range_0[i].cmd;
1788
1789 if (pci_pm & 0x1)
1790 cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
1791 else
1792 cmd->flags |= IWL_POWER_PCI_PM_MSK;
1793 }
1794 }
1795 return rc;
1796}
1797
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001798static int iwl4965_update_power_cmd(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001799 struct iwl4965_powertable_cmd *cmd, u32 mode)
Zhu Yib481de92007-09-25 17:54:57 -07001800{
1801 int rc = 0, i;
1802 u8 skip;
1803 u32 max_sleep = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001804 struct iwl4965_power_vec_entry *range;
Zhu Yib481de92007-09-25 17:54:57 -07001805 u8 period = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001806 struct iwl4965_power_mgr *pow_data;
Zhu Yib481de92007-09-25 17:54:57 -07001807
1808 if (mode > IWL_POWER_INDEX_5) {
1809 IWL_DEBUG_POWER("Error invalid power mode \n");
1810 return -1;
1811 }
1812 pow_data = &(priv->power_data);
1813
1814 if (pow_data->active_index == IWL_POWER_RANGE_0)
1815 range = &pow_data->pwr_range_0[0];
1816 else
1817 range = &pow_data->pwr_range_1[1];
1818
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001819 memcpy(cmd, &range[mode].cmd, sizeof(struct iwl4965_powertable_cmd));
Zhu Yib481de92007-09-25 17:54:57 -07001820
1821#ifdef IWL_MAC80211_DISABLE
1822 if (priv->assoc_network != NULL) {
1823 unsigned long flags;
1824
1825 period = priv->assoc_network->tim.tim_period;
1826 }
1827#endif /*IWL_MAC80211_DISABLE */
1828 skip = range[mode].no_dtim;
1829
1830 if (period == 0) {
1831 period = 1;
1832 skip = 0;
1833 }
1834
1835 if (skip == 0) {
1836 max_sleep = period;
1837 cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
1838 } else {
1839 __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
1840 max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
1841 cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
1842 }
1843
1844 for (i = 0; i < IWL_POWER_VEC_SIZE; i++) {
1845 if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
1846 cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
1847 }
1848
1849 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags);
1850 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
1851 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
1852 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
1853 le32_to_cpu(cmd->sleep_interval[0]),
1854 le32_to_cpu(cmd->sleep_interval[1]),
1855 le32_to_cpu(cmd->sleep_interval[2]),
1856 le32_to_cpu(cmd->sleep_interval[3]),
1857 le32_to_cpu(cmd->sleep_interval[4]));
1858
1859 return rc;
1860}
1861
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001862static int iwl4965_send_power_mode(struct iwl_priv *priv, u32 mode)
Zhu Yib481de92007-09-25 17:54:57 -07001863{
John W. Linville9a62f732007-11-15 16:27:36 -05001864 u32 uninitialized_var(final_mode);
Zhu Yib481de92007-09-25 17:54:57 -07001865 int rc;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001866 struct iwl4965_powertable_cmd cmd;
Zhu Yib481de92007-09-25 17:54:57 -07001867
1868 /* If on battery, set to 3,
Ian Schram01ebd062007-10-25 17:15:22 +08001869 * if plugged into AC power, set to CAM ("continuously aware mode"),
Zhu Yib481de92007-09-25 17:54:57 -07001870 * else user level */
1871 switch (mode) {
1872 case IWL_POWER_BATTERY:
1873 final_mode = IWL_POWER_INDEX_3;
1874 break;
1875 case IWL_POWER_AC:
1876 final_mode = IWL_POWER_MODE_CAM;
1877 break;
1878 default:
1879 final_mode = mode;
1880 break;
1881 }
1882
1883 cmd.keep_alive_beacons = 0;
1884
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001885 iwl4965_update_power_cmd(priv, &cmd, final_mode);
Zhu Yib481de92007-09-25 17:54:57 -07001886
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001887 rc = iwl4965_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001888
1889 if (final_mode == IWL_POWER_MODE_CAM)
1890 clear_bit(STATUS_POWER_PMI, &priv->status);
1891 else
1892 set_bit(STATUS_POWER_PMI, &priv->status);
1893
1894 return rc;
1895}
1896
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001897int iwl4965_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
Zhu Yib481de92007-09-25 17:54:57 -07001898{
1899 /* Filter incoming packets to determine if they are targeted toward
1900 * this network, discarding packets coming from ourselves */
1901 switch (priv->iw_mode) {
1902 case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */
1903 /* packets from our adapter are dropped (echo) */
1904 if (!compare_ether_addr(header->addr2, priv->mac_addr))
1905 return 0;
1906 /* {broad,multi}cast packets to our IBSS go through */
1907 if (is_multicast_ether_addr(header->addr1))
1908 return !compare_ether_addr(header->addr3, priv->bssid);
1909 /* packets to our adapter go through */
1910 return !compare_ether_addr(header->addr1, priv->mac_addr);
1911 case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */
1912 /* packets from our adapter are dropped (echo) */
1913 if (!compare_ether_addr(header->addr3, priv->mac_addr))
1914 return 0;
1915 /* {broad,multi}cast packets to our BSS go through */
1916 if (is_multicast_ether_addr(header->addr1))
1917 return !compare_ether_addr(header->addr2, priv->bssid);
1918 /* packets to our adapter go through */
1919 return !compare_ether_addr(header->addr1, priv->mac_addr);
1920 }
1921
1922 return 1;
1923}
1924
1925#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1926
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001927static const char *iwl4965_get_tx_fail_reason(u32 status)
Zhu Yib481de92007-09-25 17:54:57 -07001928{
1929 switch (status & TX_STATUS_MSK) {
1930 case TX_STATUS_SUCCESS:
1931 return "SUCCESS";
1932 TX_STATUS_ENTRY(SHORT_LIMIT);
1933 TX_STATUS_ENTRY(LONG_LIMIT);
1934 TX_STATUS_ENTRY(FIFO_UNDERRUN);
1935 TX_STATUS_ENTRY(MGMNT_ABORT);
1936 TX_STATUS_ENTRY(NEXT_FRAG);
1937 TX_STATUS_ENTRY(LIFE_EXPIRE);
1938 TX_STATUS_ENTRY(DEST_PS);
1939 TX_STATUS_ENTRY(ABORTED);
1940 TX_STATUS_ENTRY(BT_RETRY);
1941 TX_STATUS_ENTRY(STA_INVALID);
1942 TX_STATUS_ENTRY(FRAG_DROPPED);
1943 TX_STATUS_ENTRY(TID_DISABLE);
1944 TX_STATUS_ENTRY(FRAME_FLUSHED);
1945 TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
1946 TX_STATUS_ENTRY(TX_LOCKED);
1947 TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
1948 }
1949
1950 return "UNKNOWN";
1951}
1952
1953/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001954 * iwl4965_scan_cancel - Cancel any currently executing HW scan
Zhu Yib481de92007-09-25 17:54:57 -07001955 *
1956 * NOTE: priv->mutex is not required before calling this function
1957 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001958static int iwl4965_scan_cancel(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001959{
1960 if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
1961 clear_bit(STATUS_SCANNING, &priv->status);
1962 return 0;
1963 }
1964
1965 if (test_bit(STATUS_SCANNING, &priv->status)) {
1966 if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
1967 IWL_DEBUG_SCAN("Queuing scan abort.\n");
1968 set_bit(STATUS_SCAN_ABORTING, &priv->status);
1969 queue_work(priv->workqueue, &priv->abort_scan);
1970
1971 } else
1972 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
1973
1974 return test_bit(STATUS_SCANNING, &priv->status);
1975 }
1976
1977 return 0;
1978}
1979
1980/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001981 * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan
Zhu Yib481de92007-09-25 17:54:57 -07001982 * @ms: amount of time to wait (in milliseconds) for scan to abort
1983 *
1984 * NOTE: priv->mutex must be held before calling this function
1985 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001986static int iwl4965_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms)
Zhu Yib481de92007-09-25 17:54:57 -07001987{
1988 unsigned long now = jiffies;
1989 int ret;
1990
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001991 ret = iwl4965_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001992 if (ret && ms) {
1993 mutex_unlock(&priv->mutex);
1994 while (!time_after(jiffies, now + msecs_to_jiffies(ms)) &&
1995 test_bit(STATUS_SCANNING, &priv->status))
1996 msleep(1);
1997 mutex_lock(&priv->mutex);
1998
1999 return test_bit(STATUS_SCANNING, &priv->status);
2000 }
2001
2002 return ret;
2003}
2004
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002005static void iwl4965_sequence_reset(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002006{
2007 /* Reset ieee stats */
2008
2009 /* We don't reset the net_device_stats (ieee->stats) on
2010 * re-association */
2011
2012 priv->last_seq_num = -1;
2013 priv->last_frag_num = -1;
2014 priv->last_packet_time = 0;
2015
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002016 iwl4965_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002017}
2018
2019#define MAX_UCODE_BEACON_INTERVAL 4096
2020#define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
2021
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002022static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -07002023{
2024 u16 new_val = 0;
2025 u16 beacon_factor = 0;
2026
2027 beacon_factor =
2028 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
2029 / MAX_UCODE_BEACON_INTERVAL;
2030 new_val = beacon_val / beacon_factor;
2031
2032 return cpu_to_le16(new_val);
2033}
2034
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002035static void iwl4965_setup_rxon_timing(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002036{
2037 u64 interval_tm_unit;
2038 u64 tsf, result;
2039 unsigned long flags;
2040 struct ieee80211_conf *conf = NULL;
2041 u16 beacon_int = 0;
2042
2043 conf = ieee80211_get_hw_conf(priv->hw);
2044
2045 spin_lock_irqsave(&priv->lock, flags);
2046 priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp1);
2047 priv->rxon_timing.timestamp.dw[0] = cpu_to_le32(priv->timestamp0);
2048
2049 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
2050
2051 tsf = priv->timestamp1;
2052 tsf = ((tsf << 32) | priv->timestamp0);
2053
2054 beacon_int = priv->beacon_int;
2055 spin_unlock_irqrestore(&priv->lock, flags);
2056
2057 if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
2058 if (beacon_int == 0) {
2059 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
2060 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
2061 } else {
2062 priv->rxon_timing.beacon_interval =
2063 cpu_to_le16(beacon_int);
2064 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002065 iwl4965_adjust_beacon_interval(
Zhu Yib481de92007-09-25 17:54:57 -07002066 le16_to_cpu(priv->rxon_timing.beacon_interval));
2067 }
2068
2069 priv->rxon_timing.atim_window = 0;
2070 } else {
2071 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002072 iwl4965_adjust_beacon_interval(conf->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -07002073 /* TODO: we need to get atim_window from upper stack
2074 * for now we set to 0 */
2075 priv->rxon_timing.atim_window = 0;
2076 }
2077
2078 interval_tm_unit =
2079 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
2080 result = do_div(tsf, interval_tm_unit);
2081 priv->rxon_timing.beacon_init_val =
2082 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
2083
2084 IWL_DEBUG_ASSOC
2085 ("beacon interval %d beacon timer %d beacon tim %d\n",
2086 le16_to_cpu(priv->rxon_timing.beacon_interval),
2087 le32_to_cpu(priv->rxon_timing.beacon_init_val),
2088 le16_to_cpu(priv->rxon_timing.atim_window));
2089}
2090
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002091static int iwl4965_scan_initiate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002092{
2093 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
2094 IWL_ERROR("APs don't scan.\n");
2095 return 0;
2096 }
2097
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002098 if (!iwl4965_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002099 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
2100 return -EIO;
2101 }
2102
2103 if (test_bit(STATUS_SCANNING, &priv->status)) {
2104 IWL_DEBUG_SCAN("Scan already in progress.\n");
2105 return -EAGAIN;
2106 }
2107
2108 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
2109 IWL_DEBUG_SCAN("Scan request while abort pending. "
2110 "Queuing.\n");
2111 return -EAGAIN;
2112 }
2113
2114 IWL_DEBUG_INFO("Starting scan...\n");
2115 priv->scan_bands = 2;
2116 set_bit(STATUS_SCANNING, &priv->status);
2117 priv->scan_start = jiffies;
2118 priv->scan_pass_start = priv->scan_start;
2119
2120 queue_work(priv->workqueue, &priv->request_scan);
2121
2122 return 0;
2123}
2124
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002125static int iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
Zhu Yib481de92007-09-25 17:54:57 -07002126{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002127 struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon;
Zhu Yib481de92007-09-25 17:54:57 -07002128
2129 if (hw_decrypt)
2130 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
2131 else
2132 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
2133
2134 return 0;
2135}
2136
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002137static void iwl4965_set_flags_for_phymode(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01002138 enum ieee80211_band band)
Zhu Yib481de92007-09-25 17:54:57 -07002139{
Johannes Berg8318d782008-01-24 19:38:38 +01002140 if (band == IEEE80211_BAND_5GHZ) {
Zhu Yib481de92007-09-25 17:54:57 -07002141 priv->staging_rxon.flags &=
2142 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
2143 | RXON_FLG_CCK_MSK);
2144 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2145 } else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002146 /* Copied from iwl4965_bg_post_associate() */
Zhu Yib481de92007-09-25 17:54:57 -07002147 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2148 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2149 else
2150 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2151
2152 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
2153 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2154
2155 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
2156 priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
2157 priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
2158 }
2159}
2160
2161/*
Ian Schram01ebd062007-10-25 17:15:22 +08002162 * initialize rxon structure with default values from eeprom
Zhu Yib481de92007-09-25 17:54:57 -07002163 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002164static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002165{
Assaf Kraussbf85ea42008-03-14 10:38:49 -07002166 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07002167
2168 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
2169
2170 switch (priv->iw_mode) {
2171 case IEEE80211_IF_TYPE_AP:
2172 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
2173 break;
2174
2175 case IEEE80211_IF_TYPE_STA:
2176 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
2177 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
2178 break;
2179
2180 case IEEE80211_IF_TYPE_IBSS:
2181 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
2182 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
2183 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
2184 RXON_FILTER_ACCEPT_GRP_MSK;
2185 break;
2186
2187 case IEEE80211_IF_TYPE_MNTR:
2188 priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
2189 priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
2190 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
2191 break;
2192 }
2193
2194#if 0
2195 /* TODO: Figure out when short_preamble would be set and cache from
2196 * that */
2197 if (!hw_to_local(priv->hw)->short_preamble)
2198 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2199 else
2200 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2201#endif
2202
Johannes Berg8318d782008-01-24 19:38:38 +01002203 ch_info = iwl4965_get_channel_info(priv, priv->band,
Zhu Yib481de92007-09-25 17:54:57 -07002204 le16_to_cpu(priv->staging_rxon.channel));
2205
2206 if (!ch_info)
2207 ch_info = &priv->channel_info[0];
2208
2209 /*
2210 * in some case A channels are all non IBSS
2211 * in this case force B/G channel
2212 */
2213 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
2214 !(is_channel_ibss(ch_info)))
2215 ch_info = &priv->channel_info[0];
2216
2217 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
Johannes Berg8318d782008-01-24 19:38:38 +01002218 priv->band = ch_info->band;
Zhu Yib481de92007-09-25 17:54:57 -07002219
Johannes Berg8318d782008-01-24 19:38:38 +01002220 iwl4965_set_flags_for_phymode(priv, priv->band);
Zhu Yib481de92007-09-25 17:54:57 -07002221
2222 priv->staging_rxon.ofdm_basic_rates =
2223 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
2224 priv->staging_rxon.cck_basic_rates =
2225 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
2226
2227 priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
2228 RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
2229 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2230 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
2231 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
2232 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
2233 iwl4965_set_rxon_chain(priv);
2234}
2235
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002236static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -07002237{
Zhu Yib481de92007-09-25 17:54:57 -07002238 if (mode == IEEE80211_IF_TYPE_IBSS) {
Assaf Kraussbf85ea42008-03-14 10:38:49 -07002239 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07002240
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002241 ch_info = iwl4965_get_channel_info(priv,
Johannes Berg8318d782008-01-24 19:38:38 +01002242 priv->band,
Zhu Yib481de92007-09-25 17:54:57 -07002243 le16_to_cpu(priv->staging_rxon.channel));
2244
2245 if (!ch_info || !is_channel_ibss(ch_info)) {
2246 IWL_ERROR("channel %d not IBSS channel\n",
2247 le16_to_cpu(priv->staging_rxon.channel));
2248 return -EINVAL;
2249 }
2250 }
2251
Zhu Yib481de92007-09-25 17:54:57 -07002252 priv->iw_mode = mode;
2253
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002254 iwl4965_connection_init_rx_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002255 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2256
Assaf Kraussbf85ea42008-03-14 10:38:49 -07002257 iwlcore_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002258
Mohamed Abbasfde35712007-11-29 11:10:15 +08002259 /* dont commit rxon if rf-kill is on*/
2260 if (!iwl4965_is_ready_rf(priv))
2261 return -EAGAIN;
2262
2263 cancel_delayed_work(&priv->scan_check);
2264 if (iwl4965_scan_cancel_timeout(priv, 100)) {
2265 IWL_WARNING("Aborted scan still in progress after 100ms\n");
2266 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2267 return -EAGAIN;
2268 }
2269
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002270 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002271
2272 return 0;
2273}
2274
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002275static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002276 struct ieee80211_tx_control *ctl,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002277 struct iwl4965_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -07002278 struct sk_buff *skb_frag,
2279 int last_frag)
2280{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002281 struct iwl4965_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo;
Zhu Yib481de92007-09-25 17:54:57 -07002282
2283 switch (keyinfo->alg) {
2284 case ALG_CCMP:
2285 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM;
2286 memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen);
Max Stepanov8236e182008-03-12 16:58:48 -07002287 if (ctl->flags & IEEE80211_TXCTL_AMPDU)
2288 cmd->cmd.tx.tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07002289 IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
2290 break;
2291
2292 case ALG_TKIP:
2293#if 0
2294 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP;
2295
2296 if (last_frag)
2297 memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8,
2298 8);
2299 else
2300 memset(cmd->cmd.tx.tkip_mic.byte, 0, 8);
2301#endif
2302 break;
2303
2304 case ALG_WEP:
2305 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP |
2306 (ctl->key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
2307
2308 if (keyinfo->keylen == 13)
2309 cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128;
2310
2311 memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen);
2312
2313 IWL_DEBUG_TX("Configuring packet for WEP encryption "
2314 "with key %d\n", ctl->key_idx);
2315 break;
2316
Zhu Yib481de92007-09-25 17:54:57 -07002317 default:
2318 printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg);
2319 break;
2320 }
2321}
2322
2323/*
2324 * handle build REPLY_TX command notification.
2325 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002326static void iwl4965_build_tx_cmd_basic(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002327 struct iwl4965_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -07002328 struct ieee80211_tx_control *ctrl,
2329 struct ieee80211_hdr *hdr,
2330 int is_unicast, u8 std_id)
2331{
2332 __le16 *qc;
2333 u16 fc = le16_to_cpu(hdr->frame_control);
2334 __le32 tx_flags = cmd->cmd.tx.tx_flags;
2335
2336 cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
2337 if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) {
2338 tx_flags |= TX_CMD_FLG_ACK_MSK;
2339 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
2340 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2341 if (ieee80211_is_probe_response(fc) &&
2342 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
2343 tx_flags |= TX_CMD_FLG_TSF_MSK;
2344 } else {
2345 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
2346 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2347 }
2348
Tomas Winkler87e4f7d2008-01-14 17:46:16 -08002349 if (ieee80211_is_back_request(fc))
2350 tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK;
2351
2352
Zhu Yib481de92007-09-25 17:54:57 -07002353 cmd->cmd.tx.sta_id = std_id;
2354 if (ieee80211_get_morefrag(hdr))
2355 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
2356
2357 qc = ieee80211_get_qos_ctrl(hdr);
2358 if (qc) {
2359 cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf);
2360 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
2361 } else
2362 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2363
2364 if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) {
2365 tx_flags |= TX_CMD_FLG_RTS_MSK;
2366 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
2367 } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) {
2368 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
2369 tx_flags |= TX_CMD_FLG_CTS_MSK;
2370 }
2371
2372 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
2373 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
2374
2375 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
2376 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
2377 if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ ||
2378 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
Ian Schrambc434dd2007-10-25 17:15:29 +08002379 cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3);
Zhu Yib481de92007-09-25 17:54:57 -07002380 else
Ian Schrambc434dd2007-10-25 17:15:29 +08002381 cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2);
Zhu Yib481de92007-09-25 17:54:57 -07002382 } else
2383 cmd->cmd.tx.timeout.pm_frame_timeout = 0;
2384
2385 cmd->cmd.tx.driver_txop = 0;
2386 cmd->cmd.tx.tx_flags = tx_flags;
2387 cmd->cmd.tx.next_frame_len = 0;
2388}
Tomas Winkler19758be2008-03-12 16:58:51 -07002389static void iwl_update_tx_stats(struct iwl_priv *priv, u16 fc, u16 len)
2390{
2391 /* 0 - mgmt, 1 - cnt, 2 - data */
2392 int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2;
2393 priv->tx_stats[idx].cnt++;
2394 priv->tx_stats[idx].bytes += len;
2395}
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002396/**
2397 * iwl4965_get_sta_id - Find station's index within station table
2398 *
2399 * If new IBSS station, create new entry in station table
2400 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002401static int iwl4965_get_sta_id(struct iwl_priv *priv,
Ben Cahill9fbab512007-11-29 11:09:47 +08002402 struct ieee80211_hdr *hdr)
Zhu Yib481de92007-09-25 17:54:57 -07002403{
2404 int sta_id;
2405 u16 fc = le16_to_cpu(hdr->frame_control);
Joe Perches0795af52007-10-03 17:59:30 -07002406 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07002407
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002408 /* If this frame is broadcast or management, use broadcast station id */
Zhu Yib481de92007-09-25 17:54:57 -07002409 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
2410 is_multicast_ether_addr(hdr->addr1))
2411 return priv->hw_setting.bcast_sta_id;
2412
2413 switch (priv->iw_mode) {
2414
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002415 /* If we are a client station in a BSS network, use the special
2416 * AP station entry (that's the only station we communicate with) */
Zhu Yib481de92007-09-25 17:54:57 -07002417 case IEEE80211_IF_TYPE_STA:
2418 return IWL_AP_ID;
2419
2420 /* If we are an AP, then find the station, or use BCAST */
2421 case IEEE80211_IF_TYPE_AP:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002422 sta_id = iwl4965_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07002423 if (sta_id != IWL_INVALID_STATION)
2424 return sta_id;
2425 return priv->hw_setting.bcast_sta_id;
2426
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002427 /* If this frame is going out to an IBSS network, find the station,
2428 * or create a new station table entry */
Zhu Yib481de92007-09-25 17:54:57 -07002429 case IEEE80211_IF_TYPE_IBSS:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002430 sta_id = iwl4965_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07002431 if (sta_id != IWL_INVALID_STATION)
2432 return sta_id;
2433
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002434 /* Create new station table entry */
Ron Rindjunsky67d62032007-11-26 16:14:40 +02002435 sta_id = iwl4965_add_station_flags(priv, hdr->addr1,
2436 0, CMD_ASYNC, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07002437
2438 if (sta_id != IWL_INVALID_STATION)
2439 return sta_id;
2440
Joe Perches0795af52007-10-03 17:59:30 -07002441 IWL_DEBUG_DROP("Station %s not in station map. "
Zhu Yib481de92007-09-25 17:54:57 -07002442 "Defaulting to broadcast...\n",
Joe Perches0795af52007-10-03 17:59:30 -07002443 print_mac(mac, hdr->addr1));
Tomas Winkler0a6857e2008-03-12 16:58:49 -07002444 iwl_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
Zhu Yib481de92007-09-25 17:54:57 -07002445 return priv->hw_setting.bcast_sta_id;
2446
2447 default:
Ian Schram01ebd062007-10-25 17:15:22 +08002448 IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002449 return priv->hw_setting.bcast_sta_id;
2450 }
2451}
2452
2453/*
2454 * start REPLY_TX command process
2455 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002456static int iwl4965_tx_skb(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002457 struct sk_buff *skb, struct ieee80211_tx_control *ctl)
2458{
2459 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002460 struct iwl4965_tfd_frame *tfd;
Zhu Yib481de92007-09-25 17:54:57 -07002461 u32 *control_flags;
2462 int txq_id = ctl->queue;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002463 struct iwl4965_tx_queue *txq = NULL;
2464 struct iwl4965_queue *q = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07002465 dma_addr_t phys_addr;
2466 dma_addr_t txcmd_phys;
Tomas Winkler87e4f7d2008-01-14 17:46:16 -08002467 dma_addr_t scratch_phys;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002468 struct iwl4965_cmd *out_cmd = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07002469 u16 len, idx, len_org;
2470 u8 id, hdr_len, unicast;
2471 u8 sta_id;
2472 u16 seq_number = 0;
2473 u16 fc;
2474 __le16 *qc;
2475 u8 wait_write_ptr = 0;
2476 unsigned long flags;
2477 int rc;
2478
2479 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002480 if (iwl4965_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002481 IWL_DEBUG_DROP("Dropping - RF KILL\n");
2482 goto drop_unlock;
2483 }
2484
Johannes Berg32bfd352007-12-19 01:31:26 +01002485 if (!priv->vif) {
2486 IWL_DEBUG_DROP("Dropping - !priv->vif\n");
Zhu Yib481de92007-09-25 17:54:57 -07002487 goto drop_unlock;
2488 }
2489
Johannes Berg8318d782008-01-24 19:38:38 +01002490 if ((ctl->tx_rate->hw_value & 0xFF) == IWL_INVALID_RATE) {
Zhu Yib481de92007-09-25 17:54:57 -07002491 IWL_ERROR("ERROR: No TX rate available.\n");
2492 goto drop_unlock;
2493 }
2494
2495 unicast = !is_multicast_ether_addr(hdr->addr1);
2496 id = 0;
2497
2498 fc = le16_to_cpu(hdr->frame_control);
2499
Tomas Winkler0a6857e2008-03-12 16:58:49 -07002500#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07002501 if (ieee80211_is_auth(fc))
2502 IWL_DEBUG_TX("Sending AUTH frame\n");
2503 else if (ieee80211_is_assoc_request(fc))
2504 IWL_DEBUG_TX("Sending ASSOC frame\n");
2505 else if (ieee80211_is_reassoc_request(fc))
2506 IWL_DEBUG_TX("Sending REASSOC frame\n");
2507#endif
2508
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002509 /* drop all data frame if we are not associated */
Gregory Greenman76f39152008-01-23 10:15:21 -08002510 if (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) &&
2511 (!iwl4965_is_associated(priv) ||
Reinette Chatrea6477242008-02-14 10:40:28 -08002512 ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && !priv->assoc_id) ||
Gregory Greenman76f39152008-01-23 10:15:21 -08002513 !priv->assoc_station_added)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002514 IWL_DEBUG_DROP("Dropping - !iwl4965_is_associated\n");
Zhu Yib481de92007-09-25 17:54:57 -07002515 goto drop_unlock;
2516 }
2517
2518 spin_unlock_irqrestore(&priv->lock, flags);
2519
2520 hdr_len = ieee80211_get_hdrlen(fc);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002521
2522 /* Find (or create) index into station table for destination station */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002523 sta_id = iwl4965_get_sta_id(priv, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07002524 if (sta_id == IWL_INVALID_STATION) {
Joe Perches0795af52007-10-03 17:59:30 -07002525 DECLARE_MAC_BUF(mac);
2526
2527 IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
2528 print_mac(mac, hdr->addr1));
Zhu Yib481de92007-09-25 17:54:57 -07002529 goto drop;
2530 }
2531
2532 IWL_DEBUG_RATE("station Id %d\n", sta_id);
2533
2534 qc = ieee80211_get_qos_ctrl(hdr);
2535 if (qc) {
2536 u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
2537 seq_number = priv->stations[sta_id].tid[tid].seq_number &
2538 IEEE80211_SCTL_SEQ;
2539 hdr->seq_ctrl = cpu_to_le16(seq_number) |
2540 (hdr->seq_ctrl &
2541 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG));
2542 seq_number += 0x10;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002543#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -07002544 /* aggregation is on for this <sta,tid> */
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02002545 if (ctl->flags & IEEE80211_TXCTL_AMPDU)
Zhu Yib481de92007-09-25 17:54:57 -07002546 txq_id = priv->stations[sta_id].tid[tid].agg.txq_id;
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02002547 priv->stations[sta_id].tid[tid].tfds_in_queue++;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002548#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07002549 }
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002550
2551 /* Descriptor for chosen Tx queue */
Zhu Yib481de92007-09-25 17:54:57 -07002552 txq = &priv->txq[txq_id];
2553 q = &txq->q;
2554
2555 spin_lock_irqsave(&priv->lock, flags);
2556
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002557 /* Set up first empty TFD within this queue's circular TFD buffer */
Tomas Winklerfc4b6852007-10-25 17:15:24 +08002558 tfd = &txq->bd[q->write_ptr];
Zhu Yib481de92007-09-25 17:54:57 -07002559 memset(tfd, 0, sizeof(*tfd));
2560 control_flags = (u32 *) tfd;
Tomas Winklerfc4b6852007-10-25 17:15:24 +08002561 idx = get_cmd_index(q, q->write_ptr, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002562
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002563 /* Set up driver data for this TFD */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002564 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl4965_tx_info));
Tomas Winklerfc4b6852007-10-25 17:15:24 +08002565 txq->txb[q->write_ptr].skb[0] = skb;
2566 memcpy(&(txq->txb[q->write_ptr].status.control),
Zhu Yib481de92007-09-25 17:54:57 -07002567 ctl, sizeof(struct ieee80211_tx_control));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002568
2569 /* Set up first empty entry in queue's array of Tx/cmd buffers */
Zhu Yib481de92007-09-25 17:54:57 -07002570 out_cmd = &txq->cmd[idx];
2571 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
2572 memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002573
2574 /*
2575 * Set up the Tx-command (not MAC!) header.
2576 * Store the chosen Tx queue and TFD index within the sequence field;
2577 * after Tx, uCode's Tx response will return this value so driver can
2578 * locate the frame within the tx queue and do post-tx processing.
2579 */
Zhu Yib481de92007-09-25 17:54:57 -07002580 out_cmd->hdr.cmd = REPLY_TX;
2581 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +08002582 INDEX_TO_SEQ(q->write_ptr)));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002583
2584 /* Copy MAC header from skb into command buffer */
Zhu Yib481de92007-09-25 17:54:57 -07002585 memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len);
2586
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002587 /*
2588 * Use the first empty entry in this queue's command buffer array
2589 * to contain the Tx command and MAC header concatenated together
2590 * (payload data will be in another buffer).
2591 * Size of this varies, due to varying MAC header length.
2592 * If end is not dword aligned, we'll have 2 extra bytes at the end
2593 * of the MAC header (device reads on dword boundaries).
2594 * We'll tell device about this padding later.
2595 */
Zhu Yib481de92007-09-25 17:54:57 -07002596 len = priv->hw_setting.tx_cmd_len +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002597 sizeof(struct iwl4965_cmd_header) + hdr_len;
Zhu Yib481de92007-09-25 17:54:57 -07002598
2599 len_org = len;
2600 len = (len + 3) & ~3;
2601
2602 if (len_org != len)
2603 len_org = 1;
2604 else
2605 len_org = 0;
2606
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002607 /* Physical address of this Tx command's header (not MAC header!),
2608 * within command buffer array. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002609 txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl4965_cmd) * idx +
2610 offsetof(struct iwl4965_cmd, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07002611
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002612 /* Add buffer containing Tx command and MAC(!) header to TFD's
2613 * first entry */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002614 iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len);
Zhu Yib481de92007-09-25 17:54:57 -07002615
2616 if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002617 iwl4965_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002618
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002619 /* Set up TFD's 2nd entry to point directly to remainder of skb,
2620 * if any (802.11 null frames have no payload). */
Zhu Yib481de92007-09-25 17:54:57 -07002621 len = skb->len - hdr_len;
2622 if (len) {
2623 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
2624 len, PCI_DMA_TODEVICE);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002625 iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len);
Zhu Yib481de92007-09-25 17:54:57 -07002626 }
2627
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002628 /* Tell 4965 about any 2-byte padding after MAC header */
Zhu Yib481de92007-09-25 17:54:57 -07002629 if (len_org)
2630 out_cmd->cmd.tx.tx_flags |= TX_CMD_FLG_MH_PAD_MSK;
2631
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002632 /* Total # bytes to be transmitted */
Zhu Yib481de92007-09-25 17:54:57 -07002633 len = (u16)skb->len;
2634 out_cmd->cmd.tx.len = cpu_to_le16(len);
2635
2636 /* TODO need this for burst mode later on */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002637 iwl4965_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07002638
2639 /* set is_hcca to 0; it probably will never be implemented */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002640 iwl4965_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002641
Tomas Winkler19758be2008-03-12 16:58:51 -07002642 iwl_update_tx_stats(priv, fc, len);
2643
Tomas Winkler87e4f7d2008-01-14 17:46:16 -08002644 scratch_phys = txcmd_phys + sizeof(struct iwl4965_cmd_header) +
2645 offsetof(struct iwl4965_tx_cmd, scratch);
2646 out_cmd->cmd.tx.dram_lsb_ptr = cpu_to_le32(scratch_phys);
2647 out_cmd->cmd.tx.dram_msb_ptr = iwl_get_dma_hi_address(scratch_phys);
2648
Zhu Yib481de92007-09-25 17:54:57 -07002649 if (!ieee80211_get_morefrag(hdr)) {
2650 txq->need_update = 1;
2651 if (qc) {
2652 u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
2653 priv->stations[sta_id].tid[tid].seq_number = seq_number;
2654 }
2655 } else {
2656 wait_write_ptr = 1;
2657 txq->need_update = 0;
2658 }
2659
Tomas Winkler0a6857e2008-03-12 16:58:49 -07002660 iwl_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload,
Zhu Yib481de92007-09-25 17:54:57 -07002661 sizeof(out_cmd->cmd.tx));
2662
Tomas Winkler0a6857e2008-03-12 16:58:49 -07002663 iwl_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr,
Zhu Yib481de92007-09-25 17:54:57 -07002664 ieee80211_get_hdrlen(fc));
2665
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002666 /* Set up entry for this TFD in Tx byte-count array */
Zhu Yib481de92007-09-25 17:54:57 -07002667 iwl4965_tx_queue_update_wr_ptr(priv, txq, len);
2668
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002669 /* Tell device the write index *just past* this latest filled TFD */
Tomas Winklerc54b6792008-03-06 17:36:53 -08002670 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002671 rc = iwl4965_tx_queue_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07002672 spin_unlock_irqrestore(&priv->lock, flags);
2673
2674 if (rc)
2675 return rc;
2676
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002677 if ((iwl4965_queue_space(q) < q->high_mark)
Zhu Yib481de92007-09-25 17:54:57 -07002678 && priv->mac80211_registered) {
2679 if (wait_write_ptr) {
2680 spin_lock_irqsave(&priv->lock, flags);
2681 txq->need_update = 1;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002682 iwl4965_tx_queue_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07002683 spin_unlock_irqrestore(&priv->lock, flags);
2684 }
2685
2686 ieee80211_stop_queue(priv->hw, ctl->queue);
2687 }
2688
2689 return 0;
2690
2691drop_unlock:
2692 spin_unlock_irqrestore(&priv->lock, flags);
2693drop:
2694 return -1;
2695}
2696
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002697static void iwl4965_set_rate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002698{
Johannes Berg8318d782008-01-24 19:38:38 +01002699 const struct ieee80211_supported_band *hw = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07002700 struct ieee80211_rate *rate;
2701 int i;
2702
Johannes Berg8318d782008-01-24 19:38:38 +01002703 hw = iwl4965_get_hw_mode(priv, priv->band);
Saleem Abdulrasoolc4ba9622007-11-18 23:59:08 -08002704 if (!hw) {
2705 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
2706 return;
2707 }
Zhu Yib481de92007-09-25 17:54:57 -07002708
2709 priv->active_rate = 0;
2710 priv->active_rate_basic = 0;
2711
Johannes Berg8318d782008-01-24 19:38:38 +01002712 for (i = 0; i < hw->n_bitrates; i++) {
2713 rate = &(hw->bitrates[i]);
2714 if (rate->hw_value < IWL_RATE_COUNT)
2715 priv->active_rate |= (1 << rate->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07002716 }
2717
2718 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
2719 priv->active_rate, priv->active_rate_basic);
2720
2721 /*
2722 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
2723 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
2724 * OFDM
2725 */
2726 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
2727 priv->staging_rxon.cck_basic_rates =
2728 ((priv->active_rate_basic &
2729 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
2730 else
2731 priv->staging_rxon.cck_basic_rates =
2732 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
2733
2734 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
2735 priv->staging_rxon.ofdm_basic_rates =
2736 ((priv->active_rate_basic &
2737 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
2738 IWL_FIRST_OFDM_RATE) & 0xFF;
2739 else
2740 priv->staging_rxon.ofdm_basic_rates =
2741 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
2742}
2743
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002744static void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
Zhu Yib481de92007-09-25 17:54:57 -07002745{
2746 unsigned long flags;
2747
2748 if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
2749 return;
2750
2751 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
2752 disable_radio ? "OFF" : "ON");
2753
2754 if (disable_radio) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002755 iwl4965_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002756 /* FIXME: This is a workaround for AP */
2757 if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
2758 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002759 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07002760 CSR_UCODE_SW_BIT_RFKILL);
2761 spin_unlock_irqrestore(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002762 iwl4965_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002763 set_bit(STATUS_RF_KILL_SW, &priv->status);
2764 }
2765 return;
2766 }
2767
2768 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002769 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07002770
2771 clear_bit(STATUS_RF_KILL_SW, &priv->status);
2772 spin_unlock_irqrestore(&priv->lock, flags);
2773
2774 /* wake up ucode */
2775 msleep(10);
2776
2777 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002778 iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
2779 if (!iwl4965_grab_nic_access(priv))
2780 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002781 spin_unlock_irqrestore(&priv->lock, flags);
2782
2783 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
2784 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2785 "disabled by HW switch\n");
2786 return;
2787 }
2788
2789 queue_work(priv->workqueue, &priv->restart);
2790 return;
2791}
2792
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002793void iwl4965_set_decrypted_flag(struct iwl_priv *priv, struct sk_buff *skb,
Zhu Yib481de92007-09-25 17:54:57 -07002794 u32 decrypt_res, struct ieee80211_rx_status *stats)
2795{
2796 u16 fc =
2797 le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control);
2798
2799 if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
2800 return;
2801
2802 if (!(fc & IEEE80211_FCTL_PROTECTED))
2803 return;
2804
2805 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
2806 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
2807 case RX_RES_STATUS_SEC_TYPE_TKIP:
2808 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2809 RX_RES_STATUS_BAD_ICV_MIC)
2810 stats->flag |= RX_FLAG_MMIC_ERROR;
2811 case RX_RES_STATUS_SEC_TYPE_WEP:
2812 case RX_RES_STATUS_SEC_TYPE_CCMP:
2813 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2814 RX_RES_STATUS_DECRYPT_OK) {
2815 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
2816 stats->flag |= RX_FLAG_DECRYPTED;
2817 }
2818 break;
2819
2820 default:
2821 break;
2822 }
2823}
2824
Zhu Yib481de92007-09-25 17:54:57 -07002825
2826#define IWL_PACKET_RETRY_TIME HZ
2827
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002828int iwl4965_is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
Zhu Yib481de92007-09-25 17:54:57 -07002829{
2830 u16 sc = le16_to_cpu(header->seq_ctrl);
2831 u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
2832 u16 frag = sc & IEEE80211_SCTL_FRAG;
2833 u16 *last_seq, *last_frag;
2834 unsigned long *last_time;
2835
2836 switch (priv->iw_mode) {
2837 case IEEE80211_IF_TYPE_IBSS:{
2838 struct list_head *p;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002839 struct iwl4965_ibss_seq *entry = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07002840 u8 *mac = header->addr2;
2841 int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1);
2842
2843 __list_for_each(p, &priv->ibss_mac_hash[index]) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002844 entry = list_entry(p, struct iwl4965_ibss_seq, list);
Zhu Yib481de92007-09-25 17:54:57 -07002845 if (!compare_ether_addr(entry->mac, mac))
2846 break;
2847 }
2848 if (p == &priv->ibss_mac_hash[index]) {
2849 entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
2850 if (!entry) {
Ian Schrambc434dd2007-10-25 17:15:29 +08002851 IWL_ERROR("Cannot malloc new mac entry\n");
Zhu Yib481de92007-09-25 17:54:57 -07002852 return 0;
2853 }
2854 memcpy(entry->mac, mac, ETH_ALEN);
2855 entry->seq_num = seq;
2856 entry->frag_num = frag;
2857 entry->packet_time = jiffies;
Ian Schrambc434dd2007-10-25 17:15:29 +08002858 list_add(&entry->list, &priv->ibss_mac_hash[index]);
Zhu Yib481de92007-09-25 17:54:57 -07002859 return 0;
2860 }
2861 last_seq = &entry->seq_num;
2862 last_frag = &entry->frag_num;
2863 last_time = &entry->packet_time;
2864 break;
2865 }
2866 case IEEE80211_IF_TYPE_STA:
2867 last_seq = &priv->last_seq_num;
2868 last_frag = &priv->last_frag_num;
2869 last_time = &priv->last_packet_time;
2870 break;
2871 default:
2872 return 0;
2873 }
2874 if ((*last_seq == seq) &&
2875 time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) {
2876 if (*last_frag == frag)
2877 goto drop;
2878 if (*last_frag + 1 != frag)
2879 /* out-of-order fragment */
2880 goto drop;
2881 } else
2882 *last_seq = seq;
2883
2884 *last_frag = frag;
2885 *last_time = jiffies;
2886 return 0;
2887
2888 drop:
2889 return 1;
2890}
2891
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002892#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07002893
2894#include "iwl-spectrum.h"
2895
2896#define BEACON_TIME_MASK_LOW 0x00FFFFFF
2897#define BEACON_TIME_MASK_HIGH 0xFF000000
2898#define TIME_UNIT 1024
2899
2900/*
2901 * extended beacon time format
2902 * time in usec will be changed into a 32-bit value in 8:24 format
2903 * the high 1 byte is the beacon counts
2904 * the lower 3 bytes is the time in usec within one beacon interval
2905 */
2906
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002907static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07002908{
2909 u32 quot;
2910 u32 rem;
2911 u32 interval = beacon_interval * 1024;
2912
2913 if (!interval || !usec)
2914 return 0;
2915
2916 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
2917 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
2918
2919 return (quot << 24) + rem;
2920}
2921
2922/* base is usually what we get from ucode with each received frame,
2923 * the same as HW timer counter counting down
2924 */
2925
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002926static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07002927{
2928 u32 base_low = base & BEACON_TIME_MASK_LOW;
2929 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
2930 u32 interval = beacon_interval * TIME_UNIT;
2931 u32 res = (base & BEACON_TIME_MASK_HIGH) +
2932 (addon & BEACON_TIME_MASK_HIGH);
2933
2934 if (base_low > addon_low)
2935 res += base_low - addon_low;
2936 else if (base_low < addon_low) {
2937 res += interval + base_low - addon_low;
2938 res += (1 << 24);
2939 } else
2940 res += (1 << 24);
2941
2942 return cpu_to_le32(res);
2943}
2944
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002945static int iwl4965_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002946 struct ieee80211_measurement_params *params,
2947 u8 type)
2948{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002949 struct iwl4965_spectrum_cmd spectrum;
2950 struct iwl4965_rx_packet *res;
2951 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07002952 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
2953 .data = (void *)&spectrum,
2954 .meta.flags = CMD_WANT_SKB,
2955 };
2956 u32 add_time = le64_to_cpu(params->start_time);
2957 int rc;
2958 int spectrum_resp_status;
2959 int duration = le16_to_cpu(params->duration);
2960
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002961 if (iwl4965_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002962 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002963 iwl4965_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -07002964 le64_to_cpu(params->start_time) - priv->last_tsf,
2965 le16_to_cpu(priv->rxon_timing.beacon_interval));
2966
2967 memset(&spectrum, 0, sizeof(spectrum));
2968
2969 spectrum.channel_count = cpu_to_le16(1);
2970 spectrum.flags =
2971 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
2972 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
2973 cmd.len = sizeof(spectrum);
2974 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
2975
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002976 if (iwl4965_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002977 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002978 iwl4965_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -07002979 add_time,
2980 le16_to_cpu(priv->rxon_timing.beacon_interval));
2981 else
2982 spectrum.start_time = 0;
2983
2984 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
2985 spectrum.channels[0].channel = params->channel;
2986 spectrum.channels[0].type = type;
2987 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
2988 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
2989 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
2990
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002991 rc = iwl4965_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07002992 if (rc)
2993 return rc;
2994
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002995 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002996 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
2997 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
2998 rc = -EIO;
2999 }
3000
3001 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
3002 switch (spectrum_resp_status) {
3003 case 0: /* Command will be handled */
3004 if (res->u.spectrum.id != 0xff) {
3005 IWL_DEBUG_INFO
3006 ("Replaced existing measurement: %d\n",
3007 res->u.spectrum.id);
3008 priv->measurement_status &= ~MEASUREMENT_READY;
3009 }
3010 priv->measurement_status |= MEASUREMENT_ACTIVE;
3011 rc = 0;
3012 break;
3013
3014 case 1: /* Command will not be handled */
3015 rc = -EAGAIN;
3016 break;
3017 }
3018
3019 dev_kfree_skb_any(cmd.meta.u.skb);
3020
3021 return rc;
3022}
3023#endif
3024
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003025static void iwl4965_txstatus_to_ieee(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003026 struct iwl4965_tx_info *tx_sta)
Zhu Yib481de92007-09-25 17:54:57 -07003027{
3028
3029 tx_sta->status.ack_signal = 0;
3030 tx_sta->status.excessive_retries = 0;
3031 tx_sta->status.queue_length = 0;
3032 tx_sta->status.queue_number = 0;
3033
3034 if (in_interrupt())
3035 ieee80211_tx_status_irqsafe(priv->hw,
3036 tx_sta->skb[0], &(tx_sta->status));
3037 else
3038 ieee80211_tx_status(priv->hw,
3039 tx_sta->skb[0], &(tx_sta->status));
3040
3041 tx_sta->skb[0] = NULL;
3042}
3043
3044/**
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003045 * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
Zhu Yib481de92007-09-25 17:54:57 -07003046 *
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003047 * When FW advances 'R' index, all entries between old and new 'R' index
3048 * need to be reclaimed. As result, some free space forms. If there is
3049 * enough free space (> low mark), wake the stack that feeds us.
Zhu Yib481de92007-09-25 17:54:57 -07003050 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003051int iwl4965_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index)
Zhu Yib481de92007-09-25 17:54:57 -07003052{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003053 struct iwl4965_tx_queue *txq = &priv->txq[txq_id];
3054 struct iwl4965_queue *q = &txq->q;
Zhu Yib481de92007-09-25 17:54:57 -07003055 int nfreed = 0;
3056
3057 if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) {
3058 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
3059 "is out of range [0-%d] %d %d.\n", txq_id,
Tomas Winklerfc4b6852007-10-25 17:15:24 +08003060 index, q->n_bd, q->write_ptr, q->read_ptr);
Zhu Yib481de92007-09-25 17:54:57 -07003061 return 0;
3062 }
3063
Tomas Winklerc54b6792008-03-06 17:36:53 -08003064 for (index = iwl_queue_inc_wrap(index, q->n_bd);
Tomas Winklerfc4b6852007-10-25 17:15:24 +08003065 q->read_ptr != index;
Tomas Winklerc54b6792008-03-06 17:36:53 -08003066 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
Zhu Yib481de92007-09-25 17:54:57 -07003067 if (txq_id != IWL_CMD_QUEUE_NUM) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003068 iwl4965_txstatus_to_ieee(priv,
Tomas Winklerfc4b6852007-10-25 17:15:24 +08003069 &(txq->txb[txq->q.read_ptr]));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003070 iwl4965_hw_txq_free_tfd(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07003071 } else if (nfreed > 1) {
3072 IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index,
Tomas Winklerfc4b6852007-10-25 17:15:24 +08003073 q->write_ptr, q->read_ptr);
Zhu Yib481de92007-09-25 17:54:57 -07003074 queue_work(priv->workqueue, &priv->restart);
3075 }
3076 nfreed++;
3077 }
3078
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003079/* if (iwl4965_queue_space(q) > q->low_mark && (txq_id >= 0) &&
Zhu Yib481de92007-09-25 17:54:57 -07003080 (txq_id != IWL_CMD_QUEUE_NUM) &&
3081 priv->mac80211_registered)
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003082 ieee80211_wake_queue(priv->hw, txq_id); */
Zhu Yib481de92007-09-25 17:54:57 -07003083
3084
3085 return nfreed;
3086}
3087
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003088static int iwl4965_is_tx_success(u32 status)
Zhu Yib481de92007-09-25 17:54:57 -07003089{
3090 status &= TX_STATUS_MSK;
3091 return (status == TX_STATUS_SUCCESS)
3092 || (status == TX_STATUS_DIRECT_DONE);
3093}
3094
3095/******************************************************************************
3096 *
3097 * Generic RX handler implementations
3098 *
3099 ******************************************************************************/
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003100#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -07003101
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003102static inline int iwl4965_get_ra_sta_id(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07003103 struct ieee80211_hdr *hdr)
3104{
3105 if (priv->iw_mode == IEEE80211_IF_TYPE_STA)
3106 return IWL_AP_ID;
3107 else {
3108 u8 *da = ieee80211_get_DA(hdr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003109 return iwl4965_hw_find_station(priv, da);
Zhu Yib481de92007-09-25 17:54:57 -07003110 }
3111}
3112
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003113static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr(
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003114 struct iwl_priv *priv, int txq_id, int idx)
Zhu Yib481de92007-09-25 17:54:57 -07003115{
3116 if (priv->txq[txq_id].txb[idx].skb[0])
3117 return (struct ieee80211_hdr *)priv->txq[txq_id].
3118 txb[idx].skb[0]->data;
3119 return NULL;
3120}
3121
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003122static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp)
Zhu Yib481de92007-09-25 17:54:57 -07003123{
3124 __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status +
3125 tx_resp->frame_count);
3126 return le32_to_cpu(*scd_ssn) & MAX_SN;
3127
3128}
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003129
3130/**
3131 * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue
3132 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003133static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003134 struct iwl4965_ht_agg *agg,
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003135 struct iwl4965_tx_resp_agg *tx_resp,
Zhu Yib481de92007-09-25 17:54:57 -07003136 u16 start_idx)
3137{
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003138 u16 status;
3139 struct agg_tx_status *frame_status = &tx_resp->status;
Zhu Yib481de92007-09-25 17:54:57 -07003140 struct ieee80211_tx_status *tx_status = NULL;
3141 struct ieee80211_hdr *hdr = NULL;
3142 int i, sh;
3143 int txq_id, idx;
3144 u16 seq;
3145
3146 if (agg->wait_for_ba)
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003147 IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
Zhu Yib481de92007-09-25 17:54:57 -07003148
3149 agg->frame_count = tx_resp->frame_count;
3150 agg->start_idx = start_idx;
3151 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003152 agg->bitmap = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003153
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003154 /* # frames attempted by Tx command */
Zhu Yib481de92007-09-25 17:54:57 -07003155 if (agg->frame_count == 1) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003156 /* Only one frame was attempted; no block-ack will arrive */
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003157 status = le16_to_cpu(frame_status[0].status);
3158 seq = le16_to_cpu(frame_status[0].sequence);
3159 idx = SEQ_TO_INDEX(seq);
3160 txq_id = SEQ_TO_QUEUE(seq);
Zhu Yib481de92007-09-25 17:54:57 -07003161
Zhu Yib481de92007-09-25 17:54:57 -07003162 /* FIXME: code repetition */
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003163 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
3164 agg->frame_count, agg->start_idx, idx);
Zhu Yib481de92007-09-25 17:54:57 -07003165
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003166 tx_status = &(priv->txq[txq_id].txb[idx].status);
Zhu Yib481de92007-09-25 17:54:57 -07003167 tx_status->retry_count = tx_resp->failure_frame;
3168 tx_status->queue_number = status & 0xff;
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003169 tx_status->queue_length = tx_resp->failure_rts;
3170 tx_status->control.flags &= ~IEEE80211_TXCTL_AMPDU;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003171 tx_status->flags = iwl4965_is_tx_success(status)?
Zhu Yib481de92007-09-25 17:54:57 -07003172 IEEE80211_TX_STATUS_ACK : 0;
Ron Rindjunsky4c424e42008-03-04 18:09:27 -08003173 iwl4965_hwrate_to_tx_control(priv,
3174 le32_to_cpu(tx_resp->rate_n_flags),
3175 &tx_status->control);
Zhu Yib481de92007-09-25 17:54:57 -07003176 /* FIXME: code repetition end */
3177
3178 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
3179 status & 0xff, tx_resp->failure_frame);
3180 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003181 iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags));
Zhu Yib481de92007-09-25 17:54:57 -07003182
3183 agg->wait_for_ba = 0;
3184 } else {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003185 /* Two or more frames were attempted; expect block-ack */
Zhu Yib481de92007-09-25 17:54:57 -07003186 u64 bitmap = 0;
3187 int start = agg->start_idx;
3188
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003189 /* Construct bit-map of pending frames within Tx window */
Zhu Yib481de92007-09-25 17:54:57 -07003190 for (i = 0; i < agg->frame_count; i++) {
3191 u16 sc;
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003192 status = le16_to_cpu(frame_status[i].status);
3193 seq = le16_to_cpu(frame_status[i].sequence);
Zhu Yib481de92007-09-25 17:54:57 -07003194 idx = SEQ_TO_INDEX(seq);
3195 txq_id = SEQ_TO_QUEUE(seq);
3196
3197 if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
3198 AGG_TX_STATE_ABORT_MSK))
3199 continue;
3200
3201 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
3202 agg->frame_count, txq_id, idx);
3203
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003204 hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx);
Zhu Yib481de92007-09-25 17:54:57 -07003205
3206 sc = le16_to_cpu(hdr->seq_ctrl);
3207 if (idx != (SEQ_TO_SN(sc) & 0xff)) {
3208 IWL_ERROR("BUG_ON idx doesn't match seq control"
3209 " idx=%d, seq_idx=%d, seq=%d\n",
3210 idx, SEQ_TO_SN(sc),
3211 hdr->seq_ctrl);
3212 return -1;
3213 }
3214
3215 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
3216 i, idx, SEQ_TO_SN(sc));
3217
3218 sh = idx - start;
3219 if (sh > 64) {
3220 sh = (start - idx) + 0xff;
3221 bitmap = bitmap << sh;
3222 sh = 0;
3223 start = idx;
3224 } else if (sh < -64)
3225 sh = 0xff - (start - idx);
3226 else if (sh < 0) {
3227 sh = start - idx;
3228 start = idx;
3229 bitmap = bitmap << sh;
3230 sh = 0;
3231 }
3232 bitmap |= (1 << sh);
3233 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
3234 start, (u32)(bitmap & 0xFFFFFFFF));
3235 }
3236
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003237 agg->bitmap = bitmap;
Zhu Yib481de92007-09-25 17:54:57 -07003238 agg->start_idx = start;
3239 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003240 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
Zhu Yib481de92007-09-25 17:54:57 -07003241 agg->frame_count, agg->start_idx,
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003242 agg->bitmap);
Zhu Yib481de92007-09-25 17:54:57 -07003243
3244 if (bitmap)
3245 agg->wait_for_ba = 1;
3246 }
3247 return 0;
3248}
3249#endif
Zhu Yib481de92007-09-25 17:54:57 -07003250
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003251/**
3252 * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
3253 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003254static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003255 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003256{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003257 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07003258 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
3259 int txq_id = SEQ_TO_QUEUE(sequence);
3260 int index = SEQ_TO_INDEX(sequence);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003261 struct iwl4965_tx_queue *txq = &priv->txq[txq_id];
Zhu Yib481de92007-09-25 17:54:57 -07003262 struct ieee80211_tx_status *tx_status;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003263 struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
Zhu Yib481de92007-09-25 17:54:57 -07003264 u32 status = le32_to_cpu(tx_resp->status);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003265#ifdef CONFIG_IWL4965_HT
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003266 int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION;
3267 struct ieee80211_hdr *hdr;
3268 __le16 *qc;
Zhu Yib481de92007-09-25 17:54:57 -07003269#endif
3270
3271 if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) {
3272 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
3273 "is out of range [0-%d] %d %d\n", txq_id,
Tomas Winklerfc4b6852007-10-25 17:15:24 +08003274 index, txq->q.n_bd, txq->q.write_ptr,
3275 txq->q.read_ptr);
Zhu Yib481de92007-09-25 17:54:57 -07003276 return;
3277 }
3278
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003279#ifdef CONFIG_IWL4965_HT
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003280 hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, index);
3281 qc = ieee80211_get_qos_ctrl(hdr);
Zhu Yib481de92007-09-25 17:54:57 -07003282
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003283 if (qc)
Zhu Yib481de92007-09-25 17:54:57 -07003284 tid = le16_to_cpu(*qc) & 0xf;
3285
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003286 sta_id = iwl4965_get_ra_sta_id(priv, hdr);
3287 if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) {
3288 IWL_ERROR("Station not known\n");
3289 return;
3290 }
3291
3292 if (txq->sched_retry) {
3293 const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp);
3294 struct iwl4965_ht_agg *agg = NULL;
3295
3296 if (!qc)
Zhu Yib481de92007-09-25 17:54:57 -07003297 return;
Zhu Yib481de92007-09-25 17:54:57 -07003298
3299 agg = &priv->stations[sta_id].tid[tid].agg;
3300
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003301 iwl4965_tx_status_reply_tx(priv, agg,
3302 (struct iwl4965_tx_resp_agg *)tx_resp, index);
Zhu Yib481de92007-09-25 17:54:57 -07003303
3304 if ((tx_resp->frame_count == 1) &&
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003305 !iwl4965_is_tx_success(status)) {
Zhu Yib481de92007-09-25 17:54:57 -07003306 /* TODO: send BAR */
3307 }
3308
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003309 if (txq->q.read_ptr != (scd_ssn & 0xff)) {
3310 int freed;
Tomas Winklerc54b6792008-03-06 17:36:53 -08003311 index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
Zhu Yib481de92007-09-25 17:54:57 -07003312 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
3313 "%d index %d\n", scd_ssn , index);
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003314 freed = iwl4965_tx_queue_reclaim(priv, txq_id, index);
3315 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
3316
3317 if (iwl4965_queue_space(&txq->q) > txq->q.low_mark &&
3318 txq_id >= 0 && priv->mac80211_registered &&
3319 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)
3320 ieee80211_wake_queue(priv->hw, txq_id);
3321
3322 iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id);
Zhu Yib481de92007-09-25 17:54:57 -07003323 }
3324 } else {
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003325#endif /* CONFIG_IWL4965_HT */
Tomas Winklerfc4b6852007-10-25 17:15:24 +08003326 tx_status = &(txq->txb[txq->q.read_ptr].status);
Zhu Yib481de92007-09-25 17:54:57 -07003327
3328 tx_status->retry_count = tx_resp->failure_frame;
3329 tx_status->queue_number = status;
3330 tx_status->queue_length = tx_resp->bt_kill_count;
3331 tx_status->queue_length |= tx_resp->failure_rts;
Zhu Yib481de92007-09-25 17:54:57 -07003332 tx_status->flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003333 iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0;
Ron Rindjunsky4c424e42008-03-04 18:09:27 -08003334 iwl4965_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags),
3335 &tx_status->control);
Zhu Yib481de92007-09-25 17:54:57 -07003336
Zhu Yib481de92007-09-25 17:54:57 -07003337 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x "
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003338 "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status),
Zhu Yib481de92007-09-25 17:54:57 -07003339 status, le32_to_cpu(tx_resp->rate_n_flags),
3340 tx_resp->failure_frame);
3341
3342 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003343 if (index != -1) {
3344 int freed = iwl4965_tx_queue_reclaim(priv, txq_id, index);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003345#ifdef CONFIG_IWL4965_HT
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003346 if (tid != MAX_TID_COUNT)
3347 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
3348 if (iwl4965_queue_space(&txq->q) > txq->q.low_mark &&
3349 (txq_id >= 0) &&
3350 priv->mac80211_registered)
3351 ieee80211_wake_queue(priv->hw, txq_id);
3352 if (tid != MAX_TID_COUNT)
3353 iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id);
3354#endif
Zhu Yib481de92007-09-25 17:54:57 -07003355 }
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003356#ifdef CONFIG_IWL4965_HT
3357 }
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003358#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07003359
3360 if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
3361 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
3362}
3363
3364
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003365static void iwl4965_rx_reply_alive(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003366 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003367{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003368 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3369 struct iwl4965_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -07003370 struct delayed_work *pwork;
3371
3372 palive = &pkt->u.alive_frame;
3373
3374 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
3375 "0x%01X 0x%01X\n",
3376 palive->is_valid, palive->ver_type,
3377 palive->ver_subtype);
3378
3379 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
3380 IWL_DEBUG_INFO("Initialization Alive received.\n");
3381 memcpy(&priv->card_alive_init,
3382 &pkt->u.alive_frame,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003383 sizeof(struct iwl4965_init_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07003384 pwork = &priv->init_alive_start;
3385 } else {
3386 IWL_DEBUG_INFO("Runtime Alive received.\n");
3387 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003388 sizeof(struct iwl4965_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07003389 pwork = &priv->alive_start;
3390 }
3391
3392 /* We delay the ALIVE response by 5ms to
3393 * give the HW RF Kill time to activate... */
3394 if (palive->is_valid == UCODE_VALID_OK)
3395 queue_delayed_work(priv->workqueue, pwork,
3396 msecs_to_jiffies(5));
3397 else
3398 IWL_WARNING("uCode did not respond OK.\n");
3399}
3400
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003401static void iwl4965_rx_reply_add_sta(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003402 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003403{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003404 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07003405
3406 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
3407 return;
3408}
3409
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003410static void iwl4965_rx_reply_error(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003411 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003412{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003413 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07003414
3415 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
3416 "seq 0x%04X ser 0x%08X\n",
3417 le32_to_cpu(pkt->u.err_resp.error_type),
3418 get_cmd_string(pkt->u.err_resp.cmd_id),
3419 pkt->u.err_resp.cmd_id,
3420 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
3421 le32_to_cpu(pkt->u.err_resp.error_info));
3422}
3423
3424#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
3425
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003426static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003427{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003428 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3429 struct iwl4965_rxon_cmd *rxon = (void *)&priv->active_rxon;
3430 struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif);
Zhu Yib481de92007-09-25 17:54:57 -07003431 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
3432 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
3433 rxon->channel = csa->channel;
3434 priv->staging_rxon.channel = csa->channel;
3435}
3436
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003437static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003438 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003439{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003440#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003441 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3442 struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif);
Zhu Yib481de92007-09-25 17:54:57 -07003443
3444 if (!report->state) {
3445 IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO,
3446 "Spectrum Measure Notification: Start\n");
3447 return;
3448 }
3449
3450 memcpy(&priv->measure_report, report, sizeof(*report));
3451 priv->measurement_status |= MEASUREMENT_READY;
3452#endif
3453}
3454
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003455static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003456 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003457{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003458#ifdef CONFIG_IWLWIFI_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003459 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3460 struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif);
Zhu Yib481de92007-09-25 17:54:57 -07003461 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
3462 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
3463#endif
3464}
3465
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003466static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003467 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003468{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003469 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07003470 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
3471 "notification for %s:\n",
3472 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003473 iwl_print_hex_dump(IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
Zhu Yib481de92007-09-25 17:54:57 -07003474}
3475
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003476static void iwl4965_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07003477{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003478 struct iwl_priv *priv =
3479 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07003480 struct sk_buff *beacon;
3481
3482 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berg32bfd352007-12-19 01:31:26 +01003483 beacon = ieee80211_beacon_get(priv->hw, priv->vif, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07003484
3485 if (!beacon) {
3486 IWL_ERROR("update beacon failed\n");
3487 return;
3488 }
3489
3490 mutex_lock(&priv->mutex);
3491 /* new beacon skb is allocated every time; dispose previous.*/
3492 if (priv->ibss_beacon)
3493 dev_kfree_skb(priv->ibss_beacon);
3494
3495 priv->ibss_beacon = beacon;
3496 mutex_unlock(&priv->mutex);
3497
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003498 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003499}
3500
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003501static void iwl4965_rx_beacon_notif(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003502 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003503{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003504#ifdef CONFIG_IWLWIFI_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003505 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3506 struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status);
3507 u8 rate = iwl4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -07003508
3509 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
3510 "tsf %d %d rate %d\n",
3511 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
3512 beacon->beacon_notify_hdr.failure_frame,
3513 le32_to_cpu(beacon->ibss_mgr_status),
3514 le32_to_cpu(beacon->high_tsf),
3515 le32_to_cpu(beacon->low_tsf), rate);
3516#endif
3517
3518 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
3519 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
3520 queue_work(priv->workqueue, &priv->beacon_update);
3521}
3522
3523/* Service response to REPLY_SCAN_CMD (0x80) */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003524static void iwl4965_rx_reply_scan(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003525 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003526{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003527#ifdef CONFIG_IWLWIFI_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003528 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3529 struct iwl4965_scanreq_notification *notif =
3530 (struct iwl4965_scanreq_notification *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07003531
3532 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status);
3533#endif
3534}
3535
3536/* Service SCAN_START_NOTIFICATION (0x82) */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003537static void iwl4965_rx_scan_start_notif(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003538 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003539{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003540 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3541 struct iwl4965_scanstart_notification *notif =
3542 (struct iwl4965_scanstart_notification *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07003543 priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
3544 IWL_DEBUG_SCAN("Scan start: "
3545 "%d [802.11%s] "
3546 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
3547 notif->channel,
3548 notif->band ? "bg" : "a",
3549 notif->tsf_high,
3550 notif->tsf_low, notif->status, notif->beacon_timer);
3551}
3552
3553/* Service SCAN_RESULTS_NOTIFICATION (0x83) */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003554static void iwl4965_rx_scan_results_notif(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003555 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003556{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003557 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3558 struct iwl4965_scanresults_notification *notif =
3559 (struct iwl4965_scanresults_notification *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07003560
3561 IWL_DEBUG_SCAN("Scan ch.res: "
3562 "%d [802.11%s] "
3563 "(TSF: 0x%08X:%08X) - %d "
3564 "elapsed=%lu usec (%dms since last)\n",
3565 notif->channel,
3566 notif->band ? "bg" : "a",
3567 le32_to_cpu(notif->tsf_high),
3568 le32_to_cpu(notif->tsf_low),
3569 le32_to_cpu(notif->statistics[0]),
3570 le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
3571 jiffies_to_msecs(elapsed_jiffies
3572 (priv->last_scan_jiffies, jiffies)));
3573
3574 priv->last_scan_jiffies = jiffies;
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003575 priv->next_scan_jiffies = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003576}
3577
3578/* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003579static void iwl4965_rx_scan_complete_notif(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003580 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003581{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003582 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3583 struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07003584
3585 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
3586 scan_notif->scanned_channels,
3587 scan_notif->tsf_low,
3588 scan_notif->tsf_high, scan_notif->status);
3589
3590 /* The HW is no longer scanning */
3591 clear_bit(STATUS_SCAN_HW, &priv->status);
3592
3593 /* The scan completion notification came in, so kill that timer... */
3594 cancel_delayed_work(&priv->scan_check);
3595
3596 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
3597 (priv->scan_bands == 2) ? "2.4" : "5.2",
3598 jiffies_to_msecs(elapsed_jiffies
3599 (priv->scan_pass_start, jiffies)));
3600
3601 /* Remove this scanned band from the list
3602 * of pending bands to scan */
3603 priv->scan_bands--;
3604
3605 /* If a request to abort was given, or the scan did not succeed
3606 * then we reset the scan state machine and terminate,
3607 * re-queuing another scan if one has been requested */
3608 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
3609 IWL_DEBUG_INFO("Aborted scan completed.\n");
3610 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
3611 } else {
3612 /* If there are more bands on this scan pass reschedule */
3613 if (priv->scan_bands > 0)
3614 goto reschedule;
3615 }
3616
3617 priv->last_scan_jiffies = jiffies;
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003618 priv->next_scan_jiffies = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003619 IWL_DEBUG_INFO("Setting scan to off\n");
3620
3621 clear_bit(STATUS_SCANNING, &priv->status);
3622
3623 IWL_DEBUG_INFO("Scan took %dms\n",
3624 jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
3625
3626 queue_work(priv->workqueue, &priv->scan_completed);
3627
3628 return;
3629
3630reschedule:
3631 priv->scan_pass_start = jiffies;
3632 queue_work(priv->workqueue, &priv->request_scan);
3633}
3634
3635/* Handle notification from uCode that card's power state is changing
3636 * due to software, hardware, or critical temperature RFKILL */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003637static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003638 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003639{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003640 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07003641 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
3642 unsigned long status = priv->status;
3643
3644 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
3645 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
3646 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
3647
3648 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
3649 RF_CARD_DISABLED)) {
3650
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003651 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07003652 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3653
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003654 if (!iwl4965_grab_nic_access(priv)) {
3655 iwl4965_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07003656 priv, HBUS_TARG_MBX_C,
3657 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
3658
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003659 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003660 }
3661
3662 if (!(flags & RXON_CARD_DISABLED)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003663 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07003664 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003665 if (!iwl4965_grab_nic_access(priv)) {
3666 iwl4965_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07003667 priv, HBUS_TARG_MBX_C,
3668 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
3669
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003670 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003671 }
3672 }
3673
3674 if (flags & RF_CARD_DISABLED) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003675 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07003676 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003677 iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
3678 if (!iwl4965_grab_nic_access(priv))
3679 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003680 }
3681 }
3682
3683 if (flags & HW_CARD_DISABLED)
3684 set_bit(STATUS_RF_KILL_HW, &priv->status);
3685 else
3686 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3687
3688
3689 if (flags & SW_CARD_DISABLED)
3690 set_bit(STATUS_RF_KILL_SW, &priv->status);
3691 else
3692 clear_bit(STATUS_RF_KILL_SW, &priv->status);
3693
3694 if (!(flags & RXON_CARD_DISABLED))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003695 iwl4965_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003696
3697 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
3698 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
3699 (test_bit(STATUS_RF_KILL_SW, &status) !=
3700 test_bit(STATUS_RF_KILL_SW, &priv->status)))
3701 queue_work(priv->workqueue, &priv->rf_kill);
3702 else
3703 wake_up_interruptible(&priv->wait_command_queue);
3704}
3705
3706/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003707 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07003708 *
3709 * Setup the RX handlers for each of the reply types sent from the uCode
3710 * to the host.
3711 *
3712 * This function chains into the hardware specific files for them to setup
3713 * any hardware specific handlers as well.
3714 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003715static void iwl4965_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003716{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003717 priv->rx_handlers[REPLY_ALIVE] = iwl4965_rx_reply_alive;
3718 priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta;
3719 priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error;
3720 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa;
Zhu Yib481de92007-09-25 17:54:57 -07003721 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003722 iwl4965_rx_spectrum_measure_notif;
3723 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07003724 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003725 iwl4965_rx_pm_debug_statistics_notif;
3726 priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07003727
Ben Cahill9fbab512007-11-29 11:09:47 +08003728 /*
3729 * The same handler is used for both the REPLY to a discrete
3730 * statistics request from the host as well as for the periodic
3731 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07003732 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003733 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics;
3734 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -07003735
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003736 priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan;
3737 priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif;
Zhu Yib481de92007-09-25 17:54:57 -07003738 priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003739 iwl4965_rx_scan_results_notif;
Zhu Yib481de92007-09-25 17:54:57 -07003740 priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003741 iwl4965_rx_scan_complete_notif;
3742 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif;
3743 priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx;
Zhu Yib481de92007-09-25 17:54:57 -07003744
Ben Cahill9fbab512007-11-29 11:09:47 +08003745 /* Set up hardware specific Rx handlers */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003746 iwl4965_hw_rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003747}
3748
3749/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003750 * iwl4965_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
Zhu Yib481de92007-09-25 17:54:57 -07003751 * @rxb: Rx buffer to reclaim
3752 *
3753 * If an Rx buffer has an async callback associated with it the callback
3754 * will be executed. The attached skb (if present) will only be freed
3755 * if the callback returns 1
3756 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003757static void iwl4965_tx_cmd_complete(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003758 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003759{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003760 struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07003761 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
3762 int txq_id = SEQ_TO_QUEUE(sequence);
3763 int index = SEQ_TO_INDEX(sequence);
3764 int huge = sequence & SEQ_HUGE_FRAME;
3765 int cmd_index;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003766 struct iwl4965_cmd *cmd;
Zhu Yib481de92007-09-25 17:54:57 -07003767
3768 /* If a Tx command is being handled and it isn't in the actual
3769 * command queue then there a command routing bug has been introduced
3770 * in the queue management code. */
3771 if (txq_id != IWL_CMD_QUEUE_NUM)
3772 IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
3773 txq_id, pkt->hdr.cmd);
3774 BUG_ON(txq_id != IWL_CMD_QUEUE_NUM);
3775
3776 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
3777 cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
3778
3779 /* Input error checking is done when commands are added to queue. */
3780 if (cmd->meta.flags & CMD_WANT_SKB) {
3781 cmd->meta.source->u.skb = rxb->skb;
3782 rxb->skb = NULL;
3783 } else if (cmd->meta.u.callback &&
3784 !cmd->meta.u.callback(priv, cmd, rxb->skb))
3785 rxb->skb = NULL;
3786
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003787 iwl4965_tx_queue_reclaim(priv, txq_id, index);
Zhu Yib481de92007-09-25 17:54:57 -07003788
3789 if (!(cmd->meta.flags & CMD_ASYNC)) {
3790 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
3791 wake_up_interruptible(&priv->wait_command_queue);
3792 }
3793}
3794
3795/************************** RX-FUNCTIONS ****************************/
3796/*
3797 * Rx theory of operation
3798 *
Ben Cahill9fbab512007-11-29 11:09:47 +08003799 * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs),
3800 * each of which point to Receive Buffers to be filled by 4965. These get
3801 * used not only for Rx frames, but for any command response or notification
3802 * from the 4965. The driver and 4965 manage the Rx buffers by means
3803 * of indexes into the circular buffer.
Zhu Yib481de92007-09-25 17:54:57 -07003804 *
3805 * Rx Queue Indexes
3806 * The host/firmware share two index registers for managing the Rx buffers.
3807 *
3808 * The READ index maps to the first position that the firmware may be writing
3809 * to -- the driver can read up to (but not including) this position and get
3810 * good data.
3811 * The READ index is managed by the firmware once the card is enabled.
3812 *
3813 * The WRITE index maps to the last position the driver has read from -- the
3814 * position preceding WRITE is the last slot the firmware can place a packet.
3815 *
3816 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
3817 * WRITE = READ.
3818 *
Ben Cahill9fbab512007-11-29 11:09:47 +08003819 * During initialization, the host sets up the READ queue position to the first
Zhu Yib481de92007-09-25 17:54:57 -07003820 * INDEX position, and WRITE to the last (READ - 1 wrapped)
3821 *
Ben Cahill9fbab512007-11-29 11:09:47 +08003822 * When the firmware places a packet in a buffer, it will advance the READ index
Zhu Yib481de92007-09-25 17:54:57 -07003823 * and fire the RX interrupt. The driver can then query the READ index and
3824 * process as many packets as possible, moving the WRITE index forward as it
3825 * resets the Rx queue buffers with new memory.
3826 *
3827 * The management in the driver is as follows:
3828 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
3829 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Ian Schram01ebd062007-10-25 17:15:22 +08003830 * to replenish the iwl->rxq->rx_free.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003831 * + In iwl4965_rx_replenish (scheduled) if 'processed' != 'read' then the
Zhu Yib481de92007-09-25 17:54:57 -07003832 * iwl->rxq is replenished and the READ INDEX is updated (updating the
3833 * 'processed' and 'read' driver indexes as well)
3834 * + A received packet is processed and handed to the kernel network stack,
3835 * detached from the iwl->rxq. The driver 'processed' index is updated.
3836 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
3837 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
3838 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
3839 * were enough free buffers and RX_STALLED is set it is cleared.
3840 *
3841 *
3842 * Driver sequence:
3843 *
Ben Cahill9fbab512007-11-29 11:09:47 +08003844 * iwl4965_rx_queue_alloc() Allocates rx_free
3845 * iwl4965_rx_replenish() Replenishes rx_free list from rx_used, and calls
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003846 * iwl4965_rx_queue_restock
Ben Cahill9fbab512007-11-29 11:09:47 +08003847 * iwl4965_rx_queue_restock() Moves available buffers from rx_free into Rx
Zhu Yib481de92007-09-25 17:54:57 -07003848 * queue, updates firmware pointers, and updates
3849 * the WRITE index. If insufficient rx_free buffers
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003850 * are available, schedules iwl4965_rx_replenish
Zhu Yib481de92007-09-25 17:54:57 -07003851 *
3852 * -- enable interrupts --
Ben Cahill9fbab512007-11-29 11:09:47 +08003853 * ISR - iwl4965_rx() Detach iwl4965_rx_mem_buffers from pool up to the
Zhu Yib481de92007-09-25 17:54:57 -07003854 * READ INDEX, detaching the SKB from the pool.
3855 * Moves the packet buffer from queue to rx_used.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003856 * Calls iwl4965_rx_queue_restock to refill any empty
Zhu Yib481de92007-09-25 17:54:57 -07003857 * slots.
3858 * ...
3859 *
3860 */
3861
3862/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003863 * iwl4965_rx_queue_space - Return number of free slots available in queue.
Zhu Yib481de92007-09-25 17:54:57 -07003864 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003865static int iwl4965_rx_queue_space(const struct iwl4965_rx_queue *q)
Zhu Yib481de92007-09-25 17:54:57 -07003866{
3867 int s = q->read - q->write;
3868 if (s <= 0)
3869 s += RX_QUEUE_SIZE;
3870 /* keep some buffer to not confuse full and empty queue */
3871 s -= 2;
3872 if (s < 0)
3873 s = 0;
3874 return s;
3875}
3876
3877/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003878 * iwl4965_rx_queue_update_write_ptr - Update the write pointer for the RX queue
Zhu Yib481de92007-09-25 17:54:57 -07003879 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003880int iwl4965_rx_queue_update_write_ptr(struct iwl_priv *priv, struct iwl4965_rx_queue *q)
Zhu Yib481de92007-09-25 17:54:57 -07003881{
3882 u32 reg = 0;
3883 int rc = 0;
3884 unsigned long flags;
3885
3886 spin_lock_irqsave(&q->lock, flags);
3887
3888 if (q->need_update == 0)
3889 goto exit_unlock;
3890
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003891 /* If power-saving is in use, make sure device is awake */
Zhu Yib481de92007-09-25 17:54:57 -07003892 if (test_bit(STATUS_POWER_PMI, &priv->status)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003893 reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
Zhu Yib481de92007-09-25 17:54:57 -07003894
3895 if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003896 iwl4965_set_bit(priv, CSR_GP_CNTRL,
Zhu Yib481de92007-09-25 17:54:57 -07003897 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
3898 goto exit_unlock;
3899 }
3900
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003901 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003902 if (rc)
3903 goto exit_unlock;
3904
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003905 /* Device expects a multiple of 8 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003906 iwl4965_write_direct32(priv, FH_RSCSR_CHNL0_WPTR,
Zhu Yib481de92007-09-25 17:54:57 -07003907 q->write & ~0x7);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003908 iwl4965_release_nic_access(priv);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003909
3910 /* Else device is assumed to be awake */
Zhu Yib481de92007-09-25 17:54:57 -07003911 } else
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003912 /* Device expects a multiple of 8 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003913 iwl4965_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7);
Zhu Yib481de92007-09-25 17:54:57 -07003914
3915
3916 q->need_update = 0;
3917
3918 exit_unlock:
3919 spin_unlock_irqrestore(&q->lock, flags);
3920 return rc;
3921}
3922
3923/**
Ben Cahill9fbab512007-11-29 11:09:47 +08003924 * iwl4965_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
Zhu Yib481de92007-09-25 17:54:57 -07003925 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003926static inline __le32 iwl4965_dma_addr2rbd_ptr(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07003927 dma_addr_t dma_addr)
3928{
3929 return cpu_to_le32((u32)(dma_addr >> 8));
3930}
3931
3932
3933/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003934 * iwl4965_rx_queue_restock - refill RX queue from pre-allocated pool
Zhu Yib481de92007-09-25 17:54:57 -07003935 *
Ben Cahill9fbab512007-11-29 11:09:47 +08003936 * If there are slots in the RX queue that need to be restocked,
Zhu Yib481de92007-09-25 17:54:57 -07003937 * and we have free pre-allocated buffers, fill the ranks as much
Ben Cahill9fbab512007-11-29 11:09:47 +08003938 * as we can, pulling from rx_free.
Zhu Yib481de92007-09-25 17:54:57 -07003939 *
3940 * This moves the 'write' index forward to catch up with 'processed', and
3941 * also updates the memory address in the firmware to reference the new
3942 * target buffer.
3943 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003944static int iwl4965_rx_queue_restock(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003945{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003946 struct iwl4965_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07003947 struct list_head *element;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003948 struct iwl4965_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07003949 unsigned long flags;
3950 int write, rc;
3951
3952 spin_lock_irqsave(&rxq->lock, flags);
3953 write = rxq->write & ~0x7;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003954 while ((iwl4965_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003955 /* Get next free Rx buffer, remove from free list */
Zhu Yib481de92007-09-25 17:54:57 -07003956 element = rxq->rx_free.next;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003957 rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07003958 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003959
3960 /* Point to Rx buffer via next RBD in circular buffer */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003961 rxq->bd[rxq->write] = iwl4965_dma_addr2rbd_ptr(priv, rxb->dma_addr);
Zhu Yib481de92007-09-25 17:54:57 -07003962 rxq->queue[rxq->write] = rxb;
3963 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
3964 rxq->free_count--;
3965 }
3966 spin_unlock_irqrestore(&rxq->lock, flags);
3967 /* If the pre-allocated buffer pool is dropping low, schedule to
3968 * refill it */
3969 if (rxq->free_count <= RX_LOW_WATERMARK)
3970 queue_work(priv->workqueue, &priv->rx_replenish);
3971
3972
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003973 /* If we've added more space for the firmware to place data, tell it.
3974 * Increment device's write pointer in multiples of 8. */
Zhu Yib481de92007-09-25 17:54:57 -07003975 if ((write != (rxq->write & ~0x7))
3976 || (abs(rxq->write - rxq->read) > 7)) {
3977 spin_lock_irqsave(&rxq->lock, flags);
3978 rxq->need_update = 1;
3979 spin_unlock_irqrestore(&rxq->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003980 rc = iwl4965_rx_queue_update_write_ptr(priv, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07003981 if (rc)
3982 return rc;
3983 }
3984
3985 return 0;
3986}
3987
3988/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003989 * iwl4965_rx_replenish - Move all used packet from rx_used to rx_free
Zhu Yib481de92007-09-25 17:54:57 -07003990 *
3991 * When moving to rx_free an SKB is allocated for the slot.
3992 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003993 * Also restock the Rx queue via iwl4965_rx_queue_restock.
Ian Schram01ebd062007-10-25 17:15:22 +08003994 * This is called as a scheduled work item (except for during initialization)
Zhu Yib481de92007-09-25 17:54:57 -07003995 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003996static void iwl4965_rx_allocate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003997{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003998 struct iwl4965_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07003999 struct list_head *element;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004000 struct iwl4965_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07004001 unsigned long flags;
4002 spin_lock_irqsave(&rxq->lock, flags);
4003 while (!list_empty(&rxq->rx_used)) {
4004 element = rxq->rx_used.next;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004005 rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004006
4007 /* Alloc a new receive buffer */
Zhu Yib481de92007-09-25 17:54:57 -07004008 rxb->skb =
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02004009 alloc_skb(priv->hw_setting.rx_buf_size,
4010 __GFP_NOWARN | GFP_ATOMIC);
Zhu Yib481de92007-09-25 17:54:57 -07004011 if (!rxb->skb) {
4012 if (net_ratelimit())
4013 printk(KERN_CRIT DRV_NAME
4014 ": Can not allocate SKB buffers\n");
4015 /* We don't reschedule replenish work here -- we will
4016 * call the restock method and if it still needs
4017 * more buffers it will schedule replenish */
4018 break;
4019 }
4020 priv->alloc_rxb_skb++;
4021 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004022
4023 /* Get physical address of RB/SKB */
Zhu Yib481de92007-09-25 17:54:57 -07004024 rxb->dma_addr =
4025 pci_map_single(priv->pci_dev, rxb->skb->data,
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02004026 priv->hw_setting.rx_buf_size, PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07004027 list_add_tail(&rxb->list, &rxq->rx_free);
4028 rxq->free_count++;
4029 }
4030 spin_unlock_irqrestore(&rxq->lock, flags);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08004031}
4032
4033/*
4034 * this should be called while priv->lock is locked
4035*/
Tomas Winkler4fd1f842007-12-05 20:59:58 +02004036static void __iwl4965_rx_replenish(void *data)
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08004037{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004038 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08004039
4040 iwl4965_rx_allocate(priv);
4041 iwl4965_rx_queue_restock(priv);
4042}
4043
4044
4045void iwl4965_rx_replenish(void *data)
4046{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004047 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08004048 unsigned long flags;
4049
4050 iwl4965_rx_allocate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004051
4052 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004053 iwl4965_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004054 spin_unlock_irqrestore(&priv->lock, flags);
4055}
4056
4057/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
Ben Cahill9fbab512007-11-29 11:09:47 +08004058 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
Zhu Yib481de92007-09-25 17:54:57 -07004059 * This free routine walks the list of POOL entries and if SKB is set to
4060 * non NULL it is unmapped and freed
4061 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004062static void iwl4965_rx_queue_free(struct iwl_priv *priv, struct iwl4965_rx_queue *rxq)
Zhu Yib481de92007-09-25 17:54:57 -07004063{
4064 int i;
4065 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4066 if (rxq->pool[i].skb != NULL) {
4067 pci_unmap_single(priv->pci_dev,
4068 rxq->pool[i].dma_addr,
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02004069 priv->hw_setting.rx_buf_size,
4070 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07004071 dev_kfree_skb(rxq->pool[i].skb);
4072 }
4073 }
4074
4075 pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd,
4076 rxq->dma_addr);
4077 rxq->bd = NULL;
4078}
4079
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004080int iwl4965_rx_queue_alloc(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004081{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004082 struct iwl4965_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07004083 struct pci_dev *dev = priv->pci_dev;
4084 int i;
4085
4086 spin_lock_init(&rxq->lock);
4087 INIT_LIST_HEAD(&rxq->rx_free);
4088 INIT_LIST_HEAD(&rxq->rx_used);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004089
4090 /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
Zhu Yib481de92007-09-25 17:54:57 -07004091 rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr);
4092 if (!rxq->bd)
4093 return -ENOMEM;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004094
Zhu Yib481de92007-09-25 17:54:57 -07004095 /* Fill the rx_used queue with _all_ of the Rx buffers */
4096 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
4097 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004098
Zhu Yib481de92007-09-25 17:54:57 -07004099 /* Set us so that we have processed and used all buffers, but have
4100 * not restocked the Rx queue with fresh buffers */
4101 rxq->read = rxq->write = 0;
4102 rxq->free_count = 0;
4103 rxq->need_update = 0;
4104 return 0;
4105}
4106
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004107void iwl4965_rx_queue_reset(struct iwl_priv *priv, struct iwl4965_rx_queue *rxq)
Zhu Yib481de92007-09-25 17:54:57 -07004108{
4109 unsigned long flags;
4110 int i;
4111 spin_lock_irqsave(&rxq->lock, flags);
4112 INIT_LIST_HEAD(&rxq->rx_free);
4113 INIT_LIST_HEAD(&rxq->rx_used);
4114 /* Fill the rx_used queue with _all_ of the Rx buffers */
4115 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
4116 /* In the reset function, these buffers may have been allocated
4117 * to an SKB, so we need to unmap and free potential storage */
4118 if (rxq->pool[i].skb != NULL) {
4119 pci_unmap_single(priv->pci_dev,
4120 rxq->pool[i].dma_addr,
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02004121 priv->hw_setting.rx_buf_size,
4122 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07004123 priv->alloc_rxb_skb--;
4124 dev_kfree_skb(rxq->pool[i].skb);
4125 rxq->pool[i].skb = NULL;
4126 }
4127 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4128 }
4129
4130 /* Set us so that we have processed and used all buffers, but have
4131 * not restocked the Rx queue with fresh buffers */
4132 rxq->read = rxq->write = 0;
4133 rxq->free_count = 0;
4134 spin_unlock_irqrestore(&rxq->lock, flags);
4135}
4136
4137/* Convert linear signal-to-noise ratio into dB */
4138static u8 ratio2dB[100] = {
4139/* 0 1 2 3 4 5 6 7 8 9 */
4140 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
4141 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
4142 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
4143 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
4144 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
4145 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
4146 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
4147 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
4148 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
4149 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
4150};
4151
4152/* Calculates a relative dB value from a ratio of linear
4153 * (i.e. not dB) signal levels.
4154 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004155int iwl4965_calc_db_from_ratio(int sig_ratio)
Zhu Yib481de92007-09-25 17:54:57 -07004156{
Adrian Bunkc899a572007-10-14 19:51:15 +02004157 /* 1000:1 or higher just report as 60 dB */
4158 if (sig_ratio >= 1000)
Zhu Yib481de92007-09-25 17:54:57 -07004159 return 60;
4160
Adrian Bunkc899a572007-10-14 19:51:15 +02004161 /* 100:1 or higher, divide by 10 and use table,
Zhu Yib481de92007-09-25 17:54:57 -07004162 * add 20 dB to make up for divide by 10 */
Adrian Bunkc899a572007-10-14 19:51:15 +02004163 if (sig_ratio >= 100)
Zhu Yib481de92007-09-25 17:54:57 -07004164 return (20 + (int)ratio2dB[sig_ratio/10]);
4165
4166 /* We shouldn't see this */
4167 if (sig_ratio < 1)
4168 return 0;
4169
4170 /* Use table for ratios 1:1 - 99:1 */
4171 return (int)ratio2dB[sig_ratio];
4172}
4173
4174#define PERFECT_RSSI (-20) /* dBm */
4175#define WORST_RSSI (-95) /* dBm */
4176#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
4177
4178/* Calculate an indication of rx signal quality (a percentage, not dBm!).
4179 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
4180 * about formulas used below. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004181int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm)
Zhu Yib481de92007-09-25 17:54:57 -07004182{
4183 int sig_qual;
4184 int degradation = PERFECT_RSSI - rssi_dbm;
4185
4186 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
4187 * as indicator; formula is (signal dbm - noise dbm).
4188 * SNR at or above 40 is a great signal (100%).
4189 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
4190 * Weakest usable signal is usually 10 - 15 dB SNR. */
4191 if (noise_dbm) {
4192 if (rssi_dbm - noise_dbm >= 40)
4193 return 100;
4194 else if (rssi_dbm < noise_dbm)
4195 return 0;
4196 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
4197
4198 /* Else use just the signal level.
4199 * This formula is a least squares fit of data points collected and
4200 * compared with a reference system that had a percentage (%) display
4201 * for signal quality. */
4202 } else
4203 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
4204 (15 * RSSI_RANGE + 62 * degradation)) /
4205 (RSSI_RANGE * RSSI_RANGE);
4206
4207 if (sig_qual > 100)
4208 sig_qual = 100;
4209 else if (sig_qual < 1)
4210 sig_qual = 0;
4211
4212 return sig_qual;
4213}
4214
4215/**
Ben Cahill9fbab512007-11-29 11:09:47 +08004216 * iwl4965_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07004217 *
4218 * Uses the priv->rx_handlers callback function array to invoke
4219 * the appropriate handlers, including command responses,
4220 * frame-received notifications, and other notifications.
4221 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004222static void iwl4965_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004223{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004224 struct iwl4965_rx_mem_buffer *rxb;
4225 struct iwl4965_rx_packet *pkt;
4226 struct iwl4965_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07004227 u32 r, i;
4228 int reclaim;
4229 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08004230 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08004231 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07004232
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004233 /* uCode's read index (stored in shared DRAM) indicates the last Rx
4234 * buffer that the driver may process (last buffer filled by ucode). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004235 r = iwl4965_hw_get_rx_read(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004236 i = rxq->read;
4237
4238 /* Rx interrupt, but nothing sent from uCode */
4239 if (i == r)
4240 IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
4241
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08004242 if (iwl4965_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
4243 fill_rx = 1;
4244
Zhu Yib481de92007-09-25 17:54:57 -07004245 while (i != r) {
4246 rxb = rxq->queue[i];
4247
Ben Cahill9fbab512007-11-29 11:09:47 +08004248 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07004249 * then a bug has been introduced in the queue refilling
4250 * routines -- catch it here */
4251 BUG_ON(rxb == NULL);
4252
4253 rxq->queue[i] = NULL;
4254
4255 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02004256 priv->hw_setting.rx_buf_size,
Zhu Yib481de92007-09-25 17:54:57 -07004257 PCI_DMA_FROMDEVICE);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004258 pkt = (struct iwl4965_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07004259
4260 /* Reclaim a command buffer only if this packet is a response
4261 * to a (driver-originated) command.
4262 * If the packet (e.g. Rx frame) originated from uCode,
4263 * there is no command buffer to reclaim.
4264 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
4265 * but apparently a few don't get set; catch them here. */
4266 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
4267 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
4268 (pkt->hdr.cmd != REPLY_4965_RX) &&
Zhu Yicfe01702007-09-27 11:27:31 +08004269 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
Zhu Yib481de92007-09-25 17:54:57 -07004270 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
4271 (pkt->hdr.cmd != REPLY_TX);
4272
4273 /* Based on type of command response or notification,
4274 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004275 * rx_handlers table. See iwl4965_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07004276 if (priv->rx_handlers[pkt->hdr.cmd]) {
4277 IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
4278 "r = %d, i = %d, %s, 0x%02x\n", r, i,
4279 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
4280 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
4281 } else {
4282 /* No handling needed */
4283 IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
4284 "r %d i %d No handler needed for %s, 0x%02x\n",
4285 r, i, get_cmd_string(pkt->hdr.cmd),
4286 pkt->hdr.cmd);
4287 }
4288
4289 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08004290 /* Invoke any callbacks, transfer the skb to caller, and
4291 * fire off the (possibly) blocking iwl4965_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07004292 * as we reclaim the driver command queue */
4293 if (rxb && rxb->skb)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004294 iwl4965_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07004295 else
4296 IWL_WARNING("Claim null rxb?\n");
4297 }
4298
4299 /* For now we just don't re-use anything. We can tweak this
4300 * later to try and re-use notification packets and SKBs that
4301 * fail to Rx correctly */
4302 if (rxb->skb != NULL) {
4303 priv->alloc_rxb_skb--;
4304 dev_kfree_skb_any(rxb->skb);
4305 rxb->skb = NULL;
4306 }
4307
4308 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02004309 priv->hw_setting.rx_buf_size,
4310 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07004311 spin_lock_irqsave(&rxq->lock, flags);
4312 list_add_tail(&rxb->list, &priv->rxq.rx_used);
4313 spin_unlock_irqrestore(&rxq->lock, flags);
4314 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08004315 /* If there are a lot of unused frames,
4316 * restock the Rx queue so ucode wont assert. */
4317 if (fill_rx) {
4318 count++;
4319 if (count >= 8) {
4320 priv->rxq.read = i;
4321 __iwl4965_rx_replenish(priv);
4322 count = 0;
4323 }
4324 }
Zhu Yib481de92007-09-25 17:54:57 -07004325 }
4326
4327 /* Backtrack one entry */
4328 priv->rxq.read = i;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004329 iwl4965_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004330}
4331
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004332/**
4333 * iwl4965_tx_queue_update_write_ptr - Send new write index to hardware
4334 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004335static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004336 struct iwl4965_tx_queue *txq)
Zhu Yib481de92007-09-25 17:54:57 -07004337{
4338 u32 reg = 0;
4339 int rc = 0;
4340 int txq_id = txq->q.id;
4341
4342 if (txq->need_update == 0)
4343 return rc;
4344
4345 /* if we're trying to save power */
4346 if (test_bit(STATUS_POWER_PMI, &priv->status)) {
4347 /* wake up nic if it's powered down ...
4348 * uCode will wake up, and interrupt us again, so next
4349 * time we'll skip this part. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004350 reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
Zhu Yib481de92007-09-25 17:54:57 -07004351
4352 if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
4353 IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004354 iwl4965_set_bit(priv, CSR_GP_CNTRL,
Zhu Yib481de92007-09-25 17:54:57 -07004355 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
4356 return rc;
4357 }
4358
4359 /* restore this queue's parameters in nic hardware. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004360 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004361 if (rc)
4362 return rc;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004363 iwl4965_write_direct32(priv, HBUS_TARG_WRPTR,
Tomas Winklerfc4b6852007-10-25 17:15:24 +08004364 txq->q.write_ptr | (txq_id << 8));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004365 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004366
4367 /* else not in power-save mode, uCode will never sleep when we're
4368 * trying to tx (during RFKILL, we're not trying to tx). */
4369 } else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004370 iwl4965_write32(priv, HBUS_TARG_WRPTR,
Tomas Winklerfc4b6852007-10-25 17:15:24 +08004371 txq->q.write_ptr | (txq_id << 8));
Zhu Yib481de92007-09-25 17:54:57 -07004372
4373 txq->need_update = 0;
4374
4375 return rc;
4376}
4377
Tomas Winkler0a6857e2008-03-12 16:58:49 -07004378#ifdef CONFIG_IWLWIFI_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004379static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd *rxon)
Zhu Yib481de92007-09-25 17:54:57 -07004380{
Joe Perches0795af52007-10-03 17:59:30 -07004381 DECLARE_MAC_BUF(mac);
4382
Zhu Yib481de92007-09-25 17:54:57 -07004383 IWL_DEBUG_RADIO("RX CONFIG:\n");
Tomas Winkler0a6857e2008-03-12 16:58:49 -07004384 iwl_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
Zhu Yib481de92007-09-25 17:54:57 -07004385 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
4386 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
4387 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
4388 le32_to_cpu(rxon->filter_flags));
4389 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
4390 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
4391 rxon->ofdm_basic_rates);
4392 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
Joe Perches0795af52007-10-03 17:59:30 -07004393 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
4394 print_mac(mac, rxon->node_addr));
4395 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
4396 print_mac(mac, rxon->bssid_addr));
Zhu Yib481de92007-09-25 17:54:57 -07004397 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
4398}
4399#endif
4400
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004401static void iwl4965_enable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004402{
4403 IWL_DEBUG_ISR("Enabling interrupts\n");
4404 set_bit(STATUS_INT_ENABLED, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004405 iwl4965_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07004406}
4407
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004408static inline void iwl4965_disable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004409{
4410 clear_bit(STATUS_INT_ENABLED, &priv->status);
4411
4412 /* disable interrupts from uCode/NIC to host */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004413 iwl4965_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07004414
4415 /* acknowledge/clear/reset any interrupts still pending
4416 * from uCode or flow handler (Rx/Tx DMA) */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004417 iwl4965_write32(priv, CSR_INT, 0xffffffff);
4418 iwl4965_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
Zhu Yib481de92007-09-25 17:54:57 -07004419 IWL_DEBUG_ISR("Disabled interrupts\n");
4420}
4421
4422static const char *desc_lookup(int i)
4423{
4424 switch (i) {
4425 case 1:
4426 return "FAIL";
4427 case 2:
4428 return "BAD_PARAM";
4429 case 3:
4430 return "BAD_CHECKSUM";
4431 case 4:
4432 return "NMI_INTERRUPT";
4433 case 5:
4434 return "SYSASSERT";
4435 case 6:
4436 return "FATAL_ERROR";
4437 }
4438
4439 return "UNKNOWN";
4440}
4441
4442#define ERROR_START_OFFSET (1 * sizeof(u32))
4443#define ERROR_ELEM_SIZE (7 * sizeof(u32))
4444
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004445static void iwl4965_dump_nic_error_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004446{
4447 u32 data2, line;
4448 u32 desc, time, count, base, data1;
4449 u32 blink1, blink2, ilink1, ilink2;
4450 int rc;
4451
4452 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
4453
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004454 if (!iwl4965_hw_valid_rtc_data_addr(base)) {
Zhu Yib481de92007-09-25 17:54:57 -07004455 IWL_ERROR("Not valid error log pointer 0x%08X\n", base);
4456 return;
4457 }
4458
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004459 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004460 if (rc) {
4461 IWL_WARNING("Can not read from adapter at this time.\n");
4462 return;
4463 }
4464
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004465 count = iwl4965_read_targ_mem(priv, base);
Zhu Yib481de92007-09-25 17:54:57 -07004466
4467 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
4468 IWL_ERROR("Start IWL Error Log Dump:\n");
Tomas Winkler2acae162008-03-02 01:25:59 +02004469 IWL_ERROR("Status: 0x%08lX, count: %d\n", priv->status, count);
Zhu Yib481de92007-09-25 17:54:57 -07004470 }
4471
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004472 desc = iwl4965_read_targ_mem(priv, base + 1 * sizeof(u32));
4473 blink1 = iwl4965_read_targ_mem(priv, base + 3 * sizeof(u32));
4474 blink2 = iwl4965_read_targ_mem(priv, base + 4 * sizeof(u32));
4475 ilink1 = iwl4965_read_targ_mem(priv, base + 5 * sizeof(u32));
4476 ilink2 = iwl4965_read_targ_mem(priv, base + 6 * sizeof(u32));
4477 data1 = iwl4965_read_targ_mem(priv, base + 7 * sizeof(u32));
4478 data2 = iwl4965_read_targ_mem(priv, base + 8 * sizeof(u32));
4479 line = iwl4965_read_targ_mem(priv, base + 9 * sizeof(u32));
4480 time = iwl4965_read_targ_mem(priv, base + 11 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07004481
4482 IWL_ERROR("Desc Time "
4483 "data1 data2 line\n");
4484 IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n",
4485 desc_lookup(desc), desc, time, data1, data2, line);
4486 IWL_ERROR("blink1 blink2 ilink1 ilink2\n");
4487 IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2,
4488 ilink1, ilink2);
4489
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004490 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004491}
4492
4493#define EVENT_START_OFFSET (4 * sizeof(u32))
4494
4495/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004496 * iwl4965_print_event_log - Dump error event log to syslog
Zhu Yib481de92007-09-25 17:54:57 -07004497 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004498 * NOTE: Must be called with iwl4965_grab_nic_access() already obtained!
Zhu Yib481de92007-09-25 17:54:57 -07004499 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004500static void iwl4965_print_event_log(struct iwl_priv *priv, u32 start_idx,
Zhu Yib481de92007-09-25 17:54:57 -07004501 u32 num_events, u32 mode)
4502{
4503 u32 i;
4504 u32 base; /* SRAM byte address of event log header */
4505 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
4506 u32 ptr; /* SRAM byte address of log data */
4507 u32 ev, time, data; /* event log data */
4508
4509 if (num_events == 0)
4510 return;
4511
4512 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
4513
4514 if (mode == 0)
4515 event_size = 2 * sizeof(u32);
4516 else
4517 event_size = 3 * sizeof(u32);
4518
4519 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
4520
4521 /* "time" is actually "data" for mode 0 (no timestamp).
4522 * place event id # at far right for easier visual parsing. */
4523 for (i = 0; i < num_events; i++) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004524 ev = iwl4965_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07004525 ptr += sizeof(u32);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004526 time = iwl4965_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07004527 ptr += sizeof(u32);
4528 if (mode == 0)
4529 IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */
4530 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004531 data = iwl4965_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07004532 ptr += sizeof(u32);
4533 IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev);
4534 }
4535 }
4536}
4537
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004538static void iwl4965_dump_nic_event_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004539{
4540 int rc;
4541 u32 base; /* SRAM byte address of event log header */
4542 u32 capacity; /* event log capacity in # entries */
4543 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
4544 u32 num_wraps; /* # times uCode wrapped to top of log */
4545 u32 next_entry; /* index of next entry to be written by uCode */
4546 u32 size; /* # entries that we'll print */
4547
4548 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004549 if (!iwl4965_hw_valid_rtc_data_addr(base)) {
Zhu Yib481de92007-09-25 17:54:57 -07004550 IWL_ERROR("Invalid event log pointer 0x%08X\n", base);
4551 return;
4552 }
4553
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004554 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004555 if (rc) {
4556 IWL_WARNING("Can not read from adapter at this time.\n");
4557 return;
4558 }
4559
4560 /* event log header */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004561 capacity = iwl4965_read_targ_mem(priv, base);
4562 mode = iwl4965_read_targ_mem(priv, base + (1 * sizeof(u32)));
4563 num_wraps = iwl4965_read_targ_mem(priv, base + (2 * sizeof(u32)));
4564 next_entry = iwl4965_read_targ_mem(priv, base + (3 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -07004565
4566 size = num_wraps ? capacity : next_entry;
4567
4568 /* bail out if nothing in log */
4569 if (size == 0) {
Zhu Yi583fab32007-09-27 11:27:30 +08004570 IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004571 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004572 return;
4573 }
4574
Zhu Yi583fab32007-09-27 11:27:30 +08004575 IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07004576 size, num_wraps);
4577
4578 /* if uCode has wrapped back to top of log, start at the oldest entry,
4579 * i.e the next one that uCode would fill. */
4580 if (num_wraps)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004581 iwl4965_print_event_log(priv, next_entry,
Zhu Yib481de92007-09-25 17:54:57 -07004582 capacity - next_entry, mode);
4583
4584 /* (then/else) start at top of log */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004585 iwl4965_print_event_log(priv, 0, next_entry, mode);
Zhu Yib481de92007-09-25 17:54:57 -07004586
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004587 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004588}
4589
4590/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004591 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
Zhu Yib481de92007-09-25 17:54:57 -07004592 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004593static void iwl4965_irq_handle_error(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004594{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004595 /* Set the FW error flag -- cleared on iwl4965_down */
Zhu Yib481de92007-09-25 17:54:57 -07004596 set_bit(STATUS_FW_ERROR, &priv->status);
4597
4598 /* Cancel currently queued command. */
4599 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
4600
Tomas Winkler0a6857e2008-03-12 16:58:49 -07004601#ifdef CONFIG_IWLWIFI_DEBUG
4602 if (iwl_debug_level & IWL_DL_FW_ERRORS) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004603 iwl4965_dump_nic_error_log(priv);
4604 iwl4965_dump_nic_event_log(priv);
4605 iwl4965_print_rx_config_cmd(&priv->staging_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07004606 }
4607#endif
4608
4609 wake_up_interruptible(&priv->wait_command_queue);
4610
4611 /* Keep the restart process from trying to send host
4612 * commands by clearing the INIT status bit */
4613 clear_bit(STATUS_READY, &priv->status);
4614
4615 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
4616 IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS,
4617 "Restarting adapter due to uCode error.\n");
4618
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004619 if (iwl4965_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004620 memcpy(&priv->recovery_rxon, &priv->active_rxon,
4621 sizeof(priv->recovery_rxon));
4622 priv->error_recovering = 1;
4623 }
4624 queue_work(priv->workqueue, &priv->restart);
4625 }
4626}
4627
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004628static void iwl4965_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004629{
4630 unsigned long flags;
4631
4632 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
4633 sizeof(priv->staging_rxon));
4634 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004635 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004636
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004637 iwl4965_rxon_add_station(priv, priv->bssid, 1);
Zhu Yib481de92007-09-25 17:54:57 -07004638
4639 spin_lock_irqsave(&priv->lock, flags);
4640 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
4641 priv->error_recovering = 0;
4642 spin_unlock_irqrestore(&priv->lock, flags);
4643}
4644
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004645static void iwl4965_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004646{
4647 u32 inta, handled = 0;
4648 u32 inta_fh;
4649 unsigned long flags;
Tomas Winkler0a6857e2008-03-12 16:58:49 -07004650#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07004651 u32 inta_mask;
4652#endif
4653
4654 spin_lock_irqsave(&priv->lock, flags);
4655
4656 /* Ack/clear/reset pending uCode interrupts.
4657 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
4658 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004659 inta = iwl4965_read32(priv, CSR_INT);
4660 iwl4965_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07004661
4662 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
4663 * Any new interrupts that happen after this, either while we're
4664 * in this tasklet, or later, will show up in next ISR/tasklet. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004665 inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS);
4666 iwl4965_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07004667
Tomas Winkler0a6857e2008-03-12 16:58:49 -07004668#ifdef CONFIG_IWLWIFI_DEBUG
4669 if (iwl_debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08004670 /* just for debug */
4671 inta_mask = iwl4965_read32(priv, CSR_INT_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07004672 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4673 inta, inta_mask, inta_fh);
4674 }
4675#endif
4676
4677 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
4678 * atomic, make sure that inta covers all the interrupts that
4679 * we've discovered, even if FH interrupt came in just after
4680 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08004681 if (inta_fh & CSR49_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07004682 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08004683 if (inta_fh & CSR49_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07004684 inta |= CSR_INT_BIT_FH_TX;
4685
4686 /* Now service all interrupt bits discovered above. */
4687 if (inta & CSR_INT_BIT_HW_ERR) {
4688 IWL_ERROR("Microcode HW error detected. Restarting.\n");
4689
4690 /* Tell the device to stop sending interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004691 iwl4965_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004692
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004693 iwl4965_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004694
4695 handled |= CSR_INT_BIT_HW_ERR;
4696
4697 spin_unlock_irqrestore(&priv->lock, flags);
4698
4699 return;
4700 }
4701
Tomas Winkler0a6857e2008-03-12 16:58:49 -07004702#ifdef CONFIG_IWLWIFI_DEBUG
4703 if (iwl_debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07004704 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08004705 if (inta & CSR_INT_BIT_SCD)
4706 IWL_DEBUG_ISR("Scheduler finished to transmit "
4707 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004708
4709 /* Alive notification via Rx interrupt will do the real work */
4710 if (inta & CSR_INT_BIT_ALIVE)
4711 IWL_DEBUG_ISR("Alive interrupt\n");
4712 }
4713#endif
4714 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08004715 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07004716
Ben Cahill9fbab512007-11-29 11:09:47 +08004717 /* HW RF KILL switch toggled */
Zhu Yib481de92007-09-25 17:54:57 -07004718 if (inta & CSR_INT_BIT_RF_KILL) {
4719 int hw_rf_kill = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004720 if (!(iwl4965_read32(priv, CSR_GP_CNTRL) &
Zhu Yib481de92007-09-25 17:54:57 -07004721 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
4722 hw_rf_kill = 1;
4723
4724 IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL | IWL_DL_ISR,
4725 "RF_KILL bit toggled to %s.\n",
4726 hw_rf_kill ? "disable radio":"enable radio");
4727
4728 /* Queue restart only if RF_KILL switch was set to "kill"
4729 * when we loaded driver, and is now set to "enable".
4730 * After we're Alive, RF_KILL gets handled by
Reinette Chatre32304552008-02-15 14:34:37 -08004731 * iwl4965_rx_card_state_notif() */
Zhu Yi53e49092007-12-06 16:08:44 +08004732 if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) {
4733 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004734 queue_work(priv->workqueue, &priv->restart);
Zhu Yi53e49092007-12-06 16:08:44 +08004735 }
Zhu Yib481de92007-09-25 17:54:57 -07004736
4737 handled |= CSR_INT_BIT_RF_KILL;
4738 }
4739
Ben Cahill9fbab512007-11-29 11:09:47 +08004740 /* Chip got too hot and stopped itself */
Zhu Yib481de92007-09-25 17:54:57 -07004741 if (inta & CSR_INT_BIT_CT_KILL) {
4742 IWL_ERROR("Microcode CT kill error detected.\n");
4743 handled |= CSR_INT_BIT_CT_KILL;
4744 }
4745
4746 /* Error detected by uCode */
4747 if (inta & CSR_INT_BIT_SW_ERR) {
4748 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
4749 inta);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004750 iwl4965_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004751 handled |= CSR_INT_BIT_SW_ERR;
4752 }
4753
4754 /* uCode wakes up after power-down sleep */
4755 if (inta & CSR_INT_BIT_WAKEUP) {
4756 IWL_DEBUG_ISR("Wakeup interrupt\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004757 iwl4965_rx_queue_update_write_ptr(priv, &priv->rxq);
4758 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[0]);
4759 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[1]);
4760 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[2]);
4761 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[3]);
4762 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[4]);
4763 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07004764
4765 handled |= CSR_INT_BIT_WAKEUP;
4766 }
4767
4768 /* All uCode command responses, including Tx command responses,
4769 * Rx "responses" (frame-received notification), and other
4770 * notifications from uCode come through here*/
4771 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004772 iwl4965_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004773 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
4774 }
4775
4776 if (inta & CSR_INT_BIT_FH_TX) {
4777 IWL_DEBUG_ISR("Tx interrupt\n");
4778 handled |= CSR_INT_BIT_FH_TX;
4779 }
4780
4781 if (inta & ~handled)
4782 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
4783
4784 if (inta & ~CSR_INI_SET_MASK) {
4785 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
4786 inta & ~CSR_INI_SET_MASK);
4787 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
4788 }
4789
4790 /* Re-enable all interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004791 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004792
Tomas Winkler0a6857e2008-03-12 16:58:49 -07004793#ifdef CONFIG_IWLWIFI_DEBUG
4794 if (iwl_debug_level & (IWL_DL_ISR)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004795 inta = iwl4965_read32(priv, CSR_INT);
4796 inta_mask = iwl4965_read32(priv, CSR_INT_MASK);
4797 inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07004798 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
4799 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
4800 }
4801#endif
4802 spin_unlock_irqrestore(&priv->lock, flags);
4803}
4804
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004805static irqreturn_t iwl4965_isr(int irq, void *data)
Zhu Yib481de92007-09-25 17:54:57 -07004806{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004807 struct iwl_priv *priv = data;
Zhu Yib481de92007-09-25 17:54:57 -07004808 u32 inta, inta_mask;
4809 u32 inta_fh;
4810 if (!priv)
4811 return IRQ_NONE;
4812
4813 spin_lock(&priv->lock);
4814
4815 /* Disable (but don't clear!) interrupts here to avoid
4816 * back-to-back ISRs and sporadic interrupts from our NIC.
4817 * If we have something to service, the tasklet will re-enable ints.
4818 * If we *don't* have something, we'll re-enable before leaving here. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004819 inta_mask = iwl4965_read32(priv, CSR_INT_MASK); /* just for debug */
4820 iwl4965_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07004821
4822 /* Discover which interrupts are active/pending */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004823 inta = iwl4965_read32(priv, CSR_INT);
4824 inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07004825
4826 /* Ignore interrupt if there's nothing in NIC to service.
4827 * This may be due to IRQ shared with another device,
4828 * or due to sporadic interrupts thrown from our NIC. */
4829 if (!inta && !inta_fh) {
4830 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
4831 goto none;
4832 }
4833
4834 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
Oliver Neukum66fbb542007-11-15 09:31:10 +08004835 /* Hardware disappeared. It might have already raised
4836 * an interrupt */
Zhu Yib481de92007-09-25 17:54:57 -07004837 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
Oliver Neukum66fbb542007-11-15 09:31:10 +08004838 goto unplugged;
Zhu Yib481de92007-09-25 17:54:57 -07004839 }
4840
4841 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4842 inta, inta_mask, inta_fh);
4843
Joonwoo Park25c03d82008-01-23 10:15:20 -08004844 inta &= ~CSR_INT_BIT_SCD;
4845
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004846 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
Joonwoo Park25c03d82008-01-23 10:15:20 -08004847 if (likely(inta || inta_fh))
4848 tasklet_schedule(&priv->irq_tasklet);
Zhu Yib481de92007-09-25 17:54:57 -07004849
Oliver Neukum66fbb542007-11-15 09:31:10 +08004850 unplugged:
4851 spin_unlock(&priv->lock);
Zhu Yib481de92007-09-25 17:54:57 -07004852 return IRQ_HANDLED;
4853
4854 none:
4855 /* re-enable interrupts here since we don't have anything to service. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004856 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004857 spin_unlock(&priv->lock);
4858 return IRQ_NONE;
4859}
4860
Zhu Yib481de92007-09-25 17:54:57 -07004861/* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
4862 * sending probe req. This should be set long enough to hear probe responses
4863 * from more than one AP. */
4864#define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
4865#define IWL_ACTIVE_DWELL_TIME_52 (10)
4866
4867/* For faster active scanning, scan will move to the next channel if fewer than
4868 * PLCP_QUIET_THRESH packets are heard on this channel within
4869 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
4870 * time if it's a quiet channel (nothing responded to our probe, and there's
4871 * no other traffic).
4872 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
4873#define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
4874#define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
4875
4876/* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
4877 * Must be set longer than active dwell time.
4878 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
4879#define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
4880#define IWL_PASSIVE_DWELL_TIME_52 (10)
4881#define IWL_PASSIVE_DWELL_BASE (100)
4882#define IWL_CHANNEL_TUNE_TIME 5
4883
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004884static inline u16 iwl4965_get_active_dwell_time(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01004885 enum ieee80211_band band)
Zhu Yib481de92007-09-25 17:54:57 -07004886{
Johannes Berg8318d782008-01-24 19:38:38 +01004887 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07004888 return IWL_ACTIVE_DWELL_TIME_52;
4889 else
4890 return IWL_ACTIVE_DWELL_TIME_24;
4891}
4892
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004893static u16 iwl4965_get_passive_dwell_time(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01004894 enum ieee80211_band band)
Zhu Yib481de92007-09-25 17:54:57 -07004895{
Johannes Berg8318d782008-01-24 19:38:38 +01004896 u16 active = iwl4965_get_active_dwell_time(priv, band);
4897 u16 passive = (band != IEEE80211_BAND_5GHZ) ?
Zhu Yib481de92007-09-25 17:54:57 -07004898 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
4899 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
4900
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004901 if (iwl4965_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004902 /* If we're associated, we clamp the maximum passive
4903 * dwell time to be 98% of the beacon interval (minus
4904 * 2 * channel tune time) */
4905 passive = priv->beacon_int;
4906 if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive)
4907 passive = IWL_PASSIVE_DWELL_BASE;
4908 passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
4909 }
4910
4911 if (passive <= active)
4912 passive = active + 1;
4913
4914 return passive;
4915}
4916
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004917static int iwl4965_get_channels_for_scan(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01004918 enum ieee80211_band band,
Zhu Yib481de92007-09-25 17:54:57 -07004919 u8 is_active, u8 direct_mask,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004920 struct iwl4965_scan_channel *scan_ch)
Zhu Yib481de92007-09-25 17:54:57 -07004921{
4922 const struct ieee80211_channel *channels = NULL;
Johannes Berg8318d782008-01-24 19:38:38 +01004923 const struct ieee80211_supported_band *sband;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07004924 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07004925 u16 passive_dwell = 0;
4926 u16 active_dwell = 0;
4927 int added, i;
4928
Johannes Berg8318d782008-01-24 19:38:38 +01004929 sband = iwl4965_get_hw_mode(priv, band);
4930 if (!sband)
Zhu Yib481de92007-09-25 17:54:57 -07004931 return 0;
4932
Johannes Berg8318d782008-01-24 19:38:38 +01004933 channels = sband->channels;
Zhu Yib481de92007-09-25 17:54:57 -07004934
Johannes Berg8318d782008-01-24 19:38:38 +01004935 active_dwell = iwl4965_get_active_dwell_time(priv, band);
4936 passive_dwell = iwl4965_get_passive_dwell_time(priv, band);
Zhu Yib481de92007-09-25 17:54:57 -07004937
Johannes Berg8318d782008-01-24 19:38:38 +01004938 for (i = 0, added = 0; i < sband->n_channels; i++) {
4939 if (ieee80211_frequency_to_channel(channels[i].center_freq) ==
Zhu Yib481de92007-09-25 17:54:57 -07004940 le16_to_cpu(priv->active_rxon.channel)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004941 if (iwl4965_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004942 IWL_DEBUG_SCAN
4943 ("Skipping current channel %d\n",
4944 le16_to_cpu(priv->active_rxon.channel));
4945 continue;
4946 }
4947 } else if (priv->only_active_channel)
4948 continue;
4949
Johannes Berg8318d782008-01-24 19:38:38 +01004950 scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq);
Zhu Yib481de92007-09-25 17:54:57 -07004951
Johannes Berg8318d782008-01-24 19:38:38 +01004952 ch_info = iwl4965_get_channel_info(priv, band,
Ben Cahill9fbab512007-11-29 11:09:47 +08004953 scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07004954 if (!is_channel_valid(ch_info)) {
4955 IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
4956 scan_ch->channel);
4957 continue;
4958 }
4959
4960 if (!is_active || is_channel_passive(ch_info) ||
Johannes Berg8318d782008-01-24 19:38:38 +01004961 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN))
Zhu Yib481de92007-09-25 17:54:57 -07004962 scan_ch->type = 0; /* passive */
4963 else
4964 scan_ch->type = 1; /* active */
4965
4966 if (scan_ch->type & 1)
4967 scan_ch->type |= (direct_mask << 1);
4968
4969 if (is_channel_narrow(ch_info))
4970 scan_ch->type |= (1 << 7);
4971
4972 scan_ch->active_dwell = cpu_to_le16(active_dwell);
4973 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
4974
Ben Cahill9fbab512007-11-29 11:09:47 +08004975 /* Set txpower levels to defaults */
Zhu Yib481de92007-09-25 17:54:57 -07004976 scan_ch->tpc.dsp_atten = 110;
4977 /* scan_pwr_info->tpc.dsp_atten; */
4978
4979 /*scan_pwr_info->tpc.tx_gain; */
Johannes Berg8318d782008-01-24 19:38:38 +01004980 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07004981 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
4982 else {
4983 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
4984 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
Ben Cahill9fbab512007-11-29 11:09:47 +08004985 * power level:
Reinette Chatre8a1b0242008-01-14 17:46:25 -08004986 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
Zhu Yib481de92007-09-25 17:54:57 -07004987 */
4988 }
4989
4990 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
4991 scan_ch->channel,
4992 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
4993 (scan_ch->type & 1) ?
4994 active_dwell : passive_dwell);
4995
4996 scan_ch++;
4997 added++;
4998 }
4999
5000 IWL_DEBUG_SCAN("total channels to scan %d \n", added);
5001 return added;
5002}
5003
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005004static void iwl4965_init_hw_rates(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07005005 struct ieee80211_rate *rates)
5006{
5007 int i;
5008
5009 for (i = 0; i < IWL_RATE_COUNT; i++) {
Johannes Berg8318d782008-01-24 19:38:38 +01005010 rates[i].bitrate = iwl4965_rates[i].ieee * 5;
5011 rates[i].hw_value = i; /* Rate scaling will work on indexes */
5012 rates[i].hw_value_short = i;
5013 rates[i].flags = 0;
5014 if ((i > IWL_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
Zhu Yib481de92007-09-25 17:54:57 -07005015 /*
Johannes Berg8318d782008-01-24 19:38:38 +01005016 * If CCK != 1M then set short preamble rate flag.
Zhu Yib481de92007-09-25 17:54:57 -07005017 */
Tomas Winkler35cdeaf2008-03-11 16:17:20 -07005018 rates[i].flags |=
5019 (iwl4965_rates[i].plcp == IWL_RATE_1M_PLCP) ?
5020 0 : IEEE80211_RATE_SHORT_PREAMBLE;
Zhu Yib481de92007-09-25 17:54:57 -07005021 }
Zhu Yib481de92007-09-25 17:54:57 -07005022 }
Zhu Yib481de92007-09-25 17:54:57 -07005023}
5024
5025/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005026 * iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom
Zhu Yib481de92007-09-25 17:54:57 -07005027 */
Assaf Kraussbf85ea42008-03-14 10:38:49 -07005028int iwl4965_init_geos(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005029{
Assaf Kraussbf85ea42008-03-14 10:38:49 -07005030 struct iwl_channel_info *ch;
Tomas Winkler8211ef72008-03-02 01:36:04 +02005031 struct ieee80211_supported_band *sband;
Zhu Yib481de92007-09-25 17:54:57 -07005032 struct ieee80211_channel *channels;
5033 struct ieee80211_channel *geo_ch;
5034 struct ieee80211_rate *rates;
5035 int i = 0;
Zhu Yib481de92007-09-25 17:54:57 -07005036
Johannes Berg8318d782008-01-24 19:38:38 +01005037 if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
5038 priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
Zhu Yib481de92007-09-25 17:54:57 -07005039 IWL_DEBUG_INFO("Geography modes already initialized.\n");
5040 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
5041 return 0;
5042 }
5043
Zhu Yib481de92007-09-25 17:54:57 -07005044 channels = kzalloc(sizeof(struct ieee80211_channel) *
5045 priv->channel_count, GFP_KERNEL);
Johannes Berg8318d782008-01-24 19:38:38 +01005046 if (!channels)
Zhu Yib481de92007-09-25 17:54:57 -07005047 return -ENOMEM;
Zhu Yib481de92007-09-25 17:54:57 -07005048
Tomas Winkler8211ef72008-03-02 01:36:04 +02005049 rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)),
Zhu Yib481de92007-09-25 17:54:57 -07005050 GFP_KERNEL);
5051 if (!rates) {
Zhu Yib481de92007-09-25 17:54:57 -07005052 kfree(channels);
5053 return -ENOMEM;
5054 }
5055
Zhu Yib481de92007-09-25 17:54:57 -07005056 /* 5.2GHz channels start after the 2.4GHz channels */
Tomas Winkler8211ef72008-03-02 01:36:04 +02005057 sband = &priv->bands[IEEE80211_BAND_5GHZ];
Assaf Kraussbf85ea42008-03-14 10:38:49 -07005058 sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
Tomas Winkler8211ef72008-03-02 01:36:04 +02005059 /* just OFDM */
5060 sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
5061 sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE;
Johannes Berg8318d782008-01-24 19:38:38 +01005062
Tomas Winkler8211ef72008-03-02 01:36:04 +02005063 iwl4965_init_ht_hw_capab(&sband->ht_info, IEEE80211_BAND_5GHZ);
Tomas Winkler78330fd2008-02-06 02:37:18 +02005064
Tomas Winkler8211ef72008-03-02 01:36:04 +02005065 sband = &priv->bands[IEEE80211_BAND_2GHZ];
5066 sband->channels = channels;
5067 /* OFDM & CCK */
5068 sband->bitrates = rates;
5069 sband->n_bitrates = IWL_RATE_COUNT;
Zhu Yib481de92007-09-25 17:54:57 -07005070
Tomas Winkler8211ef72008-03-02 01:36:04 +02005071 iwl4965_init_ht_hw_capab(&sband->ht_info, IEEE80211_BAND_2GHZ);
Tomas Winkler78330fd2008-02-06 02:37:18 +02005072
Zhu Yib481de92007-09-25 17:54:57 -07005073 priv->ieee_channels = channels;
5074 priv->ieee_rates = rates;
5075
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005076 iwl4965_init_hw_rates(priv, rates);
Zhu Yib481de92007-09-25 17:54:57 -07005077
Tomas Winkler8211ef72008-03-02 01:36:04 +02005078 for (i = 0; i < priv->channel_count; i++) {
Zhu Yib481de92007-09-25 17:54:57 -07005079 ch = &priv->channel_info[i];
5080
Tomas Winkler8211ef72008-03-02 01:36:04 +02005081 /* FIXME: might be removed if scan is OK */
5082 if (!is_channel_valid(ch))
Zhu Yib481de92007-09-25 17:54:57 -07005083 continue;
Zhu Yib481de92007-09-25 17:54:57 -07005084
Tomas Winkler8211ef72008-03-02 01:36:04 +02005085 if (is_channel_a_band(ch))
5086 sband = &priv->bands[IEEE80211_BAND_5GHZ];
5087 else
5088 sband = &priv->bands[IEEE80211_BAND_2GHZ];
Zhu Yib481de92007-09-25 17:54:57 -07005089
Tomas Winkler8211ef72008-03-02 01:36:04 +02005090 geo_ch = &sband->channels[sband->n_channels++];
5091
5092 geo_ch->center_freq = ieee80211_channel_to_frequency(ch->channel);
Johannes Berg8318d782008-01-24 19:38:38 +01005093 geo_ch->max_power = ch->max_power_avg;
5094 geo_ch->max_antenna_gain = 0xff;
Mohamed Abbas7b723042008-01-31 21:46:40 -08005095 geo_ch->hw_value = ch->channel;
Zhu Yib481de92007-09-25 17:54:57 -07005096
5097 if (is_channel_valid(ch)) {
Johannes Berg8318d782008-01-24 19:38:38 +01005098 if (!(ch->flags & EEPROM_CHANNEL_IBSS))
5099 geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
Zhu Yib481de92007-09-25 17:54:57 -07005100
Johannes Berg8318d782008-01-24 19:38:38 +01005101 if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
5102 geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
Zhu Yib481de92007-09-25 17:54:57 -07005103
5104 if (ch->flags & EEPROM_CHANNEL_RADAR)
Johannes Berg8318d782008-01-24 19:38:38 +01005105 geo_ch->flags |= IEEE80211_CHAN_RADAR;
Zhu Yib481de92007-09-25 17:54:57 -07005106
5107 if (ch->max_power_avg > priv->max_channel_txpower_limit)
5108 priv->max_channel_txpower_limit =
5109 ch->max_power_avg;
Tomas Winkler8211ef72008-03-02 01:36:04 +02005110 } else {
Johannes Berg8318d782008-01-24 19:38:38 +01005111 geo_ch->flags |= IEEE80211_CHAN_DISABLED;
Tomas Winkler8211ef72008-03-02 01:36:04 +02005112 }
5113
5114 /* Save flags for reg domain usage */
5115 geo_ch->orig_flags = geo_ch->flags;
5116
5117 IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n",
5118 ch->channel, geo_ch->center_freq,
5119 is_channel_a_band(ch) ? "5.2" : "2.4",
5120 geo_ch->flags & IEEE80211_CHAN_DISABLED ?
5121 "restricted" : "valid",
5122 geo_ch->flags);
Zhu Yib481de92007-09-25 17:54:57 -07005123 }
5124
Tomas Winkler82b9a122008-03-04 18:09:30 -08005125 if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
5126 priv->cfg->sku & IWL_SKU_A) {
Zhu Yib481de92007-09-25 17:54:57 -07005127 printk(KERN_INFO DRV_NAME
5128 ": Incorrectly detected BG card as ABG. Please send "
5129 "your PCI ID 0x%04X:0x%04X to maintainer.\n",
5130 priv->pci_dev->device, priv->pci_dev->subsystem_device);
Tomas Winkler82b9a122008-03-04 18:09:30 -08005131 priv->cfg->sku &= ~IWL_SKU_A;
Zhu Yib481de92007-09-25 17:54:57 -07005132 }
5133
5134 printk(KERN_INFO DRV_NAME
5135 ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
Johannes Berg8318d782008-01-24 19:38:38 +01005136 priv->bands[IEEE80211_BAND_2GHZ].n_channels,
5137 priv->bands[IEEE80211_BAND_5GHZ].n_channels);
Zhu Yib481de92007-09-25 17:54:57 -07005138
Johannes Berg8318d782008-01-24 19:38:38 +01005139 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->bands[IEEE80211_BAND_2GHZ];
5140 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->bands[IEEE80211_BAND_5GHZ];
Zhu Yib481de92007-09-25 17:54:57 -07005141
Zhu Yib481de92007-09-25 17:54:57 -07005142 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
5143
5144 return 0;
5145}
5146
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005147/*
5148 * iwl4965_free_geos - undo allocations in iwl4965_init_geos
5149 */
Assaf Kraussbf85ea42008-03-14 10:38:49 -07005150void iwl4965_free_geos(struct iwl_priv *priv)
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005151{
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005152 kfree(priv->ieee_channels);
5153 kfree(priv->ieee_rates);
5154 clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
5155}
5156
Zhu Yib481de92007-09-25 17:54:57 -07005157/******************************************************************************
5158 *
5159 * uCode download functions
5160 *
5161 ******************************************************************************/
5162
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005163static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005164{
Tomas Winkler98c92212008-01-14 17:46:20 -08005165 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
5166 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
5167 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
5168 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
5169 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
5170 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07005171}
5172
5173/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005174 * iwl4965_verify_inst_full - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07005175 * looking at all data.
5176 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005177static int iwl4965_verify_inst_full(struct iwl_priv *priv, __le32 *image,
Ben Cahill9fbab512007-11-29 11:09:47 +08005178 u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07005179{
5180 u32 val;
5181 u32 save_len = len;
5182 int rc = 0;
5183 u32 errcnt;
5184
5185 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
5186
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005187 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005188 if (rc)
5189 return rc;
5190
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005191 iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND);
Zhu Yib481de92007-09-25 17:54:57 -07005192
5193 errcnt = 0;
5194 for (; len > 0; len -= sizeof(u32), image++) {
5195 /* read data comes through single port, auto-incr addr */
5196 /* NOTE: Use the debugless read so we don't flood kernel log
5197 * if IWL_DL_IO is set */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005198 val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07005199 if (val != le32_to_cpu(*image)) {
5200 IWL_ERROR("uCode INST section is invalid at "
5201 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5202 save_len - len, val, le32_to_cpu(*image));
5203 rc = -EIO;
5204 errcnt++;
5205 if (errcnt >= 20)
5206 break;
5207 }
5208 }
5209
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005210 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005211
5212 if (!errcnt)
5213 IWL_DEBUG_INFO
5214 ("ucode image in INSTRUCTION memory is good\n");
5215
5216 return rc;
5217}
5218
5219
5220/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005221 * iwl4965_verify_inst_sparse - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07005222 * using sample data 100 bytes apart. If these sample points are good,
5223 * it's a pretty good bet that everything between them is good, too.
5224 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005225static int iwl4965_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07005226{
5227 u32 val;
5228 int rc = 0;
5229 u32 errcnt = 0;
5230 u32 i;
5231
5232 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
5233
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005234 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005235 if (rc)
5236 return rc;
5237
5238 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
5239 /* read data comes through single port, auto-incr addr */
5240 /* NOTE: Use the debugless read so we don't flood kernel log
5241 * if IWL_DL_IO is set */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005242 iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Zhu Yib481de92007-09-25 17:54:57 -07005243 i + RTC_INST_LOWER_BOUND);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005244 val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07005245 if (val != le32_to_cpu(*image)) {
5246#if 0 /* Enable this if you want to see details */
5247 IWL_ERROR("uCode INST section is invalid at "
5248 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5249 i, val, *image);
5250#endif
5251 rc = -EIO;
5252 errcnt++;
5253 if (errcnt >= 3)
5254 break;
5255 }
5256 }
5257
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005258 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005259
5260 return rc;
5261}
5262
5263
5264/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005265 * iwl4965_verify_ucode - determine which instruction image is in SRAM,
Zhu Yib481de92007-09-25 17:54:57 -07005266 * and verify its contents
5267 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005268static int iwl4965_verify_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005269{
5270 __le32 *image;
5271 u32 len;
5272 int rc = 0;
5273
5274 /* Try bootstrap */
5275 image = (__le32 *)priv->ucode_boot.v_addr;
5276 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005277 rc = iwl4965_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07005278 if (rc == 0) {
5279 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
5280 return 0;
5281 }
5282
5283 /* Try initialize */
5284 image = (__le32 *)priv->ucode_init.v_addr;
5285 len = priv->ucode_init.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005286 rc = iwl4965_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07005287 if (rc == 0) {
5288 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
5289 return 0;
5290 }
5291
5292 /* Try runtime/protocol */
5293 image = (__le32 *)priv->ucode_code.v_addr;
5294 len = priv->ucode_code.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005295 rc = iwl4965_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07005296 if (rc == 0) {
5297 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
5298 return 0;
5299 }
5300
5301 IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
5302
Ben Cahill9fbab512007-11-29 11:09:47 +08005303 /* Since nothing seems to match, show first several data entries in
5304 * instruction SRAM, so maybe visual inspection will give a clue.
5305 * Selection of bootstrap image (vs. other images) is arbitrary. */
Zhu Yib481de92007-09-25 17:54:57 -07005306 image = (__le32 *)priv->ucode_boot.v_addr;
5307 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005308 rc = iwl4965_verify_inst_full(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07005309
5310 return rc;
5311}
5312
5313
5314/* check contents of special bootstrap uCode SRAM */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005315static int iwl4965_verify_bsm(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005316{
5317 __le32 *image = priv->ucode_boot.v_addr;
5318 u32 len = priv->ucode_boot.len;
5319 u32 reg;
5320 u32 val;
5321
5322 IWL_DEBUG_INFO("Begin verify bsm\n");
5323
5324 /* verify BSM SRAM contents */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005325 val = iwl4965_read_prph(priv, BSM_WR_DWCOUNT_REG);
Zhu Yib481de92007-09-25 17:54:57 -07005326 for (reg = BSM_SRAM_LOWER_BOUND;
5327 reg < BSM_SRAM_LOWER_BOUND + len;
5328 reg += sizeof(u32), image ++) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005329 val = iwl4965_read_prph(priv, reg);
Zhu Yib481de92007-09-25 17:54:57 -07005330 if (val != le32_to_cpu(*image)) {
5331 IWL_ERROR("BSM uCode verification failed at "
5332 "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
5333 BSM_SRAM_LOWER_BOUND,
5334 reg - BSM_SRAM_LOWER_BOUND, len,
5335 val, le32_to_cpu(*image));
5336 return -EIO;
5337 }
5338 }
5339
5340 IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
5341
5342 return 0;
5343}
5344
5345/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005346 * iwl4965_load_bsm - Load bootstrap instructions
Zhu Yib481de92007-09-25 17:54:57 -07005347 *
5348 * BSM operation:
5349 *
5350 * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
5351 * in special SRAM that does not power down during RFKILL. When powering back
5352 * up after power-saving sleeps (or during initial uCode load), the BSM loads
5353 * the bootstrap program into the on-board processor, and starts it.
5354 *
5355 * The bootstrap program loads (via DMA) instructions and data for a new
5356 * program from host DRAM locations indicated by the host driver in the
5357 * BSM_DRAM_* registers. Once the new program is loaded, it starts
5358 * automatically.
5359 *
5360 * When initializing the NIC, the host driver points the BSM to the
5361 * "initialize" uCode image. This uCode sets up some internal data, then
5362 * notifies host via "initialize alive" that it is complete.
5363 *
5364 * The host then replaces the BSM_DRAM_* pointer values to point to the
5365 * normal runtime uCode instructions and a backup uCode data cache buffer
5366 * (filled initially with starting data values for the on-board processor),
5367 * then triggers the "initialize" uCode to load and launch the runtime uCode,
5368 * which begins normal operation.
5369 *
5370 * When doing a power-save shutdown, runtime uCode saves data SRAM into
5371 * the backup data cache in DRAM before SRAM is powered down.
5372 *
5373 * When powering back up, the BSM loads the bootstrap program. This reloads
5374 * the runtime uCode instructions and the backup data cache into SRAM,
5375 * and re-launches the runtime uCode from where it left off.
5376 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005377static int iwl4965_load_bsm(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005378{
5379 __le32 *image = priv->ucode_boot.v_addr;
5380 u32 len = priv->ucode_boot.len;
5381 dma_addr_t pinst;
5382 dma_addr_t pdata;
5383 u32 inst_len;
5384 u32 data_len;
5385 int rc;
5386 int i;
5387 u32 done;
5388 u32 reg_offset;
5389
5390 IWL_DEBUG_INFO("Begin load bsm\n");
5391
5392 /* make sure bootstrap program is no larger than BSM's SRAM size */
5393 if (len > IWL_MAX_BSM_SIZE)
5394 return -EINVAL;
5395
5396 /* Tell bootstrap uCode where to find the "Initialize" uCode
Ben Cahill9fbab512007-11-29 11:09:47 +08005397 * in host DRAM ... host DRAM physical address bits 35:4 for 4965.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005398 * NOTE: iwl4965_initialize_alive_start() will replace these values,
Zhu Yib481de92007-09-25 17:54:57 -07005399 * after the "initialize" uCode has run, to point to
5400 * runtime/protocol instructions and backup data cache. */
5401 pinst = priv->ucode_init.p_addr >> 4;
5402 pdata = priv->ucode_init_data.p_addr >> 4;
5403 inst_len = priv->ucode_init.len;
5404 data_len = priv->ucode_init_data.len;
5405
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005406 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005407 if (rc)
5408 return rc;
5409
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005410 iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
5411 iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
5412 iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
5413 iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
Zhu Yib481de92007-09-25 17:54:57 -07005414
5415 /* Fill BSM memory with bootstrap instructions */
5416 for (reg_offset = BSM_SRAM_LOWER_BOUND;
5417 reg_offset < BSM_SRAM_LOWER_BOUND + len;
5418 reg_offset += sizeof(u32), image++)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005419 _iwl4965_write_prph(priv, reg_offset,
Zhu Yib481de92007-09-25 17:54:57 -07005420 le32_to_cpu(*image));
5421
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005422 rc = iwl4965_verify_bsm(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005423 if (rc) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005424 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005425 return rc;
5426 }
5427
5428 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005429 iwl4965_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0);
5430 iwl4965_write_prph(priv, BSM_WR_MEM_DST_REG,
Zhu Yib481de92007-09-25 17:54:57 -07005431 RTC_INST_LOWER_BOUND);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005432 iwl4965_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07005433
5434 /* Load bootstrap code into instruction SRAM now,
5435 * to prepare to load "initialize" uCode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005436 iwl4965_write_prph(priv, BSM_WR_CTRL_REG,
Zhu Yib481de92007-09-25 17:54:57 -07005437 BSM_WR_CTRL_REG_BIT_START);
5438
5439 /* Wait for load of bootstrap uCode to finish */
5440 for (i = 0; i < 100; i++) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005441 done = iwl4965_read_prph(priv, BSM_WR_CTRL_REG);
Zhu Yib481de92007-09-25 17:54:57 -07005442 if (!(done & BSM_WR_CTRL_REG_BIT_START))
5443 break;
5444 udelay(10);
5445 }
5446 if (i < 100)
5447 IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i);
5448 else {
5449 IWL_ERROR("BSM write did not complete!\n");
5450 return -EIO;
5451 }
5452
5453 /* Enable future boot loads whenever power management unit triggers it
5454 * (e.g. when powering back up after power-save shutdown) */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005455 iwl4965_write_prph(priv, BSM_WR_CTRL_REG,
Zhu Yib481de92007-09-25 17:54:57 -07005456 BSM_WR_CTRL_REG_BIT_START_EN);
5457
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005458 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005459
5460 return 0;
5461}
5462
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005463static void iwl4965_nic_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005464{
5465 /* Remove all resets to allow NIC to operate */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005466 iwl4965_write32(priv, CSR_RESET, 0);
Zhu Yib481de92007-09-25 17:54:57 -07005467}
5468
Tomas Winkler90e759d2007-11-29 11:09:41 +08005469
Zhu Yib481de92007-09-25 17:54:57 -07005470/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005471 * iwl4965_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07005472 *
5473 * Copy into buffers for card to fetch via bus-mastering
5474 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005475static int iwl4965_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005476{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005477 struct iwl4965_ucode *ucode;
Tomas Winkler90e759d2007-11-29 11:09:41 +08005478 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07005479 const struct firmware *ucode_raw;
Tomas Winkler4bf775c2008-03-04 18:09:31 -08005480 const char *name = priv->cfg->fw_name;
Zhu Yib481de92007-09-25 17:54:57 -07005481 u8 *src;
5482 size_t len;
5483 u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
5484
5485 /* Ask kernel firmware_class module to get the boot firmware off disk.
5486 * request_firmware() is synchronous, file is in memory on return. */
Tomas Winkler90e759d2007-11-29 11:09:41 +08005487 ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
5488 if (ret < 0) {
5489 IWL_ERROR("%s firmware file req failed: Reason %d\n",
5490 name, ret);
Zhu Yib481de92007-09-25 17:54:57 -07005491 goto error;
5492 }
5493
5494 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
5495 name, ucode_raw->size);
5496
5497 /* Make sure that we got at least our header! */
5498 if (ucode_raw->size < sizeof(*ucode)) {
5499 IWL_ERROR("File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08005500 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07005501 goto err_release;
5502 }
5503
5504 /* Data from ucode file: header followed by uCode images */
5505 ucode = (void *)ucode_raw->data;
5506
5507 ver = le32_to_cpu(ucode->ver);
5508 inst_size = le32_to_cpu(ucode->inst_size);
5509 data_size = le32_to_cpu(ucode->data_size);
5510 init_size = le32_to_cpu(ucode->init_size);
5511 init_data_size = le32_to_cpu(ucode->init_data_size);
5512 boot_size = le32_to_cpu(ucode->boot_size);
5513
5514 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
5515 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
5516 inst_size);
5517 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
5518 data_size);
5519 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
5520 init_size);
5521 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
5522 init_data_size);
5523 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
5524 boot_size);
5525
5526 /* Verify size of file vs. image size info in file's header */
5527 if (ucode_raw->size < sizeof(*ucode) +
5528 inst_size + data_size + init_size +
5529 init_data_size + boot_size) {
5530
5531 IWL_DEBUG_INFO("uCode file size %d too small\n",
5532 (int)ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08005533 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07005534 goto err_release;
5535 }
5536
5537 /* Verify that uCode images will fit in card's SRAM */
5538 if (inst_size > IWL_MAX_INST_SIZE) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08005539 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
5540 inst_size);
5541 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07005542 goto err_release;
5543 }
5544
5545 if (data_size > IWL_MAX_DATA_SIZE) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08005546 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
5547 data_size);
5548 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07005549 goto err_release;
5550 }
5551 if (init_size > IWL_MAX_INST_SIZE) {
5552 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08005553 ("uCode init instr len %d too large to fit in\n",
5554 init_size);
5555 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07005556 goto err_release;
5557 }
5558 if (init_data_size > IWL_MAX_DATA_SIZE) {
5559 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08005560 ("uCode init data len %d too large to fit in\n",
5561 init_data_size);
5562 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07005563 goto err_release;
5564 }
5565 if (boot_size > IWL_MAX_BSM_SIZE) {
5566 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08005567 ("uCode boot instr len %d too large to fit in\n",
5568 boot_size);
5569 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07005570 goto err_release;
5571 }
5572
5573 /* Allocate ucode buffers for card's bus-master loading ... */
5574
5575 /* Runtime instructions and 2 copies of data:
5576 * 1) unmodified from disk
5577 * 2) backup cache for save/restore during power-downs */
5578 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08005579 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07005580
5581 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08005582 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07005583
5584 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08005585 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07005586
5587 /* Initialization instructions and data */
Tomas Winkler90e759d2007-11-29 11:09:41 +08005588 if (init_size && init_data_size) {
5589 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08005590 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Zhu Yib481de92007-09-25 17:54:57 -07005591
Tomas Winkler90e759d2007-11-29 11:09:41 +08005592 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08005593 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08005594
5595 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
5596 goto err_pci_alloc;
5597 }
Zhu Yib481de92007-09-25 17:54:57 -07005598
5599 /* Bootstrap (instructions only, no data) */
Tomas Winkler90e759d2007-11-29 11:09:41 +08005600 if (boot_size) {
5601 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08005602 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07005603
Tomas Winkler90e759d2007-11-29 11:09:41 +08005604 if (!priv->ucode_boot.v_addr)
5605 goto err_pci_alloc;
5606 }
Zhu Yib481de92007-09-25 17:54:57 -07005607
5608 /* Copy images into buffers for card's bus-master reads ... */
5609
5610 /* Runtime instructions (first block of data in file) */
5611 src = &ucode->data[0];
5612 len = priv->ucode_code.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08005613 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07005614 memcpy(priv->ucode_code.v_addr, src, len);
5615 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
5616 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
5617
5618 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005619 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
Zhu Yib481de92007-09-25 17:54:57 -07005620 src = &ucode->data[inst_size];
5621 len = priv->ucode_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08005622 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07005623 memcpy(priv->ucode_data.v_addr, src, len);
5624 memcpy(priv->ucode_data_backup.v_addr, src, len);
5625
5626 /* Initialization instructions (3rd block) */
5627 if (init_size) {
5628 src = &ucode->data[inst_size + data_size];
5629 len = priv->ucode_init.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08005630 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
5631 len);
Zhu Yib481de92007-09-25 17:54:57 -07005632 memcpy(priv->ucode_init.v_addr, src, len);
5633 }
5634
5635 /* Initialization data (4th block) */
5636 if (init_data_size) {
5637 src = &ucode->data[inst_size + data_size + init_size];
5638 len = priv->ucode_init_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08005639 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
5640 len);
Zhu Yib481de92007-09-25 17:54:57 -07005641 memcpy(priv->ucode_init_data.v_addr, src, len);
5642 }
5643
5644 /* Bootstrap instructions (5th block) */
5645 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
5646 len = priv->ucode_boot.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08005647 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07005648 memcpy(priv->ucode_boot.v_addr, src, len);
5649
5650 /* We have our copies now, allow OS release its copies */
5651 release_firmware(ucode_raw);
5652 return 0;
5653
5654 err_pci_alloc:
5655 IWL_ERROR("failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08005656 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005657 iwl4965_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005658
5659 err_release:
5660 release_firmware(ucode_raw);
5661
5662 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08005663 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07005664}
5665
5666
5667/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005668 * iwl4965_set_ucode_ptrs - Set uCode address location
Zhu Yib481de92007-09-25 17:54:57 -07005669 *
5670 * Tell initialization uCode where to find runtime uCode.
5671 *
5672 * BSM registers initially contain pointers to initialization uCode.
5673 * We need to replace them to load runtime uCode inst and data,
5674 * and to save runtime data when powering down.
5675 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005676static int iwl4965_set_ucode_ptrs(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005677{
5678 dma_addr_t pinst;
5679 dma_addr_t pdata;
5680 int rc = 0;
5681 unsigned long flags;
5682
5683 /* bits 35:4 for 4965 */
5684 pinst = priv->ucode_code.p_addr >> 4;
5685 pdata = priv->ucode_data_backup.p_addr >> 4;
5686
5687 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005688 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005689 if (rc) {
5690 spin_unlock_irqrestore(&priv->lock, flags);
5691 return rc;
5692 }
5693
5694 /* Tell bootstrap uCode where to find image to load */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005695 iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
5696 iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
5697 iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07005698 priv->ucode_data.len);
5699
5700 /* Inst bytecount must be last to set up, bit 31 signals uCode
5701 * that all new ptr/size info is in place */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005702 iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07005703 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
5704
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005705 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005706
5707 spin_unlock_irqrestore(&priv->lock, flags);
5708
5709 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
5710
5711 return rc;
5712}
5713
5714/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005715 * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07005716 *
5717 * Called after REPLY_ALIVE notification received from "initialize" uCode.
5718 *
5719 * The 4965 "initialize" ALIVE reply contains calibration data for:
5720 * Voltage, temperature, and MIMO tx gain correction, now stored in priv
5721 * (3945 does not contain this data).
5722 *
5723 * Tell "initialize" uCode to go ahead and load the runtime uCode.
5724*/
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005725static void iwl4965_init_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005726{
5727 /* Check alive response for "valid" sign from uCode */
5728 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
5729 /* We had an error bringing up the hardware, so take it
5730 * all the way back down so we can try again */
5731 IWL_DEBUG_INFO("Initialize Alive failed.\n");
5732 goto restart;
5733 }
5734
5735 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
5736 * This is a paranoid check, because we would not have gotten the
5737 * "initialize" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005738 if (iwl4965_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005739 /* Runtime instruction load was bad;
5740 * take it all the way back down so we can try again */
5741 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
5742 goto restart;
5743 }
5744
5745 /* Calculate temperature */
5746 priv->temperature = iwl4965_get_temperature(priv);
5747
5748 /* Send pointers to protocol/runtime uCode image ... init code will
5749 * load and launch runtime uCode, which will send us another "Alive"
5750 * notification. */
5751 IWL_DEBUG_INFO("Initialization Alive received.\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005752 if (iwl4965_set_ucode_ptrs(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005753 /* Runtime instruction load won't happen;
5754 * take it all the way back down so we can try again */
5755 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
5756 goto restart;
5757 }
5758 return;
5759
5760 restart:
5761 queue_work(priv->workqueue, &priv->restart);
5762}
5763
5764
5765/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005766 * iwl4965_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07005767 * from protocol/runtime uCode (initialization uCode's
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005768 * Alive gets handled by iwl4965_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07005769 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005770static void iwl4965_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005771{
5772 int rc = 0;
5773
5774 IWL_DEBUG_INFO("Runtime Alive received.\n");
5775
5776 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
5777 /* We had an error bringing up the hardware, so take it
5778 * all the way back down so we can try again */
5779 IWL_DEBUG_INFO("Alive failed.\n");
5780 goto restart;
5781 }
5782
5783 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
5784 * This is a paranoid check, because we would not have gotten the
5785 * "runtime" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005786 if (iwl4965_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005787 /* Runtime instruction load was bad;
5788 * take it all the way back down so we can try again */
5789 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
5790 goto restart;
5791 }
5792
Assaf Kraussbf85ea42008-03-14 10:38:49 -07005793 iwlcore_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005794
5795 rc = iwl4965_alive_notify(priv);
5796 if (rc) {
5797 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
5798 rc);
5799 goto restart;
5800 }
5801
Ben Cahill9fbab512007-11-29 11:09:47 +08005802 /* After the ALIVE response, we can send host commands to 4965 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07005803 set_bit(STATUS_ALIVE, &priv->status);
5804
5805 /* Clear out the uCode error bit if it is set */
5806 clear_bit(STATUS_FW_ERROR, &priv->status);
5807
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005808 if (iwl4965_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07005809 return;
5810
Zhu Yi5a66926a2008-01-14 17:46:18 -08005811 ieee80211_start_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07005812
5813 priv->active_rate = priv->rates_mask;
5814 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
5815
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005816 iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode));
Zhu Yib481de92007-09-25 17:54:57 -07005817
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005818 if (iwl4965_is_associated(priv)) {
5819 struct iwl4965_rxon_cmd *active_rxon =
5820 (struct iwl4965_rxon_cmd *)(&priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07005821
5822 memcpy(&priv->staging_rxon, &priv->active_rxon,
5823 sizeof(priv->staging_rxon));
5824 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
5825 } else {
5826 /* Initialize our rx_config data */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005827 iwl4965_connection_init_rx_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005828 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
5829 }
5830
Ben Cahill9fbab512007-11-29 11:09:47 +08005831 /* Configure Bluetooth device coexistence support */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005832 iwl4965_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005833
5834 /* Configure the adapter for unassociated operation */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005835 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005836
5837 /* At this point, the NIC is initialized and operational */
5838 priv->notif_missed_beacons = 0;
5839 set_bit(STATUS_READY, &priv->status);
5840
5841 iwl4965_rf_kill_ct_config(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08005842
Zhu Yib481de92007-09-25 17:54:57 -07005843 IWL_DEBUG_INFO("ALIVE processing complete.\n");
Zhu Yi5a66926a2008-01-14 17:46:18 -08005844 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07005845
5846 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005847 iwl4965_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005848
5849 return;
5850
5851 restart:
5852 queue_work(priv->workqueue, &priv->restart);
5853}
5854
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005855static void iwl4965_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07005856
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005857static void __iwl4965_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005858{
5859 unsigned long flags;
5860 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
5861 struct ieee80211_conf *conf = NULL;
5862
5863 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
5864
5865 conf = ieee80211_get_hw_conf(priv->hw);
5866
5867 if (!exit_pending)
5868 set_bit(STATUS_EXIT_PENDING, &priv->status);
5869
Assaf Kraussbf85ea42008-03-14 10:38:49 -07005870 iwlcore_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005871
5872 /* Unblock any waiting calls */
5873 wake_up_interruptible_all(&priv->wait_command_queue);
5874
Zhu Yib481de92007-09-25 17:54:57 -07005875 /* Wipe out the EXIT_PENDING status bit if we are not actually
5876 * exiting the module */
5877 if (!exit_pending)
5878 clear_bit(STATUS_EXIT_PENDING, &priv->status);
5879
5880 /* stop and reset the on-board processor */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005881 iwl4965_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07005882
5883 /* tell the device to stop sending interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005884 iwl4965_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005885
5886 if (priv->mac80211_registered)
5887 ieee80211_stop_queues(priv->hw);
5888
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005889 /* If we have not previously called iwl4965_init() then
Zhu Yib481de92007-09-25 17:54:57 -07005890 * clear all bits but the RF Kill and SUSPEND bits and return */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005891 if (!iwl4965_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005892 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
5893 STATUS_RF_KILL_HW |
5894 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
5895 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08005896 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
5897 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07005898 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
5899 STATUS_IN_SUSPEND;
5900 goto exit;
5901 }
5902
5903 /* ...otherwise clear out all the status bits but the RF Kill and
5904 * SUSPEND bits and continue taking the NIC down. */
5905 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
5906 STATUS_RF_KILL_HW |
5907 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
5908 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08005909 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
5910 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07005911 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
5912 STATUS_IN_SUSPEND |
5913 test_bit(STATUS_FW_ERROR, &priv->status) <<
5914 STATUS_FW_ERROR;
5915
5916 spin_lock_irqsave(&priv->lock, flags);
Ben Cahill9fbab512007-11-29 11:09:47 +08005917 iwl4965_clear_bit(priv, CSR_GP_CNTRL,
5918 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07005919 spin_unlock_irqrestore(&priv->lock, flags);
5920
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005921 iwl4965_hw_txq_ctx_stop(priv);
5922 iwl4965_hw_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005923
5924 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005925 if (!iwl4965_grab_nic_access(priv)) {
5926 iwl4965_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07005927 APMG_CLK_VAL_DMA_CLK_RQT);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005928 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005929 }
5930 spin_unlock_irqrestore(&priv->lock, flags);
5931
5932 udelay(5);
5933
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005934 iwl4965_hw_nic_stop_master(priv);
5935 iwl4965_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
5936 iwl4965_hw_nic_reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005937
5938 exit:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005939 memset(&priv->card_alive, 0, sizeof(struct iwl4965_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07005940
5941 if (priv->ibss_beacon)
5942 dev_kfree_skb(priv->ibss_beacon);
5943 priv->ibss_beacon = NULL;
5944
5945 /* clear out any free frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005946 iwl4965_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005947}
5948
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005949static void iwl4965_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005950{
5951 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005952 __iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005953 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08005954
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005955 iwl4965_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005956}
5957
5958#define MAX_HW_RESTARTS 5
5959
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07005960static int __iwl4965_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005961{
5962 int rc, i;
Zhu Yib481de92007-09-25 17:54:57 -07005963
5964 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
5965 IWL_WARNING("Exit pending; will not bring the NIC up\n");
5966 return -EIO;
5967 }
5968
5969 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
5970 IWL_WARNING("Radio disabled by SW RF kill (module "
5971 "parameter)\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08005972 return -ENODEV;
5973 }
5974
Reinette Chatree903fbd2008-01-30 22:05:15 -08005975 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
5976 IWL_ERROR("ucode not available for device bringup\n");
5977 return -EIO;
5978 }
5979
Zhu Yie655b9f2008-01-24 02:19:38 -08005980 /* If platform's RF_KILL switch is NOT set to KILL */
5981 if (iwl4965_read32(priv, CSR_GP_CNTRL) &
5982 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
5983 clear_bit(STATUS_RF_KILL_HW, &priv->status);
5984 else {
5985 set_bit(STATUS_RF_KILL_HW, &priv->status);
5986 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
5987 IWL_WARNING("Radio disabled by HW RF Kill switch\n");
5988 return -ENODEV;
5989 }
Zhu Yib481de92007-09-25 17:54:57 -07005990 }
5991
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005992 iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07005993
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005994 rc = iwl4965_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005995 if (rc) {
5996 IWL_ERROR("Unable to int nic\n");
5997 return rc;
5998 }
5999
6000 /* make sure rfkill handshake bits are cleared */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006001 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
6002 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07006003 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
6004
6005 /* clear (again), then enable host interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006006 iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF);
6007 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006008
6009 /* really make sure rfkill handshake bits are cleared */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006010 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
6011 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07006012
6013 /* Copy original ucode data image from disk into backup cache.
6014 * This will be used to initialize the on-board processor's
6015 * data SRAM for a clean start when the runtime program first loads. */
6016 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a66926a2008-01-14 17:46:18 -08006017 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07006018
Zhu Yie655b9f2008-01-24 02:19:38 -08006019 /* We return success when we resume from suspend and rf_kill is on. */
6020 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07006021 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07006022
6023 for (i = 0; i < MAX_HW_RESTARTS; i++) {
6024
Assaf Kraussbf85ea42008-03-14 10:38:49 -07006025 iwlcore_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006026
6027 /* load bootstrap state machine,
6028 * load bootstrap program into processor's memory,
6029 * prepare to load the "initialize" uCode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006030 rc = iwl4965_load_bsm(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006031
6032 if (rc) {
6033 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc);
6034 continue;
6035 }
6036
6037 /* start card; "initialize" will load runtime ucode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006038 iwl4965_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006039
Zhu Yib481de92007-09-25 17:54:57 -07006040 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
6041
6042 return 0;
6043 }
6044
6045 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006046 __iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006047
6048 /* tried to restart and config the device for as long as our
6049 * patience could withstand */
6050 IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
6051 return -EIO;
6052}
6053
6054
6055/*****************************************************************************
6056 *
6057 * Workqueue callbacks
6058 *
6059 *****************************************************************************/
6060
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006061static void iwl4965_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07006062{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07006063 struct iwl_priv *priv =
6064 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07006065
6066 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6067 return;
6068
6069 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006070 iwl4965_init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006071 mutex_unlock(&priv->mutex);
6072}
6073
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006074static void iwl4965_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07006075{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07006076 struct iwl_priv *priv =
6077 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07006078
6079 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6080 return;
6081
6082 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006083 iwl4965_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006084 mutex_unlock(&priv->mutex);
6085}
6086
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006087static void iwl4965_bg_rf_kill(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07006088{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07006089 struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill);
Zhu Yib481de92007-09-25 17:54:57 -07006090
6091 wake_up_interruptible(&priv->wait_command_queue);
6092
6093 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6094 return;
6095
6096 mutex_lock(&priv->mutex);
6097
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006098 if (!iwl4965_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006099 IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL,
6100 "HW and/or SW RF Kill no longer active, restarting "
6101 "device\n");
6102 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
6103 queue_work(priv->workqueue, &priv->restart);
6104 } else {
6105
6106 if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
6107 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
6108 "disabled by SW switch\n");
6109 else
6110 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
6111 "Kill switch must be turned off for "
6112 "wireless networking to work.\n");
6113 }
6114 mutex_unlock(&priv->mutex);
6115}
6116
6117#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
6118
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006119static void iwl4965_bg_scan_check(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07006120{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07006121 struct iwl_priv *priv =
6122 container_of(data, struct iwl_priv, scan_check.work);
Zhu Yib481de92007-09-25 17:54:57 -07006123
6124 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6125 return;
6126
6127 mutex_lock(&priv->mutex);
6128 if (test_bit(STATUS_SCANNING, &priv->status) ||
6129 test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
6130 IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN,
6131 "Scan completion watchdog resetting adapter (%dms)\n",
6132 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG));
mabbas052c4b92007-10-25 17:15:43 +08006133
Zhu Yib481de92007-09-25 17:54:57 -07006134 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006135 iwl4965_send_scan_abort(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006136 }
6137 mutex_unlock(&priv->mutex);
6138}
6139
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006140static void iwl4965_bg_request_scan(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07006141{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07006142 struct iwl_priv *priv =
6143 container_of(data, struct iwl_priv, request_scan);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006144 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07006145 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006146 .len = sizeof(struct iwl4965_scan_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07006147 .meta.flags = CMD_SIZE_HUGE,
6148 };
6149 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006150 struct iwl4965_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07006151 struct ieee80211_conf *conf = NULL;
Tomas Winkler78330fd2008-02-06 02:37:18 +02006152 u16 cmd_len;
Johannes Berg8318d782008-01-24 19:38:38 +01006153 enum ieee80211_band band;
Tomas Winkler78330fd2008-02-06 02:37:18 +02006154 u8 direct_mask;
Zhu Yib481de92007-09-25 17:54:57 -07006155
6156 conf = ieee80211_get_hw_conf(priv->hw);
6157
6158 mutex_lock(&priv->mutex);
6159
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006160 if (!iwl4965_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006161 IWL_WARNING("request scan called when driver not ready.\n");
6162 goto done;
6163 }
6164
6165 /* Make sure the scan wasn't cancelled before this queued work
6166 * was given the chance to run... */
6167 if (!test_bit(STATUS_SCANNING, &priv->status))
6168 goto done;
6169
6170 /* This should never be called or scheduled if there is currently
6171 * a scan active in the hardware. */
6172 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
6173 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
6174 "Ignoring second request.\n");
6175 rc = -EIO;
6176 goto done;
6177 }
6178
6179 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
6180 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
6181 goto done;
6182 }
6183
6184 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
6185 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6186 goto done;
6187 }
6188
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006189 if (iwl4965_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006190 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6191 goto done;
6192 }
6193
6194 if (!test_bit(STATUS_READY, &priv->status)) {
6195 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
6196 goto done;
6197 }
6198
6199 if (!priv->scan_bands) {
6200 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
6201 goto done;
6202 }
6203
6204 if (!priv->scan) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006205 priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) +
Zhu Yib481de92007-09-25 17:54:57 -07006206 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
6207 if (!priv->scan) {
6208 rc = -ENOMEM;
6209 goto done;
6210 }
6211 }
6212 scan = priv->scan;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006213 memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07006214
6215 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
6216 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
6217
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006218 if (iwl4965_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006219 u16 interval = 0;
6220 u32 extra;
6221 u32 suspend_time = 100;
6222 u32 scan_suspend_time = 100;
6223 unsigned long flags;
6224
6225 IWL_DEBUG_INFO("Scanning while associated...\n");
6226
6227 spin_lock_irqsave(&priv->lock, flags);
6228 interval = priv->beacon_int;
6229 spin_unlock_irqrestore(&priv->lock, flags);
6230
6231 scan->suspend_time = 0;
mabbas052c4b92007-10-25 17:15:43 +08006232 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07006233 if (!interval)
6234 interval = suspend_time;
6235
6236 extra = (suspend_time / interval) << 22;
6237 scan_suspend_time = (extra |
6238 ((suspend_time % interval) * 1024));
6239 scan->suspend_time = cpu_to_le32(scan_suspend_time);
6240 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
6241 scan_suspend_time, interval);
6242 }
6243
6244 /* We should add the ability for user to lock to PASSIVE ONLY */
6245 if (priv->one_direct_scan) {
6246 IWL_DEBUG_SCAN
6247 ("Kicking off one direct scan for '%s'\n",
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006248 iwl4965_escape_essid(priv->direct_ssid,
Zhu Yib481de92007-09-25 17:54:57 -07006249 priv->direct_ssid_len));
6250 scan->direct_scan[0].id = WLAN_EID_SSID;
6251 scan->direct_scan[0].len = priv->direct_ssid_len;
6252 memcpy(scan->direct_scan[0].ssid,
6253 priv->direct_ssid, priv->direct_ssid_len);
6254 direct_mask = 1;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006255 } else if (!iwl4965_is_associated(priv) && priv->essid_len) {
Zhu Yib481de92007-09-25 17:54:57 -07006256 scan->direct_scan[0].id = WLAN_EID_SSID;
6257 scan->direct_scan[0].len = priv->essid_len;
6258 memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
6259 direct_mask = 1;
6260 } else
6261 direct_mask = 0;
6262
Zhu Yib481de92007-09-25 17:54:57 -07006263 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
6264 scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id;
6265 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
6266
Zhu Yib481de92007-09-25 17:54:57 -07006267
6268 switch (priv->scan_bands) {
6269 case 2:
6270 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
6271 scan->tx_cmd.rate_n_flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006272 iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP,
Zhu Yib481de92007-09-25 17:54:57 -07006273 RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK);
6274
6275 scan->good_CRC_th = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01006276 band = IEEE80211_BAND_2GHZ;
Zhu Yib481de92007-09-25 17:54:57 -07006277 break;
6278
6279 case 1:
6280 scan->tx_cmd.rate_n_flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006281 iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP,
Zhu Yib481de92007-09-25 17:54:57 -07006282 RATE_MCS_ANT_B_MSK);
6283 scan->good_CRC_th = IWL_GOOD_CRC_TH;
Johannes Berg8318d782008-01-24 19:38:38 +01006284 band = IEEE80211_BAND_5GHZ;
Zhu Yib481de92007-09-25 17:54:57 -07006285 break;
6286
6287 default:
6288 IWL_WARNING("Invalid scan band count\n");
6289 goto done;
6290 }
6291
Tomas Winkler78330fd2008-02-06 02:37:18 +02006292 /* We don't build a direct scan probe request; the uCode will do
6293 * that based on the direct_mask added to each channel entry */
6294 cmd_len = iwl4965_fill_probe_req(priv, band,
6295 (struct ieee80211_mgmt *)scan->data,
6296 IWL_MAX_SCAN_SIZE - sizeof(*scan), 0);
6297
6298 scan->tx_cmd.len = cpu_to_le16(cmd_len);
Zhu Yib481de92007-09-25 17:54:57 -07006299 /* select Rx chains */
6300
6301 /* Force use of chains B and C (0x6) for scan Rx.
6302 * Avoid A (0x1) because of its off-channel reception on A-band.
6303 * MIMO is not used here, but value is required to make uCode happy. */
6304 scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK |
6305 cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) |
6306 (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) |
6307 (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS));
6308
6309 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR)
6310 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
6311
Reinette Chatre26c0f032008-03-11 16:17:15 -07006312 if (direct_mask) {
Zhu Yib481de92007-09-25 17:54:57 -07006313 IWL_DEBUG_SCAN
6314 ("Initiating direct scan for %s.\n",
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006315 iwl4965_escape_essid(priv->essid, priv->essid_len));
Reinette Chatre26c0f032008-03-11 16:17:15 -07006316 scan->channel_count =
6317 iwl4965_get_channels_for_scan(
6318 priv, band, 1, /* active */
6319 direct_mask,
6320 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
6321 } else {
Zhu Yib481de92007-09-25 17:54:57 -07006322 IWL_DEBUG_SCAN("Initiating indirect scan.\n");
Reinette Chatre26c0f032008-03-11 16:17:15 -07006323 scan->channel_count =
6324 iwl4965_get_channels_for_scan(
6325 priv, band, 0, /* passive */
6326 direct_mask,
6327 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
6328 }
Zhu Yib481de92007-09-25 17:54:57 -07006329
6330 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006331 scan->channel_count * sizeof(struct iwl4965_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07006332 cmd.data = scan;
6333 scan->len = cpu_to_le16(cmd.len);
6334
6335 set_bit(STATUS_SCAN_HW, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006336 rc = iwl4965_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07006337 if (rc)
6338 goto done;
6339
6340 queue_delayed_work(priv->workqueue, &priv->scan_check,
6341 IWL_SCAN_CHECK_WATCHDOG);
6342
6343 mutex_unlock(&priv->mutex);
6344 return;
6345
6346 done:
Ian Schram01ebd062007-10-25 17:15:22 +08006347 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07006348 queue_work(priv->workqueue, &priv->scan_completed);
6349 mutex_unlock(&priv->mutex);
6350}
6351
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006352static void iwl4965_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07006353{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07006354 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07006355
6356 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6357 return;
6358
6359 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006360 __iwl4965_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006361 mutex_unlock(&priv->mutex);
6362}
6363
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006364static void iwl4965_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07006365{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07006366 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07006367
6368 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6369 return;
6370
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006371 iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006372 queue_work(priv->workqueue, &priv->up);
6373}
6374
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006375static void iwl4965_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07006376{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07006377 struct iwl_priv *priv =
6378 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07006379
6380 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6381 return;
6382
6383 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006384 iwl4965_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006385 mutex_unlock(&priv->mutex);
6386}
6387
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08006388#define IWL_DELAY_NEXT_SCAN (HZ*2)
6389
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006390static void iwl4965_bg_post_associate(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07006391{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07006392 struct iwl_priv *priv = container_of(data, struct iwl_priv,
Zhu Yib481de92007-09-25 17:54:57 -07006393 post_associate.work);
6394
6395 int rc = 0;
6396 struct ieee80211_conf *conf = NULL;
Joe Perches0795af52007-10-03 17:59:30 -07006397 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07006398
6399 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
6400 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__);
6401 return;
6402 }
6403
Joe Perches0795af52007-10-03 17:59:30 -07006404 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
6405 priv->assoc_id,
6406 print_mac(mac, priv->active_rxon.bssid_addr));
Zhu Yib481de92007-09-25 17:54:57 -07006407
6408
6409 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6410 return;
6411
6412 mutex_lock(&priv->mutex);
6413
Johannes Berg32bfd352007-12-19 01:31:26 +01006414 if (!priv->vif || !priv->is_open) {
Mohamed Abbas948c1712007-10-25 17:15:45 +08006415 mutex_unlock(&priv->mutex);
6416 return;
6417 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006418 iwl4965_scan_cancel_timeout(priv, 200);
mabbas052c4b92007-10-25 17:15:43 +08006419
Zhu Yib481de92007-09-25 17:54:57 -07006420 conf = ieee80211_get_hw_conf(priv->hw);
6421
6422 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006423 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006424
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006425 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
6426 iwl4965_setup_rxon_timing(priv);
6427 rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07006428 sizeof(priv->rxon_timing), &priv->rxon_timing);
6429 if (rc)
6430 IWL_WARNING("REPLY_RXON_TIMING failed - "
6431 "Attempting to continue.\n");
6432
6433 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
6434
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08006435#ifdef CONFIG_IWL4965_HT
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02006436 if (priv->current_ht_config.is_ht)
6437 iwl4965_set_rxon_ht(priv, &priv->current_ht_config);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08006438#endif /* CONFIG_IWL4965_HT*/
Zhu Yib481de92007-09-25 17:54:57 -07006439 iwl4965_set_rxon_chain(priv);
6440 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
6441
6442 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
6443 priv->assoc_id, priv->beacon_int);
6444
6445 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
6446 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
6447 else
6448 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
6449
6450 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
6451 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
6452 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
6453 else
6454 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
6455
6456 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
6457 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
6458
6459 }
6460
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006461 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006462
6463 switch (priv->iw_mode) {
6464 case IEEE80211_IF_TYPE_STA:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006465 iwl4965_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07006466 break;
6467
6468 case IEEE80211_IF_TYPE_IBSS:
6469
6470 /* clear out the station table */
Assaf Kraussbf85ea42008-03-14 10:38:49 -07006471 iwlcore_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006472
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006473 iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0);
6474 iwl4965_rxon_add_station(priv, priv->bssid, 0);
6475 iwl4965_rate_scale_init(priv->hw, IWL_STA_ID);
6476 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006477
6478 break;
6479
6480 default:
6481 IWL_ERROR("%s Should not be called in %d mode\n",
6482 __FUNCTION__, priv->iw_mode);
6483 break;
6484 }
6485
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006486 iwl4965_sequence_reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006487
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08006488#ifdef CONFIG_IWL4965_SENSITIVITY
Zhu Yib481de92007-09-25 17:54:57 -07006489 /* Enable Rx differential gain and sensitivity calibrations */
6490 iwl4965_chain_noise_reset(priv);
6491 priv->start_calib = 1;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08006492#endif /* CONFIG_IWL4965_SENSITIVITY */
Zhu Yib481de92007-09-25 17:54:57 -07006493
6494 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
6495 priv->assoc_station_added = 1;
6496
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006497 iwl4965_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08006498
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08006499 /* we have just associated, don't start scan too early */
6500 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Zhu Yib481de92007-09-25 17:54:57 -07006501 mutex_unlock(&priv->mutex);
6502}
6503
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006504static void iwl4965_bg_abort_scan(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07006505{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07006506 struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan);
Zhu Yib481de92007-09-25 17:54:57 -07006507
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006508 if (!iwl4965_is_ready(priv))
Zhu Yib481de92007-09-25 17:54:57 -07006509 return;
6510
6511 mutex_lock(&priv->mutex);
6512
6513 set_bit(STATUS_SCAN_ABORTING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006514 iwl4965_send_scan_abort(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006515
6516 mutex_unlock(&priv->mutex);
6517}
6518
Zhu Yi76bb77e2007-11-22 10:53:22 +08006519static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
6520
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006521static void iwl4965_bg_scan_completed(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07006522{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07006523 struct iwl_priv *priv =
6524 container_of(work, struct iwl_priv, scan_completed);
Zhu Yib481de92007-09-25 17:54:57 -07006525
6526 IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n");
6527
6528 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6529 return;
6530
Zhu Yia0646472007-12-20 14:10:01 +08006531 if (test_bit(STATUS_CONF_PENDING, &priv->status))
6532 iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw));
Zhu Yi76bb77e2007-11-22 10:53:22 +08006533
Zhu Yib481de92007-09-25 17:54:57 -07006534 ieee80211_scan_completed(priv->hw);
6535
6536 /* Since setting the TXPOWER may have been deferred while
6537 * performing the scan, fire one off */
6538 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006539 iwl4965_hw_reg_send_txpower(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006540 mutex_unlock(&priv->mutex);
6541}
6542
6543/*****************************************************************************
6544 *
6545 * mac80211 entry point functions
6546 *
6547 *****************************************************************************/
6548
Zhu Yi5a66926a2008-01-14 17:46:18 -08006549#define UCODE_READY_TIMEOUT (2 * HZ)
6550
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006551static int iwl4965_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07006552{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07006553 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08006554 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07006555
6556 IWL_DEBUG_MAC80211("enter\n");
6557
Zhu Yi5a66926a2008-01-14 17:46:18 -08006558 if (pci_enable_device(priv->pci_dev)) {
6559 IWL_ERROR("Fail to pci_enable_device\n");
6560 return -ENODEV;
6561 }
6562 pci_restore_state(priv->pci_dev);
6563 pci_enable_msi(priv->pci_dev);
6564
6565 ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED,
6566 DRV_NAME, priv);
6567 if (ret) {
6568 IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq);
6569 goto out_disable_msi;
6570 }
6571
Zhu Yib481de92007-09-25 17:54:57 -07006572 /* we should be verifying the device is ready to be opened */
6573 mutex_lock(&priv->mutex);
6574
Zhu Yi5a66926a2008-01-14 17:46:18 -08006575 memset(&priv->staging_rxon, 0, sizeof(struct iwl4965_rxon_cmd));
6576 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
6577 * ucode filename and max sizes are card-specific. */
6578
6579 if (!priv->ucode_code.len) {
6580 ret = iwl4965_read_ucode(priv);
6581 if (ret) {
6582 IWL_ERROR("Could not read microcode: %d\n", ret);
6583 mutex_unlock(&priv->mutex);
6584 goto out_release_irq;
6585 }
6586 }
6587
Zhu Yie655b9f2008-01-24 02:19:38 -08006588 ret = __iwl4965_up(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08006589
Zhu Yib481de92007-09-25 17:54:57 -07006590 mutex_unlock(&priv->mutex);
Zhu Yi5a66926a2008-01-14 17:46:18 -08006591
Zhu Yie655b9f2008-01-24 02:19:38 -08006592 if (ret)
6593 goto out_release_irq;
6594
6595 IWL_DEBUG_INFO("Start UP work done.\n");
6596
6597 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
6598 return 0;
6599
Zhu Yi5a66926a2008-01-14 17:46:18 -08006600 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
6601 * mac80211 will not be run successfully. */
6602 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
6603 test_bit(STATUS_READY, &priv->status),
6604 UCODE_READY_TIMEOUT);
6605 if (!ret) {
6606 if (!test_bit(STATUS_READY, &priv->status)) {
6607 IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n",
6608 jiffies_to_msecs(UCODE_READY_TIMEOUT));
6609 ret = -ETIMEDOUT;
6610 goto out_release_irq;
6611 }
6612 }
6613
Zhu Yie655b9f2008-01-24 02:19:38 -08006614 priv->is_open = 1;
Zhu Yib481de92007-09-25 17:54:57 -07006615 IWL_DEBUG_MAC80211("leave\n");
6616 return 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08006617
6618out_release_irq:
6619 free_irq(priv->pci_dev->irq, priv);
6620out_disable_msi:
6621 pci_disable_msi(priv->pci_dev);
Zhu Yie655b9f2008-01-24 02:19:38 -08006622 pci_disable_device(priv->pci_dev);
6623 priv->is_open = 0;
6624 IWL_DEBUG_MAC80211("leave - failed\n");
Zhu Yi5a66926a2008-01-14 17:46:18 -08006625 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07006626}
6627
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006628static void iwl4965_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07006629{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07006630 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07006631
6632 IWL_DEBUG_MAC80211("enter\n");
Mohamed Abbas948c1712007-10-25 17:15:45 +08006633
Zhu Yie655b9f2008-01-24 02:19:38 -08006634 if (!priv->is_open) {
6635 IWL_DEBUG_MAC80211("leave - skip\n");
6636 return;
6637 }
6638
Zhu Yib481de92007-09-25 17:54:57 -07006639 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08006640
6641 if (iwl4965_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08006642 /* stop mac, cancel any scan request and clear
6643 * RXON_FILTER_ASSOC_MSK BIT
6644 */
Zhu Yi5a66926a2008-01-14 17:46:18 -08006645 mutex_lock(&priv->mutex);
6646 iwl4965_scan_cancel_timeout(priv, 100);
6647 cancel_delayed_work(&priv->post_associate);
Mohamed Abbasfde35712007-11-29 11:10:15 +08006648 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08006649 }
6650
Zhu Yi5a66926a2008-01-14 17:46:18 -08006651 iwl4965_down(priv);
6652
6653 flush_workqueue(priv->workqueue);
6654 free_irq(priv->pci_dev->irq, priv);
6655 pci_disable_msi(priv->pci_dev);
6656 pci_save_state(priv->pci_dev);
6657 pci_disable_device(priv->pci_dev);
Mohamed Abbas948c1712007-10-25 17:15:45 +08006658
Zhu Yib481de92007-09-25 17:54:57 -07006659 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07006660}
6661
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006662static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
Zhu Yib481de92007-09-25 17:54:57 -07006663 struct ieee80211_tx_control *ctl)
6664{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07006665 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07006666
6667 IWL_DEBUG_MAC80211("enter\n");
6668
6669 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
6670 IWL_DEBUG_MAC80211("leave - monitor\n");
6671 return -1;
6672 }
6673
6674 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berg8318d782008-01-24 19:38:38 +01006675 ctl->tx_rate->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07006676
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006677 if (iwl4965_tx_skb(priv, skb, ctl))
Zhu Yib481de92007-09-25 17:54:57 -07006678 dev_kfree_skb_any(skb);
6679
6680 IWL_DEBUG_MAC80211("leave\n");
6681 return 0;
6682}
6683
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006684static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07006685 struct ieee80211_if_init_conf *conf)
6686{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07006687 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07006688 unsigned long flags;
Joe Perches0795af52007-10-03 17:59:30 -07006689 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07006690
Johannes Berg32bfd352007-12-19 01:31:26 +01006691 IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07006692
Johannes Berg32bfd352007-12-19 01:31:26 +01006693 if (priv->vif) {
6694 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
Reinette Chatre75849d22008-01-23 10:15:17 -08006695 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07006696 }
6697
6698 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01006699 priv->vif = conf->vif;
Zhu Yib481de92007-09-25 17:54:57 -07006700
6701 spin_unlock_irqrestore(&priv->lock, flags);
6702
6703 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02006704
6705 if (conf->mac_addr) {
6706 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr));
6707 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
6708 }
Zhu Yib481de92007-09-25 17:54:57 -07006709
Zhu Yi5a66926a2008-01-14 17:46:18 -08006710 if (iwl4965_is_ready(priv))
6711 iwl4965_set_mode(priv, conf->type);
6712
Zhu Yib481de92007-09-25 17:54:57 -07006713 mutex_unlock(&priv->mutex);
6714
Zhu Yi5a66926a2008-01-14 17:46:18 -08006715 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07006716 return 0;
6717}
6718
6719/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006720 * iwl4965_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07006721 *
6722 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
6723 * be set inappropriately and the driver currently sets the hardware up to
6724 * use it whenever needed.
6725 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006726static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07006727{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07006728 struct iwl_priv *priv = hw->priv;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07006729 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07006730 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08006731 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07006732
6733 mutex_lock(&priv->mutex);
Johannes Berg8318d782008-01-24 19:38:38 +01006734 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07006735
Zhu Yi12342c42007-12-20 11:27:32 +08006736 priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
6737
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006738 if (!iwl4965_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006739 IWL_DEBUG_MAC80211("leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08006740 ret = -EIO;
6741 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07006742 }
6743
Assaf Krauss00acbc92008-03-14 10:38:47 -07006744 if (unlikely(!iwl4965_mod_params.disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07006745 test_bit(STATUS_SCANNING, &priv->status))) {
Zhu Yia0646472007-12-20 14:10:01 +08006746 IWL_DEBUG_MAC80211("leave - scanning\n");
6747 set_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07006748 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08006749 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07006750 }
6751
6752 spin_lock_irqsave(&priv->lock, flags);
6753
Johannes Berg8318d782008-01-24 19:38:38 +01006754 ch_info = iwl4965_get_channel_info(priv, conf->channel->band,
6755 ieee80211_frequency_to_channel(conf->channel->center_freq));
Zhu Yib481de92007-09-25 17:54:57 -07006756 if (!is_channel_valid(ch_info)) {
Zhu Yib481de92007-09-25 17:54:57 -07006757 IWL_DEBUG_MAC80211("leave - invalid channel\n");
6758 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yi76bb77e2007-11-22 10:53:22 +08006759 ret = -EINVAL;
6760 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07006761 }
6762
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08006763#ifdef CONFIG_IWL4965_HT
Tomas Winkler78330fd2008-02-06 02:37:18 +02006764 /* if we are switching from ht to 2.4 clear flags
Zhu Yib481de92007-09-25 17:54:57 -07006765 * from any ht related info since 2.4 does not
6766 * support ht */
Tomas Winkler78330fd2008-02-06 02:37:18 +02006767 if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel->hw_value)
Zhu Yib481de92007-09-25 17:54:57 -07006768#ifdef IEEE80211_CONF_CHANNEL_SWITCH
6769 && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
6770#endif
6771 )
6772 priv->staging_rxon.flags = 0;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08006773#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07006774
Assaf Kraussbf85ea42008-03-14 10:38:49 -07006775 iwlcore_set_rxon_channel(priv, conf->channel->band,
Johannes Berg8318d782008-01-24 19:38:38 +01006776 ieee80211_frequency_to_channel(conf->channel->center_freq));
Zhu Yib481de92007-09-25 17:54:57 -07006777
Johannes Berg8318d782008-01-24 19:38:38 +01006778 iwl4965_set_flags_for_phymode(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07006779
6780 /* The list of supported rates and rate mask can be different
Johannes Berg8318d782008-01-24 19:38:38 +01006781 * for each band; since the band may have changed, reset
Zhu Yib481de92007-09-25 17:54:57 -07006782 * the rate mask to what mac80211 lists */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006783 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006784
6785 spin_unlock_irqrestore(&priv->lock, flags);
6786
6787#ifdef IEEE80211_CONF_CHANNEL_SWITCH
6788 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006789 iwl4965_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08006790 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07006791 }
6792#endif
6793
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006794 iwl4965_radio_kill_sw(priv, !conf->radio_enabled);
Zhu Yib481de92007-09-25 17:54:57 -07006795
6796 if (!conf->radio_enabled) {
6797 IWL_DEBUG_MAC80211("leave - radio disabled\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08006798 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07006799 }
6800
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006801 if (iwl4965_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006802 IWL_DEBUG_MAC80211("leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08006803 ret = -EIO;
6804 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07006805 }
6806
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006807 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006808
6809 if (memcmp(&priv->active_rxon,
6810 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006811 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006812 else
6813 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
6814
6815 IWL_DEBUG_MAC80211("leave\n");
6816
Zhu Yia0646472007-12-20 14:10:01 +08006817out:
6818 clear_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08006819 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08006820 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07006821}
6822
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07006823static void iwl4965_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006824{
6825 int rc = 0;
6826
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08006827 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07006828 return;
6829
6830 /* The following should be done only at AP bring up */
6831 if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) {
6832
6833 /* RXON - unassoc (to set timing command) */
6834 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006835 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006836
6837 /* RXON Timing */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006838 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
6839 iwl4965_setup_rxon_timing(priv);
6840 rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07006841 sizeof(priv->rxon_timing), &priv->rxon_timing);
6842 if (rc)
6843 IWL_WARNING("REPLY_RXON_TIMING failed - "
6844 "Attempting to continue.\n");
6845
6846 iwl4965_set_rxon_chain(priv);
6847
6848 /* FIXME: what should be the assoc_id for AP? */
6849 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
6850 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
6851 priv->staging_rxon.flags |=
6852 RXON_FLG_SHORT_PREAMBLE_MSK;
6853 else
6854 priv->staging_rxon.flags &=
6855 ~RXON_FLG_SHORT_PREAMBLE_MSK;
6856
6857 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
6858 if (priv->assoc_capability &
6859 WLAN_CAPABILITY_SHORT_SLOT_TIME)
6860 priv->staging_rxon.flags |=
6861 RXON_FLG_SHORT_SLOT_MSK;
6862 else
6863 priv->staging_rxon.flags &=
6864 ~RXON_FLG_SHORT_SLOT_MSK;
6865
6866 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
6867 priv->staging_rxon.flags &=
6868 ~RXON_FLG_SHORT_SLOT_MSK;
6869 }
6870 /* restore RXON assoc */
6871 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006872 iwl4965_commit_rxon(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006873 iwl4965_activate_qos(priv, 1);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006874 iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0);
Zhu Yie1493de2007-09-27 11:27:32 +08006875 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006876 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006877
6878 /* FIXME - we need to add code here to detect a totally new
6879 * configuration, reset the AP, unassoc, rxon timing, assoc,
6880 * clear sta table, add BCAST sta... */
6881}
6882
Johannes Berg32bfd352007-12-19 01:31:26 +01006883static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
6884 struct ieee80211_vif *vif,
Zhu Yib481de92007-09-25 17:54:57 -07006885 struct ieee80211_if_conf *conf)
6886{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07006887 struct iwl_priv *priv = hw->priv;
Joe Perches0795af52007-10-03 17:59:30 -07006888 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07006889 unsigned long flags;
6890 int rc;
6891
6892 if (conf == NULL)
6893 return -EIO;
6894
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08006895 if (priv->vif != vif) {
6896 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
6897 mutex_unlock(&priv->mutex);
6898 return 0;
6899 }
6900
Zhu Yib481de92007-09-25 17:54:57 -07006901 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
6902 (!conf->beacon || !conf->ssid_len)) {
6903 IWL_DEBUG_MAC80211
6904 ("Leaving in AP mode because HostAPD is not ready.\n");
6905 return 0;
6906 }
6907
Zhu Yi5a66926a2008-01-14 17:46:18 -08006908 if (!iwl4965_is_alive(priv))
6909 return -EAGAIN;
6910
Zhu Yib481de92007-09-25 17:54:57 -07006911 mutex_lock(&priv->mutex);
6912
Zhu Yib481de92007-09-25 17:54:57 -07006913 if (conf->bssid)
Joe Perches0795af52007-10-03 17:59:30 -07006914 IWL_DEBUG_MAC80211("bssid: %s\n",
6915 print_mac(mac, conf->bssid));
Zhu Yib481de92007-09-25 17:54:57 -07006916
Johannes Berg4150c572007-09-17 01:29:23 -04006917/*
6918 * very dubious code was here; the probe filtering flag is never set:
6919 *
Zhu Yib481de92007-09-25 17:54:57 -07006920 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
6921 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04006922 */
Zhu Yib481de92007-09-25 17:54:57 -07006923
6924 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
6925 if (!conf->bssid) {
6926 conf->bssid = priv->mac_addr;
6927 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Joe Perches0795af52007-10-03 17:59:30 -07006928 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
6929 print_mac(mac, conf->bssid));
Zhu Yib481de92007-09-25 17:54:57 -07006930 }
6931 if (priv->ibss_beacon)
6932 dev_kfree_skb(priv->ibss_beacon);
6933
6934 priv->ibss_beacon = conf->beacon;
6935 }
6936
Mohamed Abbasfde35712007-11-29 11:10:15 +08006937 if (iwl4965_is_rfkill(priv))
6938 goto done;
6939
Zhu Yib481de92007-09-25 17:54:57 -07006940 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
6941 !is_multicast_ether_addr(conf->bssid)) {
6942 /* If there is currently a HW scan going on in the background
6943 * then we need to cancel it else the RXON below will fail. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006944 if (iwl4965_scan_cancel_timeout(priv, 100)) {
Zhu Yib481de92007-09-25 17:54:57 -07006945 IWL_WARNING("Aborted scan still in progress "
6946 "after 100ms\n");
6947 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
6948 mutex_unlock(&priv->mutex);
6949 return -EAGAIN;
6950 }
6951 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
6952
6953 /* TODO: Audit driver for usage of these members and see
6954 * if mac80211 deprecates them (priv->bssid looks like it
6955 * shouldn't be there, but I haven't scanned the IBSS code
6956 * to verify) - jpk */
6957 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
6958
6959 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006960 iwl4965_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006961 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006962 rc = iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006963 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006964 iwl4965_rxon_add_station(
Zhu Yib481de92007-09-25 17:54:57 -07006965 priv, priv->active_rxon.bssid_addr, 1);
6966 }
6967
6968 } else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006969 iwl4965_scan_cancel_timeout(priv, 100);
Zhu Yib481de92007-09-25 17:54:57 -07006970 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006971 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006972 }
6973
Mohamed Abbasfde35712007-11-29 11:10:15 +08006974 done:
Zhu Yib481de92007-09-25 17:54:57 -07006975 spin_lock_irqsave(&priv->lock, flags);
6976 if (!conf->ssid_len)
6977 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
6978 else
6979 memcpy(priv->essid, conf->ssid, conf->ssid_len);
6980
6981 priv->essid_len = conf->ssid_len;
6982 spin_unlock_irqrestore(&priv->lock, flags);
6983
6984 IWL_DEBUG_MAC80211("leave\n");
6985 mutex_unlock(&priv->mutex);
6986
6987 return 0;
6988}
6989
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006990static void iwl4965_configure_filter(struct ieee80211_hw *hw,
Johannes Berg4150c572007-09-17 01:29:23 -04006991 unsigned int changed_flags,
6992 unsigned int *total_flags,
6993 int mc_count, struct dev_addr_list *mc_list)
6994{
6995 /*
6996 * XXX: dummy
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006997 * see also iwl4965_connection_init_rx_config
Johannes Berg4150c572007-09-17 01:29:23 -04006998 */
6999 *total_flags = 0;
7000}
7001
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007002static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07007003 struct ieee80211_if_init_conf *conf)
7004{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007005 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07007006
7007 IWL_DEBUG_MAC80211("enter\n");
7008
7009 mutex_lock(&priv->mutex);
Mohamed Abbas948c1712007-10-25 17:15:45 +08007010
Mohamed Abbasfde35712007-11-29 11:10:15 +08007011 if (iwl4965_is_ready_rf(priv)) {
7012 iwl4965_scan_cancel_timeout(priv, 100);
7013 cancel_delayed_work(&priv->post_associate);
7014 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7015 iwl4965_commit_rxon(priv);
7016 }
Johannes Berg32bfd352007-12-19 01:31:26 +01007017 if (priv->vif == conf->vif) {
7018 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07007019 memset(priv->bssid, 0, ETH_ALEN);
7020 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
7021 priv->essid_len = 0;
7022 }
7023 mutex_unlock(&priv->mutex);
7024
7025 IWL_DEBUG_MAC80211("leave\n");
7026
7027}
Johannes Berg471b3ef2007-12-28 14:32:58 +01007028
7029static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
7030 struct ieee80211_vif *vif,
7031 struct ieee80211_bss_conf *bss_conf,
7032 u32 changes)
Tomas Winkler220173b2007-10-16 00:50:25 +02007033{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007034 struct iwl_priv *priv = hw->priv;
Tomas Winkler220173b2007-10-16 00:50:25 +02007035
Johannes Berg471b3ef2007-12-28 14:32:58 +01007036 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
7037 if (bss_conf->use_short_preamble)
Tomas Winkler220173b2007-10-16 00:50:25 +02007038 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
7039 else
7040 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
7041 }
7042
Johannes Berg471b3ef2007-12-28 14:32:58 +01007043 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
Johannes Berg8318d782008-01-24 19:38:38 +01007044 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Tomas Winkler220173b2007-10-16 00:50:25 +02007045 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
7046 else
7047 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
7048 }
7049
Johannes Berg471b3ef2007-12-28 14:32:58 +01007050 if (changes & BSS_CHANGED_ASSOC) {
7051 /*
7052 * TODO:
7053 * do stuff instead of sniffing assoc resp
7054 */
7055 }
7056
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007057 if (iwl4965_is_associated(priv))
7058 iwl4965_send_rxon_assoc(priv);
Tomas Winkler220173b2007-10-16 00:50:25 +02007059}
Zhu Yib481de92007-09-25 17:54:57 -07007060
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007061static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
Zhu Yib481de92007-09-25 17:54:57 -07007062{
7063 int rc = 0;
7064 unsigned long flags;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007065 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07007066
7067 IWL_DEBUG_MAC80211("enter\n");
7068
mabbas052c4b92007-10-25 17:15:43 +08007069 mutex_lock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07007070 spin_lock_irqsave(&priv->lock, flags);
7071
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007072 if (!iwl4965_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07007073 rc = -EIO;
7074 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
7075 goto out_unlock;
7076 }
7077
7078 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */
7079 rc = -EIO;
7080 IWL_ERROR("ERROR: APs don't scan\n");
7081 goto out_unlock;
7082 }
7083
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08007084 /* we don't schedule scan within next_scan_jiffies period */
7085 if (priv->next_scan_jiffies &&
7086 time_after(priv->next_scan_jiffies, jiffies)) {
7087 rc = -EAGAIN;
7088 goto out_unlock;
7089 }
Zhu Yib481de92007-09-25 17:54:57 -07007090 /* if we just finished scan ask for delay */
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08007091 if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies +
7092 IWL_DELAY_NEXT_SCAN, jiffies)) {
Zhu Yib481de92007-09-25 17:54:57 -07007093 rc = -EAGAIN;
7094 goto out_unlock;
7095 }
7096 if (len) {
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08007097 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007098 iwl4965_escape_essid(ssid, len), (int)len);
Zhu Yib481de92007-09-25 17:54:57 -07007099
7100 priv->one_direct_scan = 1;
7101 priv->direct_ssid_len = (u8)
7102 min((u8) len, (u8) IW_ESSID_MAX_SIZE);
7103 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
Mohamed Abbas948c1712007-10-25 17:15:45 +08007104 } else
7105 priv->one_direct_scan = 0;
Zhu Yib481de92007-09-25 17:54:57 -07007106
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007107 rc = iwl4965_scan_initiate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007108
7109 IWL_DEBUG_MAC80211("leave\n");
7110
7111out_unlock:
7112 spin_unlock_irqrestore(&priv->lock, flags);
mabbas052c4b92007-10-25 17:15:43 +08007113 mutex_unlock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07007114
7115 return rc;
7116}
7117
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007118static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Zhu Yib481de92007-09-25 17:54:57 -07007119 const u8 *local_addr, const u8 *addr,
7120 struct ieee80211_key_conf *key)
7121{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007122 struct iwl_priv *priv = hw->priv;
Joe Perches0795af52007-10-03 17:59:30 -07007123 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07007124 int rc = 0;
7125 u8 sta_id;
7126
7127 IWL_DEBUG_MAC80211("enter\n");
7128
Assaf Krauss00acbc92008-03-14 10:38:47 -07007129 if (!iwl4965_mod_params.hw_crypto) {
Zhu Yib481de92007-09-25 17:54:57 -07007130 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
7131 return -EOPNOTSUPP;
7132 }
7133
7134 if (is_zero_ether_addr(addr))
7135 /* only support pairwise keys */
7136 return -EOPNOTSUPP;
7137
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007138 sta_id = iwl4965_hw_find_station(priv, addr);
Zhu Yib481de92007-09-25 17:54:57 -07007139 if (sta_id == IWL_INVALID_STATION) {
Joe Perches0795af52007-10-03 17:59:30 -07007140 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
7141 print_mac(mac, addr));
Zhu Yib481de92007-09-25 17:54:57 -07007142 return -EINVAL;
7143 }
7144
7145 mutex_lock(&priv->mutex);
7146
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007147 iwl4965_scan_cancel_timeout(priv, 100);
mabbas052c4b92007-10-25 17:15:43 +08007148
Zhu Yib481de92007-09-25 17:54:57 -07007149 switch (cmd) {
7150 case SET_KEY:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007151 rc = iwl4965_update_sta_key_info(priv, key, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07007152 if (!rc) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007153 iwl4965_set_rxon_hwcrypto(priv, 1);
7154 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007155 key->hw_key_idx = sta_id;
7156 IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n");
7157 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
7158 }
7159 break;
7160 case DISABLE_KEY:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007161 rc = iwl4965_clear_sta_key_info(priv, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07007162 if (!rc) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007163 iwl4965_set_rxon_hwcrypto(priv, 0);
7164 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007165 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
7166 }
7167 break;
7168 default:
7169 rc = -EINVAL;
7170 }
7171
7172 IWL_DEBUG_MAC80211("leave\n");
7173 mutex_unlock(&priv->mutex);
7174
7175 return rc;
7176}
7177
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007178static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, int queue,
Zhu Yib481de92007-09-25 17:54:57 -07007179 const struct ieee80211_tx_queue_params *params)
7180{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007181 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07007182 unsigned long flags;
7183 int q;
Zhu Yib481de92007-09-25 17:54:57 -07007184
7185 IWL_DEBUG_MAC80211("enter\n");
7186
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007187 if (!iwl4965_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07007188 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7189 return -EIO;
7190 }
7191
7192 if (queue >= AC_NUM) {
7193 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
7194 return 0;
7195 }
7196
Zhu Yib481de92007-09-25 17:54:57 -07007197 if (!priv->qos_data.qos_enable) {
7198 priv->qos_data.qos_active = 0;
7199 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
7200 return 0;
7201 }
7202 q = AC_NUM - 1 - queue;
7203
7204 spin_lock_irqsave(&priv->lock, flags);
7205
7206 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
7207 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
7208 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
7209 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7b2008-02-10 16:49:38 +01007210 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07007211
7212 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
7213 priv->qos_data.qos_active = 1;
7214
7215 spin_unlock_irqrestore(&priv->lock, flags);
7216
7217 mutex_lock(&priv->mutex);
7218 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007219 iwl4965_activate_qos(priv, 1);
7220 else if (priv->assoc_id && iwl4965_is_associated(priv))
7221 iwl4965_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07007222
7223 mutex_unlock(&priv->mutex);
7224
Zhu Yib481de92007-09-25 17:54:57 -07007225 IWL_DEBUG_MAC80211("leave\n");
7226 return 0;
7227}
7228
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007229static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07007230 struct ieee80211_tx_queue_stats *stats)
7231{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007232 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07007233 int i, avail;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007234 struct iwl4965_tx_queue *txq;
7235 struct iwl4965_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07007236 unsigned long flags;
7237
7238 IWL_DEBUG_MAC80211("enter\n");
7239
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007240 if (!iwl4965_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07007241 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7242 return -EIO;
7243 }
7244
7245 spin_lock_irqsave(&priv->lock, flags);
7246
7247 for (i = 0; i < AC_NUM; i++) {
7248 txq = &priv->txq[i];
7249 q = &txq->q;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007250 avail = iwl4965_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07007251
7252 stats->data[i].len = q->n_window - avail;
7253 stats->data[i].limit = q->n_window - q->high_mark;
7254 stats->data[i].count = q->n_window;
7255
7256 }
7257 spin_unlock_irqrestore(&priv->lock, flags);
7258
7259 IWL_DEBUG_MAC80211("leave\n");
7260
7261 return 0;
7262}
7263
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007264static int iwl4965_mac_get_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07007265 struct ieee80211_low_level_stats *stats)
7266{
7267 IWL_DEBUG_MAC80211("enter\n");
7268 IWL_DEBUG_MAC80211("leave\n");
7269
7270 return 0;
7271}
7272
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007273static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07007274{
7275 IWL_DEBUG_MAC80211("enter\n");
7276 IWL_DEBUG_MAC80211("leave\n");
7277
7278 return 0;
7279}
7280
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007281static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07007282{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007283 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07007284 unsigned long flags;
7285
7286 mutex_lock(&priv->mutex);
7287 IWL_DEBUG_MAC80211("enter\n");
7288
7289 priv->lq_mngr.lq_ready = 0;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007290#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -07007291 spin_lock_irqsave(&priv->lock, flags);
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02007292 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
Zhu Yib481de92007-09-25 17:54:57 -07007293 spin_unlock_irqrestore(&priv->lock, flags);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007294#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07007295
Assaf Kraussbf85ea42008-03-14 10:38:49 -07007296 iwlcore_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007297
7298 cancel_delayed_work(&priv->post_associate);
7299
7300 spin_lock_irqsave(&priv->lock, flags);
7301 priv->assoc_id = 0;
7302 priv->assoc_capability = 0;
7303 priv->call_post_assoc_from_beacon = 0;
7304 priv->assoc_station_added = 0;
7305
7306 /* new association get rid of ibss beacon skb */
7307 if (priv->ibss_beacon)
7308 dev_kfree_skb(priv->ibss_beacon);
7309
7310 priv->ibss_beacon = NULL;
7311
7312 priv->beacon_int = priv->hw->conf.beacon_int;
7313 priv->timestamp1 = 0;
7314 priv->timestamp0 = 0;
7315 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
7316 priv->beacon_int = 0;
7317
7318 spin_unlock_irqrestore(&priv->lock, flags);
7319
Mohamed Abbasfde35712007-11-29 11:10:15 +08007320 if (!iwl4965_is_ready_rf(priv)) {
7321 IWL_DEBUG_MAC80211("leave - not ready\n");
7322 mutex_unlock(&priv->mutex);
7323 return;
7324 }
7325
mabbas052c4b92007-10-25 17:15:43 +08007326 /* we are restarting association process
7327 * clear RXON_FILTER_ASSOC_MSK bit
7328 */
7329 if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007330 iwl4965_scan_cancel_timeout(priv, 100);
mabbas052c4b92007-10-25 17:15:43 +08007331 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007332 iwl4965_commit_rxon(priv);
mabbas052c4b92007-10-25 17:15:43 +08007333 }
7334
Zhu Yib481de92007-09-25 17:54:57 -07007335 /* Per mac80211.h: This is only used in IBSS mode... */
7336 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
mabbas052c4b92007-10-25 17:15:43 +08007337
Zhu Yib481de92007-09-25 17:54:57 -07007338 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
7339 mutex_unlock(&priv->mutex);
7340 return;
7341 }
7342
Zhu Yib481de92007-09-25 17:54:57 -07007343 priv->only_active_channel = 0;
7344
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007345 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007346
7347 mutex_unlock(&priv->mutex);
7348
7349 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07007350}
7351
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007352static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb,
Zhu Yib481de92007-09-25 17:54:57 -07007353 struct ieee80211_tx_control *control)
7354{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007355 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07007356 unsigned long flags;
7357
7358 mutex_lock(&priv->mutex);
7359 IWL_DEBUG_MAC80211("enter\n");
7360
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007361 if (!iwl4965_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07007362 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7363 mutex_unlock(&priv->mutex);
7364 return -EIO;
7365 }
7366
7367 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
7368 IWL_DEBUG_MAC80211("leave - not IBSS\n");
7369 mutex_unlock(&priv->mutex);
7370 return -EIO;
7371 }
7372
7373 spin_lock_irqsave(&priv->lock, flags);
7374
7375 if (priv->ibss_beacon)
7376 dev_kfree_skb(priv->ibss_beacon);
7377
7378 priv->ibss_beacon = skb;
7379
7380 priv->assoc_id = 0;
7381
7382 IWL_DEBUG_MAC80211("leave\n");
7383 spin_unlock_irqrestore(&priv->lock, flags);
7384
Assaf Kraussbf85ea42008-03-14 10:38:49 -07007385 iwlcore_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007386
7387 queue_work(priv->workqueue, &priv->post_associate.work);
7388
7389 mutex_unlock(&priv->mutex);
7390
7391 return 0;
7392}
7393
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007394#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -07007395
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02007396static void iwl4965_ht_info_fill(struct ieee80211_conf *conf,
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007397 struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07007398{
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02007399 struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
7400 struct ieee80211_ht_info *ht_conf = &conf->ht_conf;
7401 struct ieee80211_ht_bss_info *ht_bss_conf = &conf->ht_bss_conf;
Zhu Yib481de92007-09-25 17:54:57 -07007402
7403 IWL_DEBUG_MAC80211("enter: \n");
7404
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02007405 if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)) {
7406 iwl_conf->is_ht = 0;
7407 return;
Zhu Yib481de92007-09-25 17:54:57 -07007408 }
7409
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02007410 iwl_conf->is_ht = 1;
7411 priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
Zhu Yib481de92007-09-25 17:54:57 -07007412
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02007413 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
7414 iwl_conf->sgf |= 0x1;
7415 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
7416 iwl_conf->sgf |= 0x2;
Zhu Yib481de92007-09-25 17:54:57 -07007417
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02007418 iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
7419 iwl_conf->max_amsdu_size =
7420 !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
Guy Cohen134eb5d2008-03-04 18:09:25 -08007421
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02007422 iwl_conf->supported_chan_width =
7423 !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH);
Guy Cohen134eb5d2008-03-04 18:09:25 -08007424 iwl_conf->extension_chan_offset =
7425 ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET;
7426 /* If no above or below channel supplied disable FAT channel */
7427 if (iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_ABOVE &&
7428 iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_BELOW)
7429 iwl_conf->supported_chan_width = 0;
7430
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02007431 iwl_conf->tx_mimo_ps_mode =
7432 (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
7433 memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16);
Zhu Yib481de92007-09-25 17:54:57 -07007434
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02007435 iwl_conf->control_channel = ht_bss_conf->primary_channel;
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02007436 iwl_conf->tx_chan_width =
7437 !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH);
7438 iwl_conf->ht_protection =
7439 ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION;
7440 iwl_conf->non_GF_STA_present =
7441 !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT);
Zhu Yib481de92007-09-25 17:54:57 -07007442
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02007443 IWL_DEBUG_MAC80211("control channel %d\n",
7444 iwl_conf->control_channel);
Zhu Yib481de92007-09-25 17:54:57 -07007445 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07007446}
7447
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007448static int iwl4965_mac_conf_ht(struct ieee80211_hw *hw,
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02007449 struct ieee80211_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07007450{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007451 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07007452
7453 IWL_DEBUG_MAC80211("enter: \n");
7454
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02007455 iwl4965_ht_info_fill(conf, priv);
Zhu Yib481de92007-09-25 17:54:57 -07007456 iwl4965_set_rxon_chain(priv);
7457
7458 if (priv && priv->assoc_id &&
7459 (priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
7460 unsigned long flags;
7461
7462 spin_lock_irqsave(&priv->lock, flags);
7463 if (priv->beacon_int)
7464 queue_work(priv->workqueue, &priv->post_associate.work);
7465 else
7466 priv->call_post_assoc_from_beacon = 1;
7467 spin_unlock_irqrestore(&priv->lock, flags);
7468 }
7469
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02007470 IWL_DEBUG_MAC80211("leave:\n");
7471 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07007472}
7473
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007474#endif /*CONFIG_IWL4965_HT*/
Zhu Yib481de92007-09-25 17:54:57 -07007475
7476/*****************************************************************************
7477 *
7478 * sysfs attributes
7479 *
7480 *****************************************************************************/
7481
Tomas Winkler0a6857e2008-03-12 16:58:49 -07007482#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07007483
7484/*
7485 * The following adds a new attribute to the sysfs representation
7486 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
7487 * used for controlling the debug level.
7488 *
7489 * See the level definitions in iwl for details.
7490 */
7491
7492static ssize_t show_debug_level(struct device_driver *d, char *buf)
7493{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07007494 return sprintf(buf, "0x%08X\n", iwl_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07007495}
7496static ssize_t store_debug_level(struct device_driver *d,
7497 const char *buf, size_t count)
7498{
7499 char *p = (char *)buf;
7500 u32 val;
7501
7502 val = simple_strtoul(p, &p, 0);
7503 if (p == buf)
7504 printk(KERN_INFO DRV_NAME
7505 ": %s is not in hex or decimal form.\n", buf);
7506 else
Tomas Winkler0a6857e2008-03-12 16:58:49 -07007507 iwl_debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07007508
7509 return strnlen(buf, count);
7510}
7511
7512static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
7513 show_debug_level, store_debug_level);
7514
Tomas Winkler0a6857e2008-03-12 16:58:49 -07007515#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07007516
7517static ssize_t show_rf_kill(struct device *d,
7518 struct device_attribute *attr, char *buf)
7519{
7520 /*
7521 * 0 - RF kill not enabled
7522 * 1 - SW based RF kill active (sysfs)
7523 * 2 - HW based RF kill active
7524 * 3 - Both HW and SW based RF kill active
7525 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007526 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07007527 int val = (test_bit(STATUS_RF_KILL_SW, &priv->status) ? 0x1 : 0x0) |
7528 (test_bit(STATUS_RF_KILL_HW, &priv->status) ? 0x2 : 0x0);
7529
7530 return sprintf(buf, "%i\n", val);
7531}
7532
7533static ssize_t store_rf_kill(struct device *d,
7534 struct device_attribute *attr,
7535 const char *buf, size_t count)
7536{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007537 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07007538
7539 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007540 iwl4965_radio_kill_sw(priv, buf[0] == '1');
Zhu Yib481de92007-09-25 17:54:57 -07007541 mutex_unlock(&priv->mutex);
7542
7543 return count;
7544}
7545
7546static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
7547
7548static ssize_t show_temperature(struct device *d,
7549 struct device_attribute *attr, char *buf)
7550{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007551 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07007552
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007553 if (!iwl4965_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07007554 return -EAGAIN;
7555
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007556 return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07007557}
7558
7559static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
7560
7561static ssize_t show_rs_window(struct device *d,
7562 struct device_attribute *attr,
7563 char *buf)
7564{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007565 struct iwl_priv *priv = d->driver_data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007566 return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07007567}
7568static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
7569
7570static ssize_t show_tx_power(struct device *d,
7571 struct device_attribute *attr, char *buf)
7572{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007573 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07007574 return sprintf(buf, "%d\n", priv->user_txpower_limit);
7575}
7576
7577static ssize_t store_tx_power(struct device *d,
7578 struct device_attribute *attr,
7579 const char *buf, size_t count)
7580{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007581 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07007582 char *p = (char *)buf;
7583 u32 val;
7584
7585 val = simple_strtoul(p, &p, 10);
7586 if (p == buf)
7587 printk(KERN_INFO DRV_NAME
7588 ": %s is not in decimal form.\n", buf);
7589 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007590 iwl4965_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07007591
7592 return count;
7593}
7594
7595static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
7596
7597static ssize_t show_flags(struct device *d,
7598 struct device_attribute *attr, char *buf)
7599{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007600 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07007601
7602 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
7603}
7604
7605static ssize_t store_flags(struct device *d,
7606 struct device_attribute *attr,
7607 const char *buf, size_t count)
7608{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007609 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07007610 u32 flags = simple_strtoul(buf, NULL, 0);
7611
7612 mutex_lock(&priv->mutex);
7613 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
7614 /* Cancel any currently running scans... */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007615 if (iwl4965_scan_cancel_timeout(priv, 100))
Zhu Yib481de92007-09-25 17:54:57 -07007616 IWL_WARNING("Could not cancel scan.\n");
7617 else {
7618 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
7619 flags);
7620 priv->staging_rxon.flags = cpu_to_le32(flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007621 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007622 }
7623 }
7624 mutex_unlock(&priv->mutex);
7625
7626 return count;
7627}
7628
7629static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
7630
7631static ssize_t show_filter_flags(struct device *d,
7632 struct device_attribute *attr, char *buf)
7633{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007634 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07007635
7636 return sprintf(buf, "0x%04X\n",
7637 le32_to_cpu(priv->active_rxon.filter_flags));
7638}
7639
7640static ssize_t store_filter_flags(struct device *d,
7641 struct device_attribute *attr,
7642 const char *buf, size_t count)
7643{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007644 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07007645 u32 filter_flags = simple_strtoul(buf, NULL, 0);
7646
7647 mutex_lock(&priv->mutex);
7648 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
7649 /* Cancel any currently running scans... */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007650 if (iwl4965_scan_cancel_timeout(priv, 100))
Zhu Yib481de92007-09-25 17:54:57 -07007651 IWL_WARNING("Could not cancel scan.\n");
7652 else {
7653 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
7654 "0x%04X\n", filter_flags);
7655 priv->staging_rxon.filter_flags =
7656 cpu_to_le32(filter_flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007657 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007658 }
7659 }
7660 mutex_unlock(&priv->mutex);
7661
7662 return count;
7663}
7664
7665static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
7666 store_filter_flags);
7667
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007668#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07007669
7670static ssize_t show_measurement(struct device *d,
7671 struct device_attribute *attr, char *buf)
7672{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007673 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007674 struct iwl4965_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07007675 u32 size = sizeof(measure_report), len = 0, ofs = 0;
7676 u8 *data = (u8 *) & measure_report;
7677 unsigned long flags;
7678
7679 spin_lock_irqsave(&priv->lock, flags);
7680 if (!(priv->measurement_status & MEASUREMENT_READY)) {
7681 spin_unlock_irqrestore(&priv->lock, flags);
7682 return 0;
7683 }
7684 memcpy(&measure_report, &priv->measure_report, size);
7685 priv->measurement_status = 0;
7686 spin_unlock_irqrestore(&priv->lock, flags);
7687
7688 while (size && (PAGE_SIZE - len)) {
7689 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
7690 PAGE_SIZE - len, 1);
7691 len = strlen(buf);
7692 if (PAGE_SIZE - len)
7693 buf[len++] = '\n';
7694
7695 ofs += 16;
7696 size -= min(size, 16U);
7697 }
7698
7699 return len;
7700}
7701
7702static ssize_t store_measurement(struct device *d,
7703 struct device_attribute *attr,
7704 const char *buf, size_t count)
7705{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007706 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07007707 struct ieee80211_measurement_params params = {
7708 .channel = le16_to_cpu(priv->active_rxon.channel),
7709 .start_time = cpu_to_le64(priv->last_tsf),
7710 .duration = cpu_to_le16(1),
7711 };
7712 u8 type = IWL_MEASURE_BASIC;
7713 u8 buffer[32];
7714 u8 channel;
7715
7716 if (count) {
7717 char *p = buffer;
7718 strncpy(buffer, buf, min(sizeof(buffer), count));
7719 channel = simple_strtoul(p, NULL, 0);
7720 if (channel)
7721 params.channel = channel;
7722
7723 p = buffer;
7724 while (*p && *p != ' ')
7725 p++;
7726 if (*p)
7727 type = simple_strtoul(p + 1, NULL, 0);
7728 }
7729
7730 IWL_DEBUG_INFO("Invoking measurement of type %d on "
7731 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007732 iwl4965_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07007733
7734 return count;
7735}
7736
7737static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
7738 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007739#endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07007740
7741static ssize_t store_retry_rate(struct device *d,
7742 struct device_attribute *attr,
7743 const char *buf, size_t count)
7744{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007745 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07007746
7747 priv->retry_rate = simple_strtoul(buf, NULL, 0);
7748 if (priv->retry_rate <= 0)
7749 priv->retry_rate = 1;
7750
7751 return count;
7752}
7753
7754static ssize_t show_retry_rate(struct device *d,
7755 struct device_attribute *attr, char *buf)
7756{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007757 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07007758 return sprintf(buf, "%d", priv->retry_rate);
7759}
7760
7761static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
7762 store_retry_rate);
7763
7764static ssize_t store_power_level(struct device *d,
7765 struct device_attribute *attr,
7766 const char *buf, size_t count)
7767{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007768 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07007769 int rc;
7770 int mode;
7771
7772 mode = simple_strtoul(buf, NULL, 0);
7773 mutex_lock(&priv->mutex);
7774
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007775 if (!iwl4965_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07007776 rc = -EAGAIN;
7777 goto out;
7778 }
7779
7780 if ((mode < 1) || (mode > IWL_POWER_LIMIT) || (mode == IWL_POWER_AC))
7781 mode = IWL_POWER_AC;
7782 else
7783 mode |= IWL_POWER_ENABLED;
7784
7785 if (mode != priv->power_mode) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007786 rc = iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(mode));
Zhu Yib481de92007-09-25 17:54:57 -07007787 if (rc) {
7788 IWL_DEBUG_MAC80211("failed setting power mode.\n");
7789 goto out;
7790 }
7791 priv->power_mode = mode;
7792 }
7793
7794 rc = count;
7795
7796 out:
7797 mutex_unlock(&priv->mutex);
7798 return rc;
7799}
7800
7801#define MAX_WX_STRING 80
7802
7803/* Values are in microsecond */
7804static const s32 timeout_duration[] = {
7805 350000,
7806 250000,
7807 75000,
7808 37000,
7809 25000,
7810};
7811static const s32 period_duration[] = {
7812 400000,
7813 700000,
7814 1000000,
7815 1000000,
7816 1000000
7817};
7818
7819static ssize_t show_power_level(struct device *d,
7820 struct device_attribute *attr, char *buf)
7821{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007822 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07007823 int level = IWL_POWER_LEVEL(priv->power_mode);
7824 char *p = buf;
7825
7826 p += sprintf(p, "%d ", level);
7827 switch (level) {
7828 case IWL_POWER_MODE_CAM:
7829 case IWL_POWER_AC:
7830 p += sprintf(p, "(AC)");
7831 break;
7832 case IWL_POWER_BATTERY:
7833 p += sprintf(p, "(BATTERY)");
7834 break;
7835 default:
7836 p += sprintf(p,
7837 "(Timeout %dms, Period %dms)",
7838 timeout_duration[level - 1] / 1000,
7839 period_duration[level - 1] / 1000);
7840 }
7841
7842 if (!(priv->power_mode & IWL_POWER_ENABLED))
7843 p += sprintf(p, " OFF\n");
7844 else
7845 p += sprintf(p, " \n");
7846
7847 return (p - buf + 1);
7848
7849}
7850
7851static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
7852 store_power_level);
7853
7854static ssize_t show_channels(struct device *d,
7855 struct device_attribute *attr, char *buf)
7856{
Johannes Berg8318d782008-01-24 19:38:38 +01007857 /* all this shit doesn't belong into sysfs anyway */
7858 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07007859}
7860
7861static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
7862
7863static ssize_t show_statistics(struct device *d,
7864 struct device_attribute *attr, char *buf)
7865{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007866 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007867 u32 size = sizeof(struct iwl4965_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07007868 u32 len = 0, ofs = 0;
7869 u8 *data = (u8 *) & priv->statistics;
7870 int rc = 0;
7871
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007872 if (!iwl4965_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07007873 return -EAGAIN;
7874
7875 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007876 rc = iwl4965_send_statistics_request(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007877 mutex_unlock(&priv->mutex);
7878
7879 if (rc) {
7880 len = sprintf(buf,
7881 "Error sending statistics request: 0x%08X\n", rc);
7882 return len;
7883 }
7884
7885 while (size && (PAGE_SIZE - len)) {
7886 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
7887 PAGE_SIZE - len, 1);
7888 len = strlen(buf);
7889 if (PAGE_SIZE - len)
7890 buf[len++] = '\n';
7891
7892 ofs += 16;
7893 size -= min(size, 16U);
7894 }
7895
7896 return len;
7897}
7898
7899static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
7900
7901static ssize_t show_antenna(struct device *d,
7902 struct device_attribute *attr, char *buf)
7903{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007904 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07007905
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007906 if (!iwl4965_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07007907 return -EAGAIN;
7908
7909 return sprintf(buf, "%d\n", priv->antenna);
7910}
7911
7912static ssize_t store_antenna(struct device *d,
7913 struct device_attribute *attr,
7914 const char *buf, size_t count)
7915{
7916 int ant;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007917 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07007918
7919 if (count == 0)
7920 return 0;
7921
7922 if (sscanf(buf, "%1i", &ant) != 1) {
7923 IWL_DEBUG_INFO("not in hex or decimal form.\n");
7924 return count;
7925 }
7926
7927 if ((ant >= 0) && (ant <= 2)) {
7928 IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007929 priv->antenna = (enum iwl4965_antenna)ant;
Zhu Yib481de92007-09-25 17:54:57 -07007930 } else
7931 IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant);
7932
7933
7934 return count;
7935}
7936
7937static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
7938
7939static ssize_t show_status(struct device *d,
7940 struct device_attribute *attr, char *buf)
7941{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007942 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007943 if (!iwl4965_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07007944 return -EAGAIN;
7945 return sprintf(buf, "0x%08x\n", (int)priv->status);
7946}
7947
7948static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
7949
7950static ssize_t dump_error_log(struct device *d,
7951 struct device_attribute *attr,
7952 const char *buf, size_t count)
7953{
7954 char *p = (char *)buf;
7955
7956 if (p[0] == '1')
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007957 iwl4965_dump_nic_error_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07007958
7959 return strnlen(buf, count);
7960}
7961
7962static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
7963
7964static ssize_t dump_event_log(struct device *d,
7965 struct device_attribute *attr,
7966 const char *buf, size_t count)
7967{
7968 char *p = (char *)buf;
7969
7970 if (p[0] == '1')
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007971 iwl4965_dump_nic_event_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07007972
7973 return strnlen(buf, count);
7974}
7975
7976static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
7977
7978/*****************************************************************************
7979 *
7980 * driver setup and teardown
7981 *
7982 *****************************************************************************/
7983
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07007984static void iwl4965_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07007985{
7986 priv->workqueue = create_workqueue(DRV_NAME);
7987
7988 init_waitqueue_head(&priv->wait_command_queue);
7989
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007990 INIT_WORK(&priv->up, iwl4965_bg_up);
7991 INIT_WORK(&priv->restart, iwl4965_bg_restart);
7992 INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish);
7993 INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed);
7994 INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan);
7995 INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan);
7996 INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill);
7997 INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update);
7998 INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate);
7999 INIT_DELAYED_WORK(&priv->init_alive_start, iwl4965_bg_init_alive_start);
8000 INIT_DELAYED_WORK(&priv->alive_start, iwl4965_bg_alive_start);
8001 INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check);
Zhu Yib481de92007-09-25 17:54:57 -07008002
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008003 iwl4965_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008004
8005 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008006 iwl4965_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07008007}
8008
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07008009static void iwl4965_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07008010{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008011 iwl4965_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008012
Joonwoo Park3ae6a052007-11-29 10:43:16 +09008013 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07008014 cancel_delayed_work(&priv->scan_check);
8015 cancel_delayed_work(&priv->alive_start);
8016 cancel_delayed_work(&priv->post_associate);
8017 cancel_work_sync(&priv->beacon_update);
8018}
8019
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008020static struct attribute *iwl4965_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07008021 &dev_attr_antenna.attr,
8022 &dev_attr_channels.attr,
8023 &dev_attr_dump_errors.attr,
8024 &dev_attr_dump_events.attr,
8025 &dev_attr_flags.attr,
8026 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008027#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07008028 &dev_attr_measurement.attr,
8029#endif
8030 &dev_attr_power_level.attr,
8031 &dev_attr_retry_rate.attr,
8032 &dev_attr_rf_kill.attr,
8033 &dev_attr_rs_window.attr,
8034 &dev_attr_statistics.attr,
8035 &dev_attr_status.attr,
8036 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07008037 &dev_attr_tx_power.attr,
8038
8039 NULL
8040};
8041
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008042static struct attribute_group iwl4965_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07008043 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008044 .attrs = iwl4965_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07008045};
8046
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008047static struct ieee80211_ops iwl4965_hw_ops = {
8048 .tx = iwl4965_mac_tx,
8049 .start = iwl4965_mac_start,
8050 .stop = iwl4965_mac_stop,
8051 .add_interface = iwl4965_mac_add_interface,
8052 .remove_interface = iwl4965_mac_remove_interface,
8053 .config = iwl4965_mac_config,
8054 .config_interface = iwl4965_mac_config_interface,
8055 .configure_filter = iwl4965_configure_filter,
8056 .set_key = iwl4965_mac_set_key,
8057 .get_stats = iwl4965_mac_get_stats,
8058 .get_tx_stats = iwl4965_mac_get_tx_stats,
8059 .conf_tx = iwl4965_mac_conf_tx,
8060 .get_tsf = iwl4965_mac_get_tsf,
8061 .reset_tsf = iwl4965_mac_reset_tsf,
8062 .beacon_update = iwl4965_mac_beacon_update,
Johannes Berg471b3ef2007-12-28 14:32:58 +01008063 .bss_info_changed = iwl4965_bss_info_changed,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008064#ifdef CONFIG_IWL4965_HT
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008065 .conf_ht = iwl4965_mac_conf_ht,
Ron Rindjunsky9ab46172007-12-25 17:00:38 +02008066 .ampdu_action = iwl4965_mac_ampdu_action,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008067#endif /* CONFIG_IWL4965_HT */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008068 .hw_scan = iwl4965_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07008069};
8070
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008071static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07008072{
8073 int err = 0;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07008074 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07008075 struct ieee80211_hw *hw;
Tomas Winkler82b9a122008-03-04 18:09:30 -08008076 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Zhu Yi5a66926a2008-01-14 17:46:18 -08008077 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07008078
Assaf Krauss316c30d2008-03-14 10:38:46 -07008079 /************************
8080 * 1. Allocating HW data
8081 ************************/
8082
Cahill, Ben M6440adb2007-11-29 11:09:55 +08008083 /* Disabling hardware scan means that mac80211 will perform scans
8084 * "the hard way", rather than using device's scan. */
Assaf Krauss00acbc92008-03-14 10:38:47 -07008085 if (iwl4965_mod_params.disable_hw_scan) {
Zhu Yib481de92007-09-25 17:54:57 -07008086 IWL_DEBUG_INFO("Disabling hw_scan\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008087 iwl4965_hw_ops.hw_scan = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07008088 }
8089
Assaf Krauss1d0a0822008-03-14 10:38:48 -07008090 hw = iwl_alloc_all(cfg, &iwl4965_hw_ops);
8091 if (!hw) {
Zhu Yib481de92007-09-25 17:54:57 -07008092 err = -ENOMEM;
8093 goto out;
8094 }
Assaf Krauss1d0a0822008-03-14 10:38:48 -07008095 priv = hw->priv;
8096 /* At this point both hw and priv are allocated. */
8097
Zhu Yib481de92007-09-25 17:54:57 -07008098 SET_IEEE80211_DEV(hw, &pdev->dev);
8099
8100 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
Tomas Winkler82b9a122008-03-04 18:09:30 -08008101 priv->cfg = cfg;
Zhu Yib481de92007-09-25 17:54:57 -07008102 priv->pci_dev = pdev;
Assaf Krauss316c30d2008-03-14 10:38:46 -07008103
Tomas Winkler0a6857e2008-03-12 16:58:49 -07008104#ifdef CONFIG_IWLWIFI_DEBUG
Assaf Krauss00acbc92008-03-14 10:38:47 -07008105 iwl_debug_level = iwl4965_mod_params.debug;
Zhu Yib481de92007-09-25 17:54:57 -07008106 atomic_set(&priv->restrict_refcnt, 0);
8107#endif
Zhu Yib481de92007-09-25 17:54:57 -07008108
Assaf Krauss316c30d2008-03-14 10:38:46 -07008109 /**************************
8110 * 2. Initializing PCI bus
8111 **************************/
8112 if (pci_enable_device(pdev)) {
8113 err = -ENODEV;
8114 goto out_ieee80211_free_hw;
8115 }
8116
8117 pci_set_master(pdev);
8118
8119 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
8120 if (!err)
8121 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
8122 if (err) {
8123 printk(KERN_WARNING DRV_NAME
8124 ": No suitable DMA available.\n");
8125 goto out_pci_disable_device;
8126 }
8127
8128 err = pci_request_regions(pdev, DRV_NAME);
8129 if (err)
8130 goto out_pci_disable_device;
8131
8132 pci_set_drvdata(pdev, priv);
8133
8134 /* We disable the RETRY_TIMEOUT register (0x41) to keep
8135 * PCI Tx retries from interfering with C3 CPU state */
8136 pci_write_config_byte(pdev, 0x41, 0x00);
8137
8138 /***********************
8139 * 3. Read REV register
8140 ***********************/
8141 priv->hw_base = pci_iomap(pdev, 0, 0);
8142 if (!priv->hw_base) {
8143 err = -ENODEV;
8144 goto out_pci_release_regions;
8145 }
8146
8147 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
8148 (unsigned long long) pci_resource_len(pdev, 0));
8149 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
8150
8151 printk(KERN_INFO DRV_NAME
8152 ": Detected Intel Wireless WiFi Link %s\n", priv->cfg->name);
8153
8154 /*****************
8155 * 4. Read EEPROM
8156 *****************/
8157 /* nic init */
8158 iwl4965_set_bit(priv, CSR_GIO_CHICKEN_BITS,
8159 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
8160
8161 iwl4965_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
8162 err = iwl4965_poll_bit(priv, CSR_GP_CNTRL,
8163 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
8164 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
8165 if (err < 0) {
8166 IWL_DEBUG_INFO("Failed to init the card\n");
8167 goto out_iounmap;
8168 }
8169 /* Read the EEPROM */
8170 err = iwl_eeprom_init(priv);
8171 if (err) {
8172 IWL_ERROR("Unable to init EEPROM\n");
8173 goto out_iounmap;
8174 }
8175 /* MAC Address location in EEPROM same for 3945/4965 */
8176 iwl_eeprom_get_mac(priv, priv->mac_addr);
8177 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr));
8178 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
8179
8180 /************************
8181 * 5. Setup HW constants
8182 ************************/
8183 /* Device-specific setup */
8184 if (iwl4965_hw_set_hw_setting(priv)) {
8185 IWL_ERROR("failed to set hw settings\n");
8186 goto out_iounmap;
8187 }
8188
8189 /*******************
8190 * 6. Setup hw/priv
8191 *******************/
Zhu Yib481de92007-09-25 17:54:57 -07008192
Assaf Kraussbf85ea42008-03-14 10:38:49 -07008193 err = iwl_setup(priv);
8194 if (err)
Assaf Krauss316c30d2008-03-14 10:38:46 -07008195 goto out_unset_hw_settings;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07008196 /* At this point both hw and priv are initialized. */
Assaf Krauss316c30d2008-03-14 10:38:46 -07008197
8198 /**********************************
8199 * 7. Initialize module parameters
8200 **********************************/
8201
8202 /* Disable radio (SW RF KILL) via parameter when loading driver */
Assaf Krauss00acbc92008-03-14 10:38:47 -07008203 if (iwl4965_mod_params.disable) {
Assaf Krauss316c30d2008-03-14 10:38:46 -07008204 set_bit(STATUS_RF_KILL_SW, &priv->status);
8205 IWL_DEBUG_INFO("Radio disabled.\n");
8206 }
8207
Assaf Krauss00acbc92008-03-14 10:38:47 -07008208 if (iwl4965_mod_params.enable_qos)
Assaf Krauss316c30d2008-03-14 10:38:46 -07008209 priv->qos_data.qos_enable = 1;
8210
8211 /********************
8212 * 8. Setup services
8213 ********************/
8214 iwl4965_disable_interrupts(priv);
8215
8216 err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
8217 if (err) {
8218 IWL_ERROR("failed to create sysfs device attributes\n");
Assaf Kraussbf85ea42008-03-14 10:38:49 -07008219 goto out_unset_hw_settings;
Assaf Krauss316c30d2008-03-14 10:38:46 -07008220 }
8221
8222 err = iwl_dbgfs_register(priv, DRV_NAME);
8223 if (err) {
8224 IWL_ERROR("failed to create debugfs files\n");
8225 goto out_remove_sysfs;
8226 }
8227
8228 iwl4965_setup_deferred_work(priv);
8229 iwl4965_setup_rx_handlers(priv);
8230
8231 /********************
8232 * 9. Conclude
8233 ********************/
Zhu Yi5a66926a2008-01-14 17:46:18 -08008234 pci_save_state(pdev);
8235 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07008236
8237 return 0;
8238
Assaf Krauss316c30d2008-03-14 10:38:46 -07008239 out_remove_sysfs:
8240 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
Assaf Krauss316c30d2008-03-14 10:38:46 -07008241 out_unset_hw_settings:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008242 iwl4965_unset_hw_setting(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008243 out_iounmap:
8244 pci_iounmap(pdev, priv->hw_base);
8245 out_pci_release_regions:
8246 pci_release_regions(pdev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07008247 pci_set_drvdata(pdev, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07008248 out_pci_disable_device:
8249 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07008250 out_ieee80211_free_hw:
8251 ieee80211_free_hw(priv->hw);
8252 out:
8253 return err;
8254}
8255
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008256static void iwl4965_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07008257{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07008258 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07008259 struct list_head *p, *q;
8260 int i;
8261
8262 if (!priv)
8263 return;
8264
8265 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
8266
Zhu Yib481de92007-09-25 17:54:57 -07008267 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08008268
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008269 iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008270
8271 /* Free MAC hash list for ADHOC */
8272 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
8273 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
8274 list_del(p);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008275 kfree(list_entry(p, struct iwl4965_ibss_seq, list));
Zhu Yib481de92007-09-25 17:54:57 -07008276 }
8277 }
8278
Tomas Winkler712b6cf2008-03-12 16:58:52 -07008279 iwl_dbgfs_unregister(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008280 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07008281
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008282 iwl4965_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008283
8284 if (priv->rxq.bd)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008285 iwl4965_rx_queue_free(priv, &priv->rxq);
8286 iwl4965_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008287
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008288 iwl4965_unset_hw_setting(priv);
Assaf Kraussbf85ea42008-03-14 10:38:49 -07008289 iwlcore_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008290
8291 if (priv->mac80211_registered) {
8292 ieee80211_unregister_hw(priv->hw);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008293 iwl4965_rate_control_unregister(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07008294 }
8295
Mohamed Abbas948c1712007-10-25 17:15:45 +08008296 /*netif_stop_queue(dev); */
8297 flush_workqueue(priv->workqueue);
8298
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008299 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07008300 * priv->workqueue... so we can't take down the workqueue
8301 * until now... */
8302 destroy_workqueue(priv->workqueue);
8303 priv->workqueue = NULL;
8304
Zhu Yib481de92007-09-25 17:54:57 -07008305 pci_iounmap(pdev, priv->hw_base);
8306 pci_release_regions(pdev);
8307 pci_disable_device(pdev);
8308 pci_set_drvdata(pdev, NULL);
8309
Assaf Kraussbf85ea42008-03-14 10:38:49 -07008310 iwl_free_channel_map(priv);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08008311 iwl4965_free_geos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008312
8313 if (priv->ibss_beacon)
8314 dev_kfree_skb(priv->ibss_beacon);
8315
8316 ieee80211_free_hw(priv->hw);
8317}
8318
8319#ifdef CONFIG_PM
8320
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008321static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07008322{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07008323 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07008324
Zhu Yie655b9f2008-01-24 02:19:38 -08008325 if (priv->is_open) {
8326 set_bit(STATUS_IN_SUSPEND, &priv->status);
8327 iwl4965_mac_stop(priv->hw);
8328 priv->is_open = 1;
8329 }
Zhu Yib481de92007-09-25 17:54:57 -07008330
Zhu Yib481de92007-09-25 17:54:57 -07008331 pci_set_power_state(pdev, PCI_D3hot);
8332
Zhu Yib481de92007-09-25 17:54:57 -07008333 return 0;
8334}
8335
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008336static int iwl4965_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07008337{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07008338 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07008339
Zhu Yib481de92007-09-25 17:54:57 -07008340 pci_set_power_state(pdev, PCI_D0);
Zhu Yib481de92007-09-25 17:54:57 -07008341
Zhu Yie655b9f2008-01-24 02:19:38 -08008342 if (priv->is_open)
8343 iwl4965_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07008344
Zhu Yie655b9f2008-01-24 02:19:38 -08008345 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07008346 return 0;
8347}
8348
8349#endif /* CONFIG_PM */
8350
8351/*****************************************************************************
8352 *
8353 * driver and module entry point
8354 *
8355 *****************************************************************************/
8356
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008357static struct pci_driver iwl4965_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07008358 .name = DRV_NAME,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008359 .id_table = iwl4965_hw_card_ids,
8360 .probe = iwl4965_pci_probe,
8361 .remove = __devexit_p(iwl4965_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07008362#ifdef CONFIG_PM
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008363 .suspend = iwl4965_pci_suspend,
8364 .resume = iwl4965_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07008365#endif
8366};
8367
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008368static int __init iwl4965_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07008369{
8370
8371 int ret;
8372 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
8373 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008374 ret = pci_register_driver(&iwl4965_driver);
Zhu Yib481de92007-09-25 17:54:57 -07008375 if (ret) {
8376 IWL_ERROR("Unable to initialize PCI module\n");
8377 return ret;
8378 }
Tomas Winkler0a6857e2008-03-12 16:58:49 -07008379#ifdef CONFIG_IWLWIFI_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008380 ret = driver_create_file(&iwl4965_driver.driver, &driver_attr_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07008381 if (ret) {
8382 IWL_ERROR("Unable to create driver sysfs file\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008383 pci_unregister_driver(&iwl4965_driver);
Zhu Yib481de92007-09-25 17:54:57 -07008384 return ret;
8385 }
8386#endif
8387
8388 return ret;
8389}
8390
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008391static void __exit iwl4965_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07008392{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07008393#ifdef CONFIG_IWLWIFI_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008394 driver_remove_file(&iwl4965_driver.driver, &driver_attr_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07008395#endif
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008396 pci_unregister_driver(&iwl4965_driver);
Zhu Yib481de92007-09-25 17:54:57 -07008397}
8398
Assaf Krauss00acbc92008-03-14 10:38:47 -07008399module_param_named(antenna, iwl4965_mod_params.antenna, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07008400MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
Assaf Krauss00acbc92008-03-14 10:38:47 -07008401module_param_named(disable, iwl4965_mod_params.disable, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07008402MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
Assaf Krauss00acbc92008-03-14 10:38:47 -07008403module_param_named(hwcrypto, iwl4965_mod_params.hw_crypto, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07008404MODULE_PARM_DESC(hwcrypto,
8405 "using hardware crypto engine (default 0 [software])\n");
Assaf Krauss00acbc92008-03-14 10:38:47 -07008406module_param_named(debug, iwl4965_mod_params.debug, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07008407MODULE_PARM_DESC(debug, "debug output mask");
Assaf Krauss00acbc92008-03-14 10:38:47 -07008408module_param_named(
8409 disable_hw_scan, iwl4965_mod_params.disable_hw_scan, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07008410MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
8411
Assaf Krauss00acbc92008-03-14 10:38:47 -07008412module_param_named(queues_num, iwl4965_mod_params.num_of_queues, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07008413MODULE_PARM_DESC(queues_num, "number of hw queues.");
8414
8415/* QoS */
Assaf Krauss00acbc92008-03-14 10:38:47 -07008416module_param_named(qos_enable, iwl4965_mod_params.enable_qos, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07008417MODULE_PARM_DESC(qos_enable, "enable all QoS functionality");
Assaf Krauss00acbc92008-03-14 10:38:47 -07008418module_param_named(amsdu_size_8K, iwl4965_mod_params.amsdu_size_8K, int, 0444);
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02008419MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
Zhu Yib481de92007-09-25 17:54:57 -07008420
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008421module_exit(iwl4965_exit);
8422module_init(iwl4965_init);