1
/******************************************************************************
3
* Copyright(c) 2003 - 2007 Intel Corporation. All rights reserved.
5
* Portions of this file are derived from the ipw3945 project, as well
6
* as portions of the ieee80211 subsystem header files.
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.
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
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
21
* The full GNU General Public License is included in this distribution in the
22
* file called LICENSE.
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
28
*****************************************************************************/
30
#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>
41
#include <linux/skbuff.h>
42
#include <linux/netdevice.h>
43
#include <linux/etherdevice.h>
44
#include <linux/if_arp.h>
46
#include <net/ieee80211_radiotap.h>
47
#include <net/mac80211.h>
49
#include <asm/div64.h>
52
#include "iwl-helpers.h"
54
#ifdef CONFIG_IWL4965_DEBUG
55
u32 iwl4965_debug_level;
58
static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv,
59
struct iwl4965_tx_queue *txq);
61
/******************************************************************************
65
******************************************************************************/
67
/* module parameters */
68
static int iwl4965_param_disable_hw_scan; /* def: 0 = use 4965's h/w scan */
69
static int iwl4965_param_debug; /* def: 0 = minimal debug log messages */
70
static int iwl4965_param_disable; /* def: enable radio */
71
static int iwl4965_param_antenna; /* def: 0 = both antennas (use diversity) */
72
int iwl4965_param_hwcrypto; /* def: using software encryption */
73
static int iwl4965_param_qos_enable = 1; /* def: 1 = use quality of service */
74
int iwl4965_param_queues_num = IWL_MAX_NUM_QUEUES; /* def: 16 Tx queues */
77
* module name, copyright, version, etc.
78
* NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
81
#define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux"
83
#ifdef CONFIG_IWL4965_DEBUG
89
#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
95
#define IWLWIFI_VERSION "1.2.25" VD VS
96
#define DRV_COPYRIGHT "Copyright(c) 2003-2007 Intel Corporation"
97
#define DRV_VERSION IWLWIFI_VERSION
99
/* Change firmware file name, using "-" and incrementing number,
100
* *only* when uCode interface or architecture changes so that it
101
* is not compatible with earlier drivers.
102
* This number will also appear in << 8 position of 1st dword of uCode file */
103
#define IWL4965_UCODE_API "-1-lbm"
105
MODULE_DESCRIPTION(DRV_DESCRIPTION);
106
MODULE_VERSION(DRV_VERSION);
107
MODULE_AUTHOR(DRV_COPYRIGHT);
108
MODULE_LICENSE("GPL");
110
__le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr)
112
u16 fc = le16_to_cpu(hdr->frame_control);
113
int hdr_len = iwlwifi_ieee80211_get_hdrlen(fc);
115
if ((fc & 0x00cc) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA))
116
return (__le16 *) ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN);
120
static const struct ieee80211_hw_mode *iwl4965_get_hw_mode(
121
struct iwl4965_priv *priv, int mode)
125
for (i = 0; i < 3; i++)
126
if (priv->modes[i].mode == mode)
127
return &priv->modes[i];
132
static int iwl4965_is_empty_essid(const char *essid, int essid_len)
134
/* Single white space is for Linksys APs */
135
if (essid_len == 1 && essid[0] == ' ')
138
/* Otherwise, if the entire essid is 0, we assume it is hidden */
141
if (essid[essid_len] != '\0')
148
static const char *iwl4965_escape_essid(const char *essid, u8 essid_len)
150
static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
151
const char *s = essid;
154
if (iwl4965_is_empty_essid(essid, essid_len)) {
155
memcpy(escaped, "<hidden>", sizeof("<hidden>"));
159
essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE);
160
while (essid_len--) {
172
#ifndef hex_dump_to_buffer
173
static inline int snprint_line(char *buf, size_t count,
174
const u8 * data, u32 len, u32 ofs)
179
out = snprintf(buf, count, "%08X", ofs);
181
for (l = 0, i = 0; i < 2; i++) {
182
out += snprintf(buf + out, count - out, " ");
183
for (j = 0; j < 8 && l < len; j++, l++)
185
snprintf(buf + out, count - out, "%02X ",
188
out += snprintf(buf + out, count - out, " ");
190
out += snprintf(buf + out, count - out, " ");
191
for (l = 0, i = 0; i < 2; i++) {
192
out += snprintf(buf + out, count - out, " ");
193
for (j = 0; j < 8 && l < len; j++, l++) {
194
c = data[(i * 8 + j)];
195
if (!isascii(c) || !isprint(c))
198
out += snprintf(buf + out, count - out, "%c", c);
202
out += snprintf(buf + out, count - out, " ");
208
#ifdef CONFIG_IWL4965_DEBUG
209
static inline void printk_buf(int level, const void *p, u32 len)
214
if (!(iwl4965_debug_level & level))
218
snprint_line(line, sizeof(line), &data[ofs],
220
printk(KERN_DEBUG "%s\n", line);
222
len -= min(len, 16U);
226
#define printk_buf(level, p, len) do {} while (0)
229
#define hex_dump_to_buffer(d, s, l, g, lb, ls, a) \
230
snprint_line(lb, ls, d, min(s, (unsigned int)l), 0)
232
#define print_hex_dump(m, p, t, l, g, d, s, a) \
233
printk_buf(IWL_DL_INFO, d, s);
235
#endif /* hex_dump_to_buffer */
237
static void iwl4965_print_hex_dump(int level, void *p, u32 len)
239
#ifdef CONFIG_IWL4965_DEBUG
240
if (!(iwl4965_debug_level & level))
243
print_hex_dump(KERN_DEBUG, "iwl data: ", DUMP_PREFIX_OFFSET, 16, 1,
248
/*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
251
* Theory of operation
253
* A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
254
* of buffer descriptors, each of which points to one or more data buffers for
255
* the device to read from or fill. Driver and device exchange status of each
256
* queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
257
* entries in each circular buffer, to protect against confusing empty and full
260
* The device reads or writes the data in the queues via the device's several
261
* DMA/FIFO channels. Each queue is mapped to a single DMA channel.
263
* For Tx queue, there are low mark and high mark limits. If, after queuing
264
* the packet for Tx, free space become < low mark, Tx queue stopped. When
265
* reclaiming packets (on 'tx done IRQ), if free space become > high mark,
268
* The 4965 operates with up to 17 queues: One receive queue, one transmit
269
* queue (#4) for sending commands to the device firmware, and 15 other
270
* Tx queues that may be mapped to prioritized Tx DMA/FIFO channels.
272
* See more detailed info in iwl-4965-hw.h.
273
***************************************************/
275
static int iwl4965_queue_space(const struct iwl4965_queue *q)
277
int s = q->read_ptr - q->write_ptr;
279
if (q->read_ptr > q->write_ptr)
284
/* keep some reserve to not confuse empty and full situations */
292
* iwl4965_queue_inc_wrap - increment queue index, wrap back to beginning
293
* @index -- current index
294
* @n_bd -- total number of entries in queue (must be power of 2)
296
static inline int iwl4965_queue_inc_wrap(int index, int n_bd)
298
return ++index & (n_bd - 1);
302
* iwl4965_queue_dec_wrap - decrement queue index, wrap back to end
303
* @index -- current index
304
* @n_bd -- total number of entries in queue (must be power of 2)
306
static inline int iwl4965_queue_dec_wrap(int index, int n_bd)
308
return --index & (n_bd - 1);
311
static inline int x2_queue_used(const struct iwl4965_queue *q, int i)
313
return q->write_ptr > q->read_ptr ?
314
(i >= q->read_ptr && i < q->write_ptr) :
315
!(i < q->read_ptr && i >= q->write_ptr);
318
static inline u8 get_cmd_index(struct iwl4965_queue *q, u32 index, int is_huge)
320
/* This is for scan command, the big buffer at end of command array */
322
return q->n_window; /* must be power of 2 */
324
/* Otherwise, use normal size buffers */
325
return index & (q->n_window - 1);
329
* iwl4965_queue_init - Initialize queue's high/low-water and read/write indexes
331
static int iwl4965_queue_init(struct iwl4965_priv *priv, struct iwl4965_queue *q,
332
int count, int slots_num, u32 id)
335
q->n_window = slots_num;
338
/* count must be power-of-two size, otherwise iwl4965_queue_inc_wrap
339
* and iwl4965_queue_dec_wrap are broken. */
340
BUG_ON(!is_power_of_2(count));
342
/* slots_num must be power-of-two size, otherwise
343
* get_cmd_index is broken. */
344
BUG_ON(!is_power_of_2(slots_num));
346
q->low_mark = q->n_window / 4;
350
q->high_mark = q->n_window / 8;
351
if (q->high_mark < 2)
354
q->write_ptr = q->read_ptr = 0;
360
* iwl4965_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
362
static int iwl4965_tx_queue_alloc(struct iwl4965_priv *priv,
363
struct iwl4965_tx_queue *txq, u32 id)
365
struct pci_dev *dev = priv->pci_dev;
367
/* Driver private data, only for Tx (not command) queues,
368
* not shared with device. */
369
if (id != IWL_CMD_QUEUE_NUM) {
370
txq->txb = kmalloc(sizeof(txq->txb[0]) *
371
TFD_QUEUE_SIZE_MAX, GFP_KERNEL);
373
IWL_ERROR("kmalloc for auxiliary BD "
374
"structures failed\n");
380
/* Circular buffer of transmit frame descriptors (TFDs),
381
* shared with device */
382
txq->bd = pci_alloc_consistent(dev,
383
sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX,
387
IWL_ERROR("pci_alloc_consistent(%zd) failed\n",
388
sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX);
405
* iwl4965_tx_queue_init - Allocate and initialize one tx/cmd queue
407
int iwl4965_tx_queue_init(struct iwl4965_priv *priv,
408
struct iwl4965_tx_queue *txq, int slots_num, u32 txq_id)
410
struct pci_dev *dev = priv->pci_dev;
415
* Alloc buffer array for commands (Tx or other types of commands).
416
* For the command queue (#4), allocate command space + one big
417
* command for scan, since scan command is very huge; the system will
418
* not have two scans at the same time, so only one is needed.
419
* For data Tx queues (all other queues), no super-size command
422
len = sizeof(struct iwl4965_cmd) * slots_num;
423
if (txq_id == IWL_CMD_QUEUE_NUM)
424
len += IWL_MAX_SCAN_SIZE;
425
txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd);
429
/* Alloc driver data array and TFD circular buffer */
430
rc = iwl4965_tx_queue_alloc(priv, txq, txq_id);
432
pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
436
txq->need_update = 0;
438
/* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
439
* iwl4965_queue_inc_wrap and iwl4965_queue_dec_wrap are broken. */
440
BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
442
/* Initialize queue's high/low-water marks, and head/tail indexes */
443
iwl4965_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id);
445
/* Tell device where to find queue */
446
iwl4965_hw_tx_queue_init(priv, txq);
452
* iwl4965_tx_queue_free - Deallocate DMA queue.
453
* @txq: Transmit queue to deallocate.
455
* Empty queue by removing and destroying all BD's.
457
* 0-fill, but do not free "txq" descriptor structure.
459
void iwl4965_tx_queue_free(struct iwl4965_priv *priv, struct iwl4965_tx_queue *txq)
461
struct iwl4965_queue *q = &txq->q;
462
struct pci_dev *dev = priv->pci_dev;
468
/* first, empty all BD's */
469
for (; q->write_ptr != q->read_ptr;
470
q->read_ptr = iwl4965_queue_inc_wrap(q->read_ptr, q->n_bd))
471
iwl4965_hw_txq_free_tfd(priv, txq);
473
len = sizeof(struct iwl4965_cmd) * q->n_window;
474
if (q->id == IWL_CMD_QUEUE_NUM)
475
len += IWL_MAX_SCAN_SIZE;
477
/* De-alloc array of command/tx buffers */
478
pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
480
/* De-alloc circular buffer of TFDs */
482
pci_free_consistent(dev, sizeof(struct iwl4965_tfd_frame) *
483
txq->q.n_bd, txq->bd, txq->q.dma_addr);
485
/* De-alloc array of per-TFD driver data */
491
/* 0-fill queue descriptor structure */
492
memset(txq, 0, sizeof(*txq));
495
const u8 iwl4965_broadcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
497
/*************** STATION TABLE MANAGEMENT ****
498
* mac80211 should be examined to determine if sta_info is duplicating
499
* the functionality provided here
502
/**************************************************************/
504
#if 0 /* temporary disable till we add real remove station */
506
* iwl4965_remove_station - Remove driver's knowledge of station.
508
* NOTE: This does not remove station from device's station table.
510
static u8 iwl4965_remove_station(struct iwl4965_priv *priv, const u8 *addr, int is_ap)
512
int index = IWL_INVALID_STATION;
516
spin_lock_irqsave(&priv->sta_lock, flags);
520
else if (is_broadcast_ether_addr(addr))
521
index = priv->hw_setting.bcast_sta_id;
523
for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++)
524
if (priv->stations[i].used &&
525
!compare_ether_addr(priv->stations[i].sta.sta.addr,
531
if (unlikely(index == IWL_INVALID_STATION))
534
if (priv->stations[index].used) {
535
priv->stations[index].used = 0;
536
priv->num_stations--;
539
BUG_ON(priv->num_stations < 0);
542
spin_unlock_irqrestore(&priv->sta_lock, flags);
548
* iwl4965_clear_stations_table - Clear the driver's station table
550
* NOTE: This does not clear or otherwise alter the device's station table.
552
static void iwl4965_clear_stations_table(struct iwl4965_priv *priv)
556
spin_lock_irqsave(&priv->sta_lock, flags);
558
priv->num_stations = 0;
559
memset(priv->stations, 0, sizeof(priv->stations));
561
spin_unlock_irqrestore(&priv->sta_lock, flags);
565
* iwl4965_add_station_flags - Add station to tables in driver and device
567
u8 iwl4965_add_station_flags(struct iwl4965_priv *priv, const u8 *addr, int is_ap, u8 flags)
570
int index = IWL_INVALID_STATION;
571
struct iwl4965_station_entry *station;
572
unsigned long flags_spin;
574
spin_lock_irqsave(&priv->sta_lock, flags_spin);
577
else if (is_broadcast_ether_addr(addr))
578
index = priv->hw_setting.bcast_sta_id;
580
for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) {
581
if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
587
if (!priv->stations[i].used &&
588
index == IWL_INVALID_STATION)
593
/* These two conditions have the same outcome, but keep them separate
594
since they have different meanings */
595
if (unlikely(index == IWL_INVALID_STATION)) {
596
spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
600
if (priv->stations[index].used &&
601
!compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) {
602
spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
607
IWL_DEBUG_ASSOC("Add STA ID %d: " MAC_FMT "\n", index, MAC_ARG(addr));
608
station = &priv->stations[index];
610
priv->num_stations++;
612
/* Set up the REPLY_ADD_STA command to send to device */
613
memset(&station->sta, 0, sizeof(struct iwl4965_addsta_cmd));
614
memcpy(station->sta.sta.addr, addr, ETH_ALEN);
615
station->sta.mode = 0;
616
station->sta.sta.sta_id = index;
617
station->sta.station_flags = 0;
619
#ifdef CONFIG_IWL4965_HT
620
/* BCAST station and IBSS stations do not work in HT mode */
621
if (index != priv->hw_setting.bcast_sta_id &&
622
priv->iw_mode != IEEE80211_IF_TYPE_IBSS)
623
iwl4965_set_ht_add_station(priv, index);
624
#endif /*CONFIG_IWL4965_HT*/
626
spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
628
/* Add station to device's station table */
629
iwl4965_send_add_station(priv, &station->sta, flags);
634
/*************** DRIVER STATUS FUNCTIONS *****/
636
static inline int iwl4965_is_ready(struct iwl4965_priv *priv)
638
/* The adapter is 'ready' if READY and GEO_CONFIGURED bits are
639
* set but EXIT_PENDING is not */
640
return test_bit(STATUS_READY, &priv->status) &&
641
test_bit(STATUS_GEO_CONFIGURED, &priv->status) &&
642
!test_bit(STATUS_EXIT_PENDING, &priv->status);
645
static inline int iwl4965_is_alive(struct iwl4965_priv *priv)
647
return test_bit(STATUS_ALIVE, &priv->status);
650
static inline int iwl4965_is_init(struct iwl4965_priv *priv)
652
return test_bit(STATUS_INIT, &priv->status);
655
static inline int iwl4965_is_rfkill(struct iwl4965_priv *priv)
657
return test_bit(STATUS_RF_KILL_HW, &priv->status) ||
658
test_bit(STATUS_RF_KILL_SW, &priv->status);
661
static inline int iwl4965_is_ready_rf(struct iwl4965_priv *priv)
664
if (iwl4965_is_rfkill(priv))
667
return iwl4965_is_ready(priv);
670
/*************** HOST COMMAND QUEUE FUNCTIONS *****/
672
#define IWL_CMD(x) case x : return #x
674
static const char *get_cmd_string(u8 cmd)
677
IWL_CMD(REPLY_ALIVE);
678
IWL_CMD(REPLY_ERROR);
680
IWL_CMD(REPLY_RXON_ASSOC);
681
IWL_CMD(REPLY_QOS_PARAM);
682
IWL_CMD(REPLY_RXON_TIMING);
683
IWL_CMD(REPLY_ADD_STA);
684
IWL_CMD(REPLY_REMOVE_STA);
685
IWL_CMD(REPLY_REMOVE_ALL_STA);
687
IWL_CMD(REPLY_RATE_SCALE);
688
IWL_CMD(REPLY_LEDS_CMD);
689
IWL_CMD(REPLY_TX_LINK_QUALITY_CMD);
690
IWL_CMD(RADAR_NOTIFICATION);
691
IWL_CMD(REPLY_QUIET_CMD);
692
IWL_CMD(REPLY_CHANNEL_SWITCH);
693
IWL_CMD(CHANNEL_SWITCH_NOTIFICATION);
694
IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD);
695
IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION);
696
IWL_CMD(POWER_TABLE_CMD);
697
IWL_CMD(PM_SLEEP_NOTIFICATION);
698
IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC);
699
IWL_CMD(REPLY_SCAN_CMD);
700
IWL_CMD(REPLY_SCAN_ABORT_CMD);
701
IWL_CMD(SCAN_START_NOTIFICATION);
702
IWL_CMD(SCAN_RESULTS_NOTIFICATION);
703
IWL_CMD(SCAN_COMPLETE_NOTIFICATION);
704
IWL_CMD(BEACON_NOTIFICATION);
705
IWL_CMD(REPLY_TX_BEACON);
706
IWL_CMD(WHO_IS_AWAKE_NOTIFICATION);
707
IWL_CMD(QUIET_NOTIFICATION);
708
IWL_CMD(REPLY_TX_PWR_TABLE_CMD);
709
IWL_CMD(MEASURE_ABORT_NOTIFICATION);
710
IWL_CMD(REPLY_BT_CONFIG);
711
IWL_CMD(REPLY_STATISTICS_CMD);
712
IWL_CMD(STATISTICS_NOTIFICATION);
713
IWL_CMD(REPLY_CARD_STATE_CMD);
714
IWL_CMD(CARD_STATE_NOTIFICATION);
715
IWL_CMD(MISSED_BEACONS_NOTIFICATION);
716
IWL_CMD(REPLY_CT_KILL_CONFIG_CMD);
717
IWL_CMD(SENSITIVITY_CMD);
718
IWL_CMD(REPLY_PHY_CALIBRATION_CMD);
719
IWL_CMD(REPLY_RX_PHY_CMD);
720
IWL_CMD(REPLY_RX_MPDU_CMD);
721
IWL_CMD(REPLY_4965_RX);
722
IWL_CMD(REPLY_COMPRESSED_BA);
729
#define HOST_COMPLETE_TIMEOUT (HZ / 2)
732
* iwl4965_enqueue_hcmd - enqueue a uCode command
733
* @priv: device private data point
734
* @cmd: a point to the ucode command structure
736
* The function returns < 0 values to indicate the operation is
737
* failed. On success, it turns the index (> 0) of command in the
740
static int iwl4965_enqueue_hcmd(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd)
742
struct iwl4965_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
743
struct iwl4965_queue *q = &txq->q;
744
struct iwl4965_tfd_frame *tfd;
746
struct iwl4965_cmd *out_cmd;
748
u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
749
dma_addr_t phys_addr;
753
/* If any of the command structures end up being larger than
754
* the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
755
* we will need to increase the size of the TFD entries */
756
BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
757
!(cmd->meta.flags & CMD_SIZE_HUGE));
759
if (iwl4965_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) {
760
IWL_ERROR("No space for Tx\n");
764
spin_lock_irqsave(&priv->hcmd_lock, flags);
766
tfd = &txq->bd[q->write_ptr];
767
memset(tfd, 0, sizeof(*tfd));
769
control_flags = (u32 *) tfd;
771
idx = get_cmd_index(q, q->write_ptr, cmd->meta.flags & CMD_SIZE_HUGE);
772
out_cmd = &txq->cmd[idx];
774
out_cmd->hdr.cmd = cmd->id;
775
memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta));
776
memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len);
778
/* At this point, the out_cmd now has all of the incoming cmd
781
out_cmd->hdr.flags = 0;
782
out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) |
783
INDEX_TO_SEQ(q->write_ptr));
784
if (out_cmd->meta.flags & CMD_SIZE_HUGE)
785
out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME);
787
phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx +
788
offsetof(struct iwl4965_cmd, hdr);
789
iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size);
791
IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
792
"%d bytes at %d[%d]:%d\n",
793
get_cmd_string(out_cmd->hdr.cmd),
794
out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence),
795
fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM);
797
txq->need_update = 1;
799
/* Set up entry in queue's byte count circular buffer */
800
ret = iwl4965_tx_queue_update_wr_ptr(priv, txq, 0);
802
/* Increment and update queue's write index */
803
q->write_ptr = iwl4965_queue_inc_wrap(q->write_ptr, q->n_bd);
804
iwl4965_tx_queue_update_write_ptr(priv, txq);
806
spin_unlock_irqrestore(&priv->hcmd_lock, flags);
807
return ret ? ret : idx;
810
static int iwl4965_send_cmd_async(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd)
814
BUG_ON(!(cmd->meta.flags & CMD_ASYNC));
816
/* An asynchronous command can not expect an SKB to be set. */
817
BUG_ON(cmd->meta.flags & CMD_WANT_SKB);
819
/* An asynchronous command MUST have a callback. */
820
BUG_ON(!cmd->meta.u.callback);
822
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
825
ret = iwl4965_enqueue_hcmd(priv, cmd);
827
IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n",
828
get_cmd_string(cmd->id), ret);
834
static int iwl4965_send_cmd_sync(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd)
838
static atomic_t entry = ATOMIC_INIT(0); /* reentrance protection */
840
BUG_ON(cmd->meta.flags & CMD_ASYNC);
842
/* A synchronous command can not have a callback set. */
843
BUG_ON(cmd->meta.u.callback != NULL);
845
if (atomic_xchg(&entry, 1)) {
846
IWL_ERROR("Error sending %s: Already sending a host command\n",
847
get_cmd_string(cmd->id));
851
set_bit(STATUS_HCMD_ACTIVE, &priv->status);
853
if (cmd->meta.flags & CMD_WANT_SKB)
854
cmd->meta.source = &cmd->meta;
856
cmd_idx = iwl4965_enqueue_hcmd(priv, cmd);
859
IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n",
860
get_cmd_string(cmd->id), ret);
864
ret = wait_event_interruptible_timeout(priv->wait_command_queue,
865
!test_bit(STATUS_HCMD_ACTIVE, &priv->status),
866
HOST_COMPLETE_TIMEOUT);
868
if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) {
869
IWL_ERROR("Error sending %s: time out after %dms.\n",
870
get_cmd_string(cmd->id),
871
jiffies_to_msecs(HOST_COMPLETE_TIMEOUT));
873
clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
879
if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
880
IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n",
881
get_cmd_string(cmd->id));
885
if (test_bit(STATUS_FW_ERROR, &priv->status)) {
886
IWL_DEBUG_INFO("Command %s failed: FW Error\n",
887
get_cmd_string(cmd->id));
891
if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) {
892
IWL_ERROR("Error: Response NULL in '%s'\n",
893
get_cmd_string(cmd->id));
902
if (cmd->meta.flags & CMD_WANT_SKB) {
903
struct iwl4965_cmd *qcmd;
905
/* Cancel the CMD_WANT_SKB flag for the cmd in the
906
* TX cmd queue. Otherwise in case the cmd comes
907
* in later, it will possibly set an invalid
908
* address (cmd->meta.source). */
909
qcmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx];
910
qcmd->meta.flags &= ~CMD_WANT_SKB;
913
if (cmd->meta.u.skb) {
914
dev_kfree_skb_any(cmd->meta.u.skb);
915
cmd->meta.u.skb = NULL;
918
atomic_set(&entry, 0);
922
int iwl4965_send_cmd(struct iwl4965_priv *priv, struct iwl4965_host_cmd *cmd)
924
if (cmd->meta.flags & CMD_ASYNC)
925
return iwl4965_send_cmd_async(priv, cmd);
927
return iwl4965_send_cmd_sync(priv, cmd);
930
int iwl4965_send_cmd_pdu(struct iwl4965_priv *priv, u8 id, u16 len, const void *data)
932
struct iwl4965_host_cmd cmd = {
938
return iwl4965_send_cmd_sync(priv, &cmd);
941
static int __must_check iwl4965_send_cmd_u32(struct iwl4965_priv *priv, u8 id, u32 val)
943
struct iwl4965_host_cmd cmd = {
949
return iwl4965_send_cmd_sync(priv, &cmd);
952
int iwl4965_send_statistics_request(struct iwl4965_priv *priv)
954
return iwl4965_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0);
958
* iwl4965_rxon_add_station - add station into station table.
960
* there is only one AP station with id= IWL_AP_ID
961
* NOTE: mutex must be held before calling this fnction
963
static int iwl4965_rxon_add_station(struct iwl4965_priv *priv,
964
const u8 *addr, int is_ap)
968
/* Add station to device's station table */
969
sta_id = iwl4965_add_station_flags(priv, addr, is_ap, 0);
971
/* Set up default rate scaling table in device's station table */
972
iwl4965_add_station(priv, addr, is_ap);
978
* iwl4965_set_rxon_channel - Set the phymode and channel values in staging RXON
979
* @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz
980
* @channel: Any channel valid for the requested phymode
982
* In addition to setting the staging RXON, priv->phymode is also set.
984
* NOTE: Does not commit to the hardware; it sets appropriate bit fields
985
* in the staging RXON flag structure based on the phymode
987
static int iwl4965_set_rxon_channel(struct iwl4965_priv *priv, u8 phymode,
990
if (!iwl4965_get_channel_info(priv, phymode, channel)) {
991
IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
996
if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
997
(priv->phymode == phymode))
1000
priv->staging_rxon.channel = cpu_to_le16(channel);
1001
if (phymode == MODE_IEEE80211A)
1002
priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
1004
priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
1006
priv->phymode = phymode;
1008
IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, phymode);
1014
* iwl4965_check_rxon_cmd - validate RXON structure is valid
1016
* NOTE: This is really only useful during development and can eventually
1017
* be #ifdef'd out once the driver is stable and folks aren't actively
1020
static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd *rxon)
1025
if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
1026
error |= le32_to_cpu(rxon->flags &
1027
(RXON_FLG_TGJ_NARROW_BAND_MSK |
1028
RXON_FLG_RADAR_DETECT_MSK));
1030
IWL_WARNING("check 24G fields %d | %d\n",
1033
error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
1034
0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
1036
IWL_WARNING("check 52 fields %d | %d\n",
1038
error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
1040
IWL_WARNING("check 52 CCK %d | %d\n",
1043
error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
1045
IWL_WARNING("check mac addr %d | %d\n", counter++, error);
1047
/* make sure basic rates 6Mbps and 1Mbps are supported */
1048
error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
1049
((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
1051
IWL_WARNING("check basic rate %d | %d\n", counter++, error);
1053
error |= (le16_to_cpu(rxon->assoc_id) > 2007);
1055
IWL_WARNING("check assoc id %d | %d\n", counter++, error);
1057
error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
1058
== (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
1060
IWL_WARNING("check CCK and short slot %d | %d\n",
1063
error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
1064
== (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
1066
IWL_WARNING("check CCK & auto detect %d | %d\n",
1069
error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
1070
RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
1072
IWL_WARNING("check TGG and auto detect %d | %d\n",
1076
IWL_WARNING("Tuning to channel %d\n",
1077
le16_to_cpu(rxon->channel));
1080
IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
1087
* iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
1088
* @priv: staging_rxon is compared to active_rxon
1090
* If the RXON structure is changing enough to require a new tune,
1091
* or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
1092
* a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
1094
static int iwl4965_full_rxon_required(struct iwl4965_priv *priv)
1097
/* These items are only settable from the full RXON command */
1098
if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ||
1099
compare_ether_addr(priv->staging_rxon.bssid_addr,
1100
priv->active_rxon.bssid_addr) ||
1101
compare_ether_addr(priv->staging_rxon.node_addr,
1102
priv->active_rxon.node_addr) ||
1103
compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
1104
priv->active_rxon.wlap_bssid_addr) ||
1105
(priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
1106
(priv->staging_rxon.channel != priv->active_rxon.channel) ||
1107
(priv->staging_rxon.air_propagation !=
1108
priv->active_rxon.air_propagation) ||
1109
(priv->staging_rxon.ofdm_ht_single_stream_basic_rates !=
1110
priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
1111
(priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
1112
priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
1113
(priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) ||
1114
(priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
1117
/* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
1118
* be updated with the RXON_ASSOC command -- however only some
1119
* flag transitions are allowed using RXON_ASSOC */
1121
/* Check if we are not switching bands */
1122
if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
1123
(priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
1126
/* Check if we are switching association toggle */
1127
if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
1128
(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
1134
static int iwl4965_send_rxon_assoc(struct iwl4965_priv *priv)
1137
struct iwl4965_rx_packet *res = NULL;
1138
struct iwl4965_rxon_assoc_cmd rxon_assoc;
1139
struct iwl4965_host_cmd cmd = {
1140
.id = REPLY_RXON_ASSOC,
1141
.len = sizeof(rxon_assoc),
1142
.meta.flags = CMD_WANT_SKB,
1143
.data = &rxon_assoc,
1145
const struct iwl4965_rxon_cmd *rxon1 = &priv->staging_rxon;
1146
const struct iwl4965_rxon_cmd *rxon2 = &priv->active_rxon;
1148
if ((rxon1->flags == rxon2->flags) &&
1149
(rxon1->filter_flags == rxon2->filter_flags) &&
1150
(rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
1151
(rxon1->ofdm_ht_single_stream_basic_rates ==
1152
rxon2->ofdm_ht_single_stream_basic_rates) &&
1153
(rxon1->ofdm_ht_dual_stream_basic_rates ==
1154
rxon2->ofdm_ht_dual_stream_basic_rates) &&
1155
(rxon1->rx_chain == rxon2->rx_chain) &&
1156
(rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
1157
IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
1161
rxon_assoc.flags = priv->staging_rxon.flags;
1162
rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
1163
rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
1164
rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
1165
rxon_assoc.reserved = 0;
1166
rxon_assoc.ofdm_ht_single_stream_basic_rates =
1167
priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
1168
rxon_assoc.ofdm_ht_dual_stream_basic_rates =
1169
priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
1170
rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
1172
rc = iwl4965_send_cmd_sync(priv, &cmd);
1176
res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
1177
if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1178
IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n");
1182
priv->alloc_rxb_skb--;
1183
dev_kfree_skb_any(cmd.meta.u.skb);
1189
* iwl4965_commit_rxon - commit staging_rxon to hardware
1191
* The RXON command in staging_rxon is committed to the hardware and
1192
* the active_rxon structure is updated with the new data. This
1193
* function correctly transitions out of the RXON_ASSOC_MSK state if
1194
* a HW tune is required based on the RXON structure changes.
1196
static int iwl4965_commit_rxon(struct iwl4965_priv *priv)
1198
/* cast away the const for active_rxon in this function */
1199
struct iwl4965_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
1202
if (!iwl4965_is_alive(priv))
1205
/* always get timestamp with Rx frame */
1206
priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
1208
rc = iwl4965_check_rxon_cmd(&priv->staging_rxon);
1210
IWL_ERROR("Invalid RXON configuration. Not committing.\n");
1214
/* If we don't need to send a full RXON, we can use
1215
* iwl4965_rxon_assoc_cmd which is used to reconfigure filter
1216
* and other flags for the current radio configuration. */
1217
if (!iwl4965_full_rxon_required(priv)) {
1218
rc = iwl4965_send_rxon_assoc(priv);
1220
IWL_ERROR("Error setting RXON_ASSOC "
1221
"configuration (%d).\n", rc);
1225
memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
1230
/* station table will be cleared */
1231
priv->assoc_station_added = 0;
1233
#ifdef CONFIG_IWL4965_SENSITIVITY
1234
priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT;
1235
if (!priv->error_recovering)
1236
priv->start_calib = 0;
1238
iwl4965_init_sensitivity(priv, CMD_ASYNC, 1);
1239
#endif /* CONFIG_IWL4965_SENSITIVITY */
1241
/* If we are currently associated and the new config requires
1242
* an RXON_ASSOC and the new config wants the associated mask enabled,
1243
* we must clear the associated from the active configuration
1244
* before we apply the new config */
1245
if (iwl4965_is_associated(priv) &&
1246
(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
1247
IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
1248
active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1250
rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON,
1251
sizeof(struct iwl4965_rxon_cmd),
1252
&priv->active_rxon);
1254
/* If the mask clearing failed then we set
1255
* active_rxon back to what it was previously */
1257
active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
1258
IWL_ERROR("Error clearing ASSOC_MSK on current "
1259
"configuration (%d).\n", rc);
1264
IWL_DEBUG_INFO("Sending RXON\n"
1265
"* with%s RXON_FILTER_ASSOC_MSK\n"
1267
"* bssid = " MAC_FMT "\n",
1268
((priv->staging_rxon.filter_flags &
1269
RXON_FILTER_ASSOC_MSK) ? "" : "out"),
1270
le16_to_cpu(priv->staging_rxon.channel),
1271
MAC_ARG(priv->staging_rxon.bssid_addr));
1273
/* Apply the new configuration */
1274
rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON,
1275
sizeof(struct iwl4965_rxon_cmd), &priv->staging_rxon);
1277
IWL_ERROR("Error setting new configuration (%d).\n", rc);
1281
iwl4965_clear_stations_table(priv);
1283
#ifdef CONFIG_IWL4965_SENSITIVITY
1284
if (!priv->error_recovering)
1285
priv->start_calib = 0;
1287
priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT;
1288
iwl4965_init_sensitivity(priv, CMD_ASYNC, 1);
1289
#endif /* CONFIG_IWL4965_SENSITIVITY */
1291
memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
1293
/* If we issue a new RXON command which required a tune then we must
1294
* send a new TXPOWER command or we won't be able to Tx any frames */
1295
rc = iwl4965_hw_reg_send_txpower(priv);
1297
IWL_ERROR("Error setting Tx power (%d).\n", rc);
1301
/* Add the broadcast address so we can send broadcast frames */
1302
if (iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0) ==
1303
IWL_INVALID_STATION) {
1304
IWL_ERROR("Error adding BROADCAST address for transmit.\n");
1308
/* If we have set the ASSOC_MSK and we are in BSS mode then
1309
* add the IWL_AP_ID to the station rate table */
1310
if (iwl4965_is_associated(priv) &&
1311
(priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
1312
if (iwl4965_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1)
1313
== IWL_INVALID_STATION) {
1314
IWL_ERROR("Error adding AP address for transmit.\n");
1317
priv->assoc_station_added = 1;
1323
static int iwl4965_send_bt_config(struct iwl4965_priv *priv)
1325
struct iwl4965_bt_cmd bt_cmd = {
1333
return iwl4965_send_cmd_pdu(priv, REPLY_BT_CONFIG,
1334
sizeof(struct iwl4965_bt_cmd), &bt_cmd);
1337
static int iwl4965_send_scan_abort(struct iwl4965_priv *priv)
1340
struct iwl4965_rx_packet *res;
1341
struct iwl4965_host_cmd cmd = {
1342
.id = REPLY_SCAN_ABORT_CMD,
1343
.meta.flags = CMD_WANT_SKB,
1346
/* If there isn't a scan actively going on in the hardware
1347
* then we are in between scan bands and not actually
1348
* actively scanning, so don't send the abort command */
1349
if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
1350
clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1354
rc = iwl4965_send_cmd_sync(priv, &cmd);
1356
clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1360
res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
1361
if (res->u.status != CAN_ABORT_STATUS) {
1362
/* The scan abort will return 1 for success or
1363
* 2 for "failure". A failure condition can be
1364
* due to simply not being in an active scan which
1365
* can occur if we send the scan abort before we
1366
* the microcode has notified us that a scan is
1368
IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status);
1369
clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1370
clear_bit(STATUS_SCAN_HW, &priv->status);
1373
dev_kfree_skb_any(cmd.meta.u.skb);
1378
static int iwl4965_card_state_sync_callback(struct iwl4965_priv *priv,
1379
struct iwl4965_cmd *cmd,
1380
struct sk_buff *skb)
1388
* Use: Sets the device's internal card state to enable, disable, or halt
1390
* When in the 'enable' state the card operates as normal.
1391
* When in the 'disable' state, the card enters into a low power mode.
1392
* When in the 'halt' state, the card is shut down and must be fully
1393
* restarted to come back on.
1395
static int iwl4965_send_card_state(struct iwl4965_priv *priv, u32 flags, u8 meta_flag)
1397
struct iwl4965_host_cmd cmd = {
1398
.id = REPLY_CARD_STATE_CMD,
1401
.meta.flags = meta_flag,
1404
if (meta_flag & CMD_ASYNC)
1405
cmd.meta.u.callback = iwl4965_card_state_sync_callback;
1407
return iwl4965_send_cmd(priv, &cmd);
1410
static int iwl4965_add_sta_sync_callback(struct iwl4965_priv *priv,
1411
struct iwl4965_cmd *cmd, struct sk_buff *skb)
1413
struct iwl4965_rx_packet *res = NULL;
1416
IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
1420
res = (struct iwl4965_rx_packet *)skb->data;
1421
if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1422
IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1427
switch (res->u.add_sta.status) {
1428
case ADD_STA_SUCCESS_MSK:
1434
/* We didn't cache the SKB; let the caller free it */
1438
int iwl4965_send_add_station(struct iwl4965_priv *priv,
1439
struct iwl4965_addsta_cmd *sta, u8 flags)
1441
struct iwl4965_rx_packet *res = NULL;
1443
struct iwl4965_host_cmd cmd = {
1444
.id = REPLY_ADD_STA,
1445
.len = sizeof(struct iwl4965_addsta_cmd),
1446
.meta.flags = flags,
1450
if (flags & CMD_ASYNC)
1451
cmd.meta.u.callback = iwl4965_add_sta_sync_callback;
1453
cmd.meta.flags |= CMD_WANT_SKB;
1455
rc = iwl4965_send_cmd(priv, &cmd);
1457
if (rc || (flags & CMD_ASYNC))
1460
res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
1461
if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1462
IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1468
switch (res->u.add_sta.status) {
1469
case ADD_STA_SUCCESS_MSK:
1470
IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
1474
IWL_WARNING("REPLY_ADD_STA failed\n");
1479
priv->alloc_rxb_skb--;
1480
dev_kfree_skb_any(cmd.meta.u.skb);
1485
static int iwl4965_update_sta_key_info(struct iwl4965_priv *priv,
1486
struct ieee80211_key_conf *keyconf,
1489
unsigned long flags;
1490
__le16 key_flags = 0;
1492
switch (keyconf->alg) {
1494
key_flags |= STA_KEY_FLG_CCMP;
1495
key_flags |= cpu_to_le16(
1496
keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
1497
key_flags &= ~STA_KEY_FLG_INVALID;
1504
spin_lock_irqsave(&priv->sta_lock, flags);
1505
priv->stations[sta_id].keyinfo.alg = keyconf->alg;
1506
priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
1507
memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
1510
memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
1512
priv->stations[sta_id].sta.key.key_flags = key_flags;
1513
priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1514
priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1516
spin_unlock_irqrestore(&priv->sta_lock, flags);
1518
IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
1519
iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0);
1523
static int iwl4965_clear_sta_key_info(struct iwl4965_priv *priv, u8 sta_id)
1525
unsigned long flags;
1527
spin_lock_irqsave(&priv->sta_lock, flags);
1528
memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl4965_hw_key));
1529
memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl4965_keyinfo));
1530
priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
1531
priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1532
priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1533
spin_unlock_irqrestore(&priv->sta_lock, flags);
1535
IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
1536
iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0);
1540
static void iwl4965_clear_free_frames(struct iwl4965_priv *priv)
1542
struct list_head *element;
1544
IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
1545
priv->frames_count);
1547
while (!list_empty(&priv->free_frames)) {
1548
element = priv->free_frames.next;
1550
kfree(list_entry(element, struct iwl4965_frame, list));
1551
priv->frames_count--;
1554
if (priv->frames_count) {
1555
IWL_WARNING("%d frames still in use. Did we lose one?\n",
1556
priv->frames_count);
1557
priv->frames_count = 0;
1561
static struct iwl4965_frame *iwl4965_get_free_frame(struct iwl4965_priv *priv)
1563
struct iwl4965_frame *frame;
1564
struct list_head *element;
1565
if (list_empty(&priv->free_frames)) {
1566
frame = kzalloc(sizeof(*frame), GFP_KERNEL);
1568
IWL_ERROR("Could not allocate frame!\n");
1572
priv->frames_count++;
1576
element = priv->free_frames.next;
1578
return list_entry(element, struct iwl4965_frame, list);
1581
static void iwl4965_free_frame(struct iwl4965_priv *priv, struct iwl4965_frame *frame)
1583
memset(frame, 0, sizeof(*frame));
1584
list_add(&frame->list, &priv->free_frames);
1587
unsigned int iwl4965_fill_beacon_frame(struct iwl4965_priv *priv,
1588
struct ieee80211_hdr *hdr,
1589
const u8 *dest, int left)
1592
if (!iwl4965_is_associated(priv) || !priv->ibss_beacon ||
1593
((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) &&
1594
(priv->iw_mode != IEEE80211_IF_TYPE_AP)))
1597
if (priv->ibss_beacon->len > left)
1600
memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
1602
return priv->ibss_beacon->len;
1605
int iwl4965_rate_index_from_plcp(int plcp)
1609
/* 4965 HT rate format */
1610
if (plcp & RATE_MCS_HT_MSK) {
1613
if (i >= IWL_RATE_MIMO_6M_PLCP)
1614
i = i - IWL_RATE_MIMO_6M_PLCP;
1616
i += IWL_FIRST_OFDM_RATE;
1617
/* skip 9M not supported in ht*/
1618
if (i >= IWL_RATE_9M_INDEX)
1620
if ((i >= IWL_FIRST_OFDM_RATE) &&
1621
(i <= IWL_LAST_OFDM_RATE))
1624
/* 4965 legacy rate format, search for match in table */
1626
for (i = 0; i < ARRAY_SIZE(iwl4965_rates); i++)
1627
if (iwl4965_rates[i].plcp == (plcp &0xFF))
1633
static u8 iwl4965_rate_get_lowest_plcp(int rate_mask)
1637
for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
1638
i = iwl4965_rates[i].next_ieee) {
1639
if (rate_mask & (1 << i))
1640
return iwl4965_rates[i].plcp;
1643
return IWL_RATE_INVALID;
1646
static int iwl4965_send_beacon_cmd(struct iwl4965_priv *priv)
1648
struct iwl4965_frame *frame;
1649
unsigned int frame_size;
1653
frame = iwl4965_get_free_frame(priv);
1656
IWL_ERROR("Could not obtain free frame buffer for beacon "
1661
if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) {
1662
rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic &
1664
if (rate == IWL_INVALID_RATE)
1665
rate = IWL_RATE_6M_PLCP;
1667
rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic & 0xF);
1668
if (rate == IWL_INVALID_RATE)
1669
rate = IWL_RATE_1M_PLCP;
1672
frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate);
1674
rc = iwl4965_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
1677
iwl4965_free_frame(priv, frame);
1682
/******************************************************************************
1684
* EEPROM related functions
1686
******************************************************************************/
1688
static void get_eeprom_mac(struct iwl4965_priv *priv, u8 *mac)
1690
memcpy(mac, priv->eeprom.mac_address, 6);
1694
* iwl4965_eeprom_init - read EEPROM contents
1696
* Load the EEPROM contents from adapter into priv->eeprom
1698
* NOTE: This routine uses the non-debug IO access functions.
1700
int iwl4965_eeprom_init(struct iwl4965_priv *priv)
1702
u16 *e = (u16 *)&priv->eeprom;
1703
u32 gp = iwl4965_read32(priv, CSR_EEPROM_GP);
1705
int sz = sizeof(priv->eeprom);
1710
/* The EEPROM structure has several padding buffers within it
1711
* and when adding new EEPROM maps is subject to programmer errors
1712
* which may be very difficult to identify without explicitly
1713
* checking the resulting size of the eeprom map. */
1714
BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE);
1716
if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) {
1717
IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp);
1721
/* Make sure driver (instead of uCode) is allowed to read EEPROM */
1722
rc = iwl4965_eeprom_acquire_semaphore(priv);
1724
IWL_ERROR("Failed to acquire EEPROM semaphore.\n");
1728
/* eeprom is an array of 16bit values */
1729
for (addr = 0; addr < sz; addr += sizeof(u16)) {
1730
_iwl4965_write32(priv, CSR_EEPROM_REG, addr << 1);
1731
_iwl4965_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD);
1733
for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT;
1734
i += IWL_EEPROM_ACCESS_DELAY) {
1735
r = _iwl4965_read_direct32(priv, CSR_EEPROM_REG);
1736
if (r & CSR_EEPROM_REG_READ_VALID_MSK)
1738
udelay(IWL_EEPROM_ACCESS_DELAY);
1741
if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) {
1742
IWL_ERROR("Time out reading EEPROM[%d]", addr);
1746
e[addr / 2] = le16_to_cpu(r >> 16);
1751
iwl4965_eeprom_release_semaphore(priv);
1755
/******************************************************************************
1757
* Misc. internal state and helper functions
1759
******************************************************************************/
1760
#ifdef CONFIG_IWL4965_DEBUG
1763
* iwl4965_report_frame - dump frame to syslog during debug sessions
1765
* You may hack this function to show different aspects of received frames,
1766
* including selective frame dumps.
1767
* group100 parameter selects whether to show 1 out of 100 good frames.
1769
* TODO: This was originally written for 3945, need to audit for
1770
* proper operation with 4965.
1772
void iwl4965_report_frame(struct iwl4965_priv *priv,
1773
struct iwl4965_rx_packet *pkt,
1774
struct ieee80211_hdr *header, int group100)
1777
u32 print_summary = 0;
1778
u32 print_dump = 0; /* set to 1 to dump all frames' contents */
1795
struct iwl4965_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt);
1796
struct iwl4965_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
1797
struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt);
1798
u8 *data = IWL_RX_DATA(pkt);
1801
fc = le16_to_cpu(header->frame_control);
1802
seq_ctl = le16_to_cpu(header->seq_ctrl);
1805
channel = le16_to_cpu(rx_hdr->channel);
1806
phy_flags = le16_to_cpu(rx_hdr->phy_flags);
1807
rate_sym = rx_hdr->rate;
1808
length = le16_to_cpu(rx_hdr->len);
1810
/* end-of-frame status and timestamp */
1811
status = le32_to_cpu(rx_end->status);
1812
bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp);
1813
tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff;
1814
tsf = le64_to_cpu(rx_end->timestamp);
1816
/* signal statistics */
1817
rssi = rx_stats->rssi;
1818
agc = rx_stats->agc;
1819
sig_avg = le16_to_cpu(rx_stats->sig_avg);
1820
noise_diff = le16_to_cpu(rx_stats->noise_diff);
1822
to_us = !compare_ether_addr(header->addr1, priv->mac_addr);
1824
/* if data frame is to us and all is good,
1825
* (optionally) print summary for only 1 out of every 100 */
1826
if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) ==
1827
(IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
1830
print_summary = 1; /* print each frame */
1831
else if (priv->framecnt_to_us < 100) {
1832
priv->framecnt_to_us++;
1835
priv->framecnt_to_us = 0;
1840
/* print summary for all other frames */
1844
if (print_summary) {
1849
title = "100Frames";
1850
else if (fc & IEEE80211_FCTL_RETRY)
1852
else if (ieee80211_is_assoc_response(fc))
1854
else if (ieee80211_is_reassoc_response(fc))
1856
else if (ieee80211_is_probe_response(fc)) {
1858
print_dump = 1; /* dump frame contents */
1859
} else if (ieee80211_is_beacon(fc)) {
1861
print_dump = 1; /* dump frame contents */
1862
} else if (ieee80211_is_atim(fc))
1864
else if (ieee80211_is_auth(fc))
1866
else if (ieee80211_is_deauth(fc))
1868
else if (ieee80211_is_disassoc(fc))
1873
rate = iwl4965_rate_index_from_plcp(rate_sym);
1877
rate = iwl4965_rates[rate].ieee / 2;
1879
/* print frame summary.
1880
* MAC addresses show just the last byte (for brevity),
1881
* but you can hack it to show more, if you'd like to. */
1883
IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, "
1884
"len=%u, rssi=%d, chnl=%d, rate=%u, \n",
1885
title, fc, header->addr1[5],
1886
length, rssi, channel, rate);
1888
/* src/dst addresses assume managed mode */
1889
IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, "
1890
"src=0x%02x, rssi=%u, tim=%lu usec, "
1891
"phy=0x%02x, chnl=%d\n",
1892
title, fc, header->addr1[5],
1893
header->addr3[5], rssi,
1894
tsf_low - priv->scan_start_tsf,
1895
phy_flags, channel);
1899
iwl4965_print_hex_dump(IWL_DL_RX, data, length);
1903
static void iwl4965_unset_hw_setting(struct iwl4965_priv *priv)
1905
if (priv->hw_setting.shared_virt)
1906
pci_free_consistent(priv->pci_dev,
1907
sizeof(struct iwl4965_shared),
1908
priv->hw_setting.shared_virt,
1909
priv->hw_setting.shared_phys);
1913
* iwl4965_supported_rate_to_ie - fill in the supported rate in IE field
1915
* return : set the bit for each supported rate insert in ie
1917
static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate,
1918
u16 basic_rate, int *left)
1920
u16 ret_rates = 0, bit;
1925
for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) {
1926
if (bit & supported_rate) {
1928
rates[*cnt] = iwl4965_rates[i].ieee |
1929
((bit & basic_rate) ? 0x80 : 0x00);
1933
(*cnt >= IWL_SUPPORTED_RATES_IE_LEN))
1941
#ifdef CONFIG_IWL4965_HT
1942
void static iwl4965_set_ht_capab(struct ieee80211_hw *hw,
1943
struct ieee80211_ht_capability *ht_cap,
1948
* iwl4965_fill_probe_req - fill in all required fields and IE for probe request
1950
static u16 iwl4965_fill_probe_req(struct iwl4965_priv *priv,
1951
struct ieee80211_mgmt *frame,
1952
int left, int is_direct)
1956
u16 active_rates, ret_rates, cck_rates, active_rate_basic;
1958
/* Make sure there is enough space for the probe request,
1959
* two mandatory IEs and the data */
1965
frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
1966
memcpy(frame->da, iwl4965_broadcast_addr, ETH_ALEN);
1967
memcpy(frame->sa, priv->mac_addr, ETH_ALEN);
1968
memcpy(frame->bssid, iwl4965_broadcast_addr, ETH_ALEN);
1969
frame->seq_ctrl = 0;
1971
/* fill in our indirect SSID IE */
1978
pos = &(frame->u.probe_req.variable[0]);
1979
*pos++ = WLAN_EID_SSID;
1982
/* fill in our direct SSID IE... */
1985
left -= 2 + priv->essid_len;
1988
/* ... fill it in... */
1989
*pos++ = WLAN_EID_SSID;
1990
*pos++ = priv->essid_len;
1991
memcpy(pos, priv->essid, priv->essid_len);
1992
pos += priv->essid_len;
1993
len += 2 + priv->essid_len;
1996
/* fill in supported rate */
2002
/* ... fill it in... */
2003
*pos++ = WLAN_EID_SUPP_RATES;
2006
/* exclude 60M rate */
2007
active_rates = priv->rates_mask;
2008
active_rates &= ~IWL_RATE_60M_MASK;
2010
active_rate_basic = active_rates & IWL_BASIC_RATES_MASK;
2012
cck_rates = IWL_CCK_RATES_MASK & active_rates;
2013
ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates,
2014
active_rate_basic, &left);
2015
active_rates &= ~ret_rates;
2017
ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates,
2018
active_rate_basic, &left);
2019
active_rates &= ~ret_rates;
2023
if (active_rates == 0)
2026
/* fill in supported extended rate */
2031
/* ... fill it in... */
2032
*pos++ = WLAN_EID_EXT_SUPP_RATES;
2034
iwl4965_supported_rate_to_ie(pos, active_rates,
2035
active_rate_basic, &left);
2039
#ifdef CONFIG_IWL4965_HT
2040
if (is_direct && priv->is_ht_enabled) {
2041
u8 use_wide_chan = 1;
2043
if (priv->channel_width != IWL_CHANNEL_WIDTH_40MHZ)
2046
*pos++ = WLAN_EID_HT_CAPABILITY;
2047
*pos++ = sizeof(struct ieee80211_ht_capability);
2048
iwl4965_set_ht_capab(NULL, (struct ieee80211_ht_capability *)pos,
2050
len += 2 + sizeof(struct ieee80211_ht_capability);
2052
#endif /*CONFIG_IWL4965_HT */
2061
#ifdef CONFIG_IWL4965_QOS
2062
static int iwl4965_send_qos_params_command(struct iwl4965_priv *priv,
2063
struct iwl4965_qosparam_cmd *qos)
2066
return iwl4965_send_cmd_pdu(priv, REPLY_QOS_PARAM,
2067
sizeof(struct iwl4965_qosparam_cmd), qos);
2070
static void iwl4965_reset_qos(struct iwl4965_priv *priv)
2076
unsigned long flags;
2079
spin_lock_irqsave(&priv->lock, flags);
2080
priv->qos_data.qos_active = 0;
2082
if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) {
2083
if (priv->qos_data.qos_enable)
2084
priv->qos_data.qos_active = 1;
2085
if (!(priv->active_rate & 0xfff0)) {
2089
} else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
2090
if (priv->qos_data.qos_enable)
2091
priv->qos_data.qos_active = 1;
2092
} else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) {
2097
if (priv->qos_data.qos_active)
2100
priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min);
2101
priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max);
2102
priv->qos_data.def_qos_parm.ac[0].aifsn = aifs;
2103
priv->qos_data.def_qos_parm.ac[0].edca_txop = 0;
2104
priv->qos_data.def_qos_parm.ac[0].reserved1 = 0;
2106
if (priv->qos_data.qos_active) {
2108
priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min);
2109
priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max);
2110
priv->qos_data.def_qos_parm.ac[i].aifsn = 7;
2111
priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
2112
priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
2115
priv->qos_data.def_qos_parm.ac[i].cw_min =
2116
cpu_to_le16((cw_min + 1) / 2 - 1);
2117
priv->qos_data.def_qos_parm.ac[i].cw_max =
2118
cpu_to_le16(cw_max);
2119
priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
2121
priv->qos_data.def_qos_parm.ac[i].edca_txop =
2124
priv->qos_data.def_qos_parm.ac[i].edca_txop =
2126
priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
2129
priv->qos_data.def_qos_parm.ac[i].cw_min =
2130
cpu_to_le16((cw_min + 1) / 4 - 1);
2131
priv->qos_data.def_qos_parm.ac[i].cw_max =
2132
cpu_to_le16((cw_max + 1) / 2 - 1);
2133
priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
2134
priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
2136
priv->qos_data.def_qos_parm.ac[i].edca_txop =
2139
priv->qos_data.def_qos_parm.ac[i].edca_txop =
2142
for (i = 1; i < 4; i++) {
2143
priv->qos_data.def_qos_parm.ac[i].cw_min =
2144
cpu_to_le16(cw_min);
2145
priv->qos_data.def_qos_parm.ac[i].cw_max =
2146
cpu_to_le16(cw_max);
2147
priv->qos_data.def_qos_parm.ac[i].aifsn = aifs;
2148
priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
2149
priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
2152
IWL_DEBUG_QOS("set QoS to default \n");
2154
spin_unlock_irqrestore(&priv->lock, flags);
2157
static void iwl4965_activate_qos(struct iwl4965_priv *priv, u8 force)
2159
unsigned long flags;
2161
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2164
if (!priv->qos_data.qos_enable)
2167
spin_lock_irqsave(&priv->lock, flags);
2168
priv->qos_data.def_qos_parm.qos_flags = 0;
2170
if (priv->qos_data.qos_cap.q_AP.queue_request &&
2171
!priv->qos_data.qos_cap.q_AP.txop_request)
2172
priv->qos_data.def_qos_parm.qos_flags |=
2173
QOS_PARAM_FLG_TXOP_TYPE_MSK;
2174
if (priv->qos_data.qos_active)
2175
priv->qos_data.def_qos_parm.qos_flags |=
2176
QOS_PARAM_FLG_UPDATE_EDCA_MSK;
2178
#ifdef CONFIG_IWL4965_HT
2179
if (priv->is_ht_enabled && priv->current_assoc_ht.is_ht)
2180
priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
2181
#endif /* CONFIG_IWL4965_HT */
2183
spin_unlock_irqrestore(&priv->lock, flags);
2185
if (force || iwl4965_is_associated(priv)) {
2186
IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
2187
priv->qos_data.qos_active,
2188
priv->qos_data.def_qos_parm.qos_flags);
2190
iwl4965_send_qos_params_command(priv,
2191
&(priv->qos_data.def_qos_parm));
2195
#endif /* CONFIG_IWL4965_QOS */
2197
* Power management (not Tx power!) functions
2199
#define MSEC_TO_USEC 1024
2201
#define NOSLP __constant_cpu_to_le16(0), 0, 0
2202
#define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0
2203
#define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
2204
#define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
2205
__constant_cpu_to_le32(X1), \
2206
__constant_cpu_to_le32(X2), \
2207
__constant_cpu_to_le32(X3), \
2208
__constant_cpu_to_le32(X4)}
2211
/* default power management (not Tx power) table values */
2213
static struct iwl4965_power_vec_entry range_0[IWL_POWER_AC] = {
2214
{{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
2215
{{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
2216
{{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
2217
{{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
2218
{{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
2219
{{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
2223
static struct iwl4965_power_vec_entry range_1[IWL_POWER_AC] = {
2224
{{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
2225
{{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
2226
SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
2227
{{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
2228
SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
2229
{{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
2230
SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
2231
{{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
2232
{{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
2233
SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
2236
int iwl4965_power_init_handle(struct iwl4965_priv *priv)
2239
struct iwl4965_power_mgr *pow_data;
2240
int size = sizeof(struct iwl4965_power_vec_entry) * IWL_POWER_AC;
2243
IWL_DEBUG_POWER("Initialize power \n");
2245
pow_data = &(priv->power_data);
2247
memset(pow_data, 0, sizeof(*pow_data));
2249
pow_data->active_index = IWL_POWER_RANGE_0;
2250
pow_data->dtim_val = 0xffff;
2252
memcpy(&pow_data->pwr_range_0[0], &range_0[0], size);
2253
memcpy(&pow_data->pwr_range_1[0], &range_1[0], size);
2255
rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm);
2259
struct iwl4965_powertable_cmd *cmd;
2261
IWL_DEBUG_POWER("adjust power command flags\n");
2263
for (i = 0; i < IWL_POWER_AC; i++) {
2264
cmd = &pow_data->pwr_range_0[i].cmd;
2267
cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
2269
cmd->flags |= IWL_POWER_PCI_PM_MSK;
2275
static int iwl4965_update_power_cmd(struct iwl4965_priv *priv,
2276
struct iwl4965_powertable_cmd *cmd, u32 mode)
2281
struct iwl4965_power_vec_entry *range;
2283
struct iwl4965_power_mgr *pow_data;
2285
if (mode > IWL_POWER_INDEX_5) {
2286
IWL_DEBUG_POWER("Error invalid power mode \n");
2289
pow_data = &(priv->power_data);
2291
if (pow_data->active_index == IWL_POWER_RANGE_0)
2292
range = &pow_data->pwr_range_0[0];
2294
range = &pow_data->pwr_range_1[1];
2296
memcpy(cmd, &range[mode].cmd, sizeof(struct iwl4965_powertable_cmd));
2298
#ifdef IWL_MAC80211_DISABLE
2299
if (priv->assoc_network != NULL) {
2300
unsigned long flags;
2302
period = priv->assoc_network->tim.tim_period;
2304
#endif /*IWL_MAC80211_DISABLE */
2305
skip = range[mode].no_dtim;
2314
cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
2316
__le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
2317
max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
2318
cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
2321
for (i = 0; i < IWL_POWER_VEC_SIZE; i++) {
2322
if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
2323
cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
2326
IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags);
2327
IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
2328
IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
2329
IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
2330
le32_to_cpu(cmd->sleep_interval[0]),
2331
le32_to_cpu(cmd->sleep_interval[1]),
2332
le32_to_cpu(cmd->sleep_interval[2]),
2333
le32_to_cpu(cmd->sleep_interval[3]),
2334
le32_to_cpu(cmd->sleep_interval[4]));
2339
static int iwl4965_send_power_mode(struct iwl4965_priv *priv, u32 mode)
2341
u32 final_mode = mode;
2343
struct iwl4965_powertable_cmd cmd;
2345
/* If on battery, set to 3,
2346
* if plugged into AC power, set to CAM ("continuously aware mode"),
2347
* else user level */
2349
case IWL_POWER_BATTERY:
2350
final_mode = IWL_POWER_INDEX_3;
2353
final_mode = IWL_POWER_MODE_CAM;
2360
cmd.keep_alive_beacons = 0;
2362
iwl4965_update_power_cmd(priv, &cmd, final_mode);
2364
rc = iwl4965_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd);
2366
if (final_mode == IWL_POWER_MODE_CAM)
2367
clear_bit(STATUS_POWER_PMI, &priv->status);
2369
set_bit(STATUS_POWER_PMI, &priv->status);
2374
int iwl4965_is_network_packet(struct iwl4965_priv *priv, struct ieee80211_hdr *header)
2376
/* Filter incoming packets to determine if they are targeted toward
2377
* this network, discarding packets coming from ourselves */
2378
switch (priv->iw_mode) {
2379
case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */
2380
/* packets from our adapter are dropped (echo) */
2381
if (!compare_ether_addr(header->addr2, priv->mac_addr))
2383
/* {broad,multi}cast packets to our IBSS go through */
2384
if (is_multicast_ether_addr(header->addr1))
2385
return !compare_ether_addr(header->addr3, priv->bssid);
2386
/* packets to our adapter go through */
2387
return !compare_ether_addr(header->addr1, priv->mac_addr);
2388
case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */
2389
/* packets from our adapter are dropped (echo) */
2390
if (!compare_ether_addr(header->addr3, priv->mac_addr))
2392
/* {broad,multi}cast packets to our BSS go through */
2393
if (is_multicast_ether_addr(header->addr1))
2394
return !compare_ether_addr(header->addr2, priv->bssid);
2395
/* packets to our adapter go through */
2396
return !compare_ether_addr(header->addr1, priv->mac_addr);
2402
#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
2404
static const char *iwl4965_get_tx_fail_reason(u32 status)
2406
switch (status & TX_STATUS_MSK) {
2407
case TX_STATUS_SUCCESS:
2409
TX_STATUS_ENTRY(SHORT_LIMIT);
2410
TX_STATUS_ENTRY(LONG_LIMIT);
2411
TX_STATUS_ENTRY(FIFO_UNDERRUN);
2412
TX_STATUS_ENTRY(MGMNT_ABORT);
2413
TX_STATUS_ENTRY(NEXT_FRAG);
2414
TX_STATUS_ENTRY(LIFE_EXPIRE);
2415
TX_STATUS_ENTRY(DEST_PS);
2416
TX_STATUS_ENTRY(ABORTED);
2417
TX_STATUS_ENTRY(BT_RETRY);
2418
TX_STATUS_ENTRY(STA_INVALID);
2419
TX_STATUS_ENTRY(FRAG_DROPPED);
2420
TX_STATUS_ENTRY(TID_DISABLE);
2421
TX_STATUS_ENTRY(FRAME_FLUSHED);
2422
TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
2423
TX_STATUS_ENTRY(TX_LOCKED);
2424
TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
2431
* iwl4965_scan_cancel - Cancel any currently executing HW scan
2433
* NOTE: priv->mutex is not required before calling this function
2435
static int iwl4965_scan_cancel(struct iwl4965_priv *priv)
2437
if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
2438
clear_bit(STATUS_SCANNING, &priv->status);
2442
if (test_bit(STATUS_SCANNING, &priv->status)) {
2443
if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
2444
IWL_DEBUG_SCAN("Queuing scan abort.\n");
2445
set_bit(STATUS_SCAN_ABORTING, &priv->status);
2446
queue_work(priv->workqueue, &priv->abort_scan);
2449
IWL_DEBUG_SCAN("Scan abort already in progress.\n");
2451
return test_bit(STATUS_SCANNING, &priv->status);
2458
* iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan
2459
* @ms: amount of time to wait (in milliseconds) for scan to abort
2461
* NOTE: priv->mutex must be held before calling this function
2463
static int iwl4965_scan_cancel_timeout(struct iwl4965_priv *priv, unsigned long ms)
2465
unsigned long now = jiffies;
2468
ret = iwl4965_scan_cancel(priv);
2470
mutex_unlock(&priv->mutex);
2471
while (!time_after(jiffies, now + msecs_to_jiffies(ms)) &&
2472
test_bit(STATUS_SCANNING, &priv->status))
2474
mutex_lock(&priv->mutex);
2476
return test_bit(STATUS_SCANNING, &priv->status);
2482
static void iwl4965_sequence_reset(struct iwl4965_priv *priv)
2484
/* Reset ieee stats */
2486
/* We don't reset the net_device_stats (ieee->stats) on
2489
priv->last_seq_num = -1;
2490
priv->last_frag_num = -1;
2491
priv->last_packet_time = 0;
2493
iwl4965_scan_cancel(priv);
2496
#define MAX_UCODE_BEACON_INTERVAL 4096
2497
#define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
2499
static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val)
2502
u16 beacon_factor = 0;
2505
(beacon_val + MAX_UCODE_BEACON_INTERVAL)
2506
/ MAX_UCODE_BEACON_INTERVAL;
2507
new_val = beacon_val / beacon_factor;
2509
return cpu_to_le16(new_val);
2512
static void iwl4965_setup_rxon_timing(struct iwl4965_priv *priv)
2514
u64 interval_tm_unit;
2516
unsigned long flags;
2517
struct ieee80211_conf *conf = NULL;
2520
conf = ieee80211_get_hw_conf(priv->hw);
2522
spin_lock_irqsave(&priv->lock, flags);
2523
priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp1);
2524
priv->rxon_timing.timestamp.dw[0] = cpu_to_le32(priv->timestamp0);
2526
priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
2528
tsf = priv->timestamp1;
2529
tsf = ((tsf << 32) | priv->timestamp0);
2531
beacon_int = priv->beacon_int;
2532
spin_unlock_irqrestore(&priv->lock, flags);
2534
if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
2535
if (beacon_int == 0) {
2536
priv->rxon_timing.beacon_interval = cpu_to_le16(100);
2537
priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
2539
priv->rxon_timing.beacon_interval =
2540
cpu_to_le16(beacon_int);
2541
priv->rxon_timing.beacon_interval =
2542
iwl4965_adjust_beacon_interval(
2543
le16_to_cpu(priv->rxon_timing.beacon_interval));
2546
priv->rxon_timing.atim_window = 0;
2548
priv->rxon_timing.beacon_interval =
2549
iwl4965_adjust_beacon_interval(conf->beacon_int);
2550
/* TODO: we need to get atim_window from upper stack
2551
* for now we set to 0 */
2552
priv->rxon_timing.atim_window = 0;
2556
(le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
2557
result = do_div(tsf, interval_tm_unit);
2558
priv->rxon_timing.beacon_init_val =
2559
cpu_to_le32((u32) ((u64) interval_tm_unit - result));
2562
("beacon interval %d beacon timer %d beacon tim %d\n",
2563
le16_to_cpu(priv->rxon_timing.beacon_interval),
2564
le32_to_cpu(priv->rxon_timing.beacon_init_val),
2565
le16_to_cpu(priv->rxon_timing.atim_window));
2568
static int iwl4965_scan_initiate(struct iwl4965_priv *priv)
2570
if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
2571
IWL_ERROR("APs don't scan.\n");
2575
if (!iwl4965_is_ready_rf(priv)) {
2576
IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
2580
if (test_bit(STATUS_SCANNING, &priv->status)) {
2581
IWL_DEBUG_SCAN("Scan already in progress.\n");
2585
if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
2586
IWL_DEBUG_SCAN("Scan request while abort pending. "
2591
IWL_DEBUG_INFO("Starting scan...\n");
2592
priv->scan_bands = 2;
2593
set_bit(STATUS_SCANNING, &priv->status);
2594
priv->scan_start = jiffies;
2595
priv->scan_pass_start = priv->scan_start;
2597
queue_work(priv->workqueue, &priv->request_scan);
2602
static int iwl4965_set_rxon_hwcrypto(struct iwl4965_priv *priv, int hw_decrypt)
2604
struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon;
2607
rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
2609
rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
2614
static void iwl4965_set_flags_for_phymode(struct iwl4965_priv *priv, u8 phymode)
2616
if (phymode == MODE_IEEE80211A) {
2617
priv->staging_rxon.flags &=
2618
~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
2619
| RXON_FLG_CCK_MSK);
2620
priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2622
/* Copied from iwl4965_bg_post_associate() */
2623
if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2624
priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2626
priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2628
if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
2629
priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2631
priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
2632
priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
2633
priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
2638
* initialize rxon structure with default values from eeprom
2640
static void iwl4965_connection_init_rx_config(struct iwl4965_priv *priv)
2642
const struct iwl4965_channel_info *ch_info;
2644
memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
2646
switch (priv->iw_mode) {
2647
case IEEE80211_IF_TYPE_AP:
2648
priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
2651
case IEEE80211_IF_TYPE_STA:
2652
priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
2653
priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
2656
case IEEE80211_IF_TYPE_IBSS:
2657
priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
2658
priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
2659
priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
2660
RXON_FILTER_ACCEPT_GRP_MSK;
2663
case IEEE80211_IF_TYPE_MNTR:
2664
priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
2665
priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
2666
RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
2671
/* TODO: Figure out when short_preamble would be set and cache from
2673
if (!hw_to_local(priv->hw)->short_preamble)
2674
priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2676
priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2679
ch_info = iwl4965_get_channel_info(priv, priv->phymode,
2680
le16_to_cpu(priv->staging_rxon.channel));
2683
ch_info = &priv->channel_info[0];
2686
* in some case A channels are all non IBSS
2687
* in this case force B/G channel
2689
if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
2690
!(is_channel_ibss(ch_info)))
2691
ch_info = &priv->channel_info[0];
2693
priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
2694
if (is_channel_a_band(ch_info))
2695
priv->phymode = MODE_IEEE80211A;
2697
priv->phymode = MODE_IEEE80211G;
2699
iwl4965_set_flags_for_phymode(priv, priv->phymode);
2701
priv->staging_rxon.ofdm_basic_rates =
2702
(IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
2703
priv->staging_rxon.cck_basic_rates =
2704
(IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
2706
priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
2707
RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
2708
memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2709
memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
2710
priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
2711
priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
2712
iwl4965_set_rxon_chain(priv);
2715
static int iwl4965_set_mode(struct iwl4965_priv *priv, int mode)
2717
if (mode == IEEE80211_IF_TYPE_IBSS) {
2718
const struct iwl4965_channel_info *ch_info;
2720
ch_info = iwl4965_get_channel_info(priv,
2722
le16_to_cpu(priv->staging_rxon.channel));
2724
if (!ch_info || !is_channel_ibss(ch_info)) {
2725
IWL_ERROR("channel %d not IBSS channel\n",
2726
le16_to_cpu(priv->staging_rxon.channel));
2731
priv->iw_mode = mode;
2733
iwl4965_connection_init_rx_config(priv);
2734
memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2736
iwl4965_clear_stations_table(priv);
2738
/* dont commit rxon if rf-kill is on*/
2739
if (!iwl4965_is_ready_rf(priv))
2742
cancel_delayed_work(&priv->scan_check);
2743
if (iwl4965_scan_cancel_timeout(priv, 100)) {
2744
IWL_WARNING("Aborted scan still in progress after 100ms\n");
2745
IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2749
iwl4965_commit_rxon(priv);
2754
static void iwl4965_build_tx_cmd_hwcrypto(struct iwl4965_priv *priv,
2755
struct ieee80211_tx_control *ctl,
2756
struct iwl4965_cmd *cmd,
2757
struct sk_buff *skb_frag,
2760
struct iwl4965_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo;
2762
switch (keyinfo->alg) {
2764
cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM;
2765
memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen);
2766
IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
2771
cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP;
2774
memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8,
2777
memset(cmd->cmd.tx.tkip_mic.byte, 0, 8);
2782
cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP |
2783
(ctl->key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
2785
if (keyinfo->keylen == 13)
2786
cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128;
2788
memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen);
2790
IWL_DEBUG_TX("Configuring packet for WEP encryption "
2791
"with key %d\n", ctl->key_idx);
2795
IWL_DEBUG_TX("Tx packet in the clear (encrypt requested).\n");
2799
printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg);
2805
* handle build REPLY_TX command notification.
2807
static void iwl4965_build_tx_cmd_basic(struct iwl4965_priv *priv,
2808
struct iwl4965_cmd *cmd,
2809
struct ieee80211_tx_control *ctrl,
2810
struct ieee80211_hdr *hdr,
2811
int is_unicast, u8 std_id)
2814
u16 fc = le16_to_cpu(hdr->frame_control);
2815
__le32 tx_flags = cmd->cmd.tx.tx_flags;
2817
cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
2818
if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) {
2819
tx_flags |= TX_CMD_FLG_ACK_MSK;
2820
if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
2821
tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2822
if (ieee80211_is_probe_response(fc) &&
2823
!(le16_to_cpu(hdr->seq_ctrl) & 0xf))
2824
tx_flags |= TX_CMD_FLG_TSF_MSK;
2826
tx_flags &= (~TX_CMD_FLG_ACK_MSK);
2827
tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2830
if (ieee80211_is_back_request(fc))
2831
tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK;
2834
cmd->cmd.tx.sta_id = std_id;
2835
if (ieee80211_get_morefrag(hdr))
2836
tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
2838
qc = ieee80211_get_qos_ctrl(hdr);
2840
cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf);
2841
tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
2843
tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2845
if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) {
2846
tx_flags |= TX_CMD_FLG_RTS_MSK;
2847
tx_flags &= ~TX_CMD_FLG_CTS_MSK;
2848
} else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) {
2849
tx_flags &= ~TX_CMD_FLG_RTS_MSK;
2850
tx_flags |= TX_CMD_FLG_CTS_MSK;
2853
if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
2854
tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
2856
tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
2857
if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
2858
if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ ||
2859
(fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
2860
cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3);
2862
cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2);
2864
cmd->cmd.tx.timeout.pm_frame_timeout = 0;
2865
#ifdef CONFIG_IWL4965_LEDS
2866
priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
2870
cmd->cmd.tx.driver_txop = 0;
2871
cmd->cmd.tx.tx_flags = tx_flags;
2872
cmd->cmd.tx.next_frame_len = 0;
2876
* iwl4965_get_sta_id - Find station's index within station table
2878
* If new IBSS station, create new entry in station table
2880
static int iwl4965_get_sta_id(struct iwl4965_priv *priv,
2881
struct ieee80211_hdr *hdr)
2884
u16 fc = le16_to_cpu(hdr->frame_control);
2886
/* If this frame is broadcast or management, use broadcast station id */
2887
if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
2888
is_multicast_ether_addr(hdr->addr1))
2889
return priv->hw_setting.bcast_sta_id;
2891
switch (priv->iw_mode) {
2893
/* If we are a client station in a BSS network, use the special
2894
* AP station entry (that's the only station we communicate with) */
2895
case IEEE80211_IF_TYPE_STA:
2898
/* If we are an AP, then find the station, or use BCAST */
2899
case IEEE80211_IF_TYPE_AP:
2900
sta_id = iwl4965_hw_find_station(priv, hdr->addr1);
2901
if (sta_id != IWL_INVALID_STATION)
2903
return priv->hw_setting.bcast_sta_id;
2905
/* If this frame is going out to an IBSS network, find the station,
2906
* or create a new station table entry */
2907
case IEEE80211_IF_TYPE_IBSS:
2908
sta_id = iwl4965_hw_find_station(priv, hdr->addr1);
2909
if (sta_id != IWL_INVALID_STATION)
2912
/* Create new station table entry */
2913
sta_id = iwl4965_add_station_flags(priv, hdr->addr1, 0, CMD_ASYNC);
2915
if (sta_id != IWL_INVALID_STATION)
2918
IWL_DEBUG_DROP("Station " MAC_FMT " not in station map. "
2919
"Defaulting to broadcast...\n",
2920
MAC_ARG(hdr->addr1));
2921
iwl4965_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
2922
return priv->hw_setting.bcast_sta_id;
2925
IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode);
2926
return priv->hw_setting.bcast_sta_id;
2931
* start REPLY_TX command process
2933
static int iwl4965_tx_skb(struct iwl4965_priv *priv,
2934
struct sk_buff *skb, struct ieee80211_tx_control *ctl)
2936
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2937
struct iwl4965_tfd_frame *tfd;
2939
int txq_id = ctl->queue;
2940
struct iwl4965_tx_queue *txq = NULL;
2941
struct iwl4965_queue *q = NULL;
2942
dma_addr_t phys_addr;
2943
dma_addr_t txcmd_phys;
2944
dma_addr_t scratch_phys;
2945
struct iwl4965_cmd *out_cmd = NULL;
2946
u16 len, idx, len_org;
2947
u8 id, hdr_len, unicast;
2952
u8 wait_write_ptr = 0;
2953
unsigned long flags;
2956
spin_lock_irqsave(&priv->lock, flags);
2957
if (iwl4965_is_rfkill(priv)) {
2958
IWL_DEBUG_DROP("Dropping - RF KILL\n");
2962
if (!priv->interface_id) {
2963
IWL_DEBUG_DROP("Dropping - !priv->interface_id\n");
2967
if ((ctl->tx_rate & 0xFF) == IWL_INVALID_RATE) {
2968
IWL_ERROR("ERROR: No TX rate available.\n");
2972
unicast = !is_multicast_ether_addr(hdr->addr1);
2975
fc = le16_to_cpu(hdr->frame_control);
2977
#ifdef CONFIG_IWL4965_DEBUG
2978
if (ieee80211_is_auth(fc))
2979
IWL_DEBUG_TX("Sending AUTH frame\n");
2980
else if (ieee80211_is_assoc_request(fc))
2981
IWL_DEBUG_TX("Sending ASSOC frame\n");
2982
else if (ieee80211_is_reassoc_request(fc))
2983
IWL_DEBUG_TX("Sending REASSOC frame\n");
2986
/* drop all data frame if we are not associated */
2987
if (!iwl4965_is_associated(priv) && !priv->assoc_id &&
2988
((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) {
2989
IWL_DEBUG_DROP("Dropping - !iwl4965_is_associated\n");
2993
spin_unlock_irqrestore(&priv->lock, flags);
2995
hdr_len = iwlwifi_ieee80211_get_hdrlen(fc);
2997
/* Find (or create) index into station table for destination station */
2998
sta_id = iwl4965_get_sta_id(priv, hdr);
2999
if (sta_id == IWL_INVALID_STATION) {
3000
IWL_DEBUG_DROP("Dropping - INVALID STATION: " MAC_FMT "\n",
3001
MAC_ARG(hdr->addr1));
3005
IWL_DEBUG_RATE("station Id %d\n", sta_id);
3007
qc = ieee80211_get_qos_ctrl(hdr);
3009
u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
3010
seq_number = priv->stations[sta_id].tid[tid].seq_number &
3012
hdr->seq_ctrl = cpu_to_le16(seq_number) |
3014
__constant_cpu_to_le16(IEEE80211_SCTL_FRAG));
3016
#ifdef CONFIG_IWL4965_HT
3017
#ifdef CONFIG_IWL4965_HT_AGG
3018
/* aggregation is on for this <sta,tid> */
3019
if (ctl->flags & IEEE80211_TXCTL_HT_MPDU_AGG)
3020
txq_id = priv->stations[sta_id].tid[tid].agg.txq_id;
3021
#endif /* CONFIG_IWL4965_HT_AGG */
3022
#endif /* CONFIG_IWL4965_HT */
3025
/* Descriptor for chosen Tx queue */
3026
txq = &priv->txq[txq_id];
3029
spin_lock_irqsave(&priv->lock, flags);
3031
/* Set up first empty TFD within this queue's circular TFD buffer */
3032
tfd = &txq->bd[q->write_ptr];
3033
memset(tfd, 0, sizeof(*tfd));
3034
control_flags = (u32 *) tfd;
3035
idx = get_cmd_index(q, q->write_ptr, 0);
3037
/* Set up driver data for this TFD */
3038
memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl4965_tx_info));
3039
txq->txb[q->write_ptr].skb[0] = skb;
3040
memcpy(&(txq->txb[q->write_ptr].status.control),
3041
ctl, sizeof(struct ieee80211_tx_control));
3043
/* Set up first empty entry in queue's array of Tx/cmd buffers */
3044
out_cmd = &txq->cmd[idx];
3045
memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
3046
memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx));
3049
* Set up the Tx-command (not MAC!) header.
3050
* Store the chosen Tx queue and TFD index within the sequence field;
3051
* after Tx, uCode's Tx response will return this value so driver can
3052
* locate the frame within the tx queue and do post-tx processing.
3054
out_cmd->hdr.cmd = REPLY_TX;
3055
out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
3056
INDEX_TO_SEQ(q->write_ptr)));
3058
/* Copy MAC header from skb into command buffer */
3059
memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len);
3062
* Use the first empty entry in this queue's command buffer array
3063
* to contain the Tx command and MAC header concatenated together
3064
* (payload data will be in another buffer).
3065
* Size of this varies, due to varying MAC header length.
3066
* If end is not dword aligned, we'll have 2 extra bytes at the end
3067
* of the MAC header (device reads on dword boundaries).
3068
* We'll tell device about this padding later.
3070
len = priv->hw_setting.tx_cmd_len +
3071
sizeof(struct iwl4965_cmd_header) + hdr_len;
3074
len = (len + 3) & ~3;
3081
/* Physical address of this Tx command's header (not MAC header!),
3082
* within command buffer array. */
3083
txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl4965_cmd) * idx +
3084
offsetof(struct iwl4965_cmd, hdr);
3086
/* Add buffer containing Tx command and MAC(!) header to TFD's
3088
iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len);
3090
if (ctl->key_idx != -1)
3091
iwl4965_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0);
3093
/* Set up TFD's 2nd entry to point directly to remainder of skb,
3094
* if any (802.11 null frames have no payload). */
3095
len = skb->len - hdr_len;
3097
phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
3098
len, PCI_DMA_TODEVICE);
3099
iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len);
3102
/* Tell 4965 about any 2-byte padding after MAC header */
3104
out_cmd->cmd.tx.tx_flags |= TX_CMD_FLG_MH_PAD_MSK;
3106
/* Total # bytes to be transmitted */
3107
len = (u16)skb->len;
3108
out_cmd->cmd.tx.len = cpu_to_le16(len);
3110
/* TODO need this for burst mode later on */
3111
iwl4965_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id);
3113
/* set is_hcca to 0; it probably will never be implemented */
3114
iwl4965_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0);
3116
scratch_phys = txcmd_phys + sizeof(struct iwl4965_cmd_header) +
3117
offsetof(struct iwl4965_tx_cmd, scratch);
3118
out_cmd->cmd.tx.dram_lsb_ptr = cpu_to_le32(scratch_phys);
3119
out_cmd->cmd.tx.dram_msb_ptr = iwl_get_dma_hi_address(scratch_phys);
3121
#ifdef CONFIG_IWL4965_HT_AGG
3122
#ifdef CONFIG_IWL4965_HT
3123
/* TODO: move this functionality to rate scaling */
3124
iwl4965_tl_get_stats(priv, hdr);
3125
#endif /* CONFIG_IWL4965_HT_AGG */
3126
#endif /*CONFIG_IWL4965_HT */
3129
if (!ieee80211_get_morefrag(hdr)) {
3130
txq->need_update = 1;
3132
u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
3133
priv->stations[sta_id].tid[tid].seq_number = seq_number;
3137
txq->need_update = 0;
3140
iwl4965_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload,
3141
sizeof(out_cmd->cmd.tx));
3143
iwl4965_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr,
3144
iwlwifi_ieee80211_get_hdrlen(fc));
3146
/* Set up entry for this TFD in Tx byte-count array */
3147
iwl4965_tx_queue_update_wr_ptr(priv, txq, len);
3149
/* Tell device the write index *just past* this latest filled TFD */
3150
q->write_ptr = iwl4965_queue_inc_wrap(q->write_ptr, q->n_bd);
3151
rc = iwl4965_tx_queue_update_write_ptr(priv, txq);
3152
spin_unlock_irqrestore(&priv->lock, flags);
3157
if ((iwl4965_queue_space(q) < q->high_mark)
3158
&& priv->mac80211_registered) {
3159
if (wait_write_ptr) {
3160
spin_lock_irqsave(&priv->lock, flags);
3161
txq->need_update = 1;
3162
iwl4965_tx_queue_update_write_ptr(priv, txq);
3163
spin_unlock_irqrestore(&priv->lock, flags);
3166
iwlwifi_ieee80211_stop_queue(priv->hw, ctl->queue);
3172
spin_unlock_irqrestore(&priv->lock, flags);
3177
static void iwl4965_set_rate(struct iwl4965_priv *priv)
3179
const struct ieee80211_hw_mode *hw = NULL;
3180
struct ieee80211_rate *rate;
3183
hw = iwl4965_get_hw_mode(priv, priv->phymode);
3185
IWL_ERROR("Failed to set rate: unable to get hw mode\n");
3189
priv->active_rate = 0;
3190
priv->active_rate_basic = 0;
3192
IWL_DEBUG_RATE("Setting rates for 802.11%c\n",
3193
hw->mode == MODE_IEEE80211A ?
3194
'a' : ((hw->mode == MODE_IEEE80211B) ? 'b' : 'g'));
3196
for (i = 0; i < hw->num_rates; i++) {
3197
rate = &(hw->rates[i]);
3198
if ((rate->val < IWL_RATE_COUNT) &&
3199
(rate->flags & IEEE80211_RATE_SUPPORTED)) {
3200
IWL_DEBUG_RATE("Adding rate index %d (plcp %d)%s\n",
3201
rate->val, iwl4965_rates[rate->val].plcp,
3202
(rate->flags & IEEE80211_RATE_BASIC) ?
3204
priv->active_rate |= (1 << rate->val);
3205
if (rate->flags & IEEE80211_RATE_BASIC)
3206
priv->active_rate_basic |= (1 << rate->val);
3208
IWL_DEBUG_RATE("Not adding rate %d (plcp %d)\n",
3209
rate->val, iwl4965_rates[rate->val].plcp);
3212
IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
3213
priv->active_rate, priv->active_rate_basic);
3216
* If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
3217
* otherwise set it to the default of all CCK rates and 6, 12, 24 for
3220
if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
3221
priv->staging_rxon.cck_basic_rates =
3222
((priv->active_rate_basic &
3223
IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
3225
priv->staging_rxon.cck_basic_rates =
3226
(IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
3228
if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
3229
priv->staging_rxon.ofdm_basic_rates =
3230
((priv->active_rate_basic &
3231
(IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
3232
IWL_FIRST_OFDM_RATE) & 0xFF;
3234
priv->staging_rxon.ofdm_basic_rates =
3235
(IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
3238
static void iwl4965_radio_kill_sw(struct iwl4965_priv *priv, int disable_radio)
3240
unsigned long flags;
3242
if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
3245
IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
3246
disable_radio ? "OFF" : "ON");
3248
if (disable_radio) {
3249
iwl4965_scan_cancel(priv);
3250
/* FIXME: This is a workaround for AP */
3251
if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
3252
spin_lock_irqsave(&priv->lock, flags);
3253
iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET,
3254
CSR_UCODE_SW_BIT_RFKILL);
3255
spin_unlock_irqrestore(&priv->lock, flags);
3256
iwl4965_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
3257
set_bit(STATUS_RF_KILL_SW, &priv->status);
3262
spin_lock_irqsave(&priv->lock, flags);
3263
iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3265
clear_bit(STATUS_RF_KILL_SW, &priv->status);
3266
spin_unlock_irqrestore(&priv->lock, flags);
3271
spin_lock_irqsave(&priv->lock, flags);
3272
iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
3273
if (!iwl4965_grab_nic_access(priv))
3274
iwl4965_release_nic_access(priv);
3275
spin_unlock_irqrestore(&priv->lock, flags);
3277
if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
3278
IWL_DEBUG_RF_KILL("Can not turn radio back on - "
3279
"disabled by HW switch\n");
3283
queue_work(priv->workqueue, &priv->restart);
3287
void iwl4965_set_decrypted_flag(struct iwl4965_priv *priv, struct sk_buff *skb,
3288
u32 decrypt_res, struct ieee80211_rx_status *stats)
3291
le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control);
3293
if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
3296
if (!(fc & IEEE80211_FCTL_PROTECTED))
3299
IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
3300
switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
3301
case RX_RES_STATUS_SEC_TYPE_TKIP:
3302
if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
3303
RX_RES_STATUS_BAD_ICV_MIC)
3304
stats->flag |= RX_FLAG_MMIC_ERROR;
3305
case RX_RES_STATUS_SEC_TYPE_WEP:
3306
case RX_RES_STATUS_SEC_TYPE_CCMP:
3307
if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
3308
RX_RES_STATUS_DECRYPT_OK) {
3309
IWL_DEBUG_RX("hw decrypt successfully!!!\n");
3310
stats->flag |= RX_FLAG_DECRYPTED;
3319
void iwl4965_handle_data_packet_monitor(struct iwl4965_priv *priv,
3320
struct iwl4965_rx_mem_buffer *rxb,
3321
void *data, short len,
3322
struct ieee80211_rx_status *stats,
3325
struct iwl4965_rt_rx_hdr *iwl4965_rt;
3327
/* First cache any information we need before we overwrite
3328
* the information provided in the skb from the hardware */
3329
s8 signal = stats->ssi;
3331
int rate = stats->rate;
3332
u64 tsf = stats->mactime;
3333
__le16 phy_flags_hw = cpu_to_le16(phy_flags);
3335
/* We received data from the HW, so stop the watchdog */
3336
if (len > IWL_RX_BUF_SIZE - sizeof(*iwl4965_rt)) {
3337
IWL_DEBUG_DROP("Dropping too large packet in monitor\n");
3341
/* copy the frame data to write after where the radiotap header goes */
3342
iwl4965_rt = (void *)rxb->skb->data;
3343
memmove(iwl4965_rt->payload, data, len);
3345
iwl4965_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
3346
iwl4965_rt->rt_hdr.it_pad = 0; /* always good to zero */
3348
/* total header + data */
3349
iwl4965_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*iwl4965_rt));
3351
/* Set the size of the skb to the size of the frame */
3352
skb_put(rxb->skb, sizeof(*iwl4965_rt) + len);
3354
/* Big bitfield of all the fields we provide in radiotap */
3355
iwl4965_rt->rt_hdr.it_present =
3356
cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) |
3357
(1 << IEEE80211_RADIOTAP_FLAGS) |
3358
(1 << IEEE80211_RADIOTAP_RATE) |
3359
(1 << IEEE80211_RADIOTAP_CHANNEL) |
3360
(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
3361
(1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
3362
(1 << IEEE80211_RADIOTAP_ANTENNA));
3364
/* Zero the flags, we'll add to them as we go */
3365
iwl4965_rt->rt_flags = 0;
3367
iwl4965_rt->rt_tsf = cpu_to_le64(tsf);
3369
/* Convert to dBm */
3370
iwl4965_rt->rt_dbmsignal = signal;
3371
iwl4965_rt->rt_dbmnoise = noise;
3373
/* Convert the channel frequency and set the flags */
3374
iwl4965_rt->rt_channelMHz = cpu_to_le16(stats->freq);
3375
if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK))
3376
iwl4965_rt->rt_chbitmask =
3377
cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
3378
else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK)
3379
iwl4965_rt->rt_chbitmask =
3380
cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
3382
iwl4965_rt->rt_chbitmask =
3383
cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ));
3385
rate = iwl4965_rate_index_from_plcp(rate);
3387
iwl4965_rt->rt_rate = 0;
3389
iwl4965_rt->rt_rate = iwl4965_rates[rate].ieee;
3391
/* antenna number */
3392
iwl4965_rt->rt_antenna =
3393
le16_to_cpu(phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK) >> 4;
3395
/* set the preamble flag if we have it */
3396
if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
3397
iwl4965_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
3399
IWL_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
3401
stats->flag |= RX_FLAG_RADIOTAP;
3402
iwlwifi_ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats);
3407
#define IWL_PACKET_RETRY_TIME HZ
3409
int iwl4965_is_duplicate_packet(struct iwl4965_priv *priv, struct ieee80211_hdr *header)
3411
u16 sc = le16_to_cpu(header->seq_ctrl);
3412
u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
3413
u16 frag = sc & IEEE80211_SCTL_FRAG;
3414
u16 *last_seq, *last_frag;
3415
unsigned long *last_time;
3417
switch (priv->iw_mode) {
3418
case IEEE80211_IF_TYPE_IBSS:{
3419
struct list_head *p;
3420
struct iwl4965_ibss_seq *entry = NULL;
3421
u8 *mac = header->addr2;
3422
int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1);
3424
__list_for_each(p, &priv->ibss_mac_hash[index]) {
3425
entry = list_entry(p, struct iwl4965_ibss_seq, list);
3426
if (!compare_ether_addr(entry->mac, mac))
3429
if (p == &priv->ibss_mac_hash[index]) {
3430
entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
3432
IWL_ERROR("Cannot malloc new mac entry\n");
3435
memcpy(entry->mac, mac, ETH_ALEN);
3436
entry->seq_num = seq;
3437
entry->frag_num = frag;
3438
entry->packet_time = jiffies;
3439
list_add(&entry->list, &priv->ibss_mac_hash[index]);
3442
last_seq = &entry->seq_num;
3443
last_frag = &entry->frag_num;
3444
last_time = &entry->packet_time;
3447
case IEEE80211_IF_TYPE_STA:
3448
last_seq = &priv->last_seq_num;
3449
last_frag = &priv->last_frag_num;
3450
last_time = &priv->last_packet_time;
3455
if ((*last_seq == seq) &&
3456
time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) {
3457
if (*last_frag == frag)
3459
if (*last_frag + 1 != frag)
3460
/* out-of-order fragment */
3466
*last_time = jiffies;
3473
#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
3475
#include "iwl-spectrum.h"
3477
#define BEACON_TIME_MASK_LOW 0x00FFFFFF
3478
#define BEACON_TIME_MASK_HIGH 0xFF000000
3479
#define TIME_UNIT 1024
3482
* extended beacon time format
3483
* time in usec will be changed into a 32-bit value in 8:24 format
3484
* the high 1 byte is the beacon counts
3485
* the lower 3 bytes is the time in usec within one beacon interval
3488
static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval)
3492
u32 interval = beacon_interval * 1024;
3494
if (!interval || !usec)
3497
quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
3498
rem = (usec % interval) & BEACON_TIME_MASK_LOW;
3500
return (quot << 24) + rem;
3503
/* base is usually what we get from ucode with each received frame,
3504
* the same as HW timer counter counting down
3507
static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
3509
u32 base_low = base & BEACON_TIME_MASK_LOW;
3510
u32 addon_low = addon & BEACON_TIME_MASK_LOW;
3511
u32 interval = beacon_interval * TIME_UNIT;
3512
u32 res = (base & BEACON_TIME_MASK_HIGH) +
3513
(addon & BEACON_TIME_MASK_HIGH);
3515
if (base_low > addon_low)
3516
res += base_low - addon_low;
3517
else if (base_low < addon_low) {
3518
res += interval + base_low - addon_low;
3523
return cpu_to_le32(res);
3526
static int iwl4965_get_measurement(struct iwl4965_priv *priv,
3527
struct ieee80211_measurement_params *params,
3530
struct iwl4965_spectrum_cmd spectrum;
3531
struct iwl4965_rx_packet *res;
3532
struct iwl4965_host_cmd cmd = {
3533
.id = REPLY_SPECTRUM_MEASUREMENT_CMD,
3534
.data = (void *)&spectrum,
3535
.meta.flags = CMD_WANT_SKB,
3537
u32 add_time = le64_to_cpu(params->start_time);
3539
int spectrum_resp_status;
3540
int duration = le16_to_cpu(params->duration);
3542
if (iwl4965_is_associated(priv))
3544
iwl4965_usecs_to_beacons(
3545
le64_to_cpu(params->start_time) - priv->last_tsf,
3546
le16_to_cpu(priv->rxon_timing.beacon_interval));
3548
memset(&spectrum, 0, sizeof(spectrum));
3550
spectrum.channel_count = cpu_to_le16(1);
3552
RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
3553
spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
3554
cmd.len = sizeof(spectrum);
3555
spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
3557
if (iwl4965_is_associated(priv))
3558
spectrum.start_time =
3559
iwl4965_add_beacon_time(priv->last_beacon_time,
3561
le16_to_cpu(priv->rxon_timing.beacon_interval));
3563
spectrum.start_time = 0;
3565
spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
3566
spectrum.channels[0].channel = params->channel;
3567
spectrum.channels[0].type = type;
3568
if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
3569
spectrum.flags |= RXON_FLG_BAND_24G_MSK |
3570
RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
3572
rc = iwl4965_send_cmd_sync(priv, &cmd);
3576
res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data;
3577
if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
3578
IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
3582
spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
3583
switch (spectrum_resp_status) {
3584
case 0: /* Command will be handled */
3585
if (res->u.spectrum.id != 0xff) {
3587
("Replaced existing measurement: %d\n",
3588
res->u.spectrum.id);
3589
priv->measurement_status &= ~MEASUREMENT_READY;
3591
priv->measurement_status |= MEASUREMENT_ACTIVE;
3595
case 1: /* Command will not be handled */
3600
dev_kfree_skb_any(cmd.meta.u.skb);
3606
static void iwl4965_txstatus_to_ieee(struct iwl4965_priv *priv,
3607
struct iwl4965_tx_info *tx_sta)
3610
tx_sta->status.ack_signal = 0;
3611
tx_sta->status.excessive_retries = 0;
3612
tx_sta->status.queue_length = 0;
3613
tx_sta->status.queue_number = 0;
3616
iwlwifi_iwlwifi_ieee80211_tx_status_irqsafe(priv->hw,
3617
tx_sta->skb[0], &(tx_sta->status));
3619
iwlwifi_ieee80211_tx_status(priv->hw,
3620
tx_sta->skb[0], &(tx_sta->status));
3622
tx_sta->skb[0] = NULL;
3626
* iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
3628
* When FW advances 'R' index, all entries between old and new 'R' index
3629
* need to be reclaimed. As result, some free space forms. If there is
3630
* enough free space (> low mark), wake the stack that feeds us.
3632
int iwl4965_tx_queue_reclaim(struct iwl4965_priv *priv, int txq_id, int index)
3634
struct iwl4965_tx_queue *txq = &priv->txq[txq_id];
3635
struct iwl4965_queue *q = &txq->q;
3638
if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) {
3639
IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
3640
"is out of range [0-%d] %d %d.\n", txq_id,
3641
index, q->n_bd, q->write_ptr, q->read_ptr);
3645
for (index = iwl4965_queue_inc_wrap(index, q->n_bd);
3646
q->read_ptr != index;
3647
q->read_ptr = iwl4965_queue_inc_wrap(q->read_ptr, q->n_bd)) {
3648
if (txq_id != IWL_CMD_QUEUE_NUM) {
3649
iwl4965_txstatus_to_ieee(priv,
3650
&(txq->txb[txq->q.read_ptr]));
3651
iwl4965_hw_txq_free_tfd(priv, txq);
3652
} else if (nfreed > 1) {
3653
IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index,
3654
q->write_ptr, q->read_ptr);
3655
queue_work(priv->workqueue, &priv->restart);
3660
if (iwl4965_queue_space(q) > q->low_mark && (txq_id >= 0) &&
3661
(txq_id != IWL_CMD_QUEUE_NUM) &&
3662
priv->mac80211_registered)
3663
iwlwifi_ieee80211_wake_queue(priv->hw, txq_id);
3669
static int iwl4965_is_tx_success(u32 status)
3671
status &= TX_STATUS_MSK;
3672
return (status == TX_STATUS_SUCCESS)
3673
|| (status == TX_STATUS_DIRECT_DONE);
3676
/******************************************************************************
3678
* Generic RX handler implementations
3680
******************************************************************************/
3681
#ifdef CONFIG_IWL4965_HT
3682
#ifdef CONFIG_IWL4965_HT_AGG
3684
static inline int iwl4965_get_ra_sta_id(struct iwl4965_priv *priv,
3685
struct ieee80211_hdr *hdr)
3687
if (priv->iw_mode == IEEE80211_IF_TYPE_STA)
3690
u8 *da = ieee80211_get_DA(hdr);
3691
return iwl4965_hw_find_station(priv, da);
3695
static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr(
3696
struct iwl4965_priv *priv, int txq_id, int idx)
3698
if (priv->txq[txq_id].txb[idx].skb[0])
3699
return (struct ieee80211_hdr *)priv->txq[txq_id].
3700
txb[idx].skb[0]->data;
3704
static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp)
3706
__le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status +
3707
tx_resp->frame_count);
3708
return le32_to_cpu(*scd_ssn) & MAX_SN;
3713
* iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue
3715
static int iwl4965_tx_status_reply_tx(struct iwl4965_priv *priv,
3716
struct iwl4965_ht_agg *agg,
3717
struct iwl4965_tx_resp *tx_resp,
3721
__le32 *frame_status = &tx_resp->status;
3722
struct iwlwifi_ieee80211_tx_status *tx_status = NULL;
3723
struct ieee80211_hdr *hdr = NULL;
3728
if (agg->wait_for_ba)
3729
IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
3731
agg->frame_count = tx_resp->frame_count;
3732
agg->start_idx = start_idx;
3733
agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
3734
agg->bitmap0 = agg->bitmap1 = 0;
3736
/* # frames attempted by Tx command */
3737
if (agg->frame_count == 1) {
3738
/* Only one frame was attempted; no block-ack will arrive */
3739
struct iwl4965_tx_queue *txq ;
3740
status = le32_to_cpu(frame_status[0]);
3742
txq_id = agg->txq_id;
3743
txq = &priv->txq[txq_id];
3744
/* FIXME: code repetition */
3745
IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d \n",
3746
agg->frame_count, agg->start_idx);
3748
tx_status = &(priv->txq[txq_id].txb[txq->q.read_ptr].status);
3749
tx_status->retry_count = tx_resp->failure_frame;
3750
tx_status->queue_number = status & 0xff;
3751
tx_status->queue_length = tx_resp->bt_kill_count;
3752
tx_status->queue_length |= tx_resp->failure_rts;
3754
tx_status->flags = iwl4965_is_tx_success(status)?
3755
IEEE80211_TX_STATUS_ACK : 0;
3756
tx_status->control.tx_rate =
3757
iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags);
3758
/* FIXME: code repetition end */
3760
IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
3761
status & 0xff, tx_resp->failure_frame);
3762
IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
3763
iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags));
3765
agg->wait_for_ba = 0;
3767
/* Two or more frames were attempted; expect block-ack */
3769
int start = agg->start_idx;
3771
/* Construct bit-map of pending frames within Tx window */
3772
for (i = 0; i < agg->frame_count; i++) {
3774
status = le32_to_cpu(frame_status[i]);
3776
idx = SEQ_TO_INDEX(seq);
3777
txq_id = SEQ_TO_QUEUE(seq);
3779
if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
3780
AGG_TX_STATE_ABORT_MSK))
3783
IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
3784
agg->frame_count, txq_id, idx);
3786
hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx);
3788
sc = le16_to_cpu(hdr->seq_ctrl);
3789
if (idx != (SEQ_TO_SN(sc) & 0xff)) {
3790
IWL_ERROR("BUG_ON idx doesn't match seq control"
3791
" idx=%d, seq_idx=%d, seq=%d\n",
3797
IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
3798
i, idx, SEQ_TO_SN(sc));
3802
sh = (start - idx) + 0xff;
3803
bitmap = bitmap << sh;
3806
} else if (sh < -64)
3807
sh = 0xff - (start - idx);
3811
bitmap = bitmap << sh;
3814
bitmap |= (1 << sh);
3815
IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
3816
start, (u32)(bitmap & 0xFFFFFFFF));
3819
agg->bitmap0 = bitmap & 0xFFFFFFFF;
3820
agg->bitmap1 = bitmap >> 32;
3821
agg->start_idx = start;
3822
agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
3823
IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%x\n",
3824
agg->frame_count, agg->start_idx,
3828
agg->wait_for_ba = 1;
3836
* iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
3838
static void iwl4965_rx_reply_tx(struct iwl4965_priv *priv,
3839
struct iwl4965_rx_mem_buffer *rxb)
3841
struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3842
u16 sequence = le16_to_cpu(pkt->hdr.sequence);
3843
int txq_id = SEQ_TO_QUEUE(sequence);
3844
int index = SEQ_TO_INDEX(sequence);
3845
struct iwl4965_tx_queue *txq = &priv->txq[txq_id];
3846
struct iwlwifi_ieee80211_tx_status *tx_status;
3847
struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
3848
u32 status = le32_to_cpu(tx_resp->status);
3849
#ifdef CONFIG_IWL4965_HT
3850
#ifdef CONFIG_IWL4965_HT_AGG
3855
if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) {
3856
IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
3857
"is out of range [0-%d] %d %d\n", txq_id,
3858
index, txq->q.n_bd, txq->q.write_ptr,
3863
#ifdef CONFIG_IWL4965_HT
3864
#ifdef CONFIG_IWL4965_HT_AGG
3865
if (txq->sched_retry) {
3866
const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp);
3867
struct ieee80211_hdr *hdr =
3868
iwl4965_tx_queue_get_hdr(priv, txq_id, index);
3869
struct iwl4965_ht_agg *agg = NULL;
3870
__le16 *qc = ieee80211_get_qos_ctrl(hdr);
3873
IWL_ERROR("BUG_ON qc is null!!!!\n");
3877
tid = le16_to_cpu(*qc) & 0xf;
3879
sta_id = iwl4965_get_ra_sta_id(priv, hdr);
3880
if (unlikely(sta_id == IWL_INVALID_STATION)) {
3881
IWL_ERROR("Station not known for\n");
3885
agg = &priv->stations[sta_id].tid[tid].agg;
3887
iwl4965_tx_status_reply_tx(priv, agg, tx_resp, index);
3889
if ((tx_resp->frame_count == 1) &&
3890
!iwl4965_is_tx_success(status)) {
3891
/* TODO: send BAR */
3894
if ((txq->q.read_ptr != (scd_ssn & 0xff))) {
3895
index = iwl4965_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
3896
IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
3897
"%d index %d\n", scd_ssn , index);
3898
iwl4965_tx_queue_reclaim(priv, txq_id, index);
3901
#endif /* CONFIG_IWL4965_HT_AGG */
3902
#endif /* CONFIG_IWL4965_HT */
3903
tx_status = &(txq->txb[txq->q.read_ptr].status);
3905
tx_status->retry_count = tx_resp->failure_frame;
3906
tx_status->queue_number = status;
3907
tx_status->queue_length = tx_resp->bt_kill_count;
3908
tx_status->queue_length |= tx_resp->failure_rts;
3911
iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0;
3913
tx_status->control.tx_rate =
3914
iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags);
3916
IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x "
3917
"retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status),
3918
status, le32_to_cpu(tx_resp->rate_n_flags),
3919
tx_resp->failure_frame);
3921
IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
3923
iwl4965_tx_queue_reclaim(priv, txq_id, index);
3924
#ifdef CONFIG_IWL4965_HT
3925
#ifdef CONFIG_IWL4965_HT_AGG
3927
#endif /* CONFIG_IWL4965_HT_AGG */
3928
#endif /* CONFIG_IWL4965_HT */
3930
if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
3931
IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
3935
static void iwl4965_rx_reply_alive(struct iwl4965_priv *priv,
3936
struct iwl4965_rx_mem_buffer *rxb)
3938
struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3939
struct iwl4965_alive_resp *palive;
3940
struct delayed_work *pwork;
3942
palive = &pkt->u.alive_frame;
3944
IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
3946
palive->is_valid, palive->ver_type,
3947
palive->ver_subtype);
3949
if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
3950
IWL_DEBUG_INFO("Initialization Alive received.\n");
3951
memcpy(&priv->card_alive_init,
3952
&pkt->u.alive_frame,
3953
sizeof(struct iwl4965_init_alive_resp));
3954
pwork = &priv->init_alive_start;
3956
IWL_DEBUG_INFO("Runtime Alive received.\n");
3957
memcpy(&priv->card_alive, &pkt->u.alive_frame,
3958
sizeof(struct iwl4965_alive_resp));
3959
pwork = &priv->alive_start;
3962
/* We delay the ALIVE response by 5ms to
3963
* give the HW RF Kill time to activate... */
3964
if (palive->is_valid == UCODE_VALID_OK)
3965
queue_delayed_work(priv->workqueue, pwork,
3966
msecs_to_jiffies(5));
3968
IWL_WARNING("uCode did not respond OK.\n");
3971
static void iwl4965_rx_reply_add_sta(struct iwl4965_priv *priv,
3972
struct iwl4965_rx_mem_buffer *rxb)
3974
struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3976
IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
3980
static void iwl4965_rx_reply_error(struct iwl4965_priv *priv,
3981
struct iwl4965_rx_mem_buffer *rxb)
3983
struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3985
IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
3986
"seq 0x%04X ser 0x%08X\n",
3987
le32_to_cpu(pkt->u.err_resp.error_type),
3988
get_cmd_string(pkt->u.err_resp.cmd_id),
3989
pkt->u.err_resp.cmd_id,
3990
le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
3991
le32_to_cpu(pkt->u.err_resp.error_info));
3994
#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
3996
static void iwl4965_rx_csa(struct iwl4965_priv *priv, struct iwl4965_rx_mem_buffer *rxb)
3998
struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3999
struct iwl4965_rxon_cmd *rxon = (void *)&priv->active_rxon;
4000
struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif);
4001
IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
4002
le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
4003
rxon->channel = csa->channel;
4004
priv->staging_rxon.channel = csa->channel;
4007
static void iwl4965_rx_spectrum_measure_notif(struct iwl4965_priv *priv,
4008
struct iwl4965_rx_mem_buffer *rxb)
4010
#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
4011
struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
4012
struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif);
4014
if (!report->state) {
4015
IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO,
4016
"Spectrum Measure Notification: Start\n");
4020
memcpy(&priv->measure_report, report, sizeof(*report));
4021
priv->measurement_status |= MEASUREMENT_READY;
4025
static void iwl4965_rx_pm_sleep_notif(struct iwl4965_priv *priv,
4026
struct iwl4965_rx_mem_buffer *rxb)
4028
#ifdef CONFIG_IWL4965_DEBUG
4029
struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
4030
struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif);
4031
IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
4032
sleep->pm_sleep_mode, sleep->pm_wakeup_src);
4036
static void iwl4965_rx_pm_debug_statistics_notif(struct iwl4965_priv *priv,
4037
struct iwl4965_rx_mem_buffer *rxb)
4039
struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
4040
IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
4041
"notification for %s:\n",
4042
le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
4043
iwl4965_print_hex_dump(IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
4046
static void iwl4965_bg_beacon_update(struct work_struct *work)
4048
struct iwl4965_priv *priv =
4049
container_of(work, struct iwl4965_priv, beacon_update);
4050
struct sk_buff *beacon;
4052
/* Pull updated AP beacon from mac80211. will fail if not in AP mode */
4053
beacon = iwlwifi_ieee80211_beacon_get(priv->hw, priv->interface_id, NULL);
4056
IWL_ERROR("update beacon failed\n");
4060
mutex_lock(&priv->mutex);
4061
/* new beacon skb is allocated every time; dispose previous.*/
4062
if (priv->ibss_beacon)
4063
dev_kfree_skb(priv->ibss_beacon);
4065
priv->ibss_beacon = beacon;
4066
mutex_unlock(&priv->mutex);
4068
iwl4965_send_beacon_cmd(priv);
4071
static void iwl4965_rx_beacon_notif(struct iwl4965_priv *priv,
4072
struct iwl4965_rx_mem_buffer *rxb)
4074
#ifdef CONFIG_IWL4965_DEBUG
4075
struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
4076
struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status);
4077
u8 rate = iwl4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
4079
IWL_DEBUG_RX("beacon status %x retries %d iss %d "
4080
"tsf %d %d rate %d\n",
4081
le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
4082
beacon->beacon_notify_hdr.failure_frame,
4083
le32_to_cpu(beacon->ibss_mgr_status),
4084
le32_to_cpu(beacon->high_tsf),
4085
le32_to_cpu(beacon->low_tsf), rate);
4088
if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
4089
(!test_bit(STATUS_EXIT_PENDING, &priv->status)))
4090
queue_work(priv->workqueue, &priv->beacon_update);
4093
/* Service response to REPLY_SCAN_CMD (0x80) */
4094
static void iwl4965_rx_reply_scan(struct iwl4965_priv *priv,
4095
struct iwl4965_rx_mem_buffer *rxb)
4097
#ifdef CONFIG_IWL4965_DEBUG
4098
struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
4099
struct iwl4965_scanreq_notification *notif =
4100
(struct iwl4965_scanreq_notification *)pkt->u.raw;
4102
IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status);
4106
/* Service SCAN_START_NOTIFICATION (0x82) */
4107
static void iwl4965_rx_scan_start_notif(struct iwl4965_priv *priv,
4108
struct iwl4965_rx_mem_buffer *rxb)
4110
struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
4111
struct iwl4965_scanstart_notification *notif =
4112
(struct iwl4965_scanstart_notification *)pkt->u.raw;
4113
priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
4114
IWL_DEBUG_SCAN("Scan start: "
4116
"(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
4118
notif->band ? "bg" : "a",
4120
notif->tsf_low, notif->status, notif->beacon_timer);
4123
/* Service SCAN_RESULTS_NOTIFICATION (0x83) */
4124
static void iwl4965_rx_scan_results_notif(struct iwl4965_priv *priv,
4125
struct iwl4965_rx_mem_buffer *rxb)
4127
struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
4128
struct iwl4965_scanresults_notification *notif =
4129
(struct iwl4965_scanresults_notification *)pkt->u.raw;
4131
IWL_DEBUG_SCAN("Scan ch.res: "
4133
"(TSF: 0x%08X:%08X) - %d "
4134
"elapsed=%lu usec (%dms since last)\n",
4136
notif->band ? "bg" : "a",
4137
le32_to_cpu(notif->tsf_high),
4138
le32_to_cpu(notif->tsf_low),
4139
le32_to_cpu(notif->statistics[0]),
4140
le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
4141
jiffies_to_msecs(elapsed_jiffies
4142
(priv->last_scan_jiffies, jiffies)));
4144
priv->last_scan_jiffies = jiffies;
4145
priv->next_scan_jiffies = 0;
4148
/* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
4149
static void iwl4965_rx_scan_complete_notif(struct iwl4965_priv *priv,
4150
struct iwl4965_rx_mem_buffer *rxb)
4152
struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
4153
struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
4155
IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
4156
scan_notif->scanned_channels,
4157
scan_notif->tsf_low,
4158
scan_notif->tsf_high, scan_notif->status);
4160
/* The HW is no longer scanning */
4161
clear_bit(STATUS_SCAN_HW, &priv->status);
4163
/* The scan completion notification came in, so kill that timer... */
4164
cancel_delayed_work(&priv->scan_check);
4166
IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
4167
(priv->scan_bands == 2) ? "2.4" : "5.2",
4168
jiffies_to_msecs(elapsed_jiffies
4169
(priv->scan_pass_start, jiffies)));
4171
/* Remove this scanned band from the list
4172
* of pending bands to scan */
4175
/* If a request to abort was given, or the scan did not succeed
4176
* then we reset the scan state machine and terminate,
4177
* re-queuing another scan if one has been requested */
4178
if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
4179
IWL_DEBUG_INFO("Aborted scan completed.\n");
4180
clear_bit(STATUS_SCAN_ABORTING, &priv->status);
4182
/* If there are more bands on this scan pass reschedule */
4183
if (priv->scan_bands > 0)
4187
priv->last_scan_jiffies = jiffies;
4188
priv->next_scan_jiffies = 0;
4189
IWL_DEBUG_INFO("Setting scan to off\n");
4191
clear_bit(STATUS_SCANNING, &priv->status);
4193
IWL_DEBUG_INFO("Scan took %dms\n",
4194
jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
4196
queue_work(priv->workqueue, &priv->scan_completed);
4201
priv->scan_pass_start = jiffies;
4202
queue_work(priv->workqueue, &priv->request_scan);
4205
/* Handle notification from uCode that card's power state is changing
4206
* due to software, hardware, or critical temperature RFKILL */
4207
static void iwl4965_rx_card_state_notif(struct iwl4965_priv *priv,
4208
struct iwl4965_rx_mem_buffer *rxb)
4210
struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
4211
u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
4212
unsigned long status = priv->status;
4214
IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
4215
(flags & HW_CARD_DISABLED) ? "Kill" : "On",
4216
(flags & SW_CARD_DISABLED) ? "Kill" : "On");
4218
if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
4219
RF_CARD_DISABLED)) {
4221
iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET,
4222
CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
4224
if (!iwl4965_grab_nic_access(priv)) {
4225
iwl4965_write_direct32(
4226
priv, HBUS_TARG_MBX_C,
4227
HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
4229
iwl4965_release_nic_access(priv);
4232
if (!(flags & RXON_CARD_DISABLED)) {
4233
iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR,
4234
CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
4235
if (!iwl4965_grab_nic_access(priv)) {
4236
iwl4965_write_direct32(
4237
priv, HBUS_TARG_MBX_C,
4238
HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
4240
iwl4965_release_nic_access(priv);
4244
if (flags & RF_CARD_DISABLED) {
4245
iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET,
4246
CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
4247
iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
4248
if (!iwl4965_grab_nic_access(priv))
4249
iwl4965_release_nic_access(priv);
4253
if (flags & HW_CARD_DISABLED)
4254
set_bit(STATUS_RF_KILL_HW, &priv->status);
4256
clear_bit(STATUS_RF_KILL_HW, &priv->status);
4259
if (flags & SW_CARD_DISABLED)
4260
set_bit(STATUS_RF_KILL_SW, &priv->status);
4262
clear_bit(STATUS_RF_KILL_SW, &priv->status);
4264
if (!(flags & RXON_CARD_DISABLED))
4265
iwl4965_scan_cancel(priv);
4267
if ((test_bit(STATUS_RF_KILL_HW, &status) !=
4268
test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
4269
(test_bit(STATUS_RF_KILL_SW, &status) !=
4270
test_bit(STATUS_RF_KILL_SW, &priv->status)))
4271
queue_work(priv->workqueue, &priv->rf_kill);
4273
wake_up_interruptible(&priv->wait_command_queue);
4277
* iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
4279
* Setup the RX handlers for each of the reply types sent from the uCode
4282
* This function chains into the hardware specific files for them to setup
4283
* any hardware specific handlers as well.
4285
static void iwl4965_setup_rx_handlers(struct iwl4965_priv *priv)
4287
priv->rx_handlers[REPLY_ALIVE] = iwl4965_rx_reply_alive;
4288
priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta;
4289
priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error;
4290
priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa;
4291
priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
4292
iwl4965_rx_spectrum_measure_notif;
4293
priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif;
4294
priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
4295
iwl4965_rx_pm_debug_statistics_notif;
4296
priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
4299
* The same handler is used for both the REPLY to a discrete
4300
* statistics request from the host as well as for the periodic
4301
* statistics notifications (after received beacons) from the uCode.
4303
priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics;
4304
priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics;
4306
priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan;
4307
priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif;
4308
priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
4309
iwl4965_rx_scan_results_notif;
4310
priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
4311
iwl4965_rx_scan_complete_notif;
4312
priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif;
4313
priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx;
4315
/* Set up hardware specific Rx handlers */
4316
iwl4965_hw_rx_handler_setup(priv);
4320
* iwl4965_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
4321
* @rxb: Rx buffer to reclaim
4323
* If an Rx buffer has an async callback associated with it the callback
4324
* will be executed. The attached skb (if present) will only be freed
4325
* if the callback returns 1
4327
static void iwl4965_tx_cmd_complete(struct iwl4965_priv *priv,
4328
struct iwl4965_rx_mem_buffer *rxb)
4330
struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data;
4331
u16 sequence = le16_to_cpu(pkt->hdr.sequence);
4332
int txq_id = SEQ_TO_QUEUE(sequence);
4333
int index = SEQ_TO_INDEX(sequence);
4334
int huge = sequence & SEQ_HUGE_FRAME;
4336
struct iwl4965_cmd *cmd;
4338
/* If a Tx command is being handled and it isn't in the actual
4339
* command queue then there a command routing bug has been introduced
4340
* in the queue management code. */
4341
if (txq_id != IWL_CMD_QUEUE_NUM)
4342
IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
4343
txq_id, pkt->hdr.cmd);
4344
BUG_ON(txq_id != IWL_CMD_QUEUE_NUM);
4346
cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
4347
cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
4349
/* Input error checking is done when commands are added to queue. */
4350
if (cmd->meta.flags & CMD_WANT_SKB) {
4351
cmd->meta.source->u.skb = rxb->skb;
4353
} else if (cmd->meta.u.callback &&
4354
!cmd->meta.u.callback(priv, cmd, rxb->skb))
4357
iwl4965_tx_queue_reclaim(priv, txq_id, index);
4359
if (!(cmd->meta.flags & CMD_ASYNC)) {
4360
clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
4361
wake_up_interruptible(&priv->wait_command_queue);
4365
/************************** RX-FUNCTIONS ****************************/
4367
* Rx theory of operation
4369
* Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs),
4370
* each of which point to Receive Buffers to be filled by 4965. These get
4371
* used not only for Rx frames, but for any command response or notification
4372
* from the 4965. The driver and 4965 manage the Rx buffers by means
4373
* of indexes into the circular buffer.
4376
* The host/firmware share two index registers for managing the Rx buffers.
4378
* The READ index maps to the first position that the firmware may be writing
4379
* to -- the driver can read up to (but not including) this position and get
4381
* The READ index is managed by the firmware once the card is enabled.
4383
* The WRITE index maps to the last position the driver has read from -- the
4384
* position preceding WRITE is the last slot the firmware can place a packet.
4386
* The queue is empty (no good data) if WRITE = READ - 1, and is full if
4389
* During initialization, the host sets up the READ queue position to the first
4390
* INDEX position, and WRITE to the last (READ - 1 wrapped)
4392
* When the firmware places a packet in a buffer, it will advance the READ index
4393
* and fire the RX interrupt. The driver can then query the READ index and
4394
* process as many packets as possible, moving the WRITE index forward as it
4395
* resets the Rx queue buffers with new memory.
4397
* The management in the driver is as follows:
4398
* + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
4399
* iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
4400
* to replenish the iwl->rxq->rx_free.
4401
* + In iwl4965_rx_replenish (scheduled) if 'processed' != 'read' then the
4402
* iwl->rxq is replenished and the READ INDEX is updated (updating the
4403
* 'processed' and 'read' driver indexes as well)
4404
* + A received packet is processed and handed to the kernel network stack,
4405
* detached from the iwl->rxq. The driver 'processed' index is updated.
4406
* + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
4407
* list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
4408
* INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
4409
* were enough free buffers and RX_STALLED is set it is cleared.
4414
* iwl4965_rx_queue_alloc() Allocates rx_free
4415
* iwl4965_rx_replenish() Replenishes rx_free list from rx_used, and calls
4416
* iwl4965_rx_queue_restock
4417
* iwl4965_rx_queue_restock() Moves available buffers from rx_free into Rx
4418
* queue, updates firmware pointers, and updates
4419
* the WRITE index. If insufficient rx_free buffers
4420
* are available, schedules iwl4965_rx_replenish
4422
* -- enable interrupts --
4423
* ISR - iwl4965_rx() Detach iwl4965_rx_mem_buffers from pool up to the
4424
* READ INDEX, detaching the SKB from the pool.
4425
* Moves the packet buffer from queue to rx_used.
4426
* Calls iwl4965_rx_queue_restock to refill any empty
4433
* iwl4965_rx_queue_space - Return number of free slots available in queue.
4435
static int iwl4965_rx_queue_space(const struct iwl4965_rx_queue *q)
4437
int s = q->read - q->write;
4440
/* keep some buffer to not confuse full and empty queue */
4448
* iwl4965_rx_queue_update_write_ptr - Update the write pointer for the RX queue
4450
int iwl4965_rx_queue_update_write_ptr(struct iwl4965_priv *priv, struct iwl4965_rx_queue *q)
4454
unsigned long flags;
4456
spin_lock_irqsave(&q->lock, flags);
4458
if (q->need_update == 0)
4461
/* If power-saving is in use, make sure device is awake */
4462
if (test_bit(STATUS_POWER_PMI, &priv->status)) {
4463
reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
4465
if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
4466
iwl4965_set_bit(priv, CSR_GP_CNTRL,
4467
CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
4471
rc = iwl4965_grab_nic_access(priv);
4475
/* Device expects a multiple of 8 */
4476
iwl4965_write_direct32(priv, FH_RSCSR_CHNL0_WPTR,
4478
iwl4965_release_nic_access(priv);
4480
/* Else device is assumed to be awake */
4482
/* Device expects a multiple of 8 */
4483
iwl4965_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7);
4489
spin_unlock_irqrestore(&q->lock, flags);
4494
* iwl4965_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
4496
static inline __le32 iwl4965_dma_addr2rbd_ptr(struct iwl4965_priv *priv,
4497
dma_addr_t dma_addr)
4499
return cpu_to_le32((u32)(dma_addr >> 8));
4504
* iwl4965_rx_queue_restock - refill RX queue from pre-allocated pool
4506
* If there are slots in the RX queue that need to be restocked,
4507
* and we have free pre-allocated buffers, fill the ranks as much
4508
* as we can, pulling from rx_free.
4510
* This moves the 'write' index forward to catch up with 'processed', and
4511
* also updates the memory address in the firmware to reference the new
4514
static int iwl4965_rx_queue_restock(struct iwl4965_priv *priv)
4516
struct iwl4965_rx_queue *rxq = &priv->rxq;
4517
struct list_head *element;
4518
struct iwl4965_rx_mem_buffer *rxb;
4519
unsigned long flags;
4522
spin_lock_irqsave(&rxq->lock, flags);
4523
write = rxq->write & ~0x7;
4524
while ((iwl4965_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
4525
/* Get next free Rx buffer, remove from free list */
4526
element = rxq->rx_free.next;
4527
rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list);
4530
/* Point to Rx buffer via next RBD in circular buffer */
4531
rxq->bd[rxq->write] = iwl4965_dma_addr2rbd_ptr(priv, rxb->dma_addr);
4532
rxq->queue[rxq->write] = rxb;
4533
rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
4536
spin_unlock_irqrestore(&rxq->lock, flags);
4537
/* If the pre-allocated buffer pool is dropping low, schedule to
4539
if (rxq->free_count <= RX_LOW_WATERMARK)
4540
queue_work(priv->workqueue, &priv->rx_replenish);
4543
/* If we've added more space for the firmware to place data, tell it.
4544
* Increment device's write pointer in multiples of 8. */
4545
if ((write != (rxq->write & ~0x7))
4546
|| (abs(rxq->write - rxq->read) > 7)) {
4547
spin_lock_irqsave(&rxq->lock, flags);
4548
rxq->need_update = 1;
4549
spin_unlock_irqrestore(&rxq->lock, flags);
4550
rc = iwl4965_rx_queue_update_write_ptr(priv, rxq);
4559
* iwl4965_rx_replenish - Move all used packet from rx_used to rx_free
4561
* When moving to rx_free an SKB is allocated for the slot.
4563
* Also restock the Rx queue via iwl4965_rx_queue_restock.
4564
* This is called as a scheduled work item (except for during initialization)
4566
static void iwl4965_rx_allocate(struct iwl4965_priv *priv)
4568
struct iwl4965_rx_queue *rxq = &priv->rxq;
4569
struct list_head *element;
4570
struct iwl4965_rx_mem_buffer *rxb;
4571
unsigned long flags;
4572
spin_lock_irqsave(&rxq->lock, flags);
4573
while (!list_empty(&rxq->rx_used)) {
4574
element = rxq->rx_used.next;
4575
rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list);
4577
/* Alloc a new receive buffer */
4579
alloc_skb(IWL_RX_BUF_SIZE, __GFP_NOWARN | GFP_ATOMIC);
4581
if (net_ratelimit())
4582
printk(KERN_CRIT DRV_NAME
4583
": Can not allocate SKB buffers\n");
4584
/* We don't reschedule replenish work here -- we will
4585
* call the restock method and if it still needs
4586
* more buffers it will schedule replenish */
4589
priv->alloc_rxb_skb++;
4592
/* Get physical address of RB/SKB */
4594
pci_map_single(priv->pci_dev, rxb->skb->data,
4595
IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4596
list_add_tail(&rxb->list, &rxq->rx_free);
4599
spin_unlock_irqrestore(&rxq->lock, flags);
4603
* this should be called while priv->lock is locked
4605
static void __iwl4965_rx_replenish(void *data)
4607
struct iwl4965_priv *priv = data;
4609
iwl4965_rx_allocate(priv);
4610
iwl4965_rx_queue_restock(priv);
4614
void iwl4965_rx_replenish(void *data)
4616
struct iwl4965_priv *priv = data;
4617
unsigned long flags;
4619
iwl4965_rx_allocate(priv);
4621
spin_lock_irqsave(&priv->lock, flags);
4622
iwl4965_rx_queue_restock(priv);
4623
spin_unlock_irqrestore(&priv->lock, flags);
4626
/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
4627
* If an SKB has been detached, the POOL needs to have its SKB set to NULL
4628
* This free routine walks the list of POOL entries and if SKB is set to
4629
* non NULL it is unmapped and freed
4631
static void iwl4965_rx_queue_free(struct iwl4965_priv *priv, struct iwl4965_rx_queue *rxq)
4634
for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4635
if (rxq->pool[i].skb != NULL) {
4636
pci_unmap_single(priv->pci_dev,
4637
rxq->pool[i].dma_addr,
4638
IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4639
dev_kfree_skb(rxq->pool[i].skb);
4643
pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd,
4648
int iwl4965_rx_queue_alloc(struct iwl4965_priv *priv)
4650
struct iwl4965_rx_queue *rxq = &priv->rxq;
4651
struct pci_dev *dev = priv->pci_dev;
4654
spin_lock_init(&rxq->lock);
4655
INIT_LIST_HEAD(&rxq->rx_free);
4656
INIT_LIST_HEAD(&rxq->rx_used);
4658
/* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
4659
rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr);
4663
/* Fill the rx_used queue with _all_ of the Rx buffers */
4664
for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
4665
list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4667
/* Set us so that we have processed and used all buffers, but have
4668
* not restocked the Rx queue with fresh buffers */
4669
rxq->read = rxq->write = 0;
4670
rxq->free_count = 0;
4671
rxq->need_update = 0;
4675
void iwl4965_rx_queue_reset(struct iwl4965_priv *priv, struct iwl4965_rx_queue *rxq)
4677
unsigned long flags;
4679
spin_lock_irqsave(&rxq->lock, flags);
4680
INIT_LIST_HEAD(&rxq->rx_free);
4681
INIT_LIST_HEAD(&rxq->rx_used);
4682
/* Fill the rx_used queue with _all_ of the Rx buffers */
4683
for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
4684
/* In the reset function, these buffers may have been allocated
4685
* to an SKB, so we need to unmap and free potential storage */
4686
if (rxq->pool[i].skb != NULL) {
4687
pci_unmap_single(priv->pci_dev,
4688
rxq->pool[i].dma_addr,
4689
IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4690
priv->alloc_rxb_skb--;
4691
dev_kfree_skb(rxq->pool[i].skb);
4692
rxq->pool[i].skb = NULL;
4694
list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4697
/* Set us so that we have processed and used all buffers, but have
4698
* not restocked the Rx queue with fresh buffers */
4699
rxq->read = rxq->write = 0;
4700
rxq->free_count = 0;
4701
spin_unlock_irqrestore(&rxq->lock, flags);
4704
/* Convert linear signal-to-noise ratio into dB */
4705
static u8 ratio2dB[100] = {
4706
/* 0 1 2 3 4 5 6 7 8 9 */
4707
0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
4708
20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
4709
26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
4710
29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
4711
32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
4712
34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
4713
36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
4714
37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
4715
38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
4716
39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
4719
/* Calculates a relative dB value from a ratio of linear
4720
* (i.e. not dB) signal levels.
4721
* Conversion assumes that levels are voltages (20*log), not powers (10*log). */
4722
int iwl4965_calc_db_from_ratio(int sig_ratio)
4724
/* 1000:1 or higher just report as 60 dB */
4725
if (sig_ratio >= 1000)
4728
/* 100:1 or higher, divide by 10 and use table,
4729
* add 20 dB to make up for divide by 10 */
4730
if (sig_ratio >= 100)
4731
return (20 + (int)ratio2dB[sig_ratio/10]);
4733
/* We shouldn't see this */
4737
/* Use table for ratios 1:1 - 99:1 */
4738
return (int)ratio2dB[sig_ratio];
4741
#define PERFECT_RSSI (-20) /* dBm */
4742
#define WORST_RSSI (-95) /* dBm */
4743
#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
4745
/* Calculate an indication of rx signal quality (a percentage, not dBm!).
4746
* See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
4747
* about formulas used below. */
4748
int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm)
4751
int degradation = PERFECT_RSSI - rssi_dbm;
4753
/* If we get a noise measurement, use signal-to-noise ratio (SNR)
4754
* as indicator; formula is (signal dbm - noise dbm).
4755
* SNR at or above 40 is a great signal (100%).
4756
* Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
4757
* Weakest usable signal is usually 10 - 15 dB SNR. */
4759
if (rssi_dbm - noise_dbm >= 40)
4761
else if (rssi_dbm < noise_dbm)
4763
sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
4765
/* Else use just the signal level.
4766
* This formula is a least squares fit of data points collected and
4767
* compared with a reference system that had a percentage (%) display
4768
* for signal quality. */
4770
sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
4771
(15 * RSSI_RANGE + 62 * degradation)) /
4772
(RSSI_RANGE * RSSI_RANGE);
4776
else if (sig_qual < 1)
4783
* iwl4965_rx_handle - Main entry function for receiving responses from uCode
4785
* Uses the priv->rx_handlers callback function array to invoke
4786
* the appropriate handlers, including command responses,
4787
* frame-received notifications, and other notifications.
4789
static void iwl4965_rx_handle(struct iwl4965_priv *priv)
4791
struct iwl4965_rx_mem_buffer *rxb;
4792
struct iwl4965_rx_packet *pkt;
4793
struct iwl4965_rx_queue *rxq = &priv->rxq;
4796
unsigned long flags;
4800
/* uCode's read index (stored in shared DRAM) indicates the last Rx
4801
* buffer that the driver may process (last buffer filled by ucode). */
4802
r = iwl4965_hw_get_rx_read(priv);
4805
/* Rx interrupt, but nothing sent from uCode */
4807
IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
4809
if (iwl4965_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
4813
rxb = rxq->queue[i];
4815
/* If an RXB doesn't have a Rx queue slot associated with it,
4816
* then a bug has been introduced in the queue refilling
4817
* routines -- catch it here */
4818
BUG_ON(rxb == NULL);
4820
rxq->queue[i] = NULL;
4822
pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
4824
PCI_DMA_FROMDEVICE);
4825
pkt = (struct iwl4965_rx_packet *)rxb->skb->data;
4827
/* Reclaim a command buffer only if this packet is a response
4828
* to a (driver-originated) command.
4829
* If the packet (e.g. Rx frame) originated from uCode,
4830
* there is no command buffer to reclaim.
4831
* Ucode should set SEQ_RX_FRAME bit if ucode-originated,
4832
* but apparently a few don't get set; catch them here. */
4833
reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
4834
(pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
4835
(pkt->hdr.cmd != REPLY_4965_RX) &&
4836
(pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
4837
(pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
4838
(pkt->hdr.cmd != REPLY_TX);
4840
/* Based on type of command response or notification,
4841
* handle those that need handling via function in
4842
* rx_handlers table. See iwl4965_setup_rx_handlers() */
4843
if (priv->rx_handlers[pkt->hdr.cmd]) {
4844
IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
4845
"r = %d, i = %d, %s, 0x%02x\n", r, i,
4846
get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
4847
priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
4849
/* No handling needed */
4850
IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
4851
"r %d i %d No handler needed for %s, 0x%02x\n",
4852
r, i, get_cmd_string(pkt->hdr.cmd),
4857
/* Invoke any callbacks, transfer the skb to caller, and
4858
* fire off the (possibly) blocking iwl4965_send_cmd()
4859
* as we reclaim the driver command queue */
4860
if (rxb && rxb->skb)
4861
iwl4965_tx_cmd_complete(priv, rxb);
4863
IWL_WARNING("Claim null rxb?\n");
4866
/* For now we just don't re-use anything. We can tweak this
4867
* later to try and re-use notification packets and SKBs that
4868
* fail to Rx correctly */
4869
if (rxb->skb != NULL) {
4870
priv->alloc_rxb_skb--;
4871
dev_kfree_skb_any(rxb->skb);
4875
pci_unmap_single(priv->pci_dev, rxb->dma_addr,
4876
IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4877
spin_lock_irqsave(&rxq->lock, flags);
4878
list_add_tail(&rxb->list, &priv->rxq.rx_used);
4879
spin_unlock_irqrestore(&rxq->lock, flags);
4880
i = (i + 1) & RX_QUEUE_MASK;
4881
/* If there are a lot of unused frames,
4882
* restock the Rx queue so ucode wont assert. */
4887
__iwl4965_rx_replenish(priv);
4893
/* Backtrack one entry */
4895
iwl4965_rx_queue_restock(priv);
4899
* iwl4965_tx_queue_update_write_ptr - Send new write index to hardware
4901
static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv,
4902
struct iwl4965_tx_queue *txq)
4906
int txq_id = txq->q.id;
4908
if (txq->need_update == 0)
4911
/* if we're trying to save power */
4912
if (test_bit(STATUS_POWER_PMI, &priv->status)) {
4913
/* wake up nic if it's powered down ...
4914
* uCode will wake up, and interrupt us again, so next
4915
* time we'll skip this part. */
4916
reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1);
4918
if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
4919
IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg);
4920
iwl4965_set_bit(priv, CSR_GP_CNTRL,
4921
CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
4925
/* restore this queue's parameters in nic hardware. */
4926
rc = iwl4965_grab_nic_access(priv);
4929
iwl4965_write_direct32(priv, HBUS_TARG_WRPTR,
4930
txq->q.write_ptr | (txq_id << 8));
4931
iwl4965_release_nic_access(priv);
4933
/* else not in power-save mode, uCode will never sleep when we're
4934
* trying to tx (during RFKILL, we're not trying to tx). */
4936
iwl4965_write32(priv, HBUS_TARG_WRPTR,
4937
txq->q.write_ptr | (txq_id << 8));
4939
txq->need_update = 0;
4944
#ifdef CONFIG_IWL4965_DEBUG
4945
static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd *rxon)
4947
IWL_DEBUG_RADIO("RX CONFIG:\n");
4948
iwl4965_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
4949
IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
4950
IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
4951
IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
4952
le32_to_cpu(rxon->filter_flags));
4953
IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
4954
IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
4955
rxon->ofdm_basic_rates);
4956
IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
4957
IWL_DEBUG_RADIO("u8[6] node_addr: " MAC_FMT "\n",
4958
MAC_ARG(rxon->node_addr));
4959
IWL_DEBUG_RADIO("u8[6] bssid_addr: " MAC_FMT "\n",
4960
MAC_ARG(rxon->bssid_addr));
4961
IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
4965
static void iwl4965_enable_interrupts(struct iwl4965_priv *priv)
4967
IWL_DEBUG_ISR("Enabling interrupts\n");
4968
set_bit(STATUS_INT_ENABLED, &priv->status);
4969
iwl4965_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
4972
static inline void iwl4965_disable_interrupts(struct iwl4965_priv *priv)
4974
clear_bit(STATUS_INT_ENABLED, &priv->status);
4976
/* disable interrupts from uCode/NIC to host */
4977
iwl4965_write32(priv, CSR_INT_MASK, 0x00000000);
4979
/* acknowledge/clear/reset any interrupts still pending
4980
* from uCode or flow handler (Rx/Tx DMA) */
4981
iwl4965_write32(priv, CSR_INT, 0xffffffff);
4982
iwl4965_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
4983
IWL_DEBUG_ISR("Disabled interrupts\n");
4986
static const char *desc_lookup(int i)
4994
return "BAD_CHECKSUM";
4996
return "NMI_INTERRUPT";
5000
return "FATAL_ERROR";
5006
#define ERROR_START_OFFSET (1 * sizeof(u32))
5007
#define ERROR_ELEM_SIZE (7 * sizeof(u32))
5009
static void iwl4965_dump_nic_error_log(struct iwl4965_priv *priv)
5012
u32 desc, time, count, base, data1;
5013
u32 blink1, blink2, ilink1, ilink2;
5016
base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
5018
if (!iwl4965_hw_valid_rtc_data_addr(base)) {
5019
IWL_ERROR("Not valid error log pointer 0x%08X\n", base);
5023
rc = iwl4965_grab_nic_access(priv);
5025
IWL_WARNING("Can not read from adapter at this time.\n");
5029
count = iwl4965_read_targ_mem(priv, base);
5031
if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
5032
IWL_ERROR("Start IWL Error Log Dump:\n");
5033
IWL_ERROR("Status: 0x%08lX, Config: %08X count: %d\n",
5034
priv->status, priv->config, count);
5037
desc = iwl4965_read_targ_mem(priv, base + 1 * sizeof(u32));
5038
blink1 = iwl4965_read_targ_mem(priv, base + 3 * sizeof(u32));
5039
blink2 = iwl4965_read_targ_mem(priv, base + 4 * sizeof(u32));
5040
ilink1 = iwl4965_read_targ_mem(priv, base + 5 * sizeof(u32));
5041
ilink2 = iwl4965_read_targ_mem(priv, base + 6 * sizeof(u32));
5042
data1 = iwl4965_read_targ_mem(priv, base + 7 * sizeof(u32));
5043
data2 = iwl4965_read_targ_mem(priv, base + 8 * sizeof(u32));
5044
line = iwl4965_read_targ_mem(priv, base + 9 * sizeof(u32));
5045
time = iwl4965_read_targ_mem(priv, base + 11 * sizeof(u32));
5047
IWL_ERROR("Desc Time "
5048
"data1 data2 line\n");
5049
IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n",
5050
desc_lookup(desc), desc, time, data1, data2, line);
5051
IWL_ERROR("blink1 blink2 ilink1 ilink2\n");
5052
IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2,
5055
iwl4965_release_nic_access(priv);
5058
#define EVENT_START_OFFSET (4 * sizeof(u32))
5061
* iwl4965_print_event_log - Dump error event log to syslog
5063
* NOTE: Must be called with iwl4965_grab_nic_access() already obtained!
5065
static void iwl4965_print_event_log(struct iwl4965_priv *priv, u32 start_idx,
5066
u32 num_events, u32 mode)
5069
u32 base; /* SRAM byte address of event log header */
5070
u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
5071
u32 ptr; /* SRAM byte address of log data */
5072
u32 ev, time, data; /* event log data */
5074
if (num_events == 0)
5077
base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
5080
event_size = 2 * sizeof(u32);
5082
event_size = 3 * sizeof(u32);
5084
ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
5086
/* "time" is actually "data" for mode 0 (no timestamp).
5087
* place event id # at far right for easier visual parsing. */
5088
for (i = 0; i < num_events; i++) {
5089
ev = iwl4965_read_targ_mem(priv, ptr);
5091
time = iwl4965_read_targ_mem(priv, ptr);
5094
IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */
5096
data = iwl4965_read_targ_mem(priv, ptr);
5098
IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev);
5103
static void iwl4965_dump_nic_event_log(struct iwl4965_priv *priv)
5106
u32 base; /* SRAM byte address of event log header */
5107
u32 capacity; /* event log capacity in # entries */
5108
u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
5109
u32 num_wraps; /* # times uCode wrapped to top of log */
5110
u32 next_entry; /* index of next entry to be written by uCode */
5111
u32 size; /* # entries that we'll print */
5113
base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
5114
if (!iwl4965_hw_valid_rtc_data_addr(base)) {
5115
IWL_ERROR("Invalid event log pointer 0x%08X\n", base);
5119
rc = iwl4965_grab_nic_access(priv);
5121
IWL_WARNING("Can not read from adapter at this time.\n");
5125
/* event log header */
5126
capacity = iwl4965_read_targ_mem(priv, base);
5127
mode = iwl4965_read_targ_mem(priv, base + (1 * sizeof(u32)));
5128
num_wraps = iwl4965_read_targ_mem(priv, base + (2 * sizeof(u32)));
5129
next_entry = iwl4965_read_targ_mem(priv, base + (3 * sizeof(u32)));
5131
size = num_wraps ? capacity : next_entry;
5133
/* bail out if nothing in log */
5135
IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
5136
iwl4965_release_nic_access(priv);
5140
IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
5143
/* if uCode has wrapped back to top of log, start at the oldest entry,
5144
* i.e the next one that uCode would fill. */
5146
iwl4965_print_event_log(priv, next_entry,
5147
capacity - next_entry, mode);
5149
/* (then/else) start at top of log */
5150
iwl4965_print_event_log(priv, 0, next_entry, mode);
5152
iwl4965_release_nic_access(priv);
5156
* iwl4965_irq_handle_error - called for HW or SW error interrupt from card
5158
static void iwl4965_irq_handle_error(struct iwl4965_priv *priv)
5160
/* Set the FW error flag -- cleared on iwl4965_down */
5161
set_bit(STATUS_FW_ERROR, &priv->status);
5163
/* Cancel currently queued command. */
5164
clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
5166
#ifdef CONFIG_IWL4965_DEBUG
5167
if (iwl4965_debug_level & IWL_DL_FW_ERRORS) {
5168
iwl4965_dump_nic_error_log(priv);
5169
iwl4965_dump_nic_event_log(priv);
5170
iwl4965_print_rx_config_cmd(&priv->staging_rxon);
5174
wake_up_interruptible(&priv->wait_command_queue);
5176
/* Keep the restart process from trying to send host
5177
* commands by clearing the INIT status bit */
5178
clear_bit(STATUS_READY, &priv->status);
5180
if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
5181
IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS,
5182
"Restarting adapter due to uCode error.\n");
5184
if (iwl4965_is_associated(priv)) {
5185
memcpy(&priv->recovery_rxon, &priv->active_rxon,
5186
sizeof(priv->recovery_rxon));
5187
priv->error_recovering = 1;
5189
queue_work(priv->workqueue, &priv->restart);
5193
static void iwl4965_error_recovery(struct iwl4965_priv *priv)
5195
unsigned long flags;
5197
memcpy(&priv->staging_rxon, &priv->recovery_rxon,
5198
sizeof(priv->staging_rxon));
5199
priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
5200
iwl4965_commit_rxon(priv);
5202
iwl4965_rxon_add_station(priv, priv->bssid, 1);
5204
spin_lock_irqsave(&priv->lock, flags);
5205
priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
5206
priv->error_recovering = 0;
5207
spin_unlock_irqrestore(&priv->lock, flags);
5210
static void iwl4965_irq_tasklet(struct iwl4965_priv *priv)
5212
u32 inta, handled = 0;
5214
unsigned long flags;
5215
#ifdef CONFIG_IWL4965_DEBUG
5219
spin_lock_irqsave(&priv->lock, flags);
5221
/* Ack/clear/reset pending uCode interrupts.
5222
* Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
5223
* and will clear only when CSR_FH_INT_STATUS gets cleared. */
5224
inta = iwl4965_read32(priv, CSR_INT);
5225
iwl4965_write32(priv, CSR_INT, inta);
5227
/* Ack/clear/reset pending flow-handler (DMA) interrupts.
5228
* Any new interrupts that happen after this, either while we're
5229
* in this tasklet, or later, will show up in next ISR/tasklet. */
5230
inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS);
5231
iwl4965_write32(priv, CSR_FH_INT_STATUS, inta_fh);
5233
#ifdef CONFIG_IWL4965_DEBUG
5234
if (iwl4965_debug_level & IWL_DL_ISR) {
5235
/* just for debug */
5236
inta_mask = iwl4965_read32(priv, CSR_INT_MASK);
5237
IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
5238
inta, inta_mask, inta_fh);
5242
/* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
5243
* atomic, make sure that inta covers all the interrupts that
5244
* we've discovered, even if FH interrupt came in just after
5245
* reading CSR_INT. */
5246
if (inta_fh & CSR_FH_INT_RX_MASK)
5247
inta |= CSR_INT_BIT_FH_RX;
5248
if (inta_fh & CSR_FH_INT_TX_MASK)
5249
inta |= CSR_INT_BIT_FH_TX;
5251
/* Now service all interrupt bits discovered above. */
5252
if (inta & CSR_INT_BIT_HW_ERR) {
5253
IWL_ERROR("Microcode HW error detected. Restarting.\n");
5255
/* Tell the device to stop sending interrupts */
5256
iwl4965_disable_interrupts(priv);
5258
iwl4965_irq_handle_error(priv);
5260
handled |= CSR_INT_BIT_HW_ERR;
5262
spin_unlock_irqrestore(&priv->lock, flags);
5267
#ifdef CONFIG_IWL4965_DEBUG
5268
if (iwl4965_debug_level & (IWL_DL_ISR)) {
5269
/* NIC fires this, but we don't use it, redundant with WAKEUP */
5270
if (inta & CSR_INT_BIT_MAC_CLK_ACTV)
5271
IWL_DEBUG_ISR("Microcode started or stopped.\n");
5273
/* Alive notification via Rx interrupt will do the real work */
5274
if (inta & CSR_INT_BIT_ALIVE)
5275
IWL_DEBUG_ISR("Alive interrupt\n");
5278
/* Safely ignore these bits for debug checks below */
5279
inta &= ~(CSR_INT_BIT_MAC_CLK_ACTV | CSR_INT_BIT_ALIVE);
5281
/* HW RF KILL switch toggled */
5282
if (inta & CSR_INT_BIT_RF_KILL) {
5284
if (!(iwl4965_read32(priv, CSR_GP_CNTRL) &
5285
CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
5288
IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL | IWL_DL_ISR,
5289
"RF_KILL bit toggled to %s.\n",
5290
hw_rf_kill ? "disable radio":"enable radio");
5292
/* Queue restart only if RF_KILL switch was set to "kill"
5293
* when we loaded driver, and is now set to "enable".
5294
* After we're Alive, RF_KILL gets handled by
5295
* iwl4965_rx_card_state_notif() */
5296
if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) {
5297
clear_bit(STATUS_RF_KILL_HW, &priv->status);
5298
queue_work(priv->workqueue, &priv->restart);
5301
handled |= CSR_INT_BIT_RF_KILL;
5304
/* Chip got too hot and stopped itself */
5305
if (inta & CSR_INT_BIT_CT_KILL) {
5306
IWL_ERROR("Microcode CT kill error detected.\n");
5307
handled |= CSR_INT_BIT_CT_KILL;
5310
/* Error detected by uCode */
5311
if (inta & CSR_INT_BIT_SW_ERR) {
5312
IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
5314
iwl4965_irq_handle_error(priv);
5315
handled |= CSR_INT_BIT_SW_ERR;
5318
/* uCode wakes up after power-down sleep */
5319
if (inta & CSR_INT_BIT_WAKEUP) {
5320
IWL_DEBUG_ISR("Wakeup interrupt\n");
5321
iwl4965_rx_queue_update_write_ptr(priv, &priv->rxq);
5322
iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[0]);
5323
iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[1]);
5324
iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[2]);
5325
iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[3]);
5326
iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[4]);
5327
iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[5]);
5329
handled |= CSR_INT_BIT_WAKEUP;
5332
/* All uCode command responses, including Tx command responses,
5333
* Rx "responses" (frame-received notification), and other
5334
* notifications from uCode come through here*/
5335
if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
5336
iwl4965_rx_handle(priv);
5337
handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
5340
if (inta & CSR_INT_BIT_FH_TX) {
5341
IWL_DEBUG_ISR("Tx interrupt\n");
5342
handled |= CSR_INT_BIT_FH_TX;
5345
if (inta & ~handled)
5346
IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
5348
if (inta & ~CSR_INI_SET_MASK) {
5349
IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
5350
inta & ~CSR_INI_SET_MASK);
5351
IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
5354
/* Re-enable all interrupts */
5355
iwl4965_enable_interrupts(priv);
5357
#ifdef CONFIG_IWL4965_DEBUG
5358
if (iwl4965_debug_level & (IWL_DL_ISR)) {
5359
inta = iwl4965_read32(priv, CSR_INT);
5360
inta_mask = iwl4965_read32(priv, CSR_INT_MASK);
5361
inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS);
5362
IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
5363
"flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
5366
spin_unlock_irqrestore(&priv->lock, flags);
5369
static irqreturn_t iwl4965_isr(int irq, void *data)
5371
struct iwl4965_priv *priv = data;
5372
u32 inta, inta_mask;
5377
spin_lock(&priv->lock);
5379
/* Disable (but don't clear!) interrupts here to avoid
5380
* back-to-back ISRs and sporadic interrupts from our NIC.
5381
* If we have something to service, the tasklet will re-enable ints.
5382
* If we *don't* have something, we'll re-enable before leaving here. */
5383
inta_mask = iwl4965_read32(priv, CSR_INT_MASK); /* just for debug */
5384
iwl4965_write32(priv, CSR_INT_MASK, 0x00000000);
5386
/* Discover which interrupts are active/pending */
5387
inta = iwl4965_read32(priv, CSR_INT);
5388
inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS);
5390
/* Ignore interrupt if there's nothing in NIC to service.
5391
* This may be due to IRQ shared with another device,
5392
* or due to sporadic interrupts thrown from our NIC. */
5393
if (!inta && !inta_fh) {
5394
IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
5398
if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
5399
/* Hardware disappeared. It might have already raised
5401
IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
5405
IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
5406
inta, inta_mask, inta_fh);
5408
/* iwl4965_irq_tasklet() will service interrupts and re-enable them */
5409
tasklet_schedule(&priv->irq_tasklet);
5412
spin_unlock(&priv->lock);
5416
/* re-enable interrupts here since we don't have anything to service. */
5417
iwl4965_enable_interrupts(priv);
5418
spin_unlock(&priv->lock);
5422
/************************** EEPROM BANDS ****************************
5424
* The iwl4965_eeprom_band definitions below provide the mapping from the
5425
* EEPROM contents to the specific channel number supported for each
5428
* For example, iwl4965_priv->eeprom.band_3_channels[4] from the band_3
5429
* definition below maps to physical channel 42 in the 5.2GHz spectrum.
5430
* The specific geography and calibration information for that channel
5431
* is contained in the eeprom map itself.
5433
* During init, we copy the eeprom information and channel map
5434
* information into priv->channel_info_24/52 and priv->channel_map_24/52
5436
* channel_map_24/52 provides the index in the channel_info array for a
5437
* given channel. We have to have two separate maps as there is channel
5438
* overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
5441
* A value of 0xff stored in the channel_map indicates that the channel
5442
* is not supported by the hardware at all.
5444
* A value of 0xfe in the channel_map indicates that the channel is not
5445
* valid for Tx with the current hardware. This means that
5446
* while the system can tune and receive on a given channel, it may not
5447
* be able to associate or transmit any frames on that
5448
* channel. There is no corresponding channel information for that
5451
*********************************************************************/
5454
static const u8 iwl4965_eeprom_band_1[14] = {
5455
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
5459
static const u8 iwl4965_eeprom_band_2[] = { /* 4915-5080MHz */
5460
183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
5463
static const u8 iwl4965_eeprom_band_3[] = { /* 5170-5320MHz */
5464
34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
5467
static const u8 iwl4965_eeprom_band_4[] = { /* 5500-5700MHz */
5468
100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
5471
static const u8 iwl4965_eeprom_band_5[] = { /* 5725-5825MHz */
5472
145, 149, 153, 157, 161, 165
5475
static u8 iwl4965_eeprom_band_6[] = { /* 2.4 FAT channel */
5479
static u8 iwl4965_eeprom_band_7[] = { /* 5.2 FAT channel */
5480
36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157
5483
static void iwl4965_init_band_reference(const struct iwl4965_priv *priv,
5485
int *eeprom_ch_count,
5486
const struct iwl4965_eeprom_channel
5488
const u8 **eeprom_ch_index)
5491
case 1: /* 2.4GHz band */
5492
*eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_1);
5493
*eeprom_ch_info = priv->eeprom.band_1_channels;
5494
*eeprom_ch_index = iwl4965_eeprom_band_1;
5496
case 2: /* 4.9GHz band */
5497
*eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_2);
5498
*eeprom_ch_info = priv->eeprom.band_2_channels;
5499
*eeprom_ch_index = iwl4965_eeprom_band_2;
5501
case 3: /* 5.2GHz band */
5502
*eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_3);
5503
*eeprom_ch_info = priv->eeprom.band_3_channels;
5504
*eeprom_ch_index = iwl4965_eeprom_band_3;
5506
case 4: /* 5.5GHz band */
5507
*eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_4);
5508
*eeprom_ch_info = priv->eeprom.band_4_channels;
5509
*eeprom_ch_index = iwl4965_eeprom_band_4;
5511
case 5: /* 5.7GHz band */
5512
*eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_5);
5513
*eeprom_ch_info = priv->eeprom.band_5_channels;
5514
*eeprom_ch_index = iwl4965_eeprom_band_5;
5516
case 6: /* 2.4GHz FAT channels */
5517
*eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_6);
5518
*eeprom_ch_info = priv->eeprom.band_24_channels;
5519
*eeprom_ch_index = iwl4965_eeprom_band_6;
5521
case 7: /* 5 GHz FAT channels */
5522
*eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_7);
5523
*eeprom_ch_info = priv->eeprom.band_52_channels;
5524
*eeprom_ch_index = iwl4965_eeprom_band_7;
5533
* iwl4965_get_channel_info - Find driver's private channel info
5535
* Based on band and channel number.
5537
const struct iwl4965_channel_info *iwl4965_get_channel_info(const struct iwl4965_priv *priv,
5538
int phymode, u16 channel)
5543
case MODE_IEEE80211A:
5544
for (i = 14; i < priv->channel_count; i++) {
5545
if (priv->channel_info[i].channel == channel)
5546
return &priv->channel_info[i];
5550
case MODE_IEEE80211B:
5551
case MODE_IEEE80211G:
5552
if (channel >= 1 && channel <= 14)
5553
return &priv->channel_info[channel - 1];
5561
#define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
5565
* iwl4965_init_channel_map - Set up driver's info for all possible channels
5567
static int iwl4965_init_channel_map(struct iwl4965_priv *priv)
5569
int eeprom_ch_count = 0;
5570
const u8 *eeprom_ch_index = NULL;
5571
const struct iwl4965_eeprom_channel *eeprom_ch_info = NULL;
5573
struct iwl4965_channel_info *ch_info;
5575
if (priv->channel_count) {
5576
IWL_DEBUG_INFO("Channel map already initialized.\n");
5580
if (priv->eeprom.version < 0x2f) {
5581
IWL_WARNING("Unsupported EEPROM version: 0x%04X\n",
5582
priv->eeprom.version);
5586
IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n");
5588
priv->channel_count =
5589
ARRAY_SIZE(iwl4965_eeprom_band_1) +
5590
ARRAY_SIZE(iwl4965_eeprom_band_2) +
5591
ARRAY_SIZE(iwl4965_eeprom_band_3) +
5592
ARRAY_SIZE(iwl4965_eeprom_band_4) +
5593
ARRAY_SIZE(iwl4965_eeprom_band_5);
5595
IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count);
5597
priv->channel_info = kzalloc(sizeof(struct iwl4965_channel_info) *
5598
priv->channel_count, GFP_KERNEL);
5599
if (!priv->channel_info) {
5600
IWL_ERROR("Could not allocate channel_info\n");
5601
priv->channel_count = 0;
5605
ch_info = priv->channel_info;
5607
/* Loop through the 5 EEPROM bands adding them in order to the
5608
* channel map we maintain (that contains additional information than
5609
* what just in the EEPROM) */
5610
for (band = 1; band <= 5; band++) {
5612
iwl4965_init_band_reference(priv, band, &eeprom_ch_count,
5613
&eeprom_ch_info, &eeprom_ch_index);
5615
/* Loop through each band adding each of the channels */
5616
for (ch = 0; ch < eeprom_ch_count; ch++) {
5617
ch_info->channel = eeprom_ch_index[ch];
5618
ch_info->phymode = (band == 1) ? MODE_IEEE80211B :
5621
/* permanently store EEPROM's channel regulatory flags
5622
* and max power in channel info database. */
5623
ch_info->eeprom = eeprom_ch_info[ch];
5625
/* Copy the run-time flags so they are there even on
5626
* invalid channels */
5627
ch_info->flags = eeprom_ch_info[ch].flags;
5629
if (!(is_channel_valid(ch_info))) {
5630
IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - "
5634
is_channel_a_band(ch_info) ?
5640
/* Initialize regulatory-based run-time data */
5641
ch_info->max_power_avg = ch_info->curr_txpow =
5642
eeprom_ch_info[ch].max_power_avg;
5643
ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
5644
ch_info->min_power = 0;
5646
IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x"
5647
" %ddBm): Ad-Hoc %ssupported\n",
5649
is_channel_a_band(ch_info) ?
5651
CHECK_AND_PRINT(IBSS),
5652
CHECK_AND_PRINT(ACTIVE),
5653
CHECK_AND_PRINT(RADAR),
5654
CHECK_AND_PRINT(WIDE),
5655
CHECK_AND_PRINT(NARROW),
5656
CHECK_AND_PRINT(DFS),
5657
eeprom_ch_info[ch].flags,
5658
eeprom_ch_info[ch].max_power_avg,
5659
((eeprom_ch_info[ch].
5660
flags & EEPROM_CHANNEL_IBSS)
5661
&& !(eeprom_ch_info[ch].
5662
flags & EEPROM_CHANNEL_RADAR))
5665
/* Set the user_txpower_limit to the highest power
5666
* supported by any channel */
5667
if (eeprom_ch_info[ch].max_power_avg >
5668
priv->user_txpower_limit)
5669
priv->user_txpower_limit =
5670
eeprom_ch_info[ch].max_power_avg;
5676
/* Two additional EEPROM bands for 2.4 and 5 GHz FAT channels */
5677
for (band = 6; band <= 7; band++) {
5679
u8 fat_extension_chan;
5681
iwl4965_init_band_reference(priv, band, &eeprom_ch_count,
5682
&eeprom_ch_info, &eeprom_ch_index);
5684
/* EEPROM band 6 is 2.4, band 7 is 5 GHz */
5685
phymode = (band == 6) ? MODE_IEEE80211B : MODE_IEEE80211A;
5687
/* Loop through each band adding each of the channels */
5688
for (ch = 0; ch < eeprom_ch_count; ch++) {
5691
((eeprom_ch_index[ch] == 5) ||
5692
(eeprom_ch_index[ch] == 6) ||
5693
(eeprom_ch_index[ch] == 7)))
5694
fat_extension_chan = HT_IE_EXT_CHANNEL_MAX;
5696
fat_extension_chan = HT_IE_EXT_CHANNEL_ABOVE;
5698
/* Set up driver's info for lower half */
5699
iwl4965_set_fat_chan_info(priv, phymode,
5700
eeprom_ch_index[ch],
5701
&(eeprom_ch_info[ch]),
5702
fat_extension_chan);
5704
/* Set up driver's info for upper half */
5705
iwl4965_set_fat_chan_info(priv, phymode,
5706
(eeprom_ch_index[ch] + 4),
5707
&(eeprom_ch_info[ch]),
5708
HT_IE_EXT_CHANNEL_BELOW);
5715
/* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
5716
* sending probe req. This should be set long enough to hear probe responses
5717
* from more than one AP. */
5718
#define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
5719
#define IWL_ACTIVE_DWELL_TIME_52 (10)
5721
/* For faster active scanning, scan will move to the next channel if fewer than
5722
* PLCP_QUIET_THRESH packets are heard on this channel within
5723
* ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
5724
* time if it's a quiet channel (nothing responded to our probe, and there's
5725
* no other traffic).
5726
* Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
5727
#define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
5728
#define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
5730
/* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
5731
* Must be set longer than active dwell time.
5732
* For the most reliable scan, set > AP beacon interval (typically 100msec). */
5733
#define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
5734
#define IWL_PASSIVE_DWELL_TIME_52 (10)
5735
#define IWL_PASSIVE_DWELL_BASE (100)
5736
#define IWL_CHANNEL_TUNE_TIME 5
5738
static inline u16 iwl4965_get_active_dwell_time(struct iwl4965_priv *priv, int phymode)
5740
if (phymode == MODE_IEEE80211A)
5741
return IWL_ACTIVE_DWELL_TIME_52;
5743
return IWL_ACTIVE_DWELL_TIME_24;
5746
static u16 iwl4965_get_passive_dwell_time(struct iwl4965_priv *priv, int phymode)
5748
u16 active = iwl4965_get_active_dwell_time(priv, phymode);
5749
u16 passive = (phymode != MODE_IEEE80211A) ?
5750
IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
5751
IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
5753
if (iwl4965_is_associated(priv)) {
5754
/* If we're associated, we clamp the maximum passive
5755
* dwell time to be 98% of the beacon interval (minus
5756
* 2 * channel tune time) */
5757
passive = priv->beacon_int;
5758
if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive)
5759
passive = IWL_PASSIVE_DWELL_BASE;
5760
passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
5763
if (passive <= active)
5764
passive = active + 1;
5769
static int iwl4965_get_channels_for_scan(struct iwl4965_priv *priv, int phymode,
5770
u8 is_active, u8 direct_mask,
5771
struct iwl4965_scan_channel *scan_ch)
5773
const struct ieee80211_channel *channels = NULL;
5774
const struct ieee80211_hw_mode *hw_mode;
5775
const struct iwl4965_channel_info *ch_info;
5776
u16 passive_dwell = 0;
5777
u16 active_dwell = 0;
5780
hw_mode = iwl4965_get_hw_mode(priv, phymode);
5784
channels = hw_mode->channels;
5786
active_dwell = iwl4965_get_active_dwell_time(priv, phymode);
5787
passive_dwell = iwl4965_get_passive_dwell_time(priv, phymode);
5789
for (i = 0, added = 0; i < hw_mode->num_channels; i++) {
5790
if (channels[i].chan ==
5791
le16_to_cpu(priv->active_rxon.channel)) {
5792
if (iwl4965_is_associated(priv)) {
5794
("Skipping current channel %d\n",
5795
le16_to_cpu(priv->active_rxon.channel));
5798
} else if (priv->only_active_channel)
5801
scan_ch->channel = channels[i].chan;
5803
ch_info = iwl4965_get_channel_info(priv, phymode,
5805
if (!is_channel_valid(ch_info)) {
5806
IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
5811
if (!is_active || is_channel_passive(ch_info) ||
5812
!(channels[i].flag & IEEE80211_CHAN_W_ACTIVE_SCAN))
5813
scan_ch->type = 0; /* passive */
5815
scan_ch->type = 1; /* active */
5817
if (scan_ch->type & 1)
5818
scan_ch->type |= (direct_mask << 1);
5820
if (is_channel_narrow(ch_info))
5821
scan_ch->type |= (1 << 7);
5823
scan_ch->active_dwell = cpu_to_le16(active_dwell);
5824
scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
5826
/* Set txpower levels to defaults */
5827
scan_ch->tpc.dsp_atten = 110;
5828
/* scan_pwr_info->tpc.dsp_atten; */
5830
/*scan_pwr_info->tpc.tx_gain; */
5831
if (phymode == MODE_IEEE80211A)
5832
scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
5834
scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
5835
/* NOTE: if we were doing 6Mb OFDM for scans we'd use
5837
* scan_ch->tpc.tx_gain = ((1<<5) | (2 << 3)) | 3;
5841
IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
5843
(scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
5844
(scan_ch->type & 1) ?
5845
active_dwell : passive_dwell);
5851
IWL_DEBUG_SCAN("total channels to scan %d \n", added);
5855
static void iwl4965_reset_channel_flag(struct iwl4965_priv *priv)
5858
for (i = 0; i < 3; i++) {
5859
struct ieee80211_hw_mode *hw_mode = (void *)&priv->modes[i];
5860
for (j = 0; j < hw_mode->num_channels; j++)
5861
hw_mode->channels[j].flag = hw_mode->channels[j].val;
5865
static void iwl4965_init_hw_rates(struct iwl4965_priv *priv,
5866
struct ieee80211_rate *rates)
5870
for (i = 0; i < IWL_RATE_COUNT; i++) {
5871
rates[i].rate = iwl4965_rates[i].ieee * 5;
5872
rates[i].val = i; /* Rate scaling will work on indexes */
5874
rates[i].flags = IEEE80211_RATE_SUPPORTED;
5875
/* Only OFDM have the bits-per-symbol set */
5876
if ((i <= IWL_LAST_OFDM_RATE) && (i >= IWL_FIRST_OFDM_RATE))
5877
rates[i].flags |= IEEE80211_RATE_OFDM;
5880
* If CCK 1M then set rate flag to CCK else CCK_2
5881
* which is CCK | PREAMBLE2
5883
rates[i].flags |= (iwl4965_rates[i].plcp == 10) ?
5884
IEEE80211_RATE_CCK : IEEE80211_RATE_CCK_2;
5887
/* Set up which ones are basic rates... */
5888
if (IWL_BASIC_RATES_MASK & (1 << i))
5889
rates[i].flags |= IEEE80211_RATE_BASIC;
5894
* iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom
5896
static int iwl4965_init_geos(struct iwl4965_priv *priv)
5898
struct iwl4965_channel_info *ch;
5899
struct ieee80211_hw_mode *modes;
5900
struct ieee80211_channel *channels;
5901
struct ieee80211_channel *geo_ch;
5902
struct ieee80211_rate *rates;
5914
IWL_DEBUG_INFO("Geography modes already initialized.\n");
5915
set_bit(STATUS_GEO_CONFIGURED, &priv->status);
5919
modes = kzalloc(sizeof(struct ieee80211_hw_mode) * mode_count,
5924
channels = kzalloc(sizeof(struct ieee80211_channel) *
5925
priv->channel_count, GFP_KERNEL);
5931
rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_MAX_RATES + 1)),
5944
/* 5.2GHz channels start after the 2.4GHz channels */
5945
modes[A].mode = MODE_IEEE80211A;
5946
modes[A].channels = &channels[ARRAY_SIZE(iwl4965_eeprom_band_1)];
5947
modes[A].rates = rates;
5948
modes[A].num_rates = 8; /* just OFDM */
5949
modes[A].rates = &rates[4];
5950
modes[A].num_channels = 0;
5952
modes[B].mode = MODE_IEEE80211B;
5953
modes[B].channels = channels;
5954
modes[B].rates = rates;
5955
modes[B].num_rates = 4; /* just CCK */
5956
modes[B].num_channels = 0;
5958
modes[G].mode = MODE_IEEE80211G;
5959
modes[G].channels = channels;
5960
modes[G].rates = rates;
5961
modes[G].num_rates = 12; /* OFDM & CCK */
5962
modes[G].num_channels = 0;
5964
modes[G_11N].mode = MODE_IEEE80211G;
5965
modes[G_11N].channels = channels;
5966
modes[G_11N].num_rates = 13; /* OFDM & CCK */
5967
modes[G_11N].rates = rates;
5968
modes[G_11N].num_channels = 0;
5970
modes[A_11N].mode = MODE_IEEE80211A;
5971
modes[A_11N].channels = &channels[ARRAY_SIZE(iwl4965_eeprom_band_1)];
5972
modes[A_11N].rates = &rates[4];
5973
modes[A_11N].num_rates = 9; /* just OFDM */
5974
modes[A_11N].num_channels = 0;
5976
priv->ieee_channels = channels;
5977
priv->ieee_rates = rates;
5979
iwl4965_init_hw_rates(priv, rates);
5981
for (i = 0, geo_ch = channels; i < priv->channel_count; i++) {
5982
ch = &priv->channel_info[i];
5984
if (!is_channel_valid(ch)) {
5985
IWL_DEBUG_INFO("Channel %d [%sGHz] is restricted -- "
5987
ch->channel, is_channel_a_band(ch) ?
5992
if (is_channel_a_band(ch)) {
5993
geo_ch = &modes[A].channels[modes[A].num_channels++];
5994
modes[A_11N].num_channels++;
5996
geo_ch = &modes[B].channels[modes[B].num_channels++];
5997
modes[G].num_channels++;
5998
modes[G_11N].num_channels++;
6001
geo_ch->freq = ieee80211chan2mhz(ch->channel);
6002
geo_ch->chan = ch->channel;
6003
geo_ch->power_level = ch->max_power_avg;
6004
geo_ch->antenna_max = 0xff;
6006
if (is_channel_valid(ch)) {
6007
geo_ch->flag = IEEE80211_CHAN_W_SCAN;
6008
if (ch->flags & EEPROM_CHANNEL_IBSS)
6009
geo_ch->flag |= IEEE80211_CHAN_W_IBSS;
6011
if (ch->flags & EEPROM_CHANNEL_ACTIVE)
6012
geo_ch->flag |= IEEE80211_CHAN_W_ACTIVE_SCAN;
6014
if (ch->flags & EEPROM_CHANNEL_RADAR)
6015
geo_ch->flag |= IEEE80211_CHAN_W_RADAR_DETECT;
6017
if (ch->max_power_avg > priv->max_channel_txpower_limit)
6018
priv->max_channel_txpower_limit =
6022
geo_ch->val = geo_ch->flag;
6025
if ((modes[A].num_channels == 0) && priv->is_abg) {
6026
printk(KERN_INFO DRV_NAME
6027
": Incorrectly detected BG card as ABG. Please send "
6028
"your PCI ID 0x%04X:0x%04X to maintainer.\n",
6029
priv->pci_dev->device, priv->pci_dev->subsystem_device);
6033
printk(KERN_INFO DRV_NAME
6034
": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
6035
modes[G].num_channels, modes[A].num_channels);
6038
* NOTE: We register these in preference of order -- the
6039
* stack doesn't currently (as of 7.0.6 / Apr 24 '07) pick
6040
* a phymode based on rates or AP capabilities but seems to
6041
* configure it purely on if the channel being configured
6042
* is supported by a mode -- and the first match is taken
6045
if (modes[G].num_channels)
6046
iwlwifi_iwlwifi_ieee80211_register_hwmode(priv->hw, &modes[G]);
6047
if (modes[B].num_channels)
6048
iwlwifi_iwlwifi_ieee80211_register_hwmode(priv->hw, &modes[B]);
6049
if (modes[A].num_channels)
6050
iwlwifi_iwlwifi_ieee80211_register_hwmode(priv->hw, &modes[A]);
6052
priv->modes = modes;
6053
set_bit(STATUS_GEO_CONFIGURED, &priv->status);
6058
/******************************************************************************
6060
* uCode download functions
6062
******************************************************************************/
6064
static void iwl4965_dealloc_ucode_pci(struct iwl4965_priv *priv)
6066
iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
6067
iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
6068
iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
6069
iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
6070
iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
6071
iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
6075
* iwl4965_verify_inst_full - verify runtime uCode image in card vs. host,
6076
* looking at all data.
6078
static int iwl4965_verify_inst_full(struct iwl4965_priv *priv, __le32 * image,
6086
IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
6088
rc = iwl4965_grab_nic_access(priv);
6092
iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND);
6095
for (; len > 0; len -= sizeof(u32), image++) {
6096
/* read data comes through single port, auto-incr addr */
6097
/* NOTE: Use the debugless read so we don't flood kernel log
6098
* if IWL_DL_IO is set */
6099
val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT);
6100
if (val != le32_to_cpu(*image)) {
6101
IWL_ERROR("uCode INST section is invalid at "
6102
"offset 0x%x, is 0x%x, s/b 0x%x\n",
6103
save_len - len, val, le32_to_cpu(*image));
6111
iwl4965_release_nic_access(priv);
6115
("ucode image in INSTRUCTION memory is good\n");
6122
* iwl4965_verify_inst_sparse - verify runtime uCode image in card vs. host,
6123
* using sample data 100 bytes apart. If these sample points are good,
6124
* it's a pretty good bet that everything between them is good, too.
6126
static int iwl4965_verify_inst_sparse(struct iwl4965_priv *priv, __le32 *image, u32 len)
6133
IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
6135
rc = iwl4965_grab_nic_access(priv);
6139
for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
6140
/* read data comes through single port, auto-incr addr */
6141
/* NOTE: Use the debugless read so we don't flood kernel log
6142
* if IWL_DL_IO is set */
6143
iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR,
6144
i + RTC_INST_LOWER_BOUND);
6145
val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT);
6146
if (val != le32_to_cpu(*image)) {
6147
#if 0 /* Enable this if you want to see details */
6148
IWL_ERROR("uCode INST section is invalid at "
6149
"offset 0x%x, is 0x%x, s/b 0x%x\n",
6159
iwl4965_release_nic_access(priv);
6166
* iwl4965_verify_ucode - determine which instruction image is in SRAM,
6167
* and verify its contents
6169
static int iwl4965_verify_ucode(struct iwl4965_priv *priv)
6176
image = (__le32 *)priv->ucode_boot.v_addr;
6177
len = priv->ucode_boot.len;
6178
rc = iwl4965_verify_inst_sparse(priv, image, len);
6180
IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
6184
/* Try initialize */
6185
image = (__le32 *)priv->ucode_init.v_addr;
6186
len = priv->ucode_init.len;
6187
rc = iwl4965_verify_inst_sparse(priv, image, len);
6189
IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
6193
/* Try runtime/protocol */
6194
image = (__le32 *)priv->ucode_code.v_addr;
6195
len = priv->ucode_code.len;
6196
rc = iwl4965_verify_inst_sparse(priv, image, len);
6198
IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
6202
IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
6204
/* Since nothing seems to match, show first several data entries in
6205
* instruction SRAM, so maybe visual inspection will give a clue.
6206
* Selection of bootstrap image (vs. other images) is arbitrary. */
6207
image = (__le32 *)priv->ucode_boot.v_addr;
6208
len = priv->ucode_boot.len;
6209
rc = iwl4965_verify_inst_full(priv, image, len);
6215
/* check contents of special bootstrap uCode SRAM */
6216
static int iwl4965_verify_bsm(struct iwl4965_priv *priv)
6218
__le32 *image = priv->ucode_boot.v_addr;
6219
u32 len = priv->ucode_boot.len;
6223
IWL_DEBUG_INFO("Begin verify bsm\n");
6225
/* verify BSM SRAM contents */
6226
val = iwl4965_read_prph(priv, BSM_WR_DWCOUNT_REG);
6227
for (reg = BSM_SRAM_LOWER_BOUND;
6228
reg < BSM_SRAM_LOWER_BOUND + len;
6229
reg += sizeof(u32), image ++) {
6230
val = iwl4965_read_prph(priv, reg);
6231
if (val != le32_to_cpu(*image)) {
6232
IWL_ERROR("BSM uCode verification failed at "
6233
"addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
6234
BSM_SRAM_LOWER_BOUND,
6235
reg - BSM_SRAM_LOWER_BOUND, len,
6236
val, le32_to_cpu(*image));
6241
IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
6247
* iwl4965_load_bsm - Load bootstrap instructions
6251
* The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
6252
* in special SRAM that does not power down during RFKILL. When powering back
6253
* up after power-saving sleeps (or during initial uCode load), the BSM loads
6254
* the bootstrap program into the on-board processor, and starts it.
6256
* The bootstrap program loads (via DMA) instructions and data for a new
6257
* program from host DRAM locations indicated by the host driver in the
6258
* BSM_DRAM_* registers. Once the new program is loaded, it starts
6261
* When initializing the NIC, the host driver points the BSM to the
6262
* "initialize" uCode image. This uCode sets up some internal data, then
6263
* notifies host via "initialize alive" that it is complete.
6265
* The host then replaces the BSM_DRAM_* pointer values to point to the
6266
* normal runtime uCode instructions and a backup uCode data cache buffer
6267
* (filled initially with starting data values for the on-board processor),
6268
* then triggers the "initialize" uCode to load and launch the runtime uCode,
6269
* which begins normal operation.
6271
* When doing a power-save shutdown, runtime uCode saves data SRAM into
6272
* the backup data cache in DRAM before SRAM is powered down.
6274
* When powering back up, the BSM loads the bootstrap program. This reloads
6275
* the runtime uCode instructions and the backup data cache into SRAM,
6276
* and re-launches the runtime uCode from where it left off.
6278
static int iwl4965_load_bsm(struct iwl4965_priv *priv)
6280
__le32 *image = priv->ucode_boot.v_addr;
6281
u32 len = priv->ucode_boot.len;
6291
IWL_DEBUG_INFO("Begin load bsm\n");
6293
/* make sure bootstrap program is no larger than BSM's SRAM size */
6294
if (len > IWL_MAX_BSM_SIZE)
6297
/* Tell bootstrap uCode where to find the "Initialize" uCode
6298
* in host DRAM ... host DRAM physical address bits 35:4 for 4965.
6299
* NOTE: iwl4965_initialize_alive_start() will replace these values,
6300
* after the "initialize" uCode has run, to point to
6301
* runtime/protocol instructions and backup data cache. */
6302
pinst = priv->ucode_init.p_addr >> 4;
6303
pdata = priv->ucode_init_data.p_addr >> 4;
6304
inst_len = priv->ucode_init.len;
6305
data_len = priv->ucode_init_data.len;
6307
rc = iwl4965_grab_nic_access(priv);
6311
iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
6312
iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
6313
iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
6314
iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
6316
/* Fill BSM memory with bootstrap instructions */
6317
for (reg_offset = BSM_SRAM_LOWER_BOUND;
6318
reg_offset < BSM_SRAM_LOWER_BOUND + len;
6319
reg_offset += sizeof(u32), image++)
6320
_iwl4965_write_prph(priv, reg_offset,
6321
le32_to_cpu(*image));
6323
rc = iwl4965_verify_bsm(priv);
6325
iwl4965_release_nic_access(priv);
6329
/* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
6330
iwl4965_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0);
6331
iwl4965_write_prph(priv, BSM_WR_MEM_DST_REG,
6332
RTC_INST_LOWER_BOUND);
6333
iwl4965_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
6335
/* Load bootstrap code into instruction SRAM now,
6336
* to prepare to load "initialize" uCode */
6337
iwl4965_write_prph(priv, BSM_WR_CTRL_REG,
6338
BSM_WR_CTRL_REG_BIT_START);
6340
/* Wait for load of bootstrap uCode to finish */
6341
for (i = 0; i < 100; i++) {
6342
done = iwl4965_read_prph(priv, BSM_WR_CTRL_REG);
6343
if (!(done & BSM_WR_CTRL_REG_BIT_START))
6348
IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i);
6350
IWL_ERROR("BSM write did not complete!\n");
6354
/* Enable future boot loads whenever power management unit triggers it
6355
* (e.g. when powering back up after power-save shutdown) */
6356
iwl4965_write_prph(priv, BSM_WR_CTRL_REG,
6357
BSM_WR_CTRL_REG_BIT_START_EN);
6359
iwl4965_release_nic_access(priv);
6364
static void iwl4965_nic_start(struct iwl4965_priv *priv)
6366
/* Remove all resets to allow NIC to operate */
6367
iwl4965_write32(priv, CSR_RESET, 0);
6372
* iwl4965_read_ucode - Read uCode images from disk file.
6374
* Copy into buffers for card to fetch via bus-mastering
6376
static int iwl4965_read_ucode(struct iwl4965_priv *priv)
6378
struct iwl4965_ucode *ucode;
6380
const struct firmware *ucode_raw;
6381
const char *name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode";
6384
u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
6386
/* Ask kernel firmware_class module to get the boot firmware off disk.
6387
* request_firmware() is synchronous, file is in memory on return. */
6388
ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
6390
IWL_ERROR("%s firmware file req failed: Reason %d\n",
6395
IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
6396
name, ucode_raw->size);
6398
/* Make sure that we got at least our header! */
6399
if (ucode_raw->size < sizeof(*ucode)) {
6400
IWL_ERROR("File size way too small!\n");
6405
/* Data from ucode file: header followed by uCode images */
6406
ucode = (void *)ucode_raw->data;
6408
ver = le32_to_cpu(ucode->ver);
6409
inst_size = le32_to_cpu(ucode->inst_size);
6410
data_size = le32_to_cpu(ucode->data_size);
6411
init_size = le32_to_cpu(ucode->init_size);
6412
init_data_size = le32_to_cpu(ucode->init_data_size);
6413
boot_size = le32_to_cpu(ucode->boot_size);
6415
IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
6416
IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
6418
IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
6420
IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
6422
IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
6424
IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
6427
/* Verify size of file vs. image size info in file's header */
6428
if (ucode_raw->size < sizeof(*ucode) +
6429
inst_size + data_size + init_size +
6430
init_data_size + boot_size) {
6432
IWL_DEBUG_INFO("uCode file size %d too small\n",
6433
(int)ucode_raw->size);
6438
/* Verify that uCode images will fit in card's SRAM */
6439
if (inst_size > IWL_MAX_INST_SIZE) {
6440
IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
6446
if (data_size > IWL_MAX_DATA_SIZE) {
6447
IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
6452
if (init_size > IWL_MAX_INST_SIZE) {
6454
("uCode init instr len %d too large to fit in\n",
6459
if (init_data_size > IWL_MAX_DATA_SIZE) {
6461
("uCode init data len %d too large to fit in\n",
6466
if (boot_size > IWL_MAX_BSM_SIZE) {
6468
("uCode boot instr len %d too large to fit in\n",
6474
/* Allocate ucode buffers for card's bus-master loading ... */
6476
/* Runtime instructions and 2 copies of data:
6477
* 1) unmodified from disk
6478
* 2) backup cache for save/restore during power-downs */
6479
priv->ucode_code.len = inst_size;
6480
iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
6482
priv->ucode_data.len = data_size;
6483
iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
6485
priv->ucode_data_backup.len = data_size;
6486
iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
6488
/* Initialization instructions and data */
6489
if (init_size && init_data_size) {
6490
priv->ucode_init.len = init_size;
6491
iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
6493
priv->ucode_init_data.len = init_data_size;
6494
iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
6496
if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
6500
/* Bootstrap (instructions only, no data) */
6502
priv->ucode_boot.len = boot_size;
6503
iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
6505
if (!priv->ucode_boot.v_addr)
6509
/* Copy images into buffers for card's bus-master reads ... */
6511
/* Runtime instructions (first block of data in file) */
6512
src = &ucode->data[0];
6513
len = priv->ucode_code.len;
6514
IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
6515
memcpy(priv->ucode_code.v_addr, src, len);
6516
IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
6517
priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
6519
/* Runtime data (2nd block)
6520
* NOTE: Copy into backup buffer will be done in iwl4965_up() */
6521
src = &ucode->data[inst_size];
6522
len = priv->ucode_data.len;
6523
IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
6524
memcpy(priv->ucode_data.v_addr, src, len);
6525
memcpy(priv->ucode_data_backup.v_addr, src, len);
6527
/* Initialization instructions (3rd block) */
6529
src = &ucode->data[inst_size + data_size];
6530
len = priv->ucode_init.len;
6531
IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
6533
memcpy(priv->ucode_init.v_addr, src, len);
6536
/* Initialization data (4th block) */
6537
if (init_data_size) {
6538
src = &ucode->data[inst_size + data_size + init_size];
6539
len = priv->ucode_init_data.len;
6540
IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
6542
memcpy(priv->ucode_init_data.v_addr, src, len);
6545
/* Bootstrap instructions (5th block) */
6546
src = &ucode->data[inst_size + data_size + init_size + init_data_size];
6547
len = priv->ucode_boot.len;
6548
IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len);
6549
memcpy(priv->ucode_boot.v_addr, src, len);
6551
/* We have our copies now, allow OS release its copies */
6552
release_firmware(ucode_raw);
6556
IWL_ERROR("failed to allocate pci memory\n");
6558
iwl4965_dealloc_ucode_pci(priv);
6561
release_firmware(ucode_raw);
6569
* iwl4965_set_ucode_ptrs - Set uCode address location
6571
* Tell initialization uCode where to find runtime uCode.
6573
* BSM registers initially contain pointers to initialization uCode.
6574
* We need to replace them to load runtime uCode inst and data,
6575
* and to save runtime data when powering down.
6577
static int iwl4965_set_ucode_ptrs(struct iwl4965_priv *priv)
6582
unsigned long flags;
6584
/* bits 35:4 for 4965 */
6585
pinst = priv->ucode_code.p_addr >> 4;
6586
pdata = priv->ucode_data_backup.p_addr >> 4;
6588
spin_lock_irqsave(&priv->lock, flags);
6589
rc = iwl4965_grab_nic_access(priv);
6591
spin_unlock_irqrestore(&priv->lock, flags);
6595
/* Tell bootstrap uCode where to find image to load */
6596
iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
6597
iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
6598
iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
6599
priv->ucode_data.len);
6601
/* Inst bytecount must be last to set up, bit 31 signals uCode
6602
* that all new ptr/size info is in place */
6603
iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
6604
priv->ucode_code.len | BSM_DRAM_INST_LOAD);
6606
iwl4965_release_nic_access(priv);
6608
spin_unlock_irqrestore(&priv->lock, flags);
6610
IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
6616
* iwl4965_init_alive_start - Called after REPLY_ALIVE notification received
6618
* Called after REPLY_ALIVE notification received from "initialize" uCode.
6620
* The 4965 "initialize" ALIVE reply contains calibration data for:
6621
* Voltage, temperature, and MIMO tx gain correction, now stored in priv
6622
* (3945 does not contain this data).
6624
* Tell "initialize" uCode to go ahead and load the runtime uCode.
6626
static void iwl4965_init_alive_start(struct iwl4965_priv *priv)
6628
/* Check alive response for "valid" sign from uCode */
6629
if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
6630
/* We had an error bringing up the hardware, so take it
6631
* all the way back down so we can try again */
6632
IWL_DEBUG_INFO("Initialize Alive failed.\n");
6636
/* Bootstrap uCode has loaded initialize uCode ... verify inst image.
6637
* This is a paranoid check, because we would not have gotten the
6638
* "initialize" alive if code weren't properly loaded. */
6639
if (iwl4965_verify_ucode(priv)) {
6640
/* Runtime instruction load was bad;
6641
* take it all the way back down so we can try again */
6642
IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
6646
/* Calculate temperature */
6647
priv->temperature = iwl4965_get_temperature(priv);
6649
/* Send pointers to protocol/runtime uCode image ... init code will
6650
* load and launch runtime uCode, which will send us another "Alive"
6652
IWL_DEBUG_INFO("Initialization Alive received.\n");
6653
if (iwl4965_set_ucode_ptrs(priv)) {
6654
/* Runtime instruction load won't happen;
6655
* take it all the way back down so we can try again */
6656
IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
6662
queue_work(priv->workqueue, &priv->restart);
6667
* iwl4965_alive_start - called after REPLY_ALIVE notification received
6668
* from protocol/runtime uCode (initialization uCode's
6669
* Alive gets handled by iwl4965_init_alive_start()).
6671
static void iwl4965_alive_start(struct iwl4965_priv *priv)
6675
IWL_DEBUG_INFO("Runtime Alive received.\n");
6677
if (priv->card_alive.is_valid != UCODE_VALID_OK) {
6678
/* We had an error bringing up the hardware, so take it
6679
* all the way back down so we can try again */
6680
IWL_DEBUG_INFO("Alive failed.\n");
6684
/* Initialize uCode has loaded Runtime uCode ... verify inst image.
6685
* This is a paranoid check, because we would not have gotten the
6686
* "runtime" alive if code weren't properly loaded. */
6687
if (iwl4965_verify_ucode(priv)) {
6688
/* Runtime instruction load was bad;
6689
* take it all the way back down so we can try again */
6690
IWL_DEBUG_INFO("Bad runtime uCode load.\n");
6694
iwl4965_clear_stations_table(priv);
6696
rc = iwl4965_alive_notify(priv);
6698
IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
6703
/* After the ALIVE response, we can send host commands to 4965 uCode */
6704
set_bit(STATUS_ALIVE, &priv->status);
6706
/* Clear out the uCode error bit if it is set */
6707
clear_bit(STATUS_FW_ERROR, &priv->status);
6709
rc = iwl4965_init_channel_map(priv);
6711
IWL_ERROR("initializing regulatory failed: %d\n", rc);
6715
iwl4965_init_geos(priv);
6716
iwl4965_reset_channel_flag(priv);
6718
if (iwl4965_is_rfkill(priv))
6721
iwlwifi_ieee80211_start_queues(priv->hw);
6723
priv->active_rate = priv->rates_mask;
6724
priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
6726
iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode));
6728
if (iwl4965_is_associated(priv)) {
6729
struct iwl4965_rxon_cmd *active_rxon =
6730
(struct iwl4965_rxon_cmd *)(&priv->active_rxon);
6732
memcpy(&priv->staging_rxon, &priv->active_rxon,
6733
sizeof(priv->staging_rxon));
6734
active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
6736
/* Initialize our rx_config data */
6737
iwl4965_connection_init_rx_config(priv);
6738
memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
6741
/* Configure Bluetooth device coexistence support */
6742
iwl4965_send_bt_config(priv);
6744
/* Configure the adapter for unassociated operation */
6745
iwl4965_commit_rxon(priv);
6747
/* At this point, the NIC is initialized and operational */
6748
priv->notif_missed_beacons = 0;
6749
set_bit(STATUS_READY, &priv->status);
6751
iwl4965_rf_kill_ct_config(priv);
6753
iwl4965_led_register(priv);
6755
IWL_DEBUG_INFO("ALIVE processing complete.\n");
6756
wake_up_interruptible(&priv->wait_command_queue);
6758
if (priv->error_recovering)
6759
iwl4965_error_recovery(priv);
6764
queue_work(priv->workqueue, &priv->restart);
6767
static void iwl4965_cancel_deferred_work(struct iwl4965_priv *priv);
6769
static void __iwl4965_down(struct iwl4965_priv *priv)
6771
unsigned long flags;
6772
int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
6773
struct ieee80211_conf *conf = NULL;
6775
IWL_DEBUG_INFO(DRV_NAME " is going down\n");
6777
conf = ieee80211_get_hw_conf(priv->hw);
6780
set_bit(STATUS_EXIT_PENDING, &priv->status);
6782
iwl4965_led_unregister(priv);
6784
iwl4965_clear_stations_table(priv);
6786
/* Unblock any waiting calls */
6787
wake_up_interruptible_all(&priv->wait_command_queue);
6789
/* Wipe out the EXIT_PENDING status bit if we are not actually
6790
* exiting the module */
6792
clear_bit(STATUS_EXIT_PENDING, &priv->status);
6794
/* stop and reset the on-board processor */
6795
iwl4965_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
6797
/* tell the device to stop sending interrupts */
6798
iwl4965_disable_interrupts(priv);
6800
if (priv->mac80211_registered)
6801
iwlwifi_iwlwifi_ieee80211_stop_queues(priv->hw);
6803
/* If we have not previously called iwl4965_init() then
6804
* clear all bits but the RF Kill and SUSPEND bits and return */
6805
if (!iwl4965_is_init(priv)) {
6806
priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
6808
test_bit(STATUS_RF_KILL_SW, &priv->status) <<
6810
test_bit(STATUS_IN_SUSPEND, &priv->status) <<
6815
/* ...otherwise clear out all the status bits but the RF Kill and
6816
* SUSPEND bits and continue taking the NIC down. */
6817
priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
6819
test_bit(STATUS_RF_KILL_SW, &priv->status) <<
6821
test_bit(STATUS_IN_SUSPEND, &priv->status) <<
6823
test_bit(STATUS_FW_ERROR, &priv->status) <<
6826
spin_lock_irqsave(&priv->lock, flags);
6827
iwl4965_clear_bit(priv, CSR_GP_CNTRL,
6828
CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
6829
spin_unlock_irqrestore(&priv->lock, flags);
6831
iwl4965_hw_txq_ctx_stop(priv);
6832
iwl4965_hw_rxq_stop(priv);
6834
spin_lock_irqsave(&priv->lock, flags);
6835
if (!iwl4965_grab_nic_access(priv)) {
6836
iwl4965_write_prph(priv, APMG_CLK_DIS_REG,
6837
APMG_CLK_VAL_DMA_CLK_RQT);
6838
iwl4965_release_nic_access(priv);
6840
spin_unlock_irqrestore(&priv->lock, flags);
6844
iwl4965_hw_nic_stop_master(priv);
6845
iwl4965_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
6846
iwl4965_hw_nic_reset(priv);
6849
memset(&priv->card_alive, 0, sizeof(struct iwl4965_alive_resp));
6851
if (priv->ibss_beacon)
6852
dev_kfree_skb(priv->ibss_beacon);
6853
priv->ibss_beacon = NULL;
6855
/* clear out any free frames */
6856
iwl4965_clear_free_frames(priv);
6859
static void iwl4965_down(struct iwl4965_priv *priv)
6861
mutex_lock(&priv->mutex);
6862
__iwl4965_down(priv);
6863
mutex_unlock(&priv->mutex);
6865
iwl4965_cancel_deferred_work(priv);
6868
#define MAX_HW_RESTARTS 5
6870
static int __iwl4965_up(struct iwl4965_priv *priv)
6874
if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
6875
IWL_WARNING("Exit pending; will not bring the NIC up\n");
6879
if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
6880
IWL_WARNING("Radio disabled by SW RF kill (module "
6885
/* If platform's RF_KILL switch is NOT set to KILL */
6886
if (iwl4965_read32(priv, CSR_GP_CNTRL) &
6887
CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
6888
clear_bit(STATUS_RF_KILL_HW, &priv->status);
6890
set_bit(STATUS_RF_KILL_HW, &priv->status);
6891
if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
6892
IWL_WARNING("Radio disabled by HW RF Kill switch\n");
6897
iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF);
6899
rc = iwl4965_hw_nic_init(priv);
6901
IWL_ERROR("Unable to int nic\n");
6905
/* make sure rfkill handshake bits are cleared */
6906
iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
6907
iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR,
6908
CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
6910
/* clear (again), then enable host interrupts */
6911
iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF);
6912
iwl4965_enable_interrupts(priv);
6914
/* really make sure rfkill handshake bits are cleared */
6915
iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
6916
iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
6918
/* Copy original ucode data image from disk into backup cache.
6919
* This will be used to initialize the on-board processor's
6920
* data SRAM for a clean start when the runtime program first loads. */
6921
memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
6922
priv->ucode_data.len);
6924
/* We return success when we resume from suspend and rf_kill is on. */
6925
if (test_bit(STATUS_RF_KILL_HW, &priv->status))
6928
for (i = 0; i < MAX_HW_RESTARTS; i++) {
6930
iwl4965_clear_stations_table(priv);
6932
/* load bootstrap state machine,
6933
* load bootstrap program into processor's memory,
6934
* prepare to load the "initialize" uCode */
6935
rc = iwl4965_load_bsm(priv);
6938
IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc);
6942
/* start card; "initialize" will load runtime ucode */
6943
iwl4965_nic_start(priv);
6945
IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
6950
set_bit(STATUS_EXIT_PENDING, &priv->status);
6951
__iwl4965_down(priv);
6953
/* tried to restart and config the device for as long as our
6954
* patience could withstand */
6955
IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
6960
/*****************************************************************************
6962
* Workqueue callbacks
6964
*****************************************************************************/
6966
static void iwl4965_bg_init_alive_start(struct work_struct *data)
6968
struct iwl4965_priv *priv =
6969
container_of(data, struct iwl4965_priv, init_alive_start.work);
6971
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6974
mutex_lock(&priv->mutex);
6975
iwl4965_init_alive_start(priv);
6976
mutex_unlock(&priv->mutex);
6979
static void iwl4965_bg_alive_start(struct work_struct *data)
6981
struct iwl4965_priv *priv =
6982
container_of(data, struct iwl4965_priv, alive_start.work);
6984
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6987
mutex_lock(&priv->mutex);
6988
iwl4965_alive_start(priv);
6989
mutex_unlock(&priv->mutex);
6992
static void iwl4965_bg_rf_kill(struct work_struct *work)
6994
struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, rf_kill);
6996
wake_up_interruptible(&priv->wait_command_queue);
6998
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7001
mutex_lock(&priv->mutex);
7003
if (!iwl4965_is_rfkill(priv)) {
7004
IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL,
7005
"HW and/or SW RF Kill no longer active, restarting "
7007
if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
7008
queue_work(priv->workqueue, &priv->restart);
7011
if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
7012
IWL_DEBUG_RF_KILL("Can not turn radio back on - "
7013
"disabled by SW switch\n");
7015
IWL_WARNING("Radio Frequency Kill Switch is On:\n"
7016
"Kill switch must be turned off for "
7017
"wireless networking to work.\n");
7019
mutex_unlock(&priv->mutex);
7022
#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
7024
static void iwl4965_bg_scan_check(struct work_struct *data)
7026
struct iwl4965_priv *priv =
7027
container_of(data, struct iwl4965_priv, scan_check.work);
7029
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7032
mutex_lock(&priv->mutex);
7033
if (test_bit(STATUS_SCANNING, &priv->status) ||
7034
test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
7035
IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN,
7036
"Scan completion watchdog resetting adapter (%dms)\n",
7037
jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG));
7039
if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
7040
iwl4965_send_scan_abort(priv);
7042
mutex_unlock(&priv->mutex);
7045
static void iwl4965_bg_request_scan(struct work_struct *data)
7047
struct iwl4965_priv *priv =
7048
container_of(data, struct iwl4965_priv, request_scan);
7049
struct iwl4965_host_cmd cmd = {
7050
.id = REPLY_SCAN_CMD,
7051
.len = sizeof(struct iwl4965_scan_cmd),
7052
.meta.flags = CMD_SIZE_HUGE,
7055
struct iwl4965_scan_cmd *scan;
7056
struct ieee80211_conf *conf = NULL;
7060
conf = ieee80211_get_hw_conf(priv->hw);
7062
mutex_lock(&priv->mutex);
7064
if (!iwl4965_is_ready(priv)) {
7065
IWL_WARNING("request scan called when driver not ready.\n");
7069
/* Make sure the scan wasn't cancelled before this queued work
7070
* was given the chance to run... */
7071
if (!test_bit(STATUS_SCANNING, &priv->status))
7074
/* This should never be called or scheduled if there is currently
7075
* a scan active in the hardware. */
7076
if (test_bit(STATUS_SCAN_HW, &priv->status)) {
7077
IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
7078
"Ignoring second request.\n");
7083
if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
7084
IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
7088
if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
7089
IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
7093
if (iwl4965_is_rfkill(priv)) {
7094
IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
7098
if (!test_bit(STATUS_READY, &priv->status)) {
7099
IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
7103
if (!priv->scan_bands) {
7104
IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
7109
priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) +
7110
IWL_MAX_SCAN_SIZE, GFP_KERNEL);
7117
memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE);
7119
scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
7120
scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
7122
if (iwl4965_is_associated(priv)) {
7125
u32 suspend_time = 100;
7126
u32 scan_suspend_time = 100;
7127
unsigned long flags;
7129
IWL_DEBUG_INFO("Scanning while associated...\n");
7131
spin_lock_irqsave(&priv->lock, flags);
7132
interval = priv->beacon_int;
7133
spin_unlock_irqrestore(&priv->lock, flags);
7135
scan->suspend_time = 0;
7136
scan->max_out_time = cpu_to_le32(200 * 1024);
7138
interval = suspend_time;
7140
extra = (suspend_time / interval) << 22;
7141
scan_suspend_time = (extra |
7142
((suspend_time % interval) * 1024));
7143
scan->suspend_time = cpu_to_le32(scan_suspend_time);
7144
IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
7145
scan_suspend_time, interval);
7148
/* We should add the ability for user to lock to PASSIVE ONLY */
7149
if (priv->one_direct_scan) {
7151
("Kicking off one direct scan for '%s'\n",
7152
iwl4965_escape_essid(priv->direct_ssid,
7153
priv->direct_ssid_len));
7154
scan->direct_scan[0].id = WLAN_EID_SSID;
7155
scan->direct_scan[0].len = priv->direct_ssid_len;
7156
memcpy(scan->direct_scan[0].ssid,
7157
priv->direct_ssid, priv->direct_ssid_len);
7159
} else if (!iwl4965_is_associated(priv) && priv->essid_len) {
7160
scan->direct_scan[0].id = WLAN_EID_SSID;
7161
scan->direct_scan[0].len = priv->essid_len;
7162
memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
7167
/* We don't build a direct scan probe request; the uCode will do
7168
* that based on the direct_mask added to each channel entry */
7169
scan->tx_cmd.len = cpu_to_le16(
7170
iwl4965_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data,
7171
IWL_MAX_SCAN_SIZE - sizeof(scan), 0));
7172
scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
7173
scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id;
7174
scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
7176
/* flags + rate selection */
7178
scan->tx_cmd.tx_flags |= cpu_to_le32(0x200);
7180
switch (priv->scan_bands) {
7182
scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
7183
scan->tx_cmd.rate_n_flags =
7184
iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP,
7185
RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK);
7187
scan->good_CRC_th = 0;
7188
phymode = MODE_IEEE80211G;
7192
scan->tx_cmd.rate_n_flags =
7193
iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP,
7194
RATE_MCS_ANT_B_MSK);
7195
scan->good_CRC_th = IWL_GOOD_CRC_TH;
7196
phymode = MODE_IEEE80211A;
7200
IWL_WARNING("Invalid scan band count\n");
7204
/* select Rx chains */
7206
/* Force use of chains B and C (0x6) for scan Rx.
7207
* Avoid A (0x1) because of its off-channel reception on A-band.
7208
* MIMO is not used here, but value is required to make uCode happy. */
7209
scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK |
7210
cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) |
7211
(0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) |
7212
(0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS));
7214
if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR)
7215
scan->filter_flags = RXON_FILTER_PROMISC_MSK;
7219
("Initiating direct scan for %s.\n",
7220
iwl4965_escape_essid(priv->essid, priv->essid_len));
7222
IWL_DEBUG_SCAN("Initiating indirect scan.\n");
7224
scan->channel_count =
7225
iwl4965_get_channels_for_scan(
7226
priv, phymode, 1, /* active */
7228
(void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
7230
cmd.len += le16_to_cpu(scan->tx_cmd.len) +
7231
scan->channel_count * sizeof(struct iwl4965_scan_channel);
7233
scan->len = cpu_to_le16(cmd.len);
7235
set_bit(STATUS_SCAN_HW, &priv->status);
7236
rc = iwl4965_send_cmd_sync(priv, &cmd);
7240
queue_delayed_work(priv->workqueue, &priv->scan_check,
7241
IWL_SCAN_CHECK_WATCHDOG);
7243
mutex_unlock(&priv->mutex);
7247
/* inform mac80211 scan aborted */
7248
queue_work(priv->workqueue, &priv->scan_completed);
7249
mutex_unlock(&priv->mutex);
7252
static void iwl4965_bg_up(struct work_struct *data)
7254
struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, up);
7256
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7259
mutex_lock(&priv->mutex);
7261
mutex_unlock(&priv->mutex);
7264
static void iwl4965_bg_restart(struct work_struct *data)
7266
struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, restart);
7268
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7272
queue_work(priv->workqueue, &priv->up);
7275
static void iwl4965_bg_rx_replenish(struct work_struct *data)
7277
struct iwl4965_priv *priv =
7278
container_of(data, struct iwl4965_priv, rx_replenish);
7280
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7283
mutex_lock(&priv->mutex);
7284
iwl4965_rx_replenish(priv);
7285
mutex_unlock(&priv->mutex);
7288
#define IWL_DELAY_NEXT_SCAN (HZ*2)
7290
static void iwl4965_bg_post_associate(struct work_struct *data)
7292
struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv,
7293
post_associate.work);
7296
struct ieee80211_conf *conf = NULL;
7298
if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
7299
IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__);
7303
IWL_DEBUG_ASSOC("Associated as %d to: " MAC_FMT "\n",
7304
priv->assoc_id, MAC_ARG(priv->active_rxon.bssid_addr));
7307
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7310
mutex_lock(&priv->mutex);
7312
if (!priv->interface_id || !priv->is_open) {
7313
mutex_unlock(&priv->mutex);
7316
iwl4965_scan_cancel_timeout(priv, 200);
7318
conf = ieee80211_get_hw_conf(priv->hw);
7320
priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7321
iwl4965_commit_rxon(priv);
7323
memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
7324
iwl4965_setup_rxon_timing(priv);
7325
rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING,
7326
sizeof(priv->rxon_timing), &priv->rxon_timing);
7328
IWL_WARNING("REPLY_RXON_TIMING failed - "
7329
"Attempting to continue.\n");
7331
priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
7333
#ifdef CONFIG_IWL4965_HT
7334
if (priv->is_ht_enabled && priv->current_assoc_ht.is_ht)
7335
iwl4965_set_rxon_ht(priv, &priv->current_assoc_ht);
7337
priv->active_rate_ht[0] = 0;
7338
priv->active_rate_ht[1] = 0;
7339
priv->current_channel_width = IWL_CHANNEL_WIDTH_20MHZ;
7341
#endif /* CONFIG_IWL4965_HT*/
7342
iwl4965_set_rxon_chain(priv);
7343
priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
7345
IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
7346
priv->assoc_id, priv->beacon_int);
7348
if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7349
priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
7351
priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
7353
if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
7354
if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
7355
priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
7357
priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
7359
if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
7360
priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
7364
iwl4965_commit_rxon(priv);
7366
switch (priv->iw_mode) {
7367
case IEEE80211_IF_TYPE_STA:
7368
iwl4965_rate_scale_init(priv->hw, IWL_AP_ID);
7371
case IEEE80211_IF_TYPE_IBSS:
7373
/* clear out the station table */
7374
iwl4965_clear_stations_table(priv);
7376
iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0);
7377
iwl4965_rxon_add_station(priv, priv->bssid, 0);
7378
iwl4965_rate_scale_init(priv->hw, IWL_STA_ID);
7379
iwl4965_send_beacon_cmd(priv);
7384
IWL_ERROR("%s Should not be called in %d mode\n",
7385
__FUNCTION__, priv->iw_mode);
7389
iwl4965_sequence_reset(priv);
7391
#ifdef CONFIG_IWL4965_SENSITIVITY
7392
/* Enable Rx differential gain and sensitivity calibrations */
7393
iwl4965_chain_noise_reset(priv);
7394
priv->start_calib = 1;
7395
#endif /* CONFIG_IWL4965_SENSITIVITY */
7397
if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
7398
priv->assoc_station_added = 1;
7400
#ifdef CONFIG_IWL4965_QOS
7401
iwl4965_activate_qos(priv, 0);
7402
#endif /* CONFIG_IWL4965_QOS */
7403
/* we have just associated, don't start scan too early */
7404
priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
7405
mutex_unlock(&priv->mutex);
7408
static void iwl4965_bg_abort_scan(struct work_struct *work)
7410
struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, abort_scan);
7412
if (!iwl4965_is_ready(priv))
7415
mutex_lock(&priv->mutex);
7417
set_bit(STATUS_SCAN_ABORTING, &priv->status);
7418
iwl4965_send_scan_abort(priv);
7420
mutex_unlock(&priv->mutex);
7423
static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
7425
static void iwl4965_bg_scan_completed(struct work_struct *work)
7427
struct iwl4965_priv *priv =
7428
container_of(work, struct iwl4965_priv, scan_completed);
7430
IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n");
7432
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
7435
if (test_bit(STATUS_CONF_PENDING, &priv->status))
7436
iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw));
7438
iwlwifi_ieee80211_scan_completed(priv->hw);
7440
/* Since setting the TXPOWER may have been deferred while
7441
* performing the scan, fire one off */
7442
mutex_lock(&priv->mutex);
7443
iwl4965_hw_reg_send_txpower(priv);
7444
mutex_unlock(&priv->mutex);
7447
/*****************************************************************************
7449
* mac80211 entry point functions
7451
*****************************************************************************/
7453
#define UCODE_READY_TIMEOUT (2 * HZ)
7455
static int iwl4965_mac_open(struct ieee80211_hw *hw)
7457
struct iwl4965_priv *priv = hw->priv;
7460
IWL_DEBUG_MAC80211("enter\n");
7462
if (pci_enable_device(priv->pci_dev)) {
7463
IWL_ERROR("Fail to pci_enable_device\n");
7466
pci_restore_state(priv->pci_dev);
7467
pci_enable_msi(priv->pci_dev);
7469
ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED,
7472
IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq);
7473
goto out_disable_msi;
7476
/* we should be verifying the device is ready to be opened */
7477
mutex_lock(&priv->mutex);
7479
memset(&priv->staging_rxon, 0, sizeof(struct iwl4965_rxon_cmd));
7480
/* fetch ucode file from disk, alloc and copy to bus-master buffers ...
7481
* ucode filename and max sizes are card-specific. */
7483
if (!priv->ucode_code.len) {
7484
ret = iwl4965_read_ucode(priv);
7486
IWL_ERROR("Could not read microcode: %d\n", ret);
7487
mutex_unlock(&priv->mutex);
7488
goto out_release_irq;
7492
ret = __iwl4965_up(priv);
7494
mutex_unlock(&priv->mutex);
7497
goto out_release_irq;
7499
IWL_DEBUG_INFO("Start UP work done.\n");
7501
if (test_bit(STATUS_IN_SUSPEND, &priv->status))
7504
/* Wait for START_ALIVE from ucode. Otherwise callbacks from
7505
* mac80211 will not be run successfully. */
7506
ret = wait_event_interruptible_timeout(priv->wait_command_queue,
7507
test_bit(STATUS_READY, &priv->status),
7508
UCODE_READY_TIMEOUT);
7510
if (!test_bit(STATUS_READY, &priv->status)) {
7511
IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n",
7512
jiffies_to_msecs(UCODE_READY_TIMEOUT));
7514
goto out_release_irq;
7519
IWL_DEBUG_MAC80211("leave\n");
7523
free_irq(priv->pci_dev->irq, priv);
7525
pci_disable_msi(priv->pci_dev);
7526
pci_disable_device(priv->pci_dev);
7528
IWL_DEBUG_MAC80211("leave - failed\n");
7532
static int iwl4965_mac_stop(struct ieee80211_hw *hw)
7534
struct iwl4965_priv *priv = hw->priv;
7536
IWL_DEBUG_MAC80211("enter\n");
7538
if (!priv->is_open) {
7539
IWL_DEBUG_MAC80211("leave - skip\n");
7545
if (iwl4965_is_ready_rf(priv)) {
7546
/* stop mac, cancel any scan request and clear
7547
* RXON_FILTER_ASSOC_MSK BIT
7549
mutex_lock(&priv->mutex);
7550
iwl4965_scan_cancel_timeout(priv, 100);
7551
cancel_delayed_work(&priv->post_associate);
7552
mutex_unlock(&priv->mutex);
7557
flush_workqueue(priv->workqueue);
7558
free_irq(priv->pci_dev->irq, priv);
7559
pci_disable_msi(priv->pci_dev);
7560
pci_save_state(priv->pci_dev);
7561
pci_disable_device(priv->pci_dev);
7563
IWL_DEBUG_MAC80211("leave\n");
7567
static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
7568
struct ieee80211_tx_control *ctl)
7570
struct iwl4965_priv *priv = hw->priv;
7572
IWL_DEBUG_MAC80211("enter\n");
7574
if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
7575
IWL_DEBUG_MAC80211("leave - monitor\n");
7579
IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
7582
if (iwl4965_tx_skb(priv, skb, ctl))
7583
dev_kfree_skb_any(skb);
7585
IWL_DEBUG_MAC80211("leave\n");
7589
static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
7590
struct ieee80211_if_init_conf *conf)
7592
struct iwl4965_priv *priv = hw->priv;
7593
unsigned long flags;
7595
IWL_DEBUG_MAC80211("enter: id %d, type %d\n", conf->if_id, conf->type);
7597
if (priv->interface_id) {
7598
IWL_DEBUG_MAC80211("leave - interface_id != 0\n");
7602
spin_lock_irqsave(&priv->lock, flags);
7603
priv->interface_id = conf->if_id;
7605
spin_unlock_irqrestore(&priv->lock, flags);
7607
mutex_lock(&priv->mutex);
7609
if (conf->mac_addr) {
7610
IWL_DEBUG_MAC80211("Set: " MAC_FMT "\n", MAC_ARG(conf->mac_addr));
7611
memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
7614
if (iwl4965_is_ready(priv))
7615
iwl4965_set_mode(priv, conf->type);
7617
mutex_unlock(&priv->mutex);
7619
IWL_DEBUG_MAC80211("leave\n");
7624
* iwl4965_mac_config - mac80211 config callback
7626
* We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
7627
* be set inappropriately and the driver currently sets the hardware up to
7628
* use it whenever needed.
7630
static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
7632
struct iwl4965_priv *priv = hw->priv;
7633
const struct iwl4965_channel_info *ch_info;
7634
unsigned long flags;
7637
mutex_lock(&priv->mutex);
7638
IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel);
7640
if (!iwl4965_is_ready(priv)) {
7641
IWL_DEBUG_MAC80211("leave - not ready\n");
7646
/* TODO: Figure out how to get ieee80211_local->sta_scanning w/ only
7647
* what is exposed through include/ declarations */
7648
if (unlikely(!iwl4965_param_disable_hw_scan &&
7649
test_bit(STATUS_SCANNING, &priv->status))) {
7650
IWL_DEBUG_MAC80211("leave - scanning\n");
7651
set_bit(STATUS_CONF_PENDING, &priv->status);
7652
mutex_unlock(&priv->mutex);
7656
spin_lock_irqsave(&priv->lock, flags);
7658
ch_info = iwl4965_get_channel_info(priv, conf->phymode, conf->channel);
7659
if (!is_channel_valid(ch_info)) {
7660
IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n",
7661
conf->channel, conf->phymode);
7662
IWL_DEBUG_MAC80211("leave - invalid channel\n");
7663
spin_unlock_irqrestore(&priv->lock, flags);
7668
#ifdef CONFIG_IWL4965_HT
7669
/* if we are switching fron ht to 2.4 clear flags
7670
* from any ht related info since 2.4 does not
7672
if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel)
7673
#ifdef IEEE80211_CONF_CHANNEL_SWITCH
7674
&& !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
7677
priv->staging_rxon.flags = 0;
7678
#endif /* CONFIG_IWL4965_HT */
7680
iwl4965_set_rxon_channel(priv, conf->phymode, conf->channel);
7682
iwl4965_set_flags_for_phymode(priv, conf->phymode);
7684
/* The list of supported rates and rate mask can be different
7685
* for each phymode; since the phymode may have changed, reset
7686
* the rate mask to what mac80211 lists */
7687
iwl4965_set_rate(priv);
7689
spin_unlock_irqrestore(&priv->lock, flags);
7691
#ifdef IEEE80211_CONF_CHANNEL_SWITCH
7692
if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
7693
iwl4965_hw_channel_switch(priv, conf->channel);
7698
iwl4965_radio_kill_sw(priv, !conf->radio_enabled);
7700
if (!conf->radio_enabled) {
7701
IWL_DEBUG_MAC80211("leave - radio disabled\n");
7705
if (iwl4965_is_rfkill(priv)) {
7706
IWL_DEBUG_MAC80211("leave - RF kill\n");
7711
iwl4965_set_rate(priv);
7713
if (memcmp(&priv->active_rxon,
7714
&priv->staging_rxon, sizeof(priv->staging_rxon)))
7715
iwl4965_commit_rxon(priv);
7717
IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
7719
IWL_DEBUG_MAC80211("leave\n");
7722
clear_bit(STATUS_CONF_PENDING, &priv->status);
7723
mutex_unlock(&priv->mutex);
7727
static void iwl4965_config_ap(struct iwl4965_priv *priv)
7731
if (priv->status & STATUS_EXIT_PENDING)
7734
/* The following should be done only at AP bring up */
7735
if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) {
7737
/* RXON - unassoc (to set timing command) */
7738
priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7739
iwl4965_commit_rxon(priv);
7742
memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
7743
iwl4965_setup_rxon_timing(priv);
7744
rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING,
7745
sizeof(priv->rxon_timing), &priv->rxon_timing);
7747
IWL_WARNING("REPLY_RXON_TIMING failed - "
7748
"Attempting to continue.\n");
7750
iwl4965_set_rxon_chain(priv);
7752
/* FIXME: what should be the assoc_id for AP? */
7753
priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
7754
if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7755
priv->staging_rxon.flags |=
7756
RXON_FLG_SHORT_PREAMBLE_MSK;
7758
priv->staging_rxon.flags &=
7759
~RXON_FLG_SHORT_PREAMBLE_MSK;
7761
if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
7762
if (priv->assoc_capability &
7763
WLAN_CAPABILITY_SHORT_SLOT_TIME)
7764
priv->staging_rxon.flags |=
7765
RXON_FLG_SHORT_SLOT_MSK;
7767
priv->staging_rxon.flags &=
7768
~RXON_FLG_SHORT_SLOT_MSK;
7770
if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
7771
priv->staging_rxon.flags &=
7772
~RXON_FLG_SHORT_SLOT_MSK;
7774
/* restore RXON assoc */
7775
priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
7776
iwl4965_commit_rxon(priv);
7777
#ifdef CONFIG_IWL4965_QOS
7778
iwl4965_activate_qos(priv, 1);
7780
iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0);
7782
iwl4965_send_beacon_cmd(priv);
7784
/* FIXME - we need to add code here to detect a totally new
7785
* configuration, reset the AP, unassoc, rxon timing, assoc,
7786
* clear sta table, add BCAST sta... */
7789
static int iwl4965_mac_config_interface(struct ieee80211_hw *hw, int if_id,
7790
struct ieee80211_if_conf *conf)
7792
struct iwl4965_priv *priv = hw->priv;
7793
unsigned long flags;
7799
if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
7800
(!conf->beacon || !conf->ssid_len)) {
7802
("Leaving in AP mode because HostAPD is not ready.\n");
7806
if (!iwl4965_is_alive(priv))
7809
mutex_lock(&priv->mutex);
7811
IWL_DEBUG_MAC80211("enter: interface id %d\n", if_id);
7813
IWL_DEBUG_MAC80211("bssid: " MAC_FMT "\n",
7814
MAC_ARG(conf->bssid));
7816
if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
7817
!(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
7818
IWL_DEBUG_MAC80211("leave - scanning\n");
7819
mutex_unlock(&priv->mutex);
7823
if (priv->interface_id != if_id) {
7824
IWL_DEBUG_MAC80211("leave - interface_id != if_id\n");
7825
mutex_unlock(&priv->mutex);
7829
if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
7831
conf->bssid = priv->mac_addr;
7832
memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
7833
IWL_DEBUG_MAC80211("bssid was set to: " MAC_FMT "\n",
7834
MAC_ARG(conf->bssid));
7836
if (priv->ibss_beacon)
7837
dev_kfree_skb(priv->ibss_beacon);
7839
priv->ibss_beacon = conf->beacon;
7842
if (iwl4965_is_rfkill(priv))
7845
if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
7846
!is_multicast_ether_addr(conf->bssid)) {
7847
/* If there is currently a HW scan going on in the background
7848
* then we need to cancel it else the RXON below will fail. */
7849
if (iwl4965_scan_cancel_timeout(priv, 100)) {
7850
IWL_WARNING("Aborted scan still in progress "
7852
IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
7853
mutex_unlock(&priv->mutex);
7856
memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
7858
/* TODO: Audit driver for usage of these members and see
7859
* if mac80211 deprecates them (priv->bssid looks like it
7860
* shouldn't be there, but I haven't scanned the IBSS code
7861
* to verify) - jpk */
7862
memcpy(priv->bssid, conf->bssid, ETH_ALEN);
7864
if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
7865
iwl4965_config_ap(priv);
7867
rc = iwl4965_commit_rxon(priv);
7868
if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
7869
iwl4965_rxon_add_station(
7870
priv, priv->active_rxon.bssid_addr, 1);
7874
iwl4965_scan_cancel_timeout(priv, 100);
7875
priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7876
iwl4965_commit_rxon(priv);
7880
spin_lock_irqsave(&priv->lock, flags);
7881
if (!conf->ssid_len)
7882
memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
7884
memcpy(priv->essid, conf->ssid, conf->ssid_len);
7886
priv->essid_len = conf->ssid_len;
7887
spin_unlock_irqrestore(&priv->lock, flags);
7889
IWL_DEBUG_MAC80211("leave\n");
7890
mutex_unlock(&priv->mutex);
7895
static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
7896
struct ieee80211_if_init_conf *conf)
7898
struct iwl4965_priv *priv = hw->priv;
7900
IWL_DEBUG_MAC80211("enter\n");
7902
mutex_lock(&priv->mutex);
7904
if (iwl4965_is_ready_rf(priv)) {
7905
iwl4965_scan_cancel_timeout(priv, 100);
7906
cancel_delayed_work(&priv->post_associate);
7907
priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7908
iwl4965_commit_rxon(priv);
7910
if (priv->interface_id == conf->if_id) {
7911
priv->interface_id = 0;
7912
memset(priv->bssid, 0, ETH_ALEN);
7913
memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
7914
priv->essid_len = 0;
7916
mutex_unlock(&priv->mutex);
7918
IWL_DEBUG_MAC80211("leave\n");
7921
static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
7924
unsigned long flags;
7925
struct iwl4965_priv *priv = hw->priv;
7927
IWL_DEBUG_MAC80211("enter\n");
7929
mutex_lock(&priv->mutex);
7930
spin_lock_irqsave(&priv->lock, flags);
7932
if (!iwl4965_is_ready_rf(priv)) {
7934
IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
7938
if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */
7940
IWL_ERROR("ERROR: APs don't scan\n");
7944
/* we don't schedule scan within next_scan_jiffies period */
7945
if (priv->next_scan_jiffies &&
7946
time_after(priv->next_scan_jiffies, jiffies)) {
7950
/* if we just finished scan ask for delay */
7951
if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies +
7952
IWL_DELAY_NEXT_SCAN, jiffies)) {
7957
IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
7958
iwl4965_escape_essid(ssid, len), (int)len);
7960
priv->one_direct_scan = 1;
7961
priv->direct_ssid_len = (u8)
7962
min((u8) len, (u8) IW_ESSID_MAX_SIZE);
7963
memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
7965
priv->one_direct_scan = 0;
7967
rc = iwl4965_scan_initiate(priv);
7969
IWL_DEBUG_MAC80211("leave\n");
7972
spin_unlock_irqrestore(&priv->lock, flags);
7973
mutex_unlock(&priv->mutex);
7978
static int iwl4965_mac_set_key(struct ieee80211_hw *hw, set_key_cmd cmd, u8 *addr,
7979
struct ieee80211_key_conf *key, int aid)
7981
struct iwl4965_priv *priv = hw->priv;
7985
IWL_DEBUG_MAC80211("enter\n");
7987
if (!iwl4965_param_hwcrypto) {
7988
IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
7992
sta_id = iwl4965_hw_find_station(priv, addr);
7993
if (sta_id == IWL_INVALID_STATION) {
7994
IWL_DEBUG_MAC80211("leave - " MAC_FMT " not in station map.\n",
7999
mutex_lock(&priv->mutex);
8001
iwl4965_scan_cancel_timeout(priv, 100);
8005
rc = iwl4965_update_sta_key_info(priv, key, sta_id);
8007
iwl4965_set_rxon_hwcrypto(priv, 1);
8008
iwl4965_commit_rxon(priv);
8009
key->hw_key_idx = sta_id;
8010
IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n");
8014
rc = iwl4965_clear_sta_key_info(priv, sta_id);
8016
iwl4965_set_rxon_hwcrypto(priv, 0);
8017
iwl4965_commit_rxon(priv);
8018
IWL_DEBUG_MAC80211("disable hwcrypto key\n");
8025
IWL_DEBUG_MAC80211("leave\n");
8026
mutex_unlock(&priv->mutex);
8031
static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, int queue,
8032
const struct ieee80211_tx_queue_params *params)
8034
struct iwl4965_priv *priv = hw->priv;
8035
#ifdef CONFIG_IWL4965_QOS
8036
unsigned long flags;
8038
#endif /* CONFIG_IWL4965_QOS */
8040
IWL_DEBUG_MAC80211("enter\n");
8042
if (!iwl4965_is_ready_rf(priv)) {
8043
IWL_DEBUG_MAC80211("leave - RF not ready\n");
8047
if (queue >= AC_NUM) {
8048
IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
8052
#ifdef CONFIG_IWL4965_QOS
8053
if (!priv->qos_data.qos_enable) {
8054
priv->qos_data.qos_active = 0;
8055
IWL_DEBUG_MAC80211("leave - qos not enabled\n");
8058
q = AC_NUM - 1 - queue;
8060
spin_lock_irqsave(&priv->lock, flags);
8062
priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
8063
priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
8064
priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
8065
priv->qos_data.def_qos_parm.ac[q].edca_txop =
8066
cpu_to_le16((params->burst_time * 100));
8068
priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
8069
priv->qos_data.qos_active = 1;
8071
spin_unlock_irqrestore(&priv->lock, flags);
8073
mutex_lock(&priv->mutex);
8074
if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
8075
iwl4965_activate_qos(priv, 1);
8076
else if (priv->assoc_id && iwl4965_is_associated(priv))
8077
iwl4965_activate_qos(priv, 0);
8079
mutex_unlock(&priv->mutex);
8081
#endif /*CONFIG_IWL4965_QOS */
8083
IWL_DEBUG_MAC80211("leave\n");
8087
static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
8088
struct ieee80211_tx_queue_stats *stats)
8090
struct iwl4965_priv *priv = hw->priv;
8092
struct iwl4965_tx_queue *txq;
8093
struct iwl4965_queue *q;
8094
unsigned long flags;
8096
IWL_DEBUG_MAC80211("enter\n");
8098
if (!iwl4965_is_ready_rf(priv)) {
8099
IWL_DEBUG_MAC80211("leave - RF not ready\n");
8103
spin_lock_irqsave(&priv->lock, flags);
8105
for (i = 0; i < AC_NUM; i++) {
8106
txq = &priv->txq[i];
8108
avail = iwl4965_queue_space(q);
8110
stats->data[i].len = q->n_window - avail;
8111
stats->data[i].limit = q->n_window - q->high_mark;
8112
stats->data[i].count = q->n_window;
8115
spin_unlock_irqrestore(&priv->lock, flags);
8117
IWL_DEBUG_MAC80211("leave\n");
8122
static int iwl4965_mac_get_stats(struct ieee80211_hw *hw,
8123
struct ieee80211_low_level_stats *stats)
8125
IWL_DEBUG_MAC80211("enter\n");
8126
IWL_DEBUG_MAC80211("leave\n");
8131
static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw)
8133
IWL_DEBUG_MAC80211("enter\n");
8134
IWL_DEBUG_MAC80211("leave\n");
8139
static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
8141
struct iwl4965_priv *priv = hw->priv;
8142
unsigned long flags;
8144
mutex_lock(&priv->mutex);
8145
IWL_DEBUG_MAC80211("enter\n");
8147
priv->lq_mngr.lq_ready = 0;
8148
#ifdef CONFIG_IWL4965_HT
8149
spin_lock_irqsave(&priv->lock, flags);
8150
memset(&priv->current_assoc_ht, 0, sizeof(struct sta_ht_info));
8151
spin_unlock_irqrestore(&priv->lock, flags);
8152
#ifdef CONFIG_IWL4965_HT_AGG
8153
/* if (priv->lq_mngr.agg_ctrl.granted_ba)
8154
iwl4965_turn_off_agg(priv, TID_ALL_SPECIFIED);*/
8156
memset(&(priv->lq_mngr.agg_ctrl), 0, sizeof(struct iwl4965_agg_control));
8157
priv->lq_mngr.agg_ctrl.tid_traffic_load_threshold = 10;
8158
priv->lq_mngr.agg_ctrl.ba_timeout = 5000;
8159
priv->lq_mngr.agg_ctrl.auto_agg = 1;
8161
if (priv->lq_mngr.agg_ctrl.auto_agg)
8162
priv->lq_mngr.agg_ctrl.requested_ba = TID_ALL_ENABLED;
8163
#endif /*CONFIG_IWL4965_HT_AGG */
8164
#endif /* CONFIG_IWL4965_HT */
8166
#ifdef CONFIG_IWL4965_QOS
8167
iwl4965_reset_qos(priv);
8170
cancel_delayed_work(&priv->post_associate);
8172
spin_lock_irqsave(&priv->lock, flags);
8174
priv->assoc_capability = 0;
8175
priv->call_post_assoc_from_beacon = 0;
8176
priv->assoc_station_added = 0;
8178
/* new association get rid of ibss beacon skb */
8179
if (priv->ibss_beacon)
8180
dev_kfree_skb(priv->ibss_beacon);
8182
priv->ibss_beacon = NULL;
8184
priv->beacon_int = priv->hw->conf.beacon_int;
8185
priv->timestamp1 = 0;
8186
priv->timestamp0 = 0;
8187
if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
8188
priv->beacon_int = 0;
8190
spin_unlock_irqrestore(&priv->lock, flags);
8192
if (!iwl4965_is_ready_rf(priv)) {
8193
IWL_DEBUG_MAC80211("leave - not ready\n");
8194
mutex_unlock(&priv->mutex);
8198
/* we are restarting association process
8199
* clear RXON_FILTER_ASSOC_MSK bit
8201
if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
8202
iwl4965_scan_cancel_timeout(priv, 100);
8203
priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
8204
iwl4965_commit_rxon(priv);
8207
/* Per mac80211.h: This is only used in IBSS mode... */
8208
if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
8210
IWL_DEBUG_MAC80211("leave - not in IBSS\n");
8211
mutex_unlock(&priv->mutex);
8215
priv->only_active_channel = 0;
8217
iwl4965_set_rate(priv);
8219
mutex_unlock(&priv->mutex);
8221
IWL_DEBUG_MAC80211("leave\n");
8225
static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb,
8226
struct ieee80211_tx_control *control)
8228
struct iwl4965_priv *priv = hw->priv;
8229
unsigned long flags;
8231
mutex_lock(&priv->mutex);
8232
IWL_DEBUG_MAC80211("enter\n");
8234
if (!iwl4965_is_ready_rf(priv)) {
8235
IWL_DEBUG_MAC80211("leave - RF not ready\n");
8236
mutex_unlock(&priv->mutex);
8240
if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
8241
IWL_DEBUG_MAC80211("leave - not IBSS\n");
8242
mutex_unlock(&priv->mutex);
8246
spin_lock_irqsave(&priv->lock, flags);
8248
if (priv->ibss_beacon)
8249
dev_kfree_skb(priv->ibss_beacon);
8251
priv->ibss_beacon = skb;
8255
IWL_DEBUG_MAC80211("leave\n");
8256
spin_unlock_irqrestore(&priv->lock, flags);
8258
#ifdef CONFIG_IWL4965_QOS
8259
iwl4965_reset_qos(priv);
8262
queue_work(priv->workqueue, &priv->post_associate.work);
8264
mutex_unlock(&priv->mutex);
8269
#ifdef CONFIG_IWL4965_HT
8272
u16 advanced_coding_cap :1;
8273
u16 supported_chan_width_set :1;
8274
u16 mimo_power_save_mode :2;
8280
u16 beam_forming :1;
8282
u16 maximal_amsdu_size :1;
8283
u16 cck_mode_at_40MHz :1;
8284
u16 psmp_support :1;
8285
u16 stbc_ctrl_frame_support :1;
8286
u16 sig_txop_protection_support :1;
8289
} __attribute__ ((packed));
8291
union ht_param_info{
8293
u8 max_rx_ampdu_factor :2;
8298
} __attribute__ ((packed));
8300
union ht_exra_param_info {
8302
u8 ext_chan_offset :2;
8303
u8 tx_chan_width :1;
8305
u8 controlled_access_only :1;
8306
u8 service_interval_granularity :3;
8309
} __attribute__ ((packed));
8311
union ht_operation_mode{
8318
} __attribute__ ((packed));
8321
static int sta_ht_info_init(struct ieee80211_ht_capability *ht_cap,
8322
struct ieee80211_ht_additional_info *ht_extra,
8323
struct sta_ht_info *ht_info_ap,
8324
struct sta_ht_info *ht_info)
8326
union ht_cap_info cap;
8327
union ht_operation_mode op_mode;
8328
union ht_param_info param_info;
8329
union ht_exra_param_info extra_param_info;
8331
IWL_DEBUG_MAC80211("enter: \n");
8334
IWL_DEBUG_MAC80211("leave: ht_info is NULL\n");
8339
cap.val = (u16) le16_to_cpu(ht_cap->capabilities_info);
8340
param_info.val = ht_cap->mac_ht_params_info;
8343
ht_info->sgf |= 0x1;
8345
ht_info->sgf |= 0x2;
8346
ht_info->is_green_field = cap.green_field;
8347
ht_info->max_amsdu_size = cap.maximal_amsdu_size;
8348
ht_info->supported_chan_width = cap.supported_chan_width_set;
8349
ht_info->tx_mimo_ps_mode = cap.mimo_power_save_mode;
8350
memcpy(ht_info->supp_rates, ht_cap->supported_mcs_set, 16);
8352
ht_info->ampdu_factor = param_info.max_rx_ampdu_factor;
8353
ht_info->mpdu_density = param_info.mpdu_density;
8355
IWL_DEBUG_MAC80211("SISO mask 0x%X MIMO mask 0x%X \n",
8356
ht_cap->supported_mcs_set[0],
8357
ht_cap->supported_mcs_set[1]);
8360
ht_info->control_channel = ht_info_ap->control_channel;
8361
ht_info->extension_chan_offset =
8362
ht_info_ap->extension_chan_offset;
8363
ht_info->tx_chan_width = ht_info_ap->tx_chan_width;
8364
ht_info->operating_mode = ht_info_ap->operating_mode;
8368
extra_param_info.val = ht_extra->ht_param;
8369
ht_info->control_channel = ht_extra->control_chan;
8370
ht_info->extension_chan_offset =
8371
extra_param_info.ext_chan_offset;
8372
ht_info->tx_chan_width = extra_param_info.tx_chan_width;
8374
le16_to_cpu(ht_extra->operation_mode);
8375
ht_info->operating_mode = op_mode.op_mode;
8376
IWL_DEBUG_MAC80211("control channel %d\n",
8377
ht_extra->control_chan);
8382
IWL_DEBUG_MAC80211("leave\n");
8386
static int iwl4965_mac_conf_ht(struct ieee80211_hw *hw,
8387
struct ieee80211_ht_capability *ht_cap,
8388
struct ieee80211_ht_additional_info *ht_extra)
8390
struct iwl4965_priv *priv = hw->priv;
8393
IWL_DEBUG_MAC80211("enter: \n");
8395
rs = sta_ht_info_init(ht_cap, ht_extra, NULL, &priv->current_assoc_ht);
8396
iwl4965_set_rxon_chain(priv);
8398
if (priv && priv->assoc_id &&
8399
(priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
8400
unsigned long flags;
8402
spin_lock_irqsave(&priv->lock, flags);
8403
if (priv->beacon_int)
8404
queue_work(priv->workqueue, &priv->post_associate.work);
8406
priv->call_post_assoc_from_beacon = 1;
8407
spin_unlock_irqrestore(&priv->lock, flags);
8410
IWL_DEBUG_MAC80211("leave: control channel %d\n",
8411
ht_extra->control_chan);
8416
static void iwl4965_set_ht_capab(struct ieee80211_hw *hw,
8417
struct ieee80211_ht_capability *ht_cap,
8420
union ht_cap_info cap;
8421
union ht_param_info param_info;
8423
memset(&cap, 0, sizeof(union ht_cap_info));
8424
memset(¶m_info, 0, sizeof(union ht_param_info));
8426
cap.maximal_amsdu_size = HT_IE_MAX_AMSDU_SIZE_4K;
8427
cap.green_field = 1;
8430
cap.supported_chan_width_set = use_wide_chan;
8431
cap.mimo_power_save_mode = 0x3;
8433
param_info.max_rx_ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
8434
param_info.mpdu_density = CFG_HT_MPDU_DENSITY_DEF;
8435
ht_cap->capabilities_info = (__le16) cpu_to_le16(cap.val);
8436
ht_cap->mac_ht_params_info = (u8) param_info.val;
8438
ht_cap->supported_mcs_set[0] = 0xff;
8439
ht_cap->supported_mcs_set[1] = 0xff;
8440
ht_cap->supported_mcs_set[4] =
8441
(cap.supported_chan_width_set) ? 0x1: 0x0;
8444
static void iwl4965_mac_get_ht_capab(struct ieee80211_hw *hw,
8445
struct ieee80211_ht_capability *ht_cap)
8447
u8 use_wide_channel = 1;
8448
struct iwl4965_priv *priv = hw->priv;
8450
IWL_DEBUG_MAC80211("enter: \n");
8451
if (priv->channel_width != IWL_CHANNEL_WIDTH_40MHZ)
8452
use_wide_channel = 0;
8454
/* no fat tx allowed on 2.4GHZ */
8455
if (priv->phymode != MODE_IEEE80211A)
8456
use_wide_channel = 0;
8458
iwl4965_set_ht_capab(hw, ht_cap, use_wide_channel);
8459
IWL_DEBUG_MAC80211("leave: \n");
8461
#endif /*CONFIG_IWL4965_HT*/
8463
/*****************************************************************************
8467
*****************************************************************************/
8469
#ifdef CONFIG_IWL4965_DEBUG
8472
* The following adds a new attribute to the sysfs representation
8473
* of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
8474
* used for controlling the debug level.
8476
* See the level definitions in iwl for details.
8479
static ssize_t show_debug_level(struct device_driver *d, char *buf)
8481
return sprintf(buf, "0x%08X\n", iwl4965_debug_level);
8483
static ssize_t store_debug_level(struct device_driver *d,
8484
const char *buf, size_t count)
8486
char *p = (char *)buf;
8489
val = simple_strtoul(p, &p, 0);
8491
printk(KERN_INFO DRV_NAME
8492
": %s is not in hex or decimal form.\n", buf);
8494
iwl4965_debug_level = val;
8496
return strnlen(buf, count);
8499
static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
8500
show_debug_level, store_debug_level);
8502
#endif /* CONFIG_IWL4965_DEBUG */
8504
static ssize_t show_rf_kill(struct device *d,
8505
struct device_attribute *attr, char *buf)
8508
* 0 - RF kill not enabled
8509
* 1 - SW based RF kill active (sysfs)
8510
* 2 - HW based RF kill active
8511
* 3 - Both HW and SW based RF kill active
8513
struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8514
int val = (test_bit(STATUS_RF_KILL_SW, &priv->status) ? 0x1 : 0x0) |
8515
(test_bit(STATUS_RF_KILL_HW, &priv->status) ? 0x2 : 0x0);
8517
return sprintf(buf, "%i\n", val);
8520
static ssize_t store_rf_kill(struct device *d,
8521
struct device_attribute *attr,
8522
const char *buf, size_t count)
8524
struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8526
mutex_lock(&priv->mutex);
8527
iwl4965_radio_kill_sw(priv, buf[0] == '1');
8528
mutex_unlock(&priv->mutex);
8533
static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
8535
static ssize_t show_temperature(struct device *d,
8536
struct device_attribute *attr, char *buf)
8538
struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8540
if (!iwl4965_is_alive(priv))
8543
return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv));
8546
static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
8548
static ssize_t show_rs_window(struct device *d,
8549
struct device_attribute *attr,
8552
struct iwl4965_priv *priv = d->driver_data;
8553
return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID);
8555
static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
8557
static ssize_t show_tx_power(struct device *d,
8558
struct device_attribute *attr, char *buf)
8560
struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8561
return sprintf(buf, "%d\n", priv->user_txpower_limit);
8564
static ssize_t store_tx_power(struct device *d,
8565
struct device_attribute *attr,
8566
const char *buf, size_t count)
8568
struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8569
char *p = (char *)buf;
8572
val = simple_strtoul(p, &p, 10);
8574
printk(KERN_INFO DRV_NAME
8575
": %s is not in decimal form.\n", buf);
8577
iwl4965_hw_reg_set_txpower(priv, val);
8582
static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
8584
static ssize_t show_flags(struct device *d,
8585
struct device_attribute *attr, char *buf)
8587
struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8589
return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
8592
static ssize_t store_flags(struct device *d,
8593
struct device_attribute *attr,
8594
const char *buf, size_t count)
8596
struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8597
u32 flags = simple_strtoul(buf, NULL, 0);
8599
mutex_lock(&priv->mutex);
8600
if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
8601
/* Cancel any currently running scans... */
8602
if (iwl4965_scan_cancel_timeout(priv, 100))
8603
IWL_WARNING("Could not cancel scan.\n");
8605
IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
8607
priv->staging_rxon.flags = cpu_to_le32(flags);
8608
iwl4965_commit_rxon(priv);
8611
mutex_unlock(&priv->mutex);
8616
static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
8618
static ssize_t show_filter_flags(struct device *d,
8619
struct device_attribute *attr, char *buf)
8621
struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8623
return sprintf(buf, "0x%04X\n",
8624
le32_to_cpu(priv->active_rxon.filter_flags));
8627
static ssize_t store_filter_flags(struct device *d,
8628
struct device_attribute *attr,
8629
const char *buf, size_t count)
8631
struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8632
u32 filter_flags = simple_strtoul(buf, NULL, 0);
8634
mutex_lock(&priv->mutex);
8635
if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
8636
/* Cancel any currently running scans... */
8637
if (iwl4965_scan_cancel_timeout(priv, 100))
8638
IWL_WARNING("Could not cancel scan.\n");
8640
IWL_DEBUG_INFO("Committing rxon.filter_flags = "
8641
"0x%04X\n", filter_flags);
8642
priv->staging_rxon.filter_flags =
8643
cpu_to_le32(filter_flags);
8644
iwl4965_commit_rxon(priv);
8647
mutex_unlock(&priv->mutex);
8652
static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
8653
store_filter_flags);
8655
static ssize_t show_tune(struct device *d,
8656
struct device_attribute *attr, char *buf)
8658
struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8660
return sprintf(buf, "0x%04X\n",
8661
(priv->phymode << 8) |
8662
le16_to_cpu(priv->active_rxon.channel));
8665
static void iwl4965_set_flags_for_phymode(struct iwl4965_priv *priv, u8 phymode);
8667
static ssize_t store_tune(struct device *d,
8668
struct device_attribute *attr,
8669
const char *buf, size_t count)
8671
struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
8672
char *p = (char *)buf;
8673
u16 tune = simple_strtoul(p, &p, 0);
8674
u8 phymode = (tune >> 8) & 0xff;
8675
u16 channel = tune & 0xff;
8677
IWL_DEBUG_INFO("Tune request to:%d channel:%d\n", phymode, channel);
8679
mutex_lock(&priv->mutex);
8680
if ((le16_to_cpu(priv->staging_rxon.channel) != channel) ||
8681
(priv->phymode != phymode)) {
8682
const struct iwl4965_channel_info *ch_info;
8684
ch_info = iwl4965_get_channel_info(priv, phymode, channel);
8686
IWL_WARNING("Requested invalid phymode/channel "
8687
"combination: %d %d\n", phymode, channel);
8688
mutex_unlock(&priv->mutex);
8692
/* Cancel any currently running scans... */
8693
if (iwl4965_scan_cancel_timeout(priv, 100))
8694
IWL_WARNING("Could not cancel scan.\n");
8696
IWL_DEBUG_INFO("Committing phymode and "
8697
"rxon.channel = %d %d\n",
8700
iwl4965_set_rxon_channel(priv, phymode, channel);
8701
iwl4965_set_flags_for_phymode(priv, phymode);
8703
iwl4965_set_rate(priv);
8704
iwl4965_commit_rxon(priv);
8707
mutex_unlock(&priv->mutex);
8712
static DEVICE_ATTR(tune, S_IWUSR | S_IRUGO, show_tune, store_tune);
8714
#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
8716
static ssize_t show_measurement(struct device *d,
8717
struct device_attribute *attr, char *buf)
8719
struct iwl4965_priv *priv = dev_get_drvdata(d);
8720
struct iwl4965_spectrum_notification measure_report;
8721
u32 size = sizeof(measure_report), len = 0, ofs = 0;
8722
u8 *data = (u8 *) & measure_report;
8723
unsigned long flags;
8725
spin_lock_irqsave(&priv->lock, flags);
8726
if (!(priv->measurement_status & MEASUREMENT_READY)) {
8727
spin_unlock_irqrestore(&priv->lock, flags);
8730
memcpy(&measure_report, &priv->measure_report, size);
8731
priv->measurement_status = 0;
8732
spin_unlock_irqrestore(&priv->lock, flags);
8734
while (size && (PAGE_SIZE - len)) {
8735
hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
8736
PAGE_SIZE - len, 1);
8738
if (PAGE_SIZE - len)
8742
size -= min(size, 16U);
8748
static ssize_t store_measurement(struct device *d,
8749
struct device_attribute *attr,
8750
const char *buf, size_t count)
8752
struct iwl4965_priv *priv = dev_get_drvdata(d);
8753
struct ieee80211_measurement_params params = {
8754
.channel = le16_to_cpu(priv->active_rxon.channel),
8755
.start_time = cpu_to_le64(priv->last_tsf),
8756
.duration = cpu_to_le16(1),
8758
u8 type = IWL_MEASURE_BASIC;
8764
strncpy(buffer, buf, min(sizeof(buffer), count));
8765
channel = simple_strtoul(p, NULL, 0);
8767
params.channel = channel;
8770
while (*p && *p != ' ')
8773
type = simple_strtoul(p + 1, NULL, 0);
8776
IWL_DEBUG_INFO("Invoking measurement of type %d on "
8777
"channel %d (for '%s')\n", type, params.channel, buf);
8778
iwl4965_get_measurement(priv, ¶ms, type);
8783
static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
8784
show_measurement, store_measurement);
8785
#endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
8787
static ssize_t store_retry_rate(struct device *d,
8788
struct device_attribute *attr,
8789
const char *buf, size_t count)
8791
struct iwl4965_priv *priv = dev_get_drvdata(d);
8793
priv->retry_rate = simple_strtoul(buf, NULL, 0);
8794
if (priv->retry_rate <= 0)
8795
priv->retry_rate = 1;
8800
static ssize_t show_retry_rate(struct device *d,
8801
struct device_attribute *attr, char *buf)
8803
struct iwl4965_priv *priv = dev_get_drvdata(d);
8804
return sprintf(buf, "%d", priv->retry_rate);
8807
static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
8810
static ssize_t store_power_level(struct device *d,
8811
struct device_attribute *attr,
8812
const char *buf, size_t count)
8814
struct iwl4965_priv *priv = dev_get_drvdata(d);
8818
mode = simple_strtoul(buf, NULL, 0);
8819
mutex_lock(&priv->mutex);
8821
if (!iwl4965_is_ready(priv)) {
8826
if ((mode < 1) || (mode > IWL_POWER_LIMIT) || (mode == IWL_POWER_AC))
8827
mode = IWL_POWER_AC;
8829
mode |= IWL_POWER_ENABLED;
8831
if (mode != priv->power_mode) {
8832
rc = iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(mode));
8834
IWL_DEBUG_MAC80211("failed setting power mode.\n");
8837
priv->power_mode = mode;
8843
mutex_unlock(&priv->mutex);
8847
#define MAX_WX_STRING 80
8849
/* Values are in microsecond */
8850
static const s32 timeout_duration[] = {
8857
static const s32 period_duration[] = {
8865
static ssize_t show_power_level(struct device *d,
8866
struct device_attribute *attr, char *buf)
8868
struct iwl4965_priv *priv = dev_get_drvdata(d);
8869
int level = IWL_POWER_LEVEL(priv->power_mode);
8872
p += sprintf(p, "%d ", level);
8874
case IWL_POWER_MODE_CAM:
8876
p += sprintf(p, "(AC)");
8878
case IWL_POWER_BATTERY:
8879
p += sprintf(p, "(BATTERY)");
8883
"(Timeout %dms, Period %dms)",
8884
timeout_duration[level - 1] / 1000,
8885
period_duration[level - 1] / 1000);
8888
if (!(priv->power_mode & IWL_POWER_ENABLED))
8889
p += sprintf(p, " OFF\n");
8891
p += sprintf(p, " \n");
8893
return (p - buf + 1);
8897
static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
8900
static ssize_t show_channels(struct device *d,
8901
struct device_attribute *attr, char *buf)
8903
struct iwl4965_priv *priv = dev_get_drvdata(d);
8905
struct ieee80211_channel *channels = NULL;
8906
const struct ieee80211_hw_mode *hw_mode = NULL;
8909
if (!iwl4965_is_ready(priv))
8912
hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211G);
8914
hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211B);
8916
channels = hw_mode->channels;
8917
count = hw_mode->num_channels;
8922
"Displaying %d channels in 2.4GHz band "
8923
"(802.11bg):\n", count);
8925
for (i = 0; i < count; i++)
8926
len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
8928
channels[i].power_level,
8930
flag & IEEE80211_CHAN_W_RADAR_DETECT ?
8931
" (IEEE 802.11h required)" : "",
8932
(!(channels[i].flag & IEEE80211_CHAN_W_IBSS)
8935
IEEE80211_CHAN_W_RADAR_DETECT)) ? "" :
8938
flag & IEEE80211_CHAN_W_ACTIVE_SCAN ?
8939
"active/passive" : "passive only");
8941
hw_mode = iwl4965_get_hw_mode(priv, MODE_IEEE80211A);
8943
channels = hw_mode->channels;
8944
count = hw_mode->num_channels;
8950
len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band "
8951
"(802.11a):\n", count);
8953
for (i = 0; i < count; i++)
8954
len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
8956
channels[i].power_level,
8958
flag & IEEE80211_CHAN_W_RADAR_DETECT ?
8959
" (IEEE 802.11h required)" : "",
8960
(!(channels[i].flag & IEEE80211_CHAN_W_IBSS)
8963
IEEE80211_CHAN_W_RADAR_DETECT)) ? "" :
8966
flag & IEEE80211_CHAN_W_ACTIVE_SCAN ?
8967
"active/passive" : "passive only");
8972
static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
8974
static ssize_t show_statistics(struct device *d,
8975
struct device_attribute *attr, char *buf)
8977
struct iwl4965_priv *priv = dev_get_drvdata(d);
8978
u32 size = sizeof(struct iwl4965_notif_statistics);
8979
u32 len = 0, ofs = 0;
8980
u8 *data = (u8 *) & priv->statistics;
8983
if (!iwl4965_is_alive(priv))
8986
mutex_lock(&priv->mutex);
8987
rc = iwl4965_send_statistics_request(priv);
8988
mutex_unlock(&priv->mutex);
8992
"Error sending statistics request: 0x%08X\n", rc);
8996
while (size && (PAGE_SIZE - len)) {
8997
hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
8998
PAGE_SIZE - len, 1);
9000
if (PAGE_SIZE - len)
9004
size -= min(size, 16U);
9010
static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
9012
static ssize_t show_antenna(struct device *d,
9013
struct device_attribute *attr, char *buf)
9015
struct iwl4965_priv *priv = dev_get_drvdata(d);
9017
if (!iwl4965_is_alive(priv))
9020
return sprintf(buf, "%d\n", priv->antenna);
9023
static ssize_t store_antenna(struct device *d,
9024
struct device_attribute *attr,
9025
const char *buf, size_t count)
9028
struct iwl4965_priv *priv = dev_get_drvdata(d);
9033
if (sscanf(buf, "%1i", &ant) != 1) {
9034
IWL_DEBUG_INFO("not in hex or decimal form.\n");
9038
if ((ant >= 0) && (ant <= 2)) {
9039
IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant);
9040
priv->antenna = (enum iwl4965_antenna)ant;
9042
IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant);
9048
static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
9050
static ssize_t show_status(struct device *d,
9051
struct device_attribute *attr, char *buf)
9053
struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data;
9054
if (!iwl4965_is_alive(priv))
9056
return sprintf(buf, "0x%08x\n", (int)priv->status);
9059
static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
9061
static ssize_t dump_error_log(struct device *d,
9062
struct device_attribute *attr,
9063
const char *buf, size_t count)
9065
char *p = (char *)buf;
9068
iwl4965_dump_nic_error_log((struct iwl4965_priv *)d->driver_data);
9070
return strnlen(buf, count);
9073
static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
9075
static ssize_t dump_event_log(struct device *d,
9076
struct device_attribute *attr,
9077
const char *buf, size_t count)
9079
char *p = (char *)buf;
9082
iwl4965_dump_nic_event_log((struct iwl4965_priv *)d->driver_data);
9084
return strnlen(buf, count);
9087
static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
9089
/*****************************************************************************
9091
* driver setup and teardown
9093
*****************************************************************************/
9095
static void iwl4965_setup_deferred_work(struct iwl4965_priv *priv)
9097
priv->workqueue = create_workqueue(DRV_NAME);
9099
init_waitqueue_head(&priv->wait_command_queue);
9101
INIT_WORK(&priv->up, iwl4965_bg_up);
9102
INIT_WORK(&priv->restart, iwl4965_bg_restart);
9103
INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish);
9104
INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed);
9105
INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan);
9106
INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan);
9107
INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill);
9108
INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update);
9109
INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate);
9110
INIT_DELAYED_WORK(&priv->init_alive_start, iwl4965_bg_init_alive_start);
9111
INIT_DELAYED_WORK(&priv->alive_start, iwl4965_bg_alive_start);
9112
INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check);
9114
iwl4965_hw_setup_deferred_work(priv);
9116
tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
9117
iwl4965_irq_tasklet, (unsigned long)priv);
9120
#ifndef cancel_work_sync
9121
#define cancel_work_sync(x)
9124
static void iwl4965_cancel_deferred_work(struct iwl4965_priv *priv)
9126
iwl4965_hw_cancel_deferred_work(priv);
9128
cancel_delayed_work(&priv->init_alive_start);
9129
cancel_delayed_work(&priv->scan_check);
9130
cancel_delayed_work(&priv->alive_start);
9131
cancel_delayed_work(&priv->post_associate);
9132
cancel_work_sync(&priv->beacon_update);
9135
static struct attribute *iwl4965_sysfs_entries[] = {
9136
&dev_attr_antenna.attr,
9137
&dev_attr_channels.attr,
9138
&dev_attr_dump_errors.attr,
9139
&dev_attr_dump_events.attr,
9140
&dev_attr_flags.attr,
9141
&dev_attr_filter_flags.attr,
9142
#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
9143
&dev_attr_measurement.attr,
9145
&dev_attr_power_level.attr,
9146
&dev_attr_retry_rate.attr,
9147
&dev_attr_rf_kill.attr,
9148
&dev_attr_rs_window.attr,
9149
&dev_attr_statistics.attr,
9150
&dev_attr_status.attr,
9151
&dev_attr_temperature.attr,
9152
&dev_attr_tune.attr,
9153
&dev_attr_tx_power.attr,
9158
static struct attribute_group iwl4965_attribute_group = {
9159
.name = NULL, /* put in device directory */
9160
.attrs = iwl4965_sysfs_entries,
9163
static struct ieee80211_ops iwl4965_hw_ops = {
9164
.tx = iwl4965_mac_tx,
9165
.open = iwl4965_mac_open,
9166
.stop = iwl4965_mac_stop,
9167
.add_interface = iwl4965_mac_add_interface,
9168
.remove_interface = iwl4965_mac_remove_interface,
9169
.config = iwl4965_mac_config,
9170
.config_interface = iwl4965_mac_config_interface,
9171
.set_key = iwl4965_mac_set_key,
9172
.get_stats = iwl4965_mac_get_stats,
9173
.get_tx_stats = iwl4965_mac_get_tx_stats,
9174
.conf_tx = iwl4965_mac_conf_tx,
9175
.get_tsf = iwl4965_mac_get_tsf,
9176
.reset_tsf = iwl4965_mac_reset_tsf,
9177
.beacon_update = iwl4965_mac_beacon_update,
9178
#ifdef CONFIG_IWL4965_HT
9179
.conf_ht = iwl4965_mac_conf_ht,
9180
.get_ht_capab = iwl4965_mac_get_ht_capab,
9181
#ifdef CONFIG_IWL4965_HT_AGG
9182
.ht_tx_agg_start = iwl4965_mac_ht_tx_agg_start,
9183
.ht_tx_agg_stop = iwl4965_mac_ht_tx_agg_stop,
9184
.ht_rx_agg_start = iwl4965_mac_ht_rx_agg_start,
9185
.ht_rx_agg_stop = iwl4965_mac_ht_rx_agg_stop,
9186
#endif /* CONFIG_IWL4965_HT_AGG */
9187
#endif /* CONFIG_IWL4965_HT */
9188
.hw_scan = iwl4965_mac_hw_scan
9191
static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
9194
struct iwl4965_priv *priv;
9195
struct ieee80211_hw *hw;
9198
/* Disabling hardware scan means that mac80211 will perform scans
9199
* "the hard way", rather than using device's scan. */
9200
if (iwl4965_param_disable_hw_scan) {
9201
IWL_DEBUG_INFO("Disabling hw_scan\n");
9202
iwl4965_hw_ops.hw_scan = NULL;
9205
if ((iwl4965_param_queues_num > IWL_MAX_NUM_QUEUES) ||
9206
(iwl4965_param_queues_num < IWL_MIN_NUM_QUEUES)) {
9207
IWL_ERROR("invalid queues_num, should be between %d and %d\n",
9208
IWL_MIN_NUM_QUEUES, IWL_MAX_NUM_QUEUES);
9213
/* mac80211 allocates memory for this device instance, including
9214
* space for this driver's private structure */
9215
hw = iwlwifi_ieee80211_alloc_hw(sizeof(struct iwl4965_priv), &iwl4965_hw_ops);
9217
IWL_ERROR("Can not allocate network device\n");
9221
SET_IEEE80211_DEV(hw, &pdev->dev);
9223
IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
9227
priv->pci_dev = pdev;
9228
priv->antenna = (enum iwl4965_antenna)iwl4965_param_antenna;
9229
#ifdef CONFIG_IWL4965_DEBUG
9230
iwl4965_debug_level = iwl4965_param_debug;
9231
atomic_set(&priv->restrict_refcnt, 0);
9233
priv->retry_rate = 1;
9235
priv->ibss_beacon = NULL;
9237
/* Tell mac80211 and its clients (e.g. Wireless Extensions)
9238
* the range of signal quality values that we'll provide.
9239
* Negative values for level/noise indicate that we'll provide dBm.
9240
* For WE, at least, non-0 values here *enable* display of values
9241
* in app (iwconfig). */
9242
hw->max_rssi = -20; /* signal level, negative indicates dBm */
9243
hw->max_noise = -20; /* noise level, negative indicates dBm */
9244
hw->max_signal = 100; /* link quality indication (%) */
9246
/* Tell mac80211 our Tx characteristics */
9247
hw->flags = IEEE80211_HW_WEP_INCLUDE_IV |
9248
IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE;
9250
/* Default value; 4 EDCA QOS priorities */
9252
#ifdef CONFIG_IWL4965_HT
9253
#ifdef CONFIG_IWL4965_HT_AGG
9254
/* Enhanced value; more queues, to support 11n aggregation */
9256
#endif /* CONFIG_IWL4965_HT_AGG */
9257
#endif /* CONFIG_IWL4965_HT */
9259
spin_lock_init(&priv->lock);
9260
spin_lock_init(&priv->power_data.lock);
9261
spin_lock_init(&priv->sta_lock);
9262
spin_lock_init(&priv->hcmd_lock);
9263
spin_lock_init(&priv->lq_mngr.lock);
9265
for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++)
9266
INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
9268
INIT_LIST_HEAD(&priv->free_frames);
9270
mutex_init(&priv->mutex);
9271
if (pci_enable_device(pdev)) {
9273
goto out_iwlwifi_ieee80211_free_hw;
9276
pci_set_master(pdev);
9278
/* Clear the driver's (not device's) station table */
9279
iwl4965_clear_stations_table(priv);
9281
priv->data_retry_limit = -1;
9282
priv->ieee_channels = NULL;
9283
priv->ieee_rates = NULL;
9286
err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
9288
err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
9290
printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
9291
goto out_pci_disable_device;
9294
pci_set_drvdata(pdev, priv);
9295
err = pci_request_regions(pdev, DRV_NAME);
9297
goto out_pci_disable_device;
9299
/* We disable the RETRY_TIMEOUT register (0x41) to keep
9300
* PCI Tx retries from interfering with C3 CPU state */
9301
pci_write_config_byte(pdev, 0x41, 0x00);
9303
priv->hw_base = pci_iomap(pdev, 0, 0);
9304
if (!priv->hw_base) {
9306
goto out_pci_release_regions;
9309
IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
9310
(unsigned long long) pci_resource_len(pdev, 0));
9311
IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
9313
/* Initialize module parameter values here */
9315
/* Disable radio (SW RF KILL) via parameter when loading driver */
9316
if (iwl4965_param_disable) {
9317
set_bit(STATUS_RF_KILL_SW, &priv->status);
9318
IWL_DEBUG_INFO("Radio disabled.\n");
9321
priv->iw_mode = IEEE80211_IF_TYPE_STA;
9324
priv->use_ant_b_for_management_frame = 1; /* start with ant B */
9325
priv->is_ht_enabled = 1;
9326
priv->channel_width = IWL_CHANNEL_WIDTH_40MHZ;
9327
priv->valid_antenna = 0x7; /* assume all 3 connected */
9328
priv->ps_mode = IWL_MIMO_PS_NONE;
9330
/* Choose which receivers/antennas to use */
9331
iwl4965_set_rxon_chain(priv);
9333
printk(KERN_INFO DRV_NAME
9334
": Detected Intel Wireless WiFi Link 4965AGN\n");
9336
/* Device-specific setup */
9337
if (iwl4965_hw_set_hw_setting(priv)) {
9338
IWL_ERROR("failed to set hw settings\n");
9342
#ifdef CONFIG_IWL4965_QOS
9343
if (iwl4965_param_qos_enable)
9344
priv->qos_data.qos_enable = 1;
9346
iwl4965_reset_qos(priv);
9348
priv->qos_data.qos_active = 0;
9349
priv->qos_data.qos_cap.val = 0;
9350
#endif /* CONFIG_IWL4965_QOS */
9352
iwl4965_set_rxon_channel(priv, MODE_IEEE80211G, 6);
9353
iwl4965_setup_deferred_work(priv);
9354
iwl4965_setup_rx_handlers(priv);
9356
priv->rates_mask = IWL_RATES_MASK;
9357
/* If power management is turned on, default to AC mode */
9358
priv->power_mode = IWL_POWER_AC;
9359
priv->user_txpower_limit = IWL_DEFAULT_TX_POWER;
9361
iwl4965_disable_interrupts(priv);
9363
err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
9365
IWL_ERROR("failed to create sysfs device attributes\n");
9366
goto out_release_irq;
9370
iwl4965_set_bit(priv, CSR_GIO_CHICKEN_BITS,
9371
CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
9373
iwl4965_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
9374
err = iwl4965_poll_bit(priv, CSR_GP_CNTRL,
9375
CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
9376
CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
9378
IWL_DEBUG_INFO("Failed to init the card\n");
9379
goto out_remove_sysfs;
9381
/* Read the EEPROM */
9382
err = iwl4965_eeprom_init(priv);
9384
IWL_ERROR("Unable to init EEPROM\n");
9385
goto out_remove_sysfs;
9387
/* MAC Address location in EEPROM same for 3945/4965 */
9388
get_eeprom_mac(priv, priv->mac_addr);
9389
IWL_DEBUG_INFO("MAC address: " MAC_FMT "\n", MAC_ARG(priv->mac_addr));
9390
SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
9392
iwl4965_rate_control_register(priv->hw);
9393
err = iwlwifi_ieee80211_register_hw(priv->hw);
9395
IWL_ERROR("Failed to register network device (error %d)\n", err);
9396
goto out_remove_sysfs;
9399
priv->hw->conf.beacon_int = 100;
9400
priv->mac80211_registered = 1;
9401
pci_save_state(pdev);
9402
pci_disable_device(pdev);
9407
iwl4965_rate_control_unregister(priv->hw);
9408
sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
9411
destroy_workqueue(priv->workqueue);
9412
priv->workqueue = NULL;
9413
iwl4965_unset_hw_setting(priv);
9416
pci_iounmap(pdev, priv->hw_base);
9417
out_pci_release_regions:
9418
pci_release_regions(pdev);
9419
out_pci_disable_device:
9420
pci_disable_device(pdev);
9421
pci_set_drvdata(pdev, NULL);
9422
out_iwlwifi_ieee80211_free_hw:
9423
iwlwifi_ieee80211_free_hw(priv->hw);
9428
static void iwl4965_pci_remove(struct pci_dev *pdev)
9430
struct iwl4965_priv *priv = pci_get_drvdata(pdev);
9431
struct list_head *p, *q;
9437
IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
9439
set_bit(STATUS_EXIT_PENDING, &priv->status);
9443
/* Free MAC hash list for ADHOC */
9444
for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
9445
list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
9447
kfree(list_entry(p, struct iwl4965_ibss_seq, list));
9451
sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
9453
iwl4965_dealloc_ucode_pci(priv);
9456
iwl4965_rx_queue_free(priv, &priv->rxq);
9457
iwl4965_hw_txq_ctx_free(priv);
9459
iwl4965_unset_hw_setting(priv);
9460
iwl4965_clear_stations_table(priv);
9462
if (priv->mac80211_registered) {
9463
iwlwifi_ieee80211_unregister_hw(priv->hw);
9464
iwl4965_rate_control_unregister(priv->hw);
9467
/*netif_stop_queue(dev); */
9468
flush_workqueue(priv->workqueue);
9470
/* iwlwifi_ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
9471
* priv->workqueue... so we can't take down the workqueue
9473
destroy_workqueue(priv->workqueue);
9474
priv->workqueue = NULL;
9476
pci_iounmap(pdev, priv->hw_base);
9477
pci_release_regions(pdev);
9478
pci_disable_device(pdev);
9479
pci_set_drvdata(pdev, NULL);
9481
kfree(priv->channel_info);
9483
kfree(priv->ieee_channels);
9484
kfree(priv->ieee_rates);
9486
if (priv->ibss_beacon)
9487
dev_kfree_skb(priv->ibss_beacon);
9489
iwlwifi_ieee80211_free_hw(priv->hw);
9494
static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
9496
struct iwl4965_priv *priv = pci_get_drvdata(pdev);
9498
if (priv->is_open) {
9499
set_bit(STATUS_IN_SUSPEND, &priv->status);
9500
iwl4965_mac_stop(priv->hw);
9504
pci_set_power_state(pdev, PCI_D3hot);
9509
static int iwl4965_pci_resume(struct pci_dev *pdev)
9511
struct iwl4965_priv *priv = pci_get_drvdata(pdev);
9513
pci_set_power_state(pdev, PCI_D0);
9516
iwl4965_mac_open(priv->hw);
9518
clear_bit(STATUS_IN_SUSPEND, &priv->status);
9522
#endif /* CONFIG_PM */
9524
/*****************************************************************************
9526
* driver and module entry point
9528
*****************************************************************************/
9530
static struct pci_driver iwl4965_driver = {
9532
.id_table = iwl4965_hw_card_ids,
9533
.probe = iwl4965_pci_probe,
9534
.remove = __devexit_p(iwl4965_pci_remove),
9536
.suspend = iwl4965_pci_suspend,
9537
.resume = iwl4965_pci_resume,
9541
static int __init iwl4965_init(void)
9545
printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
9546
printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
9547
ret = pci_register_driver(&iwl4965_driver);
9549
IWL_ERROR("Unable to initialize PCI module\n");
9552
#ifdef CONFIG_IWL4965_DEBUG
9553
ret = driver_create_file(&iwl4965_driver.driver, &driver_attr_debug_level);
9555
IWL_ERROR("Unable to create driver sysfs file\n");
9556
pci_unregister_driver(&iwl4965_driver);
9564
static void __exit iwl4965_exit(void)
9566
#ifdef CONFIG_IWL4965_DEBUG
9567
driver_remove_file(&iwl4965_driver.driver, &driver_attr_debug_level);
9569
pci_unregister_driver(&iwl4965_driver);
9572
module_param_named(antenna, iwl4965_param_antenna, int, 0444);
9573
MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
9574
module_param_named(disable, iwl4965_param_disable, int, 0444);
9575
MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
9576
module_param_named(hwcrypto, iwl4965_param_hwcrypto, int, 0444);
9577
MODULE_PARM_DESC(hwcrypto,
9578
"using hardware crypto engine (default 0 [software])\n");
9579
module_param_named(debug, iwl4965_param_debug, int, 0444);
9580
MODULE_PARM_DESC(debug, "debug output mask");
9581
module_param_named(disable_hw_scan, iwl4965_param_disable_hw_scan, int, 0444);
9582
MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
9584
module_param_named(queues_num, iwl4965_param_queues_num, int, 0444);
9585
MODULE_PARM_DESC(queues_num, "number of hw queues.");
9588
module_param_named(qos_enable, iwl4965_param_qos_enable, int, 0444);
9589
MODULE_PARM_DESC(qos_enable, "enable all QoS functionality");
9591
module_exit(iwl4965_exit);
9592
module_init(iwl4965_init);