1 /******************************************************************************
3 * Copyright(c) 2003 - 2010 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/sched.h>
37 #include <linux/skbuff.h>
38 #include <linux/netdevice.h>
39 #include <linux/wireless.h>
40 #include <linux/firmware.h>
41 #include <linux/etherdevice.h>
42 #include <linux/if_arp.h>
44 #include <net/ieee80211_radiotap.h>
45 #include <net/mac80211.h>
47 #include <asm/div64.h>
49 #define DRV_NAME "iwl3945"
52 #include "iwl-3945-fh.h"
53 #include "iwl-commands.h"
56 #include "iwl-helpers.h"
59 #include "iwl-spectrum.h"
62 * module name, copyright, version, etc.
65 #define DRV_DESCRIPTION \
66 "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
68 #ifdef CONFIG_IWLWIFI_DEBUG
75 * add "s" to indicate spectrum measurement included.
76 * we add it here to be consistent with previous releases in which
77 * this was configurable.
79 #define DRV_VERSION IWLWIFI_VERSION VD "s"
80 #define DRV_COPYRIGHT "Copyright(c) 2003-2010 Intel Corporation"
81 #define DRV_AUTHOR "<ilw@linux.intel.com>"
83 MODULE_DESCRIPTION(DRV_DESCRIPTION
);
84 MODULE_VERSION(DRV_VERSION
);
85 MODULE_AUTHOR(DRV_COPYRIGHT
" " DRV_AUTHOR
);
86 MODULE_LICENSE("GPL");
88 /* module parameters */
89 struct iwl_mod_params iwl3945_mod_params
= {
92 /* the rest are 0 by default */
96 * iwl3945_get_antenna_flags - Get antenna flags for RXON command
97 * @priv: eeprom and antenna fields are used to determine antenna flags
99 * priv->eeprom39 is used to determine if antenna AUX/MAIN are reversed
100 * iwl3945_mod_params.antenna specifies the antenna diversity mode:
102 * IWL_ANTENNA_DIVERSITY - NIC selects best antenna by itself
103 * IWL_ANTENNA_MAIN - Force MAIN antenna
104 * IWL_ANTENNA_AUX - Force AUX antenna
106 __le32
iwl3945_get_antenna_flags(const struct iwl_priv
*priv
)
108 struct iwl3945_eeprom
*eeprom
= (struct iwl3945_eeprom
*)priv
->eeprom
;
110 switch (iwl3945_mod_params
.antenna
) {
111 case IWL_ANTENNA_DIVERSITY
:
114 case IWL_ANTENNA_MAIN
:
115 if (eeprom
->antenna_switch_type
)
116 return RXON_FLG_DIS_DIV_MSK
| RXON_FLG_ANT_B_MSK
;
117 return RXON_FLG_DIS_DIV_MSK
| RXON_FLG_ANT_A_MSK
;
119 case IWL_ANTENNA_AUX
:
120 if (eeprom
->antenna_switch_type
)
121 return RXON_FLG_DIS_DIV_MSK
| RXON_FLG_ANT_A_MSK
;
122 return RXON_FLG_DIS_DIV_MSK
| RXON_FLG_ANT_B_MSK
;
125 /* bad antenna selector value */
126 IWL_ERR(priv
, "Bad antenna selector value (0x%x)\n",
127 iwl3945_mod_params
.antenna
);
129 return 0; /* "diversity" is default if error */
132 static int iwl3945_set_ccmp_dynamic_key_info(struct iwl_priv
*priv
,
133 struct ieee80211_key_conf
*keyconf
,
137 __le16 key_flags
= 0;
140 key_flags
|= (STA_KEY_FLG_CCMP
| STA_KEY_FLG_MAP_KEY_MSK
);
141 key_flags
|= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
143 if (sta_id
== priv
->hw_params
.bcast_sta_id
)
144 key_flags
|= STA_KEY_MULTICAST_MSK
;
146 keyconf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
147 keyconf
->hw_key_idx
= keyconf
->keyidx
;
148 key_flags
&= ~STA_KEY_FLG_INVALID
;
150 spin_lock_irqsave(&priv
->sta_lock
, flags
);
151 priv
->stations
[sta_id
].keyinfo
.alg
= keyconf
->alg
;
152 priv
->stations
[sta_id
].keyinfo
.keylen
= keyconf
->keylen
;
153 memcpy(priv
->stations
[sta_id
].keyinfo
.key
, keyconf
->key
,
156 memcpy(priv
->stations
[sta_id
].sta
.key
.key
, keyconf
->key
,
159 if ((priv
->stations
[sta_id
].sta
.key
.key_flags
& STA_KEY_FLG_ENCRYPT_MSK
)
160 == STA_KEY_FLG_NO_ENC
)
161 priv
->stations
[sta_id
].sta
.key
.key_offset
=
162 iwl_get_free_ucode_key_index(priv
);
163 /* else, we are overriding an existing key => no need to allocated room
166 WARN(priv
->stations
[sta_id
].sta
.key
.key_offset
== WEP_INVALID_OFFSET
,
167 "no space for a new key");
169 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
170 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
171 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
173 IWL_DEBUG_INFO(priv
, "hwcrypto: modify ucode station key info\n");
175 ret
= iwl_send_add_sta(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
177 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
182 static int iwl3945_set_tkip_dynamic_key_info(struct iwl_priv
*priv
,
183 struct ieee80211_key_conf
*keyconf
,
189 static int iwl3945_set_wep_dynamic_key_info(struct iwl_priv
*priv
,
190 struct ieee80211_key_conf
*keyconf
,
196 static int iwl3945_clear_sta_key_info(struct iwl_priv
*priv
, u8 sta_id
)
200 spin_lock_irqsave(&priv
->sta_lock
, flags
);
201 memset(&priv
->stations
[sta_id
].keyinfo
, 0, sizeof(struct iwl_hw_key
));
202 memset(&priv
->stations
[sta_id
].sta
.key
, 0,
203 sizeof(struct iwl4965_keyinfo
));
204 priv
->stations
[sta_id
].sta
.key
.key_flags
= STA_KEY_FLG_NO_ENC
;
205 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
206 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
207 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
209 IWL_DEBUG_INFO(priv
, "hwcrypto: clear ucode station key info\n");
210 iwl_send_add_sta(priv
, &priv
->stations
[sta_id
].sta
, 0);
214 static int iwl3945_set_dynamic_key(struct iwl_priv
*priv
,
215 struct ieee80211_key_conf
*keyconf
, u8 sta_id
)
219 keyconf
->hw_key_idx
= HW_KEY_DYNAMIC
;
221 switch (keyconf
->alg
) {
223 ret
= iwl3945_set_ccmp_dynamic_key_info(priv
, keyconf
, sta_id
);
226 ret
= iwl3945_set_tkip_dynamic_key_info(priv
, keyconf
, sta_id
);
229 ret
= iwl3945_set_wep_dynamic_key_info(priv
, keyconf
, sta_id
);
232 IWL_ERR(priv
, "Unknown alg: %s alg = %d\n", __func__
, keyconf
->alg
);
236 IWL_DEBUG_WEP(priv
, "Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n",
237 keyconf
->alg
, keyconf
->keylen
, keyconf
->keyidx
,
243 static int iwl3945_remove_static_key(struct iwl_priv
*priv
)
245 int ret
= -EOPNOTSUPP
;
250 static int iwl3945_set_static_key(struct iwl_priv
*priv
,
251 struct ieee80211_key_conf
*key
)
253 if (key
->alg
== ALG_WEP
)
256 IWL_ERR(priv
, "Static key invalid: alg %d\n", key
->alg
);
260 static void iwl3945_clear_free_frames(struct iwl_priv
*priv
)
262 struct list_head
*element
;
264 IWL_DEBUG_INFO(priv
, "%d frames on pre-allocated heap on clear.\n",
267 while (!list_empty(&priv
->free_frames
)) {
268 element
= priv
->free_frames
.next
;
270 kfree(list_entry(element
, struct iwl3945_frame
, list
));
271 priv
->frames_count
--;
274 if (priv
->frames_count
) {
275 IWL_WARN(priv
, "%d frames still in use. Did we lose one?\n",
277 priv
->frames_count
= 0;
281 static struct iwl3945_frame
*iwl3945_get_free_frame(struct iwl_priv
*priv
)
283 struct iwl3945_frame
*frame
;
284 struct list_head
*element
;
285 if (list_empty(&priv
->free_frames
)) {
286 frame
= kzalloc(sizeof(*frame
), GFP_KERNEL
);
288 IWL_ERR(priv
, "Could not allocate frame!\n");
292 priv
->frames_count
++;
296 element
= priv
->free_frames
.next
;
298 return list_entry(element
, struct iwl3945_frame
, list
);
301 static void iwl3945_free_frame(struct iwl_priv
*priv
, struct iwl3945_frame
*frame
)
303 memset(frame
, 0, sizeof(*frame
));
304 list_add(&frame
->list
, &priv
->free_frames
);
307 unsigned int iwl3945_fill_beacon_frame(struct iwl_priv
*priv
,
308 struct ieee80211_hdr
*hdr
,
312 if (!iwl_is_associated(priv
) || !priv
->ibss_beacon
||
313 ((priv
->iw_mode
!= NL80211_IFTYPE_ADHOC
) &&
314 (priv
->iw_mode
!= NL80211_IFTYPE_AP
)))
317 if (priv
->ibss_beacon
->len
> left
)
320 memcpy(hdr
, priv
->ibss_beacon
->data
, priv
->ibss_beacon
->len
);
322 return priv
->ibss_beacon
->len
;
325 static int iwl3945_send_beacon_cmd(struct iwl_priv
*priv
)
327 struct iwl3945_frame
*frame
;
328 unsigned int frame_size
;
332 frame
= iwl3945_get_free_frame(priv
);
335 IWL_ERR(priv
, "Could not obtain free frame buffer for beacon "
340 rate
= iwl_rate_get_lowest_plcp(priv
);
342 frame_size
= iwl3945_hw_get_beacon_cmd(priv
, frame
, rate
);
344 rc
= iwl_send_cmd_pdu(priv
, REPLY_TX_BEACON
, frame_size
,
347 iwl3945_free_frame(priv
, frame
);
352 static void iwl3945_unset_hw_params(struct iwl_priv
*priv
)
354 if (priv
->shared_virt
)
355 pci_free_consistent(priv
->pci_dev
,
356 sizeof(struct iwl3945_shared
),
361 static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv
*priv
,
362 struct ieee80211_tx_info
*info
,
363 struct iwl_device_cmd
*cmd
,
364 struct sk_buff
*skb_frag
,
367 struct iwl3945_tx_cmd
*tx_cmd
= (struct iwl3945_tx_cmd
*)cmd
->cmd
.payload
;
368 struct iwl_hw_key
*keyinfo
= &priv
->stations
[sta_id
].keyinfo
;
370 switch (keyinfo
->alg
) {
372 tx_cmd
->sec_ctl
= TX_CMD_SEC_CCM
;
373 memcpy(tx_cmd
->key
, keyinfo
->key
, keyinfo
->keylen
);
374 IWL_DEBUG_TX(priv
, "tx_cmd with AES hwcrypto\n");
381 tx_cmd
->sec_ctl
= TX_CMD_SEC_WEP
|
382 (info
->control
.hw_key
->hw_key_idx
& TX_CMD_SEC_MSK
) << TX_CMD_SEC_SHIFT
;
384 if (keyinfo
->keylen
== 13)
385 tx_cmd
->sec_ctl
|= TX_CMD_SEC_KEY128
;
387 memcpy(&tx_cmd
->key
[3], keyinfo
->key
, keyinfo
->keylen
);
389 IWL_DEBUG_TX(priv
, "Configuring packet for WEP encryption "
390 "with key %d\n", info
->control
.hw_key
->hw_key_idx
);
394 IWL_ERR(priv
, "Unknown encode alg %d\n", keyinfo
->alg
);
400 * handle build REPLY_TX command notification.
402 static void iwl3945_build_tx_cmd_basic(struct iwl_priv
*priv
,
403 struct iwl_device_cmd
*cmd
,
404 struct ieee80211_tx_info
*info
,
405 struct ieee80211_hdr
*hdr
, u8 std_id
)
407 struct iwl3945_tx_cmd
*tx_cmd
= (struct iwl3945_tx_cmd
*)cmd
->cmd
.payload
;
408 __le32 tx_flags
= tx_cmd
->tx_flags
;
409 __le16 fc
= hdr
->frame_control
;
411 tx_cmd
->stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
412 if (!(info
->flags
& IEEE80211_TX_CTL_NO_ACK
)) {
413 tx_flags
|= TX_CMD_FLG_ACK_MSK
;
414 if (ieee80211_is_mgmt(fc
))
415 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
416 if (ieee80211_is_probe_resp(fc
) &&
417 !(le16_to_cpu(hdr
->seq_ctrl
) & 0xf))
418 tx_flags
|= TX_CMD_FLG_TSF_MSK
;
420 tx_flags
&= (~TX_CMD_FLG_ACK_MSK
);
421 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
424 tx_cmd
->sta_id
= std_id
;
425 if (ieee80211_has_morefrags(fc
))
426 tx_flags
|= TX_CMD_FLG_MORE_FRAG_MSK
;
428 if (ieee80211_is_data_qos(fc
)) {
429 u8
*qc
= ieee80211_get_qos_ctl(hdr
);
430 tx_cmd
->tid_tspec
= qc
[0] & 0xf;
431 tx_flags
&= ~TX_CMD_FLG_SEQ_CTL_MSK
;
433 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
436 priv
->cfg
->ops
->utils
->rts_tx_cmd_flag(info
, &tx_flags
);
438 if ((tx_flags
& TX_CMD_FLG_RTS_MSK
) || (tx_flags
& TX_CMD_FLG_CTS_MSK
))
439 tx_flags
|= TX_CMD_FLG_FULL_TXOP_PROT_MSK
;
441 tx_flags
&= ~(TX_CMD_FLG_ANT_SEL_MSK
);
442 if (ieee80211_is_mgmt(fc
)) {
443 if (ieee80211_is_assoc_req(fc
) || ieee80211_is_reassoc_req(fc
))
444 tx_cmd
->timeout
.pm_frame_timeout
= cpu_to_le16(3);
446 tx_cmd
->timeout
.pm_frame_timeout
= cpu_to_le16(2);
448 tx_cmd
->timeout
.pm_frame_timeout
= 0;
451 tx_cmd
->driver_txop
= 0;
452 tx_cmd
->tx_flags
= tx_flags
;
453 tx_cmd
->next_frame_len
= 0;
457 * start REPLY_TX command process
459 static int iwl3945_tx_skb(struct iwl_priv
*priv
, struct sk_buff
*skb
)
461 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
462 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
463 struct iwl3945_tx_cmd
*tx_cmd
;
464 struct iwl_tx_queue
*txq
= NULL
;
465 struct iwl_queue
*q
= NULL
;
466 struct iwl_device_cmd
*out_cmd
;
467 struct iwl_cmd_meta
*out_meta
;
468 dma_addr_t phys_addr
;
469 dma_addr_t txcmd_phys
;
470 int txq_id
= skb_get_queue_mapping(skb
);
471 u16 len
, idx
, len_org
, hdr_len
; /* TODO: len_org is not used */
478 u8 wait_write_ptr
= 0;
483 spin_lock_irqsave(&priv
->lock
, flags
);
484 if (iwl_is_rfkill(priv
)) {
485 IWL_DEBUG_DROP(priv
, "Dropping - RF KILL\n");
489 if ((ieee80211_get_tx_rate(priv
->hw
, info
)->hw_value
& 0xFF) == IWL_INVALID_RATE
) {
490 IWL_ERR(priv
, "ERROR: No TX rate available.\n");
494 unicast
= !is_multicast_ether_addr(hdr
->addr1
);
497 fc
= hdr
->frame_control
;
499 #ifdef CONFIG_IWLWIFI_DEBUG
500 if (ieee80211_is_auth(fc
))
501 IWL_DEBUG_TX(priv
, "Sending AUTH frame\n");
502 else if (ieee80211_is_assoc_req(fc
))
503 IWL_DEBUG_TX(priv
, "Sending ASSOC frame\n");
504 else if (ieee80211_is_reassoc_req(fc
))
505 IWL_DEBUG_TX(priv
, "Sending REASSOC frame\n");
508 /* drop all non-injected data frame if we are not associated */
509 if (ieee80211_is_data(fc
) &&
510 !(info
->flags
& IEEE80211_TX_CTL_INJECTED
) &&
511 (!iwl_is_associated(priv
) ||
512 ((priv
->iw_mode
== NL80211_IFTYPE_STATION
) && !priv
->assoc_id
))) {
513 IWL_DEBUG_DROP(priv
, "Dropping - !iwl_is_associated\n");
517 spin_unlock_irqrestore(&priv
->lock
, flags
);
519 hdr_len
= ieee80211_hdrlen(fc
);
521 /* Find (or create) index into station table for destination station */
522 if (info
->flags
& IEEE80211_TX_CTL_INJECTED
)
523 sta_id
= priv
->hw_params
.bcast_sta_id
;
525 sta_id
= iwl_get_sta_id(priv
, hdr
);
526 if (sta_id
== IWL_INVALID_STATION
) {
527 IWL_DEBUG_DROP(priv
, "Dropping - INVALID STATION: %pM\n",
532 IWL_DEBUG_RATE(priv
, "station Id %d\n", sta_id
);
534 if (ieee80211_is_data_qos(fc
)) {
535 qc
= ieee80211_get_qos_ctl(hdr
);
536 tid
= qc
[0] & IEEE80211_QOS_CTL_TID_MASK
;
537 if (unlikely(tid
>= MAX_TID_COUNT
))
539 seq_number
= priv
->stations
[sta_id
].tid
[tid
].seq_number
&
541 hdr
->seq_ctrl
= cpu_to_le16(seq_number
) |
543 cpu_to_le16(IEEE80211_SCTL_FRAG
));
547 /* Descriptor for chosen Tx queue */
548 txq
= &priv
->txq
[txq_id
];
551 if ((iwl_queue_space(q
) < q
->high_mark
))
554 spin_lock_irqsave(&priv
->lock
, flags
);
556 idx
= get_cmd_index(q
, q
->write_ptr
, 0);
558 /* Set up driver data for this TFD */
559 memset(&(txq
->txb
[q
->write_ptr
]), 0, sizeof(struct iwl_tx_info
));
560 txq
->txb
[q
->write_ptr
].skb
[0] = skb
;
562 /* Init first empty entry in queue's array of Tx/cmd buffers */
563 out_cmd
= txq
->cmd
[idx
];
564 out_meta
= &txq
->meta
[idx
];
565 tx_cmd
= (struct iwl3945_tx_cmd
*)out_cmd
->cmd
.payload
;
566 memset(&out_cmd
->hdr
, 0, sizeof(out_cmd
->hdr
));
567 memset(tx_cmd
, 0, sizeof(*tx_cmd
));
570 * Set up the Tx-command (not MAC!) header.
571 * Store the chosen Tx queue and TFD index within the sequence field;
572 * after Tx, uCode's Tx response will return this value so driver can
573 * locate the frame within the tx queue and do post-tx processing.
575 out_cmd
->hdr
.cmd
= REPLY_TX
;
576 out_cmd
->hdr
.sequence
= cpu_to_le16((u16
)(QUEUE_TO_SEQ(txq_id
) |
577 INDEX_TO_SEQ(q
->write_ptr
)));
579 /* Copy MAC header from skb into command buffer */
580 memcpy(tx_cmd
->hdr
, hdr
, hdr_len
);
583 if (info
->control
.hw_key
)
584 iwl3945_build_tx_cmd_hwcrypto(priv
, info
, out_cmd
, skb
, sta_id
);
586 /* TODO need this for burst mode later on */
587 iwl3945_build_tx_cmd_basic(priv
, out_cmd
, info
, hdr
, sta_id
);
589 /* set is_hcca to 0; it probably will never be implemented */
590 iwl3945_hw_build_tx_cmd_rate(priv
, out_cmd
, info
, hdr
, sta_id
, 0);
592 /* Total # bytes to be transmitted */
594 tx_cmd
->len
= cpu_to_le16(len
);
596 iwl_dbg_log_tx_data_frame(priv
, len
, hdr
);
597 iwl_update_stats(priv
, true, fc
, len
);
598 tx_cmd
->tx_flags
&= ~TX_CMD_FLG_ANT_A_MSK
;
599 tx_cmd
->tx_flags
&= ~TX_CMD_FLG_ANT_B_MSK
;
601 if (!ieee80211_has_morefrags(hdr
->frame_control
)) {
602 txq
->need_update
= 1;
604 priv
->stations
[sta_id
].tid
[tid
].seq_number
= seq_number
;
607 txq
->need_update
= 0;
610 IWL_DEBUG_TX(priv
, "sequence nr = 0X%x \n",
611 le16_to_cpu(out_cmd
->hdr
.sequence
));
612 IWL_DEBUG_TX(priv
, "tx_flags = 0X%x \n", le32_to_cpu(tx_cmd
->tx_flags
));
613 iwl_print_hex_dump(priv
, IWL_DL_TX
, tx_cmd
, sizeof(*tx_cmd
));
614 iwl_print_hex_dump(priv
, IWL_DL_TX
, (u8
*)tx_cmd
->hdr
,
615 ieee80211_hdrlen(fc
));
618 * Use the first empty entry in this queue's command buffer array
619 * to contain the Tx command and MAC header concatenated together
620 * (payload data will be in another buffer).
621 * Size of this varies, due to varying MAC header length.
622 * If end is not dword aligned, we'll have 2 extra bytes at the end
623 * of the MAC header (device reads on dword boundaries).
624 * We'll tell device about this padding later.
626 len
= sizeof(struct iwl3945_tx_cmd
) +
627 sizeof(struct iwl_cmd_header
) + hdr_len
;
630 len
= (len
+ 3) & ~3;
637 /* Physical address of this Tx command's header (not MAC header!),
638 * within command buffer array. */
639 txcmd_phys
= pci_map_single(priv
->pci_dev
, &out_cmd
->hdr
,
640 len
, PCI_DMA_TODEVICE
);
641 /* we do not map meta data ... so we can safely access address to
642 * provide to unmap command*/
643 pci_unmap_addr_set(out_meta
, mapping
, txcmd_phys
);
644 pci_unmap_len_set(out_meta
, len
, len
);
646 /* Add buffer containing Tx command and MAC(!) header to TFD's
648 priv
->cfg
->ops
->lib
->txq_attach_buf_to_tfd(priv
, txq
,
649 txcmd_phys
, len
, 1, 0);
652 /* Set up TFD's 2nd entry to point directly to remainder of skb,
653 * if any (802.11 null frames have no payload). */
654 len
= skb
->len
- hdr_len
;
656 phys_addr
= pci_map_single(priv
->pci_dev
, skb
->data
+ hdr_len
,
657 len
, PCI_DMA_TODEVICE
);
658 priv
->cfg
->ops
->lib
->txq_attach_buf_to_tfd(priv
, txq
,
664 /* Tell device the write index *just past* this latest filled TFD */
665 q
->write_ptr
= iwl_queue_inc_wrap(q
->write_ptr
, q
->n_bd
);
666 rc
= iwl_txq_update_write_ptr(priv
, txq
);
667 spin_unlock_irqrestore(&priv
->lock
, flags
);
672 if ((iwl_queue_space(q
) < q
->high_mark
)
673 && priv
->mac80211_registered
) {
674 if (wait_write_ptr
) {
675 spin_lock_irqsave(&priv
->lock
, flags
);
676 txq
->need_update
= 1;
677 iwl_txq_update_write_ptr(priv
, txq
);
678 spin_unlock_irqrestore(&priv
->lock
, flags
);
681 iwl_stop_queue(priv
, skb_get_queue_mapping(skb
));
687 spin_unlock_irqrestore(&priv
->lock
, flags
);
692 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
693 #define BEACON_TIME_MASK_HIGH 0xFF000000
694 #define TIME_UNIT 1024
697 * extended beacon time format
698 * time in usec will be changed into a 32-bit value in 8:24 format
699 * the high 1 byte is the beacon counts
700 * the lower 3 bytes is the time in usec within one beacon interval
703 static u32
iwl3945_usecs_to_beacons(u32 usec
, u32 beacon_interval
)
707 u32 interval
= beacon_interval
* 1024;
709 if (!interval
|| !usec
)
712 quot
= (usec
/ interval
) & (BEACON_TIME_MASK_HIGH
>> 24);
713 rem
= (usec
% interval
) & BEACON_TIME_MASK_LOW
;
715 return (quot
<< 24) + rem
;
718 /* base is usually what we get from ucode with each received frame,
719 * the same as HW timer counter counting down
722 static __le32
iwl3945_add_beacon_time(u32 base
, u32 addon
, u32 beacon_interval
)
724 u32 base_low
= base
& BEACON_TIME_MASK_LOW
;
725 u32 addon_low
= addon
& BEACON_TIME_MASK_LOW
;
726 u32 interval
= beacon_interval
* TIME_UNIT
;
727 u32 res
= (base
& BEACON_TIME_MASK_HIGH
) +
728 (addon
& BEACON_TIME_MASK_HIGH
);
730 if (base_low
> addon_low
)
731 res
+= base_low
- addon_low
;
732 else if (base_low
< addon_low
) {
733 res
+= interval
+ base_low
- addon_low
;
738 return cpu_to_le32(res
);
741 static int iwl3945_get_measurement(struct iwl_priv
*priv
,
742 struct ieee80211_measurement_params
*params
,
745 struct iwl_spectrum_cmd spectrum
;
746 struct iwl_rx_packet
*pkt
;
747 struct iwl_host_cmd cmd
= {
748 .id
= REPLY_SPECTRUM_MEASUREMENT_CMD
,
749 .data
= (void *)&spectrum
,
750 .flags
= CMD_WANT_SKB
,
752 u32 add_time
= le64_to_cpu(params
->start_time
);
754 int spectrum_resp_status
;
755 int duration
= le16_to_cpu(params
->duration
);
757 if (iwl_is_associated(priv
))
759 iwl3945_usecs_to_beacons(
760 le64_to_cpu(params
->start_time
) - priv
->last_tsf
,
761 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
763 memset(&spectrum
, 0, sizeof(spectrum
));
765 spectrum
.channel_count
= cpu_to_le16(1);
767 RXON_FLG_TSF2HOST_MSK
| RXON_FLG_ANT_A_MSK
| RXON_FLG_DIS_DIV_MSK
;
768 spectrum
.filter_flags
= MEASUREMENT_FILTER_FLAG
;
769 cmd
.len
= sizeof(spectrum
);
770 spectrum
.len
= cpu_to_le16(cmd
.len
- sizeof(spectrum
.len
));
772 if (iwl_is_associated(priv
))
773 spectrum
.start_time
=
774 iwl3945_add_beacon_time(priv
->last_beacon_time
,
776 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
778 spectrum
.start_time
= 0;
780 spectrum
.channels
[0].duration
= cpu_to_le32(duration
* TIME_UNIT
);
781 spectrum
.channels
[0].channel
= params
->channel
;
782 spectrum
.channels
[0].type
= type
;
783 if (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
784 spectrum
.flags
|= RXON_FLG_BAND_24G_MSK
|
785 RXON_FLG_AUTO_DETECT_MSK
| RXON_FLG_TGG_PROTECT_MSK
;
787 rc
= iwl_send_cmd_sync(priv
, &cmd
);
791 pkt
= (struct iwl_rx_packet
*)cmd
.reply_page
;
792 if (pkt
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
793 IWL_ERR(priv
, "Bad return from REPLY_RX_ON_ASSOC command\n");
797 spectrum_resp_status
= le16_to_cpu(pkt
->u
.spectrum
.status
);
798 switch (spectrum_resp_status
) {
799 case 0: /* Command will be handled */
800 if (pkt
->u
.spectrum
.id
!= 0xff) {
801 IWL_DEBUG_INFO(priv
, "Replaced existing measurement: %d\n",
803 priv
->measurement_status
&= ~MEASUREMENT_READY
;
805 priv
->measurement_status
|= MEASUREMENT_ACTIVE
;
809 case 1: /* Command will not be handled */
814 iwl_free_pages(priv
, cmd
.reply_page
);
819 static void iwl3945_rx_reply_alive(struct iwl_priv
*priv
,
820 struct iwl_rx_mem_buffer
*rxb
)
822 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
823 struct iwl_alive_resp
*palive
;
824 struct delayed_work
*pwork
;
826 palive
= &pkt
->u
.alive_frame
;
828 IWL_DEBUG_INFO(priv
, "Alive ucode status 0x%08X revision "
830 palive
->is_valid
, palive
->ver_type
,
831 palive
->ver_subtype
);
833 if (palive
->ver_subtype
== INITIALIZE_SUBTYPE
) {
834 IWL_DEBUG_INFO(priv
, "Initialization Alive received.\n");
835 memcpy(&priv
->card_alive_init
, &pkt
->u
.alive_frame
,
836 sizeof(struct iwl_alive_resp
));
837 pwork
= &priv
->init_alive_start
;
839 IWL_DEBUG_INFO(priv
, "Runtime Alive received.\n");
840 memcpy(&priv
->card_alive
, &pkt
->u
.alive_frame
,
841 sizeof(struct iwl_alive_resp
));
842 pwork
= &priv
->alive_start
;
843 iwl3945_disable_events(priv
);
846 /* We delay the ALIVE response by 5ms to
847 * give the HW RF Kill time to activate... */
848 if (palive
->is_valid
== UCODE_VALID_OK
)
849 queue_delayed_work(priv
->workqueue
, pwork
,
850 msecs_to_jiffies(5));
852 IWL_WARN(priv
, "uCode did not respond OK.\n");
855 static void iwl3945_rx_reply_add_sta(struct iwl_priv
*priv
,
856 struct iwl_rx_mem_buffer
*rxb
)
858 #ifdef CONFIG_IWLWIFI_DEBUG
859 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
862 IWL_DEBUG_RX(priv
, "Received REPLY_ADD_STA: 0x%02X\n", pkt
->u
.status
);
866 static void iwl3945_bg_beacon_update(struct work_struct
*work
)
868 struct iwl_priv
*priv
=
869 container_of(work
, struct iwl_priv
, beacon_update
);
870 struct sk_buff
*beacon
;
872 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
873 beacon
= ieee80211_beacon_get(priv
->hw
, priv
->vif
);
876 IWL_ERR(priv
, "update beacon failed\n");
880 mutex_lock(&priv
->mutex
);
881 /* new beacon skb is allocated every time; dispose previous.*/
882 if (priv
->ibss_beacon
)
883 dev_kfree_skb(priv
->ibss_beacon
);
885 priv
->ibss_beacon
= beacon
;
886 mutex_unlock(&priv
->mutex
);
888 iwl3945_send_beacon_cmd(priv
);
891 static void iwl3945_rx_beacon_notif(struct iwl_priv
*priv
,
892 struct iwl_rx_mem_buffer
*rxb
)
894 #ifdef CONFIG_IWLWIFI_DEBUG
895 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
896 struct iwl3945_beacon_notif
*beacon
= &(pkt
->u
.beacon_status
);
897 u8 rate
= beacon
->beacon_notify_hdr
.rate
;
899 IWL_DEBUG_RX(priv
, "beacon status %x retries %d iss %d "
900 "tsf %d %d rate %d\n",
901 le32_to_cpu(beacon
->beacon_notify_hdr
.status
) & TX_STATUS_MSK
,
902 beacon
->beacon_notify_hdr
.failure_frame
,
903 le32_to_cpu(beacon
->ibss_mgr_status
),
904 le32_to_cpu(beacon
->high_tsf
),
905 le32_to_cpu(beacon
->low_tsf
), rate
);
908 if ((priv
->iw_mode
== NL80211_IFTYPE_AP
) &&
909 (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)))
910 queue_work(priv
->workqueue
, &priv
->beacon_update
);
913 /* Handle notification from uCode that card's power state is changing
914 * due to software, hardware, or critical temperature RFKILL */
915 static void iwl3945_rx_card_state_notif(struct iwl_priv
*priv
,
916 struct iwl_rx_mem_buffer
*rxb
)
918 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
919 u32 flags
= le32_to_cpu(pkt
->u
.card_state_notif
.flags
);
920 unsigned long status
= priv
->status
;
922 IWL_WARN(priv
, "Card state received: HW:%s SW:%s\n",
923 (flags
& HW_CARD_DISABLED
) ? "Kill" : "On",
924 (flags
& SW_CARD_DISABLED
) ? "Kill" : "On");
926 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
927 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
929 if (flags
& HW_CARD_DISABLED
)
930 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
932 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
935 iwl_scan_cancel(priv
);
937 if ((test_bit(STATUS_RF_KILL_HW
, &status
) !=
938 test_bit(STATUS_RF_KILL_HW
, &priv
->status
)))
939 wiphy_rfkill_set_hw_state(priv
->hw
->wiphy
,
940 test_bit(STATUS_RF_KILL_HW
, &priv
->status
));
942 wake_up_interruptible(&priv
->wait_command_queue
);
946 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
948 * Setup the RX handlers for each of the reply types sent from the uCode
951 * This function chains into the hardware specific files for them to setup
952 * any hardware specific handlers as well.
954 static void iwl3945_setup_rx_handlers(struct iwl_priv
*priv
)
956 priv
->rx_handlers
[REPLY_ALIVE
] = iwl3945_rx_reply_alive
;
957 priv
->rx_handlers
[REPLY_ADD_STA
] = iwl3945_rx_reply_add_sta
;
958 priv
->rx_handlers
[REPLY_ERROR
] = iwl_rx_reply_error
;
959 priv
->rx_handlers
[CHANNEL_SWITCH_NOTIFICATION
] = iwl_rx_csa
;
960 priv
->rx_handlers
[SPECTRUM_MEASURE_NOTIFICATION
] =
961 iwl_rx_spectrum_measure_notif
;
962 priv
->rx_handlers
[PM_SLEEP_NOTIFICATION
] = iwl_rx_pm_sleep_notif
;
963 priv
->rx_handlers
[PM_DEBUG_STATISTIC_NOTIFIC
] =
964 iwl_rx_pm_debug_statistics_notif
;
965 priv
->rx_handlers
[BEACON_NOTIFICATION
] = iwl3945_rx_beacon_notif
;
968 * The same handler is used for both the REPLY to a discrete
969 * statistics request from the host as well as for the periodic
970 * statistics notifications (after received beacons) from the uCode.
972 priv
->rx_handlers
[REPLY_STATISTICS_CMD
] = iwl3945_hw_rx_statistics
;
973 priv
->rx_handlers
[STATISTICS_NOTIFICATION
] = iwl3945_hw_rx_statistics
;
975 iwl_setup_rx_scan_handlers(priv
);
976 priv
->rx_handlers
[CARD_STATE_NOTIFICATION
] = iwl3945_rx_card_state_notif
;
978 /* Set up hardware specific Rx handlers */
979 iwl3945_hw_rx_handler_setup(priv
);
982 /************************** RX-FUNCTIONS ****************************/
984 * Rx theory of operation
986 * The host allocates 32 DMA target addresses and passes the host address
987 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
991 * The host/firmware share two index registers for managing the Rx buffers.
993 * The READ index maps to the first position that the firmware may be writing
994 * to -- the driver can read up to (but not including) this position and get
996 * The READ index is managed by the firmware once the card is enabled.
998 * The WRITE index maps to the last position the driver has read from -- the
999 * position preceding WRITE is the last slot the firmware can place a packet.
1001 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
1004 * During initialization, the host sets up the READ queue position to the first
1005 * INDEX position, and WRITE to the last (READ - 1 wrapped)
1007 * When the firmware places a packet in a buffer, it will advance the READ index
1008 * and fire the RX interrupt. The driver can then query the READ index and
1009 * process as many packets as possible, moving the WRITE index forward as it
1010 * resets the Rx queue buffers with new memory.
1012 * The management in the driver is as follows:
1013 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
1014 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
1015 * to replenish the iwl->rxq->rx_free.
1016 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
1017 * iwl->rxq is replenished and the READ INDEX is updated (updating the
1018 * 'processed' and 'read' driver indexes as well)
1019 * + A received packet is processed and handed to the kernel network stack,
1020 * detached from the iwl->rxq. The driver 'processed' index is updated.
1021 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
1022 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
1023 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
1024 * were enough free buffers and RX_STALLED is set it is cleared.
1029 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
1030 * iwl3945_rx_queue_restock
1031 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
1032 * queue, updates firmware pointers, and updates
1033 * the WRITE index. If insufficient rx_free buffers
1034 * are available, schedules iwl3945_rx_replenish
1036 * -- enable interrupts --
1037 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
1038 * READ INDEX, detaching the SKB from the pool.
1039 * Moves the packet buffer from queue to rx_used.
1040 * Calls iwl3945_rx_queue_restock to refill any empty
1047 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
1049 static inline __le32
iwl3945_dma_addr2rbd_ptr(struct iwl_priv
*priv
,
1050 dma_addr_t dma_addr
)
1052 return cpu_to_le32((u32
)dma_addr
);
1056 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
1058 * If there are slots in the RX queue that need to be restocked,
1059 * and we have free pre-allocated buffers, fill the ranks as much
1060 * as we can, pulling from rx_free.
1062 * This moves the 'write' index forward to catch up with 'processed', and
1063 * also updates the memory address in the firmware to reference the new
1066 static int iwl3945_rx_queue_restock(struct iwl_priv
*priv
)
1068 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
1069 struct list_head
*element
;
1070 struct iwl_rx_mem_buffer
*rxb
;
1071 unsigned long flags
;
1074 spin_lock_irqsave(&rxq
->lock
, flags
);
1075 write
= rxq
->write
& ~0x7;
1076 while ((iwl_rx_queue_space(rxq
) > 0) && (rxq
->free_count
)) {
1077 /* Get next free Rx buffer, remove from free list */
1078 element
= rxq
->rx_free
.next
;
1079 rxb
= list_entry(element
, struct iwl_rx_mem_buffer
, list
);
1082 /* Point to Rx buffer via next RBD in circular buffer */
1083 rxq
->bd
[rxq
->write
] = iwl3945_dma_addr2rbd_ptr(priv
, rxb
->page_dma
);
1084 rxq
->queue
[rxq
->write
] = rxb
;
1085 rxq
->write
= (rxq
->write
+ 1) & RX_QUEUE_MASK
;
1088 spin_unlock_irqrestore(&rxq
->lock
, flags
);
1089 /* If the pre-allocated buffer pool is dropping low, schedule to
1091 if (rxq
->free_count
<= RX_LOW_WATERMARK
)
1092 queue_work(priv
->workqueue
, &priv
->rx_replenish
);
1095 /* If we've added more space for the firmware to place data, tell it.
1096 * Increment device's write pointer in multiples of 8. */
1097 if ((rxq
->write_actual
!= (rxq
->write
& ~0x7))
1098 || (abs(rxq
->write
- rxq
->read
) > 7)) {
1099 spin_lock_irqsave(&rxq
->lock
, flags
);
1100 rxq
->need_update
= 1;
1101 spin_unlock_irqrestore(&rxq
->lock
, flags
);
1102 rc
= iwl_rx_queue_update_write_ptr(priv
, rxq
);
1111 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
1113 * When moving to rx_free an SKB is allocated for the slot.
1115 * Also restock the Rx queue via iwl3945_rx_queue_restock.
1116 * This is called as a scheduled work item (except for during initialization)
1118 static void iwl3945_rx_allocate(struct iwl_priv
*priv
, gfp_t priority
)
1120 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
1121 struct list_head
*element
;
1122 struct iwl_rx_mem_buffer
*rxb
;
1124 unsigned long flags
;
1125 gfp_t gfp_mask
= priority
;
1128 spin_lock_irqsave(&rxq
->lock
, flags
);
1130 if (list_empty(&rxq
->rx_used
)) {
1131 spin_unlock_irqrestore(&rxq
->lock
, flags
);
1134 spin_unlock_irqrestore(&rxq
->lock
, flags
);
1136 if (rxq
->free_count
> RX_LOW_WATERMARK
)
1137 gfp_mask
|= __GFP_NOWARN
;
1139 if (priv
->hw_params
.rx_page_order
> 0)
1140 gfp_mask
|= __GFP_COMP
;
1142 /* Alloc a new receive buffer */
1143 page
= alloc_pages(gfp_mask
, priv
->hw_params
.rx_page_order
);
1145 if (net_ratelimit())
1146 IWL_DEBUG_INFO(priv
, "Failed to allocate SKB buffer.\n");
1147 if ((rxq
->free_count
<= RX_LOW_WATERMARK
) &&
1149 IWL_CRIT(priv
, "Failed to allocate SKB buffer with %s. Only %u free buffers remaining.\n",
1150 priority
== GFP_ATOMIC
? "GFP_ATOMIC" : "GFP_KERNEL",
1152 /* We don't reschedule replenish work here -- we will
1153 * call the restock method and if it still needs
1154 * more buffers it will schedule replenish */
1158 spin_lock_irqsave(&rxq
->lock
, flags
);
1159 if (list_empty(&rxq
->rx_used
)) {
1160 spin_unlock_irqrestore(&rxq
->lock
, flags
);
1161 __free_pages(page
, priv
->hw_params
.rx_page_order
);
1164 element
= rxq
->rx_used
.next
;
1165 rxb
= list_entry(element
, struct iwl_rx_mem_buffer
, list
);
1167 spin_unlock_irqrestore(&rxq
->lock
, flags
);
1170 /* Get physical address of RB/SKB */
1171 rxb
->page_dma
= pci_map_page(priv
->pci_dev
, page
, 0,
1172 PAGE_SIZE
<< priv
->hw_params
.rx_page_order
,
1173 PCI_DMA_FROMDEVICE
);
1175 spin_lock_irqsave(&rxq
->lock
, flags
);
1177 list_add_tail(&rxb
->list
, &rxq
->rx_free
);
1179 priv
->alloc_rxb_page
++;
1181 spin_unlock_irqrestore(&rxq
->lock
, flags
);
1185 void iwl3945_rx_queue_reset(struct iwl_priv
*priv
, struct iwl_rx_queue
*rxq
)
1187 unsigned long flags
;
1189 spin_lock_irqsave(&rxq
->lock
, flags
);
1190 INIT_LIST_HEAD(&rxq
->rx_free
);
1191 INIT_LIST_HEAD(&rxq
->rx_used
);
1192 /* Fill the rx_used queue with _all_ of the Rx buffers */
1193 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++) {
1194 /* In the reset function, these buffers may have been allocated
1195 * to an SKB, so we need to unmap and free potential storage */
1196 if (rxq
->pool
[i
].page
!= NULL
) {
1197 pci_unmap_page(priv
->pci_dev
, rxq
->pool
[i
].page_dma
,
1198 PAGE_SIZE
<< priv
->hw_params
.rx_page_order
,
1199 PCI_DMA_FROMDEVICE
);
1200 __iwl_free_pages(priv
, rxq
->pool
[i
].page
);
1201 rxq
->pool
[i
].page
= NULL
;
1203 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
1206 /* Set us so that we have processed and used all buffers, but have
1207 * not restocked the Rx queue with fresh buffers */
1208 rxq
->read
= rxq
->write
= 0;
1209 rxq
->write_actual
= 0;
1210 rxq
->free_count
= 0;
1211 spin_unlock_irqrestore(&rxq
->lock
, flags
);
1214 void iwl3945_rx_replenish(void *data
)
1216 struct iwl_priv
*priv
= data
;
1217 unsigned long flags
;
1219 iwl3945_rx_allocate(priv
, GFP_KERNEL
);
1221 spin_lock_irqsave(&priv
->lock
, flags
);
1222 iwl3945_rx_queue_restock(priv
);
1223 spin_unlock_irqrestore(&priv
->lock
, flags
);
1226 static void iwl3945_rx_replenish_now(struct iwl_priv
*priv
)
1228 iwl3945_rx_allocate(priv
, GFP_ATOMIC
);
1230 iwl3945_rx_queue_restock(priv
);
1234 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
1235 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
1236 * This free routine walks the list of POOL entries and if SKB is set to
1237 * non NULL it is unmapped and freed
1239 static void iwl3945_rx_queue_free(struct iwl_priv
*priv
, struct iwl_rx_queue
*rxq
)
1242 for (i
= 0; i
< RX_QUEUE_SIZE
+ RX_FREE_BUFFERS
; i
++) {
1243 if (rxq
->pool
[i
].page
!= NULL
) {
1244 pci_unmap_page(priv
->pci_dev
, rxq
->pool
[i
].page_dma
,
1245 PAGE_SIZE
<< priv
->hw_params
.rx_page_order
,
1246 PCI_DMA_FROMDEVICE
);
1247 __iwl_free_pages(priv
, rxq
->pool
[i
].page
);
1248 rxq
->pool
[i
].page
= NULL
;
1252 pci_free_consistent(priv
->pci_dev
, 4 * RX_QUEUE_SIZE
, rxq
->bd
,
1254 pci_free_consistent(priv
->pci_dev
, sizeof(struct iwl_rb_status
),
1255 rxq
->rb_stts
, rxq
->rb_stts_dma
);
1257 rxq
->rb_stts
= NULL
;
1261 /* Convert linear signal-to-noise ratio into dB */
1262 static u8 ratio2dB
[100] = {
1263 /* 0 1 2 3 4 5 6 7 8 9 */
1264 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
1265 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
1266 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
1267 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
1268 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
1269 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
1270 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
1271 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
1272 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
1273 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
1276 /* Calculates a relative dB value from a ratio of linear
1277 * (i.e. not dB) signal levels.
1278 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
1279 int iwl3945_calc_db_from_ratio(int sig_ratio
)
1281 /* 1000:1 or higher just report as 60 dB */
1282 if (sig_ratio
>= 1000)
1285 /* 100:1 or higher, divide by 10 and use table,
1286 * add 20 dB to make up for divide by 10 */
1287 if (sig_ratio
>= 100)
1288 return 20 + (int)ratio2dB
[sig_ratio
/10];
1290 /* We shouldn't see this */
1294 /* Use table for ratios 1:1 - 99:1 */
1295 return (int)ratio2dB
[sig_ratio
];
1299 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
1301 * Uses the priv->rx_handlers callback function array to invoke
1302 * the appropriate handlers, including command responses,
1303 * frame-received notifications, and other notifications.
1305 static void iwl3945_rx_handle(struct iwl_priv
*priv
)
1307 struct iwl_rx_mem_buffer
*rxb
;
1308 struct iwl_rx_packet
*pkt
;
1309 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
1312 unsigned long flags
;
1315 int total_empty
= 0;
1317 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1318 * buffer that the driver may process (last buffer filled by ucode). */
1319 r
= le16_to_cpu(rxq
->rb_stts
->closed_rb_num
) & 0x0FFF;
1322 /* calculate total frames need to be restock after handling RX */
1323 total_empty
= r
- rxq
->write_actual
;
1324 if (total_empty
< 0)
1325 total_empty
+= RX_QUEUE_SIZE
;
1327 if (total_empty
> (RX_QUEUE_SIZE
/ 2))
1329 /* Rx interrupt, but nothing sent from uCode */
1331 IWL_DEBUG_RX(priv
, "r = %d, i = %d\n", r
, i
);
1334 rxb
= rxq
->queue
[i
];
1336 /* If an RXB doesn't have a Rx queue slot associated with it,
1337 * then a bug has been introduced in the queue refilling
1338 * routines -- catch it here */
1339 BUG_ON(rxb
== NULL
);
1341 rxq
->queue
[i
] = NULL
;
1343 pci_unmap_page(priv
->pci_dev
, rxb
->page_dma
,
1344 PAGE_SIZE
<< priv
->hw_params
.rx_page_order
,
1345 PCI_DMA_FROMDEVICE
);
1346 pkt
= rxb_addr(rxb
);
1348 trace_iwlwifi_dev_rx(priv
, pkt
,
1349 le32_to_cpu(pkt
->len_n_flags
) & FH_RSCSR_FRAME_SIZE_MSK
);
1351 /* Reclaim a command buffer only if this packet is a response
1352 * to a (driver-originated) command.
1353 * If the packet (e.g. Rx frame) originated from uCode,
1354 * there is no command buffer to reclaim.
1355 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1356 * but apparently a few don't get set; catch them here. */
1357 reclaim
= !(pkt
->hdr
.sequence
& SEQ_RX_FRAME
) &&
1358 (pkt
->hdr
.cmd
!= STATISTICS_NOTIFICATION
) &&
1359 (pkt
->hdr
.cmd
!= REPLY_TX
);
1361 /* Based on type of command response or notification,
1362 * handle those that need handling via function in
1363 * rx_handlers table. See iwl3945_setup_rx_handlers() */
1364 if (priv
->rx_handlers
[pkt
->hdr
.cmd
]) {
1365 IWL_DEBUG_RX(priv
, "r = %d, i = %d, %s, 0x%02x\n", r
, i
,
1366 get_cmd_string(pkt
->hdr
.cmd
), pkt
->hdr
.cmd
);
1367 priv
->isr_stats
.rx_handlers
[pkt
->hdr
.cmd
]++;
1368 priv
->rx_handlers
[pkt
->hdr
.cmd
] (priv
, rxb
);
1370 /* No handling needed */
1372 "r %d i %d No handler needed for %s, 0x%02x\n",
1373 r
, i
, get_cmd_string(pkt
->hdr
.cmd
),
1378 * XXX: After here, we should always check rxb->page
1379 * against NULL before touching it or its virtual
1380 * memory (pkt). Because some rx_handler might have
1381 * already taken or freed the pages.
1385 /* Invoke any callbacks, transfer the buffer to caller,
1386 * and fire off the (possibly) blocking iwl_send_cmd()
1387 * as we reclaim the driver command queue */
1389 iwl_tx_cmd_complete(priv
, rxb
);
1391 IWL_WARN(priv
, "Claim null rxb?\n");
1394 /* Reuse the page if possible. For notification packets and
1395 * SKBs that fail to Rx correctly, add them back into the
1396 * rx_free list for reuse later. */
1397 spin_lock_irqsave(&rxq
->lock
, flags
);
1398 if (rxb
->page
!= NULL
) {
1399 rxb
->page_dma
= pci_map_page(priv
->pci_dev
, rxb
->page
,
1400 0, PAGE_SIZE
<< priv
->hw_params
.rx_page_order
,
1401 PCI_DMA_FROMDEVICE
);
1402 list_add_tail(&rxb
->list
, &rxq
->rx_free
);
1405 list_add_tail(&rxb
->list
, &rxq
->rx_used
);
1407 spin_unlock_irqrestore(&rxq
->lock
, flags
);
1409 i
= (i
+ 1) & RX_QUEUE_MASK
;
1410 /* If there are a lot of unused frames,
1411 * restock the Rx queue so ucode won't assert. */
1416 iwl3945_rx_replenish_now(priv
);
1422 /* Backtrack one entry */
1425 iwl3945_rx_replenish_now(priv
);
1427 iwl3945_rx_queue_restock(priv
);
1430 /* call this function to flush any scheduled tasklet */
1431 static inline void iwl_synchronize_irq(struct iwl_priv
*priv
)
1433 /* wait to make sure we flush pending tasklet*/
1434 synchronize_irq(priv
->pci_dev
->irq
);
1435 tasklet_kill(&priv
->irq_tasklet
);
1438 static const char *desc_lookup(int i
)
1446 return "BAD_CHECKSUM";
1448 return "NMI_INTERRUPT";
1452 return "FATAL_ERROR";
1458 #define ERROR_START_OFFSET (1 * sizeof(u32))
1459 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
1461 void iwl3945_dump_nic_error_log(struct iwl_priv
*priv
)
1464 u32 desc
, time
, count
, base
, data1
;
1465 u32 blink1
, blink2
, ilink1
, ilink2
;
1467 base
= le32_to_cpu(priv
->card_alive
.error_event_table_ptr
);
1469 if (!iwl3945_hw_valid_rtc_data_addr(base
)) {
1470 IWL_ERR(priv
, "Not valid error log pointer 0x%08X\n", base
);
1475 count
= iwl_read_targ_mem(priv
, base
);
1477 if (ERROR_START_OFFSET
<= count
* ERROR_ELEM_SIZE
) {
1478 IWL_ERR(priv
, "Start IWL Error Log Dump:\n");
1479 IWL_ERR(priv
, "Status: 0x%08lX, count: %d\n",
1480 priv
->status
, count
);
1483 IWL_ERR(priv
, "Desc Time asrtPC blink2 "
1484 "ilink1 nmiPC Line\n");
1485 for (i
= ERROR_START_OFFSET
;
1486 i
< (count
* ERROR_ELEM_SIZE
) + ERROR_START_OFFSET
;
1487 i
+= ERROR_ELEM_SIZE
) {
1488 desc
= iwl_read_targ_mem(priv
, base
+ i
);
1490 iwl_read_targ_mem(priv
, base
+ i
+ 1 * sizeof(u32
));
1492 iwl_read_targ_mem(priv
, base
+ i
+ 2 * sizeof(u32
));
1494 iwl_read_targ_mem(priv
, base
+ i
+ 3 * sizeof(u32
));
1496 iwl_read_targ_mem(priv
, base
+ i
+ 4 * sizeof(u32
));
1498 iwl_read_targ_mem(priv
, base
+ i
+ 5 * sizeof(u32
));
1500 iwl_read_targ_mem(priv
, base
+ i
+ 6 * sizeof(u32
));
1503 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
1504 desc_lookup(desc
), desc
, time
, blink1
, blink2
,
1505 ilink1
, ilink2
, data1
);
1506 trace_iwlwifi_dev_ucode_error(priv
, desc
, time
, data1
, 0,
1507 0, blink1
, blink2
, ilink1
, ilink2
);
1511 #define EVENT_START_OFFSET (6 * sizeof(u32))
1514 * iwl3945_print_event_log - Dump error event log to syslog
1517 static int iwl3945_print_event_log(struct iwl_priv
*priv
, u32 start_idx
,
1518 u32 num_events
, u32 mode
,
1519 int pos
, char **buf
, size_t bufsz
)
1522 u32 base
; /* SRAM byte address of event log header */
1523 u32 event_size
; /* 2 u32s, or 3 u32s if timestamp recorded */
1524 u32 ptr
; /* SRAM byte address of log data */
1525 u32 ev
, time
, data
; /* event log data */
1526 unsigned long reg_flags
;
1528 if (num_events
== 0)
1531 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
1534 event_size
= 2 * sizeof(u32
);
1536 event_size
= 3 * sizeof(u32
);
1538 ptr
= base
+ EVENT_START_OFFSET
+ (start_idx
* event_size
);
1540 /* Make sure device is powered up for SRAM reads */
1541 spin_lock_irqsave(&priv
->reg_lock
, reg_flags
);
1542 iwl_grab_nic_access(priv
);
1544 /* Set starting address; reads will auto-increment */
1545 _iwl_write_direct32(priv
, HBUS_TARG_MEM_RADDR
, ptr
);
1548 /* "time" is actually "data" for mode 0 (no timestamp).
1549 * place event id # at far right for easier visual parsing. */
1550 for (i
= 0; i
< num_events
; i
++) {
1551 ev
= _iwl_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
1552 time
= _iwl_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
1556 pos
+= scnprintf(*buf
+ pos
, bufsz
- pos
,
1560 IWL_ERR(priv
, "0x%08x\t%04u\n", time
, ev
);
1561 trace_iwlwifi_dev_ucode_event(priv
, 0,
1565 data
= _iwl_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
1567 pos
+= scnprintf(*buf
+ pos
, bufsz
- pos
,
1568 "%010u:0x%08x:%04u\n",
1571 IWL_ERR(priv
, "%010u\t0x%08x\t%04u\n",
1573 trace_iwlwifi_dev_ucode_event(priv
, time
,
1579 /* Allow device to power down */
1580 iwl_release_nic_access(priv
);
1581 spin_unlock_irqrestore(&priv
->reg_lock
, reg_flags
);
1586 * iwl3945_print_last_event_logs - Dump the newest # of event log to syslog
1588 static int iwl3945_print_last_event_logs(struct iwl_priv
*priv
, u32 capacity
,
1589 u32 num_wraps
, u32 next_entry
,
1591 int pos
, char **buf
, size_t bufsz
)
1594 * display the newest DEFAULT_LOG_ENTRIES entries
1595 * i.e the entries just before the next ont that uCode would fill.
1598 if (next_entry
< size
) {
1599 pos
= iwl3945_print_event_log(priv
,
1600 capacity
- (size
- next_entry
),
1601 size
- next_entry
, mode
,
1603 pos
= iwl3945_print_event_log(priv
, 0,
1607 pos
= iwl3945_print_event_log(priv
, next_entry
- size
,
1611 if (next_entry
< size
)
1612 pos
= iwl3945_print_event_log(priv
, 0,
1616 pos
= iwl3945_print_event_log(priv
, next_entry
- size
,
1623 /* For sanity check only. Actual size is determined by uCode, typ. 512 */
1624 #define IWL3945_MAX_EVENT_LOG_SIZE (512)
1626 #define DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES (20)
1628 int iwl3945_dump_nic_event_log(struct iwl_priv
*priv
, bool full_log
,
1629 char **buf
, bool display
)
1631 u32 base
; /* SRAM byte address of event log header */
1632 u32 capacity
; /* event log capacity in # entries */
1633 u32 mode
; /* 0 - no timestamp, 1 - timestamp recorded */
1634 u32 num_wraps
; /* # times uCode wrapped to top of log */
1635 u32 next_entry
; /* index of next entry to be written by uCode */
1636 u32 size
; /* # entries that we'll print */
1640 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
1641 if (!iwl3945_hw_valid_rtc_data_addr(base
)) {
1642 IWL_ERR(priv
, "Invalid event log pointer 0x%08X\n", base
);
1646 /* event log header */
1647 capacity
= iwl_read_targ_mem(priv
, base
);
1648 mode
= iwl_read_targ_mem(priv
, base
+ (1 * sizeof(u32
)));
1649 num_wraps
= iwl_read_targ_mem(priv
, base
+ (2 * sizeof(u32
)));
1650 next_entry
= iwl_read_targ_mem(priv
, base
+ (3 * sizeof(u32
)));
1652 if (capacity
> IWL3945_MAX_EVENT_LOG_SIZE
) {
1653 IWL_ERR(priv
, "Log capacity %d is bogus, limit to %d entries\n",
1654 capacity
, IWL3945_MAX_EVENT_LOG_SIZE
);
1655 capacity
= IWL3945_MAX_EVENT_LOG_SIZE
;
1658 if (next_entry
> IWL3945_MAX_EVENT_LOG_SIZE
) {
1659 IWL_ERR(priv
, "Log write index %d is bogus, limit to %d\n",
1660 next_entry
, IWL3945_MAX_EVENT_LOG_SIZE
);
1661 next_entry
= IWL3945_MAX_EVENT_LOG_SIZE
;
1664 size
= num_wraps
? capacity
: next_entry
;
1666 /* bail out if nothing in log */
1668 IWL_ERR(priv
, "Start IWL Event Log Dump: nothing in log\n");
1672 #ifdef CONFIG_IWLWIFI_DEBUG
1673 if (!(iwl_get_debug_level(priv
) & IWL_DL_FW_ERRORS
) && !full_log
)
1674 size
= (size
> DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES
)
1675 ? DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES
: size
;
1677 size
= (size
> DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES
)
1678 ? DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES
: size
;
1681 IWL_ERR(priv
, "Start IWL Event Log Dump: display last %d count\n",
1684 #ifdef CONFIG_IWLWIFI_DEBUG
1687 bufsz
= capacity
* 48;
1690 *buf
= kmalloc(bufsz
, GFP_KERNEL
);
1694 if ((iwl_get_debug_level(priv
) & IWL_DL_FW_ERRORS
) || full_log
) {
1695 /* if uCode has wrapped back to top of log,
1696 * start at the oldest entry,
1697 * i.e the next one that uCode would fill.
1700 pos
= iwl3945_print_event_log(priv
, next_entry
,
1701 capacity
- next_entry
, mode
,
1704 /* (then/else) start at top of log */
1705 pos
= iwl3945_print_event_log(priv
, 0, next_entry
, mode
,
1708 pos
= iwl3945_print_last_event_logs(priv
, capacity
, num_wraps
,
1709 next_entry
, size
, mode
,
1712 pos
= iwl3945_print_last_event_logs(priv
, capacity
, num_wraps
,
1713 next_entry
, size
, mode
,
1719 static void iwl3945_irq_tasklet(struct iwl_priv
*priv
)
1721 u32 inta
, handled
= 0;
1723 unsigned long flags
;
1724 #ifdef CONFIG_IWLWIFI_DEBUG
1728 spin_lock_irqsave(&priv
->lock
, flags
);
1730 /* Ack/clear/reset pending uCode interrupts.
1731 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1732 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
1733 inta
= iwl_read32(priv
, CSR_INT
);
1734 iwl_write32(priv
, CSR_INT
, inta
);
1736 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1737 * Any new interrupts that happen after this, either while we're
1738 * in this tasklet, or later, will show up in next ISR/tasklet. */
1739 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
1740 iwl_write32(priv
, CSR_FH_INT_STATUS
, inta_fh
);
1742 #ifdef CONFIG_IWLWIFI_DEBUG
1743 if (iwl_get_debug_level(priv
) & IWL_DL_ISR
) {
1744 /* just for debug */
1745 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
1746 IWL_DEBUG_ISR(priv
, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1747 inta
, inta_mask
, inta_fh
);
1751 spin_unlock_irqrestore(&priv
->lock
, flags
);
1753 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1754 * atomic, make sure that inta covers all the interrupts that
1755 * we've discovered, even if FH interrupt came in just after
1756 * reading CSR_INT. */
1757 if (inta_fh
& CSR39_FH_INT_RX_MASK
)
1758 inta
|= CSR_INT_BIT_FH_RX
;
1759 if (inta_fh
& CSR39_FH_INT_TX_MASK
)
1760 inta
|= CSR_INT_BIT_FH_TX
;
1762 /* Now service all interrupt bits discovered above. */
1763 if (inta
& CSR_INT_BIT_HW_ERR
) {
1764 IWL_ERR(priv
, "Hardware error detected. Restarting.\n");
1766 /* Tell the device to stop sending interrupts */
1767 iwl_disable_interrupts(priv
);
1769 priv
->isr_stats
.hw
++;
1770 iwl_irq_handle_error(priv
);
1772 handled
|= CSR_INT_BIT_HW_ERR
;
1777 #ifdef CONFIG_IWLWIFI_DEBUG
1778 if (iwl_get_debug_level(priv
) & (IWL_DL_ISR
)) {
1779 /* NIC fires this, but we don't use it, redundant with WAKEUP */
1780 if (inta
& CSR_INT_BIT_SCD
) {
1781 IWL_DEBUG_ISR(priv
, "Scheduler finished to transmit "
1782 "the frame/frames.\n");
1783 priv
->isr_stats
.sch
++;
1786 /* Alive notification via Rx interrupt will do the real work */
1787 if (inta
& CSR_INT_BIT_ALIVE
) {
1788 IWL_DEBUG_ISR(priv
, "Alive interrupt\n");
1789 priv
->isr_stats
.alive
++;
1793 /* Safely ignore these bits for debug checks below */
1794 inta
&= ~(CSR_INT_BIT_SCD
| CSR_INT_BIT_ALIVE
);
1796 /* Error detected by uCode */
1797 if (inta
& CSR_INT_BIT_SW_ERR
) {
1798 IWL_ERR(priv
, "Microcode SW error detected. "
1799 "Restarting 0x%X.\n", inta
);
1800 priv
->isr_stats
.sw
++;
1801 priv
->isr_stats
.sw_err
= inta
;
1802 iwl_irq_handle_error(priv
);
1803 handled
|= CSR_INT_BIT_SW_ERR
;
1806 /* uCode wakes up after power-down sleep */
1807 if (inta
& CSR_INT_BIT_WAKEUP
) {
1808 IWL_DEBUG_ISR(priv
, "Wakeup interrupt\n");
1809 iwl_rx_queue_update_write_ptr(priv
, &priv
->rxq
);
1810 iwl_txq_update_write_ptr(priv
, &priv
->txq
[0]);
1811 iwl_txq_update_write_ptr(priv
, &priv
->txq
[1]);
1812 iwl_txq_update_write_ptr(priv
, &priv
->txq
[2]);
1813 iwl_txq_update_write_ptr(priv
, &priv
->txq
[3]);
1814 iwl_txq_update_write_ptr(priv
, &priv
->txq
[4]);
1815 iwl_txq_update_write_ptr(priv
, &priv
->txq
[5]);
1817 priv
->isr_stats
.wakeup
++;
1818 handled
|= CSR_INT_BIT_WAKEUP
;
1821 /* All uCode command responses, including Tx command responses,
1822 * Rx "responses" (frame-received notification), and other
1823 * notifications from uCode come through here*/
1824 if (inta
& (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
)) {
1825 iwl3945_rx_handle(priv
);
1826 priv
->isr_stats
.rx
++;
1827 handled
|= (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
);
1830 if (inta
& CSR_INT_BIT_FH_TX
) {
1831 IWL_DEBUG_ISR(priv
, "Tx interrupt\n");
1832 priv
->isr_stats
.tx
++;
1834 iwl_write32(priv
, CSR_FH_INT_STATUS
, (1 << 6));
1835 iwl_write_direct32(priv
, FH39_TCSR_CREDIT
1836 (FH39_SRVC_CHNL
), 0x0);
1837 handled
|= CSR_INT_BIT_FH_TX
;
1840 if (inta
& ~handled
) {
1841 IWL_ERR(priv
, "Unhandled INTA bits 0x%08x\n", inta
& ~handled
);
1842 priv
->isr_stats
.unhandled
++;
1845 if (inta
& ~priv
->inta_mask
) {
1846 IWL_WARN(priv
, "Disabled INTA bits 0x%08x were pending\n",
1847 inta
& ~priv
->inta_mask
);
1848 IWL_WARN(priv
, " with FH_INT = 0x%08x\n", inta_fh
);
1851 /* Re-enable all interrupts */
1852 /* only Re-enable if disabled by irq */
1853 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
1854 iwl_enable_interrupts(priv
);
1856 #ifdef CONFIG_IWLWIFI_DEBUG
1857 if (iwl_get_debug_level(priv
) & (IWL_DL_ISR
)) {
1858 inta
= iwl_read32(priv
, CSR_INT
);
1859 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
1860 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
1861 IWL_DEBUG_ISR(priv
, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
1862 "flags 0x%08lx\n", inta
, inta_mask
, inta_fh
, flags
);
1867 static int iwl3945_get_channels_for_scan(struct iwl_priv
*priv
,
1868 enum ieee80211_band band
,
1869 u8 is_active
, u8 n_probes
,
1870 struct iwl3945_scan_channel
*scan_ch
)
1872 struct ieee80211_channel
*chan
;
1873 const struct ieee80211_supported_band
*sband
;
1874 const struct iwl_channel_info
*ch_info
;
1875 u16 passive_dwell
= 0;
1876 u16 active_dwell
= 0;
1879 sband
= iwl_get_hw_mode(priv
, band
);
1883 active_dwell
= iwl_get_active_dwell_time(priv
, band
, n_probes
);
1884 passive_dwell
= iwl_get_passive_dwell_time(priv
, band
);
1886 if (passive_dwell
<= active_dwell
)
1887 passive_dwell
= active_dwell
+ 1;
1889 for (i
= 0, added
= 0; i
< priv
->scan_request
->n_channels
; i
++) {
1890 chan
= priv
->scan_request
->channels
[i
];
1892 if (chan
->band
!= band
)
1895 scan_ch
->channel
= chan
->hw_value
;
1897 ch_info
= iwl_get_channel_info(priv
, band
, scan_ch
->channel
);
1898 if (!is_channel_valid(ch_info
)) {
1899 IWL_DEBUG_SCAN(priv
, "Channel %d is INVALID for this band.\n",
1904 scan_ch
->active_dwell
= cpu_to_le16(active_dwell
);
1905 scan_ch
->passive_dwell
= cpu_to_le16(passive_dwell
);
1906 /* If passive , set up for auto-switch
1907 * and use long active_dwell time.
1909 if (!is_active
|| is_channel_passive(ch_info
) ||
1910 (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)) {
1911 scan_ch
->type
= 0; /* passive */
1912 if (IWL_UCODE_API(priv
->ucode_ver
) == 1)
1913 scan_ch
->active_dwell
= cpu_to_le16(passive_dwell
- 1);
1915 scan_ch
->type
= 1; /* active */
1918 /* Set direct probe bits. These may be used both for active
1919 * scan channels (probes gets sent right away),
1920 * or for passive channels (probes get se sent only after
1921 * hearing clear Rx packet).*/
1922 if (IWL_UCODE_API(priv
->ucode_ver
) >= 2) {
1924 scan_ch
->type
|= IWL39_SCAN_PROBE_MASK(n_probes
);
1926 /* uCode v1 does not allow setting direct probe bits on
1927 * passive channel. */
1928 if ((scan_ch
->type
& 1) && n_probes
)
1929 scan_ch
->type
|= IWL39_SCAN_PROBE_MASK(n_probes
);
1932 /* Set txpower levels to defaults */
1933 scan_ch
->tpc
.dsp_atten
= 110;
1934 /* scan_pwr_info->tpc.dsp_atten; */
1936 /*scan_pwr_info->tpc.tx_gain; */
1937 if (band
== IEEE80211_BAND_5GHZ
)
1938 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (3 << 3)) | 3;
1940 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (5 << 3));
1941 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
1943 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
1947 IWL_DEBUG_SCAN(priv
, "Scanning %d [%s %d]\n",
1949 (scan_ch
->type
& 1) ? "ACTIVE" : "PASSIVE",
1950 (scan_ch
->type
& 1) ?
1951 active_dwell
: passive_dwell
);
1957 IWL_DEBUG_SCAN(priv
, "total channels to scan %d \n", added
);
1961 static void iwl3945_init_hw_rates(struct iwl_priv
*priv
,
1962 struct ieee80211_rate
*rates
)
1966 for (i
= 0; i
< IWL_RATE_COUNT
; i
++) {
1967 rates
[i
].bitrate
= iwl3945_rates
[i
].ieee
* 5;
1968 rates
[i
].hw_value
= i
; /* Rate scaling will work on indexes */
1969 rates
[i
].hw_value_short
= i
;
1971 if ((i
> IWL39_LAST_OFDM_RATE
) || (i
< IWL_FIRST_OFDM_RATE
)) {
1973 * If CCK != 1M then set short preamble rate flag.
1975 rates
[i
].flags
|= (iwl3945_rates
[i
].plcp
== 10) ?
1976 0 : IEEE80211_RATE_SHORT_PREAMBLE
;
1981 /******************************************************************************
1983 * uCode download functions
1985 ******************************************************************************/
1987 static void iwl3945_dealloc_ucode_pci(struct iwl_priv
*priv
)
1989 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
1990 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
1991 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
1992 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
1993 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
1994 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
1998 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
1999 * looking at all data.
2001 static int iwl3945_verify_inst_full(struct iwl_priv
*priv
, __le32
*image
, u32 len
)
2008 IWL_DEBUG_INFO(priv
, "ucode inst image size is %u\n", len
);
2010 iwl_write_direct32(priv
, HBUS_TARG_MEM_RADDR
,
2011 IWL39_RTC_INST_LOWER_BOUND
);
2014 for (; len
> 0; len
-= sizeof(u32
), image
++) {
2015 /* read data comes through single port, auto-incr addr */
2016 /* NOTE: Use the debugless read so we don't flood kernel log
2017 * if IWL_DL_IO is set */
2018 val
= _iwl_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
2019 if (val
!= le32_to_cpu(*image
)) {
2020 IWL_ERR(priv
, "uCode INST section is invalid at "
2021 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2022 save_len
- len
, val
, le32_to_cpu(*image
));
2032 IWL_DEBUG_INFO(priv
,
2033 "ucode image in INSTRUCTION memory is good\n");
2040 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
2041 * using sample data 100 bytes apart. If these sample points are good,
2042 * it's a pretty good bet that everything between them is good, too.
2044 static int iwl3945_verify_inst_sparse(struct iwl_priv
*priv
, __le32
*image
, u32 len
)
2051 IWL_DEBUG_INFO(priv
, "ucode inst image size is %u\n", len
);
2053 for (i
= 0; i
< len
; i
+= 100, image
+= 100/sizeof(u32
)) {
2054 /* read data comes through single port, auto-incr addr */
2055 /* NOTE: Use the debugless read so we don't flood kernel log
2056 * if IWL_DL_IO is set */
2057 iwl_write_direct32(priv
, HBUS_TARG_MEM_RADDR
,
2058 i
+ IWL39_RTC_INST_LOWER_BOUND
);
2059 val
= _iwl_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
2060 if (val
!= le32_to_cpu(*image
)) {
2061 #if 0 /* Enable this if you want to see details */
2062 IWL_ERR(priv
, "uCode INST section is invalid at "
2063 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2078 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
2079 * and verify its contents
2081 static int iwl3945_verify_ucode(struct iwl_priv
*priv
)
2088 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
2089 len
= priv
->ucode_boot
.len
;
2090 rc
= iwl3945_verify_inst_sparse(priv
, image
, len
);
2092 IWL_DEBUG_INFO(priv
, "Bootstrap uCode is good in inst SRAM\n");
2096 /* Try initialize */
2097 image
= (__le32
*)priv
->ucode_init
.v_addr
;
2098 len
= priv
->ucode_init
.len
;
2099 rc
= iwl3945_verify_inst_sparse(priv
, image
, len
);
2101 IWL_DEBUG_INFO(priv
, "Initialize uCode is good in inst SRAM\n");
2105 /* Try runtime/protocol */
2106 image
= (__le32
*)priv
->ucode_code
.v_addr
;
2107 len
= priv
->ucode_code
.len
;
2108 rc
= iwl3945_verify_inst_sparse(priv
, image
, len
);
2110 IWL_DEBUG_INFO(priv
, "Runtime uCode is good in inst SRAM\n");
2114 IWL_ERR(priv
, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
2116 /* Since nothing seems to match, show first several data entries in
2117 * instruction SRAM, so maybe visual inspection will give a clue.
2118 * Selection of bootstrap image (vs. other images) is arbitrary. */
2119 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
2120 len
= priv
->ucode_boot
.len
;
2121 rc
= iwl3945_verify_inst_full(priv
, image
, len
);
2126 static void iwl3945_nic_start(struct iwl_priv
*priv
)
2128 /* Remove all resets to allow NIC to operate */
2129 iwl_write32(priv
, CSR_RESET
, 0);
2133 * iwl3945_read_ucode - Read uCode images from disk file.
2135 * Copy into buffers for card to fetch via bus-mastering
2137 static int iwl3945_read_ucode(struct iwl_priv
*priv
)
2139 const struct iwl_ucode_header
*ucode
;
2140 int ret
= -EINVAL
, index
;
2141 const struct firmware
*ucode_raw
;
2142 /* firmware file name contains uCode/driver compatibility version */
2143 const char *name_pre
= priv
->cfg
->fw_name_pre
;
2144 const unsigned int api_max
= priv
->cfg
->ucode_api_max
;
2145 const unsigned int api_min
= priv
->cfg
->ucode_api_min
;
2149 u32 api_ver
, inst_size
, data_size
, init_size
, init_data_size
, boot_size
;
2151 /* Ask kernel firmware_class module to get the boot firmware off disk.
2152 * request_firmware() is synchronous, file is in memory on return. */
2153 for (index
= api_max
; index
>= api_min
; index
--) {
2154 sprintf(buf
, "%s%u%s", name_pre
, index
, ".ucode");
2155 ret
= request_firmware(&ucode_raw
, buf
, &priv
->pci_dev
->dev
);
2157 IWL_ERR(priv
, "%s firmware file req failed: %d\n",
2164 if (index
< api_max
)
2165 IWL_ERR(priv
, "Loaded firmware %s, "
2166 "which is deprecated. "
2167 " Please use API v%u instead.\n",
2169 IWL_DEBUG_INFO(priv
, "Got firmware '%s' file "
2170 "(%zd bytes) from disk\n",
2171 buf
, ucode_raw
->size
);
2179 /* Make sure that we got at least our header! */
2180 if (ucode_raw
->size
< priv
->cfg
->ops
->ucode
->get_header_size(1)) {
2181 IWL_ERR(priv
, "File size way too small!\n");
2186 /* Data from ucode file: header followed by uCode images */
2187 ucode
= (struct iwl_ucode_header
*)ucode_raw
->data
;
2189 priv
->ucode_ver
= le32_to_cpu(ucode
->ver
);
2190 api_ver
= IWL_UCODE_API(priv
->ucode_ver
);
2191 inst_size
= priv
->cfg
->ops
->ucode
->get_inst_size(ucode
, api_ver
);
2192 data_size
= priv
->cfg
->ops
->ucode
->get_data_size(ucode
, api_ver
);
2193 init_size
= priv
->cfg
->ops
->ucode
->get_init_size(ucode
, api_ver
);
2195 priv
->cfg
->ops
->ucode
->get_init_data_size(ucode
, api_ver
);
2196 boot_size
= priv
->cfg
->ops
->ucode
->get_boot_size(ucode
, api_ver
);
2197 src
= priv
->cfg
->ops
->ucode
->get_data(ucode
, api_ver
);
2199 /* api_ver should match the api version forming part of the
2200 * firmware filename ... but we don't check for that and only rely
2201 * on the API version read from firmware header from here on forward */
2203 if (api_ver
< api_min
|| api_ver
> api_max
) {
2204 IWL_ERR(priv
, "Driver unable to support your firmware API. "
2205 "Driver supports v%u, firmware is v%u.\n",
2207 priv
->ucode_ver
= 0;
2211 if (api_ver
!= api_max
)
2212 IWL_ERR(priv
, "Firmware has old API version. Expected %u, "
2213 "got %u. New firmware can be obtained "
2214 "from http://www.intellinuxwireless.org.\n",
2217 IWL_INFO(priv
, "loaded firmware version %u.%u.%u.%u\n",
2218 IWL_UCODE_MAJOR(priv
->ucode_ver
),
2219 IWL_UCODE_MINOR(priv
->ucode_ver
),
2220 IWL_UCODE_API(priv
->ucode_ver
),
2221 IWL_UCODE_SERIAL(priv
->ucode_ver
));
2223 snprintf(priv
->hw
->wiphy
->fw_version
,
2224 sizeof(priv
->hw
->wiphy
->fw_version
),
2226 IWL_UCODE_MAJOR(priv
->ucode_ver
),
2227 IWL_UCODE_MINOR(priv
->ucode_ver
),
2228 IWL_UCODE_API(priv
->ucode_ver
),
2229 IWL_UCODE_SERIAL(priv
->ucode_ver
));
2231 IWL_DEBUG_INFO(priv
, "f/w package hdr ucode version raw = 0x%x\n",
2233 IWL_DEBUG_INFO(priv
, "f/w package hdr runtime inst size = %u\n",
2235 IWL_DEBUG_INFO(priv
, "f/w package hdr runtime data size = %u\n",
2237 IWL_DEBUG_INFO(priv
, "f/w package hdr init inst size = %u\n",
2239 IWL_DEBUG_INFO(priv
, "f/w package hdr init data size = %u\n",
2241 IWL_DEBUG_INFO(priv
, "f/w package hdr boot inst size = %u\n",
2245 /* Verify size of file vs. image size info in file's header */
2246 if (ucode_raw
->size
!= priv
->cfg
->ops
->ucode
->get_header_size(api_ver
) +
2247 inst_size
+ data_size
+ init_size
+
2248 init_data_size
+ boot_size
) {
2250 IWL_DEBUG_INFO(priv
,
2251 "uCode file size %zd does not match expected size\n",
2257 /* Verify that uCode images will fit in card's SRAM */
2258 if (inst_size
> IWL39_MAX_INST_SIZE
) {
2259 IWL_DEBUG_INFO(priv
, "uCode instr len %d too large to fit in\n",
2265 if (data_size
> IWL39_MAX_DATA_SIZE
) {
2266 IWL_DEBUG_INFO(priv
, "uCode data len %d too large to fit in\n",
2271 if (init_size
> IWL39_MAX_INST_SIZE
) {
2272 IWL_DEBUG_INFO(priv
,
2273 "uCode init instr len %d too large to fit in\n",
2278 if (init_data_size
> IWL39_MAX_DATA_SIZE
) {
2279 IWL_DEBUG_INFO(priv
,
2280 "uCode init data len %d too large to fit in\n",
2285 if (boot_size
> IWL39_MAX_BSM_SIZE
) {
2286 IWL_DEBUG_INFO(priv
,
2287 "uCode boot instr len %d too large to fit in\n",
2293 /* Allocate ucode buffers for card's bus-master loading ... */
2295 /* Runtime instructions and 2 copies of data:
2296 * 1) unmodified from disk
2297 * 2) backup cache for save/restore during power-downs */
2298 priv
->ucode_code
.len
= inst_size
;
2299 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
2301 priv
->ucode_data
.len
= data_size
;
2302 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
2304 priv
->ucode_data_backup
.len
= data_size
;
2305 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
2307 if (!priv
->ucode_code
.v_addr
|| !priv
->ucode_data
.v_addr
||
2308 !priv
->ucode_data_backup
.v_addr
)
2311 /* Initialization instructions and data */
2312 if (init_size
&& init_data_size
) {
2313 priv
->ucode_init
.len
= init_size
;
2314 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
2316 priv
->ucode_init_data
.len
= init_data_size
;
2317 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
2319 if (!priv
->ucode_init
.v_addr
|| !priv
->ucode_init_data
.v_addr
)
2323 /* Bootstrap (instructions only, no data) */
2325 priv
->ucode_boot
.len
= boot_size
;
2326 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
2328 if (!priv
->ucode_boot
.v_addr
)
2332 /* Copy images into buffers for card's bus-master reads ... */
2334 /* Runtime instructions (first block of data in file) */
2336 IWL_DEBUG_INFO(priv
,
2337 "Copying (but not loading) uCode instr len %zd\n", len
);
2338 memcpy(priv
->ucode_code
.v_addr
, src
, len
);
2341 IWL_DEBUG_INFO(priv
, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
2342 priv
->ucode_code
.v_addr
, (u32
)priv
->ucode_code
.p_addr
);
2344 /* Runtime data (2nd block)
2345 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
2347 IWL_DEBUG_INFO(priv
,
2348 "Copying (but not loading) uCode data len %zd\n", len
);
2349 memcpy(priv
->ucode_data
.v_addr
, src
, len
);
2350 memcpy(priv
->ucode_data_backup
.v_addr
, src
, len
);
2353 /* Initialization instructions (3rd block) */
2356 IWL_DEBUG_INFO(priv
,
2357 "Copying (but not loading) init instr len %zd\n", len
);
2358 memcpy(priv
->ucode_init
.v_addr
, src
, len
);
2362 /* Initialization data (4th block) */
2363 if (init_data_size
) {
2364 len
= init_data_size
;
2365 IWL_DEBUG_INFO(priv
,
2366 "Copying (but not loading) init data len %zd\n", len
);
2367 memcpy(priv
->ucode_init_data
.v_addr
, src
, len
);
2371 /* Bootstrap instructions (5th block) */
2373 IWL_DEBUG_INFO(priv
,
2374 "Copying (but not loading) boot instr len %zd\n", len
);
2375 memcpy(priv
->ucode_boot
.v_addr
, src
, len
);
2377 /* We have our copies now, allow OS release its copies */
2378 release_firmware(ucode_raw
);
2382 IWL_ERR(priv
, "failed to allocate pci memory\n");
2384 iwl3945_dealloc_ucode_pci(priv
);
2387 release_firmware(ucode_raw
);
2395 * iwl3945_set_ucode_ptrs - Set uCode address location
2397 * Tell initialization uCode where to find runtime uCode.
2399 * BSM registers initially contain pointers to initialization uCode.
2400 * We need to replace them to load runtime uCode inst and data,
2401 * and to save runtime data when powering down.
2403 static int iwl3945_set_ucode_ptrs(struct iwl_priv
*priv
)
2408 /* bits 31:0 for 3945 */
2409 pinst
= priv
->ucode_code
.p_addr
;
2410 pdata
= priv
->ucode_data_backup
.p_addr
;
2412 /* Tell bootstrap uCode where to find image to load */
2413 iwl_write_prph(priv
, BSM_DRAM_INST_PTR_REG
, pinst
);
2414 iwl_write_prph(priv
, BSM_DRAM_DATA_PTR_REG
, pdata
);
2415 iwl_write_prph(priv
, BSM_DRAM_DATA_BYTECOUNT_REG
,
2416 priv
->ucode_data
.len
);
2418 /* Inst byte count must be last to set up, bit 31 signals uCode
2419 * that all new ptr/size info is in place */
2420 iwl_write_prph(priv
, BSM_DRAM_INST_BYTECOUNT_REG
,
2421 priv
->ucode_code
.len
| BSM_DRAM_INST_LOAD
);
2423 IWL_DEBUG_INFO(priv
, "Runtime uCode pointers are set.\n");
2429 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
2431 * Called after REPLY_ALIVE notification received from "initialize" uCode.
2433 * Tell "initialize" uCode to go ahead and load the runtime uCode.
2435 static void iwl3945_init_alive_start(struct iwl_priv
*priv
)
2437 /* Check alive response for "valid" sign from uCode */
2438 if (priv
->card_alive_init
.is_valid
!= UCODE_VALID_OK
) {
2439 /* We had an error bringing up the hardware, so take it
2440 * all the way back down so we can try again */
2441 IWL_DEBUG_INFO(priv
, "Initialize Alive failed.\n");
2445 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
2446 * This is a paranoid check, because we would not have gotten the
2447 * "initialize" alive if code weren't properly loaded. */
2448 if (iwl3945_verify_ucode(priv
)) {
2449 /* Runtime instruction load was bad;
2450 * take it all the way back down so we can try again */
2451 IWL_DEBUG_INFO(priv
, "Bad \"initialize\" uCode load.\n");
2455 /* Send pointers to protocol/runtime uCode image ... init code will
2456 * load and launch runtime uCode, which will send us another "Alive"
2458 IWL_DEBUG_INFO(priv
, "Initialization Alive received.\n");
2459 if (iwl3945_set_ucode_ptrs(priv
)) {
2460 /* Runtime instruction load won't happen;
2461 * take it all the way back down so we can try again */
2462 IWL_DEBUG_INFO(priv
, "Couldn't set up uCode pointers.\n");
2468 queue_work(priv
->workqueue
, &priv
->restart
);
2472 * iwl3945_alive_start - called after REPLY_ALIVE notification received
2473 * from protocol/runtime uCode (initialization uCode's
2474 * Alive gets handled by iwl3945_init_alive_start()).
2476 static void iwl3945_alive_start(struct iwl_priv
*priv
)
2478 int thermal_spin
= 0;
2481 IWL_DEBUG_INFO(priv
, "Runtime Alive received.\n");
2483 if (priv
->card_alive
.is_valid
!= UCODE_VALID_OK
) {
2484 /* We had an error bringing up the hardware, so take it
2485 * all the way back down so we can try again */
2486 IWL_DEBUG_INFO(priv
, "Alive failed.\n");
2490 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2491 * This is a paranoid check, because we would not have gotten the
2492 * "runtime" alive if code weren't properly loaded. */
2493 if (iwl3945_verify_ucode(priv
)) {
2494 /* Runtime instruction load was bad;
2495 * take it all the way back down so we can try again */
2496 IWL_DEBUG_INFO(priv
, "Bad runtime uCode load.\n");
2500 iwl_clear_stations_table(priv
);
2502 rfkill
= iwl_read_prph(priv
, APMG_RFKILL_REG
);
2503 IWL_DEBUG_INFO(priv
, "RFKILL status: 0x%x\n", rfkill
);
2506 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2507 /* if RFKILL is not on, then wait for thermal
2508 * sensor in adapter to kick in */
2509 while (iwl3945_hw_get_temperature(priv
) == 0) {
2515 IWL_DEBUG_INFO(priv
, "Thermal calibration took %dus\n",
2518 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2520 /* After the ALIVE response, we can send commands to 3945 uCode */
2521 set_bit(STATUS_ALIVE
, &priv
->status
);
2523 if (iwl_is_rfkill(priv
))
2526 ieee80211_wake_queues(priv
->hw
);
2528 priv
->active_rate
= priv
->rates_mask
;
2529 priv
->active_rate_basic
= priv
->rates_mask
& IWL_BASIC_RATES_MASK
;
2531 iwl_power_update_mode(priv
, true);
2533 if (iwl_is_associated(priv
)) {
2534 struct iwl3945_rxon_cmd
*active_rxon
=
2535 (struct iwl3945_rxon_cmd
*)(&priv
->active_rxon
);
2537 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
2538 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
2540 /* Initialize our rx_config data */
2541 iwl_connection_init_rx_config(priv
, priv
->iw_mode
);
2544 /* Configure Bluetooth device coexistence support */
2545 iwl_send_bt_config(priv
);
2547 /* Configure the adapter for unassociated operation */
2548 iwlcore_commit_rxon(priv
);
2550 iwl3945_reg_txpower_periodic(priv
);
2552 iwl_leds_init(priv
);
2554 IWL_DEBUG_INFO(priv
, "ALIVE processing complete.\n");
2555 set_bit(STATUS_READY
, &priv
->status
);
2556 wake_up_interruptible(&priv
->wait_command_queue
);
2558 /* reassociate for ADHOC mode */
2559 if (priv
->vif
&& (priv
->iw_mode
== NL80211_IFTYPE_ADHOC
)) {
2560 struct sk_buff
*beacon
= ieee80211_beacon_get(priv
->hw
,
2563 iwl_mac_beacon_update(priv
->hw
, beacon
);
2566 if (test_and_clear_bit(STATUS_MODE_PENDING
, &priv
->status
))
2567 iwl_set_mode(priv
, priv
->iw_mode
);
2572 queue_work(priv
->workqueue
, &priv
->restart
);
2575 static void iwl3945_cancel_deferred_work(struct iwl_priv
*priv
);
2577 static void __iwl3945_down(struct iwl_priv
*priv
)
2579 unsigned long flags
;
2580 int exit_pending
= test_bit(STATUS_EXIT_PENDING
, &priv
->status
);
2581 struct ieee80211_conf
*conf
= NULL
;
2583 IWL_DEBUG_INFO(priv
, DRV_NAME
" is going down\n");
2585 conf
= ieee80211_get_hw_conf(priv
->hw
);
2588 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
2590 iwl_clear_stations_table(priv
);
2592 /* Unblock any waiting calls */
2593 wake_up_interruptible_all(&priv
->wait_command_queue
);
2595 /* Wipe out the EXIT_PENDING status bit if we are not actually
2596 * exiting the module */
2598 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
2600 /* stop and reset the on-board processor */
2601 iwl_write32(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_NEVO_RESET
);
2603 /* tell the device to stop sending interrupts */
2604 spin_lock_irqsave(&priv
->lock
, flags
);
2605 iwl_disable_interrupts(priv
);
2606 spin_unlock_irqrestore(&priv
->lock
, flags
);
2607 iwl_synchronize_irq(priv
);
2609 if (priv
->mac80211_registered
)
2610 ieee80211_stop_queues(priv
->hw
);
2612 /* If we have not previously called iwl3945_init() then
2613 * clear all bits but the RF Kill bits and return */
2614 if (!iwl_is_init(priv
)) {
2615 priv
->status
= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
2617 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
2618 STATUS_GEO_CONFIGURED
|
2619 test_bit(STATUS_EXIT_PENDING
, &priv
->status
) <<
2620 STATUS_EXIT_PENDING
;
2624 /* ...otherwise clear out all the status bits but the RF Kill
2625 * bit and continue taking the NIC down. */
2626 priv
->status
&= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
2628 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
2629 STATUS_GEO_CONFIGURED
|
2630 test_bit(STATUS_FW_ERROR
, &priv
->status
) <<
2632 test_bit(STATUS_EXIT_PENDING
, &priv
->status
) <<
2633 STATUS_EXIT_PENDING
;
2635 iwl3945_hw_txq_ctx_stop(priv
);
2636 iwl3945_hw_rxq_stop(priv
);
2638 /* Power-down device's busmaster DMA clocks */
2639 iwl_write_prph(priv
, APMG_CLK_DIS_REG
, APMG_CLK_VAL_DMA_CLK_RQT
);
2642 /* Stop the device, and put it in low power state */
2643 priv
->cfg
->ops
->lib
->apm_ops
.stop(priv
);
2646 memset(&priv
->card_alive
, 0, sizeof(struct iwl_alive_resp
));
2648 if (priv
->ibss_beacon
)
2649 dev_kfree_skb(priv
->ibss_beacon
);
2650 priv
->ibss_beacon
= NULL
;
2652 /* clear out any free frames */
2653 iwl3945_clear_free_frames(priv
);
2656 static void iwl3945_down(struct iwl_priv
*priv
)
2658 mutex_lock(&priv
->mutex
);
2659 __iwl3945_down(priv
);
2660 mutex_unlock(&priv
->mutex
);
2662 iwl3945_cancel_deferred_work(priv
);
2665 #define MAX_HW_RESTARTS 5
2667 static int __iwl3945_up(struct iwl_priv
*priv
)
2671 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
2672 IWL_WARN(priv
, "Exit pending; will not bring the NIC up\n");
2676 if (!priv
->ucode_data_backup
.v_addr
|| !priv
->ucode_data
.v_addr
) {
2677 IWL_ERR(priv
, "ucode not available for device bring up\n");
2681 /* If platform's RF_KILL switch is NOT set to KILL */
2682 if (iwl_read32(priv
, CSR_GP_CNTRL
) &
2683 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
)
2684 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2686 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2687 IWL_WARN(priv
, "Radio disabled by HW RF Kill switch\n");
2691 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
2693 rc
= iwl3945_hw_nic_init(priv
);
2695 IWL_ERR(priv
, "Unable to int nic\n");
2699 /* make sure rfkill handshake bits are cleared */
2700 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2701 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
2702 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
2704 /* clear (again), then enable host interrupts */
2705 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
2706 iwl_enable_interrupts(priv
);
2708 /* really make sure rfkill handshake bits are cleared */
2709 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2710 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2712 /* Copy original ucode data image from disk into backup cache.
2713 * This will be used to initialize the on-board processor's
2714 * data SRAM for a clean start when the runtime program first loads. */
2715 memcpy(priv
->ucode_data_backup
.v_addr
, priv
->ucode_data
.v_addr
,
2716 priv
->ucode_data
.len
);
2718 /* We return success when we resume from suspend and rf_kill is on. */
2719 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
2722 for (i
= 0; i
< MAX_HW_RESTARTS
; i
++) {
2724 iwl_clear_stations_table(priv
);
2726 /* load bootstrap state machine,
2727 * load bootstrap program into processor's memory,
2728 * prepare to load the "initialize" uCode */
2729 priv
->cfg
->ops
->lib
->load_ucode(priv
);
2733 "Unable to set up bootstrap uCode: %d\n", rc
);
2737 /* start card; "initialize" will load runtime ucode */
2738 iwl3945_nic_start(priv
);
2740 IWL_DEBUG_INFO(priv
, DRV_NAME
" is coming up\n");
2745 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
2746 __iwl3945_down(priv
);
2747 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
2749 /* tried to restart and config the device for as long as our
2750 * patience could withstand */
2751 IWL_ERR(priv
, "Unable to initialize device after %d attempts.\n", i
);
2756 /*****************************************************************************
2758 * Workqueue callbacks
2760 *****************************************************************************/
2762 static void iwl3945_bg_init_alive_start(struct work_struct
*data
)
2764 struct iwl_priv
*priv
=
2765 container_of(data
, struct iwl_priv
, init_alive_start
.work
);
2767 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2770 mutex_lock(&priv
->mutex
);
2771 iwl3945_init_alive_start(priv
);
2772 mutex_unlock(&priv
->mutex
);
2775 static void iwl3945_bg_alive_start(struct work_struct
*data
)
2777 struct iwl_priv
*priv
=
2778 container_of(data
, struct iwl_priv
, alive_start
.work
);
2780 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2783 mutex_lock(&priv
->mutex
);
2784 iwl3945_alive_start(priv
);
2785 mutex_unlock(&priv
->mutex
);
2789 * 3945 cannot interrupt driver when hardware rf kill switch toggles;
2790 * driver must poll CSR_GP_CNTRL_REG register for change. This register
2791 * *is* readable even when device has been SW_RESET into low power mode
2792 * (e.g. during RF KILL).
2794 static void iwl3945_rfkill_poll(struct work_struct
*data
)
2796 struct iwl_priv
*priv
=
2797 container_of(data
, struct iwl_priv
, rfkill_poll
.work
);
2798 bool old_rfkill
= test_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2799 bool new_rfkill
= !(iwl_read32(priv
, CSR_GP_CNTRL
)
2800 & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
);
2802 if (new_rfkill
!= old_rfkill
) {
2804 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2806 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2808 wiphy_rfkill_set_hw_state(priv
->hw
->wiphy
, new_rfkill
);
2810 IWL_DEBUG_RF_KILL(priv
, "RF_KILL bit toggled to %s.\n",
2811 new_rfkill
? "disable radio" : "enable radio");
2814 /* Keep this running, even if radio now enabled. This will be
2815 * cancelled in mac_start() if system decides to start again */
2816 queue_delayed_work(priv
->workqueue
, &priv
->rfkill_poll
,
2817 round_jiffies_relative(2 * HZ
));
2821 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
2822 static void iwl3945_bg_request_scan(struct work_struct
*data
)
2824 struct iwl_priv
*priv
=
2825 container_of(data
, struct iwl_priv
, request_scan
);
2826 struct iwl_host_cmd cmd
= {
2827 .id
= REPLY_SCAN_CMD
,
2828 .len
= sizeof(struct iwl3945_scan_cmd
),
2829 .flags
= CMD_SIZE_HUGE
,
2832 struct iwl3945_scan_cmd
*scan
;
2833 struct ieee80211_conf
*conf
= NULL
;
2835 enum ieee80211_band band
;
2836 bool is_active
= false;
2838 conf
= ieee80211_get_hw_conf(priv
->hw
);
2840 mutex_lock(&priv
->mutex
);
2842 cancel_delayed_work(&priv
->scan_check
);
2844 if (!iwl_is_ready(priv
)) {
2845 IWL_WARN(priv
, "request scan called when driver not ready.\n");
2849 /* Make sure the scan wasn't canceled before this queued work
2850 * was given the chance to run... */
2851 if (!test_bit(STATUS_SCANNING
, &priv
->status
))
2854 /* This should never be called or scheduled if there is currently
2855 * a scan active in the hardware. */
2856 if (test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
2857 IWL_DEBUG_INFO(priv
, "Multiple concurrent scan requests "
2858 "Ignoring second request.\n");
2863 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
2864 IWL_DEBUG_SCAN(priv
, "Aborting scan due to device shutdown\n");
2868 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
2870 "Scan request while abort pending. Queuing.\n");
2874 if (iwl_is_rfkill(priv
)) {
2875 IWL_DEBUG_HC(priv
, "Aborting scan due to RF Kill activation\n");
2879 if (!test_bit(STATUS_READY
, &priv
->status
)) {
2881 "Scan request while uninitialized. Queuing.\n");
2885 if (!priv
->scan_bands
) {
2886 IWL_DEBUG_HC(priv
, "Aborting scan due to no requested bands\n");
2891 priv
->scan
= kmalloc(sizeof(struct iwl3945_scan_cmd
) +
2892 IWL_MAX_SCAN_SIZE
, GFP_KERNEL
);
2899 memset(scan
, 0, sizeof(struct iwl3945_scan_cmd
) + IWL_MAX_SCAN_SIZE
);
2901 scan
->quiet_plcp_th
= IWL_PLCP_QUIET_THRESH
;
2902 scan
->quiet_time
= IWL_ACTIVE_QUIET_TIME
;
2904 if (iwl_is_associated(priv
)) {
2907 u32 suspend_time
= 100;
2908 u32 scan_suspend_time
= 100;
2909 unsigned long flags
;
2911 IWL_DEBUG_INFO(priv
, "Scanning while associated...\n");
2913 spin_lock_irqsave(&priv
->lock
, flags
);
2914 interval
= priv
->beacon_int
;
2915 spin_unlock_irqrestore(&priv
->lock
, flags
);
2917 scan
->suspend_time
= 0;
2918 scan
->max_out_time
= cpu_to_le32(200 * 1024);
2920 interval
= suspend_time
;
2922 * suspend time format:
2923 * 0-19: beacon interval in usec (time before exec.)
2925 * 24-31: number of beacons (suspend between channels)
2928 extra
= (suspend_time
/ interval
) << 24;
2929 scan_suspend_time
= 0xFF0FFFFF &
2930 (extra
| ((suspend_time
% interval
) * 1024));
2932 scan
->suspend_time
= cpu_to_le32(scan_suspend_time
);
2933 IWL_DEBUG_SCAN(priv
, "suspend_time 0x%X beacon interval %d\n",
2934 scan_suspend_time
, interval
);
2937 if (priv
->scan_request
->n_ssids
) {
2939 IWL_DEBUG_SCAN(priv
, "Kicking off active scan\n");
2940 for (i
= 0; i
< priv
->scan_request
->n_ssids
; i
++) {
2941 /* always does wildcard anyway */
2942 if (!priv
->scan_request
->ssids
[i
].ssid_len
)
2944 scan
->direct_scan
[p
].id
= WLAN_EID_SSID
;
2945 scan
->direct_scan
[p
].len
=
2946 priv
->scan_request
->ssids
[i
].ssid_len
;
2947 memcpy(scan
->direct_scan
[p
].ssid
,
2948 priv
->scan_request
->ssids
[i
].ssid
,
2949 priv
->scan_request
->ssids
[i
].ssid_len
);
2955 IWL_DEBUG_SCAN(priv
, "Kicking off passive scan.\n");
2957 /* We don't build a direct scan probe request; the uCode will do
2958 * that based on the direct_mask added to each channel entry */
2959 scan
->tx_cmd
.tx_flags
= TX_CMD_FLG_SEQ_CTL_MSK
;
2960 scan
->tx_cmd
.sta_id
= priv
->hw_params
.bcast_sta_id
;
2961 scan
->tx_cmd
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
2963 /* flags + rate selection */
2965 if (priv
->scan_bands
& BIT(IEEE80211_BAND_2GHZ
)) {
2966 scan
->flags
= RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
;
2967 scan
->tx_cmd
.rate
= IWL_RATE_1M_PLCP
;
2968 scan
->good_CRC_th
= 0;
2969 band
= IEEE80211_BAND_2GHZ
;
2970 } else if (priv
->scan_bands
& BIT(IEEE80211_BAND_5GHZ
)) {
2971 scan
->tx_cmd
.rate
= IWL_RATE_6M_PLCP
;
2973 * If active scaning is requested but a certain channel
2974 * is marked passive, we can do active scanning if we
2975 * detect transmissions.
2977 scan
->good_CRC_th
= is_active
? IWL_GOOD_CRC_TH
: 0;
2978 band
= IEEE80211_BAND_5GHZ
;
2980 IWL_WARN(priv
, "Invalid scan band count\n");
2984 scan
->tx_cmd
.len
= cpu_to_le16(
2985 iwl_fill_probe_req(priv
,
2986 (struct ieee80211_mgmt
*)scan
->data
,
2987 priv
->scan_request
->ie
,
2988 priv
->scan_request
->ie_len
,
2989 IWL_MAX_SCAN_SIZE
- sizeof(*scan
)));
2991 /* select Rx antennas */
2992 scan
->flags
|= iwl3945_get_antenna_flags(priv
);
2994 if (iwl_is_monitor_mode(priv
))
2995 scan
->filter_flags
= RXON_FILTER_PROMISC_MSK
;
2997 scan
->channel_count
=
2998 iwl3945_get_channels_for_scan(priv
, band
, is_active
, n_probes
,
2999 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
3001 if (scan
->channel_count
== 0) {
3002 IWL_DEBUG_SCAN(priv
, "channel count %d\n", scan
->channel_count
);
3006 cmd
.len
+= le16_to_cpu(scan
->tx_cmd
.len
) +
3007 scan
->channel_count
* sizeof(struct iwl3945_scan_channel
);
3009 scan
->len
= cpu_to_le16(cmd
.len
);
3011 set_bit(STATUS_SCAN_HW
, &priv
->status
);
3012 rc
= iwl_send_cmd_sync(priv
, &cmd
);
3016 queue_delayed_work(priv
->workqueue
, &priv
->scan_check
,
3017 IWL_SCAN_CHECK_WATCHDOG
);
3019 mutex_unlock(&priv
->mutex
);
3023 /* can not perform scan make sure we clear scanning
3024 * bits from status so next scan request can be performed.
3025 * if we dont clear scanning status bit here all next scan
3028 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
3029 clear_bit(STATUS_SCANNING
, &priv
->status
);
3031 /* inform mac80211 scan aborted */
3032 queue_work(priv
->workqueue
, &priv
->scan_completed
);
3033 mutex_unlock(&priv
->mutex
);
3036 static void iwl3945_bg_restart(struct work_struct
*data
)
3038 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, restart
);
3040 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
3043 if (test_and_clear_bit(STATUS_FW_ERROR
, &priv
->status
)) {
3044 mutex_lock(&priv
->mutex
);
3047 mutex_unlock(&priv
->mutex
);
3049 ieee80211_restart_hw(priv
->hw
);
3053 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
3056 mutex_lock(&priv
->mutex
);
3058 mutex_unlock(&priv
->mutex
);
3062 static void iwl3945_bg_rx_replenish(struct work_struct
*data
)
3064 struct iwl_priv
*priv
=
3065 container_of(data
, struct iwl_priv
, rx_replenish
);
3067 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
3070 mutex_lock(&priv
->mutex
);
3071 iwl3945_rx_replenish(priv
);
3072 mutex_unlock(&priv
->mutex
);
3075 #define IWL_DELAY_NEXT_SCAN (HZ*2)
3077 void iwl3945_post_associate(struct iwl_priv
*priv
)
3080 struct ieee80211_conf
*conf
= NULL
;
3082 if (priv
->iw_mode
== NL80211_IFTYPE_AP
) {
3083 IWL_ERR(priv
, "%s Should not be called in AP mode\n", __func__
);
3088 IWL_DEBUG_ASSOC(priv
, "Associated as %d to: %pM\n",
3089 priv
->assoc_id
, priv
->active_rxon
.bssid_addr
);
3091 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
3094 if (!priv
->vif
|| !priv
->is_open
)
3097 iwl_scan_cancel_timeout(priv
, 200);
3099 conf
= ieee80211_get_hw_conf(priv
->hw
);
3101 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
3102 iwlcore_commit_rxon(priv
);
3104 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl_rxon_time_cmd
));
3105 iwl_setup_rxon_timing(priv
);
3106 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
3107 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
3109 IWL_WARN(priv
, "REPLY_RXON_TIMING failed - "
3110 "Attempting to continue.\n");
3112 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
3114 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
3116 IWL_DEBUG_ASSOC(priv
, "assoc id %d beacon interval %d\n",
3117 priv
->assoc_id
, priv
->beacon_int
);
3119 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
3120 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
3122 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
3124 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
3125 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
3126 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
3128 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
3130 if (priv
->iw_mode
== NL80211_IFTYPE_ADHOC
)
3131 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
3135 iwlcore_commit_rxon(priv
);
3137 switch (priv
->iw_mode
) {
3138 case NL80211_IFTYPE_STATION
:
3139 iwl3945_rate_scale_init(priv
->hw
, IWL_AP_ID
);
3142 case NL80211_IFTYPE_ADHOC
:
3145 iwl_add_station(priv
, priv
->bssid
, 0, CMD_SYNC
, NULL
);
3146 iwl3945_sync_sta(priv
, IWL_STA_ID
,
3147 (priv
->band
== IEEE80211_BAND_5GHZ
) ?
3148 IWL_RATE_6M_PLCP
: IWL_RATE_1M_PLCP
,
3150 iwl3945_rate_scale_init(priv
->hw
, IWL_STA_ID
);
3151 iwl3945_send_beacon_cmd(priv
);
3156 IWL_ERR(priv
, "%s Should not be called in %d mode\n",
3157 __func__
, priv
->iw_mode
);
3161 iwl_activate_qos(priv
, 0);
3163 /* we have just associated, don't start scan too early */
3164 priv
->next_scan_jiffies
= jiffies
+ IWL_DELAY_NEXT_SCAN
;
3167 /*****************************************************************************
3169 * mac80211 entry point functions
3171 *****************************************************************************/
3173 #define UCODE_READY_TIMEOUT (2 * HZ)
3175 static int iwl3945_mac_start(struct ieee80211_hw
*hw
)
3177 struct iwl_priv
*priv
= hw
->priv
;
3180 IWL_DEBUG_MAC80211(priv
, "enter\n");
3182 /* we should be verifying the device is ready to be opened */
3183 mutex_lock(&priv
->mutex
);
3185 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
3186 * ucode filename and max sizes are card-specific. */
3188 if (!priv
->ucode_code
.len
) {
3189 ret
= iwl3945_read_ucode(priv
);
3191 IWL_ERR(priv
, "Could not read microcode: %d\n", ret
);
3192 mutex_unlock(&priv
->mutex
);
3193 goto out_release_irq
;
3197 ret
= __iwl3945_up(priv
);
3199 mutex_unlock(&priv
->mutex
);
3202 goto out_release_irq
;
3204 IWL_DEBUG_INFO(priv
, "Start UP work.\n");
3206 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
3207 * mac80211 will not be run successfully. */
3208 ret
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
3209 test_bit(STATUS_READY
, &priv
->status
),
3210 UCODE_READY_TIMEOUT
);
3212 if (!test_bit(STATUS_READY
, &priv
->status
)) {
3214 "Wait for START_ALIVE timeout after %dms.\n",
3215 jiffies_to_msecs(UCODE_READY_TIMEOUT
));
3217 goto out_release_irq
;
3221 /* ucode is running and will send rfkill notifications,
3222 * no need to poll the killswitch state anymore */
3223 cancel_delayed_work(&priv
->rfkill_poll
);
3225 iwl_led_start(priv
);
3228 IWL_DEBUG_MAC80211(priv
, "leave\n");
3233 IWL_DEBUG_MAC80211(priv
, "leave - failed\n");
3237 static void iwl3945_mac_stop(struct ieee80211_hw
*hw
)
3239 struct iwl_priv
*priv
= hw
->priv
;
3241 IWL_DEBUG_MAC80211(priv
, "enter\n");
3243 if (!priv
->is_open
) {
3244 IWL_DEBUG_MAC80211(priv
, "leave - skip\n");
3250 if (iwl_is_ready_rf(priv
)) {
3251 /* stop mac, cancel any scan request and clear
3252 * RXON_FILTER_ASSOC_MSK BIT
3254 mutex_lock(&priv
->mutex
);
3255 iwl_scan_cancel_timeout(priv
, 100);
3256 mutex_unlock(&priv
->mutex
);
3261 flush_workqueue(priv
->workqueue
);
3263 /* start polling the killswitch state again */
3264 queue_delayed_work(priv
->workqueue
, &priv
->rfkill_poll
,
3265 round_jiffies_relative(2 * HZ
));
3267 IWL_DEBUG_MAC80211(priv
, "leave\n");
3270 static int iwl3945_mac_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
3272 struct iwl_priv
*priv
= hw
->priv
;
3274 IWL_DEBUG_MAC80211(priv
, "enter\n");
3276 IWL_DEBUG_TX(priv
, "dev->xmit(%d bytes) at rate 0x%02x\n", skb
->len
,
3277 ieee80211_get_tx_rate(hw
, IEEE80211_SKB_CB(skb
))->bitrate
);
3279 if (iwl3945_tx_skb(priv
, skb
))
3280 dev_kfree_skb_any(skb
);
3282 IWL_DEBUG_MAC80211(priv
, "leave\n");
3283 return NETDEV_TX_OK
;
3286 void iwl3945_config_ap(struct iwl_priv
*priv
)
3290 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
3293 /* The following should be done only at AP bring up */
3294 if (!(iwl_is_associated(priv
))) {
3296 /* RXON - unassoc (to set timing command) */
3297 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
3298 iwlcore_commit_rxon(priv
);
3301 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl_rxon_time_cmd
));
3302 iwl_setup_rxon_timing(priv
);
3303 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
3304 sizeof(priv
->rxon_timing
),
3305 &priv
->rxon_timing
);
3307 IWL_WARN(priv
, "REPLY_RXON_TIMING failed - "
3308 "Attempting to continue.\n");
3310 /* FIXME: what should be the assoc_id for AP? */
3311 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
3312 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
3313 priv
->staging_rxon
.flags
|=
3314 RXON_FLG_SHORT_PREAMBLE_MSK
;
3316 priv
->staging_rxon
.flags
&=
3317 ~RXON_FLG_SHORT_PREAMBLE_MSK
;
3319 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
3320 if (priv
->assoc_capability
&
3321 WLAN_CAPABILITY_SHORT_SLOT_TIME
)
3322 priv
->staging_rxon
.flags
|=
3323 RXON_FLG_SHORT_SLOT_MSK
;
3325 priv
->staging_rxon
.flags
&=
3326 ~RXON_FLG_SHORT_SLOT_MSK
;
3328 if (priv
->iw_mode
== NL80211_IFTYPE_ADHOC
)
3329 priv
->staging_rxon
.flags
&=
3330 ~RXON_FLG_SHORT_SLOT_MSK
;
3332 /* restore RXON assoc */
3333 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
3334 iwlcore_commit_rxon(priv
);
3335 iwl_add_station(priv
, iwl_bcast_addr
, 0, CMD_SYNC
, NULL
);
3337 iwl3945_send_beacon_cmd(priv
);
3339 /* FIXME - we need to add code here to detect a totally new
3340 * configuration, reset the AP, unassoc, rxon timing, assoc,
3341 * clear sta table, add BCAST sta... */
3344 static int iwl3945_mac_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
3345 struct ieee80211_vif
*vif
,
3346 struct ieee80211_sta
*sta
,
3347 struct ieee80211_key_conf
*key
)
3349 struct iwl_priv
*priv
= hw
->priv
;
3352 u8 sta_id
= IWL_INVALID_STATION
;
3355 IWL_DEBUG_MAC80211(priv
, "enter\n");
3357 if (iwl3945_mod_params
.sw_crypto
) {
3358 IWL_DEBUG_MAC80211(priv
, "leave - hwcrypto disabled\n");
3362 addr
= sta
? sta
->addr
: iwl_bcast_addr
;
3363 static_key
= !iwl_is_associated(priv
);
3366 sta_id
= iwl_find_station(priv
, addr
);
3367 if (sta_id
== IWL_INVALID_STATION
) {
3368 IWL_DEBUG_MAC80211(priv
, "leave - %pM not in station map.\n",
3374 mutex_lock(&priv
->mutex
);
3375 iwl_scan_cancel_timeout(priv
, 100);
3376 mutex_unlock(&priv
->mutex
);
3381 ret
= iwl3945_set_static_key(priv
, key
);
3383 ret
= iwl3945_set_dynamic_key(priv
, key
, sta_id
);
3384 IWL_DEBUG_MAC80211(priv
, "enable hwcrypto key\n");
3388 ret
= iwl3945_remove_static_key(priv
);
3390 ret
= iwl3945_clear_sta_key_info(priv
, sta_id
);
3391 IWL_DEBUG_MAC80211(priv
, "disable hwcrypto key\n");
3397 IWL_DEBUG_MAC80211(priv
, "leave\n");
3402 /*****************************************************************************
3406 *****************************************************************************/
3408 #ifdef CONFIG_IWLWIFI_DEBUG
3411 * The following adds a new attribute to the sysfs representation
3412 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
3413 * used for controlling the debug level.
3415 * See the level definitions in iwl for details.
3417 * The debug_level being managed using sysfs below is a per device debug
3418 * level that is used instead of the global debug level if it (the per
3419 * device debug level) is set.
3421 static ssize_t
show_debug_level(struct device
*d
,
3422 struct device_attribute
*attr
, char *buf
)
3424 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3425 return sprintf(buf
, "0x%08X\n", iwl_get_debug_level(priv
));
3427 static ssize_t
store_debug_level(struct device
*d
,
3428 struct device_attribute
*attr
,
3429 const char *buf
, size_t count
)
3431 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3435 ret
= strict_strtoul(buf
, 0, &val
);
3437 IWL_INFO(priv
, "%s is not in hex or decimal form.\n", buf
);
3439 priv
->debug_level
= val
;
3440 if (iwl_alloc_traffic_mem(priv
))
3442 "Not enough memory to generate traffic log\n");
3444 return strnlen(buf
, count
);
3447 static DEVICE_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
3448 show_debug_level
, store_debug_level
);
3450 #endif /* CONFIG_IWLWIFI_DEBUG */
3452 static ssize_t
show_temperature(struct device
*d
,
3453 struct device_attribute
*attr
, char *buf
)
3455 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3457 if (!iwl_is_alive(priv
))
3460 return sprintf(buf
, "%d\n", iwl3945_hw_get_temperature(priv
));
3463 static DEVICE_ATTR(temperature
, S_IRUGO
, show_temperature
, NULL
);
3465 static ssize_t
show_tx_power(struct device
*d
,
3466 struct device_attribute
*attr
, char *buf
)
3468 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3469 return sprintf(buf
, "%d\n", priv
->tx_power_user_lmt
);
3472 static ssize_t
store_tx_power(struct device
*d
,
3473 struct device_attribute
*attr
,
3474 const char *buf
, size_t count
)
3476 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3477 char *p
= (char *)buf
;
3480 val
= simple_strtoul(p
, &p
, 10);
3482 IWL_INFO(priv
, ": %s is not in decimal form.\n", buf
);
3484 iwl3945_hw_reg_set_txpower(priv
, val
);
3489 static DEVICE_ATTR(tx_power
, S_IWUSR
| S_IRUGO
, show_tx_power
, store_tx_power
);
3491 static ssize_t
show_flags(struct device
*d
,
3492 struct device_attribute
*attr
, char *buf
)
3494 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3496 return sprintf(buf
, "0x%04X\n", priv
->active_rxon
.flags
);
3499 static ssize_t
store_flags(struct device
*d
,
3500 struct device_attribute
*attr
,
3501 const char *buf
, size_t count
)
3503 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3504 u32 flags
= simple_strtoul(buf
, NULL
, 0);
3506 mutex_lock(&priv
->mutex
);
3507 if (le32_to_cpu(priv
->staging_rxon
.flags
) != flags
) {
3508 /* Cancel any currently running scans... */
3509 if (iwl_scan_cancel_timeout(priv
, 100))
3510 IWL_WARN(priv
, "Could not cancel scan.\n");
3512 IWL_DEBUG_INFO(priv
, "Committing rxon.flags = 0x%04X\n",
3514 priv
->staging_rxon
.flags
= cpu_to_le32(flags
);
3515 iwlcore_commit_rxon(priv
);
3518 mutex_unlock(&priv
->mutex
);
3523 static DEVICE_ATTR(flags
, S_IWUSR
| S_IRUGO
, show_flags
, store_flags
);
3525 static ssize_t
show_filter_flags(struct device
*d
,
3526 struct device_attribute
*attr
, char *buf
)
3528 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3530 return sprintf(buf
, "0x%04X\n",
3531 le32_to_cpu(priv
->active_rxon
.filter_flags
));
3534 static ssize_t
store_filter_flags(struct device
*d
,
3535 struct device_attribute
*attr
,
3536 const char *buf
, size_t count
)
3538 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3539 u32 filter_flags
= simple_strtoul(buf
, NULL
, 0);
3541 mutex_lock(&priv
->mutex
);
3542 if (le32_to_cpu(priv
->staging_rxon
.filter_flags
) != filter_flags
) {
3543 /* Cancel any currently running scans... */
3544 if (iwl_scan_cancel_timeout(priv
, 100))
3545 IWL_WARN(priv
, "Could not cancel scan.\n");
3547 IWL_DEBUG_INFO(priv
, "Committing rxon.filter_flags = "
3548 "0x%04X\n", filter_flags
);
3549 priv
->staging_rxon
.filter_flags
=
3550 cpu_to_le32(filter_flags
);
3551 iwlcore_commit_rxon(priv
);
3554 mutex_unlock(&priv
->mutex
);
3559 static DEVICE_ATTR(filter_flags
, S_IWUSR
| S_IRUGO
, show_filter_flags
,
3560 store_filter_flags
);
3562 static ssize_t
show_measurement(struct device
*d
,
3563 struct device_attribute
*attr
, char *buf
)
3565 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3566 struct iwl_spectrum_notification measure_report
;
3567 u32 size
= sizeof(measure_report
), len
= 0, ofs
= 0;
3568 u8
*data
= (u8
*)&measure_report
;
3569 unsigned long flags
;
3571 spin_lock_irqsave(&priv
->lock
, flags
);
3572 if (!(priv
->measurement_status
& MEASUREMENT_READY
)) {
3573 spin_unlock_irqrestore(&priv
->lock
, flags
);
3576 memcpy(&measure_report
, &priv
->measure_report
, size
);
3577 priv
->measurement_status
= 0;
3578 spin_unlock_irqrestore(&priv
->lock
, flags
);
3580 while (size
&& (PAGE_SIZE
- len
)) {
3581 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
3582 PAGE_SIZE
- len
, 1);
3584 if (PAGE_SIZE
- len
)
3588 size
-= min(size
, 16U);
3594 static ssize_t
store_measurement(struct device
*d
,
3595 struct device_attribute
*attr
,
3596 const char *buf
, size_t count
)
3598 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3599 struct ieee80211_measurement_params params
= {
3600 .channel
= le16_to_cpu(priv
->active_rxon
.channel
),
3601 .start_time
= cpu_to_le64(priv
->last_tsf
),
3602 .duration
= cpu_to_le16(1),
3604 u8 type
= IWL_MEASURE_BASIC
;
3610 strncpy(buffer
, buf
, min(sizeof(buffer
), count
));
3611 channel
= simple_strtoul(p
, NULL
, 0);
3613 params
.channel
= channel
;
3616 while (*p
&& *p
!= ' ')
3619 type
= simple_strtoul(p
+ 1, NULL
, 0);
3622 IWL_DEBUG_INFO(priv
, "Invoking measurement of type %d on "
3623 "channel %d (for '%s')\n", type
, params
.channel
, buf
);
3624 iwl3945_get_measurement(priv
, ¶ms
, type
);
3629 static DEVICE_ATTR(measurement
, S_IRUSR
| S_IWUSR
,
3630 show_measurement
, store_measurement
);
3632 static ssize_t
store_retry_rate(struct device
*d
,
3633 struct device_attribute
*attr
,
3634 const char *buf
, size_t count
)
3636 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3638 priv
->retry_rate
= simple_strtoul(buf
, NULL
, 0);
3639 if (priv
->retry_rate
<= 0)
3640 priv
->retry_rate
= 1;
3645 static ssize_t
show_retry_rate(struct device
*d
,
3646 struct device_attribute
*attr
, char *buf
)
3648 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3649 return sprintf(buf
, "%d", priv
->retry_rate
);
3652 static DEVICE_ATTR(retry_rate
, S_IWUSR
| S_IRUSR
, show_retry_rate
,
3656 static ssize_t
show_channels(struct device
*d
,
3657 struct device_attribute
*attr
, char *buf
)
3659 /* all this shit doesn't belong into sysfs anyway */
3663 static DEVICE_ATTR(channels
, S_IRUSR
, show_channels
, NULL
);
3665 static ssize_t
show_statistics(struct device
*d
,
3666 struct device_attribute
*attr
, char *buf
)
3668 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3669 u32 size
= sizeof(struct iwl3945_notif_statistics
);
3670 u32 len
= 0, ofs
= 0;
3671 u8
*data
= (u8
*)&priv
->statistics_39
;
3674 if (!iwl_is_alive(priv
))
3677 mutex_lock(&priv
->mutex
);
3678 rc
= iwl_send_statistics_request(priv
, CMD_SYNC
, false);
3679 mutex_unlock(&priv
->mutex
);
3683 "Error sending statistics request: 0x%08X\n", rc
);
3687 while (size
&& (PAGE_SIZE
- len
)) {
3688 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
3689 PAGE_SIZE
- len
, 1);
3691 if (PAGE_SIZE
- len
)
3695 size
-= min(size
, 16U);
3701 static DEVICE_ATTR(statistics
, S_IRUGO
, show_statistics
, NULL
);
3703 static ssize_t
show_antenna(struct device
*d
,
3704 struct device_attribute
*attr
, char *buf
)
3706 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3708 if (!iwl_is_alive(priv
))
3711 return sprintf(buf
, "%d\n", iwl3945_mod_params
.antenna
);
3714 static ssize_t
store_antenna(struct device
*d
,
3715 struct device_attribute
*attr
,
3716 const char *buf
, size_t count
)
3718 struct iwl_priv
*priv __maybe_unused
= dev_get_drvdata(d
);
3724 if (sscanf(buf
, "%1i", &ant
) != 1) {
3725 IWL_DEBUG_INFO(priv
, "not in hex or decimal form.\n");
3729 if ((ant
>= 0) && (ant
<= 2)) {
3730 IWL_DEBUG_INFO(priv
, "Setting antenna select to %d.\n", ant
);
3731 iwl3945_mod_params
.antenna
= (enum iwl3945_antenna
)ant
;
3733 IWL_DEBUG_INFO(priv
, "Bad antenna select value %d.\n", ant
);
3739 static DEVICE_ATTR(antenna
, S_IWUSR
| S_IRUGO
, show_antenna
, store_antenna
);
3741 static ssize_t
show_status(struct device
*d
,
3742 struct device_attribute
*attr
, char *buf
)
3744 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3745 if (!iwl_is_alive(priv
))
3747 return sprintf(buf
, "0x%08x\n", (int)priv
->status
);
3750 static DEVICE_ATTR(status
, S_IRUGO
, show_status
, NULL
);
3752 static ssize_t
dump_error_log(struct device
*d
,
3753 struct device_attribute
*attr
,
3754 const char *buf
, size_t count
)
3756 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3757 char *p
= (char *)buf
;
3760 iwl3945_dump_nic_error_log(priv
);
3762 return strnlen(buf
, count
);
3765 static DEVICE_ATTR(dump_errors
, S_IWUSR
, NULL
, dump_error_log
);
3767 /*****************************************************************************
3769 * driver setup and tear down
3771 *****************************************************************************/
3773 static void iwl3945_setup_deferred_work(struct iwl_priv
*priv
)
3775 priv
->workqueue
= create_singlethread_workqueue(DRV_NAME
);
3777 init_waitqueue_head(&priv
->wait_command_queue
);
3779 INIT_WORK(&priv
->restart
, iwl3945_bg_restart
);
3780 INIT_WORK(&priv
->rx_replenish
, iwl3945_bg_rx_replenish
);
3781 INIT_WORK(&priv
->beacon_update
, iwl3945_bg_beacon_update
);
3782 INIT_DELAYED_WORK(&priv
->init_alive_start
, iwl3945_bg_init_alive_start
);
3783 INIT_DELAYED_WORK(&priv
->alive_start
, iwl3945_bg_alive_start
);
3784 INIT_DELAYED_WORK(&priv
->rfkill_poll
, iwl3945_rfkill_poll
);
3785 INIT_WORK(&priv
->scan_completed
, iwl_bg_scan_completed
);
3786 INIT_WORK(&priv
->request_scan
, iwl3945_bg_request_scan
);
3787 INIT_WORK(&priv
->abort_scan
, iwl_bg_abort_scan
);
3788 INIT_DELAYED_WORK(&priv
->scan_check
, iwl_bg_scan_check
);
3790 iwl3945_hw_setup_deferred_work(priv
);
3792 tasklet_init(&priv
->irq_tasklet
, (void (*)(unsigned long))
3793 iwl3945_irq_tasklet
, (unsigned long)priv
);
3796 static void iwl3945_cancel_deferred_work(struct iwl_priv
*priv
)
3798 iwl3945_hw_cancel_deferred_work(priv
);
3800 cancel_delayed_work_sync(&priv
->init_alive_start
);
3801 cancel_delayed_work(&priv
->scan_check
);
3802 cancel_delayed_work(&priv
->alive_start
);
3803 cancel_work_sync(&priv
->beacon_update
);
3806 static struct attribute
*iwl3945_sysfs_entries
[] = {
3807 &dev_attr_antenna
.attr
,
3808 &dev_attr_channels
.attr
,
3809 &dev_attr_dump_errors
.attr
,
3810 &dev_attr_flags
.attr
,
3811 &dev_attr_filter_flags
.attr
,
3812 &dev_attr_measurement
.attr
,
3813 &dev_attr_retry_rate
.attr
,
3814 &dev_attr_statistics
.attr
,
3815 &dev_attr_status
.attr
,
3816 &dev_attr_temperature
.attr
,
3817 &dev_attr_tx_power
.attr
,
3818 #ifdef CONFIG_IWLWIFI_DEBUG
3819 &dev_attr_debug_level
.attr
,
3824 static struct attribute_group iwl3945_attribute_group
= {
3825 .name
= NULL
, /* put in device directory */
3826 .attrs
= iwl3945_sysfs_entries
,
3829 static struct ieee80211_ops iwl3945_hw_ops
= {
3830 .tx
= iwl3945_mac_tx
,
3831 .start
= iwl3945_mac_start
,
3832 .stop
= iwl3945_mac_stop
,
3833 .add_interface
= iwl_mac_add_interface
,
3834 .remove_interface
= iwl_mac_remove_interface
,
3835 .config
= iwl_mac_config
,
3836 .configure_filter
= iwl_configure_filter
,
3837 .set_key
= iwl3945_mac_set_key
,
3838 .get_tx_stats
= iwl_mac_get_tx_stats
,
3839 .conf_tx
= iwl_mac_conf_tx
,
3840 .reset_tsf
= iwl_mac_reset_tsf
,
3841 .bss_info_changed
= iwl_bss_info_changed
,
3842 .hw_scan
= iwl_mac_hw_scan
3845 static int iwl3945_init_drv(struct iwl_priv
*priv
)
3848 struct iwl3945_eeprom
*eeprom
= (struct iwl3945_eeprom
*)priv
->eeprom
;
3850 priv
->retry_rate
= 1;
3851 priv
->ibss_beacon
= NULL
;
3853 spin_lock_init(&priv
->sta_lock
);
3854 spin_lock_init(&priv
->hcmd_lock
);
3856 INIT_LIST_HEAD(&priv
->free_frames
);
3858 mutex_init(&priv
->mutex
);
3860 /* Clear the driver's (not device's) station table */
3861 iwl_clear_stations_table(priv
);
3863 priv
->ieee_channels
= NULL
;
3864 priv
->ieee_rates
= NULL
;
3865 priv
->band
= IEEE80211_BAND_2GHZ
;
3867 priv
->iw_mode
= NL80211_IFTYPE_STATION
;
3868 priv
->missed_beacon_threshold
= IWL_MISSED_BEACON_THRESHOLD_DEF
;
3870 iwl_reset_qos(priv
);
3872 priv
->qos_data
.qos_active
= 0;
3873 priv
->qos_data
.qos_cap
.val
= 0;
3875 priv
->rates_mask
= IWL_RATES_MASK
;
3876 priv
->tx_power_user_lmt
= IWL_DEFAULT_TX_POWER
;
3878 if (eeprom
->version
< EEPROM_3945_EEPROM_VERSION
) {
3879 IWL_WARN(priv
, "Unsupported EEPROM version: 0x%04X\n",
3884 ret
= iwl_init_channel_map(priv
);
3886 IWL_ERR(priv
, "initializing regulatory failed: %d\n", ret
);
3890 /* Set up txpower settings in driver for all channels */
3891 if (iwl3945_txpower_set_from_eeprom(priv
)) {
3893 goto err_free_channel_map
;
3896 ret
= iwlcore_init_geos(priv
);
3898 IWL_ERR(priv
, "initializing geos failed: %d\n", ret
);
3899 goto err_free_channel_map
;
3901 iwl3945_init_hw_rates(priv
, priv
->ieee_rates
);
3905 err_free_channel_map
:
3906 iwl_free_channel_map(priv
);
3911 static int iwl3945_setup_mac(struct iwl_priv
*priv
)
3914 struct ieee80211_hw
*hw
= priv
->hw
;
3916 hw
->rate_control_algorithm
= "iwl-3945-rs";
3917 hw
->sta_data_size
= sizeof(struct iwl3945_sta_priv
);
3919 /* Tell mac80211 our characteristics */
3920 hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
3921 IEEE80211_HW_NOISE_DBM
|
3922 IEEE80211_HW_SPECTRUM_MGMT
;
3924 if (!priv
->cfg
->broken_powersave
)
3925 hw
->flags
|= IEEE80211_HW_SUPPORTS_PS
|
3926 IEEE80211_HW_SUPPORTS_DYNAMIC_PS
;
3928 hw
->wiphy
->interface_modes
=
3929 BIT(NL80211_IFTYPE_STATION
) |
3930 BIT(NL80211_IFTYPE_ADHOC
);
3932 hw
->wiphy
->flags
|= WIPHY_FLAG_STRICT_REGULATORY
|
3933 WIPHY_FLAG_DISABLE_BEACON_HINTS
;
3935 hw
->wiphy
->max_scan_ssids
= PROBE_OPTION_MAX_3945
;
3936 /* we create the 802.11 header and a zero-length SSID element */
3937 hw
->wiphy
->max_scan_ie_len
= IWL_MAX_PROBE_REQUEST
- 24 - 2;
3939 /* Default value; 4 EDCA QOS priorities */
3942 if (priv
->bands
[IEEE80211_BAND_2GHZ
].n_channels
)
3943 priv
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
3944 &priv
->bands
[IEEE80211_BAND_2GHZ
];
3946 if (priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
)
3947 priv
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
3948 &priv
->bands
[IEEE80211_BAND_5GHZ
];
3950 ret
= ieee80211_register_hw(priv
->hw
);
3952 IWL_ERR(priv
, "Failed to register hw (error %d)\n", ret
);
3955 priv
->mac80211_registered
= 1;
3960 static int iwl3945_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
3963 struct iwl_priv
*priv
;
3964 struct ieee80211_hw
*hw
;
3965 struct iwl_cfg
*cfg
= (struct iwl_cfg
*)(ent
->driver_data
);
3966 struct iwl3945_eeprom
*eeprom
;
3967 unsigned long flags
;
3969 /***********************
3970 * 1. Allocating HW data
3971 * ********************/
3973 /* mac80211 allocates memory for this device instance, including
3974 * space for this driver's private structure */
3975 hw
= iwl_alloc_all(cfg
, &iwl3945_hw_ops
);
3977 printk(KERN_ERR DRV_NAME
"Can not allocate network device\n");
3982 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
3985 * Disabling hardware scan means that mac80211 will perform scans
3986 * "the hard way", rather than using device's scan.
3988 if (iwl3945_mod_params
.disable_hw_scan
) {
3989 IWL_DEBUG_INFO(priv
, "Disabling hw_scan\n");
3990 iwl3945_hw_ops
.hw_scan
= NULL
;
3994 IWL_DEBUG_INFO(priv
, "*** LOAD DRIVER ***\n");
3996 priv
->pci_dev
= pdev
;
3997 priv
->inta_mask
= CSR_INI_SET_MASK
;
3999 #ifdef CONFIG_IWLWIFI_DEBUG
4000 atomic_set(&priv
->restrict_refcnt
, 0);
4002 if (iwl_alloc_traffic_mem(priv
))
4003 IWL_ERR(priv
, "Not enough memory to generate traffic log\n");
4005 /***************************
4006 * 2. Initializing PCI bus
4007 * *************************/
4008 if (pci_enable_device(pdev
)) {
4010 goto out_ieee80211_free_hw
;
4013 pci_set_master(pdev
);
4015 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
4017 err
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
4019 IWL_WARN(priv
, "No suitable DMA available.\n");
4020 goto out_pci_disable_device
;
4023 pci_set_drvdata(pdev
, priv
);
4024 err
= pci_request_regions(pdev
, DRV_NAME
);
4026 goto out_pci_disable_device
;
4028 /***********************
4029 * 3. Read REV Register
4030 * ********************/
4031 priv
->hw_base
= pci_iomap(pdev
, 0, 0);
4032 if (!priv
->hw_base
) {
4034 goto out_pci_release_regions
;
4037 IWL_DEBUG_INFO(priv
, "pci_resource_len = 0x%08llx\n",
4038 (unsigned long long) pci_resource_len(pdev
, 0));
4039 IWL_DEBUG_INFO(priv
, "pci_resource_base = %p\n", priv
->hw_base
);
4041 /* We disable the RETRY_TIMEOUT register (0x41) to keep
4042 * PCI Tx retries from interfering with C3 CPU state */
4043 pci_write_config_byte(pdev
, 0x41, 0x00);
4045 /* these spin locks will be used in apm_ops.init and EEPROM access
4046 * we should init now
4048 spin_lock_init(&priv
->reg_lock
);
4049 spin_lock_init(&priv
->lock
);
4051 /***********************
4053 * ********************/
4055 /* Read the EEPROM */
4056 err
= iwl_eeprom_init(priv
);
4058 IWL_ERR(priv
, "Unable to init EEPROM\n");
4061 /* MAC Address location in EEPROM same for 3945/4965 */
4062 eeprom
= (struct iwl3945_eeprom
*)priv
->eeprom
;
4063 memcpy(priv
->mac_addr
, eeprom
->mac_address
, ETH_ALEN
);
4064 IWL_DEBUG_INFO(priv
, "MAC address: %pM\n", priv
->mac_addr
);
4065 SET_IEEE80211_PERM_ADDR(priv
->hw
, priv
->mac_addr
);
4067 /***********************
4068 * 5. Setup HW Constants
4069 * ********************/
4070 /* Device-specific setup */
4071 if (iwl3945_hw_set_hw_params(priv
)) {
4072 IWL_ERR(priv
, "failed to set hw settings\n");
4073 goto out_eeprom_free
;
4076 /***********************
4078 * ********************/
4080 err
= iwl3945_init_drv(priv
);
4082 IWL_ERR(priv
, "initializing driver failed\n");
4083 goto out_unset_hw_params
;
4086 IWL_INFO(priv
, "Detected Intel Wireless WiFi Link %s\n",
4089 /***********************
4091 * ********************/
4093 spin_lock_irqsave(&priv
->lock
, flags
);
4094 iwl_disable_interrupts(priv
);
4095 spin_unlock_irqrestore(&priv
->lock
, flags
);
4097 pci_enable_msi(priv
->pci_dev
);
4099 err
= request_irq(priv
->pci_dev
->irq
, priv
->cfg
->ops
->lib
->isr
,
4100 IRQF_SHARED
, DRV_NAME
, priv
);
4102 IWL_ERR(priv
, "Error allocating IRQ %d\n", priv
->pci_dev
->irq
);
4103 goto out_disable_msi
;
4106 err
= sysfs_create_group(&pdev
->dev
.kobj
, &iwl3945_attribute_group
);
4108 IWL_ERR(priv
, "failed to create sysfs device attributes\n");
4109 goto out_release_irq
;
4112 iwl_set_rxon_channel(priv
,
4113 &priv
->bands
[IEEE80211_BAND_2GHZ
].channels
[5]);
4114 iwl3945_setup_deferred_work(priv
);
4115 iwl3945_setup_rx_handlers(priv
);
4116 iwl_power_initialize(priv
);
4118 /*********************************
4119 * 8. Setup and Register mac80211
4120 * *******************************/
4122 iwl_enable_interrupts(priv
);
4124 err
= iwl3945_setup_mac(priv
);
4126 goto out_remove_sysfs
;
4128 err
= iwl_dbgfs_register(priv
, DRV_NAME
);
4130 IWL_ERR(priv
, "failed to create debugfs files. Ignoring error: %d\n", err
);
4132 /* Start monitoring the killswitch */
4133 queue_delayed_work(priv
->workqueue
, &priv
->rfkill_poll
,
4139 destroy_workqueue(priv
->workqueue
);
4140 priv
->workqueue
= NULL
;
4141 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl3945_attribute_group
);
4143 free_irq(priv
->pci_dev
->irq
, priv
);
4145 pci_disable_msi(priv
->pci_dev
);
4146 iwlcore_free_geos(priv
);
4147 iwl_free_channel_map(priv
);
4148 out_unset_hw_params
:
4149 iwl3945_unset_hw_params(priv
);
4151 iwl_eeprom_free(priv
);
4153 pci_iounmap(pdev
, priv
->hw_base
);
4154 out_pci_release_regions
:
4155 pci_release_regions(pdev
);
4156 out_pci_disable_device
:
4157 pci_set_drvdata(pdev
, NULL
);
4158 pci_disable_device(pdev
);
4159 out_ieee80211_free_hw
:
4160 iwl_free_traffic_mem(priv
);
4161 ieee80211_free_hw(priv
->hw
);
4166 static void __devexit
iwl3945_pci_remove(struct pci_dev
*pdev
)
4168 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
4169 unsigned long flags
;
4174 IWL_DEBUG_INFO(priv
, "*** UNLOAD DRIVER ***\n");
4176 iwl_dbgfs_unregister(priv
);
4178 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
4180 if (priv
->mac80211_registered
) {
4181 ieee80211_unregister_hw(priv
->hw
);
4182 priv
->mac80211_registered
= 0;
4188 * Make sure device is reset to low power before unloading driver.
4189 * This may be redundant with iwl_down(), but there are paths to
4190 * run iwl_down() without calling apm_ops.stop(), and there are
4191 * paths to avoid running iwl_down() at all before leaving driver.
4192 * This (inexpensive) call *makes sure* device is reset.
4194 priv
->cfg
->ops
->lib
->apm_ops
.stop(priv
);
4196 /* make sure we flush any pending irq or
4197 * tasklet for the driver
4199 spin_lock_irqsave(&priv
->lock
, flags
);
4200 iwl_disable_interrupts(priv
);
4201 spin_unlock_irqrestore(&priv
->lock
, flags
);
4203 iwl_synchronize_irq(priv
);
4205 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl3945_attribute_group
);
4207 cancel_delayed_work_sync(&priv
->rfkill_poll
);
4209 iwl3945_dealloc_ucode_pci(priv
);
4212 iwl3945_rx_queue_free(priv
, &priv
->rxq
);
4213 iwl3945_hw_txq_ctx_free(priv
);
4215 iwl3945_unset_hw_params(priv
);
4216 iwl_clear_stations_table(priv
);
4218 /*netif_stop_queue(dev); */
4219 flush_workqueue(priv
->workqueue
);
4221 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
4222 * priv->workqueue... so we can't take down the workqueue
4224 destroy_workqueue(priv
->workqueue
);
4225 priv
->workqueue
= NULL
;
4226 iwl_free_traffic_mem(priv
);
4228 free_irq(pdev
->irq
, priv
);
4229 pci_disable_msi(pdev
);
4231 pci_iounmap(pdev
, priv
->hw_base
);
4232 pci_release_regions(pdev
);
4233 pci_disable_device(pdev
);
4234 pci_set_drvdata(pdev
, NULL
);
4236 iwl_free_channel_map(priv
);
4237 iwlcore_free_geos(priv
);
4239 if (priv
->ibss_beacon
)
4240 dev_kfree_skb(priv
->ibss_beacon
);
4242 ieee80211_free_hw(priv
->hw
);
4246 /*****************************************************************************
4248 * driver and module entry point
4250 *****************************************************************************/
4252 static struct pci_driver iwl3945_driver
= {
4254 .id_table
= iwl3945_hw_card_ids
,
4255 .probe
= iwl3945_pci_probe
,
4256 .remove
= __devexit_p(iwl3945_pci_remove
),
4258 .suspend
= iwl_pci_suspend
,
4259 .resume
= iwl_pci_resume
,
4263 static int __init
iwl3945_init(void)
4267 printk(KERN_INFO DRV_NAME
": " DRV_DESCRIPTION
", " DRV_VERSION
"\n");
4268 printk(KERN_INFO DRV_NAME
": " DRV_COPYRIGHT
"\n");
4270 ret
= iwl3945_rate_control_register();
4272 printk(KERN_ERR DRV_NAME
4273 "Unable to register rate control algorithm: %d\n", ret
);
4277 ret
= pci_register_driver(&iwl3945_driver
);
4279 printk(KERN_ERR DRV_NAME
"Unable to initialize PCI module\n");
4280 goto error_register
;
4286 iwl3945_rate_control_unregister();
4290 static void __exit
iwl3945_exit(void)
4292 pci_unregister_driver(&iwl3945_driver
);
4293 iwl3945_rate_control_unregister();
4296 MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX
));
4298 module_param_named(antenna
, iwl3945_mod_params
.antenna
, int, S_IRUGO
);
4299 MODULE_PARM_DESC(antenna
, "select antenna (1=Main, 2=Aux, default 0 [both])");
4300 module_param_named(swcrypto
, iwl3945_mod_params
.sw_crypto
, int, S_IRUGO
);
4301 MODULE_PARM_DESC(swcrypto
,
4302 "using software crypto (default 1 [software])\n");
4303 #ifdef CONFIG_IWLWIFI_DEBUG
4304 module_param_named(debug
, iwl_debug_level
, uint
, S_IRUGO
| S_IWUSR
);
4305 MODULE_PARM_DESC(debug
, "debug output mask");
4307 module_param_named(disable_hw_scan
, iwl3945_mod_params
.disable_hw_scan
,
4309 MODULE_PARM_DESC(disable_hw_scan
, "disable hardware scanning (default 0)");
4310 module_param_named(fw_restart3945
, iwl3945_mod_params
.restart_fw
, int, S_IRUGO
);
4311 MODULE_PARM_DESC(fw_restart3945
, "restart firmware in case of error");
4313 module_exit(iwl3945_exit
);
4314 module_init(iwl3945_init
);