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_IWL3945_DEBUG
55
u32 iwl3945_debug_level;
58
static int iwl3945_tx_queue_update_write_ptr(struct iwl3945_priv *priv,
59
struct iwl3945_tx_queue *txq);
61
/******************************************************************************
65
******************************************************************************/
67
/* module parameters */
68
static int iwl3945_param_disable_hw_scan; /* def: 0 = use 3945's h/w scan */
69
static int iwl3945_param_debug; /* def: 0 = minimal debug log messages */
70
static int iwl3945_param_disable; /* def: 0 = enable radio */
71
static int iwl3945_param_antenna; /* def: 0 = both antennas (use diversity) */
72
int iwl3945_param_hwcrypto; /* def: 0 = use software encryption */
73
static int iwl3945_param_qos_enable = 1; /* def: 1 = use quality of service */
74
int iwl3945_param_queues_num = IWL_MAX_NUM_QUEUES; /* def: 8 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 \
82
"Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
84
#ifdef CONFIG_IWL3945_DEBUG
90
#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
96
#define IWLWIFI_VERSION "1.2.25" VD VS
97
#define DRV_COPYRIGHT "Copyright(c) 2003-2007 Intel Corporation"
98
#define DRV_VERSION IWLWIFI_VERSION
100
/* Change firmware file name, using "-" and incrementing number,
101
* *only* when uCode interface or architecture changes so that it
102
* is not compatible with earlier drivers.
103
* This number will also appear in << 8 position of 1st dword of uCode file */
104
#define IWL3945_UCODE_API "-1"
106
MODULE_DESCRIPTION(DRV_DESCRIPTION);
107
MODULE_VERSION(DRV_VERSION);
108
MODULE_AUTHOR(DRV_COPYRIGHT);
109
MODULE_LICENSE("GPL");
111
static __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr)
113
u16 fc = le16_to_cpu(hdr->frame_control);
114
int hdr_len = iwlwifi_ieee80211_get_hdrlen(fc);
116
if ((fc & 0x00cc) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA))
117
return (__le16 *) ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN);
121
static const struct ieee80211_hw_mode *iwl3945_get_hw_mode(
122
struct iwl3945_priv *priv, int mode)
126
for (i = 0; i < 3; i++)
127
if (priv->modes[i].mode == mode)
128
return &priv->modes[i];
133
static int iwl3945_is_empty_essid(const char *essid, int essid_len)
135
/* Single white space is for Linksys APs */
136
if (essid_len == 1 && essid[0] == ' ')
139
/* Otherwise, if the entire essid is 0, we assume it is hidden */
142
if (essid[essid_len] != '\0')
149
static const char *iwl3945_escape_essid(const char *essid, u8 essid_len)
151
static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
152
const char *s = essid;
155
if (iwl3945_is_empty_essid(essid, essid_len)) {
156
memcpy(escaped, "<hidden>", sizeof("<hidden>"));
160
essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE);
161
while (essid_len--) {
173
#ifndef hex_dump_to_buffer
174
static inline int snprint_line(char *buf, size_t count,
175
const u8 * data, u32 len, u32 ofs)
180
out = snprintf(buf, count, "%08X", ofs);
182
for (l = 0, i = 0; i < 2; i++) {
183
out += snprintf(buf + out, count - out, " ");
184
for (j = 0; j < 8 && l < len; j++, l++)
186
snprintf(buf + out, count - out, "%02X ",
189
out += snprintf(buf + out, count - out, " ");
191
out += snprintf(buf + out, count - out, " ");
192
for (l = 0, i = 0; i < 2; i++) {
193
out += snprintf(buf + out, count - out, " ");
194
for (j = 0; j < 8 && l < len; j++, l++) {
195
c = data[(i * 8 + j)];
196
if (!isascii(c) || !isprint(c))
199
out += snprintf(buf + out, count - out, "%c", c);
203
out += snprintf(buf + out, count - out, " ");
209
#ifdef CONFIG_IWL3945_DEBUG
210
static inline void printk_buf(int level, const void *p, u32 len)
215
if (!(iwl3945_debug_level & level))
219
snprint_line(line, sizeof(line), &data[ofs],
221
printk(KERN_DEBUG "%s\n", line);
223
len -= min(len, 16U);
227
#define printk_buf(level, p, len) do {} while (0)
230
#define hex_dump_to_buffer(d, s, l, g, lb, ls, a) \
231
snprint_line(lb, ls, d, min(s, (unsigned int)l), 0)
233
#define print_hex_dump(m, p, t, l, g, d, s, a) \
234
printk_buf(IWL_DL_INFO, d, s);
236
#endif /* hex_dump_to_buffer */
238
static void iwl3945_print_hex_dump(int level, void *p, u32 len)
240
#ifdef CONFIG_IWL3945_DEBUG
241
if (!(iwl3945_debug_level & level))
244
print_hex_dump(KERN_DEBUG, "iwl data: ", DUMP_PREFIX_OFFSET, 16, 1,
249
/*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
252
* Theory of operation
254
* A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
255
* of buffer descriptors, each of which points to one or more data buffers for
256
* the device to read from or fill. Driver and device exchange status of each
257
* queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
258
* entries in each circular buffer, to protect against confusing empty and full
261
* The device reads or writes the data in the queues via the device's several
262
* DMA/FIFO channels. Each queue is mapped to a single DMA channel.
264
* For Tx queue, there are low mark and high mark limits. If, after queuing
265
* the packet for Tx, free space become < low mark, Tx queue stopped. When
266
* reclaiming packets (on 'tx done IRQ), if free space become > high mark,
269
* The 3945 operates with six queues: One receive queue, one transmit queue
270
* (#4) for sending commands to the device firmware, and four transmit queues
271
* (#0-3) for data tx via EDCA. An additional 2 HCCA queues are unused.
272
***************************************************/
274
static int iwl3945_queue_space(const struct iwl3945_queue *q)
276
int s = q->read_ptr - q->write_ptr;
278
if (q->read_ptr > q->write_ptr)
283
/* keep some reserve to not confuse empty and full situations */
291
* iwl3945_queue_inc_wrap - increment queue index, wrap back to beginning
292
* @index -- current index
293
* @n_bd -- total number of entries in queue (must be power of 2)
295
static inline int iwl3945_queue_inc_wrap(int index, int n_bd)
297
return ++index & (n_bd - 1);
301
* iwl3945_queue_dec_wrap - increment queue index, wrap back to end
302
* @index -- current index
303
* @n_bd -- total number of entries in queue (must be power of 2)
305
static inline int iwl3945_queue_dec_wrap(int index, int n_bd)
307
return --index & (n_bd - 1);
310
static inline int x2_queue_used(const struct iwl3945_queue *q, int i)
312
return q->write_ptr > q->read_ptr ?
313
(i >= q->read_ptr && i < q->write_ptr) :
314
!(i < q->read_ptr && i >= q->write_ptr);
317
static inline u8 get_cmd_index(struct iwl3945_queue *q, u32 index, int is_huge)
319
/* This is for scan command, the big buffer at end of command array */
321
return q->n_window; /* must be power of 2 */
323
/* Otherwise, use normal size buffers */
324
return index & (q->n_window - 1);
328
* iwl3945_queue_init - Initialize queue's high/low-water and read/write indexes
330
static int iwl3945_queue_init(struct iwl3945_priv *priv, struct iwl3945_queue *q,
331
int count, int slots_num, u32 id)
334
q->n_window = slots_num;
337
/* count must be power-of-two size, otherwise iwl3945_queue_inc_wrap
338
* and iwl3945_queue_dec_wrap are broken. */
339
BUG_ON(!is_power_of_2(count));
341
/* slots_num must be power-of-two size, otherwise
342
* get_cmd_index is broken. */
343
BUG_ON(!is_power_of_2(slots_num));
345
q->low_mark = q->n_window / 4;
349
q->high_mark = q->n_window / 8;
350
if (q->high_mark < 2)
353
q->write_ptr = q->read_ptr = 0;
359
* iwl3945_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
361
static int iwl3945_tx_queue_alloc(struct iwl3945_priv *priv,
362
struct iwl3945_tx_queue *txq, u32 id)
364
struct pci_dev *dev = priv->pci_dev;
366
/* Driver private data, only for Tx (not command) queues,
367
* not shared with device. */
368
if (id != IWL_CMD_QUEUE_NUM) {
369
txq->txb = kmalloc(sizeof(txq->txb[0]) *
370
TFD_QUEUE_SIZE_MAX, GFP_KERNEL);
372
IWL_ERROR("kmalloc for auxiliary BD "
373
"structures failed\n");
379
/* Circular buffer of transmit frame descriptors (TFDs),
380
* shared with device */
381
txq->bd = pci_alloc_consistent(dev,
382
sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX,
386
IWL_ERROR("pci_alloc_consistent(%zd) failed\n",
387
sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX);
404
* iwl3945_tx_queue_init - Allocate and initialize one tx/cmd queue
406
int iwl3945_tx_queue_init(struct iwl3945_priv *priv,
407
struct iwl3945_tx_queue *txq, int slots_num, u32 txq_id)
409
struct pci_dev *dev = priv->pci_dev;
414
* Alloc buffer array for commands (Tx or other types of commands).
415
* For the command queue (#4), allocate command space + one big
416
* command for scan, since scan command is very huge; the system will
417
* not have two scans at the same time, so only one is needed.
418
* For data Tx queues (all other queues), no super-size command
421
len = sizeof(struct iwl3945_cmd) * slots_num;
422
if (txq_id == IWL_CMD_QUEUE_NUM)
423
len += IWL_MAX_SCAN_SIZE;
424
txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd);
428
/* Alloc driver data array and TFD circular buffer */
429
rc = iwl3945_tx_queue_alloc(priv, txq, txq_id);
431
pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
435
txq->need_update = 0;
437
/* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
438
* iwl3945_queue_inc_wrap and iwl3945_queue_dec_wrap are broken. */
439
BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
441
/* Initialize queue high/low-water, head/tail indexes */
442
iwl3945_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id);
444
/* Tell device where to find queue, enable DMA channel. */
445
iwl3945_hw_tx_queue_init(priv, txq);
451
* iwl3945_tx_queue_free - Deallocate DMA queue.
452
* @txq: Transmit queue to deallocate.
454
* Empty queue by removing and destroying all BD's.
456
* 0-fill, but do not free "txq" descriptor structure.
458
void iwl3945_tx_queue_free(struct iwl3945_priv *priv, struct iwl3945_tx_queue *txq)
460
struct iwl3945_queue *q = &txq->q;
461
struct pci_dev *dev = priv->pci_dev;
467
/* first, empty all BD's */
468
for (; q->write_ptr != q->read_ptr;
469
q->read_ptr = iwl3945_queue_inc_wrap(q->read_ptr, q->n_bd))
470
iwl3945_hw_txq_free_tfd(priv, txq);
472
len = sizeof(struct iwl3945_cmd) * q->n_window;
473
if (q->id == IWL_CMD_QUEUE_NUM)
474
len += IWL_MAX_SCAN_SIZE;
476
/* De-alloc array of command/tx buffers */
477
pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
479
/* De-alloc circular buffer of TFDs */
481
pci_free_consistent(dev, sizeof(struct iwl3945_tfd_frame) *
482
txq->q.n_bd, txq->bd, txq->q.dma_addr);
484
/* De-alloc array of per-TFD driver data */
490
/* 0-fill queue descriptor structure */
491
memset(txq, 0, sizeof(*txq));
494
const u8 iwl3945_broadcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
496
/*************** STATION TABLE MANAGEMENT ****
497
* mac80211 should be examined to determine if sta_info is duplicating
498
* the functionality provided here
501
/**************************************************************/
502
#if 0 /* temporary disable till we add real remove station */
504
* iwl3945_remove_station - Remove driver's knowledge of station.
506
* NOTE: This does not remove station from device's station table.
508
static u8 iwl3945_remove_station(struct iwl3945_priv *priv, const u8 *addr, int is_ap)
510
int index = IWL_INVALID_STATION;
514
spin_lock_irqsave(&priv->sta_lock, flags);
518
else if (is_broadcast_ether_addr(addr))
519
index = priv->hw_setting.bcast_sta_id;
521
for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++)
522
if (priv->stations[i].used &&
523
!compare_ether_addr(priv->stations[i].sta.sta.addr,
529
if (unlikely(index == IWL_INVALID_STATION))
532
if (priv->stations[index].used) {
533
priv->stations[index].used = 0;
534
priv->num_stations--;
537
BUG_ON(priv->num_stations < 0);
540
spin_unlock_irqrestore(&priv->sta_lock, flags);
546
* iwl3945_clear_stations_table - Clear the driver's station table
548
* NOTE: This does not clear or otherwise alter the device's station table.
550
static void iwl3945_clear_stations_table(struct iwl3945_priv *priv)
554
spin_lock_irqsave(&priv->sta_lock, flags);
556
priv->num_stations = 0;
557
memset(priv->stations, 0, sizeof(priv->stations));
559
spin_unlock_irqrestore(&priv->sta_lock, flags);
563
* iwl3945_add_station - Add station to station tables in driver and device
565
u8 iwl3945_add_station(struct iwl3945_priv *priv, const u8 *addr, int is_ap, u8 flags)
568
int index = IWL_INVALID_STATION;
569
struct iwl3945_station_entry *station;
570
unsigned long flags_spin;
573
spin_lock_irqsave(&priv->sta_lock, flags_spin);
576
else if (is_broadcast_ether_addr(addr))
577
index = priv->hw_setting.bcast_sta_id;
579
for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) {
580
if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
586
if (!priv->stations[i].used &&
587
index == IWL_INVALID_STATION)
591
/* These two conditions has the same outcome but keep them separate
592
since they have different meaning */
593
if (unlikely(index == IWL_INVALID_STATION)) {
594
spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
598
if (priv->stations[index].used &&
599
!compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) {
600
spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
604
IWL_DEBUG_ASSOC("Add STA ID %d: " MAC_FMT "\n", index, MAC_ARG(addr));
605
station = &priv->stations[index];
607
priv->num_stations++;
609
/* Set up the REPLY_ADD_STA command to send to device */
610
memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd));
611
memcpy(station->sta.sta.addr, addr, ETH_ALEN);
612
station->sta.mode = 0;
613
station->sta.sta.sta_id = index;
614
station->sta.station_flags = 0;
616
if (priv->phymode == MODE_IEEE80211A)
617
rate = IWL_RATE_6M_PLCP;
619
rate = IWL_RATE_1M_PLCP;
621
/* Turn on both antennas for the station... */
622
station->sta.rate_n_flags =
623
iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK);
624
station->current_rate.rate_n_flags =
625
le16_to_cpu(station->sta.rate_n_flags);
627
spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
629
/* Add station to device's station table */
630
iwl3945_send_add_station(priv, &station->sta, flags);
635
/*************** DRIVER STATUS FUNCTIONS *****/
637
static inline int iwl3945_is_ready(struct iwl3945_priv *priv)
639
/* The adapter is 'ready' if READY and GEO_CONFIGURED bits are
640
* set but EXIT_PENDING is not */
641
return test_bit(STATUS_READY, &priv->status) &&
642
test_bit(STATUS_GEO_CONFIGURED, &priv->status) &&
643
!test_bit(STATUS_EXIT_PENDING, &priv->status);
646
static inline int iwl3945_is_alive(struct iwl3945_priv *priv)
648
return test_bit(STATUS_ALIVE, &priv->status);
651
static inline int iwl3945_is_init(struct iwl3945_priv *priv)
653
return test_bit(STATUS_INIT, &priv->status);
656
static inline int iwl3945_is_rfkill(struct iwl3945_priv *priv)
658
return test_bit(STATUS_RF_KILL_HW, &priv->status) ||
659
test_bit(STATUS_RF_KILL_SW, &priv->status);
662
static inline int iwl3945_is_ready_rf(struct iwl3945_priv *priv)
665
if (iwl3945_is_rfkill(priv))
668
return iwl3945_is_ready(priv);
671
/*************** HOST COMMAND QUEUE FUNCTIONS *****/
673
#define IWL_CMD(x) case x : return #x
675
static const char *get_cmd_string(u8 cmd)
678
IWL_CMD(REPLY_ALIVE);
679
IWL_CMD(REPLY_ERROR);
681
IWL_CMD(REPLY_RXON_ASSOC);
682
IWL_CMD(REPLY_QOS_PARAM);
683
IWL_CMD(REPLY_RXON_TIMING);
684
IWL_CMD(REPLY_ADD_STA);
685
IWL_CMD(REPLY_REMOVE_STA);
686
IWL_CMD(REPLY_REMOVE_ALL_STA);
687
IWL_CMD(REPLY_3945_RX);
689
IWL_CMD(REPLY_RATE_SCALE);
690
IWL_CMD(REPLY_LEDS_CMD);
691
IWL_CMD(REPLY_TX_LINK_QUALITY_CMD);
692
IWL_CMD(RADAR_NOTIFICATION);
693
IWL_CMD(REPLY_QUIET_CMD);
694
IWL_CMD(REPLY_CHANNEL_SWITCH);
695
IWL_CMD(CHANNEL_SWITCH_NOTIFICATION);
696
IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD);
697
IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION);
698
IWL_CMD(POWER_TABLE_CMD);
699
IWL_CMD(PM_SLEEP_NOTIFICATION);
700
IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC);
701
IWL_CMD(REPLY_SCAN_CMD);
702
IWL_CMD(REPLY_SCAN_ABORT_CMD);
703
IWL_CMD(SCAN_START_NOTIFICATION);
704
IWL_CMD(SCAN_RESULTS_NOTIFICATION);
705
IWL_CMD(SCAN_COMPLETE_NOTIFICATION);
706
IWL_CMD(BEACON_NOTIFICATION);
707
IWL_CMD(REPLY_TX_BEACON);
708
IWL_CMD(WHO_IS_AWAKE_NOTIFICATION);
709
IWL_CMD(QUIET_NOTIFICATION);
710
IWL_CMD(REPLY_TX_PWR_TABLE_CMD);
711
IWL_CMD(MEASURE_ABORT_NOTIFICATION);
712
IWL_CMD(REPLY_BT_CONFIG);
713
IWL_CMD(REPLY_STATISTICS_CMD);
714
IWL_CMD(STATISTICS_NOTIFICATION);
715
IWL_CMD(REPLY_CARD_STATE_CMD);
716
IWL_CMD(CARD_STATE_NOTIFICATION);
717
IWL_CMD(MISSED_BEACONS_NOTIFICATION);
724
#define HOST_COMPLETE_TIMEOUT (HZ / 2)
727
* iwl3945_enqueue_hcmd - enqueue a uCode command
728
* @priv: device private data point
729
* @cmd: a point to the ucode command structure
731
* The function returns < 0 values to indicate the operation is
732
* failed. On success, it turns the index (> 0) of command in the
735
static int iwl3945_enqueue_hcmd(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd)
737
struct iwl3945_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
738
struct iwl3945_queue *q = &txq->q;
739
struct iwl3945_tfd_frame *tfd;
741
struct iwl3945_cmd *out_cmd;
743
u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
744
dma_addr_t phys_addr;
750
/* If any of the command structures end up being larger than
751
* the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
752
* we will need to increase the size of the TFD entries */
753
BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
754
!(cmd->meta.flags & CMD_SIZE_HUGE));
756
if (iwl3945_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) {
757
IWL_ERROR("No space for Tx\n");
761
spin_lock_irqsave(&priv->hcmd_lock, flags);
763
tfd = &txq->bd[q->write_ptr];
764
memset(tfd, 0, sizeof(*tfd));
766
control_flags = (u32 *) tfd;
768
idx = get_cmd_index(q, q->write_ptr, cmd->meta.flags & CMD_SIZE_HUGE);
769
out_cmd = &txq->cmd[idx];
771
out_cmd->hdr.cmd = cmd->id;
772
memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta));
773
memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len);
775
/* At this point, the out_cmd now has all of the incoming cmd
778
out_cmd->hdr.flags = 0;
779
out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) |
780
INDEX_TO_SEQ(q->write_ptr));
781
if (out_cmd->meta.flags & CMD_SIZE_HUGE)
782
out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME);
784
phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx +
785
offsetof(struct iwl3945_cmd, hdr);
786
iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size);
788
pad = U32_PAD(cmd->len);
789
count = TFD_CTL_COUNT_GET(*control_flags);
790
*control_flags = TFD_CTL_COUNT_SET(count) | TFD_CTL_PAD_SET(pad);
792
IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
793
"%d bytes at %d[%d]:%d\n",
794
get_cmd_string(out_cmd->hdr.cmd),
795
out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence),
796
fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM);
798
txq->need_update = 1;
800
/* Increment and update queue's write index */
801
q->write_ptr = iwl3945_queue_inc_wrap(q->write_ptr, q->n_bd);
802
ret = iwl3945_tx_queue_update_write_ptr(priv, txq);
804
spin_unlock_irqrestore(&priv->hcmd_lock, flags);
805
return ret ? ret : idx;
808
static int iwl3945_send_cmd_async(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd)
812
BUG_ON(!(cmd->meta.flags & CMD_ASYNC));
814
/* An asynchronous command can not expect an SKB to be set. */
815
BUG_ON(cmd->meta.flags & CMD_WANT_SKB);
817
/* An asynchronous command MUST have a callback. */
818
BUG_ON(!cmd->meta.u.callback);
820
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
823
ret = iwl3945_enqueue_hcmd(priv, cmd);
825
IWL_ERROR("Error sending %s: iwl3945_enqueue_hcmd failed: %d\n",
826
get_cmd_string(cmd->id), ret);
832
static int iwl3945_send_cmd_sync(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd)
836
static atomic_t entry = ATOMIC_INIT(0); /* reentrance protection */
838
BUG_ON(cmd->meta.flags & CMD_ASYNC);
840
/* A synchronous command can not have a callback set. */
841
BUG_ON(cmd->meta.u.callback != NULL);
843
if (atomic_xchg(&entry, 1)) {
844
IWL_ERROR("Error sending %s: Already sending a host command\n",
845
get_cmd_string(cmd->id));
849
set_bit(STATUS_HCMD_ACTIVE, &priv->status);
851
if (cmd->meta.flags & CMD_WANT_SKB)
852
cmd->meta.source = &cmd->meta;
854
cmd_idx = iwl3945_enqueue_hcmd(priv, cmd);
857
IWL_ERROR("Error sending %s: iwl3945_enqueue_hcmd failed: %d\n",
858
get_cmd_string(cmd->id), ret);
862
ret = wait_event_interruptible_timeout(priv->wait_command_queue,
863
!test_bit(STATUS_HCMD_ACTIVE, &priv->status),
864
HOST_COMPLETE_TIMEOUT);
866
if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) {
867
IWL_ERROR("Error sending %s: time out after %dms.\n",
868
get_cmd_string(cmd->id),
869
jiffies_to_msecs(HOST_COMPLETE_TIMEOUT));
871
clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
877
if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
878
IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n",
879
get_cmd_string(cmd->id));
883
if (test_bit(STATUS_FW_ERROR, &priv->status)) {
884
IWL_DEBUG_INFO("Command %s failed: FW Error\n",
885
get_cmd_string(cmd->id));
889
if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) {
890
IWL_ERROR("Error: Response NULL in '%s'\n",
891
get_cmd_string(cmd->id));
900
if (cmd->meta.flags & CMD_WANT_SKB) {
901
struct iwl3945_cmd *qcmd;
903
/* Cancel the CMD_WANT_SKB flag for the cmd in the
904
* TX cmd queue. Otherwise in case the cmd comes
905
* in later, it will possibly set an invalid
906
* address (cmd->meta.source). */
907
qcmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx];
908
qcmd->meta.flags &= ~CMD_WANT_SKB;
911
if (cmd->meta.u.skb) {
912
dev_kfree_skb_any(cmd->meta.u.skb);
913
cmd->meta.u.skb = NULL;
916
atomic_set(&entry, 0);
920
int iwl3945_send_cmd(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd)
922
if (cmd->meta.flags & CMD_ASYNC)
923
return iwl3945_send_cmd_async(priv, cmd);
925
return iwl3945_send_cmd_sync(priv, cmd);
928
int iwl3945_send_cmd_pdu(struct iwl3945_priv *priv, u8 id, u16 len, const void *data)
930
struct iwl3945_host_cmd cmd = {
936
return iwl3945_send_cmd_sync(priv, &cmd);
939
static int __must_check iwl3945_send_cmd_u32(struct iwl3945_priv *priv, u8 id, u32 val)
941
struct iwl3945_host_cmd cmd = {
947
return iwl3945_send_cmd_sync(priv, &cmd);
950
int iwl3945_send_statistics_request(struct iwl3945_priv *priv)
952
return iwl3945_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0);
956
* iwl3945_set_rxon_channel - Set the phymode and channel values in staging RXON
957
* @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz
958
* @channel: Any channel valid for the requested phymode
960
* In addition to setting the staging RXON, priv->phymode is also set.
962
* NOTE: Does not commit to the hardware; it sets appropriate bit fields
963
* in the staging RXON flag structure based on the phymode
965
static int iwl3945_set_rxon_channel(struct iwl3945_priv *priv, u8 phymode, u16 channel)
967
if (!iwl3945_get_channel_info(priv, phymode, channel)) {
968
IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
973
if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
974
(priv->phymode == phymode))
977
priv->staging_rxon.channel = cpu_to_le16(channel);
978
if (phymode == MODE_IEEE80211A)
979
priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
981
priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
983
priv->phymode = phymode;
985
IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, phymode);
991
* iwl3945_check_rxon_cmd - validate RXON structure is valid
993
* NOTE: This is really only useful during development and can eventually
994
* be #ifdef'd out once the driver is stable and folks aren't actively
997
static int iwl3945_check_rxon_cmd(struct iwl3945_rxon_cmd *rxon)
1002
if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
1003
error |= le32_to_cpu(rxon->flags &
1004
(RXON_FLG_TGJ_NARROW_BAND_MSK |
1005
RXON_FLG_RADAR_DETECT_MSK));
1007
IWL_WARNING("check 24G fields %d | %d\n",
1010
error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
1011
0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
1013
IWL_WARNING("check 52 fields %d | %d\n",
1015
error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
1017
IWL_WARNING("check 52 CCK %d | %d\n",
1020
error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
1022
IWL_WARNING("check mac addr %d | %d\n", counter++, error);
1024
/* make sure basic rates 6Mbps and 1Mbps are supported */
1025
error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
1026
((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
1028
IWL_WARNING("check basic rate %d | %d\n", counter++, error);
1030
error |= (le16_to_cpu(rxon->assoc_id) > 2007);
1032
IWL_WARNING("check assoc id %d | %d\n", counter++, error);
1034
error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
1035
== (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
1037
IWL_WARNING("check CCK and short slot %d | %d\n",
1040
error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
1041
== (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
1043
IWL_WARNING("check CCK & auto detect %d | %d\n",
1046
error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
1047
RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
1049
IWL_WARNING("check TGG and auto detect %d | %d\n",
1052
if ((rxon->flags & RXON_FLG_DIS_DIV_MSK))
1053
error |= ((rxon->flags & (RXON_FLG_ANT_B_MSK |
1054
RXON_FLG_ANT_A_MSK)) == 0);
1056
IWL_WARNING("check antenna %d %d\n", counter++, error);
1059
IWL_WARNING("Tuning to channel %d\n",
1060
le16_to_cpu(rxon->channel));
1063
IWL_ERROR("Not a valid iwl3945_rxon_assoc_cmd field values\n");
1070
* iwl3945_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
1071
* @priv: staging_rxon is compared to active_rxon
1073
* If the RXON structure is changing enough to require a new tune,
1074
* or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
1075
* a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
1077
static int iwl3945_full_rxon_required(struct iwl3945_priv *priv)
1080
/* These items are only settable from the full RXON command */
1081
if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ||
1082
compare_ether_addr(priv->staging_rxon.bssid_addr,
1083
priv->active_rxon.bssid_addr) ||
1084
compare_ether_addr(priv->staging_rxon.node_addr,
1085
priv->active_rxon.node_addr) ||
1086
compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
1087
priv->active_rxon.wlap_bssid_addr) ||
1088
(priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
1089
(priv->staging_rxon.channel != priv->active_rxon.channel) ||
1090
(priv->staging_rxon.air_propagation !=
1091
priv->active_rxon.air_propagation) ||
1092
(priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
1095
/* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
1096
* be updated with the RXON_ASSOC command -- however only some
1097
* flag transitions are allowed using RXON_ASSOC */
1099
/* Check if we are not switching bands */
1100
if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
1101
(priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
1104
/* Check if we are switching association toggle */
1105
if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
1106
(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
1112
static int iwl3945_send_rxon_assoc(struct iwl3945_priv *priv)
1115
struct iwl3945_rx_packet *res = NULL;
1116
struct iwl3945_rxon_assoc_cmd rxon_assoc;
1117
struct iwl3945_host_cmd cmd = {
1118
.id = REPLY_RXON_ASSOC,
1119
.len = sizeof(rxon_assoc),
1120
.meta.flags = CMD_WANT_SKB,
1121
.data = &rxon_assoc,
1123
const struct iwl3945_rxon_cmd *rxon1 = &priv->staging_rxon;
1124
const struct iwl3945_rxon_cmd *rxon2 = &priv->active_rxon;
1126
if ((rxon1->flags == rxon2->flags) &&
1127
(rxon1->filter_flags == rxon2->filter_flags) &&
1128
(rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
1129
(rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
1130
IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
1134
rxon_assoc.flags = priv->staging_rxon.flags;
1135
rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
1136
rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
1137
rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
1138
rxon_assoc.reserved = 0;
1140
rc = iwl3945_send_cmd_sync(priv, &cmd);
1144
res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data;
1145
if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1146
IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n");
1150
priv->alloc_rxb_skb--;
1151
dev_kfree_skb_any(cmd.meta.u.skb);
1157
* iwl3945_commit_rxon - commit staging_rxon to hardware
1159
* The RXON command in staging_rxon is committed to the hardware and
1160
* the active_rxon structure is updated with the new data. This
1161
* function correctly transitions out of the RXON_ASSOC_MSK state if
1162
* a HW tune is required based on the RXON structure changes.
1164
static int iwl3945_commit_rxon(struct iwl3945_priv *priv)
1166
/* cast away the const for active_rxon in this function */
1167
struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
1170
if (!iwl3945_is_alive(priv))
1173
/* always get timestamp with Rx frame */
1174
priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
1176
/* select antenna */
1177
priv->staging_rxon.flags &=
1178
~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
1179
priv->staging_rxon.flags |= iwl3945_get_antenna_flags(priv);
1181
rc = iwl3945_check_rxon_cmd(&priv->staging_rxon);
1183
IWL_ERROR("Invalid RXON configuration. Not committing.\n");
1187
/* If we don't need to send a full RXON, we can use
1188
* iwl3945_rxon_assoc_cmd which is used to reconfigure filter
1189
* and other flags for the current radio configuration. */
1190
if (!iwl3945_full_rxon_required(priv)) {
1191
rc = iwl3945_send_rxon_assoc(priv);
1193
IWL_ERROR("Error setting RXON_ASSOC "
1194
"configuration (%d).\n", rc);
1198
memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
1203
/* If we are currently associated and the new config requires
1204
* an RXON_ASSOC and the new config wants the associated mask enabled,
1205
* we must clear the associated from the active configuration
1206
* before we apply the new config */
1207
if (iwl3945_is_associated(priv) &&
1208
(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
1209
IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
1210
active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1212
rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON,
1213
sizeof(struct iwl3945_rxon_cmd),
1214
&priv->active_rxon);
1216
/* If the mask clearing failed then we set
1217
* active_rxon back to what it was previously */
1219
active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
1220
IWL_ERROR("Error clearing ASSOC_MSK on current "
1221
"configuration (%d).\n", rc);
1226
IWL_DEBUG_INFO("Sending RXON\n"
1227
"* with%s RXON_FILTER_ASSOC_MSK\n"
1229
"* bssid = " MAC_FMT "\n",
1230
((priv->staging_rxon.filter_flags &
1231
RXON_FILTER_ASSOC_MSK) ? "" : "out"),
1232
le16_to_cpu(priv->staging_rxon.channel),
1233
MAC_ARG(priv->staging_rxon.bssid_addr));
1235
/* Apply the new configuration */
1236
rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON,
1237
sizeof(struct iwl3945_rxon_cmd), &priv->staging_rxon);
1239
IWL_ERROR("Error setting new configuration (%d).\n", rc);
1243
memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
1245
iwl3945_clear_stations_table(priv);
1247
/* If we issue a new RXON command which required a tune then we must
1248
* send a new TXPOWER command or we won't be able to Tx any frames */
1249
rc = iwl3945_hw_reg_send_txpower(priv);
1251
IWL_ERROR("Error setting Tx power (%d).\n", rc);
1255
/* Add the broadcast address so we can send broadcast frames */
1256
if (iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0) ==
1257
IWL_INVALID_STATION) {
1258
IWL_ERROR("Error adding BROADCAST address for transmit.\n");
1262
/* If we have set the ASSOC_MSK and we are in BSS mode then
1263
* add the IWL_AP_ID to the station rate table */
1264
if (iwl3945_is_associated(priv) &&
1265
(priv->iw_mode == IEEE80211_IF_TYPE_STA))
1266
if (iwl3945_add_station(priv, priv->active_rxon.bssid_addr, 1, 0)
1267
== IWL_INVALID_STATION) {
1268
IWL_ERROR("Error adding AP address for transmit.\n");
1272
/* Init the hardware's rate fallback order based on the
1274
rc = iwl3945_init_hw_rate_table(priv);
1276
IWL_ERROR("Error setting HW rate table: %02X\n", rc);
1283
static int iwl3945_send_bt_config(struct iwl3945_priv *priv)
1285
struct iwl3945_bt_cmd bt_cmd = {
1293
return iwl3945_send_cmd_pdu(priv, REPLY_BT_CONFIG,
1294
sizeof(struct iwl3945_bt_cmd), &bt_cmd);
1297
static int iwl3945_send_scan_abort(struct iwl3945_priv *priv)
1300
struct iwl3945_rx_packet *res;
1301
struct iwl3945_host_cmd cmd = {
1302
.id = REPLY_SCAN_ABORT_CMD,
1303
.meta.flags = CMD_WANT_SKB,
1306
/* If there isn't a scan actively going on in the hardware
1307
* then we are in between scan bands and not actually
1308
* actively scanning, so don't send the abort command */
1309
if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
1310
clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1314
rc = iwl3945_send_cmd_sync(priv, &cmd);
1316
clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1320
res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data;
1321
if (res->u.status != CAN_ABORT_STATUS) {
1322
/* The scan abort will return 1 for success or
1323
* 2 for "failure". A failure condition can be
1324
* due to simply not being in an active scan which
1325
* can occur if we send the scan abort before we
1326
* the microcode has notified us that a scan is
1328
IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status);
1329
clear_bit(STATUS_SCAN_ABORTING, &priv->status);
1330
clear_bit(STATUS_SCAN_HW, &priv->status);
1333
dev_kfree_skb_any(cmd.meta.u.skb);
1338
static int iwl3945_card_state_sync_callback(struct iwl3945_priv *priv,
1339
struct iwl3945_cmd *cmd,
1340
struct sk_buff *skb)
1348
* Use: Sets the device's internal card state to enable, disable, or halt
1350
* When in the 'enable' state the card operates as normal.
1351
* When in the 'disable' state, the card enters into a low power mode.
1352
* When in the 'halt' state, the card is shut down and must be fully
1353
* restarted to come back on.
1355
static int iwl3945_send_card_state(struct iwl3945_priv *priv, u32 flags, u8 meta_flag)
1357
struct iwl3945_host_cmd cmd = {
1358
.id = REPLY_CARD_STATE_CMD,
1361
.meta.flags = meta_flag,
1364
if (meta_flag & CMD_ASYNC)
1365
cmd.meta.u.callback = iwl3945_card_state_sync_callback;
1367
return iwl3945_send_cmd(priv, &cmd);
1370
static int iwl3945_add_sta_sync_callback(struct iwl3945_priv *priv,
1371
struct iwl3945_cmd *cmd, struct sk_buff *skb)
1373
struct iwl3945_rx_packet *res = NULL;
1376
IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
1380
res = (struct iwl3945_rx_packet *)skb->data;
1381
if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1382
IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1387
switch (res->u.add_sta.status) {
1388
case ADD_STA_SUCCESS_MSK:
1394
/* We didn't cache the SKB; let the caller free it */
1398
int iwl3945_send_add_station(struct iwl3945_priv *priv,
1399
struct iwl3945_addsta_cmd *sta, u8 flags)
1401
struct iwl3945_rx_packet *res = NULL;
1403
struct iwl3945_host_cmd cmd = {
1404
.id = REPLY_ADD_STA,
1405
.len = sizeof(struct iwl3945_addsta_cmd),
1406
.meta.flags = flags,
1410
if (flags & CMD_ASYNC)
1411
cmd.meta.u.callback = iwl3945_add_sta_sync_callback;
1413
cmd.meta.flags |= CMD_WANT_SKB;
1415
rc = iwl3945_send_cmd(priv, &cmd);
1417
if (rc || (flags & CMD_ASYNC))
1420
res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data;
1421
if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
1422
IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1428
switch (res->u.add_sta.status) {
1429
case ADD_STA_SUCCESS_MSK:
1430
IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
1434
IWL_WARNING("REPLY_ADD_STA failed\n");
1439
priv->alloc_rxb_skb--;
1440
dev_kfree_skb_any(cmd.meta.u.skb);
1445
static int iwl3945_update_sta_key_info(struct iwl3945_priv *priv,
1446
struct ieee80211_key_conf *keyconf,
1449
unsigned long flags;
1450
__le16 key_flags = 0;
1452
switch (keyconf->alg) {
1454
key_flags |= STA_KEY_FLG_CCMP;
1455
key_flags |= cpu_to_le16(
1456
keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
1457
key_flags &= ~STA_KEY_FLG_INVALID;
1464
spin_lock_irqsave(&priv->sta_lock, flags);
1465
priv->stations[sta_id].keyinfo.alg = keyconf->alg;
1466
priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
1467
memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
1470
memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
1472
priv->stations[sta_id].sta.key.key_flags = key_flags;
1473
priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1474
priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1476
spin_unlock_irqrestore(&priv->sta_lock, flags);
1478
IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
1479
iwl3945_send_add_station(priv, &priv->stations[sta_id].sta, 0);
1483
static int iwl3945_clear_sta_key_info(struct iwl3945_priv *priv, u8 sta_id)
1485
unsigned long flags;
1487
spin_lock_irqsave(&priv->sta_lock, flags);
1488
memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key));
1489
memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl3945_keyinfo));
1490
priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
1491
priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1492
priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1493
spin_unlock_irqrestore(&priv->sta_lock, flags);
1495
IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
1496
iwl3945_send_add_station(priv, &priv->stations[sta_id].sta, 0);
1500
static void iwl3945_clear_free_frames(struct iwl3945_priv *priv)
1502
struct list_head *element;
1504
IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
1505
priv->frames_count);
1507
while (!list_empty(&priv->free_frames)) {
1508
element = priv->free_frames.next;
1510
kfree(list_entry(element, struct iwl3945_frame, list));
1511
priv->frames_count--;
1514
if (priv->frames_count) {
1515
IWL_WARNING("%d frames still in use. Did we lose one?\n",
1516
priv->frames_count);
1517
priv->frames_count = 0;
1521
static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl3945_priv *priv)
1523
struct iwl3945_frame *frame;
1524
struct list_head *element;
1525
if (list_empty(&priv->free_frames)) {
1526
frame = kzalloc(sizeof(*frame), GFP_KERNEL);
1528
IWL_ERROR("Could not allocate frame!\n");
1532
priv->frames_count++;
1536
element = priv->free_frames.next;
1538
return list_entry(element, struct iwl3945_frame, list);
1541
static void iwl3945_free_frame(struct iwl3945_priv *priv, struct iwl3945_frame *frame)
1543
memset(frame, 0, sizeof(*frame));
1544
list_add(&frame->list, &priv->free_frames);
1547
unsigned int iwl3945_fill_beacon_frame(struct iwl3945_priv *priv,
1548
struct ieee80211_hdr *hdr,
1549
const u8 *dest, int left)
1552
if (!iwl3945_is_associated(priv) || !priv->ibss_beacon ||
1553
((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) &&
1554
(priv->iw_mode != IEEE80211_IF_TYPE_AP)))
1557
if (priv->ibss_beacon->len > left)
1560
memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
1562
return priv->ibss_beacon->len;
1565
static int iwl3945_rate_index_from_plcp(int plcp)
1569
for (i = 0; i < IWL_RATE_COUNT; i++)
1570
if (iwl3945_rates[i].plcp == plcp)
1575
static u8 iwl3945_rate_get_lowest_plcp(int rate_mask)
1579
for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
1580
i = iwl3945_rates[i].next_ieee) {
1581
if (rate_mask & (1 << i))
1582
return iwl3945_rates[i].plcp;
1585
return IWL_RATE_INVALID;
1588
static int iwl3945_send_beacon_cmd(struct iwl3945_priv *priv)
1590
struct iwl3945_frame *frame;
1591
unsigned int frame_size;
1595
frame = iwl3945_get_free_frame(priv);
1598
IWL_ERROR("Could not obtain free frame buffer for beacon "
1603
if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) {
1604
rate = iwl3945_rate_get_lowest_plcp(priv->active_rate_basic &
1606
if (rate == IWL_INVALID_RATE)
1607
rate = IWL_RATE_6M_PLCP;
1609
rate = iwl3945_rate_get_lowest_plcp(priv->active_rate_basic & 0xF);
1610
if (rate == IWL_INVALID_RATE)
1611
rate = IWL_RATE_1M_PLCP;
1614
frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
1616
rc = iwl3945_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
1619
iwl3945_free_frame(priv, frame);
1624
/******************************************************************************
1626
* EEPROM related functions
1628
******************************************************************************/
1630
static void get_eeprom_mac(struct iwl3945_priv *priv, u8 *mac)
1632
memcpy(mac, priv->eeprom.mac_address, 6);
1636
* iwl3945_eeprom_init - read EEPROM contents
1638
* Load the EEPROM contents from adapter into priv->eeprom
1640
* NOTE: This routine uses the non-debug IO access functions.
1642
int iwl3945_eeprom_init(struct iwl3945_priv *priv)
1644
u16 *e = (u16 *)&priv->eeprom;
1645
u32 gp = iwl3945_read32(priv, CSR_EEPROM_GP);
1647
int sz = sizeof(priv->eeprom);
1652
/* The EEPROM structure has several padding buffers within it
1653
* and when adding new EEPROM maps is subject to programmer errors
1654
* which may be very difficult to identify without explicitly
1655
* checking the resulting size of the eeprom map. */
1656
BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE);
1658
if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) {
1659
IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp);
1663
/* Make sure driver (instead of uCode) is allowed to read EEPROM */
1664
rc = iwl3945_eeprom_acquire_semaphore(priv);
1666
IWL_ERROR("Failed to acquire EEPROM semaphore.\n");
1670
/* eeprom is an array of 16bit values */
1671
for (addr = 0; addr < sz; addr += sizeof(u16)) {
1672
_iwl3945_write32(priv, CSR_EEPROM_REG, addr << 1);
1673
_iwl3945_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD);
1675
for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT;
1676
i += IWL_EEPROM_ACCESS_DELAY) {
1677
r = _iwl3945_read_direct32(priv, CSR_EEPROM_REG);
1678
if (r & CSR_EEPROM_REG_READ_VALID_MSK)
1680
udelay(IWL_EEPROM_ACCESS_DELAY);
1683
if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) {
1684
IWL_ERROR("Time out reading EEPROM[%d]", addr);
1687
e[addr / 2] = le16_to_cpu(r >> 16);
1693
/******************************************************************************
1695
* Misc. internal state and helper functions
1697
******************************************************************************/
1698
#ifdef CONFIG_IWL3945_DEBUG
1701
* iwl3945_report_frame - dump frame to syslog during debug sessions
1703
* You may hack this function to show different aspects of received frames,
1704
* including selective frame dumps.
1705
* group100 parameter selects whether to show 1 out of 100 good frames.
1707
void iwl3945_report_frame(struct iwl3945_priv *priv,
1708
struct iwl3945_rx_packet *pkt,
1709
struct ieee80211_hdr *header, int group100)
1712
u32 print_summary = 0;
1713
u32 print_dump = 0; /* set to 1 to dump all frames' contents */
1730
struct iwl3945_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt);
1731
struct iwl3945_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
1732
struct iwl3945_rx_frame_end *rx_end = IWL_RX_END(pkt);
1733
u8 *data = IWL_RX_DATA(pkt);
1736
fc = le16_to_cpu(header->frame_control);
1737
seq_ctl = le16_to_cpu(header->seq_ctrl);
1740
channel = le16_to_cpu(rx_hdr->channel);
1741
phy_flags = le16_to_cpu(rx_hdr->phy_flags);
1742
rate_sym = rx_hdr->rate;
1743
length = le16_to_cpu(rx_hdr->len);
1745
/* end-of-frame status and timestamp */
1746
status = le32_to_cpu(rx_end->status);
1747
bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp);
1748
tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff;
1749
tsf = le64_to_cpu(rx_end->timestamp);
1751
/* signal statistics */
1752
rssi = rx_stats->rssi;
1753
agc = rx_stats->agc;
1754
sig_avg = le16_to_cpu(rx_stats->sig_avg);
1755
noise_diff = le16_to_cpu(rx_stats->noise_diff);
1757
to_us = !compare_ether_addr(header->addr1, priv->mac_addr);
1759
/* if data frame is to us and all is good,
1760
* (optionally) print summary for only 1 out of every 100 */
1761
if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) ==
1762
(IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
1765
print_summary = 1; /* print each frame */
1766
else if (priv->framecnt_to_us < 100) {
1767
priv->framecnt_to_us++;
1770
priv->framecnt_to_us = 0;
1775
/* print summary for all other frames */
1779
if (print_summary) {
1784
title = "100Frames";
1785
else if (fc & IEEE80211_FCTL_RETRY)
1787
else if (ieee80211_is_assoc_response(fc))
1789
else if (ieee80211_is_reassoc_response(fc))
1791
else if (ieee80211_is_probe_response(fc)) {
1793
print_dump = 1; /* dump frame contents */
1794
} else if (ieee80211_is_beacon(fc)) {
1796
print_dump = 1; /* dump frame contents */
1797
} else if (ieee80211_is_atim(fc))
1799
else if (ieee80211_is_auth(fc))
1801
else if (ieee80211_is_deauth(fc))
1803
else if (ieee80211_is_disassoc(fc))
1808
rate = iwl3945_rate_index_from_plcp(rate_sym);
1812
rate = iwl3945_rates[rate].ieee / 2;
1814
/* print frame summary.
1815
* MAC addresses show just the last byte (for brevity),
1816
* but you can hack it to show more, if you'd like to. */
1818
IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, "
1819
"len=%u, rssi=%d, chnl=%d, rate=%u, \n",
1820
title, fc, header->addr1[5],
1821
length, rssi, channel, rate);
1823
/* src/dst addresses assume managed mode */
1824
IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, "
1825
"src=0x%02x, rssi=%u, tim=%lu usec, "
1826
"phy=0x%02x, chnl=%d\n",
1827
title, fc, header->addr1[5],
1828
header->addr3[5], rssi,
1829
tsf_low - priv->scan_start_tsf,
1830
phy_flags, channel);
1834
iwl3945_print_hex_dump(IWL_DL_RX, data, length);
1838
static void iwl3945_unset_hw_setting(struct iwl3945_priv *priv)
1840
if (priv->hw_setting.shared_virt)
1841
pci_free_consistent(priv->pci_dev,
1842
sizeof(struct iwl3945_shared),
1843
priv->hw_setting.shared_virt,
1844
priv->hw_setting.shared_phys);
1848
* iwl3945_supported_rate_to_ie - fill in the supported rate in IE field
1850
* return : set the bit for each supported rate insert in ie
1852
static u16 iwl3945_supported_rate_to_ie(u8 *ie, u16 supported_rate,
1853
u16 basic_rate, int *left)
1855
u16 ret_rates = 0, bit;
1860
for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) {
1861
if (bit & supported_rate) {
1863
rates[*cnt] = iwl3945_rates[i].ieee |
1864
((bit & basic_rate) ? 0x80 : 0x00);
1868
(*cnt >= IWL_SUPPORTED_RATES_IE_LEN))
1877
* iwl3945_fill_probe_req - fill in all required fields and IE for probe request
1879
static u16 iwl3945_fill_probe_req(struct iwl3945_priv *priv,
1880
struct ieee80211_mgmt *frame,
1881
int left, int is_direct)
1885
u16 active_rates, ret_rates, cck_rates;
1887
/* Make sure there is enough space for the probe request,
1888
* two mandatory IEs and the data */
1894
frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
1895
memcpy(frame->da, iwl3945_broadcast_addr, ETH_ALEN);
1896
memcpy(frame->sa, priv->mac_addr, ETH_ALEN);
1897
memcpy(frame->bssid, iwl3945_broadcast_addr, ETH_ALEN);
1898
frame->seq_ctrl = 0;
1900
/* fill in our indirect SSID IE */
1907
pos = &(frame->u.probe_req.variable[0]);
1908
*pos++ = WLAN_EID_SSID;
1911
/* fill in our direct SSID IE... */
1914
left -= 2 + priv->essid_len;
1917
/* ... fill it in... */
1918
*pos++ = WLAN_EID_SSID;
1919
*pos++ = priv->essid_len;
1920
memcpy(pos, priv->essid, priv->essid_len);
1921
pos += priv->essid_len;
1922
len += 2 + priv->essid_len;
1925
/* fill in supported rate */
1931
/* ... fill it in... */
1932
*pos++ = WLAN_EID_SUPP_RATES;
1935
priv->active_rate = priv->rates_mask;
1936
active_rates = priv->active_rate;
1937
priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
1939
cck_rates = IWL_CCK_RATES_MASK & active_rates;
1940
ret_rates = iwl3945_supported_rate_to_ie(pos, cck_rates,
1941
priv->active_rate_basic, &left);
1942
active_rates &= ~ret_rates;
1944
ret_rates = iwl3945_supported_rate_to_ie(pos, active_rates,
1945
priv->active_rate_basic, &left);
1946
active_rates &= ~ret_rates;
1950
if (active_rates == 0)
1953
/* fill in supported extended rate */
1958
/* ... fill it in... */
1959
*pos++ = WLAN_EID_EXT_SUPP_RATES;
1961
iwl3945_supported_rate_to_ie(pos, active_rates,
1962
priv->active_rate_basic, &left);
1973
#ifdef CONFIG_IWL3945_QOS
1974
static int iwl3945_send_qos_params_command(struct iwl3945_priv *priv,
1975
struct iwl3945_qosparam_cmd *qos)
1978
return iwl3945_send_cmd_pdu(priv, REPLY_QOS_PARAM,
1979
sizeof(struct iwl3945_qosparam_cmd), qos);
1982
static void iwl3945_reset_qos(struct iwl3945_priv *priv)
1988
unsigned long flags;
1991
spin_lock_irqsave(&priv->lock, flags);
1992
priv->qos_data.qos_active = 0;
1994
if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) {
1995
if (priv->qos_data.qos_enable)
1996
priv->qos_data.qos_active = 1;
1997
if (!(priv->active_rate & 0xfff0)) {
2001
} else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
2002
if (priv->qos_data.qos_enable)
2003
priv->qos_data.qos_active = 1;
2004
} else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) {
2009
if (priv->qos_data.qos_active)
2012
priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min);
2013
priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max);
2014
priv->qos_data.def_qos_parm.ac[0].aifsn = aifs;
2015
priv->qos_data.def_qos_parm.ac[0].edca_txop = 0;
2016
priv->qos_data.def_qos_parm.ac[0].reserved1 = 0;
2018
if (priv->qos_data.qos_active) {
2020
priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min);
2021
priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max);
2022
priv->qos_data.def_qos_parm.ac[i].aifsn = 7;
2023
priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
2024
priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
2027
priv->qos_data.def_qos_parm.ac[i].cw_min =
2028
cpu_to_le16((cw_min + 1) / 2 - 1);
2029
priv->qos_data.def_qos_parm.ac[i].cw_max =
2030
cpu_to_le16(cw_max);
2031
priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
2033
priv->qos_data.def_qos_parm.ac[i].edca_txop =
2036
priv->qos_data.def_qos_parm.ac[i].edca_txop =
2038
priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
2041
priv->qos_data.def_qos_parm.ac[i].cw_min =
2042
cpu_to_le16((cw_min + 1) / 4 - 1);
2043
priv->qos_data.def_qos_parm.ac[i].cw_max =
2044
cpu_to_le16((cw_max + 1) / 2 - 1);
2045
priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
2046
priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
2048
priv->qos_data.def_qos_parm.ac[i].edca_txop =
2051
priv->qos_data.def_qos_parm.ac[i].edca_txop =
2054
for (i = 1; i < 4; i++) {
2055
priv->qos_data.def_qos_parm.ac[i].cw_min =
2056
cpu_to_le16(cw_min);
2057
priv->qos_data.def_qos_parm.ac[i].cw_max =
2058
cpu_to_le16(cw_max);
2059
priv->qos_data.def_qos_parm.ac[i].aifsn = aifs;
2060
priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
2061
priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
2064
IWL_DEBUG_QOS("set QoS to default \n");
2066
spin_unlock_irqrestore(&priv->lock, flags);
2069
static void iwl3945_activate_qos(struct iwl3945_priv *priv, u8 force)
2071
unsigned long flags;
2073
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2076
if (!priv->qos_data.qos_enable)
2079
spin_lock_irqsave(&priv->lock, flags);
2080
priv->qos_data.def_qos_parm.qos_flags = 0;
2082
if (priv->qos_data.qos_cap.q_AP.queue_request &&
2083
!priv->qos_data.qos_cap.q_AP.txop_request)
2084
priv->qos_data.def_qos_parm.qos_flags |=
2085
QOS_PARAM_FLG_TXOP_TYPE_MSK;
2087
if (priv->qos_data.qos_active)
2088
priv->qos_data.def_qos_parm.qos_flags |=
2089
QOS_PARAM_FLG_UPDATE_EDCA_MSK;
2091
spin_unlock_irqrestore(&priv->lock, flags);
2093
if (force || iwl3945_is_associated(priv)) {
2094
IWL_DEBUG_QOS("send QoS cmd with Qos active %d \n",
2095
priv->qos_data.qos_active);
2097
iwl3945_send_qos_params_command(priv,
2098
&(priv->qos_data.def_qos_parm));
2102
#endif /* CONFIG_IWL3945_QOS */
2104
* Power management (not Tx power!) functions
2106
#define MSEC_TO_USEC 1024
2108
#define NOSLP __constant_cpu_to_le32(0)
2109
#define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK
2110
#define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
2111
#define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
2112
__constant_cpu_to_le32(X1), \
2113
__constant_cpu_to_le32(X2), \
2114
__constant_cpu_to_le32(X3), \
2115
__constant_cpu_to_le32(X4)}
2118
/* default power management (not Tx power) table values */
2120
static struct iwl3945_power_vec_entry range_0[IWL_POWER_AC] = {
2121
{{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
2122
{{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
2123
{{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
2124
{{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
2125
{{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
2126
{{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
2130
static struct iwl3945_power_vec_entry range_1[IWL_POWER_AC] = {
2131
{{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
2132
{{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
2133
SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
2134
{{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
2135
SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
2136
{{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
2137
SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
2138
{{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
2139
{{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
2140
SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
2143
int iwl3945_power_init_handle(struct iwl3945_priv *priv)
2146
struct iwl3945_power_mgr *pow_data;
2147
int size = sizeof(struct iwl3945_power_vec_entry) * IWL_POWER_AC;
2150
IWL_DEBUG_POWER("Initialize power \n");
2152
pow_data = &(priv->power_data);
2154
memset(pow_data, 0, sizeof(*pow_data));
2156
pow_data->active_index = IWL_POWER_RANGE_0;
2157
pow_data->dtim_val = 0xffff;
2159
memcpy(&pow_data->pwr_range_0[0], &range_0[0], size);
2160
memcpy(&pow_data->pwr_range_1[0], &range_1[0], size);
2162
rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm);
2166
struct iwl3945_powertable_cmd *cmd;
2168
IWL_DEBUG_POWER("adjust power command flags\n");
2170
for (i = 0; i < IWL_POWER_AC; i++) {
2171
cmd = &pow_data->pwr_range_0[i].cmd;
2174
cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
2176
cmd->flags |= IWL_POWER_PCI_PM_MSK;
2182
static int iwl3945_update_power_cmd(struct iwl3945_priv *priv,
2183
struct iwl3945_powertable_cmd *cmd, u32 mode)
2188
struct iwl3945_power_vec_entry *range;
2190
struct iwl3945_power_mgr *pow_data;
2192
if (mode > IWL_POWER_INDEX_5) {
2193
IWL_DEBUG_POWER("Error invalid power mode \n");
2196
pow_data = &(priv->power_data);
2198
if (pow_data->active_index == IWL_POWER_RANGE_0)
2199
range = &pow_data->pwr_range_0[0];
2201
range = &pow_data->pwr_range_1[1];
2203
memcpy(cmd, &range[mode].cmd, sizeof(struct iwl3945_powertable_cmd));
2205
#ifdef IWL_MAC80211_DISABLE
2206
if (priv->assoc_network != NULL) {
2207
unsigned long flags;
2209
period = priv->assoc_network->tim.tim_period;
2211
#endif /*IWL_MAC80211_DISABLE */
2212
skip = range[mode].no_dtim;
2221
cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
2223
__le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
2224
max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
2225
cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
2228
for (i = 0; i < IWL_POWER_VEC_SIZE; i++) {
2229
if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
2230
cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
2233
IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags);
2234
IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
2235
IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
2236
IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
2237
le32_to_cpu(cmd->sleep_interval[0]),
2238
le32_to_cpu(cmd->sleep_interval[1]),
2239
le32_to_cpu(cmd->sleep_interval[2]),
2240
le32_to_cpu(cmd->sleep_interval[3]),
2241
le32_to_cpu(cmd->sleep_interval[4]));
2246
static int iwl3945_send_power_mode(struct iwl3945_priv *priv, u32 mode)
2248
u32 final_mode = mode;
2250
struct iwl3945_powertable_cmd cmd;
2252
/* If on battery, set to 3,
2253
* if plugged into AC power, set to CAM ("continuously aware mode"),
2254
* else user level */
2256
case IWL_POWER_BATTERY:
2257
final_mode = IWL_POWER_INDEX_3;
2260
final_mode = IWL_POWER_MODE_CAM;
2267
iwl3945_update_power_cmd(priv, &cmd, final_mode);
2269
rc = iwl3945_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd);
2271
if (final_mode == IWL_POWER_MODE_CAM)
2272
clear_bit(STATUS_POWER_PMI, &priv->status);
2274
set_bit(STATUS_POWER_PMI, &priv->status);
2279
int iwl3945_is_network_packet(struct iwl3945_priv *priv, struct ieee80211_hdr *header)
2281
/* Filter incoming packets to determine if they are targeted toward
2282
* this network, discarding packets coming from ourselves */
2283
switch (priv->iw_mode) {
2284
case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */
2285
/* packets from our adapter are dropped (echo) */
2286
if (!compare_ether_addr(header->addr2, priv->mac_addr))
2288
/* {broad,multi}cast packets to our IBSS go through */
2289
if (is_multicast_ether_addr(header->addr1))
2290
return !compare_ether_addr(header->addr3, priv->bssid);
2291
/* packets to our adapter go through */
2292
return !compare_ether_addr(header->addr1, priv->mac_addr);
2293
case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */
2294
/* packets from our adapter are dropped (echo) */
2295
if (!compare_ether_addr(header->addr3, priv->mac_addr))
2297
/* {broad,multi}cast packets to our BSS go through */
2298
if (is_multicast_ether_addr(header->addr1))
2299
return !compare_ether_addr(header->addr2, priv->bssid);
2300
/* packets to our adapter go through */
2301
return !compare_ether_addr(header->addr1, priv->mac_addr);
2307
#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
2309
static const char *iwl3945_get_tx_fail_reason(u32 status)
2311
switch (status & TX_STATUS_MSK) {
2312
case TX_STATUS_SUCCESS:
2314
TX_STATUS_ENTRY(SHORT_LIMIT);
2315
TX_STATUS_ENTRY(LONG_LIMIT);
2316
TX_STATUS_ENTRY(FIFO_UNDERRUN);
2317
TX_STATUS_ENTRY(MGMNT_ABORT);
2318
TX_STATUS_ENTRY(NEXT_FRAG);
2319
TX_STATUS_ENTRY(LIFE_EXPIRE);
2320
TX_STATUS_ENTRY(DEST_PS);
2321
TX_STATUS_ENTRY(ABORTED);
2322
TX_STATUS_ENTRY(BT_RETRY);
2323
TX_STATUS_ENTRY(STA_INVALID);
2324
TX_STATUS_ENTRY(FRAG_DROPPED);
2325
TX_STATUS_ENTRY(TID_DISABLE);
2326
TX_STATUS_ENTRY(FRAME_FLUSHED);
2327
TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
2328
TX_STATUS_ENTRY(TX_LOCKED);
2329
TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
2336
* iwl3945_scan_cancel - Cancel any currently executing HW scan
2338
* NOTE: priv->mutex is not required before calling this function
2340
static int iwl3945_scan_cancel(struct iwl3945_priv *priv)
2342
if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
2343
clear_bit(STATUS_SCANNING, &priv->status);
2347
if (test_bit(STATUS_SCANNING, &priv->status)) {
2348
if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
2349
IWL_DEBUG_SCAN("Queuing scan abort.\n");
2350
set_bit(STATUS_SCAN_ABORTING, &priv->status);
2351
queue_work(priv->workqueue, &priv->abort_scan);
2354
IWL_DEBUG_SCAN("Scan abort already in progress.\n");
2356
return test_bit(STATUS_SCANNING, &priv->status);
2363
* iwl3945_scan_cancel_timeout - Cancel any currently executing HW scan
2364
* @ms: amount of time to wait (in milliseconds) for scan to abort
2366
* NOTE: priv->mutex must be held before calling this function
2368
static int iwl3945_scan_cancel_timeout(struct iwl3945_priv *priv, unsigned long ms)
2370
unsigned long now = jiffies;
2373
ret = iwl3945_scan_cancel(priv);
2375
mutex_unlock(&priv->mutex);
2376
while (!time_after(jiffies, now + msecs_to_jiffies(ms)) &&
2377
test_bit(STATUS_SCANNING, &priv->status))
2379
mutex_lock(&priv->mutex);
2381
return test_bit(STATUS_SCANNING, &priv->status);
2387
static void iwl3945_sequence_reset(struct iwl3945_priv *priv)
2389
/* Reset ieee stats */
2391
/* We don't reset the net_device_stats (ieee->stats) on
2394
priv->last_seq_num = -1;
2395
priv->last_frag_num = -1;
2396
priv->last_packet_time = 0;
2398
iwl3945_scan_cancel(priv);
2401
#define MAX_UCODE_BEACON_INTERVAL 1024
2402
#define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
2404
static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
2407
u16 beacon_factor = 0;
2410
(beacon_val + MAX_UCODE_BEACON_INTERVAL)
2411
/ MAX_UCODE_BEACON_INTERVAL;
2412
new_val = beacon_val / beacon_factor;
2414
return cpu_to_le16(new_val);
2417
static void iwl3945_setup_rxon_timing(struct iwl3945_priv *priv)
2419
u64 interval_tm_unit;
2421
unsigned long flags;
2422
struct ieee80211_conf *conf = NULL;
2425
conf = ieee80211_get_hw_conf(priv->hw);
2427
spin_lock_irqsave(&priv->lock, flags);
2428
priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp1);
2429
priv->rxon_timing.timestamp.dw[0] = cpu_to_le32(priv->timestamp0);
2431
priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
2433
tsf = priv->timestamp1;
2434
tsf = ((tsf << 32) | priv->timestamp0);
2436
beacon_int = priv->beacon_int;
2437
spin_unlock_irqrestore(&priv->lock, flags);
2439
if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
2440
if (beacon_int == 0) {
2441
priv->rxon_timing.beacon_interval = cpu_to_le16(100);
2442
priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
2444
priv->rxon_timing.beacon_interval =
2445
cpu_to_le16(beacon_int);
2446
priv->rxon_timing.beacon_interval =
2447
iwl3945_adjust_beacon_interval(
2448
le16_to_cpu(priv->rxon_timing.beacon_interval));
2451
priv->rxon_timing.atim_window = 0;
2453
priv->rxon_timing.beacon_interval =
2454
iwl3945_adjust_beacon_interval(conf->beacon_int);
2455
/* TODO: we need to get atim_window from upper stack
2456
* for now we set to 0 */
2457
priv->rxon_timing.atim_window = 0;
2461
(le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
2462
result = do_div(tsf, interval_tm_unit);
2463
priv->rxon_timing.beacon_init_val =
2464
cpu_to_le32((u32) ((u64) interval_tm_unit - result));
2467
("beacon interval %d beacon timer %d beacon tim %d\n",
2468
le16_to_cpu(priv->rxon_timing.beacon_interval),
2469
le32_to_cpu(priv->rxon_timing.beacon_init_val),
2470
le16_to_cpu(priv->rxon_timing.atim_window));
2473
static int iwl3945_scan_initiate(struct iwl3945_priv *priv)
2475
if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
2476
IWL_ERROR("APs don't scan.\n");
2480
if (!iwl3945_is_ready_rf(priv)) {
2481
IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
2485
if (test_bit(STATUS_SCANNING, &priv->status)) {
2486
IWL_DEBUG_SCAN("Scan already in progress.\n");
2490
if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
2491
IWL_DEBUG_SCAN("Scan request while abort pending. "
2496
IWL_DEBUG_INFO("Starting scan...\n");
2497
priv->scan_bands = 2;
2498
set_bit(STATUS_SCANNING, &priv->status);
2499
priv->scan_start = jiffies;
2500
priv->scan_pass_start = priv->scan_start;
2502
queue_work(priv->workqueue, &priv->request_scan);
2507
static int iwl3945_set_rxon_hwcrypto(struct iwl3945_priv *priv, int hw_decrypt)
2509
struct iwl3945_rxon_cmd *rxon = &priv->staging_rxon;
2512
rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
2514
rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
2519
static void iwl3945_set_flags_for_phymode(struct iwl3945_priv *priv, u8 phymode)
2521
if (phymode == MODE_IEEE80211A) {
2522
priv->staging_rxon.flags &=
2523
~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
2524
| RXON_FLG_CCK_MSK);
2525
priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2527
/* Copied from iwl3945_bg_post_associate() */
2528
if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2529
priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2531
priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2533
if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
2534
priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2536
priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
2537
priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
2538
priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
2543
* initialize rxon structure with default values from eeprom
2545
static void iwl3945_connection_init_rx_config(struct iwl3945_priv *priv)
2547
const struct iwl3945_channel_info *ch_info;
2549
memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
2551
switch (priv->iw_mode) {
2552
case IEEE80211_IF_TYPE_AP:
2553
priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
2556
case IEEE80211_IF_TYPE_STA:
2557
priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
2558
priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
2561
case IEEE80211_IF_TYPE_IBSS:
2562
priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
2563
priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
2564
priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
2565
RXON_FILTER_ACCEPT_GRP_MSK;
2568
case IEEE80211_IF_TYPE_MNTR:
2569
priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
2570
priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
2571
RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
2576
/* TODO: Figure out when short_preamble would be set and cache from
2578
if (!hw_to_local(priv->hw)->short_preamble)
2579
priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2581
priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2584
ch_info = iwl3945_get_channel_info(priv, priv->phymode,
2585
le16_to_cpu(priv->staging_rxon.channel));
2588
ch_info = &priv->channel_info[0];
2591
* in some case A channels are all non IBSS
2592
* in this case force B/G channel
2594
if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
2595
!(is_channel_ibss(ch_info)))
2596
ch_info = &priv->channel_info[0];
2598
priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
2599
if (is_channel_a_band(ch_info))
2600
priv->phymode = MODE_IEEE80211A;
2602
priv->phymode = MODE_IEEE80211G;
2604
iwl3945_set_flags_for_phymode(priv, priv->phymode);
2606
priv->staging_rxon.ofdm_basic_rates =
2607
(IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
2608
priv->staging_rxon.cck_basic_rates =
2609
(IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
2612
static int iwl3945_set_mode(struct iwl3945_priv *priv, int mode)
2614
if (mode == IEEE80211_IF_TYPE_IBSS) {
2615
const struct iwl3945_channel_info *ch_info;
2617
ch_info = iwl3945_get_channel_info(priv,
2619
le16_to_cpu(priv->staging_rxon.channel));
2621
if (!ch_info || !is_channel_ibss(ch_info)) {
2622
IWL_ERROR("channel %d not IBSS channel\n",
2623
le16_to_cpu(priv->staging_rxon.channel));
2628
priv->iw_mode = mode;
2630
iwl3945_connection_init_rx_config(priv);
2631
memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2633
iwl3945_clear_stations_table(priv);
2635
/* dont commit rxon if rf-kill is on*/
2636
if (!iwl3945_is_ready_rf(priv))
2639
cancel_delayed_work(&priv->scan_check);
2640
if (iwl3945_scan_cancel_timeout(priv, 100)) {
2641
IWL_WARNING("Aborted scan still in progress after 100ms\n");
2642
IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2646
iwl3945_commit_rxon(priv);
2651
static void iwl3945_build_tx_cmd_hwcrypto(struct iwl3945_priv *priv,
2652
struct ieee80211_tx_control *ctl,
2653
struct iwl3945_cmd *cmd,
2654
struct sk_buff *skb_frag,
2657
struct iwl3945_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo;
2659
switch (keyinfo->alg) {
2661
cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM;
2662
memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen);
2663
IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
2668
cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP;
2671
memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8,
2674
memset(cmd->cmd.tx.tkip_mic.byte, 0, 8);
2679
cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP |
2680
(ctl->key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
2682
if (keyinfo->keylen == 13)
2683
cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128;
2685
memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen);
2687
IWL_DEBUG_TX("Configuring packet for WEP encryption "
2688
"with key %d\n", ctl->key_idx);
2692
IWL_DEBUG_TX("Tx packet in the clear (encrypt requested).\n");
2696
printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg);
2702
* handle build REPLY_TX command notification.
2704
static void iwl3945_build_tx_cmd_basic(struct iwl3945_priv *priv,
2705
struct iwl3945_cmd *cmd,
2706
struct ieee80211_tx_control *ctrl,
2707
struct ieee80211_hdr *hdr,
2708
int is_unicast, u8 std_id)
2711
u16 fc = le16_to_cpu(hdr->frame_control);
2712
__le32 tx_flags = cmd->cmd.tx.tx_flags;
2714
cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
2715
if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) {
2716
tx_flags |= TX_CMD_FLG_ACK_MSK;
2717
if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
2718
tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2719
if (ieee80211_is_probe_response(fc) &&
2720
!(le16_to_cpu(hdr->seq_ctrl) & 0xf))
2721
tx_flags |= TX_CMD_FLG_TSF_MSK;
2723
tx_flags &= (~TX_CMD_FLG_ACK_MSK);
2724
tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2727
cmd->cmd.tx.sta_id = std_id;
2728
if (ieee80211_get_morefrag(hdr))
2729
tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
2731
qc = ieee80211_get_qos_ctrl(hdr);
2733
cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf);
2734
tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
2736
tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
2738
if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) {
2739
tx_flags |= TX_CMD_FLG_RTS_MSK;
2740
tx_flags &= ~TX_CMD_FLG_CTS_MSK;
2741
} else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) {
2742
tx_flags &= ~TX_CMD_FLG_RTS_MSK;
2743
tx_flags |= TX_CMD_FLG_CTS_MSK;
2746
if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
2747
tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
2749
tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
2750
if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
2751
if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ ||
2752
(fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
2753
cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3);
2755
cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2);
2757
cmd->cmd.tx.timeout.pm_frame_timeout = 0;
2758
#ifdef CONFIG_IWL3945_LEDS
2759
priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
2763
cmd->cmd.tx.driver_txop = 0;
2764
cmd->cmd.tx.tx_flags = tx_flags;
2765
cmd->cmd.tx.next_frame_len = 0;
2769
* iwl3945_get_sta_id - Find station's index within station table
2771
static int iwl3945_get_sta_id(struct iwl3945_priv *priv, struct ieee80211_hdr *hdr)
2774
u16 fc = le16_to_cpu(hdr->frame_control);
2776
/* If this frame is broadcast or management, use broadcast station id */
2777
if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
2778
is_multicast_ether_addr(hdr->addr1))
2779
return priv->hw_setting.bcast_sta_id;
2781
switch (priv->iw_mode) {
2783
/* If we are a client station in a BSS network, use the special
2784
* AP station entry (that's the only station we communicate with) */
2785
case IEEE80211_IF_TYPE_STA:
2788
/* If we are an AP, then find the station, or use BCAST */
2789
case IEEE80211_IF_TYPE_AP:
2790
sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
2791
if (sta_id != IWL_INVALID_STATION)
2793
return priv->hw_setting.bcast_sta_id;
2795
/* If this frame is going out to an IBSS network, find the station,
2796
* or create a new station table entry */
2797
case IEEE80211_IF_TYPE_IBSS:
2798
sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
2799
if (sta_id != IWL_INVALID_STATION)
2802
/* Create new station table entry */
2803
sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
2805
if (sta_id != IWL_INVALID_STATION)
2808
IWL_DEBUG_DROP("Station " MAC_FMT " not in station map. "
2809
"Defaulting to broadcast...\n",
2810
MAC_ARG(hdr->addr1));
2811
iwl3945_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
2812
return priv->hw_setting.bcast_sta_id;
2815
IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode);
2816
return priv->hw_setting.bcast_sta_id;
2821
* start REPLY_TX command process
2823
static int iwl3945_tx_skb(struct iwl3945_priv *priv,
2824
struct sk_buff *skb, struct ieee80211_tx_control *ctl)
2826
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2827
struct iwl3945_tfd_frame *tfd;
2829
int txq_id = ctl->queue;
2830
struct iwl3945_tx_queue *txq = NULL;
2831
struct iwl3945_queue *q = NULL;
2832
dma_addr_t phys_addr;
2833
dma_addr_t txcmd_phys;
2834
struct iwl3945_cmd *out_cmd = NULL;
2835
u16 len, idx, len_org;
2836
u8 id, hdr_len, unicast;
2841
u8 wait_write_ptr = 0;
2842
unsigned long flags;
2845
spin_lock_irqsave(&priv->lock, flags);
2846
if (iwl3945_is_rfkill(priv)) {
2847
IWL_DEBUG_DROP("Dropping - RF KILL\n");
2851
if (!priv->interface_id) {
2852
IWL_DEBUG_DROP("Dropping - !priv->interface_id\n");
2856
if ((ctl->tx_rate & 0xFF) == IWL_INVALID_RATE) {
2857
IWL_ERROR("ERROR: No TX rate available.\n");
2861
unicast = !is_multicast_ether_addr(hdr->addr1);
2864
fc = le16_to_cpu(hdr->frame_control);
2866
#ifdef CONFIG_IWL3945_DEBUG
2867
if (ieee80211_is_auth(fc))
2868
IWL_DEBUG_TX("Sending AUTH frame\n");
2869
else if (ieee80211_is_assoc_request(fc))
2870
IWL_DEBUG_TX("Sending ASSOC frame\n");
2871
else if (ieee80211_is_reassoc_request(fc))
2872
IWL_DEBUG_TX("Sending REASSOC frame\n");
2875
/* drop all data frame if we are not associated */
2876
if (!iwl3945_is_associated(priv) && !priv->assoc_id &&
2877
((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) {
2878
IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n");
2882
spin_unlock_irqrestore(&priv->lock, flags);
2884
hdr_len = iwlwifi_ieee80211_get_hdrlen(fc);
2886
/* Find (or create) index into station table for destination station */
2887
sta_id = iwl3945_get_sta_id(priv, hdr);
2888
if (sta_id == IWL_INVALID_STATION) {
2889
IWL_DEBUG_DROP("Dropping - INVALID STATION: " MAC_FMT "\n",
2890
MAC_ARG(hdr->addr1));
2894
IWL_DEBUG_RATE("station Id %d\n", sta_id);
2896
qc = ieee80211_get_qos_ctrl(hdr);
2898
u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
2899
seq_number = priv->stations[sta_id].tid[tid].seq_number &
2901
hdr->seq_ctrl = cpu_to_le16(seq_number) |
2903
__constant_cpu_to_le16(IEEE80211_SCTL_FRAG));
2907
/* Descriptor for chosen Tx queue */
2908
txq = &priv->txq[txq_id];
2911
spin_lock_irqsave(&priv->lock, flags);
2913
/* Set up first empty TFD within this queue's circular TFD buffer */
2914
tfd = &txq->bd[q->write_ptr];
2915
memset(tfd, 0, sizeof(*tfd));
2916
control_flags = (u32 *) tfd;
2917
idx = get_cmd_index(q, q->write_ptr, 0);
2919
/* Set up driver data for this TFD */
2920
memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl3945_tx_info));
2921
txq->txb[q->write_ptr].skb[0] = skb;
2922
memcpy(&(txq->txb[q->write_ptr].status.control),
2923
ctl, sizeof(struct ieee80211_tx_control));
2925
/* Init first empty entry in queue's array of Tx/cmd buffers */
2926
out_cmd = &txq->cmd[idx];
2927
memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
2928
memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx));
2931
* Set up the Tx-command (not MAC!) header.
2932
* Store the chosen Tx queue and TFD index within the sequence field;
2933
* after Tx, uCode's Tx response will return this value so driver can
2934
* locate the frame within the tx queue and do post-tx processing.
2936
out_cmd->hdr.cmd = REPLY_TX;
2937
out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
2938
INDEX_TO_SEQ(q->write_ptr)));
2940
/* Copy MAC header from skb into command buffer */
2941
memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len);
2944
* Use the first empty entry in this queue's command buffer array
2945
* to contain the Tx command and MAC header concatenated together
2946
* (payload data will be in another buffer).
2947
* Size of this varies, due to varying MAC header length.
2948
* If end is not dword aligned, we'll have 2 extra bytes at the end
2949
* of the MAC header (device reads on dword boundaries).
2950
* We'll tell device about this padding later.
2952
len = priv->hw_setting.tx_cmd_len +
2953
sizeof(struct iwl3945_cmd_header) + hdr_len;
2956
len = (len + 3) & ~3;
2963
/* Physical address of this Tx command's header (not MAC header!),
2964
* within command buffer array. */
2965
txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl3945_cmd) * idx +
2966
offsetof(struct iwl3945_cmd, hdr);
2968
/* Add buffer containing Tx command and MAC(!) header to TFD's
2970
iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len);
2972
if (ctl->key_idx != -1)
2973
iwl3945_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0);
2975
/* Set up TFD's 2nd entry to point directly to remainder of skb,
2976
* if any (802.11 null frames have no payload). */
2977
len = skb->len - hdr_len;
2979
phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
2980
len, PCI_DMA_TODEVICE);
2981
iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len);
2985
/* If there is no payload, then we use only one Tx buffer */
2986
*control_flags = TFD_CTL_COUNT_SET(1);
2988
/* Else use 2 buffers.
2989
* Tell 3945 about any padding after MAC header */
2990
*control_flags = TFD_CTL_COUNT_SET(2) |
2991
TFD_CTL_PAD_SET(U32_PAD(len));
2993
/* Total # bytes to be transmitted */
2994
len = (u16)skb->len;
2995
out_cmd->cmd.tx.len = cpu_to_le16(len);
2997
/* TODO need this for burst mode later on */
2998
iwl3945_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id);
3000
/* set is_hcca to 0; it probably will never be implemented */
3001
iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0);
3003
out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
3004
out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
3006
if (!ieee80211_get_morefrag(hdr)) {
3007
txq->need_update = 1;
3009
u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
3010
priv->stations[sta_id].tid[tid].seq_number = seq_number;
3014
txq->need_update = 0;
3017
iwl3945_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload,
3018
sizeof(out_cmd->cmd.tx));
3020
iwl3945_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr,
3021
iwlwifi_ieee80211_get_hdrlen(fc));
3023
/* Tell device the write index *just past* this latest filled TFD */
3024
q->write_ptr = iwl3945_queue_inc_wrap(q->write_ptr, q->n_bd);
3025
rc = iwl3945_tx_queue_update_write_ptr(priv, txq);
3026
spin_unlock_irqrestore(&priv->lock, flags);
3031
if ((iwl3945_queue_space(q) < q->high_mark)
3032
&& priv->mac80211_registered) {
3033
if (wait_write_ptr) {
3034
spin_lock_irqsave(&priv->lock, flags);
3035
txq->need_update = 1;
3036
iwl3945_tx_queue_update_write_ptr(priv, txq);
3037
spin_unlock_irqrestore(&priv->lock, flags);
3040
iwlwifi_ieee80211_stop_queue(priv->hw, ctl->queue);
3046
spin_unlock_irqrestore(&priv->lock, flags);
3051
static void iwl3945_set_rate(struct iwl3945_priv *priv)
3053
const struct ieee80211_hw_mode *hw = NULL;
3054
struct ieee80211_rate *rate;
3057
hw = iwl3945_get_hw_mode(priv, priv->phymode);
3059
IWL_ERROR("Failed to set rate: unable to get hw mode\n");
3063
priv->active_rate = 0;
3064
priv->active_rate_basic = 0;
3066
IWL_DEBUG_RATE("Setting rates for 802.11%c\n",
3067
hw->mode == MODE_IEEE80211A ?
3068
'a' : ((hw->mode == MODE_IEEE80211B) ? 'b' : 'g'));
3070
for (i = 0; i < hw->num_rates; i++) {
3071
rate = &(hw->rates[i]);
3072
if ((rate->val < IWL_RATE_COUNT) &&
3073
(rate->flags & IEEE80211_RATE_SUPPORTED)) {
3074
IWL_DEBUG_RATE("Adding rate index %d (plcp %d)%s\n",
3075
rate->val, iwl3945_rates[rate->val].plcp,
3076
(rate->flags & IEEE80211_RATE_BASIC) ?
3078
priv->active_rate |= (1 << rate->val);
3079
if (rate->flags & IEEE80211_RATE_BASIC)
3080
priv->active_rate_basic |= (1 << rate->val);
3082
IWL_DEBUG_RATE("Not adding rate %d (plcp %d)\n",
3083
rate->val, iwl3945_rates[rate->val].plcp);
3086
IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
3087
priv->active_rate, priv->active_rate_basic);
3090
* If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
3091
* otherwise set it to the default of all CCK rates and 6, 12, 24 for
3094
if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
3095
priv->staging_rxon.cck_basic_rates =
3096
((priv->active_rate_basic &
3097
IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
3099
priv->staging_rxon.cck_basic_rates =
3100
(IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
3102
if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
3103
priv->staging_rxon.ofdm_basic_rates =
3104
((priv->active_rate_basic &
3105
(IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
3106
IWL_FIRST_OFDM_RATE) & 0xFF;
3108
priv->staging_rxon.ofdm_basic_rates =
3109
(IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
3112
static void iwl3945_radio_kill_sw(struct iwl3945_priv *priv, int disable_radio)
3114
unsigned long flags;
3116
if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
3119
IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
3120
disable_radio ? "OFF" : "ON");
3122
if (disable_radio) {
3123
iwl3945_scan_cancel(priv);
3124
/* FIXME: This is a workaround for AP */
3125
if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
3126
spin_lock_irqsave(&priv->lock, flags);
3127
iwl3945_write32(priv, CSR_UCODE_DRV_GP1_SET,
3128
CSR_UCODE_SW_BIT_RFKILL);
3129
spin_unlock_irqrestore(&priv->lock, flags);
3130
iwl3945_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
3131
set_bit(STATUS_RF_KILL_SW, &priv->status);
3136
spin_lock_irqsave(&priv->lock, flags);
3137
iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3139
clear_bit(STATUS_RF_KILL_SW, &priv->status);
3140
spin_unlock_irqrestore(&priv->lock, flags);
3145
spin_lock_irqsave(&priv->lock, flags);
3146
iwl3945_read32(priv, CSR_UCODE_DRV_GP1);
3147
if (!iwl3945_grab_nic_access(priv))
3148
iwl3945_release_nic_access(priv);
3149
spin_unlock_irqrestore(&priv->lock, flags);
3151
if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
3152
IWL_DEBUG_RF_KILL("Can not turn radio back on - "
3153
"disabled by HW switch\n");
3157
queue_work(priv->workqueue, &priv->restart);
3161
void iwl3945_set_decrypted_flag(struct iwl3945_priv *priv, struct sk_buff *skb,
3162
u32 decrypt_res, struct ieee80211_rx_status *stats)
3165
le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control);
3167
if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
3170
if (!(fc & IEEE80211_FCTL_PROTECTED))
3173
IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
3174
switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
3175
case RX_RES_STATUS_SEC_TYPE_TKIP:
3176
if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
3177
RX_RES_STATUS_BAD_ICV_MIC)
3178
stats->flag |= RX_FLAG_MMIC_ERROR;
3179
case RX_RES_STATUS_SEC_TYPE_WEP:
3180
case RX_RES_STATUS_SEC_TYPE_CCMP:
3181
if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
3182
RX_RES_STATUS_DECRYPT_OK) {
3183
IWL_DEBUG_RX("hw decrypt successfully!!!\n");
3184
stats->flag |= RX_FLAG_DECRYPTED;
3193
void iwl3945_handle_data_packet_monitor(struct iwl3945_priv *priv,
3194
struct iwl3945_rx_mem_buffer *rxb,
3195
void *data, short len,
3196
struct ieee80211_rx_status *stats,
3199
struct iwl3945_rt_rx_hdr *iwl3945_rt;
3201
/* First cache any information we need before we overwrite
3202
* the information provided in the skb from the hardware */
3203
s8 signal = stats->ssi;
3205
int rate = stats->rate;
3206
u64 tsf = stats->mactime;
3207
__le16 phy_flags_hw = cpu_to_le16(phy_flags);
3209
/* We received data from the HW, so stop the watchdog */
3210
if (len > IWL_RX_BUF_SIZE - sizeof(*iwl3945_rt)) {
3211
IWL_DEBUG_DROP("Dropping too large packet in monitor\n");
3215
/* copy the frame data to write after where the radiotap header goes */
3216
iwl3945_rt = (void *)rxb->skb->data;
3217
memmove(iwl3945_rt->payload, data, len);
3219
iwl3945_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
3220
iwl3945_rt->rt_hdr.it_pad = 0; /* always good to zero */
3222
/* total header + data */
3223
iwl3945_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*iwl3945_rt));
3225
/* Set the size of the skb to the size of the frame */
3226
skb_put(rxb->skb, sizeof(*iwl3945_rt) + len);
3228
/* Big bitfield of all the fields we provide in radiotap */
3229
iwl3945_rt->rt_hdr.it_present =
3230
cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) |
3231
(1 << IEEE80211_RADIOTAP_FLAGS) |
3232
(1 << IEEE80211_RADIOTAP_RATE) |
3233
(1 << IEEE80211_RADIOTAP_CHANNEL) |
3234
(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
3235
(1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
3236
(1 << IEEE80211_RADIOTAP_ANTENNA));
3238
/* Zero the flags, we'll add to them as we go */
3239
iwl3945_rt->rt_flags = 0;
3241
iwl3945_rt->rt_tsf = cpu_to_le64(tsf);
3243
/* Convert to dBm */
3244
iwl3945_rt->rt_dbmsignal = signal;
3245
iwl3945_rt->rt_dbmnoise = noise;
3247
/* Convert the channel frequency and set the flags */
3248
iwl3945_rt->rt_channelMHz = cpu_to_le16(stats->freq);
3249
if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK))
3250
iwl3945_rt->rt_chbitmask =
3251
cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
3252
else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK)
3253
iwl3945_rt->rt_chbitmask =
3254
cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
3256
iwl3945_rt->rt_chbitmask =
3257
cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ));
3259
rate = iwl3945_rate_index_from_plcp(rate);
3261
iwl3945_rt->rt_rate = 0;
3263
iwl3945_rt->rt_rate = iwl3945_rates[rate].ieee;
3265
/* antenna number */
3266
iwl3945_rt->rt_antenna =
3267
le16_to_cpu(phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK) >> 4;
3269
/* set the preamble flag if we have it */
3270
if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
3271
iwl3945_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
3273
IWL_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
3275
stats->flag |= RX_FLAG_RADIOTAP;
3276
iwlwifi_ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats);
3281
#define IWL_PACKET_RETRY_TIME HZ
3283
int iwl3945_is_duplicate_packet(struct iwl3945_priv *priv, struct ieee80211_hdr *header)
3285
u16 sc = le16_to_cpu(header->seq_ctrl);
3286
u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
3287
u16 frag = sc & IEEE80211_SCTL_FRAG;
3288
u16 *last_seq, *last_frag;
3289
unsigned long *last_time;
3291
switch (priv->iw_mode) {
3292
case IEEE80211_IF_TYPE_IBSS:{
3293
struct list_head *p;
3294
struct iwl3945_ibss_seq *entry = NULL;
3295
u8 *mac = header->addr2;
3296
int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1);
3298
__list_for_each(p, &priv->ibss_mac_hash[index]) {
3299
entry = list_entry(p, struct iwl3945_ibss_seq, list);
3300
if (!compare_ether_addr(entry->mac, mac))
3303
if (p == &priv->ibss_mac_hash[index]) {
3304
entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
3306
IWL_ERROR("Cannot malloc new mac entry\n");
3309
memcpy(entry->mac, mac, ETH_ALEN);
3310
entry->seq_num = seq;
3311
entry->frag_num = frag;
3312
entry->packet_time = jiffies;
3313
list_add(&entry->list, &priv->ibss_mac_hash[index]);
3316
last_seq = &entry->seq_num;
3317
last_frag = &entry->frag_num;
3318
last_time = &entry->packet_time;
3321
case IEEE80211_IF_TYPE_STA:
3322
last_seq = &priv->last_seq_num;
3323
last_frag = &priv->last_frag_num;
3324
last_time = &priv->last_packet_time;
3329
if ((*last_seq == seq) &&
3330
time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) {
3331
if (*last_frag == frag)
3333
if (*last_frag + 1 != frag)
3334
/* out-of-order fragment */
3340
*last_time = jiffies;
3347
#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
3349
#include "iwl-spectrum.h"
3351
#define BEACON_TIME_MASK_LOW 0x00FFFFFF
3352
#define BEACON_TIME_MASK_HIGH 0xFF000000
3353
#define TIME_UNIT 1024
3356
* extended beacon time format
3357
* time in usec will be changed into a 32-bit value in 8:24 format
3358
* the high 1 byte is the beacon counts
3359
* the lower 3 bytes is the time in usec within one beacon interval
3362
static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
3366
u32 interval = beacon_interval * 1024;
3368
if (!interval || !usec)
3371
quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
3372
rem = (usec % interval) & BEACON_TIME_MASK_LOW;
3374
return (quot << 24) + rem;
3377
/* base is usually what we get from ucode with each received frame,
3378
* the same as HW timer counter counting down
3381
static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
3383
u32 base_low = base & BEACON_TIME_MASK_LOW;
3384
u32 addon_low = addon & BEACON_TIME_MASK_LOW;
3385
u32 interval = beacon_interval * TIME_UNIT;
3386
u32 res = (base & BEACON_TIME_MASK_HIGH) +
3387
(addon & BEACON_TIME_MASK_HIGH);
3389
if (base_low > addon_low)
3390
res += base_low - addon_low;
3391
else if (base_low < addon_low) {
3392
res += interval + base_low - addon_low;
3397
return cpu_to_le32(res);
3400
static int iwl3945_get_measurement(struct iwl3945_priv *priv,
3401
struct ieee80211_measurement_params *params,
3404
struct iwl3945_spectrum_cmd spectrum;
3405
struct iwl3945_rx_packet *res;
3406
struct iwl3945_host_cmd cmd = {
3407
.id = REPLY_SPECTRUM_MEASUREMENT_CMD,
3408
.data = (void *)&spectrum,
3409
.meta.flags = CMD_WANT_SKB,
3411
u32 add_time = le64_to_cpu(params->start_time);
3413
int spectrum_resp_status;
3414
int duration = le16_to_cpu(params->duration);
3416
if (iwl3945_is_associated(priv))
3418
iwl3945_usecs_to_beacons(
3419
le64_to_cpu(params->start_time) - priv->last_tsf,
3420
le16_to_cpu(priv->rxon_timing.beacon_interval));
3422
memset(&spectrum, 0, sizeof(spectrum));
3424
spectrum.channel_count = cpu_to_le16(1);
3426
RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
3427
spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
3428
cmd.len = sizeof(spectrum);
3429
spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
3431
if (iwl3945_is_associated(priv))
3432
spectrum.start_time =
3433
iwl3945_add_beacon_time(priv->last_beacon_time,
3435
le16_to_cpu(priv->rxon_timing.beacon_interval));
3437
spectrum.start_time = 0;
3439
spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
3440
spectrum.channels[0].channel = params->channel;
3441
spectrum.channels[0].type = type;
3442
if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
3443
spectrum.flags |= RXON_FLG_BAND_24G_MSK |
3444
RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
3446
rc = iwl3945_send_cmd_sync(priv, &cmd);
3450
res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data;
3451
if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
3452
IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
3456
spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
3457
switch (spectrum_resp_status) {
3458
case 0: /* Command will be handled */
3459
if (res->u.spectrum.id != 0xff) {
3460
IWL_DEBUG_INFO("Replaced existing measurement: %d\n",
3461
res->u.spectrum.id);
3462
priv->measurement_status &= ~MEASUREMENT_READY;
3464
priv->measurement_status |= MEASUREMENT_ACTIVE;
3468
case 1: /* Command will not be handled */
3473
dev_kfree_skb_any(cmd.meta.u.skb);
3479
static void iwl3945_txstatus_to_ieee(struct iwl3945_priv *priv,
3480
struct iwl3945_tx_info *tx_sta)
3483
tx_sta->status.ack_signal = 0;
3484
tx_sta->status.excessive_retries = 0;
3485
tx_sta->status.queue_length = 0;
3486
tx_sta->status.queue_number = 0;
3489
iwlwifi_iwlwifi_ieee80211_tx_status_irqsafe(priv->hw,
3490
tx_sta->skb[0], &(tx_sta->status));
3492
iwlwifi_ieee80211_tx_status(priv->hw,
3493
tx_sta->skb[0], &(tx_sta->status));
3495
tx_sta->skb[0] = NULL;
3499
* iwl3945_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
3501
* When FW advances 'R' index, all entries between old and new 'R' index
3502
* need to be reclaimed. As result, some free space forms. If there is
3503
* enough free space (> low mark), wake the stack that feeds us.
3505
static int iwl3945_tx_queue_reclaim(struct iwl3945_priv *priv, int txq_id, int index)
3507
struct iwl3945_tx_queue *txq = &priv->txq[txq_id];
3508
struct iwl3945_queue *q = &txq->q;
3511
if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) {
3512
IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
3513
"is out of range [0-%d] %d %d.\n", txq_id,
3514
index, q->n_bd, q->write_ptr, q->read_ptr);
3518
for (index = iwl3945_queue_inc_wrap(index, q->n_bd);
3519
q->read_ptr != index;
3520
q->read_ptr = iwl3945_queue_inc_wrap(q->read_ptr, q->n_bd)) {
3521
if (txq_id != IWL_CMD_QUEUE_NUM) {
3522
iwl3945_txstatus_to_ieee(priv,
3523
&(txq->txb[txq->q.read_ptr]));
3524
iwl3945_hw_txq_free_tfd(priv, txq);
3525
} else if (nfreed > 1) {
3526
IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index,
3527
q->write_ptr, q->read_ptr);
3528
queue_work(priv->workqueue, &priv->restart);
3533
if (iwl3945_queue_space(q) > q->low_mark && (txq_id >= 0) &&
3534
(txq_id != IWL_CMD_QUEUE_NUM) &&
3535
priv->mac80211_registered)
3536
iwlwifi_ieee80211_wake_queue(priv->hw, txq_id);
3542
static int iwl3945_is_tx_success(u32 status)
3544
return (status & 0xFF) == 0x1;
3547
/******************************************************************************
3549
* Generic RX handler implementations
3551
******************************************************************************/
3553
* iwl3945_rx_reply_tx - Handle Tx response
3555
static void iwl3945_rx_reply_tx(struct iwl3945_priv *priv,
3556
struct iwl3945_rx_mem_buffer *rxb)
3558
struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3559
u16 sequence = le16_to_cpu(pkt->hdr.sequence);
3560
int txq_id = SEQ_TO_QUEUE(sequence);
3561
int index = SEQ_TO_INDEX(sequence);
3562
struct iwl3945_tx_queue *txq = &priv->txq[txq_id];
3563
struct iwlwifi_ieee80211_tx_status *tx_status;
3564
struct iwl3945_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
3565
u32 status = le32_to_cpu(tx_resp->status);
3567
if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) {
3568
IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
3569
"is out of range [0-%d] %d %d\n", txq_id,
3570
index, txq->q.n_bd, txq->q.write_ptr,
3575
tx_status = &(txq->txb[txq->q.read_ptr].status);
3577
tx_status->retry_count = tx_resp->failure_frame;
3578
tx_status->queue_number = status;
3579
tx_status->queue_length = tx_resp->bt_kill_count;
3580
tx_status->queue_length |= tx_resp->failure_rts;
3583
iwl3945_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0;
3585
tx_status->control.tx_rate = iwl3945_rate_index_from_plcp(tx_resp->rate);
3587
IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) plcp rate %d retries %d\n",
3588
txq_id, iwl3945_get_tx_fail_reason(status), status,
3589
tx_resp->rate, tx_resp->failure_frame);
3591
IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
3593
iwl3945_tx_queue_reclaim(priv, txq_id, index);
3595
if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
3596
IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
3600
static void iwl3945_rx_reply_alive(struct iwl3945_priv *priv,
3601
struct iwl3945_rx_mem_buffer *rxb)
3603
struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3604
struct iwl3945_alive_resp *palive;
3605
struct delayed_work *pwork;
3607
palive = &pkt->u.alive_frame;
3609
IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
3611
palive->is_valid, palive->ver_type,
3612
palive->ver_subtype);
3614
if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
3615
IWL_DEBUG_INFO("Initialization Alive received.\n");
3616
memcpy(&priv->card_alive_init,
3617
&pkt->u.alive_frame,
3618
sizeof(struct iwl3945_init_alive_resp));
3619
pwork = &priv->init_alive_start;
3621
IWL_DEBUG_INFO("Runtime Alive received.\n");
3622
memcpy(&priv->card_alive, &pkt->u.alive_frame,
3623
sizeof(struct iwl3945_alive_resp));
3624
pwork = &priv->alive_start;
3625
iwl3945_disable_events(priv);
3628
/* We delay the ALIVE response by 5ms to
3629
* give the HW RF Kill time to activate... */
3630
if (palive->is_valid == UCODE_VALID_OK)
3631
queue_delayed_work(priv->workqueue, pwork,
3632
msecs_to_jiffies(5));
3634
IWL_WARNING("uCode did not respond OK.\n");
3637
static void iwl3945_rx_reply_add_sta(struct iwl3945_priv *priv,
3638
struct iwl3945_rx_mem_buffer *rxb)
3640
struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3642
IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
3646
static void iwl3945_rx_reply_error(struct iwl3945_priv *priv,
3647
struct iwl3945_rx_mem_buffer *rxb)
3649
struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3651
IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
3652
"seq 0x%04X ser 0x%08X\n",
3653
le32_to_cpu(pkt->u.err_resp.error_type),
3654
get_cmd_string(pkt->u.err_resp.cmd_id),
3655
pkt->u.err_resp.cmd_id,
3656
le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
3657
le32_to_cpu(pkt->u.err_resp.error_info));
3660
#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
3662
static void iwl3945_rx_csa(struct iwl3945_priv *priv, struct iwl3945_rx_mem_buffer *rxb)
3664
struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3665
struct iwl3945_rxon_cmd *rxon = (void *)&priv->active_rxon;
3666
struct iwl3945_csa_notification *csa = &(pkt->u.csa_notif);
3667
IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
3668
le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
3669
rxon->channel = csa->channel;
3670
priv->staging_rxon.channel = csa->channel;
3673
static void iwl3945_rx_spectrum_measure_notif(struct iwl3945_priv *priv,
3674
struct iwl3945_rx_mem_buffer *rxb)
3676
#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
3677
struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3678
struct iwl3945_spectrum_notification *report = &(pkt->u.spectrum_notif);
3680
if (!report->state) {
3681
IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO,
3682
"Spectrum Measure Notification: Start\n");
3686
memcpy(&priv->measure_report, report, sizeof(*report));
3687
priv->measurement_status |= MEASUREMENT_READY;
3691
static void iwl3945_rx_pm_sleep_notif(struct iwl3945_priv *priv,
3692
struct iwl3945_rx_mem_buffer *rxb)
3694
#ifdef CONFIG_IWL3945_DEBUG
3695
struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3696
struct iwl3945_sleep_notification *sleep = &(pkt->u.sleep_notif);
3697
IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
3698
sleep->pm_sleep_mode, sleep->pm_wakeup_src);
3702
static void iwl3945_rx_pm_debug_statistics_notif(struct iwl3945_priv *priv,
3703
struct iwl3945_rx_mem_buffer *rxb)
3705
struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3706
IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
3707
"notification for %s:\n",
3708
le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
3709
iwl3945_print_hex_dump(IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
3712
static void iwl3945_bg_beacon_update(struct work_struct *work)
3714
struct iwl3945_priv *priv =
3715
container_of(work, struct iwl3945_priv, beacon_update);
3716
struct sk_buff *beacon;
3718
/* Pull updated AP beacon from mac80211. will fail if not in AP mode */
3719
beacon = iwlwifi_ieee80211_beacon_get(priv->hw, priv->interface_id, NULL);
3722
IWL_ERROR("update beacon failed\n");
3726
mutex_lock(&priv->mutex);
3727
/* new beacon skb is allocated every time; dispose previous.*/
3728
if (priv->ibss_beacon)
3729
dev_kfree_skb(priv->ibss_beacon);
3731
priv->ibss_beacon = beacon;
3732
mutex_unlock(&priv->mutex);
3734
iwl3945_send_beacon_cmd(priv);
3737
static void iwl3945_rx_beacon_notif(struct iwl3945_priv *priv,
3738
struct iwl3945_rx_mem_buffer *rxb)
3740
#ifdef CONFIG_IWL3945_DEBUG
3741
struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3742
struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
3743
u8 rate = beacon->beacon_notify_hdr.rate;
3745
IWL_DEBUG_RX("beacon status %x retries %d iss %d "
3746
"tsf %d %d rate %d\n",
3747
le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
3748
beacon->beacon_notify_hdr.failure_frame,
3749
le32_to_cpu(beacon->ibss_mgr_status),
3750
le32_to_cpu(beacon->high_tsf),
3751
le32_to_cpu(beacon->low_tsf), rate);
3754
if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
3755
(!test_bit(STATUS_EXIT_PENDING, &priv->status)))
3756
queue_work(priv->workqueue, &priv->beacon_update);
3759
/* Service response to REPLY_SCAN_CMD (0x80) */
3760
static void iwl3945_rx_reply_scan(struct iwl3945_priv *priv,
3761
struct iwl3945_rx_mem_buffer *rxb)
3763
#ifdef CONFIG_IWL3945_DEBUG
3764
struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3765
struct iwl3945_scanreq_notification *notif =
3766
(struct iwl3945_scanreq_notification *)pkt->u.raw;
3768
IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status);
3772
/* Service SCAN_START_NOTIFICATION (0x82) */
3773
static void iwl3945_rx_scan_start_notif(struct iwl3945_priv *priv,
3774
struct iwl3945_rx_mem_buffer *rxb)
3776
struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3777
struct iwl3945_scanstart_notification *notif =
3778
(struct iwl3945_scanstart_notification *)pkt->u.raw;
3779
priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
3780
IWL_DEBUG_SCAN("Scan start: "
3782
"(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
3784
notif->band ? "bg" : "a",
3786
notif->tsf_low, notif->status, notif->beacon_timer);
3789
/* Service SCAN_RESULTS_NOTIFICATION (0x83) */
3790
static void iwl3945_rx_scan_results_notif(struct iwl3945_priv *priv,
3791
struct iwl3945_rx_mem_buffer *rxb)
3793
struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3794
struct iwl3945_scanresults_notification *notif =
3795
(struct iwl3945_scanresults_notification *)pkt->u.raw;
3797
IWL_DEBUG_SCAN("Scan ch.res: "
3799
"(TSF: 0x%08X:%08X) - %d "
3800
"elapsed=%lu usec (%dms since last)\n",
3802
notif->band ? "bg" : "a",
3803
le32_to_cpu(notif->tsf_high),
3804
le32_to_cpu(notif->tsf_low),
3805
le32_to_cpu(notif->statistics[0]),
3806
le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
3807
jiffies_to_msecs(elapsed_jiffies
3808
(priv->last_scan_jiffies, jiffies)));
3810
priv->last_scan_jiffies = jiffies;
3811
priv->next_scan_jiffies = 0;
3814
/* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
3815
static void iwl3945_rx_scan_complete_notif(struct iwl3945_priv *priv,
3816
struct iwl3945_rx_mem_buffer *rxb)
3818
struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3819
struct iwl3945_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
3821
IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
3822
scan_notif->scanned_channels,
3823
scan_notif->tsf_low,
3824
scan_notif->tsf_high, scan_notif->status);
3826
/* The HW is no longer scanning */
3827
clear_bit(STATUS_SCAN_HW, &priv->status);
3829
/* The scan completion notification came in, so kill that timer... */
3830
cancel_delayed_work(&priv->scan_check);
3832
IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
3833
(priv->scan_bands == 2) ? "2.4" : "5.2",
3834
jiffies_to_msecs(elapsed_jiffies
3835
(priv->scan_pass_start, jiffies)));
3837
/* Remove this scanned band from the list
3838
* of pending bands to scan */
3841
/* If a request to abort was given, or the scan did not succeed
3842
* then we reset the scan state machine and terminate,
3843
* re-queuing another scan if one has been requested */
3844
if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
3845
IWL_DEBUG_INFO("Aborted scan completed.\n");
3846
clear_bit(STATUS_SCAN_ABORTING, &priv->status);
3848
/* If there are more bands on this scan pass reschedule */
3849
if (priv->scan_bands > 0)
3853
priv->last_scan_jiffies = jiffies;
3854
priv->next_scan_jiffies = 0;
3855
IWL_DEBUG_INFO("Setting scan to off\n");
3857
clear_bit(STATUS_SCANNING, &priv->status);
3859
IWL_DEBUG_INFO("Scan took %dms\n",
3860
jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
3862
queue_work(priv->workqueue, &priv->scan_completed);
3867
priv->scan_pass_start = jiffies;
3868
queue_work(priv->workqueue, &priv->request_scan);
3871
/* Handle notification from uCode that card's power state is changing
3872
* due to software, hardware, or critical temperature RFKILL */
3873
static void iwl3945_rx_card_state_notif(struct iwl3945_priv *priv,
3874
struct iwl3945_rx_mem_buffer *rxb)
3876
struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
3877
u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
3878
unsigned long status = priv->status;
3880
IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
3881
(flags & HW_CARD_DISABLED) ? "Kill" : "On",
3882
(flags & SW_CARD_DISABLED) ? "Kill" : "On");
3884
iwl3945_write32(priv, CSR_UCODE_DRV_GP1_SET,
3885
CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3887
if (flags & HW_CARD_DISABLED)
3888
set_bit(STATUS_RF_KILL_HW, &priv->status);
3890
clear_bit(STATUS_RF_KILL_HW, &priv->status);
3893
if (flags & SW_CARD_DISABLED)
3894
set_bit(STATUS_RF_KILL_SW, &priv->status);
3896
clear_bit(STATUS_RF_KILL_SW, &priv->status);
3898
iwl3945_scan_cancel(priv);
3900
if ((test_bit(STATUS_RF_KILL_HW, &status) !=
3901
test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
3902
(test_bit(STATUS_RF_KILL_SW, &status) !=
3903
test_bit(STATUS_RF_KILL_SW, &priv->status)))
3904
queue_work(priv->workqueue, &priv->rf_kill);
3906
wake_up_interruptible(&priv->wait_command_queue);
3910
* iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
3912
* Setup the RX handlers for each of the reply types sent from the uCode
3915
* This function chains into the hardware specific files for them to setup
3916
* any hardware specific handlers as well.
3918
static void iwl3945_setup_rx_handlers(struct iwl3945_priv *priv)
3920
priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
3921
priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
3922
priv->rx_handlers[REPLY_ERROR] = iwl3945_rx_reply_error;
3923
priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl3945_rx_csa;
3924
priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
3925
iwl3945_rx_spectrum_measure_notif;
3926
priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl3945_rx_pm_sleep_notif;
3927
priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
3928
iwl3945_rx_pm_debug_statistics_notif;
3929
priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
3932
* The same handler is used for both the REPLY to a discrete
3933
* statistics request from the host as well as for the periodic
3934
* statistics notifications (after received beacons) from the uCode.
3936
priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
3937
priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
3939
priv->rx_handlers[REPLY_SCAN_CMD] = iwl3945_rx_reply_scan;
3940
priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl3945_rx_scan_start_notif;
3941
priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
3942
iwl3945_rx_scan_results_notif;
3943
priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
3944
iwl3945_rx_scan_complete_notif;
3945
priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
3946
priv->rx_handlers[REPLY_TX] = iwl3945_rx_reply_tx;
3948
/* Set up hardware specific Rx handlers */
3949
iwl3945_hw_rx_handler_setup(priv);
3953
* iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
3954
* @rxb: Rx buffer to reclaim
3956
* If an Rx buffer has an async callback associated with it the callback
3957
* will be executed. The attached skb (if present) will only be freed
3958
* if the callback returns 1
3960
static void iwl3945_tx_cmd_complete(struct iwl3945_priv *priv,
3961
struct iwl3945_rx_mem_buffer *rxb)
3963
struct iwl3945_rx_packet *pkt = (struct iwl3945_rx_packet *)rxb->skb->data;
3964
u16 sequence = le16_to_cpu(pkt->hdr.sequence);
3965
int txq_id = SEQ_TO_QUEUE(sequence);
3966
int index = SEQ_TO_INDEX(sequence);
3967
int huge = sequence & SEQ_HUGE_FRAME;
3969
struct iwl3945_cmd *cmd;
3971
/* If a Tx command is being handled and it isn't in the actual
3972
* command queue then there a command routing bug has been introduced
3973
* in the queue management code. */
3974
if (txq_id != IWL_CMD_QUEUE_NUM)
3975
IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
3976
txq_id, pkt->hdr.cmd);
3977
BUG_ON(txq_id != IWL_CMD_QUEUE_NUM);
3979
cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
3980
cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
3982
/* Input error checking is done when commands are added to queue. */
3983
if (cmd->meta.flags & CMD_WANT_SKB) {
3984
cmd->meta.source->u.skb = rxb->skb;
3986
} else if (cmd->meta.u.callback &&
3987
!cmd->meta.u.callback(priv, cmd, rxb->skb))
3990
iwl3945_tx_queue_reclaim(priv, txq_id, index);
3992
if (!(cmd->meta.flags & CMD_ASYNC)) {
3993
clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
3994
wake_up_interruptible(&priv->wait_command_queue);
3998
/************************** RX-FUNCTIONS ****************************/
4000
* Rx theory of operation
4002
* The host allocates 32 DMA target addresses and passes the host address
4003
* to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
4007
* The host/firmware share two index registers for managing the Rx buffers.
4009
* The READ index maps to the first position that the firmware may be writing
4010
* to -- the driver can read up to (but not including) this position and get
4012
* The READ index is managed by the firmware once the card is enabled.
4014
* The WRITE index maps to the last position the driver has read from -- the
4015
* position preceding WRITE is the last slot the firmware can place a packet.
4017
* The queue is empty (no good data) if WRITE = READ - 1, and is full if
4020
* During initialization, the host sets up the READ queue position to the first
4021
* INDEX position, and WRITE to the last (READ - 1 wrapped)
4023
* When the firmware places a packet in a buffer, it will advance the READ index
4024
* and fire the RX interrupt. The driver can then query the READ index and
4025
* process as many packets as possible, moving the WRITE index forward as it
4026
* resets the Rx queue buffers with new memory.
4028
* The management in the driver is as follows:
4029
* + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
4030
* iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
4031
* to replenish the iwl->rxq->rx_free.
4032
* + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
4033
* iwl->rxq is replenished and the READ INDEX is updated (updating the
4034
* 'processed' and 'read' driver indexes as well)
4035
* + A received packet is processed and handed to the kernel network stack,
4036
* detached from the iwl->rxq. The driver 'processed' index is updated.
4037
* + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
4038
* list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
4039
* INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
4040
* were enough free buffers and RX_STALLED is set it is cleared.
4045
* iwl3945_rx_queue_alloc() Allocates rx_free
4046
* iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
4047
* iwl3945_rx_queue_restock
4048
* iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
4049
* queue, updates firmware pointers, and updates
4050
* the WRITE index. If insufficient rx_free buffers
4051
* are available, schedules iwl3945_rx_replenish
4053
* -- enable interrupts --
4054
* ISR - iwl3945_rx() Detach iwl3945_rx_mem_buffers from pool up to the
4055
* READ INDEX, detaching the SKB from the pool.
4056
* Moves the packet buffer from queue to rx_used.
4057
* Calls iwl3945_rx_queue_restock to refill any empty
4064
* iwl3945_rx_queue_space - Return number of free slots available in queue.
4066
static int iwl3945_rx_queue_space(const struct iwl3945_rx_queue *q)
4068
int s = q->read - q->write;
4071
/* keep some buffer to not confuse full and empty queue */
4079
* iwl3945_rx_queue_update_write_ptr - Update the write pointer for the RX queue
4081
int iwl3945_rx_queue_update_write_ptr(struct iwl3945_priv *priv, struct iwl3945_rx_queue *q)
4085
unsigned long flags;
4087
spin_lock_irqsave(&q->lock, flags);
4089
if (q->need_update == 0)
4092
/* If power-saving is in use, make sure device is awake */
4093
if (test_bit(STATUS_POWER_PMI, &priv->status)) {
4094
reg = iwl3945_read32(priv, CSR_UCODE_DRV_GP1);
4096
if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
4097
iwl3945_set_bit(priv, CSR_GP_CNTRL,
4098
CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
4102
rc = iwl3945_grab_nic_access(priv);
4106
/* Device expects a multiple of 8 */
4107
iwl3945_write_direct32(priv, FH_RSCSR_CHNL0_WPTR,
4109
iwl3945_release_nic_access(priv);
4111
/* Else device is assumed to be awake */
4113
/* Device expects a multiple of 8 */
4114
iwl3945_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7);
4120
spin_unlock_irqrestore(&q->lock, flags);
4125
* iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
4127
static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl3945_priv *priv,
4128
dma_addr_t dma_addr)
4130
return cpu_to_le32((u32)dma_addr);
4134
* iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
4136
* If there are slots in the RX queue that need to be restocked,
4137
* and we have free pre-allocated buffers, fill the ranks as much
4138
* as we can, pulling from rx_free.
4140
* This moves the 'write' index forward to catch up with 'processed', and
4141
* also updates the memory address in the firmware to reference the new
4144
static int iwl3945_rx_queue_restock(struct iwl3945_priv *priv)
4146
struct iwl3945_rx_queue *rxq = &priv->rxq;
4147
struct list_head *element;
4148
struct iwl3945_rx_mem_buffer *rxb;
4149
unsigned long flags;
4152
spin_lock_irqsave(&rxq->lock, flags);
4153
write = rxq->write & ~0x7;
4154
while ((iwl3945_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
4155
/* Get next free Rx buffer, remove from free list */
4156
element = rxq->rx_free.next;
4157
rxb = list_entry(element, struct iwl3945_rx_mem_buffer, list);
4160
/* Point to Rx buffer via next RBD in circular buffer */
4161
rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->dma_addr);
4162
rxq->queue[rxq->write] = rxb;
4163
rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
4166
spin_unlock_irqrestore(&rxq->lock, flags);
4167
/* If the pre-allocated buffer pool is dropping low, schedule to
4169
if (rxq->free_count <= RX_LOW_WATERMARK)
4170
queue_work(priv->workqueue, &priv->rx_replenish);
4173
/* If we've added more space for the firmware to place data, tell it.
4174
* Increment device's write pointer in multiples of 8. */
4175
if ((write != (rxq->write & ~0x7))
4176
|| (abs(rxq->write - rxq->read) > 7)) {
4177
spin_lock_irqsave(&rxq->lock, flags);
4178
rxq->need_update = 1;
4179
spin_unlock_irqrestore(&rxq->lock, flags);
4180
rc = iwl3945_rx_queue_update_write_ptr(priv, rxq);
4189
* iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
4191
* When moving to rx_free an SKB is allocated for the slot.
4193
* Also restock the Rx queue via iwl3945_rx_queue_restock.
4194
* This is called as a scheduled work item (except for during initialization)
4196
static void iwl3945_rx_allocate(struct iwl3945_priv *priv)
4198
struct iwl3945_rx_queue *rxq = &priv->rxq;
4199
struct list_head *element;
4200
struct iwl3945_rx_mem_buffer *rxb;
4201
unsigned long flags;
4202
spin_lock_irqsave(&rxq->lock, flags);
4203
while (!list_empty(&rxq->rx_used)) {
4204
element = rxq->rx_used.next;
4205
rxb = list_entry(element, struct iwl3945_rx_mem_buffer, list);
4207
/* Alloc a new receive buffer */
4209
alloc_skb(IWL_RX_BUF_SIZE, __GFP_NOWARN | GFP_ATOMIC);
4211
if (net_ratelimit())
4212
printk(KERN_CRIT DRV_NAME
4213
": Can not allocate SKB buffers\n");
4214
/* We don't reschedule replenish work here -- we will
4215
* call the restock method and if it still needs
4216
* more buffers it will schedule replenish */
4219
priv->alloc_rxb_skb++;
4222
/* Get physical address of RB/SKB */
4224
pci_map_single(priv->pci_dev, rxb->skb->data,
4225
IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4226
list_add_tail(&rxb->list, &rxq->rx_free);
4229
spin_unlock_irqrestore(&rxq->lock, flags);
4233
* this should be called while priv->lock is locked
4235
static void __iwl3945_rx_replenish(void *data)
4237
struct iwl3945_priv *priv = data;
4239
iwl3945_rx_allocate(priv);
4240
iwl3945_rx_queue_restock(priv);
4244
void iwl3945_rx_replenish(void *data)
4246
struct iwl3945_priv *priv = data;
4247
unsigned long flags;
4249
iwl3945_rx_allocate(priv);
4251
spin_lock_irqsave(&priv->lock, flags);
4252
iwl3945_rx_queue_restock(priv);
4253
spin_unlock_irqrestore(&priv->lock, flags);
4256
/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
4257
* If an SKB has been detached, the POOL needs to have its SKB set to NULL
4258
* This free routine walks the list of POOL entries and if SKB is set to
4259
* non NULL it is unmapped and freed
4261
static void iwl3945_rx_queue_free(struct iwl3945_priv *priv, struct iwl3945_rx_queue *rxq)
4264
for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4265
if (rxq->pool[i].skb != NULL) {
4266
pci_unmap_single(priv->pci_dev,
4267
rxq->pool[i].dma_addr,
4268
IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4269
dev_kfree_skb(rxq->pool[i].skb);
4273
pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd,
4278
int iwl3945_rx_queue_alloc(struct iwl3945_priv *priv)
4280
struct iwl3945_rx_queue *rxq = &priv->rxq;
4281
struct pci_dev *dev = priv->pci_dev;
4284
spin_lock_init(&rxq->lock);
4285
INIT_LIST_HEAD(&rxq->rx_free);
4286
INIT_LIST_HEAD(&rxq->rx_used);
4288
/* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
4289
rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr);
4293
/* Fill the rx_used queue with _all_ of the Rx buffers */
4294
for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
4295
list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4297
/* Set us so that we have processed and used all buffers, but have
4298
* not restocked the Rx queue with fresh buffers */
4299
rxq->read = rxq->write = 0;
4300
rxq->free_count = 0;
4301
rxq->need_update = 0;
4305
void iwl3945_rx_queue_reset(struct iwl3945_priv *priv, struct iwl3945_rx_queue *rxq)
4307
unsigned long flags;
4309
spin_lock_irqsave(&rxq->lock, flags);
4310
INIT_LIST_HEAD(&rxq->rx_free);
4311
INIT_LIST_HEAD(&rxq->rx_used);
4312
/* Fill the rx_used queue with _all_ of the Rx buffers */
4313
for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
4314
/* In the reset function, these buffers may have been allocated
4315
* to an SKB, so we need to unmap and free potential storage */
4316
if (rxq->pool[i].skb != NULL) {
4317
pci_unmap_single(priv->pci_dev,
4318
rxq->pool[i].dma_addr,
4319
IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4320
priv->alloc_rxb_skb--;
4321
dev_kfree_skb(rxq->pool[i].skb);
4322
rxq->pool[i].skb = NULL;
4324
list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4327
/* Set us so that we have processed and used all buffers, but have
4328
* not restocked the Rx queue with fresh buffers */
4329
rxq->read = rxq->write = 0;
4330
rxq->free_count = 0;
4331
spin_unlock_irqrestore(&rxq->lock, flags);
4334
/* Convert linear signal-to-noise ratio into dB */
4335
static u8 ratio2dB[100] = {
4336
/* 0 1 2 3 4 5 6 7 8 9 */
4337
0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
4338
20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
4339
26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
4340
29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
4341
32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
4342
34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
4343
36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
4344
37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
4345
38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
4346
39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
4349
/* Calculates a relative dB value from a ratio of linear
4350
* (i.e. not dB) signal levels.
4351
* Conversion assumes that levels are voltages (20*log), not powers (10*log). */
4352
int iwl3945_calc_db_from_ratio(int sig_ratio)
4354
/* Anything above 1000:1 just report as 60 dB */
4355
if (sig_ratio > 1000)
4358
/* Above 100:1, divide by 10 and use table,
4359
* add 20 dB to make up for divide by 10 */
4360
if (sig_ratio > 100)
4361
return (20 + (int)ratio2dB[sig_ratio/10]);
4363
/* We shouldn't see this */
4367
/* Use table for ratios 1:1 - 99:1 */
4368
return (int)ratio2dB[sig_ratio];
4371
#define PERFECT_RSSI (-20) /* dBm */
4372
#define WORST_RSSI (-95) /* dBm */
4373
#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
4375
/* Calculate an indication of rx signal quality (a percentage, not dBm!).
4376
* See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
4377
* about formulas used below. */
4378
int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
4381
int degradation = PERFECT_RSSI - rssi_dbm;
4383
/* If we get a noise measurement, use signal-to-noise ratio (SNR)
4384
* as indicator; formula is (signal dbm - noise dbm).
4385
* SNR at or above 40 is a great signal (100%).
4386
* Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
4387
* Weakest usable signal is usually 10 - 15 dB SNR. */
4389
if (rssi_dbm - noise_dbm >= 40)
4391
else if (rssi_dbm < noise_dbm)
4393
sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
4395
/* Else use just the signal level.
4396
* This formula is a least squares fit of data points collected and
4397
* compared with a reference system that had a percentage (%) display
4398
* for signal quality. */
4400
sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
4401
(15 * RSSI_RANGE + 62 * degradation)) /
4402
(RSSI_RANGE * RSSI_RANGE);
4406
else if (sig_qual < 1)
4413
* iwl3945_rx_handle - Main entry function for receiving responses from uCode
4415
* Uses the priv->rx_handlers callback function array to invoke
4416
* the appropriate handlers, including command responses,
4417
* frame-received notifications, and other notifications.
4419
static void iwl3945_rx_handle(struct iwl3945_priv *priv)
4421
struct iwl3945_rx_mem_buffer *rxb;
4422
struct iwl3945_rx_packet *pkt;
4423
struct iwl3945_rx_queue *rxq = &priv->rxq;
4426
unsigned long flags;
4430
/* uCode's read index (stored in shared DRAM) indicates the last Rx
4431
* buffer that the driver may process (last buffer filled by ucode). */
4432
r = iwl3945_hw_get_rx_read(priv);
4435
if (iwl3945_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
4437
/* Rx interrupt, but nothing sent from uCode */
4439
IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
4442
rxb = rxq->queue[i];
4444
/* If an RXB doesn't have a Rx queue slot associated with it,
4445
* then a bug has been introduced in the queue refilling
4446
* routines -- catch it here */
4447
BUG_ON(rxb == NULL);
4449
rxq->queue[i] = NULL;
4451
pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
4453
PCI_DMA_FROMDEVICE);
4454
pkt = (struct iwl3945_rx_packet *)rxb->skb->data;
4456
/* Reclaim a command buffer only if this packet is a response
4457
* to a (driver-originated) command.
4458
* If the packet (e.g. Rx frame) originated from uCode,
4459
* there is no command buffer to reclaim.
4460
* Ucode should set SEQ_RX_FRAME bit if ucode-originated,
4461
* but apparently a few don't get set; catch them here. */
4462
reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
4463
(pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
4464
(pkt->hdr.cmd != REPLY_TX);
4466
/* Based on type of command response or notification,
4467
* handle those that need handling via function in
4468
* rx_handlers table. See iwl3945_setup_rx_handlers() */
4469
if (priv->rx_handlers[pkt->hdr.cmd]) {
4470
IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
4471
"r = %d, i = %d, %s, 0x%02x\n", r, i,
4472
get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
4473
priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
4475
/* No handling needed */
4476
IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
4477
"r %d i %d No handler needed for %s, 0x%02x\n",
4478
r, i, get_cmd_string(pkt->hdr.cmd),
4483
/* Invoke any callbacks, transfer the skb to caller, and
4484
* fire off the (possibly) blocking iwl3945_send_cmd()
4485
* as we reclaim the driver command queue */
4486
if (rxb && rxb->skb)
4487
iwl3945_tx_cmd_complete(priv, rxb);
4489
IWL_WARNING("Claim null rxb?\n");
4492
/* For now we just don't re-use anything. We can tweak this
4493
* later to try and re-use notification packets and SKBs that
4494
* fail to Rx correctly */
4495
if (rxb->skb != NULL) {
4496
priv->alloc_rxb_skb--;
4497
dev_kfree_skb_any(rxb->skb);
4501
pci_unmap_single(priv->pci_dev, rxb->dma_addr,
4502
IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4503
spin_lock_irqsave(&rxq->lock, flags);
4504
list_add_tail(&rxb->list, &priv->rxq.rx_used);
4505
spin_unlock_irqrestore(&rxq->lock, flags);
4506
i = (i + 1) & RX_QUEUE_MASK;
4507
/* If there are a lot of unused frames,
4508
* restock the Rx queue so ucode won't assert. */
4513
__iwl3945_rx_replenish(priv);
4519
/* Backtrack one entry */
4521
iwl3945_rx_queue_restock(priv);
4525
* iwl3945_tx_queue_update_write_ptr - Send new write index to hardware
4527
static int iwl3945_tx_queue_update_write_ptr(struct iwl3945_priv *priv,
4528
struct iwl3945_tx_queue *txq)
4532
int txq_id = txq->q.id;
4534
if (txq->need_update == 0)
4537
/* if we're trying to save power */
4538
if (test_bit(STATUS_POWER_PMI, &priv->status)) {
4539
/* wake up nic if it's powered down ...
4540
* uCode will wake up, and interrupt us again, so next
4541
* time we'll skip this part. */
4542
reg = iwl3945_read32(priv, CSR_UCODE_DRV_GP1);
4544
if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
4545
IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg);
4546
iwl3945_set_bit(priv, CSR_GP_CNTRL,
4547
CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
4551
/* restore this queue's parameters in nic hardware. */
4552
rc = iwl3945_grab_nic_access(priv);
4555
iwl3945_write_direct32(priv, HBUS_TARG_WRPTR,
4556
txq->q.write_ptr | (txq_id << 8));
4557
iwl3945_release_nic_access(priv);
4559
/* else not in power-save mode, uCode will never sleep when we're
4560
* trying to tx (during RFKILL, we're not trying to tx). */
4562
iwl3945_write32(priv, HBUS_TARG_WRPTR,
4563
txq->q.write_ptr | (txq_id << 8));
4565
txq->need_update = 0;
4570
#ifdef CONFIG_IWL3945_DEBUG
4571
static void iwl3945_print_rx_config_cmd(struct iwl3945_rxon_cmd *rxon)
4573
IWL_DEBUG_RADIO("RX CONFIG:\n");
4574
iwl3945_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
4575
IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
4576
IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
4577
IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
4578
le32_to_cpu(rxon->filter_flags));
4579
IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
4580
IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
4581
rxon->ofdm_basic_rates);
4582
IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
4583
IWL_DEBUG_RADIO("u8[6] node_addr: " MAC_FMT "\n",
4584
MAC_ARG(rxon->node_addr));
4585
IWL_DEBUG_RADIO("u8[6] bssid_addr: " MAC_FMT "\n",
4586
MAC_ARG(rxon->bssid_addr));
4587
IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
4591
static void iwl3945_enable_interrupts(struct iwl3945_priv *priv)
4593
IWL_DEBUG_ISR("Enabling interrupts\n");
4594
set_bit(STATUS_INT_ENABLED, &priv->status);
4595
iwl3945_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
4598
static inline void iwl3945_disable_interrupts(struct iwl3945_priv *priv)
4600
clear_bit(STATUS_INT_ENABLED, &priv->status);
4602
/* disable interrupts from uCode/NIC to host */
4603
iwl3945_write32(priv, CSR_INT_MASK, 0x00000000);
4605
/* acknowledge/clear/reset any interrupts still pending
4606
* from uCode or flow handler (Rx/Tx DMA) */
4607
iwl3945_write32(priv, CSR_INT, 0xffffffff);
4608
iwl3945_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
4609
IWL_DEBUG_ISR("Disabled interrupts\n");
4612
static const char *desc_lookup(int i)
4620
return "BAD_CHECKSUM";
4622
return "NMI_INTERRUPT";
4626
return "FATAL_ERROR";
4632
#define ERROR_START_OFFSET (1 * sizeof(u32))
4633
#define ERROR_ELEM_SIZE (7 * sizeof(u32))
4635
static void iwl3945_dump_nic_error_log(struct iwl3945_priv *priv)
4638
u32 desc, time, count, base, data1;
4639
u32 blink1, blink2, ilink1, ilink2;
4642
base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
4644
if (!iwl3945_hw_valid_rtc_data_addr(base)) {
4645
IWL_ERROR("Not valid error log pointer 0x%08X\n", base);
4649
rc = iwl3945_grab_nic_access(priv);
4651
IWL_WARNING("Can not read from adapter at this time.\n");
4655
count = iwl3945_read_targ_mem(priv, base);
4657
if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
4658
IWL_ERROR("Start IWL Error Log Dump:\n");
4659
IWL_ERROR("Status: 0x%08lX, Config: %08X count: %d\n",
4660
priv->status, priv->config, count);
4663
IWL_ERROR("Desc Time asrtPC blink2 "
4664
"ilink1 nmiPC Line\n");
4665
for (i = ERROR_START_OFFSET;
4666
i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
4667
i += ERROR_ELEM_SIZE) {
4668
desc = iwl3945_read_targ_mem(priv, base + i);
4670
iwl3945_read_targ_mem(priv, base + i + 1 * sizeof(u32));
4672
iwl3945_read_targ_mem(priv, base + i + 2 * sizeof(u32));
4674
iwl3945_read_targ_mem(priv, base + i + 3 * sizeof(u32));
4676
iwl3945_read_targ_mem(priv, base + i + 4 * sizeof(u32));
4678
iwl3945_read_targ_mem(priv, base + i + 5 * sizeof(u32));
4680
iwl3945_read_targ_mem(priv, base + i + 6 * sizeof(u32));
4683
("%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
4684
desc_lookup(desc), desc, time, blink1, blink2,
4685
ilink1, ilink2, data1);
4688
iwl3945_release_nic_access(priv);
4692
#define EVENT_START_OFFSET (6 * sizeof(u32))
4695
* iwl3945_print_event_log - Dump error event log to syslog
4697
* NOTE: Must be called with iwl3945_grab_nic_access() already obtained!
4699
static void iwl3945_print_event_log(struct iwl3945_priv *priv, u32 start_idx,
4700
u32 num_events, u32 mode)
4703
u32 base; /* SRAM byte address of event log header */
4704
u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
4705
u32 ptr; /* SRAM byte address of log data */
4706
u32 ev, time, data; /* event log data */
4708
if (num_events == 0)
4711
base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
4714
event_size = 2 * sizeof(u32);
4716
event_size = 3 * sizeof(u32);
4718
ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
4720
/* "time" is actually "data" for mode 0 (no timestamp).
4721
* place event id # at far right for easier visual parsing. */
4722
for (i = 0; i < num_events; i++) {
4723
ev = iwl3945_read_targ_mem(priv, ptr);
4725
time = iwl3945_read_targ_mem(priv, ptr);
4728
IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */
4730
data = iwl3945_read_targ_mem(priv, ptr);
4732
IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev);
4737
static void iwl3945_dump_nic_event_log(struct iwl3945_priv *priv)
4740
u32 base; /* SRAM byte address of event log header */
4741
u32 capacity; /* event log capacity in # entries */
4742
u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
4743
u32 num_wraps; /* # times uCode wrapped to top of log */
4744
u32 next_entry; /* index of next entry to be written by uCode */
4745
u32 size; /* # entries that we'll print */
4747
base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
4748
if (!iwl3945_hw_valid_rtc_data_addr(base)) {
4749
IWL_ERROR("Invalid event log pointer 0x%08X\n", base);
4753
rc = iwl3945_grab_nic_access(priv);
4755
IWL_WARNING("Can not read from adapter at this time.\n");
4759
/* event log header */
4760
capacity = iwl3945_read_targ_mem(priv, base);
4761
mode = iwl3945_read_targ_mem(priv, base + (1 * sizeof(u32)));
4762
num_wraps = iwl3945_read_targ_mem(priv, base + (2 * sizeof(u32)));
4763
next_entry = iwl3945_read_targ_mem(priv, base + (3 * sizeof(u32)));
4765
size = num_wraps ? capacity : next_entry;
4767
/* bail out if nothing in log */
4769
IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
4770
iwl3945_release_nic_access(priv);
4774
IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
4777
/* if uCode has wrapped back to top of log, start at the oldest entry,
4778
* i.e the next one that uCode would fill. */
4780
iwl3945_print_event_log(priv, next_entry,
4781
capacity - next_entry, mode);
4783
/* (then/else) start at top of log */
4784
iwl3945_print_event_log(priv, 0, next_entry, mode);
4786
iwl3945_release_nic_access(priv);
4790
* iwl3945_irq_handle_error - called for HW or SW error interrupt from card
4792
static void iwl3945_irq_handle_error(struct iwl3945_priv *priv)
4794
/* Set the FW error flag -- cleared on iwl3945_down */
4795
set_bit(STATUS_FW_ERROR, &priv->status);
4797
/* Cancel currently queued command. */
4798
clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
4800
#ifdef CONFIG_IWL3945_DEBUG
4801
if (iwl3945_debug_level & IWL_DL_FW_ERRORS) {
4802
iwl3945_dump_nic_error_log(priv);
4803
iwl3945_dump_nic_event_log(priv);
4804
iwl3945_print_rx_config_cmd(&priv->staging_rxon);
4808
wake_up_interruptible(&priv->wait_command_queue);
4810
/* Keep the restart process from trying to send host
4811
* commands by clearing the INIT status bit */
4812
clear_bit(STATUS_READY, &priv->status);
4814
if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
4815
IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS,
4816
"Restarting adapter due to uCode error.\n");
4818
if (iwl3945_is_associated(priv)) {
4819
memcpy(&priv->recovery_rxon, &priv->active_rxon,
4820
sizeof(priv->recovery_rxon));
4821
priv->error_recovering = 1;
4823
queue_work(priv->workqueue, &priv->restart);
4827
static void iwl3945_error_recovery(struct iwl3945_priv *priv)
4829
unsigned long flags;
4831
memcpy(&priv->staging_rxon, &priv->recovery_rxon,
4832
sizeof(priv->staging_rxon));
4833
priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
4834
iwl3945_commit_rxon(priv);
4836
iwl3945_add_station(priv, priv->bssid, 1, 0);
4838
spin_lock_irqsave(&priv->lock, flags);
4839
priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
4840
priv->error_recovering = 0;
4841
spin_unlock_irqrestore(&priv->lock, flags);
4844
static void iwl3945_irq_tasklet(struct iwl3945_priv *priv)
4846
u32 inta, handled = 0;
4848
unsigned long flags;
4849
#ifdef CONFIG_IWL3945_DEBUG
4853
spin_lock_irqsave(&priv->lock, flags);
4855
/* Ack/clear/reset pending uCode interrupts.
4856
* Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
4857
* and will clear only when CSR_FH_INT_STATUS gets cleared. */
4858
inta = iwl3945_read32(priv, CSR_INT);
4859
iwl3945_write32(priv, CSR_INT, inta);
4861
/* Ack/clear/reset pending flow-handler (DMA) interrupts.
4862
* Any new interrupts that happen after this, either while we're
4863
* in this tasklet, or later, will show up in next ISR/tasklet. */
4864
inta_fh = iwl3945_read32(priv, CSR_FH_INT_STATUS);
4865
iwl3945_write32(priv, CSR_FH_INT_STATUS, inta_fh);
4867
#ifdef CONFIG_IWL3945_DEBUG
4868
if (iwl3945_debug_level & IWL_DL_ISR) {
4869
/* just for debug */
4870
inta_mask = iwl3945_read32(priv, CSR_INT_MASK);
4871
IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4872
inta, inta_mask, inta_fh);
4876
/* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
4877
* atomic, make sure that inta covers all the interrupts that
4878
* we've discovered, even if FH interrupt came in just after
4879
* reading CSR_INT. */
4880
if (inta_fh & CSR_FH_INT_RX_MASK)
4881
inta |= CSR_INT_BIT_FH_RX;
4882
if (inta_fh & CSR_FH_INT_TX_MASK)
4883
inta |= CSR_INT_BIT_FH_TX;
4885
/* Now service all interrupt bits discovered above. */
4886
if (inta & CSR_INT_BIT_HW_ERR) {
4887
IWL_ERROR("Microcode HW error detected. Restarting.\n");
4889
/* Tell the device to stop sending interrupts */
4890
iwl3945_disable_interrupts(priv);
4892
iwl3945_irq_handle_error(priv);
4894
handled |= CSR_INT_BIT_HW_ERR;
4896
spin_unlock_irqrestore(&priv->lock, flags);
4901
#ifdef CONFIG_IWL3945_DEBUG
4902
if (iwl3945_debug_level & (IWL_DL_ISR)) {
4903
/* NIC fires this, but we don't use it, redundant with WAKEUP */
4904
if (inta & CSR_INT_BIT_MAC_CLK_ACTV)
4905
IWL_DEBUG_ISR("Microcode started or stopped.\n");
4907
/* Alive notification via Rx interrupt will do the real work */
4908
if (inta & CSR_INT_BIT_ALIVE)
4909
IWL_DEBUG_ISR("Alive interrupt\n");
4912
/* Safely ignore these bits for debug checks below */
4913
inta &= ~(CSR_INT_BIT_MAC_CLK_ACTV | CSR_INT_BIT_ALIVE);
4915
/* HW RF KILL switch toggled (4965 only) */
4916
if (inta & CSR_INT_BIT_RF_KILL) {
4918
if (!(iwl3945_read32(priv, CSR_GP_CNTRL) &
4919
CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
4922
IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL | IWL_DL_ISR,
4923
"RF_KILL bit toggled to %s.\n",
4924
hw_rf_kill ? "disable radio":"enable radio");
4926
/* Queue restart only if RF_KILL switch was set to "kill"
4927
* when we loaded driver, and is now set to "enable".
4928
* After we're Alive, RF_KILL gets handled by
4929
* iwl3945_rx_card_state_notif() */
4930
if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) {
4931
clear_bit(STATUS_RF_KILL_HW, &priv->status);
4932
queue_work(priv->workqueue, &priv->restart);
4935
handled |= CSR_INT_BIT_RF_KILL;
4938
/* Chip got too hot and stopped itself (4965 only) */
4939
if (inta & CSR_INT_BIT_CT_KILL) {
4940
IWL_ERROR("Microcode CT kill error detected.\n");
4941
handled |= CSR_INT_BIT_CT_KILL;
4944
/* Error detected by uCode */
4945
if (inta & CSR_INT_BIT_SW_ERR) {
4946
IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
4948
iwl3945_irq_handle_error(priv);
4949
handled |= CSR_INT_BIT_SW_ERR;
4952
/* uCode wakes up after power-down sleep */
4953
if (inta & CSR_INT_BIT_WAKEUP) {
4954
IWL_DEBUG_ISR("Wakeup interrupt\n");
4955
iwl3945_rx_queue_update_write_ptr(priv, &priv->rxq);
4956
iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[0]);
4957
iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[1]);
4958
iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[2]);
4959
iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[3]);
4960
iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[4]);
4961
iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[5]);
4963
handled |= CSR_INT_BIT_WAKEUP;
4966
/* All uCode command responses, including Tx command responses,
4967
* Rx "responses" (frame-received notification), and other
4968
* notifications from uCode come through here*/
4969
if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
4970
iwl3945_rx_handle(priv);
4971
handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
4974
if (inta & CSR_INT_BIT_FH_TX) {
4975
IWL_DEBUG_ISR("Tx interrupt\n");
4977
iwl3945_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
4978
if (!iwl3945_grab_nic_access(priv)) {
4979
iwl3945_write_direct32(priv,
4981
(ALM_FH_SRVC_CHNL), 0x0);
4982
iwl3945_release_nic_access(priv);
4984
handled |= CSR_INT_BIT_FH_TX;
4987
if (inta & ~handled)
4988
IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
4990
if (inta & ~CSR_INI_SET_MASK) {
4991
IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
4992
inta & ~CSR_INI_SET_MASK);
4993
IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
4996
/* Re-enable all interrupts */
4997
iwl3945_enable_interrupts(priv);
4999
#ifdef CONFIG_IWL3945_DEBUG
5000
if (iwl3945_debug_level & (IWL_DL_ISR)) {
5001
inta = iwl3945_read32(priv, CSR_INT);
5002
inta_mask = iwl3945_read32(priv, CSR_INT_MASK);
5003
inta_fh = iwl3945_read32(priv, CSR_FH_INT_STATUS);
5004
IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
5005
"flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
5008
spin_unlock_irqrestore(&priv->lock, flags);
5011
static irqreturn_t iwl3945_isr(int irq, void *data)
5013
struct iwl3945_priv *priv = data;
5014
u32 inta, inta_mask;
5019
spin_lock(&priv->lock);
5021
/* Disable (but don't clear!) interrupts here to avoid
5022
* back-to-back ISRs and sporadic interrupts from our NIC.
5023
* If we have something to service, the tasklet will re-enable ints.
5024
* If we *don't* have something, we'll re-enable before leaving here. */
5025
inta_mask = iwl3945_read32(priv, CSR_INT_MASK); /* just for debug */
5026
iwl3945_write32(priv, CSR_INT_MASK, 0x00000000);
5028
/* Discover which interrupts are active/pending */
5029
inta = iwl3945_read32(priv, CSR_INT);
5030
inta_fh = iwl3945_read32(priv, CSR_FH_INT_STATUS);
5032
/* Ignore interrupt if there's nothing in NIC to service.
5033
* This may be due to IRQ shared with another device,
5034
* or due to sporadic interrupts thrown from our NIC. */
5035
if (!inta && !inta_fh) {
5036
IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
5040
if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
5041
/* Hardware disappeared. It might have already raised
5043
IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
5047
IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
5048
inta, inta_mask, inta_fh);
5050
/* iwl3945_irq_tasklet() will service interrupts and re-enable them */
5051
tasklet_schedule(&priv->irq_tasklet);
5054
spin_unlock(&priv->lock);
5058
/* re-enable interrupts here since we don't have anything to service. */
5059
iwl3945_enable_interrupts(priv);
5060
spin_unlock(&priv->lock);
5064
/************************** EEPROM BANDS ****************************
5066
* The iwl3945_eeprom_band definitions below provide the mapping from the
5067
* EEPROM contents to the specific channel number supported for each
5070
* For example, iwl3945_priv->eeprom.band_3_channels[4] from the band_3
5071
* definition below maps to physical channel 42 in the 5.2GHz spectrum.
5072
* The specific geography and calibration information for that channel
5073
* is contained in the eeprom map itself.
5075
* During init, we copy the eeprom information and channel map
5076
* information into priv->channel_info_24/52 and priv->channel_map_24/52
5078
* channel_map_24/52 provides the index in the channel_info array for a
5079
* given channel. We have to have two separate maps as there is channel
5080
* overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
5083
* A value of 0xff stored in the channel_map indicates that the channel
5084
* is not supported by the hardware at all.
5086
* A value of 0xfe in the channel_map indicates that the channel is not
5087
* valid for Tx with the current hardware. This means that
5088
* while the system can tune and receive on a given channel, it may not
5089
* be able to associate or transmit any frames on that
5090
* channel. There is no corresponding channel information for that
5093
*********************************************************************/
5096
static const u8 iwl3945_eeprom_band_1[14] = {
5097
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
5101
static const u8 iwl3945_eeprom_band_2[] = { /* 4915-5080MHz */
5102
183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
5105
static const u8 iwl3945_eeprom_band_3[] = { /* 5170-5320MHz */
5106
34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
5109
static const u8 iwl3945_eeprom_band_4[] = { /* 5500-5700MHz */
5110
100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
5113
static const u8 iwl3945_eeprom_band_5[] = { /* 5725-5825MHz */
5114
145, 149, 153, 157, 161, 165
5117
static void iwl3945_init_band_reference(const struct iwl3945_priv *priv, int band,
5118
int *eeprom_ch_count,
5119
const struct iwl3945_eeprom_channel
5121
const u8 **eeprom_ch_index)
5124
case 1: /* 2.4GHz band */
5125
*eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_1);
5126
*eeprom_ch_info = priv->eeprom.band_1_channels;
5127
*eeprom_ch_index = iwl3945_eeprom_band_1;
5129
case 2: /* 4.9GHz band */
5130
*eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_2);
5131
*eeprom_ch_info = priv->eeprom.band_2_channels;
5132
*eeprom_ch_index = iwl3945_eeprom_band_2;
5134
case 3: /* 5.2GHz band */
5135
*eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_3);
5136
*eeprom_ch_info = priv->eeprom.band_3_channels;
5137
*eeprom_ch_index = iwl3945_eeprom_band_3;
5139
case 4: /* 5.5GHz band */
5140
*eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_4);
5141
*eeprom_ch_info = priv->eeprom.band_4_channels;
5142
*eeprom_ch_index = iwl3945_eeprom_band_4;
5144
case 5: /* 5.7GHz band */
5145
*eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_5);
5146
*eeprom_ch_info = priv->eeprom.band_5_channels;
5147
*eeprom_ch_index = iwl3945_eeprom_band_5;
5156
* iwl3945_get_channel_info - Find driver's private channel info
5158
* Based on band and channel number.
5160
const struct iwl3945_channel_info *iwl3945_get_channel_info(const struct iwl3945_priv *priv,
5161
int phymode, u16 channel)
5166
case MODE_IEEE80211A:
5167
for (i = 14; i < priv->channel_count; i++) {
5168
if (priv->channel_info[i].channel == channel)
5169
return &priv->channel_info[i];
5173
case MODE_IEEE80211B:
5174
case MODE_IEEE80211G:
5175
if (channel >= 1 && channel <= 14)
5176
return &priv->channel_info[channel - 1];
5184
#define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
5188
* iwl3945_init_channel_map - Set up driver's info for all possible channels
5190
static int iwl3945_init_channel_map(struct iwl3945_priv *priv)
5192
int eeprom_ch_count = 0;
5193
const u8 *eeprom_ch_index = NULL;
5194
const struct iwl3945_eeprom_channel *eeprom_ch_info = NULL;
5196
struct iwl3945_channel_info *ch_info;
5198
if (priv->channel_count) {
5199
IWL_DEBUG_INFO("Channel map already initialized.\n");
5203
if (priv->eeprom.version < 0x2f) {
5204
IWL_WARNING("Unsupported EEPROM version: 0x%04X\n",
5205
priv->eeprom.version);
5209
IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n");
5211
priv->channel_count =
5212
ARRAY_SIZE(iwl3945_eeprom_band_1) +
5213
ARRAY_SIZE(iwl3945_eeprom_band_2) +
5214
ARRAY_SIZE(iwl3945_eeprom_band_3) +
5215
ARRAY_SIZE(iwl3945_eeprom_band_4) +
5216
ARRAY_SIZE(iwl3945_eeprom_band_5);
5218
IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count);
5220
priv->channel_info = kzalloc(sizeof(struct iwl3945_channel_info) *
5221
priv->channel_count, GFP_KERNEL);
5222
if (!priv->channel_info) {
5223
IWL_ERROR("Could not allocate channel_info\n");
5224
priv->channel_count = 0;
5228
ch_info = priv->channel_info;
5230
/* Loop through the 5 EEPROM bands adding them in order to the
5231
* channel map we maintain (that contains additional information than
5232
* what just in the EEPROM) */
5233
for (band = 1; band <= 5; band++) {
5235
iwl3945_init_band_reference(priv, band, &eeprom_ch_count,
5236
&eeprom_ch_info, &eeprom_ch_index);
5238
/* Loop through each band adding each of the channels */
5239
for (ch = 0; ch < eeprom_ch_count; ch++) {
5240
ch_info->channel = eeprom_ch_index[ch];
5241
ch_info->phymode = (band == 1) ? MODE_IEEE80211B :
5244
/* permanently store EEPROM's channel regulatory flags
5245
* and max power in channel info database. */
5246
ch_info->eeprom = eeprom_ch_info[ch];
5248
/* Copy the run-time flags so they are there even on
5249
* invalid channels */
5250
ch_info->flags = eeprom_ch_info[ch].flags;
5252
if (!(is_channel_valid(ch_info))) {
5253
IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - "
5257
is_channel_a_band(ch_info) ?
5263
/* Initialize regulatory-based run-time data */
5264
ch_info->max_power_avg = ch_info->curr_txpow =
5265
eeprom_ch_info[ch].max_power_avg;
5266
ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
5267
ch_info->min_power = 0;
5269
IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x"
5270
" %ddBm): Ad-Hoc %ssupported\n",
5272
is_channel_a_band(ch_info) ?
5274
CHECK_AND_PRINT(IBSS),
5275
CHECK_AND_PRINT(ACTIVE),
5276
CHECK_AND_PRINT(RADAR),
5277
CHECK_AND_PRINT(WIDE),
5278
CHECK_AND_PRINT(NARROW),
5279
CHECK_AND_PRINT(DFS),
5280
eeprom_ch_info[ch].flags,
5281
eeprom_ch_info[ch].max_power_avg,
5282
((eeprom_ch_info[ch].
5283
flags & EEPROM_CHANNEL_IBSS)
5284
&& !(eeprom_ch_info[ch].
5285
flags & EEPROM_CHANNEL_RADAR))
5288
/* Set the user_txpower_limit to the highest power
5289
* supported by any channel */
5290
if (eeprom_ch_info[ch].max_power_avg >
5291
priv->user_txpower_limit)
5292
priv->user_txpower_limit =
5293
eeprom_ch_info[ch].max_power_avg;
5299
/* Set up txpower settings in driver for all channels */
5300
if (iwl3945_txpower_set_from_eeprom(priv))
5306
/* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
5307
* sending probe req. This should be set long enough to hear probe responses
5308
* from more than one AP. */
5309
#define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
5310
#define IWL_ACTIVE_DWELL_TIME_52 (10)
5312
/* For faster active scanning, scan will move to the next channel if fewer than
5313
* PLCP_QUIET_THRESH packets are heard on this channel within
5314
* ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
5315
* time if it's a quiet channel (nothing responded to our probe, and there's
5316
* no other traffic).
5317
* Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
5318
#define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
5319
#define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
5321
/* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
5322
* Must be set longer than active dwell time.
5323
* For the most reliable scan, set > AP beacon interval (typically 100msec). */
5324
#define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
5325
#define IWL_PASSIVE_DWELL_TIME_52 (10)
5326
#define IWL_PASSIVE_DWELL_BASE (100)
5327
#define IWL_CHANNEL_TUNE_TIME 5
5329
static inline u16 iwl3945_get_active_dwell_time(struct iwl3945_priv *priv, int phymode)
5331
if (phymode == MODE_IEEE80211A)
5332
return IWL_ACTIVE_DWELL_TIME_52;
5334
return IWL_ACTIVE_DWELL_TIME_24;
5337
static u16 iwl3945_get_passive_dwell_time(struct iwl3945_priv *priv, int phymode)
5339
u16 active = iwl3945_get_active_dwell_time(priv, phymode);
5340
u16 passive = (phymode != MODE_IEEE80211A) ?
5341
IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
5342
IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
5344
if (iwl3945_is_associated(priv)) {
5345
/* If we're associated, we clamp the maximum passive
5346
* dwell time to be 98% of the beacon interval (minus
5347
* 2 * channel tune time) */
5348
passive = priv->beacon_int;
5349
if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive)
5350
passive = IWL_PASSIVE_DWELL_BASE;
5351
passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
5354
if (passive <= active)
5355
passive = active + 1;
5360
static int iwl3945_get_channels_for_scan(struct iwl3945_priv *priv, int phymode,
5361
u8 is_active, u8 direct_mask,
5362
struct iwl3945_scan_channel *scan_ch)
5364
const struct ieee80211_channel *channels = NULL;
5365
const struct ieee80211_hw_mode *hw_mode;
5366
const struct iwl3945_channel_info *ch_info;
5367
u16 passive_dwell = 0;
5368
u16 active_dwell = 0;
5371
hw_mode = iwl3945_get_hw_mode(priv, phymode);
5375
channels = hw_mode->channels;
5377
active_dwell = iwl3945_get_active_dwell_time(priv, phymode);
5378
passive_dwell = iwl3945_get_passive_dwell_time(priv, phymode);
5380
for (i = 0, added = 0; i < hw_mode->num_channels; i++) {
5381
if (channels[i].chan ==
5382
le16_to_cpu(priv->active_rxon.channel)) {
5383
if (iwl3945_is_associated(priv)) {
5385
("Skipping current channel %d\n",
5386
le16_to_cpu(priv->active_rxon.channel));
5389
} else if (priv->only_active_channel)
5392
scan_ch->channel = channels[i].chan;
5394
ch_info = iwl3945_get_channel_info(priv, phymode, scan_ch->channel);
5395
if (!is_channel_valid(ch_info)) {
5396
IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
5401
if (!is_active || is_channel_passive(ch_info) ||
5402
!(channels[i].flag & IEEE80211_CHAN_W_ACTIVE_SCAN))
5403
scan_ch->type = 0; /* passive */
5405
scan_ch->type = 1; /* active */
5407
if (scan_ch->type & 1)
5408
scan_ch->type |= (direct_mask << 1);
5410
if (is_channel_narrow(ch_info))
5411
scan_ch->type |= (1 << 7);
5413
scan_ch->active_dwell = cpu_to_le16(active_dwell);
5414
scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
5416
/* Set txpower levels to defaults */
5417
scan_ch->tpc.dsp_atten = 110;
5418
/* scan_pwr_info->tpc.dsp_atten; */
5420
/*scan_pwr_info->tpc.tx_gain; */
5421
if (phymode == MODE_IEEE80211A)
5422
scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
5424
scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
5425
/* NOTE: if we were doing 6Mb OFDM for scans we'd use
5427
* scan_ch->tpc.tx_gain = ((1<<5) | (2 << 3)) | 3;
5431
IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
5433
(scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
5434
(scan_ch->type & 1) ?
5435
active_dwell : passive_dwell);
5441
IWL_DEBUG_SCAN("total channels to scan %d \n", added);
5445
static void iwl3945_reset_channel_flag(struct iwl3945_priv *priv)
5448
for (i = 0; i < 3; i++) {
5449
struct ieee80211_hw_mode *hw_mode = (void *)&priv->modes[i];
5450
for (j = 0; j < hw_mode->num_channels; j++)
5451
hw_mode->channels[j].flag = hw_mode->channels[j].val;
5455
static void iwl3945_init_hw_rates(struct iwl3945_priv *priv,
5456
struct ieee80211_rate *rates)
5460
for (i = 0; i < IWL_RATE_COUNT; i++) {
5461
rates[i].rate = iwl3945_rates[i].ieee * 5;
5462
rates[i].val = i; /* Rate scaling will work on indexes */
5464
rates[i].flags = IEEE80211_RATE_SUPPORTED;
5465
/* Only OFDM have the bits-per-symbol set */
5466
if ((i <= IWL_LAST_OFDM_RATE) && (i >= IWL_FIRST_OFDM_RATE))
5467
rates[i].flags |= IEEE80211_RATE_OFDM;
5470
* If CCK 1M then set rate flag to CCK else CCK_2
5471
* which is CCK | PREAMBLE2
5473
rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
5474
IEEE80211_RATE_CCK : IEEE80211_RATE_CCK_2;
5477
/* Set up which ones are basic rates... */
5478
if (IWL_BASIC_RATES_MASK & (1 << i))
5479
rates[i].flags |= IEEE80211_RATE_BASIC;
5484
* iwl3945_init_geos - Initialize mac80211's geo/channel info based from eeprom
5486
static int iwl3945_init_geos(struct iwl3945_priv *priv)
5488
struct iwl3945_channel_info *ch;
5489
struct ieee80211_hw_mode *modes;
5490
struct ieee80211_channel *channels;
5491
struct ieee80211_channel *geo_ch;
5492
struct ieee80211_rate *rates;
5502
IWL_DEBUG_INFO("Geography modes already initialized.\n");
5503
set_bit(STATUS_GEO_CONFIGURED, &priv->status);
5507
modes = kzalloc(sizeof(struct ieee80211_hw_mode) * mode_count,
5512
channels = kzalloc(sizeof(struct ieee80211_channel) *
5513
priv->channel_count, GFP_KERNEL);
5519
rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_MAX_RATES + 1)),
5532
/* 5.2GHz channels start after the 2.4GHz channels */
5533
modes[A].mode = MODE_IEEE80211A;
5534
modes[A].channels = &channels[ARRAY_SIZE(iwl3945_eeprom_band_1)];
5535
modes[A].rates = &rates[4];
5536
modes[A].num_rates = 8; /* just OFDM */
5537
modes[A].num_channels = 0;
5539
modes[B].mode = MODE_IEEE80211B;
5540
modes[B].channels = channels;
5541
modes[B].rates = rates;
5542
modes[B].num_rates = 4; /* just CCK */
5543
modes[B].num_channels = 0;
5545
modes[G].mode = MODE_IEEE80211G;
5546
modes[G].channels = channels;
5547
modes[G].rates = rates;
5548
modes[G].num_rates = 12; /* OFDM & CCK */
5549
modes[G].num_channels = 0;
5551
priv->ieee_channels = channels;
5552
priv->ieee_rates = rates;
5554
iwl3945_init_hw_rates(priv, rates);
5556
for (i = 0, geo_ch = channels; i < priv->channel_count; i++) {
5557
ch = &priv->channel_info[i];
5559
if (!is_channel_valid(ch)) {
5560
IWL_DEBUG_INFO("Channel %d [%sGHz] is restricted -- "
5562
ch->channel, is_channel_a_band(ch) ?
5567
if (is_channel_a_band(ch))
5568
geo_ch = &modes[A].channels[modes[A].num_channels++];
5570
geo_ch = &modes[B].channels[modes[B].num_channels++];
5571
modes[G].num_channels++;
5574
geo_ch->freq = ieee80211chan2mhz(ch->channel);
5575
geo_ch->chan = ch->channel;
5576
geo_ch->power_level = ch->max_power_avg;
5577
geo_ch->antenna_max = 0xff;
5579
if (is_channel_valid(ch)) {
5580
geo_ch->flag = IEEE80211_CHAN_W_SCAN;
5581
if (ch->flags & EEPROM_CHANNEL_IBSS)
5582
geo_ch->flag |= IEEE80211_CHAN_W_IBSS;
5584
if (ch->flags & EEPROM_CHANNEL_ACTIVE)
5585
geo_ch->flag |= IEEE80211_CHAN_W_ACTIVE_SCAN;
5587
if (ch->flags & EEPROM_CHANNEL_RADAR)
5588
geo_ch->flag |= IEEE80211_CHAN_W_RADAR_DETECT;
5590
if (ch->max_power_avg > priv->max_channel_txpower_limit)
5591
priv->max_channel_txpower_limit =
5595
geo_ch->val = geo_ch->flag;
5598
if ((modes[A].num_channels == 0) && priv->is_abg) {
5599
printk(KERN_INFO DRV_NAME
5600
": Incorrectly detected BG card as ABG. Please send "
5601
"your PCI ID 0x%04X:0x%04X to maintainer.\n",
5602
priv->pci_dev->device, priv->pci_dev->subsystem_device);
5606
printk(KERN_INFO DRV_NAME
5607
": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
5608
modes[G].num_channels, modes[A].num_channels);
5611
* NOTE: We register these in preference of order -- the
5612
* stack doesn't currently (as of 7.0.6 / Apr 24 '07) pick
5613
* a phymode based on rates or AP capabilities but seems to
5614
* configure it purely on if the channel being configured
5615
* is supported by a mode -- and the first match is taken
5618
if (modes[G].num_channels)
5619
iwlwifi_iwlwifi_ieee80211_register_hwmode(priv->hw, &modes[G]);
5620
if (modes[B].num_channels)
5621
iwlwifi_iwlwifi_ieee80211_register_hwmode(priv->hw, &modes[B]);
5622
if (modes[A].num_channels)
5623
iwlwifi_iwlwifi_ieee80211_register_hwmode(priv->hw, &modes[A]);
5625
priv->modes = modes;
5626
set_bit(STATUS_GEO_CONFIGURED, &priv->status);
5631
/******************************************************************************
5633
* uCode download functions
5635
******************************************************************************/
5637
static void iwl3945_dealloc_ucode_pci(struct iwl3945_priv *priv)
5639
iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
5640
iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
5641
iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
5642
iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
5643
iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
5644
iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
5648
* iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
5649
* looking at all data.
5651
static int iwl3945_verify_inst_full(struct iwl3945_priv *priv, __le32 * image, u32 len)
5658
IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
5660
rc = iwl3945_grab_nic_access(priv);
5664
iwl3945_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND);
5667
for (; len > 0; len -= sizeof(u32), image++) {
5668
/* read data comes through single port, auto-incr addr */
5669
/* NOTE: Use the debugless read so we don't flood kernel log
5670
* if IWL_DL_IO is set */
5671
val = _iwl3945_read_direct32(priv, HBUS_TARG_MEM_RDAT);
5672
if (val != le32_to_cpu(*image)) {
5673
IWL_ERROR("uCode INST section is invalid at "
5674
"offset 0x%x, is 0x%x, s/b 0x%x\n",
5675
save_len - len, val, le32_to_cpu(*image));
5683
iwl3945_release_nic_access(priv);
5686
IWL_DEBUG_INFO("ucode image in INSTRUCTION memory is good\n");
5693
* iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
5694
* using sample data 100 bytes apart. If these sample points are good,
5695
* it's a pretty good bet that everything between them is good, too.
5697
static int iwl3945_verify_inst_sparse(struct iwl3945_priv *priv, __le32 *image, u32 len)
5704
IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
5706
rc = iwl3945_grab_nic_access(priv);
5710
for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
5711
/* read data comes through single port, auto-incr addr */
5712
/* NOTE: Use the debugless read so we don't flood kernel log
5713
* if IWL_DL_IO is set */
5714
iwl3945_write_direct32(priv, HBUS_TARG_MEM_RADDR,
5715
i + RTC_INST_LOWER_BOUND);
5716
val = _iwl3945_read_direct32(priv, HBUS_TARG_MEM_RDAT);
5717
if (val != le32_to_cpu(*image)) {
5718
#if 0 /* Enable this if you want to see details */
5719
IWL_ERROR("uCode INST section is invalid at "
5720
"offset 0x%x, is 0x%x, s/b 0x%x\n",
5730
iwl3945_release_nic_access(priv);
5737
* iwl3945_verify_ucode - determine which instruction image is in SRAM,
5738
* and verify its contents
5740
static int iwl3945_verify_ucode(struct iwl3945_priv *priv)
5747
image = (__le32 *)priv->ucode_boot.v_addr;
5748
len = priv->ucode_boot.len;
5749
rc = iwl3945_verify_inst_sparse(priv, image, len);
5751
IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
5755
/* Try initialize */
5756
image = (__le32 *)priv->ucode_init.v_addr;
5757
len = priv->ucode_init.len;
5758
rc = iwl3945_verify_inst_sparse(priv, image, len);
5760
IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
5764
/* Try runtime/protocol */
5765
image = (__le32 *)priv->ucode_code.v_addr;
5766
len = priv->ucode_code.len;
5767
rc = iwl3945_verify_inst_sparse(priv, image, len);
5769
IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
5773
IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
5775
/* Since nothing seems to match, show first several data entries in
5776
* instruction SRAM, so maybe visual inspection will give a clue.
5777
* Selection of bootstrap image (vs. other images) is arbitrary. */
5778
image = (__le32 *)priv->ucode_boot.v_addr;
5779
len = priv->ucode_boot.len;
5780
rc = iwl3945_verify_inst_full(priv, image, len);
5786
/* check contents of special bootstrap uCode SRAM */
5787
static int iwl3945_verify_bsm(struct iwl3945_priv *priv)
5789
__le32 *image = priv->ucode_boot.v_addr;
5790
u32 len = priv->ucode_boot.len;
5794
IWL_DEBUG_INFO("Begin verify bsm\n");
5796
/* verify BSM SRAM contents */
5797
val = iwl3945_read_prph(priv, BSM_WR_DWCOUNT_REG);
5798
for (reg = BSM_SRAM_LOWER_BOUND;
5799
reg < BSM_SRAM_LOWER_BOUND + len;
5800
reg += sizeof(u32), image ++) {
5801
val = iwl3945_read_prph(priv, reg);
5802
if (val != le32_to_cpu(*image)) {
5803
IWL_ERROR("BSM uCode verification failed at "
5804
"addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
5805
BSM_SRAM_LOWER_BOUND,
5806
reg - BSM_SRAM_LOWER_BOUND, len,
5807
val, le32_to_cpu(*image));
5812
IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
5818
* iwl3945_load_bsm - Load bootstrap instructions
5822
* The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
5823
* in special SRAM that does not power down during RFKILL. When powering back
5824
* up after power-saving sleeps (or during initial uCode load), the BSM loads
5825
* the bootstrap program into the on-board processor, and starts it.
5827
* The bootstrap program loads (via DMA) instructions and data for a new
5828
* program from host DRAM locations indicated by the host driver in the
5829
* BSM_DRAM_* registers. Once the new program is loaded, it starts
5832
* When initializing the NIC, the host driver points the BSM to the
5833
* "initialize" uCode image. This uCode sets up some internal data, then
5834
* notifies host via "initialize alive" that it is complete.
5836
* The host then replaces the BSM_DRAM_* pointer values to point to the
5837
* normal runtime uCode instructions and a backup uCode data cache buffer
5838
* (filled initially with starting data values for the on-board processor),
5839
* then triggers the "initialize" uCode to load and launch the runtime uCode,
5840
* which begins normal operation.
5842
* When doing a power-save shutdown, runtime uCode saves data SRAM into
5843
* the backup data cache in DRAM before SRAM is powered down.
5845
* When powering back up, the BSM loads the bootstrap program. This reloads
5846
* the runtime uCode instructions and the backup data cache into SRAM,
5847
* and re-launches the runtime uCode from where it left off.
5849
static int iwl3945_load_bsm(struct iwl3945_priv *priv)
5851
__le32 *image = priv->ucode_boot.v_addr;
5852
u32 len = priv->ucode_boot.len;
5862
IWL_DEBUG_INFO("Begin load bsm\n");
5864
/* make sure bootstrap program is no larger than BSM's SRAM size */
5865
if (len > IWL_MAX_BSM_SIZE)
5868
/* Tell bootstrap uCode where to find the "Initialize" uCode
5869
* in host DRAM ... host DRAM physical address bits 31:0 for 3945.
5870
* NOTE: iwl3945_initialize_alive_start() will replace these values,
5871
* after the "initialize" uCode has run, to point to
5872
* runtime/protocol instructions and backup data cache. */
5873
pinst = priv->ucode_init.p_addr;
5874
pdata = priv->ucode_init_data.p_addr;
5875
inst_len = priv->ucode_init.len;
5876
data_len = priv->ucode_init_data.len;
5878
rc = iwl3945_grab_nic_access(priv);
5882
iwl3945_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
5883
iwl3945_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
5884
iwl3945_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
5885
iwl3945_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
5887
/* Fill BSM memory with bootstrap instructions */
5888
for (reg_offset = BSM_SRAM_LOWER_BOUND;
5889
reg_offset < BSM_SRAM_LOWER_BOUND + len;
5890
reg_offset += sizeof(u32), image++)
5891
_iwl3945_write_prph(priv, reg_offset,
5892
le32_to_cpu(*image));
5894
rc = iwl3945_verify_bsm(priv);
5896
iwl3945_release_nic_access(priv);
5900
/* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
5901
iwl3945_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0);
5902
iwl3945_write_prph(priv, BSM_WR_MEM_DST_REG,
5903
RTC_INST_LOWER_BOUND);
5904
iwl3945_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
5906
/* Load bootstrap code into instruction SRAM now,
5907
* to prepare to load "initialize" uCode */
5908
iwl3945_write_prph(priv, BSM_WR_CTRL_REG,
5909
BSM_WR_CTRL_REG_BIT_START);
5911
/* Wait for load of bootstrap uCode to finish */
5912
for (i = 0; i < 100; i++) {
5913
done = iwl3945_read_prph(priv, BSM_WR_CTRL_REG);
5914
if (!(done & BSM_WR_CTRL_REG_BIT_START))
5919
IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i);
5921
IWL_ERROR("BSM write did not complete!\n");
5925
/* Enable future boot loads whenever power management unit triggers it
5926
* (e.g. when powering back up after power-save shutdown) */
5927
iwl3945_write_prph(priv, BSM_WR_CTRL_REG,
5928
BSM_WR_CTRL_REG_BIT_START_EN);
5930
iwl3945_release_nic_access(priv);
5935
static void iwl3945_nic_start(struct iwl3945_priv *priv)
5937
/* Remove all resets to allow NIC to operate */
5938
iwl3945_write32(priv, CSR_RESET, 0);
5942
* iwl3945_read_ucode - Read uCode images from disk file.
5944
* Copy into buffers for card to fetch via bus-mastering
5946
static int iwl3945_read_ucode(struct iwl3945_priv *priv)
5948
struct iwl3945_ucode *ucode;
5950
const struct firmware *ucode_raw;
5951
/* firmware file name contains uCode/driver compatibility version */
5952
const char *name = "iwlwifi-3945" IWL3945_UCODE_API ".ucode";
5955
u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
5957
/* Ask kernel firmware_class module to get the boot firmware off disk.
5958
* request_firmware() is synchronous, file is in memory on return. */
5959
ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
5961
IWL_ERROR("%s firmware file req failed: Reason %d\n",
5966
IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
5967
name, ucode_raw->size);
5969
/* Make sure that we got at least our header! */
5970
if (ucode_raw->size < sizeof(*ucode)) {
5971
IWL_ERROR("File size way too small!\n");
5976
/* Data from ucode file: header followed by uCode images */
5977
ucode = (void *)ucode_raw->data;
5979
ver = le32_to_cpu(ucode->ver);
5980
inst_size = le32_to_cpu(ucode->inst_size);
5981
data_size = le32_to_cpu(ucode->data_size);
5982
init_size = le32_to_cpu(ucode->init_size);
5983
init_data_size = le32_to_cpu(ucode->init_data_size);
5984
boot_size = le32_to_cpu(ucode->boot_size);
5986
IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
5987
IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", inst_size);
5988
IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", data_size);
5989
IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", init_size);
5990
IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", init_data_size);
5991
IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", boot_size);
5993
/* Verify size of file vs. image size info in file's header */
5994
if (ucode_raw->size < sizeof(*ucode) +
5995
inst_size + data_size + init_size +
5996
init_data_size + boot_size) {
5998
IWL_DEBUG_INFO("uCode file size %d too small\n",
5999
(int)ucode_raw->size);
6004
/* Verify that uCode images will fit in card's SRAM */
6005
if (inst_size > IWL_MAX_INST_SIZE) {
6006
IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
6012
if (data_size > IWL_MAX_DATA_SIZE) {
6013
IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
6018
if (init_size > IWL_MAX_INST_SIZE) {
6019
IWL_DEBUG_INFO("uCode init instr len %d too large to fit in\n",
6024
if (init_data_size > IWL_MAX_DATA_SIZE) {
6025
IWL_DEBUG_INFO("uCode init data len %d too large to fit in\n",
6030
if (boot_size > IWL_MAX_BSM_SIZE) {
6031
IWL_DEBUG_INFO("uCode boot instr len %d too large to fit in\n",
6037
/* Allocate ucode buffers for card's bus-master loading ... */
6039
/* Runtime instructions and 2 copies of data:
6040
* 1) unmodified from disk
6041
* 2) backup cache for save/restore during power-downs */
6042
priv->ucode_code.len = inst_size;
6043
iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
6045
priv->ucode_data.len = data_size;
6046
iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
6048
priv->ucode_data_backup.len = data_size;
6049
iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
6051
if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
6052
!priv->ucode_data_backup.v_addr)
6055
/* Initialization instructions and data */
6056
if (init_size && init_data_size) {
6057
priv->ucode_init.len = init_size;
6058
iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
6060
priv->ucode_init_data.len = init_data_size;
6061
iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
6063
if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
6067
/* Bootstrap (instructions only, no data) */
6069
priv->ucode_boot.len = boot_size;
6070
iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
6072
if (!priv->ucode_boot.v_addr)
6076
/* Copy images into buffers for card's bus-master reads ... */
6078
/* Runtime instructions (first block of data in file) */
6079
src = &ucode->data[0];
6080
len = priv->ucode_code.len;
6081
IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
6082
memcpy(priv->ucode_code.v_addr, src, len);
6083
IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
6084
priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
6086
/* Runtime data (2nd block)
6087
* NOTE: Copy into backup buffer will be done in iwl3945_up() */
6088
src = &ucode->data[inst_size];
6089
len = priv->ucode_data.len;
6090
IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
6091
memcpy(priv->ucode_data.v_addr, src, len);
6092
memcpy(priv->ucode_data_backup.v_addr, src, len);
6094
/* Initialization instructions (3rd block) */
6096
src = &ucode->data[inst_size + data_size];
6097
len = priv->ucode_init.len;
6098
IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
6100
memcpy(priv->ucode_init.v_addr, src, len);
6103
/* Initialization data (4th block) */
6104
if (init_data_size) {
6105
src = &ucode->data[inst_size + data_size + init_size];
6106
len = priv->ucode_init_data.len;
6107
IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n",
6109
memcpy(priv->ucode_init_data.v_addr, src, len);
6112
/* Bootstrap instructions (5th block) */
6113
src = &ucode->data[inst_size + data_size + init_size + init_data_size];
6114
len = priv->ucode_boot.len;
6115
IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n",
6117
memcpy(priv->ucode_boot.v_addr, src, len);
6119
/* We have our copies now, allow OS release its copies */
6120
release_firmware(ucode_raw);
6124
IWL_ERROR("failed to allocate pci memory\n");
6126
iwl3945_dealloc_ucode_pci(priv);
6129
release_firmware(ucode_raw);
6137
* iwl3945_set_ucode_ptrs - Set uCode address location
6139
* Tell initialization uCode where to find runtime uCode.
6141
* BSM registers initially contain pointers to initialization uCode.
6142
* We need to replace them to load runtime uCode inst and data,
6143
* and to save runtime data when powering down.
6145
static int iwl3945_set_ucode_ptrs(struct iwl3945_priv *priv)
6150
unsigned long flags;
6152
/* bits 31:0 for 3945 */
6153
pinst = priv->ucode_code.p_addr;
6154
pdata = priv->ucode_data_backup.p_addr;
6156
spin_lock_irqsave(&priv->lock, flags);
6157
rc = iwl3945_grab_nic_access(priv);
6159
spin_unlock_irqrestore(&priv->lock, flags);
6163
/* Tell bootstrap uCode where to find image to load */
6164
iwl3945_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
6165
iwl3945_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
6166
iwl3945_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
6167
priv->ucode_data.len);
6169
/* Inst bytecount must be last to set up, bit 31 signals uCode
6170
* that all new ptr/size info is in place */
6171
iwl3945_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
6172
priv->ucode_code.len | BSM_DRAM_INST_LOAD);
6174
iwl3945_release_nic_access(priv);
6176
spin_unlock_irqrestore(&priv->lock, flags);
6178
IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
6184
* iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
6186
* Called after REPLY_ALIVE notification received from "initialize" uCode.
6188
* Tell "initialize" uCode to go ahead and load the runtime uCode.
6190
static void iwl3945_init_alive_start(struct iwl3945_priv *priv)
6192
/* Check alive response for "valid" sign from uCode */
6193
if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
6194
/* We had an error bringing up the hardware, so take it
6195
* all the way back down so we can try again */
6196
IWL_DEBUG_INFO("Initialize Alive failed.\n");
6200
/* Bootstrap uCode has loaded initialize uCode ... verify inst image.
6201
* This is a paranoid check, because we would not have gotten the
6202
* "initialize" alive if code weren't properly loaded. */
6203
if (iwl3945_verify_ucode(priv)) {
6204
/* Runtime instruction load was bad;
6205
* take it all the way back down so we can try again */
6206
IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
6210
/* Send pointers to protocol/runtime uCode image ... init code will
6211
* load and launch runtime uCode, which will send us another "Alive"
6213
IWL_DEBUG_INFO("Initialization Alive received.\n");
6214
if (iwl3945_set_ucode_ptrs(priv)) {
6215
/* Runtime instruction load won't happen;
6216
* take it all the way back down so we can try again */
6217
IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
6223
queue_work(priv->workqueue, &priv->restart);
6228
* iwl3945_alive_start - called after REPLY_ALIVE notification received
6229
* from protocol/runtime uCode (initialization uCode's
6230
* Alive gets handled by iwl3945_init_alive_start()).
6232
static void iwl3945_alive_start(struct iwl3945_priv *priv)
6235
int thermal_spin = 0;
6238
IWL_DEBUG_INFO("Runtime Alive received.\n");
6240
if (priv->card_alive.is_valid != UCODE_VALID_OK) {
6241
/* We had an error bringing up the hardware, so take it
6242
* all the way back down so we can try again */
6243
IWL_DEBUG_INFO("Alive failed.\n");
6247
/* Initialize uCode has loaded Runtime uCode ... verify inst image.
6248
* This is a paranoid check, because we would not have gotten the
6249
* "runtime" alive if code weren't properly loaded. */
6250
if (iwl3945_verify_ucode(priv)) {
6251
/* Runtime instruction load was bad;
6252
* take it all the way back down so we can try again */
6253
IWL_DEBUG_INFO("Bad runtime uCode load.\n");
6257
iwl3945_clear_stations_table(priv);
6259
rc = iwl3945_grab_nic_access(priv);
6261
IWL_WARNING("Can not read rfkill status from adapter\n");
6265
rfkill = iwl3945_read_prph(priv, APMG_RFKILL_REG);
6266
IWL_DEBUG_INFO("RFKILL status: 0x%x\n", rfkill);
6267
iwl3945_release_nic_access(priv);
6270
clear_bit(STATUS_RF_KILL_HW, &priv->status);
6271
/* if rfkill is not on, then wait for thermal
6272
* sensor in adapter to kick in */
6273
while (iwl3945_hw_get_temperature(priv) == 0) {
6279
IWL_DEBUG_INFO("Thermal calibration took %dus\n",
6282
set_bit(STATUS_RF_KILL_HW, &priv->status);
6284
/* After the ALIVE response, we can send commands to 3945 uCode */
6285
set_bit(STATUS_ALIVE, &priv->status);
6287
/* Clear out the uCode error bit if it is set */
6288
clear_bit(STATUS_FW_ERROR, &priv->status);
6290
rc = iwl3945_init_channel_map(priv);
6292
IWL_ERROR("initializing regulatory failed: %d\n", rc);
6296
iwl3945_init_geos(priv);
6297
iwl3945_reset_channel_flag(priv);
6299
if (iwl3945_is_rfkill(priv))
6302
iwlwifi_ieee80211_start_queues(priv->hw);
6304
priv->active_rate = priv->rates_mask;
6305
priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
6307
iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode));
6309
if (iwl3945_is_associated(priv)) {
6310
struct iwl3945_rxon_cmd *active_rxon =
6311
(struct iwl3945_rxon_cmd *)(&priv->active_rxon);
6313
memcpy(&priv->staging_rxon, &priv->active_rxon,
6314
sizeof(priv->staging_rxon));
6315
active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
6317
/* Initialize our rx_config data */
6318
iwl3945_connection_init_rx_config(priv);
6319
memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
6322
/* Configure Bluetooth device coexistence support */
6323
iwl3945_send_bt_config(priv);
6325
/* Configure the adapter for unassociated operation */
6326
iwl3945_commit_rxon(priv);
6328
/* At this point, the NIC is initialized and operational */
6329
priv->notif_missed_beacons = 0;
6330
set_bit(STATUS_READY, &priv->status);
6332
iwl3945_reg_txpower_periodic(priv);
6334
iwl3945_led_register(priv);
6336
IWL_DEBUG_INFO("ALIVE processing complete.\n");
6337
wake_up_interruptible(&priv->wait_command_queue);
6339
if (priv->error_recovering)
6340
iwl3945_error_recovery(priv);
6345
queue_work(priv->workqueue, &priv->restart);
6348
static void iwl3945_cancel_deferred_work(struct iwl3945_priv *priv);
6350
static void __iwl3945_down(struct iwl3945_priv *priv)
6352
unsigned long flags;
6353
int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
6354
struct ieee80211_conf *conf = NULL;
6356
IWL_DEBUG_INFO(DRV_NAME " is going down\n");
6358
conf = ieee80211_get_hw_conf(priv->hw);
6361
set_bit(STATUS_EXIT_PENDING, &priv->status);
6363
iwl3945_led_unregister(priv);
6364
iwl3945_clear_stations_table(priv);
6366
/* Unblock any waiting calls */
6367
wake_up_interruptible_all(&priv->wait_command_queue);
6369
/* Wipe out the EXIT_PENDING status bit if we are not actually
6370
* exiting the module */
6372
clear_bit(STATUS_EXIT_PENDING, &priv->status);
6374
/* stop and reset the on-board processor */
6375
iwl3945_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
6377
/* tell the device to stop sending interrupts */
6378
iwl3945_disable_interrupts(priv);
6380
if (priv->mac80211_registered)
6381
iwlwifi_iwlwifi_ieee80211_stop_queues(priv->hw);
6383
/* If we have not previously called iwl3945_init() then
6384
* clear all bits but the RF Kill and SUSPEND bits and return */
6385
if (!iwl3945_is_init(priv)) {
6386
priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
6388
test_bit(STATUS_RF_KILL_SW, &priv->status) <<
6390
test_bit(STATUS_IN_SUSPEND, &priv->status) <<
6395
/* ...otherwise clear out all the status bits but the RF Kill and
6396
* SUSPEND bits and continue taking the NIC down. */
6397
priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
6399
test_bit(STATUS_RF_KILL_SW, &priv->status) <<
6401
test_bit(STATUS_IN_SUSPEND, &priv->status) <<
6403
test_bit(STATUS_FW_ERROR, &priv->status) <<
6406
spin_lock_irqsave(&priv->lock, flags);
6407
iwl3945_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
6408
spin_unlock_irqrestore(&priv->lock, flags);
6410
iwl3945_hw_txq_ctx_stop(priv);
6411
iwl3945_hw_rxq_stop(priv);
6413
spin_lock_irqsave(&priv->lock, flags);
6414
if (!iwl3945_grab_nic_access(priv)) {
6415
iwl3945_write_prph(priv, APMG_CLK_DIS_REG,
6416
APMG_CLK_VAL_DMA_CLK_RQT);
6417
iwl3945_release_nic_access(priv);
6419
spin_unlock_irqrestore(&priv->lock, flags);
6423
iwl3945_hw_nic_stop_master(priv);
6424
iwl3945_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
6425
iwl3945_hw_nic_reset(priv);
6428
memset(&priv->card_alive, 0, sizeof(struct iwl3945_alive_resp));
6430
if (priv->ibss_beacon)
6431
dev_kfree_skb(priv->ibss_beacon);
6432
priv->ibss_beacon = NULL;
6434
/* clear out any free frames */
6435
iwl3945_clear_free_frames(priv);
6438
static void iwl3945_down(struct iwl3945_priv *priv)
6440
mutex_lock(&priv->mutex);
6441
__iwl3945_down(priv);
6442
mutex_unlock(&priv->mutex);
6444
iwl3945_cancel_deferred_work(priv);
6447
#define MAX_HW_RESTARTS 5
6449
static int __iwl3945_up(struct iwl3945_priv *priv)
6453
if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
6454
IWL_WARNING("Exit pending; will not bring the NIC up\n");
6458
if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
6459
IWL_WARNING("Radio disabled by SW RF kill (module "
6464
/* If platform's RF_KILL switch is NOT set to KILL */
6465
if (iwl3945_read32(priv, CSR_GP_CNTRL) &
6466
CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
6467
clear_bit(STATUS_RF_KILL_HW, &priv->status);
6469
set_bit(STATUS_RF_KILL_HW, &priv->status);
6470
if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
6471
IWL_WARNING("Radio disabled by HW RF Kill switch\n");
6476
iwl3945_write32(priv, CSR_INT, 0xFFFFFFFF);
6478
rc = iwl3945_hw_nic_init(priv);
6480
IWL_ERROR("Unable to int nic\n");
6484
/* make sure rfkill handshake bits are cleared */
6485
iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
6486
iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR,
6487
CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
6489
/* clear (again), then enable host interrupts */
6490
iwl3945_write32(priv, CSR_INT, 0xFFFFFFFF);
6491
iwl3945_enable_interrupts(priv);
6493
/* really make sure rfkill handshake bits are cleared */
6494
iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
6495
iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
6497
/* Copy original ucode data image from disk into backup cache.
6498
* This will be used to initialize the on-board processor's
6499
* data SRAM for a clean start when the runtime program first loads. */
6500
memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
6501
priv->ucode_data.len);
6503
/* We return success when we resume from suspend and rf_kill is on. */
6504
if (test_bit(STATUS_RF_KILL_HW, &priv->status))
6507
for (i = 0; i < MAX_HW_RESTARTS; i++) {
6509
iwl3945_clear_stations_table(priv);
6511
/* load bootstrap state machine,
6512
* load bootstrap program into processor's memory,
6513
* prepare to load the "initialize" uCode */
6514
rc = iwl3945_load_bsm(priv);
6517
IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc);
6521
/* start card; "initialize" will load runtime ucode */
6522
iwl3945_nic_start(priv);
6524
IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
6529
set_bit(STATUS_EXIT_PENDING, &priv->status);
6530
__iwl3945_down(priv);
6532
/* tried to restart and config the device for as long as our
6533
* patience could withstand */
6534
IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
6539
/*****************************************************************************
6541
* Workqueue callbacks
6543
*****************************************************************************/
6545
static void iwl3945_bg_init_alive_start(struct work_struct *data)
6547
struct iwl3945_priv *priv =
6548
container_of(data, struct iwl3945_priv, init_alive_start.work);
6550
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6553
mutex_lock(&priv->mutex);
6554
iwl3945_init_alive_start(priv);
6555
mutex_unlock(&priv->mutex);
6558
static void iwl3945_bg_alive_start(struct work_struct *data)
6560
struct iwl3945_priv *priv =
6561
container_of(data, struct iwl3945_priv, alive_start.work);
6563
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6566
mutex_lock(&priv->mutex);
6567
iwl3945_alive_start(priv);
6568
mutex_unlock(&priv->mutex);
6571
static void iwl3945_bg_rf_kill(struct work_struct *work)
6573
struct iwl3945_priv *priv = container_of(work, struct iwl3945_priv, rf_kill);
6575
wake_up_interruptible(&priv->wait_command_queue);
6577
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6580
mutex_lock(&priv->mutex);
6582
if (!iwl3945_is_rfkill(priv)) {
6583
IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL,
6584
"HW and/or SW RF Kill no longer active, restarting "
6586
if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
6587
queue_work(priv->workqueue, &priv->restart);
6590
if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
6591
IWL_DEBUG_RF_KILL("Can not turn radio back on - "
6592
"disabled by SW switch\n");
6594
IWL_WARNING("Radio Frequency Kill Switch is On:\n"
6595
"Kill switch must be turned off for "
6596
"wireless networking to work.\n");
6598
mutex_unlock(&priv->mutex);
6601
#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
6603
static void iwl3945_bg_scan_check(struct work_struct *data)
6605
struct iwl3945_priv *priv =
6606
container_of(data, struct iwl3945_priv, scan_check.work);
6608
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6611
mutex_lock(&priv->mutex);
6612
if (test_bit(STATUS_SCANNING, &priv->status) ||
6613
test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
6614
IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN,
6615
"Scan completion watchdog resetting adapter (%dms)\n",
6616
jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG));
6618
if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
6619
iwl3945_send_scan_abort(priv);
6621
mutex_unlock(&priv->mutex);
6624
static void iwl3945_bg_request_scan(struct work_struct *data)
6626
struct iwl3945_priv *priv =
6627
container_of(data, struct iwl3945_priv, request_scan);
6628
struct iwl3945_host_cmd cmd = {
6629
.id = REPLY_SCAN_CMD,
6630
.len = sizeof(struct iwl3945_scan_cmd),
6631
.meta.flags = CMD_SIZE_HUGE,
6634
struct iwl3945_scan_cmd *scan;
6635
struct ieee80211_conf *conf = NULL;
6639
conf = ieee80211_get_hw_conf(priv->hw);
6641
mutex_lock(&priv->mutex);
6643
if (!iwl3945_is_ready(priv)) {
6644
IWL_WARNING("request scan called when driver not ready.\n");
6648
/* Make sure the scan wasn't cancelled before this queued work
6649
* was given the chance to run... */
6650
if (!test_bit(STATUS_SCANNING, &priv->status))
6653
/* This should never be called or scheduled if there is currently
6654
* a scan active in the hardware. */
6655
if (test_bit(STATUS_SCAN_HW, &priv->status)) {
6656
IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
6657
"Ignoring second request.\n");
6662
if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
6663
IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
6667
if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
6668
IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6672
if (iwl3945_is_rfkill(priv)) {
6673
IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6677
if (!test_bit(STATUS_READY, &priv->status)) {
6678
IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
6682
if (!priv->scan_bands) {
6683
IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
6688
priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
6689
IWL_MAX_SCAN_SIZE, GFP_KERNEL);
6696
memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
6698
scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
6699
scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
6701
if (iwl3945_is_associated(priv)) {
6704
u32 suspend_time = 100;
6705
u32 scan_suspend_time = 100;
6706
unsigned long flags;
6708
IWL_DEBUG_INFO("Scanning while associated...\n");
6710
spin_lock_irqsave(&priv->lock, flags);
6711
interval = priv->beacon_int;
6712
spin_unlock_irqrestore(&priv->lock, flags);
6714
scan->suspend_time = 0;
6715
scan->max_out_time = cpu_to_le32(200 * 1024);
6717
interval = suspend_time;
6719
* suspend time format:
6720
* 0-19: beacon interval in usec (time before exec.)
6722
* 24-31: number of beacons (suspend between channels)
6725
extra = (suspend_time / interval) << 24;
6726
scan_suspend_time = 0xFF0FFFFF &
6727
(extra | ((suspend_time % interval) * 1024));
6729
scan->suspend_time = cpu_to_le32(scan_suspend_time);
6730
IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
6731
scan_suspend_time, interval);
6734
/* We should add the ability for user to lock to PASSIVE ONLY */
6735
if (priv->one_direct_scan) {
6737
("Kicking off one direct scan for '%s'\n",
6738
iwl3945_escape_essid(priv->direct_ssid,
6739
priv->direct_ssid_len));
6740
scan->direct_scan[0].id = WLAN_EID_SSID;
6741
scan->direct_scan[0].len = priv->direct_ssid_len;
6742
memcpy(scan->direct_scan[0].ssid,
6743
priv->direct_ssid, priv->direct_ssid_len);
6745
} else if (!iwl3945_is_associated(priv) && priv->essid_len) {
6746
scan->direct_scan[0].id = WLAN_EID_SSID;
6747
scan->direct_scan[0].len = priv->essid_len;
6748
memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
6753
/* We don't build a direct scan probe request; the uCode will do
6754
* that based on the direct_mask added to each channel entry */
6755
scan->tx_cmd.len = cpu_to_le16(
6756
iwl3945_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data,
6757
IWL_MAX_SCAN_SIZE - sizeof(scan), 0));
6758
scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
6759
scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id;
6760
scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
6762
/* flags + rate selection */
6764
switch (priv->scan_bands) {
6766
scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
6767
scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
6768
scan->good_CRC_th = 0;
6769
phymode = MODE_IEEE80211G;
6773
scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
6774
scan->good_CRC_th = IWL_GOOD_CRC_TH;
6775
phymode = MODE_IEEE80211A;
6779
IWL_WARNING("Invalid scan band count\n");
6783
/* select Rx antennas */
6784
scan->flags |= iwl3945_get_antenna_flags(priv);
6786
if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR)
6787
scan->filter_flags = RXON_FILTER_PROMISC_MSK;
6791
("Initiating direct scan for %s.\n",
6792
iwl3945_escape_essid(priv->essid, priv->essid_len));
6794
IWL_DEBUG_SCAN("Initiating indirect scan.\n");
6796
scan->channel_count =
6797
iwl3945_get_channels_for_scan(
6798
priv, phymode, 1, /* active */
6800
(void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
6802
cmd.len += le16_to_cpu(scan->tx_cmd.len) +
6803
scan->channel_count * sizeof(struct iwl3945_scan_channel);
6805
scan->len = cpu_to_le16(cmd.len);
6807
set_bit(STATUS_SCAN_HW, &priv->status);
6808
rc = iwl3945_send_cmd_sync(priv, &cmd);
6812
queue_delayed_work(priv->workqueue, &priv->scan_check,
6813
IWL_SCAN_CHECK_WATCHDOG);
6815
mutex_unlock(&priv->mutex);
6819
/* inform mac80211 scan aborted */
6820
queue_work(priv->workqueue, &priv->scan_completed);
6821
mutex_unlock(&priv->mutex);
6824
static void iwl3945_bg_up(struct work_struct *data)
6826
struct iwl3945_priv *priv = container_of(data, struct iwl3945_priv, up);
6828
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6831
mutex_lock(&priv->mutex);
6833
mutex_unlock(&priv->mutex);
6836
static void iwl3945_bg_restart(struct work_struct *data)
6838
struct iwl3945_priv *priv = container_of(data, struct iwl3945_priv, restart);
6840
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6844
queue_work(priv->workqueue, &priv->up);
6847
static void iwl3945_bg_rx_replenish(struct work_struct *data)
6849
struct iwl3945_priv *priv =
6850
container_of(data, struct iwl3945_priv, rx_replenish);
6852
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6855
mutex_lock(&priv->mutex);
6856
iwl3945_rx_replenish(priv);
6857
mutex_unlock(&priv->mutex);
6860
#define IWL_DELAY_NEXT_SCAN (HZ*2)
6862
static void iwl3945_bg_post_associate(struct work_struct *data)
6864
struct iwl3945_priv *priv = container_of(data, struct iwl3945_priv,
6865
post_associate.work);
6868
struct ieee80211_conf *conf = NULL;
6870
if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
6871
IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__);
6876
IWL_DEBUG_ASSOC("Associated as %d to: " MAC_FMT "\n",
6877
priv->assoc_id, MAC_ARG(priv->active_rxon.bssid_addr));
6879
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6882
mutex_lock(&priv->mutex);
6884
if (!priv->interface_id || !priv->is_open) {
6885
mutex_unlock(&priv->mutex);
6888
iwl3945_scan_cancel_timeout(priv, 200);
6890
conf = ieee80211_get_hw_conf(priv->hw);
6892
priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
6893
iwl3945_commit_rxon(priv);
6895
memset(&priv->rxon_timing, 0, sizeof(struct iwl3945_rxon_time_cmd));
6896
iwl3945_setup_rxon_timing(priv);
6897
rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING,
6898
sizeof(priv->rxon_timing), &priv->rxon_timing);
6900
IWL_WARNING("REPLY_RXON_TIMING failed - "
6901
"Attempting to continue.\n");
6903
priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
6905
priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
6907
IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
6908
priv->assoc_id, priv->beacon_int);
6910
if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
6911
priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
6913
priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
6915
if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
6916
if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
6917
priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
6919
priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
6921
if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
6922
priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
6926
iwl3945_commit_rxon(priv);
6928
switch (priv->iw_mode) {
6929
case IEEE80211_IF_TYPE_STA:
6930
iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
6933
case IEEE80211_IF_TYPE_IBSS:
6935
/* clear out the station table */
6936
iwl3945_clear_stations_table(priv);
6938
iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0);
6939
iwl3945_add_station(priv, priv->bssid, 0, 0);
6940
iwl3945_sync_sta(priv, IWL_STA_ID,
6941
(priv->phymode == MODE_IEEE80211A)?
6942
IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
6944
iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
6945
iwl3945_send_beacon_cmd(priv);
6950
IWL_ERROR("%s Should not be called in %d mode\n",
6951
__FUNCTION__, priv->iw_mode);
6955
iwl3945_sequence_reset(priv);
6957
#ifdef CONFIG_IWL3945_QOS
6958
iwl3945_activate_qos(priv, 0);
6959
#endif /* CONFIG_IWL3945_QOS */
6960
/* we have just associated, don't start scan too early */
6961
priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
6962
mutex_unlock(&priv->mutex);
6965
static void iwl3945_bg_abort_scan(struct work_struct *work)
6967
struct iwl3945_priv *priv = container_of(work, struct iwl3945_priv, abort_scan);
6969
if (!iwl3945_is_ready(priv))
6972
mutex_lock(&priv->mutex);
6974
set_bit(STATUS_SCAN_ABORTING, &priv->status);
6975
iwl3945_send_scan_abort(priv);
6977
mutex_unlock(&priv->mutex);
6980
static int iwl3945_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
6982
static void iwl3945_bg_scan_completed(struct work_struct *work)
6984
struct iwl3945_priv *priv =
6985
container_of(work, struct iwl3945_priv, scan_completed);
6987
IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n");
6989
if (test_bit(STATUS_EXIT_PENDING, &priv->status))
6992
if (test_bit(STATUS_CONF_PENDING, &priv->status))
6993
iwl3945_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw));
6995
iwlwifi_ieee80211_scan_completed(priv->hw);
6997
/* Since setting the TXPOWER may have been deferred while
6998
* performing the scan, fire one off */
6999
mutex_lock(&priv->mutex);
7000
iwl3945_hw_reg_send_txpower(priv);
7001
mutex_unlock(&priv->mutex);
7004
/*****************************************************************************
7006
* mac80211 entry point functions
7008
*****************************************************************************/
7010
#define UCODE_READY_TIMEOUT (2 * HZ)
7012
static int iwl3945_mac_open(struct ieee80211_hw *hw)
7014
struct iwl3945_priv *priv = hw->priv;
7017
IWL_DEBUG_MAC80211("enter\n");
7019
if (pci_enable_device(priv->pci_dev)) {
7020
IWL_ERROR("Fail to pci_enable_device\n");
7023
pci_restore_state(priv->pci_dev);
7024
pci_enable_msi(priv->pci_dev);
7026
ret = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED,
7029
IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq);
7030
goto out_disable_msi;
7033
/* we should be verifying the device is ready to be opened */
7034
mutex_lock(&priv->mutex);
7036
memset(&priv->staging_rxon, 0, sizeof(struct iwl3945_rxon_cmd));
7037
/* fetch ucode file from disk, alloc and copy to bus-master buffers ...
7038
* ucode filename and max sizes are card-specific. */
7040
if (!priv->ucode_code.len) {
7041
ret = iwl3945_read_ucode(priv);
7043
IWL_ERROR("Could not read microcode: %d\n", ret);
7044
mutex_unlock(&priv->mutex);
7045
goto out_release_irq;
7049
ret = __iwl3945_up(priv);
7051
mutex_unlock(&priv->mutex);
7054
goto out_release_irq;
7056
IWL_DEBUG_INFO("Start UP work.\n");
7058
if (test_bit(STATUS_IN_SUSPEND, &priv->status))
7061
/* Wait for START_ALIVE from ucode. Otherwise callbacks from
7062
* mac80211 will not be run successfully. */
7063
ret = wait_event_interruptible_timeout(priv->wait_command_queue,
7064
test_bit(STATUS_READY, &priv->status),
7065
UCODE_READY_TIMEOUT);
7067
if (!test_bit(STATUS_READY, &priv->status)) {
7068
IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n",
7069
jiffies_to_msecs(UCODE_READY_TIMEOUT));
7071
goto out_release_irq;
7076
IWL_DEBUG_MAC80211("leave\n");
7080
free_irq(priv->pci_dev->irq, priv);
7082
pci_disable_msi(priv->pci_dev);
7083
pci_disable_device(priv->pci_dev);
7085
IWL_DEBUG_MAC80211("leave - failed\n");
7089
static int iwl3945_mac_stop(struct ieee80211_hw *hw)
7091
struct iwl3945_priv *priv = hw->priv;
7093
IWL_DEBUG_MAC80211("enter\n");
7095
if (!priv->is_open) {
7096
IWL_DEBUG_MAC80211("leave - skip\n");
7102
if (iwl3945_is_ready_rf(priv)) {
7103
/* stop mac, cancel any scan request and clear
7104
* RXON_FILTER_ASSOC_MSK BIT
7106
mutex_lock(&priv->mutex);
7107
iwl3945_scan_cancel_timeout(priv, 100);
7108
cancel_delayed_work(&priv->post_associate);
7109
mutex_unlock(&priv->mutex);
7114
flush_workqueue(priv->workqueue);
7115
free_irq(priv->pci_dev->irq, priv);
7116
pci_disable_msi(priv->pci_dev);
7117
pci_save_state(priv->pci_dev);
7118
pci_disable_device(priv->pci_dev);
7120
IWL_DEBUG_MAC80211("leave\n");
7125
static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
7126
struct ieee80211_tx_control *ctl)
7128
struct iwl3945_priv *priv = hw->priv;
7130
IWL_DEBUG_MAC80211("enter\n");
7132
if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
7133
IWL_DEBUG_MAC80211("leave - monitor\n");
7137
IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
7140
if (iwl3945_tx_skb(priv, skb, ctl))
7141
dev_kfree_skb_any(skb);
7143
IWL_DEBUG_MAC80211("leave\n");
7147
static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
7148
struct ieee80211_if_init_conf *conf)
7150
struct iwl3945_priv *priv = hw->priv;
7151
unsigned long flags;
7153
IWL_DEBUG_MAC80211("enter: id %d, type %d\n", conf->if_id, conf->type);
7155
if (priv->interface_id) {
7156
IWL_DEBUG_MAC80211("leave - interface_id != 0\n");
7160
spin_lock_irqsave(&priv->lock, flags);
7161
priv->interface_id = conf->if_id;
7163
spin_unlock_irqrestore(&priv->lock, flags);
7165
mutex_lock(&priv->mutex);
7167
if (conf->mac_addr) {
7168
IWL_DEBUG_MAC80211("Set: " MAC_FMT "\n", MAC_ARG(conf->mac_addr));
7169
memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
7172
if (iwl3945_is_ready(priv))
7173
iwl3945_set_mode(priv, conf->type);
7175
mutex_unlock(&priv->mutex);
7177
IWL_DEBUG_MAC80211("leave\n");
7182
* iwl3945_mac_config - mac80211 config callback
7184
* We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
7185
* be set inappropriately and the driver currently sets the hardware up to
7186
* use it whenever needed.
7188
static int iwl3945_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
7190
struct iwl3945_priv *priv = hw->priv;
7191
const struct iwl3945_channel_info *ch_info;
7192
unsigned long flags;
7195
mutex_lock(&priv->mutex);
7196
IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel);
7198
if (!iwl3945_is_ready(priv)) {
7199
IWL_DEBUG_MAC80211("leave - not ready\n");
7204
/* TODO: Figure out how to get ieee80211_local->sta_scanning w/ only
7205
* what is exposed through include/ declarations */
7206
if (unlikely(!iwl3945_param_disable_hw_scan &&
7207
test_bit(STATUS_SCANNING, &priv->status))) {
7208
IWL_DEBUG_MAC80211("leave - scanning\n");
7209
set_bit(STATUS_CONF_PENDING, &priv->status);
7210
mutex_unlock(&priv->mutex);
7214
spin_lock_irqsave(&priv->lock, flags);
7216
ch_info = iwl3945_get_channel_info(priv, conf->phymode, conf->channel);
7217
if (!is_channel_valid(ch_info)) {
7218
IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n",
7219
conf->channel, conf->phymode);
7220
IWL_DEBUG_MAC80211("leave - invalid channel\n");
7221
spin_unlock_irqrestore(&priv->lock, flags);
7226
iwl3945_set_rxon_channel(priv, conf->phymode, conf->channel);
7228
iwl3945_set_flags_for_phymode(priv, conf->phymode);
7230
/* The list of supported rates and rate mask can be different
7231
* for each phymode; since the phymode may have changed, reset
7232
* the rate mask to what mac80211 lists */
7233
iwl3945_set_rate(priv);
7235
spin_unlock_irqrestore(&priv->lock, flags);
7237
#ifdef IEEE80211_CONF_CHANNEL_SWITCH
7238
if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
7239
iwl3945_hw_channel_switch(priv, conf->channel);
7244
iwl3945_radio_kill_sw(priv, !conf->radio_enabled);
7246
if (!conf->radio_enabled) {
7247
IWL_DEBUG_MAC80211("leave - radio disabled\n");
7251
if (iwl3945_is_rfkill(priv)) {
7252
IWL_DEBUG_MAC80211("leave - RF kill\n");
7257
iwl3945_set_rate(priv);
7259
if (memcmp(&priv->active_rxon,
7260
&priv->staging_rxon, sizeof(priv->staging_rxon)))
7261
iwl3945_commit_rxon(priv);
7263
IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
7265
IWL_DEBUG_MAC80211("leave\n");
7268
clear_bit(STATUS_CONF_PENDING, &priv->status);
7269
mutex_unlock(&priv->mutex);
7273
static void iwl3945_config_ap(struct iwl3945_priv *priv)
7277
if (priv->status & STATUS_EXIT_PENDING)
7280
/* The following should be done only at AP bring up */
7281
if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) {
7283
/* RXON - unassoc (to set timing command) */
7284
priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7285
iwl3945_commit_rxon(priv);
7288
memset(&priv->rxon_timing, 0, sizeof(struct iwl3945_rxon_time_cmd));
7289
iwl3945_setup_rxon_timing(priv);
7290
rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING,
7291
sizeof(priv->rxon_timing), &priv->rxon_timing);
7293
IWL_WARNING("REPLY_RXON_TIMING failed - "
7294
"Attempting to continue.\n");
7296
/* FIXME: what should be the assoc_id for AP? */
7297
priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
7298
if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7299
priv->staging_rxon.flags |=
7300
RXON_FLG_SHORT_PREAMBLE_MSK;
7302
priv->staging_rxon.flags &=
7303
~RXON_FLG_SHORT_PREAMBLE_MSK;
7305
if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
7306
if (priv->assoc_capability &
7307
WLAN_CAPABILITY_SHORT_SLOT_TIME)
7308
priv->staging_rxon.flags |=
7309
RXON_FLG_SHORT_SLOT_MSK;
7311
priv->staging_rxon.flags &=
7312
~RXON_FLG_SHORT_SLOT_MSK;
7314
if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
7315
priv->staging_rxon.flags &=
7316
~RXON_FLG_SHORT_SLOT_MSK;
7318
/* restore RXON assoc */
7319
priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
7320
iwl3945_commit_rxon(priv);
7321
iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0);
7323
iwl3945_send_beacon_cmd(priv);
7325
/* FIXME - we need to add code here to detect a totally new
7326
* configuration, reset the AP, unassoc, rxon timing, assoc,
7327
* clear sta table, add BCAST sta... */
7330
static int iwl3945_mac_config_interface(struct ieee80211_hw *hw, int if_id,
7331
struct ieee80211_if_conf *conf)
7333
struct iwl3945_priv *priv = hw->priv;
7334
unsigned long flags;
7340
if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
7341
(!conf->beacon || !conf->ssid_len)) {
7343
("Leaving in AP mode because HostAPD is not ready.\n");
7347
if (!iwl3945_is_alive(priv))
7350
mutex_lock(&priv->mutex);
7352
IWL_DEBUG_MAC80211("enter: interface id %d\n", if_id);
7354
IWL_DEBUG_MAC80211("bssid: " MAC_FMT "\n",
7355
MAC_ARG(conf->bssid));
7357
if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
7358
!(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
7359
IWL_DEBUG_MAC80211("leave - scanning\n");
7360
mutex_unlock(&priv->mutex);
7364
if (priv->interface_id != if_id) {
7365
IWL_DEBUG_MAC80211("leave - interface_id != if_id\n");
7366
mutex_unlock(&priv->mutex);
7370
if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
7372
conf->bssid = priv->mac_addr;
7373
memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
7374
IWL_DEBUG_MAC80211("bssid was set to: " MAC_FMT "\n",
7375
MAC_ARG(conf->bssid));
7377
if (priv->ibss_beacon)
7378
dev_kfree_skb(priv->ibss_beacon);
7380
priv->ibss_beacon = conf->beacon;
7383
if (iwl3945_is_rfkill(priv))
7386
if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
7387
!is_multicast_ether_addr(conf->bssid)) {
7388
/* If there is currently a HW scan going on in the background
7389
* then we need to cancel it else the RXON below will fail. */
7390
if (iwl3945_scan_cancel_timeout(priv, 100)) {
7391
IWL_WARNING("Aborted scan still in progress "
7393
IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
7394
mutex_unlock(&priv->mutex);
7397
memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
7399
/* TODO: Audit driver for usage of these members and see
7400
* if mac80211 deprecates them (priv->bssid looks like it
7401
* shouldn't be there, but I haven't scanned the IBSS code
7402
* to verify) - jpk */
7403
memcpy(priv->bssid, conf->bssid, ETH_ALEN);
7405
if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
7406
iwl3945_config_ap(priv);
7408
rc = iwl3945_commit_rxon(priv);
7409
if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
7410
iwl3945_add_station(priv,
7411
priv->active_rxon.bssid_addr, 1, 0);
7415
iwl3945_scan_cancel_timeout(priv, 100);
7416
priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7417
iwl3945_commit_rxon(priv);
7421
spin_lock_irqsave(&priv->lock, flags);
7422
if (!conf->ssid_len)
7423
memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
7425
memcpy(priv->essid, conf->ssid, conf->ssid_len);
7427
priv->essid_len = conf->ssid_len;
7428
spin_unlock_irqrestore(&priv->lock, flags);
7430
IWL_DEBUG_MAC80211("leave\n");
7431
mutex_unlock(&priv->mutex);
7436
static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
7437
struct ieee80211_if_init_conf *conf)
7439
struct iwl3945_priv *priv = hw->priv;
7441
IWL_DEBUG_MAC80211("enter\n");
7443
mutex_lock(&priv->mutex);
7445
if (iwl3945_is_ready_rf(priv)) {
7446
iwl3945_scan_cancel_timeout(priv, 100);
7447
cancel_delayed_work(&priv->post_associate);
7448
priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7449
iwl3945_commit_rxon(priv);
7451
if (priv->interface_id == conf->if_id) {
7452
priv->interface_id = 0;
7453
memset(priv->bssid, 0, ETH_ALEN);
7454
memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
7455
priv->essid_len = 0;
7457
mutex_unlock(&priv->mutex);
7459
IWL_DEBUG_MAC80211("leave\n");
7462
static int iwl3945_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
7465
unsigned long flags;
7466
struct iwl3945_priv *priv = hw->priv;
7468
IWL_DEBUG_MAC80211("enter\n");
7470
mutex_lock(&priv->mutex);
7471
spin_lock_irqsave(&priv->lock, flags);
7473
if (!iwl3945_is_ready_rf(priv)) {
7475
IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
7479
if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */
7481
IWL_ERROR("ERROR: APs don't scan\n");
7485
/* we don't schedule scan within next_scan_jiffies period */
7486
if (priv->next_scan_jiffies &&
7487
time_after(priv->next_scan_jiffies, jiffies)) {
7491
/* if we just finished scan ask for delay */
7492
if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies +
7493
IWL_DELAY_NEXT_SCAN, jiffies)) {
7498
IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
7499
iwl3945_escape_essid(ssid, len), (int)len);
7501
priv->one_direct_scan = 1;
7502
priv->direct_ssid_len = (u8)
7503
min((u8) len, (u8) IW_ESSID_MAX_SIZE);
7504
memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
7506
priv->one_direct_scan = 0;
7508
rc = iwl3945_scan_initiate(priv);
7510
IWL_DEBUG_MAC80211("leave\n");
7513
spin_unlock_irqrestore(&priv->lock, flags);
7514
mutex_unlock(&priv->mutex);
7519
static int iwl3945_mac_set_key(struct ieee80211_hw *hw, set_key_cmd cmd, u8 *addr,
7520
struct ieee80211_key_conf *key, int aid)
7522
struct iwl3945_priv *priv = hw->priv;
7526
IWL_DEBUG_MAC80211("enter\n");
7528
if (!iwl3945_param_hwcrypto) {
7529
IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
7533
sta_id = iwl3945_hw_find_station(priv, addr);
7534
if (sta_id == IWL_INVALID_STATION) {
7535
IWL_DEBUG_MAC80211("leave - " MAC_FMT " not in station map.\n",
7540
mutex_lock(&priv->mutex);
7542
iwl3945_scan_cancel_timeout(priv, 100);
7546
rc = iwl3945_update_sta_key_info(priv, key, sta_id);
7548
iwl3945_set_rxon_hwcrypto(priv, 1);
7549
iwl3945_commit_rxon(priv);
7550
key->hw_key_idx = sta_id;
7551
IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n");
7555
rc = iwl3945_clear_sta_key_info(priv, sta_id);
7557
iwl3945_set_rxon_hwcrypto(priv, 0);
7558
iwl3945_commit_rxon(priv);
7559
IWL_DEBUG_MAC80211("disable hwcrypto key\n");
7566
IWL_DEBUG_MAC80211("leave\n");
7567
mutex_unlock(&priv->mutex);
7572
static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, int queue,
7573
const struct ieee80211_tx_queue_params *params)
7575
struct iwl3945_priv *priv = hw->priv;
7576
#ifdef CONFIG_IWL3945_QOS
7577
unsigned long flags;
7579
#endif /* CONFIG_IWL3945_QOS */
7581
IWL_DEBUG_MAC80211("enter\n");
7583
if (!iwl3945_is_ready_rf(priv)) {
7584
IWL_DEBUG_MAC80211("leave - RF not ready\n");
7588
if (queue >= AC_NUM) {
7589
IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
7593
#ifdef CONFIG_IWL3945_QOS
7594
if (!priv->qos_data.qos_enable) {
7595
priv->qos_data.qos_active = 0;
7596
IWL_DEBUG_MAC80211("leave - qos not enabled\n");
7599
q = AC_NUM - 1 - queue;
7601
spin_lock_irqsave(&priv->lock, flags);
7603
priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
7604
priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
7605
priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
7606
priv->qos_data.def_qos_parm.ac[q].edca_txop =
7607
cpu_to_le16((params->burst_time * 100));
7609
priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
7610
priv->qos_data.qos_active = 1;
7612
spin_unlock_irqrestore(&priv->lock, flags);
7614
mutex_lock(&priv->mutex);
7615
if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
7616
iwl3945_activate_qos(priv, 1);
7617
else if (priv->assoc_id && iwl3945_is_associated(priv))
7618
iwl3945_activate_qos(priv, 0);
7620
mutex_unlock(&priv->mutex);
7622
#endif /*CONFIG_IWL3945_QOS */
7624
IWL_DEBUG_MAC80211("leave\n");
7628
static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
7629
struct ieee80211_tx_queue_stats *stats)
7631
struct iwl3945_priv *priv = hw->priv;
7633
struct iwl3945_tx_queue *txq;
7634
struct iwl3945_queue *q;
7635
unsigned long flags;
7637
IWL_DEBUG_MAC80211("enter\n");
7639
if (!iwl3945_is_ready_rf(priv)) {
7640
IWL_DEBUG_MAC80211("leave - RF not ready\n");
7644
spin_lock_irqsave(&priv->lock, flags);
7646
for (i = 0; i < AC_NUM; i++) {
7647
txq = &priv->txq[i];
7649
avail = iwl3945_queue_space(q);
7651
stats->data[i].len = q->n_window - avail;
7652
stats->data[i].limit = q->n_window - q->high_mark;
7653
stats->data[i].count = q->n_window;
7656
spin_unlock_irqrestore(&priv->lock, flags);
7658
IWL_DEBUG_MAC80211("leave\n");
7663
static int iwl3945_mac_get_stats(struct ieee80211_hw *hw,
7664
struct ieee80211_low_level_stats *stats)
7666
IWL_DEBUG_MAC80211("enter\n");
7667
IWL_DEBUG_MAC80211("leave\n");
7672
static u64 iwl3945_mac_get_tsf(struct ieee80211_hw *hw)
7674
IWL_DEBUG_MAC80211("enter\n");
7675
IWL_DEBUG_MAC80211("leave\n");
7680
static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
7682
struct iwl3945_priv *priv = hw->priv;
7683
unsigned long flags;
7685
mutex_lock(&priv->mutex);
7686
IWL_DEBUG_MAC80211("enter\n");
7688
#ifdef CONFIG_IWL3945_QOS
7689
iwl3945_reset_qos(priv);
7691
cancel_delayed_work(&priv->post_associate);
7693
spin_lock_irqsave(&priv->lock, flags);
7695
priv->assoc_capability = 0;
7696
priv->call_post_assoc_from_beacon = 0;
7698
/* new association get rid of ibss beacon skb */
7699
if (priv->ibss_beacon)
7700
dev_kfree_skb(priv->ibss_beacon);
7702
priv->ibss_beacon = NULL;
7704
priv->beacon_int = priv->hw->conf.beacon_int;
7705
priv->timestamp1 = 0;
7706
priv->timestamp0 = 0;
7707
if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
7708
priv->beacon_int = 0;
7710
spin_unlock_irqrestore(&priv->lock, flags);
7712
if (!iwl3945_is_ready_rf(priv)) {
7713
IWL_DEBUG_MAC80211("leave - not ready\n");
7714
mutex_unlock(&priv->mutex);
7718
/* we are restarting association process
7719
* clear RXON_FILTER_ASSOC_MSK bit
7721
if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
7722
iwl3945_scan_cancel_timeout(priv, 100);
7723
priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
7724
iwl3945_commit_rxon(priv);
7727
/* Per mac80211.h: This is only used in IBSS mode... */
7728
if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
7730
IWL_DEBUG_MAC80211("leave - not in IBSS\n");
7731
mutex_unlock(&priv->mutex);
7735
priv->only_active_channel = 0;
7737
iwl3945_set_rate(priv);
7739
mutex_unlock(&priv->mutex);
7741
IWL_DEBUG_MAC80211("leave\n");
7745
static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb,
7746
struct ieee80211_tx_control *control)
7748
struct iwl3945_priv *priv = hw->priv;
7749
unsigned long flags;
7751
mutex_lock(&priv->mutex);
7752
IWL_DEBUG_MAC80211("enter\n");
7754
if (!iwl3945_is_ready_rf(priv)) {
7755
IWL_DEBUG_MAC80211("leave - RF not ready\n");
7756
mutex_unlock(&priv->mutex);
7760
if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
7761
IWL_DEBUG_MAC80211("leave - not IBSS\n");
7762
mutex_unlock(&priv->mutex);
7766
spin_lock_irqsave(&priv->lock, flags);
7768
if (priv->ibss_beacon)
7769
dev_kfree_skb(priv->ibss_beacon);
7771
priv->ibss_beacon = skb;
7775
IWL_DEBUG_MAC80211("leave\n");
7776
spin_unlock_irqrestore(&priv->lock, flags);
7778
#ifdef CONFIG_IWL3945_QOS
7779
iwl3945_reset_qos(priv);
7782
queue_work(priv->workqueue, &priv->post_associate.work);
7784
mutex_unlock(&priv->mutex);
7789
/*****************************************************************************
7793
*****************************************************************************/
7795
#ifdef CONFIG_IWL3945_DEBUG
7798
* The following adds a new attribute to the sysfs representation
7799
* of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
7800
* used for controlling the debug level.
7802
* See the level definitions in iwl for details.
7805
static ssize_t show_debug_level(struct device_driver *d, char *buf)
7807
return sprintf(buf, "0x%08X\n", iwl3945_debug_level);
7809
static ssize_t store_debug_level(struct device_driver *d,
7810
const char *buf, size_t count)
7812
char *p = (char *)buf;
7815
val = simple_strtoul(p, &p, 0);
7817
printk(KERN_INFO DRV_NAME
7818
": %s is not in hex or decimal form.\n", buf);
7820
iwl3945_debug_level = val;
7822
return strnlen(buf, count);
7825
static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
7826
show_debug_level, store_debug_level);
7828
#endif /* CONFIG_IWL3945_DEBUG */
7830
static ssize_t show_rf_kill(struct device *d,
7831
struct device_attribute *attr, char *buf)
7834
* 0 - RF kill not enabled
7835
* 1 - SW based RF kill active (sysfs)
7836
* 2 - HW based RF kill active
7837
* 3 - Both HW and SW based RF kill active
7839
struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7840
int val = (test_bit(STATUS_RF_KILL_SW, &priv->status) ? 0x1 : 0x0) |
7841
(test_bit(STATUS_RF_KILL_HW, &priv->status) ? 0x2 : 0x0);
7843
return sprintf(buf, "%i\n", val);
7846
static ssize_t store_rf_kill(struct device *d,
7847
struct device_attribute *attr,
7848
const char *buf, size_t count)
7850
struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7852
mutex_lock(&priv->mutex);
7853
iwl3945_radio_kill_sw(priv, buf[0] == '1');
7854
mutex_unlock(&priv->mutex);
7859
static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
7861
static ssize_t show_temperature(struct device *d,
7862
struct device_attribute *attr, char *buf)
7864
struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7866
if (!iwl3945_is_alive(priv))
7869
return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
7872
static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
7874
static ssize_t show_rs_window(struct device *d,
7875
struct device_attribute *attr,
7878
struct iwl3945_priv *priv = d->driver_data;
7879
return iwl3945_fill_rs_info(priv->hw, buf, IWL_AP_ID);
7881
static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
7883
static ssize_t show_tx_power(struct device *d,
7884
struct device_attribute *attr, char *buf)
7886
struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7887
return sprintf(buf, "%d\n", priv->user_txpower_limit);
7890
static ssize_t store_tx_power(struct device *d,
7891
struct device_attribute *attr,
7892
const char *buf, size_t count)
7894
struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7895
char *p = (char *)buf;
7898
val = simple_strtoul(p, &p, 10);
7900
printk(KERN_INFO DRV_NAME
7901
": %s is not in decimal form.\n", buf);
7903
iwl3945_hw_reg_set_txpower(priv, val);
7908
static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
7910
static ssize_t show_flags(struct device *d,
7911
struct device_attribute *attr, char *buf)
7913
struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7915
return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
7918
static ssize_t store_flags(struct device *d,
7919
struct device_attribute *attr,
7920
const char *buf, size_t count)
7922
struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7923
u32 flags = simple_strtoul(buf, NULL, 0);
7925
mutex_lock(&priv->mutex);
7926
if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
7927
/* Cancel any currently running scans... */
7928
if (iwl3945_scan_cancel_timeout(priv, 100))
7929
IWL_WARNING("Could not cancel scan.\n");
7931
IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
7933
priv->staging_rxon.flags = cpu_to_le32(flags);
7934
iwl3945_commit_rxon(priv);
7937
mutex_unlock(&priv->mutex);
7942
static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
7944
static ssize_t show_filter_flags(struct device *d,
7945
struct device_attribute *attr, char *buf)
7947
struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7949
return sprintf(buf, "0x%04X\n",
7950
le32_to_cpu(priv->active_rxon.filter_flags));
7953
static ssize_t store_filter_flags(struct device *d,
7954
struct device_attribute *attr,
7955
const char *buf, size_t count)
7957
struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7958
u32 filter_flags = simple_strtoul(buf, NULL, 0);
7960
mutex_lock(&priv->mutex);
7961
if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
7962
/* Cancel any currently running scans... */
7963
if (iwl3945_scan_cancel_timeout(priv, 100))
7964
IWL_WARNING("Could not cancel scan.\n");
7966
IWL_DEBUG_INFO("Committing rxon.filter_flags = "
7967
"0x%04X\n", filter_flags);
7968
priv->staging_rxon.filter_flags =
7969
cpu_to_le32(filter_flags);
7970
iwl3945_commit_rxon(priv);
7973
mutex_unlock(&priv->mutex);
7978
static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
7979
store_filter_flags);
7981
static ssize_t show_tune(struct device *d,
7982
struct device_attribute *attr, char *buf)
7984
struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7986
return sprintf(buf, "0x%04X\n",
7987
(priv->phymode << 8) |
7988
le16_to_cpu(priv->active_rxon.channel));
7991
static void iwl3945_set_flags_for_phymode(struct iwl3945_priv *priv, u8 phymode);
7993
static ssize_t store_tune(struct device *d,
7994
struct device_attribute *attr,
7995
const char *buf, size_t count)
7997
struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
7998
char *p = (char *)buf;
7999
u16 tune = simple_strtoul(p, &p, 0);
8000
u8 phymode = (tune >> 8) & 0xff;
8001
u16 channel = tune & 0xff;
8003
IWL_DEBUG_INFO("Tune request to:%d channel:%d\n", phymode, channel);
8005
mutex_lock(&priv->mutex);
8006
if ((le16_to_cpu(priv->staging_rxon.channel) != channel) ||
8007
(priv->phymode != phymode)) {
8008
const struct iwl3945_channel_info *ch_info;
8010
ch_info = iwl3945_get_channel_info(priv, phymode, channel);
8012
IWL_WARNING("Requested invalid phymode/channel "
8013
"combination: %d %d\n", phymode, channel);
8014
mutex_unlock(&priv->mutex);
8018
/* Cancel any currently running scans... */
8019
if (iwl3945_scan_cancel_timeout(priv, 100))
8020
IWL_WARNING("Could not cancel scan.\n");
8022
IWL_DEBUG_INFO("Committing phymode and "
8023
"rxon.channel = %d %d\n",
8026
iwl3945_set_rxon_channel(priv, phymode, channel);
8027
iwl3945_set_flags_for_phymode(priv, phymode);
8029
iwl3945_set_rate(priv);
8030
iwl3945_commit_rxon(priv);
8033
mutex_unlock(&priv->mutex);
8038
static DEVICE_ATTR(tune, S_IWUSR | S_IRUGO, show_tune, store_tune);
8040
#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
8042
static ssize_t show_measurement(struct device *d,
8043
struct device_attribute *attr, char *buf)
8045
struct iwl3945_priv *priv = dev_get_drvdata(d);
8046
struct iwl3945_spectrum_notification measure_report;
8047
u32 size = sizeof(measure_report), len = 0, ofs = 0;
8048
u8 *data = (u8 *) & measure_report;
8049
unsigned long flags;
8051
spin_lock_irqsave(&priv->lock, flags);
8052
if (!(priv->measurement_status & MEASUREMENT_READY)) {
8053
spin_unlock_irqrestore(&priv->lock, flags);
8056
memcpy(&measure_report, &priv->measure_report, size);
8057
priv->measurement_status = 0;
8058
spin_unlock_irqrestore(&priv->lock, flags);
8060
while (size && (PAGE_SIZE - len)) {
8061
hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
8062
PAGE_SIZE - len, 1);
8064
if (PAGE_SIZE - len)
8068
size -= min(size, 16U);
8074
static ssize_t store_measurement(struct device *d,
8075
struct device_attribute *attr,
8076
const char *buf, size_t count)
8078
struct iwl3945_priv *priv = dev_get_drvdata(d);
8079
struct ieee80211_measurement_params params = {
8080
.channel = le16_to_cpu(priv->active_rxon.channel),
8081
.start_time = cpu_to_le64(priv->last_tsf),
8082
.duration = cpu_to_le16(1),
8084
u8 type = IWL_MEASURE_BASIC;
8090
strncpy(buffer, buf, min(sizeof(buffer), count));
8091
channel = simple_strtoul(p, NULL, 0);
8093
params.channel = channel;
8096
while (*p && *p != ' ')
8099
type = simple_strtoul(p + 1, NULL, 0);
8102
IWL_DEBUG_INFO("Invoking measurement of type %d on "
8103
"channel %d (for '%s')\n", type, params.channel, buf);
8104
iwl3945_get_measurement(priv, ¶ms, type);
8109
static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
8110
show_measurement, store_measurement);
8111
#endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
8113
static ssize_t show_rate(struct device *d,
8114
struct device_attribute *attr, char *buf)
8116
struct iwl3945_priv *priv = dev_get_drvdata(d);
8117
unsigned long flags;
8120
spin_lock_irqsave(&priv->sta_lock, flags);
8121
if (priv->iw_mode == IEEE80211_IF_TYPE_STA)
8122
i = priv->stations[IWL_AP_ID].current_rate.s.rate;
8124
i = priv->stations[IWL_STA_ID].current_rate.s.rate;
8125
spin_unlock_irqrestore(&priv->sta_lock, flags);
8127
i = iwl3945_rate_index_from_plcp(i);
8129
return sprintf(buf, "0\n");
8131
return sprintf(buf, "%d%s\n",
8132
(iwl3945_rates[i].ieee >> 1),
8133
(iwl3945_rates[i].ieee & 0x1) ? ".5" : "");
8136
static DEVICE_ATTR(rate, S_IRUSR, show_rate, NULL);
8138
static ssize_t store_retry_rate(struct device *d,
8139
struct device_attribute *attr,
8140
const char *buf, size_t count)
8142
struct iwl3945_priv *priv = dev_get_drvdata(d);
8144
priv->retry_rate = simple_strtoul(buf, NULL, 0);
8145
if (priv->retry_rate <= 0)
8146
priv->retry_rate = 1;
8151
static ssize_t show_retry_rate(struct device *d,
8152
struct device_attribute *attr, char *buf)
8154
struct iwl3945_priv *priv = dev_get_drvdata(d);
8155
return sprintf(buf, "%d", priv->retry_rate);
8158
static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
8161
static ssize_t store_power_level(struct device *d,
8162
struct device_attribute *attr,
8163
const char *buf, size_t count)
8165
struct iwl3945_priv *priv = dev_get_drvdata(d);
8169
mode = simple_strtoul(buf, NULL, 0);
8170
mutex_lock(&priv->mutex);
8172
if (!iwl3945_is_ready(priv)) {
8177
if ((mode < 1) || (mode > IWL_POWER_LIMIT) || (mode == IWL_POWER_AC))
8178
mode = IWL_POWER_AC;
8180
mode |= IWL_POWER_ENABLED;
8182
if (mode != priv->power_mode) {
8183
rc = iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(mode));
8185
IWL_DEBUG_MAC80211("failed setting power mode.\n");
8188
priv->power_mode = mode;
8194
mutex_unlock(&priv->mutex);
8198
#define MAX_WX_STRING 80
8200
/* Values are in microsecond */
8201
static const s32 timeout_duration[] = {
8208
static const s32 period_duration[] = {
8216
static ssize_t show_power_level(struct device *d,
8217
struct device_attribute *attr, char *buf)
8219
struct iwl3945_priv *priv = dev_get_drvdata(d);
8220
int level = IWL_POWER_LEVEL(priv->power_mode);
8223
p += sprintf(p, "%d ", level);
8225
case IWL_POWER_MODE_CAM:
8227
p += sprintf(p, "(AC)");
8229
case IWL_POWER_BATTERY:
8230
p += sprintf(p, "(BATTERY)");
8234
"(Timeout %dms, Period %dms)",
8235
timeout_duration[level - 1] / 1000,
8236
period_duration[level - 1] / 1000);
8239
if (!(priv->power_mode & IWL_POWER_ENABLED))
8240
p += sprintf(p, " OFF\n");
8242
p += sprintf(p, " \n");
8244
return (p - buf + 1);
8248
static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
8251
static ssize_t show_channels(struct device *d,
8252
struct device_attribute *attr, char *buf)
8254
struct iwl3945_priv *priv = dev_get_drvdata(d);
8256
struct ieee80211_channel *channels = NULL;
8257
const struct ieee80211_hw_mode *hw_mode = NULL;
8260
if (!iwl3945_is_ready(priv))
8263
hw_mode = iwl3945_get_hw_mode(priv, MODE_IEEE80211G);
8265
hw_mode = iwl3945_get_hw_mode(priv, MODE_IEEE80211B);
8267
channels = hw_mode->channels;
8268
count = hw_mode->num_channels;
8273
"Displaying %d channels in 2.4GHz band "
8274
"(802.11bg):\n", count);
8276
for (i = 0; i < count; i++)
8277
len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
8279
channels[i].power_level,
8281
flag & IEEE80211_CHAN_W_RADAR_DETECT ?
8282
" (IEEE 802.11h required)" : "",
8283
(!(channels[i].flag & IEEE80211_CHAN_W_IBSS)
8286
IEEE80211_CHAN_W_RADAR_DETECT)) ? "" :
8289
flag & IEEE80211_CHAN_W_ACTIVE_SCAN ?
8290
"active/passive" : "passive only");
8292
hw_mode = iwl3945_get_hw_mode(priv, MODE_IEEE80211A);
8294
channels = hw_mode->channels;
8295
count = hw_mode->num_channels;
8301
len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band "
8302
"(802.11a):\n", count);
8304
for (i = 0; i < count; i++)
8305
len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
8307
channels[i].power_level,
8309
flag & IEEE80211_CHAN_W_RADAR_DETECT ?
8310
" (IEEE 802.11h required)" : "",
8311
(!(channels[i].flag & IEEE80211_CHAN_W_IBSS)
8314
IEEE80211_CHAN_W_RADAR_DETECT)) ? "" :
8317
flag & IEEE80211_CHAN_W_ACTIVE_SCAN ?
8318
"active/passive" : "passive only");
8323
static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
8325
static ssize_t show_statistics(struct device *d,
8326
struct device_attribute *attr, char *buf)
8328
struct iwl3945_priv *priv = dev_get_drvdata(d);
8329
u32 size = sizeof(struct iwl3945_notif_statistics);
8330
u32 len = 0, ofs = 0;
8331
u8 *data = (u8 *) & priv->statistics;
8334
if (!iwl3945_is_alive(priv))
8337
mutex_lock(&priv->mutex);
8338
rc = iwl3945_send_statistics_request(priv);
8339
mutex_unlock(&priv->mutex);
8343
"Error sending statistics request: 0x%08X\n", rc);
8347
while (size && (PAGE_SIZE - len)) {
8348
hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
8349
PAGE_SIZE - len, 1);
8351
if (PAGE_SIZE - len)
8355
size -= min(size, 16U);
8361
static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
8363
static ssize_t show_antenna(struct device *d,
8364
struct device_attribute *attr, char *buf)
8366
struct iwl3945_priv *priv = dev_get_drvdata(d);
8368
if (!iwl3945_is_alive(priv))
8371
return sprintf(buf, "%d\n", priv->antenna);
8374
static ssize_t store_antenna(struct device *d,
8375
struct device_attribute *attr,
8376
const char *buf, size_t count)
8379
struct iwl3945_priv *priv = dev_get_drvdata(d);
8384
if (sscanf(buf, "%1i", &ant) != 1) {
8385
IWL_DEBUG_INFO("not in hex or decimal form.\n");
8389
if ((ant >= 0) && (ant <= 2)) {
8390
IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant);
8391
priv->antenna = (enum iwl3945_antenna)ant;
8393
IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant);
8399
static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
8401
static ssize_t show_status(struct device *d,
8402
struct device_attribute *attr, char *buf)
8404
struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
8405
if (!iwl3945_is_alive(priv))
8407
return sprintf(buf, "0x%08x\n", (int)priv->status);
8410
static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
8412
static ssize_t dump_error_log(struct device *d,
8413
struct device_attribute *attr,
8414
const char *buf, size_t count)
8416
char *p = (char *)buf;
8419
iwl3945_dump_nic_error_log((struct iwl3945_priv *)d->driver_data);
8421
return strnlen(buf, count);
8424
static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
8426
static ssize_t dump_event_log(struct device *d,
8427
struct device_attribute *attr,
8428
const char *buf, size_t count)
8430
char *p = (char *)buf;
8433
iwl3945_dump_nic_event_log((struct iwl3945_priv *)d->driver_data);
8435
return strnlen(buf, count);
8438
static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
8440
/*****************************************************************************
8442
* driver setup and teardown
8444
*****************************************************************************/
8446
static void iwl3945_setup_deferred_work(struct iwl3945_priv *priv)
8448
priv->workqueue = create_workqueue(DRV_NAME);
8450
init_waitqueue_head(&priv->wait_command_queue);
8452
INIT_WORK(&priv->up, iwl3945_bg_up);
8453
INIT_WORK(&priv->restart, iwl3945_bg_restart);
8454
INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
8455
INIT_WORK(&priv->scan_completed, iwl3945_bg_scan_completed);
8456
INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
8457
INIT_WORK(&priv->abort_scan, iwl3945_bg_abort_scan);
8458
INIT_WORK(&priv->rf_kill, iwl3945_bg_rf_kill);
8459
INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
8460
INIT_DELAYED_WORK(&priv->post_associate, iwl3945_bg_post_associate);
8461
INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
8462
INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
8463
INIT_DELAYED_WORK(&priv->scan_check, iwl3945_bg_scan_check);
8465
iwl3945_hw_setup_deferred_work(priv);
8467
tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
8468
iwl3945_irq_tasklet, (unsigned long)priv);
8471
#ifndef cancel_work_sync
8472
#define cancel_work_sync(x)
8475
static void iwl3945_cancel_deferred_work(struct iwl3945_priv *priv)
8477
iwl3945_hw_cancel_deferred_work(priv);
8479
cancel_delayed_work(&priv->init_alive_start);
8480
cancel_delayed_work(&priv->scan_check);
8481
cancel_delayed_work(&priv->alive_start);
8482
cancel_delayed_work(&priv->post_associate);
8483
cancel_work_sync(&priv->beacon_update);
8486
static struct attribute *iwl3945_sysfs_entries[] = {
8487
&dev_attr_antenna.attr,
8488
&dev_attr_channels.attr,
8489
&dev_attr_dump_errors.attr,
8490
&dev_attr_dump_events.attr,
8491
&dev_attr_flags.attr,
8492
&dev_attr_filter_flags.attr,
8493
#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
8494
&dev_attr_measurement.attr,
8496
&dev_attr_power_level.attr,
8497
&dev_attr_rate.attr,
8498
&dev_attr_retry_rate.attr,
8499
&dev_attr_rf_kill.attr,
8500
&dev_attr_rs_window.attr,
8501
&dev_attr_statistics.attr,
8502
&dev_attr_status.attr,
8503
&dev_attr_temperature.attr,
8504
&dev_attr_tune.attr,
8505
&dev_attr_tx_power.attr,
8510
static struct attribute_group iwl3945_attribute_group = {
8511
.name = NULL, /* put in device directory */
8512
.attrs = iwl3945_sysfs_entries,
8515
static struct ieee80211_ops iwl3945_hw_ops = {
8516
.tx = iwl3945_mac_tx,
8517
.open = iwl3945_mac_open,
8518
.stop = iwl3945_mac_stop,
8519
.add_interface = iwl3945_mac_add_interface,
8520
.remove_interface = iwl3945_mac_remove_interface,
8521
.config = iwl3945_mac_config,
8522
.config_interface = iwl3945_mac_config_interface,
8523
.set_key = iwl3945_mac_set_key,
8524
.get_stats = iwl3945_mac_get_stats,
8525
.get_tx_stats = iwl3945_mac_get_tx_stats,
8526
.conf_tx = iwl3945_mac_conf_tx,
8527
.get_tsf = iwl3945_mac_get_tsf,
8528
.reset_tsf = iwl3945_mac_reset_tsf,
8529
.beacon_update = iwl3945_mac_beacon_update,
8530
.hw_scan = iwl3945_mac_hw_scan
8533
static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
8537
struct iwl3945_priv *priv;
8538
struct ieee80211_hw *hw;
8541
/* Disabling hardware scan means that mac80211 will perform scans
8542
* "the hard way", rather than using device's scan. */
8543
if (iwl3945_param_disable_hw_scan) {
8544
IWL_DEBUG_INFO("Disabling hw_scan\n");
8545
iwl3945_hw_ops.hw_scan = NULL;
8548
if ((iwl3945_param_queues_num > IWL_MAX_NUM_QUEUES) ||
8549
(iwl3945_param_queues_num < IWL_MIN_NUM_QUEUES)) {
8550
IWL_ERROR("invalid queues_num, should be between %d and %d\n",
8551
IWL_MIN_NUM_QUEUES, IWL_MAX_NUM_QUEUES);
8556
/* mac80211 allocates memory for this device instance, including
8557
* space for this driver's private structure */
8558
hw = iwlwifi_ieee80211_alloc_hw(sizeof(struct iwl3945_priv), &iwl3945_hw_ops);
8560
IWL_ERROR("Can not allocate network device\n");
8564
SET_IEEE80211_DEV(hw, &pdev->dev);
8566
IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
8570
priv->pci_dev = pdev;
8572
/* Select antenna (may be helpful if only one antenna is connected) */
8573
priv->antenna = (enum iwl3945_antenna)iwl3945_param_antenna;
8574
#ifdef CONFIG_IWL3945_DEBUG
8575
iwl3945_debug_level = iwl3945_param_debug;
8576
atomic_set(&priv->restrict_refcnt, 0);
8578
priv->retry_rate = 1;
8580
priv->ibss_beacon = NULL;
8582
/* Tell mac80211 and its clients (e.g. Wireless Extensions)
8583
* the range of signal quality values that we'll provide.
8584
* Negative values for level/noise indicate that we'll provide dBm.
8585
* For WE, at least, non-0 values here *enable* display of values
8586
* in app (iwconfig). */
8587
hw->max_rssi = -20; /* signal level, negative indicates dBm */
8588
hw->max_noise = -20; /* noise level, negative indicates dBm */
8589
hw->max_signal = 100; /* link quality indication (%) */
8591
/* Tell mac80211 our Tx characteristics */
8592
hw->flags = IEEE80211_HW_WEP_INCLUDE_IV |
8593
IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE;
8595
/* 4 EDCA QOS priorities */
8598
spin_lock_init(&priv->lock);
8599
spin_lock_init(&priv->power_data.lock);
8600
spin_lock_init(&priv->sta_lock);
8601
spin_lock_init(&priv->hcmd_lock);
8603
for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++)
8604
INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
8606
INIT_LIST_HEAD(&priv->free_frames);
8608
mutex_init(&priv->mutex);
8609
if (pci_enable_device(pdev)) {
8611
goto out_iwlwifi_ieee80211_free_hw;
8614
pci_set_master(pdev);
8616
/* Clear the driver's (not device's) station table */
8617
iwl3945_clear_stations_table(priv);
8619
priv->data_retry_limit = -1;
8620
priv->ieee_channels = NULL;
8621
priv->ieee_rates = NULL;
8624
err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
8626
err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
8628
printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
8629
goto out_pci_disable_device;
8632
pci_set_drvdata(pdev, priv);
8633
err = pci_request_regions(pdev, DRV_NAME);
8635
goto out_pci_disable_device;
8637
/* We disable the RETRY_TIMEOUT register (0x41) to keep
8638
* PCI Tx retries from interfering with C3 CPU state */
8639
pci_write_config_byte(pdev, 0x41, 0x00);
8641
priv->hw_base = pci_iomap(pdev, 0, 0);
8642
if (!priv->hw_base) {
8644
goto out_pci_release_regions;
8647
IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
8648
(unsigned long long) pci_resource_len(pdev, 0));
8649
IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
8651
/* Initialize module parameter values here */
8653
/* Disable radio (SW RF KILL) via parameter when loading driver */
8654
if (iwl3945_param_disable) {
8655
set_bit(STATUS_RF_KILL_SW, &priv->status);
8656
IWL_DEBUG_INFO("Radio disabled.\n");
8659
priv->iw_mode = IEEE80211_IF_TYPE_STA;
8662
(priv->pci_dev->device << 16) | priv->pci_dev->subsystem_device;
8665
case 0x42221005: /* 0x4222 0x8086 0x1005 is BG SKU */
8666
case 0x42221034: /* 0x4222 0x8086 0x1034 is BG SKU */
8667
case 0x42271014: /* 0x4227 0x8086 0x1014 is BG SKU */
8668
case 0x42221044: /* 0x4222 0x8086 0x1044 is BG SKU */
8673
* Rest are assumed ABG SKU -- if this is not the
8674
* case then the card will get the wrong 'Detected'
8675
* line in the kernel log however the code that
8676
* initializes the GEO table will detect no A-band
8677
* channels and remove the is_abg mask.
8684
printk(KERN_INFO DRV_NAME
8685
": Detected Intel PRO/Wireless 3945%sBG Network Connection\n",
8686
priv->is_abg ? "A" : "");
8688
/* Device-specific setup */
8689
if (iwl3945_hw_set_hw_setting(priv)) {
8690
IWL_ERROR("failed to set hw settings\n");
8694
#ifdef CONFIG_IWL3945_QOS
8695
if (iwl3945_param_qos_enable)
8696
priv->qos_data.qos_enable = 1;
8698
iwl3945_reset_qos(priv);
8700
priv->qos_data.qos_active = 0;
8701
priv->qos_data.qos_cap.val = 0;
8702
#endif /* CONFIG_IWL3945_QOS */
8704
iwl3945_set_rxon_channel(priv, MODE_IEEE80211G, 6);
8705
iwl3945_setup_deferred_work(priv);
8706
iwl3945_setup_rx_handlers(priv);
8708
priv->rates_mask = IWL_RATES_MASK;
8709
/* If power management is turned on, default to AC mode */
8710
priv->power_mode = IWL_POWER_AC;
8711
priv->user_txpower_limit = IWL_DEFAULT_TX_POWER;
8713
iwl3945_disable_interrupts(priv);
8715
err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
8717
IWL_ERROR("failed to create sysfs device attributes\n");
8718
goto out_release_irq;
8722
iwl3945_set_bit(priv, CSR_GIO_CHICKEN_BITS,
8723
CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
8725
iwl3945_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
8726
err = iwl3945_poll_bit(priv, CSR_GP_CNTRL,
8727
CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
8728
CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
8730
IWL_DEBUG_INFO("Failed to init the card\n");
8731
goto out_remove_sysfs;
8733
/* Read the EEPROM */
8734
err = iwl3945_eeprom_init(priv);
8736
IWL_ERROR("Unable to init EEPROM\n");
8737
goto out_remove_sysfs;
8739
/* MAC Address location in EEPROM same for 3945/4965 */
8740
get_eeprom_mac(priv, priv->mac_addr);
8741
IWL_DEBUG_INFO("MAC address: " MAC_FMT "\n", MAC_ARG(priv->mac_addr));
8742
SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
8744
iwl3945_rate_control_register(priv->hw);
8745
err = iwlwifi_ieee80211_register_hw(priv->hw);
8747
IWL_ERROR("Failed to register network device (error %d)\n", err);
8748
goto out_remove_sysfs;
8751
priv->hw->conf.beacon_int = 100;
8752
priv->mac80211_registered = 1;
8753
pci_save_state(pdev);
8754
pci_disable_device(pdev);
8759
iwl3945_rate_control_unregister(priv->hw);
8760
sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
8763
destroy_workqueue(priv->workqueue);
8764
priv->workqueue = NULL;
8765
iwl3945_unset_hw_setting(priv);
8768
pci_iounmap(pdev, priv->hw_base);
8769
out_pci_release_regions:
8770
pci_release_regions(pdev);
8771
out_pci_disable_device:
8772
pci_disable_device(pdev);
8773
pci_set_drvdata(pdev, NULL);
8774
out_iwlwifi_ieee80211_free_hw:
8775
iwlwifi_ieee80211_free_hw(priv->hw);
8780
static void iwl3945_pci_remove(struct pci_dev *pdev)
8782
struct iwl3945_priv *priv = pci_get_drvdata(pdev);
8783
struct list_head *p, *q;
8789
IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
8791
set_bit(STATUS_EXIT_PENDING, &priv->status);
8795
/* Free MAC hash list for ADHOC */
8796
for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
8797
list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
8799
kfree(list_entry(p, struct iwl3945_ibss_seq, list));
8803
sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
8805
iwl3945_dealloc_ucode_pci(priv);
8808
iwl3945_rx_queue_free(priv, &priv->rxq);
8809
iwl3945_hw_txq_ctx_free(priv);
8811
iwl3945_unset_hw_setting(priv);
8812
iwl3945_clear_stations_table(priv);
8814
if (priv->mac80211_registered) {
8815
iwlwifi_ieee80211_unregister_hw(priv->hw);
8816
iwl3945_rate_control_unregister(priv->hw);
8819
/*netif_stop_queue(dev); */
8820
flush_workqueue(priv->workqueue);
8822
/* iwlwifi_ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
8823
* priv->workqueue... so we can't take down the workqueue
8825
destroy_workqueue(priv->workqueue);
8826
priv->workqueue = NULL;
8828
pci_iounmap(pdev, priv->hw_base);
8829
pci_release_regions(pdev);
8830
pci_disable_device(pdev);
8831
pci_set_drvdata(pdev, NULL);
8833
kfree(priv->channel_info);
8835
kfree(priv->ieee_channels);
8836
kfree(priv->ieee_rates);
8838
if (priv->ibss_beacon)
8839
dev_kfree_skb(priv->ibss_beacon);
8841
iwlwifi_ieee80211_free_hw(priv->hw);
8846
static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
8848
struct iwl3945_priv *priv = pci_get_drvdata(pdev);
8850
if (priv->is_open) {
8851
set_bit(STATUS_IN_SUSPEND, &priv->status);
8852
iwl3945_mac_stop(priv->hw);
8856
pci_set_power_state(pdev, PCI_D3hot);
8861
static int iwl3945_pci_resume(struct pci_dev *pdev)
8863
struct iwl3945_priv *priv = pci_get_drvdata(pdev);
8865
pci_set_power_state(pdev, PCI_D0);
8868
iwl3945_mac_open(priv->hw);
8870
clear_bit(STATUS_IN_SUSPEND, &priv->status);
8874
#endif /* CONFIG_PM */
8876
/*****************************************************************************
8878
* driver and module entry point
8880
*****************************************************************************/
8882
static struct pci_driver iwl3945_driver = {
8884
.id_table = iwl3945_hw_card_ids,
8885
.probe = iwl3945_pci_probe,
8886
.remove = __devexit_p(iwl3945_pci_remove),
8888
.suspend = iwl3945_pci_suspend,
8889
.resume = iwl3945_pci_resume,
8893
static int __init iwl3945_init(void)
8897
printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
8898
printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
8899
ret = pci_register_driver(&iwl3945_driver);
8901
IWL_ERROR("Unable to initialize PCI module\n");
8904
#ifdef CONFIG_IWL3945_DEBUG
8905
ret = driver_create_file(&iwl3945_driver.driver, &driver_attr_debug_level);
8907
IWL_ERROR("Unable to create driver sysfs file\n");
8908
pci_unregister_driver(&iwl3945_driver);
8916
static void __exit iwl3945_exit(void)
8918
#ifdef CONFIG_IWL3945_DEBUG
8919
driver_remove_file(&iwl3945_driver.driver, &driver_attr_debug_level);
8921
pci_unregister_driver(&iwl3945_driver);
8924
module_param_named(antenna, iwl3945_param_antenna, int, 0444);
8925
MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
8926
module_param_named(disable, iwl3945_param_disable, int, 0444);
8927
MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
8928
module_param_named(hwcrypto, iwl3945_param_hwcrypto, int, 0444);
8929
MODULE_PARM_DESC(hwcrypto,
8930
"using hardware crypto engine (default 0 [software])\n");
8931
module_param_named(debug, iwl3945_param_debug, int, 0444);
8932
MODULE_PARM_DESC(debug, "debug output mask");
8933
module_param_named(disable_hw_scan, iwl3945_param_disable_hw_scan, int, 0444);
8934
MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
8936
module_param_named(queues_num, iwl3945_param_queues_num, int, 0444);
8937
MODULE_PARM_DESC(queues_num, "number of hw queues.");
8940
module_param_named(qos_enable, iwl3945_param_qos_enable, int, 0444);
8941
MODULE_PARM_DESC(qos_enable, "enable all QoS functionality");
8943
module_exit(iwl3945_exit);
8944
module_init(iwl3945_init);