1 /******************************************************************************
3 * Copyright(c) 2003 - 2008 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/etherdevice.h>
42 #include <linux/if_arp.h>
44 #include <net/ieee80211_radiotap.h>
45 #include <net/mac80211.h>
47 #include <asm/div64.h>
49 #include "iwl-3945-core.h"
51 #include "iwl-helpers.h"
53 #ifdef CONFIG_IWL3945_DEBUG
54 u32 iwl3945_debug_level
;
57 static int iwl3945_tx_queue_update_write_ptr(struct iwl3945_priv
*priv
,
58 struct iwl3945_tx_queue
*txq
);
60 /******************************************************************************
64 ******************************************************************************/
66 /* module parameters */
67 static int iwl3945_param_disable_hw_scan
; /* def: 0 = use 3945's h/w scan */
68 static int iwl3945_param_debug
; /* def: 0 = minimal debug log messages */
69 static int iwl3945_param_disable
; /* def: 0 = enable radio */
70 static int iwl3945_param_antenna
; /* def: 0 = both antennas (use diversity) */
71 int iwl3945_param_hwcrypto
; /* def: 0 = use software encryption */
72 static int iwl3945_param_qos_enable
= 1; /* def: 1 = use quality of service */
73 int iwl3945_param_queues_num
= IWL39_MAX_NUM_QUEUES
; /* def: 8 Tx queues */
76 * module name, copyright, version, etc.
77 * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
80 #define DRV_DESCRIPTION \
81 "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
83 #ifdef CONFIG_IWL3945_DEBUG
89 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
95 #define IWLWIFI_VERSION "1.2.26k" VD VS
96 #define DRV_COPYRIGHT "Copyright(c) 2003-2008 Intel Corporation"
97 #define DRV_VERSION IWLWIFI_VERSION
100 MODULE_DESCRIPTION(DRV_DESCRIPTION
);
101 MODULE_VERSION(DRV_VERSION
);
102 MODULE_AUTHOR(DRV_COPYRIGHT
);
103 MODULE_LICENSE("GPL");
105 static const struct ieee80211_supported_band
*iwl3945_get_band(
106 struct iwl3945_priv
*priv
, enum ieee80211_band band
)
108 return priv
->hw
->wiphy
->bands
[band
];
111 static int iwl3945_is_empty_essid(const char *essid
, int essid_len
)
113 /* Single white space is for Linksys APs */
114 if (essid_len
== 1 && essid
[0] == ' ')
117 /* Otherwise, if the entire essid is 0, we assume it is hidden */
120 if (essid
[essid_len
] != '\0')
127 static const char *iwl3945_escape_essid(const char *essid
, u8 essid_len
)
129 static char escaped
[IW_ESSID_MAX_SIZE
* 2 + 1];
130 const char *s
= essid
;
133 if (iwl3945_is_empty_essid(essid
, essid_len
)) {
134 memcpy(escaped
, "<hidden>", sizeof("<hidden>"));
138 essid_len
= min(essid_len
, (u8
) IW_ESSID_MAX_SIZE
);
139 while (essid_len
--) {
151 /*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
154 * Theory of operation
156 * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
157 * of buffer descriptors, each of which points to one or more data buffers for
158 * the device to read from or fill. Driver and device exchange status of each
159 * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
160 * entries in each circular buffer, to protect against confusing empty and full
163 * The device reads or writes the data in the queues via the device's several
164 * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
166 * For Tx queue, there are low mark and high mark limits. If, after queuing
167 * the packet for Tx, free space become < low mark, Tx queue stopped. When
168 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
171 * The 3945 operates with six queues: One receive queue, one transmit queue
172 * (#4) for sending commands to the device firmware, and four transmit queues
173 * (#0-3) for data tx via EDCA. An additional 2 HCCA queues are unused.
174 ***************************************************/
176 int iwl3945_queue_space(const struct iwl3945_queue
*q
)
178 int s
= q
->read_ptr
- q
->write_ptr
;
180 if (q
->read_ptr
> q
->write_ptr
)
185 /* keep some reserve to not confuse empty and full situations */
192 int iwl3945_x2_queue_used(const struct iwl3945_queue
*q
, int i
)
194 return q
->write_ptr
> q
->read_ptr
?
195 (i
>= q
->read_ptr
&& i
< q
->write_ptr
) :
196 !(i
< q
->read_ptr
&& i
>= q
->write_ptr
);
200 static inline u8
get_cmd_index(struct iwl3945_queue
*q
, u32 index
, int is_huge
)
202 /* This is for scan command, the big buffer at end of command array */
204 return q
->n_window
; /* must be power of 2 */
206 /* Otherwise, use normal size buffers */
207 return index
& (q
->n_window
- 1);
211 * iwl3945_queue_init - Initialize queue's high/low-water and read/write indexes
213 static int iwl3945_queue_init(struct iwl3945_priv
*priv
, struct iwl3945_queue
*q
,
214 int count
, int slots_num
, u32 id
)
217 q
->n_window
= slots_num
;
220 /* count must be power-of-two size, otherwise iwl_queue_inc_wrap
221 * and iwl_queue_dec_wrap are broken. */
222 BUG_ON(!is_power_of_2(count
));
224 /* slots_num must be power-of-two size, otherwise
225 * get_cmd_index is broken. */
226 BUG_ON(!is_power_of_2(slots_num
));
228 q
->low_mark
= q
->n_window
/ 4;
232 q
->high_mark
= q
->n_window
/ 8;
233 if (q
->high_mark
< 2)
236 q
->write_ptr
= q
->read_ptr
= 0;
242 * iwl3945_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
244 static int iwl3945_tx_queue_alloc(struct iwl3945_priv
*priv
,
245 struct iwl3945_tx_queue
*txq
, u32 id
)
247 struct pci_dev
*dev
= priv
->pci_dev
;
249 /* Driver private data, only for Tx (not command) queues,
250 * not shared with device. */
251 if (id
!= IWL_CMD_QUEUE_NUM
) {
252 txq
->txb
= kmalloc(sizeof(txq
->txb
[0]) *
253 TFD_QUEUE_SIZE_MAX
, GFP_KERNEL
);
255 IWL_ERROR("kmalloc for auxiliary BD "
256 "structures failed\n");
262 /* Circular buffer of transmit frame descriptors (TFDs),
263 * shared with device */
264 txq
->bd
= pci_alloc_consistent(dev
,
265 sizeof(txq
->bd
[0]) * TFD_QUEUE_SIZE_MAX
,
269 IWL_ERROR("pci_alloc_consistent(%zd) failed\n",
270 sizeof(txq
->bd
[0]) * TFD_QUEUE_SIZE_MAX
);
285 * iwl3945_tx_queue_init - Allocate and initialize one tx/cmd queue
287 int iwl3945_tx_queue_init(struct iwl3945_priv
*priv
,
288 struct iwl3945_tx_queue
*txq
, int slots_num
, u32 txq_id
)
290 struct pci_dev
*dev
= priv
->pci_dev
;
295 * Alloc buffer array for commands (Tx or other types of commands).
296 * For the command queue (#4), allocate command space + one big
297 * command for scan, since scan command is very huge; the system will
298 * not have two scans at the same time, so only one is needed.
299 * For data Tx queues (all other queues), no super-size command
302 len
= sizeof(struct iwl3945_cmd
) * slots_num
;
303 if (txq_id
== IWL_CMD_QUEUE_NUM
)
304 len
+= IWL_MAX_SCAN_SIZE
;
305 txq
->cmd
= pci_alloc_consistent(dev
, len
, &txq
->dma_addr_cmd
);
309 /* Alloc driver data array and TFD circular buffer */
310 rc
= iwl3945_tx_queue_alloc(priv
, txq
, txq_id
);
312 pci_free_consistent(dev
, len
, txq
->cmd
, txq
->dma_addr_cmd
);
316 txq
->need_update
= 0;
318 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
319 * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */
320 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX
& (TFD_QUEUE_SIZE_MAX
- 1));
322 /* Initialize queue high/low-water, head/tail indexes */
323 iwl3945_queue_init(priv
, &txq
->q
, TFD_QUEUE_SIZE_MAX
, slots_num
, txq_id
);
325 /* Tell device where to find queue, enable DMA channel. */
326 iwl3945_hw_tx_queue_init(priv
, txq
);
332 * iwl3945_tx_queue_free - Deallocate DMA queue.
333 * @txq: Transmit queue to deallocate.
335 * Empty queue by removing and destroying all BD's.
337 * 0-fill, but do not free "txq" descriptor structure.
339 void iwl3945_tx_queue_free(struct iwl3945_priv
*priv
, struct iwl3945_tx_queue
*txq
)
341 struct iwl3945_queue
*q
= &txq
->q
;
342 struct pci_dev
*dev
= priv
->pci_dev
;
348 /* first, empty all BD's */
349 for (; q
->write_ptr
!= q
->read_ptr
;
350 q
->read_ptr
= iwl_queue_inc_wrap(q
->read_ptr
, q
->n_bd
))
351 iwl3945_hw_txq_free_tfd(priv
, txq
);
353 len
= sizeof(struct iwl3945_cmd
) * q
->n_window
;
354 if (q
->id
== IWL_CMD_QUEUE_NUM
)
355 len
+= IWL_MAX_SCAN_SIZE
;
357 /* De-alloc array of command/tx buffers */
358 pci_free_consistent(dev
, len
, txq
->cmd
, txq
->dma_addr_cmd
);
360 /* De-alloc circular buffer of TFDs */
362 pci_free_consistent(dev
, sizeof(struct iwl3945_tfd_frame
) *
363 txq
->q
.n_bd
, txq
->bd
, txq
->q
.dma_addr
);
365 /* De-alloc array of per-TFD driver data */
369 /* 0-fill queue descriptor structure */
370 memset(txq
, 0, sizeof(*txq
));
373 const u8 iwl3945_broadcast_addr
[ETH_ALEN
] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
375 /*************** STATION TABLE MANAGEMENT ****
376 * mac80211 should be examined to determine if sta_info is duplicating
377 * the functionality provided here
380 /**************************************************************/
381 #if 0 /* temporary disable till we add real remove station */
383 * iwl3945_remove_station - Remove driver's knowledge of station.
385 * NOTE: This does not remove station from device's station table.
387 static u8
iwl3945_remove_station(struct iwl3945_priv
*priv
, const u8
*addr
, int is_ap
)
389 int index
= IWL_INVALID_STATION
;
393 spin_lock_irqsave(&priv
->sta_lock
, flags
);
397 else if (is_broadcast_ether_addr(addr
))
398 index
= priv
->hw_setting
.bcast_sta_id
;
400 for (i
= IWL_STA_ID
; i
< priv
->hw_setting
.max_stations
; i
++)
401 if (priv
->stations
[i
].used
&&
402 !compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
408 if (unlikely(index
== IWL_INVALID_STATION
))
411 if (priv
->stations
[index
].used
) {
412 priv
->stations
[index
].used
= 0;
413 priv
->num_stations
--;
416 BUG_ON(priv
->num_stations
< 0);
419 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
425 * iwl3945_clear_stations_table - Clear the driver's station table
427 * NOTE: This does not clear or otherwise alter the device's station table.
429 static void iwl3945_clear_stations_table(struct iwl3945_priv
*priv
)
433 spin_lock_irqsave(&priv
->sta_lock
, flags
);
435 priv
->num_stations
= 0;
436 memset(priv
->stations
, 0, sizeof(priv
->stations
));
438 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
442 * iwl3945_add_station - Add station to station tables in driver and device
444 u8
iwl3945_add_station(struct iwl3945_priv
*priv
, const u8
*addr
, int is_ap
, u8 flags
)
447 int index
= IWL_INVALID_STATION
;
448 struct iwl3945_station_entry
*station
;
449 unsigned long flags_spin
;
450 DECLARE_MAC_BUF(mac
);
453 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
456 else if (is_broadcast_ether_addr(addr
))
457 index
= priv
->hw_setting
.bcast_sta_id
;
459 for (i
= IWL_STA_ID
; i
< priv
->hw_setting
.max_stations
; i
++) {
460 if (!compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
466 if (!priv
->stations
[i
].used
&&
467 index
== IWL_INVALID_STATION
)
471 /* These two conditions has the same outcome but keep them separate
472 since they have different meaning */
473 if (unlikely(index
== IWL_INVALID_STATION
)) {
474 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
478 if (priv
->stations
[index
].used
&&
479 !compare_ether_addr(priv
->stations
[index
].sta
.sta
.addr
, addr
)) {
480 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
484 IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index
, print_mac(mac
, addr
));
485 station
= &priv
->stations
[index
];
487 priv
->num_stations
++;
489 /* Set up the REPLY_ADD_STA command to send to device */
490 memset(&station
->sta
, 0, sizeof(struct iwl3945_addsta_cmd
));
491 memcpy(station
->sta
.sta
.addr
, addr
, ETH_ALEN
);
492 station
->sta
.mode
= 0;
493 station
->sta
.sta
.sta_id
= index
;
494 station
->sta
.station_flags
= 0;
496 if (priv
->band
== IEEE80211_BAND_5GHZ
)
497 rate
= IWL_RATE_6M_PLCP
;
499 rate
= IWL_RATE_1M_PLCP
;
501 /* Turn on both antennas for the station... */
502 station
->sta
.rate_n_flags
=
503 iwl3945_hw_set_rate_n_flags(rate
, RATE_MCS_ANT_AB_MSK
);
504 station
->current_rate
.rate_n_flags
=
505 le16_to_cpu(station
->sta
.rate_n_flags
);
507 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
509 /* Add station to device's station table */
510 iwl3945_send_add_station(priv
, &station
->sta
, flags
);
515 /*************** DRIVER STATUS FUNCTIONS *****/
517 static inline int iwl3945_is_ready(struct iwl3945_priv
*priv
)
519 /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are
520 * set but EXIT_PENDING is not */
521 return test_bit(STATUS_READY
, &priv
->status
) &&
522 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) &&
523 !test_bit(STATUS_EXIT_PENDING
, &priv
->status
);
526 static inline int iwl3945_is_alive(struct iwl3945_priv
*priv
)
528 return test_bit(STATUS_ALIVE
, &priv
->status
);
531 static inline int iwl3945_is_init(struct iwl3945_priv
*priv
)
533 return test_bit(STATUS_INIT
, &priv
->status
);
536 static inline int iwl3945_is_rfkill_sw(struct iwl3945_priv
*priv
)
538 return test_bit(STATUS_RF_KILL_SW
, &priv
->status
);
541 static inline int iwl3945_is_rfkill_hw(struct iwl3945_priv
*priv
)
543 return test_bit(STATUS_RF_KILL_HW
, &priv
->status
);
546 static inline int iwl3945_is_rfkill(struct iwl3945_priv
*priv
)
548 return iwl3945_is_rfkill_hw(priv
) ||
549 iwl3945_is_rfkill_sw(priv
);
552 static inline int iwl3945_is_ready_rf(struct iwl3945_priv
*priv
)
555 if (iwl3945_is_rfkill(priv
))
558 return iwl3945_is_ready(priv
);
561 /*************** HOST COMMAND QUEUE FUNCTIONS *****/
563 #define IWL_CMD(x) case x : return #x
565 static const char *get_cmd_string(u8 cmd
)
568 IWL_CMD(REPLY_ALIVE
);
569 IWL_CMD(REPLY_ERROR
);
571 IWL_CMD(REPLY_RXON_ASSOC
);
572 IWL_CMD(REPLY_QOS_PARAM
);
573 IWL_CMD(REPLY_RXON_TIMING
);
574 IWL_CMD(REPLY_ADD_STA
);
575 IWL_CMD(REPLY_REMOVE_STA
);
576 IWL_CMD(REPLY_REMOVE_ALL_STA
);
577 IWL_CMD(REPLY_3945_RX
);
579 IWL_CMD(REPLY_RATE_SCALE
);
580 IWL_CMD(REPLY_LEDS_CMD
);
581 IWL_CMD(REPLY_TX_LINK_QUALITY_CMD
);
582 IWL_CMD(RADAR_NOTIFICATION
);
583 IWL_CMD(REPLY_QUIET_CMD
);
584 IWL_CMD(REPLY_CHANNEL_SWITCH
);
585 IWL_CMD(CHANNEL_SWITCH_NOTIFICATION
);
586 IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD
);
587 IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION
);
588 IWL_CMD(POWER_TABLE_CMD
);
589 IWL_CMD(PM_SLEEP_NOTIFICATION
);
590 IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC
);
591 IWL_CMD(REPLY_SCAN_CMD
);
592 IWL_CMD(REPLY_SCAN_ABORT_CMD
);
593 IWL_CMD(SCAN_START_NOTIFICATION
);
594 IWL_CMD(SCAN_RESULTS_NOTIFICATION
);
595 IWL_CMD(SCAN_COMPLETE_NOTIFICATION
);
596 IWL_CMD(BEACON_NOTIFICATION
);
597 IWL_CMD(REPLY_TX_BEACON
);
598 IWL_CMD(WHO_IS_AWAKE_NOTIFICATION
);
599 IWL_CMD(QUIET_NOTIFICATION
);
600 IWL_CMD(REPLY_TX_PWR_TABLE_CMD
);
601 IWL_CMD(MEASURE_ABORT_NOTIFICATION
);
602 IWL_CMD(REPLY_BT_CONFIG
);
603 IWL_CMD(REPLY_STATISTICS_CMD
);
604 IWL_CMD(STATISTICS_NOTIFICATION
);
605 IWL_CMD(REPLY_CARD_STATE_CMD
);
606 IWL_CMD(CARD_STATE_NOTIFICATION
);
607 IWL_CMD(MISSED_BEACONS_NOTIFICATION
);
614 #define HOST_COMPLETE_TIMEOUT (HZ / 2)
617 * iwl3945_enqueue_hcmd - enqueue a uCode command
618 * @priv: device private data point
619 * @cmd: a point to the ucode command structure
621 * The function returns < 0 values to indicate the operation is
622 * failed. On success, it turns the index (> 0) of command in the
625 static int iwl3945_enqueue_hcmd(struct iwl3945_priv
*priv
, struct iwl3945_host_cmd
*cmd
)
627 struct iwl3945_tx_queue
*txq
= &priv
->txq
[IWL_CMD_QUEUE_NUM
];
628 struct iwl3945_queue
*q
= &txq
->q
;
629 struct iwl3945_tfd_frame
*tfd
;
631 struct iwl3945_cmd
*out_cmd
;
633 u16 fix_size
= (u16
)(cmd
->len
+ sizeof(out_cmd
->hdr
));
634 dma_addr_t phys_addr
;
640 /* If any of the command structures end up being larger than
641 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
642 * we will need to increase the size of the TFD entries */
643 BUG_ON((fix_size
> TFD_MAX_PAYLOAD_SIZE
) &&
644 !(cmd
->meta
.flags
& CMD_SIZE_HUGE
));
647 if (iwl3945_is_rfkill(priv
)) {
648 IWL_DEBUG_INFO("Not sending command - RF KILL");
652 if (iwl3945_queue_space(q
) < ((cmd
->meta
.flags
& CMD_ASYNC
) ? 2 : 1)) {
653 IWL_ERROR("No space for Tx\n");
657 spin_lock_irqsave(&priv
->hcmd_lock
, flags
);
659 tfd
= &txq
->bd
[q
->write_ptr
];
660 memset(tfd
, 0, sizeof(*tfd
));
662 control_flags
= (u32
*) tfd
;
664 idx
= get_cmd_index(q
, q
->write_ptr
, cmd
->meta
.flags
& CMD_SIZE_HUGE
);
665 out_cmd
= &txq
->cmd
[idx
];
667 out_cmd
->hdr
.cmd
= cmd
->id
;
668 memcpy(&out_cmd
->meta
, &cmd
->meta
, sizeof(cmd
->meta
));
669 memcpy(&out_cmd
->cmd
.payload
, cmd
->data
, cmd
->len
);
671 /* At this point, the out_cmd now has all of the incoming cmd
674 out_cmd
->hdr
.flags
= 0;
675 out_cmd
->hdr
.sequence
= cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM
) |
676 INDEX_TO_SEQ(q
->write_ptr
));
677 if (out_cmd
->meta
.flags
& CMD_SIZE_HUGE
)
678 out_cmd
->hdr
.sequence
|= cpu_to_le16(SEQ_HUGE_FRAME
);
680 phys_addr
= txq
->dma_addr_cmd
+ sizeof(txq
->cmd
[0]) * idx
+
681 offsetof(struct iwl3945_cmd
, hdr
);
682 iwl3945_hw_txq_attach_buf_to_tfd(priv
, tfd
, phys_addr
, fix_size
);
684 pad
= U32_PAD(cmd
->len
);
685 count
= TFD_CTL_COUNT_GET(*control_flags
);
686 *control_flags
= TFD_CTL_COUNT_SET(count
) | TFD_CTL_PAD_SET(pad
);
688 IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
689 "%d bytes at %d[%d]:%d\n",
690 get_cmd_string(out_cmd
->hdr
.cmd
),
691 out_cmd
->hdr
.cmd
, le16_to_cpu(out_cmd
->hdr
.sequence
),
692 fix_size
, q
->write_ptr
, idx
, IWL_CMD_QUEUE_NUM
);
694 txq
->need_update
= 1;
696 /* Increment and update queue's write index */
697 q
->write_ptr
= iwl_queue_inc_wrap(q
->write_ptr
, q
->n_bd
);
698 ret
= iwl3945_tx_queue_update_write_ptr(priv
, txq
);
700 spin_unlock_irqrestore(&priv
->hcmd_lock
, flags
);
701 return ret
? ret
: idx
;
704 static int iwl3945_send_cmd_async(struct iwl3945_priv
*priv
, struct iwl3945_host_cmd
*cmd
)
708 BUG_ON(!(cmd
->meta
.flags
& CMD_ASYNC
));
710 /* An asynchronous command can not expect an SKB to be set. */
711 BUG_ON(cmd
->meta
.flags
& CMD_WANT_SKB
);
713 /* An asynchronous command MUST have a callback. */
714 BUG_ON(!cmd
->meta
.u
.callback
);
716 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
719 ret
= iwl3945_enqueue_hcmd(priv
, cmd
);
721 IWL_ERROR("Error sending %s: iwl3945_enqueue_hcmd failed: %d\n",
722 get_cmd_string(cmd
->id
), ret
);
728 static int iwl3945_send_cmd_sync(struct iwl3945_priv
*priv
, struct iwl3945_host_cmd
*cmd
)
733 BUG_ON(cmd
->meta
.flags
& CMD_ASYNC
);
735 /* A synchronous command can not have a callback set. */
736 BUG_ON(cmd
->meta
.u
.callback
!= NULL
);
738 if (test_and_set_bit(STATUS_HCMD_SYNC_ACTIVE
, &priv
->status
)) {
739 IWL_ERROR("Error sending %s: Already sending a host command\n",
740 get_cmd_string(cmd
->id
));
745 set_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
747 if (cmd
->meta
.flags
& CMD_WANT_SKB
)
748 cmd
->meta
.source
= &cmd
->meta
;
750 cmd_idx
= iwl3945_enqueue_hcmd(priv
, cmd
);
753 IWL_ERROR("Error sending %s: iwl3945_enqueue_hcmd failed: %d\n",
754 get_cmd_string(cmd
->id
), ret
);
758 ret
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
759 !test_bit(STATUS_HCMD_ACTIVE
, &priv
->status
),
760 HOST_COMPLETE_TIMEOUT
);
762 if (test_bit(STATUS_HCMD_ACTIVE
, &priv
->status
)) {
763 IWL_ERROR("Error sending %s: time out after %dms.\n",
764 get_cmd_string(cmd
->id
),
765 jiffies_to_msecs(HOST_COMPLETE_TIMEOUT
));
767 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
773 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) {
774 IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n",
775 get_cmd_string(cmd
->id
));
779 if (test_bit(STATUS_FW_ERROR
, &priv
->status
)) {
780 IWL_DEBUG_INFO("Command %s failed: FW Error\n",
781 get_cmd_string(cmd
->id
));
785 if ((cmd
->meta
.flags
& CMD_WANT_SKB
) && !cmd
->meta
.u
.skb
) {
786 IWL_ERROR("Error: Response NULL in '%s'\n",
787 get_cmd_string(cmd
->id
));
796 if (cmd
->meta
.flags
& CMD_WANT_SKB
) {
797 struct iwl3945_cmd
*qcmd
;
799 /* Cancel the CMD_WANT_SKB flag for the cmd in the
800 * TX cmd queue. Otherwise in case the cmd comes
801 * in later, it will possibly set an invalid
802 * address (cmd->meta.source). */
803 qcmd
= &priv
->txq
[IWL_CMD_QUEUE_NUM
].cmd
[cmd_idx
];
804 qcmd
->meta
.flags
&= ~CMD_WANT_SKB
;
807 if (cmd
->meta
.u
.skb
) {
808 dev_kfree_skb_any(cmd
->meta
.u
.skb
);
809 cmd
->meta
.u
.skb
= NULL
;
812 clear_bit(STATUS_HCMD_SYNC_ACTIVE
, &priv
->status
);
816 int iwl3945_send_cmd(struct iwl3945_priv
*priv
, struct iwl3945_host_cmd
*cmd
)
818 if (cmd
->meta
.flags
& CMD_ASYNC
)
819 return iwl3945_send_cmd_async(priv
, cmd
);
821 return iwl3945_send_cmd_sync(priv
, cmd
);
824 int iwl3945_send_cmd_pdu(struct iwl3945_priv
*priv
, u8 id
, u16 len
, const void *data
)
826 struct iwl3945_host_cmd cmd
= {
832 return iwl3945_send_cmd_sync(priv
, &cmd
);
835 static int __must_check
iwl3945_send_cmd_u32(struct iwl3945_priv
*priv
, u8 id
, u32 val
)
837 struct iwl3945_host_cmd cmd
= {
843 return iwl3945_send_cmd_sync(priv
, &cmd
);
846 int iwl3945_send_statistics_request(struct iwl3945_priv
*priv
)
848 return iwl3945_send_cmd_u32(priv
, REPLY_STATISTICS_CMD
, 0);
852 * iwl3945_set_rxon_channel - Set the phymode and channel values in staging RXON
853 * @band: 2.4 or 5 GHz band
854 * @channel: Any channel valid for the requested band
856 * In addition to setting the staging RXON, priv->band is also set.
858 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
859 * in the staging RXON flag structure based on the band
861 static int iwl3945_set_rxon_channel(struct iwl3945_priv
*priv
,
862 enum ieee80211_band band
,
865 if (!iwl3945_get_channel_info(priv
, band
, channel
)) {
866 IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
871 if ((le16_to_cpu(priv
->staging_rxon
.channel
) == channel
) &&
872 (priv
->band
== band
))
875 priv
->staging_rxon
.channel
= cpu_to_le16(channel
);
876 if (band
== IEEE80211_BAND_5GHZ
)
877 priv
->staging_rxon
.flags
&= ~RXON_FLG_BAND_24G_MSK
;
879 priv
->staging_rxon
.flags
|= RXON_FLG_BAND_24G_MSK
;
883 IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel
, band
);
889 * iwl3945_check_rxon_cmd - validate RXON structure is valid
891 * NOTE: This is really only useful during development and can eventually
892 * be #ifdef'd out once the driver is stable and folks aren't actively
895 static int iwl3945_check_rxon_cmd(struct iwl3945_rxon_cmd
*rxon
)
900 if (rxon
->flags
& RXON_FLG_BAND_24G_MSK
) {
901 error
|= le32_to_cpu(rxon
->flags
&
902 (RXON_FLG_TGJ_NARROW_BAND_MSK
|
903 RXON_FLG_RADAR_DETECT_MSK
));
905 IWL_WARNING("check 24G fields %d | %d\n",
908 error
|= (rxon
->flags
& RXON_FLG_SHORT_SLOT_MSK
) ?
909 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK
);
911 IWL_WARNING("check 52 fields %d | %d\n",
913 error
|= le32_to_cpu(rxon
->flags
& RXON_FLG_CCK_MSK
);
915 IWL_WARNING("check 52 CCK %d | %d\n",
918 error
|= (rxon
->node_addr
[0] | rxon
->bssid_addr
[0]) & 0x1;
920 IWL_WARNING("check mac addr %d | %d\n", counter
++, error
);
922 /* make sure basic rates 6Mbps and 1Mbps are supported */
923 error
|= (((rxon
->ofdm_basic_rates
& IWL_RATE_6M_MASK
) == 0) &&
924 ((rxon
->cck_basic_rates
& IWL_RATE_1M_MASK
) == 0));
926 IWL_WARNING("check basic rate %d | %d\n", counter
++, error
);
928 error
|= (le16_to_cpu(rxon
->assoc_id
) > 2007);
930 IWL_WARNING("check assoc id %d | %d\n", counter
++, error
);
932 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
))
933 == (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
));
935 IWL_WARNING("check CCK and short slot %d | %d\n",
938 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
))
939 == (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
));
941 IWL_WARNING("check CCK & auto detect %d | %d\n",
944 error
|= ((rxon
->flags
& (RXON_FLG_AUTO_DETECT_MSK
|
945 RXON_FLG_TGG_PROTECT_MSK
)) == RXON_FLG_TGG_PROTECT_MSK
);
947 IWL_WARNING("check TGG and auto detect %d | %d\n",
950 if ((rxon
->flags
& RXON_FLG_DIS_DIV_MSK
))
951 error
|= ((rxon
->flags
& (RXON_FLG_ANT_B_MSK
|
952 RXON_FLG_ANT_A_MSK
)) == 0);
954 IWL_WARNING("check antenna %d %d\n", counter
++, error
);
957 IWL_WARNING("Tuning to channel %d\n",
958 le16_to_cpu(rxon
->channel
));
961 IWL_ERROR("Not a valid iwl3945_rxon_assoc_cmd field values\n");
968 * iwl3945_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
969 * @priv: staging_rxon is compared to active_rxon
971 * If the RXON structure is changing enough to require a new tune,
972 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
973 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
975 static int iwl3945_full_rxon_required(struct iwl3945_priv
*priv
)
978 /* These items are only settable from the full RXON command */
979 if (!(iwl3945_is_associated(priv
)) ||
980 compare_ether_addr(priv
->staging_rxon
.bssid_addr
,
981 priv
->active_rxon
.bssid_addr
) ||
982 compare_ether_addr(priv
->staging_rxon
.node_addr
,
983 priv
->active_rxon
.node_addr
) ||
984 compare_ether_addr(priv
->staging_rxon
.wlap_bssid_addr
,
985 priv
->active_rxon
.wlap_bssid_addr
) ||
986 (priv
->staging_rxon
.dev_type
!= priv
->active_rxon
.dev_type
) ||
987 (priv
->staging_rxon
.channel
!= priv
->active_rxon
.channel
) ||
988 (priv
->staging_rxon
.air_propagation
!=
989 priv
->active_rxon
.air_propagation
) ||
990 (priv
->staging_rxon
.assoc_id
!= priv
->active_rxon
.assoc_id
))
993 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
994 * be updated with the RXON_ASSOC command -- however only some
995 * flag transitions are allowed using RXON_ASSOC */
997 /* Check if we are not switching bands */
998 if ((priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) !=
999 (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
))
1002 /* Check if we are switching association toggle */
1003 if ((priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) !=
1004 (priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
))
1010 static int iwl3945_send_rxon_assoc(struct iwl3945_priv
*priv
)
1013 struct iwl3945_rx_packet
*res
= NULL
;
1014 struct iwl3945_rxon_assoc_cmd rxon_assoc
;
1015 struct iwl3945_host_cmd cmd
= {
1016 .id
= REPLY_RXON_ASSOC
,
1017 .len
= sizeof(rxon_assoc
),
1018 .meta
.flags
= CMD_WANT_SKB
,
1019 .data
= &rxon_assoc
,
1021 const struct iwl3945_rxon_cmd
*rxon1
= &priv
->staging_rxon
;
1022 const struct iwl3945_rxon_cmd
*rxon2
= &priv
->active_rxon
;
1024 if ((rxon1
->flags
== rxon2
->flags
) &&
1025 (rxon1
->filter_flags
== rxon2
->filter_flags
) &&
1026 (rxon1
->cck_basic_rates
== rxon2
->cck_basic_rates
) &&
1027 (rxon1
->ofdm_basic_rates
== rxon2
->ofdm_basic_rates
)) {
1028 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
1032 rxon_assoc
.flags
= priv
->staging_rxon
.flags
;
1033 rxon_assoc
.filter_flags
= priv
->staging_rxon
.filter_flags
;
1034 rxon_assoc
.ofdm_basic_rates
= priv
->staging_rxon
.ofdm_basic_rates
;
1035 rxon_assoc
.cck_basic_rates
= priv
->staging_rxon
.cck_basic_rates
;
1036 rxon_assoc
.reserved
= 0;
1038 rc
= iwl3945_send_cmd_sync(priv
, &cmd
);
1042 res
= (struct iwl3945_rx_packet
*)cmd
.meta
.u
.skb
->data
;
1043 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1044 IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n");
1048 priv
->alloc_rxb_skb
--;
1049 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1055 * iwl3945_commit_rxon - commit staging_rxon to hardware
1057 * The RXON command in staging_rxon is committed to the hardware and
1058 * the active_rxon structure is updated with the new data. This
1059 * function correctly transitions out of the RXON_ASSOC_MSK state if
1060 * a HW tune is required based on the RXON structure changes.
1062 static int iwl3945_commit_rxon(struct iwl3945_priv
*priv
)
1064 /* cast away the const for active_rxon in this function */
1065 struct iwl3945_rxon_cmd
*active_rxon
= (void *)&priv
->active_rxon
;
1067 DECLARE_MAC_BUF(mac
);
1069 if (!iwl3945_is_alive(priv
))
1072 /* always get timestamp with Rx frame */
1073 priv
->staging_rxon
.flags
|= RXON_FLG_TSF2HOST_MSK
;
1075 /* select antenna */
1076 priv
->staging_rxon
.flags
&=
1077 ~(RXON_FLG_DIS_DIV_MSK
| RXON_FLG_ANT_SEL_MSK
);
1078 priv
->staging_rxon
.flags
|= iwl3945_get_antenna_flags(priv
);
1080 rc
= iwl3945_check_rxon_cmd(&priv
->staging_rxon
);
1082 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
1086 /* If we don't need to send a full RXON, we can use
1087 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
1088 * and other flags for the current radio configuration. */
1089 if (!iwl3945_full_rxon_required(priv
)) {
1090 rc
= iwl3945_send_rxon_assoc(priv
);
1092 IWL_ERROR("Error setting RXON_ASSOC "
1093 "configuration (%d).\n", rc
);
1097 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
1102 /* If we are currently associated and the new config requires
1103 * an RXON_ASSOC and the new config wants the associated mask enabled,
1104 * we must clear the associated from the active configuration
1105 * before we apply the new config */
1106 if (iwl3945_is_associated(priv
) &&
1107 (priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
)) {
1108 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
1109 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
1111 rc
= iwl3945_send_cmd_pdu(priv
, REPLY_RXON
,
1112 sizeof(struct iwl3945_rxon_cmd
),
1113 &priv
->active_rxon
);
1115 /* If the mask clearing failed then we set
1116 * active_rxon back to what it was previously */
1118 active_rxon
->filter_flags
|= RXON_FILTER_ASSOC_MSK
;
1119 IWL_ERROR("Error clearing ASSOC_MSK on current "
1120 "configuration (%d).\n", rc
);
1125 IWL_DEBUG_INFO("Sending RXON\n"
1126 "* with%s RXON_FILTER_ASSOC_MSK\n"
1129 ((priv
->staging_rxon
.filter_flags
&
1130 RXON_FILTER_ASSOC_MSK
) ? "" : "out"),
1131 le16_to_cpu(priv
->staging_rxon
.channel
),
1132 print_mac(mac
, priv
->staging_rxon
.bssid_addr
));
1134 /* Apply the new configuration */
1135 rc
= iwl3945_send_cmd_pdu(priv
, REPLY_RXON
,
1136 sizeof(struct iwl3945_rxon_cmd
), &priv
->staging_rxon
);
1138 IWL_ERROR("Error setting new configuration (%d).\n", rc
);
1142 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
1144 iwl3945_clear_stations_table(priv
);
1146 /* If we issue a new RXON command which required a tune then we must
1147 * send a new TXPOWER command or we won't be able to Tx any frames */
1148 rc
= iwl3945_hw_reg_send_txpower(priv
);
1150 IWL_ERROR("Error setting Tx power (%d).\n", rc
);
1154 /* Add the broadcast address so we can send broadcast frames */
1155 if (iwl3945_add_station(priv
, iwl3945_broadcast_addr
, 0, 0) ==
1156 IWL_INVALID_STATION
) {
1157 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
1161 /* If we have set the ASSOC_MSK and we are in BSS mode then
1162 * add the IWL_AP_ID to the station rate table */
1163 if (iwl3945_is_associated(priv
) &&
1164 (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
1165 if (iwl3945_add_station(priv
, priv
->active_rxon
.bssid_addr
, 1, 0)
1166 == IWL_INVALID_STATION
) {
1167 IWL_ERROR("Error adding AP address for transmit.\n");
1171 /* Init the hardware's rate fallback order based on the band */
1172 rc
= iwl3945_init_hw_rate_table(priv
);
1174 IWL_ERROR("Error setting HW rate table: %02X\n", rc
);
1181 static int iwl3945_send_bt_config(struct iwl3945_priv
*priv
)
1183 struct iwl3945_bt_cmd bt_cmd
= {
1191 return iwl3945_send_cmd_pdu(priv
, REPLY_BT_CONFIG
,
1192 sizeof(struct iwl3945_bt_cmd
), &bt_cmd
);
1195 static int iwl3945_send_scan_abort(struct iwl3945_priv
*priv
)
1198 struct iwl3945_rx_packet
*res
;
1199 struct iwl3945_host_cmd cmd
= {
1200 .id
= REPLY_SCAN_ABORT_CMD
,
1201 .meta
.flags
= CMD_WANT_SKB
,
1204 /* If there isn't a scan actively going on in the hardware
1205 * then we are in between scan bands and not actually
1206 * actively scanning, so don't send the abort command */
1207 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
1208 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1212 rc
= iwl3945_send_cmd_sync(priv
, &cmd
);
1214 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1218 res
= (struct iwl3945_rx_packet
*)cmd
.meta
.u
.skb
->data
;
1219 if (res
->u
.status
!= CAN_ABORT_STATUS
) {
1220 /* The scan abort will return 1 for success or
1221 * 2 for "failure". A failure condition can be
1222 * due to simply not being in an active scan which
1223 * can occur if we send the scan abort before we
1224 * the microcode has notified us that a scan is
1226 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res
->u
.status
);
1227 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1228 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
1231 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1236 static int iwl3945_card_state_sync_callback(struct iwl3945_priv
*priv
,
1237 struct iwl3945_cmd
*cmd
,
1238 struct sk_buff
*skb
)
1246 * Use: Sets the device's internal card state to enable, disable, or halt
1248 * When in the 'enable' state the card operates as normal.
1249 * When in the 'disable' state, the card enters into a low power mode.
1250 * When in the 'halt' state, the card is shut down and must be fully
1251 * restarted to come back on.
1253 static int iwl3945_send_card_state(struct iwl3945_priv
*priv
, u32 flags
, u8 meta_flag
)
1255 struct iwl3945_host_cmd cmd
= {
1256 .id
= REPLY_CARD_STATE_CMD
,
1259 .meta
.flags
= meta_flag
,
1262 if (meta_flag
& CMD_ASYNC
)
1263 cmd
.meta
.u
.callback
= iwl3945_card_state_sync_callback
;
1265 return iwl3945_send_cmd(priv
, &cmd
);
1268 static int iwl3945_add_sta_sync_callback(struct iwl3945_priv
*priv
,
1269 struct iwl3945_cmd
*cmd
, struct sk_buff
*skb
)
1271 struct iwl3945_rx_packet
*res
= NULL
;
1274 IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
1278 res
= (struct iwl3945_rx_packet
*)skb
->data
;
1279 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1280 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1285 switch (res
->u
.add_sta
.status
) {
1286 case ADD_STA_SUCCESS_MSK
:
1292 /* We didn't cache the SKB; let the caller free it */
1296 int iwl3945_send_add_station(struct iwl3945_priv
*priv
,
1297 struct iwl3945_addsta_cmd
*sta
, u8 flags
)
1299 struct iwl3945_rx_packet
*res
= NULL
;
1301 struct iwl3945_host_cmd cmd
= {
1302 .id
= REPLY_ADD_STA
,
1303 .len
= sizeof(struct iwl3945_addsta_cmd
),
1304 .meta
.flags
= flags
,
1308 if (flags
& CMD_ASYNC
)
1309 cmd
.meta
.u
.callback
= iwl3945_add_sta_sync_callback
;
1311 cmd
.meta
.flags
|= CMD_WANT_SKB
;
1313 rc
= iwl3945_send_cmd(priv
, &cmd
);
1315 if (rc
|| (flags
& CMD_ASYNC
))
1318 res
= (struct iwl3945_rx_packet
*)cmd
.meta
.u
.skb
->data
;
1319 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1320 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1326 switch (res
->u
.add_sta
.status
) {
1327 case ADD_STA_SUCCESS_MSK
:
1328 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
1332 IWL_WARNING("REPLY_ADD_STA failed\n");
1337 priv
->alloc_rxb_skb
--;
1338 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1343 static int iwl3945_update_sta_key_info(struct iwl3945_priv
*priv
,
1344 struct ieee80211_key_conf
*keyconf
,
1347 unsigned long flags
;
1348 __le16 key_flags
= 0;
1350 switch (keyconf
->alg
) {
1352 key_flags
|= STA_KEY_FLG_CCMP
;
1353 key_flags
|= cpu_to_le16(
1354 keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
1355 key_flags
&= ~STA_KEY_FLG_INVALID
;
1362 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1363 priv
->stations
[sta_id
].keyinfo
.alg
= keyconf
->alg
;
1364 priv
->stations
[sta_id
].keyinfo
.keylen
= keyconf
->keylen
;
1365 memcpy(priv
->stations
[sta_id
].keyinfo
.key
, keyconf
->key
,
1368 memcpy(priv
->stations
[sta_id
].sta
.key
.key
, keyconf
->key
,
1370 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
1371 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1372 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1374 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1376 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
1377 iwl3945_send_add_station(priv
, &priv
->stations
[sta_id
].sta
, 0);
1381 static int iwl3945_clear_sta_key_info(struct iwl3945_priv
*priv
, u8 sta_id
)
1383 unsigned long flags
;
1385 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1386 memset(&priv
->stations
[sta_id
].keyinfo
, 0, sizeof(struct iwl3945_hw_key
));
1387 memset(&priv
->stations
[sta_id
].sta
.key
, 0, sizeof(struct iwl3945_keyinfo
));
1388 priv
->stations
[sta_id
].sta
.key
.key_flags
= STA_KEY_FLG_NO_ENC
;
1389 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1390 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1391 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1393 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
1394 iwl3945_send_add_station(priv
, &priv
->stations
[sta_id
].sta
, 0);
1398 static void iwl3945_clear_free_frames(struct iwl3945_priv
*priv
)
1400 struct list_head
*element
;
1402 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
1403 priv
->frames_count
);
1405 while (!list_empty(&priv
->free_frames
)) {
1406 element
= priv
->free_frames
.next
;
1408 kfree(list_entry(element
, struct iwl3945_frame
, list
));
1409 priv
->frames_count
--;
1412 if (priv
->frames_count
) {
1413 IWL_WARNING("%d frames still in use. Did we lose one?\n",
1414 priv
->frames_count
);
1415 priv
->frames_count
= 0;
1419 static struct iwl3945_frame
*iwl3945_get_free_frame(struct iwl3945_priv
*priv
)
1421 struct iwl3945_frame
*frame
;
1422 struct list_head
*element
;
1423 if (list_empty(&priv
->free_frames
)) {
1424 frame
= kzalloc(sizeof(*frame
), GFP_KERNEL
);
1426 IWL_ERROR("Could not allocate frame!\n");
1430 priv
->frames_count
++;
1434 element
= priv
->free_frames
.next
;
1436 return list_entry(element
, struct iwl3945_frame
, list
);
1439 static void iwl3945_free_frame(struct iwl3945_priv
*priv
, struct iwl3945_frame
*frame
)
1441 memset(frame
, 0, sizeof(*frame
));
1442 list_add(&frame
->list
, &priv
->free_frames
);
1445 unsigned int iwl3945_fill_beacon_frame(struct iwl3945_priv
*priv
,
1446 struct ieee80211_hdr
*hdr
,
1447 const u8
*dest
, int left
)
1450 if (!iwl3945_is_associated(priv
) || !priv
->ibss_beacon
||
1451 ((priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) &&
1452 (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
)))
1455 if (priv
->ibss_beacon
->len
> left
)
1458 memcpy(hdr
, priv
->ibss_beacon
->data
, priv
->ibss_beacon
->len
);
1460 return priv
->ibss_beacon
->len
;
1463 static u8
iwl3945_rate_get_lowest_plcp(int rate_mask
)
1467 for (i
= IWL_RATE_1M_INDEX
; i
!= IWL_RATE_INVALID
;
1468 i
= iwl3945_rates
[i
].next_ieee
) {
1469 if (rate_mask
& (1 << i
))
1470 return iwl3945_rates
[i
].plcp
;
1473 return IWL_RATE_INVALID
;
1476 static int iwl3945_send_beacon_cmd(struct iwl3945_priv
*priv
)
1478 struct iwl3945_frame
*frame
;
1479 unsigned int frame_size
;
1483 frame
= iwl3945_get_free_frame(priv
);
1486 IWL_ERROR("Could not obtain free frame buffer for beacon "
1491 if (!(priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)) {
1492 rate
= iwl3945_rate_get_lowest_plcp(priv
->active_rate_basic
&
1494 if (rate
== IWL_INVALID_RATE
)
1495 rate
= IWL_RATE_6M_PLCP
;
1497 rate
= iwl3945_rate_get_lowest_plcp(priv
->active_rate_basic
& 0xF);
1498 if (rate
== IWL_INVALID_RATE
)
1499 rate
= IWL_RATE_1M_PLCP
;
1502 frame_size
= iwl3945_hw_get_beacon_cmd(priv
, frame
, rate
);
1504 rc
= iwl3945_send_cmd_pdu(priv
, REPLY_TX_BEACON
, frame_size
,
1507 iwl3945_free_frame(priv
, frame
);
1512 /******************************************************************************
1514 * EEPROM related functions
1516 ******************************************************************************/
1518 static void get_eeprom_mac(struct iwl3945_priv
*priv
, u8
*mac
)
1520 memcpy(mac
, priv
->eeprom
.mac_address
, 6);
1524 * Clear the OWNER_MSK, to establish driver (instead of uCode running on
1525 * embedded controller) as EEPROM reader; each read is a series of pulses
1526 * to/from the EEPROM chip, not a single event, so even reads could conflict
1527 * if they weren't arbitrated by some ownership mechanism. Here, the driver
1528 * simply claims ownership, which should be safe when this function is called
1529 * (i.e. before loading uCode!).
1531 static inline int iwl3945_eeprom_acquire_semaphore(struct iwl3945_priv
*priv
)
1533 _iwl3945_clear_bit(priv
, CSR_EEPROM_GP
, CSR_EEPROM_GP_IF_OWNER_MSK
);
1538 * iwl3945_eeprom_init - read EEPROM contents
1540 * Load the EEPROM contents from adapter into priv->eeprom
1542 * NOTE: This routine uses the non-debug IO access functions.
1544 int iwl3945_eeprom_init(struct iwl3945_priv
*priv
)
1546 u16
*e
= (u16
*)&priv
->eeprom
;
1547 u32 gp
= iwl3945_read32(priv
, CSR_EEPROM_GP
);
1549 int sz
= sizeof(priv
->eeprom
);
1554 /* The EEPROM structure has several padding buffers within it
1555 * and when adding new EEPROM maps is subject to programmer errors
1556 * which may be very difficult to identify without explicitly
1557 * checking the resulting size of the eeprom map. */
1558 BUILD_BUG_ON(sizeof(priv
->eeprom
) != IWL_EEPROM_IMAGE_SIZE
);
1560 if ((gp
& CSR_EEPROM_GP_VALID_MSK
) == CSR_EEPROM_GP_BAD_SIGNATURE
) {
1561 IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x\n", gp
);
1565 /* Make sure driver (instead of uCode) is allowed to read EEPROM */
1566 rc
= iwl3945_eeprom_acquire_semaphore(priv
);
1568 IWL_ERROR("Failed to acquire EEPROM semaphore.\n");
1572 /* eeprom is an array of 16bit values */
1573 for (addr
= 0; addr
< sz
; addr
+= sizeof(u16
)) {
1574 _iwl3945_write32(priv
, CSR_EEPROM_REG
, addr
<< 1);
1575 _iwl3945_clear_bit(priv
, CSR_EEPROM_REG
, CSR_EEPROM_REG_BIT_CMD
);
1577 for (i
= 0; i
< IWL_EEPROM_ACCESS_TIMEOUT
;
1578 i
+= IWL_EEPROM_ACCESS_DELAY
) {
1579 r
= _iwl3945_read_direct32(priv
, CSR_EEPROM_REG
);
1580 if (r
& CSR_EEPROM_REG_READ_VALID_MSK
)
1582 udelay(IWL_EEPROM_ACCESS_DELAY
);
1585 if (!(r
& CSR_EEPROM_REG_READ_VALID_MSK
)) {
1586 IWL_ERROR("Time out reading EEPROM[%d]\n", addr
);
1589 e
[addr
/ 2] = le16_to_cpu((__force __le16
)(r
>> 16));
1595 static void iwl3945_unset_hw_setting(struct iwl3945_priv
*priv
)
1597 if (priv
->hw_setting
.shared_virt
)
1598 pci_free_consistent(priv
->pci_dev
,
1599 sizeof(struct iwl3945_shared
),
1600 priv
->hw_setting
.shared_virt
,
1601 priv
->hw_setting
.shared_phys
);
1605 * iwl3945_supported_rate_to_ie - fill in the supported rate in IE field
1607 * return : set the bit for each supported rate insert in ie
1609 static u16
iwl3945_supported_rate_to_ie(u8
*ie
, u16 supported_rate
,
1610 u16 basic_rate
, int *left
)
1612 u16 ret_rates
= 0, bit
;
1617 for (bit
= 1, i
= 0; i
< IWL_RATE_COUNT
; i
++, bit
<<= 1) {
1618 if (bit
& supported_rate
) {
1620 rates
[*cnt
] = iwl3945_rates
[i
].ieee
|
1621 ((bit
& basic_rate
) ? 0x80 : 0x00);
1625 (*cnt
>= IWL_SUPPORTED_RATES_IE_LEN
))
1634 * iwl3945_fill_probe_req - fill in all required fields and IE for probe request
1636 static u16
iwl3945_fill_probe_req(struct iwl3945_priv
*priv
,
1637 struct ieee80211_mgmt
*frame
,
1638 int left
, int is_direct
)
1642 u16 active_rates
, ret_rates
, cck_rates
;
1644 /* Make sure there is enough space for the probe request,
1645 * two mandatory IEs and the data */
1651 frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
1652 memcpy(frame
->da
, iwl3945_broadcast_addr
, ETH_ALEN
);
1653 memcpy(frame
->sa
, priv
->mac_addr
, ETH_ALEN
);
1654 memcpy(frame
->bssid
, iwl3945_broadcast_addr
, ETH_ALEN
);
1655 frame
->seq_ctrl
= 0;
1657 /* fill in our indirect SSID IE */
1664 pos
= &(frame
->u
.probe_req
.variable
[0]);
1665 *pos
++ = WLAN_EID_SSID
;
1668 /* fill in our direct SSID IE... */
1671 left
-= 2 + priv
->essid_len
;
1674 /* ... fill it in... */
1675 *pos
++ = WLAN_EID_SSID
;
1676 *pos
++ = priv
->essid_len
;
1677 memcpy(pos
, priv
->essid
, priv
->essid_len
);
1678 pos
+= priv
->essid_len
;
1679 len
+= 2 + priv
->essid_len
;
1682 /* fill in supported rate */
1688 /* ... fill it in... */
1689 *pos
++ = WLAN_EID_SUPP_RATES
;
1692 priv
->active_rate
= priv
->rates_mask
;
1693 active_rates
= priv
->active_rate
;
1694 priv
->active_rate_basic
= priv
->rates_mask
& IWL_BASIC_RATES_MASK
;
1696 cck_rates
= IWL_CCK_RATES_MASK
& active_rates
;
1697 ret_rates
= iwl3945_supported_rate_to_ie(pos
, cck_rates
,
1698 priv
->active_rate_basic
, &left
);
1699 active_rates
&= ~ret_rates
;
1701 ret_rates
= iwl3945_supported_rate_to_ie(pos
, active_rates
,
1702 priv
->active_rate_basic
, &left
);
1703 active_rates
&= ~ret_rates
;
1707 if (active_rates
== 0)
1710 /* fill in supported extended rate */
1715 /* ... fill it in... */
1716 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
1718 iwl3945_supported_rate_to_ie(pos
, active_rates
,
1719 priv
->active_rate_basic
, &left
);
1730 static int iwl3945_send_qos_params_command(struct iwl3945_priv
*priv
,
1731 struct iwl3945_qosparam_cmd
*qos
)
1734 return iwl3945_send_cmd_pdu(priv
, REPLY_QOS_PARAM
,
1735 sizeof(struct iwl3945_qosparam_cmd
), qos
);
1738 static void iwl3945_reset_qos(struct iwl3945_priv
*priv
)
1744 unsigned long flags
;
1747 spin_lock_irqsave(&priv
->lock
, flags
);
1748 priv
->qos_data
.qos_active
= 0;
1750 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) {
1751 if (priv
->qos_data
.qos_enable
)
1752 priv
->qos_data
.qos_active
= 1;
1753 if (!(priv
->active_rate
& 0xfff0)) {
1757 } else if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
1758 if (priv
->qos_data
.qos_enable
)
1759 priv
->qos_data
.qos_active
= 1;
1760 } else if (!(priv
->staging_rxon
.flags
& RXON_FLG_SHORT_SLOT_MSK
)) {
1765 if (priv
->qos_data
.qos_active
)
1768 priv
->qos_data
.def_qos_parm
.ac
[0].cw_min
= cpu_to_le16(cw_min
);
1769 priv
->qos_data
.def_qos_parm
.ac
[0].cw_max
= cpu_to_le16(cw_max
);
1770 priv
->qos_data
.def_qos_parm
.ac
[0].aifsn
= aifs
;
1771 priv
->qos_data
.def_qos_parm
.ac
[0].edca_txop
= 0;
1772 priv
->qos_data
.def_qos_parm
.ac
[0].reserved1
= 0;
1774 if (priv
->qos_data
.qos_active
) {
1776 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_min
= cpu_to_le16(cw_min
);
1777 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_max
= cpu_to_le16(cw_max
);
1778 priv
->qos_data
.def_qos_parm
.ac
[i
].aifsn
= 7;
1779 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
= 0;
1780 priv
->qos_data
.def_qos_parm
.ac
[i
].reserved1
= 0;
1783 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_min
=
1784 cpu_to_le16((cw_min
+ 1) / 2 - 1);
1785 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_max
=
1786 cpu_to_le16(cw_max
);
1787 priv
->qos_data
.def_qos_parm
.ac
[i
].aifsn
= 2;
1789 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
=
1792 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
=
1794 priv
->qos_data
.def_qos_parm
.ac
[i
].reserved1
= 0;
1797 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_min
=
1798 cpu_to_le16((cw_min
+ 1) / 4 - 1);
1799 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_max
=
1800 cpu_to_le16((cw_max
+ 1) / 2 - 1);
1801 priv
->qos_data
.def_qos_parm
.ac
[i
].aifsn
= 2;
1802 priv
->qos_data
.def_qos_parm
.ac
[i
].reserved1
= 0;
1804 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
=
1807 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
=
1810 for (i
= 1; i
< 4; i
++) {
1811 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_min
=
1812 cpu_to_le16(cw_min
);
1813 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_max
=
1814 cpu_to_le16(cw_max
);
1815 priv
->qos_data
.def_qos_parm
.ac
[i
].aifsn
= aifs
;
1816 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
= 0;
1817 priv
->qos_data
.def_qos_parm
.ac
[i
].reserved1
= 0;
1820 IWL_DEBUG_QOS("set QoS to default \n");
1822 spin_unlock_irqrestore(&priv
->lock
, flags
);
1825 static void iwl3945_activate_qos(struct iwl3945_priv
*priv
, u8 force
)
1827 unsigned long flags
;
1829 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
1832 if (!priv
->qos_data
.qos_enable
)
1835 spin_lock_irqsave(&priv
->lock
, flags
);
1836 priv
->qos_data
.def_qos_parm
.qos_flags
= 0;
1838 if (priv
->qos_data
.qos_cap
.q_AP
.queue_request
&&
1839 !priv
->qos_data
.qos_cap
.q_AP
.txop_request
)
1840 priv
->qos_data
.def_qos_parm
.qos_flags
|=
1841 QOS_PARAM_FLG_TXOP_TYPE_MSK
;
1843 if (priv
->qos_data
.qos_active
)
1844 priv
->qos_data
.def_qos_parm
.qos_flags
|=
1845 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
1847 spin_unlock_irqrestore(&priv
->lock
, flags
);
1849 if (force
|| iwl3945_is_associated(priv
)) {
1850 IWL_DEBUG_QOS("send QoS cmd with Qos active %d \n",
1851 priv
->qos_data
.qos_active
);
1853 iwl3945_send_qos_params_command(priv
,
1854 &(priv
->qos_data
.def_qos_parm
));
1859 * Power management (not Tx power!) functions
1861 #define MSEC_TO_USEC 1024
1863 #define NOSLP __constant_cpu_to_le32(0)
1864 #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK
1865 #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
1866 #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
1867 __constant_cpu_to_le32(X1), \
1868 __constant_cpu_to_le32(X2), \
1869 __constant_cpu_to_le32(X3), \
1870 __constant_cpu_to_le32(X4)}
1873 /* default power management (not Tx power) table values */
1875 static struct iwl3945_power_vec_entry range_0
[IWL_POWER_AC
] = {
1876 {{NOSLP
, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1877 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
1878 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
1879 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
1880 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
1881 {{SLP
, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
1885 static struct iwl3945_power_vec_entry range_1
[IWL_POWER_AC
] = {
1886 {{NOSLP
, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1887 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
1888 SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
1889 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
1890 SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
1891 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
1892 SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
1893 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
1894 {{SLP
, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
1895 SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
1898 int iwl3945_power_init_handle(struct iwl3945_priv
*priv
)
1901 struct iwl3945_power_mgr
*pow_data
;
1902 int size
= sizeof(struct iwl3945_power_vec_entry
) * IWL_POWER_AC
;
1905 IWL_DEBUG_POWER("Initialize power \n");
1907 pow_data
= &(priv
->power_data
);
1909 memset(pow_data
, 0, sizeof(*pow_data
));
1911 pow_data
->active_index
= IWL_POWER_RANGE_0
;
1912 pow_data
->dtim_val
= 0xffff;
1914 memcpy(&pow_data
->pwr_range_0
[0], &range_0
[0], size
);
1915 memcpy(&pow_data
->pwr_range_1
[0], &range_1
[0], size
);
1917 rc
= pci_read_config_word(priv
->pci_dev
, PCI_LINK_CTRL
, &pci_pm
);
1921 struct iwl3945_powertable_cmd
*cmd
;
1923 IWL_DEBUG_POWER("adjust power command flags\n");
1925 for (i
= 0; i
< IWL_POWER_AC
; i
++) {
1926 cmd
= &pow_data
->pwr_range_0
[i
].cmd
;
1929 cmd
->flags
&= ~IWL_POWER_PCI_PM_MSK
;
1931 cmd
->flags
|= IWL_POWER_PCI_PM_MSK
;
1937 static int iwl3945_update_power_cmd(struct iwl3945_priv
*priv
,
1938 struct iwl3945_powertable_cmd
*cmd
, u32 mode
)
1943 struct iwl3945_power_vec_entry
*range
;
1945 struct iwl3945_power_mgr
*pow_data
;
1947 if (mode
> IWL_POWER_INDEX_5
) {
1948 IWL_DEBUG_POWER("Error invalid power mode \n");
1951 pow_data
= &(priv
->power_data
);
1953 if (pow_data
->active_index
== IWL_POWER_RANGE_0
)
1954 range
= &pow_data
->pwr_range_0
[0];
1956 range
= &pow_data
->pwr_range_1
[1];
1958 memcpy(cmd
, &range
[mode
].cmd
, sizeof(struct iwl3945_powertable_cmd
));
1960 #ifdef IWL_MAC80211_DISABLE
1961 if (priv
->assoc_network
!= NULL
) {
1962 unsigned long flags
;
1964 period
= priv
->assoc_network
->tim
.tim_period
;
1966 #endif /*IWL_MAC80211_DISABLE */
1967 skip
= range
[mode
].no_dtim
;
1976 cmd
->flags
&= ~IWL_POWER_SLEEP_OVER_DTIM_MSK
;
1978 __le32 slp_itrvl
= cmd
->sleep_interval
[IWL_POWER_VEC_SIZE
- 1];
1979 max_sleep
= (le32_to_cpu(slp_itrvl
) / period
) * period
;
1980 cmd
->flags
|= IWL_POWER_SLEEP_OVER_DTIM_MSK
;
1983 for (i
= 0; i
< IWL_POWER_VEC_SIZE
; i
++) {
1984 if (le32_to_cpu(cmd
->sleep_interval
[i
]) > max_sleep
)
1985 cmd
->sleep_interval
[i
] = cpu_to_le32(max_sleep
);
1988 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd
->flags
);
1989 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd
->tx_data_timeout
));
1990 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd
->rx_data_timeout
));
1991 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
1992 le32_to_cpu(cmd
->sleep_interval
[0]),
1993 le32_to_cpu(cmd
->sleep_interval
[1]),
1994 le32_to_cpu(cmd
->sleep_interval
[2]),
1995 le32_to_cpu(cmd
->sleep_interval
[3]),
1996 le32_to_cpu(cmd
->sleep_interval
[4]));
2001 static int iwl3945_send_power_mode(struct iwl3945_priv
*priv
, u32 mode
)
2003 u32
uninitialized_var(final_mode
);
2005 struct iwl3945_powertable_cmd cmd
;
2007 /* If on battery, set to 3,
2008 * if plugged into AC power, set to CAM ("continuously aware mode"),
2009 * else user level */
2011 case IWL_POWER_BATTERY
:
2012 final_mode
= IWL_POWER_INDEX_3
;
2015 final_mode
= IWL_POWER_MODE_CAM
;
2022 iwl3945_update_power_cmd(priv
, &cmd
, final_mode
);
2024 rc
= iwl3945_send_cmd_pdu(priv
, POWER_TABLE_CMD
, sizeof(cmd
), &cmd
);
2026 if (final_mode
== IWL_POWER_MODE_CAM
)
2027 clear_bit(STATUS_POWER_PMI
, &priv
->status
);
2029 set_bit(STATUS_POWER_PMI
, &priv
->status
);
2035 * iwl3945_scan_cancel - Cancel any currently executing HW scan
2037 * NOTE: priv->mutex is not required before calling this function
2039 static int iwl3945_scan_cancel(struct iwl3945_priv
*priv
)
2041 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
2042 clear_bit(STATUS_SCANNING
, &priv
->status
);
2046 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
2047 if (!test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
2048 IWL_DEBUG_SCAN("Queuing scan abort.\n");
2049 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
2050 queue_work(priv
->workqueue
, &priv
->abort_scan
);
2053 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
2055 return test_bit(STATUS_SCANNING
, &priv
->status
);
2062 * iwl3945_scan_cancel_timeout - Cancel any currently executing HW scan
2063 * @ms: amount of time to wait (in milliseconds) for scan to abort
2065 * NOTE: priv->mutex must be held before calling this function
2067 static int iwl3945_scan_cancel_timeout(struct iwl3945_priv
*priv
, unsigned long ms
)
2069 unsigned long now
= jiffies
;
2072 ret
= iwl3945_scan_cancel(priv
);
2074 mutex_unlock(&priv
->mutex
);
2075 while (!time_after(jiffies
, now
+ msecs_to_jiffies(ms
)) &&
2076 test_bit(STATUS_SCANNING
, &priv
->status
))
2078 mutex_lock(&priv
->mutex
);
2080 return test_bit(STATUS_SCANNING
, &priv
->status
);
2086 #define MAX_UCODE_BEACON_INTERVAL 1024
2087 #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
2089 static __le16
iwl3945_adjust_beacon_interval(u16 beacon_val
)
2092 u16 beacon_factor
= 0;
2095 (beacon_val
+ MAX_UCODE_BEACON_INTERVAL
)
2096 / MAX_UCODE_BEACON_INTERVAL
;
2097 new_val
= beacon_val
/ beacon_factor
;
2099 return cpu_to_le16(new_val
);
2102 static void iwl3945_setup_rxon_timing(struct iwl3945_priv
*priv
)
2104 u64 interval_tm_unit
;
2106 unsigned long flags
;
2107 struct ieee80211_conf
*conf
= NULL
;
2110 conf
= ieee80211_get_hw_conf(priv
->hw
);
2112 spin_lock_irqsave(&priv
->lock
, flags
);
2113 priv
->rxon_timing
.timestamp
.dw
[1] = cpu_to_le32(priv
->timestamp1
);
2114 priv
->rxon_timing
.timestamp
.dw
[0] = cpu_to_le32(priv
->timestamp0
);
2116 priv
->rxon_timing
.listen_interval
= INTEL_CONN_LISTEN_INTERVAL
;
2118 tsf
= priv
->timestamp1
;
2119 tsf
= ((tsf
<< 32) | priv
->timestamp0
);
2121 beacon_int
= priv
->beacon_int
;
2122 spin_unlock_irqrestore(&priv
->lock
, flags
);
2124 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) {
2125 if (beacon_int
== 0) {
2126 priv
->rxon_timing
.beacon_interval
= cpu_to_le16(100);
2127 priv
->rxon_timing
.beacon_init_val
= cpu_to_le32(102400);
2129 priv
->rxon_timing
.beacon_interval
=
2130 cpu_to_le16(beacon_int
);
2131 priv
->rxon_timing
.beacon_interval
=
2132 iwl3945_adjust_beacon_interval(
2133 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2136 priv
->rxon_timing
.atim_window
= 0;
2138 priv
->rxon_timing
.beacon_interval
=
2139 iwl3945_adjust_beacon_interval(conf
->beacon_int
);
2140 /* TODO: we need to get atim_window from upper stack
2141 * for now we set to 0 */
2142 priv
->rxon_timing
.atim_window
= 0;
2146 (le16_to_cpu(priv
->rxon_timing
.beacon_interval
) * 1024);
2147 result
= do_div(tsf
, interval_tm_unit
);
2148 priv
->rxon_timing
.beacon_init_val
=
2149 cpu_to_le32((u32
) ((u64
) interval_tm_unit
- result
));
2152 ("beacon interval %d beacon timer %d beacon tim %d\n",
2153 le16_to_cpu(priv
->rxon_timing
.beacon_interval
),
2154 le32_to_cpu(priv
->rxon_timing
.beacon_init_val
),
2155 le16_to_cpu(priv
->rxon_timing
.atim_window
));
2158 static int iwl3945_scan_initiate(struct iwl3945_priv
*priv
)
2160 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
2161 IWL_ERROR("APs don't scan.\n");
2165 if (!iwl3945_is_ready_rf(priv
)) {
2166 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
2170 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
2171 IWL_DEBUG_SCAN("Scan already in progress.\n");
2175 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
2176 IWL_DEBUG_SCAN("Scan request while abort pending. "
2181 IWL_DEBUG_INFO("Starting scan...\n");
2182 if (priv
->cfg
->sku
& IWL_SKU_G
)
2183 priv
->scan_bands
|= BIT(IEEE80211_BAND_2GHZ
);
2184 if (priv
->cfg
->sku
& IWL_SKU_A
)
2185 priv
->scan_bands
|= BIT(IEEE80211_BAND_5GHZ
);
2186 set_bit(STATUS_SCANNING
, &priv
->status
);
2187 priv
->scan_start
= jiffies
;
2188 priv
->scan_pass_start
= priv
->scan_start
;
2190 queue_work(priv
->workqueue
, &priv
->request_scan
);
2195 static int iwl3945_set_rxon_hwcrypto(struct iwl3945_priv
*priv
, int hw_decrypt
)
2197 struct iwl3945_rxon_cmd
*rxon
= &priv
->staging_rxon
;
2200 rxon
->filter_flags
&= ~RXON_FILTER_DIS_DECRYPT_MSK
;
2202 rxon
->filter_flags
|= RXON_FILTER_DIS_DECRYPT_MSK
;
2207 static void iwl3945_set_flags_for_phymode(struct iwl3945_priv
*priv
,
2208 enum ieee80211_band band
)
2210 if (band
== IEEE80211_BAND_5GHZ
) {
2211 priv
->staging_rxon
.flags
&=
2212 ~(RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
2213 | RXON_FLG_CCK_MSK
);
2214 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
2216 /* Copied from iwl3945_bg_post_associate() */
2217 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
2218 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
2220 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
2222 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
2223 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
2225 priv
->staging_rxon
.flags
|= RXON_FLG_BAND_24G_MSK
;
2226 priv
->staging_rxon
.flags
|= RXON_FLG_AUTO_DETECT_MSK
;
2227 priv
->staging_rxon
.flags
&= ~RXON_FLG_CCK_MSK
;
2232 * initialize rxon structure with default values from eeprom
2234 static void iwl3945_connection_init_rx_config(struct iwl3945_priv
*priv
)
2236 const struct iwl3945_channel_info
*ch_info
;
2238 memset(&priv
->staging_rxon
, 0, sizeof(priv
->staging_rxon
));
2240 switch (priv
->iw_mode
) {
2241 case IEEE80211_IF_TYPE_AP
:
2242 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_AP
;
2245 case IEEE80211_IF_TYPE_STA
:
2246 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_ESS
;
2247 priv
->staging_rxon
.filter_flags
= RXON_FILTER_ACCEPT_GRP_MSK
;
2250 case IEEE80211_IF_TYPE_IBSS
:
2251 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_IBSS
;
2252 priv
->staging_rxon
.flags
= RXON_FLG_SHORT_PREAMBLE_MSK
;
2253 priv
->staging_rxon
.filter_flags
= RXON_FILTER_BCON_AWARE_MSK
|
2254 RXON_FILTER_ACCEPT_GRP_MSK
;
2257 case IEEE80211_IF_TYPE_MNTR
:
2258 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_SNIFFER
;
2259 priv
->staging_rxon
.filter_flags
= RXON_FILTER_PROMISC_MSK
|
2260 RXON_FILTER_CTL2HOST_MSK
| RXON_FILTER_ACCEPT_GRP_MSK
;
2263 IWL_ERROR("Unsupported interface type %d\n", priv
->iw_mode
);
2268 /* TODO: Figure out when short_preamble would be set and cache from
2270 if (!hw_to_local(priv
->hw
)->short_preamble
)
2271 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
2273 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
2276 ch_info
= iwl3945_get_channel_info(priv
, priv
->band
,
2277 le16_to_cpu(priv
->active_rxon
.channel
));
2280 ch_info
= &priv
->channel_info
[0];
2283 * in some case A channels are all non IBSS
2284 * in this case force B/G channel
2286 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) &&
2287 !(is_channel_ibss(ch_info
)))
2288 ch_info
= &priv
->channel_info
[0];
2290 priv
->staging_rxon
.channel
= cpu_to_le16(ch_info
->channel
);
2291 if (is_channel_a_band(ch_info
))
2292 priv
->band
= IEEE80211_BAND_5GHZ
;
2294 priv
->band
= IEEE80211_BAND_2GHZ
;
2296 iwl3945_set_flags_for_phymode(priv
, priv
->band
);
2298 priv
->staging_rxon
.ofdm_basic_rates
=
2299 (IWL_OFDM_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
2300 priv
->staging_rxon
.cck_basic_rates
=
2301 (IWL_CCK_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
2304 static int iwl3945_set_mode(struct iwl3945_priv
*priv
, int mode
)
2306 if (mode
== IEEE80211_IF_TYPE_IBSS
) {
2307 const struct iwl3945_channel_info
*ch_info
;
2309 ch_info
= iwl3945_get_channel_info(priv
,
2311 le16_to_cpu(priv
->staging_rxon
.channel
));
2313 if (!ch_info
|| !is_channel_ibss(ch_info
)) {
2314 IWL_ERROR("channel %d not IBSS channel\n",
2315 le16_to_cpu(priv
->staging_rxon
.channel
));
2320 priv
->iw_mode
= mode
;
2322 iwl3945_connection_init_rx_config(priv
);
2323 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
2325 iwl3945_clear_stations_table(priv
);
2327 /* dont commit rxon if rf-kill is on*/
2328 if (!iwl3945_is_ready_rf(priv
))
2331 cancel_delayed_work(&priv
->scan_check
);
2332 if (iwl3945_scan_cancel_timeout(priv
, 100)) {
2333 IWL_WARNING("Aborted scan still in progress after 100ms\n");
2334 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2338 iwl3945_commit_rxon(priv
);
2343 static void iwl3945_build_tx_cmd_hwcrypto(struct iwl3945_priv
*priv
,
2344 struct ieee80211_tx_info
*info
,
2345 struct iwl3945_cmd
*cmd
,
2346 struct sk_buff
*skb_frag
,
2349 struct iwl3945_hw_key
*keyinfo
=
2350 &priv
->stations
[info
->control
.hw_key
->hw_key_idx
].keyinfo
;
2352 switch (keyinfo
->alg
) {
2354 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_CCM
;
2355 memcpy(cmd
->cmd
.tx
.key
, keyinfo
->key
, keyinfo
->keylen
);
2356 IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
2361 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_TKIP
;
2364 memcpy(cmd
->cmd
.tx
.tkip_mic
.byte
, skb_frag
->tail
- 8,
2367 memset(cmd
->cmd
.tx
.tkip_mic
.byte
, 0, 8);
2372 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_WEP
|
2373 (info
->control
.hw_key
->hw_key_idx
& TX_CMD_SEC_MSK
) << TX_CMD_SEC_SHIFT
;
2375 if (keyinfo
->keylen
== 13)
2376 cmd
->cmd
.tx
.sec_ctl
|= TX_CMD_SEC_KEY128
;
2378 memcpy(&cmd
->cmd
.tx
.key
[3], keyinfo
->key
, keyinfo
->keylen
);
2380 IWL_DEBUG_TX("Configuring packet for WEP encryption "
2381 "with key %d\n", info
->control
.hw_key
->hw_key_idx
);
2385 printk(KERN_ERR
"Unknown encode alg %d\n", keyinfo
->alg
);
2391 * handle build REPLY_TX command notification.
2393 static void iwl3945_build_tx_cmd_basic(struct iwl3945_priv
*priv
,
2394 struct iwl3945_cmd
*cmd
,
2395 struct ieee80211_tx_info
*info
,
2396 struct ieee80211_hdr
*hdr
,
2397 int is_unicast
, u8 std_id
)
2399 __le16 fc
= hdr
->frame_control
;
2400 __le32 tx_flags
= cmd
->cmd
.tx
.tx_flags
;
2402 cmd
->cmd
.tx
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
2403 if (!(info
->flags
& IEEE80211_TX_CTL_NO_ACK
)) {
2404 tx_flags
|= TX_CMD_FLG_ACK_MSK
;
2405 if (ieee80211_is_mgmt(fc
))
2406 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2407 if (ieee80211_is_probe_resp(fc
) &&
2408 !(le16_to_cpu(hdr
->seq_ctrl
) & 0xf))
2409 tx_flags
|= TX_CMD_FLG_TSF_MSK
;
2411 tx_flags
&= (~TX_CMD_FLG_ACK_MSK
);
2412 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2415 cmd
->cmd
.tx
.sta_id
= std_id
;
2416 if (ieee80211_has_morefrags(fc
))
2417 tx_flags
|= TX_CMD_FLG_MORE_FRAG_MSK
;
2419 if (ieee80211_is_data_qos(fc
)) {
2420 u8
*qc
= ieee80211_get_qos_ctl(hdr
);
2421 cmd
->cmd
.tx
.tid_tspec
= qc
[0] & 0xf;
2422 tx_flags
&= ~TX_CMD_FLG_SEQ_CTL_MSK
;
2424 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2427 if (info
->flags
& IEEE80211_TX_CTL_USE_RTS_CTS
) {
2428 tx_flags
|= TX_CMD_FLG_RTS_MSK
;
2429 tx_flags
&= ~TX_CMD_FLG_CTS_MSK
;
2430 } else if (info
->flags
& IEEE80211_TX_CTL_USE_CTS_PROTECT
) {
2431 tx_flags
&= ~TX_CMD_FLG_RTS_MSK
;
2432 tx_flags
|= TX_CMD_FLG_CTS_MSK
;
2435 if ((tx_flags
& TX_CMD_FLG_RTS_MSK
) || (tx_flags
& TX_CMD_FLG_CTS_MSK
))
2436 tx_flags
|= TX_CMD_FLG_FULL_TXOP_PROT_MSK
;
2438 tx_flags
&= ~(TX_CMD_FLG_ANT_SEL_MSK
);
2439 if (ieee80211_is_mgmt(fc
)) {
2440 if (ieee80211_is_assoc_req(fc
) || ieee80211_is_reassoc_req(fc
))
2441 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= cpu_to_le16(3);
2443 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= cpu_to_le16(2);
2445 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= 0;
2446 #ifdef CONFIG_IWL3945_LEDS
2447 priv
->rxtxpackets
+= le16_to_cpu(cmd
->cmd
.tx
.len
);
2451 cmd
->cmd
.tx
.driver_txop
= 0;
2452 cmd
->cmd
.tx
.tx_flags
= tx_flags
;
2453 cmd
->cmd
.tx
.next_frame_len
= 0;
2457 * iwl3945_get_sta_id - Find station's index within station table
2459 static int iwl3945_get_sta_id(struct iwl3945_priv
*priv
, struct ieee80211_hdr
*hdr
)
2462 u16 fc
= le16_to_cpu(hdr
->frame_control
);
2464 /* If this frame is broadcast or management, use broadcast station id */
2465 if (((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
) ||
2466 is_multicast_ether_addr(hdr
->addr1
))
2467 return priv
->hw_setting
.bcast_sta_id
;
2469 switch (priv
->iw_mode
) {
2471 /* If we are a client station in a BSS network, use the special
2472 * AP station entry (that's the only station we communicate with) */
2473 case IEEE80211_IF_TYPE_STA
:
2476 /* If we are an AP, then find the station, or use BCAST */
2477 case IEEE80211_IF_TYPE_AP
:
2478 sta_id
= iwl3945_hw_find_station(priv
, hdr
->addr1
);
2479 if (sta_id
!= IWL_INVALID_STATION
)
2481 return priv
->hw_setting
.bcast_sta_id
;
2483 /* If this frame is going out to an IBSS network, find the station,
2484 * or create a new station table entry */
2485 case IEEE80211_IF_TYPE_IBSS
: {
2486 DECLARE_MAC_BUF(mac
);
2488 /* Create new station table entry */
2489 sta_id
= iwl3945_hw_find_station(priv
, hdr
->addr1
);
2490 if (sta_id
!= IWL_INVALID_STATION
)
2493 sta_id
= iwl3945_add_station(priv
, hdr
->addr1
, 0, CMD_ASYNC
);
2495 if (sta_id
!= IWL_INVALID_STATION
)
2498 IWL_DEBUG_DROP("Station %s not in station map. "
2499 "Defaulting to broadcast...\n",
2500 print_mac(mac
, hdr
->addr1
));
2501 iwl3945_print_hex_dump(IWL_DL_DROP
, (u8
*) hdr
, sizeof(*hdr
));
2502 return priv
->hw_setting
.bcast_sta_id
;
2504 /* If we are in monitor mode, use BCAST. This is required for
2505 * packet injection. */
2506 case IEEE80211_IF_TYPE_MNTR
:
2507 return priv
->hw_setting
.bcast_sta_id
;
2510 IWL_WARNING("Unknown mode of operation: %d\n", priv
->iw_mode
);
2511 return priv
->hw_setting
.bcast_sta_id
;
2516 * start REPLY_TX command process
2518 static int iwl3945_tx_skb(struct iwl3945_priv
*priv
, struct sk_buff
*skb
)
2520 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2521 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
2522 struct iwl3945_tfd_frame
*tfd
;
2524 int txq_id
= skb_get_queue_mapping(skb
);
2525 struct iwl3945_tx_queue
*txq
= NULL
;
2526 struct iwl3945_queue
*q
= NULL
;
2527 dma_addr_t phys_addr
;
2528 dma_addr_t txcmd_phys
;
2529 struct iwl3945_cmd
*out_cmd
= NULL
;
2530 u16 len
, idx
, len_org
, hdr_len
;
2537 u8 wait_write_ptr
= 0;
2539 unsigned long flags
;
2542 spin_lock_irqsave(&priv
->lock
, flags
);
2543 if (iwl3945_is_rfkill(priv
)) {
2544 IWL_DEBUG_DROP("Dropping - RF KILL\n");
2548 if ((ieee80211_get_tx_rate(priv
->hw
, info
)->hw_value
& 0xFF) == IWL_INVALID_RATE
) {
2549 IWL_ERROR("ERROR: No TX rate available.\n");
2553 unicast
= !is_multicast_ether_addr(hdr
->addr1
);
2556 fc
= hdr
->frame_control
;
2558 #ifdef CONFIG_IWL3945_DEBUG
2559 if (ieee80211_is_auth(fc
))
2560 IWL_DEBUG_TX("Sending AUTH frame\n");
2561 else if (ieee80211_is_assoc_req(fc
))
2562 IWL_DEBUG_TX("Sending ASSOC frame\n");
2563 else if (ieee80211_is_reassoc_req(fc
))
2564 IWL_DEBUG_TX("Sending REASSOC frame\n");
2567 /* drop all data frame if we are not associated */
2568 if (ieee80211_is_data(fc
) &&
2569 (priv
->iw_mode
!= IEEE80211_IF_TYPE_MNTR
) && /* packet injection */
2570 (!iwl3945_is_associated(priv
) ||
2571 ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) && !priv
->assoc_id
))) {
2572 IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n");
2576 spin_unlock_irqrestore(&priv
->lock
, flags
);
2578 hdr_len
= ieee80211_get_hdrlen(le16_to_cpu(fc
));
2580 /* Find (or create) index into station table for destination station */
2581 sta_id
= iwl3945_get_sta_id(priv
, hdr
);
2582 if (sta_id
== IWL_INVALID_STATION
) {
2583 DECLARE_MAC_BUF(mac
);
2585 IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
2586 print_mac(mac
, hdr
->addr1
));
2590 IWL_DEBUG_RATE("station Id %d\n", sta_id
);
2592 if (ieee80211_is_data_qos(fc
)) {
2593 qc
= ieee80211_get_qos_ctl(hdr
);
2595 seq_number
= priv
->stations
[sta_id
].tid
[tid
].seq_number
&
2597 hdr
->seq_ctrl
= cpu_to_le16(seq_number
) |
2599 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG
));
2603 /* Descriptor for chosen Tx queue */
2604 txq
= &priv
->txq
[txq_id
];
2607 spin_lock_irqsave(&priv
->lock
, flags
);
2609 /* Set up first empty TFD within this queue's circular TFD buffer */
2610 tfd
= &txq
->bd
[q
->write_ptr
];
2611 memset(tfd
, 0, sizeof(*tfd
));
2612 control_flags
= (u32
*) tfd
;
2613 idx
= get_cmd_index(q
, q
->write_ptr
, 0);
2615 /* Set up driver data for this TFD */
2616 memset(&(txq
->txb
[q
->write_ptr
]), 0, sizeof(struct iwl3945_tx_info
));
2617 txq
->txb
[q
->write_ptr
].skb
[0] = skb
;
2619 /* Init first empty entry in queue's array of Tx/cmd buffers */
2620 out_cmd
= &txq
->cmd
[idx
];
2621 memset(&out_cmd
->hdr
, 0, sizeof(out_cmd
->hdr
));
2622 memset(&out_cmd
->cmd
.tx
, 0, sizeof(out_cmd
->cmd
.tx
));
2625 * Set up the Tx-command (not MAC!) header.
2626 * Store the chosen Tx queue and TFD index within the sequence field;
2627 * after Tx, uCode's Tx response will return this value so driver can
2628 * locate the frame within the tx queue and do post-tx processing.
2630 out_cmd
->hdr
.cmd
= REPLY_TX
;
2631 out_cmd
->hdr
.sequence
= cpu_to_le16((u16
)(QUEUE_TO_SEQ(txq_id
) |
2632 INDEX_TO_SEQ(q
->write_ptr
)));
2634 /* Copy MAC header from skb into command buffer */
2635 memcpy(out_cmd
->cmd
.tx
.hdr
, hdr
, hdr_len
);
2638 * Use the first empty entry in this queue's command buffer array
2639 * to contain the Tx command and MAC header concatenated together
2640 * (payload data will be in another buffer).
2641 * Size of this varies, due to varying MAC header length.
2642 * If end is not dword aligned, we'll have 2 extra bytes at the end
2643 * of the MAC header (device reads on dword boundaries).
2644 * We'll tell device about this padding later.
2646 len
= priv
->hw_setting
.tx_cmd_len
+
2647 sizeof(struct iwl3945_cmd_header
) + hdr_len
;
2650 len
= (len
+ 3) & ~3;
2657 /* Physical address of this Tx command's header (not MAC header!),
2658 * within command buffer array. */
2659 txcmd_phys
= txq
->dma_addr_cmd
+ sizeof(struct iwl3945_cmd
) * idx
+
2660 offsetof(struct iwl3945_cmd
, hdr
);
2662 /* Add buffer containing Tx command and MAC(!) header to TFD's
2664 iwl3945_hw_txq_attach_buf_to_tfd(priv
, tfd
, txcmd_phys
, len
);
2666 if (info
->control
.hw_key
)
2667 iwl3945_build_tx_cmd_hwcrypto(priv
, info
, out_cmd
, skb
, 0);
2669 /* Set up TFD's 2nd entry to point directly to remainder of skb,
2670 * if any (802.11 null frames have no payload). */
2671 len
= skb
->len
- hdr_len
;
2673 phys_addr
= pci_map_single(priv
->pci_dev
, skb
->data
+ hdr_len
,
2674 len
, PCI_DMA_TODEVICE
);
2675 iwl3945_hw_txq_attach_buf_to_tfd(priv
, tfd
, phys_addr
, len
);
2679 /* If there is no payload, then we use only one Tx buffer */
2680 *control_flags
= TFD_CTL_COUNT_SET(1);
2682 /* Else use 2 buffers.
2683 * Tell 3945 about any padding after MAC header */
2684 *control_flags
= TFD_CTL_COUNT_SET(2) |
2685 TFD_CTL_PAD_SET(U32_PAD(len
));
2687 /* Total # bytes to be transmitted */
2688 len
= (u16
)skb
->len
;
2689 out_cmd
->cmd
.tx
.len
= cpu_to_le16(len
);
2691 /* TODO need this for burst mode later on */
2692 iwl3945_build_tx_cmd_basic(priv
, out_cmd
, info
, hdr
, unicast
, sta_id
);
2694 /* set is_hcca to 0; it probably will never be implemented */
2695 iwl3945_hw_build_tx_cmd_rate(priv
, out_cmd
, info
, hdr
, sta_id
, 0);
2697 out_cmd
->cmd
.tx
.tx_flags
&= ~TX_CMD_FLG_ANT_A_MSK
;
2698 out_cmd
->cmd
.tx
.tx_flags
&= ~TX_CMD_FLG_ANT_B_MSK
;
2700 if (!ieee80211_has_morefrags(hdr
->frame_control
)) {
2701 txq
->need_update
= 1;
2703 priv
->stations
[sta_id
].tid
[tid
].seq_number
= seq_number
;
2706 txq
->need_update
= 0;
2709 iwl3945_print_hex_dump(IWL_DL_TX
, out_cmd
->cmd
.payload
,
2710 sizeof(out_cmd
->cmd
.tx
));
2712 iwl3945_print_hex_dump(IWL_DL_TX
, (u8
*)out_cmd
->cmd
.tx
.hdr
,
2713 ieee80211_get_hdrlen(le16_to_cpu(fc
)));
2715 /* Tell device the write index *just past* this latest filled TFD */
2716 q
->write_ptr
= iwl_queue_inc_wrap(q
->write_ptr
, q
->n_bd
);
2717 rc
= iwl3945_tx_queue_update_write_ptr(priv
, txq
);
2718 spin_unlock_irqrestore(&priv
->lock
, flags
);
2723 if ((iwl3945_queue_space(q
) < q
->high_mark
)
2724 && priv
->mac80211_registered
) {
2725 if (wait_write_ptr
) {
2726 spin_lock_irqsave(&priv
->lock
, flags
);
2727 txq
->need_update
= 1;
2728 iwl3945_tx_queue_update_write_ptr(priv
, txq
);
2729 spin_unlock_irqrestore(&priv
->lock
, flags
);
2732 ieee80211_stop_queue(priv
->hw
, skb_get_queue_mapping(skb
));
2738 spin_unlock_irqrestore(&priv
->lock
, flags
);
2743 static void iwl3945_set_rate(struct iwl3945_priv
*priv
)
2745 const struct ieee80211_supported_band
*sband
= NULL
;
2746 struct ieee80211_rate
*rate
;
2749 sband
= iwl3945_get_band(priv
, priv
->band
);
2751 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
2755 priv
->active_rate
= 0;
2756 priv
->active_rate_basic
= 0;
2758 IWL_DEBUG_RATE("Setting rates for %s GHz\n",
2759 sband
->band
== IEEE80211_BAND_2GHZ
? "2.4" : "5");
2761 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
2762 rate
= &sband
->bitrates
[i
];
2763 if ((rate
->hw_value
< IWL_RATE_COUNT
) &&
2764 !(rate
->flags
& IEEE80211_CHAN_DISABLED
)) {
2765 IWL_DEBUG_RATE("Adding rate index %d (plcp %d)\n",
2766 rate
->hw_value
, iwl3945_rates
[rate
->hw_value
].plcp
);
2767 priv
->active_rate
|= (1 << rate
->hw_value
);
2771 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
2772 priv
->active_rate
, priv
->active_rate_basic
);
2775 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
2776 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
2779 if (priv
->active_rate_basic
& IWL_CCK_BASIC_RATES_MASK
)
2780 priv
->staging_rxon
.cck_basic_rates
=
2781 ((priv
->active_rate_basic
&
2782 IWL_CCK_RATES_MASK
) >> IWL_FIRST_CCK_RATE
) & 0xF;
2784 priv
->staging_rxon
.cck_basic_rates
=
2785 (IWL_CCK_BASIC_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
2787 if (priv
->active_rate_basic
& IWL_OFDM_BASIC_RATES_MASK
)
2788 priv
->staging_rxon
.ofdm_basic_rates
=
2789 ((priv
->active_rate_basic
&
2790 (IWL_OFDM_BASIC_RATES_MASK
| IWL_RATE_6M_MASK
)) >>
2791 IWL_FIRST_OFDM_RATE
) & 0xFF;
2793 priv
->staging_rxon
.ofdm_basic_rates
=
2794 (IWL_OFDM_BASIC_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
2797 static void iwl3945_radio_kill_sw(struct iwl3945_priv
*priv
, int disable_radio
)
2799 unsigned long flags
;
2801 if (!!disable_radio
== test_bit(STATUS_RF_KILL_SW
, &priv
->status
))
2804 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
2805 disable_radio
? "OFF" : "ON");
2807 if (disable_radio
) {
2808 iwl3945_scan_cancel(priv
);
2809 /* FIXME: This is a workaround for AP */
2810 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
2811 spin_lock_irqsave(&priv
->lock
, flags
);
2812 iwl3945_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
2813 CSR_UCODE_SW_BIT_RFKILL
);
2814 spin_unlock_irqrestore(&priv
->lock
, flags
);
2815 iwl3945_send_card_state(priv
, CARD_STATE_CMD_DISABLE
, 0);
2816 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2821 spin_lock_irqsave(&priv
->lock
, flags
);
2822 iwl3945_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2824 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2825 spin_unlock_irqrestore(&priv
->lock
, flags
);
2830 spin_lock_irqsave(&priv
->lock
, flags
);
2831 iwl3945_read32(priv
, CSR_UCODE_DRV_GP1
);
2832 if (!iwl3945_grab_nic_access(priv
))
2833 iwl3945_release_nic_access(priv
);
2834 spin_unlock_irqrestore(&priv
->lock
, flags
);
2836 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) {
2837 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2838 "disabled by HW switch\n");
2843 queue_work(priv
->workqueue
, &priv
->restart
);
2847 void iwl3945_set_decrypted_flag(struct iwl3945_priv
*priv
, struct sk_buff
*skb
,
2848 u32 decrypt_res
, struct ieee80211_rx_status
*stats
)
2851 le16_to_cpu(((struct ieee80211_hdr
*)skb
->data
)->frame_control
);
2853 if (priv
->active_rxon
.filter_flags
& RXON_FILTER_DIS_DECRYPT_MSK
)
2856 if (!(fc
& IEEE80211_FCTL_PROTECTED
))
2859 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res
);
2860 switch (decrypt_res
& RX_RES_STATUS_SEC_TYPE_MSK
) {
2861 case RX_RES_STATUS_SEC_TYPE_TKIP
:
2862 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2863 RX_RES_STATUS_BAD_ICV_MIC
)
2864 stats
->flag
|= RX_FLAG_MMIC_ERROR
;
2865 case RX_RES_STATUS_SEC_TYPE_WEP
:
2866 case RX_RES_STATUS_SEC_TYPE_CCMP
:
2867 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2868 RX_RES_STATUS_DECRYPT_OK
) {
2869 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
2870 stats
->flag
|= RX_FLAG_DECRYPTED
;
2879 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
2881 #include "iwl-spectrum.h"
2883 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
2884 #define BEACON_TIME_MASK_HIGH 0xFF000000
2885 #define TIME_UNIT 1024
2888 * extended beacon time format
2889 * time in usec will be changed into a 32-bit value in 8:24 format
2890 * the high 1 byte is the beacon counts
2891 * the lower 3 bytes is the time in usec within one beacon interval
2894 static u32
iwl3945_usecs_to_beacons(u32 usec
, u32 beacon_interval
)
2898 u32 interval
= beacon_interval
* 1024;
2900 if (!interval
|| !usec
)
2903 quot
= (usec
/ interval
) & (BEACON_TIME_MASK_HIGH
>> 24);
2904 rem
= (usec
% interval
) & BEACON_TIME_MASK_LOW
;
2906 return (quot
<< 24) + rem
;
2909 /* base is usually what we get from ucode with each received frame,
2910 * the same as HW timer counter counting down
2913 static __le32
iwl3945_add_beacon_time(u32 base
, u32 addon
, u32 beacon_interval
)
2915 u32 base_low
= base
& BEACON_TIME_MASK_LOW
;
2916 u32 addon_low
= addon
& BEACON_TIME_MASK_LOW
;
2917 u32 interval
= beacon_interval
* TIME_UNIT
;
2918 u32 res
= (base
& BEACON_TIME_MASK_HIGH
) +
2919 (addon
& BEACON_TIME_MASK_HIGH
);
2921 if (base_low
> addon_low
)
2922 res
+= base_low
- addon_low
;
2923 else if (base_low
< addon_low
) {
2924 res
+= interval
+ base_low
- addon_low
;
2929 return cpu_to_le32(res
);
2932 static int iwl3945_get_measurement(struct iwl3945_priv
*priv
,
2933 struct ieee80211_measurement_params
*params
,
2936 struct iwl3945_spectrum_cmd spectrum
;
2937 struct iwl3945_rx_packet
*res
;
2938 struct iwl3945_host_cmd cmd
= {
2939 .id
= REPLY_SPECTRUM_MEASUREMENT_CMD
,
2940 .data
= (void *)&spectrum
,
2941 .meta
.flags
= CMD_WANT_SKB
,
2943 u32 add_time
= le64_to_cpu(params
->start_time
);
2945 int spectrum_resp_status
;
2946 int duration
= le16_to_cpu(params
->duration
);
2948 if (iwl3945_is_associated(priv
))
2950 iwl3945_usecs_to_beacons(
2951 le64_to_cpu(params
->start_time
) - priv
->last_tsf
,
2952 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2954 memset(&spectrum
, 0, sizeof(spectrum
));
2956 spectrum
.channel_count
= cpu_to_le16(1);
2958 RXON_FLG_TSF2HOST_MSK
| RXON_FLG_ANT_A_MSK
| RXON_FLG_DIS_DIV_MSK
;
2959 spectrum
.filter_flags
= MEASUREMENT_FILTER_FLAG
;
2960 cmd
.len
= sizeof(spectrum
);
2961 spectrum
.len
= cpu_to_le16(cmd
.len
- sizeof(spectrum
.len
));
2963 if (iwl3945_is_associated(priv
))
2964 spectrum
.start_time
=
2965 iwl3945_add_beacon_time(priv
->last_beacon_time
,
2967 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2969 spectrum
.start_time
= 0;
2971 spectrum
.channels
[0].duration
= cpu_to_le32(duration
* TIME_UNIT
);
2972 spectrum
.channels
[0].channel
= params
->channel
;
2973 spectrum
.channels
[0].type
= type
;
2974 if (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
2975 spectrum
.flags
|= RXON_FLG_BAND_24G_MSK
|
2976 RXON_FLG_AUTO_DETECT_MSK
| RXON_FLG_TGG_PROTECT_MSK
;
2978 rc
= iwl3945_send_cmd_sync(priv
, &cmd
);
2982 res
= (struct iwl3945_rx_packet
*)cmd
.meta
.u
.skb
->data
;
2983 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
2984 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
2988 spectrum_resp_status
= le16_to_cpu(res
->u
.spectrum
.status
);
2989 switch (spectrum_resp_status
) {
2990 case 0: /* Command will be handled */
2991 if (res
->u
.spectrum
.id
!= 0xff) {
2992 IWL_DEBUG_INFO("Replaced existing measurement: %d\n",
2993 res
->u
.spectrum
.id
);
2994 priv
->measurement_status
&= ~MEASUREMENT_READY
;
2996 priv
->measurement_status
|= MEASUREMENT_ACTIVE
;
3000 case 1: /* Command will not be handled */
3005 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
3011 static void iwl3945_rx_reply_alive(struct iwl3945_priv
*priv
,
3012 struct iwl3945_rx_mem_buffer
*rxb
)
3014 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3015 struct iwl3945_alive_resp
*palive
;
3016 struct delayed_work
*pwork
;
3018 palive
= &pkt
->u
.alive_frame
;
3020 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
3022 palive
->is_valid
, palive
->ver_type
,
3023 palive
->ver_subtype
);
3025 if (palive
->ver_subtype
== INITIALIZE_SUBTYPE
) {
3026 IWL_DEBUG_INFO("Initialization Alive received.\n");
3027 memcpy(&priv
->card_alive_init
,
3028 &pkt
->u
.alive_frame
,
3029 sizeof(struct iwl3945_init_alive_resp
));
3030 pwork
= &priv
->init_alive_start
;
3032 IWL_DEBUG_INFO("Runtime Alive received.\n");
3033 memcpy(&priv
->card_alive
, &pkt
->u
.alive_frame
,
3034 sizeof(struct iwl3945_alive_resp
));
3035 pwork
= &priv
->alive_start
;
3036 iwl3945_disable_events(priv
);
3039 /* We delay the ALIVE response by 5ms to
3040 * give the HW RF Kill time to activate... */
3041 if (palive
->is_valid
== UCODE_VALID_OK
)
3042 queue_delayed_work(priv
->workqueue
, pwork
,
3043 msecs_to_jiffies(5));
3045 IWL_WARNING("uCode did not respond OK.\n");
3048 static void iwl3945_rx_reply_add_sta(struct iwl3945_priv
*priv
,
3049 struct iwl3945_rx_mem_buffer
*rxb
)
3051 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3053 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt
->u
.status
);
3057 static void iwl3945_rx_reply_error(struct iwl3945_priv
*priv
,
3058 struct iwl3945_rx_mem_buffer
*rxb
)
3060 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3062 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
3063 "seq 0x%04X ser 0x%08X\n",
3064 le32_to_cpu(pkt
->u
.err_resp
.error_type
),
3065 get_cmd_string(pkt
->u
.err_resp
.cmd_id
),
3066 pkt
->u
.err_resp
.cmd_id
,
3067 le16_to_cpu(pkt
->u
.err_resp
.bad_cmd_seq_num
),
3068 le32_to_cpu(pkt
->u
.err_resp
.error_info
));
3071 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
3073 static void iwl3945_rx_csa(struct iwl3945_priv
*priv
, struct iwl3945_rx_mem_buffer
*rxb
)
3075 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3076 struct iwl3945_rxon_cmd
*rxon
= (void *)&priv
->active_rxon
;
3077 struct iwl3945_csa_notification
*csa
= &(pkt
->u
.csa_notif
);
3078 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
3079 le16_to_cpu(csa
->channel
), le32_to_cpu(csa
->status
));
3080 rxon
->channel
= csa
->channel
;
3081 priv
->staging_rxon
.channel
= csa
->channel
;
3084 static void iwl3945_rx_spectrum_measure_notif(struct iwl3945_priv
*priv
,
3085 struct iwl3945_rx_mem_buffer
*rxb
)
3087 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
3088 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3089 struct iwl3945_spectrum_notification
*report
= &(pkt
->u
.spectrum_notif
);
3091 if (!report
->state
) {
3092 IWL_DEBUG(IWL_DL_11H
| IWL_DL_INFO
,
3093 "Spectrum Measure Notification: Start\n");
3097 memcpy(&priv
->measure_report
, report
, sizeof(*report
));
3098 priv
->measurement_status
|= MEASUREMENT_READY
;
3102 static void iwl3945_rx_pm_sleep_notif(struct iwl3945_priv
*priv
,
3103 struct iwl3945_rx_mem_buffer
*rxb
)
3105 #ifdef CONFIG_IWL3945_DEBUG
3106 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3107 struct iwl3945_sleep_notification
*sleep
= &(pkt
->u
.sleep_notif
);
3108 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
3109 sleep
->pm_sleep_mode
, sleep
->pm_wakeup_src
);
3113 static void iwl3945_rx_pm_debug_statistics_notif(struct iwl3945_priv
*priv
,
3114 struct iwl3945_rx_mem_buffer
*rxb
)
3116 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3117 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
3118 "notification for %s:\n",
3119 le32_to_cpu(pkt
->len
), get_cmd_string(pkt
->hdr
.cmd
));
3120 iwl3945_print_hex_dump(IWL_DL_RADIO
, pkt
->u
.raw
, le32_to_cpu(pkt
->len
));
3123 static void iwl3945_bg_beacon_update(struct work_struct
*work
)
3125 struct iwl3945_priv
*priv
=
3126 container_of(work
, struct iwl3945_priv
, beacon_update
);
3127 struct sk_buff
*beacon
;
3129 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
3130 beacon
= ieee80211_beacon_get(priv
->hw
, priv
->vif
);
3133 IWL_ERROR("update beacon failed\n");
3137 mutex_lock(&priv
->mutex
);
3138 /* new beacon skb is allocated every time; dispose previous.*/
3139 if (priv
->ibss_beacon
)
3140 dev_kfree_skb(priv
->ibss_beacon
);
3142 priv
->ibss_beacon
= beacon
;
3143 mutex_unlock(&priv
->mutex
);
3145 iwl3945_send_beacon_cmd(priv
);
3148 static void iwl3945_rx_beacon_notif(struct iwl3945_priv
*priv
,
3149 struct iwl3945_rx_mem_buffer
*rxb
)
3151 #ifdef CONFIG_IWL3945_DEBUG
3152 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3153 struct iwl3945_beacon_notif
*beacon
= &(pkt
->u
.beacon_status
);
3154 u8 rate
= beacon
->beacon_notify_hdr
.rate
;
3156 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
3157 "tsf %d %d rate %d\n",
3158 le32_to_cpu(beacon
->beacon_notify_hdr
.status
) & TX_STATUS_MSK
,
3159 beacon
->beacon_notify_hdr
.failure_frame
,
3160 le32_to_cpu(beacon
->ibss_mgr_status
),
3161 le32_to_cpu(beacon
->high_tsf
),
3162 le32_to_cpu(beacon
->low_tsf
), rate
);
3165 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
3166 (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)))
3167 queue_work(priv
->workqueue
, &priv
->beacon_update
);
3170 /* Service response to REPLY_SCAN_CMD (0x80) */
3171 static void iwl3945_rx_reply_scan(struct iwl3945_priv
*priv
,
3172 struct iwl3945_rx_mem_buffer
*rxb
)
3174 #ifdef CONFIG_IWL3945_DEBUG
3175 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3176 struct iwl3945_scanreq_notification
*notif
=
3177 (struct iwl3945_scanreq_notification
*)pkt
->u
.raw
;
3179 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif
->status
);
3183 /* Service SCAN_START_NOTIFICATION (0x82) */
3184 static void iwl3945_rx_scan_start_notif(struct iwl3945_priv
*priv
,
3185 struct iwl3945_rx_mem_buffer
*rxb
)
3187 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3188 struct iwl3945_scanstart_notification
*notif
=
3189 (struct iwl3945_scanstart_notification
*)pkt
->u
.raw
;
3190 priv
->scan_start_tsf
= le32_to_cpu(notif
->tsf_low
);
3191 IWL_DEBUG_SCAN("Scan start: "
3193 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
3195 notif
->band
? "bg" : "a",
3197 notif
->tsf_low
, notif
->status
, notif
->beacon_timer
);
3200 /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
3201 static void iwl3945_rx_scan_results_notif(struct iwl3945_priv
*priv
,
3202 struct iwl3945_rx_mem_buffer
*rxb
)
3204 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3205 struct iwl3945_scanresults_notification
*notif
=
3206 (struct iwl3945_scanresults_notification
*)pkt
->u
.raw
;
3208 IWL_DEBUG_SCAN("Scan ch.res: "
3210 "(TSF: 0x%08X:%08X) - %d "
3211 "elapsed=%lu usec (%dms since last)\n",
3213 notif
->band
? "bg" : "a",
3214 le32_to_cpu(notif
->tsf_high
),
3215 le32_to_cpu(notif
->tsf_low
),
3216 le32_to_cpu(notif
->statistics
[0]),
3217 le32_to_cpu(notif
->tsf_low
) - priv
->scan_start_tsf
,
3218 jiffies_to_msecs(elapsed_jiffies
3219 (priv
->last_scan_jiffies
, jiffies
)));
3221 priv
->last_scan_jiffies
= jiffies
;
3222 priv
->next_scan_jiffies
= 0;
3225 /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
3226 static void iwl3945_rx_scan_complete_notif(struct iwl3945_priv
*priv
,
3227 struct iwl3945_rx_mem_buffer
*rxb
)
3229 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3230 struct iwl3945_scancomplete_notification
*scan_notif
= (void *)pkt
->u
.raw
;
3232 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
3233 scan_notif
->scanned_channels
,
3234 scan_notif
->tsf_low
,
3235 scan_notif
->tsf_high
, scan_notif
->status
);
3237 /* The HW is no longer scanning */
3238 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
3240 /* The scan completion notification came in, so kill that timer... */
3241 cancel_delayed_work(&priv
->scan_check
);
3243 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
3244 (priv
->scan_bands
& BIT(IEEE80211_BAND_2GHZ
)) ?
3246 jiffies_to_msecs(elapsed_jiffies
3247 (priv
->scan_pass_start
, jiffies
)));
3249 /* Remove this scanned band from the list of pending
3250 * bands to scan, band G precedes A in order of scanning
3251 * as seen in iwl3945_bg_request_scan */
3252 if (priv
->scan_bands
& BIT(IEEE80211_BAND_2GHZ
))
3253 priv
->scan_bands
&= ~BIT(IEEE80211_BAND_2GHZ
);
3254 else if (priv
->scan_bands
& BIT(IEEE80211_BAND_5GHZ
))
3255 priv
->scan_bands
&= ~BIT(IEEE80211_BAND_5GHZ
);
3257 /* If a request to abort was given, or the scan did not succeed
3258 * then we reset the scan state machine and terminate,
3259 * re-queuing another scan if one has been requested */
3260 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
3261 IWL_DEBUG_INFO("Aborted scan completed.\n");
3262 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
3264 /* If there are more bands on this scan pass reschedule */
3265 if (priv
->scan_bands
> 0)
3269 priv
->last_scan_jiffies
= jiffies
;
3270 priv
->next_scan_jiffies
= 0;
3271 IWL_DEBUG_INFO("Setting scan to off\n");
3273 clear_bit(STATUS_SCANNING
, &priv
->status
);
3275 IWL_DEBUG_INFO("Scan took %dms\n",
3276 jiffies_to_msecs(elapsed_jiffies(priv
->scan_start
, jiffies
)));
3278 queue_work(priv
->workqueue
, &priv
->scan_completed
);
3283 priv
->scan_pass_start
= jiffies
;
3284 queue_work(priv
->workqueue
, &priv
->request_scan
);
3287 /* Handle notification from uCode that card's power state is changing
3288 * due to software, hardware, or critical temperature RFKILL */
3289 static void iwl3945_rx_card_state_notif(struct iwl3945_priv
*priv
,
3290 struct iwl3945_rx_mem_buffer
*rxb
)
3292 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3293 u32 flags
= le32_to_cpu(pkt
->u
.card_state_notif
.flags
);
3294 unsigned long status
= priv
->status
;
3296 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
3297 (flags
& HW_CARD_DISABLED
) ? "Kill" : "On",
3298 (flags
& SW_CARD_DISABLED
) ? "Kill" : "On");
3300 iwl3945_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
3301 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
3303 if (flags
& HW_CARD_DISABLED
)
3304 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
3306 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
3309 if (flags
& SW_CARD_DISABLED
)
3310 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
3312 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
3314 iwl3945_scan_cancel(priv
);
3316 if ((test_bit(STATUS_RF_KILL_HW
, &status
) !=
3317 test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) ||
3318 (test_bit(STATUS_RF_KILL_SW
, &status
) !=
3319 test_bit(STATUS_RF_KILL_SW
, &priv
->status
)))
3320 queue_work(priv
->workqueue
, &priv
->rf_kill
);
3322 wake_up_interruptible(&priv
->wait_command_queue
);
3326 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
3328 * Setup the RX handlers for each of the reply types sent from the uCode
3331 * This function chains into the hardware specific files for them to setup
3332 * any hardware specific handlers as well.
3334 static void iwl3945_setup_rx_handlers(struct iwl3945_priv
*priv
)
3336 priv
->rx_handlers
[REPLY_ALIVE
] = iwl3945_rx_reply_alive
;
3337 priv
->rx_handlers
[REPLY_ADD_STA
] = iwl3945_rx_reply_add_sta
;
3338 priv
->rx_handlers
[REPLY_ERROR
] = iwl3945_rx_reply_error
;
3339 priv
->rx_handlers
[CHANNEL_SWITCH_NOTIFICATION
] = iwl3945_rx_csa
;
3340 priv
->rx_handlers
[SPECTRUM_MEASURE_NOTIFICATION
] =
3341 iwl3945_rx_spectrum_measure_notif
;
3342 priv
->rx_handlers
[PM_SLEEP_NOTIFICATION
] = iwl3945_rx_pm_sleep_notif
;
3343 priv
->rx_handlers
[PM_DEBUG_STATISTIC_NOTIFIC
] =
3344 iwl3945_rx_pm_debug_statistics_notif
;
3345 priv
->rx_handlers
[BEACON_NOTIFICATION
] = iwl3945_rx_beacon_notif
;
3348 * The same handler is used for both the REPLY to a discrete
3349 * statistics request from the host as well as for the periodic
3350 * statistics notifications (after received beacons) from the uCode.
3352 priv
->rx_handlers
[REPLY_STATISTICS_CMD
] = iwl3945_hw_rx_statistics
;
3353 priv
->rx_handlers
[STATISTICS_NOTIFICATION
] = iwl3945_hw_rx_statistics
;
3355 priv
->rx_handlers
[REPLY_SCAN_CMD
] = iwl3945_rx_reply_scan
;
3356 priv
->rx_handlers
[SCAN_START_NOTIFICATION
] = iwl3945_rx_scan_start_notif
;
3357 priv
->rx_handlers
[SCAN_RESULTS_NOTIFICATION
] =
3358 iwl3945_rx_scan_results_notif
;
3359 priv
->rx_handlers
[SCAN_COMPLETE_NOTIFICATION
] =
3360 iwl3945_rx_scan_complete_notif
;
3361 priv
->rx_handlers
[CARD_STATE_NOTIFICATION
] = iwl3945_rx_card_state_notif
;
3363 /* Set up hardware specific Rx handlers */
3364 iwl3945_hw_rx_handler_setup(priv
);
3368 * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries
3369 * When FW advances 'R' index, all entries between old and new 'R' index
3370 * need to be reclaimed.
3372 static void iwl3945_cmd_queue_reclaim(struct iwl3945_priv
*priv
,
3373 int txq_id
, int index
)
3375 struct iwl3945_tx_queue
*txq
= &priv
->txq
[txq_id
];
3376 struct iwl3945_queue
*q
= &txq
->q
;
3379 if ((index
>= q
->n_bd
) || (iwl3945_x2_queue_used(q
, index
) == 0)) {
3380 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
3381 "is out of range [0-%d] %d %d.\n", txq_id
,
3382 index
, q
->n_bd
, q
->write_ptr
, q
->read_ptr
);
3386 for (index
= iwl_queue_inc_wrap(index
, q
->n_bd
); q
->read_ptr
!= index
;
3387 q
->read_ptr
= iwl_queue_inc_wrap(q
->read_ptr
, q
->n_bd
)) {
3389 IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index
,
3390 q
->write_ptr
, q
->read_ptr
);
3391 queue_work(priv
->workqueue
, &priv
->restart
);
3400 * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
3401 * @rxb: Rx buffer to reclaim
3403 * If an Rx buffer has an async callback associated with it the callback
3404 * will be executed. The attached skb (if present) will only be freed
3405 * if the callback returns 1
3407 static void iwl3945_tx_cmd_complete(struct iwl3945_priv
*priv
,
3408 struct iwl3945_rx_mem_buffer
*rxb
)
3410 struct iwl3945_rx_packet
*pkt
= (struct iwl3945_rx_packet
*)rxb
->skb
->data
;
3411 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
3412 int txq_id
= SEQ_TO_QUEUE(sequence
);
3413 int index
= SEQ_TO_INDEX(sequence
);
3414 int huge
= sequence
& SEQ_HUGE_FRAME
;
3416 struct iwl3945_cmd
*cmd
;
3418 BUG_ON(txq_id
!= IWL_CMD_QUEUE_NUM
);
3420 cmd_index
= get_cmd_index(&priv
->txq
[IWL_CMD_QUEUE_NUM
].q
, index
, huge
);
3421 cmd
= &priv
->txq
[IWL_CMD_QUEUE_NUM
].cmd
[cmd_index
];
3423 /* Input error checking is done when commands are added to queue. */
3424 if (cmd
->meta
.flags
& CMD_WANT_SKB
) {
3425 cmd
->meta
.source
->u
.skb
= rxb
->skb
;
3427 } else if (cmd
->meta
.u
.callback
&&
3428 !cmd
->meta
.u
.callback(priv
, cmd
, rxb
->skb
))
3431 iwl3945_cmd_queue_reclaim(priv
, txq_id
, index
);
3433 if (!(cmd
->meta
.flags
& CMD_ASYNC
)) {
3434 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
3435 wake_up_interruptible(&priv
->wait_command_queue
);
3439 /************************** RX-FUNCTIONS ****************************/
3441 * Rx theory of operation
3443 * The host allocates 32 DMA target addresses and passes the host address
3444 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
3448 * The host/firmware share two index registers for managing the Rx buffers.
3450 * The READ index maps to the first position that the firmware may be writing
3451 * to -- the driver can read up to (but not including) this position and get
3453 * The READ index is managed by the firmware once the card is enabled.
3455 * The WRITE index maps to the last position the driver has read from -- the
3456 * position preceding WRITE is the last slot the firmware can place a packet.
3458 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
3461 * During initialization, the host sets up the READ queue position to the first
3462 * INDEX position, and WRITE to the last (READ - 1 wrapped)
3464 * When the firmware places a packet in a buffer, it will advance the READ index
3465 * and fire the RX interrupt. The driver can then query the READ index and
3466 * process as many packets as possible, moving the WRITE index forward as it
3467 * resets the Rx queue buffers with new memory.
3469 * The management in the driver is as follows:
3470 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
3471 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
3472 * to replenish the iwl->rxq->rx_free.
3473 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
3474 * iwl->rxq is replenished and the READ INDEX is updated (updating the
3475 * 'processed' and 'read' driver indexes as well)
3476 * + A received packet is processed and handed to the kernel network stack,
3477 * detached from the iwl->rxq. The driver 'processed' index is updated.
3478 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
3479 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
3480 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
3481 * were enough free buffers and RX_STALLED is set it is cleared.
3486 * iwl3945_rx_queue_alloc() Allocates rx_free
3487 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
3488 * iwl3945_rx_queue_restock
3489 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
3490 * queue, updates firmware pointers, and updates
3491 * the WRITE index. If insufficient rx_free buffers
3492 * are available, schedules iwl3945_rx_replenish
3494 * -- enable interrupts --
3495 * ISR - iwl3945_rx() Detach iwl3945_rx_mem_buffers from pool up to the
3496 * READ INDEX, detaching the SKB from the pool.
3497 * Moves the packet buffer from queue to rx_used.
3498 * Calls iwl3945_rx_queue_restock to refill any empty
3505 * iwl3945_rx_queue_space - Return number of free slots available in queue.
3507 static int iwl3945_rx_queue_space(const struct iwl3945_rx_queue
*q
)
3509 int s
= q
->read
- q
->write
;
3512 /* keep some buffer to not confuse full and empty queue */
3520 * iwl3945_rx_queue_update_write_ptr - Update the write pointer for the RX queue
3522 int iwl3945_rx_queue_update_write_ptr(struct iwl3945_priv
*priv
, struct iwl3945_rx_queue
*q
)
3526 unsigned long flags
;
3528 spin_lock_irqsave(&q
->lock
, flags
);
3530 if (q
->need_update
== 0)
3533 /* If power-saving is in use, make sure device is awake */
3534 if (test_bit(STATUS_POWER_PMI
, &priv
->status
)) {
3535 reg
= iwl3945_read32(priv
, CSR_UCODE_DRV_GP1
);
3537 if (reg
& CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP
) {
3538 iwl3945_set_bit(priv
, CSR_GP_CNTRL
,
3539 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
3543 rc
= iwl3945_grab_nic_access(priv
);
3547 /* Device expects a multiple of 8 */
3548 iwl3945_write_direct32(priv
, FH_RSCSR_CHNL0_WPTR
,
3550 iwl3945_release_nic_access(priv
);
3552 /* Else device is assumed to be awake */
3554 /* Device expects a multiple of 8 */
3555 iwl3945_write32(priv
, FH_RSCSR_CHNL0_WPTR
, q
->write
& ~0x7);
3561 spin_unlock_irqrestore(&q
->lock
, flags
);
3566 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
3568 static inline __le32
iwl3945_dma_addr2rbd_ptr(struct iwl3945_priv
*priv
,
3569 dma_addr_t dma_addr
)
3571 return cpu_to_le32((u32
)dma_addr
);
3575 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
3577 * If there are slots in the RX queue that need to be restocked,
3578 * and we have free pre-allocated buffers, fill the ranks as much
3579 * as we can, pulling from rx_free.
3581 * This moves the 'write' index forward to catch up with 'processed', and
3582 * also updates the memory address in the firmware to reference the new
3585 static int iwl3945_rx_queue_restock(struct iwl3945_priv
*priv
)
3587 struct iwl3945_rx_queue
*rxq
= &priv
->rxq
;
3588 struct list_head
*element
;
3589 struct iwl3945_rx_mem_buffer
*rxb
;
3590 unsigned long flags
;
3593 spin_lock_irqsave(&rxq
->lock
, flags
);
3594 write
= rxq
->write
& ~0x7;
3595 while ((iwl3945_rx_queue_space(rxq
) > 0) && (rxq
->free_count
)) {
3596 /* Get next free Rx buffer, remove from free list */
3597 element
= rxq
->rx_free
.next
;
3598 rxb
= list_entry(element
, struct iwl3945_rx_mem_buffer
, list
);
3601 /* Point to Rx buffer via next RBD in circular buffer */
3602 rxq
->bd
[rxq
->write
] = iwl3945_dma_addr2rbd_ptr(priv
, rxb
->dma_addr
);
3603 rxq
->queue
[rxq
->write
] = rxb
;
3604 rxq
->write
= (rxq
->write
+ 1) & RX_QUEUE_MASK
;
3607 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3608 /* If the pre-allocated buffer pool is dropping low, schedule to
3610 if (rxq
->free_count
<= RX_LOW_WATERMARK
)
3611 queue_work(priv
->workqueue
, &priv
->rx_replenish
);
3614 /* If we've added more space for the firmware to place data, tell it.
3615 * Increment device's write pointer in multiples of 8. */
3616 if ((write
!= (rxq
->write
& ~0x7))
3617 || (abs(rxq
->write
- rxq
->read
) > 7)) {
3618 spin_lock_irqsave(&rxq
->lock
, flags
);
3619 rxq
->need_update
= 1;
3620 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3621 rc
= iwl3945_rx_queue_update_write_ptr(priv
, rxq
);
3630 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
3632 * When moving to rx_free an SKB is allocated for the slot.
3634 * Also restock the Rx queue via iwl3945_rx_queue_restock.
3635 * This is called as a scheduled work item (except for during initialization)
3637 static void iwl3945_rx_allocate(struct iwl3945_priv
*priv
)
3639 struct iwl3945_rx_queue
*rxq
= &priv
->rxq
;
3640 struct list_head
*element
;
3641 struct iwl3945_rx_mem_buffer
*rxb
;
3642 unsigned long flags
;
3643 spin_lock_irqsave(&rxq
->lock
, flags
);
3644 while (!list_empty(&rxq
->rx_used
)) {
3645 element
= rxq
->rx_used
.next
;
3646 rxb
= list_entry(element
, struct iwl3945_rx_mem_buffer
, list
);
3648 /* Alloc a new receive buffer */
3650 alloc_skb(IWL_RX_BUF_SIZE
, __GFP_NOWARN
| GFP_ATOMIC
);
3652 if (net_ratelimit())
3653 printk(KERN_CRIT DRV_NAME
3654 ": Can not allocate SKB buffers\n");
3655 /* We don't reschedule replenish work here -- we will
3656 * call the restock method and if it still needs
3657 * more buffers it will schedule replenish */
3661 /* If radiotap head is required, reserve some headroom here.
3662 * The physical head count is a variable rx_stats->phy_count.
3663 * We reserve 4 bytes here. Plus these extra bytes, the
3664 * headroom of the physical head should be enough for the
3665 * radiotap head that iwl3945 supported. See iwl3945_rt.
3667 skb_reserve(rxb
->skb
, 4);
3669 priv
->alloc_rxb_skb
++;
3672 /* Get physical address of RB/SKB */
3674 pci_map_single(priv
->pci_dev
, rxb
->skb
->data
,
3675 IWL_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
3676 list_add_tail(&rxb
->list
, &rxq
->rx_free
);
3679 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3683 * this should be called while priv->lock is locked
3685 static void __iwl3945_rx_replenish(void *data
)
3687 struct iwl3945_priv
*priv
= data
;
3689 iwl3945_rx_allocate(priv
);
3690 iwl3945_rx_queue_restock(priv
);
3694 void iwl3945_rx_replenish(void *data
)
3696 struct iwl3945_priv
*priv
= data
;
3697 unsigned long flags
;
3699 iwl3945_rx_allocate(priv
);
3701 spin_lock_irqsave(&priv
->lock
, flags
);
3702 iwl3945_rx_queue_restock(priv
);
3703 spin_unlock_irqrestore(&priv
->lock
, flags
);
3706 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
3707 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
3708 * This free routine walks the list of POOL entries and if SKB is set to
3709 * non NULL it is unmapped and freed
3711 static void iwl3945_rx_queue_free(struct iwl3945_priv
*priv
, struct iwl3945_rx_queue
*rxq
)
3714 for (i
= 0; i
< RX_QUEUE_SIZE
+ RX_FREE_BUFFERS
; i
++) {
3715 if (rxq
->pool
[i
].skb
!= NULL
) {
3716 pci_unmap_single(priv
->pci_dev
,
3717 rxq
->pool
[i
].dma_addr
,
3718 IWL_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
3719 dev_kfree_skb(rxq
->pool
[i
].skb
);
3723 pci_free_consistent(priv
->pci_dev
, 4 * RX_QUEUE_SIZE
, rxq
->bd
,
3728 int iwl3945_rx_queue_alloc(struct iwl3945_priv
*priv
)
3730 struct iwl3945_rx_queue
*rxq
= &priv
->rxq
;
3731 struct pci_dev
*dev
= priv
->pci_dev
;
3734 spin_lock_init(&rxq
->lock
);
3735 INIT_LIST_HEAD(&rxq
->rx_free
);
3736 INIT_LIST_HEAD(&rxq
->rx_used
);
3738 /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
3739 rxq
->bd
= pci_alloc_consistent(dev
, 4 * RX_QUEUE_SIZE
, &rxq
->dma_addr
);
3743 /* Fill the rx_used queue with _all_ of the Rx buffers */
3744 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++)
3745 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
3747 /* Set us so that we have processed and used all buffers, but have
3748 * not restocked the Rx queue with fresh buffers */
3749 rxq
->read
= rxq
->write
= 0;
3750 rxq
->free_count
= 0;
3751 rxq
->need_update
= 0;
3755 void iwl3945_rx_queue_reset(struct iwl3945_priv
*priv
, struct iwl3945_rx_queue
*rxq
)
3757 unsigned long flags
;
3759 spin_lock_irqsave(&rxq
->lock
, flags
);
3760 INIT_LIST_HEAD(&rxq
->rx_free
);
3761 INIT_LIST_HEAD(&rxq
->rx_used
);
3762 /* Fill the rx_used queue with _all_ of the Rx buffers */
3763 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++) {
3764 /* In the reset function, these buffers may have been allocated
3765 * to an SKB, so we need to unmap and free potential storage */
3766 if (rxq
->pool
[i
].skb
!= NULL
) {
3767 pci_unmap_single(priv
->pci_dev
,
3768 rxq
->pool
[i
].dma_addr
,
3769 IWL_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
3770 priv
->alloc_rxb_skb
--;
3771 dev_kfree_skb(rxq
->pool
[i
].skb
);
3772 rxq
->pool
[i
].skb
= NULL
;
3774 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
3777 /* Set us so that we have processed and used all buffers, but have
3778 * not restocked the Rx queue with fresh buffers */
3779 rxq
->read
= rxq
->write
= 0;
3780 rxq
->free_count
= 0;
3781 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3784 /* Convert linear signal-to-noise ratio into dB */
3785 static u8 ratio2dB
[100] = {
3786 /* 0 1 2 3 4 5 6 7 8 9 */
3787 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
3788 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
3789 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
3790 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
3791 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
3792 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
3793 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
3794 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
3795 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
3796 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
3799 /* Calculates a relative dB value from a ratio of linear
3800 * (i.e. not dB) signal levels.
3801 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
3802 int iwl3945_calc_db_from_ratio(int sig_ratio
)
3804 /* 1000:1 or higher just report as 60 dB */
3805 if (sig_ratio
>= 1000)
3808 /* 100:1 or higher, divide by 10 and use table,
3809 * add 20 dB to make up for divide by 10 */
3810 if (sig_ratio
>= 100)
3811 return 20 + (int)ratio2dB
[sig_ratio
/10];
3813 /* We shouldn't see this */
3817 /* Use table for ratios 1:1 - 99:1 */
3818 return (int)ratio2dB
[sig_ratio
];
3821 #define PERFECT_RSSI (-20) /* dBm */
3822 #define WORST_RSSI (-95) /* dBm */
3823 #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
3825 /* Calculate an indication of rx signal quality (a percentage, not dBm!).
3826 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
3827 * about formulas used below. */
3828 int iwl3945_calc_sig_qual(int rssi_dbm
, int noise_dbm
)
3831 int degradation
= PERFECT_RSSI
- rssi_dbm
;
3833 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
3834 * as indicator; formula is (signal dbm - noise dbm).
3835 * SNR at or above 40 is a great signal (100%).
3836 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
3837 * Weakest usable signal is usually 10 - 15 dB SNR. */
3839 if (rssi_dbm
- noise_dbm
>= 40)
3841 else if (rssi_dbm
< noise_dbm
)
3843 sig_qual
= ((rssi_dbm
- noise_dbm
) * 5) / 2;
3845 /* Else use just the signal level.
3846 * This formula is a least squares fit of data points collected and
3847 * compared with a reference system that had a percentage (%) display
3848 * for signal quality. */
3850 sig_qual
= (100 * (RSSI_RANGE
* RSSI_RANGE
) - degradation
*
3851 (15 * RSSI_RANGE
+ 62 * degradation
)) /
3852 (RSSI_RANGE
* RSSI_RANGE
);
3856 else if (sig_qual
< 1)
3863 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
3865 * Uses the priv->rx_handlers callback function array to invoke
3866 * the appropriate handlers, including command responses,
3867 * frame-received notifications, and other notifications.
3869 static void iwl3945_rx_handle(struct iwl3945_priv
*priv
)
3871 struct iwl3945_rx_mem_buffer
*rxb
;
3872 struct iwl3945_rx_packet
*pkt
;
3873 struct iwl3945_rx_queue
*rxq
= &priv
->rxq
;
3876 unsigned long flags
;
3880 /* uCode's read index (stored in shared DRAM) indicates the last Rx
3881 * buffer that the driver may process (last buffer filled by ucode). */
3882 r
= iwl3945_hw_get_rx_read(priv
);
3885 if (iwl3945_rx_queue_space(rxq
) > (RX_QUEUE_SIZE
/ 2))
3887 /* Rx interrupt, but nothing sent from uCode */
3889 IWL_DEBUG(IWL_DL_RX
| IWL_DL_ISR
, "r = %d, i = %d\n", r
, i
);
3892 rxb
= rxq
->queue
[i
];
3894 /* If an RXB doesn't have a Rx queue slot associated with it,
3895 * then a bug has been introduced in the queue refilling
3896 * routines -- catch it here */
3897 BUG_ON(rxb
== NULL
);
3899 rxq
->queue
[i
] = NULL
;
3901 pci_dma_sync_single_for_cpu(priv
->pci_dev
, rxb
->dma_addr
,
3903 PCI_DMA_FROMDEVICE
);
3904 pkt
= (struct iwl3945_rx_packet
*)rxb
->skb
->data
;
3906 /* Reclaim a command buffer only if this packet is a response
3907 * to a (driver-originated) command.
3908 * If the packet (e.g. Rx frame) originated from uCode,
3909 * there is no command buffer to reclaim.
3910 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
3911 * but apparently a few don't get set; catch them here. */
3912 reclaim
= !(pkt
->hdr
.sequence
& SEQ_RX_FRAME
) &&
3913 (pkt
->hdr
.cmd
!= STATISTICS_NOTIFICATION
) &&
3914 (pkt
->hdr
.cmd
!= REPLY_TX
);
3916 /* Based on type of command response or notification,
3917 * handle those that need handling via function in
3918 * rx_handlers table. See iwl3945_setup_rx_handlers() */
3919 if (priv
->rx_handlers
[pkt
->hdr
.cmd
]) {
3920 IWL_DEBUG(IWL_DL_HOST_COMMAND
| IWL_DL_RX
| IWL_DL_ISR
,
3921 "r = %d, i = %d, %s, 0x%02x\n", r
, i
,
3922 get_cmd_string(pkt
->hdr
.cmd
), pkt
->hdr
.cmd
);
3923 priv
->rx_handlers
[pkt
->hdr
.cmd
] (priv
, rxb
);
3925 /* No handling needed */
3926 IWL_DEBUG(IWL_DL_HOST_COMMAND
| IWL_DL_RX
| IWL_DL_ISR
,
3927 "r %d i %d No handler needed for %s, 0x%02x\n",
3928 r
, i
, get_cmd_string(pkt
->hdr
.cmd
),
3933 /* Invoke any callbacks, transfer the skb to caller, and
3934 * fire off the (possibly) blocking iwl3945_send_cmd()
3935 * as we reclaim the driver command queue */
3936 if (rxb
&& rxb
->skb
)
3937 iwl3945_tx_cmd_complete(priv
, rxb
);
3939 IWL_WARNING("Claim null rxb?\n");
3942 /* For now we just don't re-use anything. We can tweak this
3943 * later to try and re-use notification packets and SKBs that
3944 * fail to Rx correctly */
3945 if (rxb
->skb
!= NULL
) {
3946 priv
->alloc_rxb_skb
--;
3947 dev_kfree_skb_any(rxb
->skb
);
3951 pci_unmap_single(priv
->pci_dev
, rxb
->dma_addr
,
3952 IWL_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
3953 spin_lock_irqsave(&rxq
->lock
, flags
);
3954 list_add_tail(&rxb
->list
, &priv
->rxq
.rx_used
);
3955 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3956 i
= (i
+ 1) & RX_QUEUE_MASK
;
3957 /* If there are a lot of unused frames,
3958 * restock the Rx queue so ucode won't assert. */
3963 __iwl3945_rx_replenish(priv
);
3969 /* Backtrack one entry */
3971 iwl3945_rx_queue_restock(priv
);
3975 * iwl3945_tx_queue_update_write_ptr - Send new write index to hardware
3977 static int iwl3945_tx_queue_update_write_ptr(struct iwl3945_priv
*priv
,
3978 struct iwl3945_tx_queue
*txq
)
3982 int txq_id
= txq
->q
.id
;
3984 if (txq
->need_update
== 0)
3987 /* if we're trying to save power */
3988 if (test_bit(STATUS_POWER_PMI
, &priv
->status
)) {
3989 /* wake up nic if it's powered down ...
3990 * uCode will wake up, and interrupt us again, so next
3991 * time we'll skip this part. */
3992 reg
= iwl3945_read32(priv
, CSR_UCODE_DRV_GP1
);
3994 if (reg
& CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP
) {
3995 IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg
);
3996 iwl3945_set_bit(priv
, CSR_GP_CNTRL
,
3997 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
4001 /* restore this queue's parameters in nic hardware. */
4002 rc
= iwl3945_grab_nic_access(priv
);
4005 iwl3945_write_direct32(priv
, HBUS_TARG_WRPTR
,
4006 txq
->q
.write_ptr
| (txq_id
<< 8));
4007 iwl3945_release_nic_access(priv
);
4009 /* else not in power-save mode, uCode will never sleep when we're
4010 * trying to tx (during RFKILL, we're not trying to tx). */
4012 iwl3945_write32(priv
, HBUS_TARG_WRPTR
,
4013 txq
->q
.write_ptr
| (txq_id
<< 8));
4015 txq
->need_update
= 0;
4020 #ifdef CONFIG_IWL3945_DEBUG
4021 static void iwl3945_print_rx_config_cmd(struct iwl3945_rxon_cmd
*rxon
)
4023 DECLARE_MAC_BUF(mac
);
4025 IWL_DEBUG_RADIO("RX CONFIG:\n");
4026 iwl3945_print_hex_dump(IWL_DL_RADIO
, (u8
*) rxon
, sizeof(*rxon
));
4027 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon
->channel
));
4028 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon
->flags
));
4029 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
4030 le32_to_cpu(rxon
->filter_flags
));
4031 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon
->dev_type
);
4032 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
4033 rxon
->ofdm_basic_rates
);
4034 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon
->cck_basic_rates
);
4035 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
4036 print_mac(mac
, rxon
->node_addr
));
4037 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
4038 print_mac(mac
, rxon
->bssid_addr
));
4039 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon
->assoc_id
));
4043 static void iwl3945_enable_interrupts(struct iwl3945_priv
*priv
)
4045 IWL_DEBUG_ISR("Enabling interrupts\n");
4046 set_bit(STATUS_INT_ENABLED
, &priv
->status
);
4047 iwl3945_write32(priv
, CSR_INT_MASK
, CSR_INI_SET_MASK
);
4051 /* call this function to flush any scheduled tasklet */
4052 static inline void iwl_synchronize_irq(struct iwl3945_priv
*priv
)
4054 /* wait to make sure we flush pedding tasklet*/
4055 synchronize_irq(priv
->pci_dev
->irq
);
4056 tasklet_kill(&priv
->irq_tasklet
);
4060 static inline void iwl3945_disable_interrupts(struct iwl3945_priv
*priv
)
4062 clear_bit(STATUS_INT_ENABLED
, &priv
->status
);
4064 /* disable interrupts from uCode/NIC to host */
4065 iwl3945_write32(priv
, CSR_INT_MASK
, 0x00000000);
4067 /* acknowledge/clear/reset any interrupts still pending
4068 * from uCode or flow handler (Rx/Tx DMA) */
4069 iwl3945_write32(priv
, CSR_INT
, 0xffffffff);
4070 iwl3945_write32(priv
, CSR_FH_INT_STATUS
, 0xffffffff);
4071 IWL_DEBUG_ISR("Disabled interrupts\n");
4074 static const char *desc_lookup(int i
)
4082 return "BAD_CHECKSUM";
4084 return "NMI_INTERRUPT";
4088 return "FATAL_ERROR";
4094 #define ERROR_START_OFFSET (1 * sizeof(u32))
4095 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
4097 static void iwl3945_dump_nic_error_log(struct iwl3945_priv
*priv
)
4100 u32 desc
, time
, count
, base
, data1
;
4101 u32 blink1
, blink2
, ilink1
, ilink2
;
4104 base
= le32_to_cpu(priv
->card_alive
.error_event_table_ptr
);
4106 if (!iwl3945_hw_valid_rtc_data_addr(base
)) {
4107 IWL_ERROR("Not valid error log pointer 0x%08X\n", base
);
4111 rc
= iwl3945_grab_nic_access(priv
);
4113 IWL_WARNING("Can not read from adapter at this time.\n");
4117 count
= iwl3945_read_targ_mem(priv
, base
);
4119 if (ERROR_START_OFFSET
<= count
* ERROR_ELEM_SIZE
) {
4120 IWL_ERROR("Start IWL Error Log Dump:\n");
4121 IWL_ERROR("Status: 0x%08lX, count: %d\n", priv
->status
, count
);
4124 IWL_ERROR("Desc Time asrtPC blink2 "
4125 "ilink1 nmiPC Line\n");
4126 for (i
= ERROR_START_OFFSET
;
4127 i
< (count
* ERROR_ELEM_SIZE
) + ERROR_START_OFFSET
;
4128 i
+= ERROR_ELEM_SIZE
) {
4129 desc
= iwl3945_read_targ_mem(priv
, base
+ i
);
4131 iwl3945_read_targ_mem(priv
, base
+ i
+ 1 * sizeof(u32
));
4133 iwl3945_read_targ_mem(priv
, base
+ i
+ 2 * sizeof(u32
));
4135 iwl3945_read_targ_mem(priv
, base
+ i
+ 3 * sizeof(u32
));
4137 iwl3945_read_targ_mem(priv
, base
+ i
+ 4 * sizeof(u32
));
4139 iwl3945_read_targ_mem(priv
, base
+ i
+ 5 * sizeof(u32
));
4141 iwl3945_read_targ_mem(priv
, base
+ i
+ 6 * sizeof(u32
));
4144 ("%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
4145 desc_lookup(desc
), desc
, time
, blink1
, blink2
,
4146 ilink1
, ilink2
, data1
);
4149 iwl3945_release_nic_access(priv
);
4153 #define EVENT_START_OFFSET (6 * sizeof(u32))
4156 * iwl3945_print_event_log - Dump error event log to syslog
4158 * NOTE: Must be called with iwl3945_grab_nic_access() already obtained!
4160 static void iwl3945_print_event_log(struct iwl3945_priv
*priv
, u32 start_idx
,
4161 u32 num_events
, u32 mode
)
4164 u32 base
; /* SRAM byte address of event log header */
4165 u32 event_size
; /* 2 u32s, or 3 u32s if timestamp recorded */
4166 u32 ptr
; /* SRAM byte address of log data */
4167 u32 ev
, time
, data
; /* event log data */
4169 if (num_events
== 0)
4172 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
4175 event_size
= 2 * sizeof(u32
);
4177 event_size
= 3 * sizeof(u32
);
4179 ptr
= base
+ EVENT_START_OFFSET
+ (start_idx
* event_size
);
4181 /* "time" is actually "data" for mode 0 (no timestamp).
4182 * place event id # at far right for easier visual parsing. */
4183 for (i
= 0; i
< num_events
; i
++) {
4184 ev
= iwl3945_read_targ_mem(priv
, ptr
);
4186 time
= iwl3945_read_targ_mem(priv
, ptr
);
4189 IWL_ERROR("0x%08x\t%04u\n", time
, ev
); /* data, ev */
4191 data
= iwl3945_read_targ_mem(priv
, ptr
);
4193 IWL_ERROR("%010u\t0x%08x\t%04u\n", time
, data
, ev
);
4198 static void iwl3945_dump_nic_event_log(struct iwl3945_priv
*priv
)
4201 u32 base
; /* SRAM byte address of event log header */
4202 u32 capacity
; /* event log capacity in # entries */
4203 u32 mode
; /* 0 - no timestamp, 1 - timestamp recorded */
4204 u32 num_wraps
; /* # times uCode wrapped to top of log */
4205 u32 next_entry
; /* index of next entry to be written by uCode */
4206 u32 size
; /* # entries that we'll print */
4208 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
4209 if (!iwl3945_hw_valid_rtc_data_addr(base
)) {
4210 IWL_ERROR("Invalid event log pointer 0x%08X\n", base
);
4214 rc
= iwl3945_grab_nic_access(priv
);
4216 IWL_WARNING("Can not read from adapter at this time.\n");
4220 /* event log header */
4221 capacity
= iwl3945_read_targ_mem(priv
, base
);
4222 mode
= iwl3945_read_targ_mem(priv
, base
+ (1 * sizeof(u32
)));
4223 num_wraps
= iwl3945_read_targ_mem(priv
, base
+ (2 * sizeof(u32
)));
4224 next_entry
= iwl3945_read_targ_mem(priv
, base
+ (3 * sizeof(u32
)));
4226 size
= num_wraps
? capacity
: next_entry
;
4228 /* bail out if nothing in log */
4230 IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
4231 iwl3945_release_nic_access(priv
);
4235 IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
4238 /* if uCode has wrapped back to top of log, start at the oldest entry,
4239 * i.e the next one that uCode would fill. */
4241 iwl3945_print_event_log(priv
, next_entry
,
4242 capacity
- next_entry
, mode
);
4244 /* (then/else) start at top of log */
4245 iwl3945_print_event_log(priv
, 0, next_entry
, mode
);
4247 iwl3945_release_nic_access(priv
);
4251 * iwl3945_irq_handle_error - called for HW or SW error interrupt from card
4253 static void iwl3945_irq_handle_error(struct iwl3945_priv
*priv
)
4255 /* Set the FW error flag -- cleared on iwl3945_down */
4256 set_bit(STATUS_FW_ERROR
, &priv
->status
);
4258 /* Cancel currently queued command. */
4259 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
4261 #ifdef CONFIG_IWL3945_DEBUG
4262 if (iwl3945_debug_level
& IWL_DL_FW_ERRORS
) {
4263 iwl3945_dump_nic_error_log(priv
);
4264 iwl3945_dump_nic_event_log(priv
);
4265 iwl3945_print_rx_config_cmd(&priv
->staging_rxon
);
4269 wake_up_interruptible(&priv
->wait_command_queue
);
4271 /* Keep the restart process from trying to send host
4272 * commands by clearing the INIT status bit */
4273 clear_bit(STATUS_READY
, &priv
->status
);
4275 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
4276 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_FW_ERRORS
,
4277 "Restarting adapter due to uCode error.\n");
4279 if (iwl3945_is_associated(priv
)) {
4280 memcpy(&priv
->recovery_rxon
, &priv
->active_rxon
,
4281 sizeof(priv
->recovery_rxon
));
4282 priv
->error_recovering
= 1;
4284 queue_work(priv
->workqueue
, &priv
->restart
);
4288 static void iwl3945_error_recovery(struct iwl3945_priv
*priv
)
4290 unsigned long flags
;
4292 memcpy(&priv
->staging_rxon
, &priv
->recovery_rxon
,
4293 sizeof(priv
->staging_rxon
));
4294 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
4295 iwl3945_commit_rxon(priv
);
4297 iwl3945_add_station(priv
, priv
->bssid
, 1, 0);
4299 spin_lock_irqsave(&priv
->lock
, flags
);
4300 priv
->assoc_id
= le16_to_cpu(priv
->staging_rxon
.assoc_id
);
4301 priv
->error_recovering
= 0;
4302 spin_unlock_irqrestore(&priv
->lock
, flags
);
4305 static void iwl3945_irq_tasklet(struct iwl3945_priv
*priv
)
4307 u32 inta
, handled
= 0;
4309 unsigned long flags
;
4310 #ifdef CONFIG_IWL3945_DEBUG
4314 spin_lock_irqsave(&priv
->lock
, flags
);
4316 /* Ack/clear/reset pending uCode interrupts.
4317 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
4318 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
4319 inta
= iwl3945_read32(priv
, CSR_INT
);
4320 iwl3945_write32(priv
, CSR_INT
, inta
);
4322 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
4323 * Any new interrupts that happen after this, either while we're
4324 * in this tasklet, or later, will show up in next ISR/tasklet. */
4325 inta_fh
= iwl3945_read32(priv
, CSR_FH_INT_STATUS
);
4326 iwl3945_write32(priv
, CSR_FH_INT_STATUS
, inta_fh
);
4328 #ifdef CONFIG_IWL3945_DEBUG
4329 if (iwl3945_debug_level
& IWL_DL_ISR
) {
4330 /* just for debug */
4331 inta_mask
= iwl3945_read32(priv
, CSR_INT_MASK
);
4332 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4333 inta
, inta_mask
, inta_fh
);
4337 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
4338 * atomic, make sure that inta covers all the interrupts that
4339 * we've discovered, even if FH interrupt came in just after
4340 * reading CSR_INT. */
4341 if (inta_fh
& CSR39_FH_INT_RX_MASK
)
4342 inta
|= CSR_INT_BIT_FH_RX
;
4343 if (inta_fh
& CSR39_FH_INT_TX_MASK
)
4344 inta
|= CSR_INT_BIT_FH_TX
;
4346 /* Now service all interrupt bits discovered above. */
4347 if (inta
& CSR_INT_BIT_HW_ERR
) {
4348 IWL_ERROR("Microcode HW error detected. Restarting.\n");
4350 /* Tell the device to stop sending interrupts */
4351 iwl3945_disable_interrupts(priv
);
4353 iwl3945_irq_handle_error(priv
);
4355 handled
|= CSR_INT_BIT_HW_ERR
;
4357 spin_unlock_irqrestore(&priv
->lock
, flags
);
4362 #ifdef CONFIG_IWL3945_DEBUG
4363 if (iwl3945_debug_level
& (IWL_DL_ISR
)) {
4364 /* NIC fires this, but we don't use it, redundant with WAKEUP */
4365 if (inta
& CSR_INT_BIT_SCD
)
4366 IWL_DEBUG_ISR("Scheduler finished to transmit "
4367 "the frame/frames.\n");
4369 /* Alive notification via Rx interrupt will do the real work */
4370 if (inta
& CSR_INT_BIT_ALIVE
)
4371 IWL_DEBUG_ISR("Alive interrupt\n");
4374 /* Safely ignore these bits for debug checks below */
4375 inta
&= ~(CSR_INT_BIT_SCD
| CSR_INT_BIT_ALIVE
);
4377 /* HW RF KILL switch toggled (4965 only) */
4378 if (inta
& CSR_INT_BIT_RF_KILL
) {
4380 if (!(iwl3945_read32(priv
, CSR_GP_CNTRL
) &
4381 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
))
4384 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_RF_KILL
| IWL_DL_ISR
,
4385 "RF_KILL bit toggled to %s.\n",
4386 hw_rf_kill
? "disable radio":"enable radio");
4388 /* Queue restart only if RF_KILL switch was set to "kill"
4389 * when we loaded driver, and is now set to "enable".
4390 * After we're Alive, RF_KILL gets handled by
4391 * iwl3945_rx_card_state_notif() */
4392 if (!hw_rf_kill
&& !test_bit(STATUS_ALIVE
, &priv
->status
)) {
4393 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
4394 queue_work(priv
->workqueue
, &priv
->restart
);
4397 handled
|= CSR_INT_BIT_RF_KILL
;
4400 /* Chip got too hot and stopped itself (4965 only) */
4401 if (inta
& CSR_INT_BIT_CT_KILL
) {
4402 IWL_ERROR("Microcode CT kill error detected.\n");
4403 handled
|= CSR_INT_BIT_CT_KILL
;
4406 /* Error detected by uCode */
4407 if (inta
& CSR_INT_BIT_SW_ERR
) {
4408 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
4410 iwl3945_irq_handle_error(priv
);
4411 handled
|= CSR_INT_BIT_SW_ERR
;
4414 /* uCode wakes up after power-down sleep */
4415 if (inta
& CSR_INT_BIT_WAKEUP
) {
4416 IWL_DEBUG_ISR("Wakeup interrupt\n");
4417 iwl3945_rx_queue_update_write_ptr(priv
, &priv
->rxq
);
4418 iwl3945_tx_queue_update_write_ptr(priv
, &priv
->txq
[0]);
4419 iwl3945_tx_queue_update_write_ptr(priv
, &priv
->txq
[1]);
4420 iwl3945_tx_queue_update_write_ptr(priv
, &priv
->txq
[2]);
4421 iwl3945_tx_queue_update_write_ptr(priv
, &priv
->txq
[3]);
4422 iwl3945_tx_queue_update_write_ptr(priv
, &priv
->txq
[4]);
4423 iwl3945_tx_queue_update_write_ptr(priv
, &priv
->txq
[5]);
4425 handled
|= CSR_INT_BIT_WAKEUP
;
4428 /* All uCode command responses, including Tx command responses,
4429 * Rx "responses" (frame-received notification), and other
4430 * notifications from uCode come through here*/
4431 if (inta
& (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
)) {
4432 iwl3945_rx_handle(priv
);
4433 handled
|= (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
);
4436 if (inta
& CSR_INT_BIT_FH_TX
) {
4437 IWL_DEBUG_ISR("Tx interrupt\n");
4439 iwl3945_write32(priv
, CSR_FH_INT_STATUS
, (1 << 6));
4440 if (!iwl3945_grab_nic_access(priv
)) {
4441 iwl3945_write_direct32(priv
,
4443 (ALM_FH_SRVC_CHNL
), 0x0);
4444 iwl3945_release_nic_access(priv
);
4446 handled
|= CSR_INT_BIT_FH_TX
;
4449 if (inta
& ~handled
)
4450 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta
& ~handled
);
4452 if (inta
& ~CSR_INI_SET_MASK
) {
4453 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
4454 inta
& ~CSR_INI_SET_MASK
);
4455 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh
);
4458 /* Re-enable all interrupts */
4459 /* only Re-enable if disabled by irq */
4460 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
4461 iwl3945_enable_interrupts(priv
);
4463 #ifdef CONFIG_IWL3945_DEBUG
4464 if (iwl3945_debug_level
& (IWL_DL_ISR
)) {
4465 inta
= iwl3945_read32(priv
, CSR_INT
);
4466 inta_mask
= iwl3945_read32(priv
, CSR_INT_MASK
);
4467 inta_fh
= iwl3945_read32(priv
, CSR_FH_INT_STATUS
);
4468 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
4469 "flags 0x%08lx\n", inta
, inta_mask
, inta_fh
, flags
);
4472 spin_unlock_irqrestore(&priv
->lock
, flags
);
4475 static irqreturn_t
iwl3945_isr(int irq
, void *data
)
4477 struct iwl3945_priv
*priv
= data
;
4478 u32 inta
, inta_mask
;
4483 spin_lock(&priv
->lock
);
4485 /* Disable (but don't clear!) interrupts here to avoid
4486 * back-to-back ISRs and sporadic interrupts from our NIC.
4487 * If we have something to service, the tasklet will re-enable ints.
4488 * If we *don't* have something, we'll re-enable before leaving here. */
4489 inta_mask
= iwl3945_read32(priv
, CSR_INT_MASK
); /* just for debug */
4490 iwl3945_write32(priv
, CSR_INT_MASK
, 0x00000000);
4492 /* Discover which interrupts are active/pending */
4493 inta
= iwl3945_read32(priv
, CSR_INT
);
4494 inta_fh
= iwl3945_read32(priv
, CSR_FH_INT_STATUS
);
4496 /* Ignore interrupt if there's nothing in NIC to service.
4497 * This may be due to IRQ shared with another device,
4498 * or due to sporadic interrupts thrown from our NIC. */
4499 if (!inta
&& !inta_fh
) {
4500 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
4504 if ((inta
== 0xFFFFFFFF) || ((inta
& 0xFFFFFFF0) == 0xa5a5a5a0)) {
4505 /* Hardware disappeared */
4506 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta
);
4510 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4511 inta
, inta_mask
, inta_fh
);
4513 inta
&= ~CSR_INT_BIT_SCD
;
4515 /* iwl3945_irq_tasklet() will service interrupts and re-enable them */
4516 if (likely(inta
|| inta_fh
))
4517 tasklet_schedule(&priv
->irq_tasklet
);
4519 spin_unlock(&priv
->lock
);
4524 /* re-enable interrupts here since we don't have anything to service. */
4525 /* only Re-enable if disabled by irq */
4526 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
4527 iwl3945_enable_interrupts(priv
);
4528 spin_unlock(&priv
->lock
);
4532 /************************** EEPROM BANDS ****************************
4534 * The iwl3945_eeprom_band definitions below provide the mapping from the
4535 * EEPROM contents to the specific channel number supported for each
4538 * For example, iwl3945_priv->eeprom.band_3_channels[4] from the band_3
4539 * definition below maps to physical channel 42 in the 5.2GHz spectrum.
4540 * The specific geography and calibration information for that channel
4541 * is contained in the eeprom map itself.
4543 * During init, we copy the eeprom information and channel map
4544 * information into priv->channel_info_24/52 and priv->channel_map_24/52
4546 * channel_map_24/52 provides the index in the channel_info array for a
4547 * given channel. We have to have two separate maps as there is channel
4548 * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
4551 * A value of 0xff stored in the channel_map indicates that the channel
4552 * is not supported by the hardware at all.
4554 * A value of 0xfe in the channel_map indicates that the channel is not
4555 * valid for Tx with the current hardware. This means that
4556 * while the system can tune and receive on a given channel, it may not
4557 * be able to associate or transmit any frames on that
4558 * channel. There is no corresponding channel information for that
4561 *********************************************************************/
4564 static const u8 iwl3945_eeprom_band_1
[14] = {
4565 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
4569 static const u8 iwl3945_eeprom_band_2
[] = { /* 4915-5080MHz */
4570 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
4573 static const u8 iwl3945_eeprom_band_3
[] = { /* 5170-5320MHz */
4574 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
4577 static const u8 iwl3945_eeprom_band_4
[] = { /* 5500-5700MHz */
4578 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
4581 static const u8 iwl3945_eeprom_band_5
[] = { /* 5725-5825MHz */
4582 145, 149, 153, 157, 161, 165
4585 static void iwl3945_init_band_reference(const struct iwl3945_priv
*priv
, int band
,
4586 int *eeprom_ch_count
,
4587 const struct iwl3945_eeprom_channel
4589 const u8
**eeprom_ch_index
)
4592 case 1: /* 2.4GHz band */
4593 *eeprom_ch_count
= ARRAY_SIZE(iwl3945_eeprom_band_1
);
4594 *eeprom_ch_info
= priv
->eeprom
.band_1_channels
;
4595 *eeprom_ch_index
= iwl3945_eeprom_band_1
;
4597 case 2: /* 4.9GHz band */
4598 *eeprom_ch_count
= ARRAY_SIZE(iwl3945_eeprom_band_2
);
4599 *eeprom_ch_info
= priv
->eeprom
.band_2_channels
;
4600 *eeprom_ch_index
= iwl3945_eeprom_band_2
;
4602 case 3: /* 5.2GHz band */
4603 *eeprom_ch_count
= ARRAY_SIZE(iwl3945_eeprom_band_3
);
4604 *eeprom_ch_info
= priv
->eeprom
.band_3_channels
;
4605 *eeprom_ch_index
= iwl3945_eeprom_band_3
;
4607 case 4: /* 5.5GHz band */
4608 *eeprom_ch_count
= ARRAY_SIZE(iwl3945_eeprom_band_4
);
4609 *eeprom_ch_info
= priv
->eeprom
.band_4_channels
;
4610 *eeprom_ch_index
= iwl3945_eeprom_band_4
;
4612 case 5: /* 5.7GHz band */
4613 *eeprom_ch_count
= ARRAY_SIZE(iwl3945_eeprom_band_5
);
4614 *eeprom_ch_info
= priv
->eeprom
.band_5_channels
;
4615 *eeprom_ch_index
= iwl3945_eeprom_band_5
;
4624 * iwl3945_get_channel_info - Find driver's private channel info
4626 * Based on band and channel number.
4628 const struct iwl3945_channel_info
*iwl3945_get_channel_info(const struct iwl3945_priv
*priv
,
4629 enum ieee80211_band band
, u16 channel
)
4634 case IEEE80211_BAND_5GHZ
:
4635 for (i
= 14; i
< priv
->channel_count
; i
++) {
4636 if (priv
->channel_info
[i
].channel
== channel
)
4637 return &priv
->channel_info
[i
];
4641 case IEEE80211_BAND_2GHZ
:
4642 if (channel
>= 1 && channel
<= 14)
4643 return &priv
->channel_info
[channel
- 1];
4645 case IEEE80211_NUM_BANDS
:
4652 #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
4656 * iwl3945_init_channel_map - Set up driver's info for all possible channels
4658 static int iwl3945_init_channel_map(struct iwl3945_priv
*priv
)
4660 int eeprom_ch_count
= 0;
4661 const u8
*eeprom_ch_index
= NULL
;
4662 const struct iwl3945_eeprom_channel
*eeprom_ch_info
= NULL
;
4664 struct iwl3945_channel_info
*ch_info
;
4666 if (priv
->channel_count
) {
4667 IWL_DEBUG_INFO("Channel map already initialized.\n");
4671 if (priv
->eeprom
.version
< 0x2f) {
4672 IWL_WARNING("Unsupported EEPROM version: 0x%04X\n",
4673 priv
->eeprom
.version
);
4677 IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n");
4679 priv
->channel_count
=
4680 ARRAY_SIZE(iwl3945_eeprom_band_1
) +
4681 ARRAY_SIZE(iwl3945_eeprom_band_2
) +
4682 ARRAY_SIZE(iwl3945_eeprom_band_3
) +
4683 ARRAY_SIZE(iwl3945_eeprom_band_4
) +
4684 ARRAY_SIZE(iwl3945_eeprom_band_5
);
4686 IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv
->channel_count
);
4688 priv
->channel_info
= kzalloc(sizeof(struct iwl3945_channel_info
) *
4689 priv
->channel_count
, GFP_KERNEL
);
4690 if (!priv
->channel_info
) {
4691 IWL_ERROR("Could not allocate channel_info\n");
4692 priv
->channel_count
= 0;
4696 ch_info
= priv
->channel_info
;
4698 /* Loop through the 5 EEPROM bands adding them in order to the
4699 * channel map we maintain (that contains additional information than
4700 * what just in the EEPROM) */
4701 for (band
= 1; band
<= 5; band
++) {
4703 iwl3945_init_band_reference(priv
, band
, &eeprom_ch_count
,
4704 &eeprom_ch_info
, &eeprom_ch_index
);
4706 /* Loop through each band adding each of the channels */
4707 for (ch
= 0; ch
< eeprom_ch_count
; ch
++) {
4708 ch_info
->channel
= eeprom_ch_index
[ch
];
4709 ch_info
->band
= (band
== 1) ? IEEE80211_BAND_2GHZ
:
4710 IEEE80211_BAND_5GHZ
;
4712 /* permanently store EEPROM's channel regulatory flags
4713 * and max power in channel info database. */
4714 ch_info
->eeprom
= eeprom_ch_info
[ch
];
4716 /* Copy the run-time flags so they are there even on
4717 * invalid channels */
4718 ch_info
->flags
= eeprom_ch_info
[ch
].flags
;
4720 if (!(is_channel_valid(ch_info
))) {
4721 IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - "
4725 is_channel_a_band(ch_info
) ?
4731 /* Initialize regulatory-based run-time data */
4732 ch_info
->max_power_avg
= ch_info
->curr_txpow
=
4733 eeprom_ch_info
[ch
].max_power_avg
;
4734 ch_info
->scan_power
= eeprom_ch_info
[ch
].max_power_avg
;
4735 ch_info
->min_power
= 0;
4737 IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x"
4738 " %ddBm): Ad-Hoc %ssupported\n",
4740 is_channel_a_band(ch_info
) ?
4742 CHECK_AND_PRINT(VALID
),
4743 CHECK_AND_PRINT(IBSS
),
4744 CHECK_AND_PRINT(ACTIVE
),
4745 CHECK_AND_PRINT(RADAR
),
4746 CHECK_AND_PRINT(WIDE
),
4747 CHECK_AND_PRINT(DFS
),
4748 eeprom_ch_info
[ch
].flags
,
4749 eeprom_ch_info
[ch
].max_power_avg
,
4750 ((eeprom_ch_info
[ch
].
4751 flags
& EEPROM_CHANNEL_IBSS
)
4752 && !(eeprom_ch_info
[ch
].
4753 flags
& EEPROM_CHANNEL_RADAR
))
4756 /* Set the user_txpower_limit to the highest power
4757 * supported by any channel */
4758 if (eeprom_ch_info
[ch
].max_power_avg
>
4759 priv
->user_txpower_limit
)
4760 priv
->user_txpower_limit
=
4761 eeprom_ch_info
[ch
].max_power_avg
;
4767 /* Set up txpower settings in driver for all channels */
4768 if (iwl3945_txpower_set_from_eeprom(priv
))
4775 * iwl3945_free_channel_map - undo allocations in iwl3945_init_channel_map
4777 static void iwl3945_free_channel_map(struct iwl3945_priv
*priv
)
4779 kfree(priv
->channel_info
);
4780 priv
->channel_count
= 0;
4783 /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
4784 * sending probe req. This should be set long enough to hear probe responses
4785 * from more than one AP. */
4786 #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
4787 #define IWL_ACTIVE_DWELL_TIME_52 (10)
4789 /* For faster active scanning, scan will move to the next channel if fewer than
4790 * PLCP_QUIET_THRESH packets are heard on this channel within
4791 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
4792 * time if it's a quiet channel (nothing responded to our probe, and there's
4793 * no other traffic).
4794 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
4795 #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
4796 #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
4798 /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
4799 * Must be set longer than active dwell time.
4800 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
4801 #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
4802 #define IWL_PASSIVE_DWELL_TIME_52 (10)
4803 #define IWL_PASSIVE_DWELL_BASE (100)
4804 #define IWL_CHANNEL_TUNE_TIME 5
4806 static inline u16
iwl3945_get_active_dwell_time(struct iwl3945_priv
*priv
,
4807 enum ieee80211_band band
)
4809 if (band
== IEEE80211_BAND_5GHZ
)
4810 return IWL_ACTIVE_DWELL_TIME_52
;
4812 return IWL_ACTIVE_DWELL_TIME_24
;
4815 static u16
iwl3945_get_passive_dwell_time(struct iwl3945_priv
*priv
,
4816 enum ieee80211_band band
)
4818 u16 active
= iwl3945_get_active_dwell_time(priv
, band
);
4819 u16 passive
= (band
== IEEE80211_BAND_2GHZ
) ?
4820 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_24
:
4821 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_52
;
4823 if (iwl3945_is_associated(priv
)) {
4824 /* If we're associated, we clamp the maximum passive
4825 * dwell time to be 98% of the beacon interval (minus
4826 * 2 * channel tune time) */
4827 passive
= priv
->beacon_int
;
4828 if ((passive
> IWL_PASSIVE_DWELL_BASE
) || !passive
)
4829 passive
= IWL_PASSIVE_DWELL_BASE
;
4830 passive
= (passive
* 98) / 100 - IWL_CHANNEL_TUNE_TIME
* 2;
4833 if (passive
<= active
)
4834 passive
= active
+ 1;
4839 static int iwl3945_get_channels_for_scan(struct iwl3945_priv
*priv
,
4840 enum ieee80211_band band
,
4841 u8 is_active
, u8 direct_mask
,
4842 struct iwl3945_scan_channel
*scan_ch
)
4844 const struct ieee80211_channel
*channels
= NULL
;
4845 const struct ieee80211_supported_band
*sband
;
4846 const struct iwl3945_channel_info
*ch_info
;
4847 u16 passive_dwell
= 0;
4848 u16 active_dwell
= 0;
4851 sband
= iwl3945_get_band(priv
, band
);
4855 channels
= sband
->channels
;
4857 active_dwell
= iwl3945_get_active_dwell_time(priv
, band
);
4858 passive_dwell
= iwl3945_get_passive_dwell_time(priv
, band
);
4860 for (i
= 0, added
= 0; i
< sband
->n_channels
; i
++) {
4861 if (channels
[i
].flags
& IEEE80211_CHAN_DISABLED
)
4864 scan_ch
->channel
= channels
[i
].hw_value
;
4866 ch_info
= iwl3945_get_channel_info(priv
, band
, scan_ch
->channel
);
4867 if (!is_channel_valid(ch_info
)) {
4868 IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n",
4873 if (!is_active
|| is_channel_passive(ch_info
) ||
4874 (channels
[i
].flags
& IEEE80211_CHAN_PASSIVE_SCAN
))
4875 scan_ch
->type
= 0; /* passive */
4877 scan_ch
->type
= 1; /* active */
4879 if (scan_ch
->type
& 1)
4880 scan_ch
->type
|= (direct_mask
<< 1);
4882 scan_ch
->active_dwell
= cpu_to_le16(active_dwell
);
4883 scan_ch
->passive_dwell
= cpu_to_le16(passive_dwell
);
4885 /* Set txpower levels to defaults */
4886 scan_ch
->tpc
.dsp_atten
= 110;
4887 /* scan_pwr_info->tpc.dsp_atten; */
4889 /*scan_pwr_info->tpc.tx_gain; */
4890 if (band
== IEEE80211_BAND_5GHZ
)
4891 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (3 << 3)) | 3;
4893 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (5 << 3));
4894 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
4896 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
4900 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
4902 (scan_ch
->type
& 1) ? "ACTIVE" : "PASSIVE",
4903 (scan_ch
->type
& 1) ?
4904 active_dwell
: passive_dwell
);
4910 IWL_DEBUG_SCAN("total channels to scan %d \n", added
);
4914 static void iwl3945_init_hw_rates(struct iwl3945_priv
*priv
,
4915 struct ieee80211_rate
*rates
)
4919 for (i
= 0; i
< IWL_RATE_COUNT
; i
++) {
4920 rates
[i
].bitrate
= iwl3945_rates
[i
].ieee
* 5;
4921 rates
[i
].hw_value
= i
; /* Rate scaling will work on indexes */
4922 rates
[i
].hw_value_short
= i
;
4924 if ((i
> IWL_LAST_OFDM_RATE
) || (i
< IWL_FIRST_OFDM_RATE
)) {
4926 * If CCK != 1M then set short preamble rate flag.
4928 rates
[i
].flags
|= (iwl3945_rates
[i
].plcp
== 10) ?
4929 0 : IEEE80211_RATE_SHORT_PREAMBLE
;
4935 * iwl3945_init_geos - Initialize mac80211's geo/channel info based from eeprom
4937 static int iwl3945_init_geos(struct iwl3945_priv
*priv
)
4939 struct iwl3945_channel_info
*ch
;
4940 struct ieee80211_supported_band
*sband
;
4941 struct ieee80211_channel
*channels
;
4942 struct ieee80211_channel
*geo_ch
;
4943 struct ieee80211_rate
*rates
;
4946 if (priv
->bands
[IEEE80211_BAND_2GHZ
].n_bitrates
||
4947 priv
->bands
[IEEE80211_BAND_5GHZ
].n_bitrates
) {
4948 IWL_DEBUG_INFO("Geography modes already initialized.\n");
4949 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
4953 channels
= kzalloc(sizeof(struct ieee80211_channel
) *
4954 priv
->channel_count
, GFP_KERNEL
);
4958 rates
= kzalloc((sizeof(struct ieee80211_rate
) * (IWL_RATE_COUNT
+ 1)),
4965 /* 5.2GHz channels start after the 2.4GHz channels */
4966 sband
= &priv
->bands
[IEEE80211_BAND_5GHZ
];
4967 sband
->channels
= &channels
[ARRAY_SIZE(iwl3945_eeprom_band_1
)];
4969 sband
->bitrates
= &rates
[IWL_FIRST_OFDM_RATE
];
4970 sband
->n_bitrates
= IWL_RATE_COUNT
- IWL_FIRST_OFDM_RATE
;
4972 sband
= &priv
->bands
[IEEE80211_BAND_2GHZ
];
4973 sband
->channels
= channels
;
4975 sband
->bitrates
= rates
;
4976 sband
->n_bitrates
= IWL_RATE_COUNT
;
4978 priv
->ieee_channels
= channels
;
4979 priv
->ieee_rates
= rates
;
4981 iwl3945_init_hw_rates(priv
, rates
);
4983 for (i
= 0; i
< priv
->channel_count
; i
++) {
4984 ch
= &priv
->channel_info
[i
];
4986 /* FIXME: might be removed if scan is OK*/
4987 if (!is_channel_valid(ch
))
4990 if (is_channel_a_band(ch
))
4991 sband
= &priv
->bands
[IEEE80211_BAND_5GHZ
];
4993 sband
= &priv
->bands
[IEEE80211_BAND_2GHZ
];
4995 geo_ch
= &sband
->channels
[sband
->n_channels
++];
4997 geo_ch
->center_freq
= ieee80211_channel_to_frequency(ch
->channel
);
4998 geo_ch
->max_power
= ch
->max_power_avg
;
4999 geo_ch
->max_antenna_gain
= 0xff;
5000 geo_ch
->hw_value
= ch
->channel
;
5002 if (is_channel_valid(ch
)) {
5003 if (!(ch
->flags
& EEPROM_CHANNEL_IBSS
))
5004 geo_ch
->flags
|= IEEE80211_CHAN_NO_IBSS
;
5006 if (!(ch
->flags
& EEPROM_CHANNEL_ACTIVE
))
5007 geo_ch
->flags
|= IEEE80211_CHAN_PASSIVE_SCAN
;
5009 if (ch
->flags
& EEPROM_CHANNEL_RADAR
)
5010 geo_ch
->flags
|= IEEE80211_CHAN_RADAR
;
5012 if (ch
->max_power_avg
> priv
->max_channel_txpower_limit
)
5013 priv
->max_channel_txpower_limit
=
5016 geo_ch
->flags
|= IEEE80211_CHAN_DISABLED
;
5019 /* Save flags for reg domain usage */
5020 geo_ch
->orig_flags
= geo_ch
->flags
;
5022 IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n",
5023 ch
->channel
, geo_ch
->center_freq
,
5024 is_channel_a_band(ch
) ? "5.2" : "2.4",
5025 geo_ch
->flags
& IEEE80211_CHAN_DISABLED
?
5026 "restricted" : "valid",
5030 if ((priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
== 0) &&
5031 priv
->cfg
->sku
& IWL_SKU_A
) {
5032 printk(KERN_INFO DRV_NAME
5033 ": Incorrectly detected BG card as ABG. Please send "
5034 "your PCI ID 0x%04X:0x%04X to maintainer.\n",
5035 priv
->pci_dev
->device
, priv
->pci_dev
->subsystem_device
);
5036 priv
->cfg
->sku
&= ~IWL_SKU_A
;
5039 printk(KERN_INFO DRV_NAME
5040 ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
5041 priv
->bands
[IEEE80211_BAND_2GHZ
].n_channels
,
5042 priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
);
5044 if (priv
->bands
[IEEE80211_BAND_2GHZ
].n_channels
)
5045 priv
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
5046 &priv
->bands
[IEEE80211_BAND_2GHZ
];
5047 if (priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
)
5048 priv
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
5049 &priv
->bands
[IEEE80211_BAND_5GHZ
];
5051 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
5057 * iwl3945_free_geos - undo allocations in iwl3945_init_geos
5059 static void iwl3945_free_geos(struct iwl3945_priv
*priv
)
5061 kfree(priv
->ieee_channels
);
5062 kfree(priv
->ieee_rates
);
5063 clear_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
5066 /******************************************************************************
5068 * uCode download functions
5070 ******************************************************************************/
5072 static void iwl3945_dealloc_ucode_pci(struct iwl3945_priv
*priv
)
5074 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
5075 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
5076 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
5077 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
5078 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
5079 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
5083 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
5084 * looking at all data.
5086 static int iwl3945_verify_inst_full(struct iwl3945_priv
*priv
, __le32
*image
, u32 len
)
5093 IWL_DEBUG_INFO("ucode inst image size is %u\n", len
);
5095 rc
= iwl3945_grab_nic_access(priv
);
5099 iwl3945_write_direct32(priv
, HBUS_TARG_MEM_RADDR
, RTC_INST_LOWER_BOUND
);
5102 for (; len
> 0; len
-= sizeof(u32
), image
++) {
5103 /* read data comes through single port, auto-incr addr */
5104 /* NOTE: Use the debugless read so we don't flood kernel log
5105 * if IWL_DL_IO is set */
5106 val
= _iwl3945_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
5107 if (val
!= le32_to_cpu(*image
)) {
5108 IWL_ERROR("uCode INST section is invalid at "
5109 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5110 save_len
- len
, val
, le32_to_cpu(*image
));
5118 iwl3945_release_nic_access(priv
);
5121 IWL_DEBUG_INFO("ucode image in INSTRUCTION memory is good\n");
5128 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
5129 * using sample data 100 bytes apart. If these sample points are good,
5130 * it's a pretty good bet that everything between them is good, too.
5132 static int iwl3945_verify_inst_sparse(struct iwl3945_priv
*priv
, __le32
*image
, u32 len
)
5139 IWL_DEBUG_INFO("ucode inst image size is %u\n", len
);
5141 rc
= iwl3945_grab_nic_access(priv
);
5145 for (i
= 0; i
< len
; i
+= 100, image
+= 100/sizeof(u32
)) {
5146 /* read data comes through single port, auto-incr addr */
5147 /* NOTE: Use the debugless read so we don't flood kernel log
5148 * if IWL_DL_IO is set */
5149 iwl3945_write_direct32(priv
, HBUS_TARG_MEM_RADDR
,
5150 i
+ RTC_INST_LOWER_BOUND
);
5151 val
= _iwl3945_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
5152 if (val
!= le32_to_cpu(*image
)) {
5153 #if 0 /* Enable this if you want to see details */
5154 IWL_ERROR("uCode INST section is invalid at "
5155 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5165 iwl3945_release_nic_access(priv
);
5172 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
5173 * and verify its contents
5175 static int iwl3945_verify_ucode(struct iwl3945_priv
*priv
)
5182 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
5183 len
= priv
->ucode_boot
.len
;
5184 rc
= iwl3945_verify_inst_sparse(priv
, image
, len
);
5186 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
5190 /* Try initialize */
5191 image
= (__le32
*)priv
->ucode_init
.v_addr
;
5192 len
= priv
->ucode_init
.len
;
5193 rc
= iwl3945_verify_inst_sparse(priv
, image
, len
);
5195 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
5199 /* Try runtime/protocol */
5200 image
= (__le32
*)priv
->ucode_code
.v_addr
;
5201 len
= priv
->ucode_code
.len
;
5202 rc
= iwl3945_verify_inst_sparse(priv
, image
, len
);
5204 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
5208 IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
5210 /* Since nothing seems to match, show first several data entries in
5211 * instruction SRAM, so maybe visual inspection will give a clue.
5212 * Selection of bootstrap image (vs. other images) is arbitrary. */
5213 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
5214 len
= priv
->ucode_boot
.len
;
5215 rc
= iwl3945_verify_inst_full(priv
, image
, len
);
5221 /* check contents of special bootstrap uCode SRAM */
5222 static int iwl3945_verify_bsm(struct iwl3945_priv
*priv
)
5224 __le32
*image
= priv
->ucode_boot
.v_addr
;
5225 u32 len
= priv
->ucode_boot
.len
;
5229 IWL_DEBUG_INFO("Begin verify bsm\n");
5231 /* verify BSM SRAM contents */
5232 val
= iwl3945_read_prph(priv
, BSM_WR_DWCOUNT_REG
);
5233 for (reg
= BSM_SRAM_LOWER_BOUND
;
5234 reg
< BSM_SRAM_LOWER_BOUND
+ len
;
5235 reg
+= sizeof(u32
), image
++) {
5236 val
= iwl3945_read_prph(priv
, reg
);
5237 if (val
!= le32_to_cpu(*image
)) {
5238 IWL_ERROR("BSM uCode verification failed at "
5239 "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
5240 BSM_SRAM_LOWER_BOUND
,
5241 reg
- BSM_SRAM_LOWER_BOUND
, len
,
5242 val
, le32_to_cpu(*image
));
5247 IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
5253 * iwl3945_load_bsm - Load bootstrap instructions
5257 * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
5258 * in special SRAM that does not power down during RFKILL. When powering back
5259 * up after power-saving sleeps (or during initial uCode load), the BSM loads
5260 * the bootstrap program into the on-board processor, and starts it.
5262 * The bootstrap program loads (via DMA) instructions and data for a new
5263 * program from host DRAM locations indicated by the host driver in the
5264 * BSM_DRAM_* registers. Once the new program is loaded, it starts
5267 * When initializing the NIC, the host driver points the BSM to the
5268 * "initialize" uCode image. This uCode sets up some internal data, then
5269 * notifies host via "initialize alive" that it is complete.
5271 * The host then replaces the BSM_DRAM_* pointer values to point to the
5272 * normal runtime uCode instructions and a backup uCode data cache buffer
5273 * (filled initially with starting data values for the on-board processor),
5274 * then triggers the "initialize" uCode to load and launch the runtime uCode,
5275 * which begins normal operation.
5277 * When doing a power-save shutdown, runtime uCode saves data SRAM into
5278 * the backup data cache in DRAM before SRAM is powered down.
5280 * When powering back up, the BSM loads the bootstrap program. This reloads
5281 * the runtime uCode instructions and the backup data cache into SRAM,
5282 * and re-launches the runtime uCode from where it left off.
5284 static int iwl3945_load_bsm(struct iwl3945_priv
*priv
)
5286 __le32
*image
= priv
->ucode_boot
.v_addr
;
5287 u32 len
= priv
->ucode_boot
.len
;
5297 IWL_DEBUG_INFO("Begin load bsm\n");
5299 /* make sure bootstrap program is no larger than BSM's SRAM size */
5300 if (len
> IWL_MAX_BSM_SIZE
)
5303 /* Tell bootstrap uCode where to find the "Initialize" uCode
5304 * in host DRAM ... host DRAM physical address bits 31:0 for 3945.
5305 * NOTE: iwl3945_initialize_alive_start() will replace these values,
5306 * after the "initialize" uCode has run, to point to
5307 * runtime/protocol instructions and backup data cache. */
5308 pinst
= priv
->ucode_init
.p_addr
;
5309 pdata
= priv
->ucode_init_data
.p_addr
;
5310 inst_len
= priv
->ucode_init
.len
;
5311 data_len
= priv
->ucode_init_data
.len
;
5313 rc
= iwl3945_grab_nic_access(priv
);
5317 iwl3945_write_prph(priv
, BSM_DRAM_INST_PTR_REG
, pinst
);
5318 iwl3945_write_prph(priv
, BSM_DRAM_DATA_PTR_REG
, pdata
);
5319 iwl3945_write_prph(priv
, BSM_DRAM_INST_BYTECOUNT_REG
, inst_len
);
5320 iwl3945_write_prph(priv
, BSM_DRAM_DATA_BYTECOUNT_REG
, data_len
);
5322 /* Fill BSM memory with bootstrap instructions */
5323 for (reg_offset
= BSM_SRAM_LOWER_BOUND
;
5324 reg_offset
< BSM_SRAM_LOWER_BOUND
+ len
;
5325 reg_offset
+= sizeof(u32
), image
++)
5326 _iwl3945_write_prph(priv
, reg_offset
,
5327 le32_to_cpu(*image
));
5329 rc
= iwl3945_verify_bsm(priv
);
5331 iwl3945_release_nic_access(priv
);
5335 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
5336 iwl3945_write_prph(priv
, BSM_WR_MEM_SRC_REG
, 0x0);
5337 iwl3945_write_prph(priv
, BSM_WR_MEM_DST_REG
,
5338 RTC_INST_LOWER_BOUND
);
5339 iwl3945_write_prph(priv
, BSM_WR_DWCOUNT_REG
, len
/ sizeof(u32
));
5341 /* Load bootstrap code into instruction SRAM now,
5342 * to prepare to load "initialize" uCode */
5343 iwl3945_write_prph(priv
, BSM_WR_CTRL_REG
,
5344 BSM_WR_CTRL_REG_BIT_START
);
5346 /* Wait for load of bootstrap uCode to finish */
5347 for (i
= 0; i
< 100; i
++) {
5348 done
= iwl3945_read_prph(priv
, BSM_WR_CTRL_REG
);
5349 if (!(done
& BSM_WR_CTRL_REG_BIT_START
))
5354 IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i
);
5356 IWL_ERROR("BSM write did not complete!\n");
5360 /* Enable future boot loads whenever power management unit triggers it
5361 * (e.g. when powering back up after power-save shutdown) */
5362 iwl3945_write_prph(priv
, BSM_WR_CTRL_REG
,
5363 BSM_WR_CTRL_REG_BIT_START_EN
);
5365 iwl3945_release_nic_access(priv
);
5370 static void iwl3945_nic_start(struct iwl3945_priv
*priv
)
5372 /* Remove all resets to allow NIC to operate */
5373 iwl3945_write32(priv
, CSR_RESET
, 0);
5377 * iwl3945_read_ucode - Read uCode images from disk file.
5379 * Copy into buffers for card to fetch via bus-mastering
5381 static int iwl3945_read_ucode(struct iwl3945_priv
*priv
)
5383 struct iwl3945_ucode
*ucode
;
5385 const struct firmware
*ucode_raw
;
5386 /* firmware file name contains uCode/driver compatibility version */
5387 const char *name
= priv
->cfg
->fw_name
;
5390 u32 ver
, inst_size
, data_size
, init_size
, init_data_size
, boot_size
;
5392 /* Ask kernel firmware_class module to get the boot firmware off disk.
5393 * request_firmware() is synchronous, file is in memory on return. */
5394 ret
= request_firmware(&ucode_raw
, name
, &priv
->pci_dev
->dev
);
5396 IWL_ERROR("%s firmware file req failed: Reason %d\n",
5401 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
5402 name
, ucode_raw
->size
);
5404 /* Make sure that we got at least our header! */
5405 if (ucode_raw
->size
< sizeof(*ucode
)) {
5406 IWL_ERROR("File size way too small!\n");
5411 /* Data from ucode file: header followed by uCode images */
5412 ucode
= (void *)ucode_raw
->data
;
5414 ver
= le32_to_cpu(ucode
->ver
);
5415 inst_size
= le32_to_cpu(ucode
->inst_size
);
5416 data_size
= le32_to_cpu(ucode
->data_size
);
5417 init_size
= le32_to_cpu(ucode
->init_size
);
5418 init_data_size
= le32_to_cpu(ucode
->init_data_size
);
5419 boot_size
= le32_to_cpu(ucode
->boot_size
);
5421 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver
);
5422 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", inst_size
);
5423 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", data_size
);
5424 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", init_size
);
5425 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", init_data_size
);
5426 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", boot_size
);
5428 /* Verify size of file vs. image size info in file's header */
5429 if (ucode_raw
->size
< sizeof(*ucode
) +
5430 inst_size
+ data_size
+ init_size
+
5431 init_data_size
+ boot_size
) {
5433 IWL_DEBUG_INFO("uCode file size %d too small\n",
5434 (int)ucode_raw
->size
);
5439 /* Verify that uCode images will fit in card's SRAM */
5440 if (inst_size
> IWL_MAX_INST_SIZE
) {
5441 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
5447 if (data_size
> IWL_MAX_DATA_SIZE
) {
5448 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
5453 if (init_size
> IWL_MAX_INST_SIZE
) {
5454 IWL_DEBUG_INFO("uCode init instr len %d too large to fit in\n",
5459 if (init_data_size
> IWL_MAX_DATA_SIZE
) {
5460 IWL_DEBUG_INFO("uCode init data len %d too large to fit in\n",
5465 if (boot_size
> IWL_MAX_BSM_SIZE
) {
5466 IWL_DEBUG_INFO("uCode boot instr len %d too large to fit in\n",
5472 /* Allocate ucode buffers for card's bus-master loading ... */
5474 /* Runtime instructions and 2 copies of data:
5475 * 1) unmodified from disk
5476 * 2) backup cache for save/restore during power-downs */
5477 priv
->ucode_code
.len
= inst_size
;
5478 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
5480 priv
->ucode_data
.len
= data_size
;
5481 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
5483 priv
->ucode_data_backup
.len
= data_size
;
5484 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
5486 if (!priv
->ucode_code
.v_addr
|| !priv
->ucode_data
.v_addr
||
5487 !priv
->ucode_data_backup
.v_addr
)
5490 /* Initialization instructions and data */
5491 if (init_size
&& init_data_size
) {
5492 priv
->ucode_init
.len
= init_size
;
5493 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
5495 priv
->ucode_init_data
.len
= init_data_size
;
5496 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
5498 if (!priv
->ucode_init
.v_addr
|| !priv
->ucode_init_data
.v_addr
)
5502 /* Bootstrap (instructions only, no data) */
5504 priv
->ucode_boot
.len
= boot_size
;
5505 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
5507 if (!priv
->ucode_boot
.v_addr
)
5511 /* Copy images into buffers for card's bus-master reads ... */
5513 /* Runtime instructions (first block of data in file) */
5514 src
= &ucode
->data
[0];
5515 len
= priv
->ucode_code
.len
;
5516 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len
);
5517 memcpy(priv
->ucode_code
.v_addr
, src
, len
);
5518 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
5519 priv
->ucode_code
.v_addr
, (u32
)priv
->ucode_code
.p_addr
);
5521 /* Runtime data (2nd block)
5522 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
5523 src
= &ucode
->data
[inst_size
];
5524 len
= priv
->ucode_data
.len
;
5525 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len
);
5526 memcpy(priv
->ucode_data
.v_addr
, src
, len
);
5527 memcpy(priv
->ucode_data_backup
.v_addr
, src
, len
);
5529 /* Initialization instructions (3rd block) */
5531 src
= &ucode
->data
[inst_size
+ data_size
];
5532 len
= priv
->ucode_init
.len
;
5533 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
5535 memcpy(priv
->ucode_init
.v_addr
, src
, len
);
5538 /* Initialization data (4th block) */
5539 if (init_data_size
) {
5540 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
];
5541 len
= priv
->ucode_init_data
.len
;
5542 IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n",
5544 memcpy(priv
->ucode_init_data
.v_addr
, src
, len
);
5547 /* Bootstrap instructions (5th block) */
5548 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
+ init_data_size
];
5549 len
= priv
->ucode_boot
.len
;
5550 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n",
5552 memcpy(priv
->ucode_boot
.v_addr
, src
, len
);
5554 /* We have our copies now, allow OS release its copies */
5555 release_firmware(ucode_raw
);
5559 IWL_ERROR("failed to allocate pci memory\n");
5561 iwl3945_dealloc_ucode_pci(priv
);
5564 release_firmware(ucode_raw
);
5572 * iwl3945_set_ucode_ptrs - Set uCode address location
5574 * Tell initialization uCode where to find runtime uCode.
5576 * BSM registers initially contain pointers to initialization uCode.
5577 * We need to replace them to load runtime uCode inst and data,
5578 * and to save runtime data when powering down.
5580 static int iwl3945_set_ucode_ptrs(struct iwl3945_priv
*priv
)
5585 unsigned long flags
;
5587 /* bits 31:0 for 3945 */
5588 pinst
= priv
->ucode_code
.p_addr
;
5589 pdata
= priv
->ucode_data_backup
.p_addr
;
5591 spin_lock_irqsave(&priv
->lock
, flags
);
5592 rc
= iwl3945_grab_nic_access(priv
);
5594 spin_unlock_irqrestore(&priv
->lock
, flags
);
5598 /* Tell bootstrap uCode where to find image to load */
5599 iwl3945_write_prph(priv
, BSM_DRAM_INST_PTR_REG
, pinst
);
5600 iwl3945_write_prph(priv
, BSM_DRAM_DATA_PTR_REG
, pdata
);
5601 iwl3945_write_prph(priv
, BSM_DRAM_DATA_BYTECOUNT_REG
,
5602 priv
->ucode_data
.len
);
5604 /* Inst bytecount must be last to set up, bit 31 signals uCode
5605 * that all new ptr/size info is in place */
5606 iwl3945_write_prph(priv
, BSM_DRAM_INST_BYTECOUNT_REG
,
5607 priv
->ucode_code
.len
| BSM_DRAM_INST_LOAD
);
5609 iwl3945_release_nic_access(priv
);
5611 spin_unlock_irqrestore(&priv
->lock
, flags
);
5613 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
5619 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
5621 * Called after REPLY_ALIVE notification received from "initialize" uCode.
5623 * Tell "initialize" uCode to go ahead and load the runtime uCode.
5625 static void iwl3945_init_alive_start(struct iwl3945_priv
*priv
)
5627 /* Check alive response for "valid" sign from uCode */
5628 if (priv
->card_alive_init
.is_valid
!= UCODE_VALID_OK
) {
5629 /* We had an error bringing up the hardware, so take it
5630 * all the way back down so we can try again */
5631 IWL_DEBUG_INFO("Initialize Alive failed.\n");
5635 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
5636 * This is a paranoid check, because we would not have gotten the
5637 * "initialize" alive if code weren't properly loaded. */
5638 if (iwl3945_verify_ucode(priv
)) {
5639 /* Runtime instruction load was bad;
5640 * take it all the way back down so we can try again */
5641 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
5645 /* Send pointers to protocol/runtime uCode image ... init code will
5646 * load and launch runtime uCode, which will send us another "Alive"
5648 IWL_DEBUG_INFO("Initialization Alive received.\n");
5649 if (iwl3945_set_ucode_ptrs(priv
)) {
5650 /* Runtime instruction load won't happen;
5651 * take it all the way back down so we can try again */
5652 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
5658 queue_work(priv
->workqueue
, &priv
->restart
);
5663 * iwl3945_alive_start - called after REPLY_ALIVE notification received
5664 * from protocol/runtime uCode (initialization uCode's
5665 * Alive gets handled by iwl3945_init_alive_start()).
5667 static void iwl3945_alive_start(struct iwl3945_priv
*priv
)
5670 int thermal_spin
= 0;
5673 IWL_DEBUG_INFO("Runtime Alive received.\n");
5675 if (priv
->card_alive
.is_valid
!= UCODE_VALID_OK
) {
5676 /* We had an error bringing up the hardware, so take it
5677 * all the way back down so we can try again */
5678 IWL_DEBUG_INFO("Alive failed.\n");
5682 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
5683 * This is a paranoid check, because we would not have gotten the
5684 * "runtime" alive if code weren't properly loaded. */
5685 if (iwl3945_verify_ucode(priv
)) {
5686 /* Runtime instruction load was bad;
5687 * take it all the way back down so we can try again */
5688 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
5692 iwl3945_clear_stations_table(priv
);
5694 rc
= iwl3945_grab_nic_access(priv
);
5696 IWL_WARNING("Can not read rfkill status from adapter\n");
5700 rfkill
= iwl3945_read_prph(priv
, APMG_RFKILL_REG
);
5701 IWL_DEBUG_INFO("RFKILL status: 0x%x\n", rfkill
);
5702 iwl3945_release_nic_access(priv
);
5705 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
5706 /* if rfkill is not on, then wait for thermal
5707 * sensor in adapter to kick in */
5708 while (iwl3945_hw_get_temperature(priv
) == 0) {
5714 IWL_DEBUG_INFO("Thermal calibration took %dus\n",
5717 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
5719 /* After the ALIVE response, we can send commands to 3945 uCode */
5720 set_bit(STATUS_ALIVE
, &priv
->status
);
5722 /* Clear out the uCode error bit if it is set */
5723 clear_bit(STATUS_FW_ERROR
, &priv
->status
);
5725 if (iwl3945_is_rfkill(priv
))
5728 ieee80211_wake_queues(priv
->hw
);
5730 priv
->active_rate
= priv
->rates_mask
;
5731 priv
->active_rate_basic
= priv
->rates_mask
& IWL_BASIC_RATES_MASK
;
5733 iwl3945_send_power_mode(priv
, IWL_POWER_LEVEL(priv
->power_mode
));
5735 if (iwl3945_is_associated(priv
)) {
5736 struct iwl3945_rxon_cmd
*active_rxon
=
5737 (struct iwl3945_rxon_cmd
*)(&priv
->active_rxon
);
5739 memcpy(&priv
->staging_rxon
, &priv
->active_rxon
,
5740 sizeof(priv
->staging_rxon
));
5741 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
5743 /* Initialize our rx_config data */
5744 iwl3945_connection_init_rx_config(priv
);
5745 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
5748 /* Configure Bluetooth device coexistence support */
5749 iwl3945_send_bt_config(priv
);
5751 /* Configure the adapter for unassociated operation */
5752 iwl3945_commit_rxon(priv
);
5754 iwl3945_reg_txpower_periodic(priv
);
5756 iwl3945_led_register(priv
);
5758 IWL_DEBUG_INFO("ALIVE processing complete.\n");
5759 set_bit(STATUS_READY
, &priv
->status
);
5760 wake_up_interruptible(&priv
->wait_command_queue
);
5762 if (priv
->error_recovering
)
5763 iwl3945_error_recovery(priv
);
5765 ieee80211_notify_mac(priv
->hw
, IEEE80211_NOTIFY_RE_ASSOC
);
5769 queue_work(priv
->workqueue
, &priv
->restart
);
5772 static void iwl3945_cancel_deferred_work(struct iwl3945_priv
*priv
);
5774 static void __iwl3945_down(struct iwl3945_priv
*priv
)
5776 unsigned long flags
;
5777 int exit_pending
= test_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5778 struct ieee80211_conf
*conf
= NULL
;
5780 IWL_DEBUG_INFO(DRV_NAME
" is going down\n");
5782 conf
= ieee80211_get_hw_conf(priv
->hw
);
5785 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5787 iwl3945_led_unregister(priv
);
5788 iwl3945_clear_stations_table(priv
);
5790 /* Unblock any waiting calls */
5791 wake_up_interruptible_all(&priv
->wait_command_queue
);
5793 /* Wipe out the EXIT_PENDING status bit if we are not actually
5794 * exiting the module */
5796 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5798 /* stop and reset the on-board processor */
5799 iwl3945_write32(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_NEVO_RESET
);
5801 /* tell the device to stop sending interrupts */
5802 spin_lock_irqsave(&priv
->lock
, flags
);
5803 iwl3945_disable_interrupts(priv
);
5804 spin_unlock_irqrestore(&priv
->lock
, flags
);
5805 iwl_synchronize_irq(priv
);
5807 if (priv
->mac80211_registered
)
5808 ieee80211_stop_queues(priv
->hw
);
5810 /* If we have not previously called iwl3945_init() then
5811 * clear all bits but the RF Kill and SUSPEND bits and return */
5812 if (!iwl3945_is_init(priv
)) {
5813 priv
->status
= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
5815 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
5817 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
5818 STATUS_GEO_CONFIGURED
|
5819 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
5821 test_bit(STATUS_EXIT_PENDING
, &priv
->status
) <<
5822 STATUS_EXIT_PENDING
;
5826 /* ...otherwise clear out all the status bits but the RF Kill and
5827 * SUSPEND bits and continue taking the NIC down. */
5828 priv
->status
&= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
5830 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
5832 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
5833 STATUS_GEO_CONFIGURED
|
5834 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
5836 test_bit(STATUS_FW_ERROR
, &priv
->status
) <<
5838 test_bit(STATUS_EXIT_PENDING
, &priv
->status
) <<
5839 STATUS_EXIT_PENDING
;
5841 spin_lock_irqsave(&priv
->lock
, flags
);
5842 iwl3945_clear_bit(priv
, CSR_GP_CNTRL
, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
5843 spin_unlock_irqrestore(&priv
->lock
, flags
);
5845 iwl3945_hw_txq_ctx_stop(priv
);
5846 iwl3945_hw_rxq_stop(priv
);
5848 spin_lock_irqsave(&priv
->lock
, flags
);
5849 if (!iwl3945_grab_nic_access(priv
)) {
5850 iwl3945_write_prph(priv
, APMG_CLK_DIS_REG
,
5851 APMG_CLK_VAL_DMA_CLK_RQT
);
5852 iwl3945_release_nic_access(priv
);
5854 spin_unlock_irqrestore(&priv
->lock
, flags
);
5858 iwl3945_hw_nic_stop_master(priv
);
5859 iwl3945_set_bit(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_SW_RESET
);
5860 iwl3945_hw_nic_reset(priv
);
5863 memset(&priv
->card_alive
, 0, sizeof(struct iwl3945_alive_resp
));
5865 if (priv
->ibss_beacon
)
5866 dev_kfree_skb(priv
->ibss_beacon
);
5867 priv
->ibss_beacon
= NULL
;
5869 /* clear out any free frames */
5870 iwl3945_clear_free_frames(priv
);
5873 static void iwl3945_down(struct iwl3945_priv
*priv
)
5875 mutex_lock(&priv
->mutex
);
5876 __iwl3945_down(priv
);
5877 mutex_unlock(&priv
->mutex
);
5879 iwl3945_cancel_deferred_work(priv
);
5882 #define MAX_HW_RESTARTS 5
5884 static int __iwl3945_up(struct iwl3945_priv
*priv
)
5888 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
5889 IWL_WARNING("Exit pending; will not bring the NIC up\n");
5893 if (test_bit(STATUS_RF_KILL_SW
, &priv
->status
)) {
5894 IWL_WARNING("Radio disabled by SW RF kill (module "
5899 if (!priv
->ucode_data_backup
.v_addr
|| !priv
->ucode_data
.v_addr
) {
5900 IWL_ERROR("ucode not available for device bringup\n");
5904 /* If platform's RF_KILL switch is NOT set to KILL */
5905 if (iwl3945_read32(priv
, CSR_GP_CNTRL
) &
5906 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
)
5907 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
5909 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
5910 if (!test_bit(STATUS_IN_SUSPEND
, &priv
->status
)) {
5911 IWL_WARNING("Radio disabled by HW RF Kill switch\n");
5916 iwl3945_write32(priv
, CSR_INT
, 0xFFFFFFFF);
5918 rc
= iwl3945_hw_nic_init(priv
);
5920 IWL_ERROR("Unable to int nic\n");
5924 /* make sure rfkill handshake bits are cleared */
5925 iwl3945_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
5926 iwl3945_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
5927 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
5929 /* clear (again), then enable host interrupts */
5930 iwl3945_write32(priv
, CSR_INT
, 0xFFFFFFFF);
5931 iwl3945_enable_interrupts(priv
);
5933 /* really make sure rfkill handshake bits are cleared */
5934 iwl3945_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
5935 iwl3945_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
5937 /* Copy original ucode data image from disk into backup cache.
5938 * This will be used to initialize the on-board processor's
5939 * data SRAM for a clean start when the runtime program first loads. */
5940 memcpy(priv
->ucode_data_backup
.v_addr
, priv
->ucode_data
.v_addr
,
5941 priv
->ucode_data
.len
);
5943 /* We return success when we resume from suspend and rf_kill is on. */
5944 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
5947 for (i
= 0; i
< MAX_HW_RESTARTS
; i
++) {
5949 iwl3945_clear_stations_table(priv
);
5951 /* load bootstrap state machine,
5952 * load bootstrap program into processor's memory,
5953 * prepare to load the "initialize" uCode */
5954 rc
= iwl3945_load_bsm(priv
);
5957 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc
);
5961 /* start card; "initialize" will load runtime ucode */
5962 iwl3945_nic_start(priv
);
5964 IWL_DEBUG_INFO(DRV_NAME
" is coming up\n");
5969 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5970 __iwl3945_down(priv
);
5971 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5973 /* tried to restart and config the device for as long as our
5974 * patience could withstand */
5975 IWL_ERROR("Unable to initialize device after %d attempts.\n", i
);
5980 /*****************************************************************************
5982 * Workqueue callbacks
5984 *****************************************************************************/
5986 static void iwl3945_bg_init_alive_start(struct work_struct
*data
)
5988 struct iwl3945_priv
*priv
=
5989 container_of(data
, struct iwl3945_priv
, init_alive_start
.work
);
5991 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5994 mutex_lock(&priv
->mutex
);
5995 iwl3945_init_alive_start(priv
);
5996 mutex_unlock(&priv
->mutex
);
5999 static void iwl3945_bg_alive_start(struct work_struct
*data
)
6001 struct iwl3945_priv
*priv
=
6002 container_of(data
, struct iwl3945_priv
, alive_start
.work
);
6004 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6007 mutex_lock(&priv
->mutex
);
6008 iwl3945_alive_start(priv
);
6009 mutex_unlock(&priv
->mutex
);
6012 static void iwl3945_bg_rf_kill(struct work_struct
*work
)
6014 struct iwl3945_priv
*priv
= container_of(work
, struct iwl3945_priv
, rf_kill
);
6016 wake_up_interruptible(&priv
->wait_command_queue
);
6018 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6021 mutex_lock(&priv
->mutex
);
6023 if (!iwl3945_is_rfkill(priv
)) {
6024 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_RF_KILL
,
6025 "HW and/or SW RF Kill no longer active, restarting "
6027 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6028 queue_work(priv
->workqueue
, &priv
->restart
);
6031 if (!test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
6032 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
6033 "disabled by SW switch\n");
6035 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
6036 "Kill switch must be turned off for "
6037 "wireless networking to work.\n");
6040 mutex_unlock(&priv
->mutex
);
6041 iwl3945_rfkill_set_hw_state(priv
);
6044 static void iwl3945_bg_set_monitor(struct work_struct
*work
)
6046 struct iwl3945_priv
*priv
= container_of(work
,
6047 struct iwl3945_priv
, set_monitor
);
6049 IWL_DEBUG(IWL_DL_STATE
, "setting monitor mode\n");
6051 mutex_lock(&priv
->mutex
);
6053 if (!iwl3945_is_ready(priv
))
6054 IWL_DEBUG(IWL_DL_STATE
, "leave - not ready\n");
6056 if (iwl3945_set_mode(priv
, IEEE80211_IF_TYPE_MNTR
) != 0)
6057 IWL_ERROR("iwl3945_set_mode() failed\n");
6059 mutex_unlock(&priv
->mutex
);
6062 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
6064 static void iwl3945_bg_scan_check(struct work_struct
*data
)
6066 struct iwl3945_priv
*priv
=
6067 container_of(data
, struct iwl3945_priv
, scan_check
.work
);
6069 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6072 mutex_lock(&priv
->mutex
);
6073 if (test_bit(STATUS_SCANNING
, &priv
->status
) ||
6074 test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
6075 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_SCAN
,
6076 "Scan completion watchdog resetting adapter (%dms)\n",
6077 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG
));
6079 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6080 iwl3945_send_scan_abort(priv
);
6082 mutex_unlock(&priv
->mutex
);
6085 static void iwl3945_bg_request_scan(struct work_struct
*data
)
6087 struct iwl3945_priv
*priv
=
6088 container_of(data
, struct iwl3945_priv
, request_scan
);
6089 struct iwl3945_host_cmd cmd
= {
6090 .id
= REPLY_SCAN_CMD
,
6091 .len
= sizeof(struct iwl3945_scan_cmd
),
6092 .meta
.flags
= CMD_SIZE_HUGE
,
6095 struct iwl3945_scan_cmd
*scan
;
6096 struct ieee80211_conf
*conf
= NULL
;
6098 enum ieee80211_band band
;
6100 conf
= ieee80211_get_hw_conf(priv
->hw
);
6102 mutex_lock(&priv
->mutex
);
6104 if (!iwl3945_is_ready(priv
)) {
6105 IWL_WARNING("request scan called when driver not ready.\n");
6109 /* Make sure the scan wasn't cancelled before this queued work
6110 * was given the chance to run... */
6111 if (!test_bit(STATUS_SCANNING
, &priv
->status
))
6114 /* This should never be called or scheduled if there is currently
6115 * a scan active in the hardware. */
6116 if (test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
6117 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
6118 "Ignoring second request.\n");
6123 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
6124 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
6128 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
6129 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6133 if (iwl3945_is_rfkill(priv
)) {
6134 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6138 if (!test_bit(STATUS_READY
, &priv
->status
)) {
6139 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
6143 if (!priv
->scan_bands
) {
6144 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
6149 priv
->scan
= kmalloc(sizeof(struct iwl3945_scan_cmd
) +
6150 IWL_MAX_SCAN_SIZE
, GFP_KERNEL
);
6157 memset(scan
, 0, sizeof(struct iwl3945_scan_cmd
) + IWL_MAX_SCAN_SIZE
);
6159 scan
->quiet_plcp_th
= IWL_PLCP_QUIET_THRESH
;
6160 scan
->quiet_time
= IWL_ACTIVE_QUIET_TIME
;
6162 if (iwl3945_is_associated(priv
)) {
6165 u32 suspend_time
= 100;
6166 u32 scan_suspend_time
= 100;
6167 unsigned long flags
;
6169 IWL_DEBUG_INFO("Scanning while associated...\n");
6171 spin_lock_irqsave(&priv
->lock
, flags
);
6172 interval
= priv
->beacon_int
;
6173 spin_unlock_irqrestore(&priv
->lock
, flags
);
6175 scan
->suspend_time
= 0;
6176 scan
->max_out_time
= cpu_to_le32(200 * 1024);
6178 interval
= suspend_time
;
6180 * suspend time format:
6181 * 0-19: beacon interval in usec (time before exec.)
6183 * 24-31: number of beacons (suspend between channels)
6186 extra
= (suspend_time
/ interval
) << 24;
6187 scan_suspend_time
= 0xFF0FFFFF &
6188 (extra
| ((suspend_time
% interval
) * 1024));
6190 scan
->suspend_time
= cpu_to_le32(scan_suspend_time
);
6191 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
6192 scan_suspend_time
, interval
);
6195 /* We should add the ability for user to lock to PASSIVE ONLY */
6196 if (priv
->one_direct_scan
) {
6198 ("Kicking off one direct scan for '%s'\n",
6199 iwl3945_escape_essid(priv
->direct_ssid
,
6200 priv
->direct_ssid_len
));
6201 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
6202 scan
->direct_scan
[0].len
= priv
->direct_ssid_len
;
6203 memcpy(scan
->direct_scan
[0].ssid
,
6204 priv
->direct_ssid
, priv
->direct_ssid_len
);
6206 } else if (!iwl3945_is_associated(priv
) && priv
->essid_len
) {
6208 ("Kicking off one direct scan for '%s' when not associated\n",
6209 iwl3945_escape_essid(priv
->essid
, priv
->essid_len
));
6210 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
6211 scan
->direct_scan
[0].len
= priv
->essid_len
;
6212 memcpy(scan
->direct_scan
[0].ssid
, priv
->essid
, priv
->essid_len
);
6215 IWL_DEBUG_SCAN("Kicking off one indirect scan.\n");
6219 /* We don't build a direct scan probe request; the uCode will do
6220 * that based on the direct_mask added to each channel entry */
6221 scan
->tx_cmd
.len
= cpu_to_le16(
6222 iwl3945_fill_probe_req(priv
, (struct ieee80211_mgmt
*)scan
->data
,
6223 IWL_MAX_SCAN_SIZE
- sizeof(*scan
), 0));
6224 scan
->tx_cmd
.tx_flags
= TX_CMD_FLG_SEQ_CTL_MSK
;
6225 scan
->tx_cmd
.sta_id
= priv
->hw_setting
.bcast_sta_id
;
6226 scan
->tx_cmd
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
6228 /* flags + rate selection */
6230 if (priv
->scan_bands
& BIT(IEEE80211_BAND_2GHZ
)) {
6231 scan
->flags
= RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
;
6232 scan
->tx_cmd
.rate
= IWL_RATE_1M_PLCP
;
6233 scan
->good_CRC_th
= 0;
6234 band
= IEEE80211_BAND_2GHZ
;
6235 } else if (priv
->scan_bands
& BIT(IEEE80211_BAND_5GHZ
)) {
6236 scan
->tx_cmd
.rate
= IWL_RATE_6M_PLCP
;
6237 scan
->good_CRC_th
= IWL_GOOD_CRC_TH
;
6238 band
= IEEE80211_BAND_5GHZ
;
6240 IWL_WARNING("Invalid scan band count\n");
6244 /* select Rx antennas */
6245 scan
->flags
|= iwl3945_get_antenna_flags(priv
);
6247 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
)
6248 scan
->filter_flags
= RXON_FILTER_PROMISC_MSK
;
6251 scan
->channel_count
=
6252 iwl3945_get_channels_for_scan(
6253 priv
, band
, 1, /* active */
6255 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
6257 scan
->channel_count
=
6258 iwl3945_get_channels_for_scan(
6259 priv
, band
, 0, /* passive */
6261 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
6263 cmd
.len
+= le16_to_cpu(scan
->tx_cmd
.len
) +
6264 scan
->channel_count
* sizeof(struct iwl3945_scan_channel
);
6266 scan
->len
= cpu_to_le16(cmd
.len
);
6268 set_bit(STATUS_SCAN_HW
, &priv
->status
);
6269 rc
= iwl3945_send_cmd_sync(priv
, &cmd
);
6273 queue_delayed_work(priv
->workqueue
, &priv
->scan_check
,
6274 IWL_SCAN_CHECK_WATCHDOG
);
6276 mutex_unlock(&priv
->mutex
);
6280 /* inform mac80211 scan aborted */
6281 queue_work(priv
->workqueue
, &priv
->scan_completed
);
6282 mutex_unlock(&priv
->mutex
);
6285 static void iwl3945_bg_up(struct work_struct
*data
)
6287 struct iwl3945_priv
*priv
= container_of(data
, struct iwl3945_priv
, up
);
6289 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6292 mutex_lock(&priv
->mutex
);
6294 mutex_unlock(&priv
->mutex
);
6295 iwl3945_rfkill_set_hw_state(priv
);
6298 static void iwl3945_bg_restart(struct work_struct
*data
)
6300 struct iwl3945_priv
*priv
= container_of(data
, struct iwl3945_priv
, restart
);
6302 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6306 queue_work(priv
->workqueue
, &priv
->up
);
6309 static void iwl3945_bg_rx_replenish(struct work_struct
*data
)
6311 struct iwl3945_priv
*priv
=
6312 container_of(data
, struct iwl3945_priv
, rx_replenish
);
6314 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6317 mutex_lock(&priv
->mutex
);
6318 iwl3945_rx_replenish(priv
);
6319 mutex_unlock(&priv
->mutex
);
6322 #define IWL_DELAY_NEXT_SCAN (HZ*2)
6324 static void iwl3945_bg_post_associate(struct work_struct
*data
)
6326 struct iwl3945_priv
*priv
= container_of(data
, struct iwl3945_priv
,
6327 post_associate
.work
);
6330 struct ieee80211_conf
*conf
= NULL
;
6331 DECLARE_MAC_BUF(mac
);
6333 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
6334 IWL_ERROR("%s Should not be called in AP mode\n", __func__
);
6339 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
6341 print_mac(mac
, priv
->active_rxon
.bssid_addr
));
6343 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6346 mutex_lock(&priv
->mutex
);
6348 if (!priv
->vif
|| !priv
->is_open
) {
6349 mutex_unlock(&priv
->mutex
);
6352 iwl3945_scan_cancel_timeout(priv
, 200);
6354 conf
= ieee80211_get_hw_conf(priv
->hw
);
6356 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6357 iwl3945_commit_rxon(priv
);
6359 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl3945_rxon_time_cmd
));
6360 iwl3945_setup_rxon_timing(priv
);
6361 rc
= iwl3945_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
6362 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
6364 IWL_WARNING("REPLY_RXON_TIMING failed - "
6365 "Attempting to continue.\n");
6367 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
6369 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
6371 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
6372 priv
->assoc_id
, priv
->beacon_int
);
6374 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
6375 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
6377 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
6379 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
6380 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
6381 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
6383 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
6385 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
6386 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
6390 iwl3945_commit_rxon(priv
);
6392 switch (priv
->iw_mode
) {
6393 case IEEE80211_IF_TYPE_STA
:
6394 iwl3945_rate_scale_init(priv
->hw
, IWL_AP_ID
);
6397 case IEEE80211_IF_TYPE_IBSS
:
6399 /* clear out the station table */
6400 iwl3945_clear_stations_table(priv
);
6402 iwl3945_add_station(priv
, iwl3945_broadcast_addr
, 0, 0);
6403 iwl3945_add_station(priv
, priv
->bssid
, 0, 0);
6404 iwl3945_sync_sta(priv
, IWL_STA_ID
,
6405 (priv
->band
== IEEE80211_BAND_5GHZ
) ?
6406 IWL_RATE_6M_PLCP
: IWL_RATE_1M_PLCP
,
6408 iwl3945_rate_scale_init(priv
->hw
, IWL_STA_ID
);
6409 iwl3945_send_beacon_cmd(priv
);
6414 IWL_ERROR("%s Should not be called in %d mode\n",
6415 __func__
, priv
->iw_mode
);
6419 iwl3945_activate_qos(priv
, 0);
6421 /* we have just associated, don't start scan too early */
6422 priv
->next_scan_jiffies
= jiffies
+ IWL_DELAY_NEXT_SCAN
;
6423 mutex_unlock(&priv
->mutex
);
6426 static void iwl3945_bg_abort_scan(struct work_struct
*work
)
6428 struct iwl3945_priv
*priv
= container_of(work
, struct iwl3945_priv
, abort_scan
);
6430 if (!iwl3945_is_ready(priv
))
6433 mutex_lock(&priv
->mutex
);
6435 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
6436 iwl3945_send_scan_abort(priv
);
6438 mutex_unlock(&priv
->mutex
);
6441 static int iwl3945_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
);
6443 static void iwl3945_bg_scan_completed(struct work_struct
*work
)
6445 struct iwl3945_priv
*priv
=
6446 container_of(work
, struct iwl3945_priv
, scan_completed
);
6448 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_SCAN
, "SCAN complete scan\n");
6450 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6453 if (test_bit(STATUS_CONF_PENDING
, &priv
->status
))
6454 iwl3945_mac_config(priv
->hw
, ieee80211_get_hw_conf(priv
->hw
));
6456 ieee80211_scan_completed(priv
->hw
);
6458 /* Since setting the TXPOWER may have been deferred while
6459 * performing the scan, fire one off */
6460 mutex_lock(&priv
->mutex
);
6461 iwl3945_hw_reg_send_txpower(priv
);
6462 mutex_unlock(&priv
->mutex
);
6465 /*****************************************************************************
6467 * mac80211 entry point functions
6469 *****************************************************************************/
6471 #define UCODE_READY_TIMEOUT (2 * HZ)
6473 static int iwl3945_mac_start(struct ieee80211_hw
*hw
)
6475 struct iwl3945_priv
*priv
= hw
->priv
;
6478 IWL_DEBUG_MAC80211("enter\n");
6480 if (pci_enable_device(priv
->pci_dev
)) {
6481 IWL_ERROR("Fail to pci_enable_device\n");
6484 pci_restore_state(priv
->pci_dev
);
6485 pci_enable_msi(priv
->pci_dev
);
6487 ret
= request_irq(priv
->pci_dev
->irq
, iwl3945_isr
, IRQF_SHARED
,
6490 IWL_ERROR("Error allocating IRQ %d\n", priv
->pci_dev
->irq
);
6491 goto out_disable_msi
;
6494 /* we should be verifying the device is ready to be opened */
6495 mutex_lock(&priv
->mutex
);
6497 memset(&priv
->staging_rxon
, 0, sizeof(struct iwl3945_rxon_cmd
));
6498 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
6499 * ucode filename and max sizes are card-specific. */
6501 if (!priv
->ucode_code
.len
) {
6502 ret
= iwl3945_read_ucode(priv
);
6504 IWL_ERROR("Could not read microcode: %d\n", ret
);
6505 mutex_unlock(&priv
->mutex
);
6506 goto out_release_irq
;
6510 ret
= __iwl3945_up(priv
);
6512 mutex_unlock(&priv
->mutex
);
6514 iwl3945_rfkill_set_hw_state(priv
);
6517 goto out_release_irq
;
6519 IWL_DEBUG_INFO("Start UP work.\n");
6521 if (test_bit(STATUS_IN_SUSPEND
, &priv
->status
))
6524 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
6525 * mac80211 will not be run successfully. */
6526 ret
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
6527 test_bit(STATUS_READY
, &priv
->status
),
6528 UCODE_READY_TIMEOUT
);
6530 if (!test_bit(STATUS_READY
, &priv
->status
)) {
6531 IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n",
6532 jiffies_to_msecs(UCODE_READY_TIMEOUT
));
6534 goto out_release_irq
;
6539 IWL_DEBUG_MAC80211("leave\n");
6543 free_irq(priv
->pci_dev
->irq
, priv
);
6545 pci_disable_msi(priv
->pci_dev
);
6546 pci_disable_device(priv
->pci_dev
);
6548 IWL_DEBUG_MAC80211("leave - failed\n");
6552 static void iwl3945_mac_stop(struct ieee80211_hw
*hw
)
6554 struct iwl3945_priv
*priv
= hw
->priv
;
6556 IWL_DEBUG_MAC80211("enter\n");
6558 if (!priv
->is_open
) {
6559 IWL_DEBUG_MAC80211("leave - skip\n");
6565 if (iwl3945_is_ready_rf(priv
)) {
6566 /* stop mac, cancel any scan request and clear
6567 * RXON_FILTER_ASSOC_MSK BIT
6569 mutex_lock(&priv
->mutex
);
6570 iwl3945_scan_cancel_timeout(priv
, 100);
6571 cancel_delayed_work(&priv
->post_associate
);
6572 mutex_unlock(&priv
->mutex
);
6577 flush_workqueue(priv
->workqueue
);
6578 free_irq(priv
->pci_dev
->irq
, priv
);
6579 pci_disable_msi(priv
->pci_dev
);
6580 pci_save_state(priv
->pci_dev
);
6581 pci_disable_device(priv
->pci_dev
);
6583 IWL_DEBUG_MAC80211("leave\n");
6586 static int iwl3945_mac_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
6588 struct iwl3945_priv
*priv
= hw
->priv
;
6590 IWL_DEBUG_MAC80211("enter\n");
6592 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb
->len
,
6593 ieee80211_get_tx_rate(hw
, IEEE80211_SKB_CB(skb
))->bitrate
);
6595 if (iwl3945_tx_skb(priv
, skb
))
6596 dev_kfree_skb_any(skb
);
6598 IWL_DEBUG_MAC80211("leave\n");
6602 static int iwl3945_mac_add_interface(struct ieee80211_hw
*hw
,
6603 struct ieee80211_if_init_conf
*conf
)
6605 struct iwl3945_priv
*priv
= hw
->priv
;
6606 unsigned long flags
;
6607 DECLARE_MAC_BUF(mac
);
6609 IWL_DEBUG_MAC80211("enter: type %d\n", conf
->type
);
6612 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
6616 spin_lock_irqsave(&priv
->lock
, flags
);
6617 priv
->vif
= conf
->vif
;
6619 spin_unlock_irqrestore(&priv
->lock
, flags
);
6621 mutex_lock(&priv
->mutex
);
6623 if (conf
->mac_addr
) {
6624 IWL_DEBUG_MAC80211("Set: %s\n", print_mac(mac
, conf
->mac_addr
));
6625 memcpy(priv
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
6628 if (iwl3945_is_ready(priv
))
6629 iwl3945_set_mode(priv
, conf
->type
);
6631 mutex_unlock(&priv
->mutex
);
6633 IWL_DEBUG_MAC80211("leave\n");
6638 * iwl3945_mac_config - mac80211 config callback
6640 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
6641 * be set inappropriately and the driver currently sets the hardware up to
6642 * use it whenever needed.
6644 static int iwl3945_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
)
6646 struct iwl3945_priv
*priv
= hw
->priv
;
6647 const struct iwl3945_channel_info
*ch_info
;
6648 unsigned long flags
;
6651 mutex_lock(&priv
->mutex
);
6652 IWL_DEBUG_MAC80211("enter to channel %d\n", conf
->channel
->hw_value
);
6654 priv
->add_radiotap
= !!(conf
->flags
& IEEE80211_CONF_RADIOTAP
);
6656 if (!iwl3945_is_ready(priv
)) {
6657 IWL_DEBUG_MAC80211("leave - not ready\n");
6662 if (unlikely(!iwl3945_param_disable_hw_scan
&&
6663 test_bit(STATUS_SCANNING
, &priv
->status
))) {
6664 IWL_DEBUG_MAC80211("leave - scanning\n");
6665 set_bit(STATUS_CONF_PENDING
, &priv
->status
);
6666 mutex_unlock(&priv
->mutex
);
6670 spin_lock_irqsave(&priv
->lock
, flags
);
6672 ch_info
= iwl3945_get_channel_info(priv
, conf
->channel
->band
,
6673 conf
->channel
->hw_value
);
6674 if (!is_channel_valid(ch_info
)) {
6675 IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this band.\n",
6676 conf
->channel
->hw_value
, conf
->channel
->band
);
6677 IWL_DEBUG_MAC80211("leave - invalid channel\n");
6678 spin_unlock_irqrestore(&priv
->lock
, flags
);
6683 iwl3945_set_rxon_channel(priv
, conf
->channel
->band
, conf
->channel
->hw_value
);
6685 iwl3945_set_flags_for_phymode(priv
, conf
->channel
->band
);
6687 /* The list of supported rates and rate mask can be different
6688 * for each phymode; since the phymode may have changed, reset
6689 * the rate mask to what mac80211 lists */
6690 iwl3945_set_rate(priv
);
6692 spin_unlock_irqrestore(&priv
->lock
, flags
);
6694 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
6695 if (conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
) {
6696 iwl3945_hw_channel_switch(priv
, conf
->channel
);
6701 iwl3945_radio_kill_sw(priv
, !conf
->radio_enabled
);
6703 if (!conf
->radio_enabled
) {
6704 IWL_DEBUG_MAC80211("leave - radio disabled\n");
6708 if (iwl3945_is_rfkill(priv
)) {
6709 IWL_DEBUG_MAC80211("leave - RF kill\n");
6714 iwl3945_set_rate(priv
);
6716 if (memcmp(&priv
->active_rxon
,
6717 &priv
->staging_rxon
, sizeof(priv
->staging_rxon
)))
6718 iwl3945_commit_rxon(priv
);
6720 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
6722 IWL_DEBUG_MAC80211("leave\n");
6725 clear_bit(STATUS_CONF_PENDING
, &priv
->status
);
6726 mutex_unlock(&priv
->mutex
);
6730 static void iwl3945_config_ap(struct iwl3945_priv
*priv
)
6734 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6737 /* The following should be done only at AP bring up */
6738 if (!(iwl3945_is_associated(priv
))) {
6740 /* RXON - unassoc (to set timing command) */
6741 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6742 iwl3945_commit_rxon(priv
);
6745 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl3945_rxon_time_cmd
));
6746 iwl3945_setup_rxon_timing(priv
);
6747 rc
= iwl3945_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
6748 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
6750 IWL_WARNING("REPLY_RXON_TIMING failed - "
6751 "Attempting to continue.\n");
6753 /* FIXME: what should be the assoc_id for AP? */
6754 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
6755 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
6756 priv
->staging_rxon
.flags
|=
6757 RXON_FLG_SHORT_PREAMBLE_MSK
;
6759 priv
->staging_rxon
.flags
&=
6760 ~RXON_FLG_SHORT_PREAMBLE_MSK
;
6762 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
6763 if (priv
->assoc_capability
&
6764 WLAN_CAPABILITY_SHORT_SLOT_TIME
)
6765 priv
->staging_rxon
.flags
|=
6766 RXON_FLG_SHORT_SLOT_MSK
;
6768 priv
->staging_rxon
.flags
&=
6769 ~RXON_FLG_SHORT_SLOT_MSK
;
6771 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
6772 priv
->staging_rxon
.flags
&=
6773 ~RXON_FLG_SHORT_SLOT_MSK
;
6775 /* restore RXON assoc */
6776 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
6777 iwl3945_commit_rxon(priv
);
6778 iwl3945_add_station(priv
, iwl3945_broadcast_addr
, 0, 0);
6780 iwl3945_send_beacon_cmd(priv
);
6782 /* FIXME - we need to add code here to detect a totally new
6783 * configuration, reset the AP, unassoc, rxon timing, assoc,
6784 * clear sta table, add BCAST sta... */
6788 static int iwl3945_mac_beacon_update(struct ieee80211_hw
*hw
, struct sk_buff
*skb
);
6790 static int iwl3945_mac_config_interface(struct ieee80211_hw
*hw
,
6791 struct ieee80211_vif
*vif
,
6792 struct ieee80211_if_conf
*conf
)
6794 struct iwl3945_priv
*priv
= hw
->priv
;
6795 DECLARE_MAC_BUF(mac
);
6796 unsigned long flags
;
6802 if (priv
->vif
!= vif
) {
6803 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
6807 /* handle this temporarily here */
6808 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
&&
6809 conf
->changed
& IEEE80211_IFCC_BEACON
) {
6810 struct sk_buff
*beacon
= ieee80211_beacon_get(hw
, vif
);
6813 rc
= iwl3945_mac_beacon_update(hw
, beacon
);
6818 /* XXX: this MUST use conf->mac_addr */
6820 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
6821 (!conf
->ssid_len
)) {
6823 ("Leaving in AP mode because HostAPD is not ready.\n");
6827 if (!iwl3945_is_alive(priv
))
6830 mutex_lock(&priv
->mutex
);
6833 IWL_DEBUG_MAC80211("bssid: %s\n",
6834 print_mac(mac
, conf
->bssid
));
6837 * very dubious code was here; the probe filtering flag is never set:
6839 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
6840 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
6843 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
6845 conf
->bssid
= priv
->mac_addr
;
6846 memcpy(priv
->bssid
, priv
->mac_addr
, ETH_ALEN
);
6847 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
6848 print_mac(mac
, conf
->bssid
));
6850 if (priv
->ibss_beacon
)
6851 dev_kfree_skb(priv
->ibss_beacon
);
6853 priv
->ibss_beacon
= ieee80211_beacon_get(hw
, vif
);
6856 if (iwl3945_is_rfkill(priv
))
6859 if (conf
->bssid
&& !is_zero_ether_addr(conf
->bssid
) &&
6860 !is_multicast_ether_addr(conf
->bssid
)) {
6861 /* If there is currently a HW scan going on in the background
6862 * then we need to cancel it else the RXON below will fail. */
6863 if (iwl3945_scan_cancel_timeout(priv
, 100)) {
6864 IWL_WARNING("Aborted scan still in progress "
6866 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
6867 mutex_unlock(&priv
->mutex
);
6870 memcpy(priv
->staging_rxon
.bssid_addr
, conf
->bssid
, ETH_ALEN
);
6872 /* TODO: Audit driver for usage of these members and see
6873 * if mac80211 deprecates them (priv->bssid looks like it
6874 * shouldn't be there, but I haven't scanned the IBSS code
6875 * to verify) - jpk */
6876 memcpy(priv
->bssid
, conf
->bssid
, ETH_ALEN
);
6878 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
6879 iwl3945_config_ap(priv
);
6881 rc
= iwl3945_commit_rxon(priv
);
6882 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) && rc
)
6883 iwl3945_add_station(priv
,
6884 priv
->active_rxon
.bssid_addr
, 1, 0);
6888 iwl3945_scan_cancel_timeout(priv
, 100);
6889 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6890 iwl3945_commit_rxon(priv
);
6894 spin_lock_irqsave(&priv
->lock
, flags
);
6895 if (!conf
->ssid_len
)
6896 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
6898 memcpy(priv
->essid
, conf
->ssid
, conf
->ssid_len
);
6900 priv
->essid_len
= conf
->ssid_len
;
6901 spin_unlock_irqrestore(&priv
->lock
, flags
);
6903 IWL_DEBUG_MAC80211("leave\n");
6904 mutex_unlock(&priv
->mutex
);
6909 static void iwl3945_configure_filter(struct ieee80211_hw
*hw
,
6910 unsigned int changed_flags
,
6911 unsigned int *total_flags
,
6912 int mc_count
, struct dev_addr_list
*mc_list
)
6914 struct iwl3945_priv
*priv
= hw
->priv
;
6916 if (changed_flags
& (*total_flags
) & FIF_OTHER_BSS
) {
6917 IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n",
6918 IEEE80211_IF_TYPE_MNTR
,
6919 changed_flags
, *total_flags
);
6920 /* queue work 'cuz mac80211 is holding a lock which
6921 * prevents us from issuing (synchronous) f/w cmds */
6922 queue_work(priv
->workqueue
, &priv
->set_monitor
);
6924 *total_flags
&= FIF_OTHER_BSS
| FIF_ALLMULTI
|
6925 FIF_BCN_PRBRESP_PROMISC
| FIF_CONTROL
;
6928 static void iwl3945_mac_remove_interface(struct ieee80211_hw
*hw
,
6929 struct ieee80211_if_init_conf
*conf
)
6931 struct iwl3945_priv
*priv
= hw
->priv
;
6933 IWL_DEBUG_MAC80211("enter\n");
6935 mutex_lock(&priv
->mutex
);
6937 if (iwl3945_is_ready_rf(priv
)) {
6938 iwl3945_scan_cancel_timeout(priv
, 100);
6939 cancel_delayed_work(&priv
->post_associate
);
6940 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6941 iwl3945_commit_rxon(priv
);
6943 if (priv
->vif
== conf
->vif
) {
6945 memset(priv
->bssid
, 0, ETH_ALEN
);
6946 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
6947 priv
->essid_len
= 0;
6949 mutex_unlock(&priv
->mutex
);
6951 IWL_DEBUG_MAC80211("leave\n");
6954 static int iwl3945_mac_hw_scan(struct ieee80211_hw
*hw
, u8
*ssid
, size_t len
)
6957 unsigned long flags
;
6958 struct iwl3945_priv
*priv
= hw
->priv
;
6960 IWL_DEBUG_MAC80211("enter\n");
6962 mutex_lock(&priv
->mutex
);
6963 spin_lock_irqsave(&priv
->lock
, flags
);
6965 if (!iwl3945_is_ready_rf(priv
)) {
6967 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
6971 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) { /* APs don't scan */
6973 IWL_ERROR("ERROR: APs don't scan\n");
6977 /* we don't schedule scan within next_scan_jiffies period */
6978 if (priv
->next_scan_jiffies
&&
6979 time_after(priv
->next_scan_jiffies
, jiffies
)) {
6983 /* if we just finished scan ask for delay for a broadcast scan */
6984 if ((len
== 0) && priv
->last_scan_jiffies
&&
6985 time_after(priv
->last_scan_jiffies
+ IWL_DELAY_NEXT_SCAN
,
6991 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
6992 iwl3945_escape_essid(ssid
, len
), (int)len
);
6994 priv
->one_direct_scan
= 1;
6995 priv
->direct_ssid_len
= (u8
)
6996 min((u8
) len
, (u8
) IW_ESSID_MAX_SIZE
);
6997 memcpy(priv
->direct_ssid
, ssid
, priv
->direct_ssid_len
);
6999 priv
->one_direct_scan
= 0;
7001 rc
= iwl3945_scan_initiate(priv
);
7003 IWL_DEBUG_MAC80211("leave\n");
7006 spin_unlock_irqrestore(&priv
->lock
, flags
);
7007 mutex_unlock(&priv
->mutex
);
7012 static int iwl3945_mac_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
7013 const u8
*local_addr
, const u8
*addr
,
7014 struct ieee80211_key_conf
*key
)
7016 struct iwl3945_priv
*priv
= hw
->priv
;
7020 IWL_DEBUG_MAC80211("enter\n");
7022 if (!iwl3945_param_hwcrypto
) {
7023 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
7027 if (is_zero_ether_addr(addr
))
7028 /* only support pairwise keys */
7031 sta_id
= iwl3945_hw_find_station(priv
, addr
);
7032 if (sta_id
== IWL_INVALID_STATION
) {
7033 DECLARE_MAC_BUF(mac
);
7035 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
7036 print_mac(mac
, addr
));
7040 mutex_lock(&priv
->mutex
);
7042 iwl3945_scan_cancel_timeout(priv
, 100);
7046 rc
= iwl3945_update_sta_key_info(priv
, key
, sta_id
);
7048 iwl3945_set_rxon_hwcrypto(priv
, 1);
7049 iwl3945_commit_rxon(priv
);
7050 key
->hw_key_idx
= sta_id
;
7051 IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n");
7052 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
7056 rc
= iwl3945_clear_sta_key_info(priv
, sta_id
);
7058 iwl3945_set_rxon_hwcrypto(priv
, 0);
7059 iwl3945_commit_rxon(priv
);
7060 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
7067 IWL_DEBUG_MAC80211("leave\n");
7068 mutex_unlock(&priv
->mutex
);
7073 static int iwl3945_mac_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
7074 const struct ieee80211_tx_queue_params
*params
)
7076 struct iwl3945_priv
*priv
= hw
->priv
;
7077 unsigned long flags
;
7080 IWL_DEBUG_MAC80211("enter\n");
7082 if (!iwl3945_is_ready_rf(priv
)) {
7083 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7087 if (queue
>= AC_NUM
) {
7088 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue
);
7092 if (!priv
->qos_data
.qos_enable
) {
7093 priv
->qos_data
.qos_active
= 0;
7094 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
7097 q
= AC_NUM
- 1 - queue
;
7099 spin_lock_irqsave(&priv
->lock
, flags
);
7101 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_min
= cpu_to_le16(params
->cw_min
);
7102 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_max
= cpu_to_le16(params
->cw_max
);
7103 priv
->qos_data
.def_qos_parm
.ac
[q
].aifsn
= params
->aifs
;
7104 priv
->qos_data
.def_qos_parm
.ac
[q
].edca_txop
=
7105 cpu_to_le16((params
->txop
* 32));
7107 priv
->qos_data
.def_qos_parm
.ac
[q
].reserved1
= 0;
7108 priv
->qos_data
.qos_active
= 1;
7110 spin_unlock_irqrestore(&priv
->lock
, flags
);
7112 mutex_lock(&priv
->mutex
);
7113 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
7114 iwl3945_activate_qos(priv
, 1);
7115 else if (priv
->assoc_id
&& iwl3945_is_associated(priv
))
7116 iwl3945_activate_qos(priv
, 0);
7118 mutex_unlock(&priv
->mutex
);
7120 IWL_DEBUG_MAC80211("leave\n");
7124 static int iwl3945_mac_get_tx_stats(struct ieee80211_hw
*hw
,
7125 struct ieee80211_tx_queue_stats
*stats
)
7127 struct iwl3945_priv
*priv
= hw
->priv
;
7129 struct iwl3945_tx_queue
*txq
;
7130 struct iwl3945_queue
*q
;
7131 unsigned long flags
;
7133 IWL_DEBUG_MAC80211("enter\n");
7135 if (!iwl3945_is_ready_rf(priv
)) {
7136 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7140 spin_lock_irqsave(&priv
->lock
, flags
);
7142 for (i
= 0; i
< AC_NUM
; i
++) {
7143 txq
= &priv
->txq
[i
];
7145 avail
= iwl3945_queue_space(q
);
7147 stats
[i
].len
= q
->n_window
- avail
;
7148 stats
[i
].limit
= q
->n_window
- q
->high_mark
;
7149 stats
[i
].count
= q
->n_window
;
7152 spin_unlock_irqrestore(&priv
->lock
, flags
);
7154 IWL_DEBUG_MAC80211("leave\n");
7159 static int iwl3945_mac_get_stats(struct ieee80211_hw
*hw
,
7160 struct ieee80211_low_level_stats
*stats
)
7162 IWL_DEBUG_MAC80211("enter\n");
7163 IWL_DEBUG_MAC80211("leave\n");
7168 static u64
iwl3945_mac_get_tsf(struct ieee80211_hw
*hw
)
7170 IWL_DEBUG_MAC80211("enter\n");
7171 IWL_DEBUG_MAC80211("leave\n");
7176 static void iwl3945_mac_reset_tsf(struct ieee80211_hw
*hw
)
7178 struct iwl3945_priv
*priv
= hw
->priv
;
7179 unsigned long flags
;
7181 mutex_lock(&priv
->mutex
);
7182 IWL_DEBUG_MAC80211("enter\n");
7184 iwl3945_reset_qos(priv
);
7186 cancel_delayed_work(&priv
->post_associate
);
7188 spin_lock_irqsave(&priv
->lock
, flags
);
7190 priv
->assoc_capability
= 0;
7191 priv
->call_post_assoc_from_beacon
= 0;
7193 /* new association get rid of ibss beacon skb */
7194 if (priv
->ibss_beacon
)
7195 dev_kfree_skb(priv
->ibss_beacon
);
7197 priv
->ibss_beacon
= NULL
;
7199 priv
->beacon_int
= priv
->hw
->conf
.beacon_int
;
7200 priv
->timestamp1
= 0;
7201 priv
->timestamp0
= 0;
7202 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
7203 priv
->beacon_int
= 0;
7205 spin_unlock_irqrestore(&priv
->lock
, flags
);
7207 if (!iwl3945_is_ready_rf(priv
)) {
7208 IWL_DEBUG_MAC80211("leave - not ready\n");
7209 mutex_unlock(&priv
->mutex
);
7213 /* we are restarting association process
7214 * clear RXON_FILTER_ASSOC_MSK bit
7216 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
7217 iwl3945_scan_cancel_timeout(priv
, 100);
7218 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
7219 iwl3945_commit_rxon(priv
);
7222 /* Per mac80211.h: This is only used in IBSS mode... */
7223 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
7225 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
7226 mutex_unlock(&priv
->mutex
);
7230 iwl3945_set_rate(priv
);
7232 mutex_unlock(&priv
->mutex
);
7234 IWL_DEBUG_MAC80211("leave\n");
7238 static int iwl3945_mac_beacon_update(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
7240 struct iwl3945_priv
*priv
= hw
->priv
;
7241 unsigned long flags
;
7243 mutex_lock(&priv
->mutex
);
7244 IWL_DEBUG_MAC80211("enter\n");
7246 if (!iwl3945_is_ready_rf(priv
)) {
7247 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7248 mutex_unlock(&priv
->mutex
);
7252 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
7253 IWL_DEBUG_MAC80211("leave - not IBSS\n");
7254 mutex_unlock(&priv
->mutex
);
7258 spin_lock_irqsave(&priv
->lock
, flags
);
7260 if (priv
->ibss_beacon
)
7261 dev_kfree_skb(priv
->ibss_beacon
);
7263 priv
->ibss_beacon
= skb
;
7267 IWL_DEBUG_MAC80211("leave\n");
7268 spin_unlock_irqrestore(&priv
->lock
, flags
);
7270 iwl3945_reset_qos(priv
);
7272 queue_work(priv
->workqueue
, &priv
->post_associate
.work
);
7274 mutex_unlock(&priv
->mutex
);
7279 /*****************************************************************************
7283 *****************************************************************************/
7285 #ifdef CONFIG_IWL3945_DEBUG
7288 * The following adds a new attribute to the sysfs representation
7289 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
7290 * used for controlling the debug level.
7292 * See the level definitions in iwl for details.
7295 static ssize_t
show_debug_level(struct device_driver
*d
, char *buf
)
7297 return sprintf(buf
, "0x%08X\n", iwl3945_debug_level
);
7299 static ssize_t
store_debug_level(struct device_driver
*d
,
7300 const char *buf
, size_t count
)
7302 char *p
= (char *)buf
;
7305 val
= simple_strtoul(p
, &p
, 0);
7307 printk(KERN_INFO DRV_NAME
7308 ": %s is not in hex or decimal form.\n", buf
);
7310 iwl3945_debug_level
= val
;
7312 return strnlen(buf
, count
);
7315 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
7316 show_debug_level
, store_debug_level
);
7318 #endif /* CONFIG_IWL3945_DEBUG */
7320 static ssize_t
show_temperature(struct device
*d
,
7321 struct device_attribute
*attr
, char *buf
)
7323 struct iwl3945_priv
*priv
= (struct iwl3945_priv
*)d
->driver_data
;
7325 if (!iwl3945_is_alive(priv
))
7328 return sprintf(buf
, "%d\n", iwl3945_hw_get_temperature(priv
));
7331 static DEVICE_ATTR(temperature
, S_IRUGO
, show_temperature
, NULL
);
7333 static ssize_t
show_rs_window(struct device
*d
,
7334 struct device_attribute
*attr
,
7337 struct iwl3945_priv
*priv
= d
->driver_data
;
7338 return iwl3945_fill_rs_info(priv
->hw
, buf
, IWL_AP_ID
);
7340 static DEVICE_ATTR(rs_window
, S_IRUGO
, show_rs_window
, NULL
);
7342 static ssize_t
show_tx_power(struct device
*d
,
7343 struct device_attribute
*attr
, char *buf
)
7345 struct iwl3945_priv
*priv
= (struct iwl3945_priv
*)d
->driver_data
;
7346 return sprintf(buf
, "%d\n", priv
->user_txpower_limit
);
7349 static ssize_t
store_tx_power(struct device
*d
,
7350 struct device_attribute
*attr
,
7351 const char *buf
, size_t count
)
7353 struct iwl3945_priv
*priv
= (struct iwl3945_priv
*)d
->driver_data
;
7354 char *p
= (char *)buf
;
7357 val
= simple_strtoul(p
, &p
, 10);
7359 printk(KERN_INFO DRV_NAME
7360 ": %s is not in decimal form.\n", buf
);
7362 iwl3945_hw_reg_set_txpower(priv
, val
);
7367 static DEVICE_ATTR(tx_power
, S_IWUSR
| S_IRUGO
, show_tx_power
, store_tx_power
);
7369 static ssize_t
show_flags(struct device
*d
,
7370 struct device_attribute
*attr
, char *buf
)
7372 struct iwl3945_priv
*priv
= (struct iwl3945_priv
*)d
->driver_data
;
7374 return sprintf(buf
, "0x%04X\n", priv
->active_rxon
.flags
);
7377 static ssize_t
store_flags(struct device
*d
,
7378 struct device_attribute
*attr
,
7379 const char *buf
, size_t count
)
7381 struct iwl3945_priv
*priv
= (struct iwl3945_priv
*)d
->driver_data
;
7382 u32 flags
= simple_strtoul(buf
, NULL
, 0);
7384 mutex_lock(&priv
->mutex
);
7385 if (le32_to_cpu(priv
->staging_rxon
.flags
) != flags
) {
7386 /* Cancel any currently running scans... */
7387 if (iwl3945_scan_cancel_timeout(priv
, 100))
7388 IWL_WARNING("Could not cancel scan.\n");
7390 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
7392 priv
->staging_rxon
.flags
= cpu_to_le32(flags
);
7393 iwl3945_commit_rxon(priv
);
7396 mutex_unlock(&priv
->mutex
);
7401 static DEVICE_ATTR(flags
, S_IWUSR
| S_IRUGO
, show_flags
, store_flags
);
7403 static ssize_t
show_filter_flags(struct device
*d
,
7404 struct device_attribute
*attr
, char *buf
)
7406 struct iwl3945_priv
*priv
= (struct iwl3945_priv
*)d
->driver_data
;
7408 return sprintf(buf
, "0x%04X\n",
7409 le32_to_cpu(priv
->active_rxon
.filter_flags
));
7412 static ssize_t
store_filter_flags(struct device
*d
,
7413 struct device_attribute
*attr
,
7414 const char *buf
, size_t count
)
7416 struct iwl3945_priv
*priv
= (struct iwl3945_priv
*)d
->driver_data
;
7417 u32 filter_flags
= simple_strtoul(buf
, NULL
, 0);
7419 mutex_lock(&priv
->mutex
);
7420 if (le32_to_cpu(priv
->staging_rxon
.filter_flags
) != filter_flags
) {
7421 /* Cancel any currently running scans... */
7422 if (iwl3945_scan_cancel_timeout(priv
, 100))
7423 IWL_WARNING("Could not cancel scan.\n");
7425 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
7426 "0x%04X\n", filter_flags
);
7427 priv
->staging_rxon
.filter_flags
=
7428 cpu_to_le32(filter_flags
);
7429 iwl3945_commit_rxon(priv
);
7432 mutex_unlock(&priv
->mutex
);
7437 static DEVICE_ATTR(filter_flags
, S_IWUSR
| S_IRUGO
, show_filter_flags
,
7438 store_filter_flags
);
7440 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
7442 static ssize_t
show_measurement(struct device
*d
,
7443 struct device_attribute
*attr
, char *buf
)
7445 struct iwl3945_priv
*priv
= dev_get_drvdata(d
);
7446 struct iwl3945_spectrum_notification measure_report
;
7447 u32 size
= sizeof(measure_report
), len
= 0, ofs
= 0;
7448 u8
*data
= (u8
*)&measure_report
;
7449 unsigned long flags
;
7451 spin_lock_irqsave(&priv
->lock
, flags
);
7452 if (!(priv
->measurement_status
& MEASUREMENT_READY
)) {
7453 spin_unlock_irqrestore(&priv
->lock
, flags
);
7456 memcpy(&measure_report
, &priv
->measure_report
, size
);
7457 priv
->measurement_status
= 0;
7458 spin_unlock_irqrestore(&priv
->lock
, flags
);
7460 while (size
&& (PAGE_SIZE
- len
)) {
7461 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
7462 PAGE_SIZE
- len
, 1);
7464 if (PAGE_SIZE
- len
)
7468 size
-= min(size
, 16U);
7474 static ssize_t
store_measurement(struct device
*d
,
7475 struct device_attribute
*attr
,
7476 const char *buf
, size_t count
)
7478 struct iwl3945_priv
*priv
= dev_get_drvdata(d
);
7479 struct ieee80211_measurement_params params
= {
7480 .channel
= le16_to_cpu(priv
->active_rxon
.channel
),
7481 .start_time
= cpu_to_le64(priv
->last_tsf
),
7482 .duration
= cpu_to_le16(1),
7484 u8 type
= IWL_MEASURE_BASIC
;
7490 strncpy(buffer
, buf
, min(sizeof(buffer
), count
));
7491 channel
= simple_strtoul(p
, NULL
, 0);
7493 params
.channel
= channel
;
7496 while (*p
&& *p
!= ' ')
7499 type
= simple_strtoul(p
+ 1, NULL
, 0);
7502 IWL_DEBUG_INFO("Invoking measurement of type %d on "
7503 "channel %d (for '%s')\n", type
, params
.channel
, buf
);
7504 iwl3945_get_measurement(priv
, ¶ms
, type
);
7509 static DEVICE_ATTR(measurement
, S_IRUSR
| S_IWUSR
,
7510 show_measurement
, store_measurement
);
7511 #endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
7513 static ssize_t
store_retry_rate(struct device
*d
,
7514 struct device_attribute
*attr
,
7515 const char *buf
, size_t count
)
7517 struct iwl3945_priv
*priv
= dev_get_drvdata(d
);
7519 priv
->retry_rate
= simple_strtoul(buf
, NULL
, 0);
7520 if (priv
->retry_rate
<= 0)
7521 priv
->retry_rate
= 1;
7526 static ssize_t
show_retry_rate(struct device
*d
,
7527 struct device_attribute
*attr
, char *buf
)
7529 struct iwl3945_priv
*priv
= dev_get_drvdata(d
);
7530 return sprintf(buf
, "%d", priv
->retry_rate
);
7533 static DEVICE_ATTR(retry_rate
, S_IWUSR
| S_IRUSR
, show_retry_rate
,
7536 static ssize_t
store_power_level(struct device
*d
,
7537 struct device_attribute
*attr
,
7538 const char *buf
, size_t count
)
7540 struct iwl3945_priv
*priv
= dev_get_drvdata(d
);
7544 mode
= simple_strtoul(buf
, NULL
, 0);
7545 mutex_lock(&priv
->mutex
);
7547 if (!iwl3945_is_ready(priv
)) {
7552 if ((mode
< 1) || (mode
> IWL_POWER_LIMIT
) || (mode
== IWL_POWER_AC
))
7553 mode
= IWL_POWER_AC
;
7555 mode
|= IWL_POWER_ENABLED
;
7557 if (mode
!= priv
->power_mode
) {
7558 rc
= iwl3945_send_power_mode(priv
, IWL_POWER_LEVEL(mode
));
7560 IWL_DEBUG_MAC80211("failed setting power mode.\n");
7563 priv
->power_mode
= mode
;
7569 mutex_unlock(&priv
->mutex
);
7573 #define MAX_WX_STRING 80
7575 /* Values are in microsecond */
7576 static const s32 timeout_duration
[] = {
7583 static const s32 period_duration
[] = {
7591 static ssize_t
show_power_level(struct device
*d
,
7592 struct device_attribute
*attr
, char *buf
)
7594 struct iwl3945_priv
*priv
= dev_get_drvdata(d
);
7595 int level
= IWL_POWER_LEVEL(priv
->power_mode
);
7598 p
+= sprintf(p
, "%d ", level
);
7600 case IWL_POWER_MODE_CAM
:
7602 p
+= sprintf(p
, "(AC)");
7604 case IWL_POWER_BATTERY
:
7605 p
+= sprintf(p
, "(BATTERY)");
7609 "(Timeout %dms, Period %dms)",
7610 timeout_duration
[level
- 1] / 1000,
7611 period_duration
[level
- 1] / 1000);
7614 if (!(priv
->power_mode
& IWL_POWER_ENABLED
))
7615 p
+= sprintf(p
, " OFF\n");
7617 p
+= sprintf(p
, " \n");
7623 static DEVICE_ATTR(power_level
, S_IWUSR
| S_IRUSR
, show_power_level
,
7626 static ssize_t
show_channels(struct device
*d
,
7627 struct device_attribute
*attr
, char *buf
)
7629 /* all this shit doesn't belong into sysfs anyway */
7633 static DEVICE_ATTR(channels
, S_IRUSR
, show_channels
, NULL
);
7635 static ssize_t
show_statistics(struct device
*d
,
7636 struct device_attribute
*attr
, char *buf
)
7638 struct iwl3945_priv
*priv
= dev_get_drvdata(d
);
7639 u32 size
= sizeof(struct iwl3945_notif_statistics
);
7640 u32 len
= 0, ofs
= 0;
7641 u8
*data
= (u8
*)&priv
->statistics
;
7644 if (!iwl3945_is_alive(priv
))
7647 mutex_lock(&priv
->mutex
);
7648 rc
= iwl3945_send_statistics_request(priv
);
7649 mutex_unlock(&priv
->mutex
);
7653 "Error sending statistics request: 0x%08X\n", rc
);
7657 while (size
&& (PAGE_SIZE
- len
)) {
7658 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
7659 PAGE_SIZE
- len
, 1);
7661 if (PAGE_SIZE
- len
)
7665 size
-= min(size
, 16U);
7671 static DEVICE_ATTR(statistics
, S_IRUGO
, show_statistics
, NULL
);
7673 static ssize_t
show_antenna(struct device
*d
,
7674 struct device_attribute
*attr
, char *buf
)
7676 struct iwl3945_priv
*priv
= dev_get_drvdata(d
);
7678 if (!iwl3945_is_alive(priv
))
7681 return sprintf(buf
, "%d\n", priv
->antenna
);
7684 static ssize_t
store_antenna(struct device
*d
,
7685 struct device_attribute
*attr
,
7686 const char *buf
, size_t count
)
7689 struct iwl3945_priv
*priv
= dev_get_drvdata(d
);
7694 if (sscanf(buf
, "%1i", &ant
) != 1) {
7695 IWL_DEBUG_INFO("not in hex or decimal form.\n");
7699 if ((ant
>= 0) && (ant
<= 2)) {
7700 IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant
);
7701 priv
->antenna
= (enum iwl3945_antenna
)ant
;
7703 IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant
);
7709 static DEVICE_ATTR(antenna
, S_IWUSR
| S_IRUGO
, show_antenna
, store_antenna
);
7711 static ssize_t
show_status(struct device
*d
,
7712 struct device_attribute
*attr
, char *buf
)
7714 struct iwl3945_priv
*priv
= (struct iwl3945_priv
*)d
->driver_data
;
7715 if (!iwl3945_is_alive(priv
))
7717 return sprintf(buf
, "0x%08x\n", (int)priv
->status
);
7720 static DEVICE_ATTR(status
, S_IRUGO
, show_status
, NULL
);
7722 static ssize_t
dump_error_log(struct device
*d
,
7723 struct device_attribute
*attr
,
7724 const char *buf
, size_t count
)
7726 char *p
= (char *)buf
;
7729 iwl3945_dump_nic_error_log((struct iwl3945_priv
*)d
->driver_data
);
7731 return strnlen(buf
, count
);
7734 static DEVICE_ATTR(dump_errors
, S_IWUSR
, NULL
, dump_error_log
);
7736 static ssize_t
dump_event_log(struct device
*d
,
7737 struct device_attribute
*attr
,
7738 const char *buf
, size_t count
)
7740 char *p
= (char *)buf
;
7743 iwl3945_dump_nic_event_log((struct iwl3945_priv
*)d
->driver_data
);
7745 return strnlen(buf
, count
);
7748 static DEVICE_ATTR(dump_events
, S_IWUSR
, NULL
, dump_event_log
);
7750 /*****************************************************************************
7752 * driver setup and teardown
7754 *****************************************************************************/
7756 static void iwl3945_setup_deferred_work(struct iwl3945_priv
*priv
)
7758 priv
->workqueue
= create_workqueue(DRV_NAME
);
7760 init_waitqueue_head(&priv
->wait_command_queue
);
7762 INIT_WORK(&priv
->up
, iwl3945_bg_up
);
7763 INIT_WORK(&priv
->restart
, iwl3945_bg_restart
);
7764 INIT_WORK(&priv
->rx_replenish
, iwl3945_bg_rx_replenish
);
7765 INIT_WORK(&priv
->scan_completed
, iwl3945_bg_scan_completed
);
7766 INIT_WORK(&priv
->request_scan
, iwl3945_bg_request_scan
);
7767 INIT_WORK(&priv
->abort_scan
, iwl3945_bg_abort_scan
);
7768 INIT_WORK(&priv
->rf_kill
, iwl3945_bg_rf_kill
);
7769 INIT_WORK(&priv
->beacon_update
, iwl3945_bg_beacon_update
);
7770 INIT_WORK(&priv
->set_monitor
, iwl3945_bg_set_monitor
);
7771 INIT_DELAYED_WORK(&priv
->post_associate
, iwl3945_bg_post_associate
);
7772 INIT_DELAYED_WORK(&priv
->init_alive_start
, iwl3945_bg_init_alive_start
);
7773 INIT_DELAYED_WORK(&priv
->alive_start
, iwl3945_bg_alive_start
);
7774 INIT_DELAYED_WORK(&priv
->scan_check
, iwl3945_bg_scan_check
);
7776 iwl3945_hw_setup_deferred_work(priv
);
7778 tasklet_init(&priv
->irq_tasklet
, (void (*)(unsigned long))
7779 iwl3945_irq_tasklet
, (unsigned long)priv
);
7782 static void iwl3945_cancel_deferred_work(struct iwl3945_priv
*priv
)
7784 iwl3945_hw_cancel_deferred_work(priv
);
7786 cancel_delayed_work_sync(&priv
->init_alive_start
);
7787 cancel_delayed_work(&priv
->scan_check
);
7788 cancel_delayed_work(&priv
->alive_start
);
7789 cancel_delayed_work(&priv
->post_associate
);
7790 cancel_work_sync(&priv
->beacon_update
);
7793 static struct attribute
*iwl3945_sysfs_entries
[] = {
7794 &dev_attr_antenna
.attr
,
7795 &dev_attr_channels
.attr
,
7796 &dev_attr_dump_errors
.attr
,
7797 &dev_attr_dump_events
.attr
,
7798 &dev_attr_flags
.attr
,
7799 &dev_attr_filter_flags
.attr
,
7800 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
7801 &dev_attr_measurement
.attr
,
7803 &dev_attr_power_level
.attr
,
7804 &dev_attr_retry_rate
.attr
,
7805 &dev_attr_rs_window
.attr
,
7806 &dev_attr_statistics
.attr
,
7807 &dev_attr_status
.attr
,
7808 &dev_attr_temperature
.attr
,
7809 &dev_attr_tx_power
.attr
,
7814 static struct attribute_group iwl3945_attribute_group
= {
7815 .name
= NULL
, /* put in device directory */
7816 .attrs
= iwl3945_sysfs_entries
,
7819 static struct ieee80211_ops iwl3945_hw_ops
= {
7820 .tx
= iwl3945_mac_tx
,
7821 .start
= iwl3945_mac_start
,
7822 .stop
= iwl3945_mac_stop
,
7823 .add_interface
= iwl3945_mac_add_interface
,
7824 .remove_interface
= iwl3945_mac_remove_interface
,
7825 .config
= iwl3945_mac_config
,
7826 .config_interface
= iwl3945_mac_config_interface
,
7827 .configure_filter
= iwl3945_configure_filter
,
7828 .set_key
= iwl3945_mac_set_key
,
7829 .get_stats
= iwl3945_mac_get_stats
,
7830 .get_tx_stats
= iwl3945_mac_get_tx_stats
,
7831 .conf_tx
= iwl3945_mac_conf_tx
,
7832 .get_tsf
= iwl3945_mac_get_tsf
,
7833 .reset_tsf
= iwl3945_mac_reset_tsf
,
7834 .hw_scan
= iwl3945_mac_hw_scan
7837 static int iwl3945_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
7840 struct iwl3945_priv
*priv
;
7841 struct ieee80211_hw
*hw
;
7842 struct iwl_3945_cfg
*cfg
= (struct iwl_3945_cfg
*)(ent
->driver_data
);
7843 unsigned long flags
;
7844 DECLARE_MAC_BUF(mac
);
7846 /* Disabling hardware scan means that mac80211 will perform scans
7847 * "the hard way", rather than using device's scan. */
7848 if (iwl3945_param_disable_hw_scan
) {
7849 IWL_DEBUG_INFO("Disabling hw_scan\n");
7850 iwl3945_hw_ops
.hw_scan
= NULL
;
7853 if ((iwl3945_param_queues_num
> IWL39_MAX_NUM_QUEUES
) ||
7854 (iwl3945_param_queues_num
< IWL_MIN_NUM_QUEUES
)) {
7855 IWL_ERROR("invalid queues_num, should be between %d and %d\n",
7856 IWL_MIN_NUM_QUEUES
, IWL39_MAX_NUM_QUEUES
);
7861 /* mac80211 allocates memory for this device instance, including
7862 * space for this driver's private structure */
7863 hw
= ieee80211_alloc_hw(sizeof(struct iwl3945_priv
), &iwl3945_hw_ops
);
7865 IWL_ERROR("Can not allocate network device\n");
7869 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
7871 hw
->rate_control_algorithm
= "iwl-3945-rs";
7873 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
7877 priv
->pci_dev
= pdev
;
7880 /* Select antenna (may be helpful if only one antenna is connected) */
7881 priv
->antenna
= (enum iwl3945_antenna
)iwl3945_param_antenna
;
7882 #ifdef CONFIG_IWL3945_DEBUG
7883 iwl3945_debug_level
= iwl3945_param_debug
;
7884 atomic_set(&priv
->restrict_refcnt
, 0);
7886 priv
->retry_rate
= 1;
7888 priv
->ibss_beacon
= NULL
;
7890 /* Tell mac80211 our characteristics */
7891 hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
7892 IEEE80211_HW_NOISE_DBM
;
7894 /* 4 EDCA QOS priorities */
7897 spin_lock_init(&priv
->lock
);
7898 spin_lock_init(&priv
->power_data
.lock
);
7899 spin_lock_init(&priv
->sta_lock
);
7900 spin_lock_init(&priv
->hcmd_lock
);
7902 INIT_LIST_HEAD(&priv
->free_frames
);
7904 mutex_init(&priv
->mutex
);
7905 if (pci_enable_device(pdev
)) {
7907 goto out_ieee80211_free_hw
;
7910 pci_set_master(pdev
);
7912 /* Clear the driver's (not device's) station table */
7913 iwl3945_clear_stations_table(priv
);
7915 priv
->data_retry_limit
= -1;
7916 priv
->ieee_channels
= NULL
;
7917 priv
->ieee_rates
= NULL
;
7918 priv
->band
= IEEE80211_BAND_2GHZ
;
7920 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
7922 err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
7924 printk(KERN_WARNING DRV_NAME
": No suitable DMA available.\n");
7925 goto out_pci_disable_device
;
7928 pci_set_drvdata(pdev
, priv
);
7929 err
= pci_request_regions(pdev
, DRV_NAME
);
7931 goto out_pci_disable_device
;
7933 /* We disable the RETRY_TIMEOUT register (0x41) to keep
7934 * PCI Tx retries from interfering with C3 CPU state */
7935 pci_write_config_byte(pdev
, 0x41, 0x00);
7937 priv
->hw_base
= pci_iomap(pdev
, 0, 0);
7938 if (!priv
->hw_base
) {
7940 goto out_pci_release_regions
;
7943 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
7944 (unsigned long long) pci_resource_len(pdev
, 0));
7945 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv
->hw_base
);
7947 /* Initialize module parameter values here */
7949 /* Disable radio (SW RF KILL) via parameter when loading driver */
7950 if (iwl3945_param_disable
) {
7951 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
7952 IWL_DEBUG_INFO("Radio disabled.\n");
7955 priv
->iw_mode
= IEEE80211_IF_TYPE_STA
;
7957 printk(KERN_INFO DRV_NAME
7958 ": Detected Intel Wireless WiFi Link %s\n", priv
->cfg
->name
);
7960 /* Device-specific setup */
7961 if (iwl3945_hw_set_hw_setting(priv
)) {
7962 IWL_ERROR("failed to set hw settings\n");
7966 if (iwl3945_param_qos_enable
)
7967 priv
->qos_data
.qos_enable
= 1;
7969 iwl3945_reset_qos(priv
);
7971 priv
->qos_data
.qos_active
= 0;
7972 priv
->qos_data
.qos_cap
.val
= 0;
7974 iwl3945_set_rxon_channel(priv
, IEEE80211_BAND_2GHZ
, 6);
7975 iwl3945_setup_deferred_work(priv
);
7976 iwl3945_setup_rx_handlers(priv
);
7978 priv
->rates_mask
= IWL_RATES_MASK
;
7979 /* If power management is turned on, default to AC mode */
7980 priv
->power_mode
= IWL_POWER_AC
;
7981 priv
->user_txpower_limit
= IWL_DEFAULT_TX_POWER
;
7983 spin_lock_irqsave(&priv
->lock
, flags
);
7984 iwl3945_disable_interrupts(priv
);
7985 spin_unlock_irqrestore(&priv
->lock
, flags
);
7987 err
= sysfs_create_group(&pdev
->dev
.kobj
, &iwl3945_attribute_group
);
7989 IWL_ERROR("failed to create sysfs device attributes\n");
7990 goto out_release_irq
;
7994 iwl3945_set_bit(priv
, CSR_GIO_CHICKEN_BITS
,
7995 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER
);
7997 iwl3945_set_bit(priv
, CSR_GP_CNTRL
, CSR_GP_CNTRL_REG_FLAG_INIT_DONE
);
7998 err
= iwl3945_poll_bit(priv
, CSR_GP_CNTRL
,
7999 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY
,
8000 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY
, 25000);
8002 IWL_DEBUG_INFO("Failed to init the card\n");
8003 goto out_remove_sysfs
;
8005 /* Read the EEPROM */
8006 err
= iwl3945_eeprom_init(priv
);
8008 IWL_ERROR("Unable to init EEPROM\n");
8009 goto out_remove_sysfs
;
8011 /* MAC Address location in EEPROM same for 3945/4965 */
8012 get_eeprom_mac(priv
, priv
->mac_addr
);
8013 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac
, priv
->mac_addr
));
8014 SET_IEEE80211_PERM_ADDR(priv
->hw
, priv
->mac_addr
);
8016 err
= iwl3945_init_channel_map(priv
);
8018 IWL_ERROR("initializing regulatory failed: %d\n", err
);
8019 goto out_remove_sysfs
;
8022 err
= iwl3945_init_geos(priv
);
8024 IWL_ERROR("initializing geos failed: %d\n", err
);
8025 goto out_free_channel_map
;
8028 err
= ieee80211_register_hw(priv
->hw
);
8030 IWL_ERROR("Failed to register network device (error %d)\n", err
);
8034 priv
->hw
->conf
.beacon_int
= 100;
8035 priv
->mac80211_registered
= 1;
8036 pci_save_state(pdev
);
8037 pci_disable_device(pdev
);
8039 err
= iwl3945_rfkill_init(priv
);
8041 IWL_ERROR("Unable to initialize RFKILL system. "
8042 "Ignoring error: %d\n", err
);
8047 iwl3945_free_geos(priv
);
8048 out_free_channel_map
:
8049 iwl3945_free_channel_map(priv
);
8051 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl3945_attribute_group
);
8054 destroy_workqueue(priv
->workqueue
);
8055 priv
->workqueue
= NULL
;
8056 iwl3945_unset_hw_setting(priv
);
8059 pci_iounmap(pdev
, priv
->hw_base
);
8060 out_pci_release_regions
:
8061 pci_release_regions(pdev
);
8062 out_pci_disable_device
:
8063 pci_disable_device(pdev
);
8064 pci_set_drvdata(pdev
, NULL
);
8065 out_ieee80211_free_hw
:
8066 ieee80211_free_hw(priv
->hw
);
8071 static void __devexit
iwl3945_pci_remove(struct pci_dev
*pdev
)
8073 struct iwl3945_priv
*priv
= pci_get_drvdata(pdev
);
8074 unsigned long flags
;
8079 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
8081 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
8085 /* make sure we flush any pending irq or
8086 * tasklet for the driver
8088 spin_lock_irqsave(&priv
->lock
, flags
);
8089 iwl3945_disable_interrupts(priv
);
8090 spin_unlock_irqrestore(&priv
->lock
, flags
);
8092 iwl_synchronize_irq(priv
);
8094 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl3945_attribute_group
);
8096 iwl3945_rfkill_unregister(priv
);
8097 iwl3945_dealloc_ucode_pci(priv
);
8100 iwl3945_rx_queue_free(priv
, &priv
->rxq
);
8101 iwl3945_hw_txq_ctx_free(priv
);
8103 iwl3945_unset_hw_setting(priv
);
8104 iwl3945_clear_stations_table(priv
);
8106 if (priv
->mac80211_registered
)
8107 ieee80211_unregister_hw(priv
->hw
);
8109 /*netif_stop_queue(dev); */
8110 flush_workqueue(priv
->workqueue
);
8112 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
8113 * priv->workqueue... so we can't take down the workqueue
8115 destroy_workqueue(priv
->workqueue
);
8116 priv
->workqueue
= NULL
;
8118 pci_iounmap(pdev
, priv
->hw_base
);
8119 pci_release_regions(pdev
);
8120 pci_disable_device(pdev
);
8121 pci_set_drvdata(pdev
, NULL
);
8123 iwl3945_free_channel_map(priv
);
8124 iwl3945_free_geos(priv
);
8126 if (priv
->ibss_beacon
)
8127 dev_kfree_skb(priv
->ibss_beacon
);
8129 ieee80211_free_hw(priv
->hw
);
8134 static int iwl3945_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
8136 struct iwl3945_priv
*priv
= pci_get_drvdata(pdev
);
8138 if (priv
->is_open
) {
8139 set_bit(STATUS_IN_SUSPEND
, &priv
->status
);
8140 iwl3945_mac_stop(priv
->hw
);
8144 pci_set_power_state(pdev
, PCI_D3hot
);
8149 static int iwl3945_pci_resume(struct pci_dev
*pdev
)
8151 struct iwl3945_priv
*priv
= pci_get_drvdata(pdev
);
8153 pci_set_power_state(pdev
, PCI_D0
);
8156 iwl3945_mac_start(priv
->hw
);
8158 clear_bit(STATUS_IN_SUSPEND
, &priv
->status
);
8162 #endif /* CONFIG_PM */
8164 /*************** RFKILL FUNCTIONS **********/
8165 #ifdef CONFIG_IWL3945_RFKILL
8166 /* software rf-kill from user */
8167 static int iwl3945_rfkill_soft_rf_kill(void *data
, enum rfkill_state state
)
8169 struct iwl3945_priv
*priv
= data
;
8175 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
8178 IWL_DEBUG_RF_KILL("we recieved soft RFKILL set to state %d\n", state
);
8179 mutex_lock(&priv
->mutex
);
8182 case RFKILL_STATE_UNBLOCKED
:
8183 if (iwl3945_is_rfkill_hw(priv
)) {
8187 iwl3945_radio_kill_sw(priv
, 0);
8189 case RFKILL_STATE_SOFT_BLOCKED
:
8190 iwl3945_radio_kill_sw(priv
, 1);
8193 IWL_WARNING("we recieved unexpected RFKILL state %d\n", state
);
8197 mutex_unlock(&priv
->mutex
);
8202 int iwl3945_rfkill_init(struct iwl3945_priv
*priv
)
8204 struct device
*device
= wiphy_dev(priv
->hw
->wiphy
);
8207 BUG_ON(device
== NULL
);
8209 IWL_DEBUG_RF_KILL("Initializing RFKILL.\n");
8210 priv
->rfkill
= rfkill_allocate(device
, RFKILL_TYPE_WLAN
);
8211 if (!priv
->rfkill
) {
8212 IWL_ERROR("Unable to allocate rfkill device.\n");
8217 priv
->rfkill
->name
= priv
->cfg
->name
;
8218 priv
->rfkill
->data
= priv
;
8219 priv
->rfkill
->state
= RFKILL_STATE_UNBLOCKED
;
8220 priv
->rfkill
->toggle_radio
= iwl3945_rfkill_soft_rf_kill
;
8221 priv
->rfkill
->user_claim_unsupported
= 1;
8223 priv
->rfkill
->dev
.class->suspend
= NULL
;
8224 priv
->rfkill
->dev
.class->resume
= NULL
;
8226 ret
= rfkill_register(priv
->rfkill
);
8228 IWL_ERROR("Unable to register rfkill: %d\n", ret
);
8232 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
8236 if (priv
->rfkill
!= NULL
)
8237 rfkill_free(priv
->rfkill
);
8238 priv
->rfkill
= NULL
;
8241 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
8245 void iwl3945_rfkill_unregister(struct iwl3945_priv
*priv
)
8248 rfkill_unregister(priv
->rfkill
);
8250 priv
->rfkill
= NULL
;
8253 /* set rf-kill to the right state. */
8254 void iwl3945_rfkill_set_hw_state(struct iwl3945_priv
*priv
)
8260 if (iwl3945_is_rfkill_hw(priv
)) {
8261 rfkill_force_state(priv
->rfkill
, RFKILL_STATE_HARD_BLOCKED
);
8265 if (!iwl3945_is_rfkill_sw(priv
))
8266 rfkill_force_state(priv
->rfkill
, RFKILL_STATE_UNBLOCKED
);
8268 rfkill_force_state(priv
->rfkill
, RFKILL_STATE_SOFT_BLOCKED
);
8272 /*****************************************************************************
8274 * driver and module entry point
8276 *****************************************************************************/
8278 static struct pci_driver iwl3945_driver
= {
8280 .id_table
= iwl3945_hw_card_ids
,
8281 .probe
= iwl3945_pci_probe
,
8282 .remove
= __devexit_p(iwl3945_pci_remove
),
8284 .suspend
= iwl3945_pci_suspend
,
8285 .resume
= iwl3945_pci_resume
,
8289 static int __init
iwl3945_init(void)
8293 printk(KERN_INFO DRV_NAME
": " DRV_DESCRIPTION
", " DRV_VERSION
"\n");
8294 printk(KERN_INFO DRV_NAME
": " DRV_COPYRIGHT
"\n");
8296 ret
= iwl3945_rate_control_register();
8298 IWL_ERROR("Unable to register rate control algorithm: %d\n", ret
);
8302 ret
= pci_register_driver(&iwl3945_driver
);
8304 IWL_ERROR("Unable to initialize PCI module\n");
8305 goto error_register
;
8307 #ifdef CONFIG_IWL3945_DEBUG
8308 ret
= driver_create_file(&iwl3945_driver
.driver
, &driver_attr_debug_level
);
8310 IWL_ERROR("Unable to create driver sysfs file\n");
8317 #ifdef CONFIG_IWL3945_DEBUG
8319 pci_unregister_driver(&iwl3945_driver
);
8322 iwl3945_rate_control_unregister();
8326 static void __exit
iwl3945_exit(void)
8328 #ifdef CONFIG_IWL3945_DEBUG
8329 driver_remove_file(&iwl3945_driver
.driver
, &driver_attr_debug_level
);
8331 pci_unregister_driver(&iwl3945_driver
);
8332 iwl3945_rate_control_unregister();
8335 module_param_named(antenna
, iwl3945_param_antenna
, int, 0444);
8336 MODULE_PARM_DESC(antenna
, "select antenna (1=Main, 2=Aux, default 0 [both])");
8337 module_param_named(disable
, iwl3945_param_disable
, int, 0444);
8338 MODULE_PARM_DESC(disable
, "manually disable the radio (default 0 [radio on])");
8339 module_param_named(hwcrypto
, iwl3945_param_hwcrypto
, int, 0444);
8340 MODULE_PARM_DESC(hwcrypto
,
8341 "using hardware crypto engine (default 0 [software])\n");
8342 module_param_named(debug
, iwl3945_param_debug
, int, 0444);
8343 MODULE_PARM_DESC(debug
, "debug output mask");
8344 module_param_named(disable_hw_scan
, iwl3945_param_disable_hw_scan
, int, 0444);
8345 MODULE_PARM_DESC(disable_hw_scan
, "disable hardware scanning (default 0)");
8347 module_param_named(queues_num
, iwl3945_param_queues_num
, int, 0444);
8348 MODULE_PARM_DESC(queues_num
, "number of hw queues.");
8351 module_param_named(qos_enable
, iwl3945_param_qos_enable
, int, 0444);
8352 MODULE_PARM_DESC(qos_enable
, "enable all QoS functionality");
8354 module_exit(iwl3945_exit
);
8355 module_init(iwl3945_init
);