blob: 41cabd6184965d0aa5d69203fff650ae03012269 [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
3 * Copyright(c) 2003 - 2007 Intel Corporation. All rights reserved.
4 *
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
30/*
31 * NOTE: This file (iwl-base.c) is used to build to multiple hardware targets
32 * by defining IWL to either 3945 or 4965. The Makefile used when building
33 * the base targets will create base-3945.o and base-4965.o
34 *
35 * The eventual goal is to move as many of the #if IWL / #endif blocks out of
36 * this file and into the hardware specific implementation files (iwl-XXXX.c)
37 * and leave only the common (non #ifdef sprinkled) code in this file
38 */
39
40#include <linux/kernel.h>
41#include <linux/module.h>
42#include <linux/version.h>
43#include <linux/init.h>
44#include <linux/pci.h>
45#include <linux/dma-mapping.h>
46#include <linux/delay.h>
47#include <linux/skbuff.h>
48#include <linux/netdevice.h>
49#include <linux/wireless.h>
50#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070051#include <linux/etherdevice.h>
52#include <linux/if_arp.h>
53
54#include <net/ieee80211_radiotap.h>
55#include <net/mac80211.h>
56
57#include <asm/div64.h>
58
Zhu Yib481de92007-09-25 17:54:57 -070059#include "iwl-4965.h"
60#include "iwl-helpers.h"
61
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080062#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -080063u32 iwl4965_debug_level;
Zhu Yib481de92007-09-25 17:54:57 -070064#endif
65
Christoph Hellwigbb8c0932008-01-27 16:41:47 -080066static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv,
67 struct iwl4965_tx_queue *txq);
Christoph Hellwig416e1432007-10-25 17:15:49 +080068
Zhu Yib481de92007-09-25 17:54:57 -070069/******************************************************************************
70 *
71 * module boiler plate
72 *
73 ******************************************************************************/
74
75/* module parameters */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -080076static int iwl4965_param_disable_hw_scan;
77static int iwl4965_param_debug;
78static int iwl4965_param_disable; /* def: enable radio */
79static int iwl4965_param_antenna; /* def: 0 = both antennas (use diversity) */
80int iwl4965_param_hwcrypto; /* def: using software encryption */
81static int iwl4965_param_qos_enable = 1;
82int iwl4965_param_queues_num = IWL_MAX_NUM_QUEUES;
Zhu Yib481de92007-09-25 17:54:57 -070083
84/*
85 * module name, copyright, version, etc.
86 * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
87 */
88
89#define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux"
90
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080091#ifdef CONFIG_IWL4965_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070092#define VD "d"
93#else
94#define VD
95#endif
96
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080097#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070098#define VS "s"
99#else
100#define VS
101#endif
102
Zhu Yi80f3e022007-10-25 17:15:48 +0800103#define IWLWIFI_VERSION "1.1.19k" VD VS
Zhu Yib481de92007-09-25 17:54:57 -0700104#define DRV_COPYRIGHT "Copyright(c) 2003-2007 Intel Corporation"
105#define DRV_VERSION IWLWIFI_VERSION
106
107/* Change firmware file name, using "-" and incrementing number,
108 * *only* when uCode interface or architecture changes so that it
109 * is not compatible with earlier drivers.
110 * This number will also appear in << 8 position of 1st dword of uCode file */
111#define IWL4965_UCODE_API "-1"
112
113MODULE_DESCRIPTION(DRV_DESCRIPTION);
114MODULE_VERSION(DRV_VERSION);
115MODULE_AUTHOR(DRV_COPYRIGHT);
116MODULE_LICENSE("GPL");
117
118__le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr)
119{
120 u16 fc = le16_to_cpu(hdr->frame_control);
121 int hdr_len = ieee80211_get_hdrlen(fc);
122
123 if ((fc & 0x00cc) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA))
124 return (__le16 *) ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN);
125 return NULL;
126}
127
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800128static const struct ieee80211_hw_mode *iwl4965_get_hw_mode(
129 struct iwl4965_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700130{
131 int i;
132
133 for (i = 0; i < 3; i++)
134 if (priv->modes[i].mode == mode)
135 return &priv->modes[i];
136
137 return NULL;
138}
139
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800140static int iwl4965_is_empty_essid(const char *essid, int essid_len)
Zhu Yib481de92007-09-25 17:54:57 -0700141{
142 /* Single white space is for Linksys APs */
143 if (essid_len == 1 && essid[0] == ' ')
144 return 1;
145
146 /* Otherwise, if the entire essid is 0, we assume it is hidden */
147 while (essid_len) {
148 essid_len--;
149 if (essid[essid_len] != '\0')
150 return 0;
151 }
152
153 return 1;
154}
155
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800156static const char *iwl4965_escape_essid(const char *essid, u8 essid_len)
Zhu Yib481de92007-09-25 17:54:57 -0700157{
158 static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
159 const char *s = essid;
160 char *d = escaped;
161
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800162 if (iwl4965_is_empty_essid(essid, essid_len)) {
Zhu Yib481de92007-09-25 17:54:57 -0700163 memcpy(escaped, "<hidden>", sizeof("<hidden>"));
164 return escaped;
165 }
166
167 essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE);
168 while (essid_len--) {
169 if (*s == '\0') {
170 *d++ = '\\';
171 *d++ = '0';
172 s++;
173 } else
174 *d++ = *s++;
175 }
176 *d = '\0';
177 return escaped;
178}
179
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800180static void iwl4965_print_hex_dump(int level, void *p, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -0700181{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800182#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800183 if (!(iwl4965_debug_level & level))
Zhu Yib481de92007-09-25 17:54:57 -0700184 return;
185
186 print_hex_dump(KERN_DEBUG, "iwl data: ", DUMP_PREFIX_OFFSET, 16, 1,
187 p, len, 1);
188#endif
189}
190
191/*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
192 * DMA services
193 *
194 * Theory of operation
195 *
196 * A queue is a circular buffers with 'Read' and 'Write' pointers.
197 * 2 empty entries always kept in the buffer to protect from overflow.
198 *
199 * For Tx queue, there are low mark and high mark limits. If, after queuing
200 * the packet for Tx, free space become < low mark, Tx queue stopped. When
201 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
202 * Tx queue resumed.
203 *
Zhu Yi583fab32007-09-27 11:27:30 +0800204 * The IWL operates with six queues, one receive queue in the device's
Zhu Yib481de92007-09-25 17:54:57 -0700205 * sram, one transmit queue for sending commands to the device firmware,
206 * and four transmit queues for data.
207 ***************************************************/
208
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800209static int iwl4965_queue_space(const struct iwl4965_queue *q)
Zhu Yib481de92007-09-25 17:54:57 -0700210{
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800211 int s = q->read_ptr - q->write_ptr;
Zhu Yib481de92007-09-25 17:54:57 -0700212
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800213 if (q->read_ptr > q->write_ptr)
Zhu Yib481de92007-09-25 17:54:57 -0700214 s -= q->n_bd;
215
216 if (s <= 0)
217 s += q->n_window;
218 /* keep some reserve to not confuse empty and full situations */
219 s -= 2;
220 if (s < 0)
221 s = 0;
222 return s;
223}
224
225/* XXX: n_bd must be power-of-two size */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800226static inline int iwl4965_queue_inc_wrap(int index, int n_bd)
Zhu Yib481de92007-09-25 17:54:57 -0700227{
228 return ++index & (n_bd - 1);
229}
230
231/* XXX: n_bd must be power-of-two size */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800232static inline int iwl4965_queue_dec_wrap(int index, int n_bd)
Zhu Yib481de92007-09-25 17:54:57 -0700233{
234 return --index & (n_bd - 1);
235}
236
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800237static inline int x2_queue_used(const struct iwl4965_queue *q, int i)
Zhu Yib481de92007-09-25 17:54:57 -0700238{
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800239 return q->write_ptr > q->read_ptr ?
240 (i >= q->read_ptr && i < q->write_ptr) :
241 !(i < q->read_ptr && i >= q->write_ptr);
Zhu Yib481de92007-09-25 17:54:57 -0700242}
243
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800244static inline u8 get_cmd_index(struct iwl4965_queue *q, u32 index, int is_huge)
Zhu Yib481de92007-09-25 17:54:57 -0700245{
246 if (is_huge)
247 return q->n_window;
248
249 return index & (q->n_window - 1);
250}
251
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800252static int iwl4965_queue_init(struct iwl4965_priv *priv, struct iwl4965_queue *q,
Zhu Yib481de92007-09-25 17:54:57 -0700253 int count, int slots_num, u32 id)
254{
255 q->n_bd = count;
256 q->n_window = slots_num;
257 q->id = id;
258
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800259 /* count must be power-of-two size, otherwise iwl4965_queue_inc_wrap
260 * and iwl4965_queue_dec_wrap are broken. */
Zhu Yib481de92007-09-25 17:54:57 -0700261 BUG_ON(!is_power_of_2(count));
262
263 /* slots_num must be power-of-two size, otherwise
264 * get_cmd_index is broken. */
265 BUG_ON(!is_power_of_2(slots_num));
266
267 q->low_mark = q->n_window / 4;
268 if (q->low_mark < 4)
269 q->low_mark = 4;
270
271 q->high_mark = q->n_window / 8;
272 if (q->high_mark < 2)
273 q->high_mark = 2;
274
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800275 q->write_ptr = q->read_ptr = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700276
277 return 0;
278}
279
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800280static int iwl4965_tx_queue_alloc(struct iwl4965_priv *priv,
281 struct iwl4965_tx_queue *txq, u32 id)
Zhu Yib481de92007-09-25 17:54:57 -0700282{
283 struct pci_dev *dev = priv->pci_dev;
284
285 if (id != IWL_CMD_QUEUE_NUM) {
286 txq->txb = kmalloc(sizeof(txq->txb[0]) *
287 TFD_QUEUE_SIZE_MAX, GFP_KERNEL);
288 if (!txq->txb) {
Ian Schram01ebd062007-10-25 17:15:22 +0800289 IWL_ERROR("kmalloc for auxiliary BD "
Zhu Yib481de92007-09-25 17:54:57 -0700290 "structures failed\n");
291 goto error;
292 }
293 } else
294 txq->txb = NULL;
295
296 txq->bd = pci_alloc_consistent(dev,
297 sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX,
298 &txq->q.dma_addr);
299
300 if (!txq->bd) {
301 IWL_ERROR("pci_alloc_consistent(%zd) failed\n",
302 sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX);
303 goto error;
304 }
305 txq->q.id = id;
306
307 return 0;
308
309 error:
310 if (txq->txb) {
311 kfree(txq->txb);
312 txq->txb = NULL;
313 }
314
315 return -ENOMEM;
316}
317
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800318int iwl4965_tx_queue_init(struct iwl4965_priv *priv,
319 struct iwl4965_tx_queue *txq, int slots_num, u32 txq_id)
Zhu Yib481de92007-09-25 17:54:57 -0700320{
321 struct pci_dev *dev = priv->pci_dev;
322 int len;
323 int rc = 0;
324
Ian Schram01ebd062007-10-25 17:15:22 +0800325 /* allocate command space + one big command for scan since scan
Zhu Yib481de92007-09-25 17:54:57 -0700326 * command is very huge the system will not have two scan at the
327 * same time */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800328 len = sizeof(struct iwl4965_cmd) * slots_num;
Zhu Yib481de92007-09-25 17:54:57 -0700329 if (txq_id == IWL_CMD_QUEUE_NUM)
330 len += IWL_MAX_SCAN_SIZE;
331 txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd);
332 if (!txq->cmd)
333 return -ENOMEM;
334
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800335 rc = iwl4965_tx_queue_alloc(priv, txq, txq_id);
Zhu Yib481de92007-09-25 17:54:57 -0700336 if (rc) {
337 pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
338
339 return -ENOMEM;
340 }
341 txq->need_update = 0;
342
343 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800344 * iwl4965_queue_inc_wrap and iwl4965_queue_dec_wrap are broken. */
Zhu Yib481de92007-09-25 17:54:57 -0700345 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800346 iwl4965_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id);
Zhu Yib481de92007-09-25 17:54:57 -0700347
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800348 iwl4965_hw_tx_queue_init(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -0700349
350 return 0;
351}
352
353/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800354 * iwl4965_tx_queue_free - Deallocate DMA queue.
Zhu Yib481de92007-09-25 17:54:57 -0700355 * @txq: Transmit queue to deallocate.
356 *
357 * Empty queue by removing and destroying all BD's.
358 * Free all buffers. txq itself is not freed.
359 *
360 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800361void iwl4965_tx_queue_free(struct iwl4965_priv *priv, struct iwl4965_tx_queue *txq)
Zhu Yib481de92007-09-25 17:54:57 -0700362{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800363 struct iwl4965_queue *q = &txq->q;
Zhu Yib481de92007-09-25 17:54:57 -0700364 struct pci_dev *dev = priv->pci_dev;
365 int len;
366
367 if (q->n_bd == 0)
368 return;
369
370 /* first, empty all BD's */
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800371 for (; q->write_ptr != q->read_ptr;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800372 q->read_ptr = iwl4965_queue_inc_wrap(q->read_ptr, q->n_bd))
373 iwl4965_hw_txq_free_tfd(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -0700374
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800375 len = sizeof(struct iwl4965_cmd) * q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -0700376 if (q->id == IWL_CMD_QUEUE_NUM)
377 len += IWL_MAX_SCAN_SIZE;
378
379 pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
380
381 /* free buffers belonging to queue itself */
382 if (txq->q.n_bd)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800383 pci_free_consistent(dev, sizeof(struct iwl4965_tfd_frame) *
Zhu Yib481de92007-09-25 17:54:57 -0700384 txq->q.n_bd, txq->bd, txq->q.dma_addr);
385
386 if (txq->txb) {
387 kfree(txq->txb);
388 txq->txb = NULL;
389 }
390
391 /* 0 fill whole structure */
392 memset(txq, 0, sizeof(*txq));
393}
394
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800395const u8 iwl4965_broadcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
Zhu Yib481de92007-09-25 17:54:57 -0700396
397/*************** STATION TABLE MANAGEMENT ****
398 *
399 * NOTE: This needs to be overhauled to better synchronize between
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800400 * how the iwl-4965.c is using iwl4965_hw_find_station vs. iwl-3945.c
Zhu Yib481de92007-09-25 17:54:57 -0700401 *
402 * mac80211 should also be examined to determine if sta_info is duplicating
403 * the functionality provided here
404 */
405
406/**************************************************************/
407
Ian Schram01ebd062007-10-25 17:15:22 +0800408#if 0 /* temporary disable till we add real remove station */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800409static u8 iwl4965_remove_station(struct iwl4965_priv *priv, const u8 *addr, int is_ap)
Zhu Yib481de92007-09-25 17:54:57 -0700410{
411 int index = IWL_INVALID_STATION;
412 int i;
413 unsigned long flags;
414
415 spin_lock_irqsave(&priv->sta_lock, flags);
416
417 if (is_ap)
418 index = IWL_AP_ID;
419 else if (is_broadcast_ether_addr(addr))
420 index = priv->hw_setting.bcast_sta_id;
421 else
422 for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++)
423 if (priv->stations[i].used &&
424 !compare_ether_addr(priv->stations[i].sta.sta.addr,
425 addr)) {
426 index = i;
427 break;
428 }
429
430 if (unlikely(index == IWL_INVALID_STATION))
431 goto out;
432
433 if (priv->stations[index].used) {
434 priv->stations[index].used = 0;
435 priv->num_stations--;
436 }
437
438 BUG_ON(priv->num_stations < 0);
439
440out:
441 spin_unlock_irqrestore(&priv->sta_lock, flags);
442 return 0;
443}
Zhu Yi556f8db2007-09-27 11:27:33 +0800444#endif
Zhu Yib481de92007-09-25 17:54:57 -0700445
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800446static void iwl4965_clear_stations_table(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700447{
448 unsigned long flags;
449
450 spin_lock_irqsave(&priv->sta_lock, flags);
451
452 priv->num_stations = 0;
453 memset(priv->stations, 0, sizeof(priv->stations));
454
455 spin_unlock_irqrestore(&priv->sta_lock, flags);
456}
457
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800458u8 iwl4965_add_station_flags(struct iwl4965_priv *priv, const u8 *addr, int is_ap, u8 flags)
Zhu Yib481de92007-09-25 17:54:57 -0700459{
460 int i;
461 int index = IWL_INVALID_STATION;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800462 struct iwl4965_station_entry *station;
Zhu Yib481de92007-09-25 17:54:57 -0700463 unsigned long flags_spin;
Joe Perches0795af52007-10-03 17:59:30 -0700464 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -0700465
466 spin_lock_irqsave(&priv->sta_lock, flags_spin);
467 if (is_ap)
468 index = IWL_AP_ID;
469 else if (is_broadcast_ether_addr(addr))
470 index = priv->hw_setting.bcast_sta_id;
471 else
472 for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) {
473 if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
474 addr)) {
475 index = i;
476 break;
477 }
478
479 if (!priv->stations[i].used &&
480 index == IWL_INVALID_STATION)
481 index = i;
482 }
483
484
Ian Schram01ebd062007-10-25 17:15:22 +0800485 /* These two conditions has the same outcome but keep them separate
Zhu Yib481de92007-09-25 17:54:57 -0700486 since they have different meaning */
487 if (unlikely(index == IWL_INVALID_STATION)) {
488 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
489 return index;
490 }
491
492 if (priv->stations[index].used &&
493 !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) {
494 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
495 return index;
496 }
497
498
Joe Perches0795af52007-10-03 17:59:30 -0700499 IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index, print_mac(mac, addr));
Zhu Yib481de92007-09-25 17:54:57 -0700500 station = &priv->stations[index];
501 station->used = 1;
502 priv->num_stations++;
503
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800504 memset(&station->sta, 0, sizeof(struct iwl4965_addsta_cmd));
Zhu Yib481de92007-09-25 17:54:57 -0700505 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
506 station->sta.mode = 0;
507 station->sta.sta.sta_id = index;
508 station->sta.station_flags = 0;
509
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800510#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -0700511 /* BCAST station and IBSS stations do not work in HT mode */
512 if (index != priv->hw_setting.bcast_sta_id &&
513 priv->iw_mode != IEEE80211_IF_TYPE_IBSS)
514 iwl4965_set_ht_add_station(priv, index);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800515#endif /*CONFIG_IWL4965_HT*/
Zhu Yib481de92007-09-25 17:54:57 -0700516
517 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800518 iwl4965_send_add_station(priv, &station->sta, flags);
Zhu Yib481de92007-09-25 17:54:57 -0700519 return index;
520
521}
522
523/*************** DRIVER STATUS FUNCTIONS *****/
524
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800525static inline int iwl4965_is_ready(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700526{
527 /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are
528 * set but EXIT_PENDING is not */
529 return test_bit(STATUS_READY, &priv->status) &&
530 test_bit(STATUS_GEO_CONFIGURED, &priv->status) &&
531 !test_bit(STATUS_EXIT_PENDING, &priv->status);
532}
533
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800534static inline int iwl4965_is_alive(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700535{
536 return test_bit(STATUS_ALIVE, &priv->status);
537}
538
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800539static inline int iwl4965_is_init(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700540{
541 return test_bit(STATUS_INIT, &priv->status);
542}
543
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800544static inline int iwl4965_is_rfkill(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700545{
546 return test_bit(STATUS_RF_KILL_HW, &priv->status) ||
547 test_bit(STATUS_RF_KILL_SW, &priv->status);
548}
549
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800550static inline int iwl4965_is_ready_rf(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700551{
552
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800553 if (iwl4965_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700554 return 0;
555
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800556 return iwl4965_is_ready(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700557}
558
559/*************** HOST COMMAND QUEUE FUNCTIONS *****/
560
561#define IWL_CMD(x) case x : return #x
562
563static const char *get_cmd_string(u8 cmd)
564{
565 switch (cmd) {
566 IWL_CMD(REPLY_ALIVE);
567 IWL_CMD(REPLY_ERROR);
568 IWL_CMD(REPLY_RXON);
569 IWL_CMD(REPLY_RXON_ASSOC);
570 IWL_CMD(REPLY_QOS_PARAM);
571 IWL_CMD(REPLY_RXON_TIMING);
572 IWL_CMD(REPLY_ADD_STA);
573 IWL_CMD(REPLY_REMOVE_STA);
574 IWL_CMD(REPLY_REMOVE_ALL_STA);
575 IWL_CMD(REPLY_TX);
576 IWL_CMD(REPLY_RATE_SCALE);
577 IWL_CMD(REPLY_LEDS_CMD);
578 IWL_CMD(REPLY_TX_LINK_QUALITY_CMD);
579 IWL_CMD(RADAR_NOTIFICATION);
580 IWL_CMD(REPLY_QUIET_CMD);
581 IWL_CMD(REPLY_CHANNEL_SWITCH);
582 IWL_CMD(CHANNEL_SWITCH_NOTIFICATION);
583 IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD);
584 IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION);
585 IWL_CMD(POWER_TABLE_CMD);
586 IWL_CMD(PM_SLEEP_NOTIFICATION);
587 IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC);
588 IWL_CMD(REPLY_SCAN_CMD);
589 IWL_CMD(REPLY_SCAN_ABORT_CMD);
590 IWL_CMD(SCAN_START_NOTIFICATION);
591 IWL_CMD(SCAN_RESULTS_NOTIFICATION);
592 IWL_CMD(SCAN_COMPLETE_NOTIFICATION);
593 IWL_CMD(BEACON_NOTIFICATION);
594 IWL_CMD(REPLY_TX_BEACON);
595 IWL_CMD(WHO_IS_AWAKE_NOTIFICATION);
596 IWL_CMD(QUIET_NOTIFICATION);
597 IWL_CMD(REPLY_TX_PWR_TABLE_CMD);
598 IWL_CMD(MEASURE_ABORT_NOTIFICATION);
599 IWL_CMD(REPLY_BT_CONFIG);
600 IWL_CMD(REPLY_STATISTICS_CMD);
601 IWL_CMD(STATISTICS_NOTIFICATION);
602 IWL_CMD(REPLY_CARD_STATE_CMD);
603 IWL_CMD(CARD_STATE_NOTIFICATION);
604 IWL_CMD(MISSED_BEACONS_NOTIFICATION);
605 IWL_CMD(REPLY_CT_KILL_CONFIG_CMD);
606 IWL_CMD(SENSITIVITY_CMD);
607 IWL_CMD(REPLY_PHY_CALIBRATION_CMD);
608 IWL_CMD(REPLY_RX_PHY_CMD);
609 IWL_CMD(REPLY_RX_MPDU_CMD);
610 IWL_CMD(REPLY_4965_RX);
611 IWL_CMD(REPLY_COMPRESSED_BA);
612 default:
613 return "UNKNOWN";
614
615 }
616}
617
618#define HOST_COMPLETE_TIMEOUT (HZ / 2)
619
620/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800621 * iwl4965_enqueue_hcmd - enqueue a uCode command
Zhu Yib481de92007-09-25 17:54:57 -0700622 * @priv: device private data point
623 * @cmd: a point to the ucode command structure
624 *
625 * The function returns < 0 values to indicate the operation is
626 * failed. On success, it turns the index (> 0) of command in the
627 * command queue.
628 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800629static int iwl4965_enqueue_hcmd(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd)
Zhu Yib481de92007-09-25 17:54:57 -0700630{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800631 struct iwl4965_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
632 struct iwl4965_queue *q = &txq->q;
633 struct iwl4965_tfd_frame *tfd;
Zhu Yib481de92007-09-25 17:54:57 -0700634 u32 *control_flags;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800635 struct iwl4965_cmd *out_cmd;
Zhu Yib481de92007-09-25 17:54:57 -0700636 u32 idx;
637 u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
638 dma_addr_t phys_addr;
639 int ret;
640 unsigned long flags;
641
642 /* If any of the command structures end up being larger than
643 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
644 * we will need to increase the size of the TFD entries */
645 BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
646 !(cmd->meta.flags & CMD_SIZE_HUGE));
647
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800648 if (iwl4965_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) {
Zhu Yib481de92007-09-25 17:54:57 -0700649 IWL_ERROR("No space for Tx\n");
650 return -ENOSPC;
651 }
652
653 spin_lock_irqsave(&priv->hcmd_lock, flags);
654
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800655 tfd = &txq->bd[q->write_ptr];
Zhu Yib481de92007-09-25 17:54:57 -0700656 memset(tfd, 0, sizeof(*tfd));
657
658 control_flags = (u32 *) tfd;
659
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800660 idx = get_cmd_index(q, q->write_ptr, cmd->meta.flags & CMD_SIZE_HUGE);
Zhu Yib481de92007-09-25 17:54:57 -0700661 out_cmd = &txq->cmd[idx];
662
663 out_cmd->hdr.cmd = cmd->id;
664 memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta));
665 memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len);
666
667 /* At this point, the out_cmd now has all of the incoming cmd
668 * information */
669
670 out_cmd->hdr.flags = 0;
671 out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800672 INDEX_TO_SEQ(q->write_ptr));
Zhu Yib481de92007-09-25 17:54:57 -0700673 if (out_cmd->meta.flags & CMD_SIZE_HUGE)
674 out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME);
675
676 phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800677 offsetof(struct iwl4965_cmd, hdr);
678 iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size);
Zhu Yib481de92007-09-25 17:54:57 -0700679
680 IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
681 "%d bytes at %d[%d]:%d\n",
682 get_cmd_string(out_cmd->hdr.cmd),
683 out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence),
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800684 fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM);
Zhu Yib481de92007-09-25 17:54:57 -0700685
686 txq->need_update = 1;
687 ret = iwl4965_tx_queue_update_wr_ptr(priv, txq, 0);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800688 q->write_ptr = iwl4965_queue_inc_wrap(q->write_ptr, q->n_bd);
689 iwl4965_tx_queue_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -0700690
691 spin_unlock_irqrestore(&priv->hcmd_lock, flags);
692 return ret ? ret : idx;
693}
694
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800695static int iwl4965_send_cmd_async(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd)
Zhu Yib481de92007-09-25 17:54:57 -0700696{
697 int ret;
698
699 BUG_ON(!(cmd->meta.flags & CMD_ASYNC));
700
701 /* An asynchronous command can not expect an SKB to be set. */
702 BUG_ON(cmd->meta.flags & CMD_WANT_SKB);
703
704 /* An asynchronous command MUST have a callback. */
705 BUG_ON(!cmd->meta.u.callback);
706
707 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
708 return -EBUSY;
709
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800710 ret = iwl4965_enqueue_hcmd(priv, cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700711 if (ret < 0) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800712 IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700713 get_cmd_string(cmd->id), ret);
714 return ret;
715 }
716 return 0;
717}
718
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800719static int iwl4965_send_cmd_sync(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd)
Zhu Yib481de92007-09-25 17:54:57 -0700720{
721 int cmd_idx;
722 int ret;
723 static atomic_t entry = ATOMIC_INIT(0); /* reentrance protection */
724
725 BUG_ON(cmd->meta.flags & CMD_ASYNC);
726
727 /* A synchronous command can not have a callback set. */
728 BUG_ON(cmd->meta.u.callback != NULL);
729
730 if (atomic_xchg(&entry, 1)) {
731 IWL_ERROR("Error sending %s: Already sending a host command\n",
732 get_cmd_string(cmd->id));
733 return -EBUSY;
734 }
735
736 set_bit(STATUS_HCMD_ACTIVE, &priv->status);
737
738 if (cmd->meta.flags & CMD_WANT_SKB)
739 cmd->meta.source = &cmd->meta;
740
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800741 cmd_idx = iwl4965_enqueue_hcmd(priv, cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700742 if (cmd_idx < 0) {
743 ret = cmd_idx;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800744 IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700745 get_cmd_string(cmd->id), ret);
746 goto out;
747 }
748
749 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
750 !test_bit(STATUS_HCMD_ACTIVE, &priv->status),
751 HOST_COMPLETE_TIMEOUT);
752 if (!ret) {
753 if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) {
754 IWL_ERROR("Error sending %s: time out after %dms.\n",
755 get_cmd_string(cmd->id),
756 jiffies_to_msecs(HOST_COMPLETE_TIMEOUT));
757
758 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
759 ret = -ETIMEDOUT;
760 goto cancel;
761 }
762 }
763
764 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
765 IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n",
766 get_cmd_string(cmd->id));
767 ret = -ECANCELED;
768 goto fail;
769 }
770 if (test_bit(STATUS_FW_ERROR, &priv->status)) {
771 IWL_DEBUG_INFO("Command %s failed: FW Error\n",
772 get_cmd_string(cmd->id));
773 ret = -EIO;
774 goto fail;
775 }
776 if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) {
777 IWL_ERROR("Error: Response NULL in '%s'\n",
778 get_cmd_string(cmd->id));
779 ret = -EIO;
780 goto out;
781 }
782
783 ret = 0;
784 goto out;
785
786cancel:
787 if (cmd->meta.flags & CMD_WANT_SKB) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800788 struct iwl4965_cmd *qcmd;
Zhu Yib481de92007-09-25 17:54:57 -0700789
790 /* Cancel the CMD_WANT_SKB flag for the cmd in the
791 * TX cmd queue. Otherwise in case the cmd comes
792 * in later, it will possibly set an invalid
793 * address (cmd->meta.source). */
794 qcmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx];
795 qcmd->meta.flags &= ~CMD_WANT_SKB;
796 }
797fail:
798 if (cmd->meta.u.skb) {
799 dev_kfree_skb_any(cmd->meta.u.skb);
800 cmd->meta.u.skb = NULL;
801 }
802out:
803 atomic_set(&entry, 0);
804 return ret;
805}
806
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800807int iwl4965_send_cmd(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd)
Zhu Yib481de92007-09-25 17:54:57 -0700808{
Zhu Yib481de92007-09-25 17:54:57 -0700809 if (cmd->meta.flags & CMD_ASYNC)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800810 return iwl4965_send_cmd_async(priv, cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700811
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800812 return iwl4965_send_cmd_sync(priv, cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700813}
814
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800815int iwl4965_send_cmd_pdu(struct iwl4965_priv *priv, u8 id, u16 len, const void *data)
Zhu Yib481de92007-09-25 17:54:57 -0700816{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800817 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700818 .id = id,
819 .len = len,
820 .data = data,
821 };
822
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800823 return iwl4965_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700824}
825
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800826static int __must_check iwl4965_send_cmd_u32(struct iwl4965_priv *priv, u8 id, u32 val)
Zhu Yib481de92007-09-25 17:54:57 -0700827{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800828 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700829 .id = id,
830 .len = sizeof(val),
831 .data = &val,
832 };
833
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800834 return iwl4965_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700835}
836
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800837int iwl4965_send_statistics_request(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700838{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800839 return iwl4965_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700840}
841
842/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800843 * iwl4965_rxon_add_station - add station into station table.
Zhu Yib481de92007-09-25 17:54:57 -0700844 *
845 * there is only one AP station with id= IWL_AP_ID
846 * NOTE: mutex must be held before calling the this fnction
847*/
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800848static int iwl4965_rxon_add_station(struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700849 const u8 *addr, int is_ap)
850{
Zhu Yi556f8db2007-09-27 11:27:33 +0800851 u8 sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700852
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800853 sta_id = iwl4965_add_station_flags(priv, addr, is_ap, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700854 iwl4965_add_station(priv, addr, is_ap);
855
Zhu Yi556f8db2007-09-27 11:27:33 +0800856 return sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700857}
858
859/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800860 * iwl4965_set_rxon_channel - Set the phymode and channel values in staging RXON
Zhu Yib481de92007-09-25 17:54:57 -0700861 * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz
862 * @channel: Any channel valid for the requested phymode
863
864 * In addition to setting the staging RXON, priv->phymode is also set.
865 *
866 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
867 * in the staging RXON flag structure based on the phymode
868 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800869static int iwl4965_set_rxon_channel(struct iwl4965_priv *priv, u8 phymode, u16 channel)
Zhu Yib481de92007-09-25 17:54:57 -0700870{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800871 if (!iwl4965_get_channel_info(priv, phymode, channel)) {
Zhu Yib481de92007-09-25 17:54:57 -0700872 IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
873 channel, phymode);
874 return -EINVAL;
875 }
876
877 if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
878 (priv->phymode == phymode))
879 return 0;
880
881 priv->staging_rxon.channel = cpu_to_le16(channel);
882 if (phymode == MODE_IEEE80211A)
883 priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
884 else
885 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
886
887 priv->phymode = phymode;
888
889 IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, phymode);
890
891 return 0;
892}
893
894/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800895 * iwl4965_check_rxon_cmd - validate RXON structure is valid
Zhu Yib481de92007-09-25 17:54:57 -0700896 *
897 * NOTE: This is really only useful during development and can eventually
898 * be #ifdef'd out once the driver is stable and folks aren't actively
899 * making changes
900 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800901static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd *rxon)
Zhu Yib481de92007-09-25 17:54:57 -0700902{
903 int error = 0;
904 int counter = 1;
905
906 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
907 error |= le32_to_cpu(rxon->flags &
908 (RXON_FLG_TGJ_NARROW_BAND_MSK |
909 RXON_FLG_RADAR_DETECT_MSK));
910 if (error)
911 IWL_WARNING("check 24G fields %d | %d\n",
912 counter++, error);
913 } else {
914 error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
915 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
916 if (error)
917 IWL_WARNING("check 52 fields %d | %d\n",
918 counter++, error);
919 error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
920 if (error)
921 IWL_WARNING("check 52 CCK %d | %d\n",
922 counter++, error);
923 }
924 error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
925 if (error)
926 IWL_WARNING("check mac addr %d | %d\n", counter++, error);
927
928 /* make sure basic rates 6Mbps and 1Mbps are supported */
929 error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
930 ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
931 if (error)
932 IWL_WARNING("check basic rate %d | %d\n", counter++, error);
933
934 error |= (le16_to_cpu(rxon->assoc_id) > 2007);
935 if (error)
936 IWL_WARNING("check assoc id %d | %d\n", counter++, error);
937
938 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
939 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
940 if (error)
941 IWL_WARNING("check CCK and short slot %d | %d\n",
942 counter++, error);
943
944 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
945 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
946 if (error)
947 IWL_WARNING("check CCK & auto detect %d | %d\n",
948 counter++, error);
949
950 error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
951 RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
952 if (error)
953 IWL_WARNING("check TGG and auto detect %d | %d\n",
954 counter++, error);
955
956 if (error)
957 IWL_WARNING("Tuning to channel %d\n",
958 le16_to_cpu(rxon->channel));
959
960 if (error) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800961 IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
Zhu Yib481de92007-09-25 17:54:57 -0700962 return -1;
963 }
964 return 0;
965}
966
967/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800968 * iwl4965_full_rxon_required - determine if RXON_ASSOC can be used in RXON commit
Ian Schram01ebd062007-10-25 17:15:22 +0800969 * @priv: staging_rxon is compared to active_rxon
Zhu Yib481de92007-09-25 17:54:57 -0700970 *
971 * If the RXON structure is changing sufficient to require a new
972 * tune or to clear and reset the RXON_FILTER_ASSOC_MSK then return 1
973 * to indicate a new tune is required.
974 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800975static int iwl4965_full_rxon_required(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700976{
977
978 /* These items are only settable from the full RXON command */
979 if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ||
980 compare_ether_addr(priv->staging_rxon.bssid_addr,
981 priv->active_rxon.bssid_addr) ||
982 compare_ether_addr(priv->staging_rxon.node_addr,
983 priv->active_rxon.node_addr) ||
984 compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
985 priv->active_rxon.wlap_bssid_addr) ||
986 (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
987 (priv->staging_rxon.channel != priv->active_rxon.channel) ||
988 (priv->staging_rxon.air_propagation !=
989 priv->active_rxon.air_propagation) ||
990 (priv->staging_rxon.ofdm_ht_single_stream_basic_rates !=
991 priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
992 (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
993 priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
994 (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) ||
995 (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
996 return 1;
997
998 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
999 * be updated with the RXON_ASSOC command -- however only some
1000 * flag transitions are allowed using RXON_ASSOC */
1001
1002 /* Check if we are not switching bands */
1003 if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
1004 (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
1005 return 1;
1006
1007 /* Check if we are switching association toggle */
1008 if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
1009 (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
1010 return 1;
1011
1012 return 0;
1013}
1014
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001015static int iwl4965_send_rxon_assoc(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001016{
1017 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001018 struct iwl4965_rx_packet *res = NULL;
1019 struct iwl4965_rxon_assoc_cmd rxon_assoc;
1020 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001021 .id = REPLY_RXON_ASSOC,
1022 .len = sizeof(rxon_assoc),
1023 .meta.flags = CMD_WANT_SKB,
1024 .data = &rxon_assoc,
1025 };
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001026 const struct iwl4965_rxon_cmd *rxon1 = &priv->staging_rxon;
1027 const struct iwl4965_rxon_cmd *rxon2 = &priv->active_rxon;
Zhu Yib481de92007-09-25 17:54:57 -07001028
1029 if ((rxon1->flags == rxon2->flags) &&
1030 (rxon1->filter_flags == rxon2->filter_flags) &&
1031 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
1032 (rxon1->ofdm_ht_single_stream_basic_rates ==
1033 rxon2->ofdm_ht_single_stream_basic_rates) &&
1034 (rxon1->ofdm_ht_dual_stream_basic_rates ==
1035 rxon2->ofdm_ht_dual_stream_basic_rates) &&
1036 (rxon1->rx_chain == rxon2->rx_chain) &&
1037 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
1038 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
1039 return 0;
1040 }
1041
1042 rxon_assoc.flags = priv->staging_rxon.flags;
1043 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
1044 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
1045 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
1046 rxon_assoc.reserved = 0;
1047 rxon_assoc.ofdm_ht_single_stream_basic_rates =
1048 priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
1049 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
1050 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
1051 rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
1052
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001053 rc = iwl4965_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001054 if (rc)
1055 return rc;
1056
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001057 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001058 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1059 IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n");
1060 rc = -EIO;
1061 }
1062
1063 priv->alloc_rxb_skb--;
1064 dev_kfree_skb_any(cmd.meta.u.skb);
1065
1066 return rc;
1067}
1068
1069/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001070 * iwl4965_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -07001071 *
Ian Schram01ebd062007-10-25 17:15:22 +08001072 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -07001073 * the active_rxon structure is updated with the new data. This
1074 * function correctly transitions out of the RXON_ASSOC_MSK state if
1075 * a HW tune is required based on the RXON structure changes.
1076 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001077static int iwl4965_commit_rxon(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001078{
1079 /* cast away the const for active_rxon in this function */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001080 struct iwl4965_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
Joe Perches0795af52007-10-03 17:59:30 -07001081 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07001082 int rc = 0;
1083
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001084 if (!iwl4965_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001085 return -1;
1086
1087 /* always get timestamp with Rx frame */
1088 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
1089
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001090 rc = iwl4965_check_rxon_cmd(&priv->staging_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07001091 if (rc) {
1092 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
1093 return -EINVAL;
1094 }
1095
1096 /* If we don't need to send a full RXON, we can use
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001097 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -07001098 * and other flags for the current radio configuration. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001099 if (!iwl4965_full_rxon_required(priv)) {
1100 rc = iwl4965_send_rxon_assoc(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001101 if (rc) {
1102 IWL_ERROR("Error setting RXON_ASSOC "
1103 "configuration (%d).\n", rc);
1104 return rc;
1105 }
1106
1107 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
1108
1109 return 0;
1110 }
1111
1112 /* station table will be cleared */
1113 priv->assoc_station_added = 0;
1114
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001115#ifdef CONFIG_IWL4965_SENSITIVITY
Zhu Yib481de92007-09-25 17:54:57 -07001116 priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT;
1117 if (!priv->error_recovering)
1118 priv->start_calib = 0;
1119
1120 iwl4965_init_sensitivity(priv, CMD_ASYNC, 1);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001121#endif /* CONFIG_IWL4965_SENSITIVITY */
Zhu Yib481de92007-09-25 17:54:57 -07001122
1123 /* If we are currently associated and the new config requires
1124 * an RXON_ASSOC and the new config wants the associated mask enabled,
1125 * we must clear the associated from the active configuration
1126 * before we apply the new config */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001127 if (iwl4965_is_associated(priv) &&
Zhu Yib481de92007-09-25 17:54:57 -07001128 (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
1129 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
1130 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1131
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001132 rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON,
1133 sizeof(struct iwl4965_rxon_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07001134 &priv->active_rxon);
1135
1136 /* If the mask clearing failed then we set
1137 * active_rxon back to what it was previously */
1138 if (rc) {
1139 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
1140 IWL_ERROR("Error clearing ASSOC_MSK on current "
1141 "configuration (%d).\n", rc);
1142 return rc;
1143 }
Zhu Yib481de92007-09-25 17:54:57 -07001144 }
1145
1146 IWL_DEBUG_INFO("Sending RXON\n"
1147 "* with%s RXON_FILTER_ASSOC_MSK\n"
1148 "* channel = %d\n"
Joe Perches0795af52007-10-03 17:59:30 -07001149 "* bssid = %s\n",
Zhu Yib481de92007-09-25 17:54:57 -07001150 ((priv->staging_rxon.filter_flags &
1151 RXON_FILTER_ASSOC_MSK) ? "" : "out"),
1152 le16_to_cpu(priv->staging_rxon.channel),
Joe Perches0795af52007-10-03 17:59:30 -07001153 print_mac(mac, priv->staging_rxon.bssid_addr));
Zhu Yib481de92007-09-25 17:54:57 -07001154
1155 /* Apply the new configuration */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001156 rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON,
1157 sizeof(struct iwl4965_rxon_cmd), &priv->staging_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07001158 if (rc) {
1159 IWL_ERROR("Error setting new configuration (%d).\n", rc);
1160 return rc;
1161 }
1162
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001163 iwl4965_clear_stations_table(priv);
Zhu Yi556f8db2007-09-27 11:27:33 +08001164
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001165#ifdef CONFIG_IWL4965_SENSITIVITY
Zhu Yib481de92007-09-25 17:54:57 -07001166 if (!priv->error_recovering)
1167 priv->start_calib = 0;
1168
1169 priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT;
1170 iwl4965_init_sensitivity(priv, CMD_ASYNC, 1);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001171#endif /* CONFIG_IWL4965_SENSITIVITY */
Zhu Yib481de92007-09-25 17:54:57 -07001172
1173 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
1174
1175 /* If we issue a new RXON command which required a tune then we must
1176 * send a new TXPOWER command or we won't be able to Tx any frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001177 rc = iwl4965_hw_reg_send_txpower(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001178 if (rc) {
1179 IWL_ERROR("Error setting Tx power (%d).\n", rc);
1180 return rc;
1181 }
1182
1183 /* Add the broadcast address so we can send broadcast frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001184 if (iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0) ==
Zhu Yib481de92007-09-25 17:54:57 -07001185 IWL_INVALID_STATION) {
1186 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
1187 return -EIO;
1188 }
1189
1190 /* If we have set the ASSOC_MSK and we are in BSS mode then
1191 * add the IWL_AP_ID to the station rate table */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001192 if (iwl4965_is_associated(priv) &&
Zhu Yib481de92007-09-25 17:54:57 -07001193 (priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001194 if (iwl4965_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1)
Zhu Yib481de92007-09-25 17:54:57 -07001195 == IWL_INVALID_STATION) {
1196 IWL_ERROR("Error adding AP address for transmit.\n");
1197 return -EIO;
1198 }
1199 priv->assoc_station_added = 1;
1200 }
1201
1202 return 0;
1203}
1204
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001205static int iwl4965_send_bt_config(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001206{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001207 struct iwl4965_bt_cmd bt_cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001208 .flags = 3,
1209 .lead_time = 0xAA,
1210 .max_kill = 1,
1211 .kill_ack_mask = 0,
1212 .kill_cts_mask = 0,
1213 };
1214
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001215 return iwl4965_send_cmd_pdu(priv, REPLY_BT_CONFIG,
1216 sizeof(struct iwl4965_bt_cmd), &bt_cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001217}
1218
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001219static int iwl4965_send_scan_abort(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001220{
1221 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001222 struct iwl4965_rx_packet *res;
1223 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001224 .id = REPLY_SCAN_ABORT_CMD,
1225 .meta.flags = CMD_WANT_SKB,
1226 };
1227
1228 /* If there isn't a scan actively going on in the hardware
1229 * then we are in between scan bands and not actually
1230 * actively scanning, so don't send the abort command */
1231 if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
1232 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1233 return 0;
1234 }
1235
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001236 rc = iwl4965_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001237 if (rc) {
1238 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1239 return rc;
1240 }
1241
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001242 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001243 if (res->u.status != CAN_ABORT_STATUS) {
1244 /* The scan abort will return 1 for success or
1245 * 2 for "failure". A failure condition can be
1246 * due to simply not being in an active scan which
1247 * can occur if we send the scan abort before we
1248 * the microcode has notified us that a scan is
1249 * completed. */
1250 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status);
1251 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1252 clear_bit(STATUS_SCAN_HW, &priv->status);
1253 }
1254
1255 dev_kfree_skb_any(cmd.meta.u.skb);
1256
1257 return rc;
1258}
1259
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001260static int iwl4965_card_state_sync_callback(struct iwl4965_priv *priv,
1261 struct iwl4965_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -07001262 struct sk_buff *skb)
1263{
1264 return 1;
1265}
1266
1267/*
1268 * CARD_STATE_CMD
1269 *
1270 * Use: Sets the internal card state to enable, disable, or halt
1271 *
1272 * When in the 'enable' state the card operates as normal.
1273 * When in the 'disable' state, the card enters into a low power mode.
1274 * When in the 'halt' state, the card is shut down and must be fully
1275 * restarted to come back on.
1276 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001277static int iwl4965_send_card_state(struct iwl4965_priv *priv, u32 flags, u8 meta_flag)
Zhu Yib481de92007-09-25 17:54:57 -07001278{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001279 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001280 .id = REPLY_CARD_STATE_CMD,
1281 .len = sizeof(u32),
1282 .data = &flags,
1283 .meta.flags = meta_flag,
1284 };
1285
1286 if (meta_flag & CMD_ASYNC)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001287 cmd.meta.u.callback = iwl4965_card_state_sync_callback;
Zhu Yib481de92007-09-25 17:54:57 -07001288
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001289 return iwl4965_send_cmd(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001290}
1291
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001292static int iwl4965_add_sta_sync_callback(struct iwl4965_priv *priv,
1293 struct iwl4965_cmd *cmd, struct sk_buff *skb)
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
1297 if (!skb) {
1298 IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
1299 return 1;
1300 }
1301
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001302 res = (struct iwl4965_rx_packet *)skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001303 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1304 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1305 res->hdr.flags);
1306 return 1;
1307 }
1308
1309 switch (res->u.add_sta.status) {
1310 case ADD_STA_SUCCESS_MSK:
1311 break;
1312 default:
1313 break;
1314 }
1315
1316 /* We didn't cache the SKB; let the caller free it */
1317 return 1;
1318}
1319
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001320int iwl4965_send_add_station(struct iwl4965_priv *priv,
1321 struct iwl4965_addsta_cmd *sta, u8 flags)
Zhu Yib481de92007-09-25 17:54:57 -07001322{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001323 struct iwl4965_rx_packet *res = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001324 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001325 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001326 .id = REPLY_ADD_STA,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001327 .len = sizeof(struct iwl4965_addsta_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07001328 .meta.flags = flags,
1329 .data = sta,
1330 };
1331
1332 if (flags & CMD_ASYNC)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001333 cmd.meta.u.callback = iwl4965_add_sta_sync_callback;
Zhu Yib481de92007-09-25 17:54:57 -07001334 else
1335 cmd.meta.flags |= CMD_WANT_SKB;
1336
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001337 rc = iwl4965_send_cmd(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001338
1339 if (rc || (flags & CMD_ASYNC))
1340 return rc;
1341
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001342 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001343 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1344 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1345 res->hdr.flags);
1346 rc = -EIO;
1347 }
1348
1349 if (rc == 0) {
1350 switch (res->u.add_sta.status) {
1351 case ADD_STA_SUCCESS_MSK:
1352 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
1353 break;
1354 default:
1355 rc = -EIO;
1356 IWL_WARNING("REPLY_ADD_STA failed\n");
1357 break;
1358 }
1359 }
1360
1361 priv->alloc_rxb_skb--;
1362 dev_kfree_skb_any(cmd.meta.u.skb);
1363
1364 return rc;
1365}
1366
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001367static int iwl4965_update_sta_key_info(struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001368 struct ieee80211_key_conf *keyconf,
1369 u8 sta_id)
1370{
1371 unsigned long flags;
1372 __le16 key_flags = 0;
1373
1374 switch (keyconf->alg) {
1375 case ALG_CCMP:
1376 key_flags |= STA_KEY_FLG_CCMP;
1377 key_flags |= cpu_to_le16(
1378 keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
1379 key_flags &= ~STA_KEY_FLG_INVALID;
1380 break;
1381 case ALG_TKIP:
1382 case ALG_WEP:
Zhu Yib481de92007-09-25 17:54:57 -07001383 default:
1384 return -EINVAL;
1385 }
1386 spin_lock_irqsave(&priv->sta_lock, flags);
1387 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
1388 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
1389 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
1390 keyconf->keylen);
1391
1392 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
1393 keyconf->keylen);
1394 priv->stations[sta_id].sta.key.key_flags = key_flags;
1395 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1396 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1397
1398 spin_unlock_irqrestore(&priv->sta_lock, flags);
1399
1400 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001401 iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001402 return 0;
1403}
1404
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001405static int iwl4965_clear_sta_key_info(struct iwl4965_priv *priv, u8 sta_id)
Zhu Yib481de92007-09-25 17:54:57 -07001406{
1407 unsigned long flags;
1408
1409 spin_lock_irqsave(&priv->sta_lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001410 memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl4965_hw_key));
1411 memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl4965_keyinfo));
Zhu Yib481de92007-09-25 17:54:57 -07001412 priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
1413 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1414 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1415 spin_unlock_irqrestore(&priv->sta_lock, flags);
1416
1417 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001418 iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001419 return 0;
1420}
1421
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001422static void iwl4965_clear_free_frames(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001423{
1424 struct list_head *element;
1425
1426 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
1427 priv->frames_count);
1428
1429 while (!list_empty(&priv->free_frames)) {
1430 element = priv->free_frames.next;
1431 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001432 kfree(list_entry(element, struct iwl4965_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -07001433 priv->frames_count--;
1434 }
1435
1436 if (priv->frames_count) {
1437 IWL_WARNING("%d frames still in use. Did we lose one?\n",
1438 priv->frames_count);
1439 priv->frames_count = 0;
1440 }
1441}
1442
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001443static struct iwl4965_frame *iwl4965_get_free_frame(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001444{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001445 struct iwl4965_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -07001446 struct list_head *element;
1447 if (list_empty(&priv->free_frames)) {
1448 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
1449 if (!frame) {
1450 IWL_ERROR("Could not allocate frame!\n");
1451 return NULL;
1452 }
1453
1454 priv->frames_count++;
1455 return frame;
1456 }
1457
1458 element = priv->free_frames.next;
1459 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001460 return list_entry(element, struct iwl4965_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -07001461}
1462
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001463static void iwl4965_free_frame(struct iwl4965_priv *priv, struct iwl4965_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -07001464{
1465 memset(frame, 0, sizeof(*frame));
1466 list_add(&frame->list, &priv->free_frames);
1467}
1468
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001469unsigned int iwl4965_fill_beacon_frame(struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001470 struct ieee80211_hdr *hdr,
1471 const u8 *dest, int left)
1472{
1473
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001474 if (!iwl4965_is_associated(priv) || !priv->ibss_beacon ||
Zhu Yib481de92007-09-25 17:54:57 -07001475 ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) &&
1476 (priv->iw_mode != IEEE80211_IF_TYPE_AP)))
1477 return 0;
1478
1479 if (priv->ibss_beacon->len > left)
1480 return 0;
1481
1482 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
1483
1484 return priv->ibss_beacon->len;
1485}
1486
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001487int iwl4965_rate_index_from_plcp(int plcp)
Zhu Yib481de92007-09-25 17:54:57 -07001488{
1489 int i = 0;
1490
1491 if (plcp & RATE_MCS_HT_MSK) {
1492 i = (plcp & 0xff);
1493
1494 if (i >= IWL_RATE_MIMO_6M_PLCP)
1495 i = i - IWL_RATE_MIMO_6M_PLCP;
1496
1497 i += IWL_FIRST_OFDM_RATE;
1498 /* skip 9M not supported in ht*/
1499 if (i >= IWL_RATE_9M_INDEX)
1500 i += 1;
1501 if ((i >= IWL_FIRST_OFDM_RATE) &&
1502 (i <= IWL_LAST_OFDM_RATE))
1503 return i;
1504 } else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001505 for (i = 0; i < ARRAY_SIZE(iwl4965_rates); i++)
1506 if (iwl4965_rates[i].plcp == (plcp &0xFF))
Zhu Yib481de92007-09-25 17:54:57 -07001507 return i;
1508 }
1509 return -1;
1510}
1511
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001512static u8 iwl4965_rate_get_lowest_plcp(int rate_mask)
Zhu Yib481de92007-09-25 17:54:57 -07001513{
1514 u8 i;
1515
1516 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001517 i = iwl4965_rates[i].next_ieee) {
Zhu Yib481de92007-09-25 17:54:57 -07001518 if (rate_mask & (1 << i))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001519 return iwl4965_rates[i].plcp;
Zhu Yib481de92007-09-25 17:54:57 -07001520 }
1521
1522 return IWL_RATE_INVALID;
1523}
1524
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001525static int iwl4965_send_beacon_cmd(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001526{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001527 struct iwl4965_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -07001528 unsigned int frame_size;
1529 int rc;
1530 u8 rate;
1531
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001532 frame = iwl4965_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001533
1534 if (!frame) {
1535 IWL_ERROR("Could not obtain free frame buffer for beacon "
1536 "command.\n");
1537 return -ENOMEM;
1538 }
1539
1540 if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001541 rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic &
Zhu Yib481de92007-09-25 17:54:57 -07001542 0xFF0);
1543 if (rate == IWL_INVALID_RATE)
1544 rate = IWL_RATE_6M_PLCP;
1545 } else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001546 rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic & 0xF);
Zhu Yib481de92007-09-25 17:54:57 -07001547 if (rate == IWL_INVALID_RATE)
1548 rate = IWL_RATE_1M_PLCP;
1549 }
1550
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001551 frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -07001552
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001553 rc = iwl4965_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -07001554 &frame->u.cmd[0]);
1555
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001556 iwl4965_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -07001557
1558 return rc;
1559}
1560
1561/******************************************************************************
1562 *
1563 * EEPROM related functions
1564 *
1565 ******************************************************************************/
1566
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001567static void get_eeprom_mac(struct iwl4965_priv *priv, u8 *mac)
Zhu Yib481de92007-09-25 17:54:57 -07001568{
1569 memcpy(mac, priv->eeprom.mac_address, 6);
1570}
1571
1572/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001573 * iwl4965_eeprom_init - read EEPROM contents
Zhu Yib481de92007-09-25 17:54:57 -07001574 *
1575 * Load the EEPROM from adapter into priv->eeprom
1576 *
1577 * NOTE: This routine uses the non-debug IO access functions.
1578 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001579int iwl4965_eeprom_init(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001580{
1581 u16 *e = (u16 *)&priv->eeprom;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001582 u32 gp = iwl4965_read32(priv, CSR_EEPROM_GP);
Zhu Yib481de92007-09-25 17:54:57 -07001583 u32 r;
1584 int sz = sizeof(priv->eeprom);
1585 int rc;
1586 int i;
1587 u16 addr;
1588
1589 /* The EEPROM structure has several padding buffers within it
1590 * and when adding new EEPROM maps is subject to programmer errors
1591 * which may be very difficult to identify without explicitly
1592 * checking the resulting size of the eeprom map. */
1593 BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE);
1594
1595 if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) {
1596 IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp);
1597 return -ENOENT;
1598 }
1599
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001600 rc = iwl4965_eeprom_acquire_semaphore(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001601 if (rc < 0) {
Ian Schram91e17472007-10-25 17:15:23 +08001602 IWL_ERROR("Failed to acquire EEPROM semaphore.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001603 return -ENOENT;
1604 }
1605
1606 /* eeprom is an array of 16bit values */
1607 for (addr = 0; addr < sz; addr += sizeof(u16)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001608 _iwl4965_write32(priv, CSR_EEPROM_REG, addr << 1);
1609 _iwl4965_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD);
Zhu Yib481de92007-09-25 17:54:57 -07001610
1611 for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT;
1612 i += IWL_EEPROM_ACCESS_DELAY) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001613 r = _iwl4965_read_direct32(priv, CSR_EEPROM_REG);
Zhu Yib481de92007-09-25 17:54:57 -07001614 if (r & CSR_EEPROM_REG_READ_VALID_MSK)
1615 break;
1616 udelay(IWL_EEPROM_ACCESS_DELAY);
1617 }
1618
1619 if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) {
1620 IWL_ERROR("Time out reading EEPROM[%d]", addr);
1621 rc = -ETIMEDOUT;
1622 goto done;
1623 }
1624 e[addr / 2] = le16_to_cpu(r >> 16);
1625 }
1626 rc = 0;
1627
1628done:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001629 iwl4965_eeprom_release_semaphore(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001630 return rc;
1631}
1632
1633/******************************************************************************
1634 *
1635 * Misc. internal state and helper functions
1636 *
1637 ******************************************************************************/
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001638#ifdef CONFIG_IWL4965_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001639
1640/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001641 * iwl4965_report_frame - dump frame to syslog during debug sessions
Zhu Yib481de92007-09-25 17:54:57 -07001642 *
1643 * hack this function to show different aspects of received frames,
1644 * including selective frame dumps.
1645 * group100 parameter selects whether to show 1 out of 100 good frames.
1646 *
1647 * TODO: ieee80211_hdr stuff is common to 3945 and 4965, so frame type
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001648 * info output is okay, but some of this stuff (e.g. iwl4965_rx_frame_stats)
Zhu Yib481de92007-09-25 17:54:57 -07001649 * is 3945-specific and gives bad output for 4965. Need to split the
1650 * functionality, keep common stuff here.
1651 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001652void iwl4965_report_frame(struct iwl4965_priv *priv,
1653 struct iwl4965_rx_packet *pkt,
Zhu Yib481de92007-09-25 17:54:57 -07001654 struct ieee80211_hdr *header, int group100)
1655{
1656 u32 to_us;
1657 u32 print_summary = 0;
1658 u32 print_dump = 0; /* set to 1 to dump all frames' contents */
1659 u32 hundred = 0;
1660 u32 dataframe = 0;
1661 u16 fc;
1662 u16 seq_ctl;
1663 u16 channel;
1664 u16 phy_flags;
1665 int rate_sym;
1666 u16 length;
1667 u16 status;
1668 u16 bcn_tmr;
1669 u32 tsf_low;
1670 u64 tsf;
1671 u8 rssi;
1672 u8 agc;
1673 u16 sig_avg;
1674 u16 noise_diff;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001675 struct iwl4965_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt);
1676 struct iwl4965_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
1677 struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt);
Zhu Yib481de92007-09-25 17:54:57 -07001678 u8 *data = IWL_RX_DATA(pkt);
1679
1680 /* MAC header */
1681 fc = le16_to_cpu(header->frame_control);
1682 seq_ctl = le16_to_cpu(header->seq_ctrl);
1683
1684 /* metadata */
1685 channel = le16_to_cpu(rx_hdr->channel);
1686 phy_flags = le16_to_cpu(rx_hdr->phy_flags);
1687 rate_sym = rx_hdr->rate;
1688 length = le16_to_cpu(rx_hdr->len);
1689
1690 /* end-of-frame status and timestamp */
1691 status = le32_to_cpu(rx_end->status);
1692 bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp);
1693 tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff;
1694 tsf = le64_to_cpu(rx_end->timestamp);
1695
1696 /* signal statistics */
1697 rssi = rx_stats->rssi;
1698 agc = rx_stats->agc;
1699 sig_avg = le16_to_cpu(rx_stats->sig_avg);
1700 noise_diff = le16_to_cpu(rx_stats->noise_diff);
1701
1702 to_us = !compare_ether_addr(header->addr1, priv->mac_addr);
1703
1704 /* if data frame is to us and all is good,
1705 * (optionally) print summary for only 1 out of every 100 */
1706 if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) ==
1707 (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
1708 dataframe = 1;
1709 if (!group100)
1710 print_summary = 1; /* print each frame */
1711 else if (priv->framecnt_to_us < 100) {
1712 priv->framecnt_to_us++;
1713 print_summary = 0;
1714 } else {
1715 priv->framecnt_to_us = 0;
1716 print_summary = 1;
1717 hundred = 1;
1718 }
1719 } else {
1720 /* print summary for all other frames */
1721 print_summary = 1;
1722 }
1723
1724 if (print_summary) {
1725 char *title;
1726 u32 rate;
1727
1728 if (hundred)
1729 title = "100Frames";
1730 else if (fc & IEEE80211_FCTL_RETRY)
1731 title = "Retry";
1732 else if (ieee80211_is_assoc_response(fc))
1733 title = "AscRsp";
1734 else if (ieee80211_is_reassoc_response(fc))
1735 title = "RasRsp";
1736 else if (ieee80211_is_probe_response(fc)) {
1737 title = "PrbRsp";
1738 print_dump = 1; /* dump frame contents */
1739 } else if (ieee80211_is_beacon(fc)) {
1740 title = "Beacon";
1741 print_dump = 1; /* dump frame contents */
1742 } else if (ieee80211_is_atim(fc))
1743 title = "ATIM";
1744 else if (ieee80211_is_auth(fc))
1745 title = "Auth";
1746 else if (ieee80211_is_deauth(fc))
1747 title = "DeAuth";
1748 else if (ieee80211_is_disassoc(fc))
1749 title = "DisAssoc";
1750 else
1751 title = "Frame";
1752
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001753 rate = iwl4965_rate_index_from_plcp(rate_sym);
Zhu Yib481de92007-09-25 17:54:57 -07001754 if (rate == -1)
1755 rate = 0;
1756 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001757 rate = iwl4965_rates[rate].ieee / 2;
Zhu Yib481de92007-09-25 17:54:57 -07001758
1759 /* print frame summary.
1760 * MAC addresses show just the last byte (for brevity),
1761 * but you can hack it to show more, if you'd like to. */
1762 if (dataframe)
1763 IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, "
1764 "len=%u, rssi=%d, chnl=%d, rate=%u, \n",
1765 title, fc, header->addr1[5],
1766 length, rssi, channel, rate);
1767 else {
1768 /* src/dst addresses assume managed mode */
1769 IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, "
1770 "src=0x%02x, rssi=%u, tim=%lu usec, "
1771 "phy=0x%02x, chnl=%d\n",
1772 title, fc, header->addr1[5],
1773 header->addr3[5], rssi,
1774 tsf_low - priv->scan_start_tsf,
1775 phy_flags, channel);
1776 }
1777 }
1778 if (print_dump)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001779 iwl4965_print_hex_dump(IWL_DL_RX, data, length);
Zhu Yib481de92007-09-25 17:54:57 -07001780}
1781#endif
1782
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001783static void iwl4965_unset_hw_setting(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001784{
1785 if (priv->hw_setting.shared_virt)
1786 pci_free_consistent(priv->pci_dev,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001787 sizeof(struct iwl4965_shared),
Zhu Yib481de92007-09-25 17:54:57 -07001788 priv->hw_setting.shared_virt,
1789 priv->hw_setting.shared_phys);
1790}
1791
1792/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001793 * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field
Zhu Yib481de92007-09-25 17:54:57 -07001794 *
1795 * return : set the bit for each supported rate insert in ie
1796 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001797static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate,
Tomas Winklerc7c46672007-10-18 02:04:15 +02001798 u16 basic_rate, int *left)
Zhu Yib481de92007-09-25 17:54:57 -07001799{
1800 u16 ret_rates = 0, bit;
1801 int i;
Tomas Winklerc7c46672007-10-18 02:04:15 +02001802 u8 *cnt = ie;
1803 u8 *rates = ie + 1;
Zhu Yib481de92007-09-25 17:54:57 -07001804
1805 for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) {
1806 if (bit & supported_rate) {
1807 ret_rates |= bit;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001808 rates[*cnt] = iwl4965_rates[i].ieee |
Tomas Winklerc7c46672007-10-18 02:04:15 +02001809 ((bit & basic_rate) ? 0x80 : 0x00);
1810 (*cnt)++;
1811 (*left)--;
1812 if ((*left <= 0) ||
1813 (*cnt >= IWL_SUPPORTED_RATES_IE_LEN))
Zhu Yib481de92007-09-25 17:54:57 -07001814 break;
1815 }
1816 }
1817
1818 return ret_rates;
1819}
1820
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001821#ifdef CONFIG_IWL4965_HT
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001822void static iwl4965_set_ht_capab(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07001823 struct ieee80211_ht_capability *ht_cap,
1824 u8 use_wide_chan);
1825#endif
1826
1827/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001828 * iwl4965_fill_probe_req - fill in all required fields and IE for probe request
Zhu Yib481de92007-09-25 17:54:57 -07001829 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001830static u16 iwl4965_fill_probe_req(struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001831 struct ieee80211_mgmt *frame,
1832 int left, int is_direct)
1833{
1834 int len = 0;
1835 u8 *pos = NULL;
mabbasbee488d2007-10-25 17:15:42 +08001836 u16 active_rates, ret_rates, cck_rates, active_rate_basic;
Zhu Yib481de92007-09-25 17:54:57 -07001837
1838 /* Make sure there is enough space for the probe request,
1839 * two mandatory IEs and the data */
1840 left -= 24;
1841 if (left < 0)
1842 return 0;
1843 len += 24;
1844
1845 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001846 memcpy(frame->da, iwl4965_broadcast_addr, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07001847 memcpy(frame->sa, priv->mac_addr, ETH_ALEN);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001848 memcpy(frame->bssid, iwl4965_broadcast_addr, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07001849 frame->seq_ctrl = 0;
1850
1851 /* fill in our indirect SSID IE */
1852 /* ...next IE... */
1853
1854 left -= 2;
1855 if (left < 0)
1856 return 0;
1857 len += 2;
1858 pos = &(frame->u.probe_req.variable[0]);
1859 *pos++ = WLAN_EID_SSID;
1860 *pos++ = 0;
1861
1862 /* fill in our direct SSID IE... */
1863 if (is_direct) {
1864 /* ...next IE... */
1865 left -= 2 + priv->essid_len;
1866 if (left < 0)
1867 return 0;
1868 /* ... fill it in... */
1869 *pos++ = WLAN_EID_SSID;
1870 *pos++ = priv->essid_len;
1871 memcpy(pos, priv->essid, priv->essid_len);
1872 pos += priv->essid_len;
1873 len += 2 + priv->essid_len;
1874 }
1875
1876 /* fill in supported rate */
1877 /* ...next IE... */
1878 left -= 2;
1879 if (left < 0)
1880 return 0;
Tomas Winklerc7c46672007-10-18 02:04:15 +02001881
Zhu Yib481de92007-09-25 17:54:57 -07001882 /* ... fill it in... */
1883 *pos++ = WLAN_EID_SUPP_RATES;
1884 *pos = 0;
Tomas Winklerc7c46672007-10-18 02:04:15 +02001885
mabbasbee488d2007-10-25 17:15:42 +08001886 /* exclude 60M rate */
1887 active_rates = priv->rates_mask;
1888 active_rates &= ~IWL_RATE_60M_MASK;
1889
1890 active_rate_basic = active_rates & IWL_BASIC_RATES_MASK;
Zhu Yib481de92007-09-25 17:54:57 -07001891
Tomas Winklerc7c46672007-10-18 02:04:15 +02001892 cck_rates = IWL_CCK_RATES_MASK & active_rates;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001893 ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates,
mabbasbee488d2007-10-25 17:15:42 +08001894 active_rate_basic, &left);
Tomas Winklerc7c46672007-10-18 02:04:15 +02001895 active_rates &= ~ret_rates;
1896
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001897 ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates,
mabbasbee488d2007-10-25 17:15:42 +08001898 active_rate_basic, &left);
Tomas Winklerc7c46672007-10-18 02:04:15 +02001899 active_rates &= ~ret_rates;
1900
Zhu Yib481de92007-09-25 17:54:57 -07001901 len += 2 + *pos;
1902 pos += (*pos) + 1;
Tomas Winklerc7c46672007-10-18 02:04:15 +02001903 if (active_rates == 0)
Zhu Yib481de92007-09-25 17:54:57 -07001904 goto fill_end;
1905
1906 /* fill in supported extended rate */
1907 /* ...next IE... */
1908 left -= 2;
1909 if (left < 0)
1910 return 0;
1911 /* ... fill it in... */
1912 *pos++ = WLAN_EID_EXT_SUPP_RATES;
1913 *pos = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001914 iwl4965_supported_rate_to_ie(pos, active_rates,
mabbasbee488d2007-10-25 17:15:42 +08001915 active_rate_basic, &left);
Zhu Yib481de92007-09-25 17:54:57 -07001916 if (*pos > 0)
1917 len += 2 + *pos;
1918
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001919#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -07001920 if (is_direct && priv->is_ht_enabled) {
1921 u8 use_wide_chan = 1;
1922
1923 if (priv->channel_width != IWL_CHANNEL_WIDTH_40MHZ)
1924 use_wide_chan = 0;
1925 pos += (*pos) + 1;
1926 *pos++ = WLAN_EID_HT_CAPABILITY;
1927 *pos++ = sizeof(struct ieee80211_ht_capability);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001928 iwl4965_set_ht_capab(NULL, (struct ieee80211_ht_capability *)pos,
Zhu Yib481de92007-09-25 17:54:57 -07001929 use_wide_chan);
1930 len += 2 + sizeof(struct ieee80211_ht_capability);
1931 }
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001932#endif /*CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07001933
1934 fill_end:
1935 return (u16)len;
1936}
1937
1938/*
1939 * QoS support
1940*/
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001941#ifdef CONFIG_IWL4965_QOS
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001942static int iwl4965_send_qos_params_command(struct iwl4965_priv *priv,
1943 struct iwl4965_qosparam_cmd *qos)
Zhu Yib481de92007-09-25 17:54:57 -07001944{
1945
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001946 return iwl4965_send_cmd_pdu(priv, REPLY_QOS_PARAM,
1947 sizeof(struct iwl4965_qosparam_cmd), qos);
Zhu Yib481de92007-09-25 17:54:57 -07001948}
1949
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001950static void iwl4965_reset_qos(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001951{
1952 u16 cw_min = 15;
1953 u16 cw_max = 1023;
1954 u8 aifs = 2;
1955 u8 is_legacy = 0;
1956 unsigned long flags;
1957 int i;
1958
1959 spin_lock_irqsave(&priv->lock, flags);
1960 priv->qos_data.qos_active = 0;
1961
1962 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) {
1963 if (priv->qos_data.qos_enable)
1964 priv->qos_data.qos_active = 1;
1965 if (!(priv->active_rate & 0xfff0)) {
1966 cw_min = 31;
1967 is_legacy = 1;
1968 }
1969 } else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
1970 if (priv->qos_data.qos_enable)
1971 priv->qos_data.qos_active = 1;
1972 } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) {
1973 cw_min = 31;
1974 is_legacy = 1;
1975 }
1976
1977 if (priv->qos_data.qos_active)
1978 aifs = 3;
1979
1980 priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min);
1981 priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max);
1982 priv->qos_data.def_qos_parm.ac[0].aifsn = aifs;
1983 priv->qos_data.def_qos_parm.ac[0].edca_txop = 0;
1984 priv->qos_data.def_qos_parm.ac[0].reserved1 = 0;
1985
1986 if (priv->qos_data.qos_active) {
1987 i = 1;
1988 priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min);
1989 priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max);
1990 priv->qos_data.def_qos_parm.ac[i].aifsn = 7;
1991 priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
1992 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
1993
1994 i = 2;
1995 priv->qos_data.def_qos_parm.ac[i].cw_min =
1996 cpu_to_le16((cw_min + 1) / 2 - 1);
1997 priv->qos_data.def_qos_parm.ac[i].cw_max =
1998 cpu_to_le16(cw_max);
1999 priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
2000 if (is_legacy)
2001 priv->qos_data.def_qos_parm.ac[i].edca_txop =
2002 cpu_to_le16(6016);
2003 else
2004 priv->qos_data.def_qos_parm.ac[i].edca_txop =
2005 cpu_to_le16(3008);
2006 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
2007
2008 i = 3;
2009 priv->qos_data.def_qos_parm.ac[i].cw_min =
2010 cpu_to_le16((cw_min + 1) / 4 - 1);
2011 priv->qos_data.def_qos_parm.ac[i].cw_max =
2012 cpu_to_le16((cw_max + 1) / 2 - 1);
2013 priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
2014 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
2015 if (is_legacy)
2016 priv->qos_data.def_qos_parm.ac[i].edca_txop =
2017 cpu_to_le16(3264);
2018 else
2019 priv->qos_data.def_qos_parm.ac[i].edca_txop =
2020 cpu_to_le16(1504);
2021 } else {
2022 for (i = 1; i < 4; i++) {
2023 priv->qos_data.def_qos_parm.ac[i].cw_min =
2024 cpu_to_le16(cw_min);
2025 priv->qos_data.def_qos_parm.ac[i].cw_max =
2026 cpu_to_le16(cw_max);
2027 priv->qos_data.def_qos_parm.ac[i].aifsn = aifs;
2028 priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
2029 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
2030 }
2031 }
2032 IWL_DEBUG_QOS("set QoS to default \n");
2033
2034 spin_unlock_irqrestore(&priv->lock, flags);
2035}
2036
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002037static void iwl4965_activate_qos(struct iwl4965_priv *priv, u8 force)
Zhu Yib481de92007-09-25 17:54:57 -07002038{
2039 unsigned long flags;
2040
Zhu Yib481de92007-09-25 17:54:57 -07002041 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2042 return;
2043
2044 if (!priv->qos_data.qos_enable)
2045 return;
2046
2047 spin_lock_irqsave(&priv->lock, flags);
2048 priv->qos_data.def_qos_parm.qos_flags = 0;
2049
2050 if (priv->qos_data.qos_cap.q_AP.queue_request &&
2051 !priv->qos_data.qos_cap.q_AP.txop_request)
2052 priv->qos_data.def_qos_parm.qos_flags |=
2053 QOS_PARAM_FLG_TXOP_TYPE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07002054 if (priv->qos_data.qos_active)
2055 priv->qos_data.def_qos_parm.qos_flags |=
2056 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
2057
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002058#ifdef CONFIG_IWL4965_HT
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +08002059 if (priv->is_ht_enabled && priv->current_assoc_ht.is_ht)
2060 priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002061#endif /* CONFIG_IWL4965_HT */
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +08002062
Zhu Yib481de92007-09-25 17:54:57 -07002063 spin_unlock_irqrestore(&priv->lock, flags);
2064
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002065 if (force || iwl4965_is_associated(priv)) {
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +08002066 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
2067 priv->qos_data.qos_active,
2068 priv->qos_data.def_qos_parm.qos_flags);
Zhu Yib481de92007-09-25 17:54:57 -07002069
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002070 iwl4965_send_qos_params_command(priv,
Zhu Yib481de92007-09-25 17:54:57 -07002071 &(priv->qos_data.def_qos_parm));
2072 }
2073}
2074
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002075#endif /* CONFIG_IWL4965_QOS */
Zhu Yib481de92007-09-25 17:54:57 -07002076/*
2077 * Power management (not Tx power!) functions
2078 */
2079#define MSEC_TO_USEC 1024
2080
2081#define NOSLP __constant_cpu_to_le16(0), 0, 0
2082#define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0
2083#define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
2084#define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
2085 __constant_cpu_to_le32(X1), \
2086 __constant_cpu_to_le32(X2), \
2087 __constant_cpu_to_le32(X3), \
2088 __constant_cpu_to_le32(X4)}
2089
2090
2091/* default power management (not Tx power) table values */
2092/* for tim 0-10 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002093static struct iwl4965_power_vec_entry range_0[IWL_POWER_AC] = {
Zhu Yib481de92007-09-25 17:54:57 -07002094 {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
2095 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
2096 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
2097 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
2098 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
2099 {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
2100};
2101
2102/* for tim > 10 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002103static struct iwl4965_power_vec_entry range_1[IWL_POWER_AC] = {
Zhu Yib481de92007-09-25 17:54:57 -07002104 {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
2105 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
2106 SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
2107 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
2108 SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
2109 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
2110 SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
2111 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
2112 {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
2113 SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
2114};
2115
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002116int iwl4965_power_init_handle(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002117{
2118 int rc = 0, i;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002119 struct iwl4965_power_mgr *pow_data;
2120 int size = sizeof(struct iwl4965_power_vec_entry) * IWL_POWER_AC;
Zhu Yib481de92007-09-25 17:54:57 -07002121 u16 pci_pm;
2122
2123 IWL_DEBUG_POWER("Initialize power \n");
2124
2125 pow_data = &(priv->power_data);
2126
2127 memset(pow_data, 0, sizeof(*pow_data));
2128
2129 pow_data->active_index = IWL_POWER_RANGE_0;
2130 pow_data->dtim_val = 0xffff;
2131
2132 memcpy(&pow_data->pwr_range_0[0], &range_0[0], size);
2133 memcpy(&pow_data->pwr_range_1[0], &range_1[0], size);
2134
2135 rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm);
2136 if (rc != 0)
2137 return 0;
2138 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002139 struct iwl4965_powertable_cmd *cmd;
Zhu Yib481de92007-09-25 17:54:57 -07002140
2141 IWL_DEBUG_POWER("adjust power command flags\n");
2142
2143 for (i = 0; i < IWL_POWER_AC; i++) {
2144 cmd = &pow_data->pwr_range_0[i].cmd;
2145
2146 if (pci_pm & 0x1)
2147 cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
2148 else
2149 cmd->flags |= IWL_POWER_PCI_PM_MSK;
2150 }
2151 }
2152 return rc;
2153}
2154
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002155static int iwl4965_update_power_cmd(struct iwl4965_priv *priv,
2156 struct iwl4965_powertable_cmd *cmd, u32 mode)
Zhu Yib481de92007-09-25 17:54:57 -07002157{
2158 int rc = 0, i;
2159 u8 skip;
2160 u32 max_sleep = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002161 struct iwl4965_power_vec_entry *range;
Zhu Yib481de92007-09-25 17:54:57 -07002162 u8 period = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002163 struct iwl4965_power_mgr *pow_data;
Zhu Yib481de92007-09-25 17:54:57 -07002164
2165 if (mode > IWL_POWER_INDEX_5) {
2166 IWL_DEBUG_POWER("Error invalid power mode \n");
2167 return -1;
2168 }
2169 pow_data = &(priv->power_data);
2170
2171 if (pow_data->active_index == IWL_POWER_RANGE_0)
2172 range = &pow_data->pwr_range_0[0];
2173 else
2174 range = &pow_data->pwr_range_1[1];
2175
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002176 memcpy(cmd, &range[mode].cmd, sizeof(struct iwl4965_powertable_cmd));
Zhu Yib481de92007-09-25 17:54:57 -07002177
2178#ifdef IWL_MAC80211_DISABLE
2179 if (priv->assoc_network != NULL) {
2180 unsigned long flags;
2181
2182 period = priv->assoc_network->tim.tim_period;
2183 }
2184#endif /*IWL_MAC80211_DISABLE */
2185 skip = range[mode].no_dtim;
2186
2187 if (period == 0) {
2188 period = 1;
2189 skip = 0;
2190 }
2191
2192 if (skip == 0) {
2193 max_sleep = period;
2194 cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
2195 } else {
2196 __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
2197 max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
2198 cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
2199 }
2200
2201 for (i = 0; i < IWL_POWER_VEC_SIZE; i++) {
2202 if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
2203 cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
2204 }
2205
2206 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags);
2207 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
2208 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
2209 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
2210 le32_to_cpu(cmd->sleep_interval[0]),
2211 le32_to_cpu(cmd->sleep_interval[1]),
2212 le32_to_cpu(cmd->sleep_interval[2]),
2213 le32_to_cpu(cmd->sleep_interval[3]),
2214 le32_to_cpu(cmd->sleep_interval[4]));
2215
2216 return rc;
2217}
2218
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002219static int iwl4965_send_power_mode(struct iwl4965_priv *priv, u32 mode)
Zhu Yib481de92007-09-25 17:54:57 -07002220{
2221 u32 final_mode = mode;
2222 int rc;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002223 struct iwl4965_powertable_cmd cmd;
Zhu Yib481de92007-09-25 17:54:57 -07002224
2225 /* If on battery, set to 3,
Ian Schram01ebd062007-10-25 17:15:22 +08002226 * if plugged into AC power, set to CAM ("continuously aware mode"),
Zhu Yib481de92007-09-25 17:54:57 -07002227 * else user level */
2228 switch (mode) {
2229 case IWL_POWER_BATTERY:
2230 final_mode = IWL_POWER_INDEX_3;
2231 break;
2232 case IWL_POWER_AC:
2233 final_mode = IWL_POWER_MODE_CAM;
2234 break;
2235 default:
2236 final_mode = mode;
2237 break;
2238 }
2239
2240 cmd.keep_alive_beacons = 0;
2241
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002242 iwl4965_update_power_cmd(priv, &cmd, final_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002243
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002244 rc = iwl4965_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07002245
2246 if (final_mode == IWL_POWER_MODE_CAM)
2247 clear_bit(STATUS_POWER_PMI, &priv->status);
2248 else
2249 set_bit(STATUS_POWER_PMI, &priv->status);
2250
2251 return rc;
2252}
2253
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002254int iwl4965_is_network_packet(struct iwl4965_priv *priv, struct ieee80211_hdr *header)
Zhu Yib481de92007-09-25 17:54:57 -07002255{
2256 /* Filter incoming packets to determine if they are targeted toward
2257 * this network, discarding packets coming from ourselves */
2258 switch (priv->iw_mode) {
2259 case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */
2260 /* packets from our adapter are dropped (echo) */
2261 if (!compare_ether_addr(header->addr2, priv->mac_addr))
2262 return 0;
2263 /* {broad,multi}cast packets to our IBSS go through */
2264 if (is_multicast_ether_addr(header->addr1))
2265 return !compare_ether_addr(header->addr3, priv->bssid);
2266 /* packets to our adapter go through */
2267 return !compare_ether_addr(header->addr1, priv->mac_addr);
2268 case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */
2269 /* packets from our adapter are dropped (echo) */
2270 if (!compare_ether_addr(header->addr3, priv->mac_addr))
2271 return 0;
2272 /* {broad,multi}cast packets to our BSS go through */
2273 if (is_multicast_ether_addr(header->addr1))
2274 return !compare_ether_addr(header->addr2, priv->bssid);
2275 /* packets to our adapter go through */
2276 return !compare_ether_addr(header->addr1, priv->mac_addr);
2277 }
2278
2279 return 1;
2280}
2281
2282#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
2283
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002284static const char *iwl4965_get_tx_fail_reason(u32 status)
Zhu Yib481de92007-09-25 17:54:57 -07002285{
2286 switch (status & TX_STATUS_MSK) {
2287 case TX_STATUS_SUCCESS:
2288 return "SUCCESS";
2289 TX_STATUS_ENTRY(SHORT_LIMIT);
2290 TX_STATUS_ENTRY(LONG_LIMIT);
2291 TX_STATUS_ENTRY(FIFO_UNDERRUN);
2292 TX_STATUS_ENTRY(MGMNT_ABORT);
2293 TX_STATUS_ENTRY(NEXT_FRAG);
2294 TX_STATUS_ENTRY(LIFE_EXPIRE);
2295 TX_STATUS_ENTRY(DEST_PS);
2296 TX_STATUS_ENTRY(ABORTED);
2297 TX_STATUS_ENTRY(BT_RETRY);
2298 TX_STATUS_ENTRY(STA_INVALID);
2299 TX_STATUS_ENTRY(FRAG_DROPPED);
2300 TX_STATUS_ENTRY(TID_DISABLE);
2301 TX_STATUS_ENTRY(FRAME_FLUSHED);
2302 TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
2303 TX_STATUS_ENTRY(TX_LOCKED);
2304 TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
2305 }
2306
2307 return "UNKNOWN";
2308}
2309
2310/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002311 * iwl4965_scan_cancel - Cancel any currently executing HW scan
Zhu Yib481de92007-09-25 17:54:57 -07002312 *
2313 * NOTE: priv->mutex is not required before calling this function
2314 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002315static int iwl4965_scan_cancel(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002316{
2317 if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
2318 clear_bit(STATUS_SCANNING, &priv->status);
2319 return 0;
2320 }
2321
2322 if (test_bit(STATUS_SCANNING, &priv->status)) {
2323 if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
2324 IWL_DEBUG_SCAN("Queuing scan abort.\n");
2325 set_bit(STATUS_SCAN_ABORTING, &priv->status);
2326 queue_work(priv->workqueue, &priv->abort_scan);
2327
2328 } else
2329 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
2330
2331 return test_bit(STATUS_SCANNING, &priv->status);
2332 }
2333
2334 return 0;
2335}
2336
2337/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002338 * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan
Zhu Yib481de92007-09-25 17:54:57 -07002339 * @ms: amount of time to wait (in milliseconds) for scan to abort
2340 *
2341 * NOTE: priv->mutex must be held before calling this function
2342 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002343static int iwl4965_scan_cancel_timeout(struct iwl4965_priv *priv, unsigned long ms)
Zhu Yib481de92007-09-25 17:54:57 -07002344{
2345 unsigned long now = jiffies;
2346 int ret;
2347
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002348 ret = iwl4965_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002349 if (ret && ms) {
2350 mutex_unlock(&priv->mutex);
2351 while (!time_after(jiffies, now + msecs_to_jiffies(ms)) &&
2352 test_bit(STATUS_SCANNING, &priv->status))
2353 msleep(1);
2354 mutex_lock(&priv->mutex);
2355
2356 return test_bit(STATUS_SCANNING, &priv->status);
2357 }
2358
2359 return ret;
2360}
2361
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002362static void iwl4965_sequence_reset(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002363{
2364 /* Reset ieee stats */
2365
2366 /* We don't reset the net_device_stats (ieee->stats) on
2367 * re-association */
2368
2369 priv->last_seq_num = -1;
2370 priv->last_frag_num = -1;
2371 priv->last_packet_time = 0;
2372
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002373 iwl4965_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002374}
2375
2376#define MAX_UCODE_BEACON_INTERVAL 4096
2377#define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
2378
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002379static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -07002380{
2381 u16 new_val = 0;
2382 u16 beacon_factor = 0;
2383
2384 beacon_factor =
2385 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
2386 / MAX_UCODE_BEACON_INTERVAL;
2387 new_val = beacon_val / beacon_factor;
2388
2389 return cpu_to_le16(new_val);
2390}
2391
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002392static void iwl4965_setup_rxon_timing(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002393{
2394 u64 interval_tm_unit;
2395 u64 tsf, result;
2396 unsigned long flags;
2397 struct ieee80211_conf *conf = NULL;
2398 u16 beacon_int = 0;
2399
2400 conf = ieee80211_get_hw_conf(priv->hw);
2401
2402 spin_lock_irqsave(&priv->lock, flags);
2403 priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp1);
2404 priv->rxon_timing.timestamp.dw[0] = cpu_to_le32(priv->timestamp0);
2405
2406 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
2407
2408 tsf = priv->timestamp1;
2409 tsf = ((tsf << 32) | priv->timestamp0);
2410
2411 beacon_int = priv->beacon_int;
2412 spin_unlock_irqrestore(&priv->lock, flags);
2413
2414 if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
2415 if (beacon_int == 0) {
2416 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
2417 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
2418 } else {
2419 priv->rxon_timing.beacon_interval =
2420 cpu_to_le16(beacon_int);
2421 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002422 iwl4965_adjust_beacon_interval(
Zhu Yib481de92007-09-25 17:54:57 -07002423 le16_to_cpu(priv->rxon_timing.beacon_interval));
2424 }
2425
2426 priv->rxon_timing.atim_window = 0;
2427 } else {
2428 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002429 iwl4965_adjust_beacon_interval(conf->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -07002430 /* TODO: we need to get atim_window from upper stack
2431 * for now we set to 0 */
2432 priv->rxon_timing.atim_window = 0;
2433 }
2434
2435 interval_tm_unit =
2436 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
2437 result = do_div(tsf, interval_tm_unit);
2438 priv->rxon_timing.beacon_init_val =
2439 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
2440
2441 IWL_DEBUG_ASSOC
2442 ("beacon interval %d beacon timer %d beacon tim %d\n",
2443 le16_to_cpu(priv->rxon_timing.beacon_interval),
2444 le32_to_cpu(priv->rxon_timing.beacon_init_val),
2445 le16_to_cpu(priv->rxon_timing.atim_window));
2446}
2447
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002448static int iwl4965_scan_initiate(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002449{
2450 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
2451 IWL_ERROR("APs don't scan.\n");
2452 return 0;
2453 }
2454
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002455 if (!iwl4965_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002456 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
2457 return -EIO;
2458 }
2459
2460 if (test_bit(STATUS_SCANNING, &priv->status)) {
2461 IWL_DEBUG_SCAN("Scan already in progress.\n");
2462 return -EAGAIN;
2463 }
2464
2465 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
2466 IWL_DEBUG_SCAN("Scan request while abort pending. "
2467 "Queuing.\n");
2468 return -EAGAIN;
2469 }
2470
2471 IWL_DEBUG_INFO("Starting scan...\n");
2472 priv->scan_bands = 2;
2473 set_bit(STATUS_SCANNING, &priv->status);
2474 priv->scan_start = jiffies;
2475 priv->scan_pass_start = priv->scan_start;
2476
2477 queue_work(priv->workqueue, &priv->request_scan);
2478
2479 return 0;
2480}
2481
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002482static int iwl4965_set_rxon_hwcrypto(struct iwl4965_priv *priv, int hw_decrypt)
Zhu Yib481de92007-09-25 17:54:57 -07002483{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002484 struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon;
Zhu Yib481de92007-09-25 17:54:57 -07002485
2486 if (hw_decrypt)
2487 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
2488 else
2489 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
2490
2491 return 0;
2492}
2493
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002494static void iwl4965_set_flags_for_phymode(struct iwl4965_priv *priv, u8 phymode)
Zhu Yib481de92007-09-25 17:54:57 -07002495{
2496 if (phymode == MODE_IEEE80211A) {
2497 priv->staging_rxon.flags &=
2498 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
2499 | RXON_FLG_CCK_MSK);
2500 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2501 } else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002502 /* Copied from iwl4965_bg_post_associate() */
Zhu Yib481de92007-09-25 17:54:57 -07002503 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2504 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2505 else
2506 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2507
2508 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
2509 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2510
2511 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
2512 priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
2513 priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
2514 }
2515}
2516
2517/*
Ian Schram01ebd062007-10-25 17:15:22 +08002518 * initialize rxon structure with default values from eeprom
Zhu Yib481de92007-09-25 17:54:57 -07002519 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002520static void iwl4965_connection_init_rx_config(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002521{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002522 const struct iwl4965_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07002523
2524 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
2525
2526 switch (priv->iw_mode) {
2527 case IEEE80211_IF_TYPE_AP:
2528 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
2529 break;
2530
2531 case IEEE80211_IF_TYPE_STA:
2532 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
2533 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
2534 break;
2535
2536 case IEEE80211_IF_TYPE_IBSS:
2537 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
2538 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
2539 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
2540 RXON_FILTER_ACCEPT_GRP_MSK;
2541 break;
2542
2543 case IEEE80211_IF_TYPE_MNTR:
2544 priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
2545 priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
2546 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
2547 break;
2548 }
2549
2550#if 0
2551 /* TODO: Figure out when short_preamble would be set and cache from
2552 * that */
2553 if (!hw_to_local(priv->hw)->short_preamble)
2554 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2555 else
2556 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2557#endif
2558
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002559 ch_info = iwl4965_get_channel_info(priv, priv->phymode,
Zhu Yib481de92007-09-25 17:54:57 -07002560 le16_to_cpu(priv->staging_rxon.channel));
2561
2562 if (!ch_info)
2563 ch_info = &priv->channel_info[0];
2564
2565 /*
2566 * in some case A channels are all non IBSS
2567 * in this case force B/G channel
2568 */
2569 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
2570 !(is_channel_ibss(ch_info)))
2571 ch_info = &priv->channel_info[0];
2572
2573 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
2574 if (is_channel_a_band(ch_info))
2575 priv->phymode = MODE_IEEE80211A;
2576 else
2577 priv->phymode = MODE_IEEE80211G;
2578
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002579 iwl4965_set_flags_for_phymode(priv, priv->phymode);
Zhu Yib481de92007-09-25 17:54:57 -07002580
2581 priv->staging_rxon.ofdm_basic_rates =
2582 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
2583 priv->staging_rxon.cck_basic_rates =
2584 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
2585
2586 priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
2587 RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
2588 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2589 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
2590 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
2591 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
2592 iwl4965_set_rxon_chain(priv);
2593}
2594
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002595static int iwl4965_set_mode(struct iwl4965_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -07002596{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002597 if (!iwl4965_is_ready_rf(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002598 return -EAGAIN;
2599
2600 if (mode == IEEE80211_IF_TYPE_IBSS) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002601 const struct iwl4965_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07002602
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002603 ch_info = iwl4965_get_channel_info(priv,
Zhu Yib481de92007-09-25 17:54:57 -07002604 priv->phymode,
2605 le16_to_cpu(priv->staging_rxon.channel));
2606
2607 if (!ch_info || !is_channel_ibss(ch_info)) {
2608 IWL_ERROR("channel %d not IBSS channel\n",
2609 le16_to_cpu(priv->staging_rxon.channel));
2610 return -EINVAL;
2611 }
2612 }
2613
2614 cancel_delayed_work(&priv->scan_check);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002615 if (iwl4965_scan_cancel_timeout(priv, 100)) {
Zhu Yib481de92007-09-25 17:54:57 -07002616 IWL_WARNING("Aborted scan still in progress after 100ms\n");
2617 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2618 return -EAGAIN;
2619 }
2620
2621 priv->iw_mode = mode;
2622
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002623 iwl4965_connection_init_rx_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002624 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2625
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002626 iwl4965_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002627
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002628 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002629
2630 return 0;
2631}
2632
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002633static void iwl4965_build_tx_cmd_hwcrypto(struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002634 struct ieee80211_tx_control *ctl,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002635 struct iwl4965_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -07002636 struct sk_buff *skb_frag,
2637 int last_frag)
2638{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002639 struct iwl4965_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo;
Zhu Yib481de92007-09-25 17:54:57 -07002640
2641 switch (keyinfo->alg) {
2642 case ALG_CCMP:
2643 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM;
2644 memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen);
2645 IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
2646 break;
2647
2648 case ALG_TKIP:
2649#if 0
2650 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP;
2651
2652 if (last_frag)
2653 memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8,
2654 8);
2655 else
2656 memset(cmd->cmd.tx.tkip_mic.byte, 0, 8);
2657#endif
2658 break;
2659
2660 case ALG_WEP:
2661 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP |
2662 (ctl->key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
2663
2664 if (keyinfo->keylen == 13)
2665 cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128;
2666
2667 memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen);
2668
2669 IWL_DEBUG_TX("Configuring packet for WEP encryption "
2670 "with key %d\n", ctl->key_idx);
2671 break;
2672
Zhu Yib481de92007-09-25 17:54:57 -07002673 default:
2674 printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg);
2675 break;
2676 }
2677}
2678
2679/*
2680 * handle build REPLY_TX command notification.
2681 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002682static void iwl4965_build_tx_cmd_basic(struct iwl4965_priv *priv,
2683 struct iwl4965_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -07002684 struct ieee80211_tx_control *ctrl,
2685 struct ieee80211_hdr *hdr,
2686 int is_unicast, u8 std_id)
2687{
2688 __le16 *qc;
2689 u16 fc = le16_to_cpu(hdr->frame_control);
2690 __le32 tx_flags = cmd->cmd.tx.tx_flags;
2691
2692 cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
2693 if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) {
2694 tx_flags |= TX_CMD_FLG_ACK_MSK;
2695 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
2696 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2697 if (ieee80211_is_probe_response(fc) &&
2698 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
2699 tx_flags |= TX_CMD_FLG_TSF_MSK;
2700 } else {
2701 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
2702 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2703 }
2704
2705 cmd->cmd.tx.sta_id = std_id;
2706 if (ieee80211_get_morefrag(hdr))
2707 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
2708
2709 qc = ieee80211_get_qos_ctrl(hdr);
2710 if (qc) {
2711 cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf);
2712 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
2713 } else
2714 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2715
2716 if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) {
2717 tx_flags |= TX_CMD_FLG_RTS_MSK;
2718 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
2719 } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) {
2720 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
2721 tx_flags |= TX_CMD_FLG_CTS_MSK;
2722 }
2723
2724 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
2725 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
2726
2727 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
2728 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
2729 if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ ||
2730 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
Ian Schrambc434dd2007-10-25 17:15:29 +08002731 cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3);
Zhu Yib481de92007-09-25 17:54:57 -07002732 else
Ian Schrambc434dd2007-10-25 17:15:29 +08002733 cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2);
Zhu Yib481de92007-09-25 17:54:57 -07002734 } else
2735 cmd->cmd.tx.timeout.pm_frame_timeout = 0;
2736
2737 cmd->cmd.tx.driver_txop = 0;
2738 cmd->cmd.tx.tx_flags = tx_flags;
2739 cmd->cmd.tx.next_frame_len = 0;
2740}
2741
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002742static int iwl4965_get_sta_id(struct iwl4965_priv *priv, struct ieee80211_hdr *hdr)
Zhu Yib481de92007-09-25 17:54:57 -07002743{
2744 int sta_id;
2745 u16 fc = le16_to_cpu(hdr->frame_control);
Joe Perches0795af52007-10-03 17:59:30 -07002746 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07002747
2748 /* If this frame is broadcast or not data then use the broadcast
2749 * station id */
2750 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
2751 is_multicast_ether_addr(hdr->addr1))
2752 return priv->hw_setting.bcast_sta_id;
2753
2754 switch (priv->iw_mode) {
2755
2756 /* If this frame is part of a BSS network (we're a station), then
2757 * we use the AP's station id */
2758 case IEEE80211_IF_TYPE_STA:
2759 return IWL_AP_ID;
2760
2761 /* If we are an AP, then find the station, or use BCAST */
2762 case IEEE80211_IF_TYPE_AP:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002763 sta_id = iwl4965_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07002764 if (sta_id != IWL_INVALID_STATION)
2765 return sta_id;
2766 return priv->hw_setting.bcast_sta_id;
2767
2768 /* If this frame is part of a IBSS network, then we use the
2769 * target specific station id */
2770 case IEEE80211_IF_TYPE_IBSS:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002771 sta_id = iwl4965_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07002772 if (sta_id != IWL_INVALID_STATION)
2773 return sta_id;
2774
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002775 sta_id = iwl4965_add_station_flags(priv, hdr->addr1, 0, CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -07002776
2777 if (sta_id != IWL_INVALID_STATION)
2778 return sta_id;
2779
Joe Perches0795af52007-10-03 17:59:30 -07002780 IWL_DEBUG_DROP("Station %s not in station map. "
Zhu Yib481de92007-09-25 17:54:57 -07002781 "Defaulting to broadcast...\n",
Joe Perches0795af52007-10-03 17:59:30 -07002782 print_mac(mac, hdr->addr1));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002783 iwl4965_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
Zhu Yib481de92007-09-25 17:54:57 -07002784 return priv->hw_setting.bcast_sta_id;
2785
2786 default:
Ian Schram01ebd062007-10-25 17:15:22 +08002787 IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002788 return priv->hw_setting.bcast_sta_id;
2789 }
2790}
2791
2792/*
2793 * start REPLY_TX command process
2794 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002795static int iwl4965_tx_skb(struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002796 struct sk_buff *skb, struct ieee80211_tx_control *ctl)
2797{
2798 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002799 struct iwl4965_tfd_frame *tfd;
Zhu Yib481de92007-09-25 17:54:57 -07002800 u32 *control_flags;
2801 int txq_id = ctl->queue;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002802 struct iwl4965_tx_queue *txq = NULL;
2803 struct iwl4965_queue *q = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07002804 dma_addr_t phys_addr;
2805 dma_addr_t txcmd_phys;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002806 struct iwl4965_cmd *out_cmd = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07002807 u16 len, idx, len_org;
2808 u8 id, hdr_len, unicast;
2809 u8 sta_id;
2810 u16 seq_number = 0;
2811 u16 fc;
2812 __le16 *qc;
2813 u8 wait_write_ptr = 0;
2814 unsigned long flags;
2815 int rc;
2816
2817 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002818 if (iwl4965_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002819 IWL_DEBUG_DROP("Dropping - RF KILL\n");
2820 goto drop_unlock;
2821 }
2822
2823 if (!priv->interface_id) {
2824 IWL_DEBUG_DROP("Dropping - !priv->interface_id\n");
2825 goto drop_unlock;
2826 }
2827
2828 if ((ctl->tx_rate & 0xFF) == IWL_INVALID_RATE) {
2829 IWL_ERROR("ERROR: No TX rate available.\n");
2830 goto drop_unlock;
2831 }
2832
2833 unicast = !is_multicast_ether_addr(hdr->addr1);
2834 id = 0;
2835
2836 fc = le16_to_cpu(hdr->frame_control);
2837
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002838#ifdef CONFIG_IWL4965_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07002839 if (ieee80211_is_auth(fc))
2840 IWL_DEBUG_TX("Sending AUTH frame\n");
2841 else if (ieee80211_is_assoc_request(fc))
2842 IWL_DEBUG_TX("Sending ASSOC frame\n");
2843 else if (ieee80211_is_reassoc_request(fc))
2844 IWL_DEBUG_TX("Sending REASSOC frame\n");
2845#endif
2846
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002847 if (!iwl4965_is_associated(priv) &&
Zhu Yib481de92007-09-25 17:54:57 -07002848 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002849 IWL_DEBUG_DROP("Dropping - !iwl4965_is_associated\n");
Zhu Yib481de92007-09-25 17:54:57 -07002850 goto drop_unlock;
2851 }
2852
2853 spin_unlock_irqrestore(&priv->lock, flags);
2854
2855 hdr_len = ieee80211_get_hdrlen(fc);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002856 sta_id = iwl4965_get_sta_id(priv, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07002857 if (sta_id == IWL_INVALID_STATION) {
Joe Perches0795af52007-10-03 17:59:30 -07002858 DECLARE_MAC_BUF(mac);
2859
2860 IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
2861 print_mac(mac, hdr->addr1));
Zhu Yib481de92007-09-25 17:54:57 -07002862 goto drop;
2863 }
2864
2865 IWL_DEBUG_RATE("station Id %d\n", sta_id);
2866
2867 qc = ieee80211_get_qos_ctrl(hdr);
2868 if (qc) {
2869 u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
2870 seq_number = priv->stations[sta_id].tid[tid].seq_number &
2871 IEEE80211_SCTL_SEQ;
2872 hdr->seq_ctrl = cpu_to_le16(seq_number) |
2873 (hdr->seq_ctrl &
2874 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG));
2875 seq_number += 0x10;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002876#ifdef CONFIG_IWL4965_HT
2877#ifdef CONFIG_IWL4965_HT_AGG
Zhu Yib481de92007-09-25 17:54:57 -07002878 /* aggregation is on for this <sta,tid> */
2879 if (ctl->flags & IEEE80211_TXCTL_HT_MPDU_AGG)
2880 txq_id = priv->stations[sta_id].tid[tid].agg.txq_id;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002881#endif /* CONFIG_IWL4965_HT_AGG */
2882#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07002883 }
2884 txq = &priv->txq[txq_id];
2885 q = &txq->q;
2886
2887 spin_lock_irqsave(&priv->lock, flags);
2888
Tomas Winklerfc4b6852007-10-25 17:15:24 +08002889 tfd = &txq->bd[q->write_ptr];
Zhu Yib481de92007-09-25 17:54:57 -07002890 memset(tfd, 0, sizeof(*tfd));
2891 control_flags = (u32 *) tfd;
Tomas Winklerfc4b6852007-10-25 17:15:24 +08002892 idx = get_cmd_index(q, q->write_ptr, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002893
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002894 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl4965_tx_info));
Tomas Winklerfc4b6852007-10-25 17:15:24 +08002895 txq->txb[q->write_ptr].skb[0] = skb;
2896 memcpy(&(txq->txb[q->write_ptr].status.control),
Zhu Yib481de92007-09-25 17:54:57 -07002897 ctl, sizeof(struct ieee80211_tx_control));
2898 out_cmd = &txq->cmd[idx];
2899 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
2900 memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx));
2901 out_cmd->hdr.cmd = REPLY_TX;
2902 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +08002903 INDEX_TO_SEQ(q->write_ptr)));
Zhu Yib481de92007-09-25 17:54:57 -07002904 /* copy frags header */
2905 memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len);
2906
2907 /* hdr = (struct ieee80211_hdr *)out_cmd->cmd.tx.hdr; */
2908 len = priv->hw_setting.tx_cmd_len +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002909 sizeof(struct iwl4965_cmd_header) + hdr_len;
Zhu Yib481de92007-09-25 17:54:57 -07002910
2911 len_org = len;
2912 len = (len + 3) & ~3;
2913
2914 if (len_org != len)
2915 len_org = 1;
2916 else
2917 len_org = 0;
2918
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002919 txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl4965_cmd) * idx +
2920 offsetof(struct iwl4965_cmd, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07002921
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002922 iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len);
Zhu Yib481de92007-09-25 17:54:57 -07002923
2924 if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002925 iwl4965_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002926
2927 /* 802.11 null functions have no payload... */
2928 len = skb->len - hdr_len;
2929 if (len) {
2930 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
2931 len, PCI_DMA_TODEVICE);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002932 iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len);
Zhu Yib481de92007-09-25 17:54:57 -07002933 }
2934
2935 if (len_org)
2936 out_cmd->cmd.tx.tx_flags |= TX_CMD_FLG_MH_PAD_MSK;
2937
2938 len = (u16)skb->len;
2939 out_cmd->cmd.tx.len = cpu_to_le16(len);
2940
2941 /* TODO need this for burst mode later on */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002942 iwl4965_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07002943
2944 /* set is_hcca to 0; it probably will never be implemented */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002945 iwl4965_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002946
2947 iwl4965_tx_cmd(priv, out_cmd, sta_id, txcmd_phys,
2948 hdr, hdr_len, ctl, NULL);
2949
2950 if (!ieee80211_get_morefrag(hdr)) {
2951 txq->need_update = 1;
2952 if (qc) {
2953 u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
2954 priv->stations[sta_id].tid[tid].seq_number = seq_number;
2955 }
2956 } else {
2957 wait_write_ptr = 1;
2958 txq->need_update = 0;
2959 }
2960
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002961 iwl4965_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload,
Zhu Yib481de92007-09-25 17:54:57 -07002962 sizeof(out_cmd->cmd.tx));
2963
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002964 iwl4965_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr,
Zhu Yib481de92007-09-25 17:54:57 -07002965 ieee80211_get_hdrlen(fc));
2966
2967 iwl4965_tx_queue_update_wr_ptr(priv, txq, len);
2968
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002969 q->write_ptr = iwl4965_queue_inc_wrap(q->write_ptr, q->n_bd);
2970 rc = iwl4965_tx_queue_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07002971 spin_unlock_irqrestore(&priv->lock, flags);
2972
2973 if (rc)
2974 return rc;
2975
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002976 if ((iwl4965_queue_space(q) < q->high_mark)
Zhu Yib481de92007-09-25 17:54:57 -07002977 && priv->mac80211_registered) {
2978 if (wait_write_ptr) {
2979 spin_lock_irqsave(&priv->lock, flags);
2980 txq->need_update = 1;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002981 iwl4965_tx_queue_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07002982 spin_unlock_irqrestore(&priv->lock, flags);
2983 }
2984
2985 ieee80211_stop_queue(priv->hw, ctl->queue);
2986 }
2987
2988 return 0;
2989
2990drop_unlock:
2991 spin_unlock_irqrestore(&priv->lock, flags);
2992drop:
2993 return -1;
2994}
2995
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002996static void iwl4965_set_rate(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002997{
2998 const struct ieee80211_hw_mode *hw = NULL;
2999 struct ieee80211_rate *rate;
3000 int i;
3001
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003002 hw = iwl4965_get_hw_mode(priv, priv->phymode);
Saleem Abdulrasoolc4ba9622007-11-18 23:59:08 -08003003 if (!hw) {
3004 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
3005 return;
3006 }
Zhu Yib481de92007-09-25 17:54:57 -07003007
3008 priv->active_rate = 0;
3009 priv->active_rate_basic = 0;
3010
3011 IWL_DEBUG_RATE("Setting rates for 802.11%c\n",
3012 hw->mode == MODE_IEEE80211A ?
3013 'a' : ((hw->mode == MODE_IEEE80211B) ? 'b' : 'g'));
3014
3015 for (i = 0; i < hw->num_rates; i++) {
3016 rate = &(hw->rates[i]);
3017 if ((rate->val < IWL_RATE_COUNT) &&
3018 (rate->flags & IEEE80211_RATE_SUPPORTED)) {
3019 IWL_DEBUG_RATE("Adding rate index %d (plcp %d)%s\n",
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003020 rate->val, iwl4965_rates[rate->val].plcp,
Zhu Yib481de92007-09-25 17:54:57 -07003021 (rate->flags & IEEE80211_RATE_BASIC) ?
3022 "*" : "");
3023 priv->active_rate |= (1 << rate->val);
3024 if (rate->flags & IEEE80211_RATE_BASIC)
3025 priv->active_rate_basic |= (1 << rate->val);
3026 } else
3027 IWL_DEBUG_RATE("Not adding rate %d (plcp %d)\n",
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003028 rate->val, iwl4965_rates[rate->val].plcp);
Zhu Yib481de92007-09-25 17:54:57 -07003029 }
3030
3031 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
3032 priv->active_rate, priv->active_rate_basic);
3033
3034 /*
3035 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
3036 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
3037 * OFDM
3038 */
3039 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
3040 priv->staging_rxon.cck_basic_rates =
3041 ((priv->active_rate_basic &
3042 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
3043 else
3044 priv->staging_rxon.cck_basic_rates =
3045 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
3046
3047 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
3048 priv->staging_rxon.ofdm_basic_rates =
3049 ((priv->active_rate_basic &
3050 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
3051 IWL_FIRST_OFDM_RATE) & 0xFF;
3052 else
3053 priv->staging_rxon.ofdm_basic_rates =
3054 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
3055}
3056
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003057static void iwl4965_radio_kill_sw(struct iwl4965_priv *priv, int disable_radio)
Zhu Yib481de92007-09-25 17:54:57 -07003058{
3059 unsigned long flags;
3060
3061 if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
3062 return;
3063
3064 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
3065 disable_radio ? "OFF" : "ON");
3066
3067 if (disable_radio) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003068 iwl4965_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003069 /* FIXME: This is a workaround for AP */
3070 if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
3071 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003072 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07003073 CSR_UCODE_SW_BIT_RFKILL);
3074 spin_unlock_irqrestore(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003075 iwl4965_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003076 set_bit(STATUS_RF_KILL_SW, &priv->status);
3077 }
3078 return;
3079 }
3080
3081 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003082 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07003083
3084 clear_bit(STATUS_RF_KILL_SW, &priv->status);
3085 spin_unlock_irqrestore(&priv->lock, flags);
3086
3087 /* wake up ucode */
3088 msleep(10);
3089
3090 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003091 iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
3092 if (!iwl4965_grab_nic_access(priv))
3093 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003094 spin_unlock_irqrestore(&priv->lock, flags);
3095
3096 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
3097 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
3098 "disabled by HW switch\n");
3099 return;
3100 }
3101
3102 queue_work(priv->workqueue, &priv->restart);
3103 return;
3104}
3105
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003106void iwl4965_set_decrypted_flag(struct iwl4965_priv *priv, struct sk_buff *skb,
Zhu Yib481de92007-09-25 17:54:57 -07003107 u32 decrypt_res, struct ieee80211_rx_status *stats)
3108{
3109 u16 fc =
3110 le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control);
3111
3112 if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
3113 return;
3114
3115 if (!(fc & IEEE80211_FCTL_PROTECTED))
3116 return;
3117
3118 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
3119 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
3120 case RX_RES_STATUS_SEC_TYPE_TKIP:
3121 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
3122 RX_RES_STATUS_BAD_ICV_MIC)
3123 stats->flag |= RX_FLAG_MMIC_ERROR;
3124 case RX_RES_STATUS_SEC_TYPE_WEP:
3125 case RX_RES_STATUS_SEC_TYPE_CCMP:
3126 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
3127 RX_RES_STATUS_DECRYPT_OK) {
3128 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
3129 stats->flag |= RX_FLAG_DECRYPTED;
3130 }
3131 break;
3132
3133 default:
3134 break;
3135 }
3136}
3137
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003138void iwl4965_handle_data_packet_monitor(struct iwl4965_priv *priv,
3139 struct iwl4965_rx_mem_buffer *rxb,
Zhu Yib481de92007-09-25 17:54:57 -07003140 void *data, short len,
3141 struct ieee80211_rx_status *stats,
3142 u16 phy_flags)
3143{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003144 struct iwl4965_rt_rx_hdr *iwl4965_rt;
Zhu Yib481de92007-09-25 17:54:57 -07003145
3146 /* First cache any information we need before we overwrite
3147 * the information provided in the skb from the hardware */
3148 s8 signal = stats->ssi;
3149 s8 noise = 0;
3150 int rate = stats->rate;
3151 u64 tsf = stats->mactime;
3152 __le16 phy_flags_hw = cpu_to_le16(phy_flags);
3153
3154 /* We received data from the HW, so stop the watchdog */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003155 if (len > IWL_RX_BUF_SIZE - sizeof(*iwl4965_rt)) {
Zhu Yib481de92007-09-25 17:54:57 -07003156 IWL_DEBUG_DROP("Dropping too large packet in monitor\n");
3157 return;
3158 }
3159
3160 /* copy the frame data to write after where the radiotap header goes */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003161 iwl4965_rt = (void *)rxb->skb->data;
3162 memmove(iwl4965_rt->payload, data, len);
Zhu Yib481de92007-09-25 17:54:57 -07003163
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003164 iwl4965_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
3165 iwl4965_rt->rt_hdr.it_pad = 0; /* always good to zero */
Zhu Yib481de92007-09-25 17:54:57 -07003166
3167 /* total header + data */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003168 iwl4965_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*iwl4965_rt));
Zhu Yib481de92007-09-25 17:54:57 -07003169
3170 /* Set the size of the skb to the size of the frame */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003171 skb_put(rxb->skb, sizeof(*iwl4965_rt) + len);
Zhu Yib481de92007-09-25 17:54:57 -07003172
3173 /* Big bitfield of all the fields we provide in radiotap */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003174 iwl4965_rt->rt_hdr.it_present =
Zhu Yib481de92007-09-25 17:54:57 -07003175 cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) |
3176 (1 << IEEE80211_RADIOTAP_FLAGS) |
3177 (1 << IEEE80211_RADIOTAP_RATE) |
3178 (1 << IEEE80211_RADIOTAP_CHANNEL) |
3179 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
3180 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
3181 (1 << IEEE80211_RADIOTAP_ANTENNA));
3182
3183 /* Zero the flags, we'll add to them as we go */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003184 iwl4965_rt->rt_flags = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003185
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003186 iwl4965_rt->rt_tsf = cpu_to_le64(tsf);
Zhu Yib481de92007-09-25 17:54:57 -07003187
3188 /* Convert to dBm */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003189 iwl4965_rt->rt_dbmsignal = signal;
3190 iwl4965_rt->rt_dbmnoise = noise;
Zhu Yib481de92007-09-25 17:54:57 -07003191
3192 /* Convert the channel frequency and set the flags */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003193 iwl4965_rt->rt_channelMHz = cpu_to_le16(stats->freq);
Zhu Yib481de92007-09-25 17:54:57 -07003194 if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003195 iwl4965_rt->rt_chbitmask =
Zhu Yib481de92007-09-25 17:54:57 -07003196 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
3197 else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003198 iwl4965_rt->rt_chbitmask =
Zhu Yib481de92007-09-25 17:54:57 -07003199 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
3200 else /* 802.11g */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003201 iwl4965_rt->rt_chbitmask =
Zhu Yib481de92007-09-25 17:54:57 -07003202 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ));
3203
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003204 rate = iwl4965_rate_index_from_plcp(rate);
Zhu Yib481de92007-09-25 17:54:57 -07003205 if (rate == -1)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003206 iwl4965_rt->rt_rate = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003207 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003208 iwl4965_rt->rt_rate = iwl4965_rates[rate].ieee;
Zhu Yib481de92007-09-25 17:54:57 -07003209
3210 /* antenna number */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003211 iwl4965_rt->rt_antenna =
Zhu Yib481de92007-09-25 17:54:57 -07003212 le16_to_cpu(phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK) >> 4;
3213
3214 /* set the preamble flag if we have it */
3215 if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003216 iwl4965_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
Zhu Yib481de92007-09-25 17:54:57 -07003217
3218 IWL_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
3219
3220 stats->flag |= RX_FLAG_RADIOTAP;
3221 ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats);
3222 rxb->skb = NULL;
3223}
3224
3225
3226#define IWL_PACKET_RETRY_TIME HZ
3227
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003228int iwl4965_is_duplicate_packet(struct iwl4965_priv *priv, struct ieee80211_hdr *header)
Zhu Yib481de92007-09-25 17:54:57 -07003229{
3230 u16 sc = le16_to_cpu(header->seq_ctrl);
3231 u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
3232 u16 frag = sc & IEEE80211_SCTL_FRAG;
3233 u16 *last_seq, *last_frag;
3234 unsigned long *last_time;
3235
3236 switch (priv->iw_mode) {
3237 case IEEE80211_IF_TYPE_IBSS:{
3238 struct list_head *p;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003239 struct iwl4965_ibss_seq *entry = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07003240 u8 *mac = header->addr2;
3241 int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1);
3242
3243 __list_for_each(p, &priv->ibss_mac_hash[index]) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003244 entry = list_entry(p, struct iwl4965_ibss_seq, list);
Zhu Yib481de92007-09-25 17:54:57 -07003245 if (!compare_ether_addr(entry->mac, mac))
3246 break;
3247 }
3248 if (p == &priv->ibss_mac_hash[index]) {
3249 entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
3250 if (!entry) {
Ian Schrambc434dd2007-10-25 17:15:29 +08003251 IWL_ERROR("Cannot malloc new mac entry\n");
Zhu Yib481de92007-09-25 17:54:57 -07003252 return 0;
3253 }
3254 memcpy(entry->mac, mac, ETH_ALEN);
3255 entry->seq_num = seq;
3256 entry->frag_num = frag;
3257 entry->packet_time = jiffies;
Ian Schrambc434dd2007-10-25 17:15:29 +08003258 list_add(&entry->list, &priv->ibss_mac_hash[index]);
Zhu Yib481de92007-09-25 17:54:57 -07003259 return 0;
3260 }
3261 last_seq = &entry->seq_num;
3262 last_frag = &entry->frag_num;
3263 last_time = &entry->packet_time;
3264 break;
3265 }
3266 case IEEE80211_IF_TYPE_STA:
3267 last_seq = &priv->last_seq_num;
3268 last_frag = &priv->last_frag_num;
3269 last_time = &priv->last_packet_time;
3270 break;
3271 default:
3272 return 0;
3273 }
3274 if ((*last_seq == seq) &&
3275 time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) {
3276 if (*last_frag == frag)
3277 goto drop;
3278 if (*last_frag + 1 != frag)
3279 /* out-of-order fragment */
3280 goto drop;
3281 } else
3282 *last_seq = seq;
3283
3284 *last_frag = frag;
3285 *last_time = jiffies;
3286 return 0;
3287
3288 drop:
3289 return 1;
3290}
3291
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003292#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07003293
3294#include "iwl-spectrum.h"
3295
3296#define BEACON_TIME_MASK_LOW 0x00FFFFFF
3297#define BEACON_TIME_MASK_HIGH 0xFF000000
3298#define TIME_UNIT 1024
3299
3300/*
3301 * extended beacon time format
3302 * time in usec will be changed into a 32-bit value in 8:24 format
3303 * the high 1 byte is the beacon counts
3304 * the lower 3 bytes is the time in usec within one beacon interval
3305 */
3306
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003307static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07003308{
3309 u32 quot;
3310 u32 rem;
3311 u32 interval = beacon_interval * 1024;
3312
3313 if (!interval || !usec)
3314 return 0;
3315
3316 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
3317 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
3318
3319 return (quot << 24) + rem;
3320}
3321
3322/* base is usually what we get from ucode with each received frame,
3323 * the same as HW timer counter counting down
3324 */
3325
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003326static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07003327{
3328 u32 base_low = base & BEACON_TIME_MASK_LOW;
3329 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
3330 u32 interval = beacon_interval * TIME_UNIT;
3331 u32 res = (base & BEACON_TIME_MASK_HIGH) +
3332 (addon & BEACON_TIME_MASK_HIGH);
3333
3334 if (base_low > addon_low)
3335 res += base_low - addon_low;
3336 else if (base_low < addon_low) {
3337 res += interval + base_low - addon_low;
3338 res += (1 << 24);
3339 } else
3340 res += (1 << 24);
3341
3342 return cpu_to_le32(res);
3343}
3344
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003345static int iwl4965_get_measurement(struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07003346 struct ieee80211_measurement_params *params,
3347 u8 type)
3348{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003349 struct iwl4965_spectrum_cmd spectrum;
3350 struct iwl4965_rx_packet *res;
3351 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07003352 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
3353 .data = (void *)&spectrum,
3354 .meta.flags = CMD_WANT_SKB,
3355 };
3356 u32 add_time = le64_to_cpu(params->start_time);
3357 int rc;
3358 int spectrum_resp_status;
3359 int duration = le16_to_cpu(params->duration);
3360
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003361 if (iwl4965_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003362 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003363 iwl4965_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -07003364 le64_to_cpu(params->start_time) - priv->last_tsf,
3365 le16_to_cpu(priv->rxon_timing.beacon_interval));
3366
3367 memset(&spectrum, 0, sizeof(spectrum));
3368
3369 spectrum.channel_count = cpu_to_le16(1);
3370 spectrum.flags =
3371 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
3372 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
3373 cmd.len = sizeof(spectrum);
3374 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
3375
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003376 if (iwl4965_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003377 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003378 iwl4965_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -07003379 add_time,
3380 le16_to_cpu(priv->rxon_timing.beacon_interval));
3381 else
3382 spectrum.start_time = 0;
3383
3384 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
3385 spectrum.channels[0].channel = params->channel;
3386 spectrum.channels[0].type = type;
3387 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
3388 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
3389 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
3390
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003391 rc = iwl4965_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07003392 if (rc)
3393 return rc;
3394
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003395 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07003396 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
3397 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
3398 rc = -EIO;
3399 }
3400
3401 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
3402 switch (spectrum_resp_status) {
3403 case 0: /* Command will be handled */
3404 if (res->u.spectrum.id != 0xff) {
3405 IWL_DEBUG_INFO
3406 ("Replaced existing measurement: %d\n",
3407 res->u.spectrum.id);
3408 priv->measurement_status &= ~MEASUREMENT_READY;
3409 }
3410 priv->measurement_status |= MEASUREMENT_ACTIVE;
3411 rc = 0;
3412 break;
3413
3414 case 1: /* Command will not be handled */
3415 rc = -EAGAIN;
3416 break;
3417 }
3418
3419 dev_kfree_skb_any(cmd.meta.u.skb);
3420
3421 return rc;
3422}
3423#endif
3424
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003425static void iwl4965_txstatus_to_ieee(struct iwl4965_priv *priv,
3426 struct iwl4965_tx_info *tx_sta)
Zhu Yib481de92007-09-25 17:54:57 -07003427{
3428
3429 tx_sta->status.ack_signal = 0;
3430 tx_sta->status.excessive_retries = 0;
3431 tx_sta->status.queue_length = 0;
3432 tx_sta->status.queue_number = 0;
3433
3434 if (in_interrupt())
3435 ieee80211_tx_status_irqsafe(priv->hw,
3436 tx_sta->skb[0], &(tx_sta->status));
3437 else
3438 ieee80211_tx_status(priv->hw,
3439 tx_sta->skb[0], &(tx_sta->status));
3440
3441 tx_sta->skb[0] = NULL;
3442}
3443
3444/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003445 * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries no more used by NIC.
Zhu Yib481de92007-09-25 17:54:57 -07003446 *
3447 * When FW advances 'R' index, all entries between old and
3448 * new 'R' index need to be reclaimed. As result, some free space
3449 * forms. If there is enough free space (> low mark), wake Tx queue.
3450 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003451int iwl4965_tx_queue_reclaim(struct iwl4965_priv *priv, int txq_id, int index)
Zhu Yib481de92007-09-25 17:54:57 -07003452{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003453 struct iwl4965_tx_queue *txq = &priv->txq[txq_id];
3454 struct iwl4965_queue *q = &txq->q;
Zhu Yib481de92007-09-25 17:54:57 -07003455 int nfreed = 0;
3456
3457 if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) {
3458 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
3459 "is out of range [0-%d] %d %d.\n", txq_id,
Tomas Winklerfc4b6852007-10-25 17:15:24 +08003460 index, q->n_bd, q->write_ptr, q->read_ptr);
Zhu Yib481de92007-09-25 17:54:57 -07003461 return 0;
3462 }
3463
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003464 for (index = iwl4965_queue_inc_wrap(index, q->n_bd);
Tomas Winklerfc4b6852007-10-25 17:15:24 +08003465 q->read_ptr != index;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003466 q->read_ptr = iwl4965_queue_inc_wrap(q->read_ptr, q->n_bd)) {
Zhu Yib481de92007-09-25 17:54:57 -07003467 if (txq_id != IWL_CMD_QUEUE_NUM) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003468 iwl4965_txstatus_to_ieee(priv,
Tomas Winklerfc4b6852007-10-25 17:15:24 +08003469 &(txq->txb[txq->q.read_ptr]));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003470 iwl4965_hw_txq_free_tfd(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07003471 } else if (nfreed > 1) {
3472 IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index,
Tomas Winklerfc4b6852007-10-25 17:15:24 +08003473 q->write_ptr, q->read_ptr);
Zhu Yib481de92007-09-25 17:54:57 -07003474 queue_work(priv->workqueue, &priv->restart);
3475 }
3476 nfreed++;
3477 }
3478
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003479 if (iwl4965_queue_space(q) > q->low_mark && (txq_id >= 0) &&
Zhu Yib481de92007-09-25 17:54:57 -07003480 (txq_id != IWL_CMD_QUEUE_NUM) &&
3481 priv->mac80211_registered)
3482 ieee80211_wake_queue(priv->hw, txq_id);
3483
3484
3485 return nfreed;
3486}
3487
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003488static int iwl4965_is_tx_success(u32 status)
Zhu Yib481de92007-09-25 17:54:57 -07003489{
3490 status &= TX_STATUS_MSK;
3491 return (status == TX_STATUS_SUCCESS)
3492 || (status == TX_STATUS_DIRECT_DONE);
3493}
3494
3495/******************************************************************************
3496 *
3497 * Generic RX handler implementations
3498 *
3499 ******************************************************************************/
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003500#ifdef CONFIG_IWL4965_HT
3501#ifdef CONFIG_IWL4965_HT_AGG
Zhu Yib481de92007-09-25 17:54:57 -07003502
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003503static inline int iwl4965_get_ra_sta_id(struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07003504 struct ieee80211_hdr *hdr)
3505{
3506 if (priv->iw_mode == IEEE80211_IF_TYPE_STA)
3507 return IWL_AP_ID;
3508 else {
3509 u8 *da = ieee80211_get_DA(hdr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003510 return iwl4965_hw_find_station(priv, da);
Zhu Yib481de92007-09-25 17:54:57 -07003511 }
3512}
3513
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003514static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr(
3515 struct iwl4965_priv *priv, int txq_id, int idx)
Zhu Yib481de92007-09-25 17:54:57 -07003516{
3517 if (priv->txq[txq_id].txb[idx].skb[0])
3518 return (struct ieee80211_hdr *)priv->txq[txq_id].
3519 txb[idx].skb[0]->data;
3520 return NULL;
3521}
3522
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003523static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp)
Zhu Yib481de92007-09-25 17:54:57 -07003524{
3525 __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status +
3526 tx_resp->frame_count);
3527 return le32_to_cpu(*scd_ssn) & MAX_SN;
3528
3529}
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003530static int iwl4965_tx_status_reply_tx(struct iwl4965_priv *priv,
3531 struct iwl4965_ht_agg *agg,
3532 struct iwl4965_tx_resp *tx_resp,
Zhu Yib481de92007-09-25 17:54:57 -07003533 u16 start_idx)
3534{
3535 u32 status;
3536 __le32 *frame_status = &tx_resp->status;
3537 struct ieee80211_tx_status *tx_status = NULL;
3538 struct ieee80211_hdr *hdr = NULL;
3539 int i, sh;
3540 int txq_id, idx;
3541 u16 seq;
3542
3543 if (agg->wait_for_ba)
3544 IWL_DEBUG_TX_REPLY("got tx repsons w/o back\n");
3545
3546 agg->frame_count = tx_resp->frame_count;
3547 agg->start_idx = start_idx;
3548 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
3549 agg->bitmap0 = agg->bitmap1 = 0;
3550
3551 if (agg->frame_count == 1) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003552 struct iwl4965_tx_queue *txq ;
Zhu Yib481de92007-09-25 17:54:57 -07003553 status = le32_to_cpu(frame_status[0]);
3554
3555 txq_id = agg->txq_id;
3556 txq = &priv->txq[txq_id];
3557 /* FIXME: code repetition */
3558 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d \n",
3559 agg->frame_count, agg->start_idx);
3560
Tomas Winklerfc4b6852007-10-25 17:15:24 +08003561 tx_status = &(priv->txq[txq_id].txb[txq->q.read_ptr].status);
Zhu Yib481de92007-09-25 17:54:57 -07003562 tx_status->retry_count = tx_resp->failure_frame;
3563 tx_status->queue_number = status & 0xff;
3564 tx_status->queue_length = tx_resp->bt_kill_count;
3565 tx_status->queue_length |= tx_resp->failure_rts;
3566
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003567 tx_status->flags = iwl4965_is_tx_success(status)?
Zhu Yib481de92007-09-25 17:54:57 -07003568 IEEE80211_TX_STATUS_ACK : 0;
3569 tx_status->control.tx_rate =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003570 iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -07003571 /* FIXME: code repetition end */
3572
3573 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
3574 status & 0xff, tx_resp->failure_frame);
3575 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003576 iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags));
Zhu Yib481de92007-09-25 17:54:57 -07003577
3578 agg->wait_for_ba = 0;
3579 } else {
3580 u64 bitmap = 0;
3581 int start = agg->start_idx;
3582
3583 for (i = 0; i < agg->frame_count; i++) {
3584 u16 sc;
3585 status = le32_to_cpu(frame_status[i]);
3586 seq = status >> 16;
3587 idx = SEQ_TO_INDEX(seq);
3588 txq_id = SEQ_TO_QUEUE(seq);
3589
3590 if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
3591 AGG_TX_STATE_ABORT_MSK))
3592 continue;
3593
3594 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
3595 agg->frame_count, txq_id, idx);
3596
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003597 hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx);
Zhu Yib481de92007-09-25 17:54:57 -07003598
3599 sc = le16_to_cpu(hdr->seq_ctrl);
3600 if (idx != (SEQ_TO_SN(sc) & 0xff)) {
3601 IWL_ERROR("BUG_ON idx doesn't match seq control"
3602 " idx=%d, seq_idx=%d, seq=%d\n",
3603 idx, SEQ_TO_SN(sc),
3604 hdr->seq_ctrl);
3605 return -1;
3606 }
3607
3608 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
3609 i, idx, SEQ_TO_SN(sc));
3610
3611 sh = idx - start;
3612 if (sh > 64) {
3613 sh = (start - idx) + 0xff;
3614 bitmap = bitmap << sh;
3615 sh = 0;
3616 start = idx;
3617 } else if (sh < -64)
3618 sh = 0xff - (start - idx);
3619 else if (sh < 0) {
3620 sh = start - idx;
3621 start = idx;
3622 bitmap = bitmap << sh;
3623 sh = 0;
3624 }
3625 bitmap |= (1 << sh);
3626 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
3627 start, (u32)(bitmap & 0xFFFFFFFF));
3628 }
3629
3630 agg->bitmap0 = bitmap & 0xFFFFFFFF;
3631 agg->bitmap1 = bitmap >> 32;
3632 agg->start_idx = start;
3633 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
3634 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%x\n",
3635 agg->frame_count, agg->start_idx,
3636 agg->bitmap0);
3637
3638 if (bitmap)
3639 agg->wait_for_ba = 1;
3640 }
3641 return 0;
3642}
3643#endif
3644#endif
3645
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003646static void iwl4965_rx_reply_tx(struct iwl4965_priv *priv,
3647 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003648{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003649 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07003650 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
3651 int txq_id = SEQ_TO_QUEUE(sequence);
3652 int index = SEQ_TO_INDEX(sequence);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003653 struct iwl4965_tx_queue *txq = &priv->txq[txq_id];
Zhu Yib481de92007-09-25 17:54:57 -07003654 struct ieee80211_tx_status *tx_status;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003655 struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
Zhu Yib481de92007-09-25 17:54:57 -07003656 u32 status = le32_to_cpu(tx_resp->status);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003657#ifdef CONFIG_IWL4965_HT
3658#ifdef CONFIG_IWL4965_HT_AGG
Zhu Yib481de92007-09-25 17:54:57 -07003659 int tid, sta_id;
3660#endif
3661#endif
3662
3663 if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) {
3664 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
3665 "is out of range [0-%d] %d %d\n", txq_id,
Tomas Winklerfc4b6852007-10-25 17:15:24 +08003666 index, txq->q.n_bd, txq->q.write_ptr,
3667 txq->q.read_ptr);
Zhu Yib481de92007-09-25 17:54:57 -07003668 return;
3669 }
3670
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003671#ifdef CONFIG_IWL4965_HT
3672#ifdef CONFIG_IWL4965_HT_AGG
Zhu Yib481de92007-09-25 17:54:57 -07003673 if (txq->sched_retry) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003674 const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp);
Zhu Yib481de92007-09-25 17:54:57 -07003675 struct ieee80211_hdr *hdr =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003676 iwl4965_tx_queue_get_hdr(priv, txq_id, index);
3677 struct iwl4965_ht_agg *agg = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07003678 __le16 *qc = ieee80211_get_qos_ctrl(hdr);
3679
3680 if (qc == NULL) {
3681 IWL_ERROR("BUG_ON qc is null!!!!\n");
3682 return;
3683 }
3684
3685 tid = le16_to_cpu(*qc) & 0xf;
3686
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003687 sta_id = iwl4965_get_ra_sta_id(priv, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07003688 if (unlikely(sta_id == IWL_INVALID_STATION)) {
3689 IWL_ERROR("Station not known for\n");
3690 return;
3691 }
3692
3693 agg = &priv->stations[sta_id].tid[tid].agg;
3694
3695 iwl4965_tx_status_reply_tx(priv, agg, tx_resp, index);
3696
3697 if ((tx_resp->frame_count == 1) &&
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003698 !iwl4965_is_tx_success(status)) {
Zhu Yib481de92007-09-25 17:54:57 -07003699 /* TODO: send BAR */
3700 }
3701
Tomas Winklerfc4b6852007-10-25 17:15:24 +08003702 if ((txq->q.read_ptr != (scd_ssn & 0xff))) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003703 index = iwl4965_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
Zhu Yib481de92007-09-25 17:54:57 -07003704 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
3705 "%d index %d\n", scd_ssn , index);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003706 iwl4965_tx_queue_reclaim(priv, txq_id, index);
Zhu Yib481de92007-09-25 17:54:57 -07003707 }
3708 } else {
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003709#endif /* CONFIG_IWL4965_HT_AGG */
3710#endif /* CONFIG_IWL4965_HT */
Tomas Winklerfc4b6852007-10-25 17:15:24 +08003711 tx_status = &(txq->txb[txq->q.read_ptr].status);
Zhu Yib481de92007-09-25 17:54:57 -07003712
3713 tx_status->retry_count = tx_resp->failure_frame;
3714 tx_status->queue_number = status;
3715 tx_status->queue_length = tx_resp->bt_kill_count;
3716 tx_status->queue_length |= tx_resp->failure_rts;
3717
3718 tx_status->flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003719 iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0;
Zhu Yib481de92007-09-25 17:54:57 -07003720
3721 tx_status->control.tx_rate =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003722 iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -07003723
3724 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x "
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003725 "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status),
Zhu Yib481de92007-09-25 17:54:57 -07003726 status, le32_to_cpu(tx_resp->rate_n_flags),
3727 tx_resp->failure_frame);
3728
3729 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
3730 if (index != -1)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003731 iwl4965_tx_queue_reclaim(priv, txq_id, index);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003732#ifdef CONFIG_IWL4965_HT
3733#ifdef CONFIG_IWL4965_HT_AGG
Zhu Yib481de92007-09-25 17:54:57 -07003734 }
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003735#endif /* CONFIG_IWL4965_HT_AGG */
3736#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07003737
3738 if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
3739 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
3740}
3741
3742
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003743static void iwl4965_rx_reply_alive(struct iwl4965_priv *priv,
3744 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003745{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003746 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3747 struct iwl4965_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -07003748 struct delayed_work *pwork;
3749
3750 palive = &pkt->u.alive_frame;
3751
3752 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
3753 "0x%01X 0x%01X\n",
3754 palive->is_valid, palive->ver_type,
3755 palive->ver_subtype);
3756
3757 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
3758 IWL_DEBUG_INFO("Initialization Alive received.\n");
3759 memcpy(&priv->card_alive_init,
3760 &pkt->u.alive_frame,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003761 sizeof(struct iwl4965_init_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07003762 pwork = &priv->init_alive_start;
3763 } else {
3764 IWL_DEBUG_INFO("Runtime Alive received.\n");
3765 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003766 sizeof(struct iwl4965_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07003767 pwork = &priv->alive_start;
3768 }
3769
3770 /* We delay the ALIVE response by 5ms to
3771 * give the HW RF Kill time to activate... */
3772 if (palive->is_valid == UCODE_VALID_OK)
3773 queue_delayed_work(priv->workqueue, pwork,
3774 msecs_to_jiffies(5));
3775 else
3776 IWL_WARNING("uCode did not respond OK.\n");
3777}
3778
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003779static void iwl4965_rx_reply_add_sta(struct iwl4965_priv *priv,
3780 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003781{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003782 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07003783
3784 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
3785 return;
3786}
3787
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003788static void iwl4965_rx_reply_error(struct iwl4965_priv *priv,
3789 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003790{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003791 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07003792
3793 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
3794 "seq 0x%04X ser 0x%08X\n",
3795 le32_to_cpu(pkt->u.err_resp.error_type),
3796 get_cmd_string(pkt->u.err_resp.cmd_id),
3797 pkt->u.err_resp.cmd_id,
3798 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
3799 le32_to_cpu(pkt->u.err_resp.error_info));
3800}
3801
3802#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
3803
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003804static void iwl4965_rx_csa(struct iwl4965_priv *priv, struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003805{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003806 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3807 struct iwl4965_rxon_cmd *rxon = (void *)&priv->active_rxon;
3808 struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif);
Zhu Yib481de92007-09-25 17:54:57 -07003809 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
3810 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
3811 rxon->channel = csa->channel;
3812 priv->staging_rxon.channel = csa->channel;
3813}
3814
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003815static void iwl4965_rx_spectrum_measure_notif(struct iwl4965_priv *priv,
3816 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003817{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003818#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003819 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3820 struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif);
Zhu Yib481de92007-09-25 17:54:57 -07003821
3822 if (!report->state) {
3823 IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO,
3824 "Spectrum Measure Notification: Start\n");
3825 return;
3826 }
3827
3828 memcpy(&priv->measure_report, report, sizeof(*report));
3829 priv->measurement_status |= MEASUREMENT_READY;
3830#endif
3831}
3832
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003833static void iwl4965_rx_pm_sleep_notif(struct iwl4965_priv *priv,
3834 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003835{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003836#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003837 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3838 struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif);
Zhu Yib481de92007-09-25 17:54:57 -07003839 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
3840 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
3841#endif
3842}
3843
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003844static void iwl4965_rx_pm_debug_statistics_notif(struct iwl4965_priv *priv,
3845 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003846{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003847 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07003848 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
3849 "notification for %s:\n",
3850 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003851 iwl4965_print_hex_dump(IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
Zhu Yib481de92007-09-25 17:54:57 -07003852}
3853
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003854static void iwl4965_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07003855{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003856 struct iwl4965_priv *priv =
3857 container_of(work, struct iwl4965_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07003858 struct sk_buff *beacon;
3859
3860 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
3861 beacon = ieee80211_beacon_get(priv->hw, priv->interface_id, NULL);
3862
3863 if (!beacon) {
3864 IWL_ERROR("update beacon failed\n");
3865 return;
3866 }
3867
3868 mutex_lock(&priv->mutex);
3869 /* new beacon skb is allocated every time; dispose previous.*/
3870 if (priv->ibss_beacon)
3871 dev_kfree_skb(priv->ibss_beacon);
3872
3873 priv->ibss_beacon = beacon;
3874 mutex_unlock(&priv->mutex);
3875
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003876 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003877}
3878
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003879static void iwl4965_rx_beacon_notif(struct iwl4965_priv *priv,
3880 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003881{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003882#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003883 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3884 struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status);
3885 u8 rate = iwl4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -07003886
3887 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
3888 "tsf %d %d rate %d\n",
3889 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
3890 beacon->beacon_notify_hdr.failure_frame,
3891 le32_to_cpu(beacon->ibss_mgr_status),
3892 le32_to_cpu(beacon->high_tsf),
3893 le32_to_cpu(beacon->low_tsf), rate);
3894#endif
3895
3896 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
3897 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
3898 queue_work(priv->workqueue, &priv->beacon_update);
3899}
3900
3901/* Service response to REPLY_SCAN_CMD (0x80) */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003902static void iwl4965_rx_reply_scan(struct iwl4965_priv *priv,
3903 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003904{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003905#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003906 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3907 struct iwl4965_scanreq_notification *notif =
3908 (struct iwl4965_scanreq_notification *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07003909
3910 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status);
3911#endif
3912}
3913
3914/* Service SCAN_START_NOTIFICATION (0x82) */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003915static void iwl4965_rx_scan_start_notif(struct iwl4965_priv *priv,
3916 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003917{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003918 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3919 struct iwl4965_scanstart_notification *notif =
3920 (struct iwl4965_scanstart_notification *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07003921 priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
3922 IWL_DEBUG_SCAN("Scan start: "
3923 "%d [802.11%s] "
3924 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
3925 notif->channel,
3926 notif->band ? "bg" : "a",
3927 notif->tsf_high,
3928 notif->tsf_low, notif->status, notif->beacon_timer);
3929}
3930
3931/* Service SCAN_RESULTS_NOTIFICATION (0x83) */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003932static void iwl4965_rx_scan_results_notif(struct iwl4965_priv *priv,
3933 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003934{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003935 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3936 struct iwl4965_scanresults_notification *notif =
3937 (struct iwl4965_scanresults_notification *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07003938
3939 IWL_DEBUG_SCAN("Scan ch.res: "
3940 "%d [802.11%s] "
3941 "(TSF: 0x%08X:%08X) - %d "
3942 "elapsed=%lu usec (%dms since last)\n",
3943 notif->channel,
3944 notif->band ? "bg" : "a",
3945 le32_to_cpu(notif->tsf_high),
3946 le32_to_cpu(notif->tsf_low),
3947 le32_to_cpu(notif->statistics[0]),
3948 le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
3949 jiffies_to_msecs(elapsed_jiffies
3950 (priv->last_scan_jiffies, jiffies)));
3951
3952 priv->last_scan_jiffies = jiffies;
3953}
3954
3955/* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003956static void iwl4965_rx_scan_complete_notif(struct iwl4965_priv *priv,
3957 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003958{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003959 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3960 struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07003961
3962 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
3963 scan_notif->scanned_channels,
3964 scan_notif->tsf_low,
3965 scan_notif->tsf_high, scan_notif->status);
3966
3967 /* The HW is no longer scanning */
3968 clear_bit(STATUS_SCAN_HW, &priv->status);
3969
3970 /* The scan completion notification came in, so kill that timer... */
3971 cancel_delayed_work(&priv->scan_check);
3972
3973 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
3974 (priv->scan_bands == 2) ? "2.4" : "5.2",
3975 jiffies_to_msecs(elapsed_jiffies
3976 (priv->scan_pass_start, jiffies)));
3977
3978 /* Remove this scanned band from the list
3979 * of pending bands to scan */
3980 priv->scan_bands--;
3981
3982 /* If a request to abort was given, or the scan did not succeed
3983 * then we reset the scan state machine and terminate,
3984 * re-queuing another scan if one has been requested */
3985 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
3986 IWL_DEBUG_INFO("Aborted scan completed.\n");
3987 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
3988 } else {
3989 /* If there are more bands on this scan pass reschedule */
3990 if (priv->scan_bands > 0)
3991 goto reschedule;
3992 }
3993
3994 priv->last_scan_jiffies = jiffies;
3995 IWL_DEBUG_INFO("Setting scan to off\n");
3996
3997 clear_bit(STATUS_SCANNING, &priv->status);
3998
3999 IWL_DEBUG_INFO("Scan took %dms\n",
4000 jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
4001
4002 queue_work(priv->workqueue, &priv->scan_completed);
4003
4004 return;
4005
4006reschedule:
4007 priv->scan_pass_start = jiffies;
4008 queue_work(priv->workqueue, &priv->request_scan);
4009}
4010
4011/* Handle notification from uCode that card's power state is changing
4012 * due to software, hardware, or critical temperature RFKILL */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004013static void iwl4965_rx_card_state_notif(struct iwl4965_priv *priv,
4014 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07004015{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004016 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07004017 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
4018 unsigned long status = priv->status;
4019
4020 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
4021 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
4022 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
4023
4024 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
4025 RF_CARD_DISABLED)) {
4026
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004027 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07004028 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
4029
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004030 if (!iwl4965_grab_nic_access(priv)) {
4031 iwl4965_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07004032 priv, HBUS_TARG_MBX_C,
4033 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
4034
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004035 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004036 }
4037
4038 if (!(flags & RXON_CARD_DISABLED)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004039 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07004040 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004041 if (!iwl4965_grab_nic_access(priv)) {
4042 iwl4965_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07004043 priv, HBUS_TARG_MBX_C,
4044 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
4045
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004046 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004047 }
4048 }
4049
4050 if (flags & RF_CARD_DISABLED) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004051 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07004052 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004053 iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
4054 if (!iwl4965_grab_nic_access(priv))
4055 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004056 }
4057 }
4058
4059 if (flags & HW_CARD_DISABLED)
4060 set_bit(STATUS_RF_KILL_HW, &priv->status);
4061 else
4062 clear_bit(STATUS_RF_KILL_HW, &priv->status);
4063
4064
4065 if (flags & SW_CARD_DISABLED)
4066 set_bit(STATUS_RF_KILL_SW, &priv->status);
4067 else
4068 clear_bit(STATUS_RF_KILL_SW, &priv->status);
4069
4070 if (!(flags & RXON_CARD_DISABLED))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004071 iwl4965_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004072
4073 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
4074 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
4075 (test_bit(STATUS_RF_KILL_SW, &status) !=
4076 test_bit(STATUS_RF_KILL_SW, &priv->status)))
4077 queue_work(priv->workqueue, &priv->rf_kill);
4078 else
4079 wake_up_interruptible(&priv->wait_command_queue);
4080}
4081
4082/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004083 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07004084 *
4085 * Setup the RX handlers for each of the reply types sent from the uCode
4086 * to the host.
4087 *
4088 * This function chains into the hardware specific files for them to setup
4089 * any hardware specific handlers as well.
4090 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004091static void iwl4965_setup_rx_handlers(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004092{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004093 priv->rx_handlers[REPLY_ALIVE] = iwl4965_rx_reply_alive;
4094 priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta;
4095 priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error;
4096 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa;
Zhu Yib481de92007-09-25 17:54:57 -07004097 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004098 iwl4965_rx_spectrum_measure_notif;
4099 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07004100 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004101 iwl4965_rx_pm_debug_statistics_notif;
4102 priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07004103
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004104 /* NOTE: iwl4965_rx_statistics is different based on whether
Zhu Yib481de92007-09-25 17:54:57 -07004105 * the build is for the 3945 or the 4965. See the
4106 * corresponding implementation in iwl-XXXX.c
4107 *
4108 * The same handler is used for both the REPLY to a
4109 * discrete statistics request from the host as well as
4110 * for the periodic statistics notification from the uCode
4111 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004112 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics;
4113 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -07004114
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004115 priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan;
4116 priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif;
Zhu Yib481de92007-09-25 17:54:57 -07004117 priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004118 iwl4965_rx_scan_results_notif;
Zhu Yib481de92007-09-25 17:54:57 -07004119 priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004120 iwl4965_rx_scan_complete_notif;
4121 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif;
4122 priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx;
Zhu Yib481de92007-09-25 17:54:57 -07004123
4124 /* Setup hardware specific Rx handlers */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004125 iwl4965_hw_rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004126}
4127
4128/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004129 * iwl4965_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
Zhu Yib481de92007-09-25 17:54:57 -07004130 * @rxb: Rx buffer to reclaim
4131 *
4132 * If an Rx buffer has an async callback associated with it the callback
4133 * will be executed. The attached skb (if present) will only be freed
4134 * if the callback returns 1
4135 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004136static void iwl4965_tx_cmd_complete(struct iwl4965_priv *priv,
4137 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07004138{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004139 struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07004140 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
4141 int txq_id = SEQ_TO_QUEUE(sequence);
4142 int index = SEQ_TO_INDEX(sequence);
4143 int huge = sequence & SEQ_HUGE_FRAME;
4144 int cmd_index;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004145 struct iwl4965_cmd *cmd;
Zhu Yib481de92007-09-25 17:54:57 -07004146
4147 /* If a Tx command is being handled and it isn't in the actual
4148 * command queue then there a command routing bug has been introduced
4149 * in the queue management code. */
4150 if (txq_id != IWL_CMD_QUEUE_NUM)
4151 IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
4152 txq_id, pkt->hdr.cmd);
4153 BUG_ON(txq_id != IWL_CMD_QUEUE_NUM);
4154
4155 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
4156 cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
4157
4158 /* Input error checking is done when commands are added to queue. */
4159 if (cmd->meta.flags & CMD_WANT_SKB) {
4160 cmd->meta.source->u.skb = rxb->skb;
4161 rxb->skb = NULL;
4162 } else if (cmd->meta.u.callback &&
4163 !cmd->meta.u.callback(priv, cmd, rxb->skb))
4164 rxb->skb = NULL;
4165
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004166 iwl4965_tx_queue_reclaim(priv, txq_id, index);
Zhu Yib481de92007-09-25 17:54:57 -07004167
4168 if (!(cmd->meta.flags & CMD_ASYNC)) {
4169 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
4170 wake_up_interruptible(&priv->wait_command_queue);
4171 }
4172}
4173
4174/************************** RX-FUNCTIONS ****************************/
4175/*
4176 * Rx theory of operation
4177 *
4178 * The host allocates 32 DMA target addresses and passes the host address
4179 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
4180 * 0 to 31
4181 *
4182 * Rx Queue Indexes
4183 * The host/firmware share two index registers for managing the Rx buffers.
4184 *
4185 * The READ index maps to the first position that the firmware may be writing
4186 * to -- the driver can read up to (but not including) this position and get
4187 * good data.
4188 * The READ index is managed by the firmware once the card is enabled.
4189 *
4190 * The WRITE index maps to the last position the driver has read from -- the
4191 * position preceding WRITE is the last slot the firmware can place a packet.
4192 *
4193 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
4194 * WRITE = READ.
4195 *
4196 * During initialization the host sets up the READ queue position to the first
4197 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4198 *
4199 * When the firmware places a packet in a buffer it will advance the READ index
4200 * and fire the RX interrupt. The driver can then query the READ index and
4201 * process as many packets as possible, moving the WRITE index forward as it
4202 * resets the Rx queue buffers with new memory.
4203 *
4204 * The management in the driver is as follows:
4205 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
4206 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Ian Schram01ebd062007-10-25 17:15:22 +08004207 * to replenish the iwl->rxq->rx_free.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004208 * + In iwl4965_rx_replenish (scheduled) if 'processed' != 'read' then the
Zhu Yib481de92007-09-25 17:54:57 -07004209 * iwl->rxq is replenished and the READ INDEX is updated (updating the
4210 * 'processed' and 'read' driver indexes as well)
4211 * + A received packet is processed and handed to the kernel network stack,
4212 * detached from the iwl->rxq. The driver 'processed' index is updated.
4213 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
4214 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
4215 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
4216 * were enough free buffers and RX_STALLED is set it is cleared.
4217 *
4218 *
4219 * Driver sequence:
4220 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004221 * iwl4965_rx_queue_alloc() Allocates rx_free
4222 * iwl4965_rx_replenish() Replenishes rx_free list from rx_used, and calls
4223 * iwl4965_rx_queue_restock
4224 * iwl4965_rx_queue_restock() Moves available buffers from rx_free into Rx
Zhu Yib481de92007-09-25 17:54:57 -07004225 * queue, updates firmware pointers, and updates
4226 * the WRITE index. If insufficient rx_free buffers
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004227 * are available, schedules iwl4965_rx_replenish
Zhu Yib481de92007-09-25 17:54:57 -07004228 *
4229 * -- enable interrupts --
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004230 * ISR - iwl4965_rx() Detach iwl4965_rx_mem_buffers from pool up to the
Zhu Yib481de92007-09-25 17:54:57 -07004231 * READ INDEX, detaching the SKB from the pool.
4232 * Moves the packet buffer from queue to rx_used.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004233 * Calls iwl4965_rx_queue_restock to refill any empty
Zhu Yib481de92007-09-25 17:54:57 -07004234 * slots.
4235 * ...
4236 *
4237 */
4238
4239/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004240 * iwl4965_rx_queue_space - Return number of free slots available in queue.
Zhu Yib481de92007-09-25 17:54:57 -07004241 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004242static int iwl4965_rx_queue_space(const struct iwl4965_rx_queue *q)
Zhu Yib481de92007-09-25 17:54:57 -07004243{
4244 int s = q->read - q->write;
4245 if (s <= 0)
4246 s += RX_QUEUE_SIZE;
4247 /* keep some buffer to not confuse full and empty queue */
4248 s -= 2;
4249 if (s < 0)
4250 s = 0;
4251 return s;
4252}
4253
4254/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004255 * iwl4965_rx_queue_update_write_ptr - Update the write pointer for the RX queue
Zhu Yib481de92007-09-25 17:54:57 -07004256 *
4257 * NOTE: This function has 3945 and 4965 specific code sections
4258 * but is declared in base due to the majority of the
4259 * implementation being the same (only a numeric constant is
4260 * different)
4261 *
4262 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004263int iwl4965_rx_queue_update_write_ptr(struct iwl4965_priv *priv, struct iwl4965_rx_queue *q)
Zhu Yib481de92007-09-25 17:54:57 -07004264{
4265 u32 reg = 0;
4266 int rc = 0;
4267 unsigned long flags;
4268
4269 spin_lock_irqsave(&q->lock, flags);
4270
4271 if (q->need_update == 0)
4272 goto exit_unlock;
4273
4274 if (test_bit(STATUS_POWER_PMI, &priv->status)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004275 reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
Zhu Yib481de92007-09-25 17:54:57 -07004276
4277 if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004278 iwl4965_set_bit(priv, CSR_GP_CNTRL,
Zhu Yib481de92007-09-25 17:54:57 -07004279 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
4280 goto exit_unlock;
4281 }
4282
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004283 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004284 if (rc)
4285 goto exit_unlock;
4286
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004287 iwl4965_write_direct32(priv, FH_RSCSR_CHNL0_WPTR,
Zhu Yib481de92007-09-25 17:54:57 -07004288 q->write & ~0x7);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004289 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004290 } else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004291 iwl4965_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7);
Zhu Yib481de92007-09-25 17:54:57 -07004292
4293
4294 q->need_update = 0;
4295
4296 exit_unlock:
4297 spin_unlock_irqrestore(&q->lock, flags);
4298 return rc;
4299}
4300
4301/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004302 * iwl4965_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer pointer.
Zhu Yib481de92007-09-25 17:54:57 -07004303 *
4304 * NOTE: This function has 3945 and 4965 specific code paths in it.
4305 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004306static inline __le32 iwl4965_dma_addr2rbd_ptr(struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07004307 dma_addr_t dma_addr)
4308{
4309 return cpu_to_le32((u32)(dma_addr >> 8));
4310}
4311
4312
4313/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004314 * iwl4965_rx_queue_restock - refill RX queue from pre-allocated pool
Zhu Yib481de92007-09-25 17:54:57 -07004315 *
4316 * If there are slots in the RX queue that need to be restocked,
4317 * and we have free pre-allocated buffers, fill the ranks as much
4318 * as we can pulling from rx_free.
4319 *
4320 * This moves the 'write' index forward to catch up with 'processed', and
4321 * also updates the memory address in the firmware to reference the new
4322 * target buffer.
4323 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004324static int iwl4965_rx_queue_restock(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004325{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004326 struct iwl4965_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07004327 struct list_head *element;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004328 struct iwl4965_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07004329 unsigned long flags;
4330 int write, rc;
4331
4332 spin_lock_irqsave(&rxq->lock, flags);
4333 write = rxq->write & ~0x7;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004334 while ((iwl4965_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
Zhu Yib481de92007-09-25 17:54:57 -07004335 element = rxq->rx_free.next;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004336 rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07004337 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004338 rxq->bd[rxq->write] = iwl4965_dma_addr2rbd_ptr(priv, rxb->dma_addr);
Zhu Yib481de92007-09-25 17:54:57 -07004339 rxq->queue[rxq->write] = rxb;
4340 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
4341 rxq->free_count--;
4342 }
4343 spin_unlock_irqrestore(&rxq->lock, flags);
4344 /* If the pre-allocated buffer pool is dropping low, schedule to
4345 * refill it */
4346 if (rxq->free_count <= RX_LOW_WATERMARK)
4347 queue_work(priv->workqueue, &priv->rx_replenish);
4348
4349
4350 /* If we've added more space for the firmware to place data, tell it */
4351 if ((write != (rxq->write & ~0x7))
4352 || (abs(rxq->write - rxq->read) > 7)) {
4353 spin_lock_irqsave(&rxq->lock, flags);
4354 rxq->need_update = 1;
4355 spin_unlock_irqrestore(&rxq->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004356 rc = iwl4965_rx_queue_update_write_ptr(priv, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07004357 if (rc)
4358 return rc;
4359 }
4360
4361 return 0;
4362}
4363
4364/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004365 * iwl4965_rx_replenish - Move all used packet from rx_used to rx_free
Zhu Yib481de92007-09-25 17:54:57 -07004366 *
4367 * When moving to rx_free an SKB is allocated for the slot.
4368 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004369 * Also restock the Rx queue via iwl4965_rx_queue_restock.
Ian Schram01ebd062007-10-25 17:15:22 +08004370 * This is called as a scheduled work item (except for during initialization)
Zhu Yib481de92007-09-25 17:54:57 -07004371 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004372void iwl4965_rx_replenish(void *data)
Zhu Yib481de92007-09-25 17:54:57 -07004373{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004374 struct iwl4965_priv *priv = data;
4375 struct iwl4965_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07004376 struct list_head *element;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004377 struct iwl4965_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07004378 unsigned long flags;
4379 spin_lock_irqsave(&rxq->lock, flags);
4380 while (!list_empty(&rxq->rx_used)) {
4381 element = rxq->rx_used.next;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004382 rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07004383 rxb->skb =
4384 alloc_skb(IWL_RX_BUF_SIZE, __GFP_NOWARN | GFP_ATOMIC);
4385 if (!rxb->skb) {
4386 if (net_ratelimit())
4387 printk(KERN_CRIT DRV_NAME
4388 ": Can not allocate SKB buffers\n");
4389 /* We don't reschedule replenish work here -- we will
4390 * call the restock method and if it still needs
4391 * more buffers it will schedule replenish */
4392 break;
4393 }
4394 priv->alloc_rxb_skb++;
4395 list_del(element);
4396 rxb->dma_addr =
4397 pci_map_single(priv->pci_dev, rxb->skb->data,
4398 IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4399 list_add_tail(&rxb->list, &rxq->rx_free);
4400 rxq->free_count++;
4401 }
4402 spin_unlock_irqrestore(&rxq->lock, flags);
4403
4404 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004405 iwl4965_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004406 spin_unlock_irqrestore(&priv->lock, flags);
4407}
4408
4409/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
4410 * If an SKB has been detached, the POOL needs to have it's SKB set to NULL
4411 * This free routine walks the list of POOL entries and if SKB is set to
4412 * non NULL it is unmapped and freed
4413 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004414static void iwl4965_rx_queue_free(struct iwl4965_priv *priv, struct iwl4965_rx_queue *rxq)
Zhu Yib481de92007-09-25 17:54:57 -07004415{
4416 int i;
4417 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4418 if (rxq->pool[i].skb != NULL) {
4419 pci_unmap_single(priv->pci_dev,
4420 rxq->pool[i].dma_addr,
4421 IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4422 dev_kfree_skb(rxq->pool[i].skb);
4423 }
4424 }
4425
4426 pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd,
4427 rxq->dma_addr);
4428 rxq->bd = NULL;
4429}
4430
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004431int iwl4965_rx_queue_alloc(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004432{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004433 struct iwl4965_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07004434 struct pci_dev *dev = priv->pci_dev;
4435 int i;
4436
4437 spin_lock_init(&rxq->lock);
4438 INIT_LIST_HEAD(&rxq->rx_free);
4439 INIT_LIST_HEAD(&rxq->rx_used);
4440 rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr);
4441 if (!rxq->bd)
4442 return -ENOMEM;
4443 /* Fill the rx_used queue with _all_ of the Rx buffers */
4444 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
4445 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4446 /* Set us so that we have processed and used all buffers, but have
4447 * not restocked the Rx queue with fresh buffers */
4448 rxq->read = rxq->write = 0;
4449 rxq->free_count = 0;
4450 rxq->need_update = 0;
4451 return 0;
4452}
4453
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004454void iwl4965_rx_queue_reset(struct iwl4965_priv *priv, struct iwl4965_rx_queue *rxq)
Zhu Yib481de92007-09-25 17:54:57 -07004455{
4456 unsigned long flags;
4457 int i;
4458 spin_lock_irqsave(&rxq->lock, flags);
4459 INIT_LIST_HEAD(&rxq->rx_free);
4460 INIT_LIST_HEAD(&rxq->rx_used);
4461 /* Fill the rx_used queue with _all_ of the Rx buffers */
4462 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
4463 /* In the reset function, these buffers may have been allocated
4464 * to an SKB, so we need to unmap and free potential storage */
4465 if (rxq->pool[i].skb != NULL) {
4466 pci_unmap_single(priv->pci_dev,
4467 rxq->pool[i].dma_addr,
4468 IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4469 priv->alloc_rxb_skb--;
4470 dev_kfree_skb(rxq->pool[i].skb);
4471 rxq->pool[i].skb = NULL;
4472 }
4473 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4474 }
4475
4476 /* Set us so that we have processed and used all buffers, but have
4477 * not restocked the Rx queue with fresh buffers */
4478 rxq->read = rxq->write = 0;
4479 rxq->free_count = 0;
4480 spin_unlock_irqrestore(&rxq->lock, flags);
4481}
4482
4483/* Convert linear signal-to-noise ratio into dB */
4484static u8 ratio2dB[100] = {
4485/* 0 1 2 3 4 5 6 7 8 9 */
4486 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
4487 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
4488 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
4489 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
4490 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
4491 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
4492 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
4493 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
4494 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
4495 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
4496};
4497
4498/* Calculates a relative dB value from a ratio of linear
4499 * (i.e. not dB) signal levels.
4500 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004501int iwl4965_calc_db_from_ratio(int sig_ratio)
Zhu Yib481de92007-09-25 17:54:57 -07004502{
Adrian Bunkc899a572007-10-14 19:51:15 +02004503 /* 1000:1 or higher just report as 60 dB */
4504 if (sig_ratio >= 1000)
Zhu Yib481de92007-09-25 17:54:57 -07004505 return 60;
4506
Adrian Bunkc899a572007-10-14 19:51:15 +02004507 /* 100:1 or higher, divide by 10 and use table,
Zhu Yib481de92007-09-25 17:54:57 -07004508 * add 20 dB to make up for divide by 10 */
Adrian Bunkc899a572007-10-14 19:51:15 +02004509 if (sig_ratio >= 100)
Zhu Yib481de92007-09-25 17:54:57 -07004510 return (20 + (int)ratio2dB[sig_ratio/10]);
4511
4512 /* We shouldn't see this */
4513 if (sig_ratio < 1)
4514 return 0;
4515
4516 /* Use table for ratios 1:1 - 99:1 */
4517 return (int)ratio2dB[sig_ratio];
4518}
4519
4520#define PERFECT_RSSI (-20) /* dBm */
4521#define WORST_RSSI (-95) /* dBm */
4522#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
4523
4524/* Calculate an indication of rx signal quality (a percentage, not dBm!).
4525 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
4526 * about formulas used below. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004527int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm)
Zhu Yib481de92007-09-25 17:54:57 -07004528{
4529 int sig_qual;
4530 int degradation = PERFECT_RSSI - rssi_dbm;
4531
4532 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
4533 * as indicator; formula is (signal dbm - noise dbm).
4534 * SNR at or above 40 is a great signal (100%).
4535 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
4536 * Weakest usable signal is usually 10 - 15 dB SNR. */
4537 if (noise_dbm) {
4538 if (rssi_dbm - noise_dbm >= 40)
4539 return 100;
4540 else if (rssi_dbm < noise_dbm)
4541 return 0;
4542 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
4543
4544 /* Else use just the signal level.
4545 * This formula is a least squares fit of data points collected and
4546 * compared with a reference system that had a percentage (%) display
4547 * for signal quality. */
4548 } else
4549 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
4550 (15 * RSSI_RANGE + 62 * degradation)) /
4551 (RSSI_RANGE * RSSI_RANGE);
4552
4553 if (sig_qual > 100)
4554 sig_qual = 100;
4555 else if (sig_qual < 1)
4556 sig_qual = 0;
4557
4558 return sig_qual;
4559}
4560
4561/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004562 * iwl4965_rx_handle - Main entry function for receiving responses from the uCode
Zhu Yib481de92007-09-25 17:54:57 -07004563 *
4564 * Uses the priv->rx_handlers callback function array to invoke
4565 * the appropriate handlers, including command responses,
4566 * frame-received notifications, and other notifications.
4567 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004568static void iwl4965_rx_handle(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004569{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004570 struct iwl4965_rx_mem_buffer *rxb;
4571 struct iwl4965_rx_packet *pkt;
4572 struct iwl4965_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07004573 u32 r, i;
4574 int reclaim;
4575 unsigned long flags;
4576
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004577 r = iwl4965_hw_get_rx_read(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004578 i = rxq->read;
4579
4580 /* Rx interrupt, but nothing sent from uCode */
4581 if (i == r)
4582 IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
4583
4584 while (i != r) {
4585 rxb = rxq->queue[i];
4586
4587 /* If an RXB doesn't have a queue slot associated with it
4588 * then a bug has been introduced in the queue refilling
4589 * routines -- catch it here */
4590 BUG_ON(rxb == NULL);
4591
4592 rxq->queue[i] = NULL;
4593
4594 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
4595 IWL_RX_BUF_SIZE,
4596 PCI_DMA_FROMDEVICE);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004597 pkt = (struct iwl4965_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07004598
4599 /* Reclaim a command buffer only if this packet is a response
4600 * to a (driver-originated) command.
4601 * If the packet (e.g. Rx frame) originated from uCode,
4602 * there is no command buffer to reclaim.
4603 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
4604 * but apparently a few don't get set; catch them here. */
4605 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
4606 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
4607 (pkt->hdr.cmd != REPLY_4965_RX) &&
Zhu Yicfe01702007-09-27 11:27:31 +08004608 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
Zhu Yib481de92007-09-25 17:54:57 -07004609 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
4610 (pkt->hdr.cmd != REPLY_TX);
4611
4612 /* Based on type of command response or notification,
4613 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004614 * rx_handlers table. See iwl4965_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07004615 if (priv->rx_handlers[pkt->hdr.cmd]) {
4616 IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
4617 "r = %d, i = %d, %s, 0x%02x\n", r, i,
4618 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
4619 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
4620 } else {
4621 /* No handling needed */
4622 IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
4623 "r %d i %d No handler needed for %s, 0x%02x\n",
4624 r, i, get_cmd_string(pkt->hdr.cmd),
4625 pkt->hdr.cmd);
4626 }
4627
4628 if (reclaim) {
4629 /* Invoke any callbacks, transfer the skb to caller,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004630 * and fire off the (possibly) blocking iwl4965_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07004631 * as we reclaim the driver command queue */
4632 if (rxb && rxb->skb)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004633 iwl4965_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07004634 else
4635 IWL_WARNING("Claim null rxb?\n");
4636 }
4637
4638 /* For now we just don't re-use anything. We can tweak this
4639 * later to try and re-use notification packets and SKBs that
4640 * fail to Rx correctly */
4641 if (rxb->skb != NULL) {
4642 priv->alloc_rxb_skb--;
4643 dev_kfree_skb_any(rxb->skb);
4644 rxb->skb = NULL;
4645 }
4646
4647 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
4648 IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4649 spin_lock_irqsave(&rxq->lock, flags);
4650 list_add_tail(&rxb->list, &priv->rxq.rx_used);
4651 spin_unlock_irqrestore(&rxq->lock, flags);
4652 i = (i + 1) & RX_QUEUE_MASK;
4653 }
4654
4655 /* Backtrack one entry */
4656 priv->rxq.read = i;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004657 iwl4965_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004658}
4659
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004660static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv,
4661 struct iwl4965_tx_queue *txq)
Zhu Yib481de92007-09-25 17:54:57 -07004662{
4663 u32 reg = 0;
4664 int rc = 0;
4665 int txq_id = txq->q.id;
4666
4667 if (txq->need_update == 0)
4668 return rc;
4669
4670 /* if we're trying to save power */
4671 if (test_bit(STATUS_POWER_PMI, &priv->status)) {
4672 /* wake up nic if it's powered down ...
4673 * uCode will wake up, and interrupt us again, so next
4674 * time we'll skip this part. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004675 reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
Zhu Yib481de92007-09-25 17:54:57 -07004676
4677 if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
4678 IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004679 iwl4965_set_bit(priv, CSR_GP_CNTRL,
Zhu Yib481de92007-09-25 17:54:57 -07004680 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
4681 return rc;
4682 }
4683
4684 /* restore this queue's parameters in nic hardware. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004685 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004686 if (rc)
4687 return rc;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004688 iwl4965_write_direct32(priv, HBUS_TARG_WRPTR,
Tomas Winklerfc4b6852007-10-25 17:15:24 +08004689 txq->q.write_ptr | (txq_id << 8));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004690 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004691
4692 /* else not in power-save mode, uCode will never sleep when we're
4693 * trying to tx (during RFKILL, we're not trying to tx). */
4694 } else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004695 iwl4965_write32(priv, HBUS_TARG_WRPTR,
Tomas Winklerfc4b6852007-10-25 17:15:24 +08004696 txq->q.write_ptr | (txq_id << 8));
Zhu Yib481de92007-09-25 17:54:57 -07004697
4698 txq->need_update = 0;
4699
4700 return rc;
4701}
4702
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004703#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004704static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd *rxon)
Zhu Yib481de92007-09-25 17:54:57 -07004705{
Joe Perches0795af52007-10-03 17:59:30 -07004706 DECLARE_MAC_BUF(mac);
4707
Zhu Yib481de92007-09-25 17:54:57 -07004708 IWL_DEBUG_RADIO("RX CONFIG:\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004709 iwl4965_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
Zhu Yib481de92007-09-25 17:54:57 -07004710 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
4711 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
4712 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
4713 le32_to_cpu(rxon->filter_flags));
4714 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
4715 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
4716 rxon->ofdm_basic_rates);
4717 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
Joe Perches0795af52007-10-03 17:59:30 -07004718 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
4719 print_mac(mac, rxon->node_addr));
4720 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
4721 print_mac(mac, rxon->bssid_addr));
Zhu Yib481de92007-09-25 17:54:57 -07004722 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
4723}
4724#endif
4725
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004726static void iwl4965_enable_interrupts(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004727{
4728 IWL_DEBUG_ISR("Enabling interrupts\n");
4729 set_bit(STATUS_INT_ENABLED, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004730 iwl4965_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07004731}
4732
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004733static inline void iwl4965_disable_interrupts(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004734{
4735 clear_bit(STATUS_INT_ENABLED, &priv->status);
4736
4737 /* disable interrupts from uCode/NIC to host */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004738 iwl4965_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07004739
4740 /* acknowledge/clear/reset any interrupts still pending
4741 * from uCode or flow handler (Rx/Tx DMA) */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004742 iwl4965_write32(priv, CSR_INT, 0xffffffff);
4743 iwl4965_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
Zhu Yib481de92007-09-25 17:54:57 -07004744 IWL_DEBUG_ISR("Disabled interrupts\n");
4745}
4746
4747static const char *desc_lookup(int i)
4748{
4749 switch (i) {
4750 case 1:
4751 return "FAIL";
4752 case 2:
4753 return "BAD_PARAM";
4754 case 3:
4755 return "BAD_CHECKSUM";
4756 case 4:
4757 return "NMI_INTERRUPT";
4758 case 5:
4759 return "SYSASSERT";
4760 case 6:
4761 return "FATAL_ERROR";
4762 }
4763
4764 return "UNKNOWN";
4765}
4766
4767#define ERROR_START_OFFSET (1 * sizeof(u32))
4768#define ERROR_ELEM_SIZE (7 * sizeof(u32))
4769
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004770static void iwl4965_dump_nic_error_log(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004771{
4772 u32 data2, line;
4773 u32 desc, time, count, base, data1;
4774 u32 blink1, blink2, ilink1, ilink2;
4775 int rc;
4776
4777 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
4778
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004779 if (!iwl4965_hw_valid_rtc_data_addr(base)) {
Zhu Yib481de92007-09-25 17:54:57 -07004780 IWL_ERROR("Not valid error log pointer 0x%08X\n", base);
4781 return;
4782 }
4783
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004784 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004785 if (rc) {
4786 IWL_WARNING("Can not read from adapter at this time.\n");
4787 return;
4788 }
4789
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004790 count = iwl4965_read_targ_mem(priv, base);
Zhu Yib481de92007-09-25 17:54:57 -07004791
4792 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
4793 IWL_ERROR("Start IWL Error Log Dump:\n");
4794 IWL_ERROR("Status: 0x%08lX, Config: %08X count: %d\n",
4795 priv->status, priv->config, count);
4796 }
4797
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004798 desc = iwl4965_read_targ_mem(priv, base + 1 * sizeof(u32));
4799 blink1 = iwl4965_read_targ_mem(priv, base + 3 * sizeof(u32));
4800 blink2 = iwl4965_read_targ_mem(priv, base + 4 * sizeof(u32));
4801 ilink1 = iwl4965_read_targ_mem(priv, base + 5 * sizeof(u32));
4802 ilink2 = iwl4965_read_targ_mem(priv, base + 6 * sizeof(u32));
4803 data1 = iwl4965_read_targ_mem(priv, base + 7 * sizeof(u32));
4804 data2 = iwl4965_read_targ_mem(priv, base + 8 * sizeof(u32));
4805 line = iwl4965_read_targ_mem(priv, base + 9 * sizeof(u32));
4806 time = iwl4965_read_targ_mem(priv, base + 11 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07004807
4808 IWL_ERROR("Desc Time "
4809 "data1 data2 line\n");
4810 IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n",
4811 desc_lookup(desc), desc, time, data1, data2, line);
4812 IWL_ERROR("blink1 blink2 ilink1 ilink2\n");
4813 IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2,
4814 ilink1, ilink2);
4815
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004816 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004817}
4818
4819#define EVENT_START_OFFSET (4 * sizeof(u32))
4820
4821/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004822 * iwl4965_print_event_log - Dump error event log to syslog
Zhu Yib481de92007-09-25 17:54:57 -07004823 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004824 * NOTE: Must be called with iwl4965_grab_nic_access() already obtained!
Zhu Yib481de92007-09-25 17:54:57 -07004825 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004826static void iwl4965_print_event_log(struct iwl4965_priv *priv, u32 start_idx,
Zhu Yib481de92007-09-25 17:54:57 -07004827 u32 num_events, u32 mode)
4828{
4829 u32 i;
4830 u32 base; /* SRAM byte address of event log header */
4831 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
4832 u32 ptr; /* SRAM byte address of log data */
4833 u32 ev, time, data; /* event log data */
4834
4835 if (num_events == 0)
4836 return;
4837
4838 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
4839
4840 if (mode == 0)
4841 event_size = 2 * sizeof(u32);
4842 else
4843 event_size = 3 * sizeof(u32);
4844
4845 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
4846
4847 /* "time" is actually "data" for mode 0 (no timestamp).
4848 * place event id # at far right for easier visual parsing. */
4849 for (i = 0; i < num_events; i++) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004850 ev = iwl4965_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07004851 ptr += sizeof(u32);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004852 time = iwl4965_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07004853 ptr += sizeof(u32);
4854 if (mode == 0)
4855 IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */
4856 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004857 data = iwl4965_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07004858 ptr += sizeof(u32);
4859 IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev);
4860 }
4861 }
4862}
4863
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004864static void iwl4965_dump_nic_event_log(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004865{
4866 int rc;
4867 u32 base; /* SRAM byte address of event log header */
4868 u32 capacity; /* event log capacity in # entries */
4869 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
4870 u32 num_wraps; /* # times uCode wrapped to top of log */
4871 u32 next_entry; /* index of next entry to be written by uCode */
4872 u32 size; /* # entries that we'll print */
4873
4874 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004875 if (!iwl4965_hw_valid_rtc_data_addr(base)) {
Zhu Yib481de92007-09-25 17:54:57 -07004876 IWL_ERROR("Invalid event log pointer 0x%08X\n", base);
4877 return;
4878 }
4879
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004880 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004881 if (rc) {
4882 IWL_WARNING("Can not read from adapter at this time.\n");
4883 return;
4884 }
4885
4886 /* event log header */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004887 capacity = iwl4965_read_targ_mem(priv, base);
4888 mode = iwl4965_read_targ_mem(priv, base + (1 * sizeof(u32)));
4889 num_wraps = iwl4965_read_targ_mem(priv, base + (2 * sizeof(u32)));
4890 next_entry = iwl4965_read_targ_mem(priv, base + (3 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -07004891
4892 size = num_wraps ? capacity : next_entry;
4893
4894 /* bail out if nothing in log */
4895 if (size == 0) {
Zhu Yi583fab32007-09-27 11:27:30 +08004896 IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004897 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004898 return;
4899 }
4900
Zhu Yi583fab32007-09-27 11:27:30 +08004901 IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07004902 size, num_wraps);
4903
4904 /* if uCode has wrapped back to top of log, start at the oldest entry,
4905 * i.e the next one that uCode would fill. */
4906 if (num_wraps)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004907 iwl4965_print_event_log(priv, next_entry,
Zhu Yib481de92007-09-25 17:54:57 -07004908 capacity - next_entry, mode);
4909
4910 /* (then/else) start at top of log */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004911 iwl4965_print_event_log(priv, 0, next_entry, mode);
Zhu Yib481de92007-09-25 17:54:57 -07004912
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004913 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004914}
4915
4916/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004917 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
Zhu Yib481de92007-09-25 17:54:57 -07004918 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004919static void iwl4965_irq_handle_error(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004920{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004921 /* Set the FW error flag -- cleared on iwl4965_down */
Zhu Yib481de92007-09-25 17:54:57 -07004922 set_bit(STATUS_FW_ERROR, &priv->status);
4923
4924 /* Cancel currently queued command. */
4925 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
4926
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004927#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004928 if (iwl4965_debug_level & IWL_DL_FW_ERRORS) {
4929 iwl4965_dump_nic_error_log(priv);
4930 iwl4965_dump_nic_event_log(priv);
4931 iwl4965_print_rx_config_cmd(&priv->staging_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07004932 }
4933#endif
4934
4935 wake_up_interruptible(&priv->wait_command_queue);
4936
4937 /* Keep the restart process from trying to send host
4938 * commands by clearing the INIT status bit */
4939 clear_bit(STATUS_READY, &priv->status);
4940
4941 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
4942 IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS,
4943 "Restarting adapter due to uCode error.\n");
4944
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004945 if (iwl4965_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004946 memcpy(&priv->recovery_rxon, &priv->active_rxon,
4947 sizeof(priv->recovery_rxon));
4948 priv->error_recovering = 1;
4949 }
4950 queue_work(priv->workqueue, &priv->restart);
4951 }
4952}
4953
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004954static void iwl4965_error_recovery(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004955{
4956 unsigned long flags;
4957
4958 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
4959 sizeof(priv->staging_rxon));
4960 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004961 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004962
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004963 iwl4965_rxon_add_station(priv, priv->bssid, 1);
Zhu Yib481de92007-09-25 17:54:57 -07004964
4965 spin_lock_irqsave(&priv->lock, flags);
4966 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
4967 priv->error_recovering = 0;
4968 spin_unlock_irqrestore(&priv->lock, flags);
4969}
4970
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004971static void iwl4965_irq_tasklet(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004972{
4973 u32 inta, handled = 0;
4974 u32 inta_fh;
4975 unsigned long flags;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004976#ifdef CONFIG_IWL4965_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07004977 u32 inta_mask;
4978#endif
4979
4980 spin_lock_irqsave(&priv->lock, flags);
4981
4982 /* Ack/clear/reset pending uCode interrupts.
4983 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
4984 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004985 inta = iwl4965_read32(priv, CSR_INT);
4986 iwl4965_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07004987
4988 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
4989 * Any new interrupts that happen after this, either while we're
4990 * in this tasklet, or later, will show up in next ISR/tasklet. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004991 inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS);
4992 iwl4965_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07004993
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004994#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004995 if (iwl4965_debug_level & IWL_DL_ISR) {
4996 inta_mask = iwl4965_read32(priv, CSR_INT_MASK); /* just for debug */
Zhu Yib481de92007-09-25 17:54:57 -07004997 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4998 inta, inta_mask, inta_fh);
4999 }
5000#endif
5001
5002 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
5003 * atomic, make sure that inta covers all the interrupts that
5004 * we've discovered, even if FH interrupt came in just after
5005 * reading CSR_INT. */
5006 if (inta_fh & CSR_FH_INT_RX_MASK)
5007 inta |= CSR_INT_BIT_FH_RX;
5008 if (inta_fh & CSR_FH_INT_TX_MASK)
5009 inta |= CSR_INT_BIT_FH_TX;
5010
5011 /* Now service all interrupt bits discovered above. */
5012 if (inta & CSR_INT_BIT_HW_ERR) {
5013 IWL_ERROR("Microcode HW error detected. Restarting.\n");
5014
5015 /* Tell the device to stop sending interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005016 iwl4965_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005017
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005018 iwl4965_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005019
5020 handled |= CSR_INT_BIT_HW_ERR;
5021
5022 spin_unlock_irqrestore(&priv->lock, flags);
5023
5024 return;
5025 }
5026
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005027#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005028 if (iwl4965_debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07005029 /* NIC fires this, but we don't use it, redundant with WAKEUP */
5030 if (inta & CSR_INT_BIT_MAC_CLK_ACTV)
5031 IWL_DEBUG_ISR("Microcode started or stopped.\n");
5032
5033 /* Alive notification via Rx interrupt will do the real work */
5034 if (inta & CSR_INT_BIT_ALIVE)
5035 IWL_DEBUG_ISR("Alive interrupt\n");
5036 }
5037#endif
5038 /* Safely ignore these bits for debug checks below */
5039 inta &= ~(CSR_INT_BIT_MAC_CLK_ACTV | CSR_INT_BIT_ALIVE);
5040
5041 /* HW RF KILL switch toggled (4965 only) */
5042 if (inta & CSR_INT_BIT_RF_KILL) {
5043 int hw_rf_kill = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005044 if (!(iwl4965_read32(priv, CSR_GP_CNTRL) &
Zhu Yib481de92007-09-25 17:54:57 -07005045 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
5046 hw_rf_kill = 1;
5047
5048 IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL | IWL_DL_ISR,
5049 "RF_KILL bit toggled to %s.\n",
5050 hw_rf_kill ? "disable radio":"enable radio");
5051
5052 /* Queue restart only if RF_KILL switch was set to "kill"
5053 * when we loaded driver, and is now set to "enable".
5054 * After we're Alive, RF_KILL gets handled by
5055 * iwl_rx_card_state_notif() */
Zhu Yi53e49092007-12-06 16:08:44 +08005056 if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) {
5057 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07005058 queue_work(priv->workqueue, &priv->restart);
Zhu Yi53e49092007-12-06 16:08:44 +08005059 }
Zhu Yib481de92007-09-25 17:54:57 -07005060
5061 handled |= CSR_INT_BIT_RF_KILL;
5062 }
5063
5064 /* Chip got too hot and stopped itself (4965 only) */
5065 if (inta & CSR_INT_BIT_CT_KILL) {
5066 IWL_ERROR("Microcode CT kill error detected.\n");
5067 handled |= CSR_INT_BIT_CT_KILL;
5068 }
5069
5070 /* Error detected by uCode */
5071 if (inta & CSR_INT_BIT_SW_ERR) {
5072 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
5073 inta);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005074 iwl4965_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005075 handled |= CSR_INT_BIT_SW_ERR;
5076 }
5077
5078 /* uCode wakes up after power-down sleep */
5079 if (inta & CSR_INT_BIT_WAKEUP) {
5080 IWL_DEBUG_ISR("Wakeup interrupt\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005081 iwl4965_rx_queue_update_write_ptr(priv, &priv->rxq);
5082 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[0]);
5083 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[1]);
5084 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[2]);
5085 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[3]);
5086 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[4]);
5087 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07005088
5089 handled |= CSR_INT_BIT_WAKEUP;
5090 }
5091
5092 /* All uCode command responses, including Tx command responses,
5093 * Rx "responses" (frame-received notification), and other
5094 * notifications from uCode come through here*/
5095 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005096 iwl4965_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005097 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
5098 }
5099
5100 if (inta & CSR_INT_BIT_FH_TX) {
5101 IWL_DEBUG_ISR("Tx interrupt\n");
5102 handled |= CSR_INT_BIT_FH_TX;
5103 }
5104
5105 if (inta & ~handled)
5106 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
5107
5108 if (inta & ~CSR_INI_SET_MASK) {
5109 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
5110 inta & ~CSR_INI_SET_MASK);
5111 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
5112 }
5113
5114 /* Re-enable all interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005115 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005116
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005117#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005118 if (iwl4965_debug_level & (IWL_DL_ISR)) {
5119 inta = iwl4965_read32(priv, CSR_INT);
5120 inta_mask = iwl4965_read32(priv, CSR_INT_MASK);
5121 inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07005122 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
5123 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
5124 }
5125#endif
5126 spin_unlock_irqrestore(&priv->lock, flags);
5127}
5128
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005129static irqreturn_t iwl4965_isr(int irq, void *data)
Zhu Yib481de92007-09-25 17:54:57 -07005130{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005131 struct iwl4965_priv *priv = data;
Zhu Yib481de92007-09-25 17:54:57 -07005132 u32 inta, inta_mask;
5133 u32 inta_fh;
5134 if (!priv)
5135 return IRQ_NONE;
5136
5137 spin_lock(&priv->lock);
5138
5139 /* Disable (but don't clear!) interrupts here to avoid
5140 * back-to-back ISRs and sporadic interrupts from our NIC.
5141 * If we have something to service, the tasklet will re-enable ints.
5142 * If we *don't* have something, we'll re-enable before leaving here. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005143 inta_mask = iwl4965_read32(priv, CSR_INT_MASK); /* just for debug */
5144 iwl4965_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07005145
5146 /* Discover which interrupts are active/pending */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005147 inta = iwl4965_read32(priv, CSR_INT);
5148 inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07005149
5150 /* Ignore interrupt if there's nothing in NIC to service.
5151 * This may be due to IRQ shared with another device,
5152 * or due to sporadic interrupts thrown from our NIC. */
5153 if (!inta && !inta_fh) {
5154 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
5155 goto none;
5156 }
5157
5158 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
Oliver Neukum66fbb542007-11-15 09:31:10 +08005159 /* Hardware disappeared. It might have already raised
5160 * an interrupt */
Zhu Yib481de92007-09-25 17:54:57 -07005161 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
Oliver Neukum66fbb542007-11-15 09:31:10 +08005162 goto unplugged;
Zhu Yib481de92007-09-25 17:54:57 -07005163 }
5164
5165 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
5166 inta, inta_mask, inta_fh);
5167
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005168 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
Zhu Yib481de92007-09-25 17:54:57 -07005169 tasklet_schedule(&priv->irq_tasklet);
Zhu Yib481de92007-09-25 17:54:57 -07005170
Oliver Neukum66fbb542007-11-15 09:31:10 +08005171 unplugged:
5172 spin_unlock(&priv->lock);
Zhu Yib481de92007-09-25 17:54:57 -07005173 return IRQ_HANDLED;
5174
5175 none:
5176 /* re-enable interrupts here since we don't have anything to service. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005177 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005178 spin_unlock(&priv->lock);
5179 return IRQ_NONE;
5180}
5181
5182/************************** EEPROM BANDS ****************************
5183 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005184 * The iwl4965_eeprom_band definitions below provide the mapping from the
Zhu Yib481de92007-09-25 17:54:57 -07005185 * EEPROM contents to the specific channel number supported for each
5186 * band.
5187 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005188 * For example, iwl4965_priv->eeprom.band_3_channels[4] from the band_3
Zhu Yib481de92007-09-25 17:54:57 -07005189 * definition below maps to physical channel 42 in the 5.2GHz spectrum.
5190 * The specific geography and calibration information for that channel
5191 * is contained in the eeprom map itself.
5192 *
5193 * During init, we copy the eeprom information and channel map
5194 * information into priv->channel_info_24/52 and priv->channel_map_24/52
5195 *
5196 * channel_map_24/52 provides the index in the channel_info array for a
5197 * given channel. We have to have two separate maps as there is channel
5198 * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
5199 * band_2
5200 *
5201 * A value of 0xff stored in the channel_map indicates that the channel
5202 * is not supported by the hardware at all.
5203 *
5204 * A value of 0xfe in the channel_map indicates that the channel is not
5205 * valid for Tx with the current hardware. This means that
5206 * while the system can tune and receive on a given channel, it may not
5207 * be able to associate or transmit any frames on that
5208 * channel. There is no corresponding channel information for that
5209 * entry.
5210 *
5211 *********************************************************************/
5212
5213/* 2.4 GHz */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005214static const u8 iwl4965_eeprom_band_1[14] = {
Zhu Yib481de92007-09-25 17:54:57 -07005215 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
5216};
5217
5218/* 5.2 GHz bands */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005219static const u8 iwl4965_eeprom_band_2[] = {
Zhu Yib481de92007-09-25 17:54:57 -07005220 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
5221};
5222
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005223static const u8 iwl4965_eeprom_band_3[] = { /* 5205-5320MHz */
Zhu Yib481de92007-09-25 17:54:57 -07005224 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
5225};
5226
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005227static const u8 iwl4965_eeprom_band_4[] = { /* 5500-5700MHz */
Zhu Yib481de92007-09-25 17:54:57 -07005228 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
5229};
5230
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005231static const u8 iwl4965_eeprom_band_5[] = { /* 5725-5825MHz */
Zhu Yib481de92007-09-25 17:54:57 -07005232 145, 149, 153, 157, 161, 165
5233};
5234
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005235static u8 iwl4965_eeprom_band_6[] = { /* 2.4 FAT channel */
Zhu Yib481de92007-09-25 17:54:57 -07005236 1, 2, 3, 4, 5, 6, 7
5237};
5238
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005239static u8 iwl4965_eeprom_band_7[] = { /* 5.2 FAT channel */
Zhu Yib481de92007-09-25 17:54:57 -07005240 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157
5241};
5242
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005243static void iwl4965_init_band_reference(const struct iwl4965_priv *priv, int band,
Zhu Yib481de92007-09-25 17:54:57 -07005244 int *eeprom_ch_count,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005245 const struct iwl4965_eeprom_channel
Zhu Yib481de92007-09-25 17:54:57 -07005246 **eeprom_ch_info,
5247 const u8 **eeprom_ch_index)
5248{
5249 switch (band) {
5250 case 1: /* 2.4GHz band */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005251 *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_1);
Zhu Yib481de92007-09-25 17:54:57 -07005252 *eeprom_ch_info = priv->eeprom.band_1_channels;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005253 *eeprom_ch_index = iwl4965_eeprom_band_1;
Zhu Yib481de92007-09-25 17:54:57 -07005254 break;
5255 case 2: /* 5.2GHz band */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005256 *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_2);
Zhu Yib481de92007-09-25 17:54:57 -07005257 *eeprom_ch_info = priv->eeprom.band_2_channels;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005258 *eeprom_ch_index = iwl4965_eeprom_band_2;
Zhu Yib481de92007-09-25 17:54:57 -07005259 break;
5260 case 3: /* 5.2GHz band */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005261 *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_3);
Zhu Yib481de92007-09-25 17:54:57 -07005262 *eeprom_ch_info = priv->eeprom.band_3_channels;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005263 *eeprom_ch_index = iwl4965_eeprom_band_3;
Zhu Yib481de92007-09-25 17:54:57 -07005264 break;
5265 case 4: /* 5.2GHz band */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005266 *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_4);
Zhu Yib481de92007-09-25 17:54:57 -07005267 *eeprom_ch_info = priv->eeprom.band_4_channels;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005268 *eeprom_ch_index = iwl4965_eeprom_band_4;
Zhu Yib481de92007-09-25 17:54:57 -07005269 break;
5270 case 5: /* 5.2GHz band */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005271 *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_5);
Zhu Yib481de92007-09-25 17:54:57 -07005272 *eeprom_ch_info = priv->eeprom.band_5_channels;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005273 *eeprom_ch_index = iwl4965_eeprom_band_5;
Zhu Yib481de92007-09-25 17:54:57 -07005274 break;
5275 case 6:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005276 *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_6);
Zhu Yib481de92007-09-25 17:54:57 -07005277 *eeprom_ch_info = priv->eeprom.band_24_channels;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005278 *eeprom_ch_index = iwl4965_eeprom_band_6;
Zhu Yib481de92007-09-25 17:54:57 -07005279 break;
5280 case 7:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005281 *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_7);
Zhu Yib481de92007-09-25 17:54:57 -07005282 *eeprom_ch_info = priv->eeprom.band_52_channels;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005283 *eeprom_ch_index = iwl4965_eeprom_band_7;
Zhu Yib481de92007-09-25 17:54:57 -07005284 break;
5285 default:
5286 BUG();
5287 return;
5288 }
5289}
5290
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005291const struct iwl4965_channel_info *iwl4965_get_channel_info(const struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07005292 int phymode, u16 channel)
5293{
5294 int i;
5295
5296 switch (phymode) {
5297 case MODE_IEEE80211A:
5298 for (i = 14; i < priv->channel_count; i++) {
5299 if (priv->channel_info[i].channel == channel)
5300 return &priv->channel_info[i];
5301 }
5302 break;
5303
5304 case MODE_IEEE80211B:
5305 case MODE_IEEE80211G:
5306 if (channel >= 1 && channel <= 14)
5307 return &priv->channel_info[channel - 1];
5308 break;
5309
5310 }
5311
5312 return NULL;
5313}
5314
5315#define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
5316 ? # x " " : "")
5317
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005318static int iwl4965_init_channel_map(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005319{
5320 int eeprom_ch_count = 0;
5321 const u8 *eeprom_ch_index = NULL;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005322 const struct iwl4965_eeprom_channel *eeprom_ch_info = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07005323 int band, ch;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005324 struct iwl4965_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07005325
5326 if (priv->channel_count) {
5327 IWL_DEBUG_INFO("Channel map already initialized.\n");
5328 return 0;
5329 }
5330
5331 if (priv->eeprom.version < 0x2f) {
5332 IWL_WARNING("Unsupported EEPROM version: 0x%04X\n",
5333 priv->eeprom.version);
5334 return -EINVAL;
5335 }
5336
5337 IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n");
5338
5339 priv->channel_count =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005340 ARRAY_SIZE(iwl4965_eeprom_band_1) +
5341 ARRAY_SIZE(iwl4965_eeprom_band_2) +
5342 ARRAY_SIZE(iwl4965_eeprom_band_3) +
5343 ARRAY_SIZE(iwl4965_eeprom_band_4) +
5344 ARRAY_SIZE(iwl4965_eeprom_band_5);
Zhu Yib481de92007-09-25 17:54:57 -07005345
5346 IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count);
5347
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005348 priv->channel_info = kzalloc(sizeof(struct iwl4965_channel_info) *
Zhu Yib481de92007-09-25 17:54:57 -07005349 priv->channel_count, GFP_KERNEL);
5350 if (!priv->channel_info) {
5351 IWL_ERROR("Could not allocate channel_info\n");
5352 priv->channel_count = 0;
5353 return -ENOMEM;
5354 }
5355
5356 ch_info = priv->channel_info;
5357
5358 /* Loop through the 5 EEPROM bands adding them in order to the
5359 * channel map we maintain (that contains additional information than
5360 * what just in the EEPROM) */
5361 for (band = 1; band <= 5; band++) {
5362
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005363 iwl4965_init_band_reference(priv, band, &eeprom_ch_count,
Zhu Yib481de92007-09-25 17:54:57 -07005364 &eeprom_ch_info, &eeprom_ch_index);
5365
5366 /* Loop through each band adding each of the channels */
5367 for (ch = 0; ch < eeprom_ch_count; ch++) {
5368 ch_info->channel = eeprom_ch_index[ch];
5369 ch_info->phymode = (band == 1) ? MODE_IEEE80211B :
5370 MODE_IEEE80211A;
5371
5372 /* permanently store EEPROM's channel regulatory flags
5373 * and max power in channel info database. */
5374 ch_info->eeprom = eeprom_ch_info[ch];
5375
5376 /* Copy the run-time flags so they are there even on
5377 * invalid channels */
5378 ch_info->flags = eeprom_ch_info[ch].flags;
5379
5380 if (!(is_channel_valid(ch_info))) {
5381 IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - "
5382 "No traffic\n",
5383 ch_info->channel,
5384 ch_info->flags,
5385 is_channel_a_band(ch_info) ?
5386 "5.2" : "2.4");
5387 ch_info++;
5388 continue;
5389 }
5390
5391 /* Initialize regulatory-based run-time data */
5392 ch_info->max_power_avg = ch_info->curr_txpow =
5393 eeprom_ch_info[ch].max_power_avg;
5394 ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
5395 ch_info->min_power = 0;
5396
5397 IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x"
5398 " %ddBm): Ad-Hoc %ssupported\n",
5399 ch_info->channel,
5400 is_channel_a_band(ch_info) ?
5401 "5.2" : "2.4",
5402 CHECK_AND_PRINT(IBSS),
5403 CHECK_AND_PRINT(ACTIVE),
5404 CHECK_AND_PRINT(RADAR),
5405 CHECK_AND_PRINT(WIDE),
5406 CHECK_AND_PRINT(NARROW),
5407 CHECK_AND_PRINT(DFS),
5408 eeprom_ch_info[ch].flags,
5409 eeprom_ch_info[ch].max_power_avg,
5410 ((eeprom_ch_info[ch].
5411 flags & EEPROM_CHANNEL_IBSS)
5412 && !(eeprom_ch_info[ch].
5413 flags & EEPROM_CHANNEL_RADAR))
5414 ? "" : "not ");
5415
5416 /* Set the user_txpower_limit to the highest power
5417 * supported by any channel */
5418 if (eeprom_ch_info[ch].max_power_avg >
5419 priv->user_txpower_limit)
5420 priv->user_txpower_limit =
5421 eeprom_ch_info[ch].max_power_avg;
5422
5423 ch_info++;
5424 }
5425 }
5426
5427 for (band = 6; band <= 7; band++) {
5428 int phymode;
5429 u8 fat_extension_chan;
5430
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005431 iwl4965_init_band_reference(priv, band, &eeprom_ch_count,
Zhu Yib481de92007-09-25 17:54:57 -07005432 &eeprom_ch_info, &eeprom_ch_index);
5433
5434 phymode = (band == 6) ? MODE_IEEE80211B : MODE_IEEE80211A;
5435 /* Loop through each band adding each of the channels */
5436 for (ch = 0; ch < eeprom_ch_count; ch++) {
5437
5438 if ((band == 6) &&
5439 ((eeprom_ch_index[ch] == 5) ||
5440 (eeprom_ch_index[ch] == 6) ||
5441 (eeprom_ch_index[ch] == 7)))
5442 fat_extension_chan = HT_IE_EXT_CHANNEL_MAX;
5443 else
5444 fat_extension_chan = HT_IE_EXT_CHANNEL_ABOVE;
5445
5446 iwl4965_set_fat_chan_info(priv, phymode,
5447 eeprom_ch_index[ch],
5448 &(eeprom_ch_info[ch]),
5449 fat_extension_chan);
5450
5451 iwl4965_set_fat_chan_info(priv, phymode,
5452 (eeprom_ch_index[ch] + 4),
5453 &(eeprom_ch_info[ch]),
5454 HT_IE_EXT_CHANNEL_BELOW);
5455 }
5456 }
5457
5458 return 0;
5459}
5460
5461/* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
5462 * sending probe req. This should be set long enough to hear probe responses
5463 * from more than one AP. */
5464#define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
5465#define IWL_ACTIVE_DWELL_TIME_52 (10)
5466
5467/* For faster active scanning, scan will move to the next channel if fewer than
5468 * PLCP_QUIET_THRESH packets are heard on this channel within
5469 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
5470 * time if it's a quiet channel (nothing responded to our probe, and there's
5471 * no other traffic).
5472 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
5473#define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
5474#define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
5475
5476/* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
5477 * Must be set longer than active dwell time.
5478 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
5479#define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
5480#define IWL_PASSIVE_DWELL_TIME_52 (10)
5481#define IWL_PASSIVE_DWELL_BASE (100)
5482#define IWL_CHANNEL_TUNE_TIME 5
5483
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005484static inline u16 iwl4965_get_active_dwell_time(struct iwl4965_priv *priv, int phymode)
Zhu Yib481de92007-09-25 17:54:57 -07005485{
5486 if (phymode == MODE_IEEE80211A)
5487 return IWL_ACTIVE_DWELL_TIME_52;
5488 else
5489 return IWL_ACTIVE_DWELL_TIME_24;
5490}
5491
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005492static u16 iwl4965_get_passive_dwell_time(struct iwl4965_priv *priv, int phymode)
Zhu Yib481de92007-09-25 17:54:57 -07005493{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005494 u16 active = iwl4965_get_active_dwell_time(priv, phymode);
Zhu Yib481de92007-09-25 17:54:57 -07005495 u16 passive = (phymode != MODE_IEEE80211A) ?
5496 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
5497 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
5498
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005499 if (iwl4965_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005500 /* If we're associated, we clamp the maximum passive
5501 * dwell time to be 98% of the beacon interval (minus
5502 * 2 * channel tune time) */
5503 passive = priv->beacon_int;
5504 if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive)
5505 passive = IWL_PASSIVE_DWELL_BASE;
5506 passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
5507 }
5508
5509 if (passive <= active)
5510 passive = active + 1;
5511
5512 return passive;
5513}
5514
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005515static int iwl4965_get_channels_for_scan(struct iwl4965_priv *priv, int phymode,
Zhu Yib481de92007-09-25 17:54:57 -07005516 u8 is_active, u8 direct_mask,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005517 struct iwl4965_scan_channel *scan_ch)
Zhu Yib481de92007-09-25 17:54:57 -07005518{
5519 const struct ieee80211_channel *channels = NULL;
5520 const struct ieee80211_hw_mode *hw_mode;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005521 const struct iwl4965_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07005522 u16 passive_dwell = 0;
5523 u16 active_dwell = 0;
5524 int added, i;
5525
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005526 hw_mode = iwl4965_get_hw_mode(priv, phymode);
Zhu Yib481de92007-09-25 17:54:57 -07005527 if (!hw_mode)
5528 return 0;
5529
5530 channels = hw_mode->channels;
5531
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005532 active_dwell = iwl4965_get_active_dwell_time(priv, phymode);
5533 passive_dwell = iwl4965_get_passive_dwell_time(priv, phymode);
Zhu Yib481de92007-09-25 17:54:57 -07005534
5535 for (i = 0, added = 0; i < hw_mode->num_channels; i++) {
5536 if (channels[i].chan ==
5537 le16_to_cpu(priv->active_rxon.channel)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005538 if (iwl4965_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005539 IWL_DEBUG_SCAN
5540 ("Skipping current channel %d\n",
5541 le16_to_cpu(priv->active_rxon.channel));
5542 continue;
5543 }
5544 } else if (priv->only_active_channel)
5545 continue;
5546
5547 scan_ch->channel = channels[i].chan;
5548
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005549 ch_info = iwl4965_get_channel_info(priv, phymode, scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07005550 if (!is_channel_valid(ch_info)) {
5551 IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
5552 scan_ch->channel);
5553 continue;
5554 }
5555
5556 if (!is_active || is_channel_passive(ch_info) ||
5557 !(channels[i].flag & IEEE80211_CHAN_W_ACTIVE_SCAN))
5558 scan_ch->type = 0; /* passive */
5559 else
5560 scan_ch->type = 1; /* active */
5561
5562 if (scan_ch->type & 1)
5563 scan_ch->type |= (direct_mask << 1);
5564
5565 if (is_channel_narrow(ch_info))
5566 scan_ch->type |= (1 << 7);
5567
5568 scan_ch->active_dwell = cpu_to_le16(active_dwell);
5569 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
5570
5571 /* Set power levels to defaults */
5572 scan_ch->tpc.dsp_atten = 110;
5573 /* scan_pwr_info->tpc.dsp_atten; */
5574
5575 /*scan_pwr_info->tpc.tx_gain; */
5576 if (phymode == MODE_IEEE80211A)
5577 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
5578 else {
5579 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
5580 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
5581 * power level
5582 scan_ch->tpc.tx_gain = ((1<<5) | (2 << 3)) | 3;
5583 */
5584 }
5585
5586 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
5587 scan_ch->channel,
5588 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
5589 (scan_ch->type & 1) ?
5590 active_dwell : passive_dwell);
5591
5592 scan_ch++;
5593 added++;
5594 }
5595
5596 IWL_DEBUG_SCAN("total channels to scan %d \n", added);
5597 return added;
5598}
5599
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005600static void iwl4965_reset_channel_flag(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005601{
5602 int i, j;
5603 for (i = 0; i < 3; i++) {
5604 struct ieee80211_hw_mode *hw_mode = (void *)&priv->modes[i];
5605 for (j = 0; j < hw_mode->num_channels; j++)
5606 hw_mode->channels[j].flag = hw_mode->channels[j].val;
5607 }
5608}
5609
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005610static void iwl4965_init_hw_rates(struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07005611 struct ieee80211_rate *rates)
5612{
5613 int i;
5614
5615 for (i = 0; i < IWL_RATE_COUNT; i++) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005616 rates[i].rate = iwl4965_rates[i].ieee * 5;
Zhu Yib481de92007-09-25 17:54:57 -07005617 rates[i].val = i; /* Rate scaling will work on indexes */
5618 rates[i].val2 = i;
5619 rates[i].flags = IEEE80211_RATE_SUPPORTED;
5620 /* Only OFDM have the bits-per-symbol set */
5621 if ((i <= IWL_LAST_OFDM_RATE) && (i >= IWL_FIRST_OFDM_RATE))
5622 rates[i].flags |= IEEE80211_RATE_OFDM;
5623 else {
5624 /*
5625 * If CCK 1M then set rate flag to CCK else CCK_2
5626 * which is CCK | PREAMBLE2
5627 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005628 rates[i].flags |= (iwl4965_rates[i].plcp == 10) ?
Zhu Yib481de92007-09-25 17:54:57 -07005629 IEEE80211_RATE_CCK : IEEE80211_RATE_CCK_2;
5630 }
5631
5632 /* Set up which ones are basic rates... */
5633 if (IWL_BASIC_RATES_MASK & (1 << i))
5634 rates[i].flags |= IEEE80211_RATE_BASIC;
5635 }
5636
5637 iwl4965_init_hw_rates(priv, rates);
5638}
5639
5640/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005641 * iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom
Zhu Yib481de92007-09-25 17:54:57 -07005642 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005643static int iwl4965_init_geos(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005644{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005645 struct iwl4965_channel_info *ch;
Zhu Yib481de92007-09-25 17:54:57 -07005646 struct ieee80211_hw_mode *modes;
5647 struct ieee80211_channel *channels;
5648 struct ieee80211_channel *geo_ch;
5649 struct ieee80211_rate *rates;
5650 int i = 0;
5651 enum {
5652 A = 0,
5653 B = 1,
5654 G = 2,
5655 A_11N = 3,
5656 G_11N = 4,
5657 };
5658 int mode_count = 5;
5659
5660 if (priv->modes) {
5661 IWL_DEBUG_INFO("Geography modes already initialized.\n");
5662 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
5663 return 0;
5664 }
5665
5666 modes = kzalloc(sizeof(struct ieee80211_hw_mode) * mode_count,
5667 GFP_KERNEL);
5668 if (!modes)
5669 return -ENOMEM;
5670
5671 channels = kzalloc(sizeof(struct ieee80211_channel) *
5672 priv->channel_count, GFP_KERNEL);
5673 if (!channels) {
5674 kfree(modes);
5675 return -ENOMEM;
5676 }
5677
5678 rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_MAX_RATES + 1)),
5679 GFP_KERNEL);
5680 if (!rates) {
5681 kfree(modes);
5682 kfree(channels);
5683 return -ENOMEM;
5684 }
5685
5686 /* 0 = 802.11a
5687 * 1 = 802.11b
5688 * 2 = 802.11g
5689 */
5690
5691 /* 5.2GHz channels start after the 2.4GHz channels */
5692 modes[A].mode = MODE_IEEE80211A;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005693 modes[A].channels = &channels[ARRAY_SIZE(iwl4965_eeprom_band_1)];
Zhu Yib481de92007-09-25 17:54:57 -07005694 modes[A].rates = rates;
5695 modes[A].num_rates = 8; /* just OFDM */
5696 modes[A].rates = &rates[4];
5697 modes[A].num_channels = 0;
5698
5699 modes[B].mode = MODE_IEEE80211B;
5700 modes[B].channels = channels;
5701 modes[B].rates = rates;
5702 modes[B].num_rates = 4; /* just CCK */
5703 modes[B].num_channels = 0;
5704
5705 modes[G].mode = MODE_IEEE80211G;
5706 modes[G].channels = channels;
5707 modes[G].rates = rates;
5708 modes[G].num_rates = 12; /* OFDM & CCK */
5709 modes[G].num_channels = 0;
5710
5711 modes[G_11N].mode = MODE_IEEE80211G;
5712 modes[G_11N].channels = channels;
5713 modes[G_11N].num_rates = 13; /* OFDM & CCK */
5714 modes[G_11N].rates = rates;
5715 modes[G_11N].num_channels = 0;
5716
5717 modes[A_11N].mode = MODE_IEEE80211A;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005718 modes[A_11N].channels = &channels[ARRAY_SIZE(iwl4965_eeprom_band_1)];
Zhu Yib481de92007-09-25 17:54:57 -07005719 modes[A_11N].rates = &rates[4];
5720 modes[A_11N].num_rates = 9; /* just OFDM */
5721 modes[A_11N].num_channels = 0;
5722
5723 priv->ieee_channels = channels;
5724 priv->ieee_rates = rates;
5725
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005726 iwl4965_init_hw_rates(priv, rates);
Zhu Yib481de92007-09-25 17:54:57 -07005727
5728 for (i = 0, geo_ch = channels; i < priv->channel_count; i++) {
5729 ch = &priv->channel_info[i];
5730
5731 if (!is_channel_valid(ch)) {
5732 IWL_DEBUG_INFO("Channel %d [%sGHz] is restricted -- "
5733 "skipping.\n",
5734 ch->channel, is_channel_a_band(ch) ?
5735 "5.2" : "2.4");
5736 continue;
5737 }
5738
5739 if (is_channel_a_band(ch)) {
5740 geo_ch = &modes[A].channels[modes[A].num_channels++];
5741 modes[A_11N].num_channels++;
5742 } else {
5743 geo_ch = &modes[B].channels[modes[B].num_channels++];
5744 modes[G].num_channels++;
5745 modes[G_11N].num_channels++;
5746 }
5747
5748 geo_ch->freq = ieee80211chan2mhz(ch->channel);
5749 geo_ch->chan = ch->channel;
5750 geo_ch->power_level = ch->max_power_avg;
5751 geo_ch->antenna_max = 0xff;
5752
5753 if (is_channel_valid(ch)) {
5754 geo_ch->flag = IEEE80211_CHAN_W_SCAN;
5755 if (ch->flags & EEPROM_CHANNEL_IBSS)
5756 geo_ch->flag |= IEEE80211_CHAN_W_IBSS;
5757
5758 if (ch->flags & EEPROM_CHANNEL_ACTIVE)
5759 geo_ch->flag |= IEEE80211_CHAN_W_ACTIVE_SCAN;
5760
5761 if (ch->flags & EEPROM_CHANNEL_RADAR)
5762 geo_ch->flag |= IEEE80211_CHAN_W_RADAR_DETECT;
5763
5764 if (ch->max_power_avg > priv->max_channel_txpower_limit)
5765 priv->max_channel_txpower_limit =
5766 ch->max_power_avg;
5767 }
5768
5769 geo_ch->val = geo_ch->flag;
5770 }
5771
5772 if ((modes[A].num_channels == 0) && priv->is_abg) {
5773 printk(KERN_INFO DRV_NAME
5774 ": Incorrectly detected BG card as ABG. Please send "
5775 "your PCI ID 0x%04X:0x%04X to maintainer.\n",
5776 priv->pci_dev->device, priv->pci_dev->subsystem_device);
5777 priv->is_abg = 0;
5778 }
5779
5780 printk(KERN_INFO DRV_NAME
5781 ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
5782 modes[G].num_channels, modes[A].num_channels);
5783
5784 /*
5785 * NOTE: We register these in preference of order -- the
5786 * stack doesn't currently (as of 7.0.6 / Apr 24 '07) pick
5787 * a phymode based on rates or AP capabilities but seems to
5788 * configure it purely on if the channel being configured
5789 * is supported by a mode -- and the first match is taken
5790 */
5791
5792 if (modes[G].num_channels)
5793 ieee80211_register_hwmode(priv->hw, &modes[G]);
5794 if (modes[B].num_channels)
5795 ieee80211_register_hwmode(priv->hw, &modes[B]);
5796 if (modes[A].num_channels)
5797 ieee80211_register_hwmode(priv->hw, &modes[A]);
5798
5799 priv->modes = modes;
5800 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
5801
5802 return 0;
5803}
5804
5805/******************************************************************************
5806 *
5807 * uCode download functions
5808 *
5809 ******************************************************************************/
5810
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005811static void iwl4965_dealloc_ucode_pci(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005812{
5813 if (priv->ucode_code.v_addr != NULL) {
5814 pci_free_consistent(priv->pci_dev,
5815 priv->ucode_code.len,
5816 priv->ucode_code.v_addr,
5817 priv->ucode_code.p_addr);
5818 priv->ucode_code.v_addr = NULL;
5819 }
5820 if (priv->ucode_data.v_addr != NULL) {
5821 pci_free_consistent(priv->pci_dev,
5822 priv->ucode_data.len,
5823 priv->ucode_data.v_addr,
5824 priv->ucode_data.p_addr);
5825 priv->ucode_data.v_addr = NULL;
5826 }
5827 if (priv->ucode_data_backup.v_addr != NULL) {
5828 pci_free_consistent(priv->pci_dev,
5829 priv->ucode_data_backup.len,
5830 priv->ucode_data_backup.v_addr,
5831 priv->ucode_data_backup.p_addr);
5832 priv->ucode_data_backup.v_addr = NULL;
5833 }
5834 if (priv->ucode_init.v_addr != NULL) {
5835 pci_free_consistent(priv->pci_dev,
5836 priv->ucode_init.len,
5837 priv->ucode_init.v_addr,
5838 priv->ucode_init.p_addr);
5839 priv->ucode_init.v_addr = NULL;
5840 }
5841 if (priv->ucode_init_data.v_addr != NULL) {
5842 pci_free_consistent(priv->pci_dev,
5843 priv->ucode_init_data.len,
5844 priv->ucode_init_data.v_addr,
5845 priv->ucode_init_data.p_addr);
5846 priv->ucode_init_data.v_addr = NULL;
5847 }
5848 if (priv->ucode_boot.v_addr != NULL) {
5849 pci_free_consistent(priv->pci_dev,
5850 priv->ucode_boot.len,
5851 priv->ucode_boot.v_addr,
5852 priv->ucode_boot.p_addr);
5853 priv->ucode_boot.v_addr = NULL;
5854 }
5855}
5856
5857/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005858 * iwl4965_verify_inst_full - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07005859 * looking at all data.
5860 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005861static int iwl4965_verify_inst_full(struct iwl4965_priv *priv, __le32 * image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07005862{
5863 u32 val;
5864 u32 save_len = len;
5865 int rc = 0;
5866 u32 errcnt;
5867
5868 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
5869
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005870 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005871 if (rc)
5872 return rc;
5873
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005874 iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND);
Zhu Yib481de92007-09-25 17:54:57 -07005875
5876 errcnt = 0;
5877 for (; len > 0; len -= sizeof(u32), image++) {
5878 /* read data comes through single port, auto-incr addr */
5879 /* NOTE: Use the debugless read so we don't flood kernel log
5880 * if IWL_DL_IO is set */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005881 val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07005882 if (val != le32_to_cpu(*image)) {
5883 IWL_ERROR("uCode INST section is invalid at "
5884 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5885 save_len - len, val, le32_to_cpu(*image));
5886 rc = -EIO;
5887 errcnt++;
5888 if (errcnt >= 20)
5889 break;
5890 }
5891 }
5892
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005893 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005894
5895 if (!errcnt)
5896 IWL_DEBUG_INFO
5897 ("ucode image in INSTRUCTION memory is good\n");
5898
5899 return rc;
5900}
5901
5902
5903/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005904 * iwl4965_verify_inst_sparse - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07005905 * using sample data 100 bytes apart. If these sample points are good,
5906 * it's a pretty good bet that everything between them is good, too.
5907 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005908static int iwl4965_verify_inst_sparse(struct iwl4965_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07005909{
5910 u32 val;
5911 int rc = 0;
5912 u32 errcnt = 0;
5913 u32 i;
5914
5915 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
5916
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005917 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005918 if (rc)
5919 return rc;
5920
5921 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
5922 /* read data comes through single port, auto-incr addr */
5923 /* NOTE: Use the debugless read so we don't flood kernel log
5924 * if IWL_DL_IO is set */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005925 iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Zhu Yib481de92007-09-25 17:54:57 -07005926 i + RTC_INST_LOWER_BOUND);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005927 val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07005928 if (val != le32_to_cpu(*image)) {
5929#if 0 /* Enable this if you want to see details */
5930 IWL_ERROR("uCode INST section is invalid at "
5931 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5932 i, val, *image);
5933#endif
5934 rc = -EIO;
5935 errcnt++;
5936 if (errcnt >= 3)
5937 break;
5938 }
5939 }
5940
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005941 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005942
5943 return rc;
5944}
5945
5946
5947/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005948 * iwl4965_verify_ucode - determine which instruction image is in SRAM,
Zhu Yib481de92007-09-25 17:54:57 -07005949 * and verify its contents
5950 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005951static int iwl4965_verify_ucode(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005952{
5953 __le32 *image;
5954 u32 len;
5955 int rc = 0;
5956
5957 /* Try bootstrap */
5958 image = (__le32 *)priv->ucode_boot.v_addr;
5959 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005960 rc = iwl4965_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07005961 if (rc == 0) {
5962 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
5963 return 0;
5964 }
5965
5966 /* Try initialize */
5967 image = (__le32 *)priv->ucode_init.v_addr;
5968 len = priv->ucode_init.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005969 rc = iwl4965_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07005970 if (rc == 0) {
5971 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
5972 return 0;
5973 }
5974
5975 /* Try runtime/protocol */
5976 image = (__le32 *)priv->ucode_code.v_addr;
5977 len = priv->ucode_code.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005978 rc = iwl4965_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07005979 if (rc == 0) {
5980 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
5981 return 0;
5982 }
5983
5984 IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
5985
5986 /* Show first several data entries in instruction SRAM.
5987 * Selection of bootstrap image is arbitrary. */
5988 image = (__le32 *)priv->ucode_boot.v_addr;
5989 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005990 rc = iwl4965_verify_inst_full(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07005991
5992 return rc;
5993}
5994
5995
5996/* check contents of special bootstrap uCode SRAM */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005997static int iwl4965_verify_bsm(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005998{
5999 __le32 *image = priv->ucode_boot.v_addr;
6000 u32 len = priv->ucode_boot.len;
6001 u32 reg;
6002 u32 val;
6003
6004 IWL_DEBUG_INFO("Begin verify bsm\n");
6005
6006 /* verify BSM SRAM contents */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006007 val = iwl4965_read_prph(priv, BSM_WR_DWCOUNT_REG);
Zhu Yib481de92007-09-25 17:54:57 -07006008 for (reg = BSM_SRAM_LOWER_BOUND;
6009 reg < BSM_SRAM_LOWER_BOUND + len;
6010 reg += sizeof(u32), image ++) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006011 val = iwl4965_read_prph(priv, reg);
Zhu Yib481de92007-09-25 17:54:57 -07006012 if (val != le32_to_cpu(*image)) {
6013 IWL_ERROR("BSM uCode verification failed at "
6014 "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
6015 BSM_SRAM_LOWER_BOUND,
6016 reg - BSM_SRAM_LOWER_BOUND, len,
6017 val, le32_to_cpu(*image));
6018 return -EIO;
6019 }
6020 }
6021
6022 IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
6023
6024 return 0;
6025}
6026
6027/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006028 * iwl4965_load_bsm - Load bootstrap instructions
Zhu Yib481de92007-09-25 17:54:57 -07006029 *
6030 * BSM operation:
6031 *
6032 * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
6033 * in special SRAM that does not power down during RFKILL. When powering back
6034 * up after power-saving sleeps (or during initial uCode load), the BSM loads
6035 * the bootstrap program into the on-board processor, and starts it.
6036 *
6037 * The bootstrap program loads (via DMA) instructions and data for a new
6038 * program from host DRAM locations indicated by the host driver in the
6039 * BSM_DRAM_* registers. Once the new program is loaded, it starts
6040 * automatically.
6041 *
6042 * When initializing the NIC, the host driver points the BSM to the
6043 * "initialize" uCode image. This uCode sets up some internal data, then
6044 * notifies host via "initialize alive" that it is complete.
6045 *
6046 * The host then replaces the BSM_DRAM_* pointer values to point to the
6047 * normal runtime uCode instructions and a backup uCode data cache buffer
6048 * (filled initially with starting data values for the on-board processor),
6049 * then triggers the "initialize" uCode to load and launch the runtime uCode,
6050 * which begins normal operation.
6051 *
6052 * When doing a power-save shutdown, runtime uCode saves data SRAM into
6053 * the backup data cache in DRAM before SRAM is powered down.
6054 *
6055 * When powering back up, the BSM loads the bootstrap program. This reloads
6056 * the runtime uCode instructions and the backup data cache into SRAM,
6057 * and re-launches the runtime uCode from where it left off.
6058 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006059static int iwl4965_load_bsm(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006060{
6061 __le32 *image = priv->ucode_boot.v_addr;
6062 u32 len = priv->ucode_boot.len;
6063 dma_addr_t pinst;
6064 dma_addr_t pdata;
6065 u32 inst_len;
6066 u32 data_len;
6067 int rc;
6068 int i;
6069 u32 done;
6070 u32 reg_offset;
6071
6072 IWL_DEBUG_INFO("Begin load bsm\n");
6073
6074 /* make sure bootstrap program is no larger than BSM's SRAM size */
6075 if (len > IWL_MAX_BSM_SIZE)
6076 return -EINVAL;
6077
6078 /* Tell bootstrap uCode where to find the "Initialize" uCode
6079 * in host DRAM ... bits 31:0 for 3945, bits 35:4 for 4965.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006080 * NOTE: iwl4965_initialize_alive_start() will replace these values,
Zhu Yib481de92007-09-25 17:54:57 -07006081 * after the "initialize" uCode has run, to point to
6082 * runtime/protocol instructions and backup data cache. */
6083 pinst = priv->ucode_init.p_addr >> 4;
6084 pdata = priv->ucode_init_data.p_addr >> 4;
6085 inst_len = priv->ucode_init.len;
6086 data_len = priv->ucode_init_data.len;
6087
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006088 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006089 if (rc)
6090 return rc;
6091
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006092 iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
6093 iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
6094 iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
6095 iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
Zhu Yib481de92007-09-25 17:54:57 -07006096
6097 /* Fill BSM memory with bootstrap instructions */
6098 for (reg_offset = BSM_SRAM_LOWER_BOUND;
6099 reg_offset < BSM_SRAM_LOWER_BOUND + len;
6100 reg_offset += sizeof(u32), image++)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006101 _iwl4965_write_prph(priv, reg_offset,
Zhu Yib481de92007-09-25 17:54:57 -07006102 le32_to_cpu(*image));
6103
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006104 rc = iwl4965_verify_bsm(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006105 if (rc) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006106 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006107 return rc;
6108 }
6109
6110 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006111 iwl4965_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0);
6112 iwl4965_write_prph(priv, BSM_WR_MEM_DST_REG,
Zhu Yib481de92007-09-25 17:54:57 -07006113 RTC_INST_LOWER_BOUND);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006114 iwl4965_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07006115
6116 /* Load bootstrap code into instruction SRAM now,
6117 * to prepare to load "initialize" uCode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006118 iwl4965_write_prph(priv, BSM_WR_CTRL_REG,
Zhu Yib481de92007-09-25 17:54:57 -07006119 BSM_WR_CTRL_REG_BIT_START);
6120
6121 /* Wait for load of bootstrap uCode to finish */
6122 for (i = 0; i < 100; i++) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006123 done = iwl4965_read_prph(priv, BSM_WR_CTRL_REG);
Zhu Yib481de92007-09-25 17:54:57 -07006124 if (!(done & BSM_WR_CTRL_REG_BIT_START))
6125 break;
6126 udelay(10);
6127 }
6128 if (i < 100)
6129 IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i);
6130 else {
6131 IWL_ERROR("BSM write did not complete!\n");
6132 return -EIO;
6133 }
6134
6135 /* Enable future boot loads whenever power management unit triggers it
6136 * (e.g. when powering back up after power-save shutdown) */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006137 iwl4965_write_prph(priv, BSM_WR_CTRL_REG,
Zhu Yib481de92007-09-25 17:54:57 -07006138 BSM_WR_CTRL_REG_BIT_START_EN);
6139
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006140 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006141
6142 return 0;
6143}
6144
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006145static void iwl4965_nic_start(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006146{
6147 /* Remove all resets to allow NIC to operate */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006148 iwl4965_write32(priv, CSR_RESET, 0);
Zhu Yib481de92007-09-25 17:54:57 -07006149}
6150
6151/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006152 * iwl4965_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07006153 *
6154 * Copy into buffers for card to fetch via bus-mastering
6155 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006156static int iwl4965_read_ucode(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006157{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006158 struct iwl4965_ucode *ucode;
Zhu Yib481de92007-09-25 17:54:57 -07006159 int rc = 0;
6160 const struct firmware *ucode_raw;
6161 const char *name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode";
6162 u8 *src;
6163 size_t len;
6164 u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
6165
6166 /* Ask kernel firmware_class module to get the boot firmware off disk.
6167 * request_firmware() is synchronous, file is in memory on return. */
6168 rc = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
6169 if (rc < 0) {
6170 IWL_ERROR("%s firmware file req failed: Reason %d\n", name, rc);
6171 goto error;
6172 }
6173
6174 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
6175 name, ucode_raw->size);
6176
6177 /* Make sure that we got at least our header! */
6178 if (ucode_raw->size < sizeof(*ucode)) {
6179 IWL_ERROR("File size way too small!\n");
6180 rc = -EINVAL;
6181 goto err_release;
6182 }
6183
6184 /* Data from ucode file: header followed by uCode images */
6185 ucode = (void *)ucode_raw->data;
6186
6187 ver = le32_to_cpu(ucode->ver);
6188 inst_size = le32_to_cpu(ucode->inst_size);
6189 data_size = le32_to_cpu(ucode->data_size);
6190 init_size = le32_to_cpu(ucode->init_size);
6191 init_data_size = le32_to_cpu(ucode->init_data_size);
6192 boot_size = le32_to_cpu(ucode->boot_size);
6193
6194 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
6195 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
6196 inst_size);
6197 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
6198 data_size);
6199 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
6200 init_size);
6201 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
6202 init_data_size);
6203 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
6204 boot_size);
6205
6206 /* Verify size of file vs. image size info in file's header */
6207 if (ucode_raw->size < sizeof(*ucode) +
6208 inst_size + data_size + init_size +
6209 init_data_size + boot_size) {
6210
6211 IWL_DEBUG_INFO("uCode file size %d too small\n",
6212 (int)ucode_raw->size);
6213 rc = -EINVAL;
6214 goto err_release;
6215 }
6216
6217 /* Verify that uCode images will fit in card's SRAM */
6218 if (inst_size > IWL_MAX_INST_SIZE) {
6219 IWL_DEBUG_INFO("uCode instr len %d too large to fit in card\n",
6220 (int)inst_size);
6221 rc = -EINVAL;
6222 goto err_release;
6223 }
6224
6225 if (data_size > IWL_MAX_DATA_SIZE) {
6226 IWL_DEBUG_INFO("uCode data len %d too large to fit in card\n",
6227 (int)data_size);
6228 rc = -EINVAL;
6229 goto err_release;
6230 }
6231 if (init_size > IWL_MAX_INST_SIZE) {
6232 IWL_DEBUG_INFO
6233 ("uCode init instr len %d too large to fit in card\n",
6234 (int)init_size);
6235 rc = -EINVAL;
6236 goto err_release;
6237 }
6238 if (init_data_size > IWL_MAX_DATA_SIZE) {
6239 IWL_DEBUG_INFO
6240 ("uCode init data len %d too large to fit in card\n",
6241 (int)init_data_size);
6242 rc = -EINVAL;
6243 goto err_release;
6244 }
6245 if (boot_size > IWL_MAX_BSM_SIZE) {
6246 IWL_DEBUG_INFO
6247 ("uCode boot instr len %d too large to fit in bsm\n",
6248 (int)boot_size);
6249 rc = -EINVAL;
6250 goto err_release;
6251 }
6252
6253 /* Allocate ucode buffers for card's bus-master loading ... */
6254
6255 /* Runtime instructions and 2 copies of data:
6256 * 1) unmodified from disk
6257 * 2) backup cache for save/restore during power-downs */
6258 priv->ucode_code.len = inst_size;
6259 priv->ucode_code.v_addr =
6260 pci_alloc_consistent(priv->pci_dev,
6261 priv->ucode_code.len,
6262 &(priv->ucode_code.p_addr));
6263
6264 priv->ucode_data.len = data_size;
6265 priv->ucode_data.v_addr =
6266 pci_alloc_consistent(priv->pci_dev,
6267 priv->ucode_data.len,
6268 &(priv->ucode_data.p_addr));
6269
6270 priv->ucode_data_backup.len = data_size;
6271 priv->ucode_data_backup.v_addr =
6272 pci_alloc_consistent(priv->pci_dev,
6273 priv->ucode_data_backup.len,
6274 &(priv->ucode_data_backup.p_addr));
6275
6276
6277 /* Initialization instructions and data */
6278 priv->ucode_init.len = init_size;
6279 priv->ucode_init.v_addr =
6280 pci_alloc_consistent(priv->pci_dev,
6281 priv->ucode_init.len,
6282 &(priv->ucode_init.p_addr));
6283
6284 priv->ucode_init_data.len = init_data_size;
6285 priv->ucode_init_data.v_addr =
6286 pci_alloc_consistent(priv->pci_dev,
6287 priv->ucode_init_data.len,
6288 &(priv->ucode_init_data.p_addr));
6289
6290 /* Bootstrap (instructions only, no data) */
6291 priv->ucode_boot.len = boot_size;
6292 priv->ucode_boot.v_addr =
6293 pci_alloc_consistent(priv->pci_dev,
6294 priv->ucode_boot.len,
6295 &(priv->ucode_boot.p_addr));
6296
6297 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
6298 !priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr ||
6299 !priv->ucode_boot.v_addr || !priv->ucode_data_backup.v_addr)
6300 goto err_pci_alloc;
6301
6302 /* Copy images into buffers for card's bus-master reads ... */
6303
6304 /* Runtime instructions (first block of data in file) */
6305 src = &ucode->data[0];
6306 len = priv->ucode_code.len;
6307 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %d\n",
6308 (int)len);
6309 memcpy(priv->ucode_code.v_addr, src, len);
6310 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
6311 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
6312
6313 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006314 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
Zhu Yib481de92007-09-25 17:54:57 -07006315 src = &ucode->data[inst_size];
6316 len = priv->ucode_data.len;
6317 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %d\n",
6318 (int)len);
6319 memcpy(priv->ucode_data.v_addr, src, len);
6320 memcpy(priv->ucode_data_backup.v_addr, src, len);
6321
6322 /* Initialization instructions (3rd block) */
6323 if (init_size) {
6324 src = &ucode->data[inst_size + data_size];
6325 len = priv->ucode_init.len;
6326 IWL_DEBUG_INFO("Copying (but not loading) init instr len %d\n",
6327 (int)len);
6328 memcpy(priv->ucode_init.v_addr, src, len);
6329 }
6330
6331 /* Initialization data (4th block) */
6332 if (init_data_size) {
6333 src = &ucode->data[inst_size + data_size + init_size];
6334 len = priv->ucode_init_data.len;
6335 IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n",
6336 (int)len);
6337 memcpy(priv->ucode_init_data.v_addr, src, len);
6338 }
6339
6340 /* Bootstrap instructions (5th block) */
6341 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
6342 len = priv->ucode_boot.len;
6343 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n",
6344 (int)len);
6345 memcpy(priv->ucode_boot.v_addr, src, len);
6346
6347 /* We have our copies now, allow OS release its copies */
6348 release_firmware(ucode_raw);
6349 return 0;
6350
6351 err_pci_alloc:
6352 IWL_ERROR("failed to allocate pci memory\n");
6353 rc = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006354 iwl4965_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006355
6356 err_release:
6357 release_firmware(ucode_raw);
6358
6359 error:
6360 return rc;
6361}
6362
6363
6364/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006365 * iwl4965_set_ucode_ptrs - Set uCode address location
Zhu Yib481de92007-09-25 17:54:57 -07006366 *
6367 * Tell initialization uCode where to find runtime uCode.
6368 *
6369 * BSM registers initially contain pointers to initialization uCode.
6370 * We need to replace them to load runtime uCode inst and data,
6371 * and to save runtime data when powering down.
6372 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006373static int iwl4965_set_ucode_ptrs(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006374{
6375 dma_addr_t pinst;
6376 dma_addr_t pdata;
6377 int rc = 0;
6378 unsigned long flags;
6379
6380 /* bits 35:4 for 4965 */
6381 pinst = priv->ucode_code.p_addr >> 4;
6382 pdata = priv->ucode_data_backup.p_addr >> 4;
6383
6384 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006385 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006386 if (rc) {
6387 spin_unlock_irqrestore(&priv->lock, flags);
6388 return rc;
6389 }
6390
6391 /* Tell bootstrap uCode where to find image to load */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006392 iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
6393 iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
6394 iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07006395 priv->ucode_data.len);
6396
6397 /* Inst bytecount must be last to set up, bit 31 signals uCode
6398 * that all new ptr/size info is in place */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006399 iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07006400 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
6401
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006402 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006403
6404 spin_unlock_irqrestore(&priv->lock, flags);
6405
6406 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
6407
6408 return rc;
6409}
6410
6411/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006412 * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07006413 *
6414 * Called after REPLY_ALIVE notification received from "initialize" uCode.
6415 *
6416 * The 4965 "initialize" ALIVE reply contains calibration data for:
6417 * Voltage, temperature, and MIMO tx gain correction, now stored in priv
6418 * (3945 does not contain this data).
6419 *
6420 * Tell "initialize" uCode to go ahead and load the runtime uCode.
6421*/
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006422static void iwl4965_init_alive_start(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006423{
6424 /* Check alive response for "valid" sign from uCode */
6425 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
6426 /* We had an error bringing up the hardware, so take it
6427 * all the way back down so we can try again */
6428 IWL_DEBUG_INFO("Initialize Alive failed.\n");
6429 goto restart;
6430 }
6431
6432 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
6433 * This is a paranoid check, because we would not have gotten the
6434 * "initialize" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006435 if (iwl4965_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006436 /* Runtime instruction load was bad;
6437 * take it all the way back down so we can try again */
6438 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
6439 goto restart;
6440 }
6441
6442 /* Calculate temperature */
6443 priv->temperature = iwl4965_get_temperature(priv);
6444
6445 /* Send pointers to protocol/runtime uCode image ... init code will
6446 * load and launch runtime uCode, which will send us another "Alive"
6447 * notification. */
6448 IWL_DEBUG_INFO("Initialization Alive received.\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006449 if (iwl4965_set_ucode_ptrs(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006450 /* Runtime instruction load won't happen;
6451 * take it all the way back down so we can try again */
6452 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
6453 goto restart;
6454 }
6455 return;
6456
6457 restart:
6458 queue_work(priv->workqueue, &priv->restart);
6459}
6460
6461
6462/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006463 * iwl4965_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07006464 * from protocol/runtime uCode (initialization uCode's
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006465 * Alive gets handled by iwl4965_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07006466 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006467static void iwl4965_alive_start(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006468{
6469 int rc = 0;
6470
6471 IWL_DEBUG_INFO("Runtime Alive received.\n");
6472
6473 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
6474 /* We had an error bringing up the hardware, so take it
6475 * all the way back down so we can try again */
6476 IWL_DEBUG_INFO("Alive failed.\n");
6477 goto restart;
6478 }
6479
6480 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
6481 * This is a paranoid check, because we would not have gotten the
6482 * "runtime" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006483 if (iwl4965_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006484 /* Runtime instruction load was bad;
6485 * take it all the way back down so we can try again */
6486 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
6487 goto restart;
6488 }
6489
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006490 iwl4965_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006491
6492 rc = iwl4965_alive_notify(priv);
6493 if (rc) {
6494 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
6495 rc);
6496 goto restart;
6497 }
6498
6499 /* After the ALIVE response, we can process host commands */
6500 set_bit(STATUS_ALIVE, &priv->status);
6501
6502 /* Clear out the uCode error bit if it is set */
6503 clear_bit(STATUS_FW_ERROR, &priv->status);
6504
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006505 rc = iwl4965_init_channel_map(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006506 if (rc) {
6507 IWL_ERROR("initializing regulatory failed: %d\n", rc);
6508 return;
6509 }
6510
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006511 iwl4965_init_geos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006512
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006513 if (iwl4965_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07006514 return;
6515
6516 if (!priv->mac80211_registered) {
6517 /* Unlock so any user space entry points can call back into
6518 * the driver without a deadlock... */
6519 mutex_unlock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006520 iwl4965_rate_control_register(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07006521 rc = ieee80211_register_hw(priv->hw);
6522 priv->hw->conf.beacon_int = 100;
6523 mutex_lock(&priv->mutex);
6524
6525 if (rc) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006526 iwl4965_rate_control_unregister(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07006527 IWL_ERROR("Failed to register network "
6528 "device (error %d)\n", rc);
6529 return;
6530 }
6531
6532 priv->mac80211_registered = 1;
6533
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006534 iwl4965_reset_channel_flag(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006535 } else
6536 ieee80211_start_queues(priv->hw);
6537
6538 priv->active_rate = priv->rates_mask;
6539 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
6540
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006541 iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode));
Zhu Yib481de92007-09-25 17:54:57 -07006542
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006543 if (iwl4965_is_associated(priv)) {
6544 struct iwl4965_rxon_cmd *active_rxon =
6545 (struct iwl4965_rxon_cmd *)(&priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07006546
6547 memcpy(&priv->staging_rxon, &priv->active_rxon,
6548 sizeof(priv->staging_rxon));
6549 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
6550 } else {
6551 /* Initialize our rx_config data */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006552 iwl4965_connection_init_rx_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006553 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
6554 }
6555
6556 /* Configure BT coexistence */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006557 iwl4965_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006558
6559 /* Configure the adapter for unassociated operation */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006560 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006561
6562 /* At this point, the NIC is initialized and operational */
6563 priv->notif_missed_beacons = 0;
6564 set_bit(STATUS_READY, &priv->status);
6565
6566 iwl4965_rf_kill_ct_config(priv);
6567 IWL_DEBUG_INFO("ALIVE processing complete.\n");
6568
6569 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006570 iwl4965_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006571
6572 return;
6573
6574 restart:
6575 queue_work(priv->workqueue, &priv->restart);
6576}
6577
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006578static void iwl4965_cancel_deferred_work(struct iwl4965_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07006579
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006580static void __iwl4965_down(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006581{
6582 unsigned long flags;
6583 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
6584 struct ieee80211_conf *conf = NULL;
6585
6586 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
6587
6588 conf = ieee80211_get_hw_conf(priv->hw);
6589
6590 if (!exit_pending)
6591 set_bit(STATUS_EXIT_PENDING, &priv->status);
6592
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006593 iwl4965_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006594
6595 /* Unblock any waiting calls */
6596 wake_up_interruptible_all(&priv->wait_command_queue);
6597
Zhu Yib481de92007-09-25 17:54:57 -07006598 /* Wipe out the EXIT_PENDING status bit if we are not actually
6599 * exiting the module */
6600 if (!exit_pending)
6601 clear_bit(STATUS_EXIT_PENDING, &priv->status);
6602
6603 /* stop and reset the on-board processor */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006604 iwl4965_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07006605
6606 /* tell the device to stop sending interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006607 iwl4965_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006608
6609 if (priv->mac80211_registered)
6610 ieee80211_stop_queues(priv->hw);
6611
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006612 /* If we have not previously called iwl4965_init() then
Zhu Yib481de92007-09-25 17:54:57 -07006613 * clear all bits but the RF Kill and SUSPEND bits and return */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006614 if (!iwl4965_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006615 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
6616 STATUS_RF_KILL_HW |
6617 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
6618 STATUS_RF_KILL_SW |
6619 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
6620 STATUS_IN_SUSPEND;
6621 goto exit;
6622 }
6623
6624 /* ...otherwise clear out all the status bits but the RF Kill and
6625 * SUSPEND bits and continue taking the NIC down. */
6626 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
6627 STATUS_RF_KILL_HW |
6628 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
6629 STATUS_RF_KILL_SW |
6630 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
6631 STATUS_IN_SUSPEND |
6632 test_bit(STATUS_FW_ERROR, &priv->status) <<
6633 STATUS_FW_ERROR;
6634
6635 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006636 iwl4965_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07006637 spin_unlock_irqrestore(&priv->lock, flags);
6638
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006639 iwl4965_hw_txq_ctx_stop(priv);
6640 iwl4965_hw_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006641
6642 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006643 if (!iwl4965_grab_nic_access(priv)) {
6644 iwl4965_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07006645 APMG_CLK_VAL_DMA_CLK_RQT);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006646 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006647 }
6648 spin_unlock_irqrestore(&priv->lock, flags);
6649
6650 udelay(5);
6651
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006652 iwl4965_hw_nic_stop_master(priv);
6653 iwl4965_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
6654 iwl4965_hw_nic_reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006655
6656 exit:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006657 memset(&priv->card_alive, 0, sizeof(struct iwl4965_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07006658
6659 if (priv->ibss_beacon)
6660 dev_kfree_skb(priv->ibss_beacon);
6661 priv->ibss_beacon = NULL;
6662
6663 /* clear out any free frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006664 iwl4965_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006665}
6666
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006667static void iwl4965_down(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006668{
6669 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006670 __iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006671 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08006672
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006673 iwl4965_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006674}
6675
6676#define MAX_HW_RESTARTS 5
6677
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006678static int __iwl4965_up(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006679{
Joe Perches0795af52007-10-03 17:59:30 -07006680 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07006681 int rc, i;
6682 u32 hw_rf_kill = 0;
6683
6684 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
6685 IWL_WARNING("Exit pending; will not bring the NIC up\n");
6686 return -EIO;
6687 }
6688
6689 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
6690 IWL_WARNING("Radio disabled by SW RF kill (module "
6691 "parameter)\n");
6692 return 0;
6693 }
6694
Reinette Chatrea781cf92008-01-21 10:08:31 -08006695 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
6696 IWL_ERROR("ucode not available for device bringup\n");
6697 return -EIO;
6698 }
6699
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006700 iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07006701
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006702 rc = iwl4965_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006703 if (rc) {
6704 IWL_ERROR("Unable to int nic\n");
6705 return rc;
6706 }
6707
6708 /* make sure rfkill handshake bits are cleared */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006709 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
6710 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07006711 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
6712
6713 /* clear (again), then enable host interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006714 iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF);
6715 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006716
6717 /* really make sure rfkill handshake bits are cleared */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006718 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
6719 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07006720
6721 /* Copy original ucode data image from disk into backup cache.
6722 * This will be used to initialize the on-board processor's
6723 * data SRAM for a clean start when the runtime program first loads. */
6724 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
6725 priv->ucode_data.len);
6726
6727 /* If platform's RF_KILL switch is set to KILL,
6728 * wait for BIT_INT_RF_KILL interrupt before loading uCode
6729 * and getting things started */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006730 if (!(iwl4965_read32(priv, CSR_GP_CNTRL) &
Zhu Yib481de92007-09-25 17:54:57 -07006731 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
6732 hw_rf_kill = 1;
6733
6734 if (test_bit(STATUS_RF_KILL_HW, &priv->status) || hw_rf_kill) {
6735 IWL_WARNING("Radio disabled by HW RF Kill switch\n");
6736 return 0;
6737 }
6738
6739 for (i = 0; i < MAX_HW_RESTARTS; i++) {
6740
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006741 iwl4965_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006742
6743 /* load bootstrap state machine,
6744 * load bootstrap program into processor's memory,
6745 * prepare to load the "initialize" uCode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006746 rc = iwl4965_load_bsm(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006747
6748 if (rc) {
6749 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc);
6750 continue;
6751 }
6752
6753 /* start card; "initialize" will load runtime ucode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006754 iwl4965_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006755
6756 /* MAC Address location in EEPROM same for 3945/4965 */
6757 get_eeprom_mac(priv, priv->mac_addr);
Joe Perches0795af52007-10-03 17:59:30 -07006758 IWL_DEBUG_INFO("MAC address: %s\n",
6759 print_mac(mac, priv->mac_addr));
Zhu Yib481de92007-09-25 17:54:57 -07006760
6761 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
6762
6763 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
6764
6765 return 0;
6766 }
6767
6768 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006769 __iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006770
6771 /* tried to restart and config the device for as long as our
6772 * patience could withstand */
6773 IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
6774 return -EIO;
6775}
6776
6777
6778/*****************************************************************************
6779 *
6780 * Workqueue callbacks
6781 *
6782 *****************************************************************************/
6783
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006784static void iwl4965_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07006785{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006786 struct iwl4965_priv *priv =
6787 container_of(data, struct iwl4965_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07006788
6789 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6790 return;
6791
6792 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006793 iwl4965_init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006794 mutex_unlock(&priv->mutex);
6795}
6796
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006797static void iwl4965_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07006798{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006799 struct iwl4965_priv *priv =
6800 container_of(data, struct iwl4965_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07006801
6802 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6803 return;
6804
6805 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006806 iwl4965_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006807 mutex_unlock(&priv->mutex);
6808}
6809
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006810static void iwl4965_bg_rf_kill(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07006811{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006812 struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, rf_kill);
Zhu Yib481de92007-09-25 17:54:57 -07006813
6814 wake_up_interruptible(&priv->wait_command_queue);
6815
6816 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6817 return;
6818
6819 mutex_lock(&priv->mutex);
6820
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006821 if (!iwl4965_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006822 IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL,
6823 "HW and/or SW RF Kill no longer active, restarting "
6824 "device\n");
6825 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
6826 queue_work(priv->workqueue, &priv->restart);
6827 } else {
6828
6829 if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
6830 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
6831 "disabled by SW switch\n");
6832 else
6833 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
6834 "Kill switch must be turned off for "
6835 "wireless networking to work.\n");
6836 }
6837 mutex_unlock(&priv->mutex);
6838}
6839
6840#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
6841
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006842static void iwl4965_bg_scan_check(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07006843{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006844 struct iwl4965_priv *priv =
6845 container_of(data, struct iwl4965_priv, scan_check.work);
Zhu Yib481de92007-09-25 17:54:57 -07006846
6847 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6848 return;
6849
6850 mutex_lock(&priv->mutex);
6851 if (test_bit(STATUS_SCANNING, &priv->status) ||
6852 test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
6853 IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN,
6854 "Scan completion watchdog resetting adapter (%dms)\n",
6855 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG));
mabbas052c4b92007-10-25 17:15:43 +08006856
Zhu Yib481de92007-09-25 17:54:57 -07006857 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006858 iwl4965_send_scan_abort(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006859 }
6860 mutex_unlock(&priv->mutex);
6861}
6862
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006863static void iwl4965_bg_request_scan(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07006864{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006865 struct iwl4965_priv *priv =
6866 container_of(data, struct iwl4965_priv, request_scan);
6867 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07006868 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006869 .len = sizeof(struct iwl4965_scan_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07006870 .meta.flags = CMD_SIZE_HUGE,
6871 };
6872 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006873 struct iwl4965_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07006874 struct ieee80211_conf *conf = NULL;
6875 u8 direct_mask;
6876 int phymode;
6877
6878 conf = ieee80211_get_hw_conf(priv->hw);
6879
6880 mutex_lock(&priv->mutex);
6881
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006882 if (!iwl4965_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006883 IWL_WARNING("request scan called when driver not ready.\n");
6884 goto done;
6885 }
6886
6887 /* Make sure the scan wasn't cancelled before this queued work
6888 * was given the chance to run... */
6889 if (!test_bit(STATUS_SCANNING, &priv->status))
6890 goto done;
6891
6892 /* This should never be called or scheduled if there is currently
6893 * a scan active in the hardware. */
6894 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
6895 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
6896 "Ignoring second request.\n");
6897 rc = -EIO;
6898 goto done;
6899 }
6900
6901 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
6902 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
6903 goto done;
6904 }
6905
6906 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
6907 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6908 goto done;
6909 }
6910
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006911 if (iwl4965_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006912 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6913 goto done;
6914 }
6915
6916 if (!test_bit(STATUS_READY, &priv->status)) {
6917 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
6918 goto done;
6919 }
6920
6921 if (!priv->scan_bands) {
6922 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
6923 goto done;
6924 }
6925
6926 if (!priv->scan) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006927 priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) +
Zhu Yib481de92007-09-25 17:54:57 -07006928 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
6929 if (!priv->scan) {
6930 rc = -ENOMEM;
6931 goto done;
6932 }
6933 }
6934 scan = priv->scan;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006935 memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07006936
6937 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
6938 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
6939
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006940 if (iwl4965_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006941 u16 interval = 0;
6942 u32 extra;
6943 u32 suspend_time = 100;
6944 u32 scan_suspend_time = 100;
6945 unsigned long flags;
6946
6947 IWL_DEBUG_INFO("Scanning while associated...\n");
6948
6949 spin_lock_irqsave(&priv->lock, flags);
6950 interval = priv->beacon_int;
6951 spin_unlock_irqrestore(&priv->lock, flags);
6952
6953 scan->suspend_time = 0;
mabbas052c4b92007-10-25 17:15:43 +08006954 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07006955 if (!interval)
6956 interval = suspend_time;
6957
6958 extra = (suspend_time / interval) << 22;
6959 scan_suspend_time = (extra |
6960 ((suspend_time % interval) * 1024));
6961 scan->suspend_time = cpu_to_le32(scan_suspend_time);
6962 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
6963 scan_suspend_time, interval);
6964 }
6965
6966 /* We should add the ability for user to lock to PASSIVE ONLY */
6967 if (priv->one_direct_scan) {
6968 IWL_DEBUG_SCAN
6969 ("Kicking off one direct scan for '%s'\n",
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006970 iwl4965_escape_essid(priv->direct_ssid,
Zhu Yib481de92007-09-25 17:54:57 -07006971 priv->direct_ssid_len));
6972 scan->direct_scan[0].id = WLAN_EID_SSID;
6973 scan->direct_scan[0].len = priv->direct_ssid_len;
6974 memcpy(scan->direct_scan[0].ssid,
6975 priv->direct_ssid, priv->direct_ssid_len);
6976 direct_mask = 1;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006977 } else if (!iwl4965_is_associated(priv) && priv->essid_len) {
Zhu Yib481de92007-09-25 17:54:57 -07006978 scan->direct_scan[0].id = WLAN_EID_SSID;
6979 scan->direct_scan[0].len = priv->essid_len;
6980 memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
6981 direct_mask = 1;
6982 } else
6983 direct_mask = 0;
6984
6985 /* We don't build a direct scan probe request; the uCode will do
6986 * that based on the direct_mask added to each channel entry */
6987 scan->tx_cmd.len = cpu_to_le16(
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006988 iwl4965_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data,
Zhu Yib481de92007-09-25 17:54:57 -07006989 IWL_MAX_SCAN_SIZE - sizeof(scan), 0));
6990 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
6991 scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id;
6992 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
6993
6994 /* flags + rate selection */
6995
6996 scan->tx_cmd.tx_flags |= cpu_to_le32(0x200);
6997
6998 switch (priv->scan_bands) {
6999 case 2:
7000 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
7001 scan->tx_cmd.rate_n_flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007002 iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP,
Zhu Yib481de92007-09-25 17:54:57 -07007003 RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK);
7004
7005 scan->good_CRC_th = 0;
7006 phymode = MODE_IEEE80211G;
7007 break;
7008
7009 case 1:
7010 scan->tx_cmd.rate_n_flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007011 iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP,
Zhu Yib481de92007-09-25 17:54:57 -07007012 RATE_MCS_ANT_B_MSK);
7013 scan->good_CRC_th = IWL_GOOD_CRC_TH;
7014 phymode = MODE_IEEE80211A;
7015 break;
7016
7017 default:
7018 IWL_WARNING("Invalid scan band count\n");
7019 goto done;
7020 }
7021
7022 /* select Rx chains */
7023
7024 /* Force use of chains B and C (0x6) for scan Rx.
7025 * Avoid A (0x1) because of its off-channel reception on A-band.
7026 * MIMO is not used here, but value is required to make uCode happy. */
7027 scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK |
7028 cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) |
7029 (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) |
7030 (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS));
7031
7032 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR)
7033 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
7034
7035 if (direct_mask)
7036 IWL_DEBUG_SCAN
7037 ("Initiating direct scan for %s.\n",
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007038 iwl4965_escape_essid(priv->essid, priv->essid_len));
Zhu Yib481de92007-09-25 17:54:57 -07007039 else
7040 IWL_DEBUG_SCAN("Initiating indirect scan.\n");
7041
7042 scan->channel_count =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007043 iwl4965_get_channels_for_scan(
Zhu Yib481de92007-09-25 17:54:57 -07007044 priv, phymode, 1, /* active */
7045 direct_mask,
7046 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
7047
7048 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007049 scan->channel_count * sizeof(struct iwl4965_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07007050 cmd.data = scan;
7051 scan->len = cpu_to_le16(cmd.len);
7052
7053 set_bit(STATUS_SCAN_HW, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007054 rc = iwl4965_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07007055 if (rc)
7056 goto done;
7057
7058 queue_delayed_work(priv->workqueue, &priv->scan_check,
7059 IWL_SCAN_CHECK_WATCHDOG);
7060
7061 mutex_unlock(&priv->mutex);
7062 return;
7063
7064 done:
Ian Schram01ebd062007-10-25 17:15:22 +08007065 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07007066 queue_work(priv->workqueue, &priv->scan_completed);
7067 mutex_unlock(&priv->mutex);
7068}
7069
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007070static void iwl4965_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07007071{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007072 struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07007073
7074 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7075 return;
7076
7077 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007078 __iwl4965_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007079 mutex_unlock(&priv->mutex);
7080}
7081
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007082static void iwl4965_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07007083{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007084 struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07007085
7086 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7087 return;
7088
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007089 iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007090 queue_work(priv->workqueue, &priv->up);
7091}
7092
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007093static void iwl4965_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07007094{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007095 struct iwl4965_priv *priv =
7096 container_of(data, struct iwl4965_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07007097
7098 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7099 return;
7100
7101 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007102 iwl4965_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007103 mutex_unlock(&priv->mutex);
7104}
7105
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007106static void iwl4965_bg_post_associate(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07007107{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007108 struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv,
Zhu Yib481de92007-09-25 17:54:57 -07007109 post_associate.work);
7110
7111 int rc = 0;
7112 struct ieee80211_conf *conf = NULL;
Joe Perches0795af52007-10-03 17:59:30 -07007113 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07007114
7115 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
7116 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__);
7117 return;
7118 }
7119
Joe Perches0795af52007-10-03 17:59:30 -07007120 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
7121 priv->assoc_id,
7122 print_mac(mac, priv->active_rxon.bssid_addr));
Zhu Yib481de92007-09-25 17:54:57 -07007123
7124
7125 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7126 return;
7127
7128 mutex_lock(&priv->mutex);
7129
Mohamed Abbas948c1712007-10-25 17:15:45 +08007130 if (!priv->interface_id || !priv->is_open) {
7131 mutex_unlock(&priv->mutex);
7132 return;
7133 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007134 iwl4965_scan_cancel_timeout(priv, 200);
mabbas052c4b92007-10-25 17:15:43 +08007135
Zhu Yib481de92007-09-25 17:54:57 -07007136 conf = ieee80211_get_hw_conf(priv->hw);
7137
7138 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007139 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007140
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007141 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
7142 iwl4965_setup_rxon_timing(priv);
7143 rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07007144 sizeof(priv->rxon_timing), &priv->rxon_timing);
7145 if (rc)
7146 IWL_WARNING("REPLY_RXON_TIMING failed - "
7147 "Attempting to continue.\n");
7148
7149 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
7150
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007151#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -07007152 if (priv->is_ht_enabled && priv->current_assoc_ht.is_ht)
7153 iwl4965_set_rxon_ht(priv, &priv->current_assoc_ht);
7154 else {
7155 priv->active_rate_ht[0] = 0;
7156 priv->active_rate_ht[1] = 0;
7157 priv->current_channel_width = IWL_CHANNEL_WIDTH_20MHZ;
7158 }
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007159#endif /* CONFIG_IWL4965_HT*/
Zhu Yib481de92007-09-25 17:54:57 -07007160 iwl4965_set_rxon_chain(priv);
7161 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
7162
7163 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
7164 priv->assoc_id, priv->beacon_int);
7165
7166 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7167 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
7168 else
7169 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
7170
7171 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
7172 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
7173 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
7174 else
7175 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
7176
7177 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
7178 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
7179
7180 }
7181
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007182 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007183
7184 switch (priv->iw_mode) {
7185 case IEEE80211_IF_TYPE_STA:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007186 iwl4965_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07007187 break;
7188
7189 case IEEE80211_IF_TYPE_IBSS:
7190
7191 /* clear out the station table */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007192 iwl4965_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007193
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007194 iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0);
7195 iwl4965_rxon_add_station(priv, priv->bssid, 0);
7196 iwl4965_rate_scale_init(priv->hw, IWL_STA_ID);
7197 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007198
7199 break;
7200
7201 default:
7202 IWL_ERROR("%s Should not be called in %d mode\n",
7203 __FUNCTION__, priv->iw_mode);
7204 break;
7205 }
7206
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007207 iwl4965_sequence_reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007208
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007209#ifdef CONFIG_IWL4965_SENSITIVITY
Zhu Yib481de92007-09-25 17:54:57 -07007210 /* Enable Rx differential gain and sensitivity calibrations */
7211 iwl4965_chain_noise_reset(priv);
7212 priv->start_calib = 1;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007213#endif /* CONFIG_IWL4965_SENSITIVITY */
Zhu Yib481de92007-09-25 17:54:57 -07007214
7215 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
7216 priv->assoc_station_added = 1;
7217
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007218#ifdef CONFIG_IWL4965_QOS
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007219 iwl4965_activate_qos(priv, 0);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007220#endif /* CONFIG_IWL4965_QOS */
Zhu Yib481de92007-09-25 17:54:57 -07007221 mutex_unlock(&priv->mutex);
7222}
7223
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007224static void iwl4965_bg_abort_scan(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07007225{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007226 struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, abort_scan);
Zhu Yib481de92007-09-25 17:54:57 -07007227
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007228 if (!iwl4965_is_ready(priv))
Zhu Yib481de92007-09-25 17:54:57 -07007229 return;
7230
7231 mutex_lock(&priv->mutex);
7232
7233 set_bit(STATUS_SCAN_ABORTING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007234 iwl4965_send_scan_abort(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007235
7236 mutex_unlock(&priv->mutex);
7237}
7238
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007239static void iwl4965_bg_scan_completed(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07007240{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007241 struct iwl4965_priv *priv =
7242 container_of(work, struct iwl4965_priv, scan_completed);
Zhu Yib481de92007-09-25 17:54:57 -07007243
7244 IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n");
7245
7246 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7247 return;
7248
7249 ieee80211_scan_completed(priv->hw);
7250
7251 /* Since setting the TXPOWER may have been deferred while
7252 * performing the scan, fire one off */
7253 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007254 iwl4965_hw_reg_send_txpower(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007255 mutex_unlock(&priv->mutex);
7256}
7257
7258/*****************************************************************************
7259 *
7260 * mac80211 entry point functions
7261 *
7262 *****************************************************************************/
7263
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007264static int iwl4965_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07007265{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007266 struct iwl4965_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07007267
7268 IWL_DEBUG_MAC80211("enter\n");
7269
7270 /* we should be verifying the device is ready to be opened */
7271 mutex_lock(&priv->mutex);
7272
7273 priv->is_open = 1;
7274
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007275 if (!iwl4965_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07007276 ieee80211_start_queues(priv->hw);
7277
7278 mutex_unlock(&priv->mutex);
7279 IWL_DEBUG_MAC80211("leave\n");
7280 return 0;
7281}
7282
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007283static void iwl4965_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07007284{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007285 struct iwl4965_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07007286
7287 IWL_DEBUG_MAC80211("enter\n");
Mohamed Abbas948c1712007-10-25 17:15:45 +08007288
7289
7290 mutex_lock(&priv->mutex);
7291 /* stop mac, cancel any scan request and clear
7292 * RXON_FILTER_ASSOC_MSK BIT
7293 */
Zhu Yib481de92007-09-25 17:54:57 -07007294 priv->is_open = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007295 iwl4965_scan_cancel_timeout(priv, 100);
Mohamed Abbas948c1712007-10-25 17:15:45 +08007296 cancel_delayed_work(&priv->post_associate);
7297 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007298 iwl4965_commit_rxon(priv);
Mohamed Abbas948c1712007-10-25 17:15:45 +08007299 mutex_unlock(&priv->mutex);
7300
Zhu Yib481de92007-09-25 17:54:57 -07007301 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07007302}
7303
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007304static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
Zhu Yib481de92007-09-25 17:54:57 -07007305 struct ieee80211_tx_control *ctl)
7306{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007307 struct iwl4965_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07007308
7309 IWL_DEBUG_MAC80211("enter\n");
7310
7311 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
7312 IWL_DEBUG_MAC80211("leave - monitor\n");
7313 return -1;
7314 }
7315
7316 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
7317 ctl->tx_rate);
7318
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007319 if (iwl4965_tx_skb(priv, skb, ctl))
Zhu Yib481de92007-09-25 17:54:57 -07007320 dev_kfree_skb_any(skb);
7321
7322 IWL_DEBUG_MAC80211("leave\n");
7323 return 0;
7324}
7325
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007326static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07007327 struct ieee80211_if_init_conf *conf)
7328{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007329 struct iwl4965_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07007330 unsigned long flags;
Joe Perches0795af52007-10-03 17:59:30 -07007331 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07007332
7333 IWL_DEBUG_MAC80211("enter: id %d, type %d\n", conf->if_id, conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07007334
7335 if (priv->interface_id) {
7336 IWL_DEBUG_MAC80211("leave - interface_id != 0\n");
7337 return 0;
7338 }
7339
7340 spin_lock_irqsave(&priv->lock, flags);
7341 priv->interface_id = conf->if_id;
7342
7343 spin_unlock_irqrestore(&priv->lock, flags);
7344
7345 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02007346
7347 if (conf->mac_addr) {
7348 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr));
7349 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
7350 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007351 iwl4965_set_mode(priv, conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07007352
7353 IWL_DEBUG_MAC80211("leave\n");
7354 mutex_unlock(&priv->mutex);
7355
7356 return 0;
7357}
7358
7359/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007360 * iwl4965_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07007361 *
7362 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
7363 * be set inappropriately and the driver currently sets the hardware up to
7364 * use it whenever needed.
7365 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007366static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07007367{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007368 struct iwl4965_priv *priv = hw->priv;
7369 const struct iwl4965_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07007370 unsigned long flags;
7371
7372 mutex_lock(&priv->mutex);
7373 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel);
7374
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007375 if (!iwl4965_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07007376 IWL_DEBUG_MAC80211("leave - not ready\n");
7377 mutex_unlock(&priv->mutex);
7378 return -EIO;
7379 }
7380
7381 /* TODO: Figure out how to get ieee80211_local->sta_scanning w/ only
Ian Schram01ebd062007-10-25 17:15:22 +08007382 * what is exposed through include/ declarations */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007383 if (unlikely(!iwl4965_param_disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07007384 test_bit(STATUS_SCANNING, &priv->status))) {
7385 IWL_DEBUG_MAC80211("leave - scanning\n");
7386 mutex_unlock(&priv->mutex);
7387 return 0;
7388 }
7389
7390 spin_lock_irqsave(&priv->lock, flags);
7391
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007392 ch_info = iwl4965_get_channel_info(priv, conf->phymode, conf->channel);
Zhu Yib481de92007-09-25 17:54:57 -07007393 if (!is_channel_valid(ch_info)) {
7394 IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n",
7395 conf->channel, conf->phymode);
7396 IWL_DEBUG_MAC80211("leave - invalid channel\n");
7397 spin_unlock_irqrestore(&priv->lock, flags);
7398 mutex_unlock(&priv->mutex);
7399 return -EINVAL;
7400 }
7401
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007402#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -07007403 /* if we are switching fron ht to 2.4 clear flags
7404 * from any ht related info since 2.4 does not
7405 * support ht */
7406 if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel)
7407#ifdef IEEE80211_CONF_CHANNEL_SWITCH
7408 && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
7409#endif
7410 )
7411 priv->staging_rxon.flags = 0;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007412#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07007413
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007414 iwl4965_set_rxon_channel(priv, conf->phymode, conf->channel);
Zhu Yib481de92007-09-25 17:54:57 -07007415
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007416 iwl4965_set_flags_for_phymode(priv, conf->phymode);
Zhu Yib481de92007-09-25 17:54:57 -07007417
7418 /* The list of supported rates and rate mask can be different
7419 * for each phymode; since the phymode may have changed, reset
7420 * the rate mask to what mac80211 lists */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007421 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007422
7423 spin_unlock_irqrestore(&priv->lock, flags);
7424
7425#ifdef IEEE80211_CONF_CHANNEL_SWITCH
7426 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007427 iwl4965_hw_channel_switch(priv, conf->channel);
Zhu Yib481de92007-09-25 17:54:57 -07007428 mutex_unlock(&priv->mutex);
7429 return 0;
7430 }
7431#endif
7432
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007433 iwl4965_radio_kill_sw(priv, !conf->radio_enabled);
Zhu Yib481de92007-09-25 17:54:57 -07007434
7435 if (!conf->radio_enabled) {
7436 IWL_DEBUG_MAC80211("leave - radio disabled\n");
7437 mutex_unlock(&priv->mutex);
7438 return 0;
7439 }
7440
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007441 if (iwl4965_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07007442 IWL_DEBUG_MAC80211("leave - RF kill\n");
7443 mutex_unlock(&priv->mutex);
7444 return -EIO;
7445 }
7446
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007447 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007448
7449 if (memcmp(&priv->active_rxon,
7450 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007451 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007452 else
7453 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
7454
7455 IWL_DEBUG_MAC80211("leave\n");
7456
7457 mutex_unlock(&priv->mutex);
7458
7459 return 0;
7460}
7461
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007462static void iwl4965_config_ap(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07007463{
7464 int rc = 0;
7465
7466 if (priv->status & STATUS_EXIT_PENDING)
7467 return;
7468
7469 /* The following should be done only at AP bring up */
7470 if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) {
7471
7472 /* RXON - unassoc (to set timing command) */
7473 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007474 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007475
7476 /* RXON Timing */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007477 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
7478 iwl4965_setup_rxon_timing(priv);
7479 rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07007480 sizeof(priv->rxon_timing), &priv->rxon_timing);
7481 if (rc)
7482 IWL_WARNING("REPLY_RXON_TIMING failed - "
7483 "Attempting to continue.\n");
7484
7485 iwl4965_set_rxon_chain(priv);
7486
7487 /* FIXME: what should be the assoc_id for AP? */
7488 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
7489 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7490 priv->staging_rxon.flags |=
7491 RXON_FLG_SHORT_PREAMBLE_MSK;
7492 else
7493 priv->staging_rxon.flags &=
7494 ~RXON_FLG_SHORT_PREAMBLE_MSK;
7495
7496 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
7497 if (priv->assoc_capability &
7498 WLAN_CAPABILITY_SHORT_SLOT_TIME)
7499 priv->staging_rxon.flags |=
7500 RXON_FLG_SHORT_SLOT_MSK;
7501 else
7502 priv->staging_rxon.flags &=
7503 ~RXON_FLG_SHORT_SLOT_MSK;
7504
7505 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
7506 priv->staging_rxon.flags &=
7507 ~RXON_FLG_SHORT_SLOT_MSK;
7508 }
7509 /* restore RXON assoc */
7510 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007511 iwl4965_commit_rxon(priv);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007512#ifdef CONFIG_IWL4965_QOS
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007513 iwl4965_activate_qos(priv, 1);
Zhu Yib481de92007-09-25 17:54:57 -07007514#endif
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007515 iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0);
Zhu Yie1493de2007-09-27 11:27:32 +08007516 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007517 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007518
7519 /* FIXME - we need to add code here to detect a totally new
7520 * configuration, reset the AP, unassoc, rxon timing, assoc,
7521 * clear sta table, add BCAST sta... */
7522}
7523
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007524static int iwl4965_mac_config_interface(struct ieee80211_hw *hw, int if_id,
Zhu Yib481de92007-09-25 17:54:57 -07007525 struct ieee80211_if_conf *conf)
7526{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007527 struct iwl4965_priv *priv = hw->priv;
Joe Perches0795af52007-10-03 17:59:30 -07007528 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07007529 unsigned long flags;
7530 int rc;
7531
7532 if (conf == NULL)
7533 return -EIO;
7534
7535 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
7536 (!conf->beacon || !conf->ssid_len)) {
7537 IWL_DEBUG_MAC80211
7538 ("Leaving in AP mode because HostAPD is not ready.\n");
7539 return 0;
7540 }
7541
7542 mutex_lock(&priv->mutex);
7543
7544 IWL_DEBUG_MAC80211("enter: interface id %d\n", if_id);
7545 if (conf->bssid)
Joe Perches0795af52007-10-03 17:59:30 -07007546 IWL_DEBUG_MAC80211("bssid: %s\n",
7547 print_mac(mac, conf->bssid));
Zhu Yib481de92007-09-25 17:54:57 -07007548
Johannes Berg4150c572007-09-17 01:29:23 -04007549/*
7550 * very dubious code was here; the probe filtering flag is never set:
7551 *
Zhu Yib481de92007-09-25 17:54:57 -07007552 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
7553 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04007554 */
7555 if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
Zhu Yib481de92007-09-25 17:54:57 -07007556 IWL_DEBUG_MAC80211("leave - scanning\n");
7557 mutex_unlock(&priv->mutex);
7558 return 0;
7559 }
7560
7561 if (priv->interface_id != if_id) {
7562 IWL_DEBUG_MAC80211("leave - interface_id != if_id\n");
7563 mutex_unlock(&priv->mutex);
7564 return 0;
7565 }
7566
7567 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
7568 if (!conf->bssid) {
7569 conf->bssid = priv->mac_addr;
7570 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Joe Perches0795af52007-10-03 17:59:30 -07007571 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
7572 print_mac(mac, conf->bssid));
Zhu Yib481de92007-09-25 17:54:57 -07007573 }
7574 if (priv->ibss_beacon)
7575 dev_kfree_skb(priv->ibss_beacon);
7576
7577 priv->ibss_beacon = conf->beacon;
7578 }
7579
7580 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
7581 !is_multicast_ether_addr(conf->bssid)) {
7582 /* If there is currently a HW scan going on in the background
7583 * then we need to cancel it else the RXON below will fail. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007584 if (iwl4965_scan_cancel_timeout(priv, 100)) {
Zhu Yib481de92007-09-25 17:54:57 -07007585 IWL_WARNING("Aborted scan still in progress "
7586 "after 100ms\n");
7587 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
7588 mutex_unlock(&priv->mutex);
7589 return -EAGAIN;
7590 }
7591 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
7592
7593 /* TODO: Audit driver for usage of these members and see
7594 * if mac80211 deprecates them (priv->bssid looks like it
7595 * shouldn't be there, but I haven't scanned the IBSS code
7596 * to verify) - jpk */
7597 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
7598
7599 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007600 iwl4965_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007601 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007602 rc = iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007603 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007604 iwl4965_rxon_add_station(
Zhu Yib481de92007-09-25 17:54:57 -07007605 priv, priv->active_rxon.bssid_addr, 1);
7606 }
7607
7608 } else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007609 iwl4965_scan_cancel_timeout(priv, 100);
Zhu Yib481de92007-09-25 17:54:57 -07007610 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007611 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007612 }
7613
7614 spin_lock_irqsave(&priv->lock, flags);
7615 if (!conf->ssid_len)
7616 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
7617 else
7618 memcpy(priv->essid, conf->ssid, conf->ssid_len);
7619
7620 priv->essid_len = conf->ssid_len;
7621 spin_unlock_irqrestore(&priv->lock, flags);
7622
7623 IWL_DEBUG_MAC80211("leave\n");
7624 mutex_unlock(&priv->mutex);
7625
7626 return 0;
7627}
7628
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007629static void iwl4965_configure_filter(struct ieee80211_hw *hw,
Johannes Berg4150c572007-09-17 01:29:23 -04007630 unsigned int changed_flags,
7631 unsigned int *total_flags,
7632 int mc_count, struct dev_addr_list *mc_list)
7633{
7634 /*
7635 * XXX: dummy
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007636 * see also iwl4965_connection_init_rx_config
Johannes Berg4150c572007-09-17 01:29:23 -04007637 */
7638 *total_flags = 0;
7639}
7640
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007641static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07007642 struct ieee80211_if_init_conf *conf)
7643{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007644 struct iwl4965_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07007645
7646 IWL_DEBUG_MAC80211("enter\n");
7647
7648 mutex_lock(&priv->mutex);
Mohamed Abbas948c1712007-10-25 17:15:45 +08007649
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007650 iwl4965_scan_cancel_timeout(priv, 100);
Mohamed Abbas948c1712007-10-25 17:15:45 +08007651 cancel_delayed_work(&priv->post_associate);
7652 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007653 iwl4965_commit_rxon(priv);
Mohamed Abbas948c1712007-10-25 17:15:45 +08007654
Zhu Yib481de92007-09-25 17:54:57 -07007655 if (priv->interface_id == conf->if_id) {
7656 priv->interface_id = 0;
7657 memset(priv->bssid, 0, ETH_ALEN);
7658 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
7659 priv->essid_len = 0;
7660 }
7661 mutex_unlock(&priv->mutex);
7662
7663 IWL_DEBUG_MAC80211("leave\n");
7664
7665}
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007666static void iwl4965_mac_erp_ie_changed(struct ieee80211_hw *hw,
Tomas Winkler220173b2007-10-16 00:50:25 +02007667 u8 changes, int cts_protection, int preamble)
7668{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007669 struct iwl4965_priv *priv = hw->priv;
Tomas Winkler220173b2007-10-16 00:50:25 +02007670
7671 if (changes & IEEE80211_ERP_CHANGE_PREAMBLE) {
7672 if (preamble == WLAN_ERP_PREAMBLE_SHORT)
7673 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
7674 else
7675 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
7676 }
7677
7678 if (changes & IEEE80211_ERP_CHANGE_PROTECTION) {
7679 if (cts_protection)
7680 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
7681 else
7682 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
7683 }
7684
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007685 if (iwl4965_is_associated(priv))
7686 iwl4965_send_rxon_assoc(priv);
Tomas Winkler220173b2007-10-16 00:50:25 +02007687}
Zhu Yib481de92007-09-25 17:54:57 -07007688
7689#define IWL_DELAY_NEXT_SCAN (HZ*2)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007690static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
Zhu Yib481de92007-09-25 17:54:57 -07007691{
7692 int rc = 0;
7693 unsigned long flags;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007694 struct iwl4965_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07007695
7696 IWL_DEBUG_MAC80211("enter\n");
7697
mabbas052c4b92007-10-25 17:15:43 +08007698 mutex_lock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07007699 spin_lock_irqsave(&priv->lock, flags);
7700
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007701 if (!iwl4965_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07007702 rc = -EIO;
7703 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
7704 goto out_unlock;
7705 }
7706
7707 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */
7708 rc = -EIO;
7709 IWL_ERROR("ERROR: APs don't scan\n");
7710 goto out_unlock;
7711 }
7712
7713 /* if we just finished scan ask for delay */
7714 if (priv->last_scan_jiffies &&
7715 time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN,
7716 jiffies)) {
7717 rc = -EAGAIN;
7718 goto out_unlock;
7719 }
7720 if (len) {
7721 IWL_DEBUG_SCAN("direct scan for "
7722 "%s [%d]\n ",
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007723 iwl4965_escape_essid(ssid, len), (int)len);
Zhu Yib481de92007-09-25 17:54:57 -07007724
7725 priv->one_direct_scan = 1;
7726 priv->direct_ssid_len = (u8)
7727 min((u8) len, (u8) IW_ESSID_MAX_SIZE);
7728 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
Mohamed Abbas948c1712007-10-25 17:15:45 +08007729 } else
7730 priv->one_direct_scan = 0;
Zhu Yib481de92007-09-25 17:54:57 -07007731
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007732 rc = iwl4965_scan_initiate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007733
7734 IWL_DEBUG_MAC80211("leave\n");
7735
7736out_unlock:
7737 spin_unlock_irqrestore(&priv->lock, flags);
mabbas052c4b92007-10-25 17:15:43 +08007738 mutex_unlock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07007739
7740 return rc;
7741}
7742
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007743static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Zhu Yib481de92007-09-25 17:54:57 -07007744 const u8 *local_addr, const u8 *addr,
7745 struct ieee80211_key_conf *key)
7746{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007747 struct iwl4965_priv *priv = hw->priv;
Joe Perches0795af52007-10-03 17:59:30 -07007748 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07007749 int rc = 0;
7750 u8 sta_id;
7751
7752 IWL_DEBUG_MAC80211("enter\n");
7753
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007754 if (!iwl4965_param_hwcrypto) {
Zhu Yib481de92007-09-25 17:54:57 -07007755 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
7756 return -EOPNOTSUPP;
7757 }
7758
7759 if (is_zero_ether_addr(addr))
7760 /* only support pairwise keys */
7761 return -EOPNOTSUPP;
7762
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007763 sta_id = iwl4965_hw_find_station(priv, addr);
Zhu Yib481de92007-09-25 17:54:57 -07007764 if (sta_id == IWL_INVALID_STATION) {
Joe Perches0795af52007-10-03 17:59:30 -07007765 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
7766 print_mac(mac, addr));
Zhu Yib481de92007-09-25 17:54:57 -07007767 return -EINVAL;
7768 }
7769
7770 mutex_lock(&priv->mutex);
7771
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007772 iwl4965_scan_cancel_timeout(priv, 100);
mabbas052c4b92007-10-25 17:15:43 +08007773
Zhu Yib481de92007-09-25 17:54:57 -07007774 switch (cmd) {
7775 case SET_KEY:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007776 rc = iwl4965_update_sta_key_info(priv, key, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07007777 if (!rc) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007778 iwl4965_set_rxon_hwcrypto(priv, 1);
7779 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007780 key->hw_key_idx = sta_id;
7781 IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n");
7782 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
7783 }
7784 break;
7785 case DISABLE_KEY:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007786 rc = iwl4965_clear_sta_key_info(priv, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07007787 if (!rc) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007788 iwl4965_set_rxon_hwcrypto(priv, 0);
7789 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007790 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
7791 }
7792 break;
7793 default:
7794 rc = -EINVAL;
7795 }
7796
7797 IWL_DEBUG_MAC80211("leave\n");
7798 mutex_unlock(&priv->mutex);
7799
7800 return rc;
7801}
7802
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007803static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, int queue,
Zhu Yib481de92007-09-25 17:54:57 -07007804 const struct ieee80211_tx_queue_params *params)
7805{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007806 struct iwl4965_priv *priv = hw->priv;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007807#ifdef CONFIG_IWL4965_QOS
Zhu Yib481de92007-09-25 17:54:57 -07007808 unsigned long flags;
7809 int q;
7810#endif /* CONFIG_IWL_QOS */
7811
7812 IWL_DEBUG_MAC80211("enter\n");
7813
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007814 if (!iwl4965_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07007815 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7816 return -EIO;
7817 }
7818
7819 if (queue >= AC_NUM) {
7820 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
7821 return 0;
7822 }
7823
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007824#ifdef CONFIG_IWL4965_QOS
Zhu Yib481de92007-09-25 17:54:57 -07007825 if (!priv->qos_data.qos_enable) {
7826 priv->qos_data.qos_active = 0;
7827 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
7828 return 0;
7829 }
7830 q = AC_NUM - 1 - queue;
7831
7832 spin_lock_irqsave(&priv->lock, flags);
7833
7834 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
7835 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
7836 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
7837 priv->qos_data.def_qos_parm.ac[q].edca_txop =
7838 cpu_to_le16((params->burst_time * 100));
7839
7840 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
7841 priv->qos_data.qos_active = 1;
7842
7843 spin_unlock_irqrestore(&priv->lock, flags);
7844
7845 mutex_lock(&priv->mutex);
7846 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007847 iwl4965_activate_qos(priv, 1);
7848 else if (priv->assoc_id && iwl4965_is_associated(priv))
7849 iwl4965_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07007850
7851 mutex_unlock(&priv->mutex);
7852
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007853#endif /*CONFIG_IWL4965_QOS */
Zhu Yib481de92007-09-25 17:54:57 -07007854
7855 IWL_DEBUG_MAC80211("leave\n");
7856 return 0;
7857}
7858
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007859static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07007860 struct ieee80211_tx_queue_stats *stats)
7861{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007862 struct iwl4965_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07007863 int i, avail;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007864 struct iwl4965_tx_queue *txq;
7865 struct iwl4965_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07007866 unsigned long flags;
7867
7868 IWL_DEBUG_MAC80211("enter\n");
7869
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007870 if (!iwl4965_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07007871 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7872 return -EIO;
7873 }
7874
7875 spin_lock_irqsave(&priv->lock, flags);
7876
7877 for (i = 0; i < AC_NUM; i++) {
7878 txq = &priv->txq[i];
7879 q = &txq->q;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007880 avail = iwl4965_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07007881
7882 stats->data[i].len = q->n_window - avail;
7883 stats->data[i].limit = q->n_window - q->high_mark;
7884 stats->data[i].count = q->n_window;
7885
7886 }
7887 spin_unlock_irqrestore(&priv->lock, flags);
7888
7889 IWL_DEBUG_MAC80211("leave\n");
7890
7891 return 0;
7892}
7893
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007894static int iwl4965_mac_get_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07007895 struct ieee80211_low_level_stats *stats)
7896{
7897 IWL_DEBUG_MAC80211("enter\n");
7898 IWL_DEBUG_MAC80211("leave\n");
7899
7900 return 0;
7901}
7902
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007903static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07007904{
7905 IWL_DEBUG_MAC80211("enter\n");
7906 IWL_DEBUG_MAC80211("leave\n");
7907
7908 return 0;
7909}
7910
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007911static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07007912{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007913 struct iwl4965_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07007914 unsigned long flags;
7915
7916 mutex_lock(&priv->mutex);
7917 IWL_DEBUG_MAC80211("enter\n");
7918
7919 priv->lq_mngr.lq_ready = 0;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007920#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -07007921 spin_lock_irqsave(&priv->lock, flags);
7922 memset(&priv->current_assoc_ht, 0, sizeof(struct sta_ht_info));
7923 spin_unlock_irqrestore(&priv->lock, flags);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007924#ifdef CONFIG_IWL4965_HT_AGG
Zhu Yib481de92007-09-25 17:54:57 -07007925/* if (priv->lq_mngr.agg_ctrl.granted_ba)
7926 iwl4965_turn_off_agg(priv, TID_ALL_SPECIFIED);*/
7927
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007928 memset(&(priv->lq_mngr.agg_ctrl), 0, sizeof(struct iwl4965_agg_control));
Zhu Yib481de92007-09-25 17:54:57 -07007929 priv->lq_mngr.agg_ctrl.tid_traffic_load_threshold = 10;
7930 priv->lq_mngr.agg_ctrl.ba_timeout = 5000;
7931 priv->lq_mngr.agg_ctrl.auto_agg = 1;
7932
7933 if (priv->lq_mngr.agg_ctrl.auto_agg)
7934 priv->lq_mngr.agg_ctrl.requested_ba = TID_ALL_ENABLED;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007935#endif /*CONFIG_IWL4965_HT_AGG */
7936#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07007937
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007938#ifdef CONFIG_IWL4965_QOS
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007939 iwl4965_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007940#endif
7941
7942 cancel_delayed_work(&priv->post_associate);
7943
7944 spin_lock_irqsave(&priv->lock, flags);
7945 priv->assoc_id = 0;
7946 priv->assoc_capability = 0;
7947 priv->call_post_assoc_from_beacon = 0;
7948 priv->assoc_station_added = 0;
7949
7950 /* new association get rid of ibss beacon skb */
7951 if (priv->ibss_beacon)
7952 dev_kfree_skb(priv->ibss_beacon);
7953
7954 priv->ibss_beacon = NULL;
7955
7956 priv->beacon_int = priv->hw->conf.beacon_int;
7957 priv->timestamp1 = 0;
7958 priv->timestamp0 = 0;
7959 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
7960 priv->beacon_int = 0;
7961
7962 spin_unlock_irqrestore(&priv->lock, flags);
7963
mabbas052c4b92007-10-25 17:15:43 +08007964 /* we are restarting association process
7965 * clear RXON_FILTER_ASSOC_MSK bit
7966 */
7967 if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007968 iwl4965_scan_cancel_timeout(priv, 100);
mabbas052c4b92007-10-25 17:15:43 +08007969 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007970 iwl4965_commit_rxon(priv);
mabbas052c4b92007-10-25 17:15:43 +08007971 }
7972
Zhu Yib481de92007-09-25 17:54:57 -07007973 /* Per mac80211.h: This is only used in IBSS mode... */
7974 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
mabbas052c4b92007-10-25 17:15:43 +08007975
Zhu Yib481de92007-09-25 17:54:57 -07007976 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
7977 mutex_unlock(&priv->mutex);
7978 return;
7979 }
7980
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007981 if (!iwl4965_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07007982 IWL_DEBUG_MAC80211("leave - not ready\n");
7983 mutex_unlock(&priv->mutex);
7984 return;
7985 }
7986
7987 priv->only_active_channel = 0;
7988
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007989 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007990
7991 mutex_unlock(&priv->mutex);
7992
7993 IWL_DEBUG_MAC80211("leave\n");
7994
7995}
7996
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007997static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb,
Zhu Yib481de92007-09-25 17:54:57 -07007998 struct ieee80211_tx_control *control)
7999{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008000 struct iwl4965_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07008001 unsigned long flags;
8002
8003 mutex_lock(&priv->mutex);
8004 IWL_DEBUG_MAC80211("enter\n");
8005
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008006 if (!iwl4965_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07008007 IWL_DEBUG_MAC80211("leave - RF not ready\n");
8008 mutex_unlock(&priv->mutex);
8009 return -EIO;
8010 }
8011
8012 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
8013 IWL_DEBUG_MAC80211("leave - not IBSS\n");
8014 mutex_unlock(&priv->mutex);
8015 return -EIO;
8016 }
8017
8018 spin_lock_irqsave(&priv->lock, flags);
8019
8020 if (priv->ibss_beacon)
8021 dev_kfree_skb(priv->ibss_beacon);
8022
8023 priv->ibss_beacon = skb;
8024
8025 priv->assoc_id = 0;
8026
8027 IWL_DEBUG_MAC80211("leave\n");
8028 spin_unlock_irqrestore(&priv->lock, flags);
8029
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008030#ifdef CONFIG_IWL4965_QOS
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008031 iwl4965_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008032#endif
8033
8034 queue_work(priv->workqueue, &priv->post_associate.work);
8035
8036 mutex_unlock(&priv->mutex);
8037
8038 return 0;
8039}
8040
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008041#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -07008042union ht_cap_info {
8043 struct {
8044 u16 advanced_coding_cap :1;
8045 u16 supported_chan_width_set :1;
8046 u16 mimo_power_save_mode :2;
8047 u16 green_field :1;
8048 u16 short_GI20 :1;
8049 u16 short_GI40 :1;
8050 u16 tx_stbc :1;
8051 u16 rx_stbc :1;
8052 u16 beam_forming :1;
8053 u16 delayed_ba :1;
8054 u16 maximal_amsdu_size :1;
8055 u16 cck_mode_at_40MHz :1;
8056 u16 psmp_support :1;
8057 u16 stbc_ctrl_frame_support :1;
8058 u16 sig_txop_protection_support :1;
8059 };
8060 u16 val;
8061} __attribute__ ((packed));
8062
8063union ht_param_info{
8064 struct {
8065 u8 max_rx_ampdu_factor :2;
8066 u8 mpdu_density :3;
8067 u8 reserved :3;
8068 };
8069 u8 val;
8070} __attribute__ ((packed));
8071
8072union ht_exra_param_info {
8073 struct {
8074 u8 ext_chan_offset :2;
8075 u8 tx_chan_width :1;
8076 u8 rifs_mode :1;
8077 u8 controlled_access_only :1;
8078 u8 service_interval_granularity :3;
8079 };
8080 u8 val;
8081} __attribute__ ((packed));
8082
8083union ht_operation_mode{
8084 struct {
8085 u16 op_mode :2;
8086 u16 non_GF :1;
8087 u16 reserved :13;
8088 };
8089 u16 val;
8090} __attribute__ ((packed));
8091
8092
8093static int sta_ht_info_init(struct ieee80211_ht_capability *ht_cap,
8094 struct ieee80211_ht_additional_info *ht_extra,
8095 struct sta_ht_info *ht_info_ap,
8096 struct sta_ht_info *ht_info)
8097{
8098 union ht_cap_info cap;
8099 union ht_operation_mode op_mode;
8100 union ht_param_info param_info;
8101 union ht_exra_param_info extra_param_info;
8102
8103 IWL_DEBUG_MAC80211("enter: \n");
8104
8105 if (!ht_info) {
8106 IWL_DEBUG_MAC80211("leave: ht_info is NULL\n");
8107 return -1;
8108 }
8109
8110 if (ht_cap) {
8111 cap.val = (u16) le16_to_cpu(ht_cap->capabilities_info);
8112 param_info.val = ht_cap->mac_ht_params_info;
8113 ht_info->is_ht = 1;
8114 if (cap.short_GI20)
8115 ht_info->sgf |= 0x1;
8116 if (cap.short_GI40)
8117 ht_info->sgf |= 0x2;
8118 ht_info->is_green_field = cap.green_field;
8119 ht_info->max_amsdu_size = cap.maximal_amsdu_size;
8120 ht_info->supported_chan_width = cap.supported_chan_width_set;
8121 ht_info->tx_mimo_ps_mode = cap.mimo_power_save_mode;
8122 memcpy(ht_info->supp_rates, ht_cap->supported_mcs_set, 16);
8123
8124 ht_info->ampdu_factor = param_info.max_rx_ampdu_factor;
8125 ht_info->mpdu_density = param_info.mpdu_density;
8126
8127 IWL_DEBUG_MAC80211("SISO mask 0x%X MIMO mask 0x%X \n",
8128 ht_cap->supported_mcs_set[0],
8129 ht_cap->supported_mcs_set[1]);
8130
8131 if (ht_info_ap) {
8132 ht_info->control_channel = ht_info_ap->control_channel;
8133 ht_info->extension_chan_offset =
8134 ht_info_ap->extension_chan_offset;
8135 ht_info->tx_chan_width = ht_info_ap->tx_chan_width;
8136 ht_info->operating_mode = ht_info_ap->operating_mode;
8137 }
8138
8139 if (ht_extra) {
8140 extra_param_info.val = ht_extra->ht_param;
8141 ht_info->control_channel = ht_extra->control_chan;
8142 ht_info->extension_chan_offset =
8143 extra_param_info.ext_chan_offset;
8144 ht_info->tx_chan_width = extra_param_info.tx_chan_width;
8145 op_mode.val = (u16)
8146 le16_to_cpu(ht_extra->operation_mode);
8147 ht_info->operating_mode = op_mode.op_mode;
8148 IWL_DEBUG_MAC80211("control channel %d\n",
8149 ht_extra->control_chan);
8150 }
8151 } else
8152 ht_info->is_ht = 0;
8153
8154 IWL_DEBUG_MAC80211("leave\n");
8155 return 0;
8156}
8157
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008158static int iwl4965_mac_conf_ht(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07008159 struct ieee80211_ht_capability *ht_cap,
8160 struct ieee80211_ht_additional_info *ht_extra)
8161{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008162 struct iwl4965_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07008163 int rs;
8164
8165 IWL_DEBUG_MAC80211("enter: \n");
8166
8167 rs = sta_ht_info_init(ht_cap, ht_extra, NULL, &priv->current_assoc_ht);
8168 iwl4965_set_rxon_chain(priv);
8169
8170 if (priv && priv->assoc_id &&
8171 (priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
8172 unsigned long flags;
8173
8174 spin_lock_irqsave(&priv->lock, flags);
8175 if (priv->beacon_int)
8176 queue_work(priv->workqueue, &priv->post_associate.work);
8177 else
8178 priv->call_post_assoc_from_beacon = 1;
8179 spin_unlock_irqrestore(&priv->lock, flags);
8180 }
8181
8182 IWL_DEBUG_MAC80211("leave: control channel %d\n",
8183 ht_extra->control_chan);
8184 return rs;
8185
8186}
8187
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008188static void iwl4965_set_ht_capab(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07008189 struct ieee80211_ht_capability *ht_cap,
8190 u8 use_wide_chan)
8191{
8192 union ht_cap_info cap;
8193 union ht_param_info param_info;
8194
8195 memset(&cap, 0, sizeof(union ht_cap_info));
8196 memset(&param_info, 0, sizeof(union ht_param_info));
8197
8198 cap.maximal_amsdu_size = HT_IE_MAX_AMSDU_SIZE_4K;
8199 cap.green_field = 1;
8200 cap.short_GI20 = 1;
8201 cap.short_GI40 = 1;
8202 cap.supported_chan_width_set = use_wide_chan;
8203 cap.mimo_power_save_mode = 0x3;
8204
8205 param_info.max_rx_ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
8206 param_info.mpdu_density = CFG_HT_MPDU_DENSITY_DEF;
8207 ht_cap->capabilities_info = (__le16) cpu_to_le16(cap.val);
8208 ht_cap->mac_ht_params_info = (u8) param_info.val;
8209
8210 ht_cap->supported_mcs_set[0] = 0xff;
8211 ht_cap->supported_mcs_set[1] = 0xff;
8212 ht_cap->supported_mcs_set[4] =
8213 (cap.supported_chan_width_set) ? 0x1: 0x0;
8214}
8215
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008216static void iwl4965_mac_get_ht_capab(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07008217 struct ieee80211_ht_capability *ht_cap)
8218{
8219 u8 use_wide_channel = 1;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008220 struct iwl4965_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07008221
8222 IWL_DEBUG_MAC80211("enter: \n");
8223 if (priv->channel_width != IWL_CHANNEL_WIDTH_40MHZ)
8224 use_wide_channel = 0;
8225
8226 /* no fat tx allowed on 2.4GHZ */
8227 if (priv->phymode != MODE_IEEE80211A)
8228 use_wide_channel = 0;
8229
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008230 iwl4965_set_ht_capab(hw, ht_cap, use_wide_channel);
Zhu Yib481de92007-09-25 17:54:57 -07008231 IWL_DEBUG_MAC80211("leave: \n");
8232}
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008233#endif /*CONFIG_IWL4965_HT*/
Zhu Yib481de92007-09-25 17:54:57 -07008234
8235/*****************************************************************************
8236 *
8237 * sysfs attributes
8238 *
8239 *****************************************************************************/
8240
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008241#ifdef CONFIG_IWL4965_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07008242
8243/*
8244 * The following adds a new attribute to the sysfs representation
8245 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
8246 * used for controlling the debug level.
8247 *
8248 * See the level definitions in iwl for details.
8249 */
8250
8251static ssize_t show_debug_level(struct device_driver *d, char *buf)
8252{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008253 return sprintf(buf, "0x%08X\n", iwl4965_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07008254}
8255static ssize_t store_debug_level(struct device_driver *d,
8256 const char *buf, size_t count)
8257{
8258 char *p = (char *)buf;
8259 u32 val;
8260
8261 val = simple_strtoul(p, &p, 0);
8262 if (p == buf)
8263 printk(KERN_INFO DRV_NAME
8264 ": %s is not in hex or decimal form.\n", buf);
8265 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008266 iwl4965_debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07008267
8268 return strnlen(buf, count);
8269}
8270
8271static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
8272 show_debug_level, store_debug_level);
8273
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008274#endif /* CONFIG_IWL4965_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07008275
8276static ssize_t show_rf_kill(struct device *d,
8277 struct device_attribute *attr, char *buf)
8278{
8279 /*
8280 * 0 - RF kill not enabled
8281 * 1 - SW based RF kill active (sysfs)
8282 * 2 - HW based RF kill active
8283 * 3 - Both HW and SW based RF kill active
8284 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008285 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07008286 int val = (test_bit(STATUS_RF_KILL_SW, &priv->status) ? 0x1 : 0x0) |
8287 (test_bit(STATUS_RF_KILL_HW, &priv->status) ? 0x2 : 0x0);
8288
8289 return sprintf(buf, "%i\n", val);
8290}
8291
8292static ssize_t store_rf_kill(struct device *d,
8293 struct device_attribute *attr,
8294 const char *buf, size_t count)
8295{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008296 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07008297
8298 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008299 iwl4965_radio_kill_sw(priv, buf[0] == '1');
Zhu Yib481de92007-09-25 17:54:57 -07008300 mutex_unlock(&priv->mutex);
8301
8302 return count;
8303}
8304
8305static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
8306
8307static ssize_t show_temperature(struct device *d,
8308 struct device_attribute *attr, char *buf)
8309{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008310 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07008311
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008312 if (!iwl4965_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07008313 return -EAGAIN;
8314
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008315 return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07008316}
8317
8318static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
8319
8320static ssize_t show_rs_window(struct device *d,
8321 struct device_attribute *attr,
8322 char *buf)
8323{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008324 struct iwl4965_priv *priv = d->driver_data;
8325 return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07008326}
8327static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
8328
8329static ssize_t show_tx_power(struct device *d,
8330 struct device_attribute *attr, char *buf)
8331{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008332 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07008333 return sprintf(buf, "%d\n", priv->user_txpower_limit);
8334}
8335
8336static ssize_t store_tx_power(struct device *d,
8337 struct device_attribute *attr,
8338 const char *buf, size_t count)
8339{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008340 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07008341 char *p = (char *)buf;
8342 u32 val;
8343
8344 val = simple_strtoul(p, &p, 10);
8345 if (p == buf)
8346 printk(KERN_INFO DRV_NAME
8347 ": %s is not in decimal form.\n", buf);
8348 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008349 iwl4965_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07008350
8351 return count;
8352}
8353
8354static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
8355
8356static ssize_t show_flags(struct device *d,
8357 struct device_attribute *attr, char *buf)
8358{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008359 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07008360
8361 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
8362}
8363
8364static ssize_t store_flags(struct device *d,
8365 struct device_attribute *attr,
8366 const char *buf, size_t count)
8367{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008368 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07008369 u32 flags = simple_strtoul(buf, NULL, 0);
8370
8371 mutex_lock(&priv->mutex);
8372 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
8373 /* Cancel any currently running scans... */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008374 if (iwl4965_scan_cancel_timeout(priv, 100))
Zhu Yib481de92007-09-25 17:54:57 -07008375 IWL_WARNING("Could not cancel scan.\n");
8376 else {
8377 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
8378 flags);
8379 priv->staging_rxon.flags = cpu_to_le32(flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008380 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008381 }
8382 }
8383 mutex_unlock(&priv->mutex);
8384
8385 return count;
8386}
8387
8388static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
8389
8390static ssize_t show_filter_flags(struct device *d,
8391 struct device_attribute *attr, char *buf)
8392{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008393 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07008394
8395 return sprintf(buf, "0x%04X\n",
8396 le32_to_cpu(priv->active_rxon.filter_flags));
8397}
8398
8399static ssize_t store_filter_flags(struct device *d,
8400 struct device_attribute *attr,
8401 const char *buf, size_t count)
8402{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008403 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07008404 u32 filter_flags = simple_strtoul(buf, NULL, 0);
8405
8406 mutex_lock(&priv->mutex);
8407 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
8408 /* Cancel any currently running scans... */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008409 if (iwl4965_scan_cancel_timeout(priv, 100))
Zhu Yib481de92007-09-25 17:54:57 -07008410 IWL_WARNING("Could not cancel scan.\n");
8411 else {
8412 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
8413 "0x%04X\n", filter_flags);
8414 priv->staging_rxon.filter_flags =
8415 cpu_to_le32(filter_flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008416 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008417 }
8418 }
8419 mutex_unlock(&priv->mutex);
8420
8421 return count;
8422}
8423
8424static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
8425 store_filter_flags);
8426
8427static ssize_t show_tune(struct device *d,
8428 struct device_attribute *attr, char *buf)
8429{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008430 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07008431
8432 return sprintf(buf, "0x%04X\n",
8433 (priv->phymode << 8) |
8434 le16_to_cpu(priv->active_rxon.channel));
8435}
8436
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008437static void iwl4965_set_flags_for_phymode(struct iwl4965_priv *priv, u8 phymode);
Zhu Yib481de92007-09-25 17:54:57 -07008438
8439static ssize_t store_tune(struct device *d,
8440 struct device_attribute *attr,
8441 const char *buf, size_t count)
8442{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008443 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07008444 char *p = (char *)buf;
8445 u16 tune = simple_strtoul(p, &p, 0);
8446 u8 phymode = (tune >> 8) & 0xff;
8447 u16 channel = tune & 0xff;
8448
8449 IWL_DEBUG_INFO("Tune request to:%d channel:%d\n", phymode, channel);
8450
8451 mutex_lock(&priv->mutex);
8452 if ((le16_to_cpu(priv->staging_rxon.channel) != channel) ||
8453 (priv->phymode != phymode)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008454 const struct iwl4965_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07008455
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008456 ch_info = iwl4965_get_channel_info(priv, phymode, channel);
Zhu Yib481de92007-09-25 17:54:57 -07008457 if (!ch_info) {
8458 IWL_WARNING("Requested invalid phymode/channel "
8459 "combination: %d %d\n", phymode, channel);
8460 mutex_unlock(&priv->mutex);
8461 return -EINVAL;
8462 }
8463
8464 /* Cancel any currently running scans... */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008465 if (iwl4965_scan_cancel_timeout(priv, 100))
Zhu Yib481de92007-09-25 17:54:57 -07008466 IWL_WARNING("Could not cancel scan.\n");
8467 else {
8468 IWL_DEBUG_INFO("Committing phymode and "
8469 "rxon.channel = %d %d\n",
8470 phymode, channel);
8471
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008472 iwl4965_set_rxon_channel(priv, phymode, channel);
8473 iwl4965_set_flags_for_phymode(priv, phymode);
Zhu Yib481de92007-09-25 17:54:57 -07008474
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008475 iwl4965_set_rate(priv);
8476 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008477 }
8478 }
8479 mutex_unlock(&priv->mutex);
8480
8481 return count;
8482}
8483
8484static DEVICE_ATTR(tune, S_IWUSR | S_IRUGO, show_tune, store_tune);
8485
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008486#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07008487
8488static ssize_t show_measurement(struct device *d,
8489 struct device_attribute *attr, char *buf)
8490{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008491 struct iwl4965_priv *priv = dev_get_drvdata(d);
8492 struct iwl4965_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07008493 u32 size = sizeof(measure_report), len = 0, ofs = 0;
8494 u8 *data = (u8 *) & measure_report;
8495 unsigned long flags;
8496
8497 spin_lock_irqsave(&priv->lock, flags);
8498 if (!(priv->measurement_status & MEASUREMENT_READY)) {
8499 spin_unlock_irqrestore(&priv->lock, flags);
8500 return 0;
8501 }
8502 memcpy(&measure_report, &priv->measure_report, size);
8503 priv->measurement_status = 0;
8504 spin_unlock_irqrestore(&priv->lock, flags);
8505
8506 while (size && (PAGE_SIZE - len)) {
8507 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
8508 PAGE_SIZE - len, 1);
8509 len = strlen(buf);
8510 if (PAGE_SIZE - len)
8511 buf[len++] = '\n';
8512
8513 ofs += 16;
8514 size -= min(size, 16U);
8515 }
8516
8517 return len;
8518}
8519
8520static ssize_t store_measurement(struct device *d,
8521 struct device_attribute *attr,
8522 const char *buf, size_t count)
8523{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008524 struct iwl4965_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07008525 struct ieee80211_measurement_params params = {
8526 .channel = le16_to_cpu(priv->active_rxon.channel),
8527 .start_time = cpu_to_le64(priv->last_tsf),
8528 .duration = cpu_to_le16(1),
8529 };
8530 u8 type = IWL_MEASURE_BASIC;
8531 u8 buffer[32];
8532 u8 channel;
8533
8534 if (count) {
8535 char *p = buffer;
8536 strncpy(buffer, buf, min(sizeof(buffer), count));
8537 channel = simple_strtoul(p, NULL, 0);
8538 if (channel)
8539 params.channel = channel;
8540
8541 p = buffer;
8542 while (*p && *p != ' ')
8543 p++;
8544 if (*p)
8545 type = simple_strtoul(p + 1, NULL, 0);
8546 }
8547
8548 IWL_DEBUG_INFO("Invoking measurement of type %d on "
8549 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008550 iwl4965_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07008551
8552 return count;
8553}
8554
8555static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
8556 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008557#endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07008558
8559static ssize_t store_retry_rate(struct device *d,
8560 struct device_attribute *attr,
8561 const char *buf, size_t count)
8562{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008563 struct iwl4965_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07008564
8565 priv->retry_rate = simple_strtoul(buf, NULL, 0);
8566 if (priv->retry_rate <= 0)
8567 priv->retry_rate = 1;
8568
8569 return count;
8570}
8571
8572static ssize_t show_retry_rate(struct device *d,
8573 struct device_attribute *attr, char *buf)
8574{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008575 struct iwl4965_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07008576 return sprintf(buf, "%d", priv->retry_rate);
8577}
8578
8579static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
8580 store_retry_rate);
8581
8582static ssize_t store_power_level(struct device *d,
8583 struct device_attribute *attr,
8584 const char *buf, size_t count)
8585{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008586 struct iwl4965_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07008587 int rc;
8588 int mode;
8589
8590 mode = simple_strtoul(buf, NULL, 0);
8591 mutex_lock(&priv->mutex);
8592
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008593 if (!iwl4965_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07008594 rc = -EAGAIN;
8595 goto out;
8596 }
8597
8598 if ((mode < 1) || (mode > IWL_POWER_LIMIT) || (mode == IWL_POWER_AC))
8599 mode = IWL_POWER_AC;
8600 else
8601 mode |= IWL_POWER_ENABLED;
8602
8603 if (mode != priv->power_mode) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008604 rc = iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(mode));
Zhu Yib481de92007-09-25 17:54:57 -07008605 if (rc) {
8606 IWL_DEBUG_MAC80211("failed setting power mode.\n");
8607 goto out;
8608 }
8609 priv->power_mode = mode;
8610 }
8611
8612 rc = count;
8613
8614 out:
8615 mutex_unlock(&priv->mutex);
8616 return rc;
8617}
8618
8619#define MAX_WX_STRING 80
8620
8621/* Values are in microsecond */
8622static const s32 timeout_duration[] = {
8623 350000,
8624 250000,
8625 75000,
8626 37000,
8627 25000,
8628};
8629static const s32 period_duration[] = {
8630 400000,
8631 700000,
8632 1000000,
8633 1000000,
8634 1000000
8635};
8636
8637static ssize_t show_power_level(struct device *d,
8638 struct device_attribute *attr, char *buf)
8639{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008640 struct iwl4965_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07008641 int level = IWL_POWER_LEVEL(priv->power_mode);
8642 char *p = buf;
8643
8644 p += sprintf(p, "%d ", level);
8645 switch (level) {
8646 case IWL_POWER_MODE_CAM:
8647 case IWL_POWER_AC:
8648 p += sprintf(p, "(AC)");
8649 break;
8650 case IWL_POWER_BATTERY:
8651 p += sprintf(p, "(BATTERY)");
8652 break;
8653 default:
8654 p += sprintf(p,
8655 "(Timeout %dms, Period %dms)",
8656 timeout_duration[level - 1] / 1000,
8657 period_duration[level - 1] / 1000);
8658 }
8659
8660 if (!(priv->power_mode & IWL_POWER_ENABLED))
8661 p += sprintf(p, " OFF\n");
8662 else
8663 p += sprintf(p, " \n");
8664
8665 return (p - buf + 1);
8666
8667}
8668
8669static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
8670 store_power_level);
8671
8672static ssize_t show_channels(struct device *d,
8673 struct device_attribute *attr, char *buf)
8674{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008675 struct iwl4965_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07008676 int len = 0, i;
8677 struct ieee80211_channel *channels = NULL;
8678 const struct ieee80211_hw_mode *hw_mode = NULL;
8679 int count = 0;
8680
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008681 if (!iwl4965_is_ready(priv))
Zhu Yib481de92007-09-25 17:54:57 -07008682 return -EAGAIN;
8683
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008684 hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211G);
Zhu Yib481de92007-09-25 17:54:57 -07008685 if (!hw_mode)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008686 hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211B);
Zhu Yib481de92007-09-25 17:54:57 -07008687 if (hw_mode) {
8688 channels = hw_mode->channels;
8689 count = hw_mode->num_channels;
8690 }
8691
8692 len +=
8693 sprintf(&buf[len],
8694 "Displaying %d channels in 2.4GHz band "
8695 "(802.11bg):\n", count);
8696
8697 for (i = 0; i < count; i++)
8698 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
8699 channels[i].chan,
8700 channels[i].power_level,
8701 channels[i].
8702 flag & IEEE80211_CHAN_W_RADAR_DETECT ?
8703 " (IEEE 802.11h required)" : "",
8704 (!(channels[i].flag & IEEE80211_CHAN_W_IBSS)
8705 || (channels[i].
8706 flag &
8707 IEEE80211_CHAN_W_RADAR_DETECT)) ? "" :
8708 ", IBSS",
8709 channels[i].
8710 flag & IEEE80211_CHAN_W_ACTIVE_SCAN ?
8711 "active/passive" : "passive only");
8712
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008713 hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211A);
Zhu Yib481de92007-09-25 17:54:57 -07008714 if (hw_mode) {
8715 channels = hw_mode->channels;
8716 count = hw_mode->num_channels;
8717 } else {
8718 channels = NULL;
8719 count = 0;
8720 }
8721
8722 len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band "
8723 "(802.11a):\n", count);
8724
8725 for (i = 0; i < count; i++)
8726 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
8727 channels[i].chan,
8728 channels[i].power_level,
8729 channels[i].
8730 flag & IEEE80211_CHAN_W_RADAR_DETECT ?
8731 " (IEEE 802.11h required)" : "",
8732 (!(channels[i].flag & IEEE80211_CHAN_W_IBSS)
8733 || (channels[i].
8734 flag &
8735 IEEE80211_CHAN_W_RADAR_DETECT)) ? "" :
8736 ", IBSS",
8737 channels[i].
8738 flag & IEEE80211_CHAN_W_ACTIVE_SCAN ?
8739 "active/passive" : "passive only");
8740
8741 return len;
8742}
8743
8744static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
8745
8746static ssize_t show_statistics(struct device *d,
8747 struct device_attribute *attr, char *buf)
8748{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008749 struct iwl4965_priv *priv = dev_get_drvdata(d);
8750 u32 size = sizeof(struct iwl4965_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07008751 u32 len = 0, ofs = 0;
8752 u8 *data = (u8 *) & priv->statistics;
8753 int rc = 0;
8754
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008755 if (!iwl4965_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07008756 return -EAGAIN;
8757
8758 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008759 rc = iwl4965_send_statistics_request(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008760 mutex_unlock(&priv->mutex);
8761
8762 if (rc) {
8763 len = sprintf(buf,
8764 "Error sending statistics request: 0x%08X\n", rc);
8765 return len;
8766 }
8767
8768 while (size && (PAGE_SIZE - len)) {
8769 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
8770 PAGE_SIZE - len, 1);
8771 len = strlen(buf);
8772 if (PAGE_SIZE - len)
8773 buf[len++] = '\n';
8774
8775 ofs += 16;
8776 size -= min(size, 16U);
8777 }
8778
8779 return len;
8780}
8781
8782static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
8783
8784static ssize_t show_antenna(struct device *d,
8785 struct device_attribute *attr, char *buf)
8786{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008787 struct iwl4965_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07008788
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008789 if (!iwl4965_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07008790 return -EAGAIN;
8791
8792 return sprintf(buf, "%d\n", priv->antenna);
8793}
8794
8795static ssize_t store_antenna(struct device *d,
8796 struct device_attribute *attr,
8797 const char *buf, size_t count)
8798{
8799 int ant;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008800 struct iwl4965_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07008801
8802 if (count == 0)
8803 return 0;
8804
8805 if (sscanf(buf, "%1i", &ant) != 1) {
8806 IWL_DEBUG_INFO("not in hex or decimal form.\n");
8807 return count;
8808 }
8809
8810 if ((ant >= 0) && (ant <= 2)) {
8811 IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008812 priv->antenna = (enum iwl4965_antenna)ant;
Zhu Yib481de92007-09-25 17:54:57 -07008813 } else
8814 IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant);
8815
8816
8817 return count;
8818}
8819
8820static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
8821
8822static ssize_t show_status(struct device *d,
8823 struct device_attribute *attr, char *buf)
8824{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008825 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8826 if (!iwl4965_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07008827 return -EAGAIN;
8828 return sprintf(buf, "0x%08x\n", (int)priv->status);
8829}
8830
8831static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
8832
8833static ssize_t dump_error_log(struct device *d,
8834 struct device_attribute *attr,
8835 const char *buf, size_t count)
8836{
8837 char *p = (char *)buf;
8838
8839 if (p[0] == '1')
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008840 iwl4965_dump_nic_error_log((struct iwl4965_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07008841
8842 return strnlen(buf, count);
8843}
8844
8845static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
8846
8847static ssize_t dump_event_log(struct device *d,
8848 struct device_attribute *attr,
8849 const char *buf, size_t count)
8850{
8851 char *p = (char *)buf;
8852
8853 if (p[0] == '1')
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008854 iwl4965_dump_nic_event_log((struct iwl4965_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07008855
8856 return strnlen(buf, count);
8857}
8858
8859static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
8860
8861/*****************************************************************************
8862 *
8863 * driver setup and teardown
8864 *
8865 *****************************************************************************/
8866
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008867static void iwl4965_setup_deferred_work(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07008868{
8869 priv->workqueue = create_workqueue(DRV_NAME);
8870
8871 init_waitqueue_head(&priv->wait_command_queue);
8872
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008873 INIT_WORK(&priv->up, iwl4965_bg_up);
8874 INIT_WORK(&priv->restart, iwl4965_bg_restart);
8875 INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish);
8876 INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed);
8877 INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan);
8878 INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan);
8879 INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill);
8880 INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update);
8881 INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate);
8882 INIT_DELAYED_WORK(&priv->init_alive_start, iwl4965_bg_init_alive_start);
8883 INIT_DELAYED_WORK(&priv->alive_start, iwl4965_bg_alive_start);
8884 INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check);
Zhu Yib481de92007-09-25 17:54:57 -07008885
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008886 iwl4965_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008887
8888 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008889 iwl4965_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07008890}
8891
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008892static void iwl4965_cancel_deferred_work(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07008893{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008894 iwl4965_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008895
Joonwoo Park3ae6a052007-11-29 10:43:16 +09008896 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07008897 cancel_delayed_work(&priv->scan_check);
8898 cancel_delayed_work(&priv->alive_start);
8899 cancel_delayed_work(&priv->post_associate);
8900 cancel_work_sync(&priv->beacon_update);
8901}
8902
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008903static struct attribute *iwl4965_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07008904 &dev_attr_antenna.attr,
8905 &dev_attr_channels.attr,
8906 &dev_attr_dump_errors.attr,
8907 &dev_attr_dump_events.attr,
8908 &dev_attr_flags.attr,
8909 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008910#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07008911 &dev_attr_measurement.attr,
8912#endif
8913 &dev_attr_power_level.attr,
8914 &dev_attr_retry_rate.attr,
8915 &dev_attr_rf_kill.attr,
8916 &dev_attr_rs_window.attr,
8917 &dev_attr_statistics.attr,
8918 &dev_attr_status.attr,
8919 &dev_attr_temperature.attr,
8920 &dev_attr_tune.attr,
8921 &dev_attr_tx_power.attr,
8922
8923 NULL
8924};
8925
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008926static struct attribute_group iwl4965_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07008927 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008928 .attrs = iwl4965_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07008929};
8930
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008931static struct ieee80211_ops iwl4965_hw_ops = {
8932 .tx = iwl4965_mac_tx,
8933 .start = iwl4965_mac_start,
8934 .stop = iwl4965_mac_stop,
8935 .add_interface = iwl4965_mac_add_interface,
8936 .remove_interface = iwl4965_mac_remove_interface,
8937 .config = iwl4965_mac_config,
8938 .config_interface = iwl4965_mac_config_interface,
8939 .configure_filter = iwl4965_configure_filter,
8940 .set_key = iwl4965_mac_set_key,
8941 .get_stats = iwl4965_mac_get_stats,
8942 .get_tx_stats = iwl4965_mac_get_tx_stats,
8943 .conf_tx = iwl4965_mac_conf_tx,
8944 .get_tsf = iwl4965_mac_get_tsf,
8945 .reset_tsf = iwl4965_mac_reset_tsf,
8946 .beacon_update = iwl4965_mac_beacon_update,
8947 .erp_ie_changed = iwl4965_mac_erp_ie_changed,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008948#ifdef CONFIG_IWL4965_HT
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008949 .conf_ht = iwl4965_mac_conf_ht,
8950 .get_ht_capab = iwl4965_mac_get_ht_capab,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008951#ifdef CONFIG_IWL4965_HT_AGG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008952 .ht_tx_agg_start = iwl4965_mac_ht_tx_agg_start,
8953 .ht_tx_agg_stop = iwl4965_mac_ht_tx_agg_stop,
8954 .ht_rx_agg_start = iwl4965_mac_ht_rx_agg_start,
8955 .ht_rx_agg_stop = iwl4965_mac_ht_rx_agg_stop,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008956#endif /* CONFIG_IWL4965_HT_AGG */
8957#endif /* CONFIG_IWL4965_HT */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008958 .hw_scan = iwl4965_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07008959};
8960
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008961static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07008962{
8963 int err = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008964 struct iwl4965_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07008965 struct ieee80211_hw *hw;
8966 int i;
8967
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008968 if (iwl4965_param_disable_hw_scan) {
Zhu Yib481de92007-09-25 17:54:57 -07008969 IWL_DEBUG_INFO("Disabling hw_scan\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008970 iwl4965_hw_ops.hw_scan = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07008971 }
8972
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008973 if ((iwl4965_param_queues_num > IWL_MAX_NUM_QUEUES) ||
8974 (iwl4965_param_queues_num < IWL_MIN_NUM_QUEUES)) {
Zhu Yib481de92007-09-25 17:54:57 -07008975 IWL_ERROR("invalid queues_num, should be between %d and %d\n",
8976 IWL_MIN_NUM_QUEUES, IWL_MAX_NUM_QUEUES);
8977 err = -EINVAL;
8978 goto out;
8979 }
8980
8981 /* mac80211 allocates memory for this device instance, including
8982 * space for this driver's private structure */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008983 hw = ieee80211_alloc_hw(sizeof(struct iwl4965_priv), &iwl4965_hw_ops);
Zhu Yib481de92007-09-25 17:54:57 -07008984 if (hw == NULL) {
8985 IWL_ERROR("Can not allocate network device\n");
8986 err = -ENOMEM;
8987 goto out;
8988 }
8989 SET_IEEE80211_DEV(hw, &pdev->dev);
8990
Johannes Bergf51359a2007-10-28 14:53:36 +01008991 hw->rate_control_algorithm = "iwl-4965-rs";
8992
Zhu Yib481de92007-09-25 17:54:57 -07008993 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
8994 priv = hw->priv;
8995 priv->hw = hw;
8996
8997 priv->pci_dev = pdev;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008998 priv->antenna = (enum iwl4965_antenna)iwl4965_param_antenna;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008999#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009000 iwl4965_debug_level = iwl4965_param_debug;
Zhu Yib481de92007-09-25 17:54:57 -07009001 atomic_set(&priv->restrict_refcnt, 0);
9002#endif
9003 priv->retry_rate = 1;
9004
9005 priv->ibss_beacon = NULL;
9006
9007 /* Tell mac80211 and its clients (e.g. Wireless Extensions)
9008 * the range of signal quality values that we'll provide.
9009 * Negative values for level/noise indicate that we'll provide dBm.
9010 * For WE, at least, non-0 values here *enable* display of values
9011 * in app (iwconfig). */
9012 hw->max_rssi = -20; /* signal level, negative indicates dBm */
9013 hw->max_noise = -20; /* noise level, negative indicates dBm */
9014 hw->max_signal = 100; /* link quality indication (%) */
9015
9016 /* Tell mac80211 our Tx characteristics */
9017 hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE;
9018
9019 hw->queues = 4;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08009020#ifdef CONFIG_IWL4965_HT
9021#ifdef CONFIG_IWL4965_HT_AGG
Zhu Yib481de92007-09-25 17:54:57 -07009022 hw->queues = 16;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08009023#endif /* CONFIG_IWL4965_HT_AGG */
9024#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07009025
9026 spin_lock_init(&priv->lock);
9027 spin_lock_init(&priv->power_data.lock);
9028 spin_lock_init(&priv->sta_lock);
9029 spin_lock_init(&priv->hcmd_lock);
9030 spin_lock_init(&priv->lq_mngr.lock);
9031
9032 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++)
9033 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
9034
9035 INIT_LIST_HEAD(&priv->free_frames);
9036
9037 mutex_init(&priv->mutex);
9038 if (pci_enable_device(pdev)) {
9039 err = -ENODEV;
9040 goto out_ieee80211_free_hw;
9041 }
9042
9043 pci_set_master(pdev);
9044
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009045 iwl4965_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009046
9047 priv->data_retry_limit = -1;
9048 priv->ieee_channels = NULL;
9049 priv->ieee_rates = NULL;
9050 priv->phymode = -1;
9051
9052 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
9053 if (!err)
9054 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
9055 if (err) {
9056 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
9057 goto out_pci_disable_device;
9058 }
9059
9060 pci_set_drvdata(pdev, priv);
9061 err = pci_request_regions(pdev, DRV_NAME);
9062 if (err)
9063 goto out_pci_disable_device;
9064 /* We disable the RETRY_TIMEOUT register (0x41) to keep
9065 * PCI Tx retries from interfering with C3 CPU state */
9066 pci_write_config_byte(pdev, 0x41, 0x00);
9067 priv->hw_base = pci_iomap(pdev, 0, 0);
9068 if (!priv->hw_base) {
9069 err = -ENODEV;
9070 goto out_pci_release_regions;
9071 }
9072
9073 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
9074 (unsigned long long) pci_resource_len(pdev, 0));
9075 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
9076
9077 /* Initialize module parameter values here */
9078
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009079 if (iwl4965_param_disable) {
Zhu Yib481de92007-09-25 17:54:57 -07009080 set_bit(STATUS_RF_KILL_SW, &priv->status);
9081 IWL_DEBUG_INFO("Radio disabled.\n");
9082 }
9083
9084 priv->iw_mode = IEEE80211_IF_TYPE_STA;
9085
9086 priv->ps_mode = 0;
9087 priv->use_ant_b_for_management_frame = 1; /* start with ant B */
9088 priv->is_ht_enabled = 1;
9089 priv->channel_width = IWL_CHANNEL_WIDTH_40MHZ;
9090 priv->valid_antenna = 0x7; /* assume all 3 connected */
9091 priv->ps_mode = IWL_MIMO_PS_NONE;
Zhu Yib481de92007-09-25 17:54:57 -07009092
9093 iwl4965_set_rxon_chain(priv);
9094
9095 printk(KERN_INFO DRV_NAME
9096 ": Detected Intel Wireless WiFi Link 4965AGN\n");
9097
9098 /* Device-specific setup */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009099 if (iwl4965_hw_set_hw_setting(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07009100 IWL_ERROR("failed to set hw settings\n");
9101 mutex_unlock(&priv->mutex);
9102 goto out_iounmap;
9103 }
9104
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08009105#ifdef CONFIG_IWL4965_QOS
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009106 if (iwl4965_param_qos_enable)
Zhu Yib481de92007-09-25 17:54:57 -07009107 priv->qos_data.qos_enable = 1;
9108
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009109 iwl4965_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009110
9111 priv->qos_data.qos_active = 0;
9112 priv->qos_data.qos_cap.val = 0;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08009113#endif /* CONFIG_IWL4965_QOS */
Zhu Yib481de92007-09-25 17:54:57 -07009114
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009115 iwl4965_set_rxon_channel(priv, MODE_IEEE80211G, 6);
9116 iwl4965_setup_deferred_work(priv);
9117 iwl4965_setup_rx_handlers(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009118
9119 priv->rates_mask = IWL_RATES_MASK;
9120 /* If power management is turned on, default to AC mode */
9121 priv->power_mode = IWL_POWER_AC;
9122 priv->user_txpower_limit = IWL_DEFAULT_TX_POWER;
9123
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009124 iwl4965_disable_interrupts(priv);
Jes Sorensen49df2b32007-10-26 16:10:39 +02009125
Zhu Yib481de92007-09-25 17:54:57 -07009126 pci_enable_msi(pdev);
9127
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009128 err = request_irq(pdev->irq, iwl4965_isr, IRQF_SHARED, DRV_NAME, priv);
Zhu Yib481de92007-09-25 17:54:57 -07009129 if (err) {
9130 IWL_ERROR("Error allocating IRQ %d\n", pdev->irq);
9131 goto out_disable_msi;
9132 }
9133
9134 mutex_lock(&priv->mutex);
9135
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009136 err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07009137 if (err) {
9138 IWL_ERROR("failed to create sysfs device attributes\n");
9139 mutex_unlock(&priv->mutex);
9140 goto out_release_irq;
9141 }
9142
9143 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
9144 * ucode filename and max sizes are card-specific. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009145 err = iwl4965_read_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009146 if (err) {
9147 IWL_ERROR("Could not read microcode: %d\n", err);
9148 mutex_unlock(&priv->mutex);
9149 goto out_pci_alloc;
9150 }
9151
9152 mutex_unlock(&priv->mutex);
9153
Ian Schram01ebd062007-10-25 17:15:22 +08009154 IWL_DEBUG_INFO("Queueing UP work.\n");
Zhu Yib481de92007-09-25 17:54:57 -07009155
9156 queue_work(priv->workqueue, &priv->up);
9157
9158 return 0;
9159
9160 out_pci_alloc:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009161 iwl4965_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009162
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009163 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07009164
9165 out_release_irq:
9166 free_irq(pdev->irq, priv);
9167
9168 out_disable_msi:
9169 pci_disable_msi(pdev);
9170 destroy_workqueue(priv->workqueue);
9171 priv->workqueue = NULL;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009172 iwl4965_unset_hw_setting(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009173
9174 out_iounmap:
9175 pci_iounmap(pdev, priv->hw_base);
9176 out_pci_release_regions:
9177 pci_release_regions(pdev);
9178 out_pci_disable_device:
9179 pci_disable_device(pdev);
9180 pci_set_drvdata(pdev, NULL);
9181 out_ieee80211_free_hw:
9182 ieee80211_free_hw(priv->hw);
9183 out:
9184 return err;
9185}
9186
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009187static void iwl4965_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07009188{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009189 struct iwl4965_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07009190 struct list_head *p, *q;
9191 int i;
9192
9193 if (!priv)
9194 return;
9195
9196 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
9197
Zhu Yib481de92007-09-25 17:54:57 -07009198 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08009199
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009200 iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009201
9202 /* Free MAC hash list for ADHOC */
9203 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
9204 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
9205 list_del(p);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009206 kfree(list_entry(p, struct iwl4965_ibss_seq, list));
Zhu Yib481de92007-09-25 17:54:57 -07009207 }
9208 }
9209
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009210 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07009211
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009212 iwl4965_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009213
9214 if (priv->rxq.bd)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009215 iwl4965_rx_queue_free(priv, &priv->rxq);
9216 iwl4965_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009217
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009218 iwl4965_unset_hw_setting(priv);
9219 iwl4965_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009220
9221 if (priv->mac80211_registered) {
9222 ieee80211_unregister_hw(priv->hw);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009223 iwl4965_rate_control_unregister(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07009224 }
9225
Mohamed Abbas948c1712007-10-25 17:15:45 +08009226 /*netif_stop_queue(dev); */
9227 flush_workqueue(priv->workqueue);
9228
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009229 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07009230 * priv->workqueue... so we can't take down the workqueue
9231 * until now... */
9232 destroy_workqueue(priv->workqueue);
9233 priv->workqueue = NULL;
9234
9235 free_irq(pdev->irq, priv);
9236 pci_disable_msi(pdev);
9237 pci_iounmap(pdev, priv->hw_base);
9238 pci_release_regions(pdev);
9239 pci_disable_device(pdev);
9240 pci_set_drvdata(pdev, NULL);
9241
9242 kfree(priv->channel_info);
9243
9244 kfree(priv->ieee_channels);
9245 kfree(priv->ieee_rates);
9246
9247 if (priv->ibss_beacon)
9248 dev_kfree_skb(priv->ibss_beacon);
9249
9250 ieee80211_free_hw(priv->hw);
9251}
9252
9253#ifdef CONFIG_PM
9254
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009255static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07009256{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009257 struct iwl4965_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07009258
Zhu Yib481de92007-09-25 17:54:57 -07009259 set_bit(STATUS_IN_SUSPEND, &priv->status);
9260
9261 /* Take down the device; powers it off, etc. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009262 iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009263
9264 if (priv->mac80211_registered)
9265 ieee80211_stop_queues(priv->hw);
9266
9267 pci_save_state(pdev);
9268 pci_disable_device(pdev);
9269 pci_set_power_state(pdev, PCI_D3hot);
9270
Zhu Yib481de92007-09-25 17:54:57 -07009271 return 0;
9272}
9273
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009274static void iwl4965_resume(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07009275{
9276 unsigned long flags;
9277
9278 /* The following it a temporary work around due to the
9279 * suspend / resume not fully initializing the NIC correctly.
9280 * Without all of the following, resume will not attempt to take
9281 * down the NIC (it shouldn't really need to) and will just try
9282 * and bring the NIC back up. However that fails during the
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009283 * ucode verification process. This then causes iwl4965_down to be
9284 * called *after* iwl4965_hw_nic_init() has succeeded -- which
Zhu Yib481de92007-09-25 17:54:57 -07009285 * then lets the next init sequence succeed. So, we've
9286 * replicated all of that NIC init code here... */
9287
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009288 iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07009289
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009290 iwl4965_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009291
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009292 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
9293 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07009294 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009295 iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF);
9296 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
9297 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07009298
9299 /* tell the device to stop sending interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009300 iwl4965_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009301
9302 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009303 iwl4965_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07009304
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009305 if (!iwl4965_grab_nic_access(priv)) {
9306 iwl4965_write_prph(priv, APMG_CLK_DIS_REG,
Tomas Winklerac17a942007-10-25 17:15:37 +08009307 APMG_CLK_VAL_DMA_CLK_RQT);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009308 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009309 }
9310 spin_unlock_irqrestore(&priv->lock, flags);
9311
9312 udelay(5);
9313
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009314 iwl4965_hw_nic_reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009315
9316 /* Bring the device back up */
9317 clear_bit(STATUS_IN_SUSPEND, &priv->status);
9318 queue_work(priv->workqueue, &priv->up);
9319}
9320
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009321static int iwl4965_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07009322{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009323 struct iwl4965_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07009324 int err;
9325
9326 printk(KERN_INFO "Coming out of suspend...\n");
9327
Zhu Yib481de92007-09-25 17:54:57 -07009328 pci_set_power_state(pdev, PCI_D0);
9329 err = pci_enable_device(pdev);
9330 pci_restore_state(pdev);
9331
9332 /*
9333 * Suspend/Resume resets the PCI configuration space, so we have to
9334 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
9335 * from interfering with C3 CPU state. pci_restore_state won't help
9336 * here since it only restores the first 64 bytes pci config header.
9337 */
9338 pci_write_config_byte(pdev, 0x41, 0x00);
9339
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009340 iwl4965_resume(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009341
9342 return 0;
9343}
9344
9345#endif /* CONFIG_PM */
9346
9347/*****************************************************************************
9348 *
9349 * driver and module entry point
9350 *
9351 *****************************************************************************/
9352
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009353static struct pci_driver iwl4965_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07009354 .name = DRV_NAME,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009355 .id_table = iwl4965_hw_card_ids,
9356 .probe = iwl4965_pci_probe,
9357 .remove = __devexit_p(iwl4965_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07009358#ifdef CONFIG_PM
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009359 .suspend = iwl4965_pci_suspend,
9360 .resume = iwl4965_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07009361#endif
9362};
9363
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009364static int __init iwl4965_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07009365{
9366
9367 int ret;
9368 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
9369 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009370 ret = pci_register_driver(&iwl4965_driver);
Zhu Yib481de92007-09-25 17:54:57 -07009371 if (ret) {
9372 IWL_ERROR("Unable to initialize PCI module\n");
9373 return ret;
9374 }
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08009375#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009376 ret = driver_create_file(&iwl4965_driver.driver, &driver_attr_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07009377 if (ret) {
9378 IWL_ERROR("Unable to create driver sysfs file\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009379 pci_unregister_driver(&iwl4965_driver);
Zhu Yib481de92007-09-25 17:54:57 -07009380 return ret;
9381 }
9382#endif
9383
9384 return ret;
9385}
9386
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009387static void __exit iwl4965_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07009388{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08009389#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009390 driver_remove_file(&iwl4965_driver.driver, &driver_attr_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07009391#endif
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009392 pci_unregister_driver(&iwl4965_driver);
Zhu Yib481de92007-09-25 17:54:57 -07009393}
9394
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009395module_param_named(antenna, iwl4965_param_antenna, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07009396MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009397module_param_named(disable, iwl4965_param_disable, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07009398MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009399module_param_named(hwcrypto, iwl4965_param_hwcrypto, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07009400MODULE_PARM_DESC(hwcrypto,
9401 "using hardware crypto engine (default 0 [software])\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009402module_param_named(debug, iwl4965_param_debug, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07009403MODULE_PARM_DESC(debug, "debug output mask");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009404module_param_named(disable_hw_scan, iwl4965_param_disable_hw_scan, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07009405MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
9406
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009407module_param_named(queues_num, iwl4965_param_queues_num, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07009408MODULE_PARM_DESC(queues_num, "number of hw queues.");
9409
9410/* QoS */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009411module_param_named(qos_enable, iwl4965_param_qos_enable, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07009412MODULE_PARM_DESC(qos_enable, "enable all QoS functionality");
9413
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009414module_exit(iwl4965_exit);
9415module_init(iwl4965_init);