1 /******************************************************************************
3 * Copyright(c) 2003 - 2009 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 * Intel Linux Wireless <ilw@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/init.h>
33 #include <linux/pci.h>
34 #include <linux/dma-mapping.h>
35 #include <linux/delay.h>
36 #include <linux/skbuff.h>
37 #include <linux/netdevice.h>
38 #include <linux/wireless.h>
39 #include <linux/firmware.h>
40 #include <linux/etherdevice.h>
41 #include <linux/if_arp.h>
43 #include <net/ieee80211_radiotap.h>
44 #include <net/lib80211.h>
45 #include <net/mac80211.h>
47 #include <asm/div64.h>
49 #define DRV_NAME "iwl3945"
52 #include "iwl-3945-fh.h"
53 #include "iwl-commands.h"
55 #include "iwl-helpers.h"
60 * module name, copyright, version, etc.
63 #define DRV_DESCRIPTION \
64 "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
66 #ifdef CONFIG_IWL3945_DEBUG
72 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
78 #define IWL39_VERSION "1.2.26k" VD VS
79 #define DRV_COPYRIGHT "Copyright(c) 2003-2009 Intel Corporation"
80 #define DRV_AUTHOR "<ilw@linux.intel.com>"
81 #define DRV_VERSION IWL39_VERSION
84 MODULE_DESCRIPTION(DRV_DESCRIPTION
);
85 MODULE_VERSION(DRV_VERSION
);
86 MODULE_AUTHOR(DRV_COPYRIGHT
" " DRV_AUTHOR
);
87 MODULE_LICENSE("GPL");
89 /* module parameters */
90 struct iwl_mod_params iwl3945_mod_params
= {
91 .num_of_queues
= IWL39_MAX_NUM_QUEUES
,
93 /* the rest are 0 by default */
96 /*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
101 * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
102 * of buffer descriptors, each of which points to one or more data buffers for
103 * the device to read from or fill. Driver and device exchange status of each
104 * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
105 * entries in each circular buffer, to protect against confusing empty and full
108 * The device reads or writes the data in the queues via the device's several
109 * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
111 * For Tx queue, there are low mark and high mark limits. If, after queuing
112 * the packet for Tx, free space become < low mark, Tx queue stopped. When
113 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
116 * The 3945 operates with six queues: One receive queue, one transmit queue
117 * (#4) for sending commands to the device firmware, and four transmit queues
118 * (#0-3) for data tx via EDCA. An additional 2 HCCA queues are unused.
119 ***************************************************/
122 * iwl3945_queue_init - Initialize queue's high/low-water and read/write indexes
124 static int iwl3945_queue_init(struct iwl_priv
*priv
, struct iwl_queue
*q
,
125 int count
, int slots_num
, u32 id
)
128 q
->n_window
= slots_num
;
131 /* count must be power-of-two size, otherwise iwl_queue_inc_wrap
132 * and iwl_queue_dec_wrap are broken. */
133 BUG_ON(!is_power_of_2(count
));
135 /* slots_num must be power-of-two size, otherwise
136 * get_cmd_index is broken. */
137 BUG_ON(!is_power_of_2(slots_num
));
139 q
->low_mark
= q
->n_window
/ 4;
143 q
->high_mark
= q
->n_window
/ 8;
144 if (q
->high_mark
< 2)
147 q
->write_ptr
= q
->read_ptr
= 0;
153 * iwl3945_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
155 static int iwl3945_tx_queue_alloc(struct iwl_priv
*priv
,
156 struct iwl_tx_queue
*txq
, u32 id
)
158 struct pci_dev
*dev
= priv
->pci_dev
;
160 /* Driver private data, only for Tx (not command) queues,
161 * not shared with device. */
162 if (id
!= IWL_CMD_QUEUE_NUM
) {
163 txq
->txb
= kmalloc(sizeof(txq
->txb
[0]) *
164 TFD_QUEUE_SIZE_MAX
, GFP_KERNEL
);
166 IWL_ERR(priv
, "kmalloc for auxiliary BD "
167 "structures failed\n");
173 /* Circular buffer of transmit frame descriptors (TFDs),
174 * shared with device */
175 txq
->tfds39
= pci_alloc_consistent(dev
,
176 sizeof(txq
->tfds39
[0]) * TFD_QUEUE_SIZE_MAX
,
180 IWL_ERR(priv
, "pci_alloc_consistent(%zd) failed\n",
181 sizeof(txq
->tfds39
[0]) * TFD_QUEUE_SIZE_MAX
);
196 * iwl3945_tx_queue_init - Allocate and initialize one tx/cmd queue
198 int iwl3945_tx_queue_init(struct iwl_priv
*priv
,
199 struct iwl_tx_queue
*txq
, int slots_num
, u32 txq_id
)
205 * Alloc buffer array for commands (Tx or other types of commands).
206 * For the command queue (#4), allocate command space + one big
207 * command for scan, since scan command is very huge; the system will
208 * not have two scans at the same time, so only one is needed.
209 * For data Tx queues (all other queues), no super-size command
212 len
= sizeof(struct iwl_cmd
);
213 for (i
= 0; i
<= slots_num
; i
++) {
214 if (i
== slots_num
) {
215 if (txq_id
== IWL_CMD_QUEUE_NUM
)
216 len
+= IWL_MAX_SCAN_SIZE
;
221 txq
->cmd
[i
] = kmalloc(len
, GFP_KERNEL
);
226 /* Alloc driver data array and TFD circular buffer */
227 rc
= iwl3945_tx_queue_alloc(priv
, txq
, txq_id
);
231 txq
->need_update
= 0;
233 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
234 * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */
235 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX
& (TFD_QUEUE_SIZE_MAX
- 1));
237 /* Initialize queue high/low-water, head/tail indexes */
238 iwl3945_queue_init(priv
, &txq
->q
, TFD_QUEUE_SIZE_MAX
, slots_num
, txq_id
);
240 /* Tell device where to find queue, enable DMA channel. */
241 iwl3945_hw_tx_queue_init(priv
, txq
);
245 for (i
= 0; i
< slots_num
; i
++) {
250 if (txq_id
== IWL_CMD_QUEUE_NUM
) {
251 kfree(txq
->cmd
[slots_num
]);
252 txq
->cmd
[slots_num
] = NULL
;
258 * iwl3945_tx_queue_free - Deallocate DMA queue.
259 * @txq: Transmit queue to deallocate.
261 * Empty queue by removing and destroying all BD's.
263 * 0-fill, but do not free "txq" descriptor structure.
265 void iwl3945_tx_queue_free(struct iwl_priv
*priv
, struct iwl_tx_queue
*txq
)
267 struct iwl_queue
*q
= &txq
->q
;
268 struct pci_dev
*dev
= priv
->pci_dev
;
274 /* first, empty all BD's */
275 for (; q
->write_ptr
!= q
->read_ptr
;
276 q
->read_ptr
= iwl_queue_inc_wrap(q
->read_ptr
, q
->n_bd
))
277 priv
->cfg
->ops
->lib
->txq_free_tfd(priv
, txq
);
279 len
= sizeof(struct iwl_cmd
) * q
->n_window
;
280 if (q
->id
== IWL_CMD_QUEUE_NUM
)
281 len
+= IWL_MAX_SCAN_SIZE
;
283 /* De-alloc array of command/tx buffers */
284 for (i
= 0; i
< TFD_TX_CMD_SLOTS
; i
++)
287 /* De-alloc circular buffer of TFDs */
289 pci_free_consistent(dev
, sizeof(struct iwl3945_tfd
) *
290 txq
->q
.n_bd
, txq
->tfds39
, txq
->q
.dma_addr
);
292 /* De-alloc array of per-TFD driver data */
296 /* 0-fill queue descriptor structure */
297 memset(txq
, 0, sizeof(*txq
));
300 /*************** STATION TABLE MANAGEMENT ****
301 * mac80211 should be examined to determine if sta_info is duplicating
302 * the functionality provided here
305 /**************************************************************/
306 #if 0 /* temporary disable till we add real remove station */
308 * iwl3945_remove_station - Remove driver's knowledge of station.
310 * NOTE: This does not remove station from device's station table.
312 static u8
iwl3945_remove_station(struct iwl_priv
*priv
, const u8
*addr
, int is_ap
)
314 int index
= IWL_INVALID_STATION
;
318 spin_lock_irqsave(&priv
->sta_lock
, flags
);
322 else if (is_broadcast_ether_addr(addr
))
323 index
= priv
->hw_params
.bcast_sta_id
;
325 for (i
= IWL_STA_ID
; i
< priv
->hw_params
.max_stations
; i
++)
326 if (priv
->stations_39
[i
].used
&&
327 !compare_ether_addr(priv
->stations_39
[i
].sta
.sta
.addr
,
333 if (unlikely(index
== IWL_INVALID_STATION
))
336 if (priv
->stations_39
[index
].used
) {
337 priv
->stations_39
[index
].used
= 0;
338 priv
->num_stations
--;
341 BUG_ON(priv
->num_stations
< 0);
344 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
350 * iwl3945_clear_stations_table - Clear the driver's station table
352 * NOTE: This does not clear or otherwise alter the device's station table.
354 static void iwl3945_clear_stations_table(struct iwl_priv
*priv
)
358 spin_lock_irqsave(&priv
->sta_lock
, flags
);
360 priv
->num_stations
= 0;
361 memset(priv
->stations_39
, 0, sizeof(priv
->stations_39
));
363 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
367 * iwl3945_add_station - Add station to station tables in driver and device
369 u8
iwl3945_add_station(struct iwl_priv
*priv
, const u8
*addr
, int is_ap
, u8 flags
)
372 int index
= IWL_INVALID_STATION
;
373 struct iwl3945_station_entry
*station
;
374 unsigned long flags_spin
;
377 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
380 else if (is_broadcast_ether_addr(addr
))
381 index
= priv
->hw_params
.bcast_sta_id
;
383 for (i
= IWL_STA_ID
; i
< priv
->hw_params
.max_stations
; i
++) {
384 if (!compare_ether_addr(priv
->stations_39
[i
].sta
.sta
.addr
,
390 if (!priv
->stations_39
[i
].used
&&
391 index
== IWL_INVALID_STATION
)
395 /* These two conditions has the same outcome but keep them separate
396 since they have different meaning */
397 if (unlikely(index
== IWL_INVALID_STATION
)) {
398 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
402 if (priv
->stations_39
[index
].used
&&
403 !compare_ether_addr(priv
->stations_39
[index
].sta
.sta
.addr
, addr
)) {
404 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
408 IWL_DEBUG_ASSOC("Add STA ID %d: %pM\n", index
, addr
);
409 station
= &priv
->stations_39
[index
];
411 priv
->num_stations
++;
413 /* Set up the REPLY_ADD_STA command to send to device */
414 memset(&station
->sta
, 0, sizeof(struct iwl3945_addsta_cmd
));
415 memcpy(station
->sta
.sta
.addr
, addr
, ETH_ALEN
);
416 station
->sta
.mode
= 0;
417 station
->sta
.sta
.sta_id
= index
;
418 station
->sta
.station_flags
= 0;
420 if (priv
->band
== IEEE80211_BAND_5GHZ
)
421 rate
= IWL_RATE_6M_PLCP
;
423 rate
= IWL_RATE_1M_PLCP
;
425 /* Turn on both antennas for the station... */
426 station
->sta
.rate_n_flags
=
427 iwl3945_hw_set_rate_n_flags(rate
, RATE_MCS_ANT_AB_MSK
);
429 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
431 /* Add station to device's station table */
432 iwl3945_send_add_station(priv
, &station
->sta
, flags
);
437 int iwl3945_send_statistics_request(struct iwl_priv
*priv
)
441 struct iwl_host_cmd cmd
= {
442 .id
= REPLY_STATISTICS_CMD
,
447 return iwl_send_cmd_sync(priv
, &cmd
);
451 * iwl3945_set_rxon_channel - Set the phymode and channel values in staging RXON
452 * @band: 2.4 or 5 GHz band
453 * @channel: Any channel valid for the requested band
455 * In addition to setting the staging RXON, priv->band is also set.
457 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
458 * in the staging RXON flag structure based on the band
460 static int iwl3945_set_rxon_channel(struct iwl_priv
*priv
,
461 enum ieee80211_band band
,
464 if (!iwl3945_get_channel_info(priv
, band
, channel
)) {
465 IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
470 if ((le16_to_cpu(priv
->staging39_rxon
.channel
) == channel
) &&
471 (priv
->band
== band
))
474 priv
->staging39_rxon
.channel
= cpu_to_le16(channel
);
475 if (band
== IEEE80211_BAND_5GHZ
)
476 priv
->staging39_rxon
.flags
&= ~RXON_FLG_BAND_24G_MSK
;
478 priv
->staging39_rxon
.flags
|= RXON_FLG_BAND_24G_MSK
;
482 IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel
, band
);
488 * iwl3945_check_rxon_cmd - validate RXON structure is valid
490 * NOTE: This is really only useful during development and can eventually
491 * be #ifdef'd out once the driver is stable and folks aren't actively
494 static int iwl3945_check_rxon_cmd(struct iwl_priv
*priv
)
498 struct iwl3945_rxon_cmd
*rxon
= &priv
->staging39_rxon
;
500 if (rxon
->flags
& RXON_FLG_BAND_24G_MSK
) {
501 error
|= le32_to_cpu(rxon
->flags
&
502 (RXON_FLG_TGJ_NARROW_BAND_MSK
|
503 RXON_FLG_RADAR_DETECT_MSK
));
505 IWL_WARN(priv
, "check 24G fields %d | %d\n",
508 error
|= (rxon
->flags
& RXON_FLG_SHORT_SLOT_MSK
) ?
509 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK
);
511 IWL_WARN(priv
, "check 52 fields %d | %d\n",
513 error
|= le32_to_cpu(rxon
->flags
& RXON_FLG_CCK_MSK
);
515 IWL_WARN(priv
, "check 52 CCK %d | %d\n",
518 error
|= (rxon
->node_addr
[0] | rxon
->bssid_addr
[0]) & 0x1;
520 IWL_WARN(priv
, "check mac addr %d | %d\n", counter
++, error
);
522 /* make sure basic rates 6Mbps and 1Mbps are supported */
523 error
|= (((rxon
->ofdm_basic_rates
& IWL_RATE_6M_MASK
) == 0) &&
524 ((rxon
->cck_basic_rates
& IWL_RATE_1M_MASK
) == 0));
526 IWL_WARN(priv
, "check basic rate %d | %d\n", counter
++, error
);
528 error
|= (le16_to_cpu(rxon
->assoc_id
) > 2007);
530 IWL_WARN(priv
, "check assoc id %d | %d\n", counter
++, error
);
532 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
))
533 == (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
));
535 IWL_WARN(priv
, "check CCK and short slot %d | %d\n",
538 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
))
539 == (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
));
541 IWL_WARN(priv
, "check CCK & auto detect %d | %d\n",
544 error
|= ((rxon
->flags
& (RXON_FLG_AUTO_DETECT_MSK
|
545 RXON_FLG_TGG_PROTECT_MSK
)) == RXON_FLG_TGG_PROTECT_MSK
);
547 IWL_WARN(priv
, "check TGG and auto detect %d | %d\n",
550 if ((rxon
->flags
& RXON_FLG_DIS_DIV_MSK
))
551 error
|= ((rxon
->flags
& (RXON_FLG_ANT_B_MSK
|
552 RXON_FLG_ANT_A_MSK
)) == 0);
554 IWL_WARN(priv
, "check antenna %d %d\n", counter
++, error
);
557 IWL_WARN(priv
, "Tuning to channel %d\n",
558 le16_to_cpu(rxon
->channel
));
561 IWL_ERR(priv
, "Not a valid rxon_assoc_cmd field values\n");
568 * iwl3945_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
569 * @priv: staging_rxon is compared to active_rxon
571 * If the RXON structure is changing enough to require a new tune,
572 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
573 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
575 static int iwl3945_full_rxon_required(struct iwl_priv
*priv
)
578 /* These items are only settable from the full RXON command */
579 if (!(iwl3945_is_associated(priv
)) ||
580 compare_ether_addr(priv
->staging39_rxon
.bssid_addr
,
581 priv
->active39_rxon
.bssid_addr
) ||
582 compare_ether_addr(priv
->staging39_rxon
.node_addr
,
583 priv
->active39_rxon
.node_addr
) ||
584 compare_ether_addr(priv
->staging39_rxon
.wlap_bssid_addr
,
585 priv
->active39_rxon
.wlap_bssid_addr
) ||
586 (priv
->staging39_rxon
.dev_type
!= priv
->active39_rxon
.dev_type
) ||
587 (priv
->staging39_rxon
.channel
!= priv
->active39_rxon
.channel
) ||
588 (priv
->staging39_rxon
.air_propagation
!=
589 priv
->active39_rxon
.air_propagation
) ||
590 (priv
->staging39_rxon
.assoc_id
!= priv
->active39_rxon
.assoc_id
))
593 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
594 * be updated with the RXON_ASSOC command -- however only some
595 * flag transitions are allowed using RXON_ASSOC */
597 /* Check if we are not switching bands */
598 if ((priv
->staging39_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) !=
599 (priv
->active39_rxon
.flags
& RXON_FLG_BAND_24G_MSK
))
602 /* Check if we are switching association toggle */
603 if ((priv
->staging39_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) !=
604 (priv
->active39_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
))
610 static int iwl3945_send_rxon_assoc(struct iwl_priv
*priv
)
613 struct iwl_rx_packet
*res
= NULL
;
614 struct iwl3945_rxon_assoc_cmd rxon_assoc
;
615 struct iwl_host_cmd cmd
= {
616 .id
= REPLY_RXON_ASSOC
,
617 .len
= sizeof(rxon_assoc
),
618 .meta
.flags
= CMD_WANT_SKB
,
621 const struct iwl3945_rxon_cmd
*rxon1
= &priv
->staging39_rxon
;
622 const struct iwl3945_rxon_cmd
*rxon2
= &priv
->active39_rxon
;
624 if ((rxon1
->flags
== rxon2
->flags
) &&
625 (rxon1
->filter_flags
== rxon2
->filter_flags
) &&
626 (rxon1
->cck_basic_rates
== rxon2
->cck_basic_rates
) &&
627 (rxon1
->ofdm_basic_rates
== rxon2
->ofdm_basic_rates
)) {
628 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
632 rxon_assoc
.flags
= priv
->staging39_rxon
.flags
;
633 rxon_assoc
.filter_flags
= priv
->staging39_rxon
.filter_flags
;
634 rxon_assoc
.ofdm_basic_rates
= priv
->staging39_rxon
.ofdm_basic_rates
;
635 rxon_assoc
.cck_basic_rates
= priv
->staging39_rxon
.cck_basic_rates
;
636 rxon_assoc
.reserved
= 0;
638 rc
= iwl_send_cmd_sync(priv
, &cmd
);
642 res
= (struct iwl_rx_packet
*)cmd
.meta
.u
.skb
->data
;
643 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
644 IWL_ERR(priv
, "Bad return from REPLY_RXON_ASSOC command\n");
648 priv
->alloc_rxb_skb
--;
649 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
655 * iwl3945_commit_rxon - commit staging_rxon to hardware
657 * The RXON command in staging_rxon is committed to the hardware and
658 * the active_rxon structure is updated with the new data. This
659 * function correctly transitions out of the RXON_ASSOC_MSK state if
660 * a HW tune is required based on the RXON structure changes.
662 static int iwl3945_commit_rxon(struct iwl_priv
*priv
)
664 /* cast away the const for active_rxon in this function */
665 struct iwl3945_rxon_cmd
*active_rxon
= (void *)&priv
->active39_rxon
;
668 if (!iwl_is_alive(priv
))
671 /* always get timestamp with Rx frame */
672 priv
->staging39_rxon
.flags
|= RXON_FLG_TSF2HOST_MSK
;
675 priv
->staging39_rxon
.flags
&=
676 ~(RXON_FLG_DIS_DIV_MSK
| RXON_FLG_ANT_SEL_MSK
);
677 priv
->staging39_rxon
.flags
|= iwl3945_get_antenna_flags(priv
);
679 rc
= iwl3945_check_rxon_cmd(priv
);
681 IWL_ERR(priv
, "Invalid RXON configuration. Not committing.\n");
685 /* If we don't need to send a full RXON, we can use
686 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
687 * and other flags for the current radio configuration. */
688 if (!iwl3945_full_rxon_required(priv
)) {
689 rc
= iwl3945_send_rxon_assoc(priv
);
691 IWL_ERR(priv
, "Error setting RXON_ASSOC "
692 "configuration (%d).\n", rc
);
696 memcpy(active_rxon
, &priv
->staging39_rxon
, sizeof(*active_rxon
));
701 /* If we are currently associated and the new config requires
702 * an RXON_ASSOC and the new config wants the associated mask enabled,
703 * we must clear the associated from the active configuration
704 * before we apply the new config */
705 if (iwl3945_is_associated(priv
) &&
706 (priv
->staging39_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
)) {
707 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
708 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
710 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
711 sizeof(struct iwl3945_rxon_cmd
),
712 &priv
->active39_rxon
);
714 /* If the mask clearing failed then we set
715 * active_rxon back to what it was previously */
717 active_rxon
->filter_flags
|= RXON_FILTER_ASSOC_MSK
;
718 IWL_ERR(priv
, "Error clearing ASSOC_MSK on current "
719 "configuration (%d).\n", rc
);
724 IWL_DEBUG_INFO("Sending RXON\n"
725 "* with%s RXON_FILTER_ASSOC_MSK\n"
728 ((priv
->staging39_rxon
.filter_flags
&
729 RXON_FILTER_ASSOC_MSK
) ? "" : "out"),
730 le16_to_cpu(priv
->staging39_rxon
.channel
),
731 priv
->staging_rxon
.bssid_addr
);
733 /* Apply the new configuration */
734 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
735 sizeof(struct iwl3945_rxon_cmd
), &priv
->staging39_rxon
);
737 IWL_ERR(priv
, "Error setting new configuration (%d).\n", rc
);
741 memcpy(active_rxon
, &priv
->staging39_rxon
, sizeof(*active_rxon
));
743 iwl3945_clear_stations_table(priv
);
745 /* If we issue a new RXON command which required a tune then we must
746 * send a new TXPOWER command or we won't be able to Tx any frames */
747 rc
= priv
->cfg
->ops
->lib
->send_tx_power(priv
);
749 IWL_ERR(priv
, "Error setting Tx power (%d).\n", rc
);
753 /* Add the broadcast address so we can send broadcast frames */
754 if (iwl3945_add_station(priv
, iwl_bcast_addr
, 0, 0) ==
755 IWL_INVALID_STATION
) {
756 IWL_ERR(priv
, "Error adding BROADCAST address for transmit.\n");
760 /* If we have set the ASSOC_MSK and we are in BSS mode then
761 * add the IWL_AP_ID to the station rate table */
762 if (iwl3945_is_associated(priv
) &&
763 (priv
->iw_mode
== NL80211_IFTYPE_STATION
))
764 if (iwl3945_add_station(priv
, priv
->active39_rxon
.bssid_addr
, 1, 0)
765 == IWL_INVALID_STATION
) {
766 IWL_ERR(priv
, "Error adding AP address for transmit\n");
770 /* Init the hardware's rate fallback order based on the band */
771 rc
= iwl3945_init_hw_rate_table(priv
);
773 IWL_ERR(priv
, "Error setting HW rate table: %02X\n", rc
);
780 static int iwl3945_send_bt_config(struct iwl_priv
*priv
)
782 struct iwl_bt_cmd bt_cmd
= {
790 return iwl_send_cmd_pdu(priv
, REPLY_BT_CONFIG
,
791 sizeof(bt_cmd
), &bt_cmd
);
794 static int iwl3945_add_sta_sync_callback(struct iwl_priv
*priv
,
795 struct iwl_cmd
*cmd
, struct sk_buff
*skb
)
797 struct iwl_rx_packet
*res
= NULL
;
800 IWL_ERR(priv
, "Error: Response NULL in REPLY_ADD_STA.\n");
804 res
= (struct iwl_rx_packet
*)skb
->data
;
805 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
806 IWL_ERR(priv
, "Bad return from REPLY_ADD_STA (0x%08X)\n",
811 switch (res
->u
.add_sta
.status
) {
812 case ADD_STA_SUCCESS_MSK
:
818 /* We didn't cache the SKB; let the caller free it */
822 int iwl3945_send_add_station(struct iwl_priv
*priv
,
823 struct iwl3945_addsta_cmd
*sta
, u8 flags
)
825 struct iwl_rx_packet
*res
= NULL
;
827 struct iwl_host_cmd cmd
= {
829 .len
= sizeof(struct iwl3945_addsta_cmd
),
834 if (flags
& CMD_ASYNC
)
835 cmd
.meta
.u
.callback
= iwl3945_add_sta_sync_callback
;
837 cmd
.meta
.flags
|= CMD_WANT_SKB
;
839 rc
= iwl_send_cmd(priv
, &cmd
);
841 if (rc
|| (flags
& CMD_ASYNC
))
844 res
= (struct iwl_rx_packet
*)cmd
.meta
.u
.skb
->data
;
845 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
846 IWL_ERR(priv
, "Bad return from REPLY_ADD_STA (0x%08X)\n",
852 switch (res
->u
.add_sta
.status
) {
853 case ADD_STA_SUCCESS_MSK
:
854 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
858 IWL_WARN(priv
, "REPLY_ADD_STA failed\n");
863 priv
->alloc_rxb_skb
--;
864 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
869 static int iwl3945_update_sta_key_info(struct iwl_priv
*priv
,
870 struct ieee80211_key_conf
*keyconf
,
874 __le16 key_flags
= 0;
876 switch (keyconf
->alg
) {
878 key_flags
|= STA_KEY_FLG_CCMP
;
879 key_flags
|= cpu_to_le16(
880 keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
881 key_flags
&= ~STA_KEY_FLG_INVALID
;
888 spin_lock_irqsave(&priv
->sta_lock
, flags
);
889 priv
->stations_39
[sta_id
].keyinfo
.alg
= keyconf
->alg
;
890 priv
->stations_39
[sta_id
].keyinfo
.keylen
= keyconf
->keylen
;
891 memcpy(priv
->stations_39
[sta_id
].keyinfo
.key
, keyconf
->key
,
894 memcpy(priv
->stations_39
[sta_id
].sta
.key
.key
, keyconf
->key
,
896 priv
->stations_39
[sta_id
].sta
.key
.key_flags
= key_flags
;
897 priv
->stations_39
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
898 priv
->stations_39
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
900 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
902 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
903 iwl3945_send_add_station(priv
, &priv
->stations_39
[sta_id
].sta
, 0);
907 static int iwl3945_clear_sta_key_info(struct iwl_priv
*priv
, u8 sta_id
)
911 spin_lock_irqsave(&priv
->sta_lock
, flags
);
912 memset(&priv
->stations_39
[sta_id
].keyinfo
, 0, sizeof(struct iwl3945_hw_key
));
913 memset(&priv
->stations_39
[sta_id
].sta
.key
, 0,
914 sizeof(struct iwl4965_keyinfo
));
915 priv
->stations_39
[sta_id
].sta
.key
.key_flags
= STA_KEY_FLG_NO_ENC
;
916 priv
->stations_39
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
917 priv
->stations_39
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
918 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
920 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
921 iwl3945_send_add_station(priv
, &priv
->stations_39
[sta_id
].sta
, 0);
925 static void iwl3945_clear_free_frames(struct iwl_priv
*priv
)
927 struct list_head
*element
;
929 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
932 while (!list_empty(&priv
->free_frames
)) {
933 element
= priv
->free_frames
.next
;
935 kfree(list_entry(element
, struct iwl3945_frame
, list
));
936 priv
->frames_count
--;
939 if (priv
->frames_count
) {
940 IWL_WARN(priv
, "%d frames still in use. Did we lose one?\n",
942 priv
->frames_count
= 0;
946 static struct iwl3945_frame
*iwl3945_get_free_frame(struct iwl_priv
*priv
)
948 struct iwl3945_frame
*frame
;
949 struct list_head
*element
;
950 if (list_empty(&priv
->free_frames
)) {
951 frame
= kzalloc(sizeof(*frame
), GFP_KERNEL
);
953 IWL_ERR(priv
, "Could not allocate frame!\n");
957 priv
->frames_count
++;
961 element
= priv
->free_frames
.next
;
963 return list_entry(element
, struct iwl3945_frame
, list
);
966 static void iwl3945_free_frame(struct iwl_priv
*priv
, struct iwl3945_frame
*frame
)
968 memset(frame
, 0, sizeof(*frame
));
969 list_add(&frame
->list
, &priv
->free_frames
);
972 unsigned int iwl3945_fill_beacon_frame(struct iwl_priv
*priv
,
973 struct ieee80211_hdr
*hdr
,
977 if (!iwl3945_is_associated(priv
) || !priv
->ibss_beacon
||
978 ((priv
->iw_mode
!= NL80211_IFTYPE_ADHOC
) &&
979 (priv
->iw_mode
!= NL80211_IFTYPE_AP
)))
982 if (priv
->ibss_beacon
->len
> left
)
985 memcpy(hdr
, priv
->ibss_beacon
->data
, priv
->ibss_beacon
->len
);
987 return priv
->ibss_beacon
->len
;
990 static u8
iwl3945_rate_get_lowest_plcp(struct iwl_priv
*priv
)
996 if (priv
->staging39_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
997 rate_mask
= priv
->active_rate_basic
& IWL_CCK_RATES_MASK
;
999 rate_mask
= priv
->active_rate_basic
& IWL_OFDM_RATES_MASK
;
1001 for (i
= IWL_RATE_1M_INDEX
; i
!= IWL_RATE_INVALID
;
1002 i
= iwl3945_rates
[i
].next_ieee
) {
1003 if (rate_mask
& (1 << i
))
1004 return iwl3945_rates
[i
].plcp
;
1007 /* No valid rate was found. Assign the lowest one */
1008 if (priv
->staging39_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
1009 return IWL_RATE_1M_PLCP
;
1011 return IWL_RATE_6M_PLCP
;
1014 static int iwl3945_send_beacon_cmd(struct iwl_priv
*priv
)
1016 struct iwl3945_frame
*frame
;
1017 unsigned int frame_size
;
1021 frame
= iwl3945_get_free_frame(priv
);
1024 IWL_ERR(priv
, "Could not obtain free frame buffer for beacon "
1029 rate
= iwl3945_rate_get_lowest_plcp(priv
);
1031 frame_size
= iwl3945_hw_get_beacon_cmd(priv
, frame
, rate
);
1033 rc
= iwl_send_cmd_pdu(priv
, REPLY_TX_BEACON
, frame_size
,
1036 iwl3945_free_frame(priv
, frame
);
1041 /******************************************************************************
1043 * EEPROM related functions
1045 ******************************************************************************/
1047 static void get_eeprom_mac(struct iwl_priv
*priv
, u8
*mac
)
1049 memcpy(mac
, priv
->eeprom39
.mac_address
, 6);
1053 * Clear the OWNER_MSK, to establish driver (instead of uCode running on
1054 * embedded controller) as EEPROM reader; each read is a series of pulses
1055 * to/from the EEPROM chip, not a single event, so even reads could conflict
1056 * if they weren't arbitrated by some ownership mechanism. Here, the driver
1057 * simply claims ownership, which should be safe when this function is called
1058 * (i.e. before loading uCode!).
1060 static inline int iwl3945_eeprom_acquire_semaphore(struct iwl_priv
*priv
)
1062 _iwl_clear_bit(priv
, CSR_EEPROM_GP
, CSR_EEPROM_GP_IF_OWNER_MSK
);
1067 * iwl3945_eeprom_init - read EEPROM contents
1069 * Load the EEPROM contents from adapter into priv->eeprom39
1071 * NOTE: This routine uses the non-debug IO access functions.
1073 int iwl3945_eeprom_init(struct iwl_priv
*priv
)
1075 u16
*e
= (u16
*)&priv
->eeprom39
;
1076 u32 gp
= iwl_read32(priv
, CSR_EEPROM_GP
);
1077 int sz
= sizeof(priv
->eeprom39
);
1081 /* The EEPROM structure has several padding buffers within it
1082 * and when adding new EEPROM maps is subject to programmer errors
1083 * which may be very difficult to identify without explicitly
1084 * checking the resulting size of the eeprom map. */
1085 BUILD_BUG_ON(sizeof(priv
->eeprom39
) != IWL_EEPROM_IMAGE_SIZE
);
1087 if ((gp
& CSR_EEPROM_GP_VALID_MSK
) == CSR_EEPROM_GP_BAD_SIGNATURE
) {
1088 IWL_ERR(priv
, "EEPROM not found, EEPROM_GP=0x%08x\n", gp
);
1092 /* Make sure driver (instead of uCode) is allowed to read EEPROM */
1093 ret
= iwl3945_eeprom_acquire_semaphore(priv
);
1095 IWL_ERR(priv
, "Failed to acquire EEPROM semaphore.\n");
1099 /* eeprom is an array of 16bit values */
1100 for (addr
= 0; addr
< sz
; addr
+= sizeof(u16
)) {
1103 _iwl_write32(priv
, CSR_EEPROM_REG
,
1104 CSR_EEPROM_REG_MSK_ADDR
& (addr
<< 1));
1105 _iwl_clear_bit(priv
, CSR_EEPROM_REG
, CSR_EEPROM_REG_BIT_CMD
);
1106 ret
= iwl_poll_direct_bit(priv
, CSR_EEPROM_REG
,
1107 CSR_EEPROM_REG_READ_VALID_MSK
,
1108 IWL_EEPROM_ACCESS_TIMEOUT
);
1110 IWL_ERR(priv
, "Time out reading EEPROM[%d]\n", addr
);
1114 r
= _iwl_read_direct32(priv
, CSR_EEPROM_REG
);
1115 e
[addr
/ 2] = le16_to_cpu((__force __le16
)(r
>> 16));
1121 static void iwl3945_unset_hw_params(struct iwl_priv
*priv
)
1123 if (priv
->shared_virt
)
1124 pci_free_consistent(priv
->pci_dev
,
1125 sizeof(struct iwl3945_shared
),
1133 static int iwl3945_send_qos_params_command(struct iwl_priv
*priv
,
1134 struct iwl_qosparam_cmd
*qos
)
1137 return iwl_send_cmd_pdu(priv
, REPLY_QOS_PARAM
,
1138 sizeof(struct iwl_qosparam_cmd
), qos
);
1141 static void iwl3945_activate_qos(struct iwl_priv
*priv
, u8 force
)
1143 unsigned long flags
;
1145 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
1148 spin_lock_irqsave(&priv
->lock
, flags
);
1149 priv
->qos_data
.def_qos_parm
.qos_flags
= 0;
1151 if (priv
->qos_data
.qos_cap
.q_AP
.queue_request
&&
1152 !priv
->qos_data
.qos_cap
.q_AP
.txop_request
)
1153 priv
->qos_data
.def_qos_parm
.qos_flags
|=
1154 QOS_PARAM_FLG_TXOP_TYPE_MSK
;
1156 if (priv
->qos_data
.qos_active
)
1157 priv
->qos_data
.def_qos_parm
.qos_flags
|=
1158 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
1160 spin_unlock_irqrestore(&priv
->lock
, flags
);
1162 if (force
|| iwl3945_is_associated(priv
)) {
1163 IWL_DEBUG_QOS("send QoS cmd with QoS active %d \n",
1164 priv
->qos_data
.qos_active
);
1166 iwl3945_send_qos_params_command(priv
,
1167 &(priv
->qos_data
.def_qos_parm
));
1172 * Power management (not Tx power!) functions
1174 #define MSEC_TO_USEC 1024
1177 /* default power management (not Tx power) table values */
1179 static struct iwl_power_vec_entry range_0
[IWL_POWER_MAX
] = {
1180 {{NOSLP
, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1181 {{SLP
, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
1182 {{SLP
, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
1183 {{SLP
, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
1184 {{SLP
, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
1185 {{SLP
, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
1189 static struct iwl_power_vec_entry range_1
[IWL_POWER_MAX
] = {
1190 {{NOSLP
, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1191 {{SLP
, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
1192 {{SLP
, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
1193 {{SLP
, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
1194 {{SLP
, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
1195 {{SLP
, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
1198 int iwl3945_power_init_handle(struct iwl_priv
*priv
)
1201 struct iwl_power_mgr
*pow_data
;
1202 int size
= sizeof(struct iwl_power_vec_entry
) * IWL_POWER_MAX
;
1205 IWL_DEBUG_POWER("Initialize power \n");
1207 pow_data
= &priv
->power_data
;
1209 memset(pow_data
, 0, sizeof(*pow_data
));
1211 pow_data
->dtim_period
= 1;
1213 memcpy(&pow_data
->pwr_range_0
[0], &range_0
[0], size
);
1214 memcpy(&pow_data
->pwr_range_1
[0], &range_1
[0], size
);
1216 rc
= pci_read_config_word(priv
->pci_dev
, PCI_LINK_CTRL
, &pci_pm
);
1220 struct iwl_powertable_cmd
*cmd
;
1222 IWL_DEBUG_POWER("adjust power command flags\n");
1224 for (i
= 0; i
< IWL_POWER_MAX
; i
++) {
1225 cmd
= &pow_data
->pwr_range_0
[i
].cmd
;
1228 cmd
->flags
&= ~IWL_POWER_PCI_PM_MSK
;
1230 cmd
->flags
|= IWL_POWER_PCI_PM_MSK
;
1236 static int iwl3945_update_power_cmd(struct iwl_priv
*priv
,
1237 struct iwl_powertable_cmd
*cmd
, u32 mode
)
1239 struct iwl_power_mgr
*pow_data
;
1240 struct iwl_power_vec_entry
*range
;
1246 if (mode
> IWL_POWER_INDEX_5
) {
1247 IWL_DEBUG_POWER("Error invalid power mode \n");
1250 pow_data
= &priv
->power_data
;
1252 if (pow_data
->dtim_period
< 10)
1253 range
= &pow_data
->pwr_range_0
[0];
1255 range
= &pow_data
->pwr_range_1
[1];
1257 memcpy(cmd
, &range
[mode
].cmd
, sizeof(struct iwl3945_powertable_cmd
));
1264 skip
= !!range
[mode
].no_dtim
;
1268 __le32 slp_itrvl
= cmd
->sleep_interval
[IWL_POWER_VEC_SIZE
- 1];
1269 max_sleep
= (le32_to_cpu(slp_itrvl
) / period
) * period
;
1270 cmd
->flags
|= IWL_POWER_SLEEP_OVER_DTIM_MSK
;
1273 cmd
->flags
&= ~IWL_POWER_SLEEP_OVER_DTIM_MSK
;
1276 for (i
= 0; i
< IWL_POWER_VEC_SIZE
; i
++)
1277 if (le32_to_cpu(cmd
->sleep_interval
[i
]) > max_sleep
)
1278 cmd
->sleep_interval
[i
] = cpu_to_le32(max_sleep
);
1280 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd
->flags
);
1281 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd
->tx_data_timeout
));
1282 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd
->rx_data_timeout
));
1283 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
1284 le32_to_cpu(cmd
->sleep_interval
[0]),
1285 le32_to_cpu(cmd
->sleep_interval
[1]),
1286 le32_to_cpu(cmd
->sleep_interval
[2]),
1287 le32_to_cpu(cmd
->sleep_interval
[3]),
1288 le32_to_cpu(cmd
->sleep_interval
[4]));
1293 static int iwl3945_send_power_mode(struct iwl_priv
*priv
, u32 mode
)
1295 u32
uninitialized_var(final_mode
);
1297 struct iwl_powertable_cmd cmd
;
1299 /* If on battery, set to 3,
1300 * if plugged into AC power, set to CAM ("continuously aware mode"),
1301 * else user level */
1303 case IWL39_POWER_BATTERY
:
1304 final_mode
= IWL_POWER_INDEX_3
;
1306 case IWL39_POWER_AC
:
1307 final_mode
= IWL_POWER_MODE_CAM
;
1314 iwl3945_update_power_cmd(priv
, &cmd
, final_mode
);
1316 /* FIXME use get_hcmd_size 3945 command is 4 bytes shorter */
1317 rc
= iwl_send_cmd_pdu(priv
, POWER_TABLE_CMD
,
1318 sizeof(struct iwl3945_powertable_cmd
), &cmd
);
1320 if (final_mode
== IWL_POWER_MODE_CAM
)
1321 clear_bit(STATUS_POWER_PMI
, &priv
->status
);
1323 set_bit(STATUS_POWER_PMI
, &priv
->status
);
1328 #define MAX_UCODE_BEACON_INTERVAL 1024
1329 #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
1331 static __le16
iwl3945_adjust_beacon_interval(u16 beacon_val
)
1334 u16 beacon_factor
= 0;
1337 (beacon_val
+ MAX_UCODE_BEACON_INTERVAL
)
1338 / MAX_UCODE_BEACON_INTERVAL
;
1339 new_val
= beacon_val
/ beacon_factor
;
1341 return cpu_to_le16(new_val
);
1344 static void iwl3945_setup_rxon_timing(struct iwl_priv
*priv
)
1346 u64 interval_tm_unit
;
1348 unsigned long flags
;
1349 struct ieee80211_conf
*conf
= NULL
;
1352 conf
= ieee80211_get_hw_conf(priv
->hw
);
1354 spin_lock_irqsave(&priv
->lock
, flags
);
1355 priv
->rxon_timing
.timestamp
= cpu_to_le64(priv
->timestamp
);
1356 priv
->rxon_timing
.listen_interval
= INTEL_CONN_LISTEN_INTERVAL
;
1358 tsf
= priv
->timestamp
;
1360 beacon_int
= priv
->beacon_int
;
1361 spin_unlock_irqrestore(&priv
->lock
, flags
);
1363 if (priv
->iw_mode
== NL80211_IFTYPE_STATION
) {
1364 if (beacon_int
== 0) {
1365 priv
->rxon_timing
.beacon_interval
= cpu_to_le16(100);
1366 priv
->rxon_timing
.beacon_init_val
= cpu_to_le32(102400);
1368 priv
->rxon_timing
.beacon_interval
=
1369 cpu_to_le16(beacon_int
);
1370 priv
->rxon_timing
.beacon_interval
=
1371 iwl3945_adjust_beacon_interval(
1372 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
1375 priv
->rxon_timing
.atim_window
= 0;
1377 priv
->rxon_timing
.beacon_interval
=
1378 iwl3945_adjust_beacon_interval(conf
->beacon_int
);
1379 /* TODO: we need to get atim_window from upper stack
1380 * for now we set to 0 */
1381 priv
->rxon_timing
.atim_window
= 0;
1385 (le16_to_cpu(priv
->rxon_timing
.beacon_interval
) * 1024);
1386 result
= do_div(tsf
, interval_tm_unit
);
1387 priv
->rxon_timing
.beacon_init_val
=
1388 cpu_to_le32((u32
) ((u64
) interval_tm_unit
- result
));
1391 ("beacon interval %d beacon timer %d beacon tim %d\n",
1392 le16_to_cpu(priv
->rxon_timing
.beacon_interval
),
1393 le32_to_cpu(priv
->rxon_timing
.beacon_init_val
),
1394 le16_to_cpu(priv
->rxon_timing
.atim_window
));
1397 static int iwl3945_scan_initiate(struct iwl_priv
*priv
)
1399 if (!iwl_is_ready_rf(priv
)) {
1400 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
1404 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
1405 IWL_DEBUG_SCAN("Scan already in progress.\n");
1409 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
1410 IWL_DEBUG_SCAN("Scan request while abort pending. "
1415 IWL_DEBUG_INFO("Starting scan...\n");
1416 if (priv
->cfg
->sku
& IWL_SKU_G
)
1417 priv
->scan_bands
|= BIT(IEEE80211_BAND_2GHZ
);
1418 if (priv
->cfg
->sku
& IWL_SKU_A
)
1419 priv
->scan_bands
|= BIT(IEEE80211_BAND_5GHZ
);
1420 set_bit(STATUS_SCANNING
, &priv
->status
);
1421 priv
->scan_start
= jiffies
;
1422 priv
->scan_pass_start
= priv
->scan_start
;
1424 queue_work(priv
->workqueue
, &priv
->request_scan
);
1429 static int iwl3945_set_rxon_hwcrypto(struct iwl_priv
*priv
, int hw_decrypt
)
1431 struct iwl3945_rxon_cmd
*rxon
= &priv
->staging39_rxon
;
1434 rxon
->filter_flags
&= ~RXON_FILTER_DIS_DECRYPT_MSK
;
1436 rxon
->filter_flags
|= RXON_FILTER_DIS_DECRYPT_MSK
;
1441 static void iwl3945_set_flags_for_phymode(struct iwl_priv
*priv
,
1442 enum ieee80211_band band
)
1444 if (band
== IEEE80211_BAND_5GHZ
) {
1445 priv
->staging39_rxon
.flags
&=
1446 ~(RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
1447 | RXON_FLG_CCK_MSK
);
1448 priv
->staging39_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
1450 /* Copied from iwl3945_bg_post_associate() */
1451 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
1452 priv
->staging39_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
1454 priv
->staging39_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
1456 if (priv
->iw_mode
== NL80211_IFTYPE_ADHOC
)
1457 priv
->staging39_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
1459 priv
->staging39_rxon
.flags
|= RXON_FLG_BAND_24G_MSK
;
1460 priv
->staging39_rxon
.flags
|= RXON_FLG_AUTO_DETECT_MSK
;
1461 priv
->staging39_rxon
.flags
&= ~RXON_FLG_CCK_MSK
;
1466 * initialize rxon structure with default values from eeprom
1468 static void iwl3945_connection_init_rx_config(struct iwl_priv
*priv
,
1471 const struct iwl_channel_info
*ch_info
;
1473 memset(&priv
->staging39_rxon
, 0, sizeof(priv
->staging39_rxon
));
1476 case NL80211_IFTYPE_AP
:
1477 priv
->staging39_rxon
.dev_type
= RXON_DEV_TYPE_AP
;
1480 case NL80211_IFTYPE_STATION
:
1481 priv
->staging39_rxon
.dev_type
= RXON_DEV_TYPE_ESS
;
1482 priv
->staging39_rxon
.filter_flags
= RXON_FILTER_ACCEPT_GRP_MSK
;
1485 case NL80211_IFTYPE_ADHOC
:
1486 priv
->staging39_rxon
.dev_type
= RXON_DEV_TYPE_IBSS
;
1487 priv
->staging39_rxon
.flags
= RXON_FLG_SHORT_PREAMBLE_MSK
;
1488 priv
->staging39_rxon
.filter_flags
= RXON_FILTER_BCON_AWARE_MSK
|
1489 RXON_FILTER_ACCEPT_GRP_MSK
;
1492 case NL80211_IFTYPE_MONITOR
:
1493 priv
->staging39_rxon
.dev_type
= RXON_DEV_TYPE_SNIFFER
;
1494 priv
->staging39_rxon
.filter_flags
= RXON_FILTER_PROMISC_MSK
|
1495 RXON_FILTER_CTL2HOST_MSK
| RXON_FILTER_ACCEPT_GRP_MSK
;
1498 IWL_ERR(priv
, "Unsupported interface type %d\n", mode
);
1503 /* TODO: Figure out when short_preamble would be set and cache from
1505 if (!hw_to_local(priv
->hw
)->short_preamble
)
1506 priv
->staging39_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
1508 priv
->staging39_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
1511 ch_info
= iwl3945_get_channel_info(priv
, priv
->band
,
1512 le16_to_cpu(priv
->active39_rxon
.channel
));
1515 ch_info
= &priv
->channel_info
[0];
1518 * in some case A channels are all non IBSS
1519 * in this case force B/G channel
1521 if ((mode
== NL80211_IFTYPE_ADHOC
) && !(is_channel_ibss(ch_info
)))
1522 ch_info
= &priv
->channel_info
[0];
1524 priv
->staging39_rxon
.channel
= cpu_to_le16(ch_info
->channel
);
1525 if (is_channel_a_band(ch_info
))
1526 priv
->band
= IEEE80211_BAND_5GHZ
;
1528 priv
->band
= IEEE80211_BAND_2GHZ
;
1530 iwl3945_set_flags_for_phymode(priv
, priv
->band
);
1532 priv
->staging39_rxon
.ofdm_basic_rates
=
1533 (IWL_OFDM_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
1534 priv
->staging39_rxon
.cck_basic_rates
=
1535 (IWL_CCK_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
1538 static int iwl3945_set_mode(struct iwl_priv
*priv
, int mode
)
1540 if (mode
== NL80211_IFTYPE_ADHOC
) {
1541 const struct iwl_channel_info
*ch_info
;
1543 ch_info
= iwl3945_get_channel_info(priv
,
1545 le16_to_cpu(priv
->staging39_rxon
.channel
));
1547 if (!ch_info
|| !is_channel_ibss(ch_info
)) {
1548 IWL_ERR(priv
, "channel %d not IBSS channel\n",
1549 le16_to_cpu(priv
->staging39_rxon
.channel
));
1554 iwl3945_connection_init_rx_config(priv
, mode
);
1555 memcpy(priv
->staging39_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
1557 iwl3945_clear_stations_table(priv
);
1559 /* don't commit rxon if rf-kill is on*/
1560 if (!iwl_is_ready_rf(priv
))
1563 cancel_delayed_work(&priv
->scan_check
);
1564 if (iwl_scan_cancel_timeout(priv
, 100)) {
1565 IWL_WARN(priv
, "Aborted scan still in progress after 100ms\n");
1566 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
1570 iwl3945_commit_rxon(priv
);
1575 static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv
*priv
,
1576 struct ieee80211_tx_info
*info
,
1577 struct iwl_cmd
*cmd
,
1578 struct sk_buff
*skb_frag
,
1581 struct iwl3945_tx_cmd
*tx
= (struct iwl3945_tx_cmd
*)cmd
->cmd
.payload
;
1582 struct iwl3945_hw_key
*keyinfo
=
1583 &priv
->stations_39
[info
->control
.hw_key
->hw_key_idx
].keyinfo
;
1585 switch (keyinfo
->alg
) {
1587 tx
->sec_ctl
= TX_CMD_SEC_CCM
;
1588 memcpy(tx
->key
, keyinfo
->key
, keyinfo
->keylen
);
1589 IWL_DEBUG_TX("tx_cmd with AES hwcrypto\n");
1594 tx
->sec_ctl
= TX_CMD_SEC_TKIP
;
1597 memcpy(tx
->tkip_mic
.byte
, skb_frag
->tail
- 8,
1600 memset(tx
->tkip_mic
.byte
, 0, 8);
1605 tx
->sec_ctl
= TX_CMD_SEC_WEP
|
1606 (info
->control
.hw_key
->hw_key_idx
& TX_CMD_SEC_MSK
) << TX_CMD_SEC_SHIFT
;
1608 if (keyinfo
->keylen
== 13)
1609 tx
->sec_ctl
|= TX_CMD_SEC_KEY128
;
1611 memcpy(&tx
->key
[3], keyinfo
->key
, keyinfo
->keylen
);
1613 IWL_DEBUG_TX("Configuring packet for WEP encryption "
1614 "with key %d\n", info
->control
.hw_key
->hw_key_idx
);
1618 IWL_ERR(priv
, "Unknown encode alg %d\n", keyinfo
->alg
);
1624 * handle build REPLY_TX command notification.
1626 static void iwl3945_build_tx_cmd_basic(struct iwl_priv
*priv
,
1627 struct iwl_cmd
*cmd
,
1628 struct ieee80211_tx_info
*info
,
1629 struct ieee80211_hdr
*hdr
, u8 std_id
)
1631 struct iwl3945_tx_cmd
*tx
= (struct iwl3945_tx_cmd
*)cmd
->cmd
.payload
;
1632 __le32 tx_flags
= tx
->tx_flags
;
1633 __le16 fc
= hdr
->frame_control
;
1634 u8 rc_flags
= info
->control
.rates
[0].flags
;
1636 tx
->stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
1637 if (!(info
->flags
& IEEE80211_TX_CTL_NO_ACK
)) {
1638 tx_flags
|= TX_CMD_FLG_ACK_MSK
;
1639 if (ieee80211_is_mgmt(fc
))
1640 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
1641 if (ieee80211_is_probe_resp(fc
) &&
1642 !(le16_to_cpu(hdr
->seq_ctrl
) & 0xf))
1643 tx_flags
|= TX_CMD_FLG_TSF_MSK
;
1645 tx_flags
&= (~TX_CMD_FLG_ACK_MSK
);
1646 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
1649 tx
->sta_id
= std_id
;
1650 if (ieee80211_has_morefrags(fc
))
1651 tx_flags
|= TX_CMD_FLG_MORE_FRAG_MSK
;
1653 if (ieee80211_is_data_qos(fc
)) {
1654 u8
*qc
= ieee80211_get_qos_ctl(hdr
);
1655 tx
->tid_tspec
= qc
[0] & 0xf;
1656 tx_flags
&= ~TX_CMD_FLG_SEQ_CTL_MSK
;
1658 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
1661 if (rc_flags
& IEEE80211_TX_RC_USE_RTS_CTS
) {
1662 tx_flags
|= TX_CMD_FLG_RTS_MSK
;
1663 tx_flags
&= ~TX_CMD_FLG_CTS_MSK
;
1664 } else if (rc_flags
& IEEE80211_TX_RC_USE_CTS_PROTECT
) {
1665 tx_flags
&= ~TX_CMD_FLG_RTS_MSK
;
1666 tx_flags
|= TX_CMD_FLG_CTS_MSK
;
1669 if ((tx_flags
& TX_CMD_FLG_RTS_MSK
) || (tx_flags
& TX_CMD_FLG_CTS_MSK
))
1670 tx_flags
|= TX_CMD_FLG_FULL_TXOP_PROT_MSK
;
1672 tx_flags
&= ~(TX_CMD_FLG_ANT_SEL_MSK
);
1673 if (ieee80211_is_mgmt(fc
)) {
1674 if (ieee80211_is_assoc_req(fc
) || ieee80211_is_reassoc_req(fc
))
1675 tx
->timeout
.pm_frame_timeout
= cpu_to_le16(3);
1677 tx
->timeout
.pm_frame_timeout
= cpu_to_le16(2);
1679 tx
->timeout
.pm_frame_timeout
= 0;
1680 #ifdef CONFIG_IWL3945_LEDS
1681 priv
->rxtxpackets
+= le16_to_cpu(cmd
->cmd
.tx
.len
);
1685 tx
->driver_txop
= 0;
1686 tx
->tx_flags
= tx_flags
;
1687 tx
->next_frame_len
= 0;
1691 * iwl3945_get_sta_id - Find station's index within station table
1693 static int iwl3945_get_sta_id(struct iwl_priv
*priv
, struct ieee80211_hdr
*hdr
)
1696 u16 fc
= le16_to_cpu(hdr
->frame_control
);
1698 /* If this frame is broadcast or management, use broadcast station id */
1699 if (((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
) ||
1700 is_multicast_ether_addr(hdr
->addr1
))
1701 return priv
->hw_params
.bcast_sta_id
;
1703 switch (priv
->iw_mode
) {
1705 /* If we are a client station in a BSS network, use the special
1706 * AP station entry (that's the only station we communicate with) */
1707 case NL80211_IFTYPE_STATION
:
1710 /* If we are an AP, then find the station, or use BCAST */
1711 case NL80211_IFTYPE_AP
:
1712 sta_id
= iwl3945_hw_find_station(priv
, hdr
->addr1
);
1713 if (sta_id
!= IWL_INVALID_STATION
)
1715 return priv
->hw_params
.bcast_sta_id
;
1717 /* If this frame is going out to an IBSS network, find the station,
1718 * or create a new station table entry */
1719 case NL80211_IFTYPE_ADHOC
: {
1720 /* Create new station table entry */
1721 sta_id
= iwl3945_hw_find_station(priv
, hdr
->addr1
);
1722 if (sta_id
!= IWL_INVALID_STATION
)
1725 sta_id
= iwl3945_add_station(priv
, hdr
->addr1
, 0, CMD_ASYNC
);
1727 if (sta_id
!= IWL_INVALID_STATION
)
1730 IWL_DEBUG_DROP("Station %pM not in station map. "
1731 "Defaulting to broadcast...\n",
1733 iwl_print_hex_dump(priv
, IWL_DL_DROP
, (u8
*) hdr
, sizeof(*hdr
));
1734 return priv
->hw_params
.bcast_sta_id
;
1736 /* If we are in monitor mode, use BCAST. This is required for
1737 * packet injection. */
1738 case NL80211_IFTYPE_MONITOR
:
1739 return priv
->hw_params
.bcast_sta_id
;
1742 IWL_WARN(priv
, "Unknown mode of operation: %d\n",
1744 return priv
->hw_params
.bcast_sta_id
;
1749 * start REPLY_TX command process
1751 static int iwl3945_tx_skb(struct iwl_priv
*priv
, struct sk_buff
*skb
)
1753 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1754 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1755 struct iwl3945_tx_cmd
*tx
;
1756 struct iwl_tx_queue
*txq
= NULL
;
1757 struct iwl_queue
*q
= NULL
;
1758 struct iwl_cmd
*out_cmd
= NULL
;
1759 dma_addr_t phys_addr
;
1760 dma_addr_t txcmd_phys
;
1761 int txq_id
= skb_get_queue_mapping(skb
);
1762 u16 len
, idx
, len_org
, hdr_len
;
1769 u8 wait_write_ptr
= 0;
1771 unsigned long flags
;
1774 spin_lock_irqsave(&priv
->lock
, flags
);
1775 if (iwl_is_rfkill(priv
)) {
1776 IWL_DEBUG_DROP("Dropping - RF KILL\n");
1780 if ((ieee80211_get_tx_rate(priv
->hw
, info
)->hw_value
& 0xFF) == IWL_INVALID_RATE
) {
1781 IWL_ERR(priv
, "ERROR: No TX rate available.\n");
1785 unicast
= !is_multicast_ether_addr(hdr
->addr1
);
1788 fc
= hdr
->frame_control
;
1790 #ifdef CONFIG_IWL3945_DEBUG
1791 if (ieee80211_is_auth(fc
))
1792 IWL_DEBUG_TX("Sending AUTH frame\n");
1793 else if (ieee80211_is_assoc_req(fc
))
1794 IWL_DEBUG_TX("Sending ASSOC frame\n");
1795 else if (ieee80211_is_reassoc_req(fc
))
1796 IWL_DEBUG_TX("Sending REASSOC frame\n");
1799 /* drop all data frame if we are not associated */
1800 if (ieee80211_is_data(fc
) &&
1801 (priv
->iw_mode
!= NL80211_IFTYPE_MONITOR
) && /* packet injection */
1802 (!iwl3945_is_associated(priv
) ||
1803 ((priv
->iw_mode
== NL80211_IFTYPE_STATION
) && !priv
->assoc_id
))) {
1804 IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n");
1808 spin_unlock_irqrestore(&priv
->lock
, flags
);
1810 hdr_len
= ieee80211_hdrlen(fc
);
1812 /* Find (or create) index into station table for destination station */
1813 sta_id
= iwl3945_get_sta_id(priv
, hdr
);
1814 if (sta_id
== IWL_INVALID_STATION
) {
1815 IWL_DEBUG_DROP("Dropping - INVALID STATION: %pM\n",
1820 IWL_DEBUG_RATE("station Id %d\n", sta_id
);
1822 if (ieee80211_is_data_qos(fc
)) {
1823 qc
= ieee80211_get_qos_ctl(hdr
);
1824 tid
= qc
[0] & IEEE80211_QOS_CTL_TID_MASK
;
1825 seq_number
= priv
->stations_39
[sta_id
].tid
[tid
].seq_number
&
1827 hdr
->seq_ctrl
= cpu_to_le16(seq_number
) |
1829 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG
));
1833 /* Descriptor for chosen Tx queue */
1834 txq
= &priv
->txq
[txq_id
];
1837 spin_lock_irqsave(&priv
->lock
, flags
);
1839 idx
= get_cmd_index(q
, q
->write_ptr
, 0);
1841 /* Set up driver data for this TFD */
1842 memset(&(txq
->txb
[q
->write_ptr
]), 0, sizeof(struct iwl_tx_info
));
1843 txq
->txb
[q
->write_ptr
].skb
[0] = skb
;
1845 /* Init first empty entry in queue's array of Tx/cmd buffers */
1846 out_cmd
= txq
->cmd
[idx
];
1847 tx
= (struct iwl3945_tx_cmd
*)out_cmd
->cmd
.payload
;
1848 memset(&out_cmd
->hdr
, 0, sizeof(out_cmd
->hdr
));
1849 memset(tx
, 0, sizeof(*tx
));
1852 * Set up the Tx-command (not MAC!) header.
1853 * Store the chosen Tx queue and TFD index within the sequence field;
1854 * after Tx, uCode's Tx response will return this value so driver can
1855 * locate the frame within the tx queue and do post-tx processing.
1857 out_cmd
->hdr
.cmd
= REPLY_TX
;
1858 out_cmd
->hdr
.sequence
= cpu_to_le16((u16
)(QUEUE_TO_SEQ(txq_id
) |
1859 INDEX_TO_SEQ(q
->write_ptr
)));
1861 /* Copy MAC header from skb into command buffer */
1862 memcpy(tx
->hdr
, hdr
, hdr_len
);
1865 * Use the first empty entry in this queue's command buffer array
1866 * to contain the Tx command and MAC header concatenated together
1867 * (payload data will be in another buffer).
1868 * Size of this varies, due to varying MAC header length.
1869 * If end is not dword aligned, we'll have 2 extra bytes at the end
1870 * of the MAC header (device reads on dword boundaries).
1871 * We'll tell device about this padding later.
1873 len
= sizeof(struct iwl3945_tx_cmd
) +
1874 sizeof(struct iwl_cmd_header
) + hdr_len
;
1877 len
= (len
+ 3) & ~3;
1884 /* Physical address of this Tx command's header (not MAC header!),
1885 * within command buffer array. */
1886 txcmd_phys
= pci_map_single(priv
->pci_dev
,
1887 out_cmd
, sizeof(struct iwl_cmd
),
1889 pci_unmap_addr_set(&out_cmd
->meta
, mapping
, txcmd_phys
);
1890 pci_unmap_len_set(&out_cmd
->meta
, len
, sizeof(struct iwl_cmd
));
1891 /* Add buffer containing Tx command and MAC(!) header to TFD's
1893 txcmd_phys
+= offsetof(struct iwl_cmd
, hdr
);
1895 /* Add buffer containing Tx command and MAC(!) header to TFD's
1897 priv
->cfg
->ops
->lib
->txq_attach_buf_to_tfd(priv
, txq
,
1898 txcmd_phys
, len
, 1, 0);
1900 if (info
->control
.hw_key
)
1901 iwl3945_build_tx_cmd_hwcrypto(priv
, info
, out_cmd
, skb
, 0);
1903 /* Set up TFD's 2nd entry to point directly to remainder of skb,
1904 * if any (802.11 null frames have no payload). */
1905 len
= skb
->len
- hdr_len
;
1907 phys_addr
= pci_map_single(priv
->pci_dev
, skb
->data
+ hdr_len
,
1908 len
, PCI_DMA_TODEVICE
);
1909 priv
->cfg
->ops
->lib
->txq_attach_buf_to_tfd(priv
, txq
,
1914 /* Total # bytes to be transmitted */
1915 len
= (u16
)skb
->len
;
1916 tx
->len
= cpu_to_le16(len
);
1918 /* TODO need this for burst mode later on */
1919 iwl3945_build_tx_cmd_basic(priv
, out_cmd
, info
, hdr
, sta_id
);
1921 /* set is_hcca to 0; it probably will never be implemented */
1922 iwl3945_hw_build_tx_cmd_rate(priv
, out_cmd
, info
, hdr
, sta_id
, 0);
1924 tx
->tx_flags
&= ~TX_CMD_FLG_ANT_A_MSK
;
1925 tx
->tx_flags
&= ~TX_CMD_FLG_ANT_B_MSK
;
1927 if (!ieee80211_has_morefrags(hdr
->frame_control
)) {
1928 txq
->need_update
= 1;
1930 priv
->stations_39
[sta_id
].tid
[tid
].seq_number
= seq_number
;
1933 txq
->need_update
= 0;
1936 iwl_print_hex_dump(priv
, IWL_DL_TX
, tx
, sizeof(*tx
));
1938 iwl_print_hex_dump(priv
, IWL_DL_TX
, (u8
*)tx
->hdr
,
1939 ieee80211_hdrlen(fc
));
1941 /* Tell device the write index *just past* this latest filled TFD */
1942 q
->write_ptr
= iwl_queue_inc_wrap(q
->write_ptr
, q
->n_bd
);
1943 rc
= iwl_txq_update_write_ptr(priv
, txq
);
1944 spin_unlock_irqrestore(&priv
->lock
, flags
);
1949 if ((iwl_queue_space(q
) < q
->high_mark
)
1950 && priv
->mac80211_registered
) {
1951 if (wait_write_ptr
) {
1952 spin_lock_irqsave(&priv
->lock
, flags
);
1953 txq
->need_update
= 1;
1954 iwl_txq_update_write_ptr(priv
, txq
);
1955 spin_unlock_irqrestore(&priv
->lock
, flags
);
1958 ieee80211_stop_queue(priv
->hw
, skb_get_queue_mapping(skb
));
1964 spin_unlock_irqrestore(&priv
->lock
, flags
);
1969 static void iwl3945_set_rate(struct iwl_priv
*priv
)
1971 const struct ieee80211_supported_band
*sband
= NULL
;
1972 struct ieee80211_rate
*rate
;
1975 sband
= iwl_get_hw_mode(priv
, priv
->band
);
1977 IWL_ERR(priv
, "Failed to set rate: unable to get hw mode\n");
1981 priv
->active_rate
= 0;
1982 priv
->active_rate_basic
= 0;
1984 IWL_DEBUG_RATE("Setting rates for %s GHz\n",
1985 sband
->band
== IEEE80211_BAND_2GHZ
? "2.4" : "5");
1987 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
1988 rate
= &sband
->bitrates
[i
];
1989 if ((rate
->hw_value
< IWL_RATE_COUNT
) &&
1990 !(rate
->flags
& IEEE80211_CHAN_DISABLED
)) {
1991 IWL_DEBUG_RATE("Adding rate index %d (plcp %d)\n",
1992 rate
->hw_value
, iwl3945_rates
[rate
->hw_value
].plcp
);
1993 priv
->active_rate
|= (1 << rate
->hw_value
);
1997 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
1998 priv
->active_rate
, priv
->active_rate_basic
);
2001 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
2002 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
2005 if (priv
->active_rate_basic
& IWL_CCK_BASIC_RATES_MASK
)
2006 priv
->staging39_rxon
.cck_basic_rates
=
2007 ((priv
->active_rate_basic
&
2008 IWL_CCK_RATES_MASK
) >> IWL_FIRST_CCK_RATE
) & 0xF;
2010 priv
->staging39_rxon
.cck_basic_rates
=
2011 (IWL_CCK_BASIC_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
2013 if (priv
->active_rate_basic
& IWL_OFDM_BASIC_RATES_MASK
)
2014 priv
->staging39_rxon
.ofdm_basic_rates
=
2015 ((priv
->active_rate_basic
&
2016 (IWL_OFDM_BASIC_RATES_MASK
| IWL_RATE_6M_MASK
)) >>
2017 IWL_FIRST_OFDM_RATE
) & 0xFF;
2019 priv
->staging39_rxon
.ofdm_basic_rates
=
2020 (IWL_OFDM_BASIC_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
2023 static void iwl3945_radio_kill_sw(struct iwl_priv
*priv
, int disable_radio
)
2025 unsigned long flags
;
2027 if (!!disable_radio
== test_bit(STATUS_RF_KILL_SW
, &priv
->status
))
2030 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
2031 disable_radio
? "OFF" : "ON");
2033 if (disable_radio
) {
2034 iwl_scan_cancel(priv
);
2035 /* FIXME: This is a workaround for AP */
2036 if (priv
->iw_mode
!= NL80211_IFTYPE_AP
) {
2037 spin_lock_irqsave(&priv
->lock
, flags
);
2038 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
2039 CSR_UCODE_SW_BIT_RFKILL
);
2040 spin_unlock_irqrestore(&priv
->lock
, flags
);
2041 iwl_send_card_state(priv
, CARD_STATE_CMD_DISABLE
, 0);
2042 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2047 spin_lock_irqsave(&priv
->lock
, flags
);
2048 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2050 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2051 spin_unlock_irqrestore(&priv
->lock
, flags
);
2056 spin_lock_irqsave(&priv
->lock
, flags
);
2057 iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
2058 if (!iwl_grab_nic_access(priv
))
2059 iwl_release_nic_access(priv
);
2060 spin_unlock_irqrestore(&priv
->lock
, flags
);
2062 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) {
2063 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2064 "disabled by HW switch\n");
2069 queue_work(priv
->workqueue
, &priv
->restart
);
2073 void iwl3945_set_decrypted_flag(struct iwl_priv
*priv
, struct sk_buff
*skb
,
2074 u32 decrypt_res
, struct ieee80211_rx_status
*stats
)
2077 le16_to_cpu(((struct ieee80211_hdr
*)skb
->data
)->frame_control
);
2079 if (priv
->active39_rxon
.filter_flags
& RXON_FILTER_DIS_DECRYPT_MSK
)
2082 if (!(fc
& IEEE80211_FCTL_PROTECTED
))
2085 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res
);
2086 switch (decrypt_res
& RX_RES_STATUS_SEC_TYPE_MSK
) {
2087 case RX_RES_STATUS_SEC_TYPE_TKIP
:
2088 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2089 RX_RES_STATUS_BAD_ICV_MIC
)
2090 stats
->flag
|= RX_FLAG_MMIC_ERROR
;
2091 case RX_RES_STATUS_SEC_TYPE_WEP
:
2092 case RX_RES_STATUS_SEC_TYPE_CCMP
:
2093 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2094 RX_RES_STATUS_DECRYPT_OK
) {
2095 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
2096 stats
->flag
|= RX_FLAG_DECRYPTED
;
2105 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
2107 #include "iwl-spectrum.h"
2109 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
2110 #define BEACON_TIME_MASK_HIGH 0xFF000000
2111 #define TIME_UNIT 1024
2114 * extended beacon time format
2115 * time in usec will be changed into a 32-bit value in 8:24 format
2116 * the high 1 byte is the beacon counts
2117 * the lower 3 bytes is the time in usec within one beacon interval
2120 static u32
iwl3945_usecs_to_beacons(u32 usec
, u32 beacon_interval
)
2124 u32 interval
= beacon_interval
* 1024;
2126 if (!interval
|| !usec
)
2129 quot
= (usec
/ interval
) & (BEACON_TIME_MASK_HIGH
>> 24);
2130 rem
= (usec
% interval
) & BEACON_TIME_MASK_LOW
;
2132 return (quot
<< 24) + rem
;
2135 /* base is usually what we get from ucode with each received frame,
2136 * the same as HW timer counter counting down
2139 static __le32
iwl3945_add_beacon_time(u32 base
, u32 addon
, u32 beacon_interval
)
2141 u32 base_low
= base
& BEACON_TIME_MASK_LOW
;
2142 u32 addon_low
= addon
& BEACON_TIME_MASK_LOW
;
2143 u32 interval
= beacon_interval
* TIME_UNIT
;
2144 u32 res
= (base
& BEACON_TIME_MASK_HIGH
) +
2145 (addon
& BEACON_TIME_MASK_HIGH
);
2147 if (base_low
> addon_low
)
2148 res
+= base_low
- addon_low
;
2149 else if (base_low
< addon_low
) {
2150 res
+= interval
+ base_low
- addon_low
;
2155 return cpu_to_le32(res
);
2158 static int iwl3945_get_measurement(struct iwl_priv
*priv
,
2159 struct ieee80211_measurement_params
*params
,
2162 struct iwl_spectrum_cmd spectrum
;
2163 struct iwl_rx_packet
*res
;
2164 struct iwl_host_cmd cmd
= {
2165 .id
= REPLY_SPECTRUM_MEASUREMENT_CMD
,
2166 .data
= (void *)&spectrum
,
2167 .meta
.flags
= CMD_WANT_SKB
,
2169 u32 add_time
= le64_to_cpu(params
->start_time
);
2171 int spectrum_resp_status
;
2172 int duration
= le16_to_cpu(params
->duration
);
2174 if (iwl3945_is_associated(priv
))
2176 iwl3945_usecs_to_beacons(
2177 le64_to_cpu(params
->start_time
) - priv
->last_tsf
,
2178 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2180 memset(&spectrum
, 0, sizeof(spectrum
));
2182 spectrum
.channel_count
= cpu_to_le16(1);
2184 RXON_FLG_TSF2HOST_MSK
| RXON_FLG_ANT_A_MSK
| RXON_FLG_DIS_DIV_MSK
;
2185 spectrum
.filter_flags
= MEASUREMENT_FILTER_FLAG
;
2186 cmd
.len
= sizeof(spectrum
);
2187 spectrum
.len
= cpu_to_le16(cmd
.len
- sizeof(spectrum
.len
));
2189 if (iwl3945_is_associated(priv
))
2190 spectrum
.start_time
=
2191 iwl3945_add_beacon_time(priv
->last_beacon_time
,
2193 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2195 spectrum
.start_time
= 0;
2197 spectrum
.channels
[0].duration
= cpu_to_le32(duration
* TIME_UNIT
);
2198 spectrum
.channels
[0].channel
= params
->channel
;
2199 spectrum
.channels
[0].type
= type
;
2200 if (priv
->active39_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
2201 spectrum
.flags
|= RXON_FLG_BAND_24G_MSK
|
2202 RXON_FLG_AUTO_DETECT_MSK
| RXON_FLG_TGG_PROTECT_MSK
;
2204 rc
= iwl_send_cmd_sync(priv
, &cmd
);
2208 res
= (struct iwl_rx_packet
*)cmd
.meta
.u
.skb
->data
;
2209 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
2210 IWL_ERR(priv
, "Bad return from REPLY_RX_ON_ASSOC command\n");
2214 spectrum_resp_status
= le16_to_cpu(res
->u
.spectrum
.status
);
2215 switch (spectrum_resp_status
) {
2216 case 0: /* Command will be handled */
2217 if (res
->u
.spectrum
.id
!= 0xff) {
2218 IWL_DEBUG_INFO("Replaced existing measurement: %d\n",
2219 res
->u
.spectrum
.id
);
2220 priv
->measurement_status
&= ~MEASUREMENT_READY
;
2222 priv
->measurement_status
|= MEASUREMENT_ACTIVE
;
2226 case 1: /* Command will not be handled */
2231 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
2237 static void iwl3945_rx_reply_alive(struct iwl_priv
*priv
,
2238 struct iwl_rx_mem_buffer
*rxb
)
2240 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2241 struct iwl_alive_resp
*palive
;
2242 struct delayed_work
*pwork
;
2244 palive
= &pkt
->u
.alive_frame
;
2246 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
2248 palive
->is_valid
, palive
->ver_type
,
2249 palive
->ver_subtype
);
2251 if (palive
->ver_subtype
== INITIALIZE_SUBTYPE
) {
2252 IWL_DEBUG_INFO("Initialization Alive received.\n");
2253 memcpy(&priv
->card_alive_init
, &pkt
->u
.alive_frame
,
2254 sizeof(struct iwl_alive_resp
));
2255 pwork
= &priv
->init_alive_start
;
2257 IWL_DEBUG_INFO("Runtime Alive received.\n");
2258 memcpy(&priv
->card_alive
, &pkt
->u
.alive_frame
,
2259 sizeof(struct iwl_alive_resp
));
2260 pwork
= &priv
->alive_start
;
2261 iwl3945_disable_events(priv
);
2264 /* We delay the ALIVE response by 5ms to
2265 * give the HW RF Kill time to activate... */
2266 if (palive
->is_valid
== UCODE_VALID_OK
)
2267 queue_delayed_work(priv
->workqueue
, pwork
,
2268 msecs_to_jiffies(5));
2270 IWL_WARN(priv
, "uCode did not respond OK.\n");
2273 static void iwl3945_rx_reply_add_sta(struct iwl_priv
*priv
,
2274 struct iwl_rx_mem_buffer
*rxb
)
2276 #ifdef CONFIG_IWLWIFI_DEBUG
2277 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2280 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt
->u
.status
);
2284 static void iwl3945_rx_reply_error(struct iwl_priv
*priv
,
2285 struct iwl_rx_mem_buffer
*rxb
)
2287 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2289 IWL_ERR(priv
, "Error Reply type 0x%08X cmd %s (0x%02X) "
2290 "seq 0x%04X ser 0x%08X\n",
2291 le32_to_cpu(pkt
->u
.err_resp
.error_type
),
2292 get_cmd_string(pkt
->u
.err_resp
.cmd_id
),
2293 pkt
->u
.err_resp
.cmd_id
,
2294 le16_to_cpu(pkt
->u
.err_resp
.bad_cmd_seq_num
),
2295 le32_to_cpu(pkt
->u
.err_resp
.error_info
));
2298 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
2300 static void iwl3945_rx_csa(struct iwl_priv
*priv
, struct iwl_rx_mem_buffer
*rxb
)
2302 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2303 struct iwl3945_rxon_cmd
*rxon
= (void *)&priv
->active39_rxon
;
2304 struct iwl_csa_notification
*csa
= &(pkt
->u
.csa_notif
);
2305 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
2306 le16_to_cpu(csa
->channel
), le32_to_cpu(csa
->status
));
2307 rxon
->channel
= csa
->channel
;
2308 priv
->staging39_rxon
.channel
= csa
->channel
;
2311 static void iwl3945_rx_spectrum_measure_notif(struct iwl_priv
*priv
,
2312 struct iwl_rx_mem_buffer
*rxb
)
2314 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
2315 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2316 struct iwl_spectrum_notification
*report
= &(pkt
->u
.spectrum_notif
);
2318 if (!report
->state
) {
2319 IWL_DEBUG(IWL_DL_11H
| IWL_DL_INFO
,
2320 "Spectrum Measure Notification: Start\n");
2324 memcpy(&priv
->measure_report
, report
, sizeof(*report
));
2325 priv
->measurement_status
|= MEASUREMENT_READY
;
2329 static void iwl3945_rx_pm_sleep_notif(struct iwl_priv
*priv
,
2330 struct iwl_rx_mem_buffer
*rxb
)
2332 #ifdef CONFIG_IWL3945_DEBUG
2333 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2334 struct iwl_sleep_notification
*sleep
= &(pkt
->u
.sleep_notif
);
2335 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
2336 sleep
->pm_sleep_mode
, sleep
->pm_wakeup_src
);
2340 static void iwl3945_rx_pm_debug_statistics_notif(struct iwl_priv
*priv
,
2341 struct iwl_rx_mem_buffer
*rxb
)
2343 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2344 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
2345 "notification for %s:\n",
2346 le32_to_cpu(pkt
->len
), get_cmd_string(pkt
->hdr
.cmd
));
2347 iwl_print_hex_dump(priv
, IWL_DL_RADIO
, pkt
->u
.raw
,
2348 le32_to_cpu(pkt
->len
));
2351 static void iwl3945_bg_beacon_update(struct work_struct
*work
)
2353 struct iwl_priv
*priv
=
2354 container_of(work
, struct iwl_priv
, beacon_update
);
2355 struct sk_buff
*beacon
;
2357 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
2358 beacon
= ieee80211_beacon_get(priv
->hw
, priv
->vif
);
2361 IWL_ERR(priv
, "update beacon failed\n");
2365 mutex_lock(&priv
->mutex
);
2366 /* new beacon skb is allocated every time; dispose previous.*/
2367 if (priv
->ibss_beacon
)
2368 dev_kfree_skb(priv
->ibss_beacon
);
2370 priv
->ibss_beacon
= beacon
;
2371 mutex_unlock(&priv
->mutex
);
2373 iwl3945_send_beacon_cmd(priv
);
2376 static void iwl3945_rx_beacon_notif(struct iwl_priv
*priv
,
2377 struct iwl_rx_mem_buffer
*rxb
)
2379 #ifdef CONFIG_IWL3945_DEBUG
2380 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2381 struct iwl3945_beacon_notif
*beacon
= &(pkt
->u
.beacon_status
);
2382 u8 rate
= beacon
->beacon_notify_hdr
.rate
;
2384 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
2385 "tsf %d %d rate %d\n",
2386 le32_to_cpu(beacon
->beacon_notify_hdr
.status
) & TX_STATUS_MSK
,
2387 beacon
->beacon_notify_hdr
.failure_frame
,
2388 le32_to_cpu(beacon
->ibss_mgr_status
),
2389 le32_to_cpu(beacon
->high_tsf
),
2390 le32_to_cpu(beacon
->low_tsf
), rate
);
2393 if ((priv
->iw_mode
== NL80211_IFTYPE_AP
) &&
2394 (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)))
2395 queue_work(priv
->workqueue
, &priv
->beacon_update
);
2398 /* Service response to REPLY_SCAN_CMD (0x80) */
2399 static void iwl3945_rx_reply_scan(struct iwl_priv
*priv
,
2400 struct iwl_rx_mem_buffer
*rxb
)
2402 #ifdef CONFIG_IWL3945_DEBUG
2403 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2404 struct iwl_scanreq_notification
*notif
=
2405 (struct iwl_scanreq_notification
*)pkt
->u
.raw
;
2407 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif
->status
);
2411 /* Service SCAN_START_NOTIFICATION (0x82) */
2412 static void iwl3945_rx_scan_start_notif(struct iwl_priv
*priv
,
2413 struct iwl_rx_mem_buffer
*rxb
)
2415 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2416 struct iwl_scanstart_notification
*notif
=
2417 (struct iwl_scanstart_notification
*)pkt
->u
.raw
;
2418 priv
->scan_start_tsf
= le32_to_cpu(notif
->tsf_low
);
2419 IWL_DEBUG_SCAN("Scan start: "
2421 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
2423 notif
->band
? "bg" : "a",
2425 notif
->tsf_low
, notif
->status
, notif
->beacon_timer
);
2428 /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
2429 static void iwl3945_rx_scan_results_notif(struct iwl_priv
*priv
,
2430 struct iwl_rx_mem_buffer
*rxb
)
2432 #ifdef CONFIG_IWLWIFI_DEBUG
2433 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2434 struct iwl_scanresults_notification
*notif
=
2435 (struct iwl_scanresults_notification
*)pkt
->u
.raw
;
2438 IWL_DEBUG_SCAN("Scan ch.res: "
2440 "(TSF: 0x%08X:%08X) - %d "
2441 "elapsed=%lu usec (%dms since last)\n",
2443 notif
->band
? "bg" : "a",
2444 le32_to_cpu(notif
->tsf_high
),
2445 le32_to_cpu(notif
->tsf_low
),
2446 le32_to_cpu(notif
->statistics
[0]),
2447 le32_to_cpu(notif
->tsf_low
) - priv
->scan_start_tsf
,
2448 jiffies_to_msecs(elapsed_jiffies
2449 (priv
->last_scan_jiffies
, jiffies
)));
2451 priv
->last_scan_jiffies
= jiffies
;
2452 priv
->next_scan_jiffies
= 0;
2455 /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
2456 static void iwl3945_rx_scan_complete_notif(struct iwl_priv
*priv
,
2457 struct iwl_rx_mem_buffer
*rxb
)
2459 #ifdef CONFIG_IWLWIFI_DEBUG
2460 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2461 struct iwl_scancomplete_notification
*scan_notif
= (void *)pkt
->u
.raw
;
2464 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
2465 scan_notif
->scanned_channels
,
2466 scan_notif
->tsf_low
,
2467 scan_notif
->tsf_high
, scan_notif
->status
);
2469 /* The HW is no longer scanning */
2470 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
2472 /* The scan completion notification came in, so kill that timer... */
2473 cancel_delayed_work(&priv
->scan_check
);
2475 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
2476 (priv
->scan_bands
& BIT(IEEE80211_BAND_2GHZ
)) ?
2478 jiffies_to_msecs(elapsed_jiffies
2479 (priv
->scan_pass_start
, jiffies
)));
2481 /* Remove this scanned band from the list of pending
2482 * bands to scan, band G precedes A in order of scanning
2483 * as seen in iwl3945_bg_request_scan */
2484 if (priv
->scan_bands
& BIT(IEEE80211_BAND_2GHZ
))
2485 priv
->scan_bands
&= ~BIT(IEEE80211_BAND_2GHZ
);
2486 else if (priv
->scan_bands
& BIT(IEEE80211_BAND_5GHZ
))
2487 priv
->scan_bands
&= ~BIT(IEEE80211_BAND_5GHZ
);
2489 /* If a request to abort was given, or the scan did not succeed
2490 * then we reset the scan state machine and terminate,
2491 * re-queuing another scan if one has been requested */
2492 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
2493 IWL_DEBUG_INFO("Aborted scan completed.\n");
2494 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
2496 /* If there are more bands on this scan pass reschedule */
2497 if (priv
->scan_bands
> 0)
2501 priv
->last_scan_jiffies
= jiffies
;
2502 priv
->next_scan_jiffies
= 0;
2503 IWL_DEBUG_INFO("Setting scan to off\n");
2505 clear_bit(STATUS_SCANNING
, &priv
->status
);
2507 IWL_DEBUG_INFO("Scan took %dms\n",
2508 jiffies_to_msecs(elapsed_jiffies(priv
->scan_start
, jiffies
)));
2510 queue_work(priv
->workqueue
, &priv
->scan_completed
);
2515 priv
->scan_pass_start
= jiffies
;
2516 queue_work(priv
->workqueue
, &priv
->request_scan
);
2519 /* Handle notification from uCode that card's power state is changing
2520 * due to software, hardware, or critical temperature RFKILL */
2521 static void iwl3945_rx_card_state_notif(struct iwl_priv
*priv
,
2522 struct iwl_rx_mem_buffer
*rxb
)
2524 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2525 u32 flags
= le32_to_cpu(pkt
->u
.card_state_notif
.flags
);
2526 unsigned long status
= priv
->status
;
2528 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
2529 (flags
& HW_CARD_DISABLED
) ? "Kill" : "On",
2530 (flags
& SW_CARD_DISABLED
) ? "Kill" : "On");
2532 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
2533 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
2535 if (flags
& HW_CARD_DISABLED
)
2536 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2538 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2541 if (flags
& SW_CARD_DISABLED
)
2542 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2544 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2546 iwl_scan_cancel(priv
);
2548 if ((test_bit(STATUS_RF_KILL_HW
, &status
) !=
2549 test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) ||
2550 (test_bit(STATUS_RF_KILL_SW
, &status
) !=
2551 test_bit(STATUS_RF_KILL_SW
, &priv
->status
)))
2552 queue_work(priv
->workqueue
, &priv
->rf_kill
);
2554 wake_up_interruptible(&priv
->wait_command_queue
);
2558 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
2560 * Setup the RX handlers for each of the reply types sent from the uCode
2563 * This function chains into the hardware specific files for them to setup
2564 * any hardware specific handlers as well.
2566 static void iwl3945_setup_rx_handlers(struct iwl_priv
*priv
)
2568 priv
->rx_handlers
[REPLY_ALIVE
] = iwl3945_rx_reply_alive
;
2569 priv
->rx_handlers
[REPLY_ADD_STA
] = iwl3945_rx_reply_add_sta
;
2570 priv
->rx_handlers
[REPLY_ERROR
] = iwl3945_rx_reply_error
;
2571 priv
->rx_handlers
[CHANNEL_SWITCH_NOTIFICATION
] = iwl3945_rx_csa
;
2572 priv
->rx_handlers
[SPECTRUM_MEASURE_NOTIFICATION
] =
2573 iwl3945_rx_spectrum_measure_notif
;
2574 priv
->rx_handlers
[PM_SLEEP_NOTIFICATION
] = iwl3945_rx_pm_sleep_notif
;
2575 priv
->rx_handlers
[PM_DEBUG_STATISTIC_NOTIFIC
] =
2576 iwl3945_rx_pm_debug_statistics_notif
;
2577 priv
->rx_handlers
[BEACON_NOTIFICATION
] = iwl3945_rx_beacon_notif
;
2580 * The same handler is used for both the REPLY to a discrete
2581 * statistics request from the host as well as for the periodic
2582 * statistics notifications (after received beacons) from the uCode.
2584 priv
->rx_handlers
[REPLY_STATISTICS_CMD
] = iwl3945_hw_rx_statistics
;
2585 priv
->rx_handlers
[STATISTICS_NOTIFICATION
] = iwl3945_hw_rx_statistics
;
2587 priv
->rx_handlers
[REPLY_SCAN_CMD
] = iwl3945_rx_reply_scan
;
2588 priv
->rx_handlers
[SCAN_START_NOTIFICATION
] = iwl3945_rx_scan_start_notif
;
2589 priv
->rx_handlers
[SCAN_RESULTS_NOTIFICATION
] =
2590 iwl3945_rx_scan_results_notif
;
2591 priv
->rx_handlers
[SCAN_COMPLETE_NOTIFICATION
] =
2592 iwl3945_rx_scan_complete_notif
;
2593 priv
->rx_handlers
[CARD_STATE_NOTIFICATION
] = iwl3945_rx_card_state_notif
;
2595 /* Set up hardware specific Rx handlers */
2596 iwl3945_hw_rx_handler_setup(priv
);
2600 * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries
2601 * When FW advances 'R' index, all entries between old and new 'R' index
2602 * need to be reclaimed.
2604 static void iwl3945_cmd_queue_reclaim(struct iwl_priv
*priv
,
2605 int txq_id
, int index
)
2607 struct iwl_tx_queue
*txq
= &priv
->txq
[txq_id
];
2608 struct iwl_queue
*q
= &txq
->q
;
2611 if ((index
>= q
->n_bd
) || (iwl_queue_used(q
, index
) == 0)) {
2612 IWL_ERR(priv
, "Read index for DMA queue txq id (%d), index %d, "
2613 "is out of range [0-%d] %d %d.\n", txq_id
,
2614 index
, q
->n_bd
, q
->write_ptr
, q
->read_ptr
);
2618 for (index
= iwl_queue_inc_wrap(index
, q
->n_bd
); q
->read_ptr
!= index
;
2619 q
->read_ptr
= iwl_queue_inc_wrap(q
->read_ptr
, q
->n_bd
)) {
2621 IWL_ERR(priv
, "HCMD skipped: index (%d) %d %d\n", index
,
2622 q
->write_ptr
, q
->read_ptr
);
2623 queue_work(priv
->workqueue
, &priv
->restart
);
2632 * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
2633 * @rxb: Rx buffer to reclaim
2635 * If an Rx buffer has an async callback associated with it the callback
2636 * will be executed. The attached skb (if present) will only be freed
2637 * if the callback returns 1
2639 static void iwl3945_tx_cmd_complete(struct iwl_priv
*priv
,
2640 struct iwl_rx_mem_buffer
*rxb
)
2642 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
2643 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
2644 int txq_id
= SEQ_TO_QUEUE(sequence
);
2645 int index
= SEQ_TO_INDEX(sequence
);
2646 int huge
= !!(pkt
->hdr
.sequence
& SEQ_HUGE_FRAME
);
2648 struct iwl_cmd
*cmd
;
2650 if (WARN(txq_id
!= IWL_CMD_QUEUE_NUM
,
2651 "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n",
2653 priv
->txq
[IWL_CMD_QUEUE_NUM
].q
.read_ptr
,
2654 priv
->txq
[IWL_CMD_QUEUE_NUM
].q
.write_ptr
)) {
2655 iwl_print_hex_dump(priv
, IWL_DL_INFO
, rxb
, 32);
2659 cmd_index
= get_cmd_index(&priv
->txq
[IWL_CMD_QUEUE_NUM
].q
, index
, huge
);
2660 cmd
= priv
->txq
[IWL_CMD_QUEUE_NUM
].cmd
[cmd_index
];
2662 /* Input error checking is done when commands are added to queue. */
2663 if (cmd
->meta
.flags
& CMD_WANT_SKB
) {
2664 cmd
->meta
.source
->u
.skb
= rxb
->skb
;
2666 } else if (cmd
->meta
.u
.callback
&&
2667 !cmd
->meta
.u
.callback(priv
, cmd
, rxb
->skb
))
2670 iwl3945_cmd_queue_reclaim(priv
, txq_id
, index
);
2672 if (!(cmd
->meta
.flags
& CMD_ASYNC
)) {
2673 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
2674 wake_up_interruptible(&priv
->wait_command_queue
);
2678 /************************** RX-FUNCTIONS ****************************/
2680 * Rx theory of operation
2682 * The host allocates 32 DMA target addresses and passes the host address
2683 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
2687 * The host/firmware share two index registers for managing the Rx buffers.
2689 * The READ index maps to the first position that the firmware may be writing
2690 * to -- the driver can read up to (but not including) this position and get
2692 * The READ index is managed by the firmware once the card is enabled.
2694 * The WRITE index maps to the last position the driver has read from -- the
2695 * position preceding WRITE is the last slot the firmware can place a packet.
2697 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
2700 * During initialization, the host sets up the READ queue position to the first
2701 * INDEX position, and WRITE to the last (READ - 1 wrapped)
2703 * When the firmware places a packet in a buffer, it will advance the READ index
2704 * and fire the RX interrupt. The driver can then query the READ index and
2705 * process as many packets as possible, moving the WRITE index forward as it
2706 * resets the Rx queue buffers with new memory.
2708 * The management in the driver is as follows:
2709 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
2710 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
2711 * to replenish the iwl->rxq->rx_free.
2712 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
2713 * iwl->rxq is replenished and the READ INDEX is updated (updating the
2714 * 'processed' and 'read' driver indexes as well)
2715 * + A received packet is processed and handed to the kernel network stack,
2716 * detached from the iwl->rxq. The driver 'processed' index is updated.
2717 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
2718 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
2719 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
2720 * were enough free buffers and RX_STALLED is set it is cleared.
2725 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
2726 * iwl3945_rx_queue_restock
2727 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
2728 * queue, updates firmware pointers, and updates
2729 * the WRITE index. If insufficient rx_free buffers
2730 * are available, schedules iwl3945_rx_replenish
2732 * -- enable interrupts --
2733 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
2734 * READ INDEX, detaching the SKB from the pool.
2735 * Moves the packet buffer from queue to rx_used.
2736 * Calls iwl3945_rx_queue_restock to refill any empty
2743 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
2745 static inline __le32
iwl3945_dma_addr2rbd_ptr(struct iwl_priv
*priv
,
2746 dma_addr_t dma_addr
)
2748 return cpu_to_le32((u32
)dma_addr
);
2752 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
2754 * If there are slots in the RX queue that need to be restocked,
2755 * and we have free pre-allocated buffers, fill the ranks as much
2756 * as we can, pulling from rx_free.
2758 * This moves the 'write' index forward to catch up with 'processed', and
2759 * also updates the memory address in the firmware to reference the new
2762 static int iwl3945_rx_queue_restock(struct iwl_priv
*priv
)
2764 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
2765 struct list_head
*element
;
2766 struct iwl_rx_mem_buffer
*rxb
;
2767 unsigned long flags
;
2770 spin_lock_irqsave(&rxq
->lock
, flags
);
2771 write
= rxq
->write
& ~0x7;
2772 while ((iwl_rx_queue_space(rxq
) > 0) && (rxq
->free_count
)) {
2773 /* Get next free Rx buffer, remove from free list */
2774 element
= rxq
->rx_free
.next
;
2775 rxb
= list_entry(element
, struct iwl_rx_mem_buffer
, list
);
2778 /* Point to Rx buffer via next RBD in circular buffer */
2779 rxq
->bd
[rxq
->write
] = iwl3945_dma_addr2rbd_ptr(priv
, rxb
->real_dma_addr
);
2780 rxq
->queue
[rxq
->write
] = rxb
;
2781 rxq
->write
= (rxq
->write
+ 1) & RX_QUEUE_MASK
;
2784 spin_unlock_irqrestore(&rxq
->lock
, flags
);
2785 /* If the pre-allocated buffer pool is dropping low, schedule to
2787 if (rxq
->free_count
<= RX_LOW_WATERMARK
)
2788 queue_work(priv
->workqueue
, &priv
->rx_replenish
);
2791 /* If we've added more space for the firmware to place data, tell it.
2792 * Increment device's write pointer in multiples of 8. */
2793 if ((write
!= (rxq
->write
& ~0x7))
2794 || (abs(rxq
->write
- rxq
->read
) > 7)) {
2795 spin_lock_irqsave(&rxq
->lock
, flags
);
2796 rxq
->need_update
= 1;
2797 spin_unlock_irqrestore(&rxq
->lock
, flags
);
2798 rc
= iwl_rx_queue_update_write_ptr(priv
, rxq
);
2807 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
2809 * When moving to rx_free an SKB is allocated for the slot.
2811 * Also restock the Rx queue via iwl3945_rx_queue_restock.
2812 * This is called as a scheduled work item (except for during initialization)
2814 static void iwl3945_rx_allocate(struct iwl_priv
*priv
)
2816 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
2817 struct list_head
*element
;
2818 struct iwl_rx_mem_buffer
*rxb
;
2819 unsigned long flags
;
2820 spin_lock_irqsave(&rxq
->lock
, flags
);
2821 while (!list_empty(&rxq
->rx_used
)) {
2822 element
= rxq
->rx_used
.next
;
2823 rxb
= list_entry(element
, struct iwl_rx_mem_buffer
, list
);
2825 /* Alloc a new receive buffer */
2827 alloc_skb(priv
->hw_params
.rx_buf_size
,
2828 __GFP_NOWARN
| GFP_ATOMIC
);
2830 if (net_ratelimit())
2831 IWL_CRIT(priv
, ": Can not allocate SKB buffers\n");
2832 /* We don't reschedule replenish work here -- we will
2833 * call the restock method and if it still needs
2834 * more buffers it will schedule replenish */
2838 /* If radiotap head is required, reserve some headroom here.
2839 * The physical head count is a variable rx_stats->phy_count.
2840 * We reserve 4 bytes here. Plus these extra bytes, the
2841 * headroom of the physical head should be enough for the
2842 * radiotap head that iwl3945 supported. See iwl3945_rt.
2844 skb_reserve(rxb
->skb
, 4);
2846 priv
->alloc_rxb_skb
++;
2849 /* Get physical address of RB/SKB */
2850 rxb
->real_dma_addr
= pci_map_single(priv
->pci_dev
,
2852 priv
->hw_params
.rx_buf_size
,
2853 PCI_DMA_FROMDEVICE
);
2854 list_add_tail(&rxb
->list
, &rxq
->rx_free
);
2857 spin_unlock_irqrestore(&rxq
->lock
, flags
);
2861 * this should be called while priv->lock is locked
2863 static void __iwl3945_rx_replenish(void *data
)
2865 struct iwl_priv
*priv
= data
;
2867 iwl3945_rx_allocate(priv
);
2868 iwl3945_rx_queue_restock(priv
);
2872 void iwl3945_rx_replenish(void *data
)
2874 struct iwl_priv
*priv
= data
;
2875 unsigned long flags
;
2877 iwl3945_rx_allocate(priv
);
2879 spin_lock_irqsave(&priv
->lock
, flags
);
2880 iwl3945_rx_queue_restock(priv
);
2881 spin_unlock_irqrestore(&priv
->lock
, flags
);
2884 /* Convert linear signal-to-noise ratio into dB */
2885 static u8 ratio2dB
[100] = {
2886 /* 0 1 2 3 4 5 6 7 8 9 */
2887 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
2888 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
2889 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
2890 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
2891 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
2892 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
2893 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
2894 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
2895 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
2896 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
2899 /* Calculates a relative dB value from a ratio of linear
2900 * (i.e. not dB) signal levels.
2901 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
2902 int iwl3945_calc_db_from_ratio(int sig_ratio
)
2904 /* 1000:1 or higher just report as 60 dB */
2905 if (sig_ratio
>= 1000)
2908 /* 100:1 or higher, divide by 10 and use table,
2909 * add 20 dB to make up for divide by 10 */
2910 if (sig_ratio
>= 100)
2911 return 20 + (int)ratio2dB
[sig_ratio
/10];
2913 /* We shouldn't see this */
2917 /* Use table for ratios 1:1 - 99:1 */
2918 return (int)ratio2dB
[sig_ratio
];
2921 #define PERFECT_RSSI (-20) /* dBm */
2922 #define WORST_RSSI (-95) /* dBm */
2923 #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
2925 /* Calculate an indication of rx signal quality (a percentage, not dBm!).
2926 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
2927 * about formulas used below. */
2928 int iwl3945_calc_sig_qual(int rssi_dbm
, int noise_dbm
)
2931 int degradation
= PERFECT_RSSI
- rssi_dbm
;
2933 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
2934 * as indicator; formula is (signal dbm - noise dbm).
2935 * SNR at or above 40 is a great signal (100%).
2936 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
2937 * Weakest usable signal is usually 10 - 15 dB SNR. */
2939 if (rssi_dbm
- noise_dbm
>= 40)
2941 else if (rssi_dbm
< noise_dbm
)
2943 sig_qual
= ((rssi_dbm
- noise_dbm
) * 5) / 2;
2945 /* Else use just the signal level.
2946 * This formula is a least squares fit of data points collected and
2947 * compared with a reference system that had a percentage (%) display
2948 * for signal quality. */
2950 sig_qual
= (100 * (RSSI_RANGE
* RSSI_RANGE
) - degradation
*
2951 (15 * RSSI_RANGE
+ 62 * degradation
)) /
2952 (RSSI_RANGE
* RSSI_RANGE
);
2956 else if (sig_qual
< 1)
2963 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
2965 * Uses the priv->rx_handlers callback function array to invoke
2966 * the appropriate handlers, including command responses,
2967 * frame-received notifications, and other notifications.
2969 static void iwl3945_rx_handle(struct iwl_priv
*priv
)
2971 struct iwl_rx_mem_buffer
*rxb
;
2972 struct iwl_rx_packet
*pkt
;
2973 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
2976 unsigned long flags
;
2980 /* uCode's read index (stored in shared DRAM) indicates the last Rx
2981 * buffer that the driver may process (last buffer filled by ucode). */
2982 r
= le16_to_cpu(rxq
->rb_stts
->closed_rb_num
) & 0x0FFF;
2985 if (iwl_rx_queue_space(rxq
) > (RX_QUEUE_SIZE
/ 2))
2987 /* Rx interrupt, but nothing sent from uCode */
2989 IWL_DEBUG(IWL_DL_RX
| IWL_DL_ISR
, "r = %d, i = %d\n", r
, i
);
2992 rxb
= rxq
->queue
[i
];
2994 /* If an RXB doesn't have a Rx queue slot associated with it,
2995 * then a bug has been introduced in the queue refilling
2996 * routines -- catch it here */
2997 BUG_ON(rxb
== NULL
);
2999 rxq
->queue
[i
] = NULL
;
3001 pci_dma_sync_single_for_cpu(priv
->pci_dev
, rxb
->real_dma_addr
,
3002 priv
->hw_params
.rx_buf_size
,
3003 PCI_DMA_FROMDEVICE
);
3004 pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
3006 /* Reclaim a command buffer only if this packet is a response
3007 * to a (driver-originated) command.
3008 * If the packet (e.g. Rx frame) originated from uCode,
3009 * there is no command buffer to reclaim.
3010 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
3011 * but apparently a few don't get set; catch them here. */
3012 reclaim
= !(pkt
->hdr
.sequence
& SEQ_RX_FRAME
) &&
3013 (pkt
->hdr
.cmd
!= STATISTICS_NOTIFICATION
) &&
3014 (pkt
->hdr
.cmd
!= REPLY_TX
);
3016 /* Based on type of command response or notification,
3017 * handle those that need handling via function in
3018 * rx_handlers table. See iwl3945_setup_rx_handlers() */
3019 if (priv
->rx_handlers
[pkt
->hdr
.cmd
]) {
3020 IWL_DEBUG(IWL_DL_HCMD
| IWL_DL_RX
| IWL_DL_ISR
,
3021 "r = %d, i = %d, %s, 0x%02x\n", r
, i
,
3022 get_cmd_string(pkt
->hdr
.cmd
), pkt
->hdr
.cmd
);
3023 priv
->rx_handlers
[pkt
->hdr
.cmd
] (priv
, rxb
);
3025 /* No handling needed */
3026 IWL_DEBUG(IWL_DL_HCMD
| IWL_DL_RX
| IWL_DL_ISR
,
3027 "r %d i %d No handler needed for %s, 0x%02x\n",
3028 r
, i
, get_cmd_string(pkt
->hdr
.cmd
),
3033 /* Invoke any callbacks, transfer the skb to caller, and
3034 * fire off the (possibly) blocking iwl_send_cmd()
3035 * as we reclaim the driver command queue */
3036 if (rxb
&& rxb
->skb
)
3037 iwl3945_tx_cmd_complete(priv
, rxb
);
3039 IWL_WARN(priv
, "Claim null rxb?\n");
3042 /* For now we just don't re-use anything. We can tweak this
3043 * later to try and re-use notification packets and SKBs that
3044 * fail to Rx correctly */
3045 if (rxb
->skb
!= NULL
) {
3046 priv
->alloc_rxb_skb
--;
3047 dev_kfree_skb_any(rxb
->skb
);
3051 pci_unmap_single(priv
->pci_dev
, rxb
->real_dma_addr
,
3052 priv
->hw_params
.rx_buf_size
,
3053 PCI_DMA_FROMDEVICE
);
3054 spin_lock_irqsave(&rxq
->lock
, flags
);
3055 list_add_tail(&rxb
->list
, &priv
->rxq
.rx_used
);
3056 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3057 i
= (i
+ 1) & RX_QUEUE_MASK
;
3058 /* If there are a lot of unused frames,
3059 * restock the Rx queue so ucode won't assert. */
3064 __iwl3945_rx_replenish(priv
);
3070 /* Backtrack one entry */
3072 iwl3945_rx_queue_restock(priv
);
3075 #ifdef CONFIG_IWL3945_DEBUG
3076 static void iwl3945_print_rx_config_cmd(struct iwl_priv
*priv
,
3077 struct iwl3945_rxon_cmd
*rxon
)
3079 IWL_DEBUG_RADIO("RX CONFIG:\n");
3080 iwl_print_hex_dump(priv
, IWL_DL_RADIO
, (u8
*) rxon
, sizeof(*rxon
));
3081 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon
->channel
));
3082 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon
->flags
));
3083 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
3084 le32_to_cpu(rxon
->filter_flags
));
3085 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon
->dev_type
);
3086 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
3087 rxon
->ofdm_basic_rates
);
3088 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon
->cck_basic_rates
);
3089 IWL_DEBUG_RADIO("u8[6] node_addr: %pM\n", rxon
->node_addr
);
3090 IWL_DEBUG_RADIO("u8[6] bssid_addr: %pM\n", rxon
->bssid_addr
);
3091 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon
->assoc_id
));
3095 static void iwl3945_enable_interrupts(struct iwl_priv
*priv
)
3097 IWL_DEBUG_ISR("Enabling interrupts\n");
3098 set_bit(STATUS_INT_ENABLED
, &priv
->status
);
3099 iwl_write32(priv
, CSR_INT_MASK
, CSR_INI_SET_MASK
);
3103 /* call this function to flush any scheduled tasklet */
3104 static inline void iwl_synchronize_irq(struct iwl_priv
*priv
)
3106 /* wait to make sure we flush pending tasklet*/
3107 synchronize_irq(priv
->pci_dev
->irq
);
3108 tasklet_kill(&priv
->irq_tasklet
);
3112 static inline void iwl3945_disable_interrupts(struct iwl_priv
*priv
)
3114 clear_bit(STATUS_INT_ENABLED
, &priv
->status
);
3116 /* disable interrupts from uCode/NIC to host */
3117 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
3119 /* acknowledge/clear/reset any interrupts still pending
3120 * from uCode or flow handler (Rx/Tx DMA) */
3121 iwl_write32(priv
, CSR_INT
, 0xffffffff);
3122 iwl_write32(priv
, CSR_FH_INT_STATUS
, 0xffffffff);
3123 IWL_DEBUG_ISR("Disabled interrupts\n");
3126 static const char *desc_lookup(int i
)
3134 return "BAD_CHECKSUM";
3136 return "NMI_INTERRUPT";
3140 return "FATAL_ERROR";
3146 #define ERROR_START_OFFSET (1 * sizeof(u32))
3147 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
3149 static void iwl3945_dump_nic_error_log(struct iwl_priv
*priv
)
3152 u32 desc
, time
, count
, base
, data1
;
3153 u32 blink1
, blink2
, ilink1
, ilink2
;
3156 base
= le32_to_cpu(priv
->card_alive
.error_event_table_ptr
);
3158 if (!iwl3945_hw_valid_rtc_data_addr(base
)) {
3159 IWL_ERR(priv
, "Not valid error log pointer 0x%08X\n", base
);
3163 rc
= iwl_grab_nic_access(priv
);
3165 IWL_WARN(priv
, "Can not read from adapter at this time.\n");
3169 count
= iwl_read_targ_mem(priv
, base
);
3171 if (ERROR_START_OFFSET
<= count
* ERROR_ELEM_SIZE
) {
3172 IWL_ERR(priv
, "Start IWL Error Log Dump:\n");
3173 IWL_ERR(priv
, "Status: 0x%08lX, count: %d\n",
3174 priv
->status
, count
);
3177 IWL_ERR(priv
, "Desc Time asrtPC blink2 "
3178 "ilink1 nmiPC Line\n");
3179 for (i
= ERROR_START_OFFSET
;
3180 i
< (count
* ERROR_ELEM_SIZE
) + ERROR_START_OFFSET
;
3181 i
+= ERROR_ELEM_SIZE
) {
3182 desc
= iwl_read_targ_mem(priv
, base
+ i
);
3184 iwl_read_targ_mem(priv
, base
+ i
+ 1 * sizeof(u32
));
3186 iwl_read_targ_mem(priv
, base
+ i
+ 2 * sizeof(u32
));
3188 iwl_read_targ_mem(priv
, base
+ i
+ 3 * sizeof(u32
));
3190 iwl_read_targ_mem(priv
, base
+ i
+ 4 * sizeof(u32
));
3192 iwl_read_targ_mem(priv
, base
+ i
+ 5 * sizeof(u32
));
3194 iwl_read_targ_mem(priv
, base
+ i
+ 6 * sizeof(u32
));
3197 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
3198 desc_lookup(desc
), desc
, time
, blink1
, blink2
,
3199 ilink1
, ilink2
, data1
);
3202 iwl_release_nic_access(priv
);
3206 #define EVENT_START_OFFSET (6 * sizeof(u32))
3209 * iwl3945_print_event_log - Dump error event log to syslog
3211 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
3213 static void iwl3945_print_event_log(struct iwl_priv
*priv
, u32 start_idx
,
3214 u32 num_events
, u32 mode
)
3217 u32 base
; /* SRAM byte address of event log header */
3218 u32 event_size
; /* 2 u32s, or 3 u32s if timestamp recorded */
3219 u32 ptr
; /* SRAM byte address of log data */
3220 u32 ev
, time
, data
; /* event log data */
3222 if (num_events
== 0)
3225 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
3228 event_size
= 2 * sizeof(u32
);
3230 event_size
= 3 * sizeof(u32
);
3232 ptr
= base
+ EVENT_START_OFFSET
+ (start_idx
* event_size
);
3234 /* "time" is actually "data" for mode 0 (no timestamp).
3235 * place event id # at far right for easier visual parsing. */
3236 for (i
= 0; i
< num_events
; i
++) {
3237 ev
= iwl_read_targ_mem(priv
, ptr
);
3239 time
= iwl_read_targ_mem(priv
, ptr
);
3243 IWL_ERR(priv
, "0x%08x\t%04u\n", time
, ev
);
3245 data
= iwl_read_targ_mem(priv
, ptr
);
3247 IWL_ERR(priv
, "%010u\t0x%08x\t%04u\n", time
, data
, ev
);
3252 static void iwl3945_dump_nic_event_log(struct iwl_priv
*priv
)
3255 u32 base
; /* SRAM byte address of event log header */
3256 u32 capacity
; /* event log capacity in # entries */
3257 u32 mode
; /* 0 - no timestamp, 1 - timestamp recorded */
3258 u32 num_wraps
; /* # times uCode wrapped to top of log */
3259 u32 next_entry
; /* index of next entry to be written by uCode */
3260 u32 size
; /* # entries that we'll print */
3262 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
3263 if (!iwl3945_hw_valid_rtc_data_addr(base
)) {
3264 IWL_ERR(priv
, "Invalid event log pointer 0x%08X\n", base
);
3268 rc
= iwl_grab_nic_access(priv
);
3270 IWL_WARN(priv
, "Can not read from adapter at this time.\n");
3274 /* event log header */
3275 capacity
= iwl_read_targ_mem(priv
, base
);
3276 mode
= iwl_read_targ_mem(priv
, base
+ (1 * sizeof(u32
)));
3277 num_wraps
= iwl_read_targ_mem(priv
, base
+ (2 * sizeof(u32
)));
3278 next_entry
= iwl_read_targ_mem(priv
, base
+ (3 * sizeof(u32
)));
3280 size
= num_wraps
? capacity
: next_entry
;
3282 /* bail out if nothing in log */
3284 IWL_ERR(priv
, "Start IWL Event Log Dump: nothing in log\n");
3285 iwl_release_nic_access(priv
);
3289 IWL_ERR(priv
, "Start IWL Event Log Dump: display count %d, wraps %d\n",
3292 /* if uCode has wrapped back to top of log, start at the oldest entry,
3293 * i.e the next one that uCode would fill. */
3295 iwl3945_print_event_log(priv
, next_entry
,
3296 capacity
- next_entry
, mode
);
3298 /* (then/else) start at top of log */
3299 iwl3945_print_event_log(priv
, 0, next_entry
, mode
);
3301 iwl_release_nic_access(priv
);
3305 * iwl3945_irq_handle_error - called for HW or SW error interrupt from card
3307 static void iwl3945_irq_handle_error(struct iwl_priv
*priv
)
3309 /* Set the FW error flag -- cleared on iwl3945_down */
3310 set_bit(STATUS_FW_ERROR
, &priv
->status
);
3312 /* Cancel currently queued command. */
3313 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
3315 #ifdef CONFIG_IWL3945_DEBUG
3316 if (priv
->debug_level
& IWL_DL_FW_ERRORS
) {
3317 iwl3945_dump_nic_error_log(priv
);
3318 iwl3945_dump_nic_event_log(priv
);
3319 iwl3945_print_rx_config_cmd(priv
, &priv
->staging39_rxon
);
3323 wake_up_interruptible(&priv
->wait_command_queue
);
3325 /* Keep the restart process from trying to send host
3326 * commands by clearing the INIT status bit */
3327 clear_bit(STATUS_READY
, &priv
->status
);
3329 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
3330 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_FW_ERRORS
,
3331 "Restarting adapter due to uCode error.\n");
3333 if (iwl3945_is_associated(priv
)) {
3334 memcpy(&priv
->recovery39_rxon
, &priv
->active39_rxon
,
3335 sizeof(priv
->recovery39_rxon
));
3336 priv
->error_recovering
= 1;
3338 queue_work(priv
->workqueue
, &priv
->restart
);
3342 static void iwl3945_error_recovery(struct iwl_priv
*priv
)
3344 unsigned long flags
;
3346 memcpy(&priv
->staging39_rxon
, &priv
->recovery39_rxon
,
3347 sizeof(priv
->staging39_rxon
));
3348 priv
->staging39_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
3349 iwl3945_commit_rxon(priv
);
3351 iwl3945_add_station(priv
, priv
->bssid
, 1, 0);
3353 spin_lock_irqsave(&priv
->lock
, flags
);
3354 priv
->assoc_id
= le16_to_cpu(priv
->staging39_rxon
.assoc_id
);
3355 priv
->error_recovering
= 0;
3356 spin_unlock_irqrestore(&priv
->lock
, flags
);
3359 static void iwl3945_irq_tasklet(struct iwl_priv
*priv
)
3361 u32 inta
, handled
= 0;
3363 unsigned long flags
;
3364 #ifdef CONFIG_IWL3945_DEBUG
3368 spin_lock_irqsave(&priv
->lock
, flags
);
3370 /* Ack/clear/reset pending uCode interrupts.
3371 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
3372 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
3373 inta
= iwl_read32(priv
, CSR_INT
);
3374 iwl_write32(priv
, CSR_INT
, inta
);
3376 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
3377 * Any new interrupts that happen after this, either while we're
3378 * in this tasklet, or later, will show up in next ISR/tasklet. */
3379 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
3380 iwl_write32(priv
, CSR_FH_INT_STATUS
, inta_fh
);
3382 #ifdef CONFIG_IWL3945_DEBUG
3383 if (priv
->debug_level
& IWL_DL_ISR
) {
3384 /* just for debug */
3385 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
3386 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
3387 inta
, inta_mask
, inta_fh
);
3391 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
3392 * atomic, make sure that inta covers all the interrupts that
3393 * we've discovered, even if FH interrupt came in just after
3394 * reading CSR_INT. */
3395 if (inta_fh
& CSR39_FH_INT_RX_MASK
)
3396 inta
|= CSR_INT_BIT_FH_RX
;
3397 if (inta_fh
& CSR39_FH_INT_TX_MASK
)
3398 inta
|= CSR_INT_BIT_FH_TX
;
3400 /* Now service all interrupt bits discovered above. */
3401 if (inta
& CSR_INT_BIT_HW_ERR
) {
3402 IWL_ERR(priv
, "Microcode HW error detected. Restarting.\n");
3404 /* Tell the device to stop sending interrupts */
3405 iwl3945_disable_interrupts(priv
);
3407 iwl3945_irq_handle_error(priv
);
3409 handled
|= CSR_INT_BIT_HW_ERR
;
3411 spin_unlock_irqrestore(&priv
->lock
, flags
);
3416 #ifdef CONFIG_IWL3945_DEBUG
3417 if (priv
->debug_level
& (IWL_DL_ISR
)) {
3418 /* NIC fires this, but we don't use it, redundant with WAKEUP */
3419 if (inta
& CSR_INT_BIT_SCD
)
3420 IWL_DEBUG_ISR("Scheduler finished to transmit "
3421 "the frame/frames.\n");
3423 /* Alive notification via Rx interrupt will do the real work */
3424 if (inta
& CSR_INT_BIT_ALIVE
)
3425 IWL_DEBUG_ISR("Alive interrupt\n");
3428 /* Safely ignore these bits for debug checks below */
3429 inta
&= ~(CSR_INT_BIT_SCD
| CSR_INT_BIT_ALIVE
);
3431 /* Error detected by uCode */
3432 if (inta
& CSR_INT_BIT_SW_ERR
) {
3433 IWL_ERR(priv
, "Microcode SW error detected. "
3434 "Restarting 0x%X.\n", inta
);
3435 iwl3945_irq_handle_error(priv
);
3436 handled
|= CSR_INT_BIT_SW_ERR
;
3439 /* uCode wakes up after power-down sleep */
3440 if (inta
& CSR_INT_BIT_WAKEUP
) {
3441 IWL_DEBUG_ISR("Wakeup interrupt\n");
3442 iwl_rx_queue_update_write_ptr(priv
, &priv
->rxq
);
3443 iwl_txq_update_write_ptr(priv
, &priv
->txq
[0]);
3444 iwl_txq_update_write_ptr(priv
, &priv
->txq
[1]);
3445 iwl_txq_update_write_ptr(priv
, &priv
->txq
[2]);
3446 iwl_txq_update_write_ptr(priv
, &priv
->txq
[3]);
3447 iwl_txq_update_write_ptr(priv
, &priv
->txq
[4]);
3448 iwl_txq_update_write_ptr(priv
, &priv
->txq
[5]);
3450 handled
|= CSR_INT_BIT_WAKEUP
;
3453 /* All uCode command responses, including Tx command responses,
3454 * Rx "responses" (frame-received notification), and other
3455 * notifications from uCode come through here*/
3456 if (inta
& (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
)) {
3457 iwl3945_rx_handle(priv
);
3458 handled
|= (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
);
3461 if (inta
& CSR_INT_BIT_FH_TX
) {
3462 IWL_DEBUG_ISR("Tx interrupt\n");
3464 iwl_write32(priv
, CSR_FH_INT_STATUS
, (1 << 6));
3465 if (!iwl_grab_nic_access(priv
)) {
3466 iwl_write_direct32(priv
, FH39_TCSR_CREDIT
3467 (FH39_SRVC_CHNL
), 0x0);
3468 iwl_release_nic_access(priv
);
3470 handled
|= CSR_INT_BIT_FH_TX
;
3473 if (inta
& ~handled
)
3474 IWL_ERR(priv
, "Unhandled INTA bits 0x%08x\n", inta
& ~handled
);
3476 if (inta
& ~CSR_INI_SET_MASK
) {
3477 IWL_WARN(priv
, "Disabled INTA bits 0x%08x were pending\n",
3478 inta
& ~CSR_INI_SET_MASK
);
3479 IWL_WARN(priv
, " with FH_INT = 0x%08x\n", inta_fh
);
3482 /* Re-enable all interrupts */
3483 /* only Re-enable if disabled by irq */
3484 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
3485 iwl3945_enable_interrupts(priv
);
3487 #ifdef CONFIG_IWL3945_DEBUG
3488 if (priv
->debug_level
& (IWL_DL_ISR
)) {
3489 inta
= iwl_read32(priv
, CSR_INT
);
3490 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
3491 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
3492 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
3493 "flags 0x%08lx\n", inta
, inta_mask
, inta_fh
, flags
);
3496 spin_unlock_irqrestore(&priv
->lock
, flags
);
3499 static irqreturn_t
iwl3945_isr(int irq
, void *data
)
3501 struct iwl_priv
*priv
= data
;
3502 u32 inta
, inta_mask
;
3507 spin_lock(&priv
->lock
);
3509 /* Disable (but don't clear!) interrupts here to avoid
3510 * back-to-back ISRs and sporadic interrupts from our NIC.
3511 * If we have something to service, the tasklet will re-enable ints.
3512 * If we *don't* have something, we'll re-enable before leaving here. */
3513 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
); /* just for debug */
3514 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
3516 /* Discover which interrupts are active/pending */
3517 inta
= iwl_read32(priv
, CSR_INT
);
3518 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
3520 /* Ignore interrupt if there's nothing in NIC to service.
3521 * This may be due to IRQ shared with another device,
3522 * or due to sporadic interrupts thrown from our NIC. */
3523 if (!inta
&& !inta_fh
) {
3524 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
3528 if ((inta
== 0xFFFFFFFF) || ((inta
& 0xFFFFFFF0) == 0xa5a5a5a0)) {
3529 /* Hardware disappeared */
3530 IWL_WARN(priv
, "HARDWARE GONE?? INTA == 0x%08x\n", inta
);
3534 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
3535 inta
, inta_mask
, inta_fh
);
3537 inta
&= ~CSR_INT_BIT_SCD
;
3539 /* iwl3945_irq_tasklet() will service interrupts and re-enable them */
3540 if (likely(inta
|| inta_fh
))
3541 tasklet_schedule(&priv
->irq_tasklet
);
3543 spin_unlock(&priv
->lock
);
3548 /* re-enable interrupts here since we don't have anything to service. */
3549 /* only Re-enable if disabled by irq */
3550 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
3551 iwl3945_enable_interrupts(priv
);
3552 spin_unlock(&priv
->lock
);
3556 /************************** EEPROM BANDS ****************************
3558 * The iwl3945_eeprom_band definitions below provide the mapping from the
3559 * EEPROM contents to the specific channel number supported for each
3562 * For example, iwl3945_priv->eeprom39.band_3_channels[4] from the band_3
3563 * definition below maps to physical channel 42 in the 5.2GHz spectrum.
3564 * The specific geography and calibration information for that channel
3565 * is contained in the eeprom map itself.
3567 * During init, we copy the eeprom information and channel map
3568 * information into priv->channel_info_24/52 and priv->channel_map_24/52
3570 * channel_map_24/52 provides the index in the channel_info array for a
3571 * given channel. We have to have two separate maps as there is channel
3572 * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
3575 * A value of 0xff stored in the channel_map indicates that the channel
3576 * is not supported by the hardware at all.
3578 * A value of 0xfe in the channel_map indicates that the channel is not
3579 * valid for Tx with the current hardware. This means that
3580 * while the system can tune and receive on a given channel, it may not
3581 * be able to associate or transmit any frames on that
3582 * channel. There is no corresponding channel information for that
3585 *********************************************************************/
3588 static const u8 iwl3945_eeprom_band_1
[14] = {
3589 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
3593 static const u8 iwl3945_eeprom_band_2
[] = { /* 4915-5080MHz */
3594 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
3597 static const u8 iwl3945_eeprom_band_3
[] = { /* 5170-5320MHz */
3598 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
3601 static const u8 iwl3945_eeprom_band_4
[] = { /* 5500-5700MHz */
3602 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
3605 static const u8 iwl3945_eeprom_band_5
[] = { /* 5725-5825MHz */
3606 145, 149, 153, 157, 161, 165
3609 static void iwl3945_init_band_reference(const struct iwl_priv
*priv
, int band
,
3610 int *eeprom_ch_count
,
3611 const struct iwl_eeprom_channel
3613 const u8
**eeprom_ch_index
)
3616 case 1: /* 2.4GHz band */
3617 *eeprom_ch_count
= ARRAY_SIZE(iwl3945_eeprom_band_1
);
3618 *eeprom_ch_info
= priv
->eeprom39
.band_1_channels
;
3619 *eeprom_ch_index
= iwl3945_eeprom_band_1
;
3621 case 2: /* 4.9GHz band */
3622 *eeprom_ch_count
= ARRAY_SIZE(iwl3945_eeprom_band_2
);
3623 *eeprom_ch_info
= priv
->eeprom39
.band_2_channels
;
3624 *eeprom_ch_index
= iwl3945_eeprom_band_2
;
3626 case 3: /* 5.2GHz band */
3627 *eeprom_ch_count
= ARRAY_SIZE(iwl3945_eeprom_band_3
);
3628 *eeprom_ch_info
= priv
->eeprom39
.band_3_channels
;
3629 *eeprom_ch_index
= iwl3945_eeprom_band_3
;
3631 case 4: /* 5.5GHz band */
3632 *eeprom_ch_count
= ARRAY_SIZE(iwl3945_eeprom_band_4
);
3633 *eeprom_ch_info
= priv
->eeprom39
.band_4_channels
;
3634 *eeprom_ch_index
= iwl3945_eeprom_band_4
;
3636 case 5: /* 5.7GHz band */
3637 *eeprom_ch_count
= ARRAY_SIZE(iwl3945_eeprom_band_5
);
3638 *eeprom_ch_info
= priv
->eeprom39
.band_5_channels
;
3639 *eeprom_ch_index
= iwl3945_eeprom_band_5
;
3648 * iwl3945_get_channel_info - Find driver's private channel info
3650 * Based on band and channel number.
3652 const struct iwl_channel_info
*
3653 iwl3945_get_channel_info(const struct iwl_priv
*priv
,
3654 enum ieee80211_band band
, u16 channel
)
3659 case IEEE80211_BAND_5GHZ
:
3660 for (i
= 14; i
< priv
->channel_count
; i
++) {
3661 if (priv
->channel_info
[i
].channel
== channel
)
3662 return &priv
->channel_info
[i
];
3666 case IEEE80211_BAND_2GHZ
:
3667 if (channel
>= 1 && channel
<= 14)
3668 return &priv
->channel_info
[channel
- 1];
3670 case IEEE80211_NUM_BANDS
:
3677 #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
3681 * iwl3945_init_channel_map - Set up driver's info for all possible channels
3683 static int iwl3945_init_channel_map(struct iwl_priv
*priv
)
3685 int eeprom_ch_count
= 0;
3686 const u8
*eeprom_ch_index
= NULL
;
3687 const struct iwl_eeprom_channel
*eeprom_ch_info
= NULL
;
3689 struct iwl_channel_info
*ch_info
;
3691 if (priv
->channel_count
) {
3692 IWL_DEBUG_INFO("Channel map already initialized.\n");
3696 if (priv
->eeprom39
.version
< 0x2f) {
3697 IWL_WARN(priv
, "Unsupported EEPROM version: 0x%04X\n",
3698 priv
->eeprom39
.version
);
3702 IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n");
3704 priv
->channel_count
=
3705 ARRAY_SIZE(iwl3945_eeprom_band_1
) +
3706 ARRAY_SIZE(iwl3945_eeprom_band_2
) +
3707 ARRAY_SIZE(iwl3945_eeprom_band_3
) +
3708 ARRAY_SIZE(iwl3945_eeprom_band_4
) +
3709 ARRAY_SIZE(iwl3945_eeprom_band_5
);
3711 IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv
->channel_count
);
3713 priv
->channel_info
= kzalloc(sizeof(struct iwl_channel_info
) *
3714 priv
->channel_count
, GFP_KERNEL
);
3715 if (!priv
->channel_info
) {
3716 IWL_ERR(priv
, "Could not allocate channel_info\n");
3717 priv
->channel_count
= 0;
3721 ch_info
= priv
->channel_info
;
3723 /* Loop through the 5 EEPROM bands adding them in order to the
3724 * channel map we maintain (that contains additional information than
3725 * what just in the EEPROM) */
3726 for (band
= 1; band
<= 5; band
++) {
3728 iwl3945_init_band_reference(priv
, band
, &eeprom_ch_count
,
3729 &eeprom_ch_info
, &eeprom_ch_index
);
3731 /* Loop through each band adding each of the channels */
3732 for (ch
= 0; ch
< eeprom_ch_count
; ch
++) {
3733 ch_info
->channel
= eeprom_ch_index
[ch
];
3734 ch_info
->band
= (band
== 1) ? IEEE80211_BAND_2GHZ
:
3735 IEEE80211_BAND_5GHZ
;
3737 /* permanently store EEPROM's channel regulatory flags
3738 * and max power in channel info database. */
3739 ch_info
->eeprom
= eeprom_ch_info
[ch
];
3741 /* Copy the run-time flags so they are there even on
3742 * invalid channels */
3743 ch_info
->flags
= eeprom_ch_info
[ch
].flags
;
3745 if (!(is_channel_valid(ch_info
))) {
3746 IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - "
3750 is_channel_a_band(ch_info
) ?
3756 /* Initialize regulatory-based run-time data */
3757 ch_info
->max_power_avg
= ch_info
->curr_txpow
=
3758 eeprom_ch_info
[ch
].max_power_avg
;
3759 ch_info
->scan_power
= eeprom_ch_info
[ch
].max_power_avg
;
3760 ch_info
->min_power
= 0;
3762 IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x"
3763 " %ddBm): Ad-Hoc %ssupported\n",
3765 is_channel_a_band(ch_info
) ?
3767 CHECK_AND_PRINT(VALID
),
3768 CHECK_AND_PRINT(IBSS
),
3769 CHECK_AND_PRINT(ACTIVE
),
3770 CHECK_AND_PRINT(RADAR
),
3771 CHECK_AND_PRINT(WIDE
),
3772 CHECK_AND_PRINT(DFS
),
3773 eeprom_ch_info
[ch
].flags
,
3774 eeprom_ch_info
[ch
].max_power_avg
,
3775 ((eeprom_ch_info
[ch
].
3776 flags
& EEPROM_CHANNEL_IBSS
)
3777 && !(eeprom_ch_info
[ch
].
3778 flags
& EEPROM_CHANNEL_RADAR
))
3781 /* Set the tx_power_user_lmt to the highest power
3782 * supported by any channel */
3783 if (eeprom_ch_info
[ch
].max_power_avg
>
3784 priv
->tx_power_user_lmt
)
3785 priv
->tx_power_user_lmt
=
3786 eeprom_ch_info
[ch
].max_power_avg
;
3792 /* Set up txpower settings in driver for all channels */
3793 if (iwl3945_txpower_set_from_eeprom(priv
))
3800 * iwl3945_free_channel_map - undo allocations in iwl3945_init_channel_map
3802 static void iwl3945_free_channel_map(struct iwl_priv
*priv
)
3804 kfree(priv
->channel_info
);
3805 priv
->channel_count
= 0;
3808 static int iwl3945_get_channels_for_scan(struct iwl_priv
*priv
,
3809 enum ieee80211_band band
,
3810 u8 is_active
, u8 n_probes
,
3811 struct iwl3945_scan_channel
*scan_ch
)
3813 const struct ieee80211_channel
*channels
= NULL
;
3814 const struct ieee80211_supported_band
*sband
;
3815 const struct iwl_channel_info
*ch_info
;
3816 u16 passive_dwell
= 0;
3817 u16 active_dwell
= 0;
3820 sband
= iwl_get_hw_mode(priv
, band
);
3824 channels
= sband
->channels
;
3826 active_dwell
= iwl_get_active_dwell_time(priv
, band
, n_probes
);
3827 passive_dwell
= iwl_get_passive_dwell_time(priv
, band
);
3829 if (passive_dwell
<= active_dwell
)
3830 passive_dwell
= active_dwell
+ 1;
3832 for (i
= 0, added
= 0; i
< sband
->n_channels
; i
++) {
3833 if (channels
[i
].flags
& IEEE80211_CHAN_DISABLED
)
3836 scan_ch
->channel
= channels
[i
].hw_value
;
3838 ch_info
= iwl3945_get_channel_info(priv
, band
, scan_ch
->channel
);
3839 if (!is_channel_valid(ch_info
)) {
3840 IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n",
3845 scan_ch
->active_dwell
= cpu_to_le16(active_dwell
);
3846 scan_ch
->passive_dwell
= cpu_to_le16(passive_dwell
);
3847 /* If passive , set up for auto-switch
3848 * and use long active_dwell time.
3850 if (!is_active
|| is_channel_passive(ch_info
) ||
3851 (channels
[i
].flags
& IEEE80211_CHAN_PASSIVE_SCAN
)) {
3852 scan_ch
->type
= 0; /* passive */
3853 if (IWL_UCODE_API(priv
->ucode_ver
) == 1)
3854 scan_ch
->active_dwell
= cpu_to_le16(passive_dwell
- 1);
3856 scan_ch
->type
= 1; /* active */
3859 /* Set direct probe bits. These may be used both for active
3860 * scan channels (probes gets sent right away),
3861 * or for passive channels (probes get se sent only after
3862 * hearing clear Rx packet).*/
3863 if (IWL_UCODE_API(priv
->ucode_ver
) >= 2) {
3865 scan_ch
->type
|= IWL_SCAN_PROBE_MASK(n_probes
);
3867 /* uCode v1 does not allow setting direct probe bits on
3868 * passive channel. */
3869 if ((scan_ch
->type
& 1) && n_probes
)
3870 scan_ch
->type
|= IWL_SCAN_PROBE_MASK(n_probes
);
3873 /* Set txpower levels to defaults */
3874 scan_ch
->tpc
.dsp_atten
= 110;
3875 /* scan_pwr_info->tpc.dsp_atten; */
3877 /*scan_pwr_info->tpc.tx_gain; */
3878 if (band
== IEEE80211_BAND_5GHZ
)
3879 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (3 << 3)) | 3;
3881 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (5 << 3));
3882 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
3884 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
3888 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
3890 (scan_ch
->type
& 1) ? "ACTIVE" : "PASSIVE",
3891 (scan_ch
->type
& 1) ?
3892 active_dwell
: passive_dwell
);
3898 IWL_DEBUG_SCAN("total channels to scan %d \n", added
);
3902 static void iwl3945_init_hw_rates(struct iwl_priv
*priv
,
3903 struct ieee80211_rate
*rates
)
3907 for (i
= 0; i
< IWL_RATE_COUNT
; i
++) {
3908 rates
[i
].bitrate
= iwl3945_rates
[i
].ieee
* 5;
3909 rates
[i
].hw_value
= i
; /* Rate scaling will work on indexes */
3910 rates
[i
].hw_value_short
= i
;
3912 if ((i
> IWL39_LAST_OFDM_RATE
) || (i
< IWL_FIRST_OFDM_RATE
)) {
3914 * If CCK != 1M then set short preamble rate flag.
3916 rates
[i
].flags
|= (iwl3945_rates
[i
].plcp
== 10) ?
3917 0 : IEEE80211_RATE_SHORT_PREAMBLE
;
3923 * iwl3945_init_geos - Initialize mac80211's geo/channel info based from eeprom
3925 static int iwl3945_init_geos(struct iwl_priv
*priv
)
3927 struct iwl_channel_info
*ch
;
3928 struct ieee80211_supported_band
*sband
;
3929 struct ieee80211_channel
*channels
;
3930 struct ieee80211_channel
*geo_ch
;
3931 struct ieee80211_rate
*rates
;
3934 if (priv
->bands
[IEEE80211_BAND_2GHZ
].n_bitrates
||
3935 priv
->bands
[IEEE80211_BAND_5GHZ
].n_bitrates
) {
3936 IWL_DEBUG_INFO("Geography modes already initialized.\n");
3937 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
3941 channels
= kzalloc(sizeof(struct ieee80211_channel
) *
3942 priv
->channel_count
, GFP_KERNEL
);
3946 rates
= kzalloc((sizeof(struct ieee80211_rate
) * (IWL_RATE_COUNT
+ 1)),
3953 /* 5.2GHz channels start after the 2.4GHz channels */
3954 sband
= &priv
->bands
[IEEE80211_BAND_5GHZ
];
3955 sband
->channels
= &channels
[ARRAY_SIZE(iwl3945_eeprom_band_1
)];
3957 sband
->bitrates
= &rates
[IWL_FIRST_OFDM_RATE
];
3958 sband
->n_bitrates
= IWL_RATE_COUNT
- IWL_FIRST_OFDM_RATE
;
3960 sband
= &priv
->bands
[IEEE80211_BAND_2GHZ
];
3961 sband
->channels
= channels
;
3963 sband
->bitrates
= rates
;
3964 sband
->n_bitrates
= IWL_RATE_COUNT
;
3966 priv
->ieee_channels
= channels
;
3967 priv
->ieee_rates
= rates
;
3969 iwl3945_init_hw_rates(priv
, rates
);
3971 for (i
= 0; i
< priv
->channel_count
; i
++) {
3972 ch
= &priv
->channel_info
[i
];
3974 /* FIXME: might be removed if scan is OK*/
3975 if (!is_channel_valid(ch
))
3978 if (is_channel_a_band(ch
))
3979 sband
= &priv
->bands
[IEEE80211_BAND_5GHZ
];
3981 sband
= &priv
->bands
[IEEE80211_BAND_2GHZ
];
3983 geo_ch
= &sband
->channels
[sband
->n_channels
++];
3985 geo_ch
->center_freq
= ieee80211_channel_to_frequency(ch
->channel
);
3986 geo_ch
->max_power
= ch
->max_power_avg
;
3987 geo_ch
->max_antenna_gain
= 0xff;
3988 geo_ch
->hw_value
= ch
->channel
;
3990 if (is_channel_valid(ch
)) {
3991 if (!(ch
->flags
& EEPROM_CHANNEL_IBSS
))
3992 geo_ch
->flags
|= IEEE80211_CHAN_NO_IBSS
;
3994 if (!(ch
->flags
& EEPROM_CHANNEL_ACTIVE
))
3995 geo_ch
->flags
|= IEEE80211_CHAN_PASSIVE_SCAN
;
3997 if (ch
->flags
& EEPROM_CHANNEL_RADAR
)
3998 geo_ch
->flags
|= IEEE80211_CHAN_RADAR
;
4000 if (ch
->max_power_avg
> priv
->tx_power_channel_lmt
)
4001 priv
->tx_power_channel_lmt
=
4004 geo_ch
->flags
|= IEEE80211_CHAN_DISABLED
;
4007 /* Save flags for reg domain usage */
4008 geo_ch
->orig_flags
= geo_ch
->flags
;
4010 IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n",
4011 ch
->channel
, geo_ch
->center_freq
,
4012 is_channel_a_band(ch
) ? "5.2" : "2.4",
4013 geo_ch
->flags
& IEEE80211_CHAN_DISABLED
?
4014 "restricted" : "valid",
4018 if ((priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
== 0) &&
4019 priv
->cfg
->sku
& IWL_SKU_A
) {
4020 IWL_INFO(priv
, "Incorrectly detected BG card as ABG. "
4021 "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n",
4022 priv
->pci_dev
->device
, priv
->pci_dev
->subsystem_device
);
4023 priv
->cfg
->sku
&= ~IWL_SKU_A
;
4026 IWL_INFO(priv
, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
4027 priv
->bands
[IEEE80211_BAND_2GHZ
].n_channels
,
4028 priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
);
4030 if (priv
->bands
[IEEE80211_BAND_2GHZ
].n_channels
)
4031 priv
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
4032 &priv
->bands
[IEEE80211_BAND_2GHZ
];
4033 if (priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
)
4034 priv
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
4035 &priv
->bands
[IEEE80211_BAND_5GHZ
];
4037 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
4043 * iwl3945_free_geos - undo allocations in iwl3945_init_geos
4045 static void iwl3945_free_geos(struct iwl_priv
*priv
)
4047 kfree(priv
->ieee_channels
);
4048 kfree(priv
->ieee_rates
);
4049 clear_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
4052 /******************************************************************************
4054 * uCode download functions
4056 ******************************************************************************/
4058 static void iwl3945_dealloc_ucode_pci(struct iwl_priv
*priv
)
4060 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
4061 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
4062 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
4063 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
4064 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
4065 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
4069 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
4070 * looking at all data.
4072 static int iwl3945_verify_inst_full(struct iwl_priv
*priv
, __le32
*image
, u32 len
)
4079 IWL_DEBUG_INFO("ucode inst image size is %u\n", len
);
4081 rc
= iwl_grab_nic_access(priv
);
4085 iwl_write_direct32(priv
, HBUS_TARG_MEM_RADDR
,
4086 IWL39_RTC_INST_LOWER_BOUND
);
4089 for (; len
> 0; len
-= sizeof(u32
), image
++) {
4090 /* read data comes through single port, auto-incr addr */
4091 /* NOTE: Use the debugless read so we don't flood kernel log
4092 * if IWL_DL_IO is set */
4093 val
= _iwl_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
4094 if (val
!= le32_to_cpu(*image
)) {
4095 IWL_ERR(priv
, "uCode INST section is invalid at "
4096 "offset 0x%x, is 0x%x, s/b 0x%x\n",
4097 save_len
- len
, val
, le32_to_cpu(*image
));
4105 iwl_release_nic_access(priv
);
4108 IWL_DEBUG_INFO("ucode image in INSTRUCTION memory is good\n");
4115 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
4116 * using sample data 100 bytes apart. If these sample points are good,
4117 * it's a pretty good bet that everything between them is good, too.
4119 static int iwl3945_verify_inst_sparse(struct iwl_priv
*priv
, __le32
*image
, u32 len
)
4126 IWL_DEBUG_INFO("ucode inst image size is %u\n", len
);
4128 rc
= iwl_grab_nic_access(priv
);
4132 for (i
= 0; i
< len
; i
+= 100, image
+= 100/sizeof(u32
)) {
4133 /* read data comes through single port, auto-incr addr */
4134 /* NOTE: Use the debugless read so we don't flood kernel log
4135 * if IWL_DL_IO is set */
4136 iwl_write_direct32(priv
, HBUS_TARG_MEM_RADDR
,
4137 i
+ IWL39_RTC_INST_LOWER_BOUND
);
4138 val
= _iwl_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
4139 if (val
!= le32_to_cpu(*image
)) {
4140 #if 0 /* Enable this if you want to see details */
4141 IWL_ERR(priv
, "uCode INST section is invalid at "
4142 "offset 0x%x, is 0x%x, s/b 0x%x\n",
4152 iwl_release_nic_access(priv
);
4159 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
4160 * and verify its contents
4162 static int iwl3945_verify_ucode(struct iwl_priv
*priv
)
4169 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
4170 len
= priv
->ucode_boot
.len
;
4171 rc
= iwl3945_verify_inst_sparse(priv
, image
, len
);
4173 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
4177 /* Try initialize */
4178 image
= (__le32
*)priv
->ucode_init
.v_addr
;
4179 len
= priv
->ucode_init
.len
;
4180 rc
= iwl3945_verify_inst_sparse(priv
, image
, len
);
4182 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
4186 /* Try runtime/protocol */
4187 image
= (__le32
*)priv
->ucode_code
.v_addr
;
4188 len
= priv
->ucode_code
.len
;
4189 rc
= iwl3945_verify_inst_sparse(priv
, image
, len
);
4191 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
4195 IWL_ERR(priv
, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
4197 /* Since nothing seems to match, show first several data entries in
4198 * instruction SRAM, so maybe visual inspection will give a clue.
4199 * Selection of bootstrap image (vs. other images) is arbitrary. */
4200 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
4201 len
= priv
->ucode_boot
.len
;
4202 rc
= iwl3945_verify_inst_full(priv
, image
, len
);
4207 static void iwl3945_nic_start(struct iwl_priv
*priv
)
4209 /* Remove all resets to allow NIC to operate */
4210 iwl_write32(priv
, CSR_RESET
, 0);
4214 * iwl3945_read_ucode - Read uCode images from disk file.
4216 * Copy into buffers for card to fetch via bus-mastering
4218 static int iwl3945_read_ucode(struct iwl_priv
*priv
)
4220 struct iwl_ucode
*ucode
;
4221 int ret
= -EINVAL
, index
;
4222 const struct firmware
*ucode_raw
;
4223 /* firmware file name contains uCode/driver compatibility version */
4224 const char *name_pre
= priv
->cfg
->fw_name_pre
;
4225 const unsigned int api_max
= priv
->cfg
->ucode_api_max
;
4226 const unsigned int api_min
= priv
->cfg
->ucode_api_min
;
4230 u32 api_ver
, inst_size
, data_size
, init_size
, init_data_size
, boot_size
;
4232 /* Ask kernel firmware_class module to get the boot firmware off disk.
4233 * request_firmware() is synchronous, file is in memory on return. */
4234 for (index
= api_max
; index
>= api_min
; index
--) {
4235 sprintf(buf
, "%s%u%s", name_pre
, index
, ".ucode");
4236 ret
= request_firmware(&ucode_raw
, buf
, &priv
->pci_dev
->dev
);
4238 IWL_ERR(priv
, "%s firmware file req failed: %d\n",
4245 if (index
< api_max
)
4246 IWL_ERR(priv
, "Loaded firmware %s, "
4247 "which is deprecated. "
4248 " Please use API v%u instead.\n",
4250 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
4251 buf
, ucode_raw
->size
);
4259 /* Make sure that we got at least our header! */
4260 if (ucode_raw
->size
< sizeof(*ucode
)) {
4261 IWL_ERR(priv
, "File size way too small!\n");
4266 /* Data from ucode file: header followed by uCode images */
4267 ucode
= (void *)ucode_raw
->data
;
4269 priv
->ucode_ver
= le32_to_cpu(ucode
->ver
);
4270 api_ver
= IWL_UCODE_API(priv
->ucode_ver
);
4271 inst_size
= le32_to_cpu(ucode
->inst_size
);
4272 data_size
= le32_to_cpu(ucode
->data_size
);
4273 init_size
= le32_to_cpu(ucode
->init_size
);
4274 init_data_size
= le32_to_cpu(ucode
->init_data_size
);
4275 boot_size
= le32_to_cpu(ucode
->boot_size
);
4277 /* api_ver should match the api version forming part of the
4278 * firmware filename ... but we don't check for that and only rely
4279 * on the API version read from firware header from here on forward */
4281 if (api_ver
< api_min
|| api_ver
> api_max
) {
4282 IWL_ERR(priv
, "Driver unable to support your firmware API. "
4283 "Driver supports v%u, firmware is v%u.\n",
4285 priv
->ucode_ver
= 0;
4289 if (api_ver
!= api_max
)
4290 IWL_ERR(priv
, "Firmware has old API version. Expected %u, "
4291 "got %u. New firmware can be obtained "
4292 "from http://www.intellinuxwireless.org.\n",
4295 IWL_INFO(priv
, "loaded firmware version %u.%u.%u.%u\n",
4296 IWL_UCODE_MAJOR(priv
->ucode_ver
),
4297 IWL_UCODE_MINOR(priv
->ucode_ver
),
4298 IWL_UCODE_API(priv
->ucode_ver
),
4299 IWL_UCODE_SERIAL(priv
->ucode_ver
));
4301 IWL_DEBUG_INFO("f/w package hdr ucode version raw = 0x%x\n",
4303 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", inst_size
);
4304 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", data_size
);
4305 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", init_size
);
4306 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", init_data_size
);
4307 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", boot_size
);
4310 /* Verify size of file vs. image size info in file's header */
4311 if (ucode_raw
->size
< sizeof(*ucode
) +
4312 inst_size
+ data_size
+ init_size
+
4313 init_data_size
+ boot_size
) {
4315 IWL_DEBUG_INFO("uCode file size %d too small\n",
4316 (int)ucode_raw
->size
);
4321 /* Verify that uCode images will fit in card's SRAM */
4322 if (inst_size
> IWL39_MAX_INST_SIZE
) {
4323 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
4329 if (data_size
> IWL39_MAX_DATA_SIZE
) {
4330 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
4335 if (init_size
> IWL39_MAX_INST_SIZE
) {
4336 IWL_DEBUG_INFO("uCode init instr len %d too large to fit in\n",
4341 if (init_data_size
> IWL39_MAX_DATA_SIZE
) {
4342 IWL_DEBUG_INFO("uCode init data len %d too large to fit in\n",
4347 if (boot_size
> IWL39_MAX_BSM_SIZE
) {
4348 IWL_DEBUG_INFO("uCode boot instr len %d too large to fit in\n",
4354 /* Allocate ucode buffers for card's bus-master loading ... */
4356 /* Runtime instructions and 2 copies of data:
4357 * 1) unmodified from disk
4358 * 2) backup cache for save/restore during power-downs */
4359 priv
->ucode_code
.len
= inst_size
;
4360 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
4362 priv
->ucode_data
.len
= data_size
;
4363 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
4365 priv
->ucode_data_backup
.len
= data_size
;
4366 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
4368 if (!priv
->ucode_code
.v_addr
|| !priv
->ucode_data
.v_addr
||
4369 !priv
->ucode_data_backup
.v_addr
)
4372 /* Initialization instructions and data */
4373 if (init_size
&& init_data_size
) {
4374 priv
->ucode_init
.len
= init_size
;
4375 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
4377 priv
->ucode_init_data
.len
= init_data_size
;
4378 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
4380 if (!priv
->ucode_init
.v_addr
|| !priv
->ucode_init_data
.v_addr
)
4384 /* Bootstrap (instructions only, no data) */
4386 priv
->ucode_boot
.len
= boot_size
;
4387 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
4389 if (!priv
->ucode_boot
.v_addr
)
4393 /* Copy images into buffers for card's bus-master reads ... */
4395 /* Runtime instructions (first block of data in file) */
4396 src
= &ucode
->data
[0];
4397 len
= priv
->ucode_code
.len
;
4398 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len
);
4399 memcpy(priv
->ucode_code
.v_addr
, src
, len
);
4400 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
4401 priv
->ucode_code
.v_addr
, (u32
)priv
->ucode_code
.p_addr
);
4403 /* Runtime data (2nd block)
4404 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
4405 src
= &ucode
->data
[inst_size
];
4406 len
= priv
->ucode_data
.len
;
4407 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len
);
4408 memcpy(priv
->ucode_data
.v_addr
, src
, len
);
4409 memcpy(priv
->ucode_data_backup
.v_addr
, src
, len
);
4411 /* Initialization instructions (3rd block) */
4413 src
= &ucode
->data
[inst_size
+ data_size
];
4414 len
= priv
->ucode_init
.len
;
4415 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
4417 memcpy(priv
->ucode_init
.v_addr
, src
, len
);
4420 /* Initialization data (4th block) */
4421 if (init_data_size
) {
4422 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
];
4423 len
= priv
->ucode_init_data
.len
;
4424 IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n",
4426 memcpy(priv
->ucode_init_data
.v_addr
, src
, len
);
4429 /* Bootstrap instructions (5th block) */
4430 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
+ init_data_size
];
4431 len
= priv
->ucode_boot
.len
;
4432 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n",
4434 memcpy(priv
->ucode_boot
.v_addr
, src
, len
);
4436 /* We have our copies now, allow OS release its copies */
4437 release_firmware(ucode_raw
);
4441 IWL_ERR(priv
, "failed to allocate pci memory\n");
4443 iwl3945_dealloc_ucode_pci(priv
);
4446 release_firmware(ucode_raw
);
4454 * iwl3945_set_ucode_ptrs - Set uCode address location
4456 * Tell initialization uCode where to find runtime uCode.
4458 * BSM registers initially contain pointers to initialization uCode.
4459 * We need to replace them to load runtime uCode inst and data,
4460 * and to save runtime data when powering down.
4462 static int iwl3945_set_ucode_ptrs(struct iwl_priv
*priv
)
4467 unsigned long flags
;
4469 /* bits 31:0 for 3945 */
4470 pinst
= priv
->ucode_code
.p_addr
;
4471 pdata
= priv
->ucode_data_backup
.p_addr
;
4473 spin_lock_irqsave(&priv
->lock
, flags
);
4474 rc
= iwl_grab_nic_access(priv
);
4476 spin_unlock_irqrestore(&priv
->lock
, flags
);
4480 /* Tell bootstrap uCode where to find image to load */
4481 iwl_write_prph(priv
, BSM_DRAM_INST_PTR_REG
, pinst
);
4482 iwl_write_prph(priv
, BSM_DRAM_DATA_PTR_REG
, pdata
);
4483 iwl_write_prph(priv
, BSM_DRAM_DATA_BYTECOUNT_REG
,
4484 priv
->ucode_data
.len
);
4486 /* Inst byte count must be last to set up, bit 31 signals uCode
4487 * that all new ptr/size info is in place */
4488 iwl_write_prph(priv
, BSM_DRAM_INST_BYTECOUNT_REG
,
4489 priv
->ucode_code
.len
| BSM_DRAM_INST_LOAD
);
4491 iwl_release_nic_access(priv
);
4493 spin_unlock_irqrestore(&priv
->lock
, flags
);
4495 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
4501 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
4503 * Called after REPLY_ALIVE notification received from "initialize" uCode.
4505 * Tell "initialize" uCode to go ahead and load the runtime uCode.
4507 static void iwl3945_init_alive_start(struct iwl_priv
*priv
)
4509 /* Check alive response for "valid" sign from uCode */
4510 if (priv
->card_alive_init
.is_valid
!= UCODE_VALID_OK
) {
4511 /* We had an error bringing up the hardware, so take it
4512 * all the way back down so we can try again */
4513 IWL_DEBUG_INFO("Initialize Alive failed.\n");
4517 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
4518 * This is a paranoid check, because we would not have gotten the
4519 * "initialize" alive if code weren't properly loaded. */
4520 if (iwl3945_verify_ucode(priv
)) {
4521 /* Runtime instruction load was bad;
4522 * take it all the way back down so we can try again */
4523 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
4527 /* Send pointers to protocol/runtime uCode image ... init code will
4528 * load and launch runtime uCode, which will send us another "Alive"
4530 IWL_DEBUG_INFO("Initialization Alive received.\n");
4531 if (iwl3945_set_ucode_ptrs(priv
)) {
4532 /* Runtime instruction load won't happen;
4533 * take it all the way back down so we can try again */
4534 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
4540 queue_work(priv
->workqueue
, &priv
->restart
);
4545 static int iwl3945_mac_beacon_update(struct ieee80211_hw
*hw
,
4546 struct sk_buff
*skb
);
4549 * iwl3945_alive_start - called after REPLY_ALIVE notification received
4550 * from protocol/runtime uCode (initialization uCode's
4551 * Alive gets handled by iwl3945_init_alive_start()).
4553 static void iwl3945_alive_start(struct iwl_priv
*priv
)
4556 int thermal_spin
= 0;
4559 IWL_DEBUG_INFO("Runtime Alive received.\n");
4561 if (priv
->card_alive
.is_valid
!= UCODE_VALID_OK
) {
4562 /* We had an error bringing up the hardware, so take it
4563 * all the way back down so we can try again */
4564 IWL_DEBUG_INFO("Alive failed.\n");
4568 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
4569 * This is a paranoid check, because we would not have gotten the
4570 * "runtime" alive if code weren't properly loaded. */
4571 if (iwl3945_verify_ucode(priv
)) {
4572 /* Runtime instruction load was bad;
4573 * take it all the way back down so we can try again */
4574 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
4578 iwl3945_clear_stations_table(priv
);
4580 rc
= iwl_grab_nic_access(priv
);
4582 IWL_WARN(priv
, "Can not read RFKILL status from adapter\n");
4586 rfkill
= iwl_read_prph(priv
, APMG_RFKILL_REG
);
4587 IWL_DEBUG_INFO("RFKILL status: 0x%x\n", rfkill
);
4588 iwl_release_nic_access(priv
);
4591 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
4592 /* if RFKILL is not on, then wait for thermal
4593 * sensor in adapter to kick in */
4594 while (iwl3945_hw_get_temperature(priv
) == 0) {
4600 IWL_DEBUG_INFO("Thermal calibration took %dus\n",
4603 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
4605 /* After the ALIVE response, we can send commands to 3945 uCode */
4606 set_bit(STATUS_ALIVE
, &priv
->status
);
4608 /* Clear out the uCode error bit if it is set */
4609 clear_bit(STATUS_FW_ERROR
, &priv
->status
);
4611 if (iwl_is_rfkill(priv
))
4614 ieee80211_wake_queues(priv
->hw
);
4616 priv
->active_rate
= priv
->rates_mask
;
4617 priv
->active_rate_basic
= priv
->rates_mask
& IWL_BASIC_RATES_MASK
;
4619 iwl3945_send_power_mode(priv
, IWL_POWER_LEVEL(priv
->power_mode
));
4621 if (iwl3945_is_associated(priv
)) {
4622 struct iwl3945_rxon_cmd
*active_rxon
=
4623 (struct iwl3945_rxon_cmd
*)(&priv
->active39_rxon
);
4625 memcpy(&priv
->staging39_rxon
, &priv
->active39_rxon
,
4626 sizeof(priv
->staging39_rxon
));
4627 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
4629 /* Initialize our rx_config data */
4630 iwl3945_connection_init_rx_config(priv
, priv
->iw_mode
);
4631 memcpy(priv
->staging39_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
4634 /* Configure Bluetooth device coexistence support */
4635 iwl3945_send_bt_config(priv
);
4637 /* Configure the adapter for unassociated operation */
4638 iwl3945_commit_rxon(priv
);
4640 iwl3945_reg_txpower_periodic(priv
);
4642 iwl3945_led_register(priv
);
4644 IWL_DEBUG_INFO("ALIVE processing complete.\n");
4645 set_bit(STATUS_READY
, &priv
->status
);
4646 wake_up_interruptible(&priv
->wait_command_queue
);
4648 if (priv
->error_recovering
)
4649 iwl3945_error_recovery(priv
);
4651 /* reassociate for ADHOC mode */
4652 if (priv
->vif
&& (priv
->iw_mode
== NL80211_IFTYPE_ADHOC
)) {
4653 struct sk_buff
*beacon
= ieee80211_beacon_get(priv
->hw
,
4656 iwl3945_mac_beacon_update(priv
->hw
, beacon
);
4662 queue_work(priv
->workqueue
, &priv
->restart
);
4665 static void iwl3945_cancel_deferred_work(struct iwl_priv
*priv
);
4667 static void __iwl3945_down(struct iwl_priv
*priv
)
4669 unsigned long flags
;
4670 int exit_pending
= test_bit(STATUS_EXIT_PENDING
, &priv
->status
);
4671 struct ieee80211_conf
*conf
= NULL
;
4673 IWL_DEBUG_INFO(DRV_NAME
" is going down\n");
4675 conf
= ieee80211_get_hw_conf(priv
->hw
);
4678 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
4680 iwl3945_led_unregister(priv
);
4681 iwl3945_clear_stations_table(priv
);
4683 /* Unblock any waiting calls */
4684 wake_up_interruptible_all(&priv
->wait_command_queue
);
4686 /* Wipe out the EXIT_PENDING status bit if we are not actually
4687 * exiting the module */
4689 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
4691 /* stop and reset the on-board processor */
4692 iwl_write32(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_NEVO_RESET
);
4694 /* tell the device to stop sending interrupts */
4695 spin_lock_irqsave(&priv
->lock
, flags
);
4696 iwl3945_disable_interrupts(priv
);
4697 spin_unlock_irqrestore(&priv
->lock
, flags
);
4698 iwl_synchronize_irq(priv
);
4700 if (priv
->mac80211_registered
)
4701 ieee80211_stop_queues(priv
->hw
);
4703 /* If we have not previously called iwl3945_init() then
4704 * clear all bits but the RF Kill and SUSPEND bits and return */
4705 if (!iwl_is_init(priv
)) {
4706 priv
->status
= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
4708 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
4710 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
4711 STATUS_GEO_CONFIGURED
|
4712 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
4714 test_bit(STATUS_EXIT_PENDING
, &priv
->status
) <<
4715 STATUS_EXIT_PENDING
;
4719 /* ...otherwise clear out all the status bits but the RF Kill and
4720 * SUSPEND bits and continue taking the NIC down. */
4721 priv
->status
&= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
4723 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
4725 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
4726 STATUS_GEO_CONFIGURED
|
4727 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
4729 test_bit(STATUS_FW_ERROR
, &priv
->status
) <<
4731 test_bit(STATUS_EXIT_PENDING
, &priv
->status
) <<
4732 STATUS_EXIT_PENDING
;
4734 priv
->cfg
->ops
->lib
->apm_ops
.reset(priv
);
4735 spin_lock_irqsave(&priv
->lock
, flags
);
4736 iwl_clear_bit(priv
, CSR_GP_CNTRL
, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
4737 spin_unlock_irqrestore(&priv
->lock
, flags
);
4739 iwl3945_hw_txq_ctx_stop(priv
);
4740 iwl3945_hw_rxq_stop(priv
);
4742 spin_lock_irqsave(&priv
->lock
, flags
);
4743 if (!iwl_grab_nic_access(priv
)) {
4744 iwl_write_prph(priv
, APMG_CLK_DIS_REG
,
4745 APMG_CLK_VAL_DMA_CLK_RQT
);
4746 iwl_release_nic_access(priv
);
4748 spin_unlock_irqrestore(&priv
->lock
, flags
);
4752 if (exit_pending
|| test_bit(STATUS_IN_SUSPEND
, &priv
->status
))
4753 priv
->cfg
->ops
->lib
->apm_ops
.stop(priv
);
4755 priv
->cfg
->ops
->lib
->apm_ops
.reset(priv
);
4758 memset(&priv
->card_alive
, 0, sizeof(struct iwl_alive_resp
));
4760 if (priv
->ibss_beacon
)
4761 dev_kfree_skb(priv
->ibss_beacon
);
4762 priv
->ibss_beacon
= NULL
;
4764 /* clear out any free frames */
4765 iwl3945_clear_free_frames(priv
);
4768 static void iwl3945_down(struct iwl_priv
*priv
)
4770 mutex_lock(&priv
->mutex
);
4771 __iwl3945_down(priv
);
4772 mutex_unlock(&priv
->mutex
);
4774 iwl3945_cancel_deferred_work(priv
);
4777 #define MAX_HW_RESTARTS 5
4779 static int __iwl3945_up(struct iwl_priv
*priv
)
4783 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
4784 IWL_WARN(priv
, "Exit pending; will not bring the NIC up\n");
4788 if (test_bit(STATUS_RF_KILL_SW
, &priv
->status
)) {
4789 IWL_WARN(priv
, "Radio disabled by SW RF kill (module "
4794 if (!priv
->ucode_data_backup
.v_addr
|| !priv
->ucode_data
.v_addr
) {
4795 IWL_ERR(priv
, "ucode not available for device bring up\n");
4799 /* If platform's RF_KILL switch is NOT set to KILL */
4800 if (iwl_read32(priv
, CSR_GP_CNTRL
) &
4801 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
)
4802 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
4804 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
4805 if (!test_bit(STATUS_IN_SUSPEND
, &priv
->status
)) {
4806 IWL_WARN(priv
, "Radio disabled by HW RF Kill switch\n");
4811 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
4813 rc
= iwl3945_hw_nic_init(priv
);
4815 IWL_ERR(priv
, "Unable to int nic\n");
4819 /* make sure rfkill handshake bits are cleared */
4820 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
4821 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
4822 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
4824 /* clear (again), then enable host interrupts */
4825 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
4826 iwl3945_enable_interrupts(priv
);
4828 /* really make sure rfkill handshake bits are cleared */
4829 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
4830 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
4832 /* Copy original ucode data image from disk into backup cache.
4833 * This will be used to initialize the on-board processor's
4834 * data SRAM for a clean start when the runtime program first loads. */
4835 memcpy(priv
->ucode_data_backup
.v_addr
, priv
->ucode_data
.v_addr
,
4836 priv
->ucode_data
.len
);
4838 /* We return success when we resume from suspend and rf_kill is on. */
4839 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
4842 for (i
= 0; i
< MAX_HW_RESTARTS
; i
++) {
4844 iwl3945_clear_stations_table(priv
);
4846 /* load bootstrap state machine,
4847 * load bootstrap program into processor's memory,
4848 * prepare to load the "initialize" uCode */
4849 priv
->cfg
->ops
->lib
->load_ucode(priv
);
4853 "Unable to set up bootstrap uCode: %d\n", rc
);
4857 /* start card; "initialize" will load runtime ucode */
4858 iwl3945_nic_start(priv
);
4860 IWL_DEBUG_INFO(DRV_NAME
" is coming up\n");
4865 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
4866 __iwl3945_down(priv
);
4867 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
4869 /* tried to restart and config the device for as long as our
4870 * patience could withstand */
4871 IWL_ERR(priv
, "Unable to initialize device after %d attempts.\n", i
);
4876 /*****************************************************************************
4878 * Workqueue callbacks
4880 *****************************************************************************/
4882 static void iwl3945_bg_init_alive_start(struct work_struct
*data
)
4884 struct iwl_priv
*priv
=
4885 container_of(data
, struct iwl_priv
, init_alive_start
.work
);
4887 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
4890 mutex_lock(&priv
->mutex
);
4891 iwl3945_init_alive_start(priv
);
4892 mutex_unlock(&priv
->mutex
);
4895 static void iwl3945_bg_alive_start(struct work_struct
*data
)
4897 struct iwl_priv
*priv
=
4898 container_of(data
, struct iwl_priv
, alive_start
.work
);
4900 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
4903 mutex_lock(&priv
->mutex
);
4904 iwl3945_alive_start(priv
);
4905 mutex_unlock(&priv
->mutex
);
4908 static void iwl3945_rfkill_poll(struct work_struct
*data
)
4910 struct iwl_priv
*priv
=
4911 container_of(data
, struct iwl_priv
, rfkill_poll
.work
);
4912 unsigned long status
= priv
->status
;
4914 if (iwl_read32(priv
, CSR_GP_CNTRL
) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
)
4915 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
4917 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
4919 if (test_bit(STATUS_RF_KILL_HW
, &status
) != test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
4920 queue_work(priv
->workqueue
, &priv
->rf_kill
);
4922 queue_delayed_work(priv
->workqueue
, &priv
->rfkill_poll
,
4923 round_jiffies_relative(2 * HZ
));
4927 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
4928 static void iwl3945_bg_request_scan(struct work_struct
*data
)
4930 struct iwl_priv
*priv
=
4931 container_of(data
, struct iwl_priv
, request_scan
);
4932 struct iwl_host_cmd cmd
= {
4933 .id
= REPLY_SCAN_CMD
,
4934 .len
= sizeof(struct iwl3945_scan_cmd
),
4935 .meta
.flags
= CMD_SIZE_HUGE
,
4938 struct iwl3945_scan_cmd
*scan
;
4939 struct ieee80211_conf
*conf
= NULL
;
4941 enum ieee80211_band band
;
4942 DECLARE_SSID_BUF(ssid
);
4944 conf
= ieee80211_get_hw_conf(priv
->hw
);
4946 mutex_lock(&priv
->mutex
);
4948 if (!iwl_is_ready(priv
)) {
4949 IWL_WARN(priv
, "request scan called when driver not ready.\n");
4953 /* Make sure the scan wasn't canceled before this queued work
4954 * was given the chance to run... */
4955 if (!test_bit(STATUS_SCANNING
, &priv
->status
))
4958 /* This should never be called or scheduled if there is currently
4959 * a scan active in the hardware. */
4960 if (test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
4961 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
4962 "Ignoring second request.\n");
4967 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
4968 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
4972 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
4973 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
4977 if (iwl_is_rfkill(priv
)) {
4978 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
4982 if (!test_bit(STATUS_READY
, &priv
->status
)) {
4983 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
4987 if (!priv
->scan_bands
) {
4988 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
4993 priv
->scan
= kmalloc(sizeof(struct iwl3945_scan_cmd
) +
4994 IWL_MAX_SCAN_SIZE
, GFP_KERNEL
);
5001 memset(scan
, 0, sizeof(struct iwl3945_scan_cmd
) + IWL_MAX_SCAN_SIZE
);
5003 scan
->quiet_plcp_th
= IWL_PLCP_QUIET_THRESH
;
5004 scan
->quiet_time
= IWL_ACTIVE_QUIET_TIME
;
5006 if (iwl3945_is_associated(priv
)) {
5009 u32 suspend_time
= 100;
5010 u32 scan_suspend_time
= 100;
5011 unsigned long flags
;
5013 IWL_DEBUG_INFO("Scanning while associated...\n");
5015 spin_lock_irqsave(&priv
->lock
, flags
);
5016 interval
= priv
->beacon_int
;
5017 spin_unlock_irqrestore(&priv
->lock
, flags
);
5019 scan
->suspend_time
= 0;
5020 scan
->max_out_time
= cpu_to_le32(200 * 1024);
5022 interval
= suspend_time
;
5024 * suspend time format:
5025 * 0-19: beacon interval in usec (time before exec.)
5027 * 24-31: number of beacons (suspend between channels)
5030 extra
= (suspend_time
/ interval
) << 24;
5031 scan_suspend_time
= 0xFF0FFFFF &
5032 (extra
| ((suspend_time
% interval
) * 1024));
5034 scan
->suspend_time
= cpu_to_le32(scan_suspend_time
);
5035 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
5036 scan_suspend_time
, interval
);
5039 /* We should add the ability for user to lock to PASSIVE ONLY */
5040 if (priv
->one_direct_scan
) {
5042 ("Kicking off one direct scan for '%s'\n",
5043 print_ssid(ssid
, priv
->direct_ssid
,
5044 priv
->direct_ssid_len
));
5045 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
5046 scan
->direct_scan
[0].len
= priv
->direct_ssid_len
;
5047 memcpy(scan
->direct_scan
[0].ssid
,
5048 priv
->direct_ssid
, priv
->direct_ssid_len
);
5051 IWL_DEBUG_SCAN("Kicking off one indirect scan.\n");
5053 /* We don't build a direct scan probe request; the uCode will do
5054 * that based on the direct_mask added to each channel entry */
5055 scan
->tx_cmd
.tx_flags
= TX_CMD_FLG_SEQ_CTL_MSK
;
5056 scan
->tx_cmd
.sta_id
= priv
->hw_params
.bcast_sta_id
;
5057 scan
->tx_cmd
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
5059 /* flags + rate selection */
5061 if (priv
->scan_bands
& BIT(IEEE80211_BAND_2GHZ
)) {
5062 scan
->flags
= RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
;
5063 scan
->tx_cmd
.rate
= IWL_RATE_1M_PLCP
;
5064 scan
->good_CRC_th
= 0;
5065 band
= IEEE80211_BAND_2GHZ
;
5066 } else if (priv
->scan_bands
& BIT(IEEE80211_BAND_5GHZ
)) {
5067 scan
->tx_cmd
.rate
= IWL_RATE_6M_PLCP
;
5068 scan
->good_CRC_th
= IWL_GOOD_CRC_TH
;
5069 band
= IEEE80211_BAND_5GHZ
;
5071 IWL_WARN(priv
, "Invalid scan band count\n");
5075 scan
->tx_cmd
.len
= cpu_to_le16(
5076 iwl_fill_probe_req(priv
, band
,
5077 (struct ieee80211_mgmt
*)scan
->data
,
5078 IWL_MAX_SCAN_SIZE
- sizeof(*scan
)));
5080 /* select Rx antennas */
5081 scan
->flags
|= iwl3945_get_antenna_flags(priv
);
5083 if (priv
->iw_mode
== NL80211_IFTYPE_MONITOR
)
5084 scan
->filter_flags
= RXON_FILTER_PROMISC_MSK
;
5086 scan
->channel_count
=
5087 iwl3945_get_channels_for_scan(priv
, band
, 1, /* active */
5089 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
5091 if (scan
->channel_count
== 0) {
5092 IWL_DEBUG_SCAN("channel count %d\n", scan
->channel_count
);
5096 cmd
.len
+= le16_to_cpu(scan
->tx_cmd
.len
) +
5097 scan
->channel_count
* sizeof(struct iwl3945_scan_channel
);
5099 scan
->len
= cpu_to_le16(cmd
.len
);
5101 set_bit(STATUS_SCAN_HW
, &priv
->status
);
5102 rc
= iwl_send_cmd_sync(priv
, &cmd
);
5106 queue_delayed_work(priv
->workqueue
, &priv
->scan_check
,
5107 IWL_SCAN_CHECK_WATCHDOG
);
5109 mutex_unlock(&priv
->mutex
);
5113 /* can not perform scan make sure we clear scanning
5114 * bits from status so next scan request can be performed.
5115 * if we dont clear scanning status bit here all next scan
5118 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
5119 clear_bit(STATUS_SCANNING
, &priv
->status
);
5121 /* inform mac80211 scan aborted */
5122 queue_work(priv
->workqueue
, &priv
->scan_completed
);
5123 mutex_unlock(&priv
->mutex
);
5126 static void iwl3945_bg_up(struct work_struct
*data
)
5128 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, up
);
5130 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5133 mutex_lock(&priv
->mutex
);
5135 mutex_unlock(&priv
->mutex
);
5136 iwl_rfkill_set_hw_state(priv
);
5139 static void iwl3945_bg_restart(struct work_struct
*data
)
5141 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, restart
);
5143 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5147 queue_work(priv
->workqueue
, &priv
->up
);
5150 static void iwl3945_bg_rx_replenish(struct work_struct
*data
)
5152 struct iwl_priv
*priv
=
5153 container_of(data
, struct iwl_priv
, rx_replenish
);
5155 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5158 mutex_lock(&priv
->mutex
);
5159 iwl3945_rx_replenish(priv
);
5160 mutex_unlock(&priv
->mutex
);
5163 #define IWL_DELAY_NEXT_SCAN (HZ*2)
5165 static void iwl3945_post_associate(struct iwl_priv
*priv
)
5168 struct ieee80211_conf
*conf
= NULL
;
5170 if (priv
->iw_mode
== NL80211_IFTYPE_AP
) {
5171 IWL_ERR(priv
, "%s Should not be called in AP mode\n", __func__
);
5176 IWL_DEBUG_ASSOC("Associated as %d to: %pM\n",
5177 priv
->assoc_id
, priv
->active39_rxon
.bssid_addr
);
5179 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5182 if (!priv
->vif
|| !priv
->is_open
)
5185 iwl_scan_cancel_timeout(priv
, 200);
5187 conf
= ieee80211_get_hw_conf(priv
->hw
);
5189 priv
->staging39_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
5190 iwl3945_commit_rxon(priv
);
5192 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl_rxon_time_cmd
));
5193 iwl3945_setup_rxon_timing(priv
);
5194 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
5195 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
5197 IWL_WARN(priv
, "REPLY_RXON_TIMING failed - "
5198 "Attempting to continue.\n");
5200 priv
->staging39_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
5202 priv
->staging39_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
5204 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
5205 priv
->assoc_id
, priv
->beacon_int
);
5207 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
5208 priv
->staging39_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
5210 priv
->staging39_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
5212 if (priv
->staging39_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
5213 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
5214 priv
->staging39_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
5216 priv
->staging39_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
5218 if (priv
->iw_mode
== NL80211_IFTYPE_ADHOC
)
5219 priv
->staging39_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
5223 iwl3945_commit_rxon(priv
);
5225 switch (priv
->iw_mode
) {
5226 case NL80211_IFTYPE_STATION
:
5227 iwl3945_rate_scale_init(priv
->hw
, IWL_AP_ID
);
5230 case NL80211_IFTYPE_ADHOC
:
5233 iwl3945_add_station(priv
, priv
->bssid
, 0, 0);
5234 iwl3945_sync_sta(priv
, IWL_STA_ID
,
5235 (priv
->band
== IEEE80211_BAND_5GHZ
) ?
5236 IWL_RATE_6M_PLCP
: IWL_RATE_1M_PLCP
,
5238 iwl3945_rate_scale_init(priv
->hw
, IWL_STA_ID
);
5239 iwl3945_send_beacon_cmd(priv
);
5244 IWL_ERR(priv
, "%s Should not be called in %d mode\n",
5245 __func__
, priv
->iw_mode
);
5249 iwl3945_activate_qos(priv
, 0);
5251 /* we have just associated, don't start scan too early */
5252 priv
->next_scan_jiffies
= jiffies
+ IWL_DELAY_NEXT_SCAN
;
5255 static int iwl3945_mac_config(struct ieee80211_hw
*hw
, u32 changed
);
5257 /*****************************************************************************
5259 * mac80211 entry point functions
5261 *****************************************************************************/
5263 #define UCODE_READY_TIMEOUT (2 * HZ)
5265 static int iwl3945_mac_start(struct ieee80211_hw
*hw
)
5267 struct iwl_priv
*priv
= hw
->priv
;
5270 IWL_DEBUG_MAC80211("enter\n");
5272 /* we should be verifying the device is ready to be opened */
5273 mutex_lock(&priv
->mutex
);
5275 memset(&priv
->staging39_rxon
, 0, sizeof(struct iwl3945_rxon_cmd
));
5276 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
5277 * ucode filename and max sizes are card-specific. */
5279 if (!priv
->ucode_code
.len
) {
5280 ret
= iwl3945_read_ucode(priv
);
5282 IWL_ERR(priv
, "Could not read microcode: %d\n", ret
);
5283 mutex_unlock(&priv
->mutex
);
5284 goto out_release_irq
;
5288 ret
= __iwl3945_up(priv
);
5290 mutex_unlock(&priv
->mutex
);
5292 iwl_rfkill_set_hw_state(priv
);
5295 goto out_release_irq
;
5297 IWL_DEBUG_INFO("Start UP work.\n");
5299 if (test_bit(STATUS_IN_SUSPEND
, &priv
->status
))
5302 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
5303 * mac80211 will not be run successfully. */
5304 ret
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
5305 test_bit(STATUS_READY
, &priv
->status
),
5306 UCODE_READY_TIMEOUT
);
5308 if (!test_bit(STATUS_READY
, &priv
->status
)) {
5310 "Wait for START_ALIVE timeout after %dms.\n",
5311 jiffies_to_msecs(UCODE_READY_TIMEOUT
));
5313 goto out_release_irq
;
5317 /* ucode is running and will send rfkill notifications,
5318 * no need to poll the killswitch state anymore */
5319 cancel_delayed_work(&priv
->rfkill_poll
);
5322 IWL_DEBUG_MAC80211("leave\n");
5327 IWL_DEBUG_MAC80211("leave - failed\n");
5331 static void iwl3945_mac_stop(struct ieee80211_hw
*hw
)
5333 struct iwl_priv
*priv
= hw
->priv
;
5335 IWL_DEBUG_MAC80211("enter\n");
5337 if (!priv
->is_open
) {
5338 IWL_DEBUG_MAC80211("leave - skip\n");
5344 if (iwl_is_ready_rf(priv
)) {
5345 /* stop mac, cancel any scan request and clear
5346 * RXON_FILTER_ASSOC_MSK BIT
5348 mutex_lock(&priv
->mutex
);
5349 iwl_scan_cancel_timeout(priv
, 100);
5350 mutex_unlock(&priv
->mutex
);
5355 flush_workqueue(priv
->workqueue
);
5357 /* start polling the killswitch state again */
5358 queue_delayed_work(priv
->workqueue
, &priv
->rfkill_poll
,
5359 round_jiffies_relative(2 * HZ
));
5361 IWL_DEBUG_MAC80211("leave\n");
5364 static int iwl3945_mac_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
5366 struct iwl_priv
*priv
= hw
->priv
;
5368 IWL_DEBUG_MAC80211("enter\n");
5370 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb
->len
,
5371 ieee80211_get_tx_rate(hw
, IEEE80211_SKB_CB(skb
))->bitrate
);
5373 if (iwl3945_tx_skb(priv
, skb
))
5374 dev_kfree_skb_any(skb
);
5376 IWL_DEBUG_MAC80211("leave\n");
5377 return NETDEV_TX_OK
;
5380 static int iwl3945_mac_add_interface(struct ieee80211_hw
*hw
,
5381 struct ieee80211_if_init_conf
*conf
)
5383 struct iwl_priv
*priv
= hw
->priv
;
5384 unsigned long flags
;
5386 IWL_DEBUG_MAC80211("enter: type %d\n", conf
->type
);
5389 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
5393 spin_lock_irqsave(&priv
->lock
, flags
);
5394 priv
->vif
= conf
->vif
;
5395 priv
->iw_mode
= conf
->type
;
5397 spin_unlock_irqrestore(&priv
->lock
, flags
);
5399 mutex_lock(&priv
->mutex
);
5401 if (conf
->mac_addr
) {
5402 IWL_DEBUG_MAC80211("Set: %pM\n", conf
->mac_addr
);
5403 memcpy(priv
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
5406 if (iwl_is_ready(priv
))
5407 iwl3945_set_mode(priv
, conf
->type
);
5409 mutex_unlock(&priv
->mutex
);
5411 IWL_DEBUG_MAC80211("leave\n");
5416 * iwl3945_mac_config - mac80211 config callback
5418 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
5419 * be set inappropriately and the driver currently sets the hardware up to
5420 * use it whenever needed.
5422 static int iwl3945_mac_config(struct ieee80211_hw
*hw
, u32 changed
)
5424 struct iwl_priv
*priv
= hw
->priv
;
5425 const struct iwl_channel_info
*ch_info
;
5426 struct ieee80211_conf
*conf
= &hw
->conf
;
5427 unsigned long flags
;
5430 mutex_lock(&priv
->mutex
);
5431 IWL_DEBUG_MAC80211("enter to channel %d\n", conf
->channel
->hw_value
);
5433 if (!iwl_is_ready(priv
)) {
5434 IWL_DEBUG_MAC80211("leave - not ready\n");
5439 if (unlikely(!iwl3945_mod_params
.disable_hw_scan
&&
5440 test_bit(STATUS_SCANNING
, &priv
->status
))) {
5441 IWL_DEBUG_MAC80211("leave - scanning\n");
5442 set_bit(STATUS_CONF_PENDING
, &priv
->status
);
5443 mutex_unlock(&priv
->mutex
);
5447 spin_lock_irqsave(&priv
->lock
, flags
);
5449 ch_info
= iwl3945_get_channel_info(priv
, conf
->channel
->band
,
5450 conf
->channel
->hw_value
);
5451 if (!is_channel_valid(ch_info
)) {
5452 IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this band.\n",
5453 conf
->channel
->hw_value
, conf
->channel
->band
);
5454 IWL_DEBUG_MAC80211("leave - invalid channel\n");
5455 spin_unlock_irqrestore(&priv
->lock
, flags
);
5460 iwl3945_set_rxon_channel(priv
, conf
->channel
->band
, conf
->channel
->hw_value
);
5462 iwl3945_set_flags_for_phymode(priv
, conf
->channel
->band
);
5464 /* The list of supported rates and rate mask can be different
5465 * for each phymode; since the phymode may have changed, reset
5466 * the rate mask to what mac80211 lists */
5467 iwl3945_set_rate(priv
);
5469 spin_unlock_irqrestore(&priv
->lock
, flags
);
5471 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
5472 if (conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
) {
5473 iwl3945_hw_channel_switch(priv
, conf
->channel
);
5478 iwl3945_radio_kill_sw(priv
, !conf
->radio_enabled
);
5480 if (!conf
->radio_enabled
) {
5481 IWL_DEBUG_MAC80211("leave - radio disabled\n");
5485 if (iwl_is_rfkill(priv
)) {
5486 IWL_DEBUG_MAC80211("leave - RF kill\n");
5491 iwl3945_set_rate(priv
);
5493 if (memcmp(&priv
->active39_rxon
,
5494 &priv
->staging39_rxon
, sizeof(priv
->staging39_rxon
)))
5495 iwl3945_commit_rxon(priv
);
5497 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
5499 IWL_DEBUG_MAC80211("leave\n");
5502 clear_bit(STATUS_CONF_PENDING
, &priv
->status
);
5503 mutex_unlock(&priv
->mutex
);
5507 static void iwl3945_config_ap(struct iwl_priv
*priv
)
5511 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5514 /* The following should be done only at AP bring up */
5515 if (!(iwl3945_is_associated(priv
))) {
5517 /* RXON - unassoc (to set timing command) */
5518 priv
->staging39_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
5519 iwl3945_commit_rxon(priv
);
5522 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl_rxon_time_cmd
));
5523 iwl3945_setup_rxon_timing(priv
);
5524 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
5525 sizeof(priv
->rxon_timing
),
5526 &priv
->rxon_timing
);
5528 IWL_WARN(priv
, "REPLY_RXON_TIMING failed - "
5529 "Attempting to continue.\n");
5531 /* FIXME: what should be the assoc_id for AP? */
5532 priv
->staging39_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
5533 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
5534 priv
->staging39_rxon
.flags
|=
5535 RXON_FLG_SHORT_PREAMBLE_MSK
;
5537 priv
->staging39_rxon
.flags
&=
5538 ~RXON_FLG_SHORT_PREAMBLE_MSK
;
5540 if (priv
->staging39_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
5541 if (priv
->assoc_capability
&
5542 WLAN_CAPABILITY_SHORT_SLOT_TIME
)
5543 priv
->staging39_rxon
.flags
|=
5544 RXON_FLG_SHORT_SLOT_MSK
;
5546 priv
->staging39_rxon
.flags
&=
5547 ~RXON_FLG_SHORT_SLOT_MSK
;
5549 if (priv
->iw_mode
== NL80211_IFTYPE_ADHOC
)
5550 priv
->staging39_rxon
.flags
&=
5551 ~RXON_FLG_SHORT_SLOT_MSK
;
5553 /* restore RXON assoc */
5554 priv
->staging39_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
5555 iwl3945_commit_rxon(priv
);
5556 iwl3945_add_station(priv
, iwl_bcast_addr
, 0, 0);
5558 iwl3945_send_beacon_cmd(priv
);
5560 /* FIXME - we need to add code here to detect a totally new
5561 * configuration, reset the AP, unassoc, rxon timing, assoc,
5562 * clear sta table, add BCAST sta... */
5565 static int iwl3945_mac_config_interface(struct ieee80211_hw
*hw
,
5566 struct ieee80211_vif
*vif
,
5567 struct ieee80211_if_conf
*conf
)
5569 struct iwl_priv
*priv
= hw
->priv
;
5575 if (priv
->vif
!= vif
) {
5576 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
5580 /* handle this temporarily here */
5581 if (priv
->iw_mode
== NL80211_IFTYPE_ADHOC
&&
5582 conf
->changed
& IEEE80211_IFCC_BEACON
) {
5583 struct sk_buff
*beacon
= ieee80211_beacon_get(hw
, vif
);
5586 mutex_lock(&priv
->mutex
);
5587 rc
= iwl3945_mac_beacon_update(hw
, beacon
);
5588 mutex_unlock(&priv
->mutex
);
5593 if (!iwl_is_alive(priv
))
5596 mutex_lock(&priv
->mutex
);
5599 IWL_DEBUG_MAC80211("bssid: %pM\n", conf
->bssid
);
5602 * very dubious code was here; the probe filtering flag is never set:
5604 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
5605 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
5608 if (priv
->iw_mode
== NL80211_IFTYPE_AP
) {
5610 conf
->bssid
= priv
->mac_addr
;
5611 memcpy(priv
->bssid
, priv
->mac_addr
, ETH_ALEN
);
5612 IWL_DEBUG_MAC80211("bssid was set to: %pM\n",
5615 if (priv
->ibss_beacon
)
5616 dev_kfree_skb(priv
->ibss_beacon
);
5618 priv
->ibss_beacon
= ieee80211_beacon_get(hw
, vif
);
5621 if (iwl_is_rfkill(priv
))
5624 if (conf
->bssid
&& !is_zero_ether_addr(conf
->bssid
) &&
5625 !is_multicast_ether_addr(conf
->bssid
)) {
5626 /* If there is currently a HW scan going on in the background
5627 * then we need to cancel it else the RXON below will fail. */
5628 if (iwl_scan_cancel_timeout(priv
, 100)) {
5629 IWL_WARN(priv
, "Aborted scan still in progress "
5631 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
5632 mutex_unlock(&priv
->mutex
);
5635 memcpy(priv
->staging39_rxon
.bssid_addr
, conf
->bssid
, ETH_ALEN
);
5637 /* TODO: Audit driver for usage of these members and see
5638 * if mac80211 deprecates them (priv->bssid looks like it
5639 * shouldn't be there, but I haven't scanned the IBSS code
5640 * to verify) - jpk */
5641 memcpy(priv
->bssid
, conf
->bssid
, ETH_ALEN
);
5643 if (priv
->iw_mode
== NL80211_IFTYPE_AP
)
5644 iwl3945_config_ap(priv
);
5646 rc
= iwl3945_commit_rxon(priv
);
5647 if ((priv
->iw_mode
== NL80211_IFTYPE_STATION
) && rc
)
5648 iwl3945_add_station(priv
,
5649 priv
->active39_rxon
.bssid_addr
, 1, 0);
5653 iwl_scan_cancel_timeout(priv
, 100);
5654 priv
->staging39_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
5655 iwl3945_commit_rxon(priv
);
5659 IWL_DEBUG_MAC80211("leave\n");
5660 mutex_unlock(&priv
->mutex
);
5665 static void iwl3945_configure_filter(struct ieee80211_hw
*hw
,
5666 unsigned int changed_flags
,
5667 unsigned int *total_flags
,
5668 int mc_count
, struct dev_addr_list
*mc_list
)
5670 struct iwl_priv
*priv
= hw
->priv
;
5671 __le32
*filter_flags
= &priv
->staging39_rxon
.filter_flags
;
5673 IWL_DEBUG_MAC80211("Enter: changed: 0x%x, total: 0x%x\n",
5674 changed_flags
, *total_flags
);
5676 if (changed_flags
& (FIF_OTHER_BSS
| FIF_PROMISC_IN_BSS
)) {
5677 if (*total_flags
& (FIF_OTHER_BSS
| FIF_PROMISC_IN_BSS
))
5678 *filter_flags
|= RXON_FILTER_PROMISC_MSK
;
5680 *filter_flags
&= ~RXON_FILTER_PROMISC_MSK
;
5682 if (changed_flags
& FIF_ALLMULTI
) {
5683 if (*total_flags
& FIF_ALLMULTI
)
5684 *filter_flags
|= RXON_FILTER_ACCEPT_GRP_MSK
;
5686 *filter_flags
&= ~RXON_FILTER_ACCEPT_GRP_MSK
;
5688 if (changed_flags
& FIF_CONTROL
) {
5689 if (*total_flags
& FIF_CONTROL
)
5690 *filter_flags
|= RXON_FILTER_CTL2HOST_MSK
;
5692 *filter_flags
&= ~RXON_FILTER_CTL2HOST_MSK
;
5694 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
) {
5695 if (*total_flags
& FIF_BCN_PRBRESP_PROMISC
)
5696 *filter_flags
|= RXON_FILTER_BCON_AWARE_MSK
;
5698 *filter_flags
&= ~RXON_FILTER_BCON_AWARE_MSK
;
5701 /* We avoid iwl_commit_rxon here to commit the new filter flags
5702 * since mac80211 will call ieee80211_hw_config immediately.
5703 * (mc_list is not supported at this time). Otherwise, we need to
5704 * queue a background iwl_commit_rxon work.
5707 *total_flags
&= FIF_OTHER_BSS
| FIF_ALLMULTI
| FIF_PROMISC_IN_BSS
|
5708 FIF_BCN_PRBRESP_PROMISC
| FIF_CONTROL
;
5711 static void iwl3945_mac_remove_interface(struct ieee80211_hw
*hw
,
5712 struct ieee80211_if_init_conf
*conf
)
5714 struct iwl_priv
*priv
= hw
->priv
;
5716 IWL_DEBUG_MAC80211("enter\n");
5718 mutex_lock(&priv
->mutex
);
5720 if (iwl_is_ready_rf(priv
)) {
5721 iwl_scan_cancel_timeout(priv
, 100);
5722 priv
->staging39_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
5723 iwl3945_commit_rxon(priv
);
5725 if (priv
->vif
== conf
->vif
) {
5727 memset(priv
->bssid
, 0, ETH_ALEN
);
5729 mutex_unlock(&priv
->mutex
);
5731 IWL_DEBUG_MAC80211("leave\n");
5734 #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
5736 static void iwl3945_bss_info_changed(struct ieee80211_hw
*hw
,
5737 struct ieee80211_vif
*vif
,
5738 struct ieee80211_bss_conf
*bss_conf
,
5741 struct iwl_priv
*priv
= hw
->priv
;
5743 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes
);
5745 if (changes
& BSS_CHANGED_ERP_PREAMBLE
) {
5746 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
5747 bss_conf
->use_short_preamble
);
5748 if (bss_conf
->use_short_preamble
)
5749 priv
->staging39_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
5751 priv
->staging39_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
5754 if (changes
& BSS_CHANGED_ERP_CTS_PROT
) {
5755 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf
->use_cts_prot
);
5756 if (bss_conf
->use_cts_prot
&& (priv
->band
!= IEEE80211_BAND_5GHZ
))
5757 priv
->staging39_rxon
.flags
|= RXON_FLG_TGG_PROTECT_MSK
;
5759 priv
->staging39_rxon
.flags
&= ~RXON_FLG_TGG_PROTECT_MSK
;
5762 if (changes
& BSS_CHANGED_ASSOC
) {
5763 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf
->assoc
);
5764 /* This should never happen as this function should
5765 * never be called from interrupt context. */
5766 if (WARN_ON_ONCE(in_interrupt()))
5768 if (bss_conf
->assoc
) {
5769 priv
->assoc_id
= bss_conf
->aid
;
5770 priv
->beacon_int
= bss_conf
->beacon_int
;
5771 priv
->timestamp
= bss_conf
->timestamp
;
5772 priv
->assoc_capability
= bss_conf
->assoc_capability
;
5773 priv
->power_data
.dtim_period
= bss_conf
->dtim_period
;
5774 priv
->next_scan_jiffies
= jiffies
+
5775 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC
;
5776 mutex_lock(&priv
->mutex
);
5777 iwl3945_post_associate(priv
);
5778 mutex_unlock(&priv
->mutex
);
5781 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf
->assoc
);
5783 } else if (changes
&& iwl3945_is_associated(priv
) && priv
->assoc_id
) {
5784 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes
);
5785 iwl3945_send_rxon_assoc(priv
);
5790 static int iwl3945_mac_hw_scan(struct ieee80211_hw
*hw
, u8
*ssid
, size_t len
)
5793 unsigned long flags
;
5794 struct iwl_priv
*priv
= hw
->priv
;
5795 DECLARE_SSID_BUF(ssid_buf
);
5797 IWL_DEBUG_MAC80211("enter\n");
5799 mutex_lock(&priv
->mutex
);
5800 spin_lock_irqsave(&priv
->lock
, flags
);
5802 if (!iwl_is_ready_rf(priv
)) {
5804 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
5808 /* we don't schedule scan within next_scan_jiffies period */
5809 if (priv
->next_scan_jiffies
&&
5810 time_after(priv
->next_scan_jiffies
, jiffies
)) {
5814 /* if we just finished scan ask for delay for a broadcast scan */
5815 if ((len
== 0) && priv
->last_scan_jiffies
&&
5816 time_after(priv
->last_scan_jiffies
+ IWL_DELAY_NEXT_SCAN
,
5822 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
5823 print_ssid(ssid_buf
, ssid
, len
), (int)len
);
5825 priv
->one_direct_scan
= 1;
5826 priv
->direct_ssid_len
= (u8
)
5827 min((u8
) len
, (u8
) IW_ESSID_MAX_SIZE
);
5828 memcpy(priv
->direct_ssid
, ssid
, priv
->direct_ssid_len
);
5830 priv
->one_direct_scan
= 0;
5832 rc
= iwl3945_scan_initiate(priv
);
5834 IWL_DEBUG_MAC80211("leave\n");
5837 spin_unlock_irqrestore(&priv
->lock
, flags
);
5838 mutex_unlock(&priv
->mutex
);
5843 static int iwl3945_mac_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
5844 struct ieee80211_vif
*vif
,
5845 struct ieee80211_sta
*sta
,
5846 struct ieee80211_key_conf
*key
)
5848 struct iwl_priv
*priv
= hw
->priv
;
5853 IWL_DEBUG_MAC80211("enter\n");
5855 if (iwl3945_mod_params
.sw_crypto
) {
5856 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
5860 addr
= sta
? sta
->addr
: iwl_bcast_addr
;
5861 sta_id
= iwl3945_hw_find_station(priv
, addr
);
5862 if (sta_id
== IWL_INVALID_STATION
) {
5863 IWL_DEBUG_MAC80211("leave - %pM not in station map.\n",
5868 mutex_lock(&priv
->mutex
);
5870 iwl_scan_cancel_timeout(priv
, 100);
5874 ret
= iwl3945_update_sta_key_info(priv
, key
, sta_id
);
5876 iwl3945_set_rxon_hwcrypto(priv
, 1);
5877 iwl3945_commit_rxon(priv
);
5878 key
->hw_key_idx
= sta_id
;
5879 IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n");
5880 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
5884 ret
= iwl3945_clear_sta_key_info(priv
, sta_id
);
5886 iwl3945_set_rxon_hwcrypto(priv
, 0);
5887 iwl3945_commit_rxon(priv
);
5888 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
5895 IWL_DEBUG_MAC80211("leave\n");
5896 mutex_unlock(&priv
->mutex
);
5901 static int iwl3945_mac_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
5902 const struct ieee80211_tx_queue_params
*params
)
5904 struct iwl_priv
*priv
= hw
->priv
;
5905 unsigned long flags
;
5908 IWL_DEBUG_MAC80211("enter\n");
5910 if (!iwl_is_ready_rf(priv
)) {
5911 IWL_DEBUG_MAC80211("leave - RF not ready\n");
5915 if (queue
>= AC_NUM
) {
5916 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue
);
5920 q
= AC_NUM
- 1 - queue
;
5922 spin_lock_irqsave(&priv
->lock
, flags
);
5924 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_min
= cpu_to_le16(params
->cw_min
);
5925 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_max
= cpu_to_le16(params
->cw_max
);
5926 priv
->qos_data
.def_qos_parm
.ac
[q
].aifsn
= params
->aifs
;
5927 priv
->qos_data
.def_qos_parm
.ac
[q
].edca_txop
=
5928 cpu_to_le16((params
->txop
* 32));
5930 priv
->qos_data
.def_qos_parm
.ac
[q
].reserved1
= 0;
5931 priv
->qos_data
.qos_active
= 1;
5933 spin_unlock_irqrestore(&priv
->lock
, flags
);
5935 mutex_lock(&priv
->mutex
);
5936 if (priv
->iw_mode
== NL80211_IFTYPE_AP
)
5937 iwl3945_activate_qos(priv
, 1);
5938 else if (priv
->assoc_id
&& iwl3945_is_associated(priv
))
5939 iwl3945_activate_qos(priv
, 0);
5941 mutex_unlock(&priv
->mutex
);
5943 IWL_DEBUG_MAC80211("leave\n");
5947 static int iwl3945_mac_get_tx_stats(struct ieee80211_hw
*hw
,
5948 struct ieee80211_tx_queue_stats
*stats
)
5950 struct iwl_priv
*priv
= hw
->priv
;
5952 struct iwl_tx_queue
*txq
;
5953 struct iwl_queue
*q
;
5954 unsigned long flags
;
5956 IWL_DEBUG_MAC80211("enter\n");
5958 if (!iwl_is_ready_rf(priv
)) {
5959 IWL_DEBUG_MAC80211("leave - RF not ready\n");
5963 spin_lock_irqsave(&priv
->lock
, flags
);
5965 for (i
= 0; i
< AC_NUM
; i
++) {
5966 txq
= &priv
->txq
[i
];
5968 avail
= iwl_queue_space(q
);
5970 stats
[i
].len
= q
->n_window
- avail
;
5971 stats
[i
].limit
= q
->n_window
- q
->high_mark
;
5972 stats
[i
].count
= q
->n_window
;
5975 spin_unlock_irqrestore(&priv
->lock
, flags
);
5977 IWL_DEBUG_MAC80211("leave\n");
5982 static void iwl3945_mac_reset_tsf(struct ieee80211_hw
*hw
)
5984 struct iwl_priv
*priv
= hw
->priv
;
5985 unsigned long flags
;
5987 mutex_lock(&priv
->mutex
);
5988 IWL_DEBUG_MAC80211("enter\n");
5990 iwl_reset_qos(priv
);
5992 spin_lock_irqsave(&priv
->lock
, flags
);
5994 priv
->assoc_capability
= 0;
5996 /* new association get rid of ibss beacon skb */
5997 if (priv
->ibss_beacon
)
5998 dev_kfree_skb(priv
->ibss_beacon
);
6000 priv
->ibss_beacon
= NULL
;
6002 priv
->beacon_int
= priv
->hw
->conf
.beacon_int
;
6003 priv
->timestamp
= 0;
6004 if ((priv
->iw_mode
== NL80211_IFTYPE_STATION
))
6005 priv
->beacon_int
= 0;
6007 spin_unlock_irqrestore(&priv
->lock
, flags
);
6009 if (!iwl_is_ready_rf(priv
)) {
6010 IWL_DEBUG_MAC80211("leave - not ready\n");
6011 mutex_unlock(&priv
->mutex
);
6015 /* we are restarting association process
6016 * clear RXON_FILTER_ASSOC_MSK bit
6018 if (priv
->iw_mode
!= NL80211_IFTYPE_AP
) {
6019 iwl_scan_cancel_timeout(priv
, 100);
6020 priv
->staging39_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6021 iwl3945_commit_rxon(priv
);
6024 /* Per mac80211.h: This is only used in IBSS mode... */
6025 if (priv
->iw_mode
!= NL80211_IFTYPE_ADHOC
) {
6027 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
6028 mutex_unlock(&priv
->mutex
);
6032 iwl3945_set_rate(priv
);
6034 mutex_unlock(&priv
->mutex
);
6036 IWL_DEBUG_MAC80211("leave\n");
6040 static int iwl3945_mac_beacon_update(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
6042 struct iwl_priv
*priv
= hw
->priv
;
6043 unsigned long flags
;
6045 IWL_DEBUG_MAC80211("enter\n");
6047 if (!iwl_is_ready_rf(priv
)) {
6048 IWL_DEBUG_MAC80211("leave - RF not ready\n");
6052 if (priv
->iw_mode
!= NL80211_IFTYPE_ADHOC
) {
6053 IWL_DEBUG_MAC80211("leave - not IBSS\n");
6057 spin_lock_irqsave(&priv
->lock
, flags
);
6059 if (priv
->ibss_beacon
)
6060 dev_kfree_skb(priv
->ibss_beacon
);
6062 priv
->ibss_beacon
= skb
;
6066 IWL_DEBUG_MAC80211("leave\n");
6067 spin_unlock_irqrestore(&priv
->lock
, flags
);
6069 iwl_reset_qos(priv
);
6071 iwl3945_post_associate(priv
);
6077 /*****************************************************************************
6081 *****************************************************************************/
6083 #ifdef CONFIG_IWL3945_DEBUG
6086 * The following adds a new attribute to the sysfs representation
6087 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
6088 * used for controlling the debug level.
6090 * See the level definitions in iwl for details.
6092 static ssize_t
show_debug_level(struct device
*d
,
6093 struct device_attribute
*attr
, char *buf
)
6095 struct iwl_priv
*priv
= d
->driver_data
;
6097 return sprintf(buf
, "0x%08X\n", priv
->debug_level
);
6099 static ssize_t
store_debug_level(struct device
*d
,
6100 struct device_attribute
*attr
,
6101 const char *buf
, size_t count
)
6103 struct iwl_priv
*priv
= d
->driver_data
;
6107 ret
= strict_strtoul(buf
, 0, &val
);
6109 IWL_INFO(priv
, "%s is not in hex or decimal form.\n", buf
);
6111 priv
->debug_level
= val
;
6113 return strnlen(buf
, count
);
6116 static DEVICE_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
6117 show_debug_level
, store_debug_level
);
6119 #endif /* CONFIG_IWL3945_DEBUG */
6121 static ssize_t
show_temperature(struct device
*d
,
6122 struct device_attribute
*attr
, char *buf
)
6124 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6126 if (!iwl_is_alive(priv
))
6129 return sprintf(buf
, "%d\n", iwl3945_hw_get_temperature(priv
));
6132 static DEVICE_ATTR(temperature
, S_IRUGO
, show_temperature
, NULL
);
6134 static ssize_t
show_tx_power(struct device
*d
,
6135 struct device_attribute
*attr
, char *buf
)
6137 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6138 return sprintf(buf
, "%d\n", priv
->tx_power_user_lmt
);
6141 static ssize_t
store_tx_power(struct device
*d
,
6142 struct device_attribute
*attr
,
6143 const char *buf
, size_t count
)
6145 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6146 char *p
= (char *)buf
;
6149 val
= simple_strtoul(p
, &p
, 10);
6151 IWL_INFO(priv
, ": %s is not in decimal form.\n", buf
);
6153 iwl3945_hw_reg_set_txpower(priv
, val
);
6158 static DEVICE_ATTR(tx_power
, S_IWUSR
| S_IRUGO
, show_tx_power
, store_tx_power
);
6160 static ssize_t
show_flags(struct device
*d
,
6161 struct device_attribute
*attr
, char *buf
)
6163 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6165 return sprintf(buf
, "0x%04X\n", priv
->active39_rxon
.flags
);
6168 static ssize_t
store_flags(struct device
*d
,
6169 struct device_attribute
*attr
,
6170 const char *buf
, size_t count
)
6172 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6173 u32 flags
= simple_strtoul(buf
, NULL
, 0);
6175 mutex_lock(&priv
->mutex
);
6176 if (le32_to_cpu(priv
->staging39_rxon
.flags
) != flags
) {
6177 /* Cancel any currently running scans... */
6178 if (iwl_scan_cancel_timeout(priv
, 100))
6179 IWL_WARN(priv
, "Could not cancel scan.\n");
6181 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
6183 priv
->staging39_rxon
.flags
= cpu_to_le32(flags
);
6184 iwl3945_commit_rxon(priv
);
6187 mutex_unlock(&priv
->mutex
);
6192 static DEVICE_ATTR(flags
, S_IWUSR
| S_IRUGO
, show_flags
, store_flags
);
6194 static ssize_t
show_filter_flags(struct device
*d
,
6195 struct device_attribute
*attr
, char *buf
)
6197 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6199 return sprintf(buf
, "0x%04X\n",
6200 le32_to_cpu(priv
->active39_rxon
.filter_flags
));
6203 static ssize_t
store_filter_flags(struct device
*d
,
6204 struct device_attribute
*attr
,
6205 const char *buf
, size_t count
)
6207 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6208 u32 filter_flags
= simple_strtoul(buf
, NULL
, 0);
6210 mutex_lock(&priv
->mutex
);
6211 if (le32_to_cpu(priv
->staging39_rxon
.filter_flags
) != filter_flags
) {
6212 /* Cancel any currently running scans... */
6213 if (iwl_scan_cancel_timeout(priv
, 100))
6214 IWL_WARN(priv
, "Could not cancel scan.\n");
6216 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
6217 "0x%04X\n", filter_flags
);
6218 priv
->staging39_rxon
.filter_flags
=
6219 cpu_to_le32(filter_flags
);
6220 iwl3945_commit_rxon(priv
);
6223 mutex_unlock(&priv
->mutex
);
6228 static DEVICE_ATTR(filter_flags
, S_IWUSR
| S_IRUGO
, show_filter_flags
,
6229 store_filter_flags
);
6231 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
6233 static ssize_t
show_measurement(struct device
*d
,
6234 struct device_attribute
*attr
, char *buf
)
6236 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6237 struct iwl_spectrum_notification measure_report
;
6238 u32 size
= sizeof(measure_report
), len
= 0, ofs
= 0;
6239 u8
*data
= (u8
*)&measure_report
;
6240 unsigned long flags
;
6242 spin_lock_irqsave(&priv
->lock
, flags
);
6243 if (!(priv
->measurement_status
& MEASUREMENT_READY
)) {
6244 spin_unlock_irqrestore(&priv
->lock
, flags
);
6247 memcpy(&measure_report
, &priv
->measure_report
, size
);
6248 priv
->measurement_status
= 0;
6249 spin_unlock_irqrestore(&priv
->lock
, flags
);
6251 while (size
&& (PAGE_SIZE
- len
)) {
6252 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
6253 PAGE_SIZE
- len
, 1);
6255 if (PAGE_SIZE
- len
)
6259 size
-= min(size
, 16U);
6265 static ssize_t
store_measurement(struct device
*d
,
6266 struct device_attribute
*attr
,
6267 const char *buf
, size_t count
)
6269 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6270 struct ieee80211_measurement_params params
= {
6271 .channel
= le16_to_cpu(priv
->active39_rxon
.channel
),
6272 .start_time
= cpu_to_le64(priv
->last_tsf
),
6273 .duration
= cpu_to_le16(1),
6275 u8 type
= IWL_MEASURE_BASIC
;
6281 strncpy(buffer
, buf
, min(sizeof(buffer
), count
));
6282 channel
= simple_strtoul(p
, NULL
, 0);
6284 params
.channel
= channel
;
6287 while (*p
&& *p
!= ' ')
6290 type
= simple_strtoul(p
+ 1, NULL
, 0);
6293 IWL_DEBUG_INFO("Invoking measurement of type %d on "
6294 "channel %d (for '%s')\n", type
, params
.channel
, buf
);
6295 iwl3945_get_measurement(priv
, ¶ms
, type
);
6300 static DEVICE_ATTR(measurement
, S_IRUSR
| S_IWUSR
,
6301 show_measurement
, store_measurement
);
6302 #endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
6304 static ssize_t
store_retry_rate(struct device
*d
,
6305 struct device_attribute
*attr
,
6306 const char *buf
, size_t count
)
6308 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6310 priv
->retry_rate
= simple_strtoul(buf
, NULL
, 0);
6311 if (priv
->retry_rate
<= 0)
6312 priv
->retry_rate
= 1;
6317 static ssize_t
show_retry_rate(struct device
*d
,
6318 struct device_attribute
*attr
, char *buf
)
6320 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6321 return sprintf(buf
, "%d", priv
->retry_rate
);
6324 static DEVICE_ATTR(retry_rate
, S_IWUSR
| S_IRUSR
, show_retry_rate
,
6327 static ssize_t
store_power_level(struct device
*d
,
6328 struct device_attribute
*attr
,
6329 const char *buf
, size_t count
)
6331 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6335 mode
= simple_strtoul(buf
, NULL
, 0);
6336 mutex_lock(&priv
->mutex
);
6338 if (!iwl_is_ready(priv
)) {
6343 if ((mode
< 1) || (mode
> IWL39_POWER_LIMIT
) ||
6344 (mode
== IWL39_POWER_AC
))
6345 mode
= IWL39_POWER_AC
;
6347 mode
|= IWL_POWER_ENABLED
;
6349 if (mode
!= priv
->power_mode
) {
6350 rc
= iwl3945_send_power_mode(priv
, IWL_POWER_LEVEL(mode
));
6352 IWL_DEBUG_MAC80211("failed setting power mode.\n");
6355 priv
->power_mode
= mode
;
6361 mutex_unlock(&priv
->mutex
);
6365 #define MAX_WX_STRING 80
6367 /* Values are in microsecond */
6368 static const s32 timeout_duration
[] = {
6375 static const s32 period_duration
[] = {
6383 static ssize_t
show_power_level(struct device
*d
,
6384 struct device_attribute
*attr
, char *buf
)
6386 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6387 int level
= IWL_POWER_LEVEL(priv
->power_mode
);
6390 p
+= sprintf(p
, "%d ", level
);
6392 case IWL_POWER_MODE_CAM
:
6393 case IWL39_POWER_AC
:
6394 p
+= sprintf(p
, "(AC)");
6396 case IWL39_POWER_BATTERY
:
6397 p
+= sprintf(p
, "(BATTERY)");
6401 "(Timeout %dms, Period %dms)",
6402 timeout_duration
[level
- 1] / 1000,
6403 period_duration
[level
- 1] / 1000);
6406 if (!(priv
->power_mode
& IWL_POWER_ENABLED
))
6407 p
+= sprintf(p
, " OFF\n");
6409 p
+= sprintf(p
, " \n");
6415 static DEVICE_ATTR(power_level
, S_IWUSR
| S_IRUSR
, show_power_level
,
6418 static ssize_t
show_channels(struct device
*d
,
6419 struct device_attribute
*attr
, char *buf
)
6421 /* all this shit doesn't belong into sysfs anyway */
6425 static DEVICE_ATTR(channels
, S_IRUSR
, show_channels
, NULL
);
6427 static ssize_t
show_statistics(struct device
*d
,
6428 struct device_attribute
*attr
, char *buf
)
6430 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6431 u32 size
= sizeof(struct iwl3945_notif_statistics
);
6432 u32 len
= 0, ofs
= 0;
6433 u8
*data
= (u8
*)&priv
->statistics_39
;
6436 if (!iwl_is_alive(priv
))
6439 mutex_lock(&priv
->mutex
);
6440 rc
= iwl3945_send_statistics_request(priv
);
6441 mutex_unlock(&priv
->mutex
);
6445 "Error sending statistics request: 0x%08X\n", rc
);
6449 while (size
&& (PAGE_SIZE
- len
)) {
6450 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
6451 PAGE_SIZE
- len
, 1);
6453 if (PAGE_SIZE
- len
)
6457 size
-= min(size
, 16U);
6463 static DEVICE_ATTR(statistics
, S_IRUGO
, show_statistics
, NULL
);
6465 static ssize_t
show_antenna(struct device
*d
,
6466 struct device_attribute
*attr
, char *buf
)
6468 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6470 if (!iwl_is_alive(priv
))
6473 return sprintf(buf
, "%d\n", priv
->antenna
);
6476 static ssize_t
store_antenna(struct device
*d
,
6477 struct device_attribute
*attr
,
6478 const char *buf
, size_t count
)
6481 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6486 if (sscanf(buf
, "%1i", &ant
) != 1) {
6487 IWL_DEBUG_INFO("not in hex or decimal form.\n");
6491 if ((ant
>= 0) && (ant
<= 2)) {
6492 IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant
);
6493 priv
->antenna
= (enum iwl3945_antenna
)ant
;
6495 IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant
);
6501 static DEVICE_ATTR(antenna
, S_IWUSR
| S_IRUGO
, show_antenna
, store_antenna
);
6503 static ssize_t
show_status(struct device
*d
,
6504 struct device_attribute
*attr
, char *buf
)
6506 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6507 if (!iwl_is_alive(priv
))
6509 return sprintf(buf
, "0x%08x\n", (int)priv
->status
);
6512 static DEVICE_ATTR(status
, S_IRUGO
, show_status
, NULL
);
6514 static ssize_t
dump_error_log(struct device
*d
,
6515 struct device_attribute
*attr
,
6516 const char *buf
, size_t count
)
6518 char *p
= (char *)buf
;
6521 iwl3945_dump_nic_error_log((struct iwl_priv
*)d
->driver_data
);
6523 return strnlen(buf
, count
);
6526 static DEVICE_ATTR(dump_errors
, S_IWUSR
, NULL
, dump_error_log
);
6528 static ssize_t
dump_event_log(struct device
*d
,
6529 struct device_attribute
*attr
,
6530 const char *buf
, size_t count
)
6532 char *p
= (char *)buf
;
6535 iwl3945_dump_nic_event_log((struct iwl_priv
*)d
->driver_data
);
6537 return strnlen(buf
, count
);
6540 static DEVICE_ATTR(dump_events
, S_IWUSR
, NULL
, dump_event_log
);
6542 /*****************************************************************************
6544 * driver setup and tear down
6546 *****************************************************************************/
6548 static void iwl3945_setup_deferred_work(struct iwl_priv
*priv
)
6550 priv
->workqueue
= create_workqueue(DRV_NAME
);
6552 init_waitqueue_head(&priv
->wait_command_queue
);
6554 INIT_WORK(&priv
->up
, iwl3945_bg_up
);
6555 INIT_WORK(&priv
->restart
, iwl3945_bg_restart
);
6556 INIT_WORK(&priv
->rx_replenish
, iwl3945_bg_rx_replenish
);
6557 INIT_WORK(&priv
->rf_kill
, iwl_bg_rf_kill
);
6558 INIT_WORK(&priv
->beacon_update
, iwl3945_bg_beacon_update
);
6559 INIT_DELAYED_WORK(&priv
->init_alive_start
, iwl3945_bg_init_alive_start
);
6560 INIT_DELAYED_WORK(&priv
->alive_start
, iwl3945_bg_alive_start
);
6561 INIT_DELAYED_WORK(&priv
->rfkill_poll
, iwl3945_rfkill_poll
);
6562 INIT_WORK(&priv
->scan_completed
, iwl_bg_scan_completed
);
6563 INIT_WORK(&priv
->request_scan
, iwl3945_bg_request_scan
);
6564 INIT_WORK(&priv
->abort_scan
, iwl_bg_abort_scan
);
6565 INIT_DELAYED_WORK(&priv
->scan_check
, iwl_bg_scan_check
);
6567 iwl3945_hw_setup_deferred_work(priv
);
6569 tasklet_init(&priv
->irq_tasklet
, (void (*)(unsigned long))
6570 iwl3945_irq_tasklet
, (unsigned long)priv
);
6573 static void iwl3945_cancel_deferred_work(struct iwl_priv
*priv
)
6575 iwl3945_hw_cancel_deferred_work(priv
);
6577 cancel_delayed_work_sync(&priv
->init_alive_start
);
6578 cancel_delayed_work(&priv
->scan_check
);
6579 cancel_delayed_work(&priv
->alive_start
);
6580 cancel_work_sync(&priv
->beacon_update
);
6583 static struct attribute
*iwl3945_sysfs_entries
[] = {
6584 &dev_attr_antenna
.attr
,
6585 &dev_attr_channels
.attr
,
6586 &dev_attr_dump_errors
.attr
,
6587 &dev_attr_dump_events
.attr
,
6588 &dev_attr_flags
.attr
,
6589 &dev_attr_filter_flags
.attr
,
6590 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
6591 &dev_attr_measurement
.attr
,
6593 &dev_attr_power_level
.attr
,
6594 &dev_attr_retry_rate
.attr
,
6595 &dev_attr_statistics
.attr
,
6596 &dev_attr_status
.attr
,
6597 &dev_attr_temperature
.attr
,
6598 &dev_attr_tx_power
.attr
,
6599 #ifdef CONFIG_IWL3945_DEBUG
6600 &dev_attr_debug_level
.attr
,
6605 static struct attribute_group iwl3945_attribute_group
= {
6606 .name
= NULL
, /* put in device directory */
6607 .attrs
= iwl3945_sysfs_entries
,
6610 static struct ieee80211_ops iwl3945_hw_ops
= {
6611 .tx
= iwl3945_mac_tx
,
6612 .start
= iwl3945_mac_start
,
6613 .stop
= iwl3945_mac_stop
,
6614 .add_interface
= iwl3945_mac_add_interface
,
6615 .remove_interface
= iwl3945_mac_remove_interface
,
6616 .config
= iwl3945_mac_config
,
6617 .config_interface
= iwl3945_mac_config_interface
,
6618 .configure_filter
= iwl3945_configure_filter
,
6619 .set_key
= iwl3945_mac_set_key
,
6620 .get_tx_stats
= iwl3945_mac_get_tx_stats
,
6621 .conf_tx
= iwl3945_mac_conf_tx
,
6622 .reset_tsf
= iwl3945_mac_reset_tsf
,
6623 .bss_info_changed
= iwl3945_bss_info_changed
,
6624 .hw_scan
= iwl3945_mac_hw_scan
6627 static int iwl3945_init_drv(struct iwl_priv
*priv
)
6631 priv
->retry_rate
= 1;
6632 priv
->ibss_beacon
= NULL
;
6634 spin_lock_init(&priv
->lock
);
6635 spin_lock_init(&priv
->power_data
.lock
);
6636 spin_lock_init(&priv
->sta_lock
);
6637 spin_lock_init(&priv
->hcmd_lock
);
6639 INIT_LIST_HEAD(&priv
->free_frames
);
6641 mutex_init(&priv
->mutex
);
6643 /* Clear the driver's (not device's) station table */
6644 iwl3945_clear_stations_table(priv
);
6646 priv
->data_retry_limit
= -1;
6647 priv
->ieee_channels
= NULL
;
6648 priv
->ieee_rates
= NULL
;
6649 priv
->band
= IEEE80211_BAND_2GHZ
;
6651 priv
->iw_mode
= NL80211_IFTYPE_STATION
;
6653 iwl_reset_qos(priv
);
6655 priv
->qos_data
.qos_active
= 0;
6656 priv
->qos_data
.qos_cap
.val
= 0;
6658 priv
->rates_mask
= IWL_RATES_MASK
;
6659 /* If power management is turned on, default to AC mode */
6660 priv
->power_mode
= IWL39_POWER_AC
;
6661 priv
->tx_power_user_lmt
= IWL_DEFAULT_TX_POWER
;
6663 ret
= iwl3945_init_channel_map(priv
);
6665 IWL_ERR(priv
, "initializing regulatory failed: %d\n", ret
);
6669 ret
= iwl3945_init_geos(priv
);
6671 IWL_ERR(priv
, "initializing geos failed: %d\n", ret
);
6672 goto err_free_channel_map
;
6677 err_free_channel_map
:
6678 iwl3945_free_channel_map(priv
);
6683 static int iwl3945_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
6686 struct iwl_priv
*priv
;
6687 struct ieee80211_hw
*hw
;
6688 struct iwl_cfg
*cfg
= (struct iwl_cfg
*)(ent
->driver_data
);
6689 unsigned long flags
;
6691 /***********************
6692 * 1. Allocating HW data
6693 * ********************/
6695 /* mac80211 allocates memory for this device instance, including
6696 * space for this driver's private structure */
6697 hw
= iwl_alloc_all(cfg
, &iwl3945_hw_ops
);
6699 printk(KERN_ERR DRV_NAME
"Can not allocate network device\n");
6704 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
6706 if ((iwl3945_mod_params
.num_of_queues
> IWL39_MAX_NUM_QUEUES
) ||
6707 (iwl3945_mod_params
.num_of_queues
< IWL_MIN_NUM_QUEUES
)) {
6709 "invalid queues_num, should be between %d and %d\n",
6710 IWL_MIN_NUM_QUEUES
, IWL39_MAX_NUM_QUEUES
);
6716 * Disabling hardware scan means that mac80211 will perform scans
6717 * "the hard way", rather than using device's scan.
6719 if (iwl3945_mod_params
.disable_hw_scan
) {
6720 IWL_DEBUG_INFO("Disabling hw_scan\n");
6721 iwl3945_hw_ops
.hw_scan
= NULL
;
6725 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
6727 priv
->pci_dev
= pdev
;
6729 #ifdef CONFIG_IWL3945_DEBUG
6730 priv
->debug_level
= iwl3945_mod_params
.debug
;
6731 atomic_set(&priv
->restrict_refcnt
, 0);
6733 hw
->rate_control_algorithm
= "iwl-3945-rs";
6734 hw
->sta_data_size
= sizeof(struct iwl3945_sta_priv
);
6736 /* Select antenna (may be helpful if only one antenna is connected) */
6737 priv
->antenna
= (enum iwl3945_antenna
)iwl3945_mod_params
.antenna
;
6739 /* Tell mac80211 our characteristics */
6740 hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
6741 IEEE80211_HW_NOISE_DBM
;
6743 hw
->wiphy
->interface_modes
=
6744 BIT(NL80211_IFTYPE_STATION
) |
6745 BIT(NL80211_IFTYPE_ADHOC
);
6747 hw
->wiphy
->custom_regulatory
= true;
6749 /* 4 EDCA QOS priorities */
6752 /***************************
6753 * 2. Initializing PCI bus
6754 * *************************/
6755 if (pci_enable_device(pdev
)) {
6757 goto out_ieee80211_free_hw
;
6760 pci_set_master(pdev
);
6762 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
6764 err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
6766 IWL_WARN(priv
, "No suitable DMA available.\n");
6767 goto out_pci_disable_device
;
6770 pci_set_drvdata(pdev
, priv
);
6771 err
= pci_request_regions(pdev
, DRV_NAME
);
6773 goto out_pci_disable_device
;
6775 /***********************
6776 * 3. Read REV Register
6777 * ********************/
6778 priv
->hw_base
= pci_iomap(pdev
, 0, 0);
6779 if (!priv
->hw_base
) {
6781 goto out_pci_release_regions
;
6784 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
6785 (unsigned long long) pci_resource_len(pdev
, 0));
6786 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv
->hw_base
);
6788 /* We disable the RETRY_TIMEOUT register (0x41) to keep
6789 * PCI Tx retries from interfering with C3 CPU state */
6790 pci_write_config_byte(pdev
, 0x41, 0x00);
6793 err
= priv
->cfg
->ops
->lib
->apm_ops
.init(priv
);
6795 IWL_DEBUG_INFO("Failed to init APMG\n");
6799 /***********************
6801 * ********************/
6803 /* Read the EEPROM */
6804 err
= iwl3945_eeprom_init(priv
);
6806 IWL_ERR(priv
, "Unable to init EEPROM\n");
6807 goto out_remove_sysfs
;
6809 /* MAC Address location in EEPROM same for 3945/4965 */
6810 get_eeprom_mac(priv
, priv
->mac_addr
);
6811 IWL_DEBUG_INFO("MAC address: %pM\n", priv
->mac_addr
);
6812 SET_IEEE80211_PERM_ADDR(priv
->hw
, priv
->mac_addr
);
6814 /***********************
6815 * 5. Setup HW Constants
6816 * ********************/
6817 /* Device-specific setup */
6818 if (iwl3945_hw_set_hw_params(priv
)) {
6819 IWL_ERR(priv
, "failed to set hw settings\n");
6823 /***********************
6825 * ********************/
6827 err
= iwl3945_init_drv(priv
);
6829 IWL_ERR(priv
, "initializing driver failed\n");
6833 IWL_INFO(priv
, "Detected Intel Wireless WiFi Link %s\n",
6836 /***********************************
6837 * 7. Initialize Module Parameters
6838 * **********************************/
6840 /* Initialize module parameter values here */
6841 /* Disable radio (SW RF KILL) via parameter when loading driver */
6842 if (iwl3945_mod_params
.disable
) {
6843 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
6844 IWL_DEBUG_INFO("Radio disabled.\n");
6848 /***********************
6850 * ********************/
6852 spin_lock_irqsave(&priv
->lock
, flags
);
6853 iwl3945_disable_interrupts(priv
);
6854 spin_unlock_irqrestore(&priv
->lock
, flags
);
6856 pci_enable_msi(priv
->pci_dev
);
6858 err
= request_irq(priv
->pci_dev
->irq
, iwl3945_isr
, IRQF_SHARED
,
6861 IWL_ERR(priv
, "Error allocating IRQ %d\n", priv
->pci_dev
->irq
);
6862 goto out_disable_msi
;
6865 err
= sysfs_create_group(&pdev
->dev
.kobj
, &iwl3945_attribute_group
);
6867 IWL_ERR(priv
, "failed to create sysfs device attributes\n");
6868 goto out_release_irq
;
6871 iwl3945_set_rxon_channel(priv
, IEEE80211_BAND_2GHZ
, 6);
6872 iwl3945_setup_deferred_work(priv
);
6873 iwl3945_setup_rx_handlers(priv
);
6875 /*********************************
6876 * 9. Setup and Register mac80211
6877 * *******************************/
6879 err
= ieee80211_register_hw(priv
->hw
);
6881 IWL_ERR(priv
, "Failed to register network device: %d\n", err
);
6882 goto out_remove_sysfs
;
6885 priv
->hw
->conf
.beacon_int
= 100;
6886 priv
->mac80211_registered
= 1;
6888 err
= iwl_rfkill_init(priv
);
6890 IWL_ERR(priv
, "Unable to initialize RFKILL system. "
6891 "Ignoring error: %d\n", err
);
6893 /* Start monitoring the killswitch */
6894 queue_delayed_work(priv
->workqueue
, &priv
->rfkill_poll
,
6900 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl3945_attribute_group
);
6902 iwl3945_free_geos(priv
);
6905 free_irq(priv
->pci_dev
->irq
, priv
);
6906 destroy_workqueue(priv
->workqueue
);
6907 priv
->workqueue
= NULL
;
6908 iwl3945_unset_hw_params(priv
);
6910 pci_disable_msi(priv
->pci_dev
);
6912 pci_iounmap(pdev
, priv
->hw_base
);
6913 out_pci_release_regions
:
6914 pci_release_regions(pdev
);
6915 out_pci_disable_device
:
6916 pci_disable_device(pdev
);
6917 pci_set_drvdata(pdev
, NULL
);
6918 out_ieee80211_free_hw
:
6919 ieee80211_free_hw(priv
->hw
);
6924 static void __devexit
iwl3945_pci_remove(struct pci_dev
*pdev
)
6926 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
6927 unsigned long flags
;
6932 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
6934 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
6936 if (priv
->mac80211_registered
) {
6937 ieee80211_unregister_hw(priv
->hw
);
6938 priv
->mac80211_registered
= 0;
6943 /* make sure we flush any pending irq or
6944 * tasklet for the driver
6946 spin_lock_irqsave(&priv
->lock
, flags
);
6947 iwl3945_disable_interrupts(priv
);
6948 spin_unlock_irqrestore(&priv
->lock
, flags
);
6950 iwl_synchronize_irq(priv
);
6952 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl3945_attribute_group
);
6954 iwl_rfkill_unregister(priv
);
6955 cancel_delayed_work(&priv
->rfkill_poll
);
6957 iwl3945_dealloc_ucode_pci(priv
);
6960 iwl_rx_queue_free(priv
, &priv
->rxq
);
6961 iwl3945_hw_txq_ctx_free(priv
);
6963 iwl3945_unset_hw_params(priv
);
6964 iwl3945_clear_stations_table(priv
);
6966 /*netif_stop_queue(dev); */
6967 flush_workqueue(priv
->workqueue
);
6969 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
6970 * priv->workqueue... so we can't take down the workqueue
6972 destroy_workqueue(priv
->workqueue
);
6973 priv
->workqueue
= NULL
;
6975 free_irq(pdev
->irq
, priv
);
6976 pci_disable_msi(pdev
);
6978 pci_iounmap(pdev
, priv
->hw_base
);
6979 pci_release_regions(pdev
);
6980 pci_disable_device(pdev
);
6981 pci_set_drvdata(pdev
, NULL
);
6983 iwl3945_free_channel_map(priv
);
6984 iwl3945_free_geos(priv
);
6986 if (priv
->ibss_beacon
)
6987 dev_kfree_skb(priv
->ibss_beacon
);
6989 ieee80211_free_hw(priv
->hw
);
6994 static int iwl3945_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
6996 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
6998 if (priv
->is_open
) {
6999 set_bit(STATUS_IN_SUSPEND
, &priv
->status
);
7000 iwl3945_mac_stop(priv
->hw
);
7003 pci_save_state(pdev
);
7004 pci_disable_device(pdev
);
7005 pci_set_power_state(pdev
, PCI_D3hot
);
7010 static int iwl3945_pci_resume(struct pci_dev
*pdev
)
7012 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
7014 pci_set_power_state(pdev
, PCI_D0
);
7015 pci_enable_device(pdev
);
7016 pci_restore_state(pdev
);
7019 iwl3945_mac_start(priv
->hw
);
7021 clear_bit(STATUS_IN_SUSPEND
, &priv
->status
);
7025 #endif /* CONFIG_PM */
7027 /*****************************************************************************
7029 * driver and module entry point
7031 *****************************************************************************/
7033 static struct pci_driver iwl3945_driver
= {
7035 .id_table
= iwl3945_hw_card_ids
,
7036 .probe
= iwl3945_pci_probe
,
7037 .remove
= __devexit_p(iwl3945_pci_remove
),
7039 .suspend
= iwl3945_pci_suspend
,
7040 .resume
= iwl3945_pci_resume
,
7044 static int __init
iwl3945_init(void)
7048 printk(KERN_INFO DRV_NAME
": " DRV_DESCRIPTION
", " DRV_VERSION
"\n");
7049 printk(KERN_INFO DRV_NAME
": " DRV_COPYRIGHT
"\n");
7051 ret
= iwl3945_rate_control_register();
7053 printk(KERN_ERR DRV_NAME
7054 "Unable to register rate control algorithm: %d\n", ret
);
7058 ret
= pci_register_driver(&iwl3945_driver
);
7060 printk(KERN_ERR DRV_NAME
"Unable to initialize PCI module\n");
7061 goto error_register
;
7067 iwl3945_rate_control_unregister();
7071 static void __exit
iwl3945_exit(void)
7073 pci_unregister_driver(&iwl3945_driver
);
7074 iwl3945_rate_control_unregister();
7077 MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX
));
7079 module_param_named(antenna
, iwl3945_mod_params
.antenna
, int, 0444);
7080 MODULE_PARM_DESC(antenna
, "select antenna (1=Main, 2=Aux, default 0 [both])");
7081 module_param_named(disable
, iwl3945_mod_params
.disable
, int, 0444);
7082 MODULE_PARM_DESC(disable
, "manually disable the radio (default 0 [radio on])");
7083 module_param_named(swcrypto
, iwl3945_mod_params
.sw_crypto
, int, 0444);
7084 MODULE_PARM_DESC(swcrypto
,
7085 "using software crypto (default 1 [software])\n");
7086 module_param_named(debug
, iwl3945_mod_params
.debug
, uint
, 0444);
7087 MODULE_PARM_DESC(debug
, "debug output mask");
7088 module_param_named(disable_hw_scan
, iwl3945_mod_params
.disable_hw_scan
, int, 0444);
7089 MODULE_PARM_DESC(disable_hw_scan
, "disable hardware scanning (default 0)");
7091 module_param_named(queues_num
, iwl3945_mod_params
.num_of_queues
, int, 0444);
7092 MODULE_PARM_DESC(queues_num
, "number of hw queues.");
7094 module_exit(iwl3945_exit
);
7095 module_init(iwl3945_init
);