1 /******************************************************************************
3 * Copyright(c) 2003 - 2007 Intel Corporation. All rights reserved.
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
24 * Contact Information:
25 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *****************************************************************************/
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/version.h>
33 #include <linux/init.h>
34 #include <linux/pci.h>
35 #include <linux/dma-mapping.h>
36 #include <linux/delay.h>
37 #include <linux/skbuff.h>
38 #include <linux/netdevice.h>
39 #include <linux/wireless.h>
40 #include <linux/firmware.h>
41 #include <linux/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
= IWL_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-2007 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 __le16
*ieee80211_get_qos_ctrl(struct ieee80211_hdr
*hdr
)
107 u16 fc
= le16_to_cpu(hdr
->frame_control
);
108 int hdr_len
= ieee80211_get_hdrlen(fc
);
110 if ((fc
& 0x00cc) == (IEEE80211_STYPE_QOS_DATA
| IEEE80211_FTYPE_DATA
))
111 return (__le16
*) ((u8
*) hdr
+ hdr_len
- QOS_CONTROL_LEN
);
115 static const struct ieee80211_supported_band
*iwl3945_get_band(
116 struct iwl3945_priv
*priv
, enum ieee80211_band band
)
118 return priv
->hw
->wiphy
->bands
[band
];
121 static int iwl3945_is_empty_essid(const char *essid
, int essid_len
)
123 /* Single white space is for Linksys APs */
124 if (essid_len
== 1 && essid
[0] == ' ')
127 /* Otherwise, if the entire essid is 0, we assume it is hidden */
130 if (essid
[essid_len
] != '\0')
137 static const char *iwl3945_escape_essid(const char *essid
, u8 essid_len
)
139 static char escaped
[IW_ESSID_MAX_SIZE
* 2 + 1];
140 const char *s
= essid
;
143 if (iwl3945_is_empty_essid(essid
, essid_len
)) {
144 memcpy(escaped
, "<hidden>", sizeof("<hidden>"));
148 essid_len
= min(essid_len
, (u8
) IW_ESSID_MAX_SIZE
);
149 while (essid_len
--) {
161 /*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
164 * Theory of operation
166 * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
167 * of buffer descriptors, each of which points to one or more data buffers for
168 * the device to read from or fill. Driver and device exchange status of each
169 * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
170 * entries in each circular buffer, to protect against confusing empty and full
173 * The device reads or writes the data in the queues via the device's several
174 * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
176 * For Tx queue, there are low mark and high mark limits. If, after queuing
177 * the packet for Tx, free space become < low mark, Tx queue stopped. When
178 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
181 * The 3945 operates with six queues: One receive queue, one transmit queue
182 * (#4) for sending commands to the device firmware, and four transmit queues
183 * (#0-3) for data tx via EDCA. An additional 2 HCCA queues are unused.
184 ***************************************************/
186 static int iwl3945_queue_space(const struct iwl3945_queue
*q
)
188 int s
= q
->read_ptr
- q
->write_ptr
;
190 if (q
->read_ptr
> q
->write_ptr
)
195 /* keep some reserve to not confuse empty and full situations */
203 * iwl3945_queue_inc_wrap - increment queue index, wrap back to beginning
204 * @index -- current index
205 * @n_bd -- total number of entries in queue (must be power of 2)
207 static inline int iwl3945_queue_inc_wrap(int index
, int n_bd
)
209 return ++index
& (n_bd
- 1);
213 * iwl3945_queue_dec_wrap - increment queue index, wrap back to end
214 * @index -- current index
215 * @n_bd -- total number of entries in queue (must be power of 2)
217 static inline int iwl3945_queue_dec_wrap(int index
, int n_bd
)
219 return --index
& (n_bd
- 1);
222 static inline int x2_queue_used(const struct iwl3945_queue
*q
, int i
)
224 return q
->write_ptr
> q
->read_ptr
?
225 (i
>= q
->read_ptr
&& i
< q
->write_ptr
) :
226 !(i
< q
->read_ptr
&& i
>= q
->write_ptr
);
229 static inline u8
get_cmd_index(struct iwl3945_queue
*q
, u32 index
, int is_huge
)
231 /* This is for scan command, the big buffer at end of command array */
233 return q
->n_window
; /* must be power of 2 */
235 /* Otherwise, use normal size buffers */
236 return index
& (q
->n_window
- 1);
240 * iwl3945_queue_init - Initialize queue's high/low-water and read/write indexes
242 static int iwl3945_queue_init(struct iwl3945_priv
*priv
, struct iwl3945_queue
*q
,
243 int count
, int slots_num
, u32 id
)
246 q
->n_window
= slots_num
;
249 /* count must be power-of-two size, otherwise iwl3945_queue_inc_wrap
250 * and iwl3945_queue_dec_wrap are broken. */
251 BUG_ON(!is_power_of_2(count
));
253 /* slots_num must be power-of-two size, otherwise
254 * get_cmd_index is broken. */
255 BUG_ON(!is_power_of_2(slots_num
));
257 q
->low_mark
= q
->n_window
/ 4;
261 q
->high_mark
= q
->n_window
/ 8;
262 if (q
->high_mark
< 2)
265 q
->write_ptr
= q
->read_ptr
= 0;
271 * iwl3945_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
273 static int iwl3945_tx_queue_alloc(struct iwl3945_priv
*priv
,
274 struct iwl3945_tx_queue
*txq
, u32 id
)
276 struct pci_dev
*dev
= priv
->pci_dev
;
278 /* Driver private data, only for Tx (not command) queues,
279 * not shared with device. */
280 if (id
!= IWL_CMD_QUEUE_NUM
) {
281 txq
->txb
= kmalloc(sizeof(txq
->txb
[0]) *
282 TFD_QUEUE_SIZE_MAX
, GFP_KERNEL
);
284 IWL_ERROR("kmalloc for auxiliary BD "
285 "structures failed\n");
291 /* Circular buffer of transmit frame descriptors (TFDs),
292 * shared with device */
293 txq
->bd
= pci_alloc_consistent(dev
,
294 sizeof(txq
->bd
[0]) * TFD_QUEUE_SIZE_MAX
,
298 IWL_ERROR("pci_alloc_consistent(%zd) failed\n",
299 sizeof(txq
->bd
[0]) * TFD_QUEUE_SIZE_MAX
);
316 * iwl3945_tx_queue_init - Allocate and initialize one tx/cmd queue
318 int iwl3945_tx_queue_init(struct iwl3945_priv
*priv
,
319 struct iwl3945_tx_queue
*txq
, int slots_num
, u32 txq_id
)
321 struct pci_dev
*dev
= priv
->pci_dev
;
326 * Alloc buffer array for commands (Tx or other types of commands).
327 * For the command queue (#4), allocate command space + one big
328 * command for scan, since scan command is very huge; the system will
329 * not have two scans at the same time, so only one is needed.
330 * For data Tx queues (all other queues), no super-size command
333 len
= sizeof(struct iwl3945_cmd
) * slots_num
;
334 if (txq_id
== IWL_CMD_QUEUE_NUM
)
335 len
+= IWL_MAX_SCAN_SIZE
;
336 txq
->cmd
= pci_alloc_consistent(dev
, len
, &txq
->dma_addr_cmd
);
340 /* Alloc driver data array and TFD circular buffer */
341 rc
= iwl3945_tx_queue_alloc(priv
, txq
, txq_id
);
343 pci_free_consistent(dev
, len
, txq
->cmd
, txq
->dma_addr_cmd
);
347 txq
->need_update
= 0;
349 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
350 * iwl3945_queue_inc_wrap and iwl3945_queue_dec_wrap are broken. */
351 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX
& (TFD_QUEUE_SIZE_MAX
- 1));
353 /* Initialize queue high/low-water, head/tail indexes */
354 iwl3945_queue_init(priv
, &txq
->q
, TFD_QUEUE_SIZE_MAX
, slots_num
, txq_id
);
356 /* Tell device where to find queue, enable DMA channel. */
357 iwl3945_hw_tx_queue_init(priv
, txq
);
363 * iwl3945_tx_queue_free - Deallocate DMA queue.
364 * @txq: Transmit queue to deallocate.
366 * Empty queue by removing and destroying all BD's.
368 * 0-fill, but do not free "txq" descriptor structure.
370 void iwl3945_tx_queue_free(struct iwl3945_priv
*priv
, struct iwl3945_tx_queue
*txq
)
372 struct iwl3945_queue
*q
= &txq
->q
;
373 struct pci_dev
*dev
= priv
->pci_dev
;
379 /* first, empty all BD's */
380 for (; q
->write_ptr
!= q
->read_ptr
;
381 q
->read_ptr
= iwl3945_queue_inc_wrap(q
->read_ptr
, q
->n_bd
))
382 iwl3945_hw_txq_free_tfd(priv
, txq
);
384 len
= sizeof(struct iwl3945_cmd
) * q
->n_window
;
385 if (q
->id
== IWL_CMD_QUEUE_NUM
)
386 len
+= IWL_MAX_SCAN_SIZE
;
388 /* De-alloc array of command/tx buffers */
389 pci_free_consistent(dev
, len
, txq
->cmd
, txq
->dma_addr_cmd
);
391 /* De-alloc circular buffer of TFDs */
393 pci_free_consistent(dev
, sizeof(struct iwl3945_tfd_frame
) *
394 txq
->q
.n_bd
, txq
->bd
, txq
->q
.dma_addr
);
396 /* De-alloc array of per-TFD driver data */
402 /* 0-fill queue descriptor structure */
403 memset(txq
, 0, sizeof(*txq
));
406 const u8 iwl3945_broadcast_addr
[ETH_ALEN
] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
408 /*************** STATION TABLE MANAGEMENT ****
409 * mac80211 should be examined to determine if sta_info is duplicating
410 * the functionality provided here
413 /**************************************************************/
414 #if 0 /* temporary disable till we add real remove station */
416 * iwl3945_remove_station - Remove driver's knowledge of station.
418 * NOTE: This does not remove station from device's station table.
420 static u8
iwl3945_remove_station(struct iwl3945_priv
*priv
, const u8
*addr
, int is_ap
)
422 int index
= IWL_INVALID_STATION
;
426 spin_lock_irqsave(&priv
->sta_lock
, flags
);
430 else if (is_broadcast_ether_addr(addr
))
431 index
= priv
->hw_setting
.bcast_sta_id
;
433 for (i
= IWL_STA_ID
; i
< priv
->hw_setting
.max_stations
; i
++)
434 if (priv
->stations
[i
].used
&&
435 !compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
441 if (unlikely(index
== IWL_INVALID_STATION
))
444 if (priv
->stations
[index
].used
) {
445 priv
->stations
[index
].used
= 0;
446 priv
->num_stations
--;
449 BUG_ON(priv
->num_stations
< 0);
452 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
458 * iwl3945_clear_stations_table - Clear the driver's station table
460 * NOTE: This does not clear or otherwise alter the device's station table.
462 static void iwl3945_clear_stations_table(struct iwl3945_priv
*priv
)
466 spin_lock_irqsave(&priv
->sta_lock
, flags
);
468 priv
->num_stations
= 0;
469 memset(priv
->stations
, 0, sizeof(priv
->stations
));
471 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
475 * iwl3945_add_station - Add station to station tables in driver and device
477 u8
iwl3945_add_station(struct iwl3945_priv
*priv
, const u8
*addr
, int is_ap
, u8 flags
)
480 int index
= IWL_INVALID_STATION
;
481 struct iwl3945_station_entry
*station
;
482 unsigned long flags_spin
;
483 DECLARE_MAC_BUF(mac
);
486 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
489 else if (is_broadcast_ether_addr(addr
))
490 index
= priv
->hw_setting
.bcast_sta_id
;
492 for (i
= IWL_STA_ID
; i
< priv
->hw_setting
.max_stations
; i
++) {
493 if (!compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
499 if (!priv
->stations
[i
].used
&&
500 index
== IWL_INVALID_STATION
)
504 /* These two conditions has the same outcome but keep them separate
505 since they have different meaning */
506 if (unlikely(index
== IWL_INVALID_STATION
)) {
507 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
511 if (priv
->stations
[index
].used
&&
512 !compare_ether_addr(priv
->stations
[index
].sta
.sta
.addr
, addr
)) {
513 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
517 IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index
, print_mac(mac
, addr
));
518 station
= &priv
->stations
[index
];
520 priv
->num_stations
++;
522 /* Set up the REPLY_ADD_STA command to send to device */
523 memset(&station
->sta
, 0, sizeof(struct iwl3945_addsta_cmd
));
524 memcpy(station
->sta
.sta
.addr
, addr
, ETH_ALEN
);
525 station
->sta
.mode
= 0;
526 station
->sta
.sta
.sta_id
= index
;
527 station
->sta
.station_flags
= 0;
529 if (priv
->band
== IEEE80211_BAND_5GHZ
)
530 rate
= IWL_RATE_6M_PLCP
;
532 rate
= IWL_RATE_1M_PLCP
;
534 /* Turn on both antennas for the station... */
535 station
->sta
.rate_n_flags
=
536 iwl3945_hw_set_rate_n_flags(rate
, RATE_MCS_ANT_AB_MSK
);
537 station
->current_rate
.rate_n_flags
=
538 le16_to_cpu(station
->sta
.rate_n_flags
);
540 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
542 /* Add station to device's station table */
543 iwl3945_send_add_station(priv
, &station
->sta
, flags
);
548 /*************** DRIVER STATUS FUNCTIONS *****/
550 static inline int iwl3945_is_ready(struct iwl3945_priv
*priv
)
552 /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are
553 * set but EXIT_PENDING is not */
554 return test_bit(STATUS_READY
, &priv
->status
) &&
555 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) &&
556 !test_bit(STATUS_EXIT_PENDING
, &priv
->status
);
559 static inline int iwl3945_is_alive(struct iwl3945_priv
*priv
)
561 return test_bit(STATUS_ALIVE
, &priv
->status
);
564 static inline int iwl3945_is_init(struct iwl3945_priv
*priv
)
566 return test_bit(STATUS_INIT
, &priv
->status
);
569 static inline int iwl3945_is_rfkill(struct iwl3945_priv
*priv
)
571 return test_bit(STATUS_RF_KILL_HW
, &priv
->status
) ||
572 test_bit(STATUS_RF_KILL_SW
, &priv
->status
);
575 static inline int iwl3945_is_ready_rf(struct iwl3945_priv
*priv
)
578 if (iwl3945_is_rfkill(priv
))
581 return iwl3945_is_ready(priv
);
584 /*************** HOST COMMAND QUEUE FUNCTIONS *****/
586 #define IWL_CMD(x) case x : return #x
588 static const char *get_cmd_string(u8 cmd
)
591 IWL_CMD(REPLY_ALIVE
);
592 IWL_CMD(REPLY_ERROR
);
594 IWL_CMD(REPLY_RXON_ASSOC
);
595 IWL_CMD(REPLY_QOS_PARAM
);
596 IWL_CMD(REPLY_RXON_TIMING
);
597 IWL_CMD(REPLY_ADD_STA
);
598 IWL_CMD(REPLY_REMOVE_STA
);
599 IWL_CMD(REPLY_REMOVE_ALL_STA
);
600 IWL_CMD(REPLY_3945_RX
);
602 IWL_CMD(REPLY_RATE_SCALE
);
603 IWL_CMD(REPLY_LEDS_CMD
);
604 IWL_CMD(REPLY_TX_LINK_QUALITY_CMD
);
605 IWL_CMD(RADAR_NOTIFICATION
);
606 IWL_CMD(REPLY_QUIET_CMD
);
607 IWL_CMD(REPLY_CHANNEL_SWITCH
);
608 IWL_CMD(CHANNEL_SWITCH_NOTIFICATION
);
609 IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD
);
610 IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION
);
611 IWL_CMD(POWER_TABLE_CMD
);
612 IWL_CMD(PM_SLEEP_NOTIFICATION
);
613 IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC
);
614 IWL_CMD(REPLY_SCAN_CMD
);
615 IWL_CMD(REPLY_SCAN_ABORT_CMD
);
616 IWL_CMD(SCAN_START_NOTIFICATION
);
617 IWL_CMD(SCAN_RESULTS_NOTIFICATION
);
618 IWL_CMD(SCAN_COMPLETE_NOTIFICATION
);
619 IWL_CMD(BEACON_NOTIFICATION
);
620 IWL_CMD(REPLY_TX_BEACON
);
621 IWL_CMD(WHO_IS_AWAKE_NOTIFICATION
);
622 IWL_CMD(QUIET_NOTIFICATION
);
623 IWL_CMD(REPLY_TX_PWR_TABLE_CMD
);
624 IWL_CMD(MEASURE_ABORT_NOTIFICATION
);
625 IWL_CMD(REPLY_BT_CONFIG
);
626 IWL_CMD(REPLY_STATISTICS_CMD
);
627 IWL_CMD(STATISTICS_NOTIFICATION
);
628 IWL_CMD(REPLY_CARD_STATE_CMD
);
629 IWL_CMD(CARD_STATE_NOTIFICATION
);
630 IWL_CMD(MISSED_BEACONS_NOTIFICATION
);
637 #define HOST_COMPLETE_TIMEOUT (HZ / 2)
640 * iwl3945_enqueue_hcmd - enqueue a uCode command
641 * @priv: device private data point
642 * @cmd: a point to the ucode command structure
644 * The function returns < 0 values to indicate the operation is
645 * failed. On success, it turns the index (> 0) of command in the
648 static int iwl3945_enqueue_hcmd(struct iwl3945_priv
*priv
, struct iwl3945_host_cmd
*cmd
)
650 struct iwl3945_tx_queue
*txq
= &priv
->txq
[IWL_CMD_QUEUE_NUM
];
651 struct iwl3945_queue
*q
= &txq
->q
;
652 struct iwl3945_tfd_frame
*tfd
;
654 struct iwl3945_cmd
*out_cmd
;
656 u16 fix_size
= (u16
)(cmd
->len
+ sizeof(out_cmd
->hdr
));
657 dma_addr_t phys_addr
;
663 /* If any of the command structures end up being larger than
664 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
665 * we will need to increase the size of the TFD entries */
666 BUG_ON((fix_size
> TFD_MAX_PAYLOAD_SIZE
) &&
667 !(cmd
->meta
.flags
& CMD_SIZE_HUGE
));
670 if (iwl3945_is_rfkill(priv
)) {
671 IWL_DEBUG_INFO("Not sending command - RF KILL");
675 if (iwl3945_queue_space(q
) < ((cmd
->meta
.flags
& CMD_ASYNC
) ? 2 : 1)) {
676 IWL_ERROR("No space for Tx\n");
680 spin_lock_irqsave(&priv
->hcmd_lock
, flags
);
682 tfd
= &txq
->bd
[q
->write_ptr
];
683 memset(tfd
, 0, sizeof(*tfd
));
685 control_flags
= (u32
*) tfd
;
687 idx
= get_cmd_index(q
, q
->write_ptr
, cmd
->meta
.flags
& CMD_SIZE_HUGE
);
688 out_cmd
= &txq
->cmd
[idx
];
690 out_cmd
->hdr
.cmd
= cmd
->id
;
691 memcpy(&out_cmd
->meta
, &cmd
->meta
, sizeof(cmd
->meta
));
692 memcpy(&out_cmd
->cmd
.payload
, cmd
->data
, cmd
->len
);
694 /* At this point, the out_cmd now has all of the incoming cmd
697 out_cmd
->hdr
.flags
= 0;
698 out_cmd
->hdr
.sequence
= cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM
) |
699 INDEX_TO_SEQ(q
->write_ptr
));
700 if (out_cmd
->meta
.flags
& CMD_SIZE_HUGE
)
701 out_cmd
->hdr
.sequence
|= cpu_to_le16(SEQ_HUGE_FRAME
);
703 phys_addr
= txq
->dma_addr_cmd
+ sizeof(txq
->cmd
[0]) * idx
+
704 offsetof(struct iwl3945_cmd
, hdr
);
705 iwl3945_hw_txq_attach_buf_to_tfd(priv
, tfd
, phys_addr
, fix_size
);
707 pad
= U32_PAD(cmd
->len
);
708 count
= TFD_CTL_COUNT_GET(*control_flags
);
709 *control_flags
= TFD_CTL_COUNT_SET(count
) | TFD_CTL_PAD_SET(pad
);
711 IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
712 "%d bytes at %d[%d]:%d\n",
713 get_cmd_string(out_cmd
->hdr
.cmd
),
714 out_cmd
->hdr
.cmd
, le16_to_cpu(out_cmd
->hdr
.sequence
),
715 fix_size
, q
->write_ptr
, idx
, IWL_CMD_QUEUE_NUM
);
717 txq
->need_update
= 1;
719 /* Increment and update queue's write index */
720 q
->write_ptr
= iwl3945_queue_inc_wrap(q
->write_ptr
, q
->n_bd
);
721 ret
= iwl3945_tx_queue_update_write_ptr(priv
, txq
);
723 spin_unlock_irqrestore(&priv
->hcmd_lock
, flags
);
724 return ret
? ret
: idx
;
727 static int iwl3945_send_cmd_async(struct iwl3945_priv
*priv
, struct iwl3945_host_cmd
*cmd
)
731 BUG_ON(!(cmd
->meta
.flags
& CMD_ASYNC
));
733 /* An asynchronous command can not expect an SKB to be set. */
734 BUG_ON(cmd
->meta
.flags
& CMD_WANT_SKB
);
736 /* An asynchronous command MUST have a callback. */
737 BUG_ON(!cmd
->meta
.u
.callback
);
739 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
742 ret
= iwl3945_enqueue_hcmd(priv
, cmd
);
744 IWL_ERROR("Error sending %s: iwl3945_enqueue_hcmd failed: %d\n",
745 get_cmd_string(cmd
->id
), ret
);
751 static int iwl3945_send_cmd_sync(struct iwl3945_priv
*priv
, struct iwl3945_host_cmd
*cmd
)
755 static atomic_t entry
= ATOMIC_INIT(0); /* reentrance protection */
757 BUG_ON(cmd
->meta
.flags
& CMD_ASYNC
);
759 /* A synchronous command can not have a callback set. */
760 BUG_ON(cmd
->meta
.u
.callback
!= NULL
);
762 if (atomic_xchg(&entry
, 1)) {
763 IWL_ERROR("Error sending %s: Already sending a host command\n",
764 get_cmd_string(cmd
->id
));
768 set_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
770 if (cmd
->meta
.flags
& CMD_WANT_SKB
)
771 cmd
->meta
.source
= &cmd
->meta
;
773 cmd_idx
= iwl3945_enqueue_hcmd(priv
, cmd
);
776 IWL_ERROR("Error sending %s: iwl3945_enqueue_hcmd failed: %d\n",
777 get_cmd_string(cmd
->id
), ret
);
781 ret
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
782 !test_bit(STATUS_HCMD_ACTIVE
, &priv
->status
),
783 HOST_COMPLETE_TIMEOUT
);
785 if (test_bit(STATUS_HCMD_ACTIVE
, &priv
->status
)) {
786 IWL_ERROR("Error sending %s: time out after %dms.\n",
787 get_cmd_string(cmd
->id
),
788 jiffies_to_msecs(HOST_COMPLETE_TIMEOUT
));
790 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
796 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) {
797 IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n",
798 get_cmd_string(cmd
->id
));
802 if (test_bit(STATUS_FW_ERROR
, &priv
->status
)) {
803 IWL_DEBUG_INFO("Command %s failed: FW Error\n",
804 get_cmd_string(cmd
->id
));
808 if ((cmd
->meta
.flags
& CMD_WANT_SKB
) && !cmd
->meta
.u
.skb
) {
809 IWL_ERROR("Error: Response NULL in '%s'\n",
810 get_cmd_string(cmd
->id
));
819 if (cmd
->meta
.flags
& CMD_WANT_SKB
) {
820 struct iwl3945_cmd
*qcmd
;
822 /* Cancel the CMD_WANT_SKB flag for the cmd in the
823 * TX cmd queue. Otherwise in case the cmd comes
824 * in later, it will possibly set an invalid
825 * address (cmd->meta.source). */
826 qcmd
= &priv
->txq
[IWL_CMD_QUEUE_NUM
].cmd
[cmd_idx
];
827 qcmd
->meta
.flags
&= ~CMD_WANT_SKB
;
830 if (cmd
->meta
.u
.skb
) {
831 dev_kfree_skb_any(cmd
->meta
.u
.skb
);
832 cmd
->meta
.u
.skb
= NULL
;
835 atomic_set(&entry
, 0);
839 int iwl3945_send_cmd(struct iwl3945_priv
*priv
, struct iwl3945_host_cmd
*cmd
)
841 if (cmd
->meta
.flags
& CMD_ASYNC
)
842 return iwl3945_send_cmd_async(priv
, cmd
);
844 return iwl3945_send_cmd_sync(priv
, cmd
);
847 int iwl3945_send_cmd_pdu(struct iwl3945_priv
*priv
, u8 id
, u16 len
, const void *data
)
849 struct iwl3945_host_cmd cmd
= {
855 return iwl3945_send_cmd_sync(priv
, &cmd
);
858 static int __must_check
iwl3945_send_cmd_u32(struct iwl3945_priv
*priv
, u8 id
, u32 val
)
860 struct iwl3945_host_cmd cmd
= {
866 return iwl3945_send_cmd_sync(priv
, &cmd
);
869 int iwl3945_send_statistics_request(struct iwl3945_priv
*priv
)
871 return iwl3945_send_cmd_u32(priv
, REPLY_STATISTICS_CMD
, 0);
875 * iwl3945_set_rxon_channel - Set the phymode and channel values in staging RXON
876 * @band: 2.4 or 5 GHz band
877 * @channel: Any channel valid for the requested band
879 * In addition to setting the staging RXON, priv->band is also set.
881 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
882 * in the staging RXON flag structure based on the band
884 static int iwl3945_set_rxon_channel(struct iwl3945_priv
*priv
,
885 enum ieee80211_band band
,
888 if (!iwl3945_get_channel_info(priv
, band
, channel
)) {
889 IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
894 if ((le16_to_cpu(priv
->staging_rxon
.channel
) == channel
) &&
895 (priv
->band
== band
))
898 priv
->staging_rxon
.channel
= cpu_to_le16(channel
);
899 if (band
== IEEE80211_BAND_5GHZ
)
900 priv
->staging_rxon
.flags
&= ~RXON_FLG_BAND_24G_MSK
;
902 priv
->staging_rxon
.flags
|= RXON_FLG_BAND_24G_MSK
;
906 IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel
, band
);
912 * iwl3945_check_rxon_cmd - validate RXON structure is valid
914 * NOTE: This is really only useful during development and can eventually
915 * be #ifdef'd out once the driver is stable and folks aren't actively
918 static int iwl3945_check_rxon_cmd(struct iwl3945_rxon_cmd
*rxon
)
923 if (rxon
->flags
& RXON_FLG_BAND_24G_MSK
) {
924 error
|= le32_to_cpu(rxon
->flags
&
925 (RXON_FLG_TGJ_NARROW_BAND_MSK
|
926 RXON_FLG_RADAR_DETECT_MSK
));
928 IWL_WARNING("check 24G fields %d | %d\n",
931 error
|= (rxon
->flags
& RXON_FLG_SHORT_SLOT_MSK
) ?
932 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK
);
934 IWL_WARNING("check 52 fields %d | %d\n",
936 error
|= le32_to_cpu(rxon
->flags
& RXON_FLG_CCK_MSK
);
938 IWL_WARNING("check 52 CCK %d | %d\n",
941 error
|= (rxon
->node_addr
[0] | rxon
->bssid_addr
[0]) & 0x1;
943 IWL_WARNING("check mac addr %d | %d\n", counter
++, error
);
945 /* make sure basic rates 6Mbps and 1Mbps are supported */
946 error
|= (((rxon
->ofdm_basic_rates
& IWL_RATE_6M_MASK
) == 0) &&
947 ((rxon
->cck_basic_rates
& IWL_RATE_1M_MASK
) == 0));
949 IWL_WARNING("check basic rate %d | %d\n", counter
++, error
);
951 error
|= (le16_to_cpu(rxon
->assoc_id
) > 2007);
953 IWL_WARNING("check assoc id %d | %d\n", counter
++, error
);
955 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
))
956 == (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
));
958 IWL_WARNING("check CCK and short slot %d | %d\n",
961 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
))
962 == (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
));
964 IWL_WARNING("check CCK & auto detect %d | %d\n",
967 error
|= ((rxon
->flags
& (RXON_FLG_AUTO_DETECT_MSK
|
968 RXON_FLG_TGG_PROTECT_MSK
)) == RXON_FLG_TGG_PROTECT_MSK
);
970 IWL_WARNING("check TGG and auto detect %d | %d\n",
973 if ((rxon
->flags
& RXON_FLG_DIS_DIV_MSK
))
974 error
|= ((rxon
->flags
& (RXON_FLG_ANT_B_MSK
|
975 RXON_FLG_ANT_A_MSK
)) == 0);
977 IWL_WARNING("check antenna %d %d\n", counter
++, error
);
980 IWL_WARNING("Tuning to channel %d\n",
981 le16_to_cpu(rxon
->channel
));
984 IWL_ERROR("Not a valid iwl3945_rxon_assoc_cmd field values\n");
991 * iwl3945_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
992 * @priv: staging_rxon is compared to active_rxon
994 * If the RXON structure is changing enough to require a new tune,
995 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
996 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
998 static int iwl3945_full_rxon_required(struct iwl3945_priv
*priv
)
1001 /* These items are only settable from the full RXON command */
1002 if (!(priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) ||
1003 compare_ether_addr(priv
->staging_rxon
.bssid_addr
,
1004 priv
->active_rxon
.bssid_addr
) ||
1005 compare_ether_addr(priv
->staging_rxon
.node_addr
,
1006 priv
->active_rxon
.node_addr
) ||
1007 compare_ether_addr(priv
->staging_rxon
.wlap_bssid_addr
,
1008 priv
->active_rxon
.wlap_bssid_addr
) ||
1009 (priv
->staging_rxon
.dev_type
!= priv
->active_rxon
.dev_type
) ||
1010 (priv
->staging_rxon
.channel
!= priv
->active_rxon
.channel
) ||
1011 (priv
->staging_rxon
.air_propagation
!=
1012 priv
->active_rxon
.air_propagation
) ||
1013 (priv
->staging_rxon
.assoc_id
!= priv
->active_rxon
.assoc_id
))
1016 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
1017 * be updated with the RXON_ASSOC command -- however only some
1018 * flag transitions are allowed using RXON_ASSOC */
1020 /* Check if we are not switching bands */
1021 if ((priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) !=
1022 (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
))
1025 /* Check if we are switching association toggle */
1026 if ((priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) !=
1027 (priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
))
1033 static int iwl3945_send_rxon_assoc(struct iwl3945_priv
*priv
)
1036 struct iwl3945_rx_packet
*res
= NULL
;
1037 struct iwl3945_rxon_assoc_cmd rxon_assoc
;
1038 struct iwl3945_host_cmd cmd
= {
1039 .id
= REPLY_RXON_ASSOC
,
1040 .len
= sizeof(rxon_assoc
),
1041 .meta
.flags
= CMD_WANT_SKB
,
1042 .data
= &rxon_assoc
,
1044 const struct iwl3945_rxon_cmd
*rxon1
= &priv
->staging_rxon
;
1045 const struct iwl3945_rxon_cmd
*rxon2
= &priv
->active_rxon
;
1047 if ((rxon1
->flags
== rxon2
->flags
) &&
1048 (rxon1
->filter_flags
== rxon2
->filter_flags
) &&
1049 (rxon1
->cck_basic_rates
== rxon2
->cck_basic_rates
) &&
1050 (rxon1
->ofdm_basic_rates
== rxon2
->ofdm_basic_rates
)) {
1051 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
1055 rxon_assoc
.flags
= priv
->staging_rxon
.flags
;
1056 rxon_assoc
.filter_flags
= priv
->staging_rxon
.filter_flags
;
1057 rxon_assoc
.ofdm_basic_rates
= priv
->staging_rxon
.ofdm_basic_rates
;
1058 rxon_assoc
.cck_basic_rates
= priv
->staging_rxon
.cck_basic_rates
;
1059 rxon_assoc
.reserved
= 0;
1061 rc
= iwl3945_send_cmd_sync(priv
, &cmd
);
1065 res
= (struct iwl3945_rx_packet
*)cmd
.meta
.u
.skb
->data
;
1066 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1067 IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n");
1071 priv
->alloc_rxb_skb
--;
1072 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1078 * iwl3945_commit_rxon - commit staging_rxon to hardware
1080 * The RXON command in staging_rxon is committed to the hardware and
1081 * the active_rxon structure is updated with the new data. This
1082 * function correctly transitions out of the RXON_ASSOC_MSK state if
1083 * a HW tune is required based on the RXON structure changes.
1085 static int iwl3945_commit_rxon(struct iwl3945_priv
*priv
)
1087 /* cast away the const for active_rxon in this function */
1088 struct iwl3945_rxon_cmd
*active_rxon
= (void *)&priv
->active_rxon
;
1090 DECLARE_MAC_BUF(mac
);
1092 if (!iwl3945_is_alive(priv
))
1095 /* always get timestamp with Rx frame */
1096 priv
->staging_rxon
.flags
|= RXON_FLG_TSF2HOST_MSK
;
1098 /* select antenna */
1099 priv
->staging_rxon
.flags
&=
1100 ~(RXON_FLG_DIS_DIV_MSK
| RXON_FLG_ANT_SEL_MSK
);
1101 priv
->staging_rxon
.flags
|= iwl3945_get_antenna_flags(priv
);
1103 rc
= iwl3945_check_rxon_cmd(&priv
->staging_rxon
);
1105 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
1109 /* If we don't need to send a full RXON, we can use
1110 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
1111 * and other flags for the current radio configuration. */
1112 if (!iwl3945_full_rxon_required(priv
)) {
1113 rc
= iwl3945_send_rxon_assoc(priv
);
1115 IWL_ERROR("Error setting RXON_ASSOC "
1116 "configuration (%d).\n", rc
);
1120 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
1125 /* If we are currently associated and the new config requires
1126 * an RXON_ASSOC and the new config wants the associated mask enabled,
1127 * we must clear the associated from the active configuration
1128 * before we apply the new config */
1129 if (iwl3945_is_associated(priv
) &&
1130 (priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
)) {
1131 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
1132 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
1134 rc
= iwl3945_send_cmd_pdu(priv
, REPLY_RXON
,
1135 sizeof(struct iwl3945_rxon_cmd
),
1136 &priv
->active_rxon
);
1138 /* If the mask clearing failed then we set
1139 * active_rxon back to what it was previously */
1141 active_rxon
->filter_flags
|= RXON_FILTER_ASSOC_MSK
;
1142 IWL_ERROR("Error clearing ASSOC_MSK on current "
1143 "configuration (%d).\n", rc
);
1148 IWL_DEBUG_INFO("Sending RXON\n"
1149 "* with%s RXON_FILTER_ASSOC_MSK\n"
1152 ((priv
->staging_rxon
.filter_flags
&
1153 RXON_FILTER_ASSOC_MSK
) ? "" : "out"),
1154 le16_to_cpu(priv
->staging_rxon
.channel
),
1155 print_mac(mac
, priv
->staging_rxon
.bssid_addr
));
1157 /* Apply the new configuration */
1158 rc
= iwl3945_send_cmd_pdu(priv
, REPLY_RXON
,
1159 sizeof(struct iwl3945_rxon_cmd
), &priv
->staging_rxon
);
1161 IWL_ERROR("Error setting new configuration (%d).\n", rc
);
1165 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
1167 iwl3945_clear_stations_table(priv
);
1169 /* If we issue a new RXON command which required a tune then we must
1170 * send a new TXPOWER command or we won't be able to Tx any frames */
1171 rc
= iwl3945_hw_reg_send_txpower(priv
);
1173 IWL_ERROR("Error setting Tx power (%d).\n", rc
);
1177 /* Add the broadcast address so we can send broadcast frames */
1178 if (iwl3945_add_station(priv
, iwl3945_broadcast_addr
, 0, 0) ==
1179 IWL_INVALID_STATION
) {
1180 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
1184 /* If we have set the ASSOC_MSK and we are in BSS mode then
1185 * add the IWL_AP_ID to the station rate table */
1186 if (iwl3945_is_associated(priv
) &&
1187 (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
1188 if (iwl3945_add_station(priv
, priv
->active_rxon
.bssid_addr
, 1, 0)
1189 == IWL_INVALID_STATION
) {
1190 IWL_ERROR("Error adding AP address for transmit.\n");
1194 /* Init the hardware's rate fallback order based on the band */
1195 rc
= iwl3945_init_hw_rate_table(priv
);
1197 IWL_ERROR("Error setting HW rate table: %02X\n", rc
);
1204 static int iwl3945_send_bt_config(struct iwl3945_priv
*priv
)
1206 struct iwl3945_bt_cmd bt_cmd
= {
1214 return iwl3945_send_cmd_pdu(priv
, REPLY_BT_CONFIG
,
1215 sizeof(struct iwl3945_bt_cmd
), &bt_cmd
);
1218 static int iwl3945_send_scan_abort(struct iwl3945_priv
*priv
)
1221 struct iwl3945_rx_packet
*res
;
1222 struct iwl3945_host_cmd cmd
= {
1223 .id
= REPLY_SCAN_ABORT_CMD
,
1224 .meta
.flags
= CMD_WANT_SKB
,
1227 /* If there isn't a scan actively going on in the hardware
1228 * then we are in between scan bands and not actually
1229 * actively scanning, so don't send the abort command */
1230 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
1231 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1235 rc
= iwl3945_send_cmd_sync(priv
, &cmd
);
1237 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1241 res
= (struct iwl3945_rx_packet
*)cmd
.meta
.u
.skb
->data
;
1242 if (res
->u
.status
!= CAN_ABORT_STATUS
) {
1243 /* The scan abort will return 1 for success or
1244 * 2 for "failure". A failure condition can be
1245 * due to simply not being in an active scan which
1246 * can occur if we send the scan abort before we
1247 * the microcode has notified us that a scan is
1249 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res
->u
.status
);
1250 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1251 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
1254 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1259 static int iwl3945_card_state_sync_callback(struct iwl3945_priv
*priv
,
1260 struct iwl3945_cmd
*cmd
,
1261 struct sk_buff
*skb
)
1269 * Use: Sets the device's internal card state to enable, disable, or halt
1271 * When in the 'enable' state the card operates as normal.
1272 * When in the 'disable' state, the card enters into a low power mode.
1273 * When in the 'halt' state, the card is shut down and must be fully
1274 * restarted to come back on.
1276 static int iwl3945_send_card_state(struct iwl3945_priv
*priv
, u32 flags
, u8 meta_flag
)
1278 struct iwl3945_host_cmd cmd
= {
1279 .id
= REPLY_CARD_STATE_CMD
,
1282 .meta
.flags
= meta_flag
,
1285 if (meta_flag
& CMD_ASYNC
)
1286 cmd
.meta
.u
.callback
= iwl3945_card_state_sync_callback
;
1288 return iwl3945_send_cmd(priv
, &cmd
);
1291 static int iwl3945_add_sta_sync_callback(struct iwl3945_priv
*priv
,
1292 struct iwl3945_cmd
*cmd
, struct sk_buff
*skb
)
1294 struct iwl3945_rx_packet
*res
= NULL
;
1297 IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
1301 res
= (struct iwl3945_rx_packet
*)skb
->data
;
1302 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1303 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1308 switch (res
->u
.add_sta
.status
) {
1309 case ADD_STA_SUCCESS_MSK
:
1315 /* We didn't cache the SKB; let the caller free it */
1319 int iwl3945_send_add_station(struct iwl3945_priv
*priv
,
1320 struct iwl3945_addsta_cmd
*sta
, u8 flags
)
1322 struct iwl3945_rx_packet
*res
= NULL
;
1324 struct iwl3945_host_cmd cmd
= {
1325 .id
= REPLY_ADD_STA
,
1326 .len
= sizeof(struct iwl3945_addsta_cmd
),
1327 .meta
.flags
= flags
,
1331 if (flags
& CMD_ASYNC
)
1332 cmd
.meta
.u
.callback
= iwl3945_add_sta_sync_callback
;
1334 cmd
.meta
.flags
|= CMD_WANT_SKB
;
1336 rc
= iwl3945_send_cmd(priv
, &cmd
);
1338 if (rc
|| (flags
& CMD_ASYNC
))
1341 res
= (struct iwl3945_rx_packet
*)cmd
.meta
.u
.skb
->data
;
1342 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1343 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1349 switch (res
->u
.add_sta
.status
) {
1350 case ADD_STA_SUCCESS_MSK
:
1351 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
1355 IWL_WARNING("REPLY_ADD_STA failed\n");
1360 priv
->alloc_rxb_skb
--;
1361 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1366 static int iwl3945_update_sta_key_info(struct iwl3945_priv
*priv
,
1367 struct ieee80211_key_conf
*keyconf
,
1370 unsigned long flags
;
1371 __le16 key_flags
= 0;
1373 switch (keyconf
->alg
) {
1375 key_flags
|= STA_KEY_FLG_CCMP
;
1376 key_flags
|= cpu_to_le16(
1377 keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
1378 key_flags
&= ~STA_KEY_FLG_INVALID
;
1385 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1386 priv
->stations
[sta_id
].keyinfo
.alg
= keyconf
->alg
;
1387 priv
->stations
[sta_id
].keyinfo
.keylen
= keyconf
->keylen
;
1388 memcpy(priv
->stations
[sta_id
].keyinfo
.key
, keyconf
->key
,
1391 memcpy(priv
->stations
[sta_id
].sta
.key
.key
, keyconf
->key
,
1393 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
1394 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1395 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1397 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1399 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
1400 iwl3945_send_add_station(priv
, &priv
->stations
[sta_id
].sta
, 0);
1404 static int iwl3945_clear_sta_key_info(struct iwl3945_priv
*priv
, u8 sta_id
)
1406 unsigned long flags
;
1408 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1409 memset(&priv
->stations
[sta_id
].keyinfo
, 0, sizeof(struct iwl3945_hw_key
));
1410 memset(&priv
->stations
[sta_id
].sta
.key
, 0, sizeof(struct iwl3945_keyinfo
));
1411 priv
->stations
[sta_id
].sta
.key
.key_flags
= STA_KEY_FLG_NO_ENC
;
1412 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1413 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1414 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1416 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
1417 iwl3945_send_add_station(priv
, &priv
->stations
[sta_id
].sta
, 0);
1421 static void iwl3945_clear_free_frames(struct iwl3945_priv
*priv
)
1423 struct list_head
*element
;
1425 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
1426 priv
->frames_count
);
1428 while (!list_empty(&priv
->free_frames
)) {
1429 element
= priv
->free_frames
.next
;
1431 kfree(list_entry(element
, struct iwl3945_frame
, list
));
1432 priv
->frames_count
--;
1435 if (priv
->frames_count
) {
1436 IWL_WARNING("%d frames still in use. Did we lose one?\n",
1437 priv
->frames_count
);
1438 priv
->frames_count
= 0;
1442 static struct iwl3945_frame
*iwl3945_get_free_frame(struct iwl3945_priv
*priv
)
1444 struct iwl3945_frame
*frame
;
1445 struct list_head
*element
;
1446 if (list_empty(&priv
->free_frames
)) {
1447 frame
= kzalloc(sizeof(*frame
), GFP_KERNEL
);
1449 IWL_ERROR("Could not allocate frame!\n");
1453 priv
->frames_count
++;
1457 element
= priv
->free_frames
.next
;
1459 return list_entry(element
, struct iwl3945_frame
, list
);
1462 static void iwl3945_free_frame(struct iwl3945_priv
*priv
, struct iwl3945_frame
*frame
)
1464 memset(frame
, 0, sizeof(*frame
));
1465 list_add(&frame
->list
, &priv
->free_frames
);
1468 unsigned int iwl3945_fill_beacon_frame(struct iwl3945_priv
*priv
,
1469 struct ieee80211_hdr
*hdr
,
1470 const u8
*dest
, int left
)
1473 if (!iwl3945_is_associated(priv
) || !priv
->ibss_beacon
||
1474 ((priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) &&
1475 (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
)))
1478 if (priv
->ibss_beacon
->len
> left
)
1481 memcpy(hdr
, priv
->ibss_beacon
->data
, priv
->ibss_beacon
->len
);
1483 return priv
->ibss_beacon
->len
;
1486 static u8
iwl3945_rate_get_lowest_plcp(int rate_mask
)
1490 for (i
= IWL_RATE_1M_INDEX
; i
!= IWL_RATE_INVALID
;
1491 i
= iwl3945_rates
[i
].next_ieee
) {
1492 if (rate_mask
& (1 << i
))
1493 return iwl3945_rates
[i
].plcp
;
1496 return IWL_RATE_INVALID
;
1499 static int iwl3945_send_beacon_cmd(struct iwl3945_priv
*priv
)
1501 struct iwl3945_frame
*frame
;
1502 unsigned int frame_size
;
1506 frame
= iwl3945_get_free_frame(priv
);
1509 IWL_ERROR("Could not obtain free frame buffer for beacon "
1514 if (!(priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)) {
1515 rate
= iwl3945_rate_get_lowest_plcp(priv
->active_rate_basic
&
1517 if (rate
== IWL_INVALID_RATE
)
1518 rate
= IWL_RATE_6M_PLCP
;
1520 rate
= iwl3945_rate_get_lowest_plcp(priv
->active_rate_basic
& 0xF);
1521 if (rate
== IWL_INVALID_RATE
)
1522 rate
= IWL_RATE_1M_PLCP
;
1525 frame_size
= iwl3945_hw_get_beacon_cmd(priv
, frame
, rate
);
1527 rc
= iwl3945_send_cmd_pdu(priv
, REPLY_TX_BEACON
, frame_size
,
1530 iwl3945_free_frame(priv
, frame
);
1535 /******************************************************************************
1537 * EEPROM related functions
1539 ******************************************************************************/
1541 static void get_eeprom_mac(struct iwl3945_priv
*priv
, u8
*mac
)
1543 memcpy(mac
, priv
->eeprom
.mac_address
, 6);
1547 * Clear the OWNER_MSK, to establish driver (instead of uCode running on
1548 * embedded controller) as EEPROM reader; each read is a series of pulses
1549 * to/from the EEPROM chip, not a single event, so even reads could conflict
1550 * if they weren't arbitrated by some ownership mechanism. Here, the driver
1551 * simply claims ownership, which should be safe when this function is called
1552 * (i.e. before loading uCode!).
1554 static inline int iwl3945_eeprom_acquire_semaphore(struct iwl3945_priv
*priv
)
1556 _iwl3945_clear_bit(priv
, CSR_EEPROM_GP
, CSR_EEPROM_GP_IF_OWNER_MSK
);
1561 * iwl3945_eeprom_init - read EEPROM contents
1563 * Load the EEPROM contents from adapter into priv->eeprom
1565 * NOTE: This routine uses the non-debug IO access functions.
1567 int iwl3945_eeprom_init(struct iwl3945_priv
*priv
)
1569 u16
*e
= (u16
*)&priv
->eeprom
;
1570 u32 gp
= iwl3945_read32(priv
, CSR_EEPROM_GP
);
1572 int sz
= sizeof(priv
->eeprom
);
1577 /* The EEPROM structure has several padding buffers within it
1578 * and when adding new EEPROM maps is subject to programmer errors
1579 * which may be very difficult to identify without explicitly
1580 * checking the resulting size of the eeprom map. */
1581 BUILD_BUG_ON(sizeof(priv
->eeprom
) != IWL_EEPROM_IMAGE_SIZE
);
1583 if ((gp
& CSR_EEPROM_GP_VALID_MSK
) == CSR_EEPROM_GP_BAD_SIGNATURE
) {
1584 IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp
);
1588 /* Make sure driver (instead of uCode) is allowed to read EEPROM */
1589 rc
= iwl3945_eeprom_acquire_semaphore(priv
);
1591 IWL_ERROR("Failed to acquire EEPROM semaphore.\n");
1595 /* eeprom is an array of 16bit values */
1596 for (addr
= 0; addr
< sz
; addr
+= sizeof(u16
)) {
1597 _iwl3945_write32(priv
, CSR_EEPROM_REG
, addr
<< 1);
1598 _iwl3945_clear_bit(priv
, CSR_EEPROM_REG
, CSR_EEPROM_REG_BIT_CMD
);
1600 for (i
= 0; i
< IWL_EEPROM_ACCESS_TIMEOUT
;
1601 i
+= IWL_EEPROM_ACCESS_DELAY
) {
1602 r
= _iwl3945_read_direct32(priv
, CSR_EEPROM_REG
);
1603 if (r
& CSR_EEPROM_REG_READ_VALID_MSK
)
1605 udelay(IWL_EEPROM_ACCESS_DELAY
);
1608 if (!(r
& CSR_EEPROM_REG_READ_VALID_MSK
)) {
1609 IWL_ERROR("Time out reading EEPROM[%d]", addr
);
1612 e
[addr
/ 2] = le16_to_cpu((__force __le16
)(r
>> 16));
1618 static void iwl3945_unset_hw_setting(struct iwl3945_priv
*priv
)
1620 if (priv
->hw_setting
.shared_virt
)
1621 pci_free_consistent(priv
->pci_dev
,
1622 sizeof(struct iwl3945_shared
),
1623 priv
->hw_setting
.shared_virt
,
1624 priv
->hw_setting
.shared_phys
);
1628 * iwl3945_supported_rate_to_ie - fill in the supported rate in IE field
1630 * return : set the bit for each supported rate insert in ie
1632 static u16
iwl3945_supported_rate_to_ie(u8
*ie
, u16 supported_rate
,
1633 u16 basic_rate
, int *left
)
1635 u16 ret_rates
= 0, bit
;
1640 for (bit
= 1, i
= 0; i
< IWL_RATE_COUNT
; i
++, bit
<<= 1) {
1641 if (bit
& supported_rate
) {
1643 rates
[*cnt
] = iwl3945_rates
[i
].ieee
|
1644 ((bit
& basic_rate
) ? 0x80 : 0x00);
1648 (*cnt
>= IWL_SUPPORTED_RATES_IE_LEN
))
1657 * iwl3945_fill_probe_req - fill in all required fields and IE for probe request
1659 static u16
iwl3945_fill_probe_req(struct iwl3945_priv
*priv
,
1660 struct ieee80211_mgmt
*frame
,
1661 int left
, int is_direct
)
1665 u16 active_rates
, ret_rates
, cck_rates
;
1667 /* Make sure there is enough space for the probe request,
1668 * two mandatory IEs and the data */
1674 frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
1675 memcpy(frame
->da
, iwl3945_broadcast_addr
, ETH_ALEN
);
1676 memcpy(frame
->sa
, priv
->mac_addr
, ETH_ALEN
);
1677 memcpy(frame
->bssid
, iwl3945_broadcast_addr
, ETH_ALEN
);
1678 frame
->seq_ctrl
= 0;
1680 /* fill in our indirect SSID IE */
1687 pos
= &(frame
->u
.probe_req
.variable
[0]);
1688 *pos
++ = WLAN_EID_SSID
;
1691 /* fill in our direct SSID IE... */
1694 left
-= 2 + priv
->essid_len
;
1697 /* ... fill it in... */
1698 *pos
++ = WLAN_EID_SSID
;
1699 *pos
++ = priv
->essid_len
;
1700 memcpy(pos
, priv
->essid
, priv
->essid_len
);
1701 pos
+= priv
->essid_len
;
1702 len
+= 2 + priv
->essid_len
;
1705 /* fill in supported rate */
1711 /* ... fill it in... */
1712 *pos
++ = WLAN_EID_SUPP_RATES
;
1715 priv
->active_rate
= priv
->rates_mask
;
1716 active_rates
= priv
->active_rate
;
1717 priv
->active_rate_basic
= priv
->rates_mask
& IWL_BASIC_RATES_MASK
;
1719 cck_rates
= IWL_CCK_RATES_MASK
& active_rates
;
1720 ret_rates
= iwl3945_supported_rate_to_ie(pos
, cck_rates
,
1721 priv
->active_rate_basic
, &left
);
1722 active_rates
&= ~ret_rates
;
1724 ret_rates
= iwl3945_supported_rate_to_ie(pos
, active_rates
,
1725 priv
->active_rate_basic
, &left
);
1726 active_rates
&= ~ret_rates
;
1730 if (active_rates
== 0)
1733 /* fill in supported extended rate */
1738 /* ... fill it in... */
1739 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
1741 iwl3945_supported_rate_to_ie(pos
, active_rates
,
1742 priv
->active_rate_basic
, &left
);
1753 static int iwl3945_send_qos_params_command(struct iwl3945_priv
*priv
,
1754 struct iwl3945_qosparam_cmd
*qos
)
1757 return iwl3945_send_cmd_pdu(priv
, REPLY_QOS_PARAM
,
1758 sizeof(struct iwl3945_qosparam_cmd
), qos
);
1761 static void iwl3945_reset_qos(struct iwl3945_priv
*priv
)
1767 unsigned long flags
;
1770 spin_lock_irqsave(&priv
->lock
, flags
);
1771 priv
->qos_data
.qos_active
= 0;
1773 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) {
1774 if (priv
->qos_data
.qos_enable
)
1775 priv
->qos_data
.qos_active
= 1;
1776 if (!(priv
->active_rate
& 0xfff0)) {
1780 } else if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
1781 if (priv
->qos_data
.qos_enable
)
1782 priv
->qos_data
.qos_active
= 1;
1783 } else if (!(priv
->staging_rxon
.flags
& RXON_FLG_SHORT_SLOT_MSK
)) {
1788 if (priv
->qos_data
.qos_active
)
1791 priv
->qos_data
.def_qos_parm
.ac
[0].cw_min
= cpu_to_le16(cw_min
);
1792 priv
->qos_data
.def_qos_parm
.ac
[0].cw_max
= cpu_to_le16(cw_max
);
1793 priv
->qos_data
.def_qos_parm
.ac
[0].aifsn
= aifs
;
1794 priv
->qos_data
.def_qos_parm
.ac
[0].edca_txop
= 0;
1795 priv
->qos_data
.def_qos_parm
.ac
[0].reserved1
= 0;
1797 if (priv
->qos_data
.qos_active
) {
1799 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_min
= cpu_to_le16(cw_min
);
1800 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_max
= cpu_to_le16(cw_max
);
1801 priv
->qos_data
.def_qos_parm
.ac
[i
].aifsn
= 7;
1802 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
= 0;
1803 priv
->qos_data
.def_qos_parm
.ac
[i
].reserved1
= 0;
1806 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_min
=
1807 cpu_to_le16((cw_min
+ 1) / 2 - 1);
1808 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_max
=
1809 cpu_to_le16(cw_max
);
1810 priv
->qos_data
.def_qos_parm
.ac
[i
].aifsn
= 2;
1812 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
=
1815 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
=
1817 priv
->qos_data
.def_qos_parm
.ac
[i
].reserved1
= 0;
1820 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_min
=
1821 cpu_to_le16((cw_min
+ 1) / 4 - 1);
1822 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_max
=
1823 cpu_to_le16((cw_max
+ 1) / 2 - 1);
1824 priv
->qos_data
.def_qos_parm
.ac
[i
].aifsn
= 2;
1825 priv
->qos_data
.def_qos_parm
.ac
[i
].reserved1
= 0;
1827 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
=
1830 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
=
1833 for (i
= 1; i
< 4; i
++) {
1834 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_min
=
1835 cpu_to_le16(cw_min
);
1836 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_max
=
1837 cpu_to_le16(cw_max
);
1838 priv
->qos_data
.def_qos_parm
.ac
[i
].aifsn
= aifs
;
1839 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
= 0;
1840 priv
->qos_data
.def_qos_parm
.ac
[i
].reserved1
= 0;
1843 IWL_DEBUG_QOS("set QoS to default \n");
1845 spin_unlock_irqrestore(&priv
->lock
, flags
);
1848 static void iwl3945_activate_qos(struct iwl3945_priv
*priv
, u8 force
)
1850 unsigned long flags
;
1852 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
1855 if (!priv
->qos_data
.qos_enable
)
1858 spin_lock_irqsave(&priv
->lock
, flags
);
1859 priv
->qos_data
.def_qos_parm
.qos_flags
= 0;
1861 if (priv
->qos_data
.qos_cap
.q_AP
.queue_request
&&
1862 !priv
->qos_data
.qos_cap
.q_AP
.txop_request
)
1863 priv
->qos_data
.def_qos_parm
.qos_flags
|=
1864 QOS_PARAM_FLG_TXOP_TYPE_MSK
;
1866 if (priv
->qos_data
.qos_active
)
1867 priv
->qos_data
.def_qos_parm
.qos_flags
|=
1868 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
1870 spin_unlock_irqrestore(&priv
->lock
, flags
);
1872 if (force
|| iwl3945_is_associated(priv
)) {
1873 IWL_DEBUG_QOS("send QoS cmd with Qos active %d \n",
1874 priv
->qos_data
.qos_active
);
1876 iwl3945_send_qos_params_command(priv
,
1877 &(priv
->qos_data
.def_qos_parm
));
1882 * Power management (not Tx power!) functions
1884 #define MSEC_TO_USEC 1024
1886 #define NOSLP __constant_cpu_to_le32(0)
1887 #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK
1888 #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
1889 #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
1890 __constant_cpu_to_le32(X1), \
1891 __constant_cpu_to_le32(X2), \
1892 __constant_cpu_to_le32(X3), \
1893 __constant_cpu_to_le32(X4)}
1896 /* default power management (not Tx power) table values */
1898 static struct iwl3945_power_vec_entry range_0
[IWL_POWER_AC
] = {
1899 {{NOSLP
, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1900 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
1901 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
1902 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
1903 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
1904 {{SLP
, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
1908 static struct iwl3945_power_vec_entry range_1
[IWL_POWER_AC
] = {
1909 {{NOSLP
, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1910 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
1911 SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
1912 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
1913 SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
1914 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
1915 SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
1916 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
1917 {{SLP
, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
1918 SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
1921 int iwl3945_power_init_handle(struct iwl3945_priv
*priv
)
1924 struct iwl3945_power_mgr
*pow_data
;
1925 int size
= sizeof(struct iwl3945_power_vec_entry
) * IWL_POWER_AC
;
1928 IWL_DEBUG_POWER("Initialize power \n");
1930 pow_data
= &(priv
->power_data
);
1932 memset(pow_data
, 0, sizeof(*pow_data
));
1934 pow_data
->active_index
= IWL_POWER_RANGE_0
;
1935 pow_data
->dtim_val
= 0xffff;
1937 memcpy(&pow_data
->pwr_range_0
[0], &range_0
[0], size
);
1938 memcpy(&pow_data
->pwr_range_1
[0], &range_1
[0], size
);
1940 rc
= pci_read_config_word(priv
->pci_dev
, PCI_LINK_CTRL
, &pci_pm
);
1944 struct iwl3945_powertable_cmd
*cmd
;
1946 IWL_DEBUG_POWER("adjust power command flags\n");
1948 for (i
= 0; i
< IWL_POWER_AC
; i
++) {
1949 cmd
= &pow_data
->pwr_range_0
[i
].cmd
;
1952 cmd
->flags
&= ~IWL_POWER_PCI_PM_MSK
;
1954 cmd
->flags
|= IWL_POWER_PCI_PM_MSK
;
1960 static int iwl3945_update_power_cmd(struct iwl3945_priv
*priv
,
1961 struct iwl3945_powertable_cmd
*cmd
, u32 mode
)
1966 struct iwl3945_power_vec_entry
*range
;
1968 struct iwl3945_power_mgr
*pow_data
;
1970 if (mode
> IWL_POWER_INDEX_5
) {
1971 IWL_DEBUG_POWER("Error invalid power mode \n");
1974 pow_data
= &(priv
->power_data
);
1976 if (pow_data
->active_index
== IWL_POWER_RANGE_0
)
1977 range
= &pow_data
->pwr_range_0
[0];
1979 range
= &pow_data
->pwr_range_1
[1];
1981 memcpy(cmd
, &range
[mode
].cmd
, sizeof(struct iwl3945_powertable_cmd
));
1983 #ifdef IWL_MAC80211_DISABLE
1984 if (priv
->assoc_network
!= NULL
) {
1985 unsigned long flags
;
1987 period
= priv
->assoc_network
->tim
.tim_period
;
1989 #endif /*IWL_MAC80211_DISABLE */
1990 skip
= range
[mode
].no_dtim
;
1999 cmd
->flags
&= ~IWL_POWER_SLEEP_OVER_DTIM_MSK
;
2001 __le32 slp_itrvl
= cmd
->sleep_interval
[IWL_POWER_VEC_SIZE
- 1];
2002 max_sleep
= (le32_to_cpu(slp_itrvl
) / period
) * period
;
2003 cmd
->flags
|= IWL_POWER_SLEEP_OVER_DTIM_MSK
;
2006 for (i
= 0; i
< IWL_POWER_VEC_SIZE
; i
++) {
2007 if (le32_to_cpu(cmd
->sleep_interval
[i
]) > max_sleep
)
2008 cmd
->sleep_interval
[i
] = cpu_to_le32(max_sleep
);
2011 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd
->flags
);
2012 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd
->tx_data_timeout
));
2013 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd
->rx_data_timeout
));
2014 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
2015 le32_to_cpu(cmd
->sleep_interval
[0]),
2016 le32_to_cpu(cmd
->sleep_interval
[1]),
2017 le32_to_cpu(cmd
->sleep_interval
[2]),
2018 le32_to_cpu(cmd
->sleep_interval
[3]),
2019 le32_to_cpu(cmd
->sleep_interval
[4]));
2024 static int iwl3945_send_power_mode(struct iwl3945_priv
*priv
, u32 mode
)
2026 u32
uninitialized_var(final_mode
);
2028 struct iwl3945_powertable_cmd cmd
;
2030 /* If on battery, set to 3,
2031 * if plugged into AC power, set to CAM ("continuously aware mode"),
2032 * else user level */
2034 case IWL_POWER_BATTERY
:
2035 final_mode
= IWL_POWER_INDEX_3
;
2038 final_mode
= IWL_POWER_MODE_CAM
;
2045 iwl3945_update_power_cmd(priv
, &cmd
, final_mode
);
2047 rc
= iwl3945_send_cmd_pdu(priv
, POWER_TABLE_CMD
, sizeof(cmd
), &cmd
);
2049 if (final_mode
== IWL_POWER_MODE_CAM
)
2050 clear_bit(STATUS_POWER_PMI
, &priv
->status
);
2052 set_bit(STATUS_POWER_PMI
, &priv
->status
);
2057 int iwl3945_is_network_packet(struct iwl3945_priv
*priv
, struct ieee80211_hdr
*header
)
2059 /* Filter incoming packets to determine if they are targeted toward
2060 * this network, discarding packets coming from ourselves */
2061 switch (priv
->iw_mode
) {
2062 case IEEE80211_IF_TYPE_IBSS
: /* Header: Dest. | Source | BSSID */
2063 /* packets from our adapter are dropped (echo) */
2064 if (!compare_ether_addr(header
->addr2
, priv
->mac_addr
))
2066 /* {broad,multi}cast packets to our IBSS go through */
2067 if (is_multicast_ether_addr(header
->addr1
))
2068 return !compare_ether_addr(header
->addr3
, priv
->bssid
);
2069 /* packets to our adapter go through */
2070 return !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
2071 case IEEE80211_IF_TYPE_STA
: /* Header: Dest. | AP{BSSID} | Source */
2072 /* packets from our adapter are dropped (echo) */
2073 if (!compare_ether_addr(header
->addr3
, priv
->mac_addr
))
2075 /* {broad,multi}cast packets to our BSS go through */
2076 if (is_multicast_ether_addr(header
->addr1
))
2077 return !compare_ether_addr(header
->addr2
, priv
->bssid
);
2078 /* packets to our adapter go through */
2079 return !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
2085 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
2087 static const char *iwl3945_get_tx_fail_reason(u32 status
)
2089 switch (status
& TX_STATUS_MSK
) {
2090 case TX_STATUS_SUCCESS
:
2092 TX_STATUS_ENTRY(SHORT_LIMIT
);
2093 TX_STATUS_ENTRY(LONG_LIMIT
);
2094 TX_STATUS_ENTRY(FIFO_UNDERRUN
);
2095 TX_STATUS_ENTRY(MGMNT_ABORT
);
2096 TX_STATUS_ENTRY(NEXT_FRAG
);
2097 TX_STATUS_ENTRY(LIFE_EXPIRE
);
2098 TX_STATUS_ENTRY(DEST_PS
);
2099 TX_STATUS_ENTRY(ABORTED
);
2100 TX_STATUS_ENTRY(BT_RETRY
);
2101 TX_STATUS_ENTRY(STA_INVALID
);
2102 TX_STATUS_ENTRY(FRAG_DROPPED
);
2103 TX_STATUS_ENTRY(TID_DISABLE
);
2104 TX_STATUS_ENTRY(FRAME_FLUSHED
);
2105 TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL
);
2106 TX_STATUS_ENTRY(TX_LOCKED
);
2107 TX_STATUS_ENTRY(NO_BEACON_ON_RADAR
);
2114 * iwl3945_scan_cancel - Cancel any currently executing HW scan
2116 * NOTE: priv->mutex is not required before calling this function
2118 static int iwl3945_scan_cancel(struct iwl3945_priv
*priv
)
2120 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
2121 clear_bit(STATUS_SCANNING
, &priv
->status
);
2125 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
2126 if (!test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
2127 IWL_DEBUG_SCAN("Queuing scan abort.\n");
2128 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
2129 queue_work(priv
->workqueue
, &priv
->abort_scan
);
2132 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
2134 return test_bit(STATUS_SCANNING
, &priv
->status
);
2141 * iwl3945_scan_cancel_timeout - Cancel any currently executing HW scan
2142 * @ms: amount of time to wait (in milliseconds) for scan to abort
2144 * NOTE: priv->mutex must be held before calling this function
2146 static int iwl3945_scan_cancel_timeout(struct iwl3945_priv
*priv
, unsigned long ms
)
2148 unsigned long now
= jiffies
;
2151 ret
= iwl3945_scan_cancel(priv
);
2153 mutex_unlock(&priv
->mutex
);
2154 while (!time_after(jiffies
, now
+ msecs_to_jiffies(ms
)) &&
2155 test_bit(STATUS_SCANNING
, &priv
->status
))
2157 mutex_lock(&priv
->mutex
);
2159 return test_bit(STATUS_SCANNING
, &priv
->status
);
2165 static void iwl3945_sequence_reset(struct iwl3945_priv
*priv
)
2167 /* Reset ieee stats */
2169 /* We don't reset the net_device_stats (ieee->stats) on
2172 priv
->last_seq_num
= -1;
2173 priv
->last_frag_num
= -1;
2174 priv
->last_packet_time
= 0;
2176 iwl3945_scan_cancel(priv
);
2179 #define MAX_UCODE_BEACON_INTERVAL 1024
2180 #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
2182 static __le16
iwl3945_adjust_beacon_interval(u16 beacon_val
)
2185 u16 beacon_factor
= 0;
2188 (beacon_val
+ MAX_UCODE_BEACON_INTERVAL
)
2189 / MAX_UCODE_BEACON_INTERVAL
;
2190 new_val
= beacon_val
/ beacon_factor
;
2192 return cpu_to_le16(new_val
);
2195 static void iwl3945_setup_rxon_timing(struct iwl3945_priv
*priv
)
2197 u64 interval_tm_unit
;
2199 unsigned long flags
;
2200 struct ieee80211_conf
*conf
= NULL
;
2203 conf
= ieee80211_get_hw_conf(priv
->hw
);
2205 spin_lock_irqsave(&priv
->lock
, flags
);
2206 priv
->rxon_timing
.timestamp
.dw
[1] = cpu_to_le32(priv
->timestamp1
);
2207 priv
->rxon_timing
.timestamp
.dw
[0] = cpu_to_le32(priv
->timestamp0
);
2209 priv
->rxon_timing
.listen_interval
= INTEL_CONN_LISTEN_INTERVAL
;
2211 tsf
= priv
->timestamp1
;
2212 tsf
= ((tsf
<< 32) | priv
->timestamp0
);
2214 beacon_int
= priv
->beacon_int
;
2215 spin_unlock_irqrestore(&priv
->lock
, flags
);
2217 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) {
2218 if (beacon_int
== 0) {
2219 priv
->rxon_timing
.beacon_interval
= cpu_to_le16(100);
2220 priv
->rxon_timing
.beacon_init_val
= cpu_to_le32(102400);
2222 priv
->rxon_timing
.beacon_interval
=
2223 cpu_to_le16(beacon_int
);
2224 priv
->rxon_timing
.beacon_interval
=
2225 iwl3945_adjust_beacon_interval(
2226 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2229 priv
->rxon_timing
.atim_window
= 0;
2231 priv
->rxon_timing
.beacon_interval
=
2232 iwl3945_adjust_beacon_interval(conf
->beacon_int
);
2233 /* TODO: we need to get atim_window from upper stack
2234 * for now we set to 0 */
2235 priv
->rxon_timing
.atim_window
= 0;
2239 (le16_to_cpu(priv
->rxon_timing
.beacon_interval
) * 1024);
2240 result
= do_div(tsf
, interval_tm_unit
);
2241 priv
->rxon_timing
.beacon_init_val
=
2242 cpu_to_le32((u32
) ((u64
) interval_tm_unit
- result
));
2245 ("beacon interval %d beacon timer %d beacon tim %d\n",
2246 le16_to_cpu(priv
->rxon_timing
.beacon_interval
),
2247 le32_to_cpu(priv
->rxon_timing
.beacon_init_val
),
2248 le16_to_cpu(priv
->rxon_timing
.atim_window
));
2251 static int iwl3945_scan_initiate(struct iwl3945_priv
*priv
)
2253 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
2254 IWL_ERROR("APs don't scan.\n");
2258 if (!iwl3945_is_ready_rf(priv
)) {
2259 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
2263 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
2264 IWL_DEBUG_SCAN("Scan already in progress.\n");
2268 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
2269 IWL_DEBUG_SCAN("Scan request while abort pending. "
2274 IWL_DEBUG_INFO("Starting scan...\n");
2275 priv
->scan_bands
= 2;
2276 set_bit(STATUS_SCANNING
, &priv
->status
);
2277 priv
->scan_start
= jiffies
;
2278 priv
->scan_pass_start
= priv
->scan_start
;
2280 queue_work(priv
->workqueue
, &priv
->request_scan
);
2285 static int iwl3945_set_rxon_hwcrypto(struct iwl3945_priv
*priv
, int hw_decrypt
)
2287 struct iwl3945_rxon_cmd
*rxon
= &priv
->staging_rxon
;
2290 rxon
->filter_flags
&= ~RXON_FILTER_DIS_DECRYPT_MSK
;
2292 rxon
->filter_flags
|= RXON_FILTER_DIS_DECRYPT_MSK
;
2297 static void iwl3945_set_flags_for_phymode(struct iwl3945_priv
*priv
,
2298 enum ieee80211_band band
)
2300 if (band
== IEEE80211_BAND_5GHZ
) {
2301 priv
->staging_rxon
.flags
&=
2302 ~(RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
2303 | RXON_FLG_CCK_MSK
);
2304 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
2306 /* Copied from iwl3945_bg_post_associate() */
2307 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
2308 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
2310 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
2312 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
2313 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
2315 priv
->staging_rxon
.flags
|= RXON_FLG_BAND_24G_MSK
;
2316 priv
->staging_rxon
.flags
|= RXON_FLG_AUTO_DETECT_MSK
;
2317 priv
->staging_rxon
.flags
&= ~RXON_FLG_CCK_MSK
;
2322 * initialize rxon structure with default values from eeprom
2324 static void iwl3945_connection_init_rx_config(struct iwl3945_priv
*priv
)
2326 const struct iwl3945_channel_info
*ch_info
;
2328 memset(&priv
->staging_rxon
, 0, sizeof(priv
->staging_rxon
));
2330 switch (priv
->iw_mode
) {
2331 case IEEE80211_IF_TYPE_AP
:
2332 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_AP
;
2335 case IEEE80211_IF_TYPE_STA
:
2336 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_ESS
;
2337 priv
->staging_rxon
.filter_flags
= RXON_FILTER_ACCEPT_GRP_MSK
;
2340 case IEEE80211_IF_TYPE_IBSS
:
2341 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_IBSS
;
2342 priv
->staging_rxon
.flags
= RXON_FLG_SHORT_PREAMBLE_MSK
;
2343 priv
->staging_rxon
.filter_flags
= RXON_FILTER_BCON_AWARE_MSK
|
2344 RXON_FILTER_ACCEPT_GRP_MSK
;
2347 case IEEE80211_IF_TYPE_MNTR
:
2348 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_SNIFFER
;
2349 priv
->staging_rxon
.filter_flags
= RXON_FILTER_PROMISC_MSK
|
2350 RXON_FILTER_CTL2HOST_MSK
| RXON_FILTER_ACCEPT_GRP_MSK
;
2355 /* TODO: Figure out when short_preamble would be set and cache from
2357 if (!hw_to_local(priv
->hw
)->short_preamble
)
2358 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
2360 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
2363 ch_info
= iwl3945_get_channel_info(priv
, priv
->band
,
2364 le16_to_cpu(priv
->staging_rxon
.channel
));
2367 ch_info
= &priv
->channel_info
[0];
2370 * in some case A channels are all non IBSS
2371 * in this case force B/G channel
2373 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) &&
2374 !(is_channel_ibss(ch_info
)))
2375 ch_info
= &priv
->channel_info
[0];
2377 priv
->staging_rxon
.channel
= cpu_to_le16(ch_info
->channel
);
2378 if (is_channel_a_band(ch_info
))
2379 priv
->band
= IEEE80211_BAND_5GHZ
;
2381 priv
->band
= IEEE80211_BAND_2GHZ
;
2383 iwl3945_set_flags_for_phymode(priv
, priv
->band
);
2385 priv
->staging_rxon
.ofdm_basic_rates
=
2386 (IWL_OFDM_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
2387 priv
->staging_rxon
.cck_basic_rates
=
2388 (IWL_CCK_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
2391 static int iwl3945_set_mode(struct iwl3945_priv
*priv
, int mode
)
2393 if (mode
== IEEE80211_IF_TYPE_IBSS
) {
2394 const struct iwl3945_channel_info
*ch_info
;
2396 ch_info
= iwl3945_get_channel_info(priv
,
2398 le16_to_cpu(priv
->staging_rxon
.channel
));
2400 if (!ch_info
|| !is_channel_ibss(ch_info
)) {
2401 IWL_ERROR("channel %d not IBSS channel\n",
2402 le16_to_cpu(priv
->staging_rxon
.channel
));
2407 priv
->iw_mode
= mode
;
2409 iwl3945_connection_init_rx_config(priv
);
2410 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
2412 iwl3945_clear_stations_table(priv
);
2414 /* dont commit rxon if rf-kill is on*/
2415 if (!iwl3945_is_ready_rf(priv
))
2418 cancel_delayed_work(&priv
->scan_check
);
2419 if (iwl3945_scan_cancel_timeout(priv
, 100)) {
2420 IWL_WARNING("Aborted scan still in progress after 100ms\n");
2421 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2425 iwl3945_commit_rxon(priv
);
2430 static void iwl3945_build_tx_cmd_hwcrypto(struct iwl3945_priv
*priv
,
2431 struct ieee80211_tx_control
*ctl
,
2432 struct iwl3945_cmd
*cmd
,
2433 struct sk_buff
*skb_frag
,
2436 struct iwl3945_hw_key
*keyinfo
= &priv
->stations
[ctl
->key_idx
].keyinfo
;
2438 switch (keyinfo
->alg
) {
2440 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_CCM
;
2441 memcpy(cmd
->cmd
.tx
.key
, keyinfo
->key
, keyinfo
->keylen
);
2442 IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
2447 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_TKIP
;
2450 memcpy(cmd
->cmd
.tx
.tkip_mic
.byte
, skb_frag
->tail
- 8,
2453 memset(cmd
->cmd
.tx
.tkip_mic
.byte
, 0, 8);
2458 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_WEP
|
2459 (ctl
->key_idx
& TX_CMD_SEC_MSK
) << TX_CMD_SEC_SHIFT
;
2461 if (keyinfo
->keylen
== 13)
2462 cmd
->cmd
.tx
.sec_ctl
|= TX_CMD_SEC_KEY128
;
2464 memcpy(&cmd
->cmd
.tx
.key
[3], keyinfo
->key
, keyinfo
->keylen
);
2466 IWL_DEBUG_TX("Configuring packet for WEP encryption "
2467 "with key %d\n", ctl
->key_idx
);
2471 printk(KERN_ERR
"Unknown encode alg %d\n", keyinfo
->alg
);
2477 * handle build REPLY_TX command notification.
2479 static void iwl3945_build_tx_cmd_basic(struct iwl3945_priv
*priv
,
2480 struct iwl3945_cmd
*cmd
,
2481 struct ieee80211_tx_control
*ctrl
,
2482 struct ieee80211_hdr
*hdr
,
2483 int is_unicast
, u8 std_id
)
2486 u16 fc
= le16_to_cpu(hdr
->frame_control
);
2487 __le32 tx_flags
= cmd
->cmd
.tx
.tx_flags
;
2489 cmd
->cmd
.tx
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
2490 if (!(ctrl
->flags
& IEEE80211_TXCTL_NO_ACK
)) {
2491 tx_flags
|= TX_CMD_FLG_ACK_MSK
;
2492 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
)
2493 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2494 if (ieee80211_is_probe_response(fc
) &&
2495 !(le16_to_cpu(hdr
->seq_ctrl
) & 0xf))
2496 tx_flags
|= TX_CMD_FLG_TSF_MSK
;
2498 tx_flags
&= (~TX_CMD_FLG_ACK_MSK
);
2499 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2502 cmd
->cmd
.tx
.sta_id
= std_id
;
2503 if (ieee80211_get_morefrag(hdr
))
2504 tx_flags
|= TX_CMD_FLG_MORE_FRAG_MSK
;
2506 qc
= ieee80211_get_qos_ctrl(hdr
);
2508 cmd
->cmd
.tx
.tid_tspec
= (u8
) (le16_to_cpu(*qc
) & 0xf);
2509 tx_flags
&= ~TX_CMD_FLG_SEQ_CTL_MSK
;
2511 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2513 if (ctrl
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
) {
2514 tx_flags
|= TX_CMD_FLG_RTS_MSK
;
2515 tx_flags
&= ~TX_CMD_FLG_CTS_MSK
;
2516 } else if (ctrl
->flags
& IEEE80211_TXCTL_USE_CTS_PROTECT
) {
2517 tx_flags
&= ~TX_CMD_FLG_RTS_MSK
;
2518 tx_flags
|= TX_CMD_FLG_CTS_MSK
;
2521 if ((tx_flags
& TX_CMD_FLG_RTS_MSK
) || (tx_flags
& TX_CMD_FLG_CTS_MSK
))
2522 tx_flags
|= TX_CMD_FLG_FULL_TXOP_PROT_MSK
;
2524 tx_flags
&= ~(TX_CMD_FLG_ANT_SEL_MSK
);
2525 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
2526 if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_ASSOC_REQ
||
2527 (fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_REASSOC_REQ
)
2528 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= cpu_to_le16(3);
2530 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= cpu_to_le16(2);
2532 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= 0;
2534 cmd
->cmd
.tx
.driver_txop
= 0;
2535 cmd
->cmd
.tx
.tx_flags
= tx_flags
;
2536 cmd
->cmd
.tx
.next_frame_len
= 0;
2540 * iwl3945_get_sta_id - Find station's index within station table
2542 static int iwl3945_get_sta_id(struct iwl3945_priv
*priv
, struct ieee80211_hdr
*hdr
)
2545 u16 fc
= le16_to_cpu(hdr
->frame_control
);
2547 /* If this frame is broadcast or management, use broadcast station id */
2548 if (((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
) ||
2549 is_multicast_ether_addr(hdr
->addr1
))
2550 return priv
->hw_setting
.bcast_sta_id
;
2552 switch (priv
->iw_mode
) {
2554 /* If we are a client station in a BSS network, use the special
2555 * AP station entry (that's the only station we communicate with) */
2556 case IEEE80211_IF_TYPE_STA
:
2559 /* If we are an AP, then find the station, or use BCAST */
2560 case IEEE80211_IF_TYPE_AP
:
2561 sta_id
= iwl3945_hw_find_station(priv
, hdr
->addr1
);
2562 if (sta_id
!= IWL_INVALID_STATION
)
2564 return priv
->hw_setting
.bcast_sta_id
;
2566 /* If this frame is going out to an IBSS network, find the station,
2567 * or create a new station table entry */
2568 case IEEE80211_IF_TYPE_IBSS
: {
2569 DECLARE_MAC_BUF(mac
);
2571 /* Create new station table entry */
2572 sta_id
= iwl3945_hw_find_station(priv
, hdr
->addr1
);
2573 if (sta_id
!= IWL_INVALID_STATION
)
2576 sta_id
= iwl3945_add_station(priv
, hdr
->addr1
, 0, CMD_ASYNC
);
2578 if (sta_id
!= IWL_INVALID_STATION
)
2581 IWL_DEBUG_DROP("Station %s not in station map. "
2582 "Defaulting to broadcast...\n",
2583 print_mac(mac
, hdr
->addr1
));
2584 iwl3945_print_hex_dump(IWL_DL_DROP
, (u8
*) hdr
, sizeof(*hdr
));
2585 return priv
->hw_setting
.bcast_sta_id
;
2588 IWL_WARNING("Unknown mode of operation: %d", priv
->iw_mode
);
2589 return priv
->hw_setting
.bcast_sta_id
;
2594 * start REPLY_TX command process
2596 static int iwl3945_tx_skb(struct iwl3945_priv
*priv
,
2597 struct sk_buff
*skb
, struct ieee80211_tx_control
*ctl
)
2599 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2600 struct iwl3945_tfd_frame
*tfd
;
2602 int txq_id
= ctl
->queue
;
2603 struct iwl3945_tx_queue
*txq
= NULL
;
2604 struct iwl3945_queue
*q
= NULL
;
2605 dma_addr_t phys_addr
;
2606 dma_addr_t txcmd_phys
;
2607 struct iwl3945_cmd
*out_cmd
= NULL
;
2608 u16 len
, idx
, len_org
;
2609 u8 id
, hdr_len
, unicast
;
2614 u8 wait_write_ptr
= 0;
2615 unsigned long flags
;
2618 spin_lock_irqsave(&priv
->lock
, flags
);
2619 if (iwl3945_is_rfkill(priv
)) {
2620 IWL_DEBUG_DROP("Dropping - RF KILL\n");
2625 IWL_DEBUG_DROP("Dropping - !priv->vif\n");
2629 if ((ctl
->tx_rate
->hw_value
& 0xFF) == IWL_INVALID_RATE
) {
2630 IWL_ERROR("ERROR: No TX rate available.\n");
2634 unicast
= !is_multicast_ether_addr(hdr
->addr1
);
2637 fc
= le16_to_cpu(hdr
->frame_control
);
2639 #ifdef CONFIG_IWL3945_DEBUG
2640 if (ieee80211_is_auth(fc
))
2641 IWL_DEBUG_TX("Sending AUTH frame\n");
2642 else if (ieee80211_is_assoc_request(fc
))
2643 IWL_DEBUG_TX("Sending ASSOC frame\n");
2644 else if (ieee80211_is_reassoc_request(fc
))
2645 IWL_DEBUG_TX("Sending REASSOC frame\n");
2648 /* drop all data frame if we are not associated */
2649 if ((!iwl3945_is_associated(priv
) ||
2650 ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) && !priv
->assoc_id
)) &&
2651 ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
)) {
2652 IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n");
2656 spin_unlock_irqrestore(&priv
->lock
, flags
);
2658 hdr_len
= ieee80211_get_hdrlen(fc
);
2660 /* Find (or create) index into station table for destination station */
2661 sta_id
= iwl3945_get_sta_id(priv
, hdr
);
2662 if (sta_id
== IWL_INVALID_STATION
) {
2663 DECLARE_MAC_BUF(mac
);
2665 IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
2666 print_mac(mac
, hdr
->addr1
));
2670 IWL_DEBUG_RATE("station Id %d\n", sta_id
);
2672 qc
= ieee80211_get_qos_ctrl(hdr
);
2674 u8 tid
= (u8
)(le16_to_cpu(*qc
) & 0xf);
2675 seq_number
= priv
->stations
[sta_id
].tid
[tid
].seq_number
&
2677 hdr
->seq_ctrl
= cpu_to_le16(seq_number
) |
2679 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG
));
2683 /* Descriptor for chosen Tx queue */
2684 txq
= &priv
->txq
[txq_id
];
2687 spin_lock_irqsave(&priv
->lock
, flags
);
2689 /* Set up first empty TFD within this queue's circular TFD buffer */
2690 tfd
= &txq
->bd
[q
->write_ptr
];
2691 memset(tfd
, 0, sizeof(*tfd
));
2692 control_flags
= (u32
*) tfd
;
2693 idx
= get_cmd_index(q
, q
->write_ptr
, 0);
2695 /* Set up driver data for this TFD */
2696 memset(&(txq
->txb
[q
->write_ptr
]), 0, sizeof(struct iwl3945_tx_info
));
2697 txq
->txb
[q
->write_ptr
].skb
[0] = skb
;
2698 memcpy(&(txq
->txb
[q
->write_ptr
].status
.control
),
2699 ctl
, sizeof(struct ieee80211_tx_control
));
2701 /* Init first empty entry in queue's array of Tx/cmd buffers */
2702 out_cmd
= &txq
->cmd
[idx
];
2703 memset(&out_cmd
->hdr
, 0, sizeof(out_cmd
->hdr
));
2704 memset(&out_cmd
->cmd
.tx
, 0, sizeof(out_cmd
->cmd
.tx
));
2707 * Set up the Tx-command (not MAC!) header.
2708 * Store the chosen Tx queue and TFD index within the sequence field;
2709 * after Tx, uCode's Tx response will return this value so driver can
2710 * locate the frame within the tx queue and do post-tx processing.
2712 out_cmd
->hdr
.cmd
= REPLY_TX
;
2713 out_cmd
->hdr
.sequence
= cpu_to_le16((u16
)(QUEUE_TO_SEQ(txq_id
) |
2714 INDEX_TO_SEQ(q
->write_ptr
)));
2716 /* Copy MAC header from skb into command buffer */
2717 memcpy(out_cmd
->cmd
.tx
.hdr
, hdr
, hdr_len
);
2720 * Use the first empty entry in this queue's command buffer array
2721 * to contain the Tx command and MAC header concatenated together
2722 * (payload data will be in another buffer).
2723 * Size of this varies, due to varying MAC header length.
2724 * If end is not dword aligned, we'll have 2 extra bytes at the end
2725 * of the MAC header (device reads on dword boundaries).
2726 * We'll tell device about this padding later.
2728 len
= priv
->hw_setting
.tx_cmd_len
+
2729 sizeof(struct iwl3945_cmd_header
) + hdr_len
;
2732 len
= (len
+ 3) & ~3;
2739 /* Physical address of this Tx command's header (not MAC header!),
2740 * within command buffer array. */
2741 txcmd_phys
= txq
->dma_addr_cmd
+ sizeof(struct iwl3945_cmd
) * idx
+
2742 offsetof(struct iwl3945_cmd
, hdr
);
2744 /* Add buffer containing Tx command and MAC(!) header to TFD's
2746 iwl3945_hw_txq_attach_buf_to_tfd(priv
, tfd
, txcmd_phys
, len
);
2748 if (!(ctl
->flags
& IEEE80211_TXCTL_DO_NOT_ENCRYPT
))
2749 iwl3945_build_tx_cmd_hwcrypto(priv
, ctl
, out_cmd
, skb
, 0);
2751 /* Set up TFD's 2nd entry to point directly to remainder of skb,
2752 * if any (802.11 null frames have no payload). */
2753 len
= skb
->len
- hdr_len
;
2755 phys_addr
= pci_map_single(priv
->pci_dev
, skb
->data
+ hdr_len
,
2756 len
, PCI_DMA_TODEVICE
);
2757 iwl3945_hw_txq_attach_buf_to_tfd(priv
, tfd
, phys_addr
, len
);
2761 /* If there is no payload, then we use only one Tx buffer */
2762 *control_flags
= TFD_CTL_COUNT_SET(1);
2764 /* Else use 2 buffers.
2765 * Tell 3945 about any padding after MAC header */
2766 *control_flags
= TFD_CTL_COUNT_SET(2) |
2767 TFD_CTL_PAD_SET(U32_PAD(len
));
2769 /* Total # bytes to be transmitted */
2770 len
= (u16
)skb
->len
;
2771 out_cmd
->cmd
.tx
.len
= cpu_to_le16(len
);
2773 /* TODO need this for burst mode later on */
2774 iwl3945_build_tx_cmd_basic(priv
, out_cmd
, ctl
, hdr
, unicast
, sta_id
);
2776 /* set is_hcca to 0; it probably will never be implemented */
2777 iwl3945_hw_build_tx_cmd_rate(priv
, out_cmd
, ctl
, hdr
, sta_id
, 0);
2779 out_cmd
->cmd
.tx
.tx_flags
&= ~TX_CMD_FLG_ANT_A_MSK
;
2780 out_cmd
->cmd
.tx
.tx_flags
&= ~TX_CMD_FLG_ANT_B_MSK
;
2782 if (!ieee80211_get_morefrag(hdr
)) {
2783 txq
->need_update
= 1;
2785 u8 tid
= (u8
)(le16_to_cpu(*qc
) & 0xf);
2786 priv
->stations
[sta_id
].tid
[tid
].seq_number
= seq_number
;
2790 txq
->need_update
= 0;
2793 iwl3945_print_hex_dump(IWL_DL_TX
, out_cmd
->cmd
.payload
,
2794 sizeof(out_cmd
->cmd
.tx
));
2796 iwl3945_print_hex_dump(IWL_DL_TX
, (u8
*)out_cmd
->cmd
.tx
.hdr
,
2797 ieee80211_get_hdrlen(fc
));
2799 /* Tell device the write index *just past* this latest filled TFD */
2800 q
->write_ptr
= iwl3945_queue_inc_wrap(q
->write_ptr
, q
->n_bd
);
2801 rc
= iwl3945_tx_queue_update_write_ptr(priv
, txq
);
2802 spin_unlock_irqrestore(&priv
->lock
, flags
);
2807 if ((iwl3945_queue_space(q
) < q
->high_mark
)
2808 && priv
->mac80211_registered
) {
2809 if (wait_write_ptr
) {
2810 spin_lock_irqsave(&priv
->lock
, flags
);
2811 txq
->need_update
= 1;
2812 iwl3945_tx_queue_update_write_ptr(priv
, txq
);
2813 spin_unlock_irqrestore(&priv
->lock
, flags
);
2816 ieee80211_stop_queue(priv
->hw
, ctl
->queue
);
2822 spin_unlock_irqrestore(&priv
->lock
, flags
);
2827 static void iwl3945_set_rate(struct iwl3945_priv
*priv
)
2829 const struct ieee80211_supported_band
*sband
= NULL
;
2830 struct ieee80211_rate
*rate
;
2833 sband
= iwl3945_get_band(priv
, priv
->band
);
2835 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
2839 priv
->active_rate
= 0;
2840 priv
->active_rate_basic
= 0;
2842 IWL_DEBUG_RATE("Setting rates for %s GHz\n",
2843 sband
->band
== IEEE80211_BAND_2GHZ
? "2.4" : "5");
2845 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
2846 rate
= &sband
->bitrates
[i
];
2847 if ((rate
->hw_value
< IWL_RATE_COUNT
) &&
2848 !(rate
->flags
& IEEE80211_CHAN_DISABLED
)) {
2849 IWL_DEBUG_RATE("Adding rate index %d (plcp %d)\n",
2850 rate
->hw_value
, iwl3945_rates
[rate
->hw_value
].plcp
);
2851 priv
->active_rate
|= (1 << rate
->hw_value
);
2855 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
2856 priv
->active_rate
, priv
->active_rate_basic
);
2859 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
2860 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
2863 if (priv
->active_rate_basic
& IWL_CCK_BASIC_RATES_MASK
)
2864 priv
->staging_rxon
.cck_basic_rates
=
2865 ((priv
->active_rate_basic
&
2866 IWL_CCK_RATES_MASK
) >> IWL_FIRST_CCK_RATE
) & 0xF;
2868 priv
->staging_rxon
.cck_basic_rates
=
2869 (IWL_CCK_BASIC_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
2871 if (priv
->active_rate_basic
& IWL_OFDM_BASIC_RATES_MASK
)
2872 priv
->staging_rxon
.ofdm_basic_rates
=
2873 ((priv
->active_rate_basic
&
2874 (IWL_OFDM_BASIC_RATES_MASK
| IWL_RATE_6M_MASK
)) >>
2875 IWL_FIRST_OFDM_RATE
) & 0xFF;
2877 priv
->staging_rxon
.ofdm_basic_rates
=
2878 (IWL_OFDM_BASIC_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
2881 static void iwl3945_radio_kill_sw(struct iwl3945_priv
*priv
, int disable_radio
)
2883 unsigned long flags
;
2885 if (!!disable_radio
== test_bit(STATUS_RF_KILL_SW
, &priv
->status
))
2888 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
2889 disable_radio
? "OFF" : "ON");
2891 if (disable_radio
) {
2892 iwl3945_scan_cancel(priv
);
2893 /* FIXME: This is a workaround for AP */
2894 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
2895 spin_lock_irqsave(&priv
->lock
, flags
);
2896 iwl3945_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
2897 CSR_UCODE_SW_BIT_RFKILL
);
2898 spin_unlock_irqrestore(&priv
->lock
, flags
);
2899 iwl3945_send_card_state(priv
, CARD_STATE_CMD_DISABLE
, 0);
2900 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2905 spin_lock_irqsave(&priv
->lock
, flags
);
2906 iwl3945_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2908 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2909 spin_unlock_irqrestore(&priv
->lock
, flags
);
2914 spin_lock_irqsave(&priv
->lock
, flags
);
2915 iwl3945_read32(priv
, CSR_UCODE_DRV_GP1
);
2916 if (!iwl3945_grab_nic_access(priv
))
2917 iwl3945_release_nic_access(priv
);
2918 spin_unlock_irqrestore(&priv
->lock
, flags
);
2920 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) {
2921 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2922 "disabled by HW switch\n");
2926 queue_work(priv
->workqueue
, &priv
->restart
);
2930 void iwl3945_set_decrypted_flag(struct iwl3945_priv
*priv
, struct sk_buff
*skb
,
2931 u32 decrypt_res
, struct ieee80211_rx_status
*stats
)
2934 le16_to_cpu(((struct ieee80211_hdr
*)skb
->data
)->frame_control
);
2936 if (priv
->active_rxon
.filter_flags
& RXON_FILTER_DIS_DECRYPT_MSK
)
2939 if (!(fc
& IEEE80211_FCTL_PROTECTED
))
2942 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res
);
2943 switch (decrypt_res
& RX_RES_STATUS_SEC_TYPE_MSK
) {
2944 case RX_RES_STATUS_SEC_TYPE_TKIP
:
2945 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2946 RX_RES_STATUS_BAD_ICV_MIC
)
2947 stats
->flag
|= RX_FLAG_MMIC_ERROR
;
2948 case RX_RES_STATUS_SEC_TYPE_WEP
:
2949 case RX_RES_STATUS_SEC_TYPE_CCMP
:
2950 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2951 RX_RES_STATUS_DECRYPT_OK
) {
2952 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
2953 stats
->flag
|= RX_FLAG_DECRYPTED
;
2962 #define IWL_PACKET_RETRY_TIME HZ
2964 int iwl3945_is_duplicate_packet(struct iwl3945_priv
*priv
, struct ieee80211_hdr
*header
)
2966 u16 sc
= le16_to_cpu(header
->seq_ctrl
);
2967 u16 seq
= (sc
& IEEE80211_SCTL_SEQ
) >> 4;
2968 u16 frag
= sc
& IEEE80211_SCTL_FRAG
;
2969 u16
*last_seq
, *last_frag
;
2970 unsigned long *last_time
;
2972 switch (priv
->iw_mode
) {
2973 case IEEE80211_IF_TYPE_IBSS
:{
2974 struct list_head
*p
;
2975 struct iwl3945_ibss_seq
*entry
= NULL
;
2976 u8
*mac
= header
->addr2
;
2977 int index
= mac
[5] & (IWL_IBSS_MAC_HASH_SIZE
- 1);
2979 __list_for_each(p
, &priv
->ibss_mac_hash
[index
]) {
2980 entry
= list_entry(p
, struct iwl3945_ibss_seq
, list
);
2981 if (!compare_ether_addr(entry
->mac
, mac
))
2984 if (p
== &priv
->ibss_mac_hash
[index
]) {
2985 entry
= kzalloc(sizeof(*entry
), GFP_ATOMIC
);
2987 IWL_ERROR("Cannot malloc new mac entry\n");
2990 memcpy(entry
->mac
, mac
, ETH_ALEN
);
2991 entry
->seq_num
= seq
;
2992 entry
->frag_num
= frag
;
2993 entry
->packet_time
= jiffies
;
2994 list_add(&entry
->list
, &priv
->ibss_mac_hash
[index
]);
2997 last_seq
= &entry
->seq_num
;
2998 last_frag
= &entry
->frag_num
;
2999 last_time
= &entry
->packet_time
;
3002 case IEEE80211_IF_TYPE_STA
:
3003 last_seq
= &priv
->last_seq_num
;
3004 last_frag
= &priv
->last_frag_num
;
3005 last_time
= &priv
->last_packet_time
;
3010 if ((*last_seq
== seq
) &&
3011 time_after(*last_time
+ IWL_PACKET_RETRY_TIME
, jiffies
)) {
3012 if (*last_frag
== frag
)
3014 if (*last_frag
+ 1 != frag
)
3015 /* out-of-order fragment */
3021 *last_time
= jiffies
;
3028 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
3030 #include "iwl-spectrum.h"
3032 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
3033 #define BEACON_TIME_MASK_HIGH 0xFF000000
3034 #define TIME_UNIT 1024
3037 * extended beacon time format
3038 * time in usec will be changed into a 32-bit value in 8:24 format
3039 * the high 1 byte is the beacon counts
3040 * the lower 3 bytes is the time in usec within one beacon interval
3043 static u32
iwl3945_usecs_to_beacons(u32 usec
, u32 beacon_interval
)
3047 u32 interval
= beacon_interval
* 1024;
3049 if (!interval
|| !usec
)
3052 quot
= (usec
/ interval
) & (BEACON_TIME_MASK_HIGH
>> 24);
3053 rem
= (usec
% interval
) & BEACON_TIME_MASK_LOW
;
3055 return (quot
<< 24) + rem
;
3058 /* base is usually what we get from ucode with each received frame,
3059 * the same as HW timer counter counting down
3062 static __le32
iwl3945_add_beacon_time(u32 base
, u32 addon
, u32 beacon_interval
)
3064 u32 base_low
= base
& BEACON_TIME_MASK_LOW
;
3065 u32 addon_low
= addon
& BEACON_TIME_MASK_LOW
;
3066 u32 interval
= beacon_interval
* TIME_UNIT
;
3067 u32 res
= (base
& BEACON_TIME_MASK_HIGH
) +
3068 (addon
& BEACON_TIME_MASK_HIGH
);
3070 if (base_low
> addon_low
)
3071 res
+= base_low
- addon_low
;
3072 else if (base_low
< addon_low
) {
3073 res
+= interval
+ base_low
- addon_low
;
3078 return cpu_to_le32(res
);
3081 static int iwl3945_get_measurement(struct iwl3945_priv
*priv
,
3082 struct ieee80211_measurement_params
*params
,
3085 struct iwl3945_spectrum_cmd spectrum
;
3086 struct iwl3945_rx_packet
*res
;
3087 struct iwl3945_host_cmd cmd
= {
3088 .id
= REPLY_SPECTRUM_MEASUREMENT_CMD
,
3089 .data
= (void *)&spectrum
,
3090 .meta
.flags
= CMD_WANT_SKB
,
3092 u32 add_time
= le64_to_cpu(params
->start_time
);
3094 int spectrum_resp_status
;
3095 int duration
= le16_to_cpu(params
->duration
);
3097 if (iwl3945_is_associated(priv
))
3099 iwl3945_usecs_to_beacons(
3100 le64_to_cpu(params
->start_time
) - priv
->last_tsf
,
3101 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
3103 memset(&spectrum
, 0, sizeof(spectrum
));
3105 spectrum
.channel_count
= cpu_to_le16(1);
3107 RXON_FLG_TSF2HOST_MSK
| RXON_FLG_ANT_A_MSK
| RXON_FLG_DIS_DIV_MSK
;
3108 spectrum
.filter_flags
= MEASUREMENT_FILTER_FLAG
;
3109 cmd
.len
= sizeof(spectrum
);
3110 spectrum
.len
= cpu_to_le16(cmd
.len
- sizeof(spectrum
.len
));
3112 if (iwl3945_is_associated(priv
))
3113 spectrum
.start_time
=
3114 iwl3945_add_beacon_time(priv
->last_beacon_time
,
3116 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
3118 spectrum
.start_time
= 0;
3120 spectrum
.channels
[0].duration
= cpu_to_le32(duration
* TIME_UNIT
);
3121 spectrum
.channels
[0].channel
= params
->channel
;
3122 spectrum
.channels
[0].type
= type
;
3123 if (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
3124 spectrum
.flags
|= RXON_FLG_BAND_24G_MSK
|
3125 RXON_FLG_AUTO_DETECT_MSK
| RXON_FLG_TGG_PROTECT_MSK
;
3127 rc
= iwl3945_send_cmd_sync(priv
, &cmd
);
3131 res
= (struct iwl3945_rx_packet
*)cmd
.meta
.u
.skb
->data
;
3132 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
3133 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
3137 spectrum_resp_status
= le16_to_cpu(res
->u
.spectrum
.status
);
3138 switch (spectrum_resp_status
) {
3139 case 0: /* Command will be handled */
3140 if (res
->u
.spectrum
.id
!= 0xff) {
3141 IWL_DEBUG_INFO("Replaced existing measurement: %d\n",
3142 res
->u
.spectrum
.id
);
3143 priv
->measurement_status
&= ~MEASUREMENT_READY
;
3145 priv
->measurement_status
|= MEASUREMENT_ACTIVE
;
3149 case 1: /* Command will not be handled */
3154 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
3160 static void iwl3945_txstatus_to_ieee(struct iwl3945_priv
*priv
,
3161 struct iwl3945_tx_info
*tx_sta
)
3164 tx_sta
->status
.ack_signal
= 0;
3165 tx_sta
->status
.excessive_retries
= 0;
3166 tx_sta
->status
.queue_length
= 0;
3167 tx_sta
->status
.queue_number
= 0;
3170 ieee80211_tx_status_irqsafe(priv
->hw
,
3171 tx_sta
->skb
[0], &(tx_sta
->status
));
3173 ieee80211_tx_status(priv
->hw
,
3174 tx_sta
->skb
[0], &(tx_sta
->status
));
3176 tx_sta
->skb
[0] = NULL
;
3180 * iwl3945_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
3182 * When FW advances 'R' index, all entries between old and new 'R' index
3183 * need to be reclaimed. As result, some free space forms. If there is
3184 * enough free space (> low mark), wake the stack that feeds us.
3186 static int iwl3945_tx_queue_reclaim(struct iwl3945_priv
*priv
, int txq_id
, int index
)
3188 struct iwl3945_tx_queue
*txq
= &priv
->txq
[txq_id
];
3189 struct iwl3945_queue
*q
= &txq
->q
;
3192 if ((index
>= q
->n_bd
) || (x2_queue_used(q
, index
) == 0)) {
3193 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
3194 "is out of range [0-%d] %d %d.\n", txq_id
,
3195 index
, q
->n_bd
, q
->write_ptr
, q
->read_ptr
);
3199 for (index
= iwl3945_queue_inc_wrap(index
, q
->n_bd
);
3200 q
->read_ptr
!= index
;
3201 q
->read_ptr
= iwl3945_queue_inc_wrap(q
->read_ptr
, q
->n_bd
)) {
3202 if (txq_id
!= IWL_CMD_QUEUE_NUM
) {
3203 iwl3945_txstatus_to_ieee(priv
,
3204 &(txq
->txb
[txq
->q
.read_ptr
]));
3205 iwl3945_hw_txq_free_tfd(priv
, txq
);
3206 } else if (nfreed
> 1) {
3207 IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index
,
3208 q
->write_ptr
, q
->read_ptr
);
3209 queue_work(priv
->workqueue
, &priv
->restart
);
3214 if (iwl3945_queue_space(q
) > q
->low_mark
&& (txq_id
>= 0) &&
3215 (txq_id
!= IWL_CMD_QUEUE_NUM
) &&
3216 priv
->mac80211_registered
)
3217 ieee80211_wake_queue(priv
->hw
, txq_id
);
3223 static int iwl3945_is_tx_success(u32 status
)
3225 return (status
& 0xFF) == 0x1;
3228 /******************************************************************************
3230 * Generic RX handler implementations
3232 ******************************************************************************/
3234 * iwl3945_rx_reply_tx - Handle Tx response
3236 static void iwl3945_rx_reply_tx(struct iwl3945_priv
*priv
,
3237 struct iwl3945_rx_mem_buffer
*rxb
)
3239 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3240 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
3241 int txq_id
= SEQ_TO_QUEUE(sequence
);
3242 int index
= SEQ_TO_INDEX(sequence
);
3243 struct iwl3945_tx_queue
*txq
= &priv
->txq
[txq_id
];
3244 struct ieee80211_tx_status
*tx_status
;
3245 struct iwl3945_tx_resp
*tx_resp
= (void *)&pkt
->u
.raw
[0];
3246 u32 status
= le32_to_cpu(tx_resp
->status
);
3248 if ((index
>= txq
->q
.n_bd
) || (x2_queue_used(&txq
->q
, index
) == 0)) {
3249 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
3250 "is out of range [0-%d] %d %d\n", txq_id
,
3251 index
, txq
->q
.n_bd
, txq
->q
.write_ptr
,
3256 tx_status
= &(txq
->txb
[txq
->q
.read_ptr
].status
);
3258 tx_status
->retry_count
= tx_resp
->failure_frame
;
3259 tx_status
->queue_number
= status
;
3260 tx_status
->queue_length
= tx_resp
->bt_kill_count
;
3261 tx_status
->queue_length
|= tx_resp
->failure_rts
;
3264 iwl3945_is_tx_success(status
) ? IEEE80211_TX_STATUS_ACK
: 0;
3266 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) plcp rate %d retries %d\n",
3267 txq_id
, iwl3945_get_tx_fail_reason(status
), status
,
3268 tx_resp
->rate
, tx_resp
->failure_frame
);
3270 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index
);
3272 iwl3945_tx_queue_reclaim(priv
, txq_id
, index
);
3274 if (iwl_check_bits(status
, TX_ABORT_REQUIRED_MSK
))
3275 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
3279 static void iwl3945_rx_reply_alive(struct iwl3945_priv
*priv
,
3280 struct iwl3945_rx_mem_buffer
*rxb
)
3282 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3283 struct iwl3945_alive_resp
*palive
;
3284 struct delayed_work
*pwork
;
3286 palive
= &pkt
->u
.alive_frame
;
3288 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
3290 palive
->is_valid
, palive
->ver_type
,
3291 palive
->ver_subtype
);
3293 if (palive
->ver_subtype
== INITIALIZE_SUBTYPE
) {
3294 IWL_DEBUG_INFO("Initialization Alive received.\n");
3295 memcpy(&priv
->card_alive_init
,
3296 &pkt
->u
.alive_frame
,
3297 sizeof(struct iwl3945_init_alive_resp
));
3298 pwork
= &priv
->init_alive_start
;
3300 IWL_DEBUG_INFO("Runtime Alive received.\n");
3301 memcpy(&priv
->card_alive
, &pkt
->u
.alive_frame
,
3302 sizeof(struct iwl3945_alive_resp
));
3303 pwork
= &priv
->alive_start
;
3304 iwl3945_disable_events(priv
);
3307 /* We delay the ALIVE response by 5ms to
3308 * give the HW RF Kill time to activate... */
3309 if (palive
->is_valid
== UCODE_VALID_OK
)
3310 queue_delayed_work(priv
->workqueue
, pwork
,
3311 msecs_to_jiffies(5));
3313 IWL_WARNING("uCode did not respond OK.\n");
3316 static void iwl3945_rx_reply_add_sta(struct iwl3945_priv
*priv
,
3317 struct iwl3945_rx_mem_buffer
*rxb
)
3319 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3321 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt
->u
.status
);
3325 static void iwl3945_rx_reply_error(struct iwl3945_priv
*priv
,
3326 struct iwl3945_rx_mem_buffer
*rxb
)
3328 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3330 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
3331 "seq 0x%04X ser 0x%08X\n",
3332 le32_to_cpu(pkt
->u
.err_resp
.error_type
),
3333 get_cmd_string(pkt
->u
.err_resp
.cmd_id
),
3334 pkt
->u
.err_resp
.cmd_id
,
3335 le16_to_cpu(pkt
->u
.err_resp
.bad_cmd_seq_num
),
3336 le32_to_cpu(pkt
->u
.err_resp
.error_info
));
3339 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
3341 static void iwl3945_rx_csa(struct iwl3945_priv
*priv
, struct iwl3945_rx_mem_buffer
*rxb
)
3343 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3344 struct iwl3945_rxon_cmd
*rxon
= (void *)&priv
->active_rxon
;
3345 struct iwl3945_csa_notification
*csa
= &(pkt
->u
.csa_notif
);
3346 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
3347 le16_to_cpu(csa
->channel
), le32_to_cpu(csa
->status
));
3348 rxon
->channel
= csa
->channel
;
3349 priv
->staging_rxon
.channel
= csa
->channel
;
3352 static void iwl3945_rx_spectrum_measure_notif(struct iwl3945_priv
*priv
,
3353 struct iwl3945_rx_mem_buffer
*rxb
)
3355 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
3356 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3357 struct iwl3945_spectrum_notification
*report
= &(pkt
->u
.spectrum_notif
);
3359 if (!report
->state
) {
3360 IWL_DEBUG(IWL_DL_11H
| IWL_DL_INFO
,
3361 "Spectrum Measure Notification: Start\n");
3365 memcpy(&priv
->measure_report
, report
, sizeof(*report
));
3366 priv
->measurement_status
|= MEASUREMENT_READY
;
3370 static void iwl3945_rx_pm_sleep_notif(struct iwl3945_priv
*priv
,
3371 struct iwl3945_rx_mem_buffer
*rxb
)
3373 #ifdef CONFIG_IWL3945_DEBUG
3374 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3375 struct iwl3945_sleep_notification
*sleep
= &(pkt
->u
.sleep_notif
);
3376 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
3377 sleep
->pm_sleep_mode
, sleep
->pm_wakeup_src
);
3381 static void iwl3945_rx_pm_debug_statistics_notif(struct iwl3945_priv
*priv
,
3382 struct iwl3945_rx_mem_buffer
*rxb
)
3384 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3385 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
3386 "notification for %s:\n",
3387 le32_to_cpu(pkt
->len
), get_cmd_string(pkt
->hdr
.cmd
));
3388 iwl3945_print_hex_dump(IWL_DL_RADIO
, pkt
->u
.raw
, le32_to_cpu(pkt
->len
));
3391 static void iwl3945_bg_beacon_update(struct work_struct
*work
)
3393 struct iwl3945_priv
*priv
=
3394 container_of(work
, struct iwl3945_priv
, beacon_update
);
3395 struct sk_buff
*beacon
;
3397 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
3398 beacon
= ieee80211_beacon_get(priv
->hw
, priv
->vif
, NULL
);
3401 IWL_ERROR("update beacon failed\n");
3405 mutex_lock(&priv
->mutex
);
3406 /* new beacon skb is allocated every time; dispose previous.*/
3407 if (priv
->ibss_beacon
)
3408 dev_kfree_skb(priv
->ibss_beacon
);
3410 priv
->ibss_beacon
= beacon
;
3411 mutex_unlock(&priv
->mutex
);
3413 iwl3945_send_beacon_cmd(priv
);
3416 static void iwl3945_rx_beacon_notif(struct iwl3945_priv
*priv
,
3417 struct iwl3945_rx_mem_buffer
*rxb
)
3419 #ifdef CONFIG_IWL3945_DEBUG
3420 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3421 struct iwl3945_beacon_notif
*beacon
= &(pkt
->u
.beacon_status
);
3422 u8 rate
= beacon
->beacon_notify_hdr
.rate
;
3424 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
3425 "tsf %d %d rate %d\n",
3426 le32_to_cpu(beacon
->beacon_notify_hdr
.status
) & TX_STATUS_MSK
,
3427 beacon
->beacon_notify_hdr
.failure_frame
,
3428 le32_to_cpu(beacon
->ibss_mgr_status
),
3429 le32_to_cpu(beacon
->high_tsf
),
3430 le32_to_cpu(beacon
->low_tsf
), rate
);
3433 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
3434 (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)))
3435 queue_work(priv
->workqueue
, &priv
->beacon_update
);
3438 /* Service response to REPLY_SCAN_CMD (0x80) */
3439 static void iwl3945_rx_reply_scan(struct iwl3945_priv
*priv
,
3440 struct iwl3945_rx_mem_buffer
*rxb
)
3442 #ifdef CONFIG_IWL3945_DEBUG
3443 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3444 struct iwl3945_scanreq_notification
*notif
=
3445 (struct iwl3945_scanreq_notification
*)pkt
->u
.raw
;
3447 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif
->status
);
3451 /* Service SCAN_START_NOTIFICATION (0x82) */
3452 static void iwl3945_rx_scan_start_notif(struct iwl3945_priv
*priv
,
3453 struct iwl3945_rx_mem_buffer
*rxb
)
3455 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3456 struct iwl3945_scanstart_notification
*notif
=
3457 (struct iwl3945_scanstart_notification
*)pkt
->u
.raw
;
3458 priv
->scan_start_tsf
= le32_to_cpu(notif
->tsf_low
);
3459 IWL_DEBUG_SCAN("Scan start: "
3461 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
3463 notif
->band
? "bg" : "a",
3465 notif
->tsf_low
, notif
->status
, notif
->beacon_timer
);
3468 /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
3469 static void iwl3945_rx_scan_results_notif(struct iwl3945_priv
*priv
,
3470 struct iwl3945_rx_mem_buffer
*rxb
)
3472 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3473 struct iwl3945_scanresults_notification
*notif
=
3474 (struct iwl3945_scanresults_notification
*)pkt
->u
.raw
;
3476 IWL_DEBUG_SCAN("Scan ch.res: "
3478 "(TSF: 0x%08X:%08X) - %d "
3479 "elapsed=%lu usec (%dms since last)\n",
3481 notif
->band
? "bg" : "a",
3482 le32_to_cpu(notif
->tsf_high
),
3483 le32_to_cpu(notif
->tsf_low
),
3484 le32_to_cpu(notif
->statistics
[0]),
3485 le32_to_cpu(notif
->tsf_low
) - priv
->scan_start_tsf
,
3486 jiffies_to_msecs(elapsed_jiffies
3487 (priv
->last_scan_jiffies
, jiffies
)));
3489 priv
->last_scan_jiffies
= jiffies
;
3490 priv
->next_scan_jiffies
= 0;
3493 /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
3494 static void iwl3945_rx_scan_complete_notif(struct iwl3945_priv
*priv
,
3495 struct iwl3945_rx_mem_buffer
*rxb
)
3497 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3498 struct iwl3945_scancomplete_notification
*scan_notif
= (void *)pkt
->u
.raw
;
3500 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
3501 scan_notif
->scanned_channels
,
3502 scan_notif
->tsf_low
,
3503 scan_notif
->tsf_high
, scan_notif
->status
);
3505 /* The HW is no longer scanning */
3506 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
3508 /* The scan completion notification came in, so kill that timer... */
3509 cancel_delayed_work(&priv
->scan_check
);
3511 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
3512 (priv
->scan_bands
== 2) ? "2.4" : "5.2",
3513 jiffies_to_msecs(elapsed_jiffies
3514 (priv
->scan_pass_start
, jiffies
)));
3516 /* Remove this scanned band from the list
3517 * of pending bands to scan */
3520 /* If a request to abort was given, or the scan did not succeed
3521 * then we reset the scan state machine and terminate,
3522 * re-queuing another scan if one has been requested */
3523 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
3524 IWL_DEBUG_INFO("Aborted scan completed.\n");
3525 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
3527 /* If there are more bands on this scan pass reschedule */
3528 if (priv
->scan_bands
> 0)
3532 priv
->last_scan_jiffies
= jiffies
;
3533 priv
->next_scan_jiffies
= 0;
3534 IWL_DEBUG_INFO("Setting scan to off\n");
3536 clear_bit(STATUS_SCANNING
, &priv
->status
);
3538 IWL_DEBUG_INFO("Scan took %dms\n",
3539 jiffies_to_msecs(elapsed_jiffies(priv
->scan_start
, jiffies
)));
3541 queue_work(priv
->workqueue
, &priv
->scan_completed
);
3546 priv
->scan_pass_start
= jiffies
;
3547 queue_work(priv
->workqueue
, &priv
->request_scan
);
3550 /* Handle notification from uCode that card's power state is changing
3551 * due to software, hardware, or critical temperature RFKILL */
3552 static void iwl3945_rx_card_state_notif(struct iwl3945_priv
*priv
,
3553 struct iwl3945_rx_mem_buffer
*rxb
)
3555 struct iwl3945_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3556 u32 flags
= le32_to_cpu(pkt
->u
.card_state_notif
.flags
);
3557 unsigned long status
= priv
->status
;
3559 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
3560 (flags
& HW_CARD_DISABLED
) ? "Kill" : "On",
3561 (flags
& SW_CARD_DISABLED
) ? "Kill" : "On");
3563 iwl3945_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
3564 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
3566 if (flags
& HW_CARD_DISABLED
)
3567 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
3569 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
3572 if (flags
& SW_CARD_DISABLED
)
3573 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
3575 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
3577 iwl3945_scan_cancel(priv
);
3579 if ((test_bit(STATUS_RF_KILL_HW
, &status
) !=
3580 test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) ||
3581 (test_bit(STATUS_RF_KILL_SW
, &status
) !=
3582 test_bit(STATUS_RF_KILL_SW
, &priv
->status
)))
3583 queue_work(priv
->workqueue
, &priv
->rf_kill
);
3585 wake_up_interruptible(&priv
->wait_command_queue
);
3589 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
3591 * Setup the RX handlers for each of the reply types sent from the uCode
3594 * This function chains into the hardware specific files for them to setup
3595 * any hardware specific handlers as well.
3597 static void iwl3945_setup_rx_handlers(struct iwl3945_priv
*priv
)
3599 priv
->rx_handlers
[REPLY_ALIVE
] = iwl3945_rx_reply_alive
;
3600 priv
->rx_handlers
[REPLY_ADD_STA
] = iwl3945_rx_reply_add_sta
;
3601 priv
->rx_handlers
[REPLY_ERROR
] = iwl3945_rx_reply_error
;
3602 priv
->rx_handlers
[CHANNEL_SWITCH_NOTIFICATION
] = iwl3945_rx_csa
;
3603 priv
->rx_handlers
[SPECTRUM_MEASURE_NOTIFICATION
] =
3604 iwl3945_rx_spectrum_measure_notif
;
3605 priv
->rx_handlers
[PM_SLEEP_NOTIFICATION
] = iwl3945_rx_pm_sleep_notif
;
3606 priv
->rx_handlers
[PM_DEBUG_STATISTIC_NOTIFIC
] =
3607 iwl3945_rx_pm_debug_statistics_notif
;
3608 priv
->rx_handlers
[BEACON_NOTIFICATION
] = iwl3945_rx_beacon_notif
;
3611 * The same handler is used for both the REPLY to a discrete
3612 * statistics request from the host as well as for the periodic
3613 * statistics notifications (after received beacons) from the uCode.
3615 priv
->rx_handlers
[REPLY_STATISTICS_CMD
] = iwl3945_hw_rx_statistics
;
3616 priv
->rx_handlers
[STATISTICS_NOTIFICATION
] = iwl3945_hw_rx_statistics
;
3618 priv
->rx_handlers
[REPLY_SCAN_CMD
] = iwl3945_rx_reply_scan
;
3619 priv
->rx_handlers
[SCAN_START_NOTIFICATION
] = iwl3945_rx_scan_start_notif
;
3620 priv
->rx_handlers
[SCAN_RESULTS_NOTIFICATION
] =
3621 iwl3945_rx_scan_results_notif
;
3622 priv
->rx_handlers
[SCAN_COMPLETE_NOTIFICATION
] =
3623 iwl3945_rx_scan_complete_notif
;
3624 priv
->rx_handlers
[CARD_STATE_NOTIFICATION
] = iwl3945_rx_card_state_notif
;
3625 priv
->rx_handlers
[REPLY_TX
] = iwl3945_rx_reply_tx
;
3627 /* Set up hardware specific Rx handlers */
3628 iwl3945_hw_rx_handler_setup(priv
);
3632 * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
3633 * @rxb: Rx buffer to reclaim
3635 * If an Rx buffer has an async callback associated with it the callback
3636 * will be executed. The attached skb (if present) will only be freed
3637 * if the callback returns 1
3639 static void iwl3945_tx_cmd_complete(struct iwl3945_priv
*priv
,
3640 struct iwl3945_rx_mem_buffer
*rxb
)
3642 struct iwl3945_rx_packet
*pkt
= (struct iwl3945_rx_packet
*)rxb
->skb
->data
;
3643 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
3644 int txq_id
= SEQ_TO_QUEUE(sequence
);
3645 int index
= SEQ_TO_INDEX(sequence
);
3646 int huge
= sequence
& SEQ_HUGE_FRAME
;
3648 struct iwl3945_cmd
*cmd
;
3650 /* If a Tx command is being handled and it isn't in the actual
3651 * command queue then there a command routing bug has been introduced
3652 * in the queue management code. */
3653 if (txq_id
!= IWL_CMD_QUEUE_NUM
)
3654 IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
3655 txq_id
, pkt
->hdr
.cmd
);
3656 BUG_ON(txq_id
!= IWL_CMD_QUEUE_NUM
);
3658 cmd_index
= get_cmd_index(&priv
->txq
[IWL_CMD_QUEUE_NUM
].q
, index
, huge
);
3659 cmd
= &priv
->txq
[IWL_CMD_QUEUE_NUM
].cmd
[cmd_index
];
3661 /* Input error checking is done when commands are added to queue. */
3662 if (cmd
->meta
.flags
& CMD_WANT_SKB
) {
3663 cmd
->meta
.source
->u
.skb
= rxb
->skb
;
3665 } else if (cmd
->meta
.u
.callback
&&
3666 !cmd
->meta
.u
.callback(priv
, cmd
, rxb
->skb
))
3669 iwl3945_tx_queue_reclaim(priv
, txq_id
, index
);
3671 if (!(cmd
->meta
.flags
& CMD_ASYNC
)) {
3672 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
3673 wake_up_interruptible(&priv
->wait_command_queue
);
3677 /************************** RX-FUNCTIONS ****************************/
3679 * Rx theory of operation
3681 * The host allocates 32 DMA target addresses and passes the host address
3682 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
3686 * The host/firmware share two index registers for managing the Rx buffers.
3688 * The READ index maps to the first position that the firmware may be writing
3689 * to -- the driver can read up to (but not including) this position and get
3691 * The READ index is managed by the firmware once the card is enabled.
3693 * The WRITE index maps to the last position the driver has read from -- the
3694 * position preceding WRITE is the last slot the firmware can place a packet.
3696 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
3699 * During initialization, the host sets up the READ queue position to the first
3700 * INDEX position, and WRITE to the last (READ - 1 wrapped)
3702 * When the firmware places a packet in a buffer, it will advance the READ index
3703 * and fire the RX interrupt. The driver can then query the READ index and
3704 * process as many packets as possible, moving the WRITE index forward as it
3705 * resets the Rx queue buffers with new memory.
3707 * The management in the driver is as follows:
3708 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
3709 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
3710 * to replenish the iwl->rxq->rx_free.
3711 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
3712 * iwl->rxq is replenished and the READ INDEX is updated (updating the
3713 * 'processed' and 'read' driver indexes as well)
3714 * + A received packet is processed and handed to the kernel network stack,
3715 * detached from the iwl->rxq. The driver 'processed' index is updated.
3716 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
3717 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
3718 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
3719 * were enough free buffers and RX_STALLED is set it is cleared.
3724 * iwl3945_rx_queue_alloc() Allocates rx_free
3725 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
3726 * iwl3945_rx_queue_restock
3727 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
3728 * queue, updates firmware pointers, and updates
3729 * the WRITE index. If insufficient rx_free buffers
3730 * are available, schedules iwl3945_rx_replenish
3732 * -- enable interrupts --
3733 * ISR - iwl3945_rx() Detach iwl3945_rx_mem_buffers from pool up to the
3734 * READ INDEX, detaching the SKB from the pool.
3735 * Moves the packet buffer from queue to rx_used.
3736 * Calls iwl3945_rx_queue_restock to refill any empty
3743 * iwl3945_rx_queue_space - Return number of free slots available in queue.
3745 static int iwl3945_rx_queue_space(const struct iwl3945_rx_queue
*q
)
3747 int s
= q
->read
- q
->write
;
3750 /* keep some buffer to not confuse full and empty queue */
3758 * iwl3945_rx_queue_update_write_ptr - Update the write pointer for the RX queue
3760 int iwl3945_rx_queue_update_write_ptr(struct iwl3945_priv
*priv
, struct iwl3945_rx_queue
*q
)
3764 unsigned long flags
;
3766 spin_lock_irqsave(&q
->lock
, flags
);
3768 if (q
->need_update
== 0)
3771 /* If power-saving is in use, make sure device is awake */
3772 if (test_bit(STATUS_POWER_PMI
, &priv
->status
)) {
3773 reg
= iwl3945_read32(priv
, CSR_UCODE_DRV_GP1
);
3775 if (reg
& CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP
) {
3776 iwl3945_set_bit(priv
, CSR_GP_CNTRL
,
3777 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
3781 rc
= iwl3945_grab_nic_access(priv
);
3785 /* Device expects a multiple of 8 */
3786 iwl3945_write_direct32(priv
, FH_RSCSR_CHNL0_WPTR
,
3788 iwl3945_release_nic_access(priv
);
3790 /* Else device is assumed to be awake */
3792 /* Device expects a multiple of 8 */
3793 iwl3945_write32(priv
, FH_RSCSR_CHNL0_WPTR
, q
->write
& ~0x7);
3799 spin_unlock_irqrestore(&q
->lock
, flags
);
3804 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
3806 static inline __le32
iwl3945_dma_addr2rbd_ptr(struct iwl3945_priv
*priv
,
3807 dma_addr_t dma_addr
)
3809 return cpu_to_le32((u32
)dma_addr
);
3813 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
3815 * If there are slots in the RX queue that need to be restocked,
3816 * and we have free pre-allocated buffers, fill the ranks as much
3817 * as we can, pulling from rx_free.
3819 * This moves the 'write' index forward to catch up with 'processed', and
3820 * also updates the memory address in the firmware to reference the new
3823 static int iwl3945_rx_queue_restock(struct iwl3945_priv
*priv
)
3825 struct iwl3945_rx_queue
*rxq
= &priv
->rxq
;
3826 struct list_head
*element
;
3827 struct iwl3945_rx_mem_buffer
*rxb
;
3828 unsigned long flags
;
3831 spin_lock_irqsave(&rxq
->lock
, flags
);
3832 write
= rxq
->write
& ~0x7;
3833 while ((iwl3945_rx_queue_space(rxq
) > 0) && (rxq
->free_count
)) {
3834 /* Get next free Rx buffer, remove from free list */
3835 element
= rxq
->rx_free
.next
;
3836 rxb
= list_entry(element
, struct iwl3945_rx_mem_buffer
, list
);
3839 /* Point to Rx buffer via next RBD in circular buffer */
3840 rxq
->bd
[rxq
->write
] = iwl3945_dma_addr2rbd_ptr(priv
, rxb
->dma_addr
);
3841 rxq
->queue
[rxq
->write
] = rxb
;
3842 rxq
->write
= (rxq
->write
+ 1) & RX_QUEUE_MASK
;
3845 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3846 /* If the pre-allocated buffer pool is dropping low, schedule to
3848 if (rxq
->free_count
<= RX_LOW_WATERMARK
)
3849 queue_work(priv
->workqueue
, &priv
->rx_replenish
);
3852 /* If we've added more space for the firmware to place data, tell it.
3853 * Increment device's write pointer in multiples of 8. */
3854 if ((write
!= (rxq
->write
& ~0x7))
3855 || (abs(rxq
->write
- rxq
->read
) > 7)) {
3856 spin_lock_irqsave(&rxq
->lock
, flags
);
3857 rxq
->need_update
= 1;
3858 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3859 rc
= iwl3945_rx_queue_update_write_ptr(priv
, rxq
);
3868 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
3870 * When moving to rx_free an SKB is allocated for the slot.
3872 * Also restock the Rx queue via iwl3945_rx_queue_restock.
3873 * This is called as a scheduled work item (except for during initialization)
3875 static void iwl3945_rx_allocate(struct iwl3945_priv
*priv
)
3877 struct iwl3945_rx_queue
*rxq
= &priv
->rxq
;
3878 struct list_head
*element
;
3879 struct iwl3945_rx_mem_buffer
*rxb
;
3880 unsigned long flags
;
3881 spin_lock_irqsave(&rxq
->lock
, flags
);
3882 while (!list_empty(&rxq
->rx_used
)) {
3883 element
= rxq
->rx_used
.next
;
3884 rxb
= list_entry(element
, struct iwl3945_rx_mem_buffer
, list
);
3886 /* Alloc a new receive buffer */
3888 alloc_skb(IWL_RX_BUF_SIZE
, __GFP_NOWARN
| GFP_ATOMIC
);
3890 if (net_ratelimit())
3891 printk(KERN_CRIT DRV_NAME
3892 ": Can not allocate SKB buffers\n");
3893 /* We don't reschedule replenish work here -- we will
3894 * call the restock method and if it still needs
3895 * more buffers it will schedule replenish */
3899 /* If radiotap head is required, reserve some headroom here.
3900 * The physical head count is a variable rx_stats->phy_count.
3901 * We reserve 4 bytes here. Plus these extra bytes, the
3902 * headroom of the physical head should be enough for the
3903 * radiotap head that iwl3945 supported. See iwl3945_rt.
3905 skb_reserve(rxb
->skb
, 4);
3907 priv
->alloc_rxb_skb
++;
3910 /* Get physical address of RB/SKB */
3912 pci_map_single(priv
->pci_dev
, rxb
->skb
->data
,
3913 IWL_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
3914 list_add_tail(&rxb
->list
, &rxq
->rx_free
);
3917 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3921 * this should be called while priv->lock is locked
3923 static void __iwl3945_rx_replenish(void *data
)
3925 struct iwl3945_priv
*priv
= data
;
3927 iwl3945_rx_allocate(priv
);
3928 iwl3945_rx_queue_restock(priv
);
3932 void iwl3945_rx_replenish(void *data
)
3934 struct iwl3945_priv
*priv
= data
;
3935 unsigned long flags
;
3937 iwl3945_rx_allocate(priv
);
3939 spin_lock_irqsave(&priv
->lock
, flags
);
3940 iwl3945_rx_queue_restock(priv
);
3941 spin_unlock_irqrestore(&priv
->lock
, flags
);
3944 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
3945 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
3946 * This free routine walks the list of POOL entries and if SKB is set to
3947 * non NULL it is unmapped and freed
3949 static void iwl3945_rx_queue_free(struct iwl3945_priv
*priv
, struct iwl3945_rx_queue
*rxq
)
3952 for (i
= 0; i
< RX_QUEUE_SIZE
+ RX_FREE_BUFFERS
; i
++) {
3953 if (rxq
->pool
[i
].skb
!= NULL
) {
3954 pci_unmap_single(priv
->pci_dev
,
3955 rxq
->pool
[i
].dma_addr
,
3956 IWL_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
3957 dev_kfree_skb(rxq
->pool
[i
].skb
);
3961 pci_free_consistent(priv
->pci_dev
, 4 * RX_QUEUE_SIZE
, rxq
->bd
,
3966 int iwl3945_rx_queue_alloc(struct iwl3945_priv
*priv
)
3968 struct iwl3945_rx_queue
*rxq
= &priv
->rxq
;
3969 struct pci_dev
*dev
= priv
->pci_dev
;
3972 spin_lock_init(&rxq
->lock
);
3973 INIT_LIST_HEAD(&rxq
->rx_free
);
3974 INIT_LIST_HEAD(&rxq
->rx_used
);
3976 /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
3977 rxq
->bd
= pci_alloc_consistent(dev
, 4 * RX_QUEUE_SIZE
, &rxq
->dma_addr
);
3981 /* Fill the rx_used queue with _all_ of the Rx buffers */
3982 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++)
3983 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
3985 /* Set us so that we have processed and used all buffers, but have
3986 * not restocked the Rx queue with fresh buffers */
3987 rxq
->read
= rxq
->write
= 0;
3988 rxq
->free_count
= 0;
3989 rxq
->need_update
= 0;
3993 void iwl3945_rx_queue_reset(struct iwl3945_priv
*priv
, struct iwl3945_rx_queue
*rxq
)
3995 unsigned long flags
;
3997 spin_lock_irqsave(&rxq
->lock
, flags
);
3998 INIT_LIST_HEAD(&rxq
->rx_free
);
3999 INIT_LIST_HEAD(&rxq
->rx_used
);
4000 /* Fill the rx_used queue with _all_ of the Rx buffers */
4001 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++) {
4002 /* In the reset function, these buffers may have been allocated
4003 * to an SKB, so we need to unmap and free potential storage */
4004 if (rxq
->pool
[i
].skb
!= NULL
) {
4005 pci_unmap_single(priv
->pci_dev
,
4006 rxq
->pool
[i
].dma_addr
,
4007 IWL_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
4008 priv
->alloc_rxb_skb
--;
4009 dev_kfree_skb(rxq
->pool
[i
].skb
);
4010 rxq
->pool
[i
].skb
= NULL
;
4012 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
4015 /* Set us so that we have processed and used all buffers, but have
4016 * not restocked the Rx queue with fresh buffers */
4017 rxq
->read
= rxq
->write
= 0;
4018 rxq
->free_count
= 0;
4019 spin_unlock_irqrestore(&rxq
->lock
, flags
);
4022 /* Convert linear signal-to-noise ratio into dB */
4023 static u8 ratio2dB
[100] = {
4024 /* 0 1 2 3 4 5 6 7 8 9 */
4025 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
4026 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
4027 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
4028 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
4029 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
4030 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
4031 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
4032 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
4033 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
4034 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
4037 /* Calculates a relative dB value from a ratio of linear
4038 * (i.e. not dB) signal levels.
4039 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
4040 int iwl3945_calc_db_from_ratio(int sig_ratio
)
4042 /* 1000:1 or higher just report as 60 dB */
4043 if (sig_ratio
>= 1000)
4046 /* 100:1 or higher, divide by 10 and use table,
4047 * add 20 dB to make up for divide by 10 */
4048 if (sig_ratio
>= 100)
4049 return (20 + (int)ratio2dB
[sig_ratio
/10]);
4051 /* We shouldn't see this */
4055 /* Use table for ratios 1:1 - 99:1 */
4056 return (int)ratio2dB
[sig_ratio
];
4059 #define PERFECT_RSSI (-20) /* dBm */
4060 #define WORST_RSSI (-95) /* dBm */
4061 #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
4063 /* Calculate an indication of rx signal quality (a percentage, not dBm!).
4064 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
4065 * about formulas used below. */
4066 int iwl3945_calc_sig_qual(int rssi_dbm
, int noise_dbm
)
4069 int degradation
= PERFECT_RSSI
- rssi_dbm
;
4071 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
4072 * as indicator; formula is (signal dbm - noise dbm).
4073 * SNR at or above 40 is a great signal (100%).
4074 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
4075 * Weakest usable signal is usually 10 - 15 dB SNR. */
4077 if (rssi_dbm
- noise_dbm
>= 40)
4079 else if (rssi_dbm
< noise_dbm
)
4081 sig_qual
= ((rssi_dbm
- noise_dbm
) * 5) / 2;
4083 /* Else use just the signal level.
4084 * This formula is a least squares fit of data points collected and
4085 * compared with a reference system that had a percentage (%) display
4086 * for signal quality. */
4088 sig_qual
= (100 * (RSSI_RANGE
* RSSI_RANGE
) - degradation
*
4089 (15 * RSSI_RANGE
+ 62 * degradation
)) /
4090 (RSSI_RANGE
* RSSI_RANGE
);
4094 else if (sig_qual
< 1)
4101 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
4103 * Uses the priv->rx_handlers callback function array to invoke
4104 * the appropriate handlers, including command responses,
4105 * frame-received notifications, and other notifications.
4107 static void iwl3945_rx_handle(struct iwl3945_priv
*priv
)
4109 struct iwl3945_rx_mem_buffer
*rxb
;
4110 struct iwl3945_rx_packet
*pkt
;
4111 struct iwl3945_rx_queue
*rxq
= &priv
->rxq
;
4114 unsigned long flags
;
4118 /* uCode's read index (stored in shared DRAM) indicates the last Rx
4119 * buffer that the driver may process (last buffer filled by ucode). */
4120 r
= iwl3945_hw_get_rx_read(priv
);
4123 if (iwl3945_rx_queue_space(rxq
) > (RX_QUEUE_SIZE
/ 2))
4125 /* Rx interrupt, but nothing sent from uCode */
4127 IWL_DEBUG(IWL_DL_RX
| IWL_DL_ISR
, "r = %d, i = %d\n", r
, i
);
4130 rxb
= rxq
->queue
[i
];
4132 /* If an RXB doesn't have a Rx queue slot associated with it,
4133 * then a bug has been introduced in the queue refilling
4134 * routines -- catch it here */
4135 BUG_ON(rxb
== NULL
);
4137 rxq
->queue
[i
] = NULL
;
4139 pci_dma_sync_single_for_cpu(priv
->pci_dev
, rxb
->dma_addr
,
4141 PCI_DMA_FROMDEVICE
);
4142 pkt
= (struct iwl3945_rx_packet
*)rxb
->skb
->data
;
4144 /* Reclaim a command buffer only if this packet is a response
4145 * to a (driver-originated) command.
4146 * If the packet (e.g. Rx frame) originated from uCode,
4147 * there is no command buffer to reclaim.
4148 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
4149 * but apparently a few don't get set; catch them here. */
4150 reclaim
= !(pkt
->hdr
.sequence
& SEQ_RX_FRAME
) &&
4151 (pkt
->hdr
.cmd
!= STATISTICS_NOTIFICATION
) &&
4152 (pkt
->hdr
.cmd
!= REPLY_TX
);
4154 /* Based on type of command response or notification,
4155 * handle those that need handling via function in
4156 * rx_handlers table. See iwl3945_setup_rx_handlers() */
4157 if (priv
->rx_handlers
[pkt
->hdr
.cmd
]) {
4158 IWL_DEBUG(IWL_DL_HOST_COMMAND
| IWL_DL_RX
| IWL_DL_ISR
,
4159 "r = %d, i = %d, %s, 0x%02x\n", r
, i
,
4160 get_cmd_string(pkt
->hdr
.cmd
), pkt
->hdr
.cmd
);
4161 priv
->rx_handlers
[pkt
->hdr
.cmd
] (priv
, rxb
);
4163 /* No handling needed */
4164 IWL_DEBUG(IWL_DL_HOST_COMMAND
| IWL_DL_RX
| IWL_DL_ISR
,
4165 "r %d i %d No handler needed for %s, 0x%02x\n",
4166 r
, i
, get_cmd_string(pkt
->hdr
.cmd
),
4171 /* Invoke any callbacks, transfer the skb to caller, and
4172 * fire off the (possibly) blocking iwl3945_send_cmd()
4173 * as we reclaim the driver command queue */
4174 if (rxb
&& rxb
->skb
)
4175 iwl3945_tx_cmd_complete(priv
, rxb
);
4177 IWL_WARNING("Claim null rxb?\n");
4180 /* For now we just don't re-use anything. We can tweak this
4181 * later to try and re-use notification packets and SKBs that
4182 * fail to Rx correctly */
4183 if (rxb
->skb
!= NULL
) {
4184 priv
->alloc_rxb_skb
--;
4185 dev_kfree_skb_any(rxb
->skb
);
4189 pci_unmap_single(priv
->pci_dev
, rxb
->dma_addr
,
4190 IWL_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
4191 spin_lock_irqsave(&rxq
->lock
, flags
);
4192 list_add_tail(&rxb
->list
, &priv
->rxq
.rx_used
);
4193 spin_unlock_irqrestore(&rxq
->lock
, flags
);
4194 i
= (i
+ 1) & RX_QUEUE_MASK
;
4195 /* If there are a lot of unused frames,
4196 * restock the Rx queue so ucode won't assert. */
4201 __iwl3945_rx_replenish(priv
);
4207 /* Backtrack one entry */
4209 iwl3945_rx_queue_restock(priv
);
4213 * iwl3945_tx_queue_update_write_ptr - Send new write index to hardware
4215 static int iwl3945_tx_queue_update_write_ptr(struct iwl3945_priv
*priv
,
4216 struct iwl3945_tx_queue
*txq
)
4220 int txq_id
= txq
->q
.id
;
4222 if (txq
->need_update
== 0)
4225 /* if we're trying to save power */
4226 if (test_bit(STATUS_POWER_PMI
, &priv
->status
)) {
4227 /* wake up nic if it's powered down ...
4228 * uCode will wake up, and interrupt us again, so next
4229 * time we'll skip this part. */
4230 reg
= iwl3945_read32(priv
, CSR_UCODE_DRV_GP1
);
4232 if (reg
& CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP
) {
4233 IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg
);
4234 iwl3945_set_bit(priv
, CSR_GP_CNTRL
,
4235 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
4239 /* restore this queue's parameters in nic hardware. */
4240 rc
= iwl3945_grab_nic_access(priv
);
4243 iwl3945_write_direct32(priv
, HBUS_TARG_WRPTR
,
4244 txq
->q
.write_ptr
| (txq_id
<< 8));
4245 iwl3945_release_nic_access(priv
);
4247 /* else not in power-save mode, uCode will never sleep when we're
4248 * trying to tx (during RFKILL, we're not trying to tx). */
4250 iwl3945_write32(priv
, HBUS_TARG_WRPTR
,
4251 txq
->q
.write_ptr
| (txq_id
<< 8));
4253 txq
->need_update
= 0;
4258 #ifdef CONFIG_IWL3945_DEBUG
4259 static void iwl3945_print_rx_config_cmd(struct iwl3945_rxon_cmd
*rxon
)
4261 DECLARE_MAC_BUF(mac
);
4263 IWL_DEBUG_RADIO("RX CONFIG:\n");
4264 iwl3945_print_hex_dump(IWL_DL_RADIO
, (u8
*) rxon
, sizeof(*rxon
));
4265 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon
->channel
));
4266 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon
->flags
));
4267 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
4268 le32_to_cpu(rxon
->filter_flags
));
4269 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon
->dev_type
);
4270 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
4271 rxon
->ofdm_basic_rates
);
4272 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon
->cck_basic_rates
);
4273 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
4274 print_mac(mac
, rxon
->node_addr
));
4275 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
4276 print_mac(mac
, rxon
->bssid_addr
));
4277 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon
->assoc_id
));
4281 static void iwl3945_enable_interrupts(struct iwl3945_priv
*priv
)
4283 IWL_DEBUG_ISR("Enabling interrupts\n");
4284 set_bit(STATUS_INT_ENABLED
, &priv
->status
);
4285 iwl3945_write32(priv
, CSR_INT_MASK
, CSR_INI_SET_MASK
);
4288 static inline void iwl3945_disable_interrupts(struct iwl3945_priv
*priv
)
4290 clear_bit(STATUS_INT_ENABLED
, &priv
->status
);
4292 /* disable interrupts from uCode/NIC to host */
4293 iwl3945_write32(priv
, CSR_INT_MASK
, 0x00000000);
4295 /* acknowledge/clear/reset any interrupts still pending
4296 * from uCode or flow handler (Rx/Tx DMA) */
4297 iwl3945_write32(priv
, CSR_INT
, 0xffffffff);
4298 iwl3945_write32(priv
, CSR_FH_INT_STATUS
, 0xffffffff);
4299 IWL_DEBUG_ISR("Disabled interrupts\n");
4302 static const char *desc_lookup(int i
)
4310 return "BAD_CHECKSUM";
4312 return "NMI_INTERRUPT";
4316 return "FATAL_ERROR";
4322 #define ERROR_START_OFFSET (1 * sizeof(u32))
4323 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
4325 static void iwl3945_dump_nic_error_log(struct iwl3945_priv
*priv
)
4328 u32 desc
, time
, count
, base
, data1
;
4329 u32 blink1
, blink2
, ilink1
, ilink2
;
4332 base
= le32_to_cpu(priv
->card_alive
.error_event_table_ptr
);
4334 if (!iwl3945_hw_valid_rtc_data_addr(base
)) {
4335 IWL_ERROR("Not valid error log pointer 0x%08X\n", base
);
4339 rc
= iwl3945_grab_nic_access(priv
);
4341 IWL_WARNING("Can not read from adapter at this time.\n");
4345 count
= iwl3945_read_targ_mem(priv
, base
);
4347 if (ERROR_START_OFFSET
<= count
* ERROR_ELEM_SIZE
) {
4348 IWL_ERROR("Start IWL Error Log Dump:\n");
4349 IWL_ERROR("Status: 0x%08lX, count: %d\n", priv
->status
, count
);
4352 IWL_ERROR("Desc Time asrtPC blink2 "
4353 "ilink1 nmiPC Line\n");
4354 for (i
= ERROR_START_OFFSET
;
4355 i
< (count
* ERROR_ELEM_SIZE
) + ERROR_START_OFFSET
;
4356 i
+= ERROR_ELEM_SIZE
) {
4357 desc
= iwl3945_read_targ_mem(priv
, base
+ i
);
4359 iwl3945_read_targ_mem(priv
, base
+ i
+ 1 * sizeof(u32
));
4361 iwl3945_read_targ_mem(priv
, base
+ i
+ 2 * sizeof(u32
));
4363 iwl3945_read_targ_mem(priv
, base
+ i
+ 3 * sizeof(u32
));
4365 iwl3945_read_targ_mem(priv
, base
+ i
+ 4 * sizeof(u32
));
4367 iwl3945_read_targ_mem(priv
, base
+ i
+ 5 * sizeof(u32
));
4369 iwl3945_read_targ_mem(priv
, base
+ i
+ 6 * sizeof(u32
));
4372 ("%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
4373 desc_lookup(desc
), desc
, time
, blink1
, blink2
,
4374 ilink1
, ilink2
, data1
);
4377 iwl3945_release_nic_access(priv
);
4381 #define EVENT_START_OFFSET (6 * sizeof(u32))
4384 * iwl3945_print_event_log - Dump error event log to syslog
4386 * NOTE: Must be called with iwl3945_grab_nic_access() already obtained!
4388 static void iwl3945_print_event_log(struct iwl3945_priv
*priv
, u32 start_idx
,
4389 u32 num_events
, u32 mode
)
4392 u32 base
; /* SRAM byte address of event log header */
4393 u32 event_size
; /* 2 u32s, or 3 u32s if timestamp recorded */
4394 u32 ptr
; /* SRAM byte address of log data */
4395 u32 ev
, time
, data
; /* event log data */
4397 if (num_events
== 0)
4400 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
4403 event_size
= 2 * sizeof(u32
);
4405 event_size
= 3 * sizeof(u32
);
4407 ptr
= base
+ EVENT_START_OFFSET
+ (start_idx
* event_size
);
4409 /* "time" is actually "data" for mode 0 (no timestamp).
4410 * place event id # at far right for easier visual parsing. */
4411 for (i
= 0; i
< num_events
; i
++) {
4412 ev
= iwl3945_read_targ_mem(priv
, ptr
);
4414 time
= iwl3945_read_targ_mem(priv
, ptr
);
4417 IWL_ERROR("0x%08x\t%04u\n", time
, ev
); /* data, ev */
4419 data
= iwl3945_read_targ_mem(priv
, ptr
);
4421 IWL_ERROR("%010u\t0x%08x\t%04u\n", time
, data
, ev
);
4426 static void iwl3945_dump_nic_event_log(struct iwl3945_priv
*priv
)
4429 u32 base
; /* SRAM byte address of event log header */
4430 u32 capacity
; /* event log capacity in # entries */
4431 u32 mode
; /* 0 - no timestamp, 1 - timestamp recorded */
4432 u32 num_wraps
; /* # times uCode wrapped to top of log */
4433 u32 next_entry
; /* index of next entry to be written by uCode */
4434 u32 size
; /* # entries that we'll print */
4436 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
4437 if (!iwl3945_hw_valid_rtc_data_addr(base
)) {
4438 IWL_ERROR("Invalid event log pointer 0x%08X\n", base
);
4442 rc
= iwl3945_grab_nic_access(priv
);
4444 IWL_WARNING("Can not read from adapter at this time.\n");
4448 /* event log header */
4449 capacity
= iwl3945_read_targ_mem(priv
, base
);
4450 mode
= iwl3945_read_targ_mem(priv
, base
+ (1 * sizeof(u32
)));
4451 num_wraps
= iwl3945_read_targ_mem(priv
, base
+ (2 * sizeof(u32
)));
4452 next_entry
= iwl3945_read_targ_mem(priv
, base
+ (3 * sizeof(u32
)));
4454 size
= num_wraps
? capacity
: next_entry
;
4456 /* bail out if nothing in log */
4458 IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
4459 iwl3945_release_nic_access(priv
);
4463 IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
4466 /* if uCode has wrapped back to top of log, start at the oldest entry,
4467 * i.e the next one that uCode would fill. */
4469 iwl3945_print_event_log(priv
, next_entry
,
4470 capacity
- next_entry
, mode
);
4472 /* (then/else) start at top of log */
4473 iwl3945_print_event_log(priv
, 0, next_entry
, mode
);
4475 iwl3945_release_nic_access(priv
);
4479 * iwl3945_irq_handle_error - called for HW or SW error interrupt from card
4481 static void iwl3945_irq_handle_error(struct iwl3945_priv
*priv
)
4483 /* Set the FW error flag -- cleared on iwl3945_down */
4484 set_bit(STATUS_FW_ERROR
, &priv
->status
);
4486 /* Cancel currently queued command. */
4487 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
4489 #ifdef CONFIG_IWL3945_DEBUG
4490 if (iwl3945_debug_level
& IWL_DL_FW_ERRORS
) {
4491 iwl3945_dump_nic_error_log(priv
);
4492 iwl3945_dump_nic_event_log(priv
);
4493 iwl3945_print_rx_config_cmd(&priv
->staging_rxon
);
4497 wake_up_interruptible(&priv
->wait_command_queue
);
4499 /* Keep the restart process from trying to send host
4500 * commands by clearing the INIT status bit */
4501 clear_bit(STATUS_READY
, &priv
->status
);
4503 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
4504 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_FW_ERRORS
,
4505 "Restarting adapter due to uCode error.\n");
4507 if (iwl3945_is_associated(priv
)) {
4508 memcpy(&priv
->recovery_rxon
, &priv
->active_rxon
,
4509 sizeof(priv
->recovery_rxon
));
4510 priv
->error_recovering
= 1;
4512 queue_work(priv
->workqueue
, &priv
->restart
);
4516 static void iwl3945_error_recovery(struct iwl3945_priv
*priv
)
4518 unsigned long flags
;
4520 memcpy(&priv
->staging_rxon
, &priv
->recovery_rxon
,
4521 sizeof(priv
->staging_rxon
));
4522 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
4523 iwl3945_commit_rxon(priv
);
4525 iwl3945_add_station(priv
, priv
->bssid
, 1, 0);
4527 spin_lock_irqsave(&priv
->lock
, flags
);
4528 priv
->assoc_id
= le16_to_cpu(priv
->staging_rxon
.assoc_id
);
4529 priv
->error_recovering
= 0;
4530 spin_unlock_irqrestore(&priv
->lock
, flags
);
4533 static void iwl3945_irq_tasklet(struct iwl3945_priv
*priv
)
4535 u32 inta
, handled
= 0;
4537 unsigned long flags
;
4538 #ifdef CONFIG_IWL3945_DEBUG
4542 spin_lock_irqsave(&priv
->lock
, flags
);
4544 /* Ack/clear/reset pending uCode interrupts.
4545 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
4546 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
4547 inta
= iwl3945_read32(priv
, CSR_INT
);
4548 iwl3945_write32(priv
, CSR_INT
, inta
);
4550 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
4551 * Any new interrupts that happen after this, either while we're
4552 * in this tasklet, or later, will show up in next ISR/tasklet. */
4553 inta_fh
= iwl3945_read32(priv
, CSR_FH_INT_STATUS
);
4554 iwl3945_write32(priv
, CSR_FH_INT_STATUS
, inta_fh
);
4556 #ifdef CONFIG_IWL3945_DEBUG
4557 if (iwl3945_debug_level
& IWL_DL_ISR
) {
4558 /* just for debug */
4559 inta_mask
= iwl3945_read32(priv
, CSR_INT_MASK
);
4560 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4561 inta
, inta_mask
, inta_fh
);
4565 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
4566 * atomic, make sure that inta covers all the interrupts that
4567 * we've discovered, even if FH interrupt came in just after
4568 * reading CSR_INT. */
4569 if (inta_fh
& CSR39_FH_INT_RX_MASK
)
4570 inta
|= CSR_INT_BIT_FH_RX
;
4571 if (inta_fh
& CSR39_FH_INT_TX_MASK
)
4572 inta
|= CSR_INT_BIT_FH_TX
;
4574 /* Now service all interrupt bits discovered above. */
4575 if (inta
& CSR_INT_BIT_HW_ERR
) {
4576 IWL_ERROR("Microcode HW error detected. Restarting.\n");
4578 /* Tell the device to stop sending interrupts */
4579 iwl3945_disable_interrupts(priv
);
4581 iwl3945_irq_handle_error(priv
);
4583 handled
|= CSR_INT_BIT_HW_ERR
;
4585 spin_unlock_irqrestore(&priv
->lock
, flags
);
4590 #ifdef CONFIG_IWL3945_DEBUG
4591 if (iwl3945_debug_level
& (IWL_DL_ISR
)) {
4592 /* NIC fires this, but we don't use it, redundant with WAKEUP */
4593 if (inta
& CSR_INT_BIT_SCD
)
4594 IWL_DEBUG_ISR("Scheduler finished to transmit "
4595 "the frame/frames.\n");
4597 /* Alive notification via Rx interrupt will do the real work */
4598 if (inta
& CSR_INT_BIT_ALIVE
)
4599 IWL_DEBUG_ISR("Alive interrupt\n");
4602 /* Safely ignore these bits for debug checks below */
4603 inta
&= ~(CSR_INT_BIT_SCD
| CSR_INT_BIT_ALIVE
);
4605 /* HW RF KILL switch toggled (4965 only) */
4606 if (inta
& CSR_INT_BIT_RF_KILL
) {
4608 if (!(iwl3945_read32(priv
, CSR_GP_CNTRL
) &
4609 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
))
4612 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_RF_KILL
| IWL_DL_ISR
,
4613 "RF_KILL bit toggled to %s.\n",
4614 hw_rf_kill
? "disable radio":"enable radio");
4616 /* Queue restart only if RF_KILL switch was set to "kill"
4617 * when we loaded driver, and is now set to "enable".
4618 * After we're Alive, RF_KILL gets handled by
4619 * iwl3945_rx_card_state_notif() */
4620 if (!hw_rf_kill
&& !test_bit(STATUS_ALIVE
, &priv
->status
)) {
4621 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
4622 queue_work(priv
->workqueue
, &priv
->restart
);
4625 handled
|= CSR_INT_BIT_RF_KILL
;
4628 /* Chip got too hot and stopped itself (4965 only) */
4629 if (inta
& CSR_INT_BIT_CT_KILL
) {
4630 IWL_ERROR("Microcode CT kill error detected.\n");
4631 handled
|= CSR_INT_BIT_CT_KILL
;
4634 /* Error detected by uCode */
4635 if (inta
& CSR_INT_BIT_SW_ERR
) {
4636 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
4638 iwl3945_irq_handle_error(priv
);
4639 handled
|= CSR_INT_BIT_SW_ERR
;
4642 /* uCode wakes up after power-down sleep */
4643 if (inta
& CSR_INT_BIT_WAKEUP
) {
4644 IWL_DEBUG_ISR("Wakeup interrupt\n");
4645 iwl3945_rx_queue_update_write_ptr(priv
, &priv
->rxq
);
4646 iwl3945_tx_queue_update_write_ptr(priv
, &priv
->txq
[0]);
4647 iwl3945_tx_queue_update_write_ptr(priv
, &priv
->txq
[1]);
4648 iwl3945_tx_queue_update_write_ptr(priv
, &priv
->txq
[2]);
4649 iwl3945_tx_queue_update_write_ptr(priv
, &priv
->txq
[3]);
4650 iwl3945_tx_queue_update_write_ptr(priv
, &priv
->txq
[4]);
4651 iwl3945_tx_queue_update_write_ptr(priv
, &priv
->txq
[5]);
4653 handled
|= CSR_INT_BIT_WAKEUP
;
4656 /* All uCode command responses, including Tx command responses,
4657 * Rx "responses" (frame-received notification), and other
4658 * notifications from uCode come through here*/
4659 if (inta
& (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
)) {
4660 iwl3945_rx_handle(priv
);
4661 handled
|= (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
);
4664 if (inta
& CSR_INT_BIT_FH_TX
) {
4665 IWL_DEBUG_ISR("Tx interrupt\n");
4667 iwl3945_write32(priv
, CSR_FH_INT_STATUS
, (1 << 6));
4668 if (!iwl3945_grab_nic_access(priv
)) {
4669 iwl3945_write_direct32(priv
,
4671 (ALM_FH_SRVC_CHNL
), 0x0);
4672 iwl3945_release_nic_access(priv
);
4674 handled
|= CSR_INT_BIT_FH_TX
;
4677 if (inta
& ~handled
)
4678 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta
& ~handled
);
4680 if (inta
& ~CSR_INI_SET_MASK
) {
4681 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
4682 inta
& ~CSR_INI_SET_MASK
);
4683 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh
);
4686 /* Re-enable all interrupts */
4687 iwl3945_enable_interrupts(priv
);
4689 #ifdef CONFIG_IWL3945_DEBUG
4690 if (iwl3945_debug_level
& (IWL_DL_ISR
)) {
4691 inta
= iwl3945_read32(priv
, CSR_INT
);
4692 inta_mask
= iwl3945_read32(priv
, CSR_INT_MASK
);
4693 inta_fh
= iwl3945_read32(priv
, CSR_FH_INT_STATUS
);
4694 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
4695 "flags 0x%08lx\n", inta
, inta_mask
, inta_fh
, flags
);
4698 spin_unlock_irqrestore(&priv
->lock
, flags
);
4701 static irqreturn_t
iwl3945_isr(int irq
, void *data
)
4703 struct iwl3945_priv
*priv
= data
;
4704 u32 inta
, inta_mask
;
4709 spin_lock(&priv
->lock
);
4711 /* Disable (but don't clear!) interrupts here to avoid
4712 * back-to-back ISRs and sporadic interrupts from our NIC.
4713 * If we have something to service, the tasklet will re-enable ints.
4714 * If we *don't* have something, we'll re-enable before leaving here. */
4715 inta_mask
= iwl3945_read32(priv
, CSR_INT_MASK
); /* just for debug */
4716 iwl3945_write32(priv
, CSR_INT_MASK
, 0x00000000);
4718 /* Discover which interrupts are active/pending */
4719 inta
= iwl3945_read32(priv
, CSR_INT
);
4720 inta_fh
= iwl3945_read32(priv
, CSR_FH_INT_STATUS
);
4722 /* Ignore interrupt if there's nothing in NIC to service.
4723 * This may be due to IRQ shared with another device,
4724 * or due to sporadic interrupts thrown from our NIC. */
4725 if (!inta
&& !inta_fh
) {
4726 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
4730 if ((inta
== 0xFFFFFFFF) || ((inta
& 0xFFFFFFF0) == 0xa5a5a5a0)) {
4731 /* Hardware disappeared */
4732 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta
);
4736 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4737 inta
, inta_mask
, inta_fh
);
4739 inta
&= ~CSR_INT_BIT_SCD
;
4741 /* iwl3945_irq_tasklet() will service interrupts and re-enable them */
4742 if (likely(inta
|| inta_fh
))
4743 tasklet_schedule(&priv
->irq_tasklet
);
4745 spin_unlock(&priv
->lock
);
4750 /* re-enable interrupts here since we don't have anything to service. */
4751 iwl3945_enable_interrupts(priv
);
4752 spin_unlock(&priv
->lock
);
4756 /************************** EEPROM BANDS ****************************
4758 * The iwl3945_eeprom_band definitions below provide the mapping from the
4759 * EEPROM contents to the specific channel number supported for each
4762 * For example, iwl3945_priv->eeprom.band_3_channels[4] from the band_3
4763 * definition below maps to physical channel 42 in the 5.2GHz spectrum.
4764 * The specific geography and calibration information for that channel
4765 * is contained in the eeprom map itself.
4767 * During init, we copy the eeprom information and channel map
4768 * information into priv->channel_info_24/52 and priv->channel_map_24/52
4770 * channel_map_24/52 provides the index in the channel_info array for a
4771 * given channel. We have to have two separate maps as there is channel
4772 * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
4775 * A value of 0xff stored in the channel_map indicates that the channel
4776 * is not supported by the hardware at all.
4778 * A value of 0xfe in the channel_map indicates that the channel is not
4779 * valid for Tx with the current hardware. This means that
4780 * while the system can tune and receive on a given channel, it may not
4781 * be able to associate or transmit any frames on that
4782 * channel. There is no corresponding channel information for that
4785 *********************************************************************/
4788 static const u8 iwl3945_eeprom_band_1
[14] = {
4789 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
4793 static const u8 iwl3945_eeprom_band_2
[] = { /* 4915-5080MHz */
4794 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
4797 static const u8 iwl3945_eeprom_band_3
[] = { /* 5170-5320MHz */
4798 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
4801 static const u8 iwl3945_eeprom_band_4
[] = { /* 5500-5700MHz */
4802 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
4805 static const u8 iwl3945_eeprom_band_5
[] = { /* 5725-5825MHz */
4806 145, 149, 153, 157, 161, 165
4809 static void iwl3945_init_band_reference(const struct iwl3945_priv
*priv
, int band
,
4810 int *eeprom_ch_count
,
4811 const struct iwl3945_eeprom_channel
4813 const u8
**eeprom_ch_index
)
4816 case 1: /* 2.4GHz band */
4817 *eeprom_ch_count
= ARRAY_SIZE(iwl3945_eeprom_band_1
);
4818 *eeprom_ch_info
= priv
->eeprom
.band_1_channels
;
4819 *eeprom_ch_index
= iwl3945_eeprom_band_1
;
4821 case 2: /* 4.9GHz band */
4822 *eeprom_ch_count
= ARRAY_SIZE(iwl3945_eeprom_band_2
);
4823 *eeprom_ch_info
= priv
->eeprom
.band_2_channels
;
4824 *eeprom_ch_index
= iwl3945_eeprom_band_2
;
4826 case 3: /* 5.2GHz band */
4827 *eeprom_ch_count
= ARRAY_SIZE(iwl3945_eeprom_band_3
);
4828 *eeprom_ch_info
= priv
->eeprom
.band_3_channels
;
4829 *eeprom_ch_index
= iwl3945_eeprom_band_3
;
4831 case 4: /* 5.5GHz band */
4832 *eeprom_ch_count
= ARRAY_SIZE(iwl3945_eeprom_band_4
);
4833 *eeprom_ch_info
= priv
->eeprom
.band_4_channels
;
4834 *eeprom_ch_index
= iwl3945_eeprom_band_4
;
4836 case 5: /* 5.7GHz band */
4837 *eeprom_ch_count
= ARRAY_SIZE(iwl3945_eeprom_band_5
);
4838 *eeprom_ch_info
= priv
->eeprom
.band_5_channels
;
4839 *eeprom_ch_index
= iwl3945_eeprom_band_5
;
4848 * iwl3945_get_channel_info - Find driver's private channel info
4850 * Based on band and channel number.
4852 const struct iwl3945_channel_info
*iwl3945_get_channel_info(const struct iwl3945_priv
*priv
,
4853 enum ieee80211_band band
, u16 channel
)
4858 case IEEE80211_BAND_5GHZ
:
4859 for (i
= 14; i
< priv
->channel_count
; i
++) {
4860 if (priv
->channel_info
[i
].channel
== channel
)
4861 return &priv
->channel_info
[i
];
4865 case IEEE80211_BAND_2GHZ
:
4866 if (channel
>= 1 && channel
<= 14)
4867 return &priv
->channel_info
[channel
- 1];
4869 case IEEE80211_NUM_BANDS
:
4876 #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
4880 * iwl3945_init_channel_map - Set up driver's info for all possible channels
4882 static int iwl3945_init_channel_map(struct iwl3945_priv
*priv
)
4884 int eeprom_ch_count
= 0;
4885 const u8
*eeprom_ch_index
= NULL
;
4886 const struct iwl3945_eeprom_channel
*eeprom_ch_info
= NULL
;
4888 struct iwl3945_channel_info
*ch_info
;
4890 if (priv
->channel_count
) {
4891 IWL_DEBUG_INFO("Channel map already initialized.\n");
4895 if (priv
->eeprom
.version
< 0x2f) {
4896 IWL_WARNING("Unsupported EEPROM version: 0x%04X\n",
4897 priv
->eeprom
.version
);
4901 IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n");
4903 priv
->channel_count
=
4904 ARRAY_SIZE(iwl3945_eeprom_band_1
) +
4905 ARRAY_SIZE(iwl3945_eeprom_band_2
) +
4906 ARRAY_SIZE(iwl3945_eeprom_band_3
) +
4907 ARRAY_SIZE(iwl3945_eeprom_band_4
) +
4908 ARRAY_SIZE(iwl3945_eeprom_band_5
);
4910 IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv
->channel_count
);
4912 priv
->channel_info
= kzalloc(sizeof(struct iwl3945_channel_info
) *
4913 priv
->channel_count
, GFP_KERNEL
);
4914 if (!priv
->channel_info
) {
4915 IWL_ERROR("Could not allocate channel_info\n");
4916 priv
->channel_count
= 0;
4920 ch_info
= priv
->channel_info
;
4922 /* Loop through the 5 EEPROM bands adding them in order to the
4923 * channel map we maintain (that contains additional information than
4924 * what just in the EEPROM) */
4925 for (band
= 1; band
<= 5; band
++) {
4927 iwl3945_init_band_reference(priv
, band
, &eeprom_ch_count
,
4928 &eeprom_ch_info
, &eeprom_ch_index
);
4930 /* Loop through each band adding each of the channels */
4931 for (ch
= 0; ch
< eeprom_ch_count
; ch
++) {
4932 ch_info
->channel
= eeprom_ch_index
[ch
];
4933 ch_info
->band
= (band
== 1) ? IEEE80211_BAND_2GHZ
:
4934 IEEE80211_BAND_5GHZ
;
4936 /* permanently store EEPROM's channel regulatory flags
4937 * and max power in channel info database. */
4938 ch_info
->eeprom
= eeprom_ch_info
[ch
];
4940 /* Copy the run-time flags so they are there even on
4941 * invalid channels */
4942 ch_info
->flags
= eeprom_ch_info
[ch
].flags
;
4944 if (!(is_channel_valid(ch_info
))) {
4945 IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - "
4949 is_channel_a_band(ch_info
) ?
4955 /* Initialize regulatory-based run-time data */
4956 ch_info
->max_power_avg
= ch_info
->curr_txpow
=
4957 eeprom_ch_info
[ch
].max_power_avg
;
4958 ch_info
->scan_power
= eeprom_ch_info
[ch
].max_power_avg
;
4959 ch_info
->min_power
= 0;
4961 IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s%s(0x%02x"
4962 " %ddBm): Ad-Hoc %ssupported\n",
4964 is_channel_a_band(ch_info
) ?
4966 CHECK_AND_PRINT(VALID
),
4967 CHECK_AND_PRINT(IBSS
),
4968 CHECK_AND_PRINT(ACTIVE
),
4969 CHECK_AND_PRINT(RADAR
),
4970 CHECK_AND_PRINT(WIDE
),
4971 CHECK_AND_PRINT(NARROW
),
4972 CHECK_AND_PRINT(DFS
),
4973 eeprom_ch_info
[ch
].flags
,
4974 eeprom_ch_info
[ch
].max_power_avg
,
4975 ((eeprom_ch_info
[ch
].
4976 flags
& EEPROM_CHANNEL_IBSS
)
4977 && !(eeprom_ch_info
[ch
].
4978 flags
& EEPROM_CHANNEL_RADAR
))
4981 /* Set the user_txpower_limit to the highest power
4982 * supported by any channel */
4983 if (eeprom_ch_info
[ch
].max_power_avg
>
4984 priv
->user_txpower_limit
)
4985 priv
->user_txpower_limit
=
4986 eeprom_ch_info
[ch
].max_power_avg
;
4992 /* Set up txpower settings in driver for all channels */
4993 if (iwl3945_txpower_set_from_eeprom(priv
))
5000 * iwl3945_free_channel_map - undo allocations in iwl3945_init_channel_map
5002 static void iwl3945_free_channel_map(struct iwl3945_priv
*priv
)
5004 kfree(priv
->channel_info
);
5005 priv
->channel_count
= 0;
5008 /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
5009 * sending probe req. This should be set long enough to hear probe responses
5010 * from more than one AP. */
5011 #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
5012 #define IWL_ACTIVE_DWELL_TIME_52 (10)
5014 /* For faster active scanning, scan will move to the next channel if fewer than
5015 * PLCP_QUIET_THRESH packets are heard on this channel within
5016 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
5017 * time if it's a quiet channel (nothing responded to our probe, and there's
5018 * no other traffic).
5019 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
5020 #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
5021 #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
5023 /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
5024 * Must be set longer than active dwell time.
5025 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
5026 #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
5027 #define IWL_PASSIVE_DWELL_TIME_52 (10)
5028 #define IWL_PASSIVE_DWELL_BASE (100)
5029 #define IWL_CHANNEL_TUNE_TIME 5
5031 static inline u16
iwl3945_get_active_dwell_time(struct iwl3945_priv
*priv
,
5032 enum ieee80211_band band
)
5034 if (band
== IEEE80211_BAND_5GHZ
)
5035 return IWL_ACTIVE_DWELL_TIME_52
;
5037 return IWL_ACTIVE_DWELL_TIME_24
;
5040 static u16
iwl3945_get_passive_dwell_time(struct iwl3945_priv
*priv
,
5041 enum ieee80211_band band
)
5043 u16 active
= iwl3945_get_active_dwell_time(priv
, band
);
5044 u16 passive
= (band
== IEEE80211_BAND_2GHZ
) ?
5045 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_24
:
5046 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_52
;
5048 if (iwl3945_is_associated(priv
)) {
5049 /* If we're associated, we clamp the maximum passive
5050 * dwell time to be 98% of the beacon interval (minus
5051 * 2 * channel tune time) */
5052 passive
= priv
->beacon_int
;
5053 if ((passive
> IWL_PASSIVE_DWELL_BASE
) || !passive
)
5054 passive
= IWL_PASSIVE_DWELL_BASE
;
5055 passive
= (passive
* 98) / 100 - IWL_CHANNEL_TUNE_TIME
* 2;
5058 if (passive
<= active
)
5059 passive
= active
+ 1;
5064 static int iwl3945_get_channels_for_scan(struct iwl3945_priv
*priv
,
5065 enum ieee80211_band band
,
5066 u8 is_active
, u8 direct_mask
,
5067 struct iwl3945_scan_channel
*scan_ch
)
5069 const struct ieee80211_channel
*channels
= NULL
;
5070 const struct ieee80211_supported_band
*sband
;
5071 const struct iwl3945_channel_info
*ch_info
;
5072 u16 passive_dwell
= 0;
5073 u16 active_dwell
= 0;
5076 sband
= iwl3945_get_band(priv
, band
);
5080 channels
= sband
->channels
;
5082 active_dwell
= iwl3945_get_active_dwell_time(priv
, band
);
5083 passive_dwell
= iwl3945_get_passive_dwell_time(priv
, band
);
5085 for (i
= 0, added
= 0; i
< sband
->n_channels
; i
++) {
5086 if (channels
[i
].hw_value
==
5087 le16_to_cpu(priv
->active_rxon
.channel
)) {
5088 if (iwl3945_is_associated(priv
)) {
5090 ("Skipping current channel %d\n",
5091 le16_to_cpu(priv
->active_rxon
.channel
));
5094 } else if (priv
->only_active_channel
)
5097 scan_ch
->channel
= channels
[i
].hw_value
;
5099 ch_info
= iwl3945_get_channel_info(priv
, band
, scan_ch
->channel
);
5100 if (!is_channel_valid(ch_info
)) {
5101 IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
5106 if (!is_active
|| is_channel_passive(ch_info
) ||
5107 (channels
[i
].flags
& IEEE80211_CHAN_PASSIVE_SCAN
))
5108 scan_ch
->type
= 0; /* passive */
5110 scan_ch
->type
= 1; /* active */
5112 if (scan_ch
->type
& 1)
5113 scan_ch
->type
|= (direct_mask
<< 1);
5115 if (is_channel_narrow(ch_info
))
5116 scan_ch
->type
|= (1 << 7);
5118 scan_ch
->active_dwell
= cpu_to_le16(active_dwell
);
5119 scan_ch
->passive_dwell
= cpu_to_le16(passive_dwell
);
5121 /* Set txpower levels to defaults */
5122 scan_ch
->tpc
.dsp_atten
= 110;
5123 /* scan_pwr_info->tpc.dsp_atten; */
5125 /*scan_pwr_info->tpc.tx_gain; */
5126 if (band
== IEEE80211_BAND_5GHZ
)
5127 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (3 << 3)) | 3;
5129 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (5 << 3));
5130 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
5132 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
5136 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
5138 (scan_ch
->type
& 1) ? "ACTIVE" : "PASSIVE",
5139 (scan_ch
->type
& 1) ?
5140 active_dwell
: passive_dwell
);
5146 IWL_DEBUG_SCAN("total channels to scan %d \n", added
);
5150 static void iwl3945_init_hw_rates(struct iwl3945_priv
*priv
,
5151 struct ieee80211_rate
*rates
)
5155 for (i
= 0; i
< IWL_RATE_COUNT
; i
++) {
5156 rates
[i
].bitrate
= iwl3945_rates
[i
].ieee
* 5;
5157 rates
[i
].hw_value
= i
; /* Rate scaling will work on indexes */
5158 rates
[i
].hw_value_short
= i
;
5160 if ((i
> IWL_LAST_OFDM_RATE
) || (i
< IWL_FIRST_OFDM_RATE
)) {
5162 * If CCK != 1M then set short preamble rate flag.
5164 rates
[i
].flags
|= (iwl3945_rates
[i
].plcp
== 10) ?
5165 0 : IEEE80211_RATE_SHORT_PREAMBLE
;
5171 * iwl3945_init_geos - Initialize mac80211's geo/channel info based from eeprom
5173 static int iwl3945_init_geos(struct iwl3945_priv
*priv
)
5175 struct iwl3945_channel_info
*ch
;
5176 struct ieee80211_supported_band
*sband
;
5177 struct ieee80211_channel
*channels
;
5178 struct ieee80211_channel
*geo_ch
;
5179 struct ieee80211_rate
*rates
;
5182 if (priv
->bands
[IEEE80211_BAND_2GHZ
].n_bitrates
||
5183 priv
->bands
[IEEE80211_BAND_5GHZ
].n_bitrates
) {
5184 IWL_DEBUG_INFO("Geography modes already initialized.\n");
5185 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
5189 channels
= kzalloc(sizeof(struct ieee80211_channel
) *
5190 priv
->channel_count
, GFP_KERNEL
);
5194 rates
= kzalloc((sizeof(struct ieee80211_rate
) * (IWL_RATE_COUNT
+ 1)),
5201 /* 5.2GHz channels start after the 2.4GHz channels */
5202 sband
= &priv
->bands
[IEEE80211_BAND_5GHZ
];
5203 sband
->channels
= &channels
[ARRAY_SIZE(iwl3945_eeprom_band_1
)];
5205 sband
->bitrates
= &rates
[IWL_FIRST_OFDM_RATE
];
5206 sband
->n_bitrates
= IWL_RATE_COUNT
- IWL_FIRST_OFDM_RATE
;
5208 sband
= &priv
->bands
[IEEE80211_BAND_2GHZ
];
5209 sband
->channels
= channels
;
5211 sband
->bitrates
= rates
;
5212 sband
->n_bitrates
= IWL_RATE_COUNT
;
5214 priv
->ieee_channels
= channels
;
5215 priv
->ieee_rates
= rates
;
5217 iwl3945_init_hw_rates(priv
, rates
);
5219 for (i
= 0; i
< priv
->channel_count
; i
++) {
5220 ch
= &priv
->channel_info
[i
];
5222 /* FIXME: might be removed if scan is OK*/
5223 if (!is_channel_valid(ch
))
5226 if (is_channel_a_band(ch
))
5227 sband
= &priv
->bands
[IEEE80211_BAND_5GHZ
];
5229 sband
= &priv
->bands
[IEEE80211_BAND_2GHZ
];
5231 geo_ch
= &sband
->channels
[sband
->n_channels
++];
5233 geo_ch
->center_freq
= ieee80211_channel_to_frequency(ch
->channel
);
5234 geo_ch
->max_power
= ch
->max_power_avg
;
5235 geo_ch
->max_antenna_gain
= 0xff;
5236 geo_ch
->hw_value
= ch
->channel
;
5238 if (is_channel_valid(ch
)) {
5239 if (!(ch
->flags
& EEPROM_CHANNEL_IBSS
))
5240 geo_ch
->flags
|= IEEE80211_CHAN_NO_IBSS
;
5242 if (!(ch
->flags
& EEPROM_CHANNEL_ACTIVE
))
5243 geo_ch
->flags
|= IEEE80211_CHAN_PASSIVE_SCAN
;
5245 if (ch
->flags
& EEPROM_CHANNEL_RADAR
)
5246 geo_ch
->flags
|= IEEE80211_CHAN_RADAR
;
5248 if (ch
->max_power_avg
> priv
->max_channel_txpower_limit
)
5249 priv
->max_channel_txpower_limit
=
5252 geo_ch
->flags
|= IEEE80211_CHAN_DISABLED
;
5255 /* Save flags for reg domain usage */
5256 geo_ch
->orig_flags
= geo_ch
->flags
;
5258 IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n",
5259 ch
->channel
, geo_ch
->center_freq
,
5260 is_channel_a_band(ch
) ? "5.2" : "2.4",
5261 geo_ch
->flags
& IEEE80211_CHAN_DISABLED
?
5262 "restricted" : "valid",
5266 if ((priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
== 0) &&
5267 priv
->cfg
->sku
& IWL_SKU_A
) {
5268 printk(KERN_INFO DRV_NAME
5269 ": Incorrectly detected BG card as ABG. Please send "
5270 "your PCI ID 0x%04X:0x%04X to maintainer.\n",
5271 priv
->pci_dev
->device
, priv
->pci_dev
->subsystem_device
);
5272 priv
->cfg
->sku
&= ~IWL_SKU_A
;
5275 printk(KERN_INFO DRV_NAME
5276 ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
5277 priv
->bands
[IEEE80211_BAND_2GHZ
].n_channels
,
5278 priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
);
5280 priv
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &priv
->bands
[IEEE80211_BAND_2GHZ
];
5281 priv
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = &priv
->bands
[IEEE80211_BAND_5GHZ
];
5283 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
5289 * iwl3945_free_geos - undo allocations in iwl3945_init_geos
5291 static void iwl3945_free_geos(struct iwl3945_priv
*priv
)
5293 kfree(priv
->ieee_channels
);
5294 kfree(priv
->ieee_rates
);
5295 clear_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
5298 /******************************************************************************
5300 * uCode download functions
5302 ******************************************************************************/
5304 static void iwl3945_dealloc_ucode_pci(struct iwl3945_priv
*priv
)
5306 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
5307 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
5308 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
5309 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
5310 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
5311 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
5315 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
5316 * looking at all data.
5318 static int iwl3945_verify_inst_full(struct iwl3945_priv
*priv
, __le32
* image
, u32 len
)
5325 IWL_DEBUG_INFO("ucode inst image size is %u\n", len
);
5327 rc
= iwl3945_grab_nic_access(priv
);
5331 iwl3945_write_direct32(priv
, HBUS_TARG_MEM_RADDR
, RTC_INST_LOWER_BOUND
);
5334 for (; len
> 0; len
-= sizeof(u32
), image
++) {
5335 /* read data comes through single port, auto-incr addr */
5336 /* NOTE: Use the debugless read so we don't flood kernel log
5337 * if IWL_DL_IO is set */
5338 val
= _iwl3945_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
5339 if (val
!= le32_to_cpu(*image
)) {
5340 IWL_ERROR("uCode INST section is invalid at "
5341 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5342 save_len
- len
, val
, le32_to_cpu(*image
));
5350 iwl3945_release_nic_access(priv
);
5353 IWL_DEBUG_INFO("ucode image in INSTRUCTION memory is good\n");
5360 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
5361 * using sample data 100 bytes apart. If these sample points are good,
5362 * it's a pretty good bet that everything between them is good, too.
5364 static int iwl3945_verify_inst_sparse(struct iwl3945_priv
*priv
, __le32
*image
, u32 len
)
5371 IWL_DEBUG_INFO("ucode inst image size is %u\n", len
);
5373 rc
= iwl3945_grab_nic_access(priv
);
5377 for (i
= 0; i
< len
; i
+= 100, image
+= 100/sizeof(u32
)) {
5378 /* read data comes through single port, auto-incr addr */
5379 /* NOTE: Use the debugless read so we don't flood kernel log
5380 * if IWL_DL_IO is set */
5381 iwl3945_write_direct32(priv
, HBUS_TARG_MEM_RADDR
,
5382 i
+ RTC_INST_LOWER_BOUND
);
5383 val
= _iwl3945_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
5384 if (val
!= le32_to_cpu(*image
)) {
5385 #if 0 /* Enable this if you want to see details */
5386 IWL_ERROR("uCode INST section is invalid at "
5387 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5397 iwl3945_release_nic_access(priv
);
5404 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
5405 * and verify its contents
5407 static int iwl3945_verify_ucode(struct iwl3945_priv
*priv
)
5414 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
5415 len
= priv
->ucode_boot
.len
;
5416 rc
= iwl3945_verify_inst_sparse(priv
, image
, len
);
5418 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
5422 /* Try initialize */
5423 image
= (__le32
*)priv
->ucode_init
.v_addr
;
5424 len
= priv
->ucode_init
.len
;
5425 rc
= iwl3945_verify_inst_sparse(priv
, image
, len
);
5427 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
5431 /* Try runtime/protocol */
5432 image
= (__le32
*)priv
->ucode_code
.v_addr
;
5433 len
= priv
->ucode_code
.len
;
5434 rc
= iwl3945_verify_inst_sparse(priv
, image
, len
);
5436 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
5440 IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
5442 /* Since nothing seems to match, show first several data entries in
5443 * instruction SRAM, so maybe visual inspection will give a clue.
5444 * Selection of bootstrap image (vs. other images) is arbitrary. */
5445 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
5446 len
= priv
->ucode_boot
.len
;
5447 rc
= iwl3945_verify_inst_full(priv
, image
, len
);
5453 /* check contents of special bootstrap uCode SRAM */
5454 static int iwl3945_verify_bsm(struct iwl3945_priv
*priv
)
5456 __le32
*image
= priv
->ucode_boot
.v_addr
;
5457 u32 len
= priv
->ucode_boot
.len
;
5461 IWL_DEBUG_INFO("Begin verify bsm\n");
5463 /* verify BSM SRAM contents */
5464 val
= iwl3945_read_prph(priv
, BSM_WR_DWCOUNT_REG
);
5465 for (reg
= BSM_SRAM_LOWER_BOUND
;
5466 reg
< BSM_SRAM_LOWER_BOUND
+ len
;
5467 reg
+= sizeof(u32
), image
++) {
5468 val
= iwl3945_read_prph(priv
, reg
);
5469 if (val
!= le32_to_cpu(*image
)) {
5470 IWL_ERROR("BSM uCode verification failed at "
5471 "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
5472 BSM_SRAM_LOWER_BOUND
,
5473 reg
- BSM_SRAM_LOWER_BOUND
, len
,
5474 val
, le32_to_cpu(*image
));
5479 IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
5485 * iwl3945_load_bsm - Load bootstrap instructions
5489 * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
5490 * in special SRAM that does not power down during RFKILL. When powering back
5491 * up after power-saving sleeps (or during initial uCode load), the BSM loads
5492 * the bootstrap program into the on-board processor, and starts it.
5494 * The bootstrap program loads (via DMA) instructions and data for a new
5495 * program from host DRAM locations indicated by the host driver in the
5496 * BSM_DRAM_* registers. Once the new program is loaded, it starts
5499 * When initializing the NIC, the host driver points the BSM to the
5500 * "initialize" uCode image. This uCode sets up some internal data, then
5501 * notifies host via "initialize alive" that it is complete.
5503 * The host then replaces the BSM_DRAM_* pointer values to point to the
5504 * normal runtime uCode instructions and a backup uCode data cache buffer
5505 * (filled initially with starting data values for the on-board processor),
5506 * then triggers the "initialize" uCode to load and launch the runtime uCode,
5507 * which begins normal operation.
5509 * When doing a power-save shutdown, runtime uCode saves data SRAM into
5510 * the backup data cache in DRAM before SRAM is powered down.
5512 * When powering back up, the BSM loads the bootstrap program. This reloads
5513 * the runtime uCode instructions and the backup data cache into SRAM,
5514 * and re-launches the runtime uCode from where it left off.
5516 static int iwl3945_load_bsm(struct iwl3945_priv
*priv
)
5518 __le32
*image
= priv
->ucode_boot
.v_addr
;
5519 u32 len
= priv
->ucode_boot
.len
;
5529 IWL_DEBUG_INFO("Begin load bsm\n");
5531 /* make sure bootstrap program is no larger than BSM's SRAM size */
5532 if (len
> IWL_MAX_BSM_SIZE
)
5535 /* Tell bootstrap uCode where to find the "Initialize" uCode
5536 * in host DRAM ... host DRAM physical address bits 31:0 for 3945.
5537 * NOTE: iwl3945_initialize_alive_start() will replace these values,
5538 * after the "initialize" uCode has run, to point to
5539 * runtime/protocol instructions and backup data cache. */
5540 pinst
= priv
->ucode_init
.p_addr
;
5541 pdata
= priv
->ucode_init_data
.p_addr
;
5542 inst_len
= priv
->ucode_init
.len
;
5543 data_len
= priv
->ucode_init_data
.len
;
5545 rc
= iwl3945_grab_nic_access(priv
);
5549 iwl3945_write_prph(priv
, BSM_DRAM_INST_PTR_REG
, pinst
);
5550 iwl3945_write_prph(priv
, BSM_DRAM_DATA_PTR_REG
, pdata
);
5551 iwl3945_write_prph(priv
, BSM_DRAM_INST_BYTECOUNT_REG
, inst_len
);
5552 iwl3945_write_prph(priv
, BSM_DRAM_DATA_BYTECOUNT_REG
, data_len
);
5554 /* Fill BSM memory with bootstrap instructions */
5555 for (reg_offset
= BSM_SRAM_LOWER_BOUND
;
5556 reg_offset
< BSM_SRAM_LOWER_BOUND
+ len
;
5557 reg_offset
+= sizeof(u32
), image
++)
5558 _iwl3945_write_prph(priv
, reg_offset
,
5559 le32_to_cpu(*image
));
5561 rc
= iwl3945_verify_bsm(priv
);
5563 iwl3945_release_nic_access(priv
);
5567 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
5568 iwl3945_write_prph(priv
, BSM_WR_MEM_SRC_REG
, 0x0);
5569 iwl3945_write_prph(priv
, BSM_WR_MEM_DST_REG
,
5570 RTC_INST_LOWER_BOUND
);
5571 iwl3945_write_prph(priv
, BSM_WR_DWCOUNT_REG
, len
/ sizeof(u32
));
5573 /* Load bootstrap code into instruction SRAM now,
5574 * to prepare to load "initialize" uCode */
5575 iwl3945_write_prph(priv
, BSM_WR_CTRL_REG
,
5576 BSM_WR_CTRL_REG_BIT_START
);
5578 /* Wait for load of bootstrap uCode to finish */
5579 for (i
= 0; i
< 100; i
++) {
5580 done
= iwl3945_read_prph(priv
, BSM_WR_CTRL_REG
);
5581 if (!(done
& BSM_WR_CTRL_REG_BIT_START
))
5586 IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i
);
5588 IWL_ERROR("BSM write did not complete!\n");
5592 /* Enable future boot loads whenever power management unit triggers it
5593 * (e.g. when powering back up after power-save shutdown) */
5594 iwl3945_write_prph(priv
, BSM_WR_CTRL_REG
,
5595 BSM_WR_CTRL_REG_BIT_START_EN
);
5597 iwl3945_release_nic_access(priv
);
5602 static void iwl3945_nic_start(struct iwl3945_priv
*priv
)
5604 /* Remove all resets to allow NIC to operate */
5605 iwl3945_write32(priv
, CSR_RESET
, 0);
5609 * iwl3945_read_ucode - Read uCode images from disk file.
5611 * Copy into buffers for card to fetch via bus-mastering
5613 static int iwl3945_read_ucode(struct iwl3945_priv
*priv
)
5615 struct iwl3945_ucode
*ucode
;
5617 const struct firmware
*ucode_raw
;
5618 /* firmware file name contains uCode/driver compatibility version */
5619 const char *name
= priv
->cfg
->fw_name
;
5622 u32 ver
, inst_size
, data_size
, init_size
, init_data_size
, boot_size
;
5624 /* Ask kernel firmware_class module to get the boot firmware off disk.
5625 * request_firmware() is synchronous, file is in memory on return. */
5626 ret
= request_firmware(&ucode_raw
, name
, &priv
->pci_dev
->dev
);
5628 IWL_ERROR("%s firmware file req failed: Reason %d\n",
5633 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
5634 name
, ucode_raw
->size
);
5636 /* Make sure that we got at least our header! */
5637 if (ucode_raw
->size
< sizeof(*ucode
)) {
5638 IWL_ERROR("File size way too small!\n");
5643 /* Data from ucode file: header followed by uCode images */
5644 ucode
= (void *)ucode_raw
->data
;
5646 ver
= le32_to_cpu(ucode
->ver
);
5647 inst_size
= le32_to_cpu(ucode
->inst_size
);
5648 data_size
= le32_to_cpu(ucode
->data_size
);
5649 init_size
= le32_to_cpu(ucode
->init_size
);
5650 init_data_size
= le32_to_cpu(ucode
->init_data_size
);
5651 boot_size
= le32_to_cpu(ucode
->boot_size
);
5653 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver
);
5654 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", inst_size
);
5655 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", data_size
);
5656 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", init_size
);
5657 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", init_data_size
);
5658 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", boot_size
);
5660 /* Verify size of file vs. image size info in file's header */
5661 if (ucode_raw
->size
< sizeof(*ucode
) +
5662 inst_size
+ data_size
+ init_size
+
5663 init_data_size
+ boot_size
) {
5665 IWL_DEBUG_INFO("uCode file size %d too small\n",
5666 (int)ucode_raw
->size
);
5671 /* Verify that uCode images will fit in card's SRAM */
5672 if (inst_size
> IWL_MAX_INST_SIZE
) {
5673 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
5679 if (data_size
> IWL_MAX_DATA_SIZE
) {
5680 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
5685 if (init_size
> IWL_MAX_INST_SIZE
) {
5686 IWL_DEBUG_INFO("uCode init instr len %d too large to fit in\n",
5691 if (init_data_size
> IWL_MAX_DATA_SIZE
) {
5692 IWL_DEBUG_INFO("uCode init data len %d too large to fit in\n",
5697 if (boot_size
> IWL_MAX_BSM_SIZE
) {
5698 IWL_DEBUG_INFO("uCode boot instr len %d too large to fit in\n",
5704 /* Allocate ucode buffers for card's bus-master loading ... */
5706 /* Runtime instructions and 2 copies of data:
5707 * 1) unmodified from disk
5708 * 2) backup cache for save/restore during power-downs */
5709 priv
->ucode_code
.len
= inst_size
;
5710 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
5712 priv
->ucode_data
.len
= data_size
;
5713 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
5715 priv
->ucode_data_backup
.len
= data_size
;
5716 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
5718 if (!priv
->ucode_code
.v_addr
|| !priv
->ucode_data
.v_addr
||
5719 !priv
->ucode_data_backup
.v_addr
)
5722 /* Initialization instructions and data */
5723 if (init_size
&& init_data_size
) {
5724 priv
->ucode_init
.len
= init_size
;
5725 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
5727 priv
->ucode_init_data
.len
= init_data_size
;
5728 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
5730 if (!priv
->ucode_init
.v_addr
|| !priv
->ucode_init_data
.v_addr
)
5734 /* Bootstrap (instructions only, no data) */
5736 priv
->ucode_boot
.len
= boot_size
;
5737 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
5739 if (!priv
->ucode_boot
.v_addr
)
5743 /* Copy images into buffers for card's bus-master reads ... */
5745 /* Runtime instructions (first block of data in file) */
5746 src
= &ucode
->data
[0];
5747 len
= priv
->ucode_code
.len
;
5748 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len
);
5749 memcpy(priv
->ucode_code
.v_addr
, src
, len
);
5750 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
5751 priv
->ucode_code
.v_addr
, (u32
)priv
->ucode_code
.p_addr
);
5753 /* Runtime data (2nd block)
5754 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
5755 src
= &ucode
->data
[inst_size
];
5756 len
= priv
->ucode_data
.len
;
5757 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len
);
5758 memcpy(priv
->ucode_data
.v_addr
, src
, len
);
5759 memcpy(priv
->ucode_data_backup
.v_addr
, src
, len
);
5761 /* Initialization instructions (3rd block) */
5763 src
= &ucode
->data
[inst_size
+ data_size
];
5764 len
= priv
->ucode_init
.len
;
5765 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
5767 memcpy(priv
->ucode_init
.v_addr
, src
, len
);
5770 /* Initialization data (4th block) */
5771 if (init_data_size
) {
5772 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
];
5773 len
= priv
->ucode_init_data
.len
;
5774 IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n",
5776 memcpy(priv
->ucode_init_data
.v_addr
, src
, len
);
5779 /* Bootstrap instructions (5th block) */
5780 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
+ init_data_size
];
5781 len
= priv
->ucode_boot
.len
;
5782 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n",
5784 memcpy(priv
->ucode_boot
.v_addr
, src
, len
);
5786 /* We have our copies now, allow OS release its copies */
5787 release_firmware(ucode_raw
);
5791 IWL_ERROR("failed to allocate pci memory\n");
5793 iwl3945_dealloc_ucode_pci(priv
);
5796 release_firmware(ucode_raw
);
5804 * iwl3945_set_ucode_ptrs - Set uCode address location
5806 * Tell initialization uCode where to find runtime uCode.
5808 * BSM registers initially contain pointers to initialization uCode.
5809 * We need to replace them to load runtime uCode inst and data,
5810 * and to save runtime data when powering down.
5812 static int iwl3945_set_ucode_ptrs(struct iwl3945_priv
*priv
)
5817 unsigned long flags
;
5819 /* bits 31:0 for 3945 */
5820 pinst
= priv
->ucode_code
.p_addr
;
5821 pdata
= priv
->ucode_data_backup
.p_addr
;
5823 spin_lock_irqsave(&priv
->lock
, flags
);
5824 rc
= iwl3945_grab_nic_access(priv
);
5826 spin_unlock_irqrestore(&priv
->lock
, flags
);
5830 /* Tell bootstrap uCode where to find image to load */
5831 iwl3945_write_prph(priv
, BSM_DRAM_INST_PTR_REG
, pinst
);
5832 iwl3945_write_prph(priv
, BSM_DRAM_DATA_PTR_REG
, pdata
);
5833 iwl3945_write_prph(priv
, BSM_DRAM_DATA_BYTECOUNT_REG
,
5834 priv
->ucode_data
.len
);
5836 /* Inst bytecount must be last to set up, bit 31 signals uCode
5837 * that all new ptr/size info is in place */
5838 iwl3945_write_prph(priv
, BSM_DRAM_INST_BYTECOUNT_REG
,
5839 priv
->ucode_code
.len
| BSM_DRAM_INST_LOAD
);
5841 iwl3945_release_nic_access(priv
);
5843 spin_unlock_irqrestore(&priv
->lock
, flags
);
5845 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
5851 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
5853 * Called after REPLY_ALIVE notification received from "initialize" uCode.
5855 * Tell "initialize" uCode to go ahead and load the runtime uCode.
5857 static void iwl3945_init_alive_start(struct iwl3945_priv
*priv
)
5859 /* Check alive response for "valid" sign from uCode */
5860 if (priv
->card_alive_init
.is_valid
!= UCODE_VALID_OK
) {
5861 /* We had an error bringing up the hardware, so take it
5862 * all the way back down so we can try again */
5863 IWL_DEBUG_INFO("Initialize Alive failed.\n");
5867 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
5868 * This is a paranoid check, because we would not have gotten the
5869 * "initialize" alive if code weren't properly loaded. */
5870 if (iwl3945_verify_ucode(priv
)) {
5871 /* Runtime instruction load was bad;
5872 * take it all the way back down so we can try again */
5873 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
5877 /* Send pointers to protocol/runtime uCode image ... init code will
5878 * load and launch runtime uCode, which will send us another "Alive"
5880 IWL_DEBUG_INFO("Initialization Alive received.\n");
5881 if (iwl3945_set_ucode_ptrs(priv
)) {
5882 /* Runtime instruction load won't happen;
5883 * take it all the way back down so we can try again */
5884 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
5890 queue_work(priv
->workqueue
, &priv
->restart
);
5895 * iwl3945_alive_start - called after REPLY_ALIVE notification received
5896 * from protocol/runtime uCode (initialization uCode's
5897 * Alive gets handled by iwl3945_init_alive_start()).
5899 static void iwl3945_alive_start(struct iwl3945_priv
*priv
)
5902 int thermal_spin
= 0;
5905 IWL_DEBUG_INFO("Runtime Alive received.\n");
5907 if (priv
->card_alive
.is_valid
!= UCODE_VALID_OK
) {
5908 /* We had an error bringing up the hardware, so take it
5909 * all the way back down so we can try again */
5910 IWL_DEBUG_INFO("Alive failed.\n");
5914 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
5915 * This is a paranoid check, because we would not have gotten the
5916 * "runtime" alive if code weren't properly loaded. */
5917 if (iwl3945_verify_ucode(priv
)) {
5918 /* Runtime instruction load was bad;
5919 * take it all the way back down so we can try again */
5920 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
5924 iwl3945_clear_stations_table(priv
);
5926 rc
= iwl3945_grab_nic_access(priv
);
5928 IWL_WARNING("Can not read rfkill status from adapter\n");
5932 rfkill
= iwl3945_read_prph(priv
, APMG_RFKILL_REG
);
5933 IWL_DEBUG_INFO("RFKILL status: 0x%x\n", rfkill
);
5934 iwl3945_release_nic_access(priv
);
5937 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
5938 /* if rfkill is not on, then wait for thermal
5939 * sensor in adapter to kick in */
5940 while (iwl3945_hw_get_temperature(priv
) == 0) {
5946 IWL_DEBUG_INFO("Thermal calibration took %dus\n",
5949 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
5951 /* After the ALIVE response, we can send commands to 3945 uCode */
5952 set_bit(STATUS_ALIVE
, &priv
->status
);
5954 /* Clear out the uCode error bit if it is set */
5955 clear_bit(STATUS_FW_ERROR
, &priv
->status
);
5957 if (iwl3945_is_rfkill(priv
))
5960 ieee80211_start_queues(priv
->hw
);
5962 priv
->active_rate
= priv
->rates_mask
;
5963 priv
->active_rate_basic
= priv
->rates_mask
& IWL_BASIC_RATES_MASK
;
5965 iwl3945_send_power_mode(priv
, IWL_POWER_LEVEL(priv
->power_mode
));
5967 if (iwl3945_is_associated(priv
)) {
5968 struct iwl3945_rxon_cmd
*active_rxon
=
5969 (struct iwl3945_rxon_cmd
*)(&priv
->active_rxon
);
5971 memcpy(&priv
->staging_rxon
, &priv
->active_rxon
,
5972 sizeof(priv
->staging_rxon
));
5973 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
5975 /* Initialize our rx_config data */
5976 iwl3945_connection_init_rx_config(priv
);
5977 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
5980 /* Configure Bluetooth device coexistence support */
5981 iwl3945_send_bt_config(priv
);
5983 /* Configure the adapter for unassociated operation */
5984 iwl3945_commit_rxon(priv
);
5986 /* At this point, the NIC is initialized and operational */
5987 priv
->notif_missed_beacons
= 0;
5988 set_bit(STATUS_READY
, &priv
->status
);
5990 iwl3945_reg_txpower_periodic(priv
);
5992 IWL_DEBUG_INFO("ALIVE processing complete.\n");
5993 wake_up_interruptible(&priv
->wait_command_queue
);
5995 if (priv
->error_recovering
)
5996 iwl3945_error_recovery(priv
);
6001 queue_work(priv
->workqueue
, &priv
->restart
);
6004 static void iwl3945_cancel_deferred_work(struct iwl3945_priv
*priv
);
6006 static void __iwl3945_down(struct iwl3945_priv
*priv
)
6008 unsigned long flags
;
6009 int exit_pending
= test_bit(STATUS_EXIT_PENDING
, &priv
->status
);
6010 struct ieee80211_conf
*conf
= NULL
;
6012 IWL_DEBUG_INFO(DRV_NAME
" is going down\n");
6014 conf
= ieee80211_get_hw_conf(priv
->hw
);
6017 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
6019 iwl3945_clear_stations_table(priv
);
6021 /* Unblock any waiting calls */
6022 wake_up_interruptible_all(&priv
->wait_command_queue
);
6024 /* Wipe out the EXIT_PENDING status bit if we are not actually
6025 * exiting the module */
6027 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
6029 /* stop and reset the on-board processor */
6030 iwl3945_write32(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_NEVO_RESET
);
6032 /* tell the device to stop sending interrupts */
6033 iwl3945_disable_interrupts(priv
);
6035 if (priv
->mac80211_registered
)
6036 ieee80211_stop_queues(priv
->hw
);
6038 /* If we have not previously called iwl3945_init() then
6039 * clear all bits but the RF Kill and SUSPEND bits and return */
6040 if (!iwl3945_is_init(priv
)) {
6041 priv
->status
= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
6043 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
6045 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
6046 STATUS_GEO_CONFIGURED
|
6047 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
6052 /* ...otherwise clear out all the status bits but the RF Kill and
6053 * SUSPEND bits and continue taking the NIC down. */
6054 priv
->status
&= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
6056 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
6058 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
6059 STATUS_GEO_CONFIGURED
|
6060 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
6062 test_bit(STATUS_FW_ERROR
, &priv
->status
) <<
6065 spin_lock_irqsave(&priv
->lock
, flags
);
6066 iwl3945_clear_bit(priv
, CSR_GP_CNTRL
, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
6067 spin_unlock_irqrestore(&priv
->lock
, flags
);
6069 iwl3945_hw_txq_ctx_stop(priv
);
6070 iwl3945_hw_rxq_stop(priv
);
6072 spin_lock_irqsave(&priv
->lock
, flags
);
6073 if (!iwl3945_grab_nic_access(priv
)) {
6074 iwl3945_write_prph(priv
, APMG_CLK_DIS_REG
,
6075 APMG_CLK_VAL_DMA_CLK_RQT
);
6076 iwl3945_release_nic_access(priv
);
6078 spin_unlock_irqrestore(&priv
->lock
, flags
);
6082 iwl3945_hw_nic_stop_master(priv
);
6083 iwl3945_set_bit(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_SW_RESET
);
6084 iwl3945_hw_nic_reset(priv
);
6087 memset(&priv
->card_alive
, 0, sizeof(struct iwl3945_alive_resp
));
6089 if (priv
->ibss_beacon
)
6090 dev_kfree_skb(priv
->ibss_beacon
);
6091 priv
->ibss_beacon
= NULL
;
6093 /* clear out any free frames */
6094 iwl3945_clear_free_frames(priv
);
6097 static void iwl3945_down(struct iwl3945_priv
*priv
)
6099 mutex_lock(&priv
->mutex
);
6100 __iwl3945_down(priv
);
6101 mutex_unlock(&priv
->mutex
);
6103 iwl3945_cancel_deferred_work(priv
);
6106 #define MAX_HW_RESTARTS 5
6108 static int __iwl3945_up(struct iwl3945_priv
*priv
)
6112 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
6113 IWL_WARNING("Exit pending; will not bring the NIC up\n");
6117 if (test_bit(STATUS_RF_KILL_SW
, &priv
->status
)) {
6118 IWL_WARNING("Radio disabled by SW RF kill (module "
6123 if (!priv
->ucode_data_backup
.v_addr
|| !priv
->ucode_data
.v_addr
) {
6124 IWL_ERROR("ucode not available for device bringup\n");
6128 /* If platform's RF_KILL switch is NOT set to KILL */
6129 if (iwl3945_read32(priv
, CSR_GP_CNTRL
) &
6130 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
)
6131 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
6133 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
6134 if (!test_bit(STATUS_IN_SUSPEND
, &priv
->status
)) {
6135 IWL_WARNING("Radio disabled by HW RF Kill switch\n");
6140 iwl3945_write32(priv
, CSR_INT
, 0xFFFFFFFF);
6142 rc
= iwl3945_hw_nic_init(priv
);
6144 IWL_ERROR("Unable to int nic\n");
6148 /* make sure rfkill handshake bits are cleared */
6149 iwl3945_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
6150 iwl3945_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
6151 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
6153 /* clear (again), then enable host interrupts */
6154 iwl3945_write32(priv
, CSR_INT
, 0xFFFFFFFF);
6155 iwl3945_enable_interrupts(priv
);
6157 /* really make sure rfkill handshake bits are cleared */
6158 iwl3945_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
6159 iwl3945_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
6161 /* Copy original ucode data image from disk into backup cache.
6162 * This will be used to initialize the on-board processor's
6163 * data SRAM for a clean start when the runtime program first loads. */
6164 memcpy(priv
->ucode_data_backup
.v_addr
, priv
->ucode_data
.v_addr
,
6165 priv
->ucode_data
.len
);
6167 /* We return success when we resume from suspend and rf_kill is on. */
6168 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
6171 for (i
= 0; i
< MAX_HW_RESTARTS
; i
++) {
6173 iwl3945_clear_stations_table(priv
);
6175 /* load bootstrap state machine,
6176 * load bootstrap program into processor's memory,
6177 * prepare to load the "initialize" uCode */
6178 rc
= iwl3945_load_bsm(priv
);
6181 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc
);
6185 /* start card; "initialize" will load runtime ucode */
6186 iwl3945_nic_start(priv
);
6188 IWL_DEBUG_INFO(DRV_NAME
" is coming up\n");
6193 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
6194 __iwl3945_down(priv
);
6196 /* tried to restart and config the device for as long as our
6197 * patience could withstand */
6198 IWL_ERROR("Unable to initialize device after %d attempts.\n", i
);
6203 /*****************************************************************************
6205 * Workqueue callbacks
6207 *****************************************************************************/
6209 static void iwl3945_bg_init_alive_start(struct work_struct
*data
)
6211 struct iwl3945_priv
*priv
=
6212 container_of(data
, struct iwl3945_priv
, init_alive_start
.work
);
6214 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6217 mutex_lock(&priv
->mutex
);
6218 iwl3945_init_alive_start(priv
);
6219 mutex_unlock(&priv
->mutex
);
6222 static void iwl3945_bg_alive_start(struct work_struct
*data
)
6224 struct iwl3945_priv
*priv
=
6225 container_of(data
, struct iwl3945_priv
, alive_start
.work
);
6227 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6230 mutex_lock(&priv
->mutex
);
6231 iwl3945_alive_start(priv
);
6232 mutex_unlock(&priv
->mutex
);
6235 static void iwl3945_bg_rf_kill(struct work_struct
*work
)
6237 struct iwl3945_priv
*priv
= container_of(work
, struct iwl3945_priv
, rf_kill
);
6239 wake_up_interruptible(&priv
->wait_command_queue
);
6241 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6244 mutex_lock(&priv
->mutex
);
6246 if (!iwl3945_is_rfkill(priv
)) {
6247 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_RF_KILL
,
6248 "HW and/or SW RF Kill no longer active, restarting "
6250 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6251 queue_work(priv
->workqueue
, &priv
->restart
);
6254 if (!test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
6255 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
6256 "disabled by SW switch\n");
6258 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
6259 "Kill switch must be turned off for "
6260 "wireless networking to work.\n");
6262 mutex_unlock(&priv
->mutex
);
6265 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
6267 static void iwl3945_bg_scan_check(struct work_struct
*data
)
6269 struct iwl3945_priv
*priv
=
6270 container_of(data
, struct iwl3945_priv
, scan_check
.work
);
6272 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6275 mutex_lock(&priv
->mutex
);
6276 if (test_bit(STATUS_SCANNING
, &priv
->status
) ||
6277 test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
6278 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_SCAN
,
6279 "Scan completion watchdog resetting adapter (%dms)\n",
6280 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG
));
6282 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6283 iwl3945_send_scan_abort(priv
);
6285 mutex_unlock(&priv
->mutex
);
6288 static void iwl3945_bg_request_scan(struct work_struct
*data
)
6290 struct iwl3945_priv
*priv
=
6291 container_of(data
, struct iwl3945_priv
, request_scan
);
6292 struct iwl3945_host_cmd cmd
= {
6293 .id
= REPLY_SCAN_CMD
,
6294 .len
= sizeof(struct iwl3945_scan_cmd
),
6295 .meta
.flags
= CMD_SIZE_HUGE
,
6298 struct iwl3945_scan_cmd
*scan
;
6299 struct ieee80211_conf
*conf
= NULL
;
6301 enum ieee80211_band band
;
6303 conf
= ieee80211_get_hw_conf(priv
->hw
);
6305 mutex_lock(&priv
->mutex
);
6307 if (!iwl3945_is_ready(priv
)) {
6308 IWL_WARNING("request scan called when driver not ready.\n");
6312 /* Make sure the scan wasn't cancelled before this queued work
6313 * was given the chance to run... */
6314 if (!test_bit(STATUS_SCANNING
, &priv
->status
))
6317 /* This should never be called or scheduled if there is currently
6318 * a scan active in the hardware. */
6319 if (test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
6320 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
6321 "Ignoring second request.\n");
6326 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
6327 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
6331 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
6332 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6336 if (iwl3945_is_rfkill(priv
)) {
6337 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6341 if (!test_bit(STATUS_READY
, &priv
->status
)) {
6342 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
6346 if (!priv
->scan_bands
) {
6347 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
6352 priv
->scan
= kmalloc(sizeof(struct iwl3945_scan_cmd
) +
6353 IWL_MAX_SCAN_SIZE
, GFP_KERNEL
);
6360 memset(scan
, 0, sizeof(struct iwl3945_scan_cmd
) + IWL_MAX_SCAN_SIZE
);
6362 scan
->quiet_plcp_th
= IWL_PLCP_QUIET_THRESH
;
6363 scan
->quiet_time
= IWL_ACTIVE_QUIET_TIME
;
6365 if (iwl3945_is_associated(priv
)) {
6368 u32 suspend_time
= 100;
6369 u32 scan_suspend_time
= 100;
6370 unsigned long flags
;
6372 IWL_DEBUG_INFO("Scanning while associated...\n");
6374 spin_lock_irqsave(&priv
->lock
, flags
);
6375 interval
= priv
->beacon_int
;
6376 spin_unlock_irqrestore(&priv
->lock
, flags
);
6378 scan
->suspend_time
= 0;
6379 scan
->max_out_time
= cpu_to_le32(200 * 1024);
6381 interval
= suspend_time
;
6383 * suspend time format:
6384 * 0-19: beacon interval in usec (time before exec.)
6386 * 24-31: number of beacons (suspend between channels)
6389 extra
= (suspend_time
/ interval
) << 24;
6390 scan_suspend_time
= 0xFF0FFFFF &
6391 (extra
| ((suspend_time
% interval
) * 1024));
6393 scan
->suspend_time
= cpu_to_le32(scan_suspend_time
);
6394 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
6395 scan_suspend_time
, interval
);
6398 /* We should add the ability for user to lock to PASSIVE ONLY */
6399 if (priv
->one_direct_scan
) {
6401 ("Kicking off one direct scan for '%s'\n",
6402 iwl3945_escape_essid(priv
->direct_ssid
,
6403 priv
->direct_ssid_len
));
6404 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
6405 scan
->direct_scan
[0].len
= priv
->direct_ssid_len
;
6406 memcpy(scan
->direct_scan
[0].ssid
,
6407 priv
->direct_ssid
, priv
->direct_ssid_len
);
6409 } else if (!iwl3945_is_associated(priv
) && priv
->essid_len
) {
6410 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
6411 scan
->direct_scan
[0].len
= priv
->essid_len
;
6412 memcpy(scan
->direct_scan
[0].ssid
, priv
->essid
, priv
->essid_len
);
6417 /* We don't build a direct scan probe request; the uCode will do
6418 * that based on the direct_mask added to each channel entry */
6419 scan
->tx_cmd
.len
= cpu_to_le16(
6420 iwl3945_fill_probe_req(priv
, (struct ieee80211_mgmt
*)scan
->data
,
6421 IWL_MAX_SCAN_SIZE
- sizeof(*scan
), 0));
6422 scan
->tx_cmd
.tx_flags
= TX_CMD_FLG_SEQ_CTL_MSK
;
6423 scan
->tx_cmd
.sta_id
= priv
->hw_setting
.bcast_sta_id
;
6424 scan
->tx_cmd
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
6426 /* flags + rate selection */
6428 switch (priv
->scan_bands
) {
6430 scan
->flags
= RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
;
6431 scan
->tx_cmd
.rate
= IWL_RATE_1M_PLCP
;
6432 scan
->good_CRC_th
= 0;
6433 band
= IEEE80211_BAND_2GHZ
;
6437 scan
->tx_cmd
.rate
= IWL_RATE_6M_PLCP
;
6438 scan
->good_CRC_th
= IWL_GOOD_CRC_TH
;
6439 band
= IEEE80211_BAND_5GHZ
;
6443 IWL_WARNING("Invalid scan band count\n");
6447 /* select Rx antennas */
6448 scan
->flags
|= iwl3945_get_antenna_flags(priv
);
6450 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
)
6451 scan
->filter_flags
= RXON_FILTER_PROMISC_MSK
;
6455 ("Initiating direct scan for %s.\n",
6456 iwl3945_escape_essid(priv
->essid
, priv
->essid_len
));
6458 IWL_DEBUG_SCAN("Initiating indirect scan.\n");
6460 scan
->channel_count
=
6461 iwl3945_get_channels_for_scan(
6462 priv
, band
, 1, /* active */
6464 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
6466 cmd
.len
+= le16_to_cpu(scan
->tx_cmd
.len
) +
6467 scan
->channel_count
* sizeof(struct iwl3945_scan_channel
);
6469 scan
->len
= cpu_to_le16(cmd
.len
);
6471 set_bit(STATUS_SCAN_HW
, &priv
->status
);
6472 rc
= iwl3945_send_cmd_sync(priv
, &cmd
);
6476 queue_delayed_work(priv
->workqueue
, &priv
->scan_check
,
6477 IWL_SCAN_CHECK_WATCHDOG
);
6479 mutex_unlock(&priv
->mutex
);
6483 /* inform mac80211 scan aborted */
6484 queue_work(priv
->workqueue
, &priv
->scan_completed
);
6485 mutex_unlock(&priv
->mutex
);
6488 static void iwl3945_bg_up(struct work_struct
*data
)
6490 struct iwl3945_priv
*priv
= container_of(data
, struct iwl3945_priv
, up
);
6492 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6495 mutex_lock(&priv
->mutex
);
6497 mutex_unlock(&priv
->mutex
);
6500 static void iwl3945_bg_restart(struct work_struct
*data
)
6502 struct iwl3945_priv
*priv
= container_of(data
, struct iwl3945_priv
, restart
);
6504 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6508 queue_work(priv
->workqueue
, &priv
->up
);
6511 static void iwl3945_bg_rx_replenish(struct work_struct
*data
)
6513 struct iwl3945_priv
*priv
=
6514 container_of(data
, struct iwl3945_priv
, rx_replenish
);
6516 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6519 mutex_lock(&priv
->mutex
);
6520 iwl3945_rx_replenish(priv
);
6521 mutex_unlock(&priv
->mutex
);
6524 #define IWL_DELAY_NEXT_SCAN (HZ*2)
6526 static void iwl3945_bg_post_associate(struct work_struct
*data
)
6528 struct iwl3945_priv
*priv
= container_of(data
, struct iwl3945_priv
,
6529 post_associate
.work
);
6532 struct ieee80211_conf
*conf
= NULL
;
6533 DECLARE_MAC_BUF(mac
);
6535 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
6536 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__
);
6541 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
6543 print_mac(mac
, priv
->active_rxon
.bssid_addr
));
6545 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6548 mutex_lock(&priv
->mutex
);
6550 if (!priv
->vif
|| !priv
->is_open
) {
6551 mutex_unlock(&priv
->mutex
);
6554 iwl3945_scan_cancel_timeout(priv
, 200);
6556 conf
= ieee80211_get_hw_conf(priv
->hw
);
6558 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6559 iwl3945_commit_rxon(priv
);
6561 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl3945_rxon_time_cmd
));
6562 iwl3945_setup_rxon_timing(priv
);
6563 rc
= iwl3945_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
6564 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
6566 IWL_WARNING("REPLY_RXON_TIMING failed - "
6567 "Attempting to continue.\n");
6569 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
6571 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
6573 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
6574 priv
->assoc_id
, priv
->beacon_int
);
6576 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
6577 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
6579 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
6581 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
6582 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
6583 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
6585 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
6587 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
6588 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
6592 iwl3945_commit_rxon(priv
);
6594 switch (priv
->iw_mode
) {
6595 case IEEE80211_IF_TYPE_STA
:
6596 iwl3945_rate_scale_init(priv
->hw
, IWL_AP_ID
);
6599 case IEEE80211_IF_TYPE_IBSS
:
6601 /* clear out the station table */
6602 iwl3945_clear_stations_table(priv
);
6604 iwl3945_add_station(priv
, iwl3945_broadcast_addr
, 0, 0);
6605 iwl3945_add_station(priv
, priv
->bssid
, 0, 0);
6606 iwl3945_sync_sta(priv
, IWL_STA_ID
,
6607 (priv
->band
== IEEE80211_BAND_5GHZ
) ?
6608 IWL_RATE_6M_PLCP
: IWL_RATE_1M_PLCP
,
6610 iwl3945_rate_scale_init(priv
->hw
, IWL_STA_ID
);
6611 iwl3945_send_beacon_cmd(priv
);
6616 IWL_ERROR("%s Should not be called in %d mode\n",
6617 __FUNCTION__
, priv
->iw_mode
);
6621 iwl3945_sequence_reset(priv
);
6623 iwl3945_activate_qos(priv
, 0);
6625 /* we have just associated, don't start scan too early */
6626 priv
->next_scan_jiffies
= jiffies
+ IWL_DELAY_NEXT_SCAN
;
6627 mutex_unlock(&priv
->mutex
);
6630 static void iwl3945_bg_abort_scan(struct work_struct
*work
)
6632 struct iwl3945_priv
*priv
= container_of(work
, struct iwl3945_priv
, abort_scan
);
6634 if (!iwl3945_is_ready(priv
))
6637 mutex_lock(&priv
->mutex
);
6639 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
6640 iwl3945_send_scan_abort(priv
);
6642 mutex_unlock(&priv
->mutex
);
6645 static int iwl3945_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
);
6647 static void iwl3945_bg_scan_completed(struct work_struct
*work
)
6649 struct iwl3945_priv
*priv
=
6650 container_of(work
, struct iwl3945_priv
, scan_completed
);
6652 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_SCAN
, "SCAN complete scan\n");
6654 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6657 if (test_bit(STATUS_CONF_PENDING
, &priv
->status
))
6658 iwl3945_mac_config(priv
->hw
, ieee80211_get_hw_conf(priv
->hw
));
6660 ieee80211_scan_completed(priv
->hw
);
6662 /* Since setting the TXPOWER may have been deferred while
6663 * performing the scan, fire one off */
6664 mutex_lock(&priv
->mutex
);
6665 iwl3945_hw_reg_send_txpower(priv
);
6666 mutex_unlock(&priv
->mutex
);
6669 /*****************************************************************************
6671 * mac80211 entry point functions
6673 *****************************************************************************/
6675 #define UCODE_READY_TIMEOUT (2 * HZ)
6677 static int iwl3945_mac_start(struct ieee80211_hw
*hw
)
6679 struct iwl3945_priv
*priv
= hw
->priv
;
6682 IWL_DEBUG_MAC80211("enter\n");
6684 if (pci_enable_device(priv
->pci_dev
)) {
6685 IWL_ERROR("Fail to pci_enable_device\n");
6688 pci_restore_state(priv
->pci_dev
);
6689 pci_enable_msi(priv
->pci_dev
);
6691 ret
= request_irq(priv
->pci_dev
->irq
, iwl3945_isr
, IRQF_SHARED
,
6694 IWL_ERROR("Error allocating IRQ %d\n", priv
->pci_dev
->irq
);
6695 goto out_disable_msi
;
6698 /* we should be verifying the device is ready to be opened */
6699 mutex_lock(&priv
->mutex
);
6701 memset(&priv
->staging_rxon
, 0, sizeof(struct iwl3945_rxon_cmd
));
6702 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
6703 * ucode filename and max sizes are card-specific. */
6705 if (!priv
->ucode_code
.len
) {
6706 ret
= iwl3945_read_ucode(priv
);
6708 IWL_ERROR("Could not read microcode: %d\n", ret
);
6709 mutex_unlock(&priv
->mutex
);
6710 goto out_release_irq
;
6714 ret
= __iwl3945_up(priv
);
6716 mutex_unlock(&priv
->mutex
);
6719 goto out_release_irq
;
6721 IWL_DEBUG_INFO("Start UP work.\n");
6723 if (test_bit(STATUS_IN_SUSPEND
, &priv
->status
))
6726 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
6727 * mac80211 will not be run successfully. */
6728 ret
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
6729 test_bit(STATUS_READY
, &priv
->status
),
6730 UCODE_READY_TIMEOUT
);
6732 if (!test_bit(STATUS_READY
, &priv
->status
)) {
6733 IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n",
6734 jiffies_to_msecs(UCODE_READY_TIMEOUT
));
6736 goto out_release_irq
;
6741 IWL_DEBUG_MAC80211("leave\n");
6745 free_irq(priv
->pci_dev
->irq
, priv
);
6747 pci_disable_msi(priv
->pci_dev
);
6748 pci_disable_device(priv
->pci_dev
);
6750 IWL_DEBUG_MAC80211("leave - failed\n");
6754 static void iwl3945_mac_stop(struct ieee80211_hw
*hw
)
6756 struct iwl3945_priv
*priv
= hw
->priv
;
6758 IWL_DEBUG_MAC80211("enter\n");
6760 if (!priv
->is_open
) {
6761 IWL_DEBUG_MAC80211("leave - skip\n");
6767 if (iwl3945_is_ready_rf(priv
)) {
6768 /* stop mac, cancel any scan request and clear
6769 * RXON_FILTER_ASSOC_MSK BIT
6771 mutex_lock(&priv
->mutex
);
6772 iwl3945_scan_cancel_timeout(priv
, 100);
6773 cancel_delayed_work(&priv
->post_associate
);
6774 mutex_unlock(&priv
->mutex
);
6779 flush_workqueue(priv
->workqueue
);
6780 free_irq(priv
->pci_dev
->irq
, priv
);
6781 pci_disable_msi(priv
->pci_dev
);
6782 pci_save_state(priv
->pci_dev
);
6783 pci_disable_device(priv
->pci_dev
);
6785 IWL_DEBUG_MAC80211("leave\n");
6788 static int iwl3945_mac_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
6789 struct ieee80211_tx_control
*ctl
)
6791 struct iwl3945_priv
*priv
= hw
->priv
;
6793 IWL_DEBUG_MAC80211("enter\n");
6795 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
) {
6796 IWL_DEBUG_MAC80211("leave - monitor\n");
6800 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb
->len
,
6801 ctl
->tx_rate
->bitrate
);
6803 if (iwl3945_tx_skb(priv
, skb
, ctl
))
6804 dev_kfree_skb_any(skb
);
6806 IWL_DEBUG_MAC80211("leave\n");
6810 static int iwl3945_mac_add_interface(struct ieee80211_hw
*hw
,
6811 struct ieee80211_if_init_conf
*conf
)
6813 struct iwl3945_priv
*priv
= hw
->priv
;
6814 unsigned long flags
;
6815 DECLARE_MAC_BUF(mac
);
6817 IWL_DEBUG_MAC80211("enter: type %d\n", conf
->type
);
6820 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
6824 spin_lock_irqsave(&priv
->lock
, flags
);
6825 priv
->vif
= conf
->vif
;
6827 spin_unlock_irqrestore(&priv
->lock
, flags
);
6829 mutex_lock(&priv
->mutex
);
6831 if (conf
->mac_addr
) {
6832 IWL_DEBUG_MAC80211("Set: %s\n", print_mac(mac
, conf
->mac_addr
));
6833 memcpy(priv
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
6836 if (iwl3945_is_ready(priv
))
6837 iwl3945_set_mode(priv
, conf
->type
);
6839 mutex_unlock(&priv
->mutex
);
6841 IWL_DEBUG_MAC80211("leave\n");
6846 * iwl3945_mac_config - mac80211 config callback
6848 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
6849 * be set inappropriately and the driver currently sets the hardware up to
6850 * use it whenever needed.
6852 static int iwl3945_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
)
6854 struct iwl3945_priv
*priv
= hw
->priv
;
6855 const struct iwl3945_channel_info
*ch_info
;
6856 unsigned long flags
;
6859 mutex_lock(&priv
->mutex
);
6860 IWL_DEBUG_MAC80211("enter to channel %d\n", conf
->channel
->hw_value
);
6862 priv
->add_radiotap
= !!(conf
->flags
& IEEE80211_CONF_RADIOTAP
);
6864 if (!iwl3945_is_ready(priv
)) {
6865 IWL_DEBUG_MAC80211("leave - not ready\n");
6870 if (unlikely(!iwl3945_param_disable_hw_scan
&&
6871 test_bit(STATUS_SCANNING
, &priv
->status
))) {
6872 IWL_DEBUG_MAC80211("leave - scanning\n");
6873 set_bit(STATUS_CONF_PENDING
, &priv
->status
);
6874 mutex_unlock(&priv
->mutex
);
6878 spin_lock_irqsave(&priv
->lock
, flags
);
6880 ch_info
= iwl3945_get_channel_info(priv
, conf
->channel
->band
,
6881 conf
->channel
->hw_value
);
6882 if (!is_channel_valid(ch_info
)) {
6883 IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n",
6884 conf
->channel
->hw_value
, conf
->channel
->band
);
6885 IWL_DEBUG_MAC80211("leave - invalid channel\n");
6886 spin_unlock_irqrestore(&priv
->lock
, flags
);
6891 iwl3945_set_rxon_channel(priv
, conf
->channel
->band
, conf
->channel
->hw_value
);
6893 iwl3945_set_flags_for_phymode(priv
, conf
->channel
->band
);
6895 /* The list of supported rates and rate mask can be different
6896 * for each phymode; since the phymode may have changed, reset
6897 * the rate mask to what mac80211 lists */
6898 iwl3945_set_rate(priv
);
6900 spin_unlock_irqrestore(&priv
->lock
, flags
);
6902 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
6903 if (conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
) {
6904 iwl3945_hw_channel_switch(priv
, conf
->channel
);
6909 iwl3945_radio_kill_sw(priv
, !conf
->radio_enabled
);
6911 if (!conf
->radio_enabled
) {
6912 IWL_DEBUG_MAC80211("leave - radio disabled\n");
6916 if (iwl3945_is_rfkill(priv
)) {
6917 IWL_DEBUG_MAC80211("leave - RF kill\n");
6922 iwl3945_set_rate(priv
);
6924 if (memcmp(&priv
->active_rxon
,
6925 &priv
->staging_rxon
, sizeof(priv
->staging_rxon
)))
6926 iwl3945_commit_rxon(priv
);
6928 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
6930 IWL_DEBUG_MAC80211("leave\n");
6933 clear_bit(STATUS_CONF_PENDING
, &priv
->status
);
6934 mutex_unlock(&priv
->mutex
);
6938 static void iwl3945_config_ap(struct iwl3945_priv
*priv
)
6942 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6945 /* The following should be done only at AP bring up */
6946 if ((priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) == 0) {
6948 /* RXON - unassoc (to set timing command) */
6949 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6950 iwl3945_commit_rxon(priv
);
6953 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl3945_rxon_time_cmd
));
6954 iwl3945_setup_rxon_timing(priv
);
6955 rc
= iwl3945_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
6956 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
6958 IWL_WARNING("REPLY_RXON_TIMING failed - "
6959 "Attempting to continue.\n");
6961 /* FIXME: what should be the assoc_id for AP? */
6962 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
6963 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
6964 priv
->staging_rxon
.flags
|=
6965 RXON_FLG_SHORT_PREAMBLE_MSK
;
6967 priv
->staging_rxon
.flags
&=
6968 ~RXON_FLG_SHORT_PREAMBLE_MSK
;
6970 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
6971 if (priv
->assoc_capability
&
6972 WLAN_CAPABILITY_SHORT_SLOT_TIME
)
6973 priv
->staging_rxon
.flags
|=
6974 RXON_FLG_SHORT_SLOT_MSK
;
6976 priv
->staging_rxon
.flags
&=
6977 ~RXON_FLG_SHORT_SLOT_MSK
;
6979 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
6980 priv
->staging_rxon
.flags
&=
6981 ~RXON_FLG_SHORT_SLOT_MSK
;
6983 /* restore RXON assoc */
6984 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
6985 iwl3945_commit_rxon(priv
);
6986 iwl3945_add_station(priv
, iwl3945_broadcast_addr
, 0, 0);
6988 iwl3945_send_beacon_cmd(priv
);
6990 /* FIXME - we need to add code here to detect a totally new
6991 * configuration, reset the AP, unassoc, rxon timing, assoc,
6992 * clear sta table, add BCAST sta... */
6995 static int iwl3945_mac_config_interface(struct ieee80211_hw
*hw
,
6996 struct ieee80211_vif
*vif
,
6997 struct ieee80211_if_conf
*conf
)
6999 struct iwl3945_priv
*priv
= hw
->priv
;
7000 DECLARE_MAC_BUF(mac
);
7001 unsigned long flags
;
7007 if (priv
->vif
!= vif
) {
7008 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
7009 mutex_unlock(&priv
->mutex
);
7013 /* XXX: this MUST use conf->mac_addr */
7015 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
7016 (!conf
->beacon
|| !conf
->ssid_len
)) {
7018 ("Leaving in AP mode because HostAPD is not ready.\n");
7022 if (!iwl3945_is_alive(priv
))
7025 mutex_lock(&priv
->mutex
);
7028 IWL_DEBUG_MAC80211("bssid: %s\n",
7029 print_mac(mac
, conf
->bssid
));
7032 * very dubious code was here; the probe filtering flag is never set:
7034 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
7035 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
7038 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
7040 conf
->bssid
= priv
->mac_addr
;
7041 memcpy(priv
->bssid
, priv
->mac_addr
, ETH_ALEN
);
7042 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
7043 print_mac(mac
, conf
->bssid
));
7045 if (priv
->ibss_beacon
)
7046 dev_kfree_skb(priv
->ibss_beacon
);
7048 priv
->ibss_beacon
= conf
->beacon
;
7051 if (iwl3945_is_rfkill(priv
))
7054 if (conf
->bssid
&& !is_zero_ether_addr(conf
->bssid
) &&
7055 !is_multicast_ether_addr(conf
->bssid
)) {
7056 /* If there is currently a HW scan going on in the background
7057 * then we need to cancel it else the RXON below will fail. */
7058 if (iwl3945_scan_cancel_timeout(priv
, 100)) {
7059 IWL_WARNING("Aborted scan still in progress "
7061 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
7062 mutex_unlock(&priv
->mutex
);
7065 memcpy(priv
->staging_rxon
.bssid_addr
, conf
->bssid
, ETH_ALEN
);
7067 /* TODO: Audit driver for usage of these members and see
7068 * if mac80211 deprecates them (priv->bssid looks like it
7069 * shouldn't be there, but I haven't scanned the IBSS code
7070 * to verify) - jpk */
7071 memcpy(priv
->bssid
, conf
->bssid
, ETH_ALEN
);
7073 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
7074 iwl3945_config_ap(priv
);
7076 rc
= iwl3945_commit_rxon(priv
);
7077 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) && rc
)
7078 iwl3945_add_station(priv
,
7079 priv
->active_rxon
.bssid_addr
, 1, 0);
7083 iwl3945_scan_cancel_timeout(priv
, 100);
7084 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
7085 iwl3945_commit_rxon(priv
);
7089 spin_lock_irqsave(&priv
->lock
, flags
);
7090 if (!conf
->ssid_len
)
7091 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
7093 memcpy(priv
->essid
, conf
->ssid
, conf
->ssid_len
);
7095 priv
->essid_len
= conf
->ssid_len
;
7096 spin_unlock_irqrestore(&priv
->lock
, flags
);
7098 IWL_DEBUG_MAC80211("leave\n");
7099 mutex_unlock(&priv
->mutex
);
7104 static void iwl3945_configure_filter(struct ieee80211_hw
*hw
,
7105 unsigned int changed_flags
,
7106 unsigned int *total_flags
,
7107 int mc_count
, struct dev_addr_list
*mc_list
)
7111 * see also iwl3945_connection_init_rx_config
7116 static void iwl3945_mac_remove_interface(struct ieee80211_hw
*hw
,
7117 struct ieee80211_if_init_conf
*conf
)
7119 struct iwl3945_priv
*priv
= hw
->priv
;
7121 IWL_DEBUG_MAC80211("enter\n");
7123 mutex_lock(&priv
->mutex
);
7125 if (iwl3945_is_ready_rf(priv
)) {
7126 iwl3945_scan_cancel_timeout(priv
, 100);
7127 cancel_delayed_work(&priv
->post_associate
);
7128 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
7129 iwl3945_commit_rxon(priv
);
7131 if (priv
->vif
== conf
->vif
) {
7133 memset(priv
->bssid
, 0, ETH_ALEN
);
7134 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
7135 priv
->essid_len
= 0;
7137 mutex_unlock(&priv
->mutex
);
7139 IWL_DEBUG_MAC80211("leave\n");
7142 static int iwl3945_mac_hw_scan(struct ieee80211_hw
*hw
, u8
*ssid
, size_t len
)
7145 unsigned long flags
;
7146 struct iwl3945_priv
*priv
= hw
->priv
;
7148 IWL_DEBUG_MAC80211("enter\n");
7150 mutex_lock(&priv
->mutex
);
7151 spin_lock_irqsave(&priv
->lock
, flags
);
7153 if (!iwl3945_is_ready_rf(priv
)) {
7155 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
7159 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) { /* APs don't scan */
7161 IWL_ERROR("ERROR: APs don't scan\n");
7165 /* we don't schedule scan within next_scan_jiffies period */
7166 if (priv
->next_scan_jiffies
&&
7167 time_after(priv
->next_scan_jiffies
, jiffies
)) {
7171 /* if we just finished scan ask for delay */
7172 if (priv
->last_scan_jiffies
&& time_after(priv
->last_scan_jiffies
+
7173 IWL_DELAY_NEXT_SCAN
, jiffies
)) {
7178 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
7179 iwl3945_escape_essid(ssid
, len
), (int)len
);
7181 priv
->one_direct_scan
= 1;
7182 priv
->direct_ssid_len
= (u8
)
7183 min((u8
) len
, (u8
) IW_ESSID_MAX_SIZE
);
7184 memcpy(priv
->direct_ssid
, ssid
, priv
->direct_ssid_len
);
7186 priv
->one_direct_scan
= 0;
7188 rc
= iwl3945_scan_initiate(priv
);
7190 IWL_DEBUG_MAC80211("leave\n");
7193 spin_unlock_irqrestore(&priv
->lock
, flags
);
7194 mutex_unlock(&priv
->mutex
);
7199 static int iwl3945_mac_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
7200 const u8
*local_addr
, const u8
*addr
,
7201 struct ieee80211_key_conf
*key
)
7203 struct iwl3945_priv
*priv
= hw
->priv
;
7207 IWL_DEBUG_MAC80211("enter\n");
7209 if (!iwl3945_param_hwcrypto
) {
7210 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
7214 if (is_zero_ether_addr(addr
))
7215 /* only support pairwise keys */
7218 sta_id
= iwl3945_hw_find_station(priv
, addr
);
7219 if (sta_id
== IWL_INVALID_STATION
) {
7220 DECLARE_MAC_BUF(mac
);
7222 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
7223 print_mac(mac
, addr
));
7227 mutex_lock(&priv
->mutex
);
7229 iwl3945_scan_cancel_timeout(priv
, 100);
7233 rc
= iwl3945_update_sta_key_info(priv
, key
, sta_id
);
7235 iwl3945_set_rxon_hwcrypto(priv
, 1);
7236 iwl3945_commit_rxon(priv
);
7237 key
->hw_key_idx
= sta_id
;
7238 IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n");
7239 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
7243 rc
= iwl3945_clear_sta_key_info(priv
, sta_id
);
7245 iwl3945_set_rxon_hwcrypto(priv
, 0);
7246 iwl3945_commit_rxon(priv
);
7247 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
7254 IWL_DEBUG_MAC80211("leave\n");
7255 mutex_unlock(&priv
->mutex
);
7260 static int iwl3945_mac_conf_tx(struct ieee80211_hw
*hw
, int queue
,
7261 const struct ieee80211_tx_queue_params
*params
)
7263 struct iwl3945_priv
*priv
= hw
->priv
;
7264 unsigned long flags
;
7267 IWL_DEBUG_MAC80211("enter\n");
7269 if (!iwl3945_is_ready_rf(priv
)) {
7270 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7274 if (queue
>= AC_NUM
) {
7275 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue
);
7279 if (!priv
->qos_data
.qos_enable
) {
7280 priv
->qos_data
.qos_active
= 0;
7281 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
7284 q
= AC_NUM
- 1 - queue
;
7286 spin_lock_irqsave(&priv
->lock
, flags
);
7288 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_min
= cpu_to_le16(params
->cw_min
);
7289 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_max
= cpu_to_le16(params
->cw_max
);
7290 priv
->qos_data
.def_qos_parm
.ac
[q
].aifsn
= params
->aifs
;
7291 priv
->qos_data
.def_qos_parm
.ac
[q
].edca_txop
=
7292 cpu_to_le16((params
->txop
* 32));
7294 priv
->qos_data
.def_qos_parm
.ac
[q
].reserved1
= 0;
7295 priv
->qos_data
.qos_active
= 1;
7297 spin_unlock_irqrestore(&priv
->lock
, flags
);
7299 mutex_lock(&priv
->mutex
);
7300 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
7301 iwl3945_activate_qos(priv
, 1);
7302 else if (priv
->assoc_id
&& iwl3945_is_associated(priv
))
7303 iwl3945_activate_qos(priv
, 0);
7305 mutex_unlock(&priv
->mutex
);
7307 IWL_DEBUG_MAC80211("leave\n");
7311 static int iwl3945_mac_get_tx_stats(struct ieee80211_hw
*hw
,
7312 struct ieee80211_tx_queue_stats
*stats
)
7314 struct iwl3945_priv
*priv
= hw
->priv
;
7316 struct iwl3945_tx_queue
*txq
;
7317 struct iwl3945_queue
*q
;
7318 unsigned long flags
;
7320 IWL_DEBUG_MAC80211("enter\n");
7322 if (!iwl3945_is_ready_rf(priv
)) {
7323 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7327 spin_lock_irqsave(&priv
->lock
, flags
);
7329 for (i
= 0; i
< AC_NUM
; i
++) {
7330 txq
= &priv
->txq
[i
];
7332 avail
= iwl3945_queue_space(q
);
7334 stats
->data
[i
].len
= q
->n_window
- avail
;
7335 stats
->data
[i
].limit
= q
->n_window
- q
->high_mark
;
7336 stats
->data
[i
].count
= q
->n_window
;
7339 spin_unlock_irqrestore(&priv
->lock
, flags
);
7341 IWL_DEBUG_MAC80211("leave\n");
7346 static int iwl3945_mac_get_stats(struct ieee80211_hw
*hw
,
7347 struct ieee80211_low_level_stats
*stats
)
7349 IWL_DEBUG_MAC80211("enter\n");
7350 IWL_DEBUG_MAC80211("leave\n");
7355 static u64
iwl3945_mac_get_tsf(struct ieee80211_hw
*hw
)
7357 IWL_DEBUG_MAC80211("enter\n");
7358 IWL_DEBUG_MAC80211("leave\n");
7363 static void iwl3945_mac_reset_tsf(struct ieee80211_hw
*hw
)
7365 struct iwl3945_priv
*priv
= hw
->priv
;
7366 unsigned long flags
;
7368 mutex_lock(&priv
->mutex
);
7369 IWL_DEBUG_MAC80211("enter\n");
7371 iwl3945_reset_qos(priv
);
7373 cancel_delayed_work(&priv
->post_associate
);
7375 spin_lock_irqsave(&priv
->lock
, flags
);
7377 priv
->assoc_capability
= 0;
7378 priv
->call_post_assoc_from_beacon
= 0;
7380 /* new association get rid of ibss beacon skb */
7381 if (priv
->ibss_beacon
)
7382 dev_kfree_skb(priv
->ibss_beacon
);
7384 priv
->ibss_beacon
= NULL
;
7386 priv
->beacon_int
= priv
->hw
->conf
.beacon_int
;
7387 priv
->timestamp1
= 0;
7388 priv
->timestamp0
= 0;
7389 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
7390 priv
->beacon_int
= 0;
7392 spin_unlock_irqrestore(&priv
->lock
, flags
);
7394 if (!iwl3945_is_ready_rf(priv
)) {
7395 IWL_DEBUG_MAC80211("leave - not ready\n");
7396 mutex_unlock(&priv
->mutex
);
7400 /* we are restarting association process
7401 * clear RXON_FILTER_ASSOC_MSK bit
7403 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
7404 iwl3945_scan_cancel_timeout(priv
, 100);
7405 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
7406 iwl3945_commit_rxon(priv
);
7409 /* Per mac80211.h: This is only used in IBSS mode... */
7410 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
7412 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
7413 mutex_unlock(&priv
->mutex
);
7417 priv
->only_active_channel
= 0;
7419 iwl3945_set_rate(priv
);
7421 mutex_unlock(&priv
->mutex
);
7423 IWL_DEBUG_MAC80211("leave\n");
7427 static int iwl3945_mac_beacon_update(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
7428 struct ieee80211_tx_control
*control
)
7430 struct iwl3945_priv
*priv
= hw
->priv
;
7431 unsigned long flags
;
7433 mutex_lock(&priv
->mutex
);
7434 IWL_DEBUG_MAC80211("enter\n");
7436 if (!iwl3945_is_ready_rf(priv
)) {
7437 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7438 mutex_unlock(&priv
->mutex
);
7442 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
7443 IWL_DEBUG_MAC80211("leave - not IBSS\n");
7444 mutex_unlock(&priv
->mutex
);
7448 spin_lock_irqsave(&priv
->lock
, flags
);
7450 if (priv
->ibss_beacon
)
7451 dev_kfree_skb(priv
->ibss_beacon
);
7453 priv
->ibss_beacon
= skb
;
7457 IWL_DEBUG_MAC80211("leave\n");
7458 spin_unlock_irqrestore(&priv
->lock
, flags
);
7460 iwl3945_reset_qos(priv
);
7462 queue_work(priv
->workqueue
, &priv
->post_associate
.work
);
7464 mutex_unlock(&priv
->mutex
);
7469 /*****************************************************************************
7473 *****************************************************************************/
7475 #ifdef CONFIG_IWL3945_DEBUG
7478 * The following adds a new attribute to the sysfs representation
7479 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
7480 * used for controlling the debug level.
7482 * See the level definitions in iwl for details.
7485 static ssize_t
show_debug_level(struct device_driver
*d
, char *buf
)
7487 return sprintf(buf
, "0x%08X\n", iwl3945_debug_level
);
7489 static ssize_t
store_debug_level(struct device_driver
*d
,
7490 const char *buf
, size_t count
)
7492 char *p
= (char *)buf
;
7495 val
= simple_strtoul(p
, &p
, 0);
7497 printk(KERN_INFO DRV_NAME
7498 ": %s is not in hex or decimal form.\n", buf
);
7500 iwl3945_debug_level
= val
;
7502 return strnlen(buf
, count
);
7505 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
7506 show_debug_level
, store_debug_level
);
7508 #endif /* CONFIG_IWL3945_DEBUG */
7510 static ssize_t
show_rf_kill(struct device
*d
,
7511 struct device_attribute
*attr
, char *buf
)
7514 * 0 - RF kill not enabled
7515 * 1 - SW based RF kill active (sysfs)
7516 * 2 - HW based RF kill active
7517 * 3 - Both HW and SW based RF kill active
7519 struct iwl3945_priv
*priv
= (struct iwl3945_priv
*)d
->driver_data
;
7520 int val
= (test_bit(STATUS_RF_KILL_SW
, &priv
->status
) ? 0x1 : 0x0) |
7521 (test_bit(STATUS_RF_KILL_HW
, &priv
->status
) ? 0x2 : 0x0);
7523 return sprintf(buf
, "%i\n", val
);
7526 static ssize_t
store_rf_kill(struct device
*d
,
7527 struct device_attribute
*attr
,
7528 const char *buf
, size_t count
)
7530 struct iwl3945_priv
*priv
= (struct iwl3945_priv
*)d
->driver_data
;
7532 mutex_lock(&priv
->mutex
);
7533 iwl3945_radio_kill_sw(priv
, buf
[0] == '1');
7534 mutex_unlock(&priv
->mutex
);
7539 static DEVICE_ATTR(rf_kill
, S_IWUSR
| S_IRUGO
, show_rf_kill
, store_rf_kill
);
7541 static ssize_t
show_temperature(struct device
*d
,
7542 struct device_attribute
*attr
, char *buf
)
7544 struct iwl3945_priv
*priv
= (struct iwl3945_priv
*)d
->driver_data
;
7546 if (!iwl3945_is_alive(priv
))
7549 return sprintf(buf
, "%d\n", iwl3945_hw_get_temperature(priv
));
7552 static DEVICE_ATTR(temperature
, S_IRUGO
, show_temperature
, NULL
);
7554 static ssize_t
show_rs_window(struct device
*d
,
7555 struct device_attribute
*attr
,
7558 struct iwl3945_priv
*priv
= d
->driver_data
;
7559 return iwl3945_fill_rs_info(priv
->hw
, buf
, IWL_AP_ID
);
7561 static DEVICE_ATTR(rs_window
, S_IRUGO
, show_rs_window
, NULL
);
7563 static ssize_t
show_tx_power(struct device
*d
,
7564 struct device_attribute
*attr
, char *buf
)
7566 struct iwl3945_priv
*priv
= (struct iwl3945_priv
*)d
->driver_data
;
7567 return sprintf(buf
, "%d\n", priv
->user_txpower_limit
);
7570 static ssize_t
store_tx_power(struct device
*d
,
7571 struct device_attribute
*attr
,
7572 const char *buf
, size_t count
)
7574 struct iwl3945_priv
*priv
= (struct iwl3945_priv
*)d
->driver_data
;
7575 char *p
= (char *)buf
;
7578 val
= simple_strtoul(p
, &p
, 10);
7580 printk(KERN_INFO DRV_NAME
7581 ": %s is not in decimal form.\n", buf
);
7583 iwl3945_hw_reg_set_txpower(priv
, val
);
7588 static DEVICE_ATTR(tx_power
, S_IWUSR
| S_IRUGO
, show_tx_power
, store_tx_power
);
7590 static ssize_t
show_flags(struct device
*d
,
7591 struct device_attribute
*attr
, char *buf
)
7593 struct iwl3945_priv
*priv
= (struct iwl3945_priv
*)d
->driver_data
;
7595 return sprintf(buf
, "0x%04X\n", priv
->active_rxon
.flags
);
7598 static ssize_t
store_flags(struct device
*d
,
7599 struct device_attribute
*attr
,
7600 const char *buf
, size_t count
)
7602 struct iwl3945_priv
*priv
= (struct iwl3945_priv
*)d
->driver_data
;
7603 u32 flags
= simple_strtoul(buf
, NULL
, 0);
7605 mutex_lock(&priv
->mutex
);
7606 if (le32_to_cpu(priv
->staging_rxon
.flags
) != flags
) {
7607 /* Cancel any currently running scans... */
7608 if (iwl3945_scan_cancel_timeout(priv
, 100))
7609 IWL_WARNING("Could not cancel scan.\n");
7611 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
7613 priv
->staging_rxon
.flags
= cpu_to_le32(flags
);
7614 iwl3945_commit_rxon(priv
);
7617 mutex_unlock(&priv
->mutex
);
7622 static DEVICE_ATTR(flags
, S_IWUSR
| S_IRUGO
, show_flags
, store_flags
);
7624 static ssize_t
show_filter_flags(struct device
*d
,
7625 struct device_attribute
*attr
, char *buf
)
7627 struct iwl3945_priv
*priv
= (struct iwl3945_priv
*)d
->driver_data
;
7629 return sprintf(buf
, "0x%04X\n",
7630 le32_to_cpu(priv
->active_rxon
.filter_flags
));
7633 static ssize_t
store_filter_flags(struct device
*d
,
7634 struct device_attribute
*attr
,
7635 const char *buf
, size_t count
)
7637 struct iwl3945_priv
*priv
= (struct iwl3945_priv
*)d
->driver_data
;
7638 u32 filter_flags
= simple_strtoul(buf
, NULL
, 0);
7640 mutex_lock(&priv
->mutex
);
7641 if (le32_to_cpu(priv
->staging_rxon
.filter_flags
) != filter_flags
) {
7642 /* Cancel any currently running scans... */
7643 if (iwl3945_scan_cancel_timeout(priv
, 100))
7644 IWL_WARNING("Could not cancel scan.\n");
7646 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
7647 "0x%04X\n", filter_flags
);
7648 priv
->staging_rxon
.filter_flags
=
7649 cpu_to_le32(filter_flags
);
7650 iwl3945_commit_rxon(priv
);
7653 mutex_unlock(&priv
->mutex
);
7658 static DEVICE_ATTR(filter_flags
, S_IWUSR
| S_IRUGO
, show_filter_flags
,
7659 store_filter_flags
);
7661 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
7663 static ssize_t
show_measurement(struct device
*d
,
7664 struct device_attribute
*attr
, char *buf
)
7666 struct iwl3945_priv
*priv
= dev_get_drvdata(d
);
7667 struct iwl3945_spectrum_notification measure_report
;
7668 u32 size
= sizeof(measure_report
), len
= 0, ofs
= 0;
7669 u8
*data
= (u8
*) & measure_report
;
7670 unsigned long flags
;
7672 spin_lock_irqsave(&priv
->lock
, flags
);
7673 if (!(priv
->measurement_status
& MEASUREMENT_READY
)) {
7674 spin_unlock_irqrestore(&priv
->lock
, flags
);
7677 memcpy(&measure_report
, &priv
->measure_report
, size
);
7678 priv
->measurement_status
= 0;
7679 spin_unlock_irqrestore(&priv
->lock
, flags
);
7681 while (size
&& (PAGE_SIZE
- len
)) {
7682 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
7683 PAGE_SIZE
- len
, 1);
7685 if (PAGE_SIZE
- len
)
7689 size
-= min(size
, 16U);
7695 static ssize_t
store_measurement(struct device
*d
,
7696 struct device_attribute
*attr
,
7697 const char *buf
, size_t count
)
7699 struct iwl3945_priv
*priv
= dev_get_drvdata(d
);
7700 struct ieee80211_measurement_params params
= {
7701 .channel
= le16_to_cpu(priv
->active_rxon
.channel
),
7702 .start_time
= cpu_to_le64(priv
->last_tsf
),
7703 .duration
= cpu_to_le16(1),
7705 u8 type
= IWL_MEASURE_BASIC
;
7711 strncpy(buffer
, buf
, min(sizeof(buffer
), count
));
7712 channel
= simple_strtoul(p
, NULL
, 0);
7714 params
.channel
= channel
;
7717 while (*p
&& *p
!= ' ')
7720 type
= simple_strtoul(p
+ 1, NULL
, 0);
7723 IWL_DEBUG_INFO("Invoking measurement of type %d on "
7724 "channel %d (for '%s')\n", type
, params
.channel
, buf
);
7725 iwl3945_get_measurement(priv
, ¶ms
, type
);
7730 static DEVICE_ATTR(measurement
, S_IRUSR
| S_IWUSR
,
7731 show_measurement
, store_measurement
);
7732 #endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
7734 static ssize_t
store_retry_rate(struct device
*d
,
7735 struct device_attribute
*attr
,
7736 const char *buf
, size_t count
)
7738 struct iwl3945_priv
*priv
= dev_get_drvdata(d
);
7740 priv
->retry_rate
= simple_strtoul(buf
, NULL
, 0);
7741 if (priv
->retry_rate
<= 0)
7742 priv
->retry_rate
= 1;
7747 static ssize_t
show_retry_rate(struct device
*d
,
7748 struct device_attribute
*attr
, char *buf
)
7750 struct iwl3945_priv
*priv
= dev_get_drvdata(d
);
7751 return sprintf(buf
, "%d", priv
->retry_rate
);
7754 static DEVICE_ATTR(retry_rate
, S_IWUSR
| S_IRUSR
, show_retry_rate
,
7757 static ssize_t
store_power_level(struct device
*d
,
7758 struct device_attribute
*attr
,
7759 const char *buf
, size_t count
)
7761 struct iwl3945_priv
*priv
= dev_get_drvdata(d
);
7765 mode
= simple_strtoul(buf
, NULL
, 0);
7766 mutex_lock(&priv
->mutex
);
7768 if (!iwl3945_is_ready(priv
)) {
7773 if ((mode
< 1) || (mode
> IWL_POWER_LIMIT
) || (mode
== IWL_POWER_AC
))
7774 mode
= IWL_POWER_AC
;
7776 mode
|= IWL_POWER_ENABLED
;
7778 if (mode
!= priv
->power_mode
) {
7779 rc
= iwl3945_send_power_mode(priv
, IWL_POWER_LEVEL(mode
));
7781 IWL_DEBUG_MAC80211("failed setting power mode.\n");
7784 priv
->power_mode
= mode
;
7790 mutex_unlock(&priv
->mutex
);
7794 #define MAX_WX_STRING 80
7796 /* Values are in microsecond */
7797 static const s32 timeout_duration
[] = {
7804 static const s32 period_duration
[] = {
7812 static ssize_t
show_power_level(struct device
*d
,
7813 struct device_attribute
*attr
, char *buf
)
7815 struct iwl3945_priv
*priv
= dev_get_drvdata(d
);
7816 int level
= IWL_POWER_LEVEL(priv
->power_mode
);
7819 p
+= sprintf(p
, "%d ", level
);
7821 case IWL_POWER_MODE_CAM
:
7823 p
+= sprintf(p
, "(AC)");
7825 case IWL_POWER_BATTERY
:
7826 p
+= sprintf(p
, "(BATTERY)");
7830 "(Timeout %dms, Period %dms)",
7831 timeout_duration
[level
- 1] / 1000,
7832 period_duration
[level
- 1] / 1000);
7835 if (!(priv
->power_mode
& IWL_POWER_ENABLED
))
7836 p
+= sprintf(p
, " OFF\n");
7838 p
+= sprintf(p
, " \n");
7840 return (p
- buf
+ 1);
7844 static DEVICE_ATTR(power_level
, S_IWUSR
| S_IRUSR
, show_power_level
,
7847 static ssize_t
show_channels(struct device
*d
,
7848 struct device_attribute
*attr
, char *buf
)
7850 /* all this shit doesn't belong into sysfs anyway */
7854 static DEVICE_ATTR(channels
, S_IRUSR
, show_channels
, NULL
);
7856 static ssize_t
show_statistics(struct device
*d
,
7857 struct device_attribute
*attr
, char *buf
)
7859 struct iwl3945_priv
*priv
= dev_get_drvdata(d
);
7860 u32 size
= sizeof(struct iwl3945_notif_statistics
);
7861 u32 len
= 0, ofs
= 0;
7862 u8
*data
= (u8
*) & priv
->statistics
;
7865 if (!iwl3945_is_alive(priv
))
7868 mutex_lock(&priv
->mutex
);
7869 rc
= iwl3945_send_statistics_request(priv
);
7870 mutex_unlock(&priv
->mutex
);
7874 "Error sending statistics request: 0x%08X\n", rc
);
7878 while (size
&& (PAGE_SIZE
- len
)) {
7879 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
7880 PAGE_SIZE
- len
, 1);
7882 if (PAGE_SIZE
- len
)
7886 size
-= min(size
, 16U);
7892 static DEVICE_ATTR(statistics
, S_IRUGO
, show_statistics
, NULL
);
7894 static ssize_t
show_antenna(struct device
*d
,
7895 struct device_attribute
*attr
, char *buf
)
7897 struct iwl3945_priv
*priv
= dev_get_drvdata(d
);
7899 if (!iwl3945_is_alive(priv
))
7902 return sprintf(buf
, "%d\n", priv
->antenna
);
7905 static ssize_t
store_antenna(struct device
*d
,
7906 struct device_attribute
*attr
,
7907 const char *buf
, size_t count
)
7910 struct iwl3945_priv
*priv
= dev_get_drvdata(d
);
7915 if (sscanf(buf
, "%1i", &ant
) != 1) {
7916 IWL_DEBUG_INFO("not in hex or decimal form.\n");
7920 if ((ant
>= 0) && (ant
<= 2)) {
7921 IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant
);
7922 priv
->antenna
= (enum iwl3945_antenna
)ant
;
7924 IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant
);
7930 static DEVICE_ATTR(antenna
, S_IWUSR
| S_IRUGO
, show_antenna
, store_antenna
);
7932 static ssize_t
show_status(struct device
*d
,
7933 struct device_attribute
*attr
, char *buf
)
7935 struct iwl3945_priv
*priv
= (struct iwl3945_priv
*)d
->driver_data
;
7936 if (!iwl3945_is_alive(priv
))
7938 return sprintf(buf
, "0x%08x\n", (int)priv
->status
);
7941 static DEVICE_ATTR(status
, S_IRUGO
, show_status
, NULL
);
7943 static ssize_t
dump_error_log(struct device
*d
,
7944 struct device_attribute
*attr
,
7945 const char *buf
, size_t count
)
7947 char *p
= (char *)buf
;
7950 iwl3945_dump_nic_error_log((struct iwl3945_priv
*)d
->driver_data
);
7952 return strnlen(buf
, count
);
7955 static DEVICE_ATTR(dump_errors
, S_IWUSR
, NULL
, dump_error_log
);
7957 static ssize_t
dump_event_log(struct device
*d
,
7958 struct device_attribute
*attr
,
7959 const char *buf
, size_t count
)
7961 char *p
= (char *)buf
;
7964 iwl3945_dump_nic_event_log((struct iwl3945_priv
*)d
->driver_data
);
7966 return strnlen(buf
, count
);
7969 static DEVICE_ATTR(dump_events
, S_IWUSR
, NULL
, dump_event_log
);
7971 /*****************************************************************************
7973 * driver setup and teardown
7975 *****************************************************************************/
7977 static void iwl3945_setup_deferred_work(struct iwl3945_priv
*priv
)
7979 priv
->workqueue
= create_workqueue(DRV_NAME
);
7981 init_waitqueue_head(&priv
->wait_command_queue
);
7983 INIT_WORK(&priv
->up
, iwl3945_bg_up
);
7984 INIT_WORK(&priv
->restart
, iwl3945_bg_restart
);
7985 INIT_WORK(&priv
->rx_replenish
, iwl3945_bg_rx_replenish
);
7986 INIT_WORK(&priv
->scan_completed
, iwl3945_bg_scan_completed
);
7987 INIT_WORK(&priv
->request_scan
, iwl3945_bg_request_scan
);
7988 INIT_WORK(&priv
->abort_scan
, iwl3945_bg_abort_scan
);
7989 INIT_WORK(&priv
->rf_kill
, iwl3945_bg_rf_kill
);
7990 INIT_WORK(&priv
->beacon_update
, iwl3945_bg_beacon_update
);
7991 INIT_DELAYED_WORK(&priv
->post_associate
, iwl3945_bg_post_associate
);
7992 INIT_DELAYED_WORK(&priv
->init_alive_start
, iwl3945_bg_init_alive_start
);
7993 INIT_DELAYED_WORK(&priv
->alive_start
, iwl3945_bg_alive_start
);
7994 INIT_DELAYED_WORK(&priv
->scan_check
, iwl3945_bg_scan_check
);
7996 iwl3945_hw_setup_deferred_work(priv
);
7998 tasklet_init(&priv
->irq_tasklet
, (void (*)(unsigned long))
7999 iwl3945_irq_tasklet
, (unsigned long)priv
);
8002 static void iwl3945_cancel_deferred_work(struct iwl3945_priv
*priv
)
8004 iwl3945_hw_cancel_deferred_work(priv
);
8006 cancel_delayed_work_sync(&priv
->init_alive_start
);
8007 cancel_delayed_work(&priv
->scan_check
);
8008 cancel_delayed_work(&priv
->alive_start
);
8009 cancel_delayed_work(&priv
->post_associate
);
8010 cancel_work_sync(&priv
->beacon_update
);
8013 static struct attribute
*iwl3945_sysfs_entries
[] = {
8014 &dev_attr_antenna
.attr
,
8015 &dev_attr_channels
.attr
,
8016 &dev_attr_dump_errors
.attr
,
8017 &dev_attr_dump_events
.attr
,
8018 &dev_attr_flags
.attr
,
8019 &dev_attr_filter_flags
.attr
,
8020 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
8021 &dev_attr_measurement
.attr
,
8023 &dev_attr_power_level
.attr
,
8024 &dev_attr_retry_rate
.attr
,
8025 &dev_attr_rf_kill
.attr
,
8026 &dev_attr_rs_window
.attr
,
8027 &dev_attr_statistics
.attr
,
8028 &dev_attr_status
.attr
,
8029 &dev_attr_temperature
.attr
,
8030 &dev_attr_tx_power
.attr
,
8035 static struct attribute_group iwl3945_attribute_group
= {
8036 .name
= NULL
, /* put in device directory */
8037 .attrs
= iwl3945_sysfs_entries
,
8040 static struct ieee80211_ops iwl3945_hw_ops
= {
8041 .tx
= iwl3945_mac_tx
,
8042 .start
= iwl3945_mac_start
,
8043 .stop
= iwl3945_mac_stop
,
8044 .add_interface
= iwl3945_mac_add_interface
,
8045 .remove_interface
= iwl3945_mac_remove_interface
,
8046 .config
= iwl3945_mac_config
,
8047 .config_interface
= iwl3945_mac_config_interface
,
8048 .configure_filter
= iwl3945_configure_filter
,
8049 .set_key
= iwl3945_mac_set_key
,
8050 .get_stats
= iwl3945_mac_get_stats
,
8051 .get_tx_stats
= iwl3945_mac_get_tx_stats
,
8052 .conf_tx
= iwl3945_mac_conf_tx
,
8053 .get_tsf
= iwl3945_mac_get_tsf
,
8054 .reset_tsf
= iwl3945_mac_reset_tsf
,
8055 .beacon_update
= iwl3945_mac_beacon_update
,
8056 .hw_scan
= iwl3945_mac_hw_scan
8059 static int iwl3945_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
8062 struct iwl3945_priv
*priv
;
8063 struct ieee80211_hw
*hw
;
8064 struct iwl_3945_cfg
*cfg
= (struct iwl_3945_cfg
*)(ent
->driver_data
);
8066 DECLARE_MAC_BUF(mac
);
8068 /* Disabling hardware scan means that mac80211 will perform scans
8069 * "the hard way", rather than using device's scan. */
8070 if (iwl3945_param_disable_hw_scan
) {
8071 IWL_DEBUG_INFO("Disabling hw_scan\n");
8072 iwl3945_hw_ops
.hw_scan
= NULL
;
8075 if ((iwl3945_param_queues_num
> IWL_MAX_NUM_QUEUES
) ||
8076 (iwl3945_param_queues_num
< IWL_MIN_NUM_QUEUES
)) {
8077 IWL_ERROR("invalid queues_num, should be between %d and %d\n",
8078 IWL_MIN_NUM_QUEUES
, IWL_MAX_NUM_QUEUES
);
8083 /* mac80211 allocates memory for this device instance, including
8084 * space for this driver's private structure */
8085 hw
= ieee80211_alloc_hw(sizeof(struct iwl3945_priv
), &iwl3945_hw_ops
);
8087 IWL_ERROR("Can not allocate network device\n");
8091 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
8093 hw
->rate_control_algorithm
= "iwl-3945-rs";
8095 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
8099 priv
->pci_dev
= pdev
;
8102 /* Select antenna (may be helpful if only one antenna is connected) */
8103 priv
->antenna
= (enum iwl3945_antenna
)iwl3945_param_antenna
;
8104 #ifdef CONFIG_IWL3945_DEBUG
8105 iwl3945_debug_level
= iwl3945_param_debug
;
8106 atomic_set(&priv
->restrict_refcnt
, 0);
8108 priv
->retry_rate
= 1;
8110 priv
->ibss_beacon
= NULL
;
8112 /* Tell mac80211 and its clients (e.g. Wireless Extensions)
8113 * the range of signal quality values that we'll provide.
8114 * Negative values for level/noise indicate that we'll provide dBm.
8115 * For WE, at least, non-0 values here *enable* display of values
8116 * in app (iwconfig). */
8117 hw
->max_rssi
= -20; /* signal level, negative indicates dBm */
8118 hw
->max_noise
= -20; /* noise level, negative indicates dBm */
8119 hw
->max_signal
= 100; /* link quality indication (%) */
8121 /* Tell mac80211 our Tx characteristics */
8122 hw
->flags
= IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE
;
8124 /* 4 EDCA QOS priorities */
8127 spin_lock_init(&priv
->lock
);
8128 spin_lock_init(&priv
->power_data
.lock
);
8129 spin_lock_init(&priv
->sta_lock
);
8130 spin_lock_init(&priv
->hcmd_lock
);
8132 for (i
= 0; i
< IWL_IBSS_MAC_HASH_SIZE
; i
++)
8133 INIT_LIST_HEAD(&priv
->ibss_mac_hash
[i
]);
8135 INIT_LIST_HEAD(&priv
->free_frames
);
8137 mutex_init(&priv
->mutex
);
8138 if (pci_enable_device(pdev
)) {
8140 goto out_ieee80211_free_hw
;
8143 pci_set_master(pdev
);
8145 /* Clear the driver's (not device's) station table */
8146 iwl3945_clear_stations_table(priv
);
8148 priv
->data_retry_limit
= -1;
8149 priv
->ieee_channels
= NULL
;
8150 priv
->ieee_rates
= NULL
;
8151 priv
->band
= IEEE80211_BAND_2GHZ
;
8153 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
8155 err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
8157 printk(KERN_WARNING DRV_NAME
": No suitable DMA available.\n");
8158 goto out_pci_disable_device
;
8161 pci_set_drvdata(pdev
, priv
);
8162 err
= pci_request_regions(pdev
, DRV_NAME
);
8164 goto out_pci_disable_device
;
8166 /* We disable the RETRY_TIMEOUT register (0x41) to keep
8167 * PCI Tx retries from interfering with C3 CPU state */
8168 pci_write_config_byte(pdev
, 0x41, 0x00);
8170 priv
->hw_base
= pci_iomap(pdev
, 0, 0);
8171 if (!priv
->hw_base
) {
8173 goto out_pci_release_regions
;
8176 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
8177 (unsigned long long) pci_resource_len(pdev
, 0));
8178 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv
->hw_base
);
8180 /* Initialize module parameter values here */
8182 /* Disable radio (SW RF KILL) via parameter when loading driver */
8183 if (iwl3945_param_disable
) {
8184 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
8185 IWL_DEBUG_INFO("Radio disabled.\n");
8188 priv
->iw_mode
= IEEE80211_IF_TYPE_STA
;
8190 printk(KERN_INFO DRV_NAME
8191 ": Detected Intel Wireless WiFi Link %s\n", priv
->cfg
->name
);
8193 /* Device-specific setup */
8194 if (iwl3945_hw_set_hw_setting(priv
)) {
8195 IWL_ERROR("failed to set hw settings\n");
8199 if (iwl3945_param_qos_enable
)
8200 priv
->qos_data
.qos_enable
= 1;
8202 iwl3945_reset_qos(priv
);
8204 priv
->qos_data
.qos_active
= 0;
8205 priv
->qos_data
.qos_cap
.val
= 0;
8207 iwl3945_set_rxon_channel(priv
, IEEE80211_BAND_2GHZ
, 6);
8208 iwl3945_setup_deferred_work(priv
);
8209 iwl3945_setup_rx_handlers(priv
);
8211 priv
->rates_mask
= IWL_RATES_MASK
;
8212 /* If power management is turned on, default to AC mode */
8213 priv
->power_mode
= IWL_POWER_AC
;
8214 priv
->user_txpower_limit
= IWL_DEFAULT_TX_POWER
;
8216 iwl3945_disable_interrupts(priv
);
8218 err
= sysfs_create_group(&pdev
->dev
.kobj
, &iwl3945_attribute_group
);
8220 IWL_ERROR("failed to create sysfs device attributes\n");
8221 goto out_release_irq
;
8225 iwl3945_set_bit(priv
, CSR_GIO_CHICKEN_BITS
,
8226 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER
);
8228 iwl3945_set_bit(priv
, CSR_GP_CNTRL
, CSR_GP_CNTRL_REG_FLAG_INIT_DONE
);
8229 err
= iwl3945_poll_bit(priv
, CSR_GP_CNTRL
,
8230 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY
,
8231 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY
, 25000);
8233 IWL_DEBUG_INFO("Failed to init the card\n");
8234 goto out_remove_sysfs
;
8236 /* Read the EEPROM */
8237 err
= iwl3945_eeprom_init(priv
);
8239 IWL_ERROR("Unable to init EEPROM\n");
8240 goto out_remove_sysfs
;
8242 /* MAC Address location in EEPROM same for 3945/4965 */
8243 get_eeprom_mac(priv
, priv
->mac_addr
);
8244 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac
, priv
->mac_addr
));
8245 SET_IEEE80211_PERM_ADDR(priv
->hw
, priv
->mac_addr
);
8247 err
= iwl3945_init_channel_map(priv
);
8249 IWL_ERROR("initializing regulatory failed: %d\n", err
);
8250 goto out_remove_sysfs
;
8253 err
= iwl3945_init_geos(priv
);
8255 IWL_ERROR("initializing geos failed: %d\n", err
);
8256 goto out_free_channel_map
;
8259 iwl3945_rate_control_register(priv
->hw
);
8260 err
= ieee80211_register_hw(priv
->hw
);
8262 IWL_ERROR("Failed to register network device (error %d)\n", err
);
8266 priv
->hw
->conf
.beacon_int
= 100;
8267 priv
->mac80211_registered
= 1;
8268 pci_save_state(pdev
);
8269 pci_disable_device(pdev
);
8274 iwl3945_free_geos(priv
);
8275 out_free_channel_map
:
8276 iwl3945_free_channel_map(priv
);
8278 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl3945_attribute_group
);
8281 destroy_workqueue(priv
->workqueue
);
8282 priv
->workqueue
= NULL
;
8283 iwl3945_unset_hw_setting(priv
);
8286 pci_iounmap(pdev
, priv
->hw_base
);
8287 out_pci_release_regions
:
8288 pci_release_regions(pdev
);
8289 out_pci_disable_device
:
8290 pci_disable_device(pdev
);
8291 pci_set_drvdata(pdev
, NULL
);
8292 out_ieee80211_free_hw
:
8293 ieee80211_free_hw(priv
->hw
);
8298 static void iwl3945_pci_remove(struct pci_dev
*pdev
)
8300 struct iwl3945_priv
*priv
= pci_get_drvdata(pdev
);
8301 struct list_head
*p
, *q
;
8307 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
8309 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
8313 /* Free MAC hash list for ADHOC */
8314 for (i
= 0; i
< IWL_IBSS_MAC_HASH_SIZE
; i
++) {
8315 list_for_each_safe(p
, q
, &priv
->ibss_mac_hash
[i
]) {
8317 kfree(list_entry(p
, struct iwl3945_ibss_seq
, list
));
8321 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl3945_attribute_group
);
8323 iwl3945_dealloc_ucode_pci(priv
);
8326 iwl3945_rx_queue_free(priv
, &priv
->rxq
);
8327 iwl3945_hw_txq_ctx_free(priv
);
8329 iwl3945_unset_hw_setting(priv
);
8330 iwl3945_clear_stations_table(priv
);
8332 if (priv
->mac80211_registered
) {
8333 ieee80211_unregister_hw(priv
->hw
);
8334 iwl3945_rate_control_unregister(priv
->hw
);
8337 /*netif_stop_queue(dev); */
8338 flush_workqueue(priv
->workqueue
);
8340 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
8341 * priv->workqueue... so we can't take down the workqueue
8343 destroy_workqueue(priv
->workqueue
);
8344 priv
->workqueue
= NULL
;
8346 pci_iounmap(pdev
, priv
->hw_base
);
8347 pci_release_regions(pdev
);
8348 pci_disable_device(pdev
);
8349 pci_set_drvdata(pdev
, NULL
);
8351 iwl3945_free_channel_map(priv
);
8352 iwl3945_free_geos(priv
);
8354 if (priv
->ibss_beacon
)
8355 dev_kfree_skb(priv
->ibss_beacon
);
8357 ieee80211_free_hw(priv
->hw
);
8362 static int iwl3945_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
8364 struct iwl3945_priv
*priv
= pci_get_drvdata(pdev
);
8366 if (priv
->is_open
) {
8367 set_bit(STATUS_IN_SUSPEND
, &priv
->status
);
8368 iwl3945_mac_stop(priv
->hw
);
8372 pci_set_power_state(pdev
, PCI_D3hot
);
8377 static int iwl3945_pci_resume(struct pci_dev
*pdev
)
8379 struct iwl3945_priv
*priv
= pci_get_drvdata(pdev
);
8381 pci_set_power_state(pdev
, PCI_D0
);
8384 iwl3945_mac_start(priv
->hw
);
8386 clear_bit(STATUS_IN_SUSPEND
, &priv
->status
);
8390 #endif /* CONFIG_PM */
8392 /*****************************************************************************
8394 * driver and module entry point
8396 *****************************************************************************/
8398 static struct pci_driver iwl3945_driver
= {
8400 .id_table
= iwl3945_hw_card_ids
,
8401 .probe
= iwl3945_pci_probe
,
8402 .remove
= __devexit_p(iwl3945_pci_remove
),
8404 .suspend
= iwl3945_pci_suspend
,
8405 .resume
= iwl3945_pci_resume
,
8409 static int __init
iwl3945_init(void)
8413 printk(KERN_INFO DRV_NAME
": " DRV_DESCRIPTION
", " DRV_VERSION
"\n");
8414 printk(KERN_INFO DRV_NAME
": " DRV_COPYRIGHT
"\n");
8415 ret
= pci_register_driver(&iwl3945_driver
);
8417 IWL_ERROR("Unable to initialize PCI module\n");
8420 #ifdef CONFIG_IWL3945_DEBUG
8421 ret
= driver_create_file(&iwl3945_driver
.driver
, &driver_attr_debug_level
);
8423 IWL_ERROR("Unable to create driver sysfs file\n");
8424 pci_unregister_driver(&iwl3945_driver
);
8432 static void __exit
iwl3945_exit(void)
8434 #ifdef CONFIG_IWL3945_DEBUG
8435 driver_remove_file(&iwl3945_driver
.driver
, &driver_attr_debug_level
);
8437 pci_unregister_driver(&iwl3945_driver
);
8440 module_param_named(antenna
, iwl3945_param_antenna
, int, 0444);
8441 MODULE_PARM_DESC(antenna
, "select antenna (1=Main, 2=Aux, default 0 [both])");
8442 module_param_named(disable
, iwl3945_param_disable
, int, 0444);
8443 MODULE_PARM_DESC(disable
, "manually disable the radio (default 0 [radio on])");
8444 module_param_named(hwcrypto
, iwl3945_param_hwcrypto
, int, 0444);
8445 MODULE_PARM_DESC(hwcrypto
,
8446 "using hardware crypto engine (default 0 [software])\n");
8447 module_param_named(debug
, iwl3945_param_debug
, int, 0444);
8448 MODULE_PARM_DESC(debug
, "debug output mask");
8449 module_param_named(disable_hw_scan
, iwl3945_param_disable_hw_scan
, int, 0444);
8450 MODULE_PARM_DESC(disable_hw_scan
, "disable hardware scanning (default 0)");
8452 module_param_named(queues_num
, iwl3945_param_queues_num
, int, 0444);
8453 MODULE_PARM_DESC(queues_num
, "number of hw queues.");
8456 module_param_named(qos_enable
, iwl3945_param_qos_enable
, int, 0444);
8457 MODULE_PARM_DESC(qos_enable
, "enable all QoS functionality");
8459 module_exit(iwl3945_exit
);
8460 module_init(iwl3945_init
);