blob: 16cb990e06fa542a9eab79db6a41c8cc776e4bdc [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
Zhu Yib481de92007-09-25 17:54:57 -070030#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/version.h>
33#include <linux/init.h>
34#include <linux/pci.h>
35#include <linux/dma-mapping.h>
36#include <linux/delay.h>
37#include <linux/skbuff.h>
38#include <linux/netdevice.h>
39#include <linux/wireless.h>
40#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070041#include <linux/etherdevice.h>
42#include <linux/if_arp.h>
43
Zhu Yib481de92007-09-25 17:54:57 -070044#include <net/mac80211.h>
45
46#include <asm/div64.h>
47
Zhu Yib481de92007-09-25 17:54:57 -070048#include "iwl-4965.h"
49#include "iwl-helpers.h"
50
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080051#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -080052u32 iwl4965_debug_level;
Zhu Yib481de92007-09-25 17:54:57 -070053#endif
54
Christoph Hellwigbb8c0932008-01-27 16:41:47 -080055static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv,
56 struct iwl4965_tx_queue *txq);
Christoph Hellwig416e1432007-10-25 17:15:49 +080057
Zhu Yib481de92007-09-25 17:54:57 -070058/******************************************************************************
59 *
60 * module boiler plate
61 *
62 ******************************************************************************/
63
64/* module parameters */
Cahill, Ben M6440adb2007-11-29 11:09:55 +080065static int iwl4965_param_disable_hw_scan; /* def: 0 = use 4965's h/w scan */
66static int iwl4965_param_debug; /* def: 0 = minimal debug log messages */
Ben Cahill9fbab512007-11-29 11:09:47 +080067static int iwl4965_param_disable; /* def: enable radio */
68static int iwl4965_param_antenna; /* def: 0 = both antennas (use diversity) */
69int iwl4965_param_hwcrypto; /* def: using software encryption */
Cahill, Ben M6440adb2007-11-29 11:09:55 +080070static int iwl4965_param_qos_enable = 1; /* def: 1 = use quality of service */
71int iwl4965_param_queues_num = IWL_MAX_NUM_QUEUES; /* def: 16 Tx queues */
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +020072int iwl4965_param_amsdu_size_8K; /* def: enable 8K amsdu size */
Zhu Yib481de92007-09-25 17:54:57 -070073
74/*
75 * module name, copyright, version, etc.
76 * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
77 */
78
79#define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux"
80
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080081#ifdef CONFIG_IWL4965_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070082#define VD "d"
83#else
84#define VD
85#endif
86
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080087#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070088#define VS "s"
89#else
90#define VS
91#endif
92
Zhu Yi71972662008-01-14 17:46:23 -080093#define IWLWIFI_VERSION "1.2.23k" VD VS
Zhu Yib481de92007-09-25 17:54:57 -070094#define DRV_COPYRIGHT "Copyright(c) 2003-2007 Intel Corporation"
95#define DRV_VERSION IWLWIFI_VERSION
96
97/* Change firmware file name, using "-" and incrementing number,
98 * *only* when uCode interface or architecture changes so that it
99 * is not compatible with earlier drivers.
100 * This number will also appear in << 8 position of 1st dword of uCode file */
101#define IWL4965_UCODE_API "-1"
102
103MODULE_DESCRIPTION(DRV_DESCRIPTION);
104MODULE_VERSION(DRV_VERSION);
105MODULE_AUTHOR(DRV_COPYRIGHT);
106MODULE_LICENSE("GPL");
107
108__le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr)
109{
110 u16 fc = le16_to_cpu(hdr->frame_control);
111 int hdr_len = ieee80211_get_hdrlen(fc);
112
113 if ((fc & 0x00cc) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA))
114 return (__le16 *) ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN);
115 return NULL;
116}
117
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800118static const struct ieee80211_hw_mode *iwl4965_get_hw_mode(
119 struct iwl4965_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700120{
121 int i;
122
123 for (i = 0; i < 3; i++)
124 if (priv->modes[i].mode == mode)
125 return &priv->modes[i];
126
127 return NULL;
128}
129
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800130static int iwl4965_is_empty_essid(const char *essid, int essid_len)
Zhu Yib481de92007-09-25 17:54:57 -0700131{
132 /* Single white space is for Linksys APs */
133 if (essid_len == 1 && essid[0] == ' ')
134 return 1;
135
136 /* Otherwise, if the entire essid is 0, we assume it is hidden */
137 while (essid_len) {
138 essid_len--;
139 if (essid[essid_len] != '\0')
140 return 0;
141 }
142
143 return 1;
144}
145
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800146static const char *iwl4965_escape_essid(const char *essid, u8 essid_len)
Zhu Yib481de92007-09-25 17:54:57 -0700147{
148 static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
149 const char *s = essid;
150 char *d = escaped;
151
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800152 if (iwl4965_is_empty_essid(essid, essid_len)) {
Zhu Yib481de92007-09-25 17:54:57 -0700153 memcpy(escaped, "<hidden>", sizeof("<hidden>"));
154 return escaped;
155 }
156
157 essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE);
158 while (essid_len--) {
159 if (*s == '\0') {
160 *d++ = '\\';
161 *d++ = '0';
162 s++;
163 } else
164 *d++ = *s++;
165 }
166 *d = '\0';
167 return escaped;
168}
169
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800170static void iwl4965_print_hex_dump(int level, void *p, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -0700171{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800172#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800173 if (!(iwl4965_debug_level & level))
Zhu Yib481de92007-09-25 17:54:57 -0700174 return;
175
176 print_hex_dump(KERN_DEBUG, "iwl data: ", DUMP_PREFIX_OFFSET, 16, 1,
177 p, len, 1);
178#endif
179}
180
181/*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
182 * DMA services
183 *
184 * Theory of operation
185 *
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800186 * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
187 * of buffer descriptors, each of which points to one or more data buffers for
188 * the device to read from or fill. Driver and device exchange status of each
189 * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
190 * entries in each circular buffer, to protect against confusing empty and full
191 * queue states.
192 *
193 * The device reads or writes the data in the queues via the device's several
194 * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
Zhu Yib481de92007-09-25 17:54:57 -0700195 *
196 * For Tx queue, there are low mark and high mark limits. If, after queuing
197 * the packet for Tx, free space become < low mark, Tx queue stopped. When
198 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
199 * Tx queue resumed.
200 *
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800201 * The 4965 operates with up to 17 queues: One receive queue, one transmit
202 * queue (#4) for sending commands to the device firmware, and 15 other
203 * Tx queues that may be mapped to prioritized Tx DMA/FIFO channels.
Ben Cahille3851442007-11-29 11:10:07 +0800204 *
205 * See more detailed info in iwl-4965-hw.h.
Zhu Yib481de92007-09-25 17:54:57 -0700206 ***************************************************/
207
Ron Rindjunskyfe01b472008-01-28 14:07:24 +0200208int iwl4965_queue_space(const struct iwl4965_queue *q)
Zhu Yib481de92007-09-25 17:54:57 -0700209{
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800210 int s = q->read_ptr - q->write_ptr;
Zhu Yib481de92007-09-25 17:54:57 -0700211
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800212 if (q->read_ptr > q->write_ptr)
Zhu Yib481de92007-09-25 17:54:57 -0700213 s -= q->n_bd;
214
215 if (s <= 0)
216 s += q->n_window;
217 /* keep some reserve to not confuse empty and full situations */
218 s -= 2;
219 if (s < 0)
220 s = 0;
221 return s;
222}
223
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800224/**
225 * iwl4965_queue_inc_wrap - increment queue index, wrap back to beginning
226 * @index -- current index
227 * @n_bd -- total number of entries in queue (must be power of 2)
228 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800229static inline int iwl4965_queue_inc_wrap(int index, int n_bd)
Zhu Yib481de92007-09-25 17:54:57 -0700230{
231 return ++index & (n_bd - 1);
232}
233
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800234/**
235 * iwl4965_queue_dec_wrap - decrement queue index, wrap back to end
236 * @index -- current index
237 * @n_bd -- total number of entries in queue (must be power of 2)
238 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800239static inline int iwl4965_queue_dec_wrap(int index, int n_bd)
Zhu Yib481de92007-09-25 17:54:57 -0700240{
241 return --index & (n_bd - 1);
242}
243
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800244static inline int x2_queue_used(const struct iwl4965_queue *q, int i)
Zhu Yib481de92007-09-25 17:54:57 -0700245{
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800246 return q->write_ptr > q->read_ptr ?
247 (i >= q->read_ptr && i < q->write_ptr) :
248 !(i < q->read_ptr && i >= q->write_ptr);
Zhu Yib481de92007-09-25 17:54:57 -0700249}
250
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800251static inline u8 get_cmd_index(struct iwl4965_queue *q, u32 index, int is_huge)
Zhu Yib481de92007-09-25 17:54:57 -0700252{
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800253 /* This is for scan command, the big buffer at end of command array */
Zhu Yib481de92007-09-25 17:54:57 -0700254 if (is_huge)
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800255 return q->n_window; /* must be power of 2 */
Zhu Yib481de92007-09-25 17:54:57 -0700256
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800257 /* Otherwise, use normal size buffers */
Zhu Yib481de92007-09-25 17:54:57 -0700258 return index & (q->n_window - 1);
259}
260
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800261/**
262 * iwl4965_queue_init - Initialize queue's high/low-water and read/write indexes
263 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800264static int iwl4965_queue_init(struct iwl4965_priv *priv, struct iwl4965_queue *q,
Zhu Yib481de92007-09-25 17:54:57 -0700265 int count, int slots_num, u32 id)
266{
267 q->n_bd = count;
268 q->n_window = slots_num;
269 q->id = id;
270
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800271 /* count must be power-of-two size, otherwise iwl4965_queue_inc_wrap
272 * and iwl4965_queue_dec_wrap are broken. */
Zhu Yib481de92007-09-25 17:54:57 -0700273 BUG_ON(!is_power_of_2(count));
274
275 /* slots_num must be power-of-two size, otherwise
276 * get_cmd_index is broken. */
277 BUG_ON(!is_power_of_2(slots_num));
278
279 q->low_mark = q->n_window / 4;
280 if (q->low_mark < 4)
281 q->low_mark = 4;
282
283 q->high_mark = q->n_window / 8;
284 if (q->high_mark < 2)
285 q->high_mark = 2;
286
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800287 q->write_ptr = q->read_ptr = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700288
289 return 0;
290}
291
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800292/**
293 * iwl4965_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
294 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800295static int iwl4965_tx_queue_alloc(struct iwl4965_priv *priv,
296 struct iwl4965_tx_queue *txq, u32 id)
Zhu Yib481de92007-09-25 17:54:57 -0700297{
298 struct pci_dev *dev = priv->pci_dev;
299
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800300 /* Driver private data, only for Tx (not command) queues,
301 * not shared with device. */
Zhu Yib481de92007-09-25 17:54:57 -0700302 if (id != IWL_CMD_QUEUE_NUM) {
303 txq->txb = kmalloc(sizeof(txq->txb[0]) *
304 TFD_QUEUE_SIZE_MAX, GFP_KERNEL);
305 if (!txq->txb) {
Ian Schram01ebd062007-10-25 17:15:22 +0800306 IWL_ERROR("kmalloc for auxiliary BD "
Zhu Yib481de92007-09-25 17:54:57 -0700307 "structures failed\n");
308 goto error;
309 }
310 } else
311 txq->txb = NULL;
312
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800313 /* Circular buffer of transmit frame descriptors (TFDs),
314 * shared with device */
Zhu Yib481de92007-09-25 17:54:57 -0700315 txq->bd = pci_alloc_consistent(dev,
316 sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX,
317 &txq->q.dma_addr);
318
319 if (!txq->bd) {
320 IWL_ERROR("pci_alloc_consistent(%zd) failed\n",
321 sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX);
322 goto error;
323 }
324 txq->q.id = id;
325
326 return 0;
327
328 error:
329 if (txq->txb) {
330 kfree(txq->txb);
331 txq->txb = NULL;
332 }
333
334 return -ENOMEM;
335}
336
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800337/**
338 * iwl4965_tx_queue_init - Allocate and initialize one tx/cmd queue
339 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800340int iwl4965_tx_queue_init(struct iwl4965_priv *priv,
341 struct iwl4965_tx_queue *txq, int slots_num, u32 txq_id)
Zhu Yib481de92007-09-25 17:54:57 -0700342{
343 struct pci_dev *dev = priv->pci_dev;
344 int len;
345 int rc = 0;
346
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800347 /*
348 * Alloc buffer array for commands (Tx or other types of commands).
349 * For the command queue (#4), allocate command space + one big
350 * command for scan, since scan command is very huge; the system will
351 * not have two scans at the same time, so only one is needed.
Tomas Winklerbb542442007-12-05 20:59:59 +0200352 * For normal Tx queues (all other queues), no super-size command
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800353 * space is needed.
354 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800355 len = sizeof(struct iwl4965_cmd) * slots_num;
Zhu Yib481de92007-09-25 17:54:57 -0700356 if (txq_id == IWL_CMD_QUEUE_NUM)
357 len += IWL_MAX_SCAN_SIZE;
358 txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd);
359 if (!txq->cmd)
360 return -ENOMEM;
361
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800362 /* Alloc driver data array and TFD circular buffer */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800363 rc = iwl4965_tx_queue_alloc(priv, txq, txq_id);
Zhu Yib481de92007-09-25 17:54:57 -0700364 if (rc) {
365 pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
366
367 return -ENOMEM;
368 }
369 txq->need_update = 0;
370
371 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800372 * iwl4965_queue_inc_wrap and iwl4965_queue_dec_wrap are broken. */
Zhu Yib481de92007-09-25 17:54:57 -0700373 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800374
375 /* Initialize queue's high/low-water marks, and head/tail indexes */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800376 iwl4965_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id);
Zhu Yib481de92007-09-25 17:54:57 -0700377
Cahill, Ben M8b6eaea2007-11-29 11:09:54 +0800378 /* Tell device where to find queue */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800379 iwl4965_hw_tx_queue_init(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -0700380
381 return 0;
382}
383
384/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800385 * iwl4965_tx_queue_free - Deallocate DMA queue.
Zhu Yib481de92007-09-25 17:54:57 -0700386 * @txq: Transmit queue to deallocate.
387 *
388 * Empty queue by removing and destroying all BD's.
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800389 * Free all buffers.
390 * 0-fill, but do not free "txq" descriptor structure.
Zhu Yib481de92007-09-25 17:54:57 -0700391 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800392void iwl4965_tx_queue_free(struct iwl4965_priv *priv, struct iwl4965_tx_queue *txq)
Zhu Yib481de92007-09-25 17:54:57 -0700393{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800394 struct iwl4965_queue *q = &txq->q;
Zhu Yib481de92007-09-25 17:54:57 -0700395 struct pci_dev *dev = priv->pci_dev;
396 int len;
397
398 if (q->n_bd == 0)
399 return;
400
401 /* first, empty all BD's */
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800402 for (; q->write_ptr != q->read_ptr;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800403 q->read_ptr = iwl4965_queue_inc_wrap(q->read_ptr, q->n_bd))
404 iwl4965_hw_txq_free_tfd(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -0700405
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800406 len = sizeof(struct iwl4965_cmd) * q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -0700407 if (q->id == IWL_CMD_QUEUE_NUM)
408 len += IWL_MAX_SCAN_SIZE;
409
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800410 /* De-alloc array of command/tx buffers */
Zhu Yib481de92007-09-25 17:54:57 -0700411 pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
412
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800413 /* De-alloc circular buffer of TFDs */
Zhu Yib481de92007-09-25 17:54:57 -0700414 if (txq->q.n_bd)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800415 pci_free_consistent(dev, sizeof(struct iwl4965_tfd_frame) *
Zhu Yib481de92007-09-25 17:54:57 -0700416 txq->q.n_bd, txq->bd, txq->q.dma_addr);
417
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800418 /* De-alloc array of per-TFD driver data */
Zhu Yib481de92007-09-25 17:54:57 -0700419 if (txq->txb) {
420 kfree(txq->txb);
421 txq->txb = NULL;
422 }
423
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800424 /* 0-fill queue descriptor structure */
Zhu Yib481de92007-09-25 17:54:57 -0700425 memset(txq, 0, sizeof(*txq));
426}
427
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800428const u8 iwl4965_broadcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
Zhu Yib481de92007-09-25 17:54:57 -0700429
430/*************** STATION TABLE MANAGEMENT ****
Ben Cahill9fbab512007-11-29 11:09:47 +0800431 * mac80211 should be examined to determine if sta_info is duplicating
Zhu Yib481de92007-09-25 17:54:57 -0700432 * the functionality provided here
433 */
434
435/**************************************************************/
436
Ian Schram01ebd062007-10-25 17:15:22 +0800437#if 0 /* temporary disable till we add real remove station */
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800438/**
439 * iwl4965_remove_station - Remove driver's knowledge of station.
440 *
441 * NOTE: This does not remove station from device's station table.
442 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800443static u8 iwl4965_remove_station(struct iwl4965_priv *priv, const u8 *addr, int is_ap)
Zhu Yib481de92007-09-25 17:54:57 -0700444{
445 int index = IWL_INVALID_STATION;
446 int i;
447 unsigned long flags;
448
449 spin_lock_irqsave(&priv->sta_lock, flags);
450
451 if (is_ap)
452 index = IWL_AP_ID;
453 else if (is_broadcast_ether_addr(addr))
454 index = priv->hw_setting.bcast_sta_id;
455 else
456 for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++)
457 if (priv->stations[i].used &&
458 !compare_ether_addr(priv->stations[i].sta.sta.addr,
459 addr)) {
460 index = i;
461 break;
462 }
463
464 if (unlikely(index == IWL_INVALID_STATION))
465 goto out;
466
467 if (priv->stations[index].used) {
468 priv->stations[index].used = 0;
469 priv->num_stations--;
470 }
471
472 BUG_ON(priv->num_stations < 0);
473
474out:
475 spin_unlock_irqrestore(&priv->sta_lock, flags);
476 return 0;
477}
Zhu Yi556f8db2007-09-27 11:27:33 +0800478#endif
Zhu Yib481de92007-09-25 17:54:57 -0700479
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800480/**
481 * iwl4965_clear_stations_table - Clear the driver's station table
482 *
483 * NOTE: This does not clear or otherwise alter the device's station table.
484 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800485static void iwl4965_clear_stations_table(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700486{
487 unsigned long flags;
488
489 spin_lock_irqsave(&priv->sta_lock, flags);
490
491 priv->num_stations = 0;
492 memset(priv->stations, 0, sizeof(priv->stations));
493
494 spin_unlock_irqrestore(&priv->sta_lock, flags);
495}
496
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800497/**
498 * iwl4965_add_station_flags - Add station to tables in driver and device
499 */
Ron Rindjunsky67d62032007-11-26 16:14:40 +0200500u8 iwl4965_add_station_flags(struct iwl4965_priv *priv, const u8 *addr,
501 int is_ap, u8 flags, void *ht_data)
Zhu Yib481de92007-09-25 17:54:57 -0700502{
503 int i;
504 int index = IWL_INVALID_STATION;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800505 struct iwl4965_station_entry *station;
Zhu Yib481de92007-09-25 17:54:57 -0700506 unsigned long flags_spin;
Joe Perches0795af52007-10-03 17:59:30 -0700507 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -0700508
509 spin_lock_irqsave(&priv->sta_lock, flags_spin);
510 if (is_ap)
511 index = IWL_AP_ID;
512 else if (is_broadcast_ether_addr(addr))
513 index = priv->hw_setting.bcast_sta_id;
514 else
515 for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) {
516 if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
517 addr)) {
518 index = i;
519 break;
520 }
521
522 if (!priv->stations[i].used &&
523 index == IWL_INVALID_STATION)
524 index = i;
525 }
526
527
Ben Cahill9fbab512007-11-29 11:09:47 +0800528 /* These two conditions have the same outcome, but keep them separate
529 since they have different meanings */
Zhu Yib481de92007-09-25 17:54:57 -0700530 if (unlikely(index == IWL_INVALID_STATION)) {
531 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
532 return index;
533 }
534
535 if (priv->stations[index].used &&
536 !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) {
537 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
538 return index;
539 }
540
541
Joe Perches0795af52007-10-03 17:59:30 -0700542 IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index, print_mac(mac, addr));
Zhu Yib481de92007-09-25 17:54:57 -0700543 station = &priv->stations[index];
544 station->used = 1;
545 priv->num_stations++;
546
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800547 /* Set up the REPLY_ADD_STA command to send to device */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800548 memset(&station->sta, 0, sizeof(struct iwl4965_addsta_cmd));
Zhu Yib481de92007-09-25 17:54:57 -0700549 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
550 station->sta.mode = 0;
551 station->sta.sta.sta_id = index;
552 station->sta.station_flags = 0;
553
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800554#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -0700555 /* BCAST station and IBSS stations do not work in HT mode */
556 if (index != priv->hw_setting.bcast_sta_id &&
557 priv->iw_mode != IEEE80211_IF_TYPE_IBSS)
Ron Rindjunsky67d62032007-11-26 16:14:40 +0200558 iwl4965_set_ht_add_station(priv, index,
559 (struct ieee80211_ht_info *) ht_data);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800560#endif /*CONFIG_IWL4965_HT*/
Zhu Yib481de92007-09-25 17:54:57 -0700561
562 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800563
564 /* Add station to device's station table */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800565 iwl4965_send_add_station(priv, &station->sta, flags);
Zhu Yib481de92007-09-25 17:54:57 -0700566 return index;
567
568}
569
570/*************** DRIVER STATUS FUNCTIONS *****/
571
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800572static inline int iwl4965_is_ready(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700573{
574 /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are
575 * set but EXIT_PENDING is not */
576 return test_bit(STATUS_READY, &priv->status) &&
577 test_bit(STATUS_GEO_CONFIGURED, &priv->status) &&
578 !test_bit(STATUS_EXIT_PENDING, &priv->status);
579}
580
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800581static inline int iwl4965_is_alive(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700582{
583 return test_bit(STATUS_ALIVE, &priv->status);
584}
585
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800586static inline int iwl4965_is_init(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700587{
588 return test_bit(STATUS_INIT, &priv->status);
589}
590
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800591static inline int iwl4965_is_rfkill(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700592{
593 return test_bit(STATUS_RF_KILL_HW, &priv->status) ||
594 test_bit(STATUS_RF_KILL_SW, &priv->status);
595}
596
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800597static inline int iwl4965_is_ready_rf(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700598{
599
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800600 if (iwl4965_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700601 return 0;
602
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800603 return iwl4965_is_ready(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700604}
605
606/*************** HOST COMMAND QUEUE FUNCTIONS *****/
607
608#define IWL_CMD(x) case x : return #x
609
610static const char *get_cmd_string(u8 cmd)
611{
612 switch (cmd) {
613 IWL_CMD(REPLY_ALIVE);
614 IWL_CMD(REPLY_ERROR);
615 IWL_CMD(REPLY_RXON);
616 IWL_CMD(REPLY_RXON_ASSOC);
617 IWL_CMD(REPLY_QOS_PARAM);
618 IWL_CMD(REPLY_RXON_TIMING);
619 IWL_CMD(REPLY_ADD_STA);
620 IWL_CMD(REPLY_REMOVE_STA);
621 IWL_CMD(REPLY_REMOVE_ALL_STA);
622 IWL_CMD(REPLY_TX);
623 IWL_CMD(REPLY_RATE_SCALE);
624 IWL_CMD(REPLY_LEDS_CMD);
625 IWL_CMD(REPLY_TX_LINK_QUALITY_CMD);
626 IWL_CMD(RADAR_NOTIFICATION);
627 IWL_CMD(REPLY_QUIET_CMD);
628 IWL_CMD(REPLY_CHANNEL_SWITCH);
629 IWL_CMD(CHANNEL_SWITCH_NOTIFICATION);
630 IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD);
631 IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION);
632 IWL_CMD(POWER_TABLE_CMD);
633 IWL_CMD(PM_SLEEP_NOTIFICATION);
634 IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC);
635 IWL_CMD(REPLY_SCAN_CMD);
636 IWL_CMD(REPLY_SCAN_ABORT_CMD);
637 IWL_CMD(SCAN_START_NOTIFICATION);
638 IWL_CMD(SCAN_RESULTS_NOTIFICATION);
639 IWL_CMD(SCAN_COMPLETE_NOTIFICATION);
640 IWL_CMD(BEACON_NOTIFICATION);
641 IWL_CMD(REPLY_TX_BEACON);
642 IWL_CMD(WHO_IS_AWAKE_NOTIFICATION);
643 IWL_CMD(QUIET_NOTIFICATION);
644 IWL_CMD(REPLY_TX_PWR_TABLE_CMD);
645 IWL_CMD(MEASURE_ABORT_NOTIFICATION);
646 IWL_CMD(REPLY_BT_CONFIG);
647 IWL_CMD(REPLY_STATISTICS_CMD);
648 IWL_CMD(STATISTICS_NOTIFICATION);
649 IWL_CMD(REPLY_CARD_STATE_CMD);
650 IWL_CMD(CARD_STATE_NOTIFICATION);
651 IWL_CMD(MISSED_BEACONS_NOTIFICATION);
652 IWL_CMD(REPLY_CT_KILL_CONFIG_CMD);
653 IWL_CMD(SENSITIVITY_CMD);
654 IWL_CMD(REPLY_PHY_CALIBRATION_CMD);
655 IWL_CMD(REPLY_RX_PHY_CMD);
656 IWL_CMD(REPLY_RX_MPDU_CMD);
657 IWL_CMD(REPLY_4965_RX);
658 IWL_CMD(REPLY_COMPRESSED_BA);
659 default:
660 return "UNKNOWN";
661
662 }
663}
664
665#define HOST_COMPLETE_TIMEOUT (HZ / 2)
666
667/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800668 * iwl4965_enqueue_hcmd - enqueue a uCode command
Zhu Yib481de92007-09-25 17:54:57 -0700669 * @priv: device private data point
670 * @cmd: a point to the ucode command structure
671 *
672 * The function returns < 0 values to indicate the operation is
673 * failed. On success, it turns the index (> 0) of command in the
674 * command queue.
675 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800676static int iwl4965_enqueue_hcmd(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd)
Zhu Yib481de92007-09-25 17:54:57 -0700677{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800678 struct iwl4965_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
679 struct iwl4965_queue *q = &txq->q;
680 struct iwl4965_tfd_frame *tfd;
Zhu Yib481de92007-09-25 17:54:57 -0700681 u32 *control_flags;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800682 struct iwl4965_cmd *out_cmd;
Zhu Yib481de92007-09-25 17:54:57 -0700683 u32 idx;
684 u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
685 dma_addr_t phys_addr;
686 int ret;
687 unsigned long flags;
688
689 /* If any of the command structures end up being larger than
690 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
691 * we will need to increase the size of the TFD entries */
692 BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
693 !(cmd->meta.flags & CMD_SIZE_HUGE));
694
Gregory Greenmanc342a1b2008-02-06 11:20:40 -0800695 if (iwl4965_is_rfkill(priv)) {
696 IWL_DEBUG_INFO("Not sending command - RF KILL");
697 return -EIO;
698 }
699
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800700 if (iwl4965_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) {
Zhu Yib481de92007-09-25 17:54:57 -0700701 IWL_ERROR("No space for Tx\n");
702 return -ENOSPC;
703 }
704
705 spin_lock_irqsave(&priv->hcmd_lock, flags);
706
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800707 tfd = &txq->bd[q->write_ptr];
Zhu Yib481de92007-09-25 17:54:57 -0700708 memset(tfd, 0, sizeof(*tfd));
709
710 control_flags = (u32 *) tfd;
711
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800712 idx = get_cmd_index(q, q->write_ptr, cmd->meta.flags & CMD_SIZE_HUGE);
Zhu Yib481de92007-09-25 17:54:57 -0700713 out_cmd = &txq->cmd[idx];
714
715 out_cmd->hdr.cmd = cmd->id;
716 memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta));
717 memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len);
718
719 /* At this point, the out_cmd now has all of the incoming cmd
720 * information */
721
722 out_cmd->hdr.flags = 0;
723 out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800724 INDEX_TO_SEQ(q->write_ptr));
Zhu Yib481de92007-09-25 17:54:57 -0700725 if (out_cmd->meta.flags & CMD_SIZE_HUGE)
726 out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME);
727
728 phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800729 offsetof(struct iwl4965_cmd, hdr);
730 iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size);
Zhu Yib481de92007-09-25 17:54:57 -0700731
732 IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
733 "%d bytes at %d[%d]:%d\n",
734 get_cmd_string(out_cmd->hdr.cmd),
735 out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence),
Tomas Winklerfc4b6852007-10-25 17:15:24 +0800736 fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM);
Zhu Yib481de92007-09-25 17:54:57 -0700737
738 txq->need_update = 1;
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800739
740 /* Set up entry in queue's byte count circular buffer */
Zhu Yib481de92007-09-25 17:54:57 -0700741 ret = iwl4965_tx_queue_update_wr_ptr(priv, txq, 0);
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800742
743 /* Increment and update queue's write index */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800744 q->write_ptr = iwl4965_queue_inc_wrap(q->write_ptr, q->n_bd);
745 iwl4965_tx_queue_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -0700746
747 spin_unlock_irqrestore(&priv->hcmd_lock, flags);
748 return ret ? ret : idx;
749}
750
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800751static int iwl4965_send_cmd_async(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd)
Zhu Yib481de92007-09-25 17:54:57 -0700752{
753 int ret;
754
755 BUG_ON(!(cmd->meta.flags & CMD_ASYNC));
756
757 /* An asynchronous command can not expect an SKB to be set. */
758 BUG_ON(cmd->meta.flags & CMD_WANT_SKB);
759
760 /* An asynchronous command MUST have a callback. */
761 BUG_ON(!cmd->meta.u.callback);
762
763 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
764 return -EBUSY;
765
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800766 ret = iwl4965_enqueue_hcmd(priv, cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700767 if (ret < 0) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800768 IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700769 get_cmd_string(cmd->id), ret);
770 return ret;
771 }
772 return 0;
773}
774
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800775static int iwl4965_send_cmd_sync(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd)
Zhu Yib481de92007-09-25 17:54:57 -0700776{
777 int cmd_idx;
778 int ret;
779 static atomic_t entry = ATOMIC_INIT(0); /* reentrance protection */
780
781 BUG_ON(cmd->meta.flags & CMD_ASYNC);
782
783 /* A synchronous command can not have a callback set. */
784 BUG_ON(cmd->meta.u.callback != NULL);
785
786 if (atomic_xchg(&entry, 1)) {
787 IWL_ERROR("Error sending %s: Already sending a host command\n",
788 get_cmd_string(cmd->id));
789 return -EBUSY;
790 }
791
792 set_bit(STATUS_HCMD_ACTIVE, &priv->status);
793
794 if (cmd->meta.flags & CMD_WANT_SKB)
795 cmd->meta.source = &cmd->meta;
796
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800797 cmd_idx = iwl4965_enqueue_hcmd(priv, cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700798 if (cmd_idx < 0) {
799 ret = cmd_idx;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800800 IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700801 get_cmd_string(cmd->id), ret);
802 goto out;
803 }
804
805 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
806 !test_bit(STATUS_HCMD_ACTIVE, &priv->status),
807 HOST_COMPLETE_TIMEOUT);
808 if (!ret) {
809 if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) {
810 IWL_ERROR("Error sending %s: time out after %dms.\n",
811 get_cmd_string(cmd->id),
812 jiffies_to_msecs(HOST_COMPLETE_TIMEOUT));
813
814 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
815 ret = -ETIMEDOUT;
816 goto cancel;
817 }
818 }
819
820 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
821 IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n",
822 get_cmd_string(cmd->id));
823 ret = -ECANCELED;
824 goto fail;
825 }
826 if (test_bit(STATUS_FW_ERROR, &priv->status)) {
827 IWL_DEBUG_INFO("Command %s failed: FW Error\n",
828 get_cmd_string(cmd->id));
829 ret = -EIO;
830 goto fail;
831 }
832 if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) {
833 IWL_ERROR("Error: Response NULL in '%s'\n",
834 get_cmd_string(cmd->id));
835 ret = -EIO;
836 goto out;
837 }
838
839 ret = 0;
840 goto out;
841
842cancel:
843 if (cmd->meta.flags & CMD_WANT_SKB) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800844 struct iwl4965_cmd *qcmd;
Zhu Yib481de92007-09-25 17:54:57 -0700845
846 /* Cancel the CMD_WANT_SKB flag for the cmd in the
847 * TX cmd queue. Otherwise in case the cmd comes
848 * in later, it will possibly set an invalid
849 * address (cmd->meta.source). */
850 qcmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx];
851 qcmd->meta.flags &= ~CMD_WANT_SKB;
852 }
853fail:
854 if (cmd->meta.u.skb) {
855 dev_kfree_skb_any(cmd->meta.u.skb);
856 cmd->meta.u.skb = NULL;
857 }
858out:
859 atomic_set(&entry, 0);
860 return ret;
861}
862
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800863int iwl4965_send_cmd(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd)
Zhu Yib481de92007-09-25 17:54:57 -0700864{
Zhu Yib481de92007-09-25 17:54:57 -0700865 if (cmd->meta.flags & CMD_ASYNC)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800866 return iwl4965_send_cmd_async(priv, cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700867
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800868 return iwl4965_send_cmd_sync(priv, cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700869}
870
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800871int iwl4965_send_cmd_pdu(struct iwl4965_priv *priv, u8 id, u16 len, const void *data)
Zhu Yib481de92007-09-25 17:54:57 -0700872{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800873 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700874 .id = id,
875 .len = len,
876 .data = data,
877 };
878
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800879 return iwl4965_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700880}
881
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800882static int __must_check iwl4965_send_cmd_u32(struct iwl4965_priv *priv, u8 id, u32 val)
Zhu Yib481de92007-09-25 17:54:57 -0700883{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800884 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700885 .id = id,
886 .len = sizeof(val),
887 .data = &val,
888 };
889
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800890 return iwl4965_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700891}
892
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800893int iwl4965_send_statistics_request(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700894{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800895 return iwl4965_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700896}
897
898/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800899 * iwl4965_rxon_add_station - add station into station table.
Zhu Yib481de92007-09-25 17:54:57 -0700900 *
901 * there is only one AP station with id= IWL_AP_ID
Ben Cahill9fbab512007-11-29 11:09:47 +0800902 * NOTE: mutex must be held before calling this fnction
903 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800904static int iwl4965_rxon_add_station(struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700905 const u8 *addr, int is_ap)
906{
Zhu Yi556f8db2007-09-27 11:27:33 +0800907 u8 sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700908
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800909 /* Add station to device's station table */
Ron Rindjunsky67d62032007-11-26 16:14:40 +0200910#ifdef CONFIG_IWL4965_HT
911 struct ieee80211_conf *conf = &priv->hw->conf;
912 struct ieee80211_ht_info *cur_ht_config = &conf->ht_conf;
913
914 if ((is_ap) &&
915 (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) &&
916 (priv->iw_mode == IEEE80211_IF_TYPE_STA))
917 sta_id = iwl4965_add_station_flags(priv, addr, is_ap,
918 0, cur_ht_config);
919 else
920#endif /* CONFIG_IWL4965_HT */
921 sta_id = iwl4965_add_station_flags(priv, addr, is_ap,
922 0, NULL);
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800923
924 /* Set up default rate scaling table in device's station table */
Zhu Yib481de92007-09-25 17:54:57 -0700925 iwl4965_add_station(priv, addr, is_ap);
926
Zhu Yi556f8db2007-09-27 11:27:33 +0800927 return sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700928}
929
930/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800931 * iwl4965_set_rxon_channel - Set the phymode and channel values in staging RXON
Zhu Yib481de92007-09-25 17:54:57 -0700932 * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz
933 * @channel: Any channel valid for the requested phymode
934
935 * In addition to setting the staging RXON, priv->phymode is also set.
936 *
937 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
938 * in the staging RXON flag structure based on the phymode
939 */
Ben Cahill9fbab512007-11-29 11:09:47 +0800940static int iwl4965_set_rxon_channel(struct iwl4965_priv *priv, u8 phymode,
941 u16 channel)
Zhu Yib481de92007-09-25 17:54:57 -0700942{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800943 if (!iwl4965_get_channel_info(priv, phymode, channel)) {
Zhu Yib481de92007-09-25 17:54:57 -0700944 IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
945 channel, phymode);
946 return -EINVAL;
947 }
948
949 if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
950 (priv->phymode == phymode))
951 return 0;
952
953 priv->staging_rxon.channel = cpu_to_le16(channel);
954 if (phymode == MODE_IEEE80211A)
955 priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
956 else
957 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
958
959 priv->phymode = phymode;
960
961 IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, phymode);
962
963 return 0;
964}
965
966/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800967 * iwl4965_check_rxon_cmd - validate RXON structure is valid
Zhu Yib481de92007-09-25 17:54:57 -0700968 *
969 * NOTE: This is really only useful during development and can eventually
970 * be #ifdef'd out once the driver is stable and folks aren't actively
971 * making changes
972 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800973static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd *rxon)
Zhu Yib481de92007-09-25 17:54:57 -0700974{
975 int error = 0;
976 int counter = 1;
977
978 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
979 error |= le32_to_cpu(rxon->flags &
980 (RXON_FLG_TGJ_NARROW_BAND_MSK |
981 RXON_FLG_RADAR_DETECT_MSK));
982 if (error)
983 IWL_WARNING("check 24G fields %d | %d\n",
984 counter++, error);
985 } else {
986 error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
987 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
988 if (error)
989 IWL_WARNING("check 52 fields %d | %d\n",
990 counter++, error);
991 error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
992 if (error)
993 IWL_WARNING("check 52 CCK %d | %d\n",
994 counter++, error);
995 }
996 error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
997 if (error)
998 IWL_WARNING("check mac addr %d | %d\n", counter++, error);
999
1000 /* make sure basic rates 6Mbps and 1Mbps are supported */
1001 error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
1002 ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
1003 if (error)
1004 IWL_WARNING("check basic rate %d | %d\n", counter++, error);
1005
1006 error |= (le16_to_cpu(rxon->assoc_id) > 2007);
1007 if (error)
1008 IWL_WARNING("check assoc id %d | %d\n", counter++, error);
1009
1010 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
1011 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
1012 if (error)
1013 IWL_WARNING("check CCK and short slot %d | %d\n",
1014 counter++, error);
1015
1016 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
1017 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
1018 if (error)
1019 IWL_WARNING("check CCK & auto detect %d | %d\n",
1020 counter++, error);
1021
1022 error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
1023 RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
1024 if (error)
1025 IWL_WARNING("check TGG and auto detect %d | %d\n",
1026 counter++, error);
1027
1028 if (error)
1029 IWL_WARNING("Tuning to channel %d\n",
1030 le16_to_cpu(rxon->channel));
1031
1032 if (error) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001033 IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
Zhu Yib481de92007-09-25 17:54:57 -07001034 return -1;
1035 }
1036 return 0;
1037}
1038
1039/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001040 * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
Ian Schram01ebd062007-10-25 17:15:22 +08001041 * @priv: staging_rxon is compared to active_rxon
Zhu Yib481de92007-09-25 17:54:57 -07001042 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001043 * If the RXON structure is changing enough to require a new tune,
1044 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
1045 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
Zhu Yib481de92007-09-25 17:54:57 -07001046 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001047static int iwl4965_full_rxon_required(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001048{
1049
1050 /* These items are only settable from the full RXON command */
1051 if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ||
1052 compare_ether_addr(priv->staging_rxon.bssid_addr,
1053 priv->active_rxon.bssid_addr) ||
1054 compare_ether_addr(priv->staging_rxon.node_addr,
1055 priv->active_rxon.node_addr) ||
1056 compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
1057 priv->active_rxon.wlap_bssid_addr) ||
1058 (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
1059 (priv->staging_rxon.channel != priv->active_rxon.channel) ||
1060 (priv->staging_rxon.air_propagation !=
1061 priv->active_rxon.air_propagation) ||
1062 (priv->staging_rxon.ofdm_ht_single_stream_basic_rates !=
1063 priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
1064 (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
1065 priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
1066 (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) ||
1067 (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
1068 return 1;
1069
1070 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
1071 * be updated with the RXON_ASSOC command -- however only some
1072 * flag transitions are allowed using RXON_ASSOC */
1073
1074 /* Check if we are not switching bands */
1075 if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
1076 (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
1077 return 1;
1078
1079 /* Check if we are switching association toggle */
1080 if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
1081 (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
1082 return 1;
1083
1084 return 0;
1085}
1086
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001087static int iwl4965_send_rxon_assoc(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001088{
1089 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001090 struct iwl4965_rx_packet *res = NULL;
1091 struct iwl4965_rxon_assoc_cmd rxon_assoc;
1092 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001093 .id = REPLY_RXON_ASSOC,
1094 .len = sizeof(rxon_assoc),
1095 .meta.flags = CMD_WANT_SKB,
1096 .data = &rxon_assoc,
1097 };
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001098 const struct iwl4965_rxon_cmd *rxon1 = &priv->staging_rxon;
1099 const struct iwl4965_rxon_cmd *rxon2 = &priv->active_rxon;
Zhu Yib481de92007-09-25 17:54:57 -07001100
1101 if ((rxon1->flags == rxon2->flags) &&
1102 (rxon1->filter_flags == rxon2->filter_flags) &&
1103 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
1104 (rxon1->ofdm_ht_single_stream_basic_rates ==
1105 rxon2->ofdm_ht_single_stream_basic_rates) &&
1106 (rxon1->ofdm_ht_dual_stream_basic_rates ==
1107 rxon2->ofdm_ht_dual_stream_basic_rates) &&
1108 (rxon1->rx_chain == rxon2->rx_chain) &&
1109 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
1110 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
1111 return 0;
1112 }
1113
1114 rxon_assoc.flags = priv->staging_rxon.flags;
1115 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
1116 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
1117 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
1118 rxon_assoc.reserved = 0;
1119 rxon_assoc.ofdm_ht_single_stream_basic_rates =
1120 priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
1121 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
1122 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
1123 rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
1124
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001125 rc = iwl4965_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001126 if (rc)
1127 return rc;
1128
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001129 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001130 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1131 IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n");
1132 rc = -EIO;
1133 }
1134
1135 priv->alloc_rxb_skb--;
1136 dev_kfree_skb_any(cmd.meta.u.skb);
1137
1138 return rc;
1139}
1140
1141/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001142 * iwl4965_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -07001143 *
Ian Schram01ebd062007-10-25 17:15:22 +08001144 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -07001145 * the active_rxon structure is updated with the new data. This
1146 * function correctly transitions out of the RXON_ASSOC_MSK state if
1147 * a HW tune is required based on the RXON structure changes.
1148 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001149static int iwl4965_commit_rxon(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001150{
1151 /* cast away the const for active_rxon in this function */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001152 struct iwl4965_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
Joe Perches0795af52007-10-03 17:59:30 -07001153 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07001154 int rc = 0;
1155
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001156 if (!iwl4965_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001157 return -1;
1158
1159 /* always get timestamp with Rx frame */
1160 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
1161
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001162 rc = iwl4965_check_rxon_cmd(&priv->staging_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07001163 if (rc) {
1164 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
1165 return -EINVAL;
1166 }
1167
1168 /* If we don't need to send a full RXON, we can use
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001169 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -07001170 * and other flags for the current radio configuration. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001171 if (!iwl4965_full_rxon_required(priv)) {
1172 rc = iwl4965_send_rxon_assoc(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001173 if (rc) {
1174 IWL_ERROR("Error setting RXON_ASSOC "
1175 "configuration (%d).\n", rc);
1176 return rc;
1177 }
1178
1179 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
1180
1181 return 0;
1182 }
1183
1184 /* station table will be cleared */
1185 priv->assoc_station_added = 0;
1186
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001187#ifdef CONFIG_IWL4965_SENSITIVITY
Zhu Yib481de92007-09-25 17:54:57 -07001188 priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT;
1189 if (!priv->error_recovering)
1190 priv->start_calib = 0;
1191
1192 iwl4965_init_sensitivity(priv, CMD_ASYNC, 1);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001193#endif /* CONFIG_IWL4965_SENSITIVITY */
Zhu Yib481de92007-09-25 17:54:57 -07001194
1195 /* If we are currently associated and the new config requires
1196 * an RXON_ASSOC and the new config wants the associated mask enabled,
1197 * we must clear the associated from the active configuration
1198 * before we apply the new config */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001199 if (iwl4965_is_associated(priv) &&
Zhu Yib481de92007-09-25 17:54:57 -07001200 (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
1201 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
1202 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1203
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001204 rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON,
1205 sizeof(struct iwl4965_rxon_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07001206 &priv->active_rxon);
1207
1208 /* If the mask clearing failed then we set
1209 * active_rxon back to what it was previously */
1210 if (rc) {
1211 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
1212 IWL_ERROR("Error clearing ASSOC_MSK on current "
1213 "configuration (%d).\n", rc);
1214 return rc;
1215 }
Zhu Yib481de92007-09-25 17:54:57 -07001216 }
1217
1218 IWL_DEBUG_INFO("Sending RXON\n"
1219 "* with%s RXON_FILTER_ASSOC_MSK\n"
1220 "* channel = %d\n"
Joe Perches0795af52007-10-03 17:59:30 -07001221 "* bssid = %s\n",
Zhu Yib481de92007-09-25 17:54:57 -07001222 ((priv->staging_rxon.filter_flags &
1223 RXON_FILTER_ASSOC_MSK) ? "" : "out"),
1224 le16_to_cpu(priv->staging_rxon.channel),
Joe Perches0795af52007-10-03 17:59:30 -07001225 print_mac(mac, priv->staging_rxon.bssid_addr));
Zhu Yib481de92007-09-25 17:54:57 -07001226
1227 /* Apply the new configuration */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001228 rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON,
1229 sizeof(struct iwl4965_rxon_cmd), &priv->staging_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07001230 if (rc) {
1231 IWL_ERROR("Error setting new configuration (%d).\n", rc);
1232 return rc;
1233 }
1234
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001235 iwl4965_clear_stations_table(priv);
Zhu Yi556f8db2007-09-27 11:27:33 +08001236
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001237#ifdef CONFIG_IWL4965_SENSITIVITY
Zhu Yib481de92007-09-25 17:54:57 -07001238 if (!priv->error_recovering)
1239 priv->start_calib = 0;
1240
1241 priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT;
1242 iwl4965_init_sensitivity(priv, CMD_ASYNC, 1);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001243#endif /* CONFIG_IWL4965_SENSITIVITY */
Zhu Yib481de92007-09-25 17:54:57 -07001244
1245 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
1246
1247 /* If we issue a new RXON command which required a tune then we must
1248 * send a new TXPOWER command or we won't be able to Tx any frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001249 rc = iwl4965_hw_reg_send_txpower(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001250 if (rc) {
1251 IWL_ERROR("Error setting Tx power (%d).\n", rc);
1252 return rc;
1253 }
1254
1255 /* Add the broadcast address so we can send broadcast frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001256 if (iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0) ==
Zhu Yib481de92007-09-25 17:54:57 -07001257 IWL_INVALID_STATION) {
1258 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
1259 return -EIO;
1260 }
1261
1262 /* If we have set the ASSOC_MSK and we are in BSS mode then
1263 * add the IWL_AP_ID to the station rate table */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001264 if (iwl4965_is_associated(priv) &&
Zhu Yib481de92007-09-25 17:54:57 -07001265 (priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001266 if (iwl4965_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1)
Zhu Yib481de92007-09-25 17:54:57 -07001267 == IWL_INVALID_STATION) {
1268 IWL_ERROR("Error adding AP address for transmit.\n");
1269 return -EIO;
1270 }
1271 priv->assoc_station_added = 1;
1272 }
1273
1274 return 0;
1275}
1276
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001277static int iwl4965_send_bt_config(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001278{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001279 struct iwl4965_bt_cmd bt_cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001280 .flags = 3,
1281 .lead_time = 0xAA,
1282 .max_kill = 1,
1283 .kill_ack_mask = 0,
1284 .kill_cts_mask = 0,
1285 };
1286
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001287 return iwl4965_send_cmd_pdu(priv, REPLY_BT_CONFIG,
1288 sizeof(struct iwl4965_bt_cmd), &bt_cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001289}
1290
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001291static int iwl4965_send_scan_abort(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001292{
1293 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001294 struct iwl4965_rx_packet *res;
1295 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001296 .id = REPLY_SCAN_ABORT_CMD,
1297 .meta.flags = CMD_WANT_SKB,
1298 };
1299
1300 /* If there isn't a scan actively going on in the hardware
1301 * then we are in between scan bands and not actually
1302 * actively scanning, so don't send the abort command */
1303 if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
1304 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1305 return 0;
1306 }
1307
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001308 rc = iwl4965_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001309 if (rc) {
1310 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1311 return rc;
1312 }
1313
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001314 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001315 if (res->u.status != CAN_ABORT_STATUS) {
1316 /* The scan abort will return 1 for success or
1317 * 2 for "failure". A failure condition can be
1318 * due to simply not being in an active scan which
1319 * can occur if we send the scan abort before we
1320 * the microcode has notified us that a scan is
1321 * completed. */
1322 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status);
1323 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1324 clear_bit(STATUS_SCAN_HW, &priv->status);
1325 }
1326
1327 dev_kfree_skb_any(cmd.meta.u.skb);
1328
1329 return rc;
1330}
1331
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001332static int iwl4965_card_state_sync_callback(struct iwl4965_priv *priv,
1333 struct iwl4965_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -07001334 struct sk_buff *skb)
1335{
1336 return 1;
1337}
1338
1339/*
1340 * CARD_STATE_CMD
1341 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001342 * Use: Sets the device's internal card state to enable, disable, or halt
Zhu Yib481de92007-09-25 17:54:57 -07001343 *
1344 * When in the 'enable' state the card operates as normal.
1345 * When in the 'disable' state, the card enters into a low power mode.
1346 * When in the 'halt' state, the card is shut down and must be fully
1347 * restarted to come back on.
1348 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001349static int iwl4965_send_card_state(struct iwl4965_priv *priv, u32 flags, u8 meta_flag)
Zhu Yib481de92007-09-25 17:54:57 -07001350{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001351 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001352 .id = REPLY_CARD_STATE_CMD,
1353 .len = sizeof(u32),
1354 .data = &flags,
1355 .meta.flags = meta_flag,
1356 };
1357
1358 if (meta_flag & CMD_ASYNC)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001359 cmd.meta.u.callback = iwl4965_card_state_sync_callback;
Zhu Yib481de92007-09-25 17:54:57 -07001360
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001361 return iwl4965_send_cmd(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001362}
1363
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001364static int iwl4965_add_sta_sync_callback(struct iwl4965_priv *priv,
1365 struct iwl4965_cmd *cmd, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07001366{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001367 struct iwl4965_rx_packet *res = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001368
1369 if (!skb) {
1370 IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
1371 return 1;
1372 }
1373
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001374 res = (struct iwl4965_rx_packet *)skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001375 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1376 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1377 res->hdr.flags);
1378 return 1;
1379 }
1380
1381 switch (res->u.add_sta.status) {
1382 case ADD_STA_SUCCESS_MSK:
1383 break;
1384 default:
1385 break;
1386 }
1387
1388 /* We didn't cache the SKB; let the caller free it */
1389 return 1;
1390}
1391
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001392int iwl4965_send_add_station(struct iwl4965_priv *priv,
1393 struct iwl4965_addsta_cmd *sta, u8 flags)
Zhu Yib481de92007-09-25 17:54:57 -07001394{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001395 struct iwl4965_rx_packet *res = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07001396 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001397 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001398 .id = REPLY_ADD_STA,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001399 .len = sizeof(struct iwl4965_addsta_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07001400 .meta.flags = flags,
1401 .data = sta,
1402 };
1403
1404 if (flags & CMD_ASYNC)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001405 cmd.meta.u.callback = iwl4965_add_sta_sync_callback;
Zhu Yib481de92007-09-25 17:54:57 -07001406 else
1407 cmd.meta.flags |= CMD_WANT_SKB;
1408
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001409 rc = iwl4965_send_cmd(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001410
1411 if (rc || (flags & CMD_ASYNC))
1412 return rc;
1413
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001414 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001415 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1416 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1417 res->hdr.flags);
1418 rc = -EIO;
1419 }
1420
1421 if (rc == 0) {
1422 switch (res->u.add_sta.status) {
1423 case ADD_STA_SUCCESS_MSK:
1424 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
1425 break;
1426 default:
1427 rc = -EIO;
1428 IWL_WARNING("REPLY_ADD_STA failed\n");
1429 break;
1430 }
1431 }
1432
1433 priv->alloc_rxb_skb--;
1434 dev_kfree_skb_any(cmd.meta.u.skb);
1435
1436 return rc;
1437}
1438
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001439static int iwl4965_update_sta_key_info(struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001440 struct ieee80211_key_conf *keyconf,
1441 u8 sta_id)
1442{
1443 unsigned long flags;
1444 __le16 key_flags = 0;
1445
1446 switch (keyconf->alg) {
1447 case ALG_CCMP:
1448 key_flags |= STA_KEY_FLG_CCMP;
1449 key_flags |= cpu_to_le16(
1450 keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
1451 key_flags &= ~STA_KEY_FLG_INVALID;
1452 break;
1453 case ALG_TKIP:
1454 case ALG_WEP:
Zhu Yib481de92007-09-25 17:54:57 -07001455 default:
1456 return -EINVAL;
1457 }
1458 spin_lock_irqsave(&priv->sta_lock, flags);
1459 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
1460 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
1461 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
1462 keyconf->keylen);
1463
1464 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
1465 keyconf->keylen);
1466 priv->stations[sta_id].sta.key.key_flags = key_flags;
1467 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1468 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1469
1470 spin_unlock_irqrestore(&priv->sta_lock, flags);
1471
1472 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001473 iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001474 return 0;
1475}
1476
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001477static int iwl4965_clear_sta_key_info(struct iwl4965_priv *priv, u8 sta_id)
Zhu Yib481de92007-09-25 17:54:57 -07001478{
1479 unsigned long flags;
1480
1481 spin_lock_irqsave(&priv->sta_lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001482 memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl4965_hw_key));
1483 memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl4965_keyinfo));
Zhu Yib481de92007-09-25 17:54:57 -07001484 priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
1485 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1486 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1487 spin_unlock_irqrestore(&priv->sta_lock, flags);
1488
1489 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001490 iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001491 return 0;
1492}
1493
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001494static void iwl4965_clear_free_frames(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001495{
1496 struct list_head *element;
1497
1498 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
1499 priv->frames_count);
1500
1501 while (!list_empty(&priv->free_frames)) {
1502 element = priv->free_frames.next;
1503 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001504 kfree(list_entry(element, struct iwl4965_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -07001505 priv->frames_count--;
1506 }
1507
1508 if (priv->frames_count) {
1509 IWL_WARNING("%d frames still in use. Did we lose one?\n",
1510 priv->frames_count);
1511 priv->frames_count = 0;
1512 }
1513}
1514
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001515static struct iwl4965_frame *iwl4965_get_free_frame(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001516{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001517 struct iwl4965_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -07001518 struct list_head *element;
1519 if (list_empty(&priv->free_frames)) {
1520 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
1521 if (!frame) {
1522 IWL_ERROR("Could not allocate frame!\n");
1523 return NULL;
1524 }
1525
1526 priv->frames_count++;
1527 return frame;
1528 }
1529
1530 element = priv->free_frames.next;
1531 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001532 return list_entry(element, struct iwl4965_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -07001533}
1534
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001535static void iwl4965_free_frame(struct iwl4965_priv *priv, struct iwl4965_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -07001536{
1537 memset(frame, 0, sizeof(*frame));
1538 list_add(&frame->list, &priv->free_frames);
1539}
1540
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001541unsigned int iwl4965_fill_beacon_frame(struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001542 struct ieee80211_hdr *hdr,
1543 const u8 *dest, int left)
1544{
1545
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001546 if (!iwl4965_is_associated(priv) || !priv->ibss_beacon ||
Zhu Yib481de92007-09-25 17:54:57 -07001547 ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) &&
1548 (priv->iw_mode != IEEE80211_IF_TYPE_AP)))
1549 return 0;
1550
1551 if (priv->ibss_beacon->len > left)
1552 return 0;
1553
1554 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
1555
1556 return priv->ibss_beacon->len;
1557}
1558
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001559int iwl4965_rate_index_from_plcp(int plcp)
Zhu Yib481de92007-09-25 17:54:57 -07001560{
1561 int i = 0;
1562
Ben Cahill77626352007-11-29 11:09:44 +08001563 /* 4965 HT rate format */
Zhu Yib481de92007-09-25 17:54:57 -07001564 if (plcp & RATE_MCS_HT_MSK) {
1565 i = (plcp & 0xff);
1566
1567 if (i >= IWL_RATE_MIMO_6M_PLCP)
1568 i = i - IWL_RATE_MIMO_6M_PLCP;
1569
1570 i += IWL_FIRST_OFDM_RATE;
1571 /* skip 9M not supported in ht*/
1572 if (i >= IWL_RATE_9M_INDEX)
1573 i += 1;
1574 if ((i >= IWL_FIRST_OFDM_RATE) &&
1575 (i <= IWL_LAST_OFDM_RATE))
1576 return i;
Ben Cahill77626352007-11-29 11:09:44 +08001577
1578 /* 4965 legacy rate format, search for match in table */
Zhu Yib481de92007-09-25 17:54:57 -07001579 } else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001580 for (i = 0; i < ARRAY_SIZE(iwl4965_rates); i++)
1581 if (iwl4965_rates[i].plcp == (plcp &0xFF))
Zhu Yib481de92007-09-25 17:54:57 -07001582 return i;
1583 }
1584 return -1;
1585}
1586
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001587static u8 iwl4965_rate_get_lowest_plcp(int rate_mask)
Zhu Yib481de92007-09-25 17:54:57 -07001588{
1589 u8 i;
1590
1591 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001592 i = iwl4965_rates[i].next_ieee) {
Zhu Yib481de92007-09-25 17:54:57 -07001593 if (rate_mask & (1 << i))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001594 return iwl4965_rates[i].plcp;
Zhu Yib481de92007-09-25 17:54:57 -07001595 }
1596
1597 return IWL_RATE_INVALID;
1598}
1599
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001600static int iwl4965_send_beacon_cmd(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001601{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001602 struct iwl4965_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -07001603 unsigned int frame_size;
1604 int rc;
1605 u8 rate;
1606
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001607 frame = iwl4965_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001608
1609 if (!frame) {
1610 IWL_ERROR("Could not obtain free frame buffer for beacon "
1611 "command.\n");
1612 return -ENOMEM;
1613 }
1614
1615 if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001616 rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic &
Zhu Yib481de92007-09-25 17:54:57 -07001617 0xFF0);
1618 if (rate == IWL_INVALID_RATE)
1619 rate = IWL_RATE_6M_PLCP;
1620 } else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001621 rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic & 0xF);
Zhu Yib481de92007-09-25 17:54:57 -07001622 if (rate == IWL_INVALID_RATE)
1623 rate = IWL_RATE_1M_PLCP;
1624 }
1625
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001626 frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -07001627
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001628 rc = iwl4965_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -07001629 &frame->u.cmd[0]);
1630
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001631 iwl4965_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -07001632
1633 return rc;
1634}
1635
1636/******************************************************************************
1637 *
1638 * EEPROM related functions
1639 *
1640 ******************************************************************************/
1641
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001642static void get_eeprom_mac(struct iwl4965_priv *priv, u8 *mac)
Zhu Yib481de92007-09-25 17:54:57 -07001643{
1644 memcpy(mac, priv->eeprom.mac_address, 6);
1645}
1646
Reinette Chatre74a3a252008-01-23 10:15:19 -08001647static inline void iwl4965_eeprom_release_semaphore(struct iwl4965_priv *priv)
1648{
1649 iwl4965_clear_bit(priv, CSR_HW_IF_CONFIG_REG,
1650 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
1651}
1652
Zhu Yib481de92007-09-25 17:54:57 -07001653/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001654 * iwl4965_eeprom_init - read EEPROM contents
Zhu Yib481de92007-09-25 17:54:57 -07001655 *
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001656 * Load the EEPROM contents from adapter into priv->eeprom
Zhu Yib481de92007-09-25 17:54:57 -07001657 *
1658 * NOTE: This routine uses the non-debug IO access functions.
1659 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001660int iwl4965_eeprom_init(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001661{
Tomas Winkler58ff6d42008-02-13 02:47:54 +02001662 u16 *e = (u16 *)&priv->eeprom;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001663 u32 gp = iwl4965_read32(priv, CSR_EEPROM_GP);
Zhu Yib481de92007-09-25 17:54:57 -07001664 u32 r;
1665 int sz = sizeof(priv->eeprom);
1666 int rc;
1667 int i;
1668 u16 addr;
1669
1670 /* The EEPROM structure has several padding buffers within it
1671 * and when adding new EEPROM maps is subject to programmer errors
1672 * which may be very difficult to identify without explicitly
1673 * checking the resulting size of the eeprom map. */
1674 BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE);
1675
1676 if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) {
1677 IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp);
1678 return -ENOENT;
1679 }
1680
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001681 /* Make sure driver (instead of uCode) is allowed to read EEPROM */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001682 rc = iwl4965_eeprom_acquire_semaphore(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001683 if (rc < 0) {
Ian Schram91e17472007-10-25 17:15:23 +08001684 IWL_ERROR("Failed to acquire EEPROM semaphore.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001685 return -ENOENT;
1686 }
1687
1688 /* eeprom is an array of 16bit values */
1689 for (addr = 0; addr < sz; addr += sizeof(u16)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001690 _iwl4965_write32(priv, CSR_EEPROM_REG, addr << 1);
1691 _iwl4965_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD);
Zhu Yib481de92007-09-25 17:54:57 -07001692
1693 for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT;
1694 i += IWL_EEPROM_ACCESS_DELAY) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001695 r = _iwl4965_read_direct32(priv, CSR_EEPROM_REG);
Zhu Yib481de92007-09-25 17:54:57 -07001696 if (r & CSR_EEPROM_REG_READ_VALID_MSK)
1697 break;
1698 udelay(IWL_EEPROM_ACCESS_DELAY);
1699 }
1700
1701 if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) {
1702 IWL_ERROR("Time out reading EEPROM[%d]", addr);
1703 rc = -ETIMEDOUT;
1704 goto done;
1705 }
Tomas Winkler58ff6d42008-02-13 02:47:54 +02001706 e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16));
Zhu Yib481de92007-09-25 17:54:57 -07001707 }
1708 rc = 0;
1709
1710done:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001711 iwl4965_eeprom_release_semaphore(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001712 return rc;
1713}
1714
1715/******************************************************************************
1716 *
1717 * Misc. internal state and helper functions
1718 *
1719 ******************************************************************************/
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001720#ifdef CONFIG_IWL4965_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001721
1722/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001723 * iwl4965_report_frame - dump frame to syslog during debug sessions
Zhu Yib481de92007-09-25 17:54:57 -07001724 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001725 * You may hack this function to show different aspects of received frames,
Zhu Yib481de92007-09-25 17:54:57 -07001726 * including selective frame dumps.
1727 * group100 parameter selects whether to show 1 out of 100 good frames.
1728 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001729 * TODO: This was originally written for 3945, need to audit for
1730 * proper operation with 4965.
Zhu Yib481de92007-09-25 17:54:57 -07001731 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001732void iwl4965_report_frame(struct iwl4965_priv *priv,
1733 struct iwl4965_rx_packet *pkt,
Zhu Yib481de92007-09-25 17:54:57 -07001734 struct ieee80211_hdr *header, int group100)
1735{
1736 u32 to_us;
1737 u32 print_summary = 0;
1738 u32 print_dump = 0; /* set to 1 to dump all frames' contents */
1739 u32 hundred = 0;
1740 u32 dataframe = 0;
1741 u16 fc;
1742 u16 seq_ctl;
1743 u16 channel;
1744 u16 phy_flags;
1745 int rate_sym;
1746 u16 length;
1747 u16 status;
1748 u16 bcn_tmr;
1749 u32 tsf_low;
1750 u64 tsf;
1751 u8 rssi;
1752 u8 agc;
1753 u16 sig_avg;
1754 u16 noise_diff;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001755 struct iwl4965_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt);
1756 struct iwl4965_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
1757 struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt);
Zhu Yib481de92007-09-25 17:54:57 -07001758 u8 *data = IWL_RX_DATA(pkt);
1759
1760 /* MAC header */
1761 fc = le16_to_cpu(header->frame_control);
1762 seq_ctl = le16_to_cpu(header->seq_ctrl);
1763
1764 /* metadata */
1765 channel = le16_to_cpu(rx_hdr->channel);
1766 phy_flags = le16_to_cpu(rx_hdr->phy_flags);
1767 rate_sym = rx_hdr->rate;
1768 length = le16_to_cpu(rx_hdr->len);
1769
1770 /* end-of-frame status and timestamp */
1771 status = le32_to_cpu(rx_end->status);
1772 bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp);
1773 tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff;
1774 tsf = le64_to_cpu(rx_end->timestamp);
1775
1776 /* signal statistics */
1777 rssi = rx_stats->rssi;
1778 agc = rx_stats->agc;
1779 sig_avg = le16_to_cpu(rx_stats->sig_avg);
1780 noise_diff = le16_to_cpu(rx_stats->noise_diff);
1781
1782 to_us = !compare_ether_addr(header->addr1, priv->mac_addr);
1783
1784 /* if data frame is to us and all is good,
1785 * (optionally) print summary for only 1 out of every 100 */
1786 if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) ==
1787 (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
1788 dataframe = 1;
1789 if (!group100)
1790 print_summary = 1; /* print each frame */
1791 else if (priv->framecnt_to_us < 100) {
1792 priv->framecnt_to_us++;
1793 print_summary = 0;
1794 } else {
1795 priv->framecnt_to_us = 0;
1796 print_summary = 1;
1797 hundred = 1;
1798 }
1799 } else {
1800 /* print summary for all other frames */
1801 print_summary = 1;
1802 }
1803
1804 if (print_summary) {
1805 char *title;
1806 u32 rate;
1807
1808 if (hundred)
1809 title = "100Frames";
1810 else if (fc & IEEE80211_FCTL_RETRY)
1811 title = "Retry";
1812 else if (ieee80211_is_assoc_response(fc))
1813 title = "AscRsp";
1814 else if (ieee80211_is_reassoc_response(fc))
1815 title = "RasRsp";
1816 else if (ieee80211_is_probe_response(fc)) {
1817 title = "PrbRsp";
1818 print_dump = 1; /* dump frame contents */
1819 } else if (ieee80211_is_beacon(fc)) {
1820 title = "Beacon";
1821 print_dump = 1; /* dump frame contents */
1822 } else if (ieee80211_is_atim(fc))
1823 title = "ATIM";
1824 else if (ieee80211_is_auth(fc))
1825 title = "Auth";
1826 else if (ieee80211_is_deauth(fc))
1827 title = "DeAuth";
1828 else if (ieee80211_is_disassoc(fc))
1829 title = "DisAssoc";
1830 else
1831 title = "Frame";
1832
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001833 rate = iwl4965_rate_index_from_plcp(rate_sym);
Zhu Yib481de92007-09-25 17:54:57 -07001834 if (rate == -1)
1835 rate = 0;
1836 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001837 rate = iwl4965_rates[rate].ieee / 2;
Zhu Yib481de92007-09-25 17:54:57 -07001838
1839 /* print frame summary.
1840 * MAC addresses show just the last byte (for brevity),
1841 * but you can hack it to show more, if you'd like to. */
1842 if (dataframe)
1843 IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, "
1844 "len=%u, rssi=%d, chnl=%d, rate=%u, \n",
1845 title, fc, header->addr1[5],
1846 length, rssi, channel, rate);
1847 else {
1848 /* src/dst addresses assume managed mode */
1849 IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, "
1850 "src=0x%02x, rssi=%u, tim=%lu usec, "
1851 "phy=0x%02x, chnl=%d\n",
1852 title, fc, header->addr1[5],
1853 header->addr3[5], rssi,
1854 tsf_low - priv->scan_start_tsf,
1855 phy_flags, channel);
1856 }
1857 }
1858 if (print_dump)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001859 iwl4965_print_hex_dump(IWL_DL_RX, data, length);
Zhu Yib481de92007-09-25 17:54:57 -07001860}
1861#endif
1862
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001863static void iwl4965_unset_hw_setting(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001864{
1865 if (priv->hw_setting.shared_virt)
1866 pci_free_consistent(priv->pci_dev,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001867 sizeof(struct iwl4965_shared),
Zhu Yib481de92007-09-25 17:54:57 -07001868 priv->hw_setting.shared_virt,
1869 priv->hw_setting.shared_phys);
1870}
1871
1872/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001873 * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field
Zhu Yib481de92007-09-25 17:54:57 -07001874 *
1875 * return : set the bit for each supported rate insert in ie
1876 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001877static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate,
Tomas Winklerc7c46672007-10-18 02:04:15 +02001878 u16 basic_rate, int *left)
Zhu Yib481de92007-09-25 17:54:57 -07001879{
1880 u16 ret_rates = 0, bit;
1881 int i;
Tomas Winklerc7c46672007-10-18 02:04:15 +02001882 u8 *cnt = ie;
1883 u8 *rates = ie + 1;
Zhu Yib481de92007-09-25 17:54:57 -07001884
1885 for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) {
1886 if (bit & supported_rate) {
1887 ret_rates |= bit;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001888 rates[*cnt] = iwl4965_rates[i].ieee |
Tomas Winklerc7c46672007-10-18 02:04:15 +02001889 ((bit & basic_rate) ? 0x80 : 0x00);
1890 (*cnt)++;
1891 (*left)--;
1892 if ((*left <= 0) ||
1893 (*cnt >= IWL_SUPPORTED_RATES_IE_LEN))
Zhu Yib481de92007-09-25 17:54:57 -07001894 break;
1895 }
1896 }
1897
1898 return ret_rates;
1899}
1900
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001901#ifdef CONFIG_IWL4965_HT
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001902void static iwl4965_set_ht_capab(struct ieee80211_hw *hw,
Ron Rindjunsky8fb88032007-11-26 16:14:38 +02001903 struct ieee80211_ht_cap *ht_cap,
1904 u8 use_current_config);
Zhu Yib481de92007-09-25 17:54:57 -07001905#endif
1906
1907/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001908 * iwl4965_fill_probe_req - fill in all required fields and IE for probe request
Zhu Yib481de92007-09-25 17:54:57 -07001909 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001910static u16 iwl4965_fill_probe_req(struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001911 struct ieee80211_mgmt *frame,
1912 int left, int is_direct)
1913{
1914 int len = 0;
1915 u8 *pos = NULL;
mabbasbee488d2007-10-25 17:15:42 +08001916 u16 active_rates, ret_rates, cck_rates, active_rate_basic;
Ron Rindjunsky8fb88032007-11-26 16:14:38 +02001917#ifdef CONFIG_IWL4965_HT
1918 struct ieee80211_hw_mode *mode;
1919#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07001920
1921 /* Make sure there is enough space for the probe request,
1922 * two mandatory IEs and the data */
1923 left -= 24;
1924 if (left < 0)
1925 return 0;
1926 len += 24;
1927
1928 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001929 memcpy(frame->da, iwl4965_broadcast_addr, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07001930 memcpy(frame->sa, priv->mac_addr, ETH_ALEN);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001931 memcpy(frame->bssid, iwl4965_broadcast_addr, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07001932 frame->seq_ctrl = 0;
1933
1934 /* fill in our indirect SSID IE */
1935 /* ...next IE... */
1936
1937 left -= 2;
1938 if (left < 0)
1939 return 0;
1940 len += 2;
1941 pos = &(frame->u.probe_req.variable[0]);
1942 *pos++ = WLAN_EID_SSID;
1943 *pos++ = 0;
1944
1945 /* fill in our direct SSID IE... */
1946 if (is_direct) {
1947 /* ...next IE... */
1948 left -= 2 + priv->essid_len;
1949 if (left < 0)
1950 return 0;
1951 /* ... fill it in... */
1952 *pos++ = WLAN_EID_SSID;
1953 *pos++ = priv->essid_len;
1954 memcpy(pos, priv->essid, priv->essid_len);
1955 pos += priv->essid_len;
1956 len += 2 + priv->essid_len;
1957 }
1958
1959 /* fill in supported rate */
1960 /* ...next IE... */
1961 left -= 2;
1962 if (left < 0)
1963 return 0;
Tomas Winklerc7c46672007-10-18 02:04:15 +02001964
Zhu Yib481de92007-09-25 17:54:57 -07001965 /* ... fill it in... */
1966 *pos++ = WLAN_EID_SUPP_RATES;
1967 *pos = 0;
Tomas Winklerc7c46672007-10-18 02:04:15 +02001968
mabbasbee488d2007-10-25 17:15:42 +08001969 /* exclude 60M rate */
1970 active_rates = priv->rates_mask;
1971 active_rates &= ~IWL_RATE_60M_MASK;
1972
1973 active_rate_basic = active_rates & IWL_BASIC_RATES_MASK;
Zhu Yib481de92007-09-25 17:54:57 -07001974
Tomas Winklerc7c46672007-10-18 02:04:15 +02001975 cck_rates = IWL_CCK_RATES_MASK & active_rates;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001976 ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates,
mabbasbee488d2007-10-25 17:15:42 +08001977 active_rate_basic, &left);
Tomas Winklerc7c46672007-10-18 02:04:15 +02001978 active_rates &= ~ret_rates;
1979
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001980 ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates,
mabbasbee488d2007-10-25 17:15:42 +08001981 active_rate_basic, &left);
Tomas Winklerc7c46672007-10-18 02:04:15 +02001982 active_rates &= ~ret_rates;
1983
Zhu Yib481de92007-09-25 17:54:57 -07001984 len += 2 + *pos;
1985 pos += (*pos) + 1;
Tomas Winklerc7c46672007-10-18 02:04:15 +02001986 if (active_rates == 0)
Zhu Yib481de92007-09-25 17:54:57 -07001987 goto fill_end;
1988
1989 /* fill in supported extended rate */
1990 /* ...next IE... */
1991 left -= 2;
1992 if (left < 0)
1993 return 0;
1994 /* ... fill it in... */
1995 *pos++ = WLAN_EID_EXT_SUPP_RATES;
1996 *pos = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001997 iwl4965_supported_rate_to_ie(pos, active_rates,
mabbasbee488d2007-10-25 17:15:42 +08001998 active_rate_basic, &left);
Zhu Yib481de92007-09-25 17:54:57 -07001999 if (*pos > 0)
2000 len += 2 + *pos;
2001
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002002#ifdef CONFIG_IWL4965_HT
Ron Rindjunsky8fb88032007-11-26 16:14:38 +02002003 mode = priv->hw->conf.mode;
2004 if (mode->ht_info.ht_supported) {
Zhu Yib481de92007-09-25 17:54:57 -07002005 pos += (*pos) + 1;
2006 *pos++ = WLAN_EID_HT_CAPABILITY;
Ron Rindjunsky8fb88032007-11-26 16:14:38 +02002007 *pos++ = sizeof(struct ieee80211_ht_cap);
2008 iwl4965_set_ht_capab(priv->hw,
2009 (struct ieee80211_ht_cap *)pos, 0);
2010 len += 2 + sizeof(struct ieee80211_ht_cap);
Zhu Yib481de92007-09-25 17:54:57 -07002011 }
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002012#endif /*CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07002013
2014 fill_end:
2015 return (u16)len;
2016}
2017
2018/*
2019 * QoS support
2020*/
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002021#ifdef CONFIG_IWL4965_QOS
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002022static int iwl4965_send_qos_params_command(struct iwl4965_priv *priv,
2023 struct iwl4965_qosparam_cmd *qos)
Zhu Yib481de92007-09-25 17:54:57 -07002024{
2025
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002026 return iwl4965_send_cmd_pdu(priv, REPLY_QOS_PARAM,
2027 sizeof(struct iwl4965_qosparam_cmd), qos);
Zhu Yib481de92007-09-25 17:54:57 -07002028}
2029
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002030static void iwl4965_reset_qos(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002031{
2032 u16 cw_min = 15;
2033 u16 cw_max = 1023;
2034 u8 aifs = 2;
2035 u8 is_legacy = 0;
2036 unsigned long flags;
2037 int i;
2038
2039 spin_lock_irqsave(&priv->lock, flags);
2040 priv->qos_data.qos_active = 0;
2041
2042 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) {
2043 if (priv->qos_data.qos_enable)
2044 priv->qos_data.qos_active = 1;
2045 if (!(priv->active_rate & 0xfff0)) {
2046 cw_min = 31;
2047 is_legacy = 1;
2048 }
2049 } else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
2050 if (priv->qos_data.qos_enable)
2051 priv->qos_data.qos_active = 1;
2052 } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) {
2053 cw_min = 31;
2054 is_legacy = 1;
2055 }
2056
2057 if (priv->qos_data.qos_active)
2058 aifs = 3;
2059
2060 priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min);
2061 priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max);
2062 priv->qos_data.def_qos_parm.ac[0].aifsn = aifs;
2063 priv->qos_data.def_qos_parm.ac[0].edca_txop = 0;
2064 priv->qos_data.def_qos_parm.ac[0].reserved1 = 0;
2065
2066 if (priv->qos_data.qos_active) {
2067 i = 1;
2068 priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min);
2069 priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max);
2070 priv->qos_data.def_qos_parm.ac[i].aifsn = 7;
2071 priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
2072 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
2073
2074 i = 2;
2075 priv->qos_data.def_qos_parm.ac[i].cw_min =
2076 cpu_to_le16((cw_min + 1) / 2 - 1);
2077 priv->qos_data.def_qos_parm.ac[i].cw_max =
2078 cpu_to_le16(cw_max);
2079 priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
2080 if (is_legacy)
2081 priv->qos_data.def_qos_parm.ac[i].edca_txop =
2082 cpu_to_le16(6016);
2083 else
2084 priv->qos_data.def_qos_parm.ac[i].edca_txop =
2085 cpu_to_le16(3008);
2086 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
2087
2088 i = 3;
2089 priv->qos_data.def_qos_parm.ac[i].cw_min =
2090 cpu_to_le16((cw_min + 1) / 4 - 1);
2091 priv->qos_data.def_qos_parm.ac[i].cw_max =
2092 cpu_to_le16((cw_max + 1) / 2 - 1);
2093 priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
2094 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
2095 if (is_legacy)
2096 priv->qos_data.def_qos_parm.ac[i].edca_txop =
2097 cpu_to_le16(3264);
2098 else
2099 priv->qos_data.def_qos_parm.ac[i].edca_txop =
2100 cpu_to_le16(1504);
2101 } else {
2102 for (i = 1; i < 4; i++) {
2103 priv->qos_data.def_qos_parm.ac[i].cw_min =
2104 cpu_to_le16(cw_min);
2105 priv->qos_data.def_qos_parm.ac[i].cw_max =
2106 cpu_to_le16(cw_max);
2107 priv->qos_data.def_qos_parm.ac[i].aifsn = aifs;
2108 priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
2109 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
2110 }
2111 }
2112 IWL_DEBUG_QOS("set QoS to default \n");
2113
2114 spin_unlock_irqrestore(&priv->lock, flags);
2115}
2116
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002117static void iwl4965_activate_qos(struct iwl4965_priv *priv, u8 force)
Zhu Yib481de92007-09-25 17:54:57 -07002118{
2119 unsigned long flags;
2120
Zhu Yib481de92007-09-25 17:54:57 -07002121 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2122 return;
2123
2124 if (!priv->qos_data.qos_enable)
2125 return;
2126
2127 spin_lock_irqsave(&priv->lock, flags);
2128 priv->qos_data.def_qos_parm.qos_flags = 0;
2129
2130 if (priv->qos_data.qos_cap.q_AP.queue_request &&
2131 !priv->qos_data.qos_cap.q_AP.txop_request)
2132 priv->qos_data.def_qos_parm.qos_flags |=
2133 QOS_PARAM_FLG_TXOP_TYPE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07002134 if (priv->qos_data.qos_active)
2135 priv->qos_data.def_qos_parm.qos_flags |=
2136 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
2137
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002138#ifdef CONFIG_IWL4965_HT
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02002139 if (priv->current_ht_config.is_ht)
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +08002140 priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002141#endif /* CONFIG_IWL4965_HT */
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +08002142
Zhu Yib481de92007-09-25 17:54:57 -07002143 spin_unlock_irqrestore(&priv->lock, flags);
2144
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002145 if (force || iwl4965_is_associated(priv)) {
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +08002146 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
2147 priv->qos_data.qos_active,
2148 priv->qos_data.def_qos_parm.qos_flags);
Zhu Yib481de92007-09-25 17:54:57 -07002149
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002150 iwl4965_send_qos_params_command(priv,
Zhu Yib481de92007-09-25 17:54:57 -07002151 &(priv->qos_data.def_qos_parm));
2152 }
2153}
2154
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002155#endif /* CONFIG_IWL4965_QOS */
Zhu Yib481de92007-09-25 17:54:57 -07002156/*
2157 * Power management (not Tx power!) functions
2158 */
2159#define MSEC_TO_USEC 1024
2160
2161#define NOSLP __constant_cpu_to_le16(0), 0, 0
2162#define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0
2163#define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
2164#define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
2165 __constant_cpu_to_le32(X1), \
2166 __constant_cpu_to_le32(X2), \
2167 __constant_cpu_to_le32(X3), \
2168 __constant_cpu_to_le32(X4)}
2169
2170
2171/* default power management (not Tx power) table values */
2172/* for tim 0-10 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002173static struct iwl4965_power_vec_entry range_0[IWL_POWER_AC] = {
Zhu Yib481de92007-09-25 17:54:57 -07002174 {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
2175 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
2176 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
2177 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
2178 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
2179 {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
2180};
2181
2182/* for tim > 10 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002183static struct iwl4965_power_vec_entry range_1[IWL_POWER_AC] = {
Zhu Yib481de92007-09-25 17:54:57 -07002184 {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
2185 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
2186 SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
2187 {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
2188 SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
2189 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
2190 SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
2191 {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
2192 {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
2193 SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
2194};
2195
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002196int iwl4965_power_init_handle(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002197{
2198 int rc = 0, i;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002199 struct iwl4965_power_mgr *pow_data;
2200 int size = sizeof(struct iwl4965_power_vec_entry) * IWL_POWER_AC;
Zhu Yib481de92007-09-25 17:54:57 -07002201 u16 pci_pm;
2202
2203 IWL_DEBUG_POWER("Initialize power \n");
2204
2205 pow_data = &(priv->power_data);
2206
2207 memset(pow_data, 0, sizeof(*pow_data));
2208
2209 pow_data->active_index = IWL_POWER_RANGE_0;
2210 pow_data->dtim_val = 0xffff;
2211
2212 memcpy(&pow_data->pwr_range_0[0], &range_0[0], size);
2213 memcpy(&pow_data->pwr_range_1[0], &range_1[0], size);
2214
2215 rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm);
2216 if (rc != 0)
2217 return 0;
2218 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002219 struct iwl4965_powertable_cmd *cmd;
Zhu Yib481de92007-09-25 17:54:57 -07002220
2221 IWL_DEBUG_POWER("adjust power command flags\n");
2222
2223 for (i = 0; i < IWL_POWER_AC; i++) {
2224 cmd = &pow_data->pwr_range_0[i].cmd;
2225
2226 if (pci_pm & 0x1)
2227 cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
2228 else
2229 cmd->flags |= IWL_POWER_PCI_PM_MSK;
2230 }
2231 }
2232 return rc;
2233}
2234
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002235static int iwl4965_update_power_cmd(struct iwl4965_priv *priv,
2236 struct iwl4965_powertable_cmd *cmd, u32 mode)
Zhu Yib481de92007-09-25 17:54:57 -07002237{
2238 int rc = 0, i;
2239 u8 skip;
2240 u32 max_sleep = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002241 struct iwl4965_power_vec_entry *range;
Zhu Yib481de92007-09-25 17:54:57 -07002242 u8 period = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002243 struct iwl4965_power_mgr *pow_data;
Zhu Yib481de92007-09-25 17:54:57 -07002244
2245 if (mode > IWL_POWER_INDEX_5) {
2246 IWL_DEBUG_POWER("Error invalid power mode \n");
2247 return -1;
2248 }
2249 pow_data = &(priv->power_data);
2250
2251 if (pow_data->active_index == IWL_POWER_RANGE_0)
2252 range = &pow_data->pwr_range_0[0];
2253 else
2254 range = &pow_data->pwr_range_1[1];
2255
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002256 memcpy(cmd, &range[mode].cmd, sizeof(struct iwl4965_powertable_cmd));
Zhu Yib481de92007-09-25 17:54:57 -07002257
2258#ifdef IWL_MAC80211_DISABLE
2259 if (priv->assoc_network != NULL) {
2260 unsigned long flags;
2261
2262 period = priv->assoc_network->tim.tim_period;
2263 }
2264#endif /*IWL_MAC80211_DISABLE */
2265 skip = range[mode].no_dtim;
2266
2267 if (period == 0) {
2268 period = 1;
2269 skip = 0;
2270 }
2271
2272 if (skip == 0) {
2273 max_sleep = period;
2274 cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
2275 } else {
2276 __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
2277 max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
2278 cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
2279 }
2280
2281 for (i = 0; i < IWL_POWER_VEC_SIZE; i++) {
2282 if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
2283 cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
2284 }
2285
2286 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags);
2287 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
2288 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
2289 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
2290 le32_to_cpu(cmd->sleep_interval[0]),
2291 le32_to_cpu(cmd->sleep_interval[1]),
2292 le32_to_cpu(cmd->sleep_interval[2]),
2293 le32_to_cpu(cmd->sleep_interval[3]),
2294 le32_to_cpu(cmd->sleep_interval[4]));
2295
2296 return rc;
2297}
2298
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002299static int iwl4965_send_power_mode(struct iwl4965_priv *priv, u32 mode)
Zhu Yib481de92007-09-25 17:54:57 -07002300{
John W. Linville9a62f732007-11-15 16:27:36 -05002301 u32 uninitialized_var(final_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002302 int rc;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002303 struct iwl4965_powertable_cmd cmd;
Zhu Yib481de92007-09-25 17:54:57 -07002304
2305 /* If on battery, set to 3,
Ian Schram01ebd062007-10-25 17:15:22 +08002306 * if plugged into AC power, set to CAM ("continuously aware mode"),
Zhu Yib481de92007-09-25 17:54:57 -07002307 * else user level */
2308 switch (mode) {
2309 case IWL_POWER_BATTERY:
2310 final_mode = IWL_POWER_INDEX_3;
2311 break;
2312 case IWL_POWER_AC:
2313 final_mode = IWL_POWER_MODE_CAM;
2314 break;
2315 default:
2316 final_mode = mode;
2317 break;
2318 }
2319
2320 cmd.keep_alive_beacons = 0;
2321
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002322 iwl4965_update_power_cmd(priv, &cmd, final_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002323
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002324 rc = iwl4965_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07002325
2326 if (final_mode == IWL_POWER_MODE_CAM)
2327 clear_bit(STATUS_POWER_PMI, &priv->status);
2328 else
2329 set_bit(STATUS_POWER_PMI, &priv->status);
2330
2331 return rc;
2332}
2333
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002334int iwl4965_is_network_packet(struct iwl4965_priv *priv, struct ieee80211_hdr *header)
Zhu Yib481de92007-09-25 17:54:57 -07002335{
2336 /* Filter incoming packets to determine if they are targeted toward
2337 * this network, discarding packets coming from ourselves */
2338 switch (priv->iw_mode) {
2339 case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */
2340 /* packets from our adapter are dropped (echo) */
2341 if (!compare_ether_addr(header->addr2, priv->mac_addr))
2342 return 0;
2343 /* {broad,multi}cast packets to our IBSS go through */
2344 if (is_multicast_ether_addr(header->addr1))
2345 return !compare_ether_addr(header->addr3, priv->bssid);
2346 /* packets to our adapter go through */
2347 return !compare_ether_addr(header->addr1, priv->mac_addr);
2348 case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */
2349 /* packets from our adapter are dropped (echo) */
2350 if (!compare_ether_addr(header->addr3, priv->mac_addr))
2351 return 0;
2352 /* {broad,multi}cast packets to our BSS go through */
2353 if (is_multicast_ether_addr(header->addr1))
2354 return !compare_ether_addr(header->addr2, priv->bssid);
2355 /* packets to our adapter go through */
2356 return !compare_ether_addr(header->addr1, priv->mac_addr);
2357 }
2358
2359 return 1;
2360}
2361
2362#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
2363
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002364static const char *iwl4965_get_tx_fail_reason(u32 status)
Zhu Yib481de92007-09-25 17:54:57 -07002365{
2366 switch (status & TX_STATUS_MSK) {
2367 case TX_STATUS_SUCCESS:
2368 return "SUCCESS";
2369 TX_STATUS_ENTRY(SHORT_LIMIT);
2370 TX_STATUS_ENTRY(LONG_LIMIT);
2371 TX_STATUS_ENTRY(FIFO_UNDERRUN);
2372 TX_STATUS_ENTRY(MGMNT_ABORT);
2373 TX_STATUS_ENTRY(NEXT_FRAG);
2374 TX_STATUS_ENTRY(LIFE_EXPIRE);
2375 TX_STATUS_ENTRY(DEST_PS);
2376 TX_STATUS_ENTRY(ABORTED);
2377 TX_STATUS_ENTRY(BT_RETRY);
2378 TX_STATUS_ENTRY(STA_INVALID);
2379 TX_STATUS_ENTRY(FRAG_DROPPED);
2380 TX_STATUS_ENTRY(TID_DISABLE);
2381 TX_STATUS_ENTRY(FRAME_FLUSHED);
2382 TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
2383 TX_STATUS_ENTRY(TX_LOCKED);
2384 TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
2385 }
2386
2387 return "UNKNOWN";
2388}
2389
2390/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002391 * iwl4965_scan_cancel - Cancel any currently executing HW scan
Zhu Yib481de92007-09-25 17:54:57 -07002392 *
2393 * NOTE: priv->mutex is not required before calling this function
2394 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002395static int iwl4965_scan_cancel(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002396{
2397 if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
2398 clear_bit(STATUS_SCANNING, &priv->status);
2399 return 0;
2400 }
2401
2402 if (test_bit(STATUS_SCANNING, &priv->status)) {
2403 if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
2404 IWL_DEBUG_SCAN("Queuing scan abort.\n");
2405 set_bit(STATUS_SCAN_ABORTING, &priv->status);
2406 queue_work(priv->workqueue, &priv->abort_scan);
2407
2408 } else
2409 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
2410
2411 return test_bit(STATUS_SCANNING, &priv->status);
2412 }
2413
2414 return 0;
2415}
2416
2417/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002418 * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan
Zhu Yib481de92007-09-25 17:54:57 -07002419 * @ms: amount of time to wait (in milliseconds) for scan to abort
2420 *
2421 * NOTE: priv->mutex must be held before calling this function
2422 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002423static int iwl4965_scan_cancel_timeout(struct iwl4965_priv *priv, unsigned long ms)
Zhu Yib481de92007-09-25 17:54:57 -07002424{
2425 unsigned long now = jiffies;
2426 int ret;
2427
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002428 ret = iwl4965_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002429 if (ret && ms) {
2430 mutex_unlock(&priv->mutex);
2431 while (!time_after(jiffies, now + msecs_to_jiffies(ms)) &&
2432 test_bit(STATUS_SCANNING, &priv->status))
2433 msleep(1);
2434 mutex_lock(&priv->mutex);
2435
2436 return test_bit(STATUS_SCANNING, &priv->status);
2437 }
2438
2439 return ret;
2440}
2441
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002442static void iwl4965_sequence_reset(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002443{
2444 /* Reset ieee stats */
2445
2446 /* We don't reset the net_device_stats (ieee->stats) on
2447 * re-association */
2448
2449 priv->last_seq_num = -1;
2450 priv->last_frag_num = -1;
2451 priv->last_packet_time = 0;
2452
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002453 iwl4965_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002454}
2455
2456#define MAX_UCODE_BEACON_INTERVAL 4096
2457#define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
2458
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002459static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -07002460{
2461 u16 new_val = 0;
2462 u16 beacon_factor = 0;
2463
2464 beacon_factor =
2465 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
2466 / MAX_UCODE_BEACON_INTERVAL;
2467 new_val = beacon_val / beacon_factor;
2468
2469 return cpu_to_le16(new_val);
2470}
2471
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002472static void iwl4965_setup_rxon_timing(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002473{
2474 u64 interval_tm_unit;
2475 u64 tsf, result;
2476 unsigned long flags;
2477 struct ieee80211_conf *conf = NULL;
2478 u16 beacon_int = 0;
2479
2480 conf = ieee80211_get_hw_conf(priv->hw);
2481
2482 spin_lock_irqsave(&priv->lock, flags);
2483 priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp1);
2484 priv->rxon_timing.timestamp.dw[0] = cpu_to_le32(priv->timestamp0);
2485
2486 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
2487
2488 tsf = priv->timestamp1;
2489 tsf = ((tsf << 32) | priv->timestamp0);
2490
2491 beacon_int = priv->beacon_int;
2492 spin_unlock_irqrestore(&priv->lock, flags);
2493
2494 if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
2495 if (beacon_int == 0) {
2496 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
2497 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
2498 } else {
2499 priv->rxon_timing.beacon_interval =
2500 cpu_to_le16(beacon_int);
2501 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002502 iwl4965_adjust_beacon_interval(
Zhu Yib481de92007-09-25 17:54:57 -07002503 le16_to_cpu(priv->rxon_timing.beacon_interval));
2504 }
2505
2506 priv->rxon_timing.atim_window = 0;
2507 } else {
2508 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002509 iwl4965_adjust_beacon_interval(conf->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -07002510 /* TODO: we need to get atim_window from upper stack
2511 * for now we set to 0 */
2512 priv->rxon_timing.atim_window = 0;
2513 }
2514
2515 interval_tm_unit =
2516 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
2517 result = do_div(tsf, interval_tm_unit);
2518 priv->rxon_timing.beacon_init_val =
2519 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
2520
2521 IWL_DEBUG_ASSOC
2522 ("beacon interval %d beacon timer %d beacon tim %d\n",
2523 le16_to_cpu(priv->rxon_timing.beacon_interval),
2524 le32_to_cpu(priv->rxon_timing.beacon_init_val),
2525 le16_to_cpu(priv->rxon_timing.atim_window));
2526}
2527
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002528static int iwl4965_scan_initiate(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002529{
2530 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
2531 IWL_ERROR("APs don't scan.\n");
2532 return 0;
2533 }
2534
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002535 if (!iwl4965_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002536 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
2537 return -EIO;
2538 }
2539
2540 if (test_bit(STATUS_SCANNING, &priv->status)) {
2541 IWL_DEBUG_SCAN("Scan already in progress.\n");
2542 return -EAGAIN;
2543 }
2544
2545 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
2546 IWL_DEBUG_SCAN("Scan request while abort pending. "
2547 "Queuing.\n");
2548 return -EAGAIN;
2549 }
2550
2551 IWL_DEBUG_INFO("Starting scan...\n");
2552 priv->scan_bands = 2;
2553 set_bit(STATUS_SCANNING, &priv->status);
2554 priv->scan_start = jiffies;
2555 priv->scan_pass_start = priv->scan_start;
2556
2557 queue_work(priv->workqueue, &priv->request_scan);
2558
2559 return 0;
2560}
2561
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002562static int iwl4965_set_rxon_hwcrypto(struct iwl4965_priv *priv, int hw_decrypt)
Zhu Yib481de92007-09-25 17:54:57 -07002563{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002564 struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon;
Zhu Yib481de92007-09-25 17:54:57 -07002565
2566 if (hw_decrypt)
2567 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
2568 else
2569 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
2570
2571 return 0;
2572}
2573
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002574static void iwl4965_set_flags_for_phymode(struct iwl4965_priv *priv, u8 phymode)
Zhu Yib481de92007-09-25 17:54:57 -07002575{
2576 if (phymode == MODE_IEEE80211A) {
2577 priv->staging_rxon.flags &=
2578 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
2579 | RXON_FLG_CCK_MSK);
2580 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2581 } else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002582 /* Copied from iwl4965_bg_post_associate() */
Zhu Yib481de92007-09-25 17:54:57 -07002583 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2584 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2585 else
2586 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2587
2588 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
2589 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2590
2591 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
2592 priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
2593 priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
2594 }
2595}
2596
2597/*
Ian Schram01ebd062007-10-25 17:15:22 +08002598 * initialize rxon structure with default values from eeprom
Zhu Yib481de92007-09-25 17:54:57 -07002599 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002600static void iwl4965_connection_init_rx_config(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002601{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002602 const struct iwl4965_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07002603
2604 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
2605
2606 switch (priv->iw_mode) {
2607 case IEEE80211_IF_TYPE_AP:
2608 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
2609 break;
2610
2611 case IEEE80211_IF_TYPE_STA:
2612 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
2613 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
2614 break;
2615
2616 case IEEE80211_IF_TYPE_IBSS:
2617 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
2618 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
2619 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
2620 RXON_FILTER_ACCEPT_GRP_MSK;
2621 break;
2622
2623 case IEEE80211_IF_TYPE_MNTR:
2624 priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
2625 priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
2626 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
2627 break;
2628 }
2629
2630#if 0
2631 /* TODO: Figure out when short_preamble would be set and cache from
2632 * that */
2633 if (!hw_to_local(priv->hw)->short_preamble)
2634 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2635 else
2636 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2637#endif
2638
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002639 ch_info = iwl4965_get_channel_info(priv, priv->phymode,
Zhu Yib481de92007-09-25 17:54:57 -07002640 le16_to_cpu(priv->staging_rxon.channel));
2641
2642 if (!ch_info)
2643 ch_info = &priv->channel_info[0];
2644
2645 /*
2646 * in some case A channels are all non IBSS
2647 * in this case force B/G channel
2648 */
2649 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
2650 !(is_channel_ibss(ch_info)))
2651 ch_info = &priv->channel_info[0];
2652
2653 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
2654 if (is_channel_a_band(ch_info))
2655 priv->phymode = MODE_IEEE80211A;
2656 else
2657 priv->phymode = MODE_IEEE80211G;
2658
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002659 iwl4965_set_flags_for_phymode(priv, priv->phymode);
Zhu Yib481de92007-09-25 17:54:57 -07002660
2661 priv->staging_rxon.ofdm_basic_rates =
2662 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
2663 priv->staging_rxon.cck_basic_rates =
2664 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
2665
2666 priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
2667 RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
2668 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2669 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
2670 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
2671 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
2672 iwl4965_set_rxon_chain(priv);
2673}
2674
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002675static int iwl4965_set_mode(struct iwl4965_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -07002676{
Zhu Yib481de92007-09-25 17:54:57 -07002677 if (mode == IEEE80211_IF_TYPE_IBSS) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002678 const struct iwl4965_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07002679
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002680 ch_info = iwl4965_get_channel_info(priv,
Zhu Yib481de92007-09-25 17:54:57 -07002681 priv->phymode,
2682 le16_to_cpu(priv->staging_rxon.channel));
2683
2684 if (!ch_info || !is_channel_ibss(ch_info)) {
2685 IWL_ERROR("channel %d not IBSS channel\n",
2686 le16_to_cpu(priv->staging_rxon.channel));
2687 return -EINVAL;
2688 }
2689 }
2690
Zhu Yib481de92007-09-25 17:54:57 -07002691 priv->iw_mode = mode;
2692
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002693 iwl4965_connection_init_rx_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002694 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2695
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002696 iwl4965_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002697
Mohamed Abbasfde35712007-11-29 11:10:15 +08002698 /* dont commit rxon if rf-kill is on*/
2699 if (!iwl4965_is_ready_rf(priv))
2700 return -EAGAIN;
2701
2702 cancel_delayed_work(&priv->scan_check);
2703 if (iwl4965_scan_cancel_timeout(priv, 100)) {
2704 IWL_WARNING("Aborted scan still in progress after 100ms\n");
2705 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2706 return -EAGAIN;
2707 }
2708
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002709 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002710
2711 return 0;
2712}
2713
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002714static void iwl4965_build_tx_cmd_hwcrypto(struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002715 struct ieee80211_tx_control *ctl,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002716 struct iwl4965_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -07002717 struct sk_buff *skb_frag,
2718 int last_frag)
2719{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002720 struct iwl4965_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo;
Zhu Yib481de92007-09-25 17:54:57 -07002721
2722 switch (keyinfo->alg) {
2723 case ALG_CCMP:
2724 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM;
2725 memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen);
2726 IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
2727 break;
2728
2729 case ALG_TKIP:
2730#if 0
2731 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP;
2732
2733 if (last_frag)
2734 memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8,
2735 8);
2736 else
2737 memset(cmd->cmd.tx.tkip_mic.byte, 0, 8);
2738#endif
2739 break;
2740
2741 case ALG_WEP:
2742 cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP |
2743 (ctl->key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
2744
2745 if (keyinfo->keylen == 13)
2746 cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128;
2747
2748 memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen);
2749
2750 IWL_DEBUG_TX("Configuring packet for WEP encryption "
2751 "with key %d\n", ctl->key_idx);
2752 break;
2753
Zhu Yib481de92007-09-25 17:54:57 -07002754 default:
2755 printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg);
2756 break;
2757 }
2758}
2759
2760/*
2761 * handle build REPLY_TX command notification.
2762 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002763static void iwl4965_build_tx_cmd_basic(struct iwl4965_priv *priv,
2764 struct iwl4965_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -07002765 struct ieee80211_tx_control *ctrl,
2766 struct ieee80211_hdr *hdr,
2767 int is_unicast, u8 std_id)
2768{
2769 __le16 *qc;
2770 u16 fc = le16_to_cpu(hdr->frame_control);
2771 __le32 tx_flags = cmd->cmd.tx.tx_flags;
2772
2773 cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
2774 if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) {
2775 tx_flags |= TX_CMD_FLG_ACK_MSK;
2776 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
2777 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2778 if (ieee80211_is_probe_response(fc) &&
2779 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
2780 tx_flags |= TX_CMD_FLG_TSF_MSK;
2781 } else {
2782 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
2783 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2784 }
2785
Tomas Winkler87e4f7d2008-01-14 17:46:16 -08002786 if (ieee80211_is_back_request(fc))
2787 tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK;
2788
2789
Zhu Yib481de92007-09-25 17:54:57 -07002790 cmd->cmd.tx.sta_id = std_id;
2791 if (ieee80211_get_morefrag(hdr))
2792 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
2793
2794 qc = ieee80211_get_qos_ctrl(hdr);
2795 if (qc) {
2796 cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf);
2797 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
2798 } else
2799 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2800
2801 if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) {
2802 tx_flags |= TX_CMD_FLG_RTS_MSK;
2803 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
2804 } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) {
2805 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
2806 tx_flags |= TX_CMD_FLG_CTS_MSK;
2807 }
2808
2809 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
2810 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
2811
2812 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
2813 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
2814 if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ ||
2815 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
Ian Schrambc434dd2007-10-25 17:15:29 +08002816 cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3);
Zhu Yib481de92007-09-25 17:54:57 -07002817 else
Ian Schrambc434dd2007-10-25 17:15:29 +08002818 cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2);
Zhu Yib481de92007-09-25 17:54:57 -07002819 } else
2820 cmd->cmd.tx.timeout.pm_frame_timeout = 0;
2821
2822 cmd->cmd.tx.driver_txop = 0;
2823 cmd->cmd.tx.tx_flags = tx_flags;
2824 cmd->cmd.tx.next_frame_len = 0;
2825}
2826
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002827/**
2828 * iwl4965_get_sta_id - Find station's index within station table
2829 *
2830 * If new IBSS station, create new entry in station table
2831 */
Ben Cahill9fbab512007-11-29 11:09:47 +08002832static int iwl4965_get_sta_id(struct iwl4965_priv *priv,
2833 struct ieee80211_hdr *hdr)
Zhu Yib481de92007-09-25 17:54:57 -07002834{
2835 int sta_id;
2836 u16 fc = le16_to_cpu(hdr->frame_control);
Joe Perches0795af52007-10-03 17:59:30 -07002837 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07002838
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002839 /* If this frame is broadcast or management, use broadcast station id */
Zhu Yib481de92007-09-25 17:54:57 -07002840 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
2841 is_multicast_ether_addr(hdr->addr1))
2842 return priv->hw_setting.bcast_sta_id;
2843
2844 switch (priv->iw_mode) {
2845
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002846 /* If we are a client station in a BSS network, use the special
2847 * AP station entry (that's the only station we communicate with) */
Zhu Yib481de92007-09-25 17:54:57 -07002848 case IEEE80211_IF_TYPE_STA:
2849 return IWL_AP_ID;
2850
2851 /* If we are an AP, then find the station, or use BCAST */
2852 case IEEE80211_IF_TYPE_AP:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002853 sta_id = iwl4965_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07002854 if (sta_id != IWL_INVALID_STATION)
2855 return sta_id;
2856 return priv->hw_setting.bcast_sta_id;
2857
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002858 /* If this frame is going out to an IBSS network, find the station,
2859 * or create a new station table entry */
Zhu Yib481de92007-09-25 17:54:57 -07002860 case IEEE80211_IF_TYPE_IBSS:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002861 sta_id = iwl4965_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07002862 if (sta_id != IWL_INVALID_STATION)
2863 return sta_id;
2864
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002865 /* Create new station table entry */
Ron Rindjunsky67d62032007-11-26 16:14:40 +02002866 sta_id = iwl4965_add_station_flags(priv, hdr->addr1,
2867 0, CMD_ASYNC, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07002868
2869 if (sta_id != IWL_INVALID_STATION)
2870 return sta_id;
2871
Joe Perches0795af52007-10-03 17:59:30 -07002872 IWL_DEBUG_DROP("Station %s not in station map. "
Zhu Yib481de92007-09-25 17:54:57 -07002873 "Defaulting to broadcast...\n",
Joe Perches0795af52007-10-03 17:59:30 -07002874 print_mac(mac, hdr->addr1));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002875 iwl4965_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
Zhu Yib481de92007-09-25 17:54:57 -07002876 return priv->hw_setting.bcast_sta_id;
2877
2878 default:
Ian Schram01ebd062007-10-25 17:15:22 +08002879 IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002880 return priv->hw_setting.bcast_sta_id;
2881 }
2882}
2883
2884/*
2885 * start REPLY_TX command process
2886 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002887static int iwl4965_tx_skb(struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002888 struct sk_buff *skb, struct ieee80211_tx_control *ctl)
2889{
2890 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002891 struct iwl4965_tfd_frame *tfd;
Zhu Yib481de92007-09-25 17:54:57 -07002892 u32 *control_flags;
2893 int txq_id = ctl->queue;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002894 struct iwl4965_tx_queue *txq = NULL;
2895 struct iwl4965_queue *q = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07002896 dma_addr_t phys_addr;
2897 dma_addr_t txcmd_phys;
Tomas Winkler87e4f7d2008-01-14 17:46:16 -08002898 dma_addr_t scratch_phys;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002899 struct iwl4965_cmd *out_cmd = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07002900 u16 len, idx, len_org;
2901 u8 id, hdr_len, unicast;
2902 u8 sta_id;
2903 u16 seq_number = 0;
2904 u16 fc;
2905 __le16 *qc;
2906 u8 wait_write_ptr = 0;
2907 unsigned long flags;
2908 int rc;
2909
2910 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002911 if (iwl4965_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002912 IWL_DEBUG_DROP("Dropping - RF KILL\n");
2913 goto drop_unlock;
2914 }
2915
Johannes Berg32bfd352007-12-19 01:31:26 +01002916 if (!priv->vif) {
2917 IWL_DEBUG_DROP("Dropping - !priv->vif\n");
Zhu Yib481de92007-09-25 17:54:57 -07002918 goto drop_unlock;
2919 }
2920
2921 if ((ctl->tx_rate & 0xFF) == IWL_INVALID_RATE) {
2922 IWL_ERROR("ERROR: No TX rate available.\n");
2923 goto drop_unlock;
2924 }
2925
2926 unicast = !is_multicast_ether_addr(hdr->addr1);
2927 id = 0;
2928
2929 fc = le16_to_cpu(hdr->frame_control);
2930
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002931#ifdef CONFIG_IWL4965_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07002932 if (ieee80211_is_auth(fc))
2933 IWL_DEBUG_TX("Sending AUTH frame\n");
2934 else if (ieee80211_is_assoc_request(fc))
2935 IWL_DEBUG_TX("Sending ASSOC frame\n");
2936 else if (ieee80211_is_reassoc_request(fc))
2937 IWL_DEBUG_TX("Sending REASSOC frame\n");
2938#endif
2939
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002940 /* drop all data frame if we are not associated */
Gregory Greenman76f39152008-01-23 10:15:21 -08002941 if (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) &&
2942 (!iwl4965_is_associated(priv) ||
Reinette Chatrea6477242008-02-14 10:40:28 -08002943 ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && !priv->assoc_id) ||
Gregory Greenman76f39152008-01-23 10:15:21 -08002944 !priv->assoc_station_added)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002945 IWL_DEBUG_DROP("Dropping - !iwl4965_is_associated\n");
Zhu Yib481de92007-09-25 17:54:57 -07002946 goto drop_unlock;
2947 }
2948
2949 spin_unlock_irqrestore(&priv->lock, flags);
2950
2951 hdr_len = ieee80211_get_hdrlen(fc);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002952
2953 /* Find (or create) index into station table for destination station */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002954 sta_id = iwl4965_get_sta_id(priv, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07002955 if (sta_id == IWL_INVALID_STATION) {
Joe Perches0795af52007-10-03 17:59:30 -07002956 DECLARE_MAC_BUF(mac);
2957
2958 IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
2959 print_mac(mac, hdr->addr1));
Zhu Yib481de92007-09-25 17:54:57 -07002960 goto drop;
2961 }
2962
2963 IWL_DEBUG_RATE("station Id %d\n", sta_id);
2964
2965 qc = ieee80211_get_qos_ctrl(hdr);
2966 if (qc) {
2967 u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
2968 seq_number = priv->stations[sta_id].tid[tid].seq_number &
2969 IEEE80211_SCTL_SEQ;
2970 hdr->seq_ctrl = cpu_to_le16(seq_number) |
2971 (hdr->seq_ctrl &
2972 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG));
2973 seq_number += 0x10;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002974#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -07002975 /* aggregation is on for this <sta,tid> */
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02002976 if (ctl->flags & IEEE80211_TXCTL_AMPDU)
Zhu Yib481de92007-09-25 17:54:57 -07002977 txq_id = priv->stations[sta_id].tid[tid].agg.txq_id;
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02002978 priv->stations[sta_id].tid[tid].tfds_in_queue++;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08002979#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07002980 }
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002981
2982 /* Descriptor for chosen Tx queue */
Zhu Yib481de92007-09-25 17:54:57 -07002983 txq = &priv->txq[txq_id];
2984 q = &txq->q;
2985
2986 spin_lock_irqsave(&priv->lock, flags);
2987
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002988 /* Set up first empty TFD within this queue's circular TFD buffer */
Tomas Winklerfc4b6852007-10-25 17:15:24 +08002989 tfd = &txq->bd[q->write_ptr];
Zhu Yib481de92007-09-25 17:54:57 -07002990 memset(tfd, 0, sizeof(*tfd));
2991 control_flags = (u32 *) tfd;
Tomas Winklerfc4b6852007-10-25 17:15:24 +08002992 idx = get_cmd_index(q, q->write_ptr, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002993
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002994 /* Set up driver data for this TFD */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002995 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl4965_tx_info));
Tomas Winklerfc4b6852007-10-25 17:15:24 +08002996 txq->txb[q->write_ptr].skb[0] = skb;
2997 memcpy(&(txq->txb[q->write_ptr].status.control),
Zhu Yib481de92007-09-25 17:54:57 -07002998 ctl, sizeof(struct ieee80211_tx_control));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08002999
3000 /* Set up first empty entry in queue's array of Tx/cmd buffers */
Zhu Yib481de92007-09-25 17:54:57 -07003001 out_cmd = &txq->cmd[idx];
3002 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
3003 memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003004
3005 /*
3006 * Set up the Tx-command (not MAC!) header.
3007 * Store the chosen Tx queue and TFD index within the sequence field;
3008 * after Tx, uCode's Tx response will return this value so driver can
3009 * locate the frame within the tx queue and do post-tx processing.
3010 */
Zhu Yib481de92007-09-25 17:54:57 -07003011 out_cmd->hdr.cmd = REPLY_TX;
3012 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +08003013 INDEX_TO_SEQ(q->write_ptr)));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003014
3015 /* Copy MAC header from skb into command buffer */
Zhu Yib481de92007-09-25 17:54:57 -07003016 memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len);
3017
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003018 /*
3019 * Use the first empty entry in this queue's command buffer array
3020 * to contain the Tx command and MAC header concatenated together
3021 * (payload data will be in another buffer).
3022 * Size of this varies, due to varying MAC header length.
3023 * If end is not dword aligned, we'll have 2 extra bytes at the end
3024 * of the MAC header (device reads on dword boundaries).
3025 * We'll tell device about this padding later.
3026 */
Zhu Yib481de92007-09-25 17:54:57 -07003027 len = priv->hw_setting.tx_cmd_len +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003028 sizeof(struct iwl4965_cmd_header) + hdr_len;
Zhu Yib481de92007-09-25 17:54:57 -07003029
3030 len_org = len;
3031 len = (len + 3) & ~3;
3032
3033 if (len_org != len)
3034 len_org = 1;
3035 else
3036 len_org = 0;
3037
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003038 /* Physical address of this Tx command's header (not MAC header!),
3039 * within command buffer array. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003040 txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl4965_cmd) * idx +
3041 offsetof(struct iwl4965_cmd, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07003042
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003043 /* Add buffer containing Tx command and MAC(!) header to TFD's
3044 * first entry */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003045 iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len);
Zhu Yib481de92007-09-25 17:54:57 -07003046
3047 if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003048 iwl4965_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003049
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003050 /* Set up TFD's 2nd entry to point directly to remainder of skb,
3051 * if any (802.11 null frames have no payload). */
Zhu Yib481de92007-09-25 17:54:57 -07003052 len = skb->len - hdr_len;
3053 if (len) {
3054 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
3055 len, PCI_DMA_TODEVICE);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003056 iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len);
Zhu Yib481de92007-09-25 17:54:57 -07003057 }
3058
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003059 /* Tell 4965 about any 2-byte padding after MAC header */
Zhu Yib481de92007-09-25 17:54:57 -07003060 if (len_org)
3061 out_cmd->cmd.tx.tx_flags |= TX_CMD_FLG_MH_PAD_MSK;
3062
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003063 /* Total # bytes to be transmitted */
Zhu Yib481de92007-09-25 17:54:57 -07003064 len = (u16)skb->len;
3065 out_cmd->cmd.tx.len = cpu_to_le16(len);
3066
3067 /* TODO need this for burst mode later on */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003068 iwl4965_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07003069
3070 /* set is_hcca to 0; it probably will never be implemented */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003071 iwl4965_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003072
Tomas Winkler87e4f7d2008-01-14 17:46:16 -08003073 scratch_phys = txcmd_phys + sizeof(struct iwl4965_cmd_header) +
3074 offsetof(struct iwl4965_tx_cmd, scratch);
3075 out_cmd->cmd.tx.dram_lsb_ptr = cpu_to_le32(scratch_phys);
3076 out_cmd->cmd.tx.dram_msb_ptr = iwl_get_dma_hi_address(scratch_phys);
3077
3078#ifdef CONFIG_IWL4965_HT_AGG
3079#ifdef CONFIG_IWL4965_HT
3080 /* TODO: move this functionality to rate scaling */
3081 iwl4965_tl_get_stats(priv, hdr);
3082#endif /* CONFIG_IWL4965_HT_AGG */
3083#endif /*CONFIG_IWL4965_HT */
3084
Zhu Yib481de92007-09-25 17:54:57 -07003085
3086 if (!ieee80211_get_morefrag(hdr)) {
3087 txq->need_update = 1;
3088 if (qc) {
3089 u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
3090 priv->stations[sta_id].tid[tid].seq_number = seq_number;
3091 }
3092 } else {
3093 wait_write_ptr = 1;
3094 txq->need_update = 0;
3095 }
3096
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003097 iwl4965_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload,
Zhu Yib481de92007-09-25 17:54:57 -07003098 sizeof(out_cmd->cmd.tx));
3099
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003100 iwl4965_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr,
Zhu Yib481de92007-09-25 17:54:57 -07003101 ieee80211_get_hdrlen(fc));
3102
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003103 /* Set up entry for this TFD in Tx byte-count array */
Zhu Yib481de92007-09-25 17:54:57 -07003104 iwl4965_tx_queue_update_wr_ptr(priv, txq, len);
3105
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003106 /* Tell device the write index *just past* this latest filled TFD */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003107 q->write_ptr = iwl4965_queue_inc_wrap(q->write_ptr, q->n_bd);
3108 rc = iwl4965_tx_queue_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07003109 spin_unlock_irqrestore(&priv->lock, flags);
3110
3111 if (rc)
3112 return rc;
3113
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003114 if ((iwl4965_queue_space(q) < q->high_mark)
Zhu Yib481de92007-09-25 17:54:57 -07003115 && priv->mac80211_registered) {
3116 if (wait_write_ptr) {
3117 spin_lock_irqsave(&priv->lock, flags);
3118 txq->need_update = 1;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003119 iwl4965_tx_queue_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07003120 spin_unlock_irqrestore(&priv->lock, flags);
3121 }
3122
3123 ieee80211_stop_queue(priv->hw, ctl->queue);
3124 }
3125
3126 return 0;
3127
3128drop_unlock:
3129 spin_unlock_irqrestore(&priv->lock, flags);
3130drop:
3131 return -1;
3132}
3133
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003134static void iwl4965_set_rate(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003135{
3136 const struct ieee80211_hw_mode *hw = NULL;
3137 struct ieee80211_rate *rate;
3138 int i;
3139
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003140 hw = iwl4965_get_hw_mode(priv, priv->phymode);
Saleem Abdulrasoolc4ba9622007-11-18 23:59:08 -08003141 if (!hw) {
3142 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
3143 return;
3144 }
Zhu Yib481de92007-09-25 17:54:57 -07003145
3146 priv->active_rate = 0;
3147 priv->active_rate_basic = 0;
3148
3149 IWL_DEBUG_RATE("Setting rates for 802.11%c\n",
3150 hw->mode == MODE_IEEE80211A ?
3151 'a' : ((hw->mode == MODE_IEEE80211B) ? 'b' : 'g'));
3152
3153 for (i = 0; i < hw->num_rates; i++) {
3154 rate = &(hw->rates[i]);
3155 if ((rate->val < IWL_RATE_COUNT) &&
3156 (rate->flags & IEEE80211_RATE_SUPPORTED)) {
3157 IWL_DEBUG_RATE("Adding rate index %d (plcp %d)%s\n",
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003158 rate->val, iwl4965_rates[rate->val].plcp,
Zhu Yib481de92007-09-25 17:54:57 -07003159 (rate->flags & IEEE80211_RATE_BASIC) ?
3160 "*" : "");
3161 priv->active_rate |= (1 << rate->val);
3162 if (rate->flags & IEEE80211_RATE_BASIC)
3163 priv->active_rate_basic |= (1 << rate->val);
3164 } else
3165 IWL_DEBUG_RATE("Not adding rate %d (plcp %d)\n",
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003166 rate->val, iwl4965_rates[rate->val].plcp);
Zhu Yib481de92007-09-25 17:54:57 -07003167 }
3168
3169 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
3170 priv->active_rate, priv->active_rate_basic);
3171
3172 /*
3173 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
3174 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
3175 * OFDM
3176 */
3177 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
3178 priv->staging_rxon.cck_basic_rates =
3179 ((priv->active_rate_basic &
3180 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
3181 else
3182 priv->staging_rxon.cck_basic_rates =
3183 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
3184
3185 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
3186 priv->staging_rxon.ofdm_basic_rates =
3187 ((priv->active_rate_basic &
3188 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
3189 IWL_FIRST_OFDM_RATE) & 0xFF;
3190 else
3191 priv->staging_rxon.ofdm_basic_rates =
3192 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
3193}
3194
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003195static void iwl4965_radio_kill_sw(struct iwl4965_priv *priv, int disable_radio)
Zhu Yib481de92007-09-25 17:54:57 -07003196{
3197 unsigned long flags;
3198
3199 if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
3200 return;
3201
3202 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
3203 disable_radio ? "OFF" : "ON");
3204
3205 if (disable_radio) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003206 iwl4965_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003207 /* FIXME: This is a workaround for AP */
3208 if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
3209 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003210 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07003211 CSR_UCODE_SW_BIT_RFKILL);
3212 spin_unlock_irqrestore(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003213 iwl4965_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003214 set_bit(STATUS_RF_KILL_SW, &priv->status);
3215 }
3216 return;
3217 }
3218
3219 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003220 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07003221
3222 clear_bit(STATUS_RF_KILL_SW, &priv->status);
3223 spin_unlock_irqrestore(&priv->lock, flags);
3224
3225 /* wake up ucode */
3226 msleep(10);
3227
3228 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003229 iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
3230 if (!iwl4965_grab_nic_access(priv))
3231 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003232 spin_unlock_irqrestore(&priv->lock, flags);
3233
3234 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
3235 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
3236 "disabled by HW switch\n");
3237 return;
3238 }
3239
3240 queue_work(priv->workqueue, &priv->restart);
3241 return;
3242}
3243
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003244void iwl4965_set_decrypted_flag(struct iwl4965_priv *priv, struct sk_buff *skb,
Zhu Yib481de92007-09-25 17:54:57 -07003245 u32 decrypt_res, struct ieee80211_rx_status *stats)
3246{
3247 u16 fc =
3248 le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control);
3249
3250 if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
3251 return;
3252
3253 if (!(fc & IEEE80211_FCTL_PROTECTED))
3254 return;
3255
3256 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
3257 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
3258 case RX_RES_STATUS_SEC_TYPE_TKIP:
3259 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
3260 RX_RES_STATUS_BAD_ICV_MIC)
3261 stats->flag |= RX_FLAG_MMIC_ERROR;
3262 case RX_RES_STATUS_SEC_TYPE_WEP:
3263 case RX_RES_STATUS_SEC_TYPE_CCMP:
3264 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
3265 RX_RES_STATUS_DECRYPT_OK) {
3266 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
3267 stats->flag |= RX_FLAG_DECRYPTED;
3268 }
3269 break;
3270
3271 default:
3272 break;
3273 }
3274}
3275
Zhu Yib481de92007-09-25 17:54:57 -07003276
3277#define IWL_PACKET_RETRY_TIME HZ
3278
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003279int iwl4965_is_duplicate_packet(struct iwl4965_priv *priv, struct ieee80211_hdr *header)
Zhu Yib481de92007-09-25 17:54:57 -07003280{
3281 u16 sc = le16_to_cpu(header->seq_ctrl);
3282 u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
3283 u16 frag = sc & IEEE80211_SCTL_FRAG;
3284 u16 *last_seq, *last_frag;
3285 unsigned long *last_time;
3286
3287 switch (priv->iw_mode) {
3288 case IEEE80211_IF_TYPE_IBSS:{
3289 struct list_head *p;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003290 struct iwl4965_ibss_seq *entry = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07003291 u8 *mac = header->addr2;
3292 int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1);
3293
3294 __list_for_each(p, &priv->ibss_mac_hash[index]) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003295 entry = list_entry(p, struct iwl4965_ibss_seq, list);
Zhu Yib481de92007-09-25 17:54:57 -07003296 if (!compare_ether_addr(entry->mac, mac))
3297 break;
3298 }
3299 if (p == &priv->ibss_mac_hash[index]) {
3300 entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
3301 if (!entry) {
Ian Schrambc434dd2007-10-25 17:15:29 +08003302 IWL_ERROR("Cannot malloc new mac entry\n");
Zhu Yib481de92007-09-25 17:54:57 -07003303 return 0;
3304 }
3305 memcpy(entry->mac, mac, ETH_ALEN);
3306 entry->seq_num = seq;
3307 entry->frag_num = frag;
3308 entry->packet_time = jiffies;
Ian Schrambc434dd2007-10-25 17:15:29 +08003309 list_add(&entry->list, &priv->ibss_mac_hash[index]);
Zhu Yib481de92007-09-25 17:54:57 -07003310 return 0;
3311 }
3312 last_seq = &entry->seq_num;
3313 last_frag = &entry->frag_num;
3314 last_time = &entry->packet_time;
3315 break;
3316 }
3317 case IEEE80211_IF_TYPE_STA:
3318 last_seq = &priv->last_seq_num;
3319 last_frag = &priv->last_frag_num;
3320 last_time = &priv->last_packet_time;
3321 break;
3322 default:
3323 return 0;
3324 }
3325 if ((*last_seq == seq) &&
3326 time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) {
3327 if (*last_frag == frag)
3328 goto drop;
3329 if (*last_frag + 1 != frag)
3330 /* out-of-order fragment */
3331 goto drop;
3332 } else
3333 *last_seq = seq;
3334
3335 *last_frag = frag;
3336 *last_time = jiffies;
3337 return 0;
3338
3339 drop:
3340 return 1;
3341}
3342
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003343#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07003344
3345#include "iwl-spectrum.h"
3346
3347#define BEACON_TIME_MASK_LOW 0x00FFFFFF
3348#define BEACON_TIME_MASK_HIGH 0xFF000000
3349#define TIME_UNIT 1024
3350
3351/*
3352 * extended beacon time format
3353 * time in usec will be changed into a 32-bit value in 8:24 format
3354 * the high 1 byte is the beacon counts
3355 * the lower 3 bytes is the time in usec within one beacon interval
3356 */
3357
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003358static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07003359{
3360 u32 quot;
3361 u32 rem;
3362 u32 interval = beacon_interval * 1024;
3363
3364 if (!interval || !usec)
3365 return 0;
3366
3367 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
3368 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
3369
3370 return (quot << 24) + rem;
3371}
3372
3373/* base is usually what we get from ucode with each received frame,
3374 * the same as HW timer counter counting down
3375 */
3376
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003377static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07003378{
3379 u32 base_low = base & BEACON_TIME_MASK_LOW;
3380 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
3381 u32 interval = beacon_interval * TIME_UNIT;
3382 u32 res = (base & BEACON_TIME_MASK_HIGH) +
3383 (addon & BEACON_TIME_MASK_HIGH);
3384
3385 if (base_low > addon_low)
3386 res += base_low - addon_low;
3387 else if (base_low < addon_low) {
3388 res += interval + base_low - addon_low;
3389 res += (1 << 24);
3390 } else
3391 res += (1 << 24);
3392
3393 return cpu_to_le32(res);
3394}
3395
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003396static int iwl4965_get_measurement(struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07003397 struct ieee80211_measurement_params *params,
3398 u8 type)
3399{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003400 struct iwl4965_spectrum_cmd spectrum;
3401 struct iwl4965_rx_packet *res;
3402 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07003403 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
3404 .data = (void *)&spectrum,
3405 .meta.flags = CMD_WANT_SKB,
3406 };
3407 u32 add_time = le64_to_cpu(params->start_time);
3408 int rc;
3409 int spectrum_resp_status;
3410 int duration = le16_to_cpu(params->duration);
3411
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003412 if (iwl4965_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003413 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003414 iwl4965_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -07003415 le64_to_cpu(params->start_time) - priv->last_tsf,
3416 le16_to_cpu(priv->rxon_timing.beacon_interval));
3417
3418 memset(&spectrum, 0, sizeof(spectrum));
3419
3420 spectrum.channel_count = cpu_to_le16(1);
3421 spectrum.flags =
3422 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
3423 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
3424 cmd.len = sizeof(spectrum);
3425 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
3426
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003427 if (iwl4965_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003428 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003429 iwl4965_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -07003430 add_time,
3431 le16_to_cpu(priv->rxon_timing.beacon_interval));
3432 else
3433 spectrum.start_time = 0;
3434
3435 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
3436 spectrum.channels[0].channel = params->channel;
3437 spectrum.channels[0].type = type;
3438 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
3439 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
3440 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
3441
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003442 rc = iwl4965_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07003443 if (rc)
3444 return rc;
3445
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003446 res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07003447 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
3448 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
3449 rc = -EIO;
3450 }
3451
3452 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
3453 switch (spectrum_resp_status) {
3454 case 0: /* Command will be handled */
3455 if (res->u.spectrum.id != 0xff) {
3456 IWL_DEBUG_INFO
3457 ("Replaced existing measurement: %d\n",
3458 res->u.spectrum.id);
3459 priv->measurement_status &= ~MEASUREMENT_READY;
3460 }
3461 priv->measurement_status |= MEASUREMENT_ACTIVE;
3462 rc = 0;
3463 break;
3464
3465 case 1: /* Command will not be handled */
3466 rc = -EAGAIN;
3467 break;
3468 }
3469
3470 dev_kfree_skb_any(cmd.meta.u.skb);
3471
3472 return rc;
3473}
3474#endif
3475
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003476static void iwl4965_txstatus_to_ieee(struct iwl4965_priv *priv,
3477 struct iwl4965_tx_info *tx_sta)
Zhu Yib481de92007-09-25 17:54:57 -07003478{
3479
3480 tx_sta->status.ack_signal = 0;
3481 tx_sta->status.excessive_retries = 0;
3482 tx_sta->status.queue_length = 0;
3483 tx_sta->status.queue_number = 0;
3484
3485 if (in_interrupt())
3486 ieee80211_tx_status_irqsafe(priv->hw,
3487 tx_sta->skb[0], &(tx_sta->status));
3488 else
3489 ieee80211_tx_status(priv->hw,
3490 tx_sta->skb[0], &(tx_sta->status));
3491
3492 tx_sta->skb[0] = NULL;
3493}
3494
3495/**
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003496 * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
Zhu Yib481de92007-09-25 17:54:57 -07003497 *
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003498 * When FW advances 'R' index, all entries between old and new 'R' index
3499 * need to be reclaimed. As result, some free space forms. If there is
3500 * enough free space (> low mark), wake the stack that feeds us.
Zhu Yib481de92007-09-25 17:54:57 -07003501 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003502int iwl4965_tx_queue_reclaim(struct iwl4965_priv *priv, int txq_id, int index)
Zhu Yib481de92007-09-25 17:54:57 -07003503{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003504 struct iwl4965_tx_queue *txq = &priv->txq[txq_id];
3505 struct iwl4965_queue *q = &txq->q;
Zhu Yib481de92007-09-25 17:54:57 -07003506 int nfreed = 0;
3507
3508 if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) {
3509 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
3510 "is out of range [0-%d] %d %d.\n", txq_id,
Tomas Winklerfc4b6852007-10-25 17:15:24 +08003511 index, q->n_bd, q->write_ptr, q->read_ptr);
Zhu Yib481de92007-09-25 17:54:57 -07003512 return 0;
3513 }
3514
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003515 for (index = iwl4965_queue_inc_wrap(index, q->n_bd);
Tomas Winklerfc4b6852007-10-25 17:15:24 +08003516 q->read_ptr != index;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003517 q->read_ptr = iwl4965_queue_inc_wrap(q->read_ptr, q->n_bd)) {
Zhu Yib481de92007-09-25 17:54:57 -07003518 if (txq_id != IWL_CMD_QUEUE_NUM) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003519 iwl4965_txstatus_to_ieee(priv,
Tomas Winklerfc4b6852007-10-25 17:15:24 +08003520 &(txq->txb[txq->q.read_ptr]));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003521 iwl4965_hw_txq_free_tfd(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07003522 } else if (nfreed > 1) {
3523 IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index,
Tomas Winklerfc4b6852007-10-25 17:15:24 +08003524 q->write_ptr, q->read_ptr);
Zhu Yib481de92007-09-25 17:54:57 -07003525 queue_work(priv->workqueue, &priv->restart);
3526 }
3527 nfreed++;
3528 }
3529
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003530/* if (iwl4965_queue_space(q) > q->low_mark && (txq_id >= 0) &&
Zhu Yib481de92007-09-25 17:54:57 -07003531 (txq_id != IWL_CMD_QUEUE_NUM) &&
3532 priv->mac80211_registered)
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003533 ieee80211_wake_queue(priv->hw, txq_id); */
Zhu Yib481de92007-09-25 17:54:57 -07003534
3535
3536 return nfreed;
3537}
3538
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003539static int iwl4965_is_tx_success(u32 status)
Zhu Yib481de92007-09-25 17:54:57 -07003540{
3541 status &= TX_STATUS_MSK;
3542 return (status == TX_STATUS_SUCCESS)
3543 || (status == TX_STATUS_DIRECT_DONE);
3544}
3545
3546/******************************************************************************
3547 *
3548 * Generic RX handler implementations
3549 *
3550 ******************************************************************************/
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003551#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -07003552
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003553static inline int iwl4965_get_ra_sta_id(struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07003554 struct ieee80211_hdr *hdr)
3555{
3556 if (priv->iw_mode == IEEE80211_IF_TYPE_STA)
3557 return IWL_AP_ID;
3558 else {
3559 u8 *da = ieee80211_get_DA(hdr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003560 return iwl4965_hw_find_station(priv, da);
Zhu Yib481de92007-09-25 17:54:57 -07003561 }
3562}
3563
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003564static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr(
3565 struct iwl4965_priv *priv, int txq_id, int idx)
Zhu Yib481de92007-09-25 17:54:57 -07003566{
3567 if (priv->txq[txq_id].txb[idx].skb[0])
3568 return (struct ieee80211_hdr *)priv->txq[txq_id].
3569 txb[idx].skb[0]->data;
3570 return NULL;
3571}
3572
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003573static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp)
Zhu Yib481de92007-09-25 17:54:57 -07003574{
3575 __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status +
3576 tx_resp->frame_count);
3577 return le32_to_cpu(*scd_ssn) & MAX_SN;
3578
3579}
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003580
3581/**
3582 * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue
3583 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003584static int iwl4965_tx_status_reply_tx(struct iwl4965_priv *priv,
3585 struct iwl4965_ht_agg *agg,
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003586 struct iwl4965_tx_resp_agg *tx_resp,
Zhu Yib481de92007-09-25 17:54:57 -07003587 u16 start_idx)
3588{
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003589 u16 status;
3590 struct agg_tx_status *frame_status = &tx_resp->status;
Zhu Yib481de92007-09-25 17:54:57 -07003591 struct ieee80211_tx_status *tx_status = NULL;
3592 struct ieee80211_hdr *hdr = NULL;
3593 int i, sh;
3594 int txq_id, idx;
3595 u16 seq;
3596
3597 if (agg->wait_for_ba)
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003598 IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
Zhu Yib481de92007-09-25 17:54:57 -07003599
3600 agg->frame_count = tx_resp->frame_count;
3601 agg->start_idx = start_idx;
3602 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003603 agg->bitmap = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003604
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003605 /* # frames attempted by Tx command */
Zhu Yib481de92007-09-25 17:54:57 -07003606 if (agg->frame_count == 1) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003607 /* Only one frame was attempted; no block-ack will arrive */
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003608 status = le16_to_cpu(frame_status[0].status);
3609 seq = le16_to_cpu(frame_status[0].sequence);
3610 idx = SEQ_TO_INDEX(seq);
3611 txq_id = SEQ_TO_QUEUE(seq);
Zhu Yib481de92007-09-25 17:54:57 -07003612
Zhu Yib481de92007-09-25 17:54:57 -07003613 /* FIXME: code repetition */
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003614 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
3615 agg->frame_count, agg->start_idx, idx);
Zhu Yib481de92007-09-25 17:54:57 -07003616
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003617 tx_status = &(priv->txq[txq_id].txb[idx].status);
Zhu Yib481de92007-09-25 17:54:57 -07003618 tx_status->retry_count = tx_resp->failure_frame;
3619 tx_status->queue_number = status & 0xff;
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003620 tx_status->queue_length = tx_resp->failure_rts;
3621 tx_status->control.flags &= ~IEEE80211_TXCTL_AMPDU;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003622 tx_status->flags = iwl4965_is_tx_success(status)?
Zhu Yib481de92007-09-25 17:54:57 -07003623 IEEE80211_TX_STATUS_ACK : 0;
3624 tx_status->control.tx_rate =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003625 iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -07003626 /* FIXME: code repetition end */
3627
3628 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
3629 status & 0xff, tx_resp->failure_frame);
3630 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003631 iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags));
Zhu Yib481de92007-09-25 17:54:57 -07003632
3633 agg->wait_for_ba = 0;
3634 } else {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003635 /* Two or more frames were attempted; expect block-ack */
Zhu Yib481de92007-09-25 17:54:57 -07003636 u64 bitmap = 0;
3637 int start = agg->start_idx;
3638
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003639 /* Construct bit-map of pending frames within Tx window */
Zhu Yib481de92007-09-25 17:54:57 -07003640 for (i = 0; i < agg->frame_count; i++) {
3641 u16 sc;
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003642 status = le16_to_cpu(frame_status[i].status);
3643 seq = le16_to_cpu(frame_status[i].sequence);
Zhu Yib481de92007-09-25 17:54:57 -07003644 idx = SEQ_TO_INDEX(seq);
3645 txq_id = SEQ_TO_QUEUE(seq);
3646
3647 if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
3648 AGG_TX_STATE_ABORT_MSK))
3649 continue;
3650
3651 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
3652 agg->frame_count, txq_id, idx);
3653
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003654 hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx);
Zhu Yib481de92007-09-25 17:54:57 -07003655
3656 sc = le16_to_cpu(hdr->seq_ctrl);
3657 if (idx != (SEQ_TO_SN(sc) & 0xff)) {
3658 IWL_ERROR("BUG_ON idx doesn't match seq control"
3659 " idx=%d, seq_idx=%d, seq=%d\n",
3660 idx, SEQ_TO_SN(sc),
3661 hdr->seq_ctrl);
3662 return -1;
3663 }
3664
3665 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
3666 i, idx, SEQ_TO_SN(sc));
3667
3668 sh = idx - start;
3669 if (sh > 64) {
3670 sh = (start - idx) + 0xff;
3671 bitmap = bitmap << sh;
3672 sh = 0;
3673 start = idx;
3674 } else if (sh < -64)
3675 sh = 0xff - (start - idx);
3676 else if (sh < 0) {
3677 sh = start - idx;
3678 start = idx;
3679 bitmap = bitmap << sh;
3680 sh = 0;
3681 }
3682 bitmap |= (1 << sh);
3683 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
3684 start, (u32)(bitmap & 0xFFFFFFFF));
3685 }
3686
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003687 agg->bitmap = bitmap;
Zhu Yib481de92007-09-25 17:54:57 -07003688 agg->start_idx = start;
3689 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003690 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
Zhu Yib481de92007-09-25 17:54:57 -07003691 agg->frame_count, agg->start_idx,
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003692 agg->bitmap);
Zhu Yib481de92007-09-25 17:54:57 -07003693
3694 if (bitmap)
3695 agg->wait_for_ba = 1;
3696 }
3697 return 0;
3698}
3699#endif
Zhu Yib481de92007-09-25 17:54:57 -07003700
Cahill, Ben M6440adb2007-11-29 11:09:55 +08003701/**
3702 * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
3703 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003704static void iwl4965_rx_reply_tx(struct iwl4965_priv *priv,
3705 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003706{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003707 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07003708 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
3709 int txq_id = SEQ_TO_QUEUE(sequence);
3710 int index = SEQ_TO_INDEX(sequence);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003711 struct iwl4965_tx_queue *txq = &priv->txq[txq_id];
Zhu Yib481de92007-09-25 17:54:57 -07003712 struct ieee80211_tx_status *tx_status;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003713 struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
Zhu Yib481de92007-09-25 17:54:57 -07003714 u32 status = le32_to_cpu(tx_resp->status);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003715#ifdef CONFIG_IWL4965_HT
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003716 int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION;
3717 struct ieee80211_hdr *hdr;
3718 __le16 *qc;
Zhu Yib481de92007-09-25 17:54:57 -07003719#endif
3720
3721 if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) {
3722 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
3723 "is out of range [0-%d] %d %d\n", txq_id,
Tomas Winklerfc4b6852007-10-25 17:15:24 +08003724 index, txq->q.n_bd, txq->q.write_ptr,
3725 txq->q.read_ptr);
Zhu Yib481de92007-09-25 17:54:57 -07003726 return;
3727 }
3728
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003729#ifdef CONFIG_IWL4965_HT
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003730 hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, index);
3731 qc = ieee80211_get_qos_ctrl(hdr);
Zhu Yib481de92007-09-25 17:54:57 -07003732
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003733 if (qc)
Zhu Yib481de92007-09-25 17:54:57 -07003734 tid = le16_to_cpu(*qc) & 0xf;
3735
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003736 sta_id = iwl4965_get_ra_sta_id(priv, hdr);
3737 if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) {
3738 IWL_ERROR("Station not known\n");
3739 return;
3740 }
3741
3742 if (txq->sched_retry) {
3743 const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp);
3744 struct iwl4965_ht_agg *agg = NULL;
3745
3746 if (!qc)
Zhu Yib481de92007-09-25 17:54:57 -07003747 return;
Zhu Yib481de92007-09-25 17:54:57 -07003748
3749 agg = &priv->stations[sta_id].tid[tid].agg;
3750
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003751 iwl4965_tx_status_reply_tx(priv, agg,
3752 (struct iwl4965_tx_resp_agg *)tx_resp, index);
Zhu Yib481de92007-09-25 17:54:57 -07003753
3754 if ((tx_resp->frame_count == 1) &&
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003755 !iwl4965_is_tx_success(status)) {
Zhu Yib481de92007-09-25 17:54:57 -07003756 /* TODO: send BAR */
3757 }
3758
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003759 if (txq->q.read_ptr != (scd_ssn & 0xff)) {
3760 int freed;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003761 index = iwl4965_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
Zhu Yib481de92007-09-25 17:54:57 -07003762 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
3763 "%d index %d\n", scd_ssn , index);
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003764 freed = iwl4965_tx_queue_reclaim(priv, txq_id, index);
3765 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
3766
3767 if (iwl4965_queue_space(&txq->q) > txq->q.low_mark &&
3768 txq_id >= 0 && priv->mac80211_registered &&
3769 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)
3770 ieee80211_wake_queue(priv->hw, txq_id);
3771
3772 iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id);
Zhu Yib481de92007-09-25 17:54:57 -07003773 }
3774 } else {
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003775#endif /* CONFIG_IWL4965_HT */
Tomas Winklerfc4b6852007-10-25 17:15:24 +08003776 tx_status = &(txq->txb[txq->q.read_ptr].status);
Zhu Yib481de92007-09-25 17:54:57 -07003777
3778 tx_status->retry_count = tx_resp->failure_frame;
3779 tx_status->queue_number = status;
3780 tx_status->queue_length = tx_resp->bt_kill_count;
3781 tx_status->queue_length |= tx_resp->failure_rts;
3782
3783 tx_status->flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003784 iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0;
Zhu Yib481de92007-09-25 17:54:57 -07003785
3786 tx_status->control.tx_rate =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003787 iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -07003788
3789 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x "
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003790 "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status),
Zhu Yib481de92007-09-25 17:54:57 -07003791 status, le32_to_cpu(tx_resp->rate_n_flags),
3792 tx_resp->failure_frame);
3793
3794 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003795 if (index != -1) {
3796 int freed = iwl4965_tx_queue_reclaim(priv, txq_id, index);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003797#ifdef CONFIG_IWL4965_HT
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003798 if (tid != MAX_TID_COUNT)
3799 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
3800 if (iwl4965_queue_space(&txq->q) > txq->q.low_mark &&
3801 (txq_id >= 0) &&
3802 priv->mac80211_registered)
3803 ieee80211_wake_queue(priv->hw, txq_id);
3804 if (tid != MAX_TID_COUNT)
3805 iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id);
3806#endif
Zhu Yib481de92007-09-25 17:54:57 -07003807 }
Ron Rindjunskyfe01b472008-01-28 14:07:24 +02003808#ifdef CONFIG_IWL4965_HT
3809 }
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003810#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07003811
3812 if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
3813 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
3814}
3815
3816
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003817static void iwl4965_rx_reply_alive(struct iwl4965_priv *priv,
3818 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003819{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003820 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3821 struct iwl4965_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -07003822 struct delayed_work *pwork;
3823
3824 palive = &pkt->u.alive_frame;
3825
3826 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
3827 "0x%01X 0x%01X\n",
3828 palive->is_valid, palive->ver_type,
3829 palive->ver_subtype);
3830
3831 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
3832 IWL_DEBUG_INFO("Initialization Alive received.\n");
3833 memcpy(&priv->card_alive_init,
3834 &pkt->u.alive_frame,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003835 sizeof(struct iwl4965_init_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07003836 pwork = &priv->init_alive_start;
3837 } else {
3838 IWL_DEBUG_INFO("Runtime Alive received.\n");
3839 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003840 sizeof(struct iwl4965_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07003841 pwork = &priv->alive_start;
3842 }
3843
3844 /* We delay the ALIVE response by 5ms to
3845 * give the HW RF Kill time to activate... */
3846 if (palive->is_valid == UCODE_VALID_OK)
3847 queue_delayed_work(priv->workqueue, pwork,
3848 msecs_to_jiffies(5));
3849 else
3850 IWL_WARNING("uCode did not respond OK.\n");
3851}
3852
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003853static void iwl4965_rx_reply_add_sta(struct iwl4965_priv *priv,
3854 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003855{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003856 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07003857
3858 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
3859 return;
3860}
3861
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003862static void iwl4965_rx_reply_error(struct iwl4965_priv *priv,
3863 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003864{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003865 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07003866
3867 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
3868 "seq 0x%04X ser 0x%08X\n",
3869 le32_to_cpu(pkt->u.err_resp.error_type),
3870 get_cmd_string(pkt->u.err_resp.cmd_id),
3871 pkt->u.err_resp.cmd_id,
3872 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
3873 le32_to_cpu(pkt->u.err_resp.error_info));
3874}
3875
3876#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
3877
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003878static void iwl4965_rx_csa(struct iwl4965_priv *priv, struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003879{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003880 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3881 struct iwl4965_rxon_cmd *rxon = (void *)&priv->active_rxon;
3882 struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif);
Zhu Yib481de92007-09-25 17:54:57 -07003883 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
3884 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
3885 rxon->channel = csa->channel;
3886 priv->staging_rxon.channel = csa->channel;
3887}
3888
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003889static void iwl4965_rx_spectrum_measure_notif(struct iwl4965_priv *priv,
3890 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003891{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003892#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003893 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3894 struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif);
Zhu Yib481de92007-09-25 17:54:57 -07003895
3896 if (!report->state) {
3897 IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO,
3898 "Spectrum Measure Notification: Start\n");
3899 return;
3900 }
3901
3902 memcpy(&priv->measure_report, report, sizeof(*report));
3903 priv->measurement_status |= MEASUREMENT_READY;
3904#endif
3905}
3906
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003907static void iwl4965_rx_pm_sleep_notif(struct iwl4965_priv *priv,
3908 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003909{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003910#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003911 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3912 struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif);
Zhu Yib481de92007-09-25 17:54:57 -07003913 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
3914 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
3915#endif
3916}
3917
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003918static void iwl4965_rx_pm_debug_statistics_notif(struct iwl4965_priv *priv,
3919 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003920{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003921 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07003922 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
3923 "notification for %s:\n",
3924 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003925 iwl4965_print_hex_dump(IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
Zhu Yib481de92007-09-25 17:54:57 -07003926}
3927
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003928static void iwl4965_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07003929{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003930 struct iwl4965_priv *priv =
3931 container_of(work, struct iwl4965_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07003932 struct sk_buff *beacon;
3933
3934 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berg32bfd352007-12-19 01:31:26 +01003935 beacon = ieee80211_beacon_get(priv->hw, priv->vif, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07003936
3937 if (!beacon) {
3938 IWL_ERROR("update beacon failed\n");
3939 return;
3940 }
3941
3942 mutex_lock(&priv->mutex);
3943 /* new beacon skb is allocated every time; dispose previous.*/
3944 if (priv->ibss_beacon)
3945 dev_kfree_skb(priv->ibss_beacon);
3946
3947 priv->ibss_beacon = beacon;
3948 mutex_unlock(&priv->mutex);
3949
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003950 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003951}
3952
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003953static void iwl4965_rx_beacon_notif(struct iwl4965_priv *priv,
3954 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003955{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003956#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003957 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3958 struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status);
3959 u8 rate = iwl4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -07003960
3961 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
3962 "tsf %d %d rate %d\n",
3963 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
3964 beacon->beacon_notify_hdr.failure_frame,
3965 le32_to_cpu(beacon->ibss_mgr_status),
3966 le32_to_cpu(beacon->high_tsf),
3967 le32_to_cpu(beacon->low_tsf), rate);
3968#endif
3969
3970 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
3971 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
3972 queue_work(priv->workqueue, &priv->beacon_update);
3973}
3974
3975/* Service response to REPLY_SCAN_CMD (0x80) */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003976static void iwl4965_rx_reply_scan(struct iwl4965_priv *priv,
3977 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003978{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003979#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003980 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3981 struct iwl4965_scanreq_notification *notif =
3982 (struct iwl4965_scanreq_notification *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07003983
3984 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status);
3985#endif
3986}
3987
3988/* Service SCAN_START_NOTIFICATION (0x82) */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003989static void iwl4965_rx_scan_start_notif(struct iwl4965_priv *priv,
3990 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07003991{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003992 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3993 struct iwl4965_scanstart_notification *notif =
3994 (struct iwl4965_scanstart_notification *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07003995 priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
3996 IWL_DEBUG_SCAN("Scan start: "
3997 "%d [802.11%s] "
3998 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
3999 notif->channel,
4000 notif->band ? "bg" : "a",
4001 notif->tsf_high,
4002 notif->tsf_low, notif->status, notif->beacon_timer);
4003}
4004
4005/* Service SCAN_RESULTS_NOTIFICATION (0x83) */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004006static void iwl4965_rx_scan_results_notif(struct iwl4965_priv *priv,
4007 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07004008{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004009 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
4010 struct iwl4965_scanresults_notification *notif =
4011 (struct iwl4965_scanresults_notification *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07004012
4013 IWL_DEBUG_SCAN("Scan ch.res: "
4014 "%d [802.11%s] "
4015 "(TSF: 0x%08X:%08X) - %d "
4016 "elapsed=%lu usec (%dms since last)\n",
4017 notif->channel,
4018 notif->band ? "bg" : "a",
4019 le32_to_cpu(notif->tsf_high),
4020 le32_to_cpu(notif->tsf_low),
4021 le32_to_cpu(notif->statistics[0]),
4022 le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
4023 jiffies_to_msecs(elapsed_jiffies
4024 (priv->last_scan_jiffies, jiffies)));
4025
4026 priv->last_scan_jiffies = jiffies;
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08004027 priv->next_scan_jiffies = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004028}
4029
4030/* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004031static void iwl4965_rx_scan_complete_notif(struct iwl4965_priv *priv,
4032 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07004033{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004034 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
4035 struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
Zhu Yib481de92007-09-25 17:54:57 -07004036
4037 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
4038 scan_notif->scanned_channels,
4039 scan_notif->tsf_low,
4040 scan_notif->tsf_high, scan_notif->status);
4041
4042 /* The HW is no longer scanning */
4043 clear_bit(STATUS_SCAN_HW, &priv->status);
4044
4045 /* The scan completion notification came in, so kill that timer... */
4046 cancel_delayed_work(&priv->scan_check);
4047
4048 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
4049 (priv->scan_bands == 2) ? "2.4" : "5.2",
4050 jiffies_to_msecs(elapsed_jiffies
4051 (priv->scan_pass_start, jiffies)));
4052
4053 /* Remove this scanned band from the list
4054 * of pending bands to scan */
4055 priv->scan_bands--;
4056
4057 /* If a request to abort was given, or the scan did not succeed
4058 * then we reset the scan state machine and terminate,
4059 * re-queuing another scan if one has been requested */
4060 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
4061 IWL_DEBUG_INFO("Aborted scan completed.\n");
4062 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
4063 } else {
4064 /* If there are more bands on this scan pass reschedule */
4065 if (priv->scan_bands > 0)
4066 goto reschedule;
4067 }
4068
4069 priv->last_scan_jiffies = jiffies;
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08004070 priv->next_scan_jiffies = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004071 IWL_DEBUG_INFO("Setting scan to off\n");
4072
4073 clear_bit(STATUS_SCANNING, &priv->status);
4074
4075 IWL_DEBUG_INFO("Scan took %dms\n",
4076 jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
4077
4078 queue_work(priv->workqueue, &priv->scan_completed);
4079
4080 return;
4081
4082reschedule:
4083 priv->scan_pass_start = jiffies;
4084 queue_work(priv->workqueue, &priv->request_scan);
4085}
4086
4087/* Handle notification from uCode that card's power state is changing
4088 * due to software, hardware, or critical temperature RFKILL */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004089static void iwl4965_rx_card_state_notif(struct iwl4965_priv *priv,
4090 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07004091{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004092 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07004093 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
4094 unsigned long status = priv->status;
4095
4096 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
4097 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
4098 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
4099
4100 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
4101 RF_CARD_DISABLED)) {
4102
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004103 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07004104 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
4105
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004106 if (!iwl4965_grab_nic_access(priv)) {
4107 iwl4965_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07004108 priv, HBUS_TARG_MBX_C,
4109 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
4110
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004111 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004112 }
4113
4114 if (!(flags & RXON_CARD_DISABLED)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004115 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07004116 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004117 if (!iwl4965_grab_nic_access(priv)) {
4118 iwl4965_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07004119 priv, HBUS_TARG_MBX_C,
4120 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
4121
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004122 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004123 }
4124 }
4125
4126 if (flags & RF_CARD_DISABLED) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004127 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07004128 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004129 iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
4130 if (!iwl4965_grab_nic_access(priv))
4131 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004132 }
4133 }
4134
4135 if (flags & HW_CARD_DISABLED)
4136 set_bit(STATUS_RF_KILL_HW, &priv->status);
4137 else
4138 clear_bit(STATUS_RF_KILL_HW, &priv->status);
4139
4140
4141 if (flags & SW_CARD_DISABLED)
4142 set_bit(STATUS_RF_KILL_SW, &priv->status);
4143 else
4144 clear_bit(STATUS_RF_KILL_SW, &priv->status);
4145
4146 if (!(flags & RXON_CARD_DISABLED))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004147 iwl4965_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004148
4149 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
4150 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
4151 (test_bit(STATUS_RF_KILL_SW, &status) !=
4152 test_bit(STATUS_RF_KILL_SW, &priv->status)))
4153 queue_work(priv->workqueue, &priv->rf_kill);
4154 else
4155 wake_up_interruptible(&priv->wait_command_queue);
4156}
4157
4158/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004159 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07004160 *
4161 * Setup the RX handlers for each of the reply types sent from the uCode
4162 * to the host.
4163 *
4164 * This function chains into the hardware specific files for them to setup
4165 * any hardware specific handlers as well.
4166 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004167static void iwl4965_setup_rx_handlers(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004168{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004169 priv->rx_handlers[REPLY_ALIVE] = iwl4965_rx_reply_alive;
4170 priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta;
4171 priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error;
4172 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa;
Zhu Yib481de92007-09-25 17:54:57 -07004173 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004174 iwl4965_rx_spectrum_measure_notif;
4175 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07004176 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004177 iwl4965_rx_pm_debug_statistics_notif;
4178 priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07004179
Ben Cahill9fbab512007-11-29 11:09:47 +08004180 /*
4181 * The same handler is used for both the REPLY to a discrete
4182 * statistics request from the host as well as for the periodic
4183 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07004184 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004185 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics;
4186 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -07004187
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004188 priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan;
4189 priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif;
Zhu Yib481de92007-09-25 17:54:57 -07004190 priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004191 iwl4965_rx_scan_results_notif;
Zhu Yib481de92007-09-25 17:54:57 -07004192 priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004193 iwl4965_rx_scan_complete_notif;
4194 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif;
4195 priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx;
Zhu Yib481de92007-09-25 17:54:57 -07004196
Ben Cahill9fbab512007-11-29 11:09:47 +08004197 /* Set up hardware specific Rx handlers */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004198 iwl4965_hw_rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004199}
4200
4201/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004202 * iwl4965_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
Zhu Yib481de92007-09-25 17:54:57 -07004203 * @rxb: Rx buffer to reclaim
4204 *
4205 * If an Rx buffer has an async callback associated with it the callback
4206 * will be executed. The attached skb (if present) will only be freed
4207 * if the callback returns 1
4208 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004209static void iwl4965_tx_cmd_complete(struct iwl4965_priv *priv,
4210 struct iwl4965_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07004211{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004212 struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07004213 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
4214 int txq_id = SEQ_TO_QUEUE(sequence);
4215 int index = SEQ_TO_INDEX(sequence);
4216 int huge = sequence & SEQ_HUGE_FRAME;
4217 int cmd_index;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004218 struct iwl4965_cmd *cmd;
Zhu Yib481de92007-09-25 17:54:57 -07004219
4220 /* If a Tx command is being handled and it isn't in the actual
4221 * command queue then there a command routing bug has been introduced
4222 * in the queue management code. */
4223 if (txq_id != IWL_CMD_QUEUE_NUM)
4224 IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
4225 txq_id, pkt->hdr.cmd);
4226 BUG_ON(txq_id != IWL_CMD_QUEUE_NUM);
4227
4228 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
4229 cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
4230
4231 /* Input error checking is done when commands are added to queue. */
4232 if (cmd->meta.flags & CMD_WANT_SKB) {
4233 cmd->meta.source->u.skb = rxb->skb;
4234 rxb->skb = NULL;
4235 } else if (cmd->meta.u.callback &&
4236 !cmd->meta.u.callback(priv, cmd, rxb->skb))
4237 rxb->skb = NULL;
4238
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004239 iwl4965_tx_queue_reclaim(priv, txq_id, index);
Zhu Yib481de92007-09-25 17:54:57 -07004240
4241 if (!(cmd->meta.flags & CMD_ASYNC)) {
4242 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
4243 wake_up_interruptible(&priv->wait_command_queue);
4244 }
4245}
4246
4247/************************** RX-FUNCTIONS ****************************/
4248/*
4249 * Rx theory of operation
4250 *
Ben Cahill9fbab512007-11-29 11:09:47 +08004251 * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs),
4252 * each of which point to Receive Buffers to be filled by 4965. These get
4253 * used not only for Rx frames, but for any command response or notification
4254 * from the 4965. The driver and 4965 manage the Rx buffers by means
4255 * of indexes into the circular buffer.
Zhu Yib481de92007-09-25 17:54:57 -07004256 *
4257 * Rx Queue Indexes
4258 * The host/firmware share two index registers for managing the Rx buffers.
4259 *
4260 * The READ index maps to the first position that the firmware may be writing
4261 * to -- the driver can read up to (but not including) this position and get
4262 * good data.
4263 * The READ index is managed by the firmware once the card is enabled.
4264 *
4265 * The WRITE index maps to the last position the driver has read from -- the
4266 * position preceding WRITE is the last slot the firmware can place a packet.
4267 *
4268 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
4269 * WRITE = READ.
4270 *
Ben Cahill9fbab512007-11-29 11:09:47 +08004271 * During initialization, the host sets up the READ queue position to the first
Zhu Yib481de92007-09-25 17:54:57 -07004272 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4273 *
Ben Cahill9fbab512007-11-29 11:09:47 +08004274 * When the firmware places a packet in a buffer, it will advance the READ index
Zhu Yib481de92007-09-25 17:54:57 -07004275 * and fire the RX interrupt. The driver can then query the READ index and
4276 * process as many packets as possible, moving the WRITE index forward as it
4277 * resets the Rx queue buffers with new memory.
4278 *
4279 * The management in the driver is as follows:
4280 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
4281 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Ian Schram01ebd062007-10-25 17:15:22 +08004282 * to replenish the iwl->rxq->rx_free.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004283 * + In iwl4965_rx_replenish (scheduled) if 'processed' != 'read' then the
Zhu Yib481de92007-09-25 17:54:57 -07004284 * iwl->rxq is replenished and the READ INDEX is updated (updating the
4285 * 'processed' and 'read' driver indexes as well)
4286 * + A received packet is processed and handed to the kernel network stack,
4287 * detached from the iwl->rxq. The driver 'processed' index is updated.
4288 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
4289 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
4290 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
4291 * were enough free buffers and RX_STALLED is set it is cleared.
4292 *
4293 *
4294 * Driver sequence:
4295 *
Ben Cahill9fbab512007-11-29 11:09:47 +08004296 * iwl4965_rx_queue_alloc() Allocates rx_free
4297 * iwl4965_rx_replenish() Replenishes rx_free list from rx_used, and calls
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004298 * iwl4965_rx_queue_restock
Ben Cahill9fbab512007-11-29 11:09:47 +08004299 * iwl4965_rx_queue_restock() Moves available buffers from rx_free into Rx
Zhu Yib481de92007-09-25 17:54:57 -07004300 * queue, updates firmware pointers, and updates
4301 * the WRITE index. If insufficient rx_free buffers
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004302 * are available, schedules iwl4965_rx_replenish
Zhu Yib481de92007-09-25 17:54:57 -07004303 *
4304 * -- enable interrupts --
Ben Cahill9fbab512007-11-29 11:09:47 +08004305 * ISR - iwl4965_rx() Detach iwl4965_rx_mem_buffers from pool up to the
Zhu Yib481de92007-09-25 17:54:57 -07004306 * READ INDEX, detaching the SKB from the pool.
4307 * Moves the packet buffer from queue to rx_used.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004308 * Calls iwl4965_rx_queue_restock to refill any empty
Zhu Yib481de92007-09-25 17:54:57 -07004309 * slots.
4310 * ...
4311 *
4312 */
4313
4314/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004315 * iwl4965_rx_queue_space - Return number of free slots available in queue.
Zhu Yib481de92007-09-25 17:54:57 -07004316 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004317static int iwl4965_rx_queue_space(const struct iwl4965_rx_queue *q)
Zhu Yib481de92007-09-25 17:54:57 -07004318{
4319 int s = q->read - q->write;
4320 if (s <= 0)
4321 s += RX_QUEUE_SIZE;
4322 /* keep some buffer to not confuse full and empty queue */
4323 s -= 2;
4324 if (s < 0)
4325 s = 0;
4326 return s;
4327}
4328
4329/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004330 * iwl4965_rx_queue_update_write_ptr - Update the write pointer for the RX queue
Zhu Yib481de92007-09-25 17:54:57 -07004331 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004332int iwl4965_rx_queue_update_write_ptr(struct iwl4965_priv *priv, struct iwl4965_rx_queue *q)
Zhu Yib481de92007-09-25 17:54:57 -07004333{
4334 u32 reg = 0;
4335 int rc = 0;
4336 unsigned long flags;
4337
4338 spin_lock_irqsave(&q->lock, flags);
4339
4340 if (q->need_update == 0)
4341 goto exit_unlock;
4342
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004343 /* If power-saving is in use, make sure device is awake */
Zhu Yib481de92007-09-25 17:54:57 -07004344 if (test_bit(STATUS_POWER_PMI, &priv->status)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004345 reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
Zhu Yib481de92007-09-25 17:54:57 -07004346
4347 if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004348 iwl4965_set_bit(priv, CSR_GP_CNTRL,
Zhu Yib481de92007-09-25 17:54:57 -07004349 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
4350 goto exit_unlock;
4351 }
4352
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004353 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004354 if (rc)
4355 goto exit_unlock;
4356
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004357 /* Device expects a multiple of 8 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004358 iwl4965_write_direct32(priv, FH_RSCSR_CHNL0_WPTR,
Zhu Yib481de92007-09-25 17:54:57 -07004359 q->write & ~0x7);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004360 iwl4965_release_nic_access(priv);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004361
4362 /* Else device is assumed to be awake */
Zhu Yib481de92007-09-25 17:54:57 -07004363 } else
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004364 /* Device expects a multiple of 8 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004365 iwl4965_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7);
Zhu Yib481de92007-09-25 17:54:57 -07004366
4367
4368 q->need_update = 0;
4369
4370 exit_unlock:
4371 spin_unlock_irqrestore(&q->lock, flags);
4372 return rc;
4373}
4374
4375/**
Ben Cahill9fbab512007-11-29 11:09:47 +08004376 * iwl4965_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
Zhu Yib481de92007-09-25 17:54:57 -07004377 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004378static inline __le32 iwl4965_dma_addr2rbd_ptr(struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07004379 dma_addr_t dma_addr)
4380{
4381 return cpu_to_le32((u32)(dma_addr >> 8));
4382}
4383
4384
4385/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004386 * iwl4965_rx_queue_restock - refill RX queue from pre-allocated pool
Zhu Yib481de92007-09-25 17:54:57 -07004387 *
Ben Cahill9fbab512007-11-29 11:09:47 +08004388 * If there are slots in the RX queue that need to be restocked,
Zhu Yib481de92007-09-25 17:54:57 -07004389 * and we have free pre-allocated buffers, fill the ranks as much
Ben Cahill9fbab512007-11-29 11:09:47 +08004390 * as we can, pulling from rx_free.
Zhu Yib481de92007-09-25 17:54:57 -07004391 *
4392 * This moves the 'write' index forward to catch up with 'processed', and
4393 * also updates the memory address in the firmware to reference the new
4394 * target buffer.
4395 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004396static int iwl4965_rx_queue_restock(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004397{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004398 struct iwl4965_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07004399 struct list_head *element;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004400 struct iwl4965_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07004401 unsigned long flags;
4402 int write, rc;
4403
4404 spin_lock_irqsave(&rxq->lock, flags);
4405 write = rxq->write & ~0x7;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004406 while ((iwl4965_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004407 /* Get next free Rx buffer, remove from free list */
Zhu Yib481de92007-09-25 17:54:57 -07004408 element = rxq->rx_free.next;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004409 rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07004410 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004411
4412 /* Point to Rx buffer via next RBD in circular buffer */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004413 rxq->bd[rxq->write] = iwl4965_dma_addr2rbd_ptr(priv, rxb->dma_addr);
Zhu Yib481de92007-09-25 17:54:57 -07004414 rxq->queue[rxq->write] = rxb;
4415 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
4416 rxq->free_count--;
4417 }
4418 spin_unlock_irqrestore(&rxq->lock, flags);
4419 /* If the pre-allocated buffer pool is dropping low, schedule to
4420 * refill it */
4421 if (rxq->free_count <= RX_LOW_WATERMARK)
4422 queue_work(priv->workqueue, &priv->rx_replenish);
4423
4424
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004425 /* If we've added more space for the firmware to place data, tell it.
4426 * Increment device's write pointer in multiples of 8. */
Zhu Yib481de92007-09-25 17:54:57 -07004427 if ((write != (rxq->write & ~0x7))
4428 || (abs(rxq->write - rxq->read) > 7)) {
4429 spin_lock_irqsave(&rxq->lock, flags);
4430 rxq->need_update = 1;
4431 spin_unlock_irqrestore(&rxq->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004432 rc = iwl4965_rx_queue_update_write_ptr(priv, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07004433 if (rc)
4434 return rc;
4435 }
4436
4437 return 0;
4438}
4439
4440/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004441 * iwl4965_rx_replenish - Move all used packet from rx_used to rx_free
Zhu Yib481de92007-09-25 17:54:57 -07004442 *
4443 * When moving to rx_free an SKB is allocated for the slot.
4444 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004445 * Also restock the Rx queue via iwl4965_rx_queue_restock.
Ian Schram01ebd062007-10-25 17:15:22 +08004446 * This is called as a scheduled work item (except for during initialization)
Zhu Yib481de92007-09-25 17:54:57 -07004447 */
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08004448static void iwl4965_rx_allocate(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004449{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004450 struct iwl4965_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07004451 struct list_head *element;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004452 struct iwl4965_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07004453 unsigned long flags;
4454 spin_lock_irqsave(&rxq->lock, flags);
4455 while (!list_empty(&rxq->rx_used)) {
4456 element = rxq->rx_used.next;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004457 rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004458
4459 /* Alloc a new receive buffer */
Zhu Yib481de92007-09-25 17:54:57 -07004460 rxb->skb =
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02004461 alloc_skb(priv->hw_setting.rx_buf_size,
4462 __GFP_NOWARN | GFP_ATOMIC);
Zhu Yib481de92007-09-25 17:54:57 -07004463 if (!rxb->skb) {
4464 if (net_ratelimit())
4465 printk(KERN_CRIT DRV_NAME
4466 ": Can not allocate SKB buffers\n");
4467 /* We don't reschedule replenish work here -- we will
4468 * call the restock method and if it still needs
4469 * more buffers it will schedule replenish */
4470 break;
4471 }
4472 priv->alloc_rxb_skb++;
4473 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004474
4475 /* Get physical address of RB/SKB */
Zhu Yib481de92007-09-25 17:54:57 -07004476 rxb->dma_addr =
4477 pci_map_single(priv->pci_dev, rxb->skb->data,
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02004478 priv->hw_setting.rx_buf_size, PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07004479 list_add_tail(&rxb->list, &rxq->rx_free);
4480 rxq->free_count++;
4481 }
4482 spin_unlock_irqrestore(&rxq->lock, flags);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08004483}
4484
4485/*
4486 * this should be called while priv->lock is locked
4487*/
Tomas Winkler4fd1f842007-12-05 20:59:58 +02004488static void __iwl4965_rx_replenish(void *data)
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08004489{
4490 struct iwl4965_priv *priv = data;
4491
4492 iwl4965_rx_allocate(priv);
4493 iwl4965_rx_queue_restock(priv);
4494}
4495
4496
4497void iwl4965_rx_replenish(void *data)
4498{
4499 struct iwl4965_priv *priv = data;
4500 unsigned long flags;
4501
4502 iwl4965_rx_allocate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004503
4504 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004505 iwl4965_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004506 spin_unlock_irqrestore(&priv->lock, flags);
4507}
4508
4509/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
Ben Cahill9fbab512007-11-29 11:09:47 +08004510 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
Zhu Yib481de92007-09-25 17:54:57 -07004511 * This free routine walks the list of POOL entries and if SKB is set to
4512 * non NULL it is unmapped and freed
4513 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004514static void iwl4965_rx_queue_free(struct iwl4965_priv *priv, struct iwl4965_rx_queue *rxq)
Zhu Yib481de92007-09-25 17:54:57 -07004515{
4516 int i;
4517 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4518 if (rxq->pool[i].skb != NULL) {
4519 pci_unmap_single(priv->pci_dev,
4520 rxq->pool[i].dma_addr,
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02004521 priv->hw_setting.rx_buf_size,
4522 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07004523 dev_kfree_skb(rxq->pool[i].skb);
4524 }
4525 }
4526
4527 pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd,
4528 rxq->dma_addr);
4529 rxq->bd = NULL;
4530}
4531
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004532int iwl4965_rx_queue_alloc(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004533{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004534 struct iwl4965_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07004535 struct pci_dev *dev = priv->pci_dev;
4536 int i;
4537
4538 spin_lock_init(&rxq->lock);
4539 INIT_LIST_HEAD(&rxq->rx_free);
4540 INIT_LIST_HEAD(&rxq->rx_used);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004541
4542 /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
Zhu Yib481de92007-09-25 17:54:57 -07004543 rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr);
4544 if (!rxq->bd)
4545 return -ENOMEM;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004546
Zhu Yib481de92007-09-25 17:54:57 -07004547 /* Fill the rx_used queue with _all_ of the Rx buffers */
4548 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
4549 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004550
Zhu Yib481de92007-09-25 17:54:57 -07004551 /* Set us so that we have processed and used all buffers, but have
4552 * not restocked the Rx queue with fresh buffers */
4553 rxq->read = rxq->write = 0;
4554 rxq->free_count = 0;
4555 rxq->need_update = 0;
4556 return 0;
4557}
4558
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004559void iwl4965_rx_queue_reset(struct iwl4965_priv *priv, struct iwl4965_rx_queue *rxq)
Zhu Yib481de92007-09-25 17:54:57 -07004560{
4561 unsigned long flags;
4562 int i;
4563 spin_lock_irqsave(&rxq->lock, flags);
4564 INIT_LIST_HEAD(&rxq->rx_free);
4565 INIT_LIST_HEAD(&rxq->rx_used);
4566 /* Fill the rx_used queue with _all_ of the Rx buffers */
4567 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
4568 /* In the reset function, these buffers may have been allocated
4569 * to an SKB, so we need to unmap and free potential storage */
4570 if (rxq->pool[i].skb != NULL) {
4571 pci_unmap_single(priv->pci_dev,
4572 rxq->pool[i].dma_addr,
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02004573 priv->hw_setting.rx_buf_size,
4574 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07004575 priv->alloc_rxb_skb--;
4576 dev_kfree_skb(rxq->pool[i].skb);
4577 rxq->pool[i].skb = NULL;
4578 }
4579 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4580 }
4581
4582 /* Set us so that we have processed and used all buffers, but have
4583 * not restocked the Rx queue with fresh buffers */
4584 rxq->read = rxq->write = 0;
4585 rxq->free_count = 0;
4586 spin_unlock_irqrestore(&rxq->lock, flags);
4587}
4588
4589/* Convert linear signal-to-noise ratio into dB */
4590static u8 ratio2dB[100] = {
4591/* 0 1 2 3 4 5 6 7 8 9 */
4592 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
4593 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
4594 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
4595 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
4596 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
4597 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
4598 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
4599 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
4600 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
4601 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
4602};
4603
4604/* Calculates a relative dB value from a ratio of linear
4605 * (i.e. not dB) signal levels.
4606 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004607int iwl4965_calc_db_from_ratio(int sig_ratio)
Zhu Yib481de92007-09-25 17:54:57 -07004608{
Adrian Bunkc899a572007-10-14 19:51:15 +02004609 /* 1000:1 or higher just report as 60 dB */
4610 if (sig_ratio >= 1000)
Zhu Yib481de92007-09-25 17:54:57 -07004611 return 60;
4612
Adrian Bunkc899a572007-10-14 19:51:15 +02004613 /* 100:1 or higher, divide by 10 and use table,
Zhu Yib481de92007-09-25 17:54:57 -07004614 * add 20 dB to make up for divide by 10 */
Adrian Bunkc899a572007-10-14 19:51:15 +02004615 if (sig_ratio >= 100)
Zhu Yib481de92007-09-25 17:54:57 -07004616 return (20 + (int)ratio2dB[sig_ratio/10]);
4617
4618 /* We shouldn't see this */
4619 if (sig_ratio < 1)
4620 return 0;
4621
4622 /* Use table for ratios 1:1 - 99:1 */
4623 return (int)ratio2dB[sig_ratio];
4624}
4625
4626#define PERFECT_RSSI (-20) /* dBm */
4627#define WORST_RSSI (-95) /* dBm */
4628#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
4629
4630/* Calculate an indication of rx signal quality (a percentage, not dBm!).
4631 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
4632 * about formulas used below. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004633int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm)
Zhu Yib481de92007-09-25 17:54:57 -07004634{
4635 int sig_qual;
4636 int degradation = PERFECT_RSSI - rssi_dbm;
4637
4638 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
4639 * as indicator; formula is (signal dbm - noise dbm).
4640 * SNR at or above 40 is a great signal (100%).
4641 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
4642 * Weakest usable signal is usually 10 - 15 dB SNR. */
4643 if (noise_dbm) {
4644 if (rssi_dbm - noise_dbm >= 40)
4645 return 100;
4646 else if (rssi_dbm < noise_dbm)
4647 return 0;
4648 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
4649
4650 /* Else use just the signal level.
4651 * This formula is a least squares fit of data points collected and
4652 * compared with a reference system that had a percentage (%) display
4653 * for signal quality. */
4654 } else
4655 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
4656 (15 * RSSI_RANGE + 62 * degradation)) /
4657 (RSSI_RANGE * RSSI_RANGE);
4658
4659 if (sig_qual > 100)
4660 sig_qual = 100;
4661 else if (sig_qual < 1)
4662 sig_qual = 0;
4663
4664 return sig_qual;
4665}
4666
4667/**
Ben Cahill9fbab512007-11-29 11:09:47 +08004668 * iwl4965_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07004669 *
4670 * Uses the priv->rx_handlers callback function array to invoke
4671 * the appropriate handlers, including command responses,
4672 * frame-received notifications, and other notifications.
4673 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004674static void iwl4965_rx_handle(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004675{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004676 struct iwl4965_rx_mem_buffer *rxb;
4677 struct iwl4965_rx_packet *pkt;
4678 struct iwl4965_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07004679 u32 r, i;
4680 int reclaim;
4681 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08004682 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08004683 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07004684
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004685 /* uCode's read index (stored in shared DRAM) indicates the last Rx
4686 * buffer that the driver may process (last buffer filled by ucode). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004687 r = iwl4965_hw_get_rx_read(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004688 i = rxq->read;
4689
4690 /* Rx interrupt, but nothing sent from uCode */
4691 if (i == r)
4692 IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
4693
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08004694 if (iwl4965_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
4695 fill_rx = 1;
4696
Zhu Yib481de92007-09-25 17:54:57 -07004697 while (i != r) {
4698 rxb = rxq->queue[i];
4699
Ben Cahill9fbab512007-11-29 11:09:47 +08004700 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07004701 * then a bug has been introduced in the queue refilling
4702 * routines -- catch it here */
4703 BUG_ON(rxb == NULL);
4704
4705 rxq->queue[i] = NULL;
4706
4707 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02004708 priv->hw_setting.rx_buf_size,
Zhu Yib481de92007-09-25 17:54:57 -07004709 PCI_DMA_FROMDEVICE);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004710 pkt = (struct iwl4965_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07004711
4712 /* Reclaim a command buffer only if this packet is a response
4713 * to a (driver-originated) command.
4714 * If the packet (e.g. Rx frame) originated from uCode,
4715 * there is no command buffer to reclaim.
4716 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
4717 * but apparently a few don't get set; catch them here. */
4718 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
4719 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
4720 (pkt->hdr.cmd != REPLY_4965_RX) &&
Zhu Yicfe01702007-09-27 11:27:31 +08004721 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
Zhu Yib481de92007-09-25 17:54:57 -07004722 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
4723 (pkt->hdr.cmd != REPLY_TX);
4724
4725 /* Based on type of command response or notification,
4726 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004727 * rx_handlers table. See iwl4965_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07004728 if (priv->rx_handlers[pkt->hdr.cmd]) {
4729 IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
4730 "r = %d, i = %d, %s, 0x%02x\n", r, i,
4731 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
4732 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
4733 } else {
4734 /* No handling needed */
4735 IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
4736 "r %d i %d No handler needed for %s, 0x%02x\n",
4737 r, i, get_cmd_string(pkt->hdr.cmd),
4738 pkt->hdr.cmd);
4739 }
4740
4741 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08004742 /* Invoke any callbacks, transfer the skb to caller, and
4743 * fire off the (possibly) blocking iwl4965_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07004744 * as we reclaim the driver command queue */
4745 if (rxb && rxb->skb)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004746 iwl4965_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07004747 else
4748 IWL_WARNING("Claim null rxb?\n");
4749 }
4750
4751 /* For now we just don't re-use anything. We can tweak this
4752 * later to try and re-use notification packets and SKBs that
4753 * fail to Rx correctly */
4754 if (rxb->skb != NULL) {
4755 priv->alloc_rxb_skb--;
4756 dev_kfree_skb_any(rxb->skb);
4757 rxb->skb = NULL;
4758 }
4759
4760 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02004761 priv->hw_setting.rx_buf_size,
4762 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07004763 spin_lock_irqsave(&rxq->lock, flags);
4764 list_add_tail(&rxb->list, &priv->rxq.rx_used);
4765 spin_unlock_irqrestore(&rxq->lock, flags);
4766 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08004767 /* If there are a lot of unused frames,
4768 * restock the Rx queue so ucode wont assert. */
4769 if (fill_rx) {
4770 count++;
4771 if (count >= 8) {
4772 priv->rxq.read = i;
4773 __iwl4965_rx_replenish(priv);
4774 count = 0;
4775 }
4776 }
Zhu Yib481de92007-09-25 17:54:57 -07004777 }
4778
4779 /* Backtrack one entry */
4780 priv->rxq.read = i;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004781 iwl4965_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004782}
4783
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004784/**
4785 * iwl4965_tx_queue_update_write_ptr - Send new write index to hardware
4786 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004787static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv,
4788 struct iwl4965_tx_queue *txq)
Zhu Yib481de92007-09-25 17:54:57 -07004789{
4790 u32 reg = 0;
4791 int rc = 0;
4792 int txq_id = txq->q.id;
4793
4794 if (txq->need_update == 0)
4795 return rc;
4796
4797 /* if we're trying to save power */
4798 if (test_bit(STATUS_POWER_PMI, &priv->status)) {
4799 /* wake up nic if it's powered down ...
4800 * uCode will wake up, and interrupt us again, so next
4801 * time we'll skip this part. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004802 reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
Zhu Yib481de92007-09-25 17:54:57 -07004803
4804 if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
4805 IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004806 iwl4965_set_bit(priv, CSR_GP_CNTRL,
Zhu Yib481de92007-09-25 17:54:57 -07004807 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
4808 return rc;
4809 }
4810
4811 /* restore this queue's parameters in nic hardware. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004812 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004813 if (rc)
4814 return rc;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004815 iwl4965_write_direct32(priv, HBUS_TARG_WRPTR,
Tomas Winklerfc4b6852007-10-25 17:15:24 +08004816 txq->q.write_ptr | (txq_id << 8));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004817 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004818
4819 /* else not in power-save mode, uCode will never sleep when we're
4820 * trying to tx (during RFKILL, we're not trying to tx). */
4821 } else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004822 iwl4965_write32(priv, HBUS_TARG_WRPTR,
Tomas Winklerfc4b6852007-10-25 17:15:24 +08004823 txq->q.write_ptr | (txq_id << 8));
Zhu Yib481de92007-09-25 17:54:57 -07004824
4825 txq->need_update = 0;
4826
4827 return rc;
4828}
4829
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004830#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004831static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd *rxon)
Zhu Yib481de92007-09-25 17:54:57 -07004832{
Joe Perches0795af52007-10-03 17:59:30 -07004833 DECLARE_MAC_BUF(mac);
4834
Zhu Yib481de92007-09-25 17:54:57 -07004835 IWL_DEBUG_RADIO("RX CONFIG:\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004836 iwl4965_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
Zhu Yib481de92007-09-25 17:54:57 -07004837 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
4838 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
4839 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
4840 le32_to_cpu(rxon->filter_flags));
4841 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
4842 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
4843 rxon->ofdm_basic_rates);
4844 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
Joe Perches0795af52007-10-03 17:59:30 -07004845 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
4846 print_mac(mac, rxon->node_addr));
4847 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
4848 print_mac(mac, rxon->bssid_addr));
Zhu Yib481de92007-09-25 17:54:57 -07004849 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
4850}
4851#endif
4852
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004853static void iwl4965_enable_interrupts(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004854{
4855 IWL_DEBUG_ISR("Enabling interrupts\n");
4856 set_bit(STATUS_INT_ENABLED, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004857 iwl4965_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07004858}
4859
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004860static inline void iwl4965_disable_interrupts(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004861{
4862 clear_bit(STATUS_INT_ENABLED, &priv->status);
4863
4864 /* disable interrupts from uCode/NIC to host */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004865 iwl4965_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07004866
4867 /* acknowledge/clear/reset any interrupts still pending
4868 * from uCode or flow handler (Rx/Tx DMA) */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004869 iwl4965_write32(priv, CSR_INT, 0xffffffff);
4870 iwl4965_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
Zhu Yib481de92007-09-25 17:54:57 -07004871 IWL_DEBUG_ISR("Disabled interrupts\n");
4872}
4873
4874static const char *desc_lookup(int i)
4875{
4876 switch (i) {
4877 case 1:
4878 return "FAIL";
4879 case 2:
4880 return "BAD_PARAM";
4881 case 3:
4882 return "BAD_CHECKSUM";
4883 case 4:
4884 return "NMI_INTERRUPT";
4885 case 5:
4886 return "SYSASSERT";
4887 case 6:
4888 return "FATAL_ERROR";
4889 }
4890
4891 return "UNKNOWN";
4892}
4893
4894#define ERROR_START_OFFSET (1 * sizeof(u32))
4895#define ERROR_ELEM_SIZE (7 * sizeof(u32))
4896
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004897static void iwl4965_dump_nic_error_log(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004898{
4899 u32 data2, line;
4900 u32 desc, time, count, base, data1;
4901 u32 blink1, blink2, ilink1, ilink2;
4902 int rc;
4903
4904 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
4905
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004906 if (!iwl4965_hw_valid_rtc_data_addr(base)) {
Zhu Yib481de92007-09-25 17:54:57 -07004907 IWL_ERROR("Not valid error log pointer 0x%08X\n", base);
4908 return;
4909 }
4910
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004911 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004912 if (rc) {
4913 IWL_WARNING("Can not read from adapter at this time.\n");
4914 return;
4915 }
4916
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004917 count = iwl4965_read_targ_mem(priv, base);
Zhu Yib481de92007-09-25 17:54:57 -07004918
4919 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
4920 IWL_ERROR("Start IWL Error Log Dump:\n");
4921 IWL_ERROR("Status: 0x%08lX, Config: %08X count: %d\n",
4922 priv->status, priv->config, count);
4923 }
4924
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004925 desc = iwl4965_read_targ_mem(priv, base + 1 * sizeof(u32));
4926 blink1 = iwl4965_read_targ_mem(priv, base + 3 * sizeof(u32));
4927 blink2 = iwl4965_read_targ_mem(priv, base + 4 * sizeof(u32));
4928 ilink1 = iwl4965_read_targ_mem(priv, base + 5 * sizeof(u32));
4929 ilink2 = iwl4965_read_targ_mem(priv, base + 6 * sizeof(u32));
4930 data1 = iwl4965_read_targ_mem(priv, base + 7 * sizeof(u32));
4931 data2 = iwl4965_read_targ_mem(priv, base + 8 * sizeof(u32));
4932 line = iwl4965_read_targ_mem(priv, base + 9 * sizeof(u32));
4933 time = iwl4965_read_targ_mem(priv, base + 11 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07004934
4935 IWL_ERROR("Desc Time "
4936 "data1 data2 line\n");
4937 IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n",
4938 desc_lookup(desc), desc, time, data1, data2, line);
4939 IWL_ERROR("blink1 blink2 ilink1 ilink2\n");
4940 IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2,
4941 ilink1, ilink2);
4942
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004943 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004944}
4945
4946#define EVENT_START_OFFSET (4 * sizeof(u32))
4947
4948/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004949 * iwl4965_print_event_log - Dump error event log to syslog
Zhu Yib481de92007-09-25 17:54:57 -07004950 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004951 * NOTE: Must be called with iwl4965_grab_nic_access() already obtained!
Zhu Yib481de92007-09-25 17:54:57 -07004952 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004953static void iwl4965_print_event_log(struct iwl4965_priv *priv, u32 start_idx,
Zhu Yib481de92007-09-25 17:54:57 -07004954 u32 num_events, u32 mode)
4955{
4956 u32 i;
4957 u32 base; /* SRAM byte address of event log header */
4958 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
4959 u32 ptr; /* SRAM byte address of log data */
4960 u32 ev, time, data; /* event log data */
4961
4962 if (num_events == 0)
4963 return;
4964
4965 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
4966
4967 if (mode == 0)
4968 event_size = 2 * sizeof(u32);
4969 else
4970 event_size = 3 * sizeof(u32);
4971
4972 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
4973
4974 /* "time" is actually "data" for mode 0 (no timestamp).
4975 * place event id # at far right for easier visual parsing. */
4976 for (i = 0; i < num_events; i++) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004977 ev = iwl4965_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07004978 ptr += sizeof(u32);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004979 time = iwl4965_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07004980 ptr += sizeof(u32);
4981 if (mode == 0)
4982 IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */
4983 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004984 data = iwl4965_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07004985 ptr += sizeof(u32);
4986 IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev);
4987 }
4988 }
4989}
4990
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004991static void iwl4965_dump_nic_event_log(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004992{
4993 int rc;
4994 u32 base; /* SRAM byte address of event log header */
4995 u32 capacity; /* event log capacity in # entries */
4996 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
4997 u32 num_wraps; /* # times uCode wrapped to top of log */
4998 u32 next_entry; /* index of next entry to be written by uCode */
4999 u32 size; /* # entries that we'll print */
5000
5001 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005002 if (!iwl4965_hw_valid_rtc_data_addr(base)) {
Zhu Yib481de92007-09-25 17:54:57 -07005003 IWL_ERROR("Invalid event log pointer 0x%08X\n", base);
5004 return;
5005 }
5006
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005007 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005008 if (rc) {
5009 IWL_WARNING("Can not read from adapter at this time.\n");
5010 return;
5011 }
5012
5013 /* event log header */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005014 capacity = iwl4965_read_targ_mem(priv, base);
5015 mode = iwl4965_read_targ_mem(priv, base + (1 * sizeof(u32)));
5016 num_wraps = iwl4965_read_targ_mem(priv, base + (2 * sizeof(u32)));
5017 next_entry = iwl4965_read_targ_mem(priv, base + (3 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -07005018
5019 size = num_wraps ? capacity : next_entry;
5020
5021 /* bail out if nothing in log */
5022 if (size == 0) {
Zhu Yi583fab32007-09-27 11:27:30 +08005023 IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005024 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005025 return;
5026 }
5027
Zhu Yi583fab32007-09-27 11:27:30 +08005028 IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07005029 size, num_wraps);
5030
5031 /* if uCode has wrapped back to top of log, start at the oldest entry,
5032 * i.e the next one that uCode would fill. */
5033 if (num_wraps)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005034 iwl4965_print_event_log(priv, next_entry,
Zhu Yib481de92007-09-25 17:54:57 -07005035 capacity - next_entry, mode);
5036
5037 /* (then/else) start at top of log */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005038 iwl4965_print_event_log(priv, 0, next_entry, mode);
Zhu Yib481de92007-09-25 17:54:57 -07005039
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005040 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005041}
5042
5043/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005044 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
Zhu Yib481de92007-09-25 17:54:57 -07005045 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005046static void iwl4965_irq_handle_error(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005047{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005048 /* Set the FW error flag -- cleared on iwl4965_down */
Zhu Yib481de92007-09-25 17:54:57 -07005049 set_bit(STATUS_FW_ERROR, &priv->status);
5050
5051 /* Cancel currently queued command. */
5052 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
5053
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005054#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005055 if (iwl4965_debug_level & IWL_DL_FW_ERRORS) {
5056 iwl4965_dump_nic_error_log(priv);
5057 iwl4965_dump_nic_event_log(priv);
5058 iwl4965_print_rx_config_cmd(&priv->staging_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07005059 }
5060#endif
5061
5062 wake_up_interruptible(&priv->wait_command_queue);
5063
5064 /* Keep the restart process from trying to send host
5065 * commands by clearing the INIT status bit */
5066 clear_bit(STATUS_READY, &priv->status);
5067
5068 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
5069 IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS,
5070 "Restarting adapter due to uCode error.\n");
5071
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005072 if (iwl4965_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005073 memcpy(&priv->recovery_rxon, &priv->active_rxon,
5074 sizeof(priv->recovery_rxon));
5075 priv->error_recovering = 1;
5076 }
5077 queue_work(priv->workqueue, &priv->restart);
5078 }
5079}
5080
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005081static void iwl4965_error_recovery(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005082{
5083 unsigned long flags;
5084
5085 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
5086 sizeof(priv->staging_rxon));
5087 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005088 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005089
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005090 iwl4965_rxon_add_station(priv, priv->bssid, 1);
Zhu Yib481de92007-09-25 17:54:57 -07005091
5092 spin_lock_irqsave(&priv->lock, flags);
5093 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
5094 priv->error_recovering = 0;
5095 spin_unlock_irqrestore(&priv->lock, flags);
5096}
5097
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005098static void iwl4965_irq_tasklet(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005099{
5100 u32 inta, handled = 0;
5101 u32 inta_fh;
5102 unsigned long flags;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005103#ifdef CONFIG_IWL4965_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07005104 u32 inta_mask;
5105#endif
5106
5107 spin_lock_irqsave(&priv->lock, flags);
5108
5109 /* Ack/clear/reset pending uCode interrupts.
5110 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
5111 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005112 inta = iwl4965_read32(priv, CSR_INT);
5113 iwl4965_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07005114
5115 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
5116 * Any new interrupts that happen after this, either while we're
5117 * in this tasklet, or later, will show up in next ISR/tasklet. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005118 inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS);
5119 iwl4965_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07005120
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005121#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005122 if (iwl4965_debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08005123 /* just for debug */
5124 inta_mask = iwl4965_read32(priv, CSR_INT_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07005125 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
5126 inta, inta_mask, inta_fh);
5127 }
5128#endif
5129
5130 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
5131 * atomic, make sure that inta covers all the interrupts that
5132 * we've discovered, even if FH interrupt came in just after
5133 * reading CSR_INT. */
5134 if (inta_fh & CSR_FH_INT_RX_MASK)
5135 inta |= CSR_INT_BIT_FH_RX;
5136 if (inta_fh & CSR_FH_INT_TX_MASK)
5137 inta |= CSR_INT_BIT_FH_TX;
5138
5139 /* Now service all interrupt bits discovered above. */
5140 if (inta & CSR_INT_BIT_HW_ERR) {
5141 IWL_ERROR("Microcode HW error detected. Restarting.\n");
5142
5143 /* Tell the device to stop sending interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005144 iwl4965_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005145
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005146 iwl4965_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005147
5148 handled |= CSR_INT_BIT_HW_ERR;
5149
5150 spin_unlock_irqrestore(&priv->lock, flags);
5151
5152 return;
5153 }
5154
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005155#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005156 if (iwl4965_debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07005157 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08005158 if (inta & CSR_INT_BIT_SCD)
5159 IWL_DEBUG_ISR("Scheduler finished to transmit "
5160 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07005161
5162 /* Alive notification via Rx interrupt will do the real work */
5163 if (inta & CSR_INT_BIT_ALIVE)
5164 IWL_DEBUG_ISR("Alive interrupt\n");
5165 }
5166#endif
5167 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08005168 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07005169
Ben Cahill9fbab512007-11-29 11:09:47 +08005170 /* HW RF KILL switch toggled */
Zhu Yib481de92007-09-25 17:54:57 -07005171 if (inta & CSR_INT_BIT_RF_KILL) {
5172 int hw_rf_kill = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005173 if (!(iwl4965_read32(priv, CSR_GP_CNTRL) &
Zhu Yib481de92007-09-25 17:54:57 -07005174 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
5175 hw_rf_kill = 1;
5176
5177 IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL | IWL_DL_ISR,
5178 "RF_KILL bit toggled to %s.\n",
5179 hw_rf_kill ? "disable radio":"enable radio");
5180
5181 /* Queue restart only if RF_KILL switch was set to "kill"
5182 * when we loaded driver, and is now set to "enable".
5183 * After we're Alive, RF_KILL gets handled by
5184 * iwl_rx_card_state_notif() */
Zhu Yi53e49092007-12-06 16:08:44 +08005185 if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) {
5186 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07005187 queue_work(priv->workqueue, &priv->restart);
Zhu Yi53e49092007-12-06 16:08:44 +08005188 }
Zhu Yib481de92007-09-25 17:54:57 -07005189
5190 handled |= CSR_INT_BIT_RF_KILL;
5191 }
5192
Ben Cahill9fbab512007-11-29 11:09:47 +08005193 /* Chip got too hot and stopped itself */
Zhu Yib481de92007-09-25 17:54:57 -07005194 if (inta & CSR_INT_BIT_CT_KILL) {
5195 IWL_ERROR("Microcode CT kill error detected.\n");
5196 handled |= CSR_INT_BIT_CT_KILL;
5197 }
5198
5199 /* Error detected by uCode */
5200 if (inta & CSR_INT_BIT_SW_ERR) {
5201 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
5202 inta);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005203 iwl4965_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005204 handled |= CSR_INT_BIT_SW_ERR;
5205 }
5206
5207 /* uCode wakes up after power-down sleep */
5208 if (inta & CSR_INT_BIT_WAKEUP) {
5209 IWL_DEBUG_ISR("Wakeup interrupt\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005210 iwl4965_rx_queue_update_write_ptr(priv, &priv->rxq);
5211 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[0]);
5212 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[1]);
5213 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[2]);
5214 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[3]);
5215 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[4]);
5216 iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07005217
5218 handled |= CSR_INT_BIT_WAKEUP;
5219 }
5220
5221 /* All uCode command responses, including Tx command responses,
5222 * Rx "responses" (frame-received notification), and other
5223 * notifications from uCode come through here*/
5224 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005225 iwl4965_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005226 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
5227 }
5228
5229 if (inta & CSR_INT_BIT_FH_TX) {
5230 IWL_DEBUG_ISR("Tx interrupt\n");
5231 handled |= CSR_INT_BIT_FH_TX;
5232 }
5233
5234 if (inta & ~handled)
5235 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
5236
5237 if (inta & ~CSR_INI_SET_MASK) {
5238 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
5239 inta & ~CSR_INI_SET_MASK);
5240 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
5241 }
5242
5243 /* Re-enable all interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005244 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005245
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005246#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005247 if (iwl4965_debug_level & (IWL_DL_ISR)) {
5248 inta = iwl4965_read32(priv, CSR_INT);
5249 inta_mask = iwl4965_read32(priv, CSR_INT_MASK);
5250 inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07005251 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
5252 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
5253 }
5254#endif
5255 spin_unlock_irqrestore(&priv->lock, flags);
5256}
5257
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005258static irqreturn_t iwl4965_isr(int irq, void *data)
Zhu Yib481de92007-09-25 17:54:57 -07005259{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005260 struct iwl4965_priv *priv = data;
Zhu Yib481de92007-09-25 17:54:57 -07005261 u32 inta, inta_mask;
5262 u32 inta_fh;
5263 if (!priv)
5264 return IRQ_NONE;
5265
5266 spin_lock(&priv->lock);
5267
5268 /* Disable (but don't clear!) interrupts here to avoid
5269 * back-to-back ISRs and sporadic interrupts from our NIC.
5270 * If we have something to service, the tasklet will re-enable ints.
5271 * If we *don't* have something, we'll re-enable before leaving here. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005272 inta_mask = iwl4965_read32(priv, CSR_INT_MASK); /* just for debug */
5273 iwl4965_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07005274
5275 /* Discover which interrupts are active/pending */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005276 inta = iwl4965_read32(priv, CSR_INT);
5277 inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07005278
5279 /* Ignore interrupt if there's nothing in NIC to service.
5280 * This may be due to IRQ shared with another device,
5281 * or due to sporadic interrupts thrown from our NIC. */
5282 if (!inta && !inta_fh) {
5283 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
5284 goto none;
5285 }
5286
5287 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
Oliver Neukum66fbb542007-11-15 09:31:10 +08005288 /* Hardware disappeared. It might have already raised
5289 * an interrupt */
Zhu Yib481de92007-09-25 17:54:57 -07005290 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
Oliver Neukum66fbb542007-11-15 09:31:10 +08005291 goto unplugged;
Zhu Yib481de92007-09-25 17:54:57 -07005292 }
5293
5294 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
5295 inta, inta_mask, inta_fh);
5296
Joonwoo Park25c03d82008-01-23 10:15:20 -08005297 inta &= ~CSR_INT_BIT_SCD;
5298
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005299 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
Joonwoo Park25c03d82008-01-23 10:15:20 -08005300 if (likely(inta || inta_fh))
5301 tasklet_schedule(&priv->irq_tasklet);
Zhu Yib481de92007-09-25 17:54:57 -07005302
Oliver Neukum66fbb542007-11-15 09:31:10 +08005303 unplugged:
5304 spin_unlock(&priv->lock);
Zhu Yib481de92007-09-25 17:54:57 -07005305 return IRQ_HANDLED;
5306
5307 none:
5308 /* re-enable interrupts here since we don't have anything to service. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005309 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005310 spin_unlock(&priv->lock);
5311 return IRQ_NONE;
5312}
5313
5314/************************** EEPROM BANDS ****************************
5315 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005316 * The iwl4965_eeprom_band definitions below provide the mapping from the
Zhu Yib481de92007-09-25 17:54:57 -07005317 * EEPROM contents to the specific channel number supported for each
5318 * band.
5319 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005320 * For example, iwl4965_priv->eeprom.band_3_channels[4] from the band_3
Zhu Yib481de92007-09-25 17:54:57 -07005321 * definition below maps to physical channel 42 in the 5.2GHz spectrum.
5322 * The specific geography and calibration information for that channel
5323 * is contained in the eeprom map itself.
5324 *
5325 * During init, we copy the eeprom information and channel map
5326 * information into priv->channel_info_24/52 and priv->channel_map_24/52
5327 *
5328 * channel_map_24/52 provides the index in the channel_info array for a
5329 * given channel. We have to have two separate maps as there is channel
5330 * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
5331 * band_2
5332 *
5333 * A value of 0xff stored in the channel_map indicates that the channel
5334 * is not supported by the hardware at all.
5335 *
5336 * A value of 0xfe in the channel_map indicates that the channel is not
5337 * valid for Tx with the current hardware. This means that
5338 * while the system can tune and receive on a given channel, it may not
5339 * be able to associate or transmit any frames on that
5340 * channel. There is no corresponding channel information for that
5341 * entry.
5342 *
5343 *********************************************************************/
5344
5345/* 2.4 GHz */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005346static const u8 iwl4965_eeprom_band_1[14] = {
Zhu Yib481de92007-09-25 17:54:57 -07005347 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
5348};
5349
5350/* 5.2 GHz bands */
Ben Cahill9fbab512007-11-29 11:09:47 +08005351static const u8 iwl4965_eeprom_band_2[] = { /* 4915-5080MHz */
Zhu Yib481de92007-09-25 17:54:57 -07005352 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
5353};
5354
Ben Cahill9fbab512007-11-29 11:09:47 +08005355static const u8 iwl4965_eeprom_band_3[] = { /* 5170-5320MHz */
Zhu Yib481de92007-09-25 17:54:57 -07005356 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
5357};
5358
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005359static const u8 iwl4965_eeprom_band_4[] = { /* 5500-5700MHz */
Zhu Yib481de92007-09-25 17:54:57 -07005360 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
5361};
5362
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005363static const u8 iwl4965_eeprom_band_5[] = { /* 5725-5825MHz */
Zhu Yib481de92007-09-25 17:54:57 -07005364 145, 149, 153, 157, 161, 165
5365};
5366
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005367static u8 iwl4965_eeprom_band_6[] = { /* 2.4 FAT channel */
Zhu Yib481de92007-09-25 17:54:57 -07005368 1, 2, 3, 4, 5, 6, 7
5369};
5370
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005371static u8 iwl4965_eeprom_band_7[] = { /* 5.2 FAT channel */
Zhu Yib481de92007-09-25 17:54:57 -07005372 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157
5373};
5374
Ben Cahill9fbab512007-11-29 11:09:47 +08005375static void iwl4965_init_band_reference(const struct iwl4965_priv *priv,
5376 int band,
Zhu Yib481de92007-09-25 17:54:57 -07005377 int *eeprom_ch_count,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005378 const struct iwl4965_eeprom_channel
Zhu Yib481de92007-09-25 17:54:57 -07005379 **eeprom_ch_info,
5380 const u8 **eeprom_ch_index)
5381{
5382 switch (band) {
5383 case 1: /* 2.4GHz band */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005384 *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_1);
Zhu Yib481de92007-09-25 17:54:57 -07005385 *eeprom_ch_info = priv->eeprom.band_1_channels;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005386 *eeprom_ch_index = iwl4965_eeprom_band_1;
Zhu Yib481de92007-09-25 17:54:57 -07005387 break;
Ben Cahill9fbab512007-11-29 11:09:47 +08005388 case 2: /* 4.9GHz band */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005389 *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_2);
Zhu Yib481de92007-09-25 17:54:57 -07005390 *eeprom_ch_info = priv->eeprom.band_2_channels;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005391 *eeprom_ch_index = iwl4965_eeprom_band_2;
Zhu Yib481de92007-09-25 17:54:57 -07005392 break;
5393 case 3: /* 5.2GHz band */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005394 *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_3);
Zhu Yib481de92007-09-25 17:54:57 -07005395 *eeprom_ch_info = priv->eeprom.band_3_channels;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005396 *eeprom_ch_index = iwl4965_eeprom_band_3;
Zhu Yib481de92007-09-25 17:54:57 -07005397 break;
Ben Cahill9fbab512007-11-29 11:09:47 +08005398 case 4: /* 5.5GHz band */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005399 *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_4);
Zhu Yib481de92007-09-25 17:54:57 -07005400 *eeprom_ch_info = priv->eeprom.band_4_channels;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005401 *eeprom_ch_index = iwl4965_eeprom_band_4;
Zhu Yib481de92007-09-25 17:54:57 -07005402 break;
Ben Cahill9fbab512007-11-29 11:09:47 +08005403 case 5: /* 5.7GHz band */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005404 *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_5);
Zhu Yib481de92007-09-25 17:54:57 -07005405 *eeprom_ch_info = priv->eeprom.band_5_channels;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005406 *eeprom_ch_index = iwl4965_eeprom_band_5;
Zhu Yib481de92007-09-25 17:54:57 -07005407 break;
Ben Cahill9fbab512007-11-29 11:09:47 +08005408 case 6: /* 2.4GHz FAT channels */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005409 *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_6);
Zhu Yib481de92007-09-25 17:54:57 -07005410 *eeprom_ch_info = priv->eeprom.band_24_channels;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005411 *eeprom_ch_index = iwl4965_eeprom_band_6;
Zhu Yib481de92007-09-25 17:54:57 -07005412 break;
Ben Cahill9fbab512007-11-29 11:09:47 +08005413 case 7: /* 5 GHz FAT channels */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005414 *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_7);
Zhu Yib481de92007-09-25 17:54:57 -07005415 *eeprom_ch_info = priv->eeprom.band_52_channels;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005416 *eeprom_ch_index = iwl4965_eeprom_band_7;
Zhu Yib481de92007-09-25 17:54:57 -07005417 break;
5418 default:
5419 BUG();
5420 return;
5421 }
5422}
5423
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005424/**
5425 * iwl4965_get_channel_info - Find driver's private channel info
5426 *
5427 * Based on band and channel number.
5428 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005429const struct iwl4965_channel_info *iwl4965_get_channel_info(const struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07005430 int phymode, u16 channel)
5431{
5432 int i;
5433
5434 switch (phymode) {
5435 case MODE_IEEE80211A:
5436 for (i = 14; i < priv->channel_count; i++) {
5437 if (priv->channel_info[i].channel == channel)
5438 return &priv->channel_info[i];
5439 }
5440 break;
5441
5442 case MODE_IEEE80211B:
5443 case MODE_IEEE80211G:
5444 if (channel >= 1 && channel <= 14)
5445 return &priv->channel_info[channel - 1];
5446 break;
5447
5448 }
5449
5450 return NULL;
5451}
5452
5453#define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
5454 ? # x " " : "")
5455
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005456/**
5457 * iwl4965_init_channel_map - Set up driver's info for all possible channels
5458 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005459static int iwl4965_init_channel_map(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005460{
5461 int eeprom_ch_count = 0;
5462 const u8 *eeprom_ch_index = NULL;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005463 const struct iwl4965_eeprom_channel *eeprom_ch_info = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07005464 int band, ch;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005465 struct iwl4965_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07005466
5467 if (priv->channel_count) {
5468 IWL_DEBUG_INFO("Channel map already initialized.\n");
5469 return 0;
5470 }
5471
5472 if (priv->eeprom.version < 0x2f) {
5473 IWL_WARNING("Unsupported EEPROM version: 0x%04X\n",
5474 priv->eeprom.version);
5475 return -EINVAL;
5476 }
5477
5478 IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n");
5479
5480 priv->channel_count =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005481 ARRAY_SIZE(iwl4965_eeprom_band_1) +
5482 ARRAY_SIZE(iwl4965_eeprom_band_2) +
5483 ARRAY_SIZE(iwl4965_eeprom_band_3) +
5484 ARRAY_SIZE(iwl4965_eeprom_band_4) +
5485 ARRAY_SIZE(iwl4965_eeprom_band_5);
Zhu Yib481de92007-09-25 17:54:57 -07005486
5487 IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count);
5488
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005489 priv->channel_info = kzalloc(sizeof(struct iwl4965_channel_info) *
Zhu Yib481de92007-09-25 17:54:57 -07005490 priv->channel_count, GFP_KERNEL);
5491 if (!priv->channel_info) {
5492 IWL_ERROR("Could not allocate channel_info\n");
5493 priv->channel_count = 0;
5494 return -ENOMEM;
5495 }
5496
5497 ch_info = priv->channel_info;
5498
5499 /* Loop through the 5 EEPROM bands adding them in order to the
5500 * channel map we maintain (that contains additional information than
5501 * what just in the EEPROM) */
5502 for (band = 1; band <= 5; band++) {
5503
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005504 iwl4965_init_band_reference(priv, band, &eeprom_ch_count,
Zhu Yib481de92007-09-25 17:54:57 -07005505 &eeprom_ch_info, &eeprom_ch_index);
5506
5507 /* Loop through each band adding each of the channels */
5508 for (ch = 0; ch < eeprom_ch_count; ch++) {
5509 ch_info->channel = eeprom_ch_index[ch];
5510 ch_info->phymode = (band == 1) ? MODE_IEEE80211B :
5511 MODE_IEEE80211A;
5512
5513 /* permanently store EEPROM's channel regulatory flags
5514 * and max power in channel info database. */
5515 ch_info->eeprom = eeprom_ch_info[ch];
5516
5517 /* Copy the run-time flags so they are there even on
5518 * invalid channels */
5519 ch_info->flags = eeprom_ch_info[ch].flags;
5520
5521 if (!(is_channel_valid(ch_info))) {
5522 IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - "
5523 "No traffic\n",
5524 ch_info->channel,
5525 ch_info->flags,
5526 is_channel_a_band(ch_info) ?
5527 "5.2" : "2.4");
5528 ch_info++;
5529 continue;
5530 }
5531
5532 /* Initialize regulatory-based run-time data */
5533 ch_info->max_power_avg = ch_info->curr_txpow =
5534 eeprom_ch_info[ch].max_power_avg;
5535 ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
5536 ch_info->min_power = 0;
5537
5538 IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x"
5539 " %ddBm): Ad-Hoc %ssupported\n",
5540 ch_info->channel,
5541 is_channel_a_band(ch_info) ?
5542 "5.2" : "2.4",
5543 CHECK_AND_PRINT(IBSS),
5544 CHECK_AND_PRINT(ACTIVE),
5545 CHECK_AND_PRINT(RADAR),
5546 CHECK_AND_PRINT(WIDE),
5547 CHECK_AND_PRINT(NARROW),
5548 CHECK_AND_PRINT(DFS),
5549 eeprom_ch_info[ch].flags,
5550 eeprom_ch_info[ch].max_power_avg,
5551 ((eeprom_ch_info[ch].
5552 flags & EEPROM_CHANNEL_IBSS)
5553 && !(eeprom_ch_info[ch].
5554 flags & EEPROM_CHANNEL_RADAR))
5555 ? "" : "not ");
5556
5557 /* Set the user_txpower_limit to the highest power
5558 * supported by any channel */
5559 if (eeprom_ch_info[ch].max_power_avg >
5560 priv->user_txpower_limit)
5561 priv->user_txpower_limit =
5562 eeprom_ch_info[ch].max_power_avg;
5563
5564 ch_info++;
5565 }
5566 }
5567
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005568 /* Two additional EEPROM bands for 2.4 and 5 GHz FAT channels */
Zhu Yib481de92007-09-25 17:54:57 -07005569 for (band = 6; band <= 7; band++) {
5570 int phymode;
5571 u8 fat_extension_chan;
5572
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005573 iwl4965_init_band_reference(priv, band, &eeprom_ch_count,
Zhu Yib481de92007-09-25 17:54:57 -07005574 &eeprom_ch_info, &eeprom_ch_index);
5575
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005576 /* EEPROM band 6 is 2.4, band 7 is 5 GHz */
Zhu Yib481de92007-09-25 17:54:57 -07005577 phymode = (band == 6) ? MODE_IEEE80211B : MODE_IEEE80211A;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005578
Zhu Yib481de92007-09-25 17:54:57 -07005579 /* Loop through each band adding each of the channels */
5580 for (ch = 0; ch < eeprom_ch_count; ch++) {
5581
5582 if ((band == 6) &&
5583 ((eeprom_ch_index[ch] == 5) ||
5584 (eeprom_ch_index[ch] == 6) ||
5585 (eeprom_ch_index[ch] == 7)))
5586 fat_extension_chan = HT_IE_EXT_CHANNEL_MAX;
5587 else
5588 fat_extension_chan = HT_IE_EXT_CHANNEL_ABOVE;
5589
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005590 /* Set up driver's info for lower half */
Zhu Yib481de92007-09-25 17:54:57 -07005591 iwl4965_set_fat_chan_info(priv, phymode,
5592 eeprom_ch_index[ch],
5593 &(eeprom_ch_info[ch]),
5594 fat_extension_chan);
5595
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005596 /* Set up driver's info for upper half */
Zhu Yib481de92007-09-25 17:54:57 -07005597 iwl4965_set_fat_chan_info(priv, phymode,
5598 (eeprom_ch_index[ch] + 4),
5599 &(eeprom_ch_info[ch]),
5600 HT_IE_EXT_CHANNEL_BELOW);
5601 }
5602 }
5603
5604 return 0;
5605}
5606
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005607/*
5608 * iwl4965_free_channel_map - undo allocations in iwl4965_init_channel_map
5609 */
5610static void iwl4965_free_channel_map(struct iwl4965_priv *priv)
5611{
5612 kfree(priv->channel_info);
5613 priv->channel_count = 0;
5614}
5615
Zhu Yib481de92007-09-25 17:54:57 -07005616/* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
5617 * sending probe req. This should be set long enough to hear probe responses
5618 * from more than one AP. */
5619#define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
5620#define IWL_ACTIVE_DWELL_TIME_52 (10)
5621
5622/* For faster active scanning, scan will move to the next channel if fewer than
5623 * PLCP_QUIET_THRESH packets are heard on this channel within
5624 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
5625 * time if it's a quiet channel (nothing responded to our probe, and there's
5626 * no other traffic).
5627 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
5628#define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
5629#define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
5630
5631/* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
5632 * Must be set longer than active dwell time.
5633 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
5634#define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
5635#define IWL_PASSIVE_DWELL_TIME_52 (10)
5636#define IWL_PASSIVE_DWELL_BASE (100)
5637#define IWL_CHANNEL_TUNE_TIME 5
5638
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005639static inline u16 iwl4965_get_active_dwell_time(struct iwl4965_priv *priv, int phymode)
Zhu Yib481de92007-09-25 17:54:57 -07005640{
5641 if (phymode == MODE_IEEE80211A)
5642 return IWL_ACTIVE_DWELL_TIME_52;
5643 else
5644 return IWL_ACTIVE_DWELL_TIME_24;
5645}
5646
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005647static u16 iwl4965_get_passive_dwell_time(struct iwl4965_priv *priv, int phymode)
Zhu Yib481de92007-09-25 17:54:57 -07005648{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005649 u16 active = iwl4965_get_active_dwell_time(priv, phymode);
Zhu Yib481de92007-09-25 17:54:57 -07005650 u16 passive = (phymode != MODE_IEEE80211A) ?
5651 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
5652 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
5653
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005654 if (iwl4965_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005655 /* If we're associated, we clamp the maximum passive
5656 * dwell time to be 98% of the beacon interval (minus
5657 * 2 * channel tune time) */
5658 passive = priv->beacon_int;
5659 if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive)
5660 passive = IWL_PASSIVE_DWELL_BASE;
5661 passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
5662 }
5663
5664 if (passive <= active)
5665 passive = active + 1;
5666
5667 return passive;
5668}
5669
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005670static int iwl4965_get_channels_for_scan(struct iwl4965_priv *priv, int phymode,
Zhu Yib481de92007-09-25 17:54:57 -07005671 u8 is_active, u8 direct_mask,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005672 struct iwl4965_scan_channel *scan_ch)
Zhu Yib481de92007-09-25 17:54:57 -07005673{
5674 const struct ieee80211_channel *channels = NULL;
5675 const struct ieee80211_hw_mode *hw_mode;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005676 const struct iwl4965_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07005677 u16 passive_dwell = 0;
5678 u16 active_dwell = 0;
5679 int added, i;
5680
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005681 hw_mode = iwl4965_get_hw_mode(priv, phymode);
Zhu Yib481de92007-09-25 17:54:57 -07005682 if (!hw_mode)
5683 return 0;
5684
5685 channels = hw_mode->channels;
5686
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005687 active_dwell = iwl4965_get_active_dwell_time(priv, phymode);
5688 passive_dwell = iwl4965_get_passive_dwell_time(priv, phymode);
Zhu Yib481de92007-09-25 17:54:57 -07005689
5690 for (i = 0, added = 0; i < hw_mode->num_channels; i++) {
5691 if (channels[i].chan ==
5692 le16_to_cpu(priv->active_rxon.channel)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005693 if (iwl4965_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07005694 IWL_DEBUG_SCAN
5695 ("Skipping current channel %d\n",
5696 le16_to_cpu(priv->active_rxon.channel));
5697 continue;
5698 }
5699 } else if (priv->only_active_channel)
5700 continue;
5701
5702 scan_ch->channel = channels[i].chan;
5703
Ben Cahill9fbab512007-11-29 11:09:47 +08005704 ch_info = iwl4965_get_channel_info(priv, phymode,
5705 scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07005706 if (!is_channel_valid(ch_info)) {
5707 IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
5708 scan_ch->channel);
5709 continue;
5710 }
5711
5712 if (!is_active || is_channel_passive(ch_info) ||
5713 !(channels[i].flag & IEEE80211_CHAN_W_ACTIVE_SCAN))
5714 scan_ch->type = 0; /* passive */
5715 else
5716 scan_ch->type = 1; /* active */
5717
5718 if (scan_ch->type & 1)
5719 scan_ch->type |= (direct_mask << 1);
5720
5721 if (is_channel_narrow(ch_info))
5722 scan_ch->type |= (1 << 7);
5723
5724 scan_ch->active_dwell = cpu_to_le16(active_dwell);
5725 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
5726
Ben Cahill9fbab512007-11-29 11:09:47 +08005727 /* Set txpower levels to defaults */
Zhu Yib481de92007-09-25 17:54:57 -07005728 scan_ch->tpc.dsp_atten = 110;
5729 /* scan_pwr_info->tpc.dsp_atten; */
5730
5731 /*scan_pwr_info->tpc.tx_gain; */
5732 if (phymode == MODE_IEEE80211A)
5733 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
5734 else {
5735 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
5736 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
Ben Cahill9fbab512007-11-29 11:09:47 +08005737 * power level:
Reinette Chatre8a1b0242008-01-14 17:46:25 -08005738 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
Zhu Yib481de92007-09-25 17:54:57 -07005739 */
5740 }
5741
5742 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
5743 scan_ch->channel,
5744 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
5745 (scan_ch->type & 1) ?
5746 active_dwell : passive_dwell);
5747
5748 scan_ch++;
5749 added++;
5750 }
5751
5752 IWL_DEBUG_SCAN("total channels to scan %d \n", added);
5753 return added;
5754}
5755
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005756static void iwl4965_reset_channel_flag(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005757{
5758 int i, j;
5759 for (i = 0; i < 3; i++) {
5760 struct ieee80211_hw_mode *hw_mode = (void *)&priv->modes[i];
5761 for (j = 0; j < hw_mode->num_channels; j++)
5762 hw_mode->channels[j].flag = hw_mode->channels[j].val;
5763 }
5764}
5765
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005766static void iwl4965_init_hw_rates(struct iwl4965_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07005767 struct ieee80211_rate *rates)
5768{
5769 int i;
5770
5771 for (i = 0; i < IWL_RATE_COUNT; i++) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005772 rates[i].rate = iwl4965_rates[i].ieee * 5;
Zhu Yib481de92007-09-25 17:54:57 -07005773 rates[i].val = i; /* Rate scaling will work on indexes */
5774 rates[i].val2 = i;
5775 rates[i].flags = IEEE80211_RATE_SUPPORTED;
5776 /* Only OFDM have the bits-per-symbol set */
5777 if ((i <= IWL_LAST_OFDM_RATE) && (i >= IWL_FIRST_OFDM_RATE))
5778 rates[i].flags |= IEEE80211_RATE_OFDM;
5779 else {
5780 /*
5781 * If CCK 1M then set rate flag to CCK else CCK_2
5782 * which is CCK | PREAMBLE2
5783 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005784 rates[i].flags |= (iwl4965_rates[i].plcp == 10) ?
Zhu Yib481de92007-09-25 17:54:57 -07005785 IEEE80211_RATE_CCK : IEEE80211_RATE_CCK_2;
5786 }
5787
5788 /* Set up which ones are basic rates... */
5789 if (IWL_BASIC_RATES_MASK & (1 << i))
5790 rates[i].flags |= IEEE80211_RATE_BASIC;
5791 }
Zhu Yib481de92007-09-25 17:54:57 -07005792}
5793
5794/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005795 * iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom
Zhu Yib481de92007-09-25 17:54:57 -07005796 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005797static int iwl4965_init_geos(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005798{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005799 struct iwl4965_channel_info *ch;
Zhu Yib481de92007-09-25 17:54:57 -07005800 struct ieee80211_hw_mode *modes;
5801 struct ieee80211_channel *channels;
5802 struct ieee80211_channel *geo_ch;
5803 struct ieee80211_rate *rates;
5804 int i = 0;
5805 enum {
5806 A = 0,
5807 B = 1,
5808 G = 2,
Zhu Yib481de92007-09-25 17:54:57 -07005809 };
Ron Rindjunsky326eeee2007-11-26 16:14:37 +02005810 int mode_count = 3;
Zhu Yib481de92007-09-25 17:54:57 -07005811
5812 if (priv->modes) {
5813 IWL_DEBUG_INFO("Geography modes already initialized.\n");
5814 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
5815 return 0;
5816 }
5817
5818 modes = kzalloc(sizeof(struct ieee80211_hw_mode) * mode_count,
5819 GFP_KERNEL);
5820 if (!modes)
5821 return -ENOMEM;
5822
5823 channels = kzalloc(sizeof(struct ieee80211_channel) *
5824 priv->channel_count, GFP_KERNEL);
5825 if (!channels) {
5826 kfree(modes);
5827 return -ENOMEM;
5828 }
5829
5830 rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_MAX_RATES + 1)),
5831 GFP_KERNEL);
5832 if (!rates) {
5833 kfree(modes);
5834 kfree(channels);
5835 return -ENOMEM;
5836 }
5837
5838 /* 0 = 802.11a
5839 * 1 = 802.11b
5840 * 2 = 802.11g
5841 */
5842
5843 /* 5.2GHz channels start after the 2.4GHz channels */
5844 modes[A].mode = MODE_IEEE80211A;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005845 modes[A].channels = &channels[ARRAY_SIZE(iwl4965_eeprom_band_1)];
Zhu Yib481de92007-09-25 17:54:57 -07005846 modes[A].rates = rates;
5847 modes[A].num_rates = 8; /* just OFDM */
5848 modes[A].rates = &rates[4];
5849 modes[A].num_channels = 0;
Ron Rindjunsky326eeee2007-11-26 16:14:37 +02005850#ifdef CONFIG_IWL4965_HT
5851 iwl4965_init_ht_hw_capab(&modes[A].ht_info, MODE_IEEE80211A);
5852#endif
Zhu Yib481de92007-09-25 17:54:57 -07005853
5854 modes[B].mode = MODE_IEEE80211B;
5855 modes[B].channels = channels;
5856 modes[B].rates = rates;
5857 modes[B].num_rates = 4; /* just CCK */
5858 modes[B].num_channels = 0;
5859
5860 modes[G].mode = MODE_IEEE80211G;
5861 modes[G].channels = channels;
5862 modes[G].rates = rates;
5863 modes[G].num_rates = 12; /* OFDM & CCK */
5864 modes[G].num_channels = 0;
Ron Rindjunsky326eeee2007-11-26 16:14:37 +02005865#ifdef CONFIG_IWL4965_HT
5866 iwl4965_init_ht_hw_capab(&modes[G].ht_info, MODE_IEEE80211G);
5867#endif
Zhu Yib481de92007-09-25 17:54:57 -07005868
5869 priv->ieee_channels = channels;
5870 priv->ieee_rates = rates;
5871
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005872 iwl4965_init_hw_rates(priv, rates);
Zhu Yib481de92007-09-25 17:54:57 -07005873
5874 for (i = 0, geo_ch = channels; i < priv->channel_count; i++) {
5875 ch = &priv->channel_info[i];
5876
5877 if (!is_channel_valid(ch)) {
5878 IWL_DEBUG_INFO("Channel %d [%sGHz] is restricted -- "
5879 "skipping.\n",
5880 ch->channel, is_channel_a_band(ch) ?
5881 "5.2" : "2.4");
5882 continue;
5883 }
5884
5885 if (is_channel_a_band(ch)) {
5886 geo_ch = &modes[A].channels[modes[A].num_channels++];
Zhu Yib481de92007-09-25 17:54:57 -07005887 } else {
5888 geo_ch = &modes[B].channels[modes[B].num_channels++];
5889 modes[G].num_channels++;
Zhu Yib481de92007-09-25 17:54:57 -07005890 }
5891
5892 geo_ch->freq = ieee80211chan2mhz(ch->channel);
5893 geo_ch->chan = ch->channel;
5894 geo_ch->power_level = ch->max_power_avg;
5895 geo_ch->antenna_max = 0xff;
5896
5897 if (is_channel_valid(ch)) {
5898 geo_ch->flag = IEEE80211_CHAN_W_SCAN;
5899 if (ch->flags & EEPROM_CHANNEL_IBSS)
5900 geo_ch->flag |= IEEE80211_CHAN_W_IBSS;
5901
5902 if (ch->flags & EEPROM_CHANNEL_ACTIVE)
5903 geo_ch->flag |= IEEE80211_CHAN_W_ACTIVE_SCAN;
5904
5905 if (ch->flags & EEPROM_CHANNEL_RADAR)
5906 geo_ch->flag |= IEEE80211_CHAN_W_RADAR_DETECT;
5907
5908 if (ch->max_power_avg > priv->max_channel_txpower_limit)
5909 priv->max_channel_txpower_limit =
5910 ch->max_power_avg;
5911 }
5912
5913 geo_ch->val = geo_ch->flag;
5914 }
5915
5916 if ((modes[A].num_channels == 0) && priv->is_abg) {
5917 printk(KERN_INFO DRV_NAME
5918 ": Incorrectly detected BG card as ABG. Please send "
5919 "your PCI ID 0x%04X:0x%04X to maintainer.\n",
5920 priv->pci_dev->device, priv->pci_dev->subsystem_device);
5921 priv->is_abg = 0;
5922 }
5923
5924 printk(KERN_INFO DRV_NAME
5925 ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
5926 modes[G].num_channels, modes[A].num_channels);
5927
5928 /*
5929 * NOTE: We register these in preference of order -- the
5930 * stack doesn't currently (as of 7.0.6 / Apr 24 '07) pick
5931 * a phymode based on rates or AP capabilities but seems to
5932 * configure it purely on if the channel being configured
5933 * is supported by a mode -- and the first match is taken
5934 */
5935
5936 if (modes[G].num_channels)
5937 ieee80211_register_hwmode(priv->hw, &modes[G]);
5938 if (modes[B].num_channels)
5939 ieee80211_register_hwmode(priv->hw, &modes[B]);
5940 if (modes[A].num_channels)
5941 ieee80211_register_hwmode(priv->hw, &modes[A]);
5942
5943 priv->modes = modes;
5944 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
5945
5946 return 0;
5947}
5948
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005949/*
5950 * iwl4965_free_geos - undo allocations in iwl4965_init_geos
5951 */
5952static void iwl4965_free_geos(struct iwl4965_priv *priv)
5953{
5954 kfree(priv->modes);
5955 kfree(priv->ieee_channels);
5956 kfree(priv->ieee_rates);
5957 clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
5958}
5959
Zhu Yib481de92007-09-25 17:54:57 -07005960/******************************************************************************
5961 *
5962 * uCode download functions
5963 *
5964 ******************************************************************************/
5965
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005966static void iwl4965_dealloc_ucode_pci(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005967{
Tomas Winkler98c92212008-01-14 17:46:20 -08005968 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
5969 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
5970 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
5971 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
5972 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
5973 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07005974}
5975
5976/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005977 * iwl4965_verify_inst_full - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07005978 * looking at all data.
5979 */
Tomas Winkler4fd1f842007-12-05 20:59:58 +02005980static int iwl4965_verify_inst_full(struct iwl4965_priv *priv, __le32 *image,
Ben Cahill9fbab512007-11-29 11:09:47 +08005981 u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07005982{
5983 u32 val;
5984 u32 save_len = len;
5985 int rc = 0;
5986 u32 errcnt;
5987
5988 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
5989
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005990 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005991 if (rc)
5992 return rc;
5993
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005994 iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND);
Zhu Yib481de92007-09-25 17:54:57 -07005995
5996 errcnt = 0;
5997 for (; len > 0; len -= sizeof(u32), image++) {
5998 /* read data comes through single port, auto-incr addr */
5999 /* NOTE: Use the debugless read so we don't flood kernel log
6000 * if IWL_DL_IO is set */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006001 val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07006002 if (val != le32_to_cpu(*image)) {
6003 IWL_ERROR("uCode INST section is invalid at "
6004 "offset 0x%x, is 0x%x, s/b 0x%x\n",
6005 save_len - len, val, le32_to_cpu(*image));
6006 rc = -EIO;
6007 errcnt++;
6008 if (errcnt >= 20)
6009 break;
6010 }
6011 }
6012
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006013 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006014
6015 if (!errcnt)
6016 IWL_DEBUG_INFO
6017 ("ucode image in INSTRUCTION memory is good\n");
6018
6019 return rc;
6020}
6021
6022
6023/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006024 * iwl4965_verify_inst_sparse - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07006025 * using sample data 100 bytes apart. If these sample points are good,
6026 * it's a pretty good bet that everything between them is good, too.
6027 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006028static int iwl4965_verify_inst_sparse(struct iwl4965_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07006029{
6030 u32 val;
6031 int rc = 0;
6032 u32 errcnt = 0;
6033 u32 i;
6034
6035 IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
6036
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006037 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006038 if (rc)
6039 return rc;
6040
6041 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
6042 /* read data comes through single port, auto-incr addr */
6043 /* NOTE: Use the debugless read so we don't flood kernel log
6044 * if IWL_DL_IO is set */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006045 iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Zhu Yib481de92007-09-25 17:54:57 -07006046 i + RTC_INST_LOWER_BOUND);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006047 val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07006048 if (val != le32_to_cpu(*image)) {
6049#if 0 /* Enable this if you want to see details */
6050 IWL_ERROR("uCode INST section is invalid at "
6051 "offset 0x%x, is 0x%x, s/b 0x%x\n",
6052 i, val, *image);
6053#endif
6054 rc = -EIO;
6055 errcnt++;
6056 if (errcnt >= 3)
6057 break;
6058 }
6059 }
6060
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006061 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006062
6063 return rc;
6064}
6065
6066
6067/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006068 * iwl4965_verify_ucode - determine which instruction image is in SRAM,
Zhu Yib481de92007-09-25 17:54:57 -07006069 * and verify its contents
6070 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006071static int iwl4965_verify_ucode(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006072{
6073 __le32 *image;
6074 u32 len;
6075 int rc = 0;
6076
6077 /* Try bootstrap */
6078 image = (__le32 *)priv->ucode_boot.v_addr;
6079 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006080 rc = iwl4965_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07006081 if (rc == 0) {
6082 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
6083 return 0;
6084 }
6085
6086 /* Try initialize */
6087 image = (__le32 *)priv->ucode_init.v_addr;
6088 len = priv->ucode_init.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006089 rc = iwl4965_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07006090 if (rc == 0) {
6091 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
6092 return 0;
6093 }
6094
6095 /* Try runtime/protocol */
6096 image = (__le32 *)priv->ucode_code.v_addr;
6097 len = priv->ucode_code.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006098 rc = iwl4965_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07006099 if (rc == 0) {
6100 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
6101 return 0;
6102 }
6103
6104 IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
6105
Ben Cahill9fbab512007-11-29 11:09:47 +08006106 /* Since nothing seems to match, show first several data entries in
6107 * instruction SRAM, so maybe visual inspection will give a clue.
6108 * Selection of bootstrap image (vs. other images) is arbitrary. */
Zhu Yib481de92007-09-25 17:54:57 -07006109 image = (__le32 *)priv->ucode_boot.v_addr;
6110 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006111 rc = iwl4965_verify_inst_full(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07006112
6113 return rc;
6114}
6115
6116
6117/* check contents of special bootstrap uCode SRAM */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006118static int iwl4965_verify_bsm(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006119{
6120 __le32 *image = priv->ucode_boot.v_addr;
6121 u32 len = priv->ucode_boot.len;
6122 u32 reg;
6123 u32 val;
6124
6125 IWL_DEBUG_INFO("Begin verify bsm\n");
6126
6127 /* verify BSM SRAM contents */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006128 val = iwl4965_read_prph(priv, BSM_WR_DWCOUNT_REG);
Zhu Yib481de92007-09-25 17:54:57 -07006129 for (reg = BSM_SRAM_LOWER_BOUND;
6130 reg < BSM_SRAM_LOWER_BOUND + len;
6131 reg += sizeof(u32), image ++) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006132 val = iwl4965_read_prph(priv, reg);
Zhu Yib481de92007-09-25 17:54:57 -07006133 if (val != le32_to_cpu(*image)) {
6134 IWL_ERROR("BSM uCode verification failed at "
6135 "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
6136 BSM_SRAM_LOWER_BOUND,
6137 reg - BSM_SRAM_LOWER_BOUND, len,
6138 val, le32_to_cpu(*image));
6139 return -EIO;
6140 }
6141 }
6142
6143 IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
6144
6145 return 0;
6146}
6147
6148/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006149 * iwl4965_load_bsm - Load bootstrap instructions
Zhu Yib481de92007-09-25 17:54:57 -07006150 *
6151 * BSM operation:
6152 *
6153 * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
6154 * in special SRAM that does not power down during RFKILL. When powering back
6155 * up after power-saving sleeps (or during initial uCode load), the BSM loads
6156 * the bootstrap program into the on-board processor, and starts it.
6157 *
6158 * The bootstrap program loads (via DMA) instructions and data for a new
6159 * program from host DRAM locations indicated by the host driver in the
6160 * BSM_DRAM_* registers. Once the new program is loaded, it starts
6161 * automatically.
6162 *
6163 * When initializing the NIC, the host driver points the BSM to the
6164 * "initialize" uCode image. This uCode sets up some internal data, then
6165 * notifies host via "initialize alive" that it is complete.
6166 *
6167 * The host then replaces the BSM_DRAM_* pointer values to point to the
6168 * normal runtime uCode instructions and a backup uCode data cache buffer
6169 * (filled initially with starting data values for the on-board processor),
6170 * then triggers the "initialize" uCode to load and launch the runtime uCode,
6171 * which begins normal operation.
6172 *
6173 * When doing a power-save shutdown, runtime uCode saves data SRAM into
6174 * the backup data cache in DRAM before SRAM is powered down.
6175 *
6176 * When powering back up, the BSM loads the bootstrap program. This reloads
6177 * the runtime uCode instructions and the backup data cache into SRAM,
6178 * and re-launches the runtime uCode from where it left off.
6179 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006180static int iwl4965_load_bsm(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006181{
6182 __le32 *image = priv->ucode_boot.v_addr;
6183 u32 len = priv->ucode_boot.len;
6184 dma_addr_t pinst;
6185 dma_addr_t pdata;
6186 u32 inst_len;
6187 u32 data_len;
6188 int rc;
6189 int i;
6190 u32 done;
6191 u32 reg_offset;
6192
6193 IWL_DEBUG_INFO("Begin load bsm\n");
6194
6195 /* make sure bootstrap program is no larger than BSM's SRAM size */
6196 if (len > IWL_MAX_BSM_SIZE)
6197 return -EINVAL;
6198
6199 /* Tell bootstrap uCode where to find the "Initialize" uCode
Ben Cahill9fbab512007-11-29 11:09:47 +08006200 * in host DRAM ... host DRAM physical address bits 35:4 for 4965.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006201 * NOTE: iwl4965_initialize_alive_start() will replace these values,
Zhu Yib481de92007-09-25 17:54:57 -07006202 * after the "initialize" uCode has run, to point to
6203 * runtime/protocol instructions and backup data cache. */
6204 pinst = priv->ucode_init.p_addr >> 4;
6205 pdata = priv->ucode_init_data.p_addr >> 4;
6206 inst_len = priv->ucode_init.len;
6207 data_len = priv->ucode_init_data.len;
6208
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006209 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006210 if (rc)
6211 return rc;
6212
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006213 iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
6214 iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
6215 iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
6216 iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
Zhu Yib481de92007-09-25 17:54:57 -07006217
6218 /* Fill BSM memory with bootstrap instructions */
6219 for (reg_offset = BSM_SRAM_LOWER_BOUND;
6220 reg_offset < BSM_SRAM_LOWER_BOUND + len;
6221 reg_offset += sizeof(u32), image++)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006222 _iwl4965_write_prph(priv, reg_offset,
Zhu Yib481de92007-09-25 17:54:57 -07006223 le32_to_cpu(*image));
6224
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006225 rc = iwl4965_verify_bsm(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006226 if (rc) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006227 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006228 return rc;
6229 }
6230
6231 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006232 iwl4965_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0);
6233 iwl4965_write_prph(priv, BSM_WR_MEM_DST_REG,
Zhu Yib481de92007-09-25 17:54:57 -07006234 RTC_INST_LOWER_BOUND);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006235 iwl4965_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07006236
6237 /* Load bootstrap code into instruction SRAM now,
6238 * to prepare to load "initialize" uCode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006239 iwl4965_write_prph(priv, BSM_WR_CTRL_REG,
Zhu Yib481de92007-09-25 17:54:57 -07006240 BSM_WR_CTRL_REG_BIT_START);
6241
6242 /* Wait for load of bootstrap uCode to finish */
6243 for (i = 0; i < 100; i++) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006244 done = iwl4965_read_prph(priv, BSM_WR_CTRL_REG);
Zhu Yib481de92007-09-25 17:54:57 -07006245 if (!(done & BSM_WR_CTRL_REG_BIT_START))
6246 break;
6247 udelay(10);
6248 }
6249 if (i < 100)
6250 IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i);
6251 else {
6252 IWL_ERROR("BSM write did not complete!\n");
6253 return -EIO;
6254 }
6255
6256 /* Enable future boot loads whenever power management unit triggers it
6257 * (e.g. when powering back up after power-save shutdown) */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006258 iwl4965_write_prph(priv, BSM_WR_CTRL_REG,
Zhu Yib481de92007-09-25 17:54:57 -07006259 BSM_WR_CTRL_REG_BIT_START_EN);
6260
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006261 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006262
6263 return 0;
6264}
6265
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006266static void iwl4965_nic_start(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006267{
6268 /* Remove all resets to allow NIC to operate */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006269 iwl4965_write32(priv, CSR_RESET, 0);
Zhu Yib481de92007-09-25 17:54:57 -07006270}
6271
Tomas Winkler90e759d2007-11-29 11:09:41 +08006272
Zhu Yib481de92007-09-25 17:54:57 -07006273/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006274 * iwl4965_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07006275 *
6276 * Copy into buffers for card to fetch via bus-mastering
6277 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006278static int iwl4965_read_ucode(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006279{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006280 struct iwl4965_ucode *ucode;
Tomas Winkler90e759d2007-11-29 11:09:41 +08006281 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07006282 const struct firmware *ucode_raw;
6283 const char *name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode";
6284 u8 *src;
6285 size_t len;
6286 u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
6287
6288 /* Ask kernel firmware_class module to get the boot firmware off disk.
6289 * request_firmware() is synchronous, file is in memory on return. */
Tomas Winkler90e759d2007-11-29 11:09:41 +08006290 ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
6291 if (ret < 0) {
6292 IWL_ERROR("%s firmware file req failed: Reason %d\n",
6293 name, ret);
Zhu Yib481de92007-09-25 17:54:57 -07006294 goto error;
6295 }
6296
6297 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
6298 name, ucode_raw->size);
6299
6300 /* Make sure that we got at least our header! */
6301 if (ucode_raw->size < sizeof(*ucode)) {
6302 IWL_ERROR("File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08006303 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07006304 goto err_release;
6305 }
6306
6307 /* Data from ucode file: header followed by uCode images */
6308 ucode = (void *)ucode_raw->data;
6309
6310 ver = le32_to_cpu(ucode->ver);
6311 inst_size = le32_to_cpu(ucode->inst_size);
6312 data_size = le32_to_cpu(ucode->data_size);
6313 init_size = le32_to_cpu(ucode->init_size);
6314 init_data_size = le32_to_cpu(ucode->init_data_size);
6315 boot_size = le32_to_cpu(ucode->boot_size);
6316
6317 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
6318 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
6319 inst_size);
6320 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
6321 data_size);
6322 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
6323 init_size);
6324 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
6325 init_data_size);
6326 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
6327 boot_size);
6328
6329 /* Verify size of file vs. image size info in file's header */
6330 if (ucode_raw->size < sizeof(*ucode) +
6331 inst_size + data_size + init_size +
6332 init_data_size + boot_size) {
6333
6334 IWL_DEBUG_INFO("uCode file size %d too small\n",
6335 (int)ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08006336 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07006337 goto err_release;
6338 }
6339
6340 /* Verify that uCode images will fit in card's SRAM */
6341 if (inst_size > IWL_MAX_INST_SIZE) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08006342 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
6343 inst_size);
6344 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07006345 goto err_release;
6346 }
6347
6348 if (data_size > IWL_MAX_DATA_SIZE) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08006349 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
6350 data_size);
6351 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07006352 goto err_release;
6353 }
6354 if (init_size > IWL_MAX_INST_SIZE) {
6355 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08006356 ("uCode init instr len %d too large to fit in\n",
6357 init_size);
6358 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07006359 goto err_release;
6360 }
6361 if (init_data_size > IWL_MAX_DATA_SIZE) {
6362 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08006363 ("uCode init data len %d too large to fit in\n",
6364 init_data_size);
6365 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07006366 goto err_release;
6367 }
6368 if (boot_size > IWL_MAX_BSM_SIZE) {
6369 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08006370 ("uCode boot instr len %d too large to fit in\n",
6371 boot_size);
6372 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07006373 goto err_release;
6374 }
6375
6376 /* Allocate ucode buffers for card's bus-master loading ... */
6377
6378 /* Runtime instructions and 2 copies of data:
6379 * 1) unmodified from disk
6380 * 2) backup cache for save/restore during power-downs */
6381 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08006382 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07006383
6384 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08006385 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07006386
6387 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08006388 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07006389
6390 /* Initialization instructions and data */
Tomas Winkler90e759d2007-11-29 11:09:41 +08006391 if (init_size && init_data_size) {
6392 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08006393 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Zhu Yib481de92007-09-25 17:54:57 -07006394
Tomas Winkler90e759d2007-11-29 11:09:41 +08006395 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08006396 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08006397
6398 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
6399 goto err_pci_alloc;
6400 }
Zhu Yib481de92007-09-25 17:54:57 -07006401
6402 /* Bootstrap (instructions only, no data) */
Tomas Winkler90e759d2007-11-29 11:09:41 +08006403 if (boot_size) {
6404 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08006405 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07006406
Tomas Winkler90e759d2007-11-29 11:09:41 +08006407 if (!priv->ucode_boot.v_addr)
6408 goto err_pci_alloc;
6409 }
Zhu Yib481de92007-09-25 17:54:57 -07006410
6411 /* Copy images into buffers for card's bus-master reads ... */
6412
6413 /* Runtime instructions (first block of data in file) */
6414 src = &ucode->data[0];
6415 len = priv->ucode_code.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08006416 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07006417 memcpy(priv->ucode_code.v_addr, src, len);
6418 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
6419 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
6420
6421 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006422 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
Zhu Yib481de92007-09-25 17:54:57 -07006423 src = &ucode->data[inst_size];
6424 len = priv->ucode_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08006425 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07006426 memcpy(priv->ucode_data.v_addr, src, len);
6427 memcpy(priv->ucode_data_backup.v_addr, src, len);
6428
6429 /* Initialization instructions (3rd block) */
6430 if (init_size) {
6431 src = &ucode->data[inst_size + data_size];
6432 len = priv->ucode_init.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08006433 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
6434 len);
Zhu Yib481de92007-09-25 17:54:57 -07006435 memcpy(priv->ucode_init.v_addr, src, len);
6436 }
6437
6438 /* Initialization data (4th block) */
6439 if (init_data_size) {
6440 src = &ucode->data[inst_size + data_size + init_size];
6441 len = priv->ucode_init_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08006442 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
6443 len);
Zhu Yib481de92007-09-25 17:54:57 -07006444 memcpy(priv->ucode_init_data.v_addr, src, len);
6445 }
6446
6447 /* Bootstrap instructions (5th block) */
6448 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
6449 len = priv->ucode_boot.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08006450 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07006451 memcpy(priv->ucode_boot.v_addr, src, len);
6452
6453 /* We have our copies now, allow OS release its copies */
6454 release_firmware(ucode_raw);
6455 return 0;
6456
6457 err_pci_alloc:
6458 IWL_ERROR("failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08006459 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006460 iwl4965_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006461
6462 err_release:
6463 release_firmware(ucode_raw);
6464
6465 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08006466 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07006467}
6468
6469
6470/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006471 * iwl4965_set_ucode_ptrs - Set uCode address location
Zhu Yib481de92007-09-25 17:54:57 -07006472 *
6473 * Tell initialization uCode where to find runtime uCode.
6474 *
6475 * BSM registers initially contain pointers to initialization uCode.
6476 * We need to replace them to load runtime uCode inst and data,
6477 * and to save runtime data when powering down.
6478 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006479static int iwl4965_set_ucode_ptrs(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006480{
6481 dma_addr_t pinst;
6482 dma_addr_t pdata;
6483 int rc = 0;
6484 unsigned long flags;
6485
6486 /* bits 35:4 for 4965 */
6487 pinst = priv->ucode_code.p_addr >> 4;
6488 pdata = priv->ucode_data_backup.p_addr >> 4;
6489
6490 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006491 rc = iwl4965_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006492 if (rc) {
6493 spin_unlock_irqrestore(&priv->lock, flags);
6494 return rc;
6495 }
6496
6497 /* Tell bootstrap uCode where to find image to load */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006498 iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
6499 iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
6500 iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07006501 priv->ucode_data.len);
6502
6503 /* Inst bytecount must be last to set up, bit 31 signals uCode
6504 * that all new ptr/size info is in place */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006505 iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07006506 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
6507
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006508 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006509
6510 spin_unlock_irqrestore(&priv->lock, flags);
6511
6512 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
6513
6514 return rc;
6515}
6516
6517/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006518 * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07006519 *
6520 * Called after REPLY_ALIVE notification received from "initialize" uCode.
6521 *
6522 * The 4965 "initialize" ALIVE reply contains calibration data for:
6523 * Voltage, temperature, and MIMO tx gain correction, now stored in priv
6524 * (3945 does not contain this data).
6525 *
6526 * Tell "initialize" uCode to go ahead and load the runtime uCode.
6527*/
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006528static void iwl4965_init_alive_start(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006529{
6530 /* Check alive response for "valid" sign from uCode */
6531 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
6532 /* We had an error bringing up the hardware, so take it
6533 * all the way back down so we can try again */
6534 IWL_DEBUG_INFO("Initialize Alive failed.\n");
6535 goto restart;
6536 }
6537
6538 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
6539 * This is a paranoid check, because we would not have gotten the
6540 * "initialize" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006541 if (iwl4965_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006542 /* Runtime instruction load was bad;
6543 * take it all the way back down so we can try again */
6544 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
6545 goto restart;
6546 }
6547
6548 /* Calculate temperature */
6549 priv->temperature = iwl4965_get_temperature(priv);
6550
6551 /* Send pointers to protocol/runtime uCode image ... init code will
6552 * load and launch runtime uCode, which will send us another "Alive"
6553 * notification. */
6554 IWL_DEBUG_INFO("Initialization Alive received.\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006555 if (iwl4965_set_ucode_ptrs(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006556 /* Runtime instruction load won't happen;
6557 * take it all the way back down so we can try again */
6558 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
6559 goto restart;
6560 }
6561 return;
6562
6563 restart:
6564 queue_work(priv->workqueue, &priv->restart);
6565}
6566
6567
6568/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006569 * iwl4965_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07006570 * from protocol/runtime uCode (initialization uCode's
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006571 * Alive gets handled by iwl4965_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07006572 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006573static void iwl4965_alive_start(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006574{
6575 int rc = 0;
6576
6577 IWL_DEBUG_INFO("Runtime Alive received.\n");
6578
6579 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
6580 /* We had an error bringing up the hardware, so take it
6581 * all the way back down so we can try again */
6582 IWL_DEBUG_INFO("Alive failed.\n");
6583 goto restart;
6584 }
6585
6586 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
6587 * This is a paranoid check, because we would not have gotten the
6588 * "runtime" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006589 if (iwl4965_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006590 /* Runtime instruction load was bad;
6591 * take it all the way back down so we can try again */
6592 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
6593 goto restart;
6594 }
6595
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006596 iwl4965_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006597
6598 rc = iwl4965_alive_notify(priv);
6599 if (rc) {
6600 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
6601 rc);
6602 goto restart;
6603 }
6604
Ben Cahill9fbab512007-11-29 11:09:47 +08006605 /* After the ALIVE response, we can send host commands to 4965 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07006606 set_bit(STATUS_ALIVE, &priv->status);
6607
6608 /* Clear out the uCode error bit if it is set */
6609 clear_bit(STATUS_FW_ERROR, &priv->status);
6610
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006611 if (iwl4965_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07006612 return;
6613
Zhu Yi5a669262008-01-14 17:46:18 -08006614 ieee80211_start_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07006615
6616 priv->active_rate = priv->rates_mask;
6617 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
6618
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006619 iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode));
Zhu Yib481de92007-09-25 17:54:57 -07006620
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006621 if (iwl4965_is_associated(priv)) {
6622 struct iwl4965_rxon_cmd *active_rxon =
6623 (struct iwl4965_rxon_cmd *)(&priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07006624
6625 memcpy(&priv->staging_rxon, &priv->active_rxon,
6626 sizeof(priv->staging_rxon));
6627 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
6628 } else {
6629 /* Initialize our rx_config data */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006630 iwl4965_connection_init_rx_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006631 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
6632 }
6633
Ben Cahill9fbab512007-11-29 11:09:47 +08006634 /* Configure Bluetooth device coexistence support */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006635 iwl4965_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006636
6637 /* Configure the adapter for unassociated operation */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006638 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006639
6640 /* At this point, the NIC is initialized and operational */
6641 priv->notif_missed_beacons = 0;
6642 set_bit(STATUS_READY, &priv->status);
6643
6644 iwl4965_rf_kill_ct_config(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08006645
Zhu Yib481de92007-09-25 17:54:57 -07006646 IWL_DEBUG_INFO("ALIVE processing complete.\n");
Zhu Yi5a669262008-01-14 17:46:18 -08006647 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07006648
6649 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006650 iwl4965_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006651
6652 return;
6653
6654 restart:
6655 queue_work(priv->workqueue, &priv->restart);
6656}
6657
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006658static void iwl4965_cancel_deferred_work(struct iwl4965_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07006659
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006660static void __iwl4965_down(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006661{
6662 unsigned long flags;
6663 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
6664 struct ieee80211_conf *conf = NULL;
6665
6666 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
6667
6668 conf = ieee80211_get_hw_conf(priv->hw);
6669
6670 if (!exit_pending)
6671 set_bit(STATUS_EXIT_PENDING, &priv->status);
6672
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006673 iwl4965_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006674
6675 /* Unblock any waiting calls */
6676 wake_up_interruptible_all(&priv->wait_command_queue);
6677
Zhu Yib481de92007-09-25 17:54:57 -07006678 /* Wipe out the EXIT_PENDING status bit if we are not actually
6679 * exiting the module */
6680 if (!exit_pending)
6681 clear_bit(STATUS_EXIT_PENDING, &priv->status);
6682
6683 /* stop and reset the on-board processor */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006684 iwl4965_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07006685
6686 /* tell the device to stop sending interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006687 iwl4965_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006688
6689 if (priv->mac80211_registered)
6690 ieee80211_stop_queues(priv->hw);
6691
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006692 /* If we have not previously called iwl4965_init() then
Zhu Yib481de92007-09-25 17:54:57 -07006693 * clear all bits but the RF Kill and SUSPEND bits and return */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006694 if (!iwl4965_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006695 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
6696 STATUS_RF_KILL_HW |
6697 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
6698 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08006699 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
6700 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07006701 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
6702 STATUS_IN_SUSPEND;
6703 goto exit;
6704 }
6705
6706 /* ...otherwise clear out all the status bits but the RF Kill and
6707 * SUSPEND bits and continue taking the NIC down. */
6708 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
6709 STATUS_RF_KILL_HW |
6710 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
6711 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08006712 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
6713 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07006714 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
6715 STATUS_IN_SUSPEND |
6716 test_bit(STATUS_FW_ERROR, &priv->status) <<
6717 STATUS_FW_ERROR;
6718
6719 spin_lock_irqsave(&priv->lock, flags);
Ben Cahill9fbab512007-11-29 11:09:47 +08006720 iwl4965_clear_bit(priv, CSR_GP_CNTRL,
6721 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07006722 spin_unlock_irqrestore(&priv->lock, flags);
6723
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006724 iwl4965_hw_txq_ctx_stop(priv);
6725 iwl4965_hw_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006726
6727 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006728 if (!iwl4965_grab_nic_access(priv)) {
6729 iwl4965_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07006730 APMG_CLK_VAL_DMA_CLK_RQT);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006731 iwl4965_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006732 }
6733 spin_unlock_irqrestore(&priv->lock, flags);
6734
6735 udelay(5);
6736
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006737 iwl4965_hw_nic_stop_master(priv);
6738 iwl4965_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
6739 iwl4965_hw_nic_reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006740
6741 exit:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006742 memset(&priv->card_alive, 0, sizeof(struct iwl4965_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07006743
6744 if (priv->ibss_beacon)
6745 dev_kfree_skb(priv->ibss_beacon);
6746 priv->ibss_beacon = NULL;
6747
6748 /* clear out any free frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006749 iwl4965_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006750}
6751
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006752static void iwl4965_down(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006753{
6754 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006755 __iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006756 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08006757
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006758 iwl4965_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006759}
6760
6761#define MAX_HW_RESTARTS 5
6762
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006763static int __iwl4965_up(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07006764{
6765 int rc, i;
Zhu Yib481de92007-09-25 17:54:57 -07006766
6767 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
6768 IWL_WARNING("Exit pending; will not bring the NIC up\n");
6769 return -EIO;
6770 }
6771
6772 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
6773 IWL_WARNING("Radio disabled by SW RF kill (module "
6774 "parameter)\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08006775 return -ENODEV;
6776 }
6777
Reinette Chatree903fbd2008-01-30 22:05:15 -08006778 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
6779 IWL_ERROR("ucode not available for device bringup\n");
6780 return -EIO;
6781 }
6782
Zhu Yie655b9f2008-01-24 02:19:38 -08006783 /* If platform's RF_KILL switch is NOT set to KILL */
6784 if (iwl4965_read32(priv, CSR_GP_CNTRL) &
6785 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
6786 clear_bit(STATUS_RF_KILL_HW, &priv->status);
6787 else {
6788 set_bit(STATUS_RF_KILL_HW, &priv->status);
6789 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
6790 IWL_WARNING("Radio disabled by HW RF Kill switch\n");
6791 return -ENODEV;
6792 }
Zhu Yib481de92007-09-25 17:54:57 -07006793 }
6794
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006795 iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07006796
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006797 rc = iwl4965_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006798 if (rc) {
6799 IWL_ERROR("Unable to int nic\n");
6800 return rc;
6801 }
6802
6803 /* make sure rfkill handshake bits are cleared */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006804 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
6805 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07006806 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
6807
6808 /* clear (again), then enable host interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006809 iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF);
6810 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006811
6812 /* really make sure rfkill handshake bits are cleared */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006813 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
6814 iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07006815
6816 /* Copy original ucode data image from disk into backup cache.
6817 * This will be used to initialize the on-board processor's
6818 * data SRAM for a clean start when the runtime program first loads. */
6819 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a669262008-01-14 17:46:18 -08006820 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07006821
Zhu Yie655b9f2008-01-24 02:19:38 -08006822 /* We return success when we resume from suspend and rf_kill is on. */
6823 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07006824 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07006825
6826 for (i = 0; i < MAX_HW_RESTARTS; i++) {
6827
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006828 iwl4965_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006829
6830 /* load bootstrap state machine,
6831 * load bootstrap program into processor's memory,
6832 * prepare to load the "initialize" uCode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006833 rc = iwl4965_load_bsm(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006834
6835 if (rc) {
6836 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc);
6837 continue;
6838 }
6839
6840 /* start card; "initialize" will load runtime ucode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006841 iwl4965_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006842
Zhu Yib481de92007-09-25 17:54:57 -07006843 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
6844
6845 return 0;
6846 }
6847
6848 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006849 __iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006850
6851 /* tried to restart and config the device for as long as our
6852 * patience could withstand */
6853 IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
6854 return -EIO;
6855}
6856
6857
6858/*****************************************************************************
6859 *
6860 * Workqueue callbacks
6861 *
6862 *****************************************************************************/
6863
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006864static void iwl4965_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07006865{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006866 struct iwl4965_priv *priv =
6867 container_of(data, struct iwl4965_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07006868
6869 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6870 return;
6871
6872 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006873 iwl4965_init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006874 mutex_unlock(&priv->mutex);
6875}
6876
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006877static void iwl4965_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07006878{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006879 struct iwl4965_priv *priv =
6880 container_of(data, struct iwl4965_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07006881
6882 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6883 return;
6884
6885 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006886 iwl4965_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006887 mutex_unlock(&priv->mutex);
6888}
6889
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006890static void iwl4965_bg_rf_kill(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07006891{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006892 struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, rf_kill);
Zhu Yib481de92007-09-25 17:54:57 -07006893
6894 wake_up_interruptible(&priv->wait_command_queue);
6895
6896 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6897 return;
6898
6899 mutex_lock(&priv->mutex);
6900
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006901 if (!iwl4965_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006902 IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL,
6903 "HW and/or SW RF Kill no longer active, restarting "
6904 "device\n");
6905 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
6906 queue_work(priv->workqueue, &priv->restart);
6907 } else {
6908
6909 if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
6910 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
6911 "disabled by SW switch\n");
6912 else
6913 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
6914 "Kill switch must be turned off for "
6915 "wireless networking to work.\n");
6916 }
6917 mutex_unlock(&priv->mutex);
6918}
6919
6920#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
6921
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006922static void iwl4965_bg_scan_check(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07006923{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006924 struct iwl4965_priv *priv =
6925 container_of(data, struct iwl4965_priv, scan_check.work);
Zhu Yib481de92007-09-25 17:54:57 -07006926
6927 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6928 return;
6929
6930 mutex_lock(&priv->mutex);
6931 if (test_bit(STATUS_SCANNING, &priv->status) ||
6932 test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
6933 IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN,
6934 "Scan completion watchdog resetting adapter (%dms)\n",
6935 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG));
mabbas052c4b92007-10-25 17:15:43 +08006936
Zhu Yib481de92007-09-25 17:54:57 -07006937 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006938 iwl4965_send_scan_abort(priv);
Zhu Yib481de92007-09-25 17:54:57 -07006939 }
6940 mutex_unlock(&priv->mutex);
6941}
6942
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006943static void iwl4965_bg_request_scan(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07006944{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006945 struct iwl4965_priv *priv =
6946 container_of(data, struct iwl4965_priv, request_scan);
6947 struct iwl4965_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07006948 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006949 .len = sizeof(struct iwl4965_scan_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07006950 .meta.flags = CMD_SIZE_HUGE,
6951 };
6952 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006953 struct iwl4965_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07006954 struct ieee80211_conf *conf = NULL;
6955 u8 direct_mask;
6956 int phymode;
6957
6958 conf = ieee80211_get_hw_conf(priv->hw);
6959
6960 mutex_lock(&priv->mutex);
6961
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006962 if (!iwl4965_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006963 IWL_WARNING("request scan called when driver not ready.\n");
6964 goto done;
6965 }
6966
6967 /* Make sure the scan wasn't cancelled before this queued work
6968 * was given the chance to run... */
6969 if (!test_bit(STATUS_SCANNING, &priv->status))
6970 goto done;
6971
6972 /* This should never be called or scheduled if there is currently
6973 * a scan active in the hardware. */
6974 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
6975 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
6976 "Ignoring second request.\n");
6977 rc = -EIO;
6978 goto done;
6979 }
6980
6981 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
6982 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
6983 goto done;
6984 }
6985
6986 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
6987 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6988 goto done;
6989 }
6990
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08006991 if (iwl4965_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07006992 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6993 goto done;
6994 }
6995
6996 if (!test_bit(STATUS_READY, &priv->status)) {
6997 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
6998 goto done;
6999 }
7000
7001 if (!priv->scan_bands) {
7002 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
7003 goto done;
7004 }
7005
7006 if (!priv->scan) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007007 priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) +
Zhu Yib481de92007-09-25 17:54:57 -07007008 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
7009 if (!priv->scan) {
7010 rc = -ENOMEM;
7011 goto done;
7012 }
7013 }
7014 scan = priv->scan;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007015 memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07007016
7017 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
7018 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
7019
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007020 if (iwl4965_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07007021 u16 interval = 0;
7022 u32 extra;
7023 u32 suspend_time = 100;
7024 u32 scan_suspend_time = 100;
7025 unsigned long flags;
7026
7027 IWL_DEBUG_INFO("Scanning while associated...\n");
7028
7029 spin_lock_irqsave(&priv->lock, flags);
7030 interval = priv->beacon_int;
7031 spin_unlock_irqrestore(&priv->lock, flags);
7032
7033 scan->suspend_time = 0;
mabbas052c4b92007-10-25 17:15:43 +08007034 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07007035 if (!interval)
7036 interval = suspend_time;
7037
7038 extra = (suspend_time / interval) << 22;
7039 scan_suspend_time = (extra |
7040 ((suspend_time % interval) * 1024));
7041 scan->suspend_time = cpu_to_le32(scan_suspend_time);
7042 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
7043 scan_suspend_time, interval);
7044 }
7045
7046 /* We should add the ability for user to lock to PASSIVE ONLY */
7047 if (priv->one_direct_scan) {
7048 IWL_DEBUG_SCAN
7049 ("Kicking off one direct scan for '%s'\n",
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007050 iwl4965_escape_essid(priv->direct_ssid,
Zhu Yib481de92007-09-25 17:54:57 -07007051 priv->direct_ssid_len));
7052 scan->direct_scan[0].id = WLAN_EID_SSID;
7053 scan->direct_scan[0].len = priv->direct_ssid_len;
7054 memcpy(scan->direct_scan[0].ssid,
7055 priv->direct_ssid, priv->direct_ssid_len);
7056 direct_mask = 1;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007057 } else if (!iwl4965_is_associated(priv) && priv->essid_len) {
Zhu Yib481de92007-09-25 17:54:57 -07007058 scan->direct_scan[0].id = WLAN_EID_SSID;
7059 scan->direct_scan[0].len = priv->essid_len;
7060 memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
7061 direct_mask = 1;
7062 } else
7063 direct_mask = 0;
7064
7065 /* We don't build a direct scan probe request; the uCode will do
7066 * that based on the direct_mask added to each channel entry */
7067 scan->tx_cmd.len = cpu_to_le16(
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007068 iwl4965_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data,
Cyrill Gorcunov18904f52008-01-26 19:09:36 +03007069 IWL_MAX_SCAN_SIZE - sizeof(*scan), 0));
Zhu Yib481de92007-09-25 17:54:57 -07007070 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
7071 scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id;
7072 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
7073
7074 /* flags + rate selection */
7075
7076 scan->tx_cmd.tx_flags |= cpu_to_le32(0x200);
7077
7078 switch (priv->scan_bands) {
7079 case 2:
7080 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
7081 scan->tx_cmd.rate_n_flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007082 iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP,
Zhu Yib481de92007-09-25 17:54:57 -07007083 RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK);
7084
7085 scan->good_CRC_th = 0;
7086 phymode = MODE_IEEE80211G;
7087 break;
7088
7089 case 1:
7090 scan->tx_cmd.rate_n_flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007091 iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP,
Zhu Yib481de92007-09-25 17:54:57 -07007092 RATE_MCS_ANT_B_MSK);
7093 scan->good_CRC_th = IWL_GOOD_CRC_TH;
7094 phymode = MODE_IEEE80211A;
7095 break;
7096
7097 default:
7098 IWL_WARNING("Invalid scan band count\n");
7099 goto done;
7100 }
7101
7102 /* select Rx chains */
7103
7104 /* Force use of chains B and C (0x6) for scan Rx.
7105 * Avoid A (0x1) because of its off-channel reception on A-band.
7106 * MIMO is not used here, but value is required to make uCode happy. */
7107 scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK |
7108 cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) |
7109 (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) |
7110 (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS));
7111
7112 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR)
7113 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
7114
7115 if (direct_mask)
7116 IWL_DEBUG_SCAN
7117 ("Initiating direct scan for %s.\n",
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007118 iwl4965_escape_essid(priv->essid, priv->essid_len));
Zhu Yib481de92007-09-25 17:54:57 -07007119 else
7120 IWL_DEBUG_SCAN("Initiating indirect scan.\n");
7121
7122 scan->channel_count =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007123 iwl4965_get_channels_for_scan(
Zhu Yib481de92007-09-25 17:54:57 -07007124 priv, phymode, 1, /* active */
7125 direct_mask,
7126 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
7127
7128 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007129 scan->channel_count * sizeof(struct iwl4965_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07007130 cmd.data = scan;
7131 scan->len = cpu_to_le16(cmd.len);
7132
7133 set_bit(STATUS_SCAN_HW, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007134 rc = iwl4965_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07007135 if (rc)
7136 goto done;
7137
7138 queue_delayed_work(priv->workqueue, &priv->scan_check,
7139 IWL_SCAN_CHECK_WATCHDOG);
7140
7141 mutex_unlock(&priv->mutex);
7142 return;
7143
7144 done:
Ian Schram01ebd062007-10-25 17:15:22 +08007145 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07007146 queue_work(priv->workqueue, &priv->scan_completed);
7147 mutex_unlock(&priv->mutex);
7148}
7149
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007150static void iwl4965_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07007151{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007152 struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07007153
7154 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7155 return;
7156
7157 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007158 __iwl4965_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007159 mutex_unlock(&priv->mutex);
7160}
7161
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007162static void iwl4965_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07007163{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007164 struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07007165
7166 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7167 return;
7168
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007169 iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007170 queue_work(priv->workqueue, &priv->up);
7171}
7172
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007173static void iwl4965_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07007174{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007175 struct iwl4965_priv *priv =
7176 container_of(data, struct iwl4965_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07007177
7178 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7179 return;
7180
7181 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007182 iwl4965_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007183 mutex_unlock(&priv->mutex);
7184}
7185
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08007186#define IWL_DELAY_NEXT_SCAN (HZ*2)
7187
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007188static void iwl4965_bg_post_associate(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07007189{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007190 struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv,
Zhu Yib481de92007-09-25 17:54:57 -07007191 post_associate.work);
7192
7193 int rc = 0;
7194 struct ieee80211_conf *conf = NULL;
Joe Perches0795af52007-10-03 17:59:30 -07007195 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07007196
7197 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
7198 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__);
7199 return;
7200 }
7201
Joe Perches0795af52007-10-03 17:59:30 -07007202 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
7203 priv->assoc_id,
7204 print_mac(mac, priv->active_rxon.bssid_addr));
Zhu Yib481de92007-09-25 17:54:57 -07007205
7206
7207 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7208 return;
7209
7210 mutex_lock(&priv->mutex);
7211
Johannes Berg32bfd352007-12-19 01:31:26 +01007212 if (!priv->vif || !priv->is_open) {
Mohamed Abbas948c1712007-10-25 17:15:45 +08007213 mutex_unlock(&priv->mutex);
7214 return;
7215 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007216 iwl4965_scan_cancel_timeout(priv, 200);
mabbas052c4b92007-10-25 17:15:43 +08007217
Zhu Yib481de92007-09-25 17:54:57 -07007218 conf = ieee80211_get_hw_conf(priv->hw);
7219
7220 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007221 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007222
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007223 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
7224 iwl4965_setup_rxon_timing(priv);
7225 rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07007226 sizeof(priv->rxon_timing), &priv->rxon_timing);
7227 if (rc)
7228 IWL_WARNING("REPLY_RXON_TIMING failed - "
7229 "Attempting to continue.\n");
7230
7231 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
7232
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007233#ifdef CONFIG_IWL4965_HT
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02007234 if (priv->current_ht_config.is_ht)
7235 iwl4965_set_rxon_ht(priv, &priv->current_ht_config);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007236#endif /* CONFIG_IWL4965_HT*/
Zhu Yib481de92007-09-25 17:54:57 -07007237 iwl4965_set_rxon_chain(priv);
7238 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
7239
7240 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
7241 priv->assoc_id, priv->beacon_int);
7242
7243 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7244 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
7245 else
7246 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
7247
7248 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
7249 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
7250 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
7251 else
7252 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
7253
7254 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
7255 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
7256
7257 }
7258
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007259 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007260
7261 switch (priv->iw_mode) {
7262 case IEEE80211_IF_TYPE_STA:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007263 iwl4965_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07007264 break;
7265
7266 case IEEE80211_IF_TYPE_IBSS:
7267
7268 /* clear out the station table */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007269 iwl4965_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007270
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007271 iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0);
7272 iwl4965_rxon_add_station(priv, priv->bssid, 0);
7273 iwl4965_rate_scale_init(priv->hw, IWL_STA_ID);
7274 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007275
7276 break;
7277
7278 default:
7279 IWL_ERROR("%s Should not be called in %d mode\n",
7280 __FUNCTION__, priv->iw_mode);
7281 break;
7282 }
7283
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007284 iwl4965_sequence_reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007285
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007286#ifdef CONFIG_IWL4965_SENSITIVITY
Zhu Yib481de92007-09-25 17:54:57 -07007287 /* Enable Rx differential gain and sensitivity calibrations */
7288 iwl4965_chain_noise_reset(priv);
7289 priv->start_calib = 1;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007290#endif /* CONFIG_IWL4965_SENSITIVITY */
Zhu Yib481de92007-09-25 17:54:57 -07007291
7292 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
7293 priv->assoc_station_added = 1;
7294
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007295#ifdef CONFIG_IWL4965_QOS
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007296 iwl4965_activate_qos(priv, 0);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007297#endif /* CONFIG_IWL4965_QOS */
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08007298 /* we have just associated, don't start scan too early */
7299 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Zhu Yib481de92007-09-25 17:54:57 -07007300 mutex_unlock(&priv->mutex);
7301}
7302
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007303static void iwl4965_bg_abort_scan(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07007304{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007305 struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, abort_scan);
Zhu Yib481de92007-09-25 17:54:57 -07007306
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007307 if (!iwl4965_is_ready(priv))
Zhu Yib481de92007-09-25 17:54:57 -07007308 return;
7309
7310 mutex_lock(&priv->mutex);
7311
7312 set_bit(STATUS_SCAN_ABORTING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007313 iwl4965_send_scan_abort(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007314
7315 mutex_unlock(&priv->mutex);
7316}
7317
Zhu Yi76bb77e2007-11-22 10:53:22 +08007318static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
7319
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007320static void iwl4965_bg_scan_completed(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07007321{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007322 struct iwl4965_priv *priv =
7323 container_of(work, struct iwl4965_priv, scan_completed);
Zhu Yib481de92007-09-25 17:54:57 -07007324
7325 IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n");
7326
7327 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7328 return;
7329
Zhu Yia0646472007-12-20 14:10:01 +08007330 if (test_bit(STATUS_CONF_PENDING, &priv->status))
7331 iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw));
Zhu Yi76bb77e2007-11-22 10:53:22 +08007332
Zhu Yib481de92007-09-25 17:54:57 -07007333 ieee80211_scan_completed(priv->hw);
7334
7335 /* Since setting the TXPOWER may have been deferred while
7336 * performing the scan, fire one off */
7337 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007338 iwl4965_hw_reg_send_txpower(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007339 mutex_unlock(&priv->mutex);
7340}
7341
7342/*****************************************************************************
7343 *
7344 * mac80211 entry point functions
7345 *
7346 *****************************************************************************/
7347
Zhu Yi5a669262008-01-14 17:46:18 -08007348#define UCODE_READY_TIMEOUT (2 * HZ)
7349
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007350static int iwl4965_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07007351{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007352 struct iwl4965_priv *priv = hw->priv;
Zhu Yi5a669262008-01-14 17:46:18 -08007353 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07007354
7355 IWL_DEBUG_MAC80211("enter\n");
7356
Zhu Yi5a669262008-01-14 17:46:18 -08007357 if (pci_enable_device(priv->pci_dev)) {
7358 IWL_ERROR("Fail to pci_enable_device\n");
7359 return -ENODEV;
7360 }
7361 pci_restore_state(priv->pci_dev);
7362 pci_enable_msi(priv->pci_dev);
7363
7364 ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED,
7365 DRV_NAME, priv);
7366 if (ret) {
7367 IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq);
7368 goto out_disable_msi;
7369 }
7370
Zhu Yib481de92007-09-25 17:54:57 -07007371 /* we should be verifying the device is ready to be opened */
7372 mutex_lock(&priv->mutex);
7373
Zhu Yi5a669262008-01-14 17:46:18 -08007374 memset(&priv->staging_rxon, 0, sizeof(struct iwl4965_rxon_cmd));
7375 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
7376 * ucode filename and max sizes are card-specific. */
7377
7378 if (!priv->ucode_code.len) {
7379 ret = iwl4965_read_ucode(priv);
7380 if (ret) {
7381 IWL_ERROR("Could not read microcode: %d\n", ret);
7382 mutex_unlock(&priv->mutex);
7383 goto out_release_irq;
7384 }
7385 }
7386
Zhu Yie655b9f2008-01-24 02:19:38 -08007387 ret = __iwl4965_up(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08007388
Zhu Yib481de92007-09-25 17:54:57 -07007389 mutex_unlock(&priv->mutex);
Zhu Yi5a669262008-01-14 17:46:18 -08007390
Zhu Yie655b9f2008-01-24 02:19:38 -08007391 if (ret)
7392 goto out_release_irq;
7393
7394 IWL_DEBUG_INFO("Start UP work done.\n");
7395
7396 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
7397 return 0;
7398
Zhu Yi5a669262008-01-14 17:46:18 -08007399 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
7400 * mac80211 will not be run successfully. */
7401 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
7402 test_bit(STATUS_READY, &priv->status),
7403 UCODE_READY_TIMEOUT);
7404 if (!ret) {
7405 if (!test_bit(STATUS_READY, &priv->status)) {
7406 IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n",
7407 jiffies_to_msecs(UCODE_READY_TIMEOUT));
7408 ret = -ETIMEDOUT;
7409 goto out_release_irq;
7410 }
7411 }
7412
Zhu Yie655b9f2008-01-24 02:19:38 -08007413 priv->is_open = 1;
Zhu Yib481de92007-09-25 17:54:57 -07007414 IWL_DEBUG_MAC80211("leave\n");
7415 return 0;
Zhu Yi5a669262008-01-14 17:46:18 -08007416
7417out_release_irq:
7418 free_irq(priv->pci_dev->irq, priv);
7419out_disable_msi:
7420 pci_disable_msi(priv->pci_dev);
Zhu Yie655b9f2008-01-24 02:19:38 -08007421 pci_disable_device(priv->pci_dev);
7422 priv->is_open = 0;
7423 IWL_DEBUG_MAC80211("leave - failed\n");
Zhu Yi5a669262008-01-14 17:46:18 -08007424 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07007425}
7426
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007427static void iwl4965_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07007428{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007429 struct iwl4965_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07007430
7431 IWL_DEBUG_MAC80211("enter\n");
Mohamed Abbas948c1712007-10-25 17:15:45 +08007432
Zhu Yie655b9f2008-01-24 02:19:38 -08007433 if (!priv->is_open) {
7434 IWL_DEBUG_MAC80211("leave - skip\n");
7435 return;
7436 }
7437
Zhu Yib481de92007-09-25 17:54:57 -07007438 priv->is_open = 0;
Zhu Yi5a669262008-01-14 17:46:18 -08007439
7440 if (iwl4965_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08007441 /* stop mac, cancel any scan request and clear
7442 * RXON_FILTER_ASSOC_MSK BIT
7443 */
Zhu Yi5a669262008-01-14 17:46:18 -08007444 mutex_lock(&priv->mutex);
7445 iwl4965_scan_cancel_timeout(priv, 100);
7446 cancel_delayed_work(&priv->post_associate);
Mohamed Abbasfde35712007-11-29 11:10:15 +08007447 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08007448 }
7449
Zhu Yi5a669262008-01-14 17:46:18 -08007450 iwl4965_down(priv);
7451
7452 flush_workqueue(priv->workqueue);
7453 free_irq(priv->pci_dev->irq, priv);
7454 pci_disable_msi(priv->pci_dev);
7455 pci_save_state(priv->pci_dev);
7456 pci_disable_device(priv->pci_dev);
Mohamed Abbas948c1712007-10-25 17:15:45 +08007457
Zhu Yib481de92007-09-25 17:54:57 -07007458 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07007459}
7460
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007461static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
Zhu Yib481de92007-09-25 17:54:57 -07007462 struct ieee80211_tx_control *ctl)
7463{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007464 struct iwl4965_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07007465
7466 IWL_DEBUG_MAC80211("enter\n");
7467
7468 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
7469 IWL_DEBUG_MAC80211("leave - monitor\n");
7470 return -1;
7471 }
7472
7473 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
7474 ctl->tx_rate);
7475
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007476 if (iwl4965_tx_skb(priv, skb, ctl))
Zhu Yib481de92007-09-25 17:54:57 -07007477 dev_kfree_skb_any(skb);
7478
7479 IWL_DEBUG_MAC80211("leave\n");
7480 return 0;
7481}
7482
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007483static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07007484 struct ieee80211_if_init_conf *conf)
7485{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007486 struct iwl4965_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07007487 unsigned long flags;
Joe Perches0795af52007-10-03 17:59:30 -07007488 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07007489
Johannes Berg32bfd352007-12-19 01:31:26 +01007490 IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07007491
Johannes Berg32bfd352007-12-19 01:31:26 +01007492 if (priv->vif) {
7493 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
Reinette Chatre75849d22008-01-23 10:15:17 -08007494 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07007495 }
7496
7497 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01007498 priv->vif = conf->vif;
Zhu Yib481de92007-09-25 17:54:57 -07007499
7500 spin_unlock_irqrestore(&priv->lock, flags);
7501
7502 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02007503
7504 if (conf->mac_addr) {
7505 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr));
7506 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
7507 }
Zhu Yib481de92007-09-25 17:54:57 -07007508
Zhu Yi5a669262008-01-14 17:46:18 -08007509 if (iwl4965_is_ready(priv))
7510 iwl4965_set_mode(priv, conf->type);
7511
Zhu Yib481de92007-09-25 17:54:57 -07007512 mutex_unlock(&priv->mutex);
7513
Zhu Yi5a669262008-01-14 17:46:18 -08007514 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07007515 return 0;
7516}
7517
7518/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007519 * iwl4965_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07007520 *
7521 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
7522 * be set inappropriately and the driver currently sets the hardware up to
7523 * use it whenever needed.
7524 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007525static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07007526{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007527 struct iwl4965_priv *priv = hw->priv;
7528 const struct iwl4965_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07007529 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08007530 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07007531
7532 mutex_lock(&priv->mutex);
7533 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel);
7534
Zhu Yi12342c42007-12-20 11:27:32 +08007535 priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
7536
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007537 if (!iwl4965_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07007538 IWL_DEBUG_MAC80211("leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08007539 ret = -EIO;
7540 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07007541 }
7542
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007543 if (unlikely(!iwl4965_param_disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07007544 test_bit(STATUS_SCANNING, &priv->status))) {
Zhu Yia0646472007-12-20 14:10:01 +08007545 IWL_DEBUG_MAC80211("leave - scanning\n");
7546 set_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07007547 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08007548 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07007549 }
7550
7551 spin_lock_irqsave(&priv->lock, flags);
7552
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007553 ch_info = iwl4965_get_channel_info(priv, conf->phymode, conf->channel);
Zhu Yib481de92007-09-25 17:54:57 -07007554 if (!is_channel_valid(ch_info)) {
7555 IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n",
7556 conf->channel, conf->phymode);
7557 IWL_DEBUG_MAC80211("leave - invalid channel\n");
7558 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yi76bb77e2007-11-22 10:53:22 +08007559 ret = -EINVAL;
7560 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07007561 }
7562
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007563#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -07007564 /* if we are switching fron ht to 2.4 clear flags
7565 * from any ht related info since 2.4 does not
7566 * support ht */
7567 if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel)
7568#ifdef IEEE80211_CONF_CHANNEL_SWITCH
7569 && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
7570#endif
7571 )
7572 priv->staging_rxon.flags = 0;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007573#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07007574
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007575 iwl4965_set_rxon_channel(priv, conf->phymode, conf->channel);
Zhu Yib481de92007-09-25 17:54:57 -07007576
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007577 iwl4965_set_flags_for_phymode(priv, conf->phymode);
Zhu Yib481de92007-09-25 17:54:57 -07007578
7579 /* The list of supported rates and rate mask can be different
7580 * for each phymode; since the phymode may have changed, reset
7581 * the rate mask to what mac80211 lists */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007582 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007583
7584 spin_unlock_irqrestore(&priv->lock, flags);
7585
7586#ifdef IEEE80211_CONF_CHANNEL_SWITCH
7587 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007588 iwl4965_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08007589 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07007590 }
7591#endif
7592
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007593 iwl4965_radio_kill_sw(priv, !conf->radio_enabled);
Zhu Yib481de92007-09-25 17:54:57 -07007594
7595 if (!conf->radio_enabled) {
7596 IWL_DEBUG_MAC80211("leave - radio disabled\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08007597 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07007598 }
7599
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007600 if (iwl4965_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07007601 IWL_DEBUG_MAC80211("leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08007602 ret = -EIO;
7603 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07007604 }
7605
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007606 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007607
7608 if (memcmp(&priv->active_rxon,
7609 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007610 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007611 else
7612 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
7613
7614 IWL_DEBUG_MAC80211("leave\n");
7615
Zhu Yia0646472007-12-20 14:10:01 +08007616out:
7617 clear_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yi5a669262008-01-14 17:46:18 -08007618 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08007619 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07007620}
7621
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007622static void iwl4965_config_ap(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07007623{
7624 int rc = 0;
7625
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08007626 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07007627 return;
7628
7629 /* The following should be done only at AP bring up */
7630 if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) {
7631
7632 /* RXON - unassoc (to set timing command) */
7633 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007634 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007635
7636 /* RXON Timing */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007637 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
7638 iwl4965_setup_rxon_timing(priv);
7639 rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07007640 sizeof(priv->rxon_timing), &priv->rxon_timing);
7641 if (rc)
7642 IWL_WARNING("REPLY_RXON_TIMING failed - "
7643 "Attempting to continue.\n");
7644
7645 iwl4965_set_rxon_chain(priv);
7646
7647 /* FIXME: what should be the assoc_id for AP? */
7648 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
7649 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7650 priv->staging_rxon.flags |=
7651 RXON_FLG_SHORT_PREAMBLE_MSK;
7652 else
7653 priv->staging_rxon.flags &=
7654 ~RXON_FLG_SHORT_PREAMBLE_MSK;
7655
7656 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
7657 if (priv->assoc_capability &
7658 WLAN_CAPABILITY_SHORT_SLOT_TIME)
7659 priv->staging_rxon.flags |=
7660 RXON_FLG_SHORT_SLOT_MSK;
7661 else
7662 priv->staging_rxon.flags &=
7663 ~RXON_FLG_SHORT_SLOT_MSK;
7664
7665 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
7666 priv->staging_rxon.flags &=
7667 ~RXON_FLG_SHORT_SLOT_MSK;
7668 }
7669 /* restore RXON assoc */
7670 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007671 iwl4965_commit_rxon(priv);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007672#ifdef CONFIG_IWL4965_QOS
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007673 iwl4965_activate_qos(priv, 1);
Zhu Yib481de92007-09-25 17:54:57 -07007674#endif
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007675 iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0);
Zhu Yie1493de2007-09-27 11:27:32 +08007676 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007677 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007678
7679 /* FIXME - we need to add code here to detect a totally new
7680 * configuration, reset the AP, unassoc, rxon timing, assoc,
7681 * clear sta table, add BCAST sta... */
7682}
7683
Johannes Berg32bfd352007-12-19 01:31:26 +01007684static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
7685 struct ieee80211_vif *vif,
Zhu Yib481de92007-09-25 17:54:57 -07007686 struct ieee80211_if_conf *conf)
7687{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007688 struct iwl4965_priv *priv = hw->priv;
Joe Perches0795af52007-10-03 17:59:30 -07007689 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07007690 unsigned long flags;
7691 int rc;
7692
7693 if (conf == NULL)
7694 return -EIO;
7695
7696 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
7697 (!conf->beacon || !conf->ssid_len)) {
7698 IWL_DEBUG_MAC80211
7699 ("Leaving in AP mode because HostAPD is not ready.\n");
7700 return 0;
7701 }
7702
Zhu Yi5a669262008-01-14 17:46:18 -08007703 if (!iwl4965_is_alive(priv))
7704 return -EAGAIN;
7705
Zhu Yib481de92007-09-25 17:54:57 -07007706 mutex_lock(&priv->mutex);
7707
Zhu Yib481de92007-09-25 17:54:57 -07007708 if (conf->bssid)
Joe Perches0795af52007-10-03 17:59:30 -07007709 IWL_DEBUG_MAC80211("bssid: %s\n",
7710 print_mac(mac, conf->bssid));
Zhu Yib481de92007-09-25 17:54:57 -07007711
Johannes Berg4150c572007-09-17 01:29:23 -04007712/*
7713 * very dubious code was here; the probe filtering flag is never set:
7714 *
Zhu Yib481de92007-09-25 17:54:57 -07007715 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
7716 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04007717 */
7718 if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
Zhu Yib481de92007-09-25 17:54:57 -07007719 IWL_DEBUG_MAC80211("leave - scanning\n");
7720 mutex_unlock(&priv->mutex);
7721 return 0;
7722 }
7723
Johannes Berg32bfd352007-12-19 01:31:26 +01007724 if (priv->vif != vif) {
7725 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
Zhu Yib481de92007-09-25 17:54:57 -07007726 mutex_unlock(&priv->mutex);
7727 return 0;
7728 }
7729
7730 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
7731 if (!conf->bssid) {
7732 conf->bssid = priv->mac_addr;
7733 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Joe Perches0795af52007-10-03 17:59:30 -07007734 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
7735 print_mac(mac, conf->bssid));
Zhu Yib481de92007-09-25 17:54:57 -07007736 }
7737 if (priv->ibss_beacon)
7738 dev_kfree_skb(priv->ibss_beacon);
7739
7740 priv->ibss_beacon = conf->beacon;
7741 }
7742
Mohamed Abbasfde35712007-11-29 11:10:15 +08007743 if (iwl4965_is_rfkill(priv))
7744 goto done;
7745
Zhu Yib481de92007-09-25 17:54:57 -07007746 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
7747 !is_multicast_ether_addr(conf->bssid)) {
7748 /* If there is currently a HW scan going on in the background
7749 * then we need to cancel it else the RXON below will fail. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007750 if (iwl4965_scan_cancel_timeout(priv, 100)) {
Zhu Yib481de92007-09-25 17:54:57 -07007751 IWL_WARNING("Aborted scan still in progress "
7752 "after 100ms\n");
7753 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
7754 mutex_unlock(&priv->mutex);
7755 return -EAGAIN;
7756 }
7757 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
7758
7759 /* TODO: Audit driver for usage of these members and see
7760 * if mac80211 deprecates them (priv->bssid looks like it
7761 * shouldn't be there, but I haven't scanned the IBSS code
7762 * to verify) - jpk */
7763 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
7764
7765 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007766 iwl4965_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007767 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007768 rc = iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007769 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007770 iwl4965_rxon_add_station(
Zhu Yib481de92007-09-25 17:54:57 -07007771 priv, priv->active_rxon.bssid_addr, 1);
7772 }
7773
7774 } else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007775 iwl4965_scan_cancel_timeout(priv, 100);
Zhu Yib481de92007-09-25 17:54:57 -07007776 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007777 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007778 }
7779
Mohamed Abbasfde35712007-11-29 11:10:15 +08007780 done:
Zhu Yib481de92007-09-25 17:54:57 -07007781 spin_lock_irqsave(&priv->lock, flags);
7782 if (!conf->ssid_len)
7783 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
7784 else
7785 memcpy(priv->essid, conf->ssid, conf->ssid_len);
7786
7787 priv->essid_len = conf->ssid_len;
7788 spin_unlock_irqrestore(&priv->lock, flags);
7789
7790 IWL_DEBUG_MAC80211("leave\n");
7791 mutex_unlock(&priv->mutex);
7792
7793 return 0;
7794}
7795
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007796static void iwl4965_configure_filter(struct ieee80211_hw *hw,
Johannes Berg4150c572007-09-17 01:29:23 -04007797 unsigned int changed_flags,
7798 unsigned int *total_flags,
7799 int mc_count, struct dev_addr_list *mc_list)
7800{
7801 /*
7802 * XXX: dummy
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007803 * see also iwl4965_connection_init_rx_config
Johannes Berg4150c572007-09-17 01:29:23 -04007804 */
7805 *total_flags = 0;
7806}
7807
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007808static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07007809 struct ieee80211_if_init_conf *conf)
7810{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007811 struct iwl4965_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07007812
7813 IWL_DEBUG_MAC80211("enter\n");
7814
7815 mutex_lock(&priv->mutex);
Mohamed Abbas948c1712007-10-25 17:15:45 +08007816
Mohamed Abbasfde35712007-11-29 11:10:15 +08007817 if (iwl4965_is_ready_rf(priv)) {
7818 iwl4965_scan_cancel_timeout(priv, 100);
7819 cancel_delayed_work(&priv->post_associate);
7820 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7821 iwl4965_commit_rxon(priv);
7822 }
Johannes Berg32bfd352007-12-19 01:31:26 +01007823 if (priv->vif == conf->vif) {
7824 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07007825 memset(priv->bssid, 0, ETH_ALEN);
7826 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
7827 priv->essid_len = 0;
7828 }
7829 mutex_unlock(&priv->mutex);
7830
7831 IWL_DEBUG_MAC80211("leave\n");
7832
7833}
Johannes Berg471b3ef2007-12-28 14:32:58 +01007834
7835static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
7836 struct ieee80211_vif *vif,
7837 struct ieee80211_bss_conf *bss_conf,
7838 u32 changes)
Tomas Winkler220173b2007-10-16 00:50:25 +02007839{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007840 struct iwl4965_priv *priv = hw->priv;
Tomas Winkler220173b2007-10-16 00:50:25 +02007841
Johannes Berg471b3ef2007-12-28 14:32:58 +01007842 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
7843 if (bss_conf->use_short_preamble)
Tomas Winkler220173b2007-10-16 00:50:25 +02007844 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
7845 else
7846 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
7847 }
7848
Johannes Berg471b3ef2007-12-28 14:32:58 +01007849 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
7850 if (bss_conf->use_cts_prot && (priv->phymode != MODE_IEEE80211A))
Tomas Winkler220173b2007-10-16 00:50:25 +02007851 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
7852 else
7853 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
7854 }
7855
Johannes Berg471b3ef2007-12-28 14:32:58 +01007856 if (changes & BSS_CHANGED_ASSOC) {
7857 /*
7858 * TODO:
7859 * do stuff instead of sniffing assoc resp
7860 */
7861 }
7862
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007863 if (iwl4965_is_associated(priv))
7864 iwl4965_send_rxon_assoc(priv);
Tomas Winkler220173b2007-10-16 00:50:25 +02007865}
Zhu Yib481de92007-09-25 17:54:57 -07007866
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007867static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
Zhu Yib481de92007-09-25 17:54:57 -07007868{
7869 int rc = 0;
7870 unsigned long flags;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007871 struct iwl4965_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07007872
7873 IWL_DEBUG_MAC80211("enter\n");
7874
mabbas052c4b92007-10-25 17:15:43 +08007875 mutex_lock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07007876 spin_lock_irqsave(&priv->lock, flags);
7877
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007878 if (!iwl4965_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07007879 rc = -EIO;
7880 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
7881 goto out_unlock;
7882 }
7883
7884 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */
7885 rc = -EIO;
7886 IWL_ERROR("ERROR: APs don't scan\n");
7887 goto out_unlock;
7888 }
7889
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08007890 /* we don't schedule scan within next_scan_jiffies period */
7891 if (priv->next_scan_jiffies &&
7892 time_after(priv->next_scan_jiffies, jiffies)) {
7893 rc = -EAGAIN;
7894 goto out_unlock;
7895 }
Zhu Yib481de92007-09-25 17:54:57 -07007896 /* if we just finished scan ask for delay */
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08007897 if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies +
7898 IWL_DELAY_NEXT_SCAN, jiffies)) {
Zhu Yib481de92007-09-25 17:54:57 -07007899 rc = -EAGAIN;
7900 goto out_unlock;
7901 }
7902 if (len) {
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08007903 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007904 iwl4965_escape_essid(ssid, len), (int)len);
Zhu Yib481de92007-09-25 17:54:57 -07007905
7906 priv->one_direct_scan = 1;
7907 priv->direct_ssid_len = (u8)
7908 min((u8) len, (u8) IW_ESSID_MAX_SIZE);
7909 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
Mohamed Abbas948c1712007-10-25 17:15:45 +08007910 } else
7911 priv->one_direct_scan = 0;
Zhu Yib481de92007-09-25 17:54:57 -07007912
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007913 rc = iwl4965_scan_initiate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007914
7915 IWL_DEBUG_MAC80211("leave\n");
7916
7917out_unlock:
7918 spin_unlock_irqrestore(&priv->lock, flags);
mabbas052c4b92007-10-25 17:15:43 +08007919 mutex_unlock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07007920
7921 return rc;
7922}
7923
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007924static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Zhu Yib481de92007-09-25 17:54:57 -07007925 const u8 *local_addr, const u8 *addr,
7926 struct ieee80211_key_conf *key)
7927{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007928 struct iwl4965_priv *priv = hw->priv;
Joe Perches0795af52007-10-03 17:59:30 -07007929 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07007930 int rc = 0;
7931 u8 sta_id;
7932
7933 IWL_DEBUG_MAC80211("enter\n");
7934
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007935 if (!iwl4965_param_hwcrypto) {
Zhu Yib481de92007-09-25 17:54:57 -07007936 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
7937 return -EOPNOTSUPP;
7938 }
7939
7940 if (is_zero_ether_addr(addr))
7941 /* only support pairwise keys */
7942 return -EOPNOTSUPP;
7943
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007944 sta_id = iwl4965_hw_find_station(priv, addr);
Zhu Yib481de92007-09-25 17:54:57 -07007945 if (sta_id == IWL_INVALID_STATION) {
Joe Perches0795af52007-10-03 17:59:30 -07007946 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
7947 print_mac(mac, addr));
Zhu Yib481de92007-09-25 17:54:57 -07007948 return -EINVAL;
7949 }
7950
7951 mutex_lock(&priv->mutex);
7952
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007953 iwl4965_scan_cancel_timeout(priv, 100);
mabbas052c4b92007-10-25 17:15:43 +08007954
Zhu Yib481de92007-09-25 17:54:57 -07007955 switch (cmd) {
7956 case SET_KEY:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007957 rc = iwl4965_update_sta_key_info(priv, key, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07007958 if (!rc) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007959 iwl4965_set_rxon_hwcrypto(priv, 1);
7960 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007961 key->hw_key_idx = sta_id;
7962 IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n");
7963 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
7964 }
7965 break;
7966 case DISABLE_KEY:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007967 rc = iwl4965_clear_sta_key_info(priv, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07007968 if (!rc) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007969 iwl4965_set_rxon_hwcrypto(priv, 0);
7970 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07007971 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
7972 }
7973 break;
7974 default:
7975 rc = -EINVAL;
7976 }
7977
7978 IWL_DEBUG_MAC80211("leave\n");
7979 mutex_unlock(&priv->mutex);
7980
7981 return rc;
7982}
7983
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007984static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, int queue,
Zhu Yib481de92007-09-25 17:54:57 -07007985 const struct ieee80211_tx_queue_params *params)
7986{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007987 struct iwl4965_priv *priv = hw->priv;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08007988#ifdef CONFIG_IWL4965_QOS
Zhu Yib481de92007-09-25 17:54:57 -07007989 unsigned long flags;
7990 int q;
Reinette Chatre0054b342007-11-29 11:09:42 +08007991#endif /* CONFIG_IWL4965_QOS */
Zhu Yib481de92007-09-25 17:54:57 -07007992
7993 IWL_DEBUG_MAC80211("enter\n");
7994
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08007995 if (!iwl4965_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07007996 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7997 return -EIO;
7998 }
7999
8000 if (queue >= AC_NUM) {
8001 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
8002 return 0;
8003 }
8004
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008005#ifdef CONFIG_IWL4965_QOS
Zhu Yib481de92007-09-25 17:54:57 -07008006 if (!priv->qos_data.qos_enable) {
8007 priv->qos_data.qos_active = 0;
8008 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
8009 return 0;
8010 }
8011 q = AC_NUM - 1 - queue;
8012
8013 spin_lock_irqsave(&priv->lock, flags);
8014
8015 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
8016 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
8017 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
8018 priv->qos_data.def_qos_parm.ac[q].edca_txop =
8019 cpu_to_le16((params->burst_time * 100));
8020
8021 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
8022 priv->qos_data.qos_active = 1;
8023
8024 spin_unlock_irqrestore(&priv->lock, flags);
8025
8026 mutex_lock(&priv->mutex);
8027 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008028 iwl4965_activate_qos(priv, 1);
8029 else if (priv->assoc_id && iwl4965_is_associated(priv))
8030 iwl4965_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07008031
8032 mutex_unlock(&priv->mutex);
8033
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008034#endif /*CONFIG_IWL4965_QOS */
Zhu Yib481de92007-09-25 17:54:57 -07008035
8036 IWL_DEBUG_MAC80211("leave\n");
8037 return 0;
8038}
8039
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008040static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07008041 struct ieee80211_tx_queue_stats *stats)
8042{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008043 struct iwl4965_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07008044 int i, avail;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008045 struct iwl4965_tx_queue *txq;
8046 struct iwl4965_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07008047 unsigned long flags;
8048
8049 IWL_DEBUG_MAC80211("enter\n");
8050
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008051 if (!iwl4965_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07008052 IWL_DEBUG_MAC80211("leave - RF not ready\n");
8053 return -EIO;
8054 }
8055
8056 spin_lock_irqsave(&priv->lock, flags);
8057
8058 for (i = 0; i < AC_NUM; i++) {
8059 txq = &priv->txq[i];
8060 q = &txq->q;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008061 avail = iwl4965_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07008062
8063 stats->data[i].len = q->n_window - avail;
8064 stats->data[i].limit = q->n_window - q->high_mark;
8065 stats->data[i].count = q->n_window;
8066
8067 }
8068 spin_unlock_irqrestore(&priv->lock, flags);
8069
8070 IWL_DEBUG_MAC80211("leave\n");
8071
8072 return 0;
8073}
8074
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008075static int iwl4965_mac_get_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07008076 struct ieee80211_low_level_stats *stats)
8077{
8078 IWL_DEBUG_MAC80211("enter\n");
8079 IWL_DEBUG_MAC80211("leave\n");
8080
8081 return 0;
8082}
8083
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008084static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07008085{
8086 IWL_DEBUG_MAC80211("enter\n");
8087 IWL_DEBUG_MAC80211("leave\n");
8088
8089 return 0;
8090}
8091
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008092static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07008093{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008094 struct iwl4965_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07008095 unsigned long flags;
8096
8097 mutex_lock(&priv->mutex);
8098 IWL_DEBUG_MAC80211("enter\n");
8099
8100 priv->lq_mngr.lq_ready = 0;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008101#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -07008102 spin_lock_irqsave(&priv->lock, flags);
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02008103 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
Zhu Yib481de92007-09-25 17:54:57 -07008104 spin_unlock_irqrestore(&priv->lock, flags);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008105#ifdef CONFIG_IWL4965_HT_AGG
Zhu Yib481de92007-09-25 17:54:57 -07008106/* if (priv->lq_mngr.agg_ctrl.granted_ba)
8107 iwl4965_turn_off_agg(priv, TID_ALL_SPECIFIED);*/
8108
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008109 memset(&(priv->lq_mngr.agg_ctrl), 0, sizeof(struct iwl4965_agg_control));
Zhu Yib481de92007-09-25 17:54:57 -07008110 priv->lq_mngr.agg_ctrl.tid_traffic_load_threshold = 10;
8111 priv->lq_mngr.agg_ctrl.ba_timeout = 5000;
8112 priv->lq_mngr.agg_ctrl.auto_agg = 1;
8113
8114 if (priv->lq_mngr.agg_ctrl.auto_agg)
8115 priv->lq_mngr.agg_ctrl.requested_ba = TID_ALL_ENABLED;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008116#endif /*CONFIG_IWL4965_HT_AGG */
8117#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07008118
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008119#ifdef CONFIG_IWL4965_QOS
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008120 iwl4965_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008121#endif
8122
8123 cancel_delayed_work(&priv->post_associate);
8124
8125 spin_lock_irqsave(&priv->lock, flags);
8126 priv->assoc_id = 0;
8127 priv->assoc_capability = 0;
8128 priv->call_post_assoc_from_beacon = 0;
8129 priv->assoc_station_added = 0;
8130
8131 /* new association get rid of ibss beacon skb */
8132 if (priv->ibss_beacon)
8133 dev_kfree_skb(priv->ibss_beacon);
8134
8135 priv->ibss_beacon = NULL;
8136
8137 priv->beacon_int = priv->hw->conf.beacon_int;
8138 priv->timestamp1 = 0;
8139 priv->timestamp0 = 0;
8140 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
8141 priv->beacon_int = 0;
8142
8143 spin_unlock_irqrestore(&priv->lock, flags);
8144
Mohamed Abbasfde35712007-11-29 11:10:15 +08008145 if (!iwl4965_is_ready_rf(priv)) {
8146 IWL_DEBUG_MAC80211("leave - not ready\n");
8147 mutex_unlock(&priv->mutex);
8148 return;
8149 }
8150
mabbas052c4b92007-10-25 17:15:43 +08008151 /* we are restarting association process
8152 * clear RXON_FILTER_ASSOC_MSK bit
8153 */
8154 if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008155 iwl4965_scan_cancel_timeout(priv, 100);
mabbas052c4b92007-10-25 17:15:43 +08008156 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008157 iwl4965_commit_rxon(priv);
mabbas052c4b92007-10-25 17:15:43 +08008158 }
8159
Zhu Yib481de92007-09-25 17:54:57 -07008160 /* Per mac80211.h: This is only used in IBSS mode... */
8161 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
mabbas052c4b92007-10-25 17:15:43 +08008162
Zhu Yib481de92007-09-25 17:54:57 -07008163 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
8164 mutex_unlock(&priv->mutex);
8165 return;
8166 }
8167
Zhu Yib481de92007-09-25 17:54:57 -07008168 priv->only_active_channel = 0;
8169
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008170 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008171
8172 mutex_unlock(&priv->mutex);
8173
8174 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07008175}
8176
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008177static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb,
Zhu Yib481de92007-09-25 17:54:57 -07008178 struct ieee80211_tx_control *control)
8179{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008180 struct iwl4965_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07008181 unsigned long flags;
8182
8183 mutex_lock(&priv->mutex);
8184 IWL_DEBUG_MAC80211("enter\n");
8185
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008186 if (!iwl4965_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07008187 IWL_DEBUG_MAC80211("leave - RF not ready\n");
8188 mutex_unlock(&priv->mutex);
8189 return -EIO;
8190 }
8191
8192 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
8193 IWL_DEBUG_MAC80211("leave - not IBSS\n");
8194 mutex_unlock(&priv->mutex);
8195 return -EIO;
8196 }
8197
8198 spin_lock_irqsave(&priv->lock, flags);
8199
8200 if (priv->ibss_beacon)
8201 dev_kfree_skb(priv->ibss_beacon);
8202
8203 priv->ibss_beacon = skb;
8204
8205 priv->assoc_id = 0;
8206
8207 IWL_DEBUG_MAC80211("leave\n");
8208 spin_unlock_irqrestore(&priv->lock, flags);
8209
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008210#ifdef CONFIG_IWL4965_QOS
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008211 iwl4965_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008212#endif
8213
8214 queue_work(priv->workqueue, &priv->post_associate.work);
8215
8216 mutex_unlock(&priv->mutex);
8217
8218 return 0;
8219}
8220
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008221#ifdef CONFIG_IWL4965_HT
Zhu Yib481de92007-09-25 17:54:57 -07008222
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02008223static void iwl4965_ht_info_fill(struct ieee80211_conf *conf,
8224 struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07008225{
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02008226 struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
8227 struct ieee80211_ht_info *ht_conf = &conf->ht_conf;
8228 struct ieee80211_ht_bss_info *ht_bss_conf = &conf->ht_bss_conf;
Zhu Yib481de92007-09-25 17:54:57 -07008229
8230 IWL_DEBUG_MAC80211("enter: \n");
8231
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02008232 if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)) {
8233 iwl_conf->is_ht = 0;
8234 return;
Zhu Yib481de92007-09-25 17:54:57 -07008235 }
8236
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02008237 iwl_conf->is_ht = 1;
8238 priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
Zhu Yib481de92007-09-25 17:54:57 -07008239
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02008240 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
8241 iwl_conf->sgf |= 0x1;
8242 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
8243 iwl_conf->sgf |= 0x2;
Zhu Yib481de92007-09-25 17:54:57 -07008244
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02008245 iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
8246 iwl_conf->max_amsdu_size =
8247 !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
8248 iwl_conf->supported_chan_width =
8249 !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH);
8250 iwl_conf->tx_mimo_ps_mode =
8251 (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
8252 memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16);
Zhu Yib481de92007-09-25 17:54:57 -07008253
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02008254 iwl_conf->control_channel = ht_bss_conf->primary_channel;
8255 iwl_conf->extension_chan_offset =
8256 ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET;
8257 iwl_conf->tx_chan_width =
8258 !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH);
8259 iwl_conf->ht_protection =
8260 ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION;
8261 iwl_conf->non_GF_STA_present =
8262 !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT);
Zhu Yib481de92007-09-25 17:54:57 -07008263
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02008264 IWL_DEBUG_MAC80211("control channel %d\n",
8265 iwl_conf->control_channel);
Zhu Yib481de92007-09-25 17:54:57 -07008266 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07008267}
8268
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008269static int iwl4965_mac_conf_ht(struct ieee80211_hw *hw,
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02008270 struct ieee80211_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07008271{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008272 struct iwl4965_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07008273
8274 IWL_DEBUG_MAC80211("enter: \n");
8275
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02008276 iwl4965_ht_info_fill(conf, priv);
Zhu Yib481de92007-09-25 17:54:57 -07008277 iwl4965_set_rxon_chain(priv);
8278
8279 if (priv && priv->assoc_id &&
8280 (priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
8281 unsigned long flags;
8282
8283 spin_lock_irqsave(&priv->lock, flags);
8284 if (priv->beacon_int)
8285 queue_work(priv->workqueue, &priv->post_associate.work);
8286 else
8287 priv->call_post_assoc_from_beacon = 1;
8288 spin_unlock_irqrestore(&priv->lock, flags);
8289 }
8290
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02008291 IWL_DEBUG_MAC80211("leave:\n");
8292 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07008293}
8294
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008295static void iwl4965_set_ht_capab(struct ieee80211_hw *hw,
Ron Rindjunsky8fb88032007-11-26 16:14:38 +02008296 struct ieee80211_ht_cap *ht_cap,
8297 u8 use_current_config)
Zhu Yib481de92007-09-25 17:54:57 -07008298{
Ron Rindjunsky8fb88032007-11-26 16:14:38 +02008299 struct ieee80211_conf *conf = &hw->conf;
8300 struct ieee80211_hw_mode *mode = conf->mode;
Zhu Yib481de92007-09-25 17:54:57 -07008301
Ron Rindjunsky8fb88032007-11-26 16:14:38 +02008302 if (use_current_config) {
8303 ht_cap->cap_info = cpu_to_le16(conf->ht_conf.cap);
8304 memcpy(ht_cap->supp_mcs_set,
8305 conf->ht_conf.supp_mcs_set, 16);
8306 } else {
8307 ht_cap->cap_info = cpu_to_le16(mode->ht_info.cap);
8308 memcpy(ht_cap->supp_mcs_set,
8309 mode->ht_info.supp_mcs_set, 16);
8310 }
8311 ht_cap->ampdu_params_info =
8312 (mode->ht_info.ampdu_factor & IEEE80211_HT_CAP_AMPDU_FACTOR) |
8313 ((mode->ht_info.ampdu_density << 2) &
8314 IEEE80211_HT_CAP_AMPDU_DENSITY);
Zhu Yib481de92007-09-25 17:54:57 -07008315}
8316
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008317#endif /*CONFIG_IWL4965_HT*/
Zhu Yib481de92007-09-25 17:54:57 -07008318
8319/*****************************************************************************
8320 *
8321 * sysfs attributes
8322 *
8323 *****************************************************************************/
8324
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008325#ifdef CONFIG_IWL4965_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07008326
8327/*
8328 * The following adds a new attribute to the sysfs representation
8329 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
8330 * used for controlling the debug level.
8331 *
8332 * See the level definitions in iwl for details.
8333 */
8334
8335static ssize_t show_debug_level(struct device_driver *d, char *buf)
8336{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008337 return sprintf(buf, "0x%08X\n", iwl4965_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07008338}
8339static ssize_t store_debug_level(struct device_driver *d,
8340 const char *buf, size_t count)
8341{
8342 char *p = (char *)buf;
8343 u32 val;
8344
8345 val = simple_strtoul(p, &p, 0);
8346 if (p == buf)
8347 printk(KERN_INFO DRV_NAME
8348 ": %s is not in hex or decimal form.\n", buf);
8349 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008350 iwl4965_debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07008351
8352 return strnlen(buf, count);
8353}
8354
8355static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
8356 show_debug_level, store_debug_level);
8357
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008358#endif /* CONFIG_IWL4965_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07008359
8360static ssize_t show_rf_kill(struct device *d,
8361 struct device_attribute *attr, char *buf)
8362{
8363 /*
8364 * 0 - RF kill not enabled
8365 * 1 - SW based RF kill active (sysfs)
8366 * 2 - HW based RF kill active
8367 * 3 - Both HW and SW based RF kill active
8368 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008369 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07008370 int val = (test_bit(STATUS_RF_KILL_SW, &priv->status) ? 0x1 : 0x0) |
8371 (test_bit(STATUS_RF_KILL_HW, &priv->status) ? 0x2 : 0x0);
8372
8373 return sprintf(buf, "%i\n", val);
8374}
8375
8376static ssize_t store_rf_kill(struct device *d,
8377 struct device_attribute *attr,
8378 const char *buf, size_t count)
8379{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008380 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07008381
8382 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008383 iwl4965_radio_kill_sw(priv, buf[0] == '1');
Zhu Yib481de92007-09-25 17:54:57 -07008384 mutex_unlock(&priv->mutex);
8385
8386 return count;
8387}
8388
8389static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
8390
8391static ssize_t show_temperature(struct device *d,
8392 struct device_attribute *attr, char *buf)
8393{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008394 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07008395
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008396 if (!iwl4965_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07008397 return -EAGAIN;
8398
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008399 return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07008400}
8401
8402static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
8403
8404static ssize_t show_rs_window(struct device *d,
8405 struct device_attribute *attr,
8406 char *buf)
8407{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008408 struct iwl4965_priv *priv = d->driver_data;
8409 return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07008410}
8411static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
8412
8413static ssize_t show_tx_power(struct device *d,
8414 struct device_attribute *attr, char *buf)
8415{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008416 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07008417 return sprintf(buf, "%d\n", priv->user_txpower_limit);
8418}
8419
8420static ssize_t store_tx_power(struct device *d,
8421 struct device_attribute *attr,
8422 const char *buf, size_t count)
8423{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008424 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07008425 char *p = (char *)buf;
8426 u32 val;
8427
8428 val = simple_strtoul(p, &p, 10);
8429 if (p == buf)
8430 printk(KERN_INFO DRV_NAME
8431 ": %s is not in decimal form.\n", buf);
8432 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008433 iwl4965_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07008434
8435 return count;
8436}
8437
8438static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
8439
8440static ssize_t show_flags(struct device *d,
8441 struct device_attribute *attr, char *buf)
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
8445 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
8446}
8447
8448static ssize_t store_flags(struct device *d,
8449 struct device_attribute *attr,
8450 const char *buf, size_t count)
8451{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008452 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07008453 u32 flags = simple_strtoul(buf, NULL, 0);
8454
8455 mutex_lock(&priv->mutex);
8456 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
8457 /* Cancel any currently running scans... */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008458 if (iwl4965_scan_cancel_timeout(priv, 100))
Zhu Yib481de92007-09-25 17:54:57 -07008459 IWL_WARNING("Could not cancel scan.\n");
8460 else {
8461 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
8462 flags);
8463 priv->staging_rxon.flags = cpu_to_le32(flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008464 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008465 }
8466 }
8467 mutex_unlock(&priv->mutex);
8468
8469 return count;
8470}
8471
8472static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
8473
8474static ssize_t show_filter_flags(struct device *d,
8475 struct device_attribute *attr, char *buf)
8476{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008477 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07008478
8479 return sprintf(buf, "0x%04X\n",
8480 le32_to_cpu(priv->active_rxon.filter_flags));
8481}
8482
8483static ssize_t store_filter_flags(struct device *d,
8484 struct device_attribute *attr,
8485 const char *buf, size_t count)
8486{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008487 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07008488 u32 filter_flags = simple_strtoul(buf, NULL, 0);
8489
8490 mutex_lock(&priv->mutex);
8491 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
8492 /* Cancel any currently running scans... */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008493 if (iwl4965_scan_cancel_timeout(priv, 100))
Zhu Yib481de92007-09-25 17:54:57 -07008494 IWL_WARNING("Could not cancel scan.\n");
8495 else {
8496 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
8497 "0x%04X\n", filter_flags);
8498 priv->staging_rxon.filter_flags =
8499 cpu_to_le32(filter_flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008500 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008501 }
8502 }
8503 mutex_unlock(&priv->mutex);
8504
8505 return count;
8506}
8507
8508static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
8509 store_filter_flags);
8510
8511static ssize_t show_tune(struct device *d,
8512 struct device_attribute *attr, char *buf)
8513{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008514 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07008515
8516 return sprintf(buf, "0x%04X\n",
8517 (priv->phymode << 8) |
8518 le16_to_cpu(priv->active_rxon.channel));
8519}
8520
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008521static void iwl4965_set_flags_for_phymode(struct iwl4965_priv *priv, u8 phymode);
Zhu Yib481de92007-09-25 17:54:57 -07008522
8523static ssize_t store_tune(struct device *d,
8524 struct device_attribute *attr,
8525 const char *buf, size_t count)
8526{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008527 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07008528 char *p = (char *)buf;
8529 u16 tune = simple_strtoul(p, &p, 0);
8530 u8 phymode = (tune >> 8) & 0xff;
8531 u16 channel = tune & 0xff;
8532
8533 IWL_DEBUG_INFO("Tune request to:%d channel:%d\n", phymode, channel);
8534
8535 mutex_lock(&priv->mutex);
8536 if ((le16_to_cpu(priv->staging_rxon.channel) != channel) ||
8537 (priv->phymode != phymode)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008538 const struct iwl4965_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07008539
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008540 ch_info = iwl4965_get_channel_info(priv, phymode, channel);
Zhu Yib481de92007-09-25 17:54:57 -07008541 if (!ch_info) {
8542 IWL_WARNING("Requested invalid phymode/channel "
8543 "combination: %d %d\n", phymode, channel);
8544 mutex_unlock(&priv->mutex);
8545 return -EINVAL;
8546 }
8547
8548 /* Cancel any currently running scans... */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008549 if (iwl4965_scan_cancel_timeout(priv, 100))
Zhu Yib481de92007-09-25 17:54:57 -07008550 IWL_WARNING("Could not cancel scan.\n");
8551 else {
8552 IWL_DEBUG_INFO("Committing phymode and "
8553 "rxon.channel = %d %d\n",
8554 phymode, channel);
8555
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008556 iwl4965_set_rxon_channel(priv, phymode, channel);
8557 iwl4965_set_flags_for_phymode(priv, phymode);
Zhu Yib481de92007-09-25 17:54:57 -07008558
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008559 iwl4965_set_rate(priv);
8560 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008561 }
8562 }
8563 mutex_unlock(&priv->mutex);
8564
8565 return count;
8566}
8567
8568static DEVICE_ATTR(tune, S_IWUSR | S_IRUGO, show_tune, store_tune);
8569
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008570#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07008571
8572static ssize_t show_measurement(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);
8576 struct iwl4965_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07008577 u32 size = sizeof(measure_report), len = 0, ofs = 0;
8578 u8 *data = (u8 *) & measure_report;
8579 unsigned long flags;
8580
8581 spin_lock_irqsave(&priv->lock, flags);
8582 if (!(priv->measurement_status & MEASUREMENT_READY)) {
8583 spin_unlock_irqrestore(&priv->lock, flags);
8584 return 0;
8585 }
8586 memcpy(&measure_report, &priv->measure_report, size);
8587 priv->measurement_status = 0;
8588 spin_unlock_irqrestore(&priv->lock, flags);
8589
8590 while (size && (PAGE_SIZE - len)) {
8591 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
8592 PAGE_SIZE - len, 1);
8593 len = strlen(buf);
8594 if (PAGE_SIZE - len)
8595 buf[len++] = '\n';
8596
8597 ofs += 16;
8598 size -= min(size, 16U);
8599 }
8600
8601 return len;
8602}
8603
8604static ssize_t store_measurement(struct device *d,
8605 struct device_attribute *attr,
8606 const char *buf, size_t count)
8607{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008608 struct iwl4965_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07008609 struct ieee80211_measurement_params params = {
8610 .channel = le16_to_cpu(priv->active_rxon.channel),
8611 .start_time = cpu_to_le64(priv->last_tsf),
8612 .duration = cpu_to_le16(1),
8613 };
8614 u8 type = IWL_MEASURE_BASIC;
8615 u8 buffer[32];
8616 u8 channel;
8617
8618 if (count) {
8619 char *p = buffer;
8620 strncpy(buffer, buf, min(sizeof(buffer), count));
8621 channel = simple_strtoul(p, NULL, 0);
8622 if (channel)
8623 params.channel = channel;
8624
8625 p = buffer;
8626 while (*p && *p != ' ')
8627 p++;
8628 if (*p)
8629 type = simple_strtoul(p + 1, NULL, 0);
8630 }
8631
8632 IWL_DEBUG_INFO("Invoking measurement of type %d on "
8633 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008634 iwl4965_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07008635
8636 return count;
8637}
8638
8639static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
8640 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008641#endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07008642
8643static ssize_t store_retry_rate(struct device *d,
8644 struct device_attribute *attr,
8645 const char *buf, size_t count)
8646{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008647 struct iwl4965_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07008648
8649 priv->retry_rate = simple_strtoul(buf, NULL, 0);
8650 if (priv->retry_rate <= 0)
8651 priv->retry_rate = 1;
8652
8653 return count;
8654}
8655
8656static ssize_t show_retry_rate(struct device *d,
8657 struct device_attribute *attr, char *buf)
8658{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008659 struct iwl4965_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07008660 return sprintf(buf, "%d", priv->retry_rate);
8661}
8662
8663static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
8664 store_retry_rate);
8665
8666static ssize_t store_power_level(struct device *d,
8667 struct device_attribute *attr,
8668 const char *buf, size_t count)
8669{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008670 struct iwl4965_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07008671 int rc;
8672 int mode;
8673
8674 mode = simple_strtoul(buf, NULL, 0);
8675 mutex_lock(&priv->mutex);
8676
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008677 if (!iwl4965_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07008678 rc = -EAGAIN;
8679 goto out;
8680 }
8681
8682 if ((mode < 1) || (mode > IWL_POWER_LIMIT) || (mode == IWL_POWER_AC))
8683 mode = IWL_POWER_AC;
8684 else
8685 mode |= IWL_POWER_ENABLED;
8686
8687 if (mode != priv->power_mode) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008688 rc = iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(mode));
Zhu Yib481de92007-09-25 17:54:57 -07008689 if (rc) {
8690 IWL_DEBUG_MAC80211("failed setting power mode.\n");
8691 goto out;
8692 }
8693 priv->power_mode = mode;
8694 }
8695
8696 rc = count;
8697
8698 out:
8699 mutex_unlock(&priv->mutex);
8700 return rc;
8701}
8702
8703#define MAX_WX_STRING 80
8704
8705/* Values are in microsecond */
8706static const s32 timeout_duration[] = {
8707 350000,
8708 250000,
8709 75000,
8710 37000,
8711 25000,
8712};
8713static const s32 period_duration[] = {
8714 400000,
8715 700000,
8716 1000000,
8717 1000000,
8718 1000000
8719};
8720
8721static ssize_t show_power_level(struct device *d,
8722 struct device_attribute *attr, char *buf)
8723{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008724 struct iwl4965_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07008725 int level = IWL_POWER_LEVEL(priv->power_mode);
8726 char *p = buf;
8727
8728 p += sprintf(p, "%d ", level);
8729 switch (level) {
8730 case IWL_POWER_MODE_CAM:
8731 case IWL_POWER_AC:
8732 p += sprintf(p, "(AC)");
8733 break;
8734 case IWL_POWER_BATTERY:
8735 p += sprintf(p, "(BATTERY)");
8736 break;
8737 default:
8738 p += sprintf(p,
8739 "(Timeout %dms, Period %dms)",
8740 timeout_duration[level - 1] / 1000,
8741 period_duration[level - 1] / 1000);
8742 }
8743
8744 if (!(priv->power_mode & IWL_POWER_ENABLED))
8745 p += sprintf(p, " OFF\n");
8746 else
8747 p += sprintf(p, " \n");
8748
8749 return (p - buf + 1);
8750
8751}
8752
8753static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
8754 store_power_level);
8755
8756static ssize_t show_channels(struct device *d,
8757 struct device_attribute *attr, char *buf)
8758{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008759 struct iwl4965_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07008760 int len = 0, i;
8761 struct ieee80211_channel *channels = NULL;
8762 const struct ieee80211_hw_mode *hw_mode = NULL;
8763 int count = 0;
8764
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008765 if (!iwl4965_is_ready(priv))
Zhu Yib481de92007-09-25 17:54:57 -07008766 return -EAGAIN;
8767
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008768 hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211G);
Zhu Yib481de92007-09-25 17:54:57 -07008769 if (!hw_mode)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008770 hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211B);
Zhu Yib481de92007-09-25 17:54:57 -07008771 if (hw_mode) {
8772 channels = hw_mode->channels;
8773 count = hw_mode->num_channels;
8774 }
8775
8776 len +=
8777 sprintf(&buf[len],
8778 "Displaying %d channels in 2.4GHz band "
8779 "(802.11bg):\n", count);
8780
8781 for (i = 0; i < count; i++)
8782 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
8783 channels[i].chan,
8784 channels[i].power_level,
8785 channels[i].
8786 flag & IEEE80211_CHAN_W_RADAR_DETECT ?
8787 " (IEEE 802.11h required)" : "",
8788 (!(channels[i].flag & IEEE80211_CHAN_W_IBSS)
8789 || (channels[i].
8790 flag &
8791 IEEE80211_CHAN_W_RADAR_DETECT)) ? "" :
8792 ", IBSS",
8793 channels[i].
8794 flag & IEEE80211_CHAN_W_ACTIVE_SCAN ?
8795 "active/passive" : "passive only");
8796
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008797 hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211A);
Zhu Yib481de92007-09-25 17:54:57 -07008798 if (hw_mode) {
8799 channels = hw_mode->channels;
8800 count = hw_mode->num_channels;
8801 } else {
8802 channels = NULL;
8803 count = 0;
8804 }
8805
8806 len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band "
8807 "(802.11a):\n", count);
8808
8809 for (i = 0; i < count; i++)
8810 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
8811 channels[i].chan,
8812 channels[i].power_level,
8813 channels[i].
8814 flag & IEEE80211_CHAN_W_RADAR_DETECT ?
8815 " (IEEE 802.11h required)" : "",
8816 (!(channels[i].flag & IEEE80211_CHAN_W_IBSS)
8817 || (channels[i].
8818 flag &
8819 IEEE80211_CHAN_W_RADAR_DETECT)) ? "" :
8820 ", IBSS",
8821 channels[i].
8822 flag & IEEE80211_CHAN_W_ACTIVE_SCAN ?
8823 "active/passive" : "passive only");
8824
8825 return len;
8826}
8827
8828static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
8829
8830static ssize_t show_statistics(struct device *d,
8831 struct device_attribute *attr, char *buf)
8832{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008833 struct iwl4965_priv *priv = dev_get_drvdata(d);
8834 u32 size = sizeof(struct iwl4965_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07008835 u32 len = 0, ofs = 0;
8836 u8 *data = (u8 *) & priv->statistics;
8837 int rc = 0;
8838
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008839 if (!iwl4965_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07008840 return -EAGAIN;
8841
8842 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008843 rc = iwl4965_send_statistics_request(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008844 mutex_unlock(&priv->mutex);
8845
8846 if (rc) {
8847 len = sprintf(buf,
8848 "Error sending statistics request: 0x%08X\n", rc);
8849 return len;
8850 }
8851
8852 while (size && (PAGE_SIZE - len)) {
8853 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
8854 PAGE_SIZE - len, 1);
8855 len = strlen(buf);
8856 if (PAGE_SIZE - len)
8857 buf[len++] = '\n';
8858
8859 ofs += 16;
8860 size -= min(size, 16U);
8861 }
8862
8863 return len;
8864}
8865
8866static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
8867
8868static ssize_t show_antenna(struct device *d,
8869 struct device_attribute *attr, char *buf)
8870{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008871 struct iwl4965_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07008872
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008873 if (!iwl4965_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07008874 return -EAGAIN;
8875
8876 return sprintf(buf, "%d\n", priv->antenna);
8877}
8878
8879static ssize_t store_antenna(struct device *d,
8880 struct device_attribute *attr,
8881 const char *buf, size_t count)
8882{
8883 int ant;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008884 struct iwl4965_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07008885
8886 if (count == 0)
8887 return 0;
8888
8889 if (sscanf(buf, "%1i", &ant) != 1) {
8890 IWL_DEBUG_INFO("not in hex or decimal form.\n");
8891 return count;
8892 }
8893
8894 if ((ant >= 0) && (ant <= 2)) {
8895 IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008896 priv->antenna = (enum iwl4965_antenna)ant;
Zhu Yib481de92007-09-25 17:54:57 -07008897 } else
8898 IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant);
8899
8900
8901 return count;
8902}
8903
8904static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
8905
8906static ssize_t show_status(struct device *d,
8907 struct device_attribute *attr, char *buf)
8908{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008909 struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8910 if (!iwl4965_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07008911 return -EAGAIN;
8912 return sprintf(buf, "0x%08x\n", (int)priv->status);
8913}
8914
8915static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
8916
8917static ssize_t dump_error_log(struct device *d,
8918 struct device_attribute *attr,
8919 const char *buf, size_t count)
8920{
8921 char *p = (char *)buf;
8922
8923 if (p[0] == '1')
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008924 iwl4965_dump_nic_error_log((struct iwl4965_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07008925
8926 return strnlen(buf, count);
8927}
8928
8929static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
8930
8931static ssize_t dump_event_log(struct device *d,
8932 struct device_attribute *attr,
8933 const char *buf, size_t count)
8934{
8935 char *p = (char *)buf;
8936
8937 if (p[0] == '1')
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008938 iwl4965_dump_nic_event_log((struct iwl4965_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07008939
8940 return strnlen(buf, count);
8941}
8942
8943static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
8944
8945/*****************************************************************************
8946 *
8947 * driver setup and teardown
8948 *
8949 *****************************************************************************/
8950
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008951static void iwl4965_setup_deferred_work(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07008952{
8953 priv->workqueue = create_workqueue(DRV_NAME);
8954
8955 init_waitqueue_head(&priv->wait_command_queue);
8956
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008957 INIT_WORK(&priv->up, iwl4965_bg_up);
8958 INIT_WORK(&priv->restart, iwl4965_bg_restart);
8959 INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish);
8960 INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed);
8961 INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan);
8962 INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan);
8963 INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill);
8964 INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update);
8965 INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate);
8966 INIT_DELAYED_WORK(&priv->init_alive_start, iwl4965_bg_init_alive_start);
8967 INIT_DELAYED_WORK(&priv->alive_start, iwl4965_bg_alive_start);
8968 INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check);
Zhu Yib481de92007-09-25 17:54:57 -07008969
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008970 iwl4965_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008971
8972 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008973 iwl4965_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07008974}
8975
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008976static void iwl4965_cancel_deferred_work(struct iwl4965_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07008977{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008978 iwl4965_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07008979
Joonwoo Park3ae6a052007-11-29 10:43:16 +09008980 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07008981 cancel_delayed_work(&priv->scan_check);
8982 cancel_delayed_work(&priv->alive_start);
8983 cancel_delayed_work(&priv->post_associate);
8984 cancel_work_sync(&priv->beacon_update);
8985}
8986
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08008987static struct attribute *iwl4965_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07008988 &dev_attr_antenna.attr,
8989 &dev_attr_channels.attr,
8990 &dev_attr_dump_errors.attr,
8991 &dev_attr_dump_events.attr,
8992 &dev_attr_flags.attr,
8993 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08008994#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07008995 &dev_attr_measurement.attr,
8996#endif
8997 &dev_attr_power_level.attr,
8998 &dev_attr_retry_rate.attr,
8999 &dev_attr_rf_kill.attr,
9000 &dev_attr_rs_window.attr,
9001 &dev_attr_statistics.attr,
9002 &dev_attr_status.attr,
9003 &dev_attr_temperature.attr,
9004 &dev_attr_tune.attr,
9005 &dev_attr_tx_power.attr,
9006
9007 NULL
9008};
9009
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009010static struct attribute_group iwl4965_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07009011 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009012 .attrs = iwl4965_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07009013};
9014
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009015static struct ieee80211_ops iwl4965_hw_ops = {
9016 .tx = iwl4965_mac_tx,
9017 .start = iwl4965_mac_start,
9018 .stop = iwl4965_mac_stop,
9019 .add_interface = iwl4965_mac_add_interface,
9020 .remove_interface = iwl4965_mac_remove_interface,
9021 .config = iwl4965_mac_config,
9022 .config_interface = iwl4965_mac_config_interface,
9023 .configure_filter = iwl4965_configure_filter,
9024 .set_key = iwl4965_mac_set_key,
9025 .get_stats = iwl4965_mac_get_stats,
9026 .get_tx_stats = iwl4965_mac_get_tx_stats,
9027 .conf_tx = iwl4965_mac_conf_tx,
9028 .get_tsf = iwl4965_mac_get_tsf,
9029 .reset_tsf = iwl4965_mac_reset_tsf,
9030 .beacon_update = iwl4965_mac_beacon_update,
Johannes Berg471b3ef2007-12-28 14:32:58 +01009031 .bss_info_changed = iwl4965_bss_info_changed,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08009032#ifdef CONFIG_IWL4965_HT
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009033 .conf_ht = iwl4965_mac_conf_ht,
Ron Rindjunsky9ab46172007-12-25 17:00:38 +02009034 .ampdu_action = iwl4965_mac_ampdu_action,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08009035#endif /* CONFIG_IWL4965_HT */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009036 .hw_scan = iwl4965_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07009037};
9038
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009039static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07009040{
9041 int err = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009042 struct iwl4965_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07009043 struct ieee80211_hw *hw;
9044 int i;
Zhu Yi5a669262008-01-14 17:46:18 -08009045 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07009046
Cahill, Ben M6440adb2007-11-29 11:09:55 +08009047 /* Disabling hardware scan means that mac80211 will perform scans
9048 * "the hard way", rather than using device's scan. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009049 if (iwl4965_param_disable_hw_scan) {
Zhu Yib481de92007-09-25 17:54:57 -07009050 IWL_DEBUG_INFO("Disabling hw_scan\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009051 iwl4965_hw_ops.hw_scan = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07009052 }
9053
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009054 if ((iwl4965_param_queues_num > IWL_MAX_NUM_QUEUES) ||
9055 (iwl4965_param_queues_num < IWL_MIN_NUM_QUEUES)) {
Zhu Yib481de92007-09-25 17:54:57 -07009056 IWL_ERROR("invalid queues_num, should be between %d and %d\n",
9057 IWL_MIN_NUM_QUEUES, IWL_MAX_NUM_QUEUES);
9058 err = -EINVAL;
9059 goto out;
9060 }
9061
9062 /* mac80211 allocates memory for this device instance, including
9063 * space for this driver's private structure */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009064 hw = ieee80211_alloc_hw(sizeof(struct iwl4965_priv), &iwl4965_hw_ops);
Zhu Yib481de92007-09-25 17:54:57 -07009065 if (hw == NULL) {
9066 IWL_ERROR("Can not allocate network device\n");
9067 err = -ENOMEM;
9068 goto out;
9069 }
9070 SET_IEEE80211_DEV(hw, &pdev->dev);
9071
Johannes Bergf51359a2007-10-28 14:53:36 +01009072 hw->rate_control_algorithm = "iwl-4965-rs";
9073
Zhu Yib481de92007-09-25 17:54:57 -07009074 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
9075 priv = hw->priv;
9076 priv->hw = hw;
9077
9078 priv->pci_dev = pdev;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009079 priv->antenna = (enum iwl4965_antenna)iwl4965_param_antenna;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08009080#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009081 iwl4965_debug_level = iwl4965_param_debug;
Zhu Yib481de92007-09-25 17:54:57 -07009082 atomic_set(&priv->restrict_refcnt, 0);
9083#endif
9084 priv->retry_rate = 1;
9085
9086 priv->ibss_beacon = NULL;
9087
9088 /* Tell mac80211 and its clients (e.g. Wireless Extensions)
9089 * the range of signal quality values that we'll provide.
9090 * Negative values for level/noise indicate that we'll provide dBm.
9091 * For WE, at least, non-0 values here *enable* display of values
9092 * in app (iwconfig). */
9093 hw->max_rssi = -20; /* signal level, negative indicates dBm */
9094 hw->max_noise = -20; /* noise level, negative indicates dBm */
9095 hw->max_signal = 100; /* link quality indication (%) */
9096
9097 /* Tell mac80211 our Tx characteristics */
9098 hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE;
9099
Cahill, Ben M6440adb2007-11-29 11:09:55 +08009100 /* Default value; 4 EDCA QOS priorities */
Zhu Yib481de92007-09-25 17:54:57 -07009101 hw->queues = 4;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08009102#ifdef CONFIG_IWL4965_HT
Cahill, Ben M6440adb2007-11-29 11:09:55 +08009103 /* Enhanced value; more queues, to support 11n aggregation */
Zhu Yib481de92007-09-25 17:54:57 -07009104 hw->queues = 16;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08009105#endif /* CONFIG_IWL4965_HT */
Zhu Yib481de92007-09-25 17:54:57 -07009106
9107 spin_lock_init(&priv->lock);
9108 spin_lock_init(&priv->power_data.lock);
9109 spin_lock_init(&priv->sta_lock);
9110 spin_lock_init(&priv->hcmd_lock);
9111 spin_lock_init(&priv->lq_mngr.lock);
9112
9113 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++)
9114 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
9115
9116 INIT_LIST_HEAD(&priv->free_frames);
9117
9118 mutex_init(&priv->mutex);
9119 if (pci_enable_device(pdev)) {
9120 err = -ENODEV;
9121 goto out_ieee80211_free_hw;
9122 }
9123
9124 pci_set_master(pdev);
9125
Cahill, Ben M6440adb2007-11-29 11:09:55 +08009126 /* Clear the driver's (not device's) station table */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009127 iwl4965_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009128
9129 priv->data_retry_limit = -1;
9130 priv->ieee_channels = NULL;
9131 priv->ieee_rates = NULL;
9132 priv->phymode = -1;
9133
9134 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
9135 if (!err)
9136 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
9137 if (err) {
9138 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
9139 goto out_pci_disable_device;
9140 }
9141
9142 pci_set_drvdata(pdev, priv);
9143 err = pci_request_regions(pdev, DRV_NAME);
9144 if (err)
9145 goto out_pci_disable_device;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08009146
Zhu Yib481de92007-09-25 17:54:57 -07009147 /* We disable the RETRY_TIMEOUT register (0x41) to keep
9148 * PCI Tx retries from interfering with C3 CPU state */
9149 pci_write_config_byte(pdev, 0x41, 0x00);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08009150
Zhu Yib481de92007-09-25 17:54:57 -07009151 priv->hw_base = pci_iomap(pdev, 0, 0);
9152 if (!priv->hw_base) {
9153 err = -ENODEV;
9154 goto out_pci_release_regions;
9155 }
9156
9157 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
9158 (unsigned long long) pci_resource_len(pdev, 0));
9159 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
9160
9161 /* Initialize module parameter values here */
9162
Cahill, Ben M6440adb2007-11-29 11:09:55 +08009163 /* Disable radio (SW RF KILL) via parameter when loading driver */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009164 if (iwl4965_param_disable) {
Zhu Yib481de92007-09-25 17:54:57 -07009165 set_bit(STATUS_RF_KILL_SW, &priv->status);
9166 IWL_DEBUG_INFO("Radio disabled.\n");
9167 }
9168
9169 priv->iw_mode = IEEE80211_IF_TYPE_STA;
9170
9171 priv->ps_mode = 0;
9172 priv->use_ant_b_for_management_frame = 1; /* start with ant B */
Zhu Yib481de92007-09-25 17:54:57 -07009173 priv->valid_antenna = 0x7; /* assume all 3 connected */
9174 priv->ps_mode = IWL_MIMO_PS_NONE;
Zhu Yib481de92007-09-25 17:54:57 -07009175
Cahill, Ben M6440adb2007-11-29 11:09:55 +08009176 /* Choose which receivers/antennas to use */
Zhu Yib481de92007-09-25 17:54:57 -07009177 iwl4965_set_rxon_chain(priv);
9178
9179 printk(KERN_INFO DRV_NAME
9180 ": Detected Intel Wireless WiFi Link 4965AGN\n");
9181
9182 /* Device-specific setup */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009183 if (iwl4965_hw_set_hw_setting(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07009184 IWL_ERROR("failed to set hw settings\n");
Zhu Yib481de92007-09-25 17:54:57 -07009185 goto out_iounmap;
9186 }
9187
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08009188#ifdef CONFIG_IWL4965_QOS
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009189 if (iwl4965_param_qos_enable)
Zhu Yib481de92007-09-25 17:54:57 -07009190 priv->qos_data.qos_enable = 1;
9191
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009192 iwl4965_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009193
9194 priv->qos_data.qos_active = 0;
9195 priv->qos_data.qos_cap.val = 0;
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08009196#endif /* CONFIG_IWL4965_QOS */
Zhu Yib481de92007-09-25 17:54:57 -07009197
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009198 iwl4965_set_rxon_channel(priv, MODE_IEEE80211G, 6);
9199 iwl4965_setup_deferred_work(priv);
9200 iwl4965_setup_rx_handlers(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009201
9202 priv->rates_mask = IWL_RATES_MASK;
9203 /* If power management is turned on, default to AC mode */
9204 priv->power_mode = IWL_POWER_AC;
9205 priv->user_txpower_limit = IWL_DEFAULT_TX_POWER;
9206
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009207 iwl4965_disable_interrupts(priv);
Jes Sorensen49df2b32007-10-26 16:10:39 +02009208
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009209 err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07009210 if (err) {
9211 IWL_ERROR("failed to create sysfs device attributes\n");
Zhu Yib481de92007-09-25 17:54:57 -07009212 goto out_release_irq;
9213 }
9214
Zhu Yi5a669262008-01-14 17:46:18 -08009215 /* nic init */
9216 iwl4965_set_bit(priv, CSR_GIO_CHICKEN_BITS,
9217 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
9218
9219 iwl4965_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
9220 err = iwl4965_poll_bit(priv, CSR_GP_CNTRL,
9221 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
9222 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
9223 if (err < 0) {
9224 IWL_DEBUG_INFO("Failed to init the card\n");
9225 goto out_remove_sysfs;
9226 }
9227 /* Read the EEPROM */
9228 err = iwl4965_eeprom_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009229 if (err) {
Zhu Yi5a669262008-01-14 17:46:18 -08009230 IWL_ERROR("Unable to init EEPROM\n");
9231 goto out_remove_sysfs;
9232 }
9233 /* MAC Address location in EEPROM same for 3945/4965 */
9234 get_eeprom_mac(priv, priv->mac_addr);
9235 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr));
9236 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
9237
Reinette Chatre849e0dc2008-01-23 10:15:18 -08009238 err = iwl4965_init_channel_map(priv);
9239 if (err) {
9240 IWL_ERROR("initializing regulatory failed: %d\n", err);
9241 goto out_remove_sysfs;
9242 }
9243
9244 err = iwl4965_init_geos(priv);
9245 if (err) {
9246 IWL_ERROR("initializing geos failed: %d\n", err);
9247 goto out_free_channel_map;
9248 }
9249 iwl4965_reset_channel_flag(priv);
9250
Zhu Yi5a669262008-01-14 17:46:18 -08009251 iwl4965_rate_control_register(priv->hw);
9252 err = ieee80211_register_hw(priv->hw);
9253 if (err) {
9254 IWL_ERROR("Failed to register network device (error %d)\n", err);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08009255 goto out_free_geos;
Zhu Yib481de92007-09-25 17:54:57 -07009256 }
9257
Zhu Yi5a669262008-01-14 17:46:18 -08009258 priv->hw->conf.beacon_int = 100;
9259 priv->mac80211_registered = 1;
9260 pci_save_state(pdev);
9261 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07009262
9263 return 0;
9264
Reinette Chatre849e0dc2008-01-23 10:15:18 -08009265 out_free_geos:
9266 iwl4965_free_geos(priv);
9267 out_free_channel_map:
9268 iwl4965_free_channel_map(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08009269 out_remove_sysfs:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009270 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07009271
9272 out_release_irq:
Zhu Yib481de92007-09-25 17:54:57 -07009273 destroy_workqueue(priv->workqueue);
9274 priv->workqueue = NULL;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009275 iwl4965_unset_hw_setting(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009276
9277 out_iounmap:
9278 pci_iounmap(pdev, priv->hw_base);
9279 out_pci_release_regions:
9280 pci_release_regions(pdev);
9281 out_pci_disable_device:
9282 pci_disable_device(pdev);
9283 pci_set_drvdata(pdev, NULL);
9284 out_ieee80211_free_hw:
9285 ieee80211_free_hw(priv->hw);
9286 out:
9287 return err;
9288}
9289
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009290static void iwl4965_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07009291{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009292 struct iwl4965_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07009293 struct list_head *p, *q;
9294 int i;
9295
9296 if (!priv)
9297 return;
9298
9299 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
9300
Zhu Yib481de92007-09-25 17:54:57 -07009301 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08009302
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009303 iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009304
9305 /* Free MAC hash list for ADHOC */
9306 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
9307 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
9308 list_del(p);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009309 kfree(list_entry(p, struct iwl4965_ibss_seq, list));
Zhu Yib481de92007-09-25 17:54:57 -07009310 }
9311 }
9312
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009313 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07009314
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009315 iwl4965_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009316
9317 if (priv->rxq.bd)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009318 iwl4965_rx_queue_free(priv, &priv->rxq);
9319 iwl4965_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009320
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009321 iwl4965_unset_hw_setting(priv);
9322 iwl4965_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009323
9324 if (priv->mac80211_registered) {
9325 ieee80211_unregister_hw(priv->hw);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009326 iwl4965_rate_control_unregister(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07009327 }
9328
Mohamed Abbas948c1712007-10-25 17:15:45 +08009329 /*netif_stop_queue(dev); */
9330 flush_workqueue(priv->workqueue);
9331
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009332 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07009333 * priv->workqueue... so we can't take down the workqueue
9334 * until now... */
9335 destroy_workqueue(priv->workqueue);
9336 priv->workqueue = NULL;
9337
Zhu Yib481de92007-09-25 17:54:57 -07009338 pci_iounmap(pdev, priv->hw_base);
9339 pci_release_regions(pdev);
9340 pci_disable_device(pdev);
9341 pci_set_drvdata(pdev, NULL);
9342
Reinette Chatre849e0dc2008-01-23 10:15:18 -08009343 iwl4965_free_channel_map(priv);
9344 iwl4965_free_geos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07009345
9346 if (priv->ibss_beacon)
9347 dev_kfree_skb(priv->ibss_beacon);
9348
9349 ieee80211_free_hw(priv->hw);
9350}
9351
9352#ifdef CONFIG_PM
9353
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009354static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07009355{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009356 struct iwl4965_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07009357
Zhu Yie655b9f2008-01-24 02:19:38 -08009358 if (priv->is_open) {
9359 set_bit(STATUS_IN_SUSPEND, &priv->status);
9360 iwl4965_mac_stop(priv->hw);
9361 priv->is_open = 1;
9362 }
Zhu Yib481de92007-09-25 17:54:57 -07009363
Zhu Yib481de92007-09-25 17:54:57 -07009364 pci_set_power_state(pdev, PCI_D3hot);
9365
Zhu Yib481de92007-09-25 17:54:57 -07009366 return 0;
9367}
9368
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009369static int iwl4965_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07009370{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009371 struct iwl4965_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07009372
Zhu Yib481de92007-09-25 17:54:57 -07009373 pci_set_power_state(pdev, PCI_D0);
Zhu Yib481de92007-09-25 17:54:57 -07009374
Zhu Yie655b9f2008-01-24 02:19:38 -08009375 if (priv->is_open)
9376 iwl4965_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07009377
Zhu Yie655b9f2008-01-24 02:19:38 -08009378 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07009379 return 0;
9380}
9381
9382#endif /* CONFIG_PM */
9383
9384/*****************************************************************************
9385 *
9386 * driver and module entry point
9387 *
9388 *****************************************************************************/
9389
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009390static struct pci_driver iwl4965_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07009391 .name = DRV_NAME,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009392 .id_table = iwl4965_hw_card_ids,
9393 .probe = iwl4965_pci_probe,
9394 .remove = __devexit_p(iwl4965_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07009395#ifdef CONFIG_PM
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009396 .suspend = iwl4965_pci_suspend,
9397 .resume = iwl4965_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07009398#endif
9399};
9400
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009401static int __init iwl4965_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07009402{
9403
9404 int ret;
9405 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
9406 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009407 ret = pci_register_driver(&iwl4965_driver);
Zhu Yib481de92007-09-25 17:54:57 -07009408 if (ret) {
9409 IWL_ERROR("Unable to initialize PCI module\n");
9410 return ret;
9411 }
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08009412#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009413 ret = driver_create_file(&iwl4965_driver.driver, &driver_attr_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07009414 if (ret) {
9415 IWL_ERROR("Unable to create driver sysfs file\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009416 pci_unregister_driver(&iwl4965_driver);
Zhu Yib481de92007-09-25 17:54:57 -07009417 return ret;
9418 }
9419#endif
9420
9421 return ret;
9422}
9423
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009424static void __exit iwl4965_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07009425{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08009426#ifdef CONFIG_IWL4965_DEBUG
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009427 driver_remove_file(&iwl4965_driver.driver, &driver_attr_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07009428#endif
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009429 pci_unregister_driver(&iwl4965_driver);
Zhu Yib481de92007-09-25 17:54:57 -07009430}
9431
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009432module_param_named(antenna, iwl4965_param_antenna, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07009433MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009434module_param_named(disable, iwl4965_param_disable, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07009435MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009436module_param_named(hwcrypto, iwl4965_param_hwcrypto, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07009437MODULE_PARM_DESC(hwcrypto,
9438 "using hardware crypto engine (default 0 [software])\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009439module_param_named(debug, iwl4965_param_debug, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07009440MODULE_PARM_DESC(debug, "debug output mask");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009441module_param_named(disable_hw_scan, iwl4965_param_disable_hw_scan, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07009442MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
9443
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009444module_param_named(queues_num, iwl4965_param_queues_num, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07009445MODULE_PARM_DESC(queues_num, "number of hw queues.");
9446
9447/* QoS */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009448module_param_named(qos_enable, iwl4965_param_qos_enable, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07009449MODULE_PARM_DESC(qos_enable, "enable all QoS functionality");
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02009450module_param_named(amsdu_size_8K, iwl4965_param_amsdu_size_8K, int, 0444);
9451MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
Zhu Yib481de92007-09-25 17:54:57 -07009452
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08009453module_exit(iwl4965_exit);
9454module_init(iwl4965_init);