1 /******************************************************************************
3 * Copyright(c) 2003 - 2011 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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32 #include <linux/kernel.h>
33 #include <linux/module.h>
34 #include <linux/init.h>
35 #include <linux/pci.h>
36 #include <linux/pci-aspm.h>
37 #include <linux/slab.h>
38 #include <linux/dma-mapping.h>
39 #include <linux/delay.h>
40 #include <linux/sched.h>
41 #include <linux/skbuff.h>
42 #include <linux/netdevice.h>
43 #include <linux/firmware.h>
44 #include <linux/etherdevice.h>
45 #include <linux/if_arp.h>
47 #include <net/ieee80211_radiotap.h>
48 #include <net/mac80211.h>
50 #include <asm/div64.h>
52 #define DRV_NAME "iwl3945"
55 #include "iwl-3945-fh.h"
56 #include "iwl-commands.h"
60 #include "iwl-helpers.h"
62 #include "iwl-spectrum.h"
65 * module name, copyright, version, etc.
68 #define DRV_DESCRIPTION \
69 "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
71 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
78 * add "s" to indicate spectrum measurement included.
79 * we add it here to be consistent with previous releases in which
80 * this was configurable.
82 #define DRV_VERSION IWLWIFI_VERSION VD "s"
83 #define DRV_COPYRIGHT "Copyright(c) 2003-2011 Intel Corporation"
84 #define DRV_AUTHOR "<ilw@linux.intel.com>"
86 MODULE_DESCRIPTION(DRV_DESCRIPTION
);
87 MODULE_VERSION(DRV_VERSION
);
88 MODULE_AUTHOR(DRV_COPYRIGHT
" " DRV_AUTHOR
);
89 MODULE_LICENSE("GPL");
91 /* module parameters */
92 struct iwl_mod_params iwl3945_mod_params
= {
96 /* the rest are 0 by default */
100 * iwl3945_get_antenna_flags - Get antenna flags for RXON command
101 * @priv: eeprom and antenna fields are used to determine antenna flags
103 * priv->eeprom39 is used to determine if antenna AUX/MAIN are reversed
104 * iwl3945_mod_params.antenna specifies the antenna diversity mode:
106 * IWL_ANTENNA_DIVERSITY - NIC selects best antenna by itself
107 * IWL_ANTENNA_MAIN - Force MAIN antenna
108 * IWL_ANTENNA_AUX - Force AUX antenna
110 __le32
iwl3945_get_antenna_flags(const struct iwl_priv
*priv
)
112 struct iwl3945_eeprom
*eeprom
= (struct iwl3945_eeprom
*)priv
->eeprom
;
114 switch (iwl3945_mod_params
.antenna
) {
115 case IWL_ANTENNA_DIVERSITY
:
118 case IWL_ANTENNA_MAIN
:
119 if (eeprom
->antenna_switch_type
)
120 return RXON_FLG_DIS_DIV_MSK
| RXON_FLG_ANT_B_MSK
;
121 return RXON_FLG_DIS_DIV_MSK
| RXON_FLG_ANT_A_MSK
;
123 case IWL_ANTENNA_AUX
:
124 if (eeprom
->antenna_switch_type
)
125 return RXON_FLG_DIS_DIV_MSK
| RXON_FLG_ANT_A_MSK
;
126 return RXON_FLG_DIS_DIV_MSK
| RXON_FLG_ANT_B_MSK
;
129 /* bad antenna selector value */
130 IWL_ERR(priv
, "Bad antenna selector value (0x%x)\n",
131 iwl3945_mod_params
.antenna
);
133 return 0; /* "diversity" is default if error */
136 static int iwl3945_set_ccmp_dynamic_key_info(struct iwl_priv
*priv
,
137 struct ieee80211_key_conf
*keyconf
,
141 __le16 key_flags
= 0;
144 key_flags
|= (STA_KEY_FLG_CCMP
| STA_KEY_FLG_MAP_KEY_MSK
);
145 key_flags
|= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
147 if (sta_id
== priv
->contexts
[IWL_RXON_CTX_BSS
].bcast_sta_id
)
148 key_flags
|= STA_KEY_MULTICAST_MSK
;
150 keyconf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
151 keyconf
->hw_key_idx
= keyconf
->keyidx
;
152 key_flags
&= ~STA_KEY_FLG_INVALID
;
154 spin_lock_irqsave(&priv
->sta_lock
, flags
);
155 priv
->stations
[sta_id
].keyinfo
.cipher
= keyconf
->cipher
;
156 priv
->stations
[sta_id
].keyinfo
.keylen
= keyconf
->keylen
;
157 memcpy(priv
->stations
[sta_id
].keyinfo
.key
, keyconf
->key
,
160 memcpy(priv
->stations
[sta_id
].sta
.key
.key
, keyconf
->key
,
163 if ((priv
->stations
[sta_id
].sta
.key
.key_flags
& STA_KEY_FLG_ENCRYPT_MSK
)
164 == STA_KEY_FLG_NO_ENC
)
165 priv
->stations
[sta_id
].sta
.key
.key_offset
=
166 iwl_legacy_get_free_ucode_key_index(priv
);
167 /* else, we are overriding an existing key => no need to allocated room
170 WARN(priv
->stations
[sta_id
].sta
.key
.key_offset
== WEP_INVALID_OFFSET
,
171 "no space for a new key");
173 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
174 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
175 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
177 IWL_DEBUG_INFO(priv
, "hwcrypto: modify ucode station key info\n");
179 ret
= iwl_legacy_send_add_sta(priv
,
180 &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
182 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
187 static int iwl3945_set_tkip_dynamic_key_info(struct iwl_priv
*priv
,
188 struct ieee80211_key_conf
*keyconf
,
194 static int iwl3945_set_wep_dynamic_key_info(struct iwl_priv
*priv
,
195 struct ieee80211_key_conf
*keyconf
,
201 static int iwl3945_clear_sta_key_info(struct iwl_priv
*priv
, u8 sta_id
)
204 struct iwl_legacy_addsta_cmd sta_cmd
;
206 spin_lock_irqsave(&priv
->sta_lock
, flags
);
207 memset(&priv
->stations
[sta_id
].keyinfo
, 0, sizeof(struct iwl_hw_key
));
208 memset(&priv
->stations
[sta_id
].sta
.key
, 0,
209 sizeof(struct iwl4965_keyinfo
));
210 priv
->stations
[sta_id
].sta
.key
.key_flags
= STA_KEY_FLG_NO_ENC
;
211 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
212 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
213 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_legacy_addsta_cmd
));
214 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
216 IWL_DEBUG_INFO(priv
, "hwcrypto: clear ucode station key info\n");
217 return iwl_legacy_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
220 static int iwl3945_set_dynamic_key(struct iwl_priv
*priv
,
221 struct ieee80211_key_conf
*keyconf
, u8 sta_id
)
225 keyconf
->hw_key_idx
= HW_KEY_DYNAMIC
;
227 switch (keyconf
->cipher
) {
228 case WLAN_CIPHER_SUITE_CCMP
:
229 ret
= iwl3945_set_ccmp_dynamic_key_info(priv
, keyconf
, sta_id
);
231 case WLAN_CIPHER_SUITE_TKIP
:
232 ret
= iwl3945_set_tkip_dynamic_key_info(priv
, keyconf
, sta_id
);
234 case WLAN_CIPHER_SUITE_WEP40
:
235 case WLAN_CIPHER_SUITE_WEP104
:
236 ret
= iwl3945_set_wep_dynamic_key_info(priv
, keyconf
, sta_id
);
239 IWL_ERR(priv
, "Unknown alg: %s alg=%x\n", __func__
,
244 IWL_DEBUG_WEP(priv
, "Set dynamic key: alg=%x len=%d idx=%d sta=%d ret=%d\n",
245 keyconf
->cipher
, keyconf
->keylen
, keyconf
->keyidx
,
251 static int iwl3945_remove_static_key(struct iwl_priv
*priv
)
253 int ret
= -EOPNOTSUPP
;
258 static int iwl3945_set_static_key(struct iwl_priv
*priv
,
259 struct ieee80211_key_conf
*key
)
261 if (key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
262 key
->cipher
== WLAN_CIPHER_SUITE_WEP104
)
265 IWL_ERR(priv
, "Static key invalid: cipher %x\n", key
->cipher
);
269 static void iwl3945_clear_free_frames(struct iwl_priv
*priv
)
271 struct list_head
*element
;
273 IWL_DEBUG_INFO(priv
, "%d frames on pre-allocated heap on clear.\n",
276 while (!list_empty(&priv
->free_frames
)) {
277 element
= priv
->free_frames
.next
;
279 kfree(list_entry(element
, struct iwl3945_frame
, list
));
280 priv
->frames_count
--;
283 if (priv
->frames_count
) {
284 IWL_WARN(priv
, "%d frames still in use. Did we lose one?\n",
286 priv
->frames_count
= 0;
290 static struct iwl3945_frame
*iwl3945_get_free_frame(struct iwl_priv
*priv
)
292 struct iwl3945_frame
*frame
;
293 struct list_head
*element
;
294 if (list_empty(&priv
->free_frames
)) {
295 frame
= kzalloc(sizeof(*frame
), GFP_KERNEL
);
297 IWL_ERR(priv
, "Could not allocate frame!\n");
301 priv
->frames_count
++;
305 element
= priv
->free_frames
.next
;
307 return list_entry(element
, struct iwl3945_frame
, list
);
310 static void iwl3945_free_frame(struct iwl_priv
*priv
, struct iwl3945_frame
*frame
)
312 memset(frame
, 0, sizeof(*frame
));
313 list_add(&frame
->list
, &priv
->free_frames
);
316 unsigned int iwl3945_fill_beacon_frame(struct iwl_priv
*priv
,
317 struct ieee80211_hdr
*hdr
,
321 if (!iwl_legacy_is_associated(priv
, IWL_RXON_CTX_BSS
) || !priv
->beacon_skb
)
324 if (priv
->beacon_skb
->len
> left
)
327 memcpy(hdr
, priv
->beacon_skb
->data
, priv
->beacon_skb
->len
);
329 return priv
->beacon_skb
->len
;
332 static int iwl3945_send_beacon_cmd(struct iwl_priv
*priv
)
334 struct iwl3945_frame
*frame
;
335 unsigned int frame_size
;
339 frame
= iwl3945_get_free_frame(priv
);
342 IWL_ERR(priv
, "Could not obtain free frame buffer for beacon "
347 rate
= iwl_legacy_get_lowest_plcp(priv
,
348 &priv
->contexts
[IWL_RXON_CTX_BSS
]);
350 frame_size
= iwl3945_hw_get_beacon_cmd(priv
, frame
, rate
);
352 rc
= iwl_legacy_send_cmd_pdu(priv
, REPLY_TX_BEACON
, frame_size
,
355 iwl3945_free_frame(priv
, frame
);
360 static void iwl3945_unset_hw_params(struct iwl_priv
*priv
)
362 if (priv
->_3945
.shared_virt
)
363 dma_free_coherent(&priv
->pci_dev
->dev
,
364 sizeof(struct iwl3945_shared
),
365 priv
->_3945
.shared_virt
,
366 priv
->_3945
.shared_phys
);
369 static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv
*priv
,
370 struct ieee80211_tx_info
*info
,
371 struct iwl_device_cmd
*cmd
,
372 struct sk_buff
*skb_frag
,
375 struct iwl3945_tx_cmd
*tx_cmd
= (struct iwl3945_tx_cmd
*)cmd
->cmd
.payload
;
376 struct iwl_hw_key
*keyinfo
= &priv
->stations
[sta_id
].keyinfo
;
380 switch (keyinfo
->cipher
) {
381 case WLAN_CIPHER_SUITE_CCMP
:
382 tx_cmd
->sec_ctl
= TX_CMD_SEC_CCM
;
383 memcpy(tx_cmd
->key
, keyinfo
->key
, keyinfo
->keylen
);
384 IWL_DEBUG_TX(priv
, "tx_cmd with AES hwcrypto\n");
387 case WLAN_CIPHER_SUITE_TKIP
:
390 case WLAN_CIPHER_SUITE_WEP104
:
391 tx_cmd
->sec_ctl
|= TX_CMD_SEC_KEY128
;
393 case WLAN_CIPHER_SUITE_WEP40
:
394 tx_cmd
->sec_ctl
|= TX_CMD_SEC_WEP
|
395 (info
->control
.hw_key
->hw_key_idx
& TX_CMD_SEC_MSK
) << TX_CMD_SEC_SHIFT
;
397 memcpy(&tx_cmd
->key
[3], keyinfo
->key
, keyinfo
->keylen
);
399 IWL_DEBUG_TX(priv
, "Configuring packet for WEP encryption "
400 "with key %d\n", info
->control
.hw_key
->hw_key_idx
);
404 IWL_ERR(priv
, "Unknown encode cipher %x\n", keyinfo
->cipher
);
410 * handle build REPLY_TX command notification.
412 static void iwl3945_build_tx_cmd_basic(struct iwl_priv
*priv
,
413 struct iwl_device_cmd
*cmd
,
414 struct ieee80211_tx_info
*info
,
415 struct ieee80211_hdr
*hdr
, u8 std_id
)
417 struct iwl3945_tx_cmd
*tx_cmd
= (struct iwl3945_tx_cmd
*)cmd
->cmd
.payload
;
418 __le32 tx_flags
= tx_cmd
->tx_flags
;
419 __le16 fc
= hdr
->frame_control
;
421 tx_cmd
->stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
422 if (!(info
->flags
& IEEE80211_TX_CTL_NO_ACK
)) {
423 tx_flags
|= TX_CMD_FLG_ACK_MSK
;
424 if (ieee80211_is_mgmt(fc
))
425 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
426 if (ieee80211_is_probe_resp(fc
) &&
427 !(le16_to_cpu(hdr
->seq_ctrl
) & 0xf))
428 tx_flags
|= TX_CMD_FLG_TSF_MSK
;
430 tx_flags
&= (~TX_CMD_FLG_ACK_MSK
);
431 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
434 tx_cmd
->sta_id
= std_id
;
435 if (ieee80211_has_morefrags(fc
))
436 tx_flags
|= TX_CMD_FLG_MORE_FRAG_MSK
;
438 if (ieee80211_is_data_qos(fc
)) {
439 u8
*qc
= ieee80211_get_qos_ctl(hdr
);
440 tx_cmd
->tid_tspec
= qc
[0] & 0xf;
441 tx_flags
&= ~TX_CMD_FLG_SEQ_CTL_MSK
;
443 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
446 iwl_legacy_tx_cmd_protection(priv
, info
, fc
, &tx_flags
);
448 tx_flags
&= ~(TX_CMD_FLG_ANT_SEL_MSK
);
449 if (ieee80211_is_mgmt(fc
)) {
450 if (ieee80211_is_assoc_req(fc
) || ieee80211_is_reassoc_req(fc
))
451 tx_cmd
->timeout
.pm_frame_timeout
= cpu_to_le16(3);
453 tx_cmd
->timeout
.pm_frame_timeout
= cpu_to_le16(2);
455 tx_cmd
->timeout
.pm_frame_timeout
= 0;
458 tx_cmd
->driver_txop
= 0;
459 tx_cmd
->tx_flags
= tx_flags
;
460 tx_cmd
->next_frame_len
= 0;
464 * start REPLY_TX command process
466 static int iwl3945_tx_skb(struct iwl_priv
*priv
, struct sk_buff
*skb
)
468 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
469 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
470 struct iwl3945_tx_cmd
*tx_cmd
;
471 struct iwl_tx_queue
*txq
= NULL
;
472 struct iwl_queue
*q
= NULL
;
473 struct iwl_device_cmd
*out_cmd
;
474 struct iwl_cmd_meta
*out_meta
;
475 dma_addr_t phys_addr
;
476 dma_addr_t txcmd_phys
;
477 int txq_id
= skb_get_queue_mapping(skb
);
478 u16 len
, idx
, hdr_len
;
484 u8 wait_write_ptr
= 0;
487 spin_lock_irqsave(&priv
->lock
, flags
);
488 if (iwl_legacy_is_rfkill(priv
)) {
489 IWL_DEBUG_DROP(priv
, "Dropping - RF KILL\n");
493 if ((ieee80211_get_tx_rate(priv
->hw
, info
)->hw_value
& 0xFF) == IWL_INVALID_RATE
) {
494 IWL_ERR(priv
, "ERROR: No TX rate available.\n");
498 unicast
= !is_multicast_ether_addr(hdr
->addr1
);
501 fc
= hdr
->frame_control
;
503 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
504 if (ieee80211_is_auth(fc
))
505 IWL_DEBUG_TX(priv
, "Sending AUTH frame\n");
506 else if (ieee80211_is_assoc_req(fc
))
507 IWL_DEBUG_TX(priv
, "Sending ASSOC frame\n");
508 else if (ieee80211_is_reassoc_req(fc
))
509 IWL_DEBUG_TX(priv
, "Sending REASSOC frame\n");
512 spin_unlock_irqrestore(&priv
->lock
, flags
);
514 hdr_len
= ieee80211_hdrlen(fc
);
516 /* Find index into station table for destination station */
517 sta_id
= iwl_legacy_sta_id_or_broadcast(
518 priv
, &priv
->contexts
[IWL_RXON_CTX_BSS
],
520 if (sta_id
== IWL_INVALID_STATION
) {
521 IWL_DEBUG_DROP(priv
, "Dropping - INVALID STATION: %pM\n",
526 IWL_DEBUG_RATE(priv
, "station Id %d\n", sta_id
);
528 if (ieee80211_is_data_qos(fc
)) {
529 u8
*qc
= ieee80211_get_qos_ctl(hdr
);
530 tid
= qc
[0] & IEEE80211_QOS_CTL_TID_MASK
;
531 if (unlikely(tid
>= MAX_TID_COUNT
))
535 /* Descriptor for chosen Tx queue */
536 txq
= &priv
->txq
[txq_id
];
539 if ((iwl_legacy_queue_space(q
) < q
->high_mark
))
542 spin_lock_irqsave(&priv
->lock
, flags
);
544 idx
= iwl_legacy_get_cmd_index(q
, q
->write_ptr
, 0);
546 /* Set up driver data for this TFD */
547 memset(&(txq
->txb
[q
->write_ptr
]), 0, sizeof(struct iwl_tx_info
));
548 txq
->txb
[q
->write_ptr
].skb
= skb
;
549 txq
->txb
[q
->write_ptr
].ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
551 /* Init first empty entry in queue's array of Tx/cmd buffers */
552 out_cmd
= txq
->cmd
[idx
];
553 out_meta
= &txq
->meta
[idx
];
554 tx_cmd
= (struct iwl3945_tx_cmd
*)out_cmd
->cmd
.payload
;
555 memset(&out_cmd
->hdr
, 0, sizeof(out_cmd
->hdr
));
556 memset(tx_cmd
, 0, sizeof(*tx_cmd
));
559 * Set up the Tx-command (not MAC!) header.
560 * Store the chosen Tx queue and TFD index within the sequence field;
561 * after Tx, uCode's Tx response will return this value so driver can
562 * locate the frame within the tx queue and do post-tx processing.
564 out_cmd
->hdr
.cmd
= REPLY_TX
;
565 out_cmd
->hdr
.sequence
= cpu_to_le16((u16
)(QUEUE_TO_SEQ(txq_id
) |
566 INDEX_TO_SEQ(q
->write_ptr
)));
568 /* Copy MAC header from skb into command buffer */
569 memcpy(tx_cmd
->hdr
, hdr
, hdr_len
);
572 if (info
->control
.hw_key
)
573 iwl3945_build_tx_cmd_hwcrypto(priv
, info
, out_cmd
, skb
, sta_id
);
575 /* TODO need this for burst mode later on */
576 iwl3945_build_tx_cmd_basic(priv
, out_cmd
, info
, hdr
, sta_id
);
578 /* set is_hcca to 0; it probably will never be implemented */
579 iwl3945_hw_build_tx_cmd_rate(priv
, out_cmd
, info
, hdr
, sta_id
, 0);
581 /* Total # bytes to be transmitted */
583 tx_cmd
->len
= cpu_to_le16(len
);
585 iwl_legacy_dbg_log_tx_data_frame(priv
, len
, hdr
);
586 iwl_legacy_update_stats(priv
, true, fc
, len
);
587 tx_cmd
->tx_flags
&= ~TX_CMD_FLG_ANT_A_MSK
;
588 tx_cmd
->tx_flags
&= ~TX_CMD_FLG_ANT_B_MSK
;
590 if (!ieee80211_has_morefrags(hdr
->frame_control
)) {
591 txq
->need_update
= 1;
594 txq
->need_update
= 0;
597 IWL_DEBUG_TX(priv
, "sequence nr = 0X%x\n",
598 le16_to_cpu(out_cmd
->hdr
.sequence
));
599 IWL_DEBUG_TX(priv
, "tx_flags = 0X%x\n", le32_to_cpu(tx_cmd
->tx_flags
));
600 iwl_print_hex_dump(priv
, IWL_DL_TX
, tx_cmd
, sizeof(*tx_cmd
));
601 iwl_print_hex_dump(priv
, IWL_DL_TX
, (u8
*)tx_cmd
->hdr
,
602 ieee80211_hdrlen(fc
));
605 * Use the first empty entry in this queue's command buffer array
606 * to contain the Tx command and MAC header concatenated together
607 * (payload data will be in another buffer).
608 * Size of this varies, due to varying MAC header length.
609 * If end is not dword aligned, we'll have 2 extra bytes at the end
610 * of the MAC header (device reads on dword boundaries).
611 * We'll tell device about this padding later.
613 len
= sizeof(struct iwl3945_tx_cmd
) +
614 sizeof(struct iwl_cmd_header
) + hdr_len
;
615 len
= (len
+ 3) & ~3;
617 /* Physical address of this Tx command's header (not MAC header!),
618 * within command buffer array. */
619 txcmd_phys
= pci_map_single(priv
->pci_dev
, &out_cmd
->hdr
,
620 len
, PCI_DMA_TODEVICE
);
621 /* we do not map meta data ... so we can safely access address to
622 * provide to unmap command*/
623 dma_unmap_addr_set(out_meta
, mapping
, txcmd_phys
);
624 dma_unmap_len_set(out_meta
, len
, len
);
626 /* Add buffer containing Tx command and MAC(!) header to TFD's
628 priv
->cfg
->ops
->lib
->txq_attach_buf_to_tfd(priv
, txq
,
629 txcmd_phys
, len
, 1, 0);
632 /* Set up TFD's 2nd entry to point directly to remainder of skb,
633 * if any (802.11 null frames have no payload). */
634 len
= skb
->len
- hdr_len
;
636 phys_addr
= pci_map_single(priv
->pci_dev
, skb
->data
+ hdr_len
,
637 len
, PCI_DMA_TODEVICE
);
638 priv
->cfg
->ops
->lib
->txq_attach_buf_to_tfd(priv
, txq
,
644 /* Tell device the write index *just past* this latest filled TFD */
645 q
->write_ptr
= iwl_legacy_queue_inc_wrap(q
->write_ptr
, q
->n_bd
);
646 iwl_legacy_txq_update_write_ptr(priv
, txq
);
647 spin_unlock_irqrestore(&priv
->lock
, flags
);
649 if ((iwl_legacy_queue_space(q
) < q
->high_mark
)
650 && priv
->mac80211_registered
) {
651 if (wait_write_ptr
) {
652 spin_lock_irqsave(&priv
->lock
, flags
);
653 txq
->need_update
= 1;
654 iwl_legacy_txq_update_write_ptr(priv
, txq
);
655 spin_unlock_irqrestore(&priv
->lock
, flags
);
658 iwl_legacy_stop_queue(priv
, txq
);
664 spin_unlock_irqrestore(&priv
->lock
, flags
);
669 static int iwl3945_get_measurement(struct iwl_priv
*priv
,
670 struct ieee80211_measurement_params
*params
,
673 struct iwl_spectrum_cmd spectrum
;
674 struct iwl_rx_packet
*pkt
;
675 struct iwl_host_cmd cmd
= {
676 .id
= REPLY_SPECTRUM_MEASUREMENT_CMD
,
677 .data
= (void *)&spectrum
,
678 .flags
= CMD_WANT_SKB
,
680 u32 add_time
= le64_to_cpu(params
->start_time
);
682 int spectrum_resp_status
;
683 int duration
= le16_to_cpu(params
->duration
);
684 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
686 if (iwl_legacy_is_associated(priv
, IWL_RXON_CTX_BSS
))
687 add_time
= iwl_legacy_usecs_to_beacons(priv
,
688 le64_to_cpu(params
->start_time
) - priv
->_3945
.last_tsf
,
689 le16_to_cpu(ctx
->timing
.beacon_interval
));
691 memset(&spectrum
, 0, sizeof(spectrum
));
693 spectrum
.channel_count
= cpu_to_le16(1);
695 RXON_FLG_TSF2HOST_MSK
| RXON_FLG_ANT_A_MSK
| RXON_FLG_DIS_DIV_MSK
;
696 spectrum
.filter_flags
= MEASUREMENT_FILTER_FLAG
;
697 cmd
.len
= sizeof(spectrum
);
698 spectrum
.len
= cpu_to_le16(cmd
.len
- sizeof(spectrum
.len
));
700 if (iwl_legacy_is_associated(priv
, IWL_RXON_CTX_BSS
))
701 spectrum
.start_time
=
702 iwl_legacy_add_beacon_time(priv
,
703 priv
->_3945
.last_beacon_time
, add_time
,
704 le16_to_cpu(ctx
->timing
.beacon_interval
));
706 spectrum
.start_time
= 0;
708 spectrum
.channels
[0].duration
= cpu_to_le32(duration
* TIME_UNIT
);
709 spectrum
.channels
[0].channel
= params
->channel
;
710 spectrum
.channels
[0].type
= type
;
711 if (ctx
->active
.flags
& RXON_FLG_BAND_24G_MSK
)
712 spectrum
.flags
|= RXON_FLG_BAND_24G_MSK
|
713 RXON_FLG_AUTO_DETECT_MSK
| RXON_FLG_TGG_PROTECT_MSK
;
715 rc
= iwl_legacy_send_cmd_sync(priv
, &cmd
);
719 pkt
= (struct iwl_rx_packet
*)cmd
.reply_page
;
720 if (pkt
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
721 IWL_ERR(priv
, "Bad return from REPLY_RX_ON_ASSOC command\n");
725 spectrum_resp_status
= le16_to_cpu(pkt
->u
.spectrum
.status
);
726 switch (spectrum_resp_status
) {
727 case 0: /* Command will be handled */
728 if (pkt
->u
.spectrum
.id
!= 0xff) {
729 IWL_DEBUG_INFO(priv
, "Replaced existing measurement: %d\n",
731 priv
->measurement_status
&= ~MEASUREMENT_READY
;
733 priv
->measurement_status
|= MEASUREMENT_ACTIVE
;
737 case 1: /* Command will not be handled */
742 iwl_legacy_free_pages(priv
, cmd
.reply_page
);
747 static void iwl3945_rx_reply_alive(struct iwl_priv
*priv
,
748 struct iwl_rx_mem_buffer
*rxb
)
750 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
751 struct iwl_alive_resp
*palive
;
752 struct delayed_work
*pwork
;
754 palive
= &pkt
->u
.alive_frame
;
756 IWL_DEBUG_INFO(priv
, "Alive ucode status 0x%08X revision "
758 palive
->is_valid
, palive
->ver_type
,
759 palive
->ver_subtype
);
761 if (palive
->ver_subtype
== INITIALIZE_SUBTYPE
) {
762 IWL_DEBUG_INFO(priv
, "Initialization Alive received.\n");
763 memcpy(&priv
->card_alive_init
, &pkt
->u
.alive_frame
,
764 sizeof(struct iwl_alive_resp
));
765 pwork
= &priv
->init_alive_start
;
767 IWL_DEBUG_INFO(priv
, "Runtime Alive received.\n");
768 memcpy(&priv
->card_alive
, &pkt
->u
.alive_frame
,
769 sizeof(struct iwl_alive_resp
));
770 pwork
= &priv
->alive_start
;
771 iwl3945_disable_events(priv
);
774 /* We delay the ALIVE response by 5ms to
775 * give the HW RF Kill time to activate... */
776 if (palive
->is_valid
== UCODE_VALID_OK
)
777 queue_delayed_work(priv
->workqueue
, pwork
,
778 msecs_to_jiffies(5));
780 IWL_WARN(priv
, "uCode did not respond OK.\n");
783 static void iwl3945_rx_reply_add_sta(struct iwl_priv
*priv
,
784 struct iwl_rx_mem_buffer
*rxb
)
786 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
787 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
790 IWL_DEBUG_RX(priv
, "Received REPLY_ADD_STA: 0x%02X\n", pkt
->u
.status
);
793 static void iwl3945_rx_beacon_notif(struct iwl_priv
*priv
,
794 struct iwl_rx_mem_buffer
*rxb
)
796 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
797 struct iwl3945_beacon_notif
*beacon
= &(pkt
->u
.beacon_status
);
798 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
799 u8 rate
= beacon
->beacon_notify_hdr
.rate
;
801 IWL_DEBUG_RX(priv
, "beacon status %x retries %d iss %d "
802 "tsf %d %d rate %d\n",
803 le32_to_cpu(beacon
->beacon_notify_hdr
.status
) & TX_STATUS_MSK
,
804 beacon
->beacon_notify_hdr
.failure_frame
,
805 le32_to_cpu(beacon
->ibss_mgr_status
),
806 le32_to_cpu(beacon
->high_tsf
),
807 le32_to_cpu(beacon
->low_tsf
), rate
);
810 priv
->ibss_manager
= le32_to_cpu(beacon
->ibss_mgr_status
);
814 /* Handle notification from uCode that card's power state is changing
815 * due to software, hardware, or critical temperature RFKILL */
816 static void iwl3945_rx_card_state_notif(struct iwl_priv
*priv
,
817 struct iwl_rx_mem_buffer
*rxb
)
819 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
820 u32 flags
= le32_to_cpu(pkt
->u
.card_state_notif
.flags
);
821 unsigned long status
= priv
->status
;
823 IWL_WARN(priv
, "Card state received: HW:%s SW:%s\n",
824 (flags
& HW_CARD_DISABLED
) ? "Kill" : "On",
825 (flags
& SW_CARD_DISABLED
) ? "Kill" : "On");
827 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
828 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
830 if (flags
& HW_CARD_DISABLED
)
831 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
833 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
836 iwl_legacy_scan_cancel(priv
);
838 if ((test_bit(STATUS_RF_KILL_HW
, &status
) !=
839 test_bit(STATUS_RF_KILL_HW
, &priv
->status
)))
840 wiphy_rfkill_set_hw_state(priv
->hw
->wiphy
,
841 test_bit(STATUS_RF_KILL_HW
, &priv
->status
));
843 wake_up_interruptible(&priv
->wait_command_queue
);
847 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
849 * Setup the RX handlers for each of the reply types sent from the uCode
852 * This function chains into the hardware specific files for them to setup
853 * any hardware specific handlers as well.
855 static void iwl3945_setup_rx_handlers(struct iwl_priv
*priv
)
857 priv
->rx_handlers
[REPLY_ALIVE
] = iwl3945_rx_reply_alive
;
858 priv
->rx_handlers
[REPLY_ADD_STA
] = iwl3945_rx_reply_add_sta
;
859 priv
->rx_handlers
[REPLY_ERROR
] = iwl_legacy_rx_reply_error
;
860 priv
->rx_handlers
[CHANNEL_SWITCH_NOTIFICATION
] = iwl_legacy_rx_csa
;
861 priv
->rx_handlers
[SPECTRUM_MEASURE_NOTIFICATION
] =
862 iwl_legacy_rx_spectrum_measure_notif
;
863 priv
->rx_handlers
[PM_SLEEP_NOTIFICATION
] = iwl_legacy_rx_pm_sleep_notif
;
864 priv
->rx_handlers
[PM_DEBUG_STATISTIC_NOTIFIC
] =
865 iwl_legacy_rx_pm_debug_statistics_notif
;
866 priv
->rx_handlers
[BEACON_NOTIFICATION
] = iwl3945_rx_beacon_notif
;
869 * The same handler is used for both the REPLY to a discrete
870 * statistics request from the host as well as for the periodic
871 * statistics notifications (after received beacons) from the uCode.
873 priv
->rx_handlers
[REPLY_STATISTICS_CMD
] = iwl3945_reply_statistics
;
874 priv
->rx_handlers
[STATISTICS_NOTIFICATION
] = iwl3945_hw_rx_statistics
;
876 iwl_legacy_setup_rx_scan_handlers(priv
);
877 priv
->rx_handlers
[CARD_STATE_NOTIFICATION
] = iwl3945_rx_card_state_notif
;
879 /* Set up hardware specific Rx handlers */
880 iwl3945_hw_rx_handler_setup(priv
);
883 /************************** RX-FUNCTIONS ****************************/
885 * Rx theory of operation
887 * The host allocates 32 DMA target addresses and passes the host address
888 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
892 * The host/firmware share two index registers for managing the Rx buffers.
894 * The READ index maps to the first position that the firmware may be writing
895 * to -- the driver can read up to (but not including) this position and get
897 * The READ index is managed by the firmware once the card is enabled.
899 * The WRITE index maps to the last position the driver has read from -- the
900 * position preceding WRITE is the last slot the firmware can place a packet.
902 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
905 * During initialization, the host sets up the READ queue position to the first
906 * INDEX position, and WRITE to the last (READ - 1 wrapped)
908 * When the firmware places a packet in a buffer, it will advance the READ index
909 * and fire the RX interrupt. The driver can then query the READ index and
910 * process as many packets as possible, moving the WRITE index forward as it
911 * resets the Rx queue buffers with new memory.
913 * The management in the driver is as follows:
914 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
915 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
916 * to replenish the iwl->rxq->rx_free.
917 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
918 * iwl->rxq is replenished and the READ INDEX is updated (updating the
919 * 'processed' and 'read' driver indexes as well)
920 * + A received packet is processed and handed to the kernel network stack,
921 * detached from the iwl->rxq. The driver 'processed' index is updated.
922 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
923 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
924 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
925 * were enough free buffers and RX_STALLED is set it is cleared.
930 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
931 * iwl3945_rx_queue_restock
932 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
933 * queue, updates firmware pointers, and updates
934 * the WRITE index. If insufficient rx_free buffers
935 * are available, schedules iwl3945_rx_replenish
937 * -- enable interrupts --
938 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
939 * READ INDEX, detaching the SKB from the pool.
940 * Moves the packet buffer from queue to rx_used.
941 * Calls iwl3945_rx_queue_restock to refill any empty
948 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
950 static inline __le32
iwl3945_dma_addr2rbd_ptr(struct iwl_priv
*priv
,
953 return cpu_to_le32((u32
)dma_addr
);
957 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
959 * If there are slots in the RX queue that need to be restocked,
960 * and we have free pre-allocated buffers, fill the ranks as much
961 * as we can, pulling from rx_free.
963 * This moves the 'write' index forward to catch up with 'processed', and
964 * also updates the memory address in the firmware to reference the new
967 static void iwl3945_rx_queue_restock(struct iwl_priv
*priv
)
969 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
970 struct list_head
*element
;
971 struct iwl_rx_mem_buffer
*rxb
;
975 spin_lock_irqsave(&rxq
->lock
, flags
);
976 write
= rxq
->write
& ~0x7;
977 while ((iwl_legacy_rx_queue_space(rxq
) > 0) && (rxq
->free_count
)) {
978 /* Get next free Rx buffer, remove from free list */
979 element
= rxq
->rx_free
.next
;
980 rxb
= list_entry(element
, struct iwl_rx_mem_buffer
, list
);
983 /* Point to Rx buffer via next RBD in circular buffer */
984 rxq
->bd
[rxq
->write
] = iwl3945_dma_addr2rbd_ptr(priv
, rxb
->page_dma
);
985 rxq
->queue
[rxq
->write
] = rxb
;
986 rxq
->write
= (rxq
->write
+ 1) & RX_QUEUE_MASK
;
989 spin_unlock_irqrestore(&rxq
->lock
, flags
);
990 /* If the pre-allocated buffer pool is dropping low, schedule to
992 if (rxq
->free_count
<= RX_LOW_WATERMARK
)
993 queue_work(priv
->workqueue
, &priv
->rx_replenish
);
996 /* If we've added more space for the firmware to place data, tell it.
997 * Increment device's write pointer in multiples of 8. */
998 if ((rxq
->write_actual
!= (rxq
->write
& ~0x7))
999 || (abs(rxq
->write
- rxq
->read
) > 7)) {
1000 spin_lock_irqsave(&rxq
->lock
, flags
);
1001 rxq
->need_update
= 1;
1002 spin_unlock_irqrestore(&rxq
->lock
, flags
);
1003 iwl_legacy_rx_queue_update_write_ptr(priv
, rxq
);
1008 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
1010 * When moving to rx_free an SKB is allocated for the slot.
1012 * Also restock the Rx queue via iwl3945_rx_queue_restock.
1013 * This is called as a scheduled work item (except for during initialization)
1015 static void iwl3945_rx_allocate(struct iwl_priv
*priv
, gfp_t priority
)
1017 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
1018 struct list_head
*element
;
1019 struct iwl_rx_mem_buffer
*rxb
;
1021 unsigned long flags
;
1022 gfp_t gfp_mask
= priority
;
1025 spin_lock_irqsave(&rxq
->lock
, flags
);
1027 if (list_empty(&rxq
->rx_used
)) {
1028 spin_unlock_irqrestore(&rxq
->lock
, flags
);
1031 spin_unlock_irqrestore(&rxq
->lock
, flags
);
1033 if (rxq
->free_count
> RX_LOW_WATERMARK
)
1034 gfp_mask
|= __GFP_NOWARN
;
1036 if (priv
->hw_params
.rx_page_order
> 0)
1037 gfp_mask
|= __GFP_COMP
;
1039 /* Alloc a new receive buffer */
1040 page
= alloc_pages(gfp_mask
, priv
->hw_params
.rx_page_order
);
1042 if (net_ratelimit())
1043 IWL_DEBUG_INFO(priv
, "Failed to allocate SKB buffer.\n");
1044 if ((rxq
->free_count
<= RX_LOW_WATERMARK
) &&
1046 IWL_CRIT(priv
, "Failed to allocate SKB buffer with %s. Only %u free buffers remaining.\n",
1047 priority
== GFP_ATOMIC
? "GFP_ATOMIC" : "GFP_KERNEL",
1049 /* We don't reschedule replenish work here -- we will
1050 * call the restock method and if it still needs
1051 * more buffers it will schedule replenish */
1055 spin_lock_irqsave(&rxq
->lock
, flags
);
1056 if (list_empty(&rxq
->rx_used
)) {
1057 spin_unlock_irqrestore(&rxq
->lock
, flags
);
1058 __free_pages(page
, priv
->hw_params
.rx_page_order
);
1061 element
= rxq
->rx_used
.next
;
1062 rxb
= list_entry(element
, struct iwl_rx_mem_buffer
, list
);
1064 spin_unlock_irqrestore(&rxq
->lock
, flags
);
1067 /* Get physical address of RB/SKB */
1068 rxb
->page_dma
= pci_map_page(priv
->pci_dev
, page
, 0,
1069 PAGE_SIZE
<< priv
->hw_params
.rx_page_order
,
1070 PCI_DMA_FROMDEVICE
);
1072 spin_lock_irqsave(&rxq
->lock
, flags
);
1074 list_add_tail(&rxb
->list
, &rxq
->rx_free
);
1076 priv
->alloc_rxb_page
++;
1078 spin_unlock_irqrestore(&rxq
->lock
, flags
);
1082 void iwl3945_rx_queue_reset(struct iwl_priv
*priv
, struct iwl_rx_queue
*rxq
)
1084 unsigned long flags
;
1086 spin_lock_irqsave(&rxq
->lock
, flags
);
1087 INIT_LIST_HEAD(&rxq
->rx_free
);
1088 INIT_LIST_HEAD(&rxq
->rx_used
);
1089 /* Fill the rx_used queue with _all_ of the Rx buffers */
1090 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++) {
1091 /* In the reset function, these buffers may have been allocated
1092 * to an SKB, so we need to unmap and free potential storage */
1093 if (rxq
->pool
[i
].page
!= NULL
) {
1094 pci_unmap_page(priv
->pci_dev
, rxq
->pool
[i
].page_dma
,
1095 PAGE_SIZE
<< priv
->hw_params
.rx_page_order
,
1096 PCI_DMA_FROMDEVICE
);
1097 __iwl_legacy_free_pages(priv
, rxq
->pool
[i
].page
);
1098 rxq
->pool
[i
].page
= NULL
;
1100 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
1103 /* Set us so that we have processed and used all buffers, but have
1104 * not restocked the Rx queue with fresh buffers */
1105 rxq
->read
= rxq
->write
= 0;
1106 rxq
->write_actual
= 0;
1107 rxq
->free_count
= 0;
1108 spin_unlock_irqrestore(&rxq
->lock
, flags
);
1111 void iwl3945_rx_replenish(void *data
)
1113 struct iwl_priv
*priv
= data
;
1114 unsigned long flags
;
1116 iwl3945_rx_allocate(priv
, GFP_KERNEL
);
1118 spin_lock_irqsave(&priv
->lock
, flags
);
1119 iwl3945_rx_queue_restock(priv
);
1120 spin_unlock_irqrestore(&priv
->lock
, flags
);
1123 static void iwl3945_rx_replenish_now(struct iwl_priv
*priv
)
1125 iwl3945_rx_allocate(priv
, GFP_ATOMIC
);
1127 iwl3945_rx_queue_restock(priv
);
1131 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
1132 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
1133 * This free routine walks the list of POOL entries and if SKB is set to
1134 * non NULL it is unmapped and freed
1136 static void iwl3945_rx_queue_free(struct iwl_priv
*priv
, struct iwl_rx_queue
*rxq
)
1139 for (i
= 0; i
< RX_QUEUE_SIZE
+ RX_FREE_BUFFERS
; i
++) {
1140 if (rxq
->pool
[i
].page
!= NULL
) {
1141 pci_unmap_page(priv
->pci_dev
, rxq
->pool
[i
].page_dma
,
1142 PAGE_SIZE
<< priv
->hw_params
.rx_page_order
,
1143 PCI_DMA_FROMDEVICE
);
1144 __iwl_legacy_free_pages(priv
, rxq
->pool
[i
].page
);
1145 rxq
->pool
[i
].page
= NULL
;
1149 dma_free_coherent(&priv
->pci_dev
->dev
, 4 * RX_QUEUE_SIZE
, rxq
->bd
,
1151 dma_free_coherent(&priv
->pci_dev
->dev
, sizeof(struct iwl_rb_status
),
1152 rxq
->rb_stts
, rxq
->rb_stts_dma
);
1154 rxq
->rb_stts
= NULL
;
1158 /* Convert linear signal-to-noise ratio into dB */
1159 static u8 ratio2dB
[100] = {
1160 /* 0 1 2 3 4 5 6 7 8 9 */
1161 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
1162 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
1163 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
1164 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
1165 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
1166 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
1167 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
1168 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
1169 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
1170 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
1173 /* Calculates a relative dB value from a ratio of linear
1174 * (i.e. not dB) signal levels.
1175 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
1176 int iwl3945_calc_db_from_ratio(int sig_ratio
)
1178 /* 1000:1 or higher just report as 60 dB */
1179 if (sig_ratio
>= 1000)
1182 /* 100:1 or higher, divide by 10 and use table,
1183 * add 20 dB to make up for divide by 10 */
1184 if (sig_ratio
>= 100)
1185 return 20 + (int)ratio2dB
[sig_ratio
/10];
1187 /* We shouldn't see this */
1191 /* Use table for ratios 1:1 - 99:1 */
1192 return (int)ratio2dB
[sig_ratio
];
1196 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
1198 * Uses the priv->rx_handlers callback function array to invoke
1199 * the appropriate handlers, including command responses,
1200 * frame-received notifications, and other notifications.
1202 static void iwl3945_rx_handle(struct iwl_priv
*priv
)
1204 struct iwl_rx_mem_buffer
*rxb
;
1205 struct iwl_rx_packet
*pkt
;
1206 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
1209 unsigned long flags
;
1212 int total_empty
= 0;
1214 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1215 * buffer that the driver may process (last buffer filled by ucode). */
1216 r
= le16_to_cpu(rxq
->rb_stts
->closed_rb_num
) & 0x0FFF;
1219 /* calculate total frames need to be restock after handling RX */
1220 total_empty
= r
- rxq
->write_actual
;
1221 if (total_empty
< 0)
1222 total_empty
+= RX_QUEUE_SIZE
;
1224 if (total_empty
> (RX_QUEUE_SIZE
/ 2))
1226 /* Rx interrupt, but nothing sent from uCode */
1228 IWL_DEBUG_RX(priv
, "r = %d, i = %d\n", r
, i
);
1233 rxb
= rxq
->queue
[i
];
1235 /* If an RXB doesn't have a Rx queue slot associated with it,
1236 * then a bug has been introduced in the queue refilling
1237 * routines -- catch it here */
1238 BUG_ON(rxb
== NULL
);
1240 rxq
->queue
[i
] = NULL
;
1242 pci_unmap_page(priv
->pci_dev
, rxb
->page_dma
,
1243 PAGE_SIZE
<< priv
->hw_params
.rx_page_order
,
1244 PCI_DMA_FROMDEVICE
);
1245 pkt
= rxb_addr(rxb
);
1247 len
= le32_to_cpu(pkt
->len_n_flags
) & FH_RSCSR_FRAME_SIZE_MSK
;
1248 len
+= sizeof(u32
); /* account for status word */
1249 trace_iwlwifi_legacy_dev_rx(priv
, pkt
, len
);
1251 /* Reclaim a command buffer only if this packet is a response
1252 * to a (driver-originated) command.
1253 * If the packet (e.g. Rx frame) originated from uCode,
1254 * there is no command buffer to reclaim.
1255 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1256 * but apparently a few don't get set; catch them here. */
1257 reclaim
= !(pkt
->hdr
.sequence
& SEQ_RX_FRAME
) &&
1258 (pkt
->hdr
.cmd
!= STATISTICS_NOTIFICATION
) &&
1259 (pkt
->hdr
.cmd
!= REPLY_TX
);
1261 /* Based on type of command response or notification,
1262 * handle those that need handling via function in
1263 * rx_handlers table. See iwl3945_setup_rx_handlers() */
1264 if (priv
->rx_handlers
[pkt
->hdr
.cmd
]) {
1265 IWL_DEBUG_RX(priv
, "r = %d, i = %d, %s, 0x%02x\n", r
, i
,
1266 iwl_legacy_get_cmd_string(pkt
->hdr
.cmd
), pkt
->hdr
.cmd
);
1267 priv
->isr_stats
.rx_handlers
[pkt
->hdr
.cmd
]++;
1268 priv
->rx_handlers
[pkt
->hdr
.cmd
] (priv
, rxb
);
1270 /* No handling needed */
1272 "r %d i %d No handler needed for %s, 0x%02x\n",
1273 r
, i
, iwl_legacy_get_cmd_string(pkt
->hdr
.cmd
),
1278 * XXX: After here, we should always check rxb->page
1279 * against NULL before touching it or its virtual
1280 * memory (pkt). Because some rx_handler might have
1281 * already taken or freed the pages.
1285 /* Invoke any callbacks, transfer the buffer to caller,
1286 * and fire off the (possibly) blocking iwl_legacy_send_cmd()
1287 * as we reclaim the driver command queue */
1289 iwl_legacy_tx_cmd_complete(priv
, rxb
);
1291 IWL_WARN(priv
, "Claim null rxb?\n");
1294 /* Reuse the page if possible. For notification packets and
1295 * SKBs that fail to Rx correctly, add them back into the
1296 * rx_free list for reuse later. */
1297 spin_lock_irqsave(&rxq
->lock
, flags
);
1298 if (rxb
->page
!= NULL
) {
1299 rxb
->page_dma
= pci_map_page(priv
->pci_dev
, rxb
->page
,
1300 0, PAGE_SIZE
<< priv
->hw_params
.rx_page_order
,
1301 PCI_DMA_FROMDEVICE
);
1302 list_add_tail(&rxb
->list
, &rxq
->rx_free
);
1305 list_add_tail(&rxb
->list
, &rxq
->rx_used
);
1307 spin_unlock_irqrestore(&rxq
->lock
, flags
);
1309 i
= (i
+ 1) & RX_QUEUE_MASK
;
1310 /* If there are a lot of unused frames,
1311 * restock the Rx queue so ucode won't assert. */
1316 iwl3945_rx_replenish_now(priv
);
1322 /* Backtrack one entry */
1325 iwl3945_rx_replenish_now(priv
);
1327 iwl3945_rx_queue_restock(priv
);
1330 /* call this function to flush any scheduled tasklet */
1331 static inline void iwl3945_synchronize_irq(struct iwl_priv
*priv
)
1333 /* wait to make sure we flush pending tasklet*/
1334 synchronize_irq(priv
->pci_dev
->irq
);
1335 tasklet_kill(&priv
->irq_tasklet
);
1338 static const char *iwl3945_desc_lookup(int i
)
1346 return "BAD_CHECKSUM";
1348 return "NMI_INTERRUPT";
1352 return "FATAL_ERROR";
1358 #define ERROR_START_OFFSET (1 * sizeof(u32))
1359 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
1361 void iwl3945_dump_nic_error_log(struct iwl_priv
*priv
)
1364 u32 desc
, time
, count
, base
, data1
;
1365 u32 blink1
, blink2
, ilink1
, ilink2
;
1367 base
= le32_to_cpu(priv
->card_alive
.error_event_table_ptr
);
1369 if (!iwl3945_hw_valid_rtc_data_addr(base
)) {
1370 IWL_ERR(priv
, "Not valid error log pointer 0x%08X\n", base
);
1375 count
= iwl_legacy_read_targ_mem(priv
, base
);
1377 if (ERROR_START_OFFSET
<= count
* ERROR_ELEM_SIZE
) {
1378 IWL_ERR(priv
, "Start IWL Error Log Dump:\n");
1379 IWL_ERR(priv
, "Status: 0x%08lX, count: %d\n",
1380 priv
->status
, count
);
1383 IWL_ERR(priv
, "Desc Time asrtPC blink2 "
1384 "ilink1 nmiPC Line\n");
1385 for (i
= ERROR_START_OFFSET
;
1386 i
< (count
* ERROR_ELEM_SIZE
) + ERROR_START_OFFSET
;
1387 i
+= ERROR_ELEM_SIZE
) {
1388 desc
= iwl_legacy_read_targ_mem(priv
, base
+ i
);
1390 iwl_legacy_read_targ_mem(priv
, base
+ i
+ 1 * sizeof(u32
));
1392 iwl_legacy_read_targ_mem(priv
, base
+ i
+ 2 * sizeof(u32
));
1394 iwl_legacy_read_targ_mem(priv
, base
+ i
+ 3 * sizeof(u32
));
1396 iwl_legacy_read_targ_mem(priv
, base
+ i
+ 4 * sizeof(u32
));
1398 iwl_legacy_read_targ_mem(priv
, base
+ i
+ 5 * sizeof(u32
));
1400 iwl_legacy_read_targ_mem(priv
, base
+ i
+ 6 * sizeof(u32
));
1403 "%-13s (0x%X) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
1404 iwl3945_desc_lookup(desc
), desc
, time
, blink1
, blink2
,
1405 ilink1
, ilink2
, data1
);
1406 trace_iwlwifi_legacy_dev_ucode_error(priv
, desc
, time
, data1
, 0,
1407 0, blink1
, blink2
, ilink1
, ilink2
);
1411 static void iwl3945_irq_tasklet(struct iwl_priv
*priv
)
1413 u32 inta
, handled
= 0;
1415 unsigned long flags
;
1416 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
1420 spin_lock_irqsave(&priv
->lock
, flags
);
1422 /* Ack/clear/reset pending uCode interrupts.
1423 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1424 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
1425 inta
= iwl_read32(priv
, CSR_INT
);
1426 iwl_write32(priv
, CSR_INT
, inta
);
1428 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1429 * Any new interrupts that happen after this, either while we're
1430 * in this tasklet, or later, will show up in next ISR/tasklet. */
1431 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
1432 iwl_write32(priv
, CSR_FH_INT_STATUS
, inta_fh
);
1434 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
1435 if (iwl_legacy_get_debug_level(priv
) & IWL_DL_ISR
) {
1436 /* just for debug */
1437 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
1438 IWL_DEBUG_ISR(priv
, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1439 inta
, inta_mask
, inta_fh
);
1443 spin_unlock_irqrestore(&priv
->lock
, flags
);
1445 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1446 * atomic, make sure that inta covers all the interrupts that
1447 * we've discovered, even if FH interrupt came in just after
1448 * reading CSR_INT. */
1449 if (inta_fh
& CSR39_FH_INT_RX_MASK
)
1450 inta
|= CSR_INT_BIT_FH_RX
;
1451 if (inta_fh
& CSR39_FH_INT_TX_MASK
)
1452 inta
|= CSR_INT_BIT_FH_TX
;
1454 /* Now service all interrupt bits discovered above. */
1455 if (inta
& CSR_INT_BIT_HW_ERR
) {
1456 IWL_ERR(priv
, "Hardware error detected. Restarting.\n");
1458 /* Tell the device to stop sending interrupts */
1459 iwl_legacy_disable_interrupts(priv
);
1461 priv
->isr_stats
.hw
++;
1462 iwl_legacy_irq_handle_error(priv
);
1464 handled
|= CSR_INT_BIT_HW_ERR
;
1469 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
1470 if (iwl_legacy_get_debug_level(priv
) & (IWL_DL_ISR
)) {
1471 /* NIC fires this, but we don't use it, redundant with WAKEUP */
1472 if (inta
& CSR_INT_BIT_SCD
) {
1473 IWL_DEBUG_ISR(priv
, "Scheduler finished to transmit "
1474 "the frame/frames.\n");
1475 priv
->isr_stats
.sch
++;
1478 /* Alive notification via Rx interrupt will do the real work */
1479 if (inta
& CSR_INT_BIT_ALIVE
) {
1480 IWL_DEBUG_ISR(priv
, "Alive interrupt\n");
1481 priv
->isr_stats
.alive
++;
1485 /* Safely ignore these bits for debug checks below */
1486 inta
&= ~(CSR_INT_BIT_SCD
| CSR_INT_BIT_ALIVE
);
1488 /* Error detected by uCode */
1489 if (inta
& CSR_INT_BIT_SW_ERR
) {
1490 IWL_ERR(priv
, "Microcode SW error detected. "
1491 "Restarting 0x%X.\n", inta
);
1492 priv
->isr_stats
.sw
++;
1493 iwl_legacy_irq_handle_error(priv
);
1494 handled
|= CSR_INT_BIT_SW_ERR
;
1497 /* uCode wakes up after power-down sleep */
1498 if (inta
& CSR_INT_BIT_WAKEUP
) {
1499 IWL_DEBUG_ISR(priv
, "Wakeup interrupt\n");
1500 iwl_legacy_rx_queue_update_write_ptr(priv
, &priv
->rxq
);
1501 iwl_legacy_txq_update_write_ptr(priv
, &priv
->txq
[0]);
1502 iwl_legacy_txq_update_write_ptr(priv
, &priv
->txq
[1]);
1503 iwl_legacy_txq_update_write_ptr(priv
, &priv
->txq
[2]);
1504 iwl_legacy_txq_update_write_ptr(priv
, &priv
->txq
[3]);
1505 iwl_legacy_txq_update_write_ptr(priv
, &priv
->txq
[4]);
1506 iwl_legacy_txq_update_write_ptr(priv
, &priv
->txq
[5]);
1508 priv
->isr_stats
.wakeup
++;
1509 handled
|= CSR_INT_BIT_WAKEUP
;
1512 /* All uCode command responses, including Tx command responses,
1513 * Rx "responses" (frame-received notification), and other
1514 * notifications from uCode come through here*/
1515 if (inta
& (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
)) {
1516 iwl3945_rx_handle(priv
);
1517 priv
->isr_stats
.rx
++;
1518 handled
|= (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
);
1521 if (inta
& CSR_INT_BIT_FH_TX
) {
1522 IWL_DEBUG_ISR(priv
, "Tx interrupt\n");
1523 priv
->isr_stats
.tx
++;
1525 iwl_write32(priv
, CSR_FH_INT_STATUS
, (1 << 6));
1526 iwl_legacy_write_direct32(priv
, FH39_TCSR_CREDIT
1527 (FH39_SRVC_CHNL
), 0x0);
1528 handled
|= CSR_INT_BIT_FH_TX
;
1531 if (inta
& ~handled
) {
1532 IWL_ERR(priv
, "Unhandled INTA bits 0x%08x\n", inta
& ~handled
);
1533 priv
->isr_stats
.unhandled
++;
1536 if (inta
& ~priv
->inta_mask
) {
1537 IWL_WARN(priv
, "Disabled INTA bits 0x%08x were pending\n",
1538 inta
& ~priv
->inta_mask
);
1539 IWL_WARN(priv
, " with FH_INT = 0x%08x\n", inta_fh
);
1542 /* Re-enable all interrupts */
1543 /* only Re-enable if disabled by irq */
1544 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
1545 iwl_legacy_enable_interrupts(priv
);
1547 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
1548 if (iwl_legacy_get_debug_level(priv
) & (IWL_DL_ISR
)) {
1549 inta
= iwl_read32(priv
, CSR_INT
);
1550 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
1551 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
1552 IWL_DEBUG_ISR(priv
, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
1553 "flags 0x%08lx\n", inta
, inta_mask
, inta_fh
, flags
);
1558 static int iwl3945_get_channels_for_scan(struct iwl_priv
*priv
,
1559 enum ieee80211_band band
,
1560 u8 is_active
, u8 n_probes
,
1561 struct iwl3945_scan_channel
*scan_ch
,
1562 struct ieee80211_vif
*vif
)
1564 struct ieee80211_channel
*chan
;
1565 const struct ieee80211_supported_band
*sband
;
1566 const struct iwl_channel_info
*ch_info
;
1567 u16 passive_dwell
= 0;
1568 u16 active_dwell
= 0;
1571 sband
= iwl_get_hw_mode(priv
, band
);
1575 active_dwell
= iwl_legacy_get_active_dwell_time(priv
, band
, n_probes
);
1576 passive_dwell
= iwl_legacy_get_passive_dwell_time(priv
, band
, vif
);
1578 if (passive_dwell
<= active_dwell
)
1579 passive_dwell
= active_dwell
+ 1;
1581 for (i
= 0, added
= 0; i
< priv
->scan_request
->n_channels
; i
++) {
1582 chan
= priv
->scan_request
->channels
[i
];
1584 if (chan
->band
!= band
)
1587 scan_ch
->channel
= chan
->hw_value
;
1589 ch_info
= iwl_legacy_get_channel_info(priv
, band
,
1591 if (!iwl_legacy_is_channel_valid(ch_info
)) {
1592 IWL_DEBUG_SCAN(priv
,
1593 "Channel %d is INVALID for this band.\n",
1598 scan_ch
->active_dwell
= cpu_to_le16(active_dwell
);
1599 scan_ch
->passive_dwell
= cpu_to_le16(passive_dwell
);
1600 /* If passive , set up for auto-switch
1601 * and use long active_dwell time.
1603 if (!is_active
|| iwl_legacy_is_channel_passive(ch_info
) ||
1604 (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)) {
1605 scan_ch
->type
= 0; /* passive */
1606 if (IWL_UCODE_API(priv
->ucode_ver
) == 1)
1607 scan_ch
->active_dwell
= cpu_to_le16(passive_dwell
- 1);
1609 scan_ch
->type
= 1; /* active */
1612 /* Set direct probe bits. These may be used both for active
1613 * scan channels (probes gets sent right away),
1614 * or for passive channels (probes get se sent only after
1615 * hearing clear Rx packet).*/
1616 if (IWL_UCODE_API(priv
->ucode_ver
) >= 2) {
1618 scan_ch
->type
|= IWL39_SCAN_PROBE_MASK(n_probes
);
1620 /* uCode v1 does not allow setting direct probe bits on
1621 * passive channel. */
1622 if ((scan_ch
->type
& 1) && n_probes
)
1623 scan_ch
->type
|= IWL39_SCAN_PROBE_MASK(n_probes
);
1626 /* Set txpower levels to defaults */
1627 scan_ch
->tpc
.dsp_atten
= 110;
1628 /* scan_pwr_info->tpc.dsp_atten; */
1630 /*scan_pwr_info->tpc.tx_gain; */
1631 if (band
== IEEE80211_BAND_5GHZ
)
1632 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (3 << 3)) | 3;
1634 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (5 << 3));
1635 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
1637 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
1641 IWL_DEBUG_SCAN(priv
, "Scanning %d [%s %d]\n",
1643 (scan_ch
->type
& 1) ? "ACTIVE" : "PASSIVE",
1644 (scan_ch
->type
& 1) ?
1645 active_dwell
: passive_dwell
);
1651 IWL_DEBUG_SCAN(priv
, "total channels to scan %d\n", added
);
1655 static void iwl3945_init_hw_rates(struct iwl_priv
*priv
,
1656 struct ieee80211_rate
*rates
)
1660 for (i
= 0; i
< IWL_RATE_COUNT_LEGACY
; i
++) {
1661 rates
[i
].bitrate
= iwl3945_rates
[i
].ieee
* 5;
1662 rates
[i
].hw_value
= i
; /* Rate scaling will work on indexes */
1663 rates
[i
].hw_value_short
= i
;
1665 if ((i
> IWL39_LAST_OFDM_RATE
) || (i
< IWL_FIRST_OFDM_RATE
)) {
1667 * If CCK != 1M then set short preamble rate flag.
1669 rates
[i
].flags
|= (iwl3945_rates
[i
].plcp
== 10) ?
1670 0 : IEEE80211_RATE_SHORT_PREAMBLE
;
1675 /******************************************************************************
1677 * uCode download functions
1679 ******************************************************************************/
1681 static void iwl3945_dealloc_ucode_pci(struct iwl_priv
*priv
)
1683 iwl_legacy_free_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
1684 iwl_legacy_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
1685 iwl_legacy_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
1686 iwl_legacy_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
1687 iwl_legacy_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
1688 iwl_legacy_free_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
1692 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
1693 * looking at all data.
1695 static int iwl3945_verify_inst_full(struct iwl_priv
*priv
, __le32
*image
, u32 len
)
1702 IWL_DEBUG_INFO(priv
, "ucode inst image size is %u\n", len
);
1704 iwl_legacy_write_direct32(priv
, HBUS_TARG_MEM_RADDR
,
1705 IWL39_RTC_INST_LOWER_BOUND
);
1708 for (; len
> 0; len
-= sizeof(u32
), image
++) {
1709 /* read data comes through single port, auto-incr addr */
1710 /* NOTE: Use the debugless read so we don't flood kernel log
1711 * if IWL_DL_IO is set */
1712 val
= _iwl_legacy_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
1713 if (val
!= le32_to_cpu(*image
)) {
1714 IWL_ERR(priv
, "uCode INST section is invalid at "
1715 "offset 0x%x, is 0x%x, s/b 0x%x\n",
1716 save_len
- len
, val
, le32_to_cpu(*image
));
1726 IWL_DEBUG_INFO(priv
,
1727 "ucode image in INSTRUCTION memory is good\n");
1734 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
1735 * using sample data 100 bytes apart. If these sample points are good,
1736 * it's a pretty good bet that everything between them is good, too.
1738 static int iwl3945_verify_inst_sparse(struct iwl_priv
*priv
, __le32
*image
, u32 len
)
1745 IWL_DEBUG_INFO(priv
, "ucode inst image size is %u\n", len
);
1747 for (i
= 0; i
< len
; i
+= 100, image
+= 100/sizeof(u32
)) {
1748 /* read data comes through single port, auto-incr addr */
1749 /* NOTE: Use the debugless read so we don't flood kernel log
1750 * if IWL_DL_IO is set */
1751 iwl_legacy_write_direct32(priv
, HBUS_TARG_MEM_RADDR
,
1752 i
+ IWL39_RTC_INST_LOWER_BOUND
);
1753 val
= _iwl_legacy_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
1754 if (val
!= le32_to_cpu(*image
)) {
1755 #if 0 /* Enable this if you want to see details */
1756 IWL_ERR(priv
, "uCode INST section is invalid at "
1757 "offset 0x%x, is 0x%x, s/b 0x%x\n",
1772 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
1773 * and verify its contents
1775 static int iwl3945_verify_ucode(struct iwl_priv
*priv
)
1782 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
1783 len
= priv
->ucode_boot
.len
;
1784 rc
= iwl3945_verify_inst_sparse(priv
, image
, len
);
1786 IWL_DEBUG_INFO(priv
, "Bootstrap uCode is good in inst SRAM\n");
1790 /* Try initialize */
1791 image
= (__le32
*)priv
->ucode_init
.v_addr
;
1792 len
= priv
->ucode_init
.len
;
1793 rc
= iwl3945_verify_inst_sparse(priv
, image
, len
);
1795 IWL_DEBUG_INFO(priv
, "Initialize uCode is good in inst SRAM\n");
1799 /* Try runtime/protocol */
1800 image
= (__le32
*)priv
->ucode_code
.v_addr
;
1801 len
= priv
->ucode_code
.len
;
1802 rc
= iwl3945_verify_inst_sparse(priv
, image
, len
);
1804 IWL_DEBUG_INFO(priv
, "Runtime uCode is good in inst SRAM\n");
1808 IWL_ERR(priv
, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
1810 /* Since nothing seems to match, show first several data entries in
1811 * instruction SRAM, so maybe visual inspection will give a clue.
1812 * Selection of bootstrap image (vs. other images) is arbitrary. */
1813 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
1814 len
= priv
->ucode_boot
.len
;
1815 rc
= iwl3945_verify_inst_full(priv
, image
, len
);
1820 static void iwl3945_nic_start(struct iwl_priv
*priv
)
1822 /* Remove all resets to allow NIC to operate */
1823 iwl_write32(priv
, CSR_RESET
, 0);
1826 #define IWL3945_UCODE_GET(item) \
1827 static u32 iwl3945_ucode_get_##item(const struct iwl_ucode_header *ucode)\
1829 return le32_to_cpu(ucode->v1.item); \
1832 static u32
iwl3945_ucode_get_header_size(u32 api_ver
)
1837 static u8
*iwl3945_ucode_get_data(const struct iwl_ucode_header
*ucode
)
1839 return (u8
*) ucode
->v1
.data
;
1842 IWL3945_UCODE_GET(inst_size
);
1843 IWL3945_UCODE_GET(data_size
);
1844 IWL3945_UCODE_GET(init_size
);
1845 IWL3945_UCODE_GET(init_data_size
);
1846 IWL3945_UCODE_GET(boot_size
);
1849 * iwl3945_read_ucode - Read uCode images from disk file.
1851 * Copy into buffers for card to fetch via bus-mastering
1853 static int iwl3945_read_ucode(struct iwl_priv
*priv
)
1855 const struct iwl_ucode_header
*ucode
;
1856 int ret
= -EINVAL
, index
;
1857 const struct firmware
*ucode_raw
;
1858 /* firmware file name contains uCode/driver compatibility version */
1859 const char *name_pre
= priv
->cfg
->fw_name_pre
;
1860 const unsigned int api_max
= priv
->cfg
->ucode_api_max
;
1861 const unsigned int api_min
= priv
->cfg
->ucode_api_min
;
1865 u32 api_ver
, inst_size
, data_size
, init_size
, init_data_size
, boot_size
;
1867 /* Ask kernel firmware_class module to get the boot firmware off disk.
1868 * request_firmware() is synchronous, file is in memory on return. */
1869 for (index
= api_max
; index
>= api_min
; index
--) {
1870 sprintf(buf
, "%s%u%s", name_pre
, index
, ".ucode");
1871 ret
= request_firmware(&ucode_raw
, buf
, &priv
->pci_dev
->dev
);
1873 IWL_ERR(priv
, "%s firmware file req failed: %d\n",
1880 if (index
< api_max
)
1881 IWL_ERR(priv
, "Loaded firmware %s, "
1882 "which is deprecated. "
1883 " Please use API v%u instead.\n",
1885 IWL_DEBUG_INFO(priv
, "Got firmware '%s' file "
1886 "(%zd bytes) from disk\n",
1887 buf
, ucode_raw
->size
);
1895 /* Make sure that we got at least our header! */
1896 if (ucode_raw
->size
< iwl3945_ucode_get_header_size(1)) {
1897 IWL_ERR(priv
, "File size way too small!\n");
1902 /* Data from ucode file: header followed by uCode images */
1903 ucode
= (struct iwl_ucode_header
*)ucode_raw
->data
;
1905 priv
->ucode_ver
= le32_to_cpu(ucode
->ver
);
1906 api_ver
= IWL_UCODE_API(priv
->ucode_ver
);
1907 inst_size
= iwl3945_ucode_get_inst_size(ucode
);
1908 data_size
= iwl3945_ucode_get_data_size(ucode
);
1909 init_size
= iwl3945_ucode_get_init_size(ucode
);
1910 init_data_size
= iwl3945_ucode_get_init_data_size(ucode
);
1911 boot_size
= iwl3945_ucode_get_boot_size(ucode
);
1912 src
= iwl3945_ucode_get_data(ucode
);
1914 /* api_ver should match the api version forming part of the
1915 * firmware filename ... but we don't check for that and only rely
1916 * on the API version read from firmware header from here on forward */
1918 if (api_ver
< api_min
|| api_ver
> api_max
) {
1919 IWL_ERR(priv
, "Driver unable to support your firmware API. "
1920 "Driver supports v%u, firmware is v%u.\n",
1922 priv
->ucode_ver
= 0;
1926 if (api_ver
!= api_max
)
1927 IWL_ERR(priv
, "Firmware has old API version. Expected %u, "
1928 "got %u. New firmware can be obtained "
1929 "from http://www.intellinuxwireless.org.\n",
1932 IWL_INFO(priv
, "loaded firmware version %u.%u.%u.%u\n",
1933 IWL_UCODE_MAJOR(priv
->ucode_ver
),
1934 IWL_UCODE_MINOR(priv
->ucode_ver
),
1935 IWL_UCODE_API(priv
->ucode_ver
),
1936 IWL_UCODE_SERIAL(priv
->ucode_ver
));
1938 snprintf(priv
->hw
->wiphy
->fw_version
,
1939 sizeof(priv
->hw
->wiphy
->fw_version
),
1941 IWL_UCODE_MAJOR(priv
->ucode_ver
),
1942 IWL_UCODE_MINOR(priv
->ucode_ver
),
1943 IWL_UCODE_API(priv
->ucode_ver
),
1944 IWL_UCODE_SERIAL(priv
->ucode_ver
));
1946 IWL_DEBUG_INFO(priv
, "f/w package hdr ucode version raw = 0x%x\n",
1948 IWL_DEBUG_INFO(priv
, "f/w package hdr runtime inst size = %u\n",
1950 IWL_DEBUG_INFO(priv
, "f/w package hdr runtime data size = %u\n",
1952 IWL_DEBUG_INFO(priv
, "f/w package hdr init inst size = %u\n",
1954 IWL_DEBUG_INFO(priv
, "f/w package hdr init data size = %u\n",
1956 IWL_DEBUG_INFO(priv
, "f/w package hdr boot inst size = %u\n",
1960 /* Verify size of file vs. image size info in file's header */
1961 if (ucode_raw
->size
!= iwl3945_ucode_get_header_size(api_ver
) +
1962 inst_size
+ data_size
+ init_size
+
1963 init_data_size
+ boot_size
) {
1965 IWL_DEBUG_INFO(priv
,
1966 "uCode file size %zd does not match expected size\n",
1972 /* Verify that uCode images will fit in card's SRAM */
1973 if (inst_size
> IWL39_MAX_INST_SIZE
) {
1974 IWL_DEBUG_INFO(priv
, "uCode instr len %d too large to fit in\n",
1980 if (data_size
> IWL39_MAX_DATA_SIZE
) {
1981 IWL_DEBUG_INFO(priv
, "uCode data len %d too large to fit in\n",
1986 if (init_size
> IWL39_MAX_INST_SIZE
) {
1987 IWL_DEBUG_INFO(priv
,
1988 "uCode init instr len %d too large to fit in\n",
1993 if (init_data_size
> IWL39_MAX_DATA_SIZE
) {
1994 IWL_DEBUG_INFO(priv
,
1995 "uCode init data len %d too large to fit in\n",
2000 if (boot_size
> IWL39_MAX_BSM_SIZE
) {
2001 IWL_DEBUG_INFO(priv
,
2002 "uCode boot instr len %d too large to fit in\n",
2008 /* Allocate ucode buffers for card's bus-master loading ... */
2010 /* Runtime instructions and 2 copies of data:
2011 * 1) unmodified from disk
2012 * 2) backup cache for save/restore during power-downs */
2013 priv
->ucode_code
.len
= inst_size
;
2014 iwl_legacy_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
2016 priv
->ucode_data
.len
= data_size
;
2017 iwl_legacy_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
2019 priv
->ucode_data_backup
.len
= data_size
;
2020 iwl_legacy_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
2022 if (!priv
->ucode_code
.v_addr
|| !priv
->ucode_data
.v_addr
||
2023 !priv
->ucode_data_backup
.v_addr
)
2026 /* Initialization instructions and data */
2027 if (init_size
&& init_data_size
) {
2028 priv
->ucode_init
.len
= init_size
;
2029 iwl_legacy_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
2031 priv
->ucode_init_data
.len
= init_data_size
;
2032 iwl_legacy_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
2034 if (!priv
->ucode_init
.v_addr
|| !priv
->ucode_init_data
.v_addr
)
2038 /* Bootstrap (instructions only, no data) */
2040 priv
->ucode_boot
.len
= boot_size
;
2041 iwl_legacy_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
2043 if (!priv
->ucode_boot
.v_addr
)
2047 /* Copy images into buffers for card's bus-master reads ... */
2049 /* Runtime instructions (first block of data in file) */
2051 IWL_DEBUG_INFO(priv
,
2052 "Copying (but not loading) uCode instr len %zd\n", len
);
2053 memcpy(priv
->ucode_code
.v_addr
, src
, len
);
2056 IWL_DEBUG_INFO(priv
, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
2057 priv
->ucode_code
.v_addr
, (u32
)priv
->ucode_code
.p_addr
);
2059 /* Runtime data (2nd block)
2060 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
2062 IWL_DEBUG_INFO(priv
,
2063 "Copying (but not loading) uCode data len %zd\n", len
);
2064 memcpy(priv
->ucode_data
.v_addr
, src
, len
);
2065 memcpy(priv
->ucode_data_backup
.v_addr
, src
, len
);
2068 /* Initialization instructions (3rd block) */
2071 IWL_DEBUG_INFO(priv
,
2072 "Copying (but not loading) init instr len %zd\n", len
);
2073 memcpy(priv
->ucode_init
.v_addr
, src
, len
);
2077 /* Initialization data (4th block) */
2078 if (init_data_size
) {
2079 len
= init_data_size
;
2080 IWL_DEBUG_INFO(priv
,
2081 "Copying (but not loading) init data len %zd\n", len
);
2082 memcpy(priv
->ucode_init_data
.v_addr
, src
, len
);
2086 /* Bootstrap instructions (5th block) */
2088 IWL_DEBUG_INFO(priv
,
2089 "Copying (but not loading) boot instr len %zd\n", len
);
2090 memcpy(priv
->ucode_boot
.v_addr
, src
, len
);
2092 /* We have our copies now, allow OS release its copies */
2093 release_firmware(ucode_raw
);
2097 IWL_ERR(priv
, "failed to allocate pci memory\n");
2099 iwl3945_dealloc_ucode_pci(priv
);
2102 release_firmware(ucode_raw
);
2110 * iwl3945_set_ucode_ptrs - Set uCode address location
2112 * Tell initialization uCode where to find runtime uCode.
2114 * BSM registers initially contain pointers to initialization uCode.
2115 * We need to replace them to load runtime uCode inst and data,
2116 * and to save runtime data when powering down.
2118 static int iwl3945_set_ucode_ptrs(struct iwl_priv
*priv
)
2123 /* bits 31:0 for 3945 */
2124 pinst
= priv
->ucode_code
.p_addr
;
2125 pdata
= priv
->ucode_data_backup
.p_addr
;
2127 /* Tell bootstrap uCode where to find image to load */
2128 iwl_legacy_write_prph(priv
, BSM_DRAM_INST_PTR_REG
, pinst
);
2129 iwl_legacy_write_prph(priv
, BSM_DRAM_DATA_PTR_REG
, pdata
);
2130 iwl_legacy_write_prph(priv
, BSM_DRAM_DATA_BYTECOUNT_REG
,
2131 priv
->ucode_data
.len
);
2133 /* Inst byte count must be last to set up, bit 31 signals uCode
2134 * that all new ptr/size info is in place */
2135 iwl_legacy_write_prph(priv
, BSM_DRAM_INST_BYTECOUNT_REG
,
2136 priv
->ucode_code
.len
| BSM_DRAM_INST_LOAD
);
2138 IWL_DEBUG_INFO(priv
, "Runtime uCode pointers are set.\n");
2144 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
2146 * Called after REPLY_ALIVE notification received from "initialize" uCode.
2148 * Tell "initialize" uCode to go ahead and load the runtime uCode.
2150 static void iwl3945_init_alive_start(struct iwl_priv
*priv
)
2152 /* Check alive response for "valid" sign from uCode */
2153 if (priv
->card_alive_init
.is_valid
!= UCODE_VALID_OK
) {
2154 /* We had an error bringing up the hardware, so take it
2155 * all the way back down so we can try again */
2156 IWL_DEBUG_INFO(priv
, "Initialize Alive failed.\n");
2160 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
2161 * This is a paranoid check, because we would not have gotten the
2162 * "initialize" alive if code weren't properly loaded. */
2163 if (iwl3945_verify_ucode(priv
)) {
2164 /* Runtime instruction load was bad;
2165 * take it all the way back down so we can try again */
2166 IWL_DEBUG_INFO(priv
, "Bad \"initialize\" uCode load.\n");
2170 /* Send pointers to protocol/runtime uCode image ... init code will
2171 * load and launch runtime uCode, which will send us another "Alive"
2173 IWL_DEBUG_INFO(priv
, "Initialization Alive received.\n");
2174 if (iwl3945_set_ucode_ptrs(priv
)) {
2175 /* Runtime instruction load won't happen;
2176 * take it all the way back down so we can try again */
2177 IWL_DEBUG_INFO(priv
, "Couldn't set up uCode pointers.\n");
2183 queue_work(priv
->workqueue
, &priv
->restart
);
2187 * iwl3945_alive_start - called after REPLY_ALIVE notification received
2188 * from protocol/runtime uCode (initialization uCode's
2189 * Alive gets handled by iwl3945_init_alive_start()).
2191 static void iwl3945_alive_start(struct iwl_priv
*priv
)
2193 int thermal_spin
= 0;
2195 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
2197 IWL_DEBUG_INFO(priv
, "Runtime Alive received.\n");
2199 if (priv
->card_alive
.is_valid
!= UCODE_VALID_OK
) {
2200 /* We had an error bringing up the hardware, so take it
2201 * all the way back down so we can try again */
2202 IWL_DEBUG_INFO(priv
, "Alive failed.\n");
2206 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2207 * This is a paranoid check, because we would not have gotten the
2208 * "runtime" alive if code weren't properly loaded. */
2209 if (iwl3945_verify_ucode(priv
)) {
2210 /* Runtime instruction load was bad;
2211 * take it all the way back down so we can try again */
2212 IWL_DEBUG_INFO(priv
, "Bad runtime uCode load.\n");
2216 rfkill
= iwl_legacy_read_prph(priv
, APMG_RFKILL_REG
);
2217 IWL_DEBUG_INFO(priv
, "RFKILL status: 0x%x\n", rfkill
);
2220 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2221 /* if RFKILL is not on, then wait for thermal
2222 * sensor in adapter to kick in */
2223 while (iwl3945_hw_get_temperature(priv
) == 0) {
2229 IWL_DEBUG_INFO(priv
, "Thermal calibration took %dus\n",
2232 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2234 /* After the ALIVE response, we can send commands to 3945 uCode */
2235 set_bit(STATUS_ALIVE
, &priv
->status
);
2237 /* Enable watchdog to monitor the driver tx queues */
2238 iwl_legacy_setup_watchdog(priv
);
2240 if (iwl_legacy_is_rfkill(priv
))
2243 ieee80211_wake_queues(priv
->hw
);
2245 priv
->active_rate
= IWL_RATES_MASK_3945
;
2247 iwl_legacy_power_update_mode(priv
, true);
2249 if (iwl_legacy_is_associated(priv
, IWL_RXON_CTX_BSS
)) {
2250 struct iwl3945_rxon_cmd
*active_rxon
=
2251 (struct iwl3945_rxon_cmd
*)(&ctx
->active
);
2253 ctx
->staging
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
2254 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
2256 /* Initialize our rx_config data */
2257 iwl_legacy_connection_init_rx_config(priv
, ctx
);
2260 /* Configure Bluetooth device coexistence support */
2261 iwl_legacy_send_bt_config(priv
);
2263 set_bit(STATUS_READY
, &priv
->status
);
2265 /* Configure the adapter for unassociated operation */
2266 iwl3945_commit_rxon(priv
, ctx
);
2268 iwl3945_reg_txpower_periodic(priv
);
2270 IWL_DEBUG_INFO(priv
, "ALIVE processing complete.\n");
2271 wake_up_interruptible(&priv
->wait_command_queue
);
2276 queue_work(priv
->workqueue
, &priv
->restart
);
2279 static void iwl3945_cancel_deferred_work(struct iwl_priv
*priv
);
2281 static void __iwl3945_down(struct iwl_priv
*priv
)
2283 unsigned long flags
;
2286 IWL_DEBUG_INFO(priv
, DRV_NAME
" is going down\n");
2288 iwl_legacy_scan_cancel_timeout(priv
, 200);
2290 exit_pending
= test_and_set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
2292 /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
2293 * to prevent rearm timer */
2294 del_timer_sync(&priv
->watchdog
);
2296 /* Station information will now be cleared in device */
2297 iwl_legacy_clear_ucode_stations(priv
, NULL
);
2298 iwl_legacy_dealloc_bcast_stations(priv
);
2299 iwl_legacy_clear_driver_stations(priv
);
2301 /* Unblock any waiting calls */
2302 wake_up_interruptible_all(&priv
->wait_command_queue
);
2304 /* Wipe out the EXIT_PENDING status bit if we are not actually
2305 * exiting the module */
2307 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
2309 /* stop and reset the on-board processor */
2310 iwl_write32(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_NEVO_RESET
);
2312 /* tell the device to stop sending interrupts */
2313 spin_lock_irqsave(&priv
->lock
, flags
);
2314 iwl_legacy_disable_interrupts(priv
);
2315 spin_unlock_irqrestore(&priv
->lock
, flags
);
2316 iwl3945_synchronize_irq(priv
);
2318 if (priv
->mac80211_registered
)
2319 ieee80211_stop_queues(priv
->hw
);
2321 /* If we have not previously called iwl3945_init() then
2322 * clear all bits but the RF Kill bits and return */
2323 if (!iwl_legacy_is_init(priv
)) {
2324 priv
->status
= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
2326 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
2327 STATUS_GEO_CONFIGURED
|
2328 test_bit(STATUS_EXIT_PENDING
, &priv
->status
) <<
2329 STATUS_EXIT_PENDING
;
2333 /* ...otherwise clear out all the status bits but the RF Kill
2334 * bit and continue taking the NIC down. */
2335 priv
->status
&= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
2337 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
2338 STATUS_GEO_CONFIGURED
|
2339 test_bit(STATUS_FW_ERROR
, &priv
->status
) <<
2341 test_bit(STATUS_EXIT_PENDING
, &priv
->status
) <<
2342 STATUS_EXIT_PENDING
;
2344 iwl3945_hw_txq_ctx_stop(priv
);
2345 iwl3945_hw_rxq_stop(priv
);
2347 /* Power-down device's busmaster DMA clocks */
2348 iwl_legacy_write_prph(priv
, APMG_CLK_DIS_REG
, APMG_CLK_VAL_DMA_CLK_RQT
);
2351 /* Stop the device, and put it in low power state */
2352 iwl_legacy_apm_stop(priv
);
2355 memset(&priv
->card_alive
, 0, sizeof(struct iwl_alive_resp
));
2357 if (priv
->beacon_skb
)
2358 dev_kfree_skb(priv
->beacon_skb
);
2359 priv
->beacon_skb
= NULL
;
2361 /* clear out any free frames */
2362 iwl3945_clear_free_frames(priv
);
2365 static void iwl3945_down(struct iwl_priv
*priv
)
2367 mutex_lock(&priv
->mutex
);
2368 __iwl3945_down(priv
);
2369 mutex_unlock(&priv
->mutex
);
2371 iwl3945_cancel_deferred_work(priv
);
2374 #define MAX_HW_RESTARTS 5
2376 static int iwl3945_alloc_bcast_station(struct iwl_priv
*priv
)
2378 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
2379 unsigned long flags
;
2382 spin_lock_irqsave(&priv
->sta_lock
, flags
);
2383 sta_id
= iwl_legacy_prep_station(priv
, ctx
,
2384 iwlegacy_bcast_addr
, false, NULL
);
2385 if (sta_id
== IWL_INVALID_STATION
) {
2386 IWL_ERR(priv
, "Unable to prepare broadcast station\n");
2387 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
2392 priv
->stations
[sta_id
].used
|= IWL_STA_DRIVER_ACTIVE
;
2393 priv
->stations
[sta_id
].used
|= IWL_STA_BCAST
;
2394 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
2399 static int __iwl3945_up(struct iwl_priv
*priv
)
2403 rc
= iwl3945_alloc_bcast_station(priv
);
2407 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
2408 IWL_WARN(priv
, "Exit pending; will not bring the NIC up\n");
2412 if (!priv
->ucode_data_backup
.v_addr
|| !priv
->ucode_data
.v_addr
) {
2413 IWL_ERR(priv
, "ucode not available for device bring up\n");
2417 /* If platform's RF_KILL switch is NOT set to KILL */
2418 if (iwl_read32(priv
, CSR_GP_CNTRL
) &
2419 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
)
2420 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2422 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2423 IWL_WARN(priv
, "Radio disabled by HW RF Kill switch\n");
2427 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
2429 rc
= iwl3945_hw_nic_init(priv
);
2431 IWL_ERR(priv
, "Unable to int nic\n");
2435 /* make sure rfkill handshake bits are cleared */
2436 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2437 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
2438 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
2440 /* clear (again), then enable host interrupts */
2441 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
2442 iwl_legacy_enable_interrupts(priv
);
2444 /* really make sure rfkill handshake bits are cleared */
2445 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2446 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2448 /* Copy original ucode data image from disk into backup cache.
2449 * This will be used to initialize the on-board processor's
2450 * data SRAM for a clean start when the runtime program first loads. */
2451 memcpy(priv
->ucode_data_backup
.v_addr
, priv
->ucode_data
.v_addr
,
2452 priv
->ucode_data
.len
);
2454 /* We return success when we resume from suspend and rf_kill is on. */
2455 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
2458 for (i
= 0; i
< MAX_HW_RESTARTS
; i
++) {
2460 /* load bootstrap state machine,
2461 * load bootstrap program into processor's memory,
2462 * prepare to load the "initialize" uCode */
2463 rc
= priv
->cfg
->ops
->lib
->load_ucode(priv
);
2467 "Unable to set up bootstrap uCode: %d\n", rc
);
2471 /* start card; "initialize" will load runtime ucode */
2472 iwl3945_nic_start(priv
);
2474 IWL_DEBUG_INFO(priv
, DRV_NAME
" is coming up\n");
2479 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
2480 __iwl3945_down(priv
);
2481 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
2483 /* tried to restart and config the device for as long as our
2484 * patience could withstand */
2485 IWL_ERR(priv
, "Unable to initialize device after %d attempts.\n", i
);
2490 /*****************************************************************************
2492 * Workqueue callbacks
2494 *****************************************************************************/
2496 static void iwl3945_bg_init_alive_start(struct work_struct
*data
)
2498 struct iwl_priv
*priv
=
2499 container_of(data
, struct iwl_priv
, init_alive_start
.work
);
2501 mutex_lock(&priv
->mutex
);
2502 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2505 iwl3945_init_alive_start(priv
);
2507 mutex_unlock(&priv
->mutex
);
2510 static void iwl3945_bg_alive_start(struct work_struct
*data
)
2512 struct iwl_priv
*priv
=
2513 container_of(data
, struct iwl_priv
, alive_start
.work
);
2515 mutex_lock(&priv
->mutex
);
2516 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2519 iwl3945_alive_start(priv
);
2521 mutex_unlock(&priv
->mutex
);
2525 * 3945 cannot interrupt driver when hardware rf kill switch toggles;
2526 * driver must poll CSR_GP_CNTRL_REG register for change. This register
2527 * *is* readable even when device has been SW_RESET into low power mode
2528 * (e.g. during RF KILL).
2530 static void iwl3945_rfkill_poll(struct work_struct
*data
)
2532 struct iwl_priv
*priv
=
2533 container_of(data
, struct iwl_priv
, _3945
.rfkill_poll
.work
);
2534 bool old_rfkill
= test_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2535 bool new_rfkill
= !(iwl_read32(priv
, CSR_GP_CNTRL
)
2536 & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
);
2538 if (new_rfkill
!= old_rfkill
) {
2540 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2542 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2544 wiphy_rfkill_set_hw_state(priv
->hw
->wiphy
, new_rfkill
);
2546 IWL_DEBUG_RF_KILL(priv
, "RF_KILL bit toggled to %s.\n",
2547 new_rfkill
? "disable radio" : "enable radio");
2550 /* Keep this running, even if radio now enabled. This will be
2551 * cancelled in mac_start() if system decides to start again */
2552 queue_delayed_work(priv
->workqueue
, &priv
->_3945
.rfkill_poll
,
2553 round_jiffies_relative(2 * HZ
));
2557 int iwl3945_request_scan(struct iwl_priv
*priv
, struct ieee80211_vif
*vif
)
2559 struct iwl_host_cmd cmd
= {
2560 .id
= REPLY_SCAN_CMD
,
2561 .len
= sizeof(struct iwl3945_scan_cmd
),
2562 .flags
= CMD_SIZE_HUGE
,
2564 struct iwl3945_scan_cmd
*scan
;
2566 enum ieee80211_band band
;
2567 bool is_active
= false;
2571 lockdep_assert_held(&priv
->mutex
);
2573 if (!priv
->scan_cmd
) {
2574 priv
->scan_cmd
= kmalloc(sizeof(struct iwl3945_scan_cmd
) +
2575 IWL_MAX_SCAN_SIZE
, GFP_KERNEL
);
2576 if (!priv
->scan_cmd
) {
2577 IWL_DEBUG_SCAN(priv
, "Fail to allocate scan memory\n");
2581 scan
= priv
->scan_cmd
;
2582 memset(scan
, 0, sizeof(struct iwl3945_scan_cmd
) + IWL_MAX_SCAN_SIZE
);
2584 scan
->quiet_plcp_th
= IWL_PLCP_QUIET_THRESH
;
2585 scan
->quiet_time
= IWL_ACTIVE_QUIET_TIME
;
2587 if (iwl_legacy_is_associated(priv
, IWL_RXON_CTX_BSS
)) {
2590 u32 suspend_time
= 100;
2591 u32 scan_suspend_time
= 100;
2593 IWL_DEBUG_INFO(priv
, "Scanning while associated...\n");
2595 interval
= vif
->bss_conf
.beacon_int
;
2597 scan
->suspend_time
= 0;
2598 scan
->max_out_time
= cpu_to_le32(200 * 1024);
2600 interval
= suspend_time
;
2602 * suspend time format:
2603 * 0-19: beacon interval in usec (time before exec.)
2605 * 24-31: number of beacons (suspend between channels)
2608 extra
= (suspend_time
/ interval
) << 24;
2609 scan_suspend_time
= 0xFF0FFFFF &
2610 (extra
| ((suspend_time
% interval
) * 1024));
2612 scan
->suspend_time
= cpu_to_le32(scan_suspend_time
);
2613 IWL_DEBUG_SCAN(priv
, "suspend_time 0x%X beacon interval %d\n",
2614 scan_suspend_time
, interval
);
2617 if (priv
->scan_request
->n_ssids
) {
2619 IWL_DEBUG_SCAN(priv
, "Kicking off active scan\n");
2620 for (i
= 0; i
< priv
->scan_request
->n_ssids
; i
++) {
2621 /* always does wildcard anyway */
2622 if (!priv
->scan_request
->ssids
[i
].ssid_len
)
2624 scan
->direct_scan
[p
].id
= WLAN_EID_SSID
;
2625 scan
->direct_scan
[p
].len
=
2626 priv
->scan_request
->ssids
[i
].ssid_len
;
2627 memcpy(scan
->direct_scan
[p
].ssid
,
2628 priv
->scan_request
->ssids
[i
].ssid
,
2629 priv
->scan_request
->ssids
[i
].ssid_len
);
2635 IWL_DEBUG_SCAN(priv
, "Kicking off passive scan.\n");
2637 /* We don't build a direct scan probe request; the uCode will do
2638 * that based on the direct_mask added to each channel entry */
2639 scan
->tx_cmd
.tx_flags
= TX_CMD_FLG_SEQ_CTL_MSK
;
2640 scan
->tx_cmd
.sta_id
= priv
->contexts
[IWL_RXON_CTX_BSS
].bcast_sta_id
;
2641 scan
->tx_cmd
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
2643 /* flags + rate selection */
2645 switch (priv
->scan_band
) {
2646 case IEEE80211_BAND_2GHZ
:
2647 scan
->flags
= RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
;
2648 scan
->tx_cmd
.rate
= IWL_RATE_1M_PLCP
;
2649 band
= IEEE80211_BAND_2GHZ
;
2651 case IEEE80211_BAND_5GHZ
:
2652 scan
->tx_cmd
.rate
= IWL_RATE_6M_PLCP
;
2653 band
= IEEE80211_BAND_5GHZ
;
2656 IWL_WARN(priv
, "Invalid scan band\n");
2661 * If active scaning is requested but a certain channel
2662 * is marked passive, we can do active scanning if we
2663 * detect transmissions.
2665 scan
->good_CRC_th
= is_active
? IWL_GOOD_CRC_TH_DEFAULT
:
2666 IWL_GOOD_CRC_TH_DISABLED
;
2668 len
= iwl_legacy_fill_probe_req(priv
, (struct ieee80211_mgmt
*)scan
->data
,
2669 vif
->addr
, priv
->scan_request
->ie
,
2670 priv
->scan_request
->ie_len
,
2671 IWL_MAX_SCAN_SIZE
- sizeof(*scan
));
2672 scan
->tx_cmd
.len
= cpu_to_le16(len
);
2674 /* select Rx antennas */
2675 scan
->flags
|= iwl3945_get_antenna_flags(priv
);
2677 scan
->channel_count
= iwl3945_get_channels_for_scan(priv
, band
, is_active
, n_probes
,
2678 (void *)&scan
->data
[len
], vif
);
2679 if (scan
->channel_count
== 0) {
2680 IWL_DEBUG_SCAN(priv
, "channel count %d\n", scan
->channel_count
);
2684 cmd
.len
+= le16_to_cpu(scan
->tx_cmd
.len
) +
2685 scan
->channel_count
* sizeof(struct iwl3945_scan_channel
);
2687 scan
->len
= cpu_to_le16(cmd
.len
);
2689 set_bit(STATUS_SCAN_HW
, &priv
->status
);
2690 ret
= iwl_legacy_send_cmd_sync(priv
, &cmd
);
2692 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
2696 void iwl3945_post_scan(struct iwl_priv
*priv
)
2698 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
2701 * Since setting the RXON may have been deferred while
2702 * performing the scan, fire one off if needed
2704 if (memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
2705 iwl3945_commit_rxon(priv
, ctx
);
2708 static void iwl3945_bg_restart(struct work_struct
*data
)
2710 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, restart
);
2712 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2715 if (test_and_clear_bit(STATUS_FW_ERROR
, &priv
->status
)) {
2716 struct iwl_rxon_context
*ctx
;
2717 mutex_lock(&priv
->mutex
);
2718 for_each_context(priv
, ctx
)
2721 mutex_unlock(&priv
->mutex
);
2723 ieee80211_restart_hw(priv
->hw
);
2727 mutex_lock(&priv
->mutex
);
2728 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
2729 mutex_unlock(&priv
->mutex
);
2734 mutex_unlock(&priv
->mutex
);
2738 static void iwl3945_bg_rx_replenish(struct work_struct
*data
)
2740 struct iwl_priv
*priv
=
2741 container_of(data
, struct iwl_priv
, rx_replenish
);
2743 mutex_lock(&priv
->mutex
);
2744 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2747 iwl3945_rx_replenish(priv
);
2749 mutex_unlock(&priv
->mutex
);
2752 void iwl3945_post_associate(struct iwl_priv
*priv
)
2755 struct ieee80211_conf
*conf
= NULL
;
2756 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
2758 if (!ctx
->vif
|| !priv
->is_open
)
2761 IWL_DEBUG_ASSOC(priv
, "Associated as %d to: %pM\n",
2762 ctx
->vif
->bss_conf
.aid
, ctx
->active
.bssid_addr
);
2764 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2767 iwl_legacy_scan_cancel_timeout(priv
, 200);
2769 conf
= iwl_legacy_ieee80211_get_hw_conf(priv
->hw
);
2771 ctx
->staging
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
2772 iwl3945_commit_rxon(priv
, ctx
);
2774 rc
= iwl_legacy_send_rxon_timing(priv
, ctx
);
2776 IWL_WARN(priv
, "REPLY_RXON_TIMING failed - "
2777 "Attempting to continue.\n");
2779 ctx
->staging
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
2781 ctx
->staging
.assoc_id
= cpu_to_le16(ctx
->vif
->bss_conf
.aid
);
2783 IWL_DEBUG_ASSOC(priv
, "assoc id %d beacon interval %d\n",
2784 ctx
->vif
->bss_conf
.aid
, ctx
->vif
->bss_conf
.beacon_int
);
2786 if (ctx
->vif
->bss_conf
.use_short_preamble
)
2787 ctx
->staging
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
2789 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
2791 if (ctx
->staging
.flags
& RXON_FLG_BAND_24G_MSK
) {
2792 if (ctx
->vif
->bss_conf
.use_short_slot
)
2793 ctx
->staging
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
2795 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
2798 iwl3945_commit_rxon(priv
, ctx
);
2800 switch (ctx
->vif
->type
) {
2801 case NL80211_IFTYPE_STATION
:
2802 iwl3945_rate_scale_init(priv
->hw
, IWL_AP_ID
);
2804 case NL80211_IFTYPE_ADHOC
:
2805 iwl3945_send_beacon_cmd(priv
);
2808 IWL_ERR(priv
, "%s Should not be called in %d mode\n",
2809 __func__
, ctx
->vif
->type
);
2814 /*****************************************************************************
2816 * mac80211 entry point functions
2818 *****************************************************************************/
2820 #define UCODE_READY_TIMEOUT (2 * HZ)
2822 static int iwl3945_mac_start(struct ieee80211_hw
*hw
)
2824 struct iwl_priv
*priv
= hw
->priv
;
2827 IWL_DEBUG_MAC80211(priv
, "enter\n");
2829 /* we should be verifying the device is ready to be opened */
2830 mutex_lock(&priv
->mutex
);
2832 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
2833 * ucode filename and max sizes are card-specific. */
2835 if (!priv
->ucode_code
.len
) {
2836 ret
= iwl3945_read_ucode(priv
);
2838 IWL_ERR(priv
, "Could not read microcode: %d\n", ret
);
2839 mutex_unlock(&priv
->mutex
);
2840 goto out_release_irq
;
2844 ret
= __iwl3945_up(priv
);
2846 mutex_unlock(&priv
->mutex
);
2849 goto out_release_irq
;
2851 IWL_DEBUG_INFO(priv
, "Start UP work.\n");
2853 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
2854 * mac80211 will not be run successfully. */
2855 ret
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
2856 test_bit(STATUS_READY
, &priv
->status
),
2857 UCODE_READY_TIMEOUT
);
2859 if (!test_bit(STATUS_READY
, &priv
->status
)) {
2861 "Wait for START_ALIVE timeout after %dms.\n",
2862 jiffies_to_msecs(UCODE_READY_TIMEOUT
));
2864 goto out_release_irq
;
2868 /* ucode is running and will send rfkill notifications,
2869 * no need to poll the killswitch state anymore */
2870 cancel_delayed_work(&priv
->_3945
.rfkill_poll
);
2873 IWL_DEBUG_MAC80211(priv
, "leave\n");
2878 IWL_DEBUG_MAC80211(priv
, "leave - failed\n");
2882 static void iwl3945_mac_stop(struct ieee80211_hw
*hw
)
2884 struct iwl_priv
*priv
= hw
->priv
;
2886 IWL_DEBUG_MAC80211(priv
, "enter\n");
2888 if (!priv
->is_open
) {
2889 IWL_DEBUG_MAC80211(priv
, "leave - skip\n");
2897 flush_workqueue(priv
->workqueue
);
2899 /* start polling the killswitch state again */
2900 queue_delayed_work(priv
->workqueue
, &priv
->_3945
.rfkill_poll
,
2901 round_jiffies_relative(2 * HZ
));
2903 IWL_DEBUG_MAC80211(priv
, "leave\n");
2906 static void iwl3945_mac_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
2908 struct iwl_priv
*priv
= hw
->priv
;
2910 IWL_DEBUG_MAC80211(priv
, "enter\n");
2912 IWL_DEBUG_TX(priv
, "dev->xmit(%d bytes) at rate 0x%02x\n", skb
->len
,
2913 ieee80211_get_tx_rate(hw
, IEEE80211_SKB_CB(skb
))->bitrate
);
2915 if (iwl3945_tx_skb(priv
, skb
))
2916 dev_kfree_skb_any(skb
);
2918 IWL_DEBUG_MAC80211(priv
, "leave\n");
2921 void iwl3945_config_ap(struct iwl_priv
*priv
)
2923 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
2924 struct ieee80211_vif
*vif
= ctx
->vif
;
2927 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2930 /* The following should be done only at AP bring up */
2931 if (!(iwl_legacy_is_associated(priv
, IWL_RXON_CTX_BSS
))) {
2933 /* RXON - unassoc (to set timing command) */
2934 ctx
->staging
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
2935 iwl3945_commit_rxon(priv
, ctx
);
2938 rc
= iwl_legacy_send_rxon_timing(priv
, ctx
);
2940 IWL_WARN(priv
, "REPLY_RXON_TIMING failed - "
2941 "Attempting to continue.\n");
2943 ctx
->staging
.assoc_id
= 0;
2945 if (vif
->bss_conf
.use_short_preamble
)
2946 ctx
->staging
.flags
|=
2947 RXON_FLG_SHORT_PREAMBLE_MSK
;
2949 ctx
->staging
.flags
&=
2950 ~RXON_FLG_SHORT_PREAMBLE_MSK
;
2952 if (ctx
->staging
.flags
& RXON_FLG_BAND_24G_MSK
) {
2953 if (vif
->bss_conf
.use_short_slot
)
2954 ctx
->staging
.flags
|=
2955 RXON_FLG_SHORT_SLOT_MSK
;
2957 ctx
->staging
.flags
&=
2958 ~RXON_FLG_SHORT_SLOT_MSK
;
2960 /* restore RXON assoc */
2961 ctx
->staging
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
2962 iwl3945_commit_rxon(priv
, ctx
);
2964 iwl3945_send_beacon_cmd(priv
);
2967 static int iwl3945_mac_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
2968 struct ieee80211_vif
*vif
,
2969 struct ieee80211_sta
*sta
,
2970 struct ieee80211_key_conf
*key
)
2972 struct iwl_priv
*priv
= hw
->priv
;
2974 u8 sta_id
= IWL_INVALID_STATION
;
2977 IWL_DEBUG_MAC80211(priv
, "enter\n");
2979 if (iwl3945_mod_params
.sw_crypto
) {
2980 IWL_DEBUG_MAC80211(priv
, "leave - hwcrypto disabled\n");
2985 * To support IBSS RSN, don't program group keys in IBSS, the
2986 * hardware will then not attempt to decrypt the frames.
2988 if (vif
->type
== NL80211_IFTYPE_ADHOC
&&
2989 !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
2992 static_key
= !iwl_legacy_is_associated(priv
, IWL_RXON_CTX_BSS
);
2995 sta_id
= iwl_legacy_sta_id_or_broadcast(
2996 priv
, &priv
->contexts
[IWL_RXON_CTX_BSS
], sta
);
2997 if (sta_id
== IWL_INVALID_STATION
)
3001 mutex_lock(&priv
->mutex
);
3002 iwl_legacy_scan_cancel_timeout(priv
, 100);
3007 ret
= iwl3945_set_static_key(priv
, key
);
3009 ret
= iwl3945_set_dynamic_key(priv
, key
, sta_id
);
3010 IWL_DEBUG_MAC80211(priv
, "enable hwcrypto key\n");
3014 ret
= iwl3945_remove_static_key(priv
);
3016 ret
= iwl3945_clear_sta_key_info(priv
, sta_id
);
3017 IWL_DEBUG_MAC80211(priv
, "disable hwcrypto key\n");
3023 mutex_unlock(&priv
->mutex
);
3024 IWL_DEBUG_MAC80211(priv
, "leave\n");
3029 static int iwl3945_mac_sta_add(struct ieee80211_hw
*hw
,
3030 struct ieee80211_vif
*vif
,
3031 struct ieee80211_sta
*sta
)
3033 struct iwl_priv
*priv
= hw
->priv
;
3034 struct iwl3945_sta_priv
*sta_priv
= (void *)sta
->drv_priv
;
3036 bool is_ap
= vif
->type
== NL80211_IFTYPE_STATION
;
3039 IWL_DEBUG_INFO(priv
, "received request to add station %pM\n",
3041 mutex_lock(&priv
->mutex
);
3042 IWL_DEBUG_INFO(priv
, "proceeding to add station %pM\n",
3044 sta_priv
->common
.sta_id
= IWL_INVALID_STATION
;
3047 ret
= iwl_legacy_add_station_common(priv
,
3048 &priv
->contexts
[IWL_RXON_CTX_BSS
],
3049 sta
->addr
, is_ap
, sta
, &sta_id
);
3051 IWL_ERR(priv
, "Unable to add station %pM (%d)\n",
3053 /* Should we return success if return code is EEXIST ? */
3054 mutex_unlock(&priv
->mutex
);
3058 sta_priv
->common
.sta_id
= sta_id
;
3060 /* Initialize rate scaling */
3061 IWL_DEBUG_INFO(priv
, "Initializing rate scaling for station %pM\n",
3063 iwl3945_rs_rate_init(priv
, sta
, sta_id
);
3064 mutex_unlock(&priv
->mutex
);
3069 static void iwl3945_configure_filter(struct ieee80211_hw
*hw
,
3070 unsigned int changed_flags
,
3071 unsigned int *total_flags
,
3074 struct iwl_priv
*priv
= hw
->priv
;
3075 __le32 filter_or
= 0, filter_nand
= 0;
3076 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
3078 #define CHK(test, flag) do { \
3079 if (*total_flags & (test)) \
3080 filter_or |= (flag); \
3082 filter_nand |= (flag); \
3085 IWL_DEBUG_MAC80211(priv
, "Enter: changed: 0x%x, total: 0x%x\n",
3086 changed_flags
, *total_flags
);
3088 CHK(FIF_OTHER_BSS
| FIF_PROMISC_IN_BSS
, RXON_FILTER_PROMISC_MSK
);
3089 CHK(FIF_CONTROL
, RXON_FILTER_CTL2HOST_MSK
);
3090 CHK(FIF_BCN_PRBRESP_PROMISC
, RXON_FILTER_BCON_AWARE_MSK
);
3094 mutex_lock(&priv
->mutex
);
3096 ctx
->staging
.filter_flags
&= ~filter_nand
;
3097 ctx
->staging
.filter_flags
|= filter_or
;
3100 * Not committing directly because hardware can perform a scan,
3101 * but even if hw is ready, committing here breaks for some reason,
3102 * we'll eventually commit the filter flags change anyway.
3105 mutex_unlock(&priv
->mutex
);
3108 * Receiving all multicast frames is always enabled by the
3109 * default flags setup in iwl_legacy_connection_init_rx_config()
3110 * since we currently do not support programming multicast
3111 * filters into the device.
3113 *total_flags
&= FIF_OTHER_BSS
| FIF_ALLMULTI
| FIF_PROMISC_IN_BSS
|
3114 FIF_BCN_PRBRESP_PROMISC
| FIF_CONTROL
;
3118 /*****************************************************************************
3122 *****************************************************************************/
3124 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
3127 * The following adds a new attribute to the sysfs representation
3128 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
3129 * used for controlling the debug level.
3131 * See the level definitions in iwl for details.
3133 * The debug_level being managed using sysfs below is a per device debug
3134 * level that is used instead of the global debug level if it (the per
3135 * device debug level) is set.
3137 static ssize_t
iwl3945_show_debug_level(struct device
*d
,
3138 struct device_attribute
*attr
, char *buf
)
3140 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3141 return sprintf(buf
, "0x%08X\n", iwl_legacy_get_debug_level(priv
));
3143 static ssize_t
iwl3945_store_debug_level(struct device
*d
,
3144 struct device_attribute
*attr
,
3145 const char *buf
, size_t count
)
3147 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3151 ret
= strict_strtoul(buf
, 0, &val
);
3153 IWL_INFO(priv
, "%s is not in hex or decimal form.\n", buf
);
3155 priv
->debug_level
= val
;
3156 if (iwl_legacy_alloc_traffic_mem(priv
))
3158 "Not enough memory to generate traffic log\n");
3160 return strnlen(buf
, count
);
3163 static DEVICE_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
3164 iwl3945_show_debug_level
, iwl3945_store_debug_level
);
3166 #endif /* CONFIG_IWLWIFI_LEGACY_DEBUG */
3168 static ssize_t
iwl3945_show_temperature(struct device
*d
,
3169 struct device_attribute
*attr
, char *buf
)
3171 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3173 if (!iwl_legacy_is_alive(priv
))
3176 return sprintf(buf
, "%d\n", iwl3945_hw_get_temperature(priv
));
3179 static DEVICE_ATTR(temperature
, S_IRUGO
, iwl3945_show_temperature
, NULL
);
3181 static ssize_t
iwl3945_show_tx_power(struct device
*d
,
3182 struct device_attribute
*attr
, char *buf
)
3184 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3185 return sprintf(buf
, "%d\n", priv
->tx_power_user_lmt
);
3188 static ssize_t
iwl3945_store_tx_power(struct device
*d
,
3189 struct device_attribute
*attr
,
3190 const char *buf
, size_t count
)
3192 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3193 char *p
= (char *)buf
;
3196 val
= simple_strtoul(p
, &p
, 10);
3198 IWL_INFO(priv
, ": %s is not in decimal form.\n", buf
);
3200 iwl3945_hw_reg_set_txpower(priv
, val
);
3205 static DEVICE_ATTR(tx_power
, S_IWUSR
| S_IRUGO
, iwl3945_show_tx_power
, iwl3945_store_tx_power
);
3207 static ssize_t
iwl3945_show_flags(struct device
*d
,
3208 struct device_attribute
*attr
, char *buf
)
3210 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3211 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
3213 return sprintf(buf
, "0x%04X\n", ctx
->active
.flags
);
3216 static ssize_t
iwl3945_store_flags(struct device
*d
,
3217 struct device_attribute
*attr
,
3218 const char *buf
, size_t count
)
3220 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3221 u32 flags
= simple_strtoul(buf
, NULL
, 0);
3222 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
3224 mutex_lock(&priv
->mutex
);
3225 if (le32_to_cpu(ctx
->staging
.flags
) != flags
) {
3226 /* Cancel any currently running scans... */
3227 if (iwl_legacy_scan_cancel_timeout(priv
, 100))
3228 IWL_WARN(priv
, "Could not cancel scan.\n");
3230 IWL_DEBUG_INFO(priv
, "Committing rxon.flags = 0x%04X\n",
3232 ctx
->staging
.flags
= cpu_to_le32(flags
);
3233 iwl3945_commit_rxon(priv
, ctx
);
3236 mutex_unlock(&priv
->mutex
);
3241 static DEVICE_ATTR(flags
, S_IWUSR
| S_IRUGO
, iwl3945_show_flags
, iwl3945_store_flags
);
3243 static ssize_t
iwl3945_show_filter_flags(struct device
*d
,
3244 struct device_attribute
*attr
, char *buf
)
3246 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3247 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
3249 return sprintf(buf
, "0x%04X\n",
3250 le32_to_cpu(ctx
->active
.filter_flags
));
3253 static ssize_t
iwl3945_store_filter_flags(struct device
*d
,
3254 struct device_attribute
*attr
,
3255 const char *buf
, size_t count
)
3257 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3258 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
3259 u32 filter_flags
= simple_strtoul(buf
, NULL
, 0);
3261 mutex_lock(&priv
->mutex
);
3262 if (le32_to_cpu(ctx
->staging
.filter_flags
) != filter_flags
) {
3263 /* Cancel any currently running scans... */
3264 if (iwl_legacy_scan_cancel_timeout(priv
, 100))
3265 IWL_WARN(priv
, "Could not cancel scan.\n");
3267 IWL_DEBUG_INFO(priv
, "Committing rxon.filter_flags = "
3268 "0x%04X\n", filter_flags
);
3269 ctx
->staging
.filter_flags
=
3270 cpu_to_le32(filter_flags
);
3271 iwl3945_commit_rxon(priv
, ctx
);
3274 mutex_unlock(&priv
->mutex
);
3279 static DEVICE_ATTR(filter_flags
, S_IWUSR
| S_IRUGO
, iwl3945_show_filter_flags
,
3280 iwl3945_store_filter_flags
);
3282 static ssize_t
iwl3945_show_measurement(struct device
*d
,
3283 struct device_attribute
*attr
, char *buf
)
3285 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3286 struct iwl_spectrum_notification measure_report
;
3287 u32 size
= sizeof(measure_report
), len
= 0, ofs
= 0;
3288 u8
*data
= (u8
*)&measure_report
;
3289 unsigned long flags
;
3291 spin_lock_irqsave(&priv
->lock
, flags
);
3292 if (!(priv
->measurement_status
& MEASUREMENT_READY
)) {
3293 spin_unlock_irqrestore(&priv
->lock
, flags
);
3296 memcpy(&measure_report
, &priv
->measure_report
, size
);
3297 priv
->measurement_status
= 0;
3298 spin_unlock_irqrestore(&priv
->lock
, flags
);
3300 while (size
&& (PAGE_SIZE
- len
)) {
3301 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
3302 PAGE_SIZE
- len
, 1);
3304 if (PAGE_SIZE
- len
)
3308 size
-= min(size
, 16U);
3314 static ssize_t
iwl3945_store_measurement(struct device
*d
,
3315 struct device_attribute
*attr
,
3316 const char *buf
, size_t count
)
3318 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3319 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
3320 struct ieee80211_measurement_params params
= {
3321 .channel
= le16_to_cpu(ctx
->active
.channel
),
3322 .start_time
= cpu_to_le64(priv
->_3945
.last_tsf
),
3323 .duration
= cpu_to_le16(1),
3325 u8 type
= IWL_MEASURE_BASIC
;
3331 strncpy(buffer
, buf
, min(sizeof(buffer
), count
));
3332 channel
= simple_strtoul(p
, NULL
, 0);
3334 params
.channel
= channel
;
3337 while (*p
&& *p
!= ' ')
3340 type
= simple_strtoul(p
+ 1, NULL
, 0);
3343 IWL_DEBUG_INFO(priv
, "Invoking measurement of type %d on "
3344 "channel %d (for '%s')\n", type
, params
.channel
, buf
);
3345 iwl3945_get_measurement(priv
, ¶ms
, type
);
3350 static DEVICE_ATTR(measurement
, S_IRUSR
| S_IWUSR
,
3351 iwl3945_show_measurement
, iwl3945_store_measurement
);
3353 static ssize_t
iwl3945_store_retry_rate(struct device
*d
,
3354 struct device_attribute
*attr
,
3355 const char *buf
, size_t count
)
3357 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3359 priv
->retry_rate
= simple_strtoul(buf
, NULL
, 0);
3360 if (priv
->retry_rate
<= 0)
3361 priv
->retry_rate
= 1;
3366 static ssize_t
iwl3945_show_retry_rate(struct device
*d
,
3367 struct device_attribute
*attr
, char *buf
)
3369 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3370 return sprintf(buf
, "%d", priv
->retry_rate
);
3373 static DEVICE_ATTR(retry_rate
, S_IWUSR
| S_IRUSR
, iwl3945_show_retry_rate
,
3374 iwl3945_store_retry_rate
);
3377 static ssize_t
iwl3945_show_channels(struct device
*d
,
3378 struct device_attribute
*attr
, char *buf
)
3380 /* all this shit doesn't belong into sysfs anyway */
3384 static DEVICE_ATTR(channels
, S_IRUSR
, iwl3945_show_channels
, NULL
);
3386 static ssize_t
iwl3945_show_antenna(struct device
*d
,
3387 struct device_attribute
*attr
, char *buf
)
3389 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3391 if (!iwl_legacy_is_alive(priv
))
3394 return sprintf(buf
, "%d\n", iwl3945_mod_params
.antenna
);
3397 static ssize_t
iwl3945_store_antenna(struct device
*d
,
3398 struct device_attribute
*attr
,
3399 const char *buf
, size_t count
)
3401 struct iwl_priv
*priv __maybe_unused
= dev_get_drvdata(d
);
3407 if (sscanf(buf
, "%1i", &ant
) != 1) {
3408 IWL_DEBUG_INFO(priv
, "not in hex or decimal form.\n");
3412 if ((ant
>= 0) && (ant
<= 2)) {
3413 IWL_DEBUG_INFO(priv
, "Setting antenna select to %d.\n", ant
);
3414 iwl3945_mod_params
.antenna
= (enum iwl3945_antenna
)ant
;
3416 IWL_DEBUG_INFO(priv
, "Bad antenna select value %d.\n", ant
);
3422 static DEVICE_ATTR(antenna
, S_IWUSR
| S_IRUGO
, iwl3945_show_antenna
, iwl3945_store_antenna
);
3424 static ssize_t
iwl3945_show_status(struct device
*d
,
3425 struct device_attribute
*attr
, char *buf
)
3427 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3428 if (!iwl_legacy_is_alive(priv
))
3430 return sprintf(buf
, "0x%08x\n", (int)priv
->status
);
3433 static DEVICE_ATTR(status
, S_IRUGO
, iwl3945_show_status
, NULL
);
3435 static ssize_t
iwl3945_dump_error_log(struct device
*d
,
3436 struct device_attribute
*attr
,
3437 const char *buf
, size_t count
)
3439 struct iwl_priv
*priv
= dev_get_drvdata(d
);
3440 char *p
= (char *)buf
;
3443 iwl3945_dump_nic_error_log(priv
);
3445 return strnlen(buf
, count
);
3448 static DEVICE_ATTR(dump_errors
, S_IWUSR
, NULL
, iwl3945_dump_error_log
);
3450 /*****************************************************************************
3452 * driver setup and tear down
3454 *****************************************************************************/
3456 static void iwl3945_setup_deferred_work(struct iwl_priv
*priv
)
3458 priv
->workqueue
= create_singlethread_workqueue(DRV_NAME
);
3460 init_waitqueue_head(&priv
->wait_command_queue
);
3462 INIT_WORK(&priv
->restart
, iwl3945_bg_restart
);
3463 INIT_WORK(&priv
->rx_replenish
, iwl3945_bg_rx_replenish
);
3464 INIT_DELAYED_WORK(&priv
->init_alive_start
, iwl3945_bg_init_alive_start
);
3465 INIT_DELAYED_WORK(&priv
->alive_start
, iwl3945_bg_alive_start
);
3466 INIT_DELAYED_WORK(&priv
->_3945
.rfkill_poll
, iwl3945_rfkill_poll
);
3468 iwl_legacy_setup_scan_deferred_work(priv
);
3470 iwl3945_hw_setup_deferred_work(priv
);
3472 init_timer(&priv
->watchdog
);
3473 priv
->watchdog
.data
= (unsigned long)priv
;
3474 priv
->watchdog
.function
= iwl_legacy_bg_watchdog
;
3476 tasklet_init(&priv
->irq_tasklet
, (void (*)(unsigned long))
3477 iwl3945_irq_tasklet
, (unsigned long)priv
);
3480 static void iwl3945_cancel_deferred_work(struct iwl_priv
*priv
)
3482 iwl3945_hw_cancel_deferred_work(priv
);
3484 cancel_delayed_work_sync(&priv
->init_alive_start
);
3485 cancel_delayed_work(&priv
->alive_start
);
3487 iwl_legacy_cancel_scan_deferred_work(priv
);
3490 static struct attribute
*iwl3945_sysfs_entries
[] = {
3491 &dev_attr_antenna
.attr
,
3492 &dev_attr_channels
.attr
,
3493 &dev_attr_dump_errors
.attr
,
3494 &dev_attr_flags
.attr
,
3495 &dev_attr_filter_flags
.attr
,
3496 &dev_attr_measurement
.attr
,
3497 &dev_attr_retry_rate
.attr
,
3498 &dev_attr_status
.attr
,
3499 &dev_attr_temperature
.attr
,
3500 &dev_attr_tx_power
.attr
,
3501 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
3502 &dev_attr_debug_level
.attr
,
3507 static struct attribute_group iwl3945_attribute_group
= {
3508 .name
= NULL
, /* put in device directory */
3509 .attrs
= iwl3945_sysfs_entries
,
3512 struct ieee80211_ops iwl3945_hw_ops
= {
3513 .tx
= iwl3945_mac_tx
,
3514 .start
= iwl3945_mac_start
,
3515 .stop
= iwl3945_mac_stop
,
3516 .add_interface
= iwl_legacy_mac_add_interface
,
3517 .remove_interface
= iwl_legacy_mac_remove_interface
,
3518 .change_interface
= iwl_legacy_mac_change_interface
,
3519 .config
= iwl_legacy_mac_config
,
3520 .configure_filter
= iwl3945_configure_filter
,
3521 .set_key
= iwl3945_mac_set_key
,
3522 .conf_tx
= iwl_legacy_mac_conf_tx
,
3523 .reset_tsf
= iwl_legacy_mac_reset_tsf
,
3524 .bss_info_changed
= iwl_legacy_mac_bss_info_changed
,
3525 .hw_scan
= iwl_legacy_mac_hw_scan
,
3526 .sta_add
= iwl3945_mac_sta_add
,
3527 .sta_remove
= iwl_legacy_mac_sta_remove
,
3528 .tx_last_beacon
= iwl_legacy_mac_tx_last_beacon
,
3531 static int iwl3945_init_drv(struct iwl_priv
*priv
)
3534 struct iwl3945_eeprom
*eeprom
= (struct iwl3945_eeprom
*)priv
->eeprom
;
3536 priv
->retry_rate
= 1;
3537 priv
->beacon_skb
= NULL
;
3539 spin_lock_init(&priv
->sta_lock
);
3540 spin_lock_init(&priv
->hcmd_lock
);
3542 INIT_LIST_HEAD(&priv
->free_frames
);
3544 mutex_init(&priv
->mutex
);
3546 priv
->ieee_channels
= NULL
;
3547 priv
->ieee_rates
= NULL
;
3548 priv
->band
= IEEE80211_BAND_2GHZ
;
3550 priv
->iw_mode
= NL80211_IFTYPE_STATION
;
3551 priv
->missed_beacon_threshold
= IWL_MISSED_BEACON_THRESHOLD_DEF
;
3553 /* initialize force reset */
3554 priv
->force_reset
.reset_duration
= IWL_DELAY_NEXT_FORCE_FW_RELOAD
;
3556 if (eeprom
->version
< EEPROM_3945_EEPROM_VERSION
) {
3557 IWL_WARN(priv
, "Unsupported EEPROM version: 0x%04X\n",
3562 ret
= iwl_legacy_init_channel_map(priv
);
3564 IWL_ERR(priv
, "initializing regulatory failed: %d\n", ret
);
3568 /* Set up txpower settings in driver for all channels */
3569 if (iwl3945_txpower_set_from_eeprom(priv
)) {
3571 goto err_free_channel_map
;
3574 ret
= iwl_legacy_init_geos(priv
);
3576 IWL_ERR(priv
, "initializing geos failed: %d\n", ret
);
3577 goto err_free_channel_map
;
3579 iwl3945_init_hw_rates(priv
, priv
->ieee_rates
);
3583 err_free_channel_map
:
3584 iwl_legacy_free_channel_map(priv
);
3589 #define IWL3945_MAX_PROBE_REQUEST 200
3591 static int iwl3945_setup_mac(struct iwl_priv
*priv
)
3594 struct ieee80211_hw
*hw
= priv
->hw
;
3596 hw
->rate_control_algorithm
= "iwl-3945-rs";
3597 hw
->sta_data_size
= sizeof(struct iwl3945_sta_priv
);
3598 hw
->vif_data_size
= sizeof(struct iwl_vif_priv
);
3600 /* Tell mac80211 our characteristics */
3601 hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
3602 IEEE80211_HW_SPECTRUM_MGMT
;
3604 hw
->wiphy
->interface_modes
=
3605 priv
->contexts
[IWL_RXON_CTX_BSS
].interface_modes
;
3607 hw
->wiphy
->flags
|= WIPHY_FLAG_CUSTOM_REGULATORY
|
3608 WIPHY_FLAG_DISABLE_BEACON_HINTS
|
3609 WIPHY_FLAG_IBSS_RSN
;
3611 hw
->wiphy
->max_scan_ssids
= PROBE_OPTION_MAX_3945
;
3612 /* we create the 802.11 header and a zero-length SSID element */
3613 hw
->wiphy
->max_scan_ie_len
= IWL3945_MAX_PROBE_REQUEST
- 24 - 2;
3615 /* Default value; 4 EDCA QOS priorities */
3618 if (priv
->bands
[IEEE80211_BAND_2GHZ
].n_channels
)
3619 priv
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
3620 &priv
->bands
[IEEE80211_BAND_2GHZ
];
3622 if (priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
)
3623 priv
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
3624 &priv
->bands
[IEEE80211_BAND_5GHZ
];
3626 iwl_legacy_leds_init(priv
);
3628 ret
= ieee80211_register_hw(priv
->hw
);
3630 IWL_ERR(priv
, "Failed to register hw (error %d)\n", ret
);
3633 priv
->mac80211_registered
= 1;
3638 static int iwl3945_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
3641 struct iwl_priv
*priv
;
3642 struct ieee80211_hw
*hw
;
3643 struct iwl_cfg
*cfg
= (struct iwl_cfg
*)(ent
->driver_data
);
3644 struct iwl3945_eeprom
*eeprom
;
3645 unsigned long flags
;
3647 /***********************
3648 * 1. Allocating HW data
3649 * ********************/
3651 /* mac80211 allocates memory for this device instance, including
3652 * space for this driver's private structure */
3653 hw
= iwl_legacy_alloc_all(cfg
);
3655 pr_err("Can not allocate network device\n");
3660 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
3662 priv
->cmd_queue
= IWL39_CMD_QUEUE_NUM
;
3664 /* 3945 has only one valid context */
3665 priv
->valid_contexts
= BIT(IWL_RXON_CTX_BSS
);
3667 for (i
= 0; i
< NUM_IWL_RXON_CTX
; i
++)
3668 priv
->contexts
[i
].ctxid
= i
;
3670 priv
->contexts
[IWL_RXON_CTX_BSS
].rxon_cmd
= REPLY_RXON
;
3671 priv
->contexts
[IWL_RXON_CTX_BSS
].rxon_timing_cmd
= REPLY_RXON_TIMING
;
3672 priv
->contexts
[IWL_RXON_CTX_BSS
].rxon_assoc_cmd
= REPLY_RXON_ASSOC
;
3673 priv
->contexts
[IWL_RXON_CTX_BSS
].qos_cmd
= REPLY_QOS_PARAM
;
3674 priv
->contexts
[IWL_RXON_CTX_BSS
].ap_sta_id
= IWL_AP_ID
;
3675 priv
->contexts
[IWL_RXON_CTX_BSS
].wep_key_cmd
= REPLY_WEPKEY
;
3676 priv
->contexts
[IWL_RXON_CTX_BSS
].interface_modes
=
3677 BIT(NL80211_IFTYPE_STATION
) |
3678 BIT(NL80211_IFTYPE_ADHOC
);
3679 priv
->contexts
[IWL_RXON_CTX_BSS
].ibss_devtype
= RXON_DEV_TYPE_IBSS
;
3680 priv
->contexts
[IWL_RXON_CTX_BSS
].station_devtype
= RXON_DEV_TYPE_ESS
;
3681 priv
->contexts
[IWL_RXON_CTX_BSS
].unused_devtype
= RXON_DEV_TYPE_ESS
;
3684 * Disabling hardware scan means that mac80211 will perform scans
3685 * "the hard way", rather than using device's scan.
3687 if (iwl3945_mod_params
.disable_hw_scan
) {
3688 IWL_DEBUG_INFO(priv
, "Disabling hw_scan\n");
3689 iwl3945_hw_ops
.hw_scan
= NULL
;
3692 IWL_DEBUG_INFO(priv
, "*** LOAD DRIVER ***\n");
3694 priv
->pci_dev
= pdev
;
3695 priv
->inta_mask
= CSR_INI_SET_MASK
;
3697 if (iwl_legacy_alloc_traffic_mem(priv
))
3698 IWL_ERR(priv
, "Not enough memory to generate traffic log\n");
3700 /***************************
3701 * 2. Initializing PCI bus
3702 * *************************/
3703 pci_disable_link_state(pdev
, PCIE_LINK_STATE_L0S
| PCIE_LINK_STATE_L1
|
3704 PCIE_LINK_STATE_CLKPM
);
3706 if (pci_enable_device(pdev
)) {
3708 goto out_ieee80211_free_hw
;
3711 pci_set_master(pdev
);
3713 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
3715 err
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
3717 IWL_WARN(priv
, "No suitable DMA available.\n");
3718 goto out_pci_disable_device
;
3721 pci_set_drvdata(pdev
, priv
);
3722 err
= pci_request_regions(pdev
, DRV_NAME
);
3724 goto out_pci_disable_device
;
3726 /***********************
3727 * 3. Read REV Register
3728 * ********************/
3729 priv
->hw_base
= pci_iomap(pdev
, 0, 0);
3730 if (!priv
->hw_base
) {
3732 goto out_pci_release_regions
;
3735 IWL_DEBUG_INFO(priv
, "pci_resource_len = 0x%08llx\n",
3736 (unsigned long long) pci_resource_len(pdev
, 0));
3737 IWL_DEBUG_INFO(priv
, "pci_resource_base = %p\n", priv
->hw_base
);
3739 /* We disable the RETRY_TIMEOUT register (0x41) to keep
3740 * PCI Tx retries from interfering with C3 CPU state */
3741 pci_write_config_byte(pdev
, 0x41, 0x00);
3743 /* these spin locks will be used in apm_ops.init and EEPROM access
3744 * we should init now
3746 spin_lock_init(&priv
->reg_lock
);
3747 spin_lock_init(&priv
->lock
);
3750 * stop and reset the on-board processor just in case it is in a
3751 * strange state ... like being left stranded by a primary kernel
3752 * and this is now the kdump kernel trying to start up
3754 iwl_write32(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_NEVO_RESET
);
3756 /***********************
3758 * ********************/
3760 /* Read the EEPROM */
3761 err
= iwl_legacy_eeprom_init(priv
);
3763 IWL_ERR(priv
, "Unable to init EEPROM\n");
3766 /* MAC Address location in EEPROM same for 3945/4965 */
3767 eeprom
= (struct iwl3945_eeprom
*)priv
->eeprom
;
3768 IWL_DEBUG_INFO(priv
, "MAC address: %pM\n", eeprom
->mac_address
);
3769 SET_IEEE80211_PERM_ADDR(priv
->hw
, eeprom
->mac_address
);
3771 /***********************
3772 * 5. Setup HW Constants
3773 * ********************/
3774 /* Device-specific setup */
3775 if (iwl3945_hw_set_hw_params(priv
)) {
3776 IWL_ERR(priv
, "failed to set hw settings\n");
3777 goto out_eeprom_free
;
3780 /***********************
3782 * ********************/
3784 err
= iwl3945_init_drv(priv
);
3786 IWL_ERR(priv
, "initializing driver failed\n");
3787 goto out_unset_hw_params
;
3790 IWL_INFO(priv
, "Detected Intel Wireless WiFi Link %s\n",
3793 /***********************
3795 * ********************/
3797 spin_lock_irqsave(&priv
->lock
, flags
);
3798 iwl_legacy_disable_interrupts(priv
);
3799 spin_unlock_irqrestore(&priv
->lock
, flags
);
3801 pci_enable_msi(priv
->pci_dev
);
3803 err
= request_irq(priv
->pci_dev
->irq
, iwl_legacy_isr
,
3804 IRQF_SHARED
, DRV_NAME
, priv
);
3806 IWL_ERR(priv
, "Error allocating IRQ %d\n", priv
->pci_dev
->irq
);
3807 goto out_disable_msi
;
3810 err
= sysfs_create_group(&pdev
->dev
.kobj
, &iwl3945_attribute_group
);
3812 IWL_ERR(priv
, "failed to create sysfs device attributes\n");
3813 goto out_release_irq
;
3816 iwl_legacy_set_rxon_channel(priv
,
3817 &priv
->bands
[IEEE80211_BAND_2GHZ
].channels
[5],
3818 &priv
->contexts
[IWL_RXON_CTX_BSS
]);
3819 iwl3945_setup_deferred_work(priv
);
3820 iwl3945_setup_rx_handlers(priv
);
3821 iwl_legacy_power_initialize(priv
);
3823 /*********************************
3824 * 8. Setup and Register mac80211
3825 * *******************************/
3827 iwl_legacy_enable_interrupts(priv
);
3829 err
= iwl3945_setup_mac(priv
);
3831 goto out_remove_sysfs
;
3833 err
= iwl_legacy_dbgfs_register(priv
, DRV_NAME
);
3835 IWL_ERR(priv
, "failed to create debugfs files. Ignoring error: %d\n", err
);
3837 /* Start monitoring the killswitch */
3838 queue_delayed_work(priv
->workqueue
, &priv
->_3945
.rfkill_poll
,
3844 destroy_workqueue(priv
->workqueue
);
3845 priv
->workqueue
= NULL
;
3846 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl3945_attribute_group
);
3848 free_irq(priv
->pci_dev
->irq
, priv
);
3850 pci_disable_msi(priv
->pci_dev
);
3851 iwl_legacy_free_geos(priv
);
3852 iwl_legacy_free_channel_map(priv
);
3853 out_unset_hw_params
:
3854 iwl3945_unset_hw_params(priv
);
3856 iwl_legacy_eeprom_free(priv
);
3858 pci_iounmap(pdev
, priv
->hw_base
);
3859 out_pci_release_regions
:
3860 pci_release_regions(pdev
);
3861 out_pci_disable_device
:
3862 pci_set_drvdata(pdev
, NULL
);
3863 pci_disable_device(pdev
);
3864 out_ieee80211_free_hw
:
3865 iwl_legacy_free_traffic_mem(priv
);
3866 ieee80211_free_hw(priv
->hw
);
3871 static void __devexit
iwl3945_pci_remove(struct pci_dev
*pdev
)
3873 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
3874 unsigned long flags
;
3879 IWL_DEBUG_INFO(priv
, "*** UNLOAD DRIVER ***\n");
3881 iwl_legacy_dbgfs_unregister(priv
);
3883 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
3885 iwl_legacy_leds_exit(priv
);
3887 if (priv
->mac80211_registered
) {
3888 ieee80211_unregister_hw(priv
->hw
);
3889 priv
->mac80211_registered
= 0;
3895 * Make sure device is reset to low power before unloading driver.
3896 * This may be redundant with iwl_down(), but there are paths to
3897 * run iwl_down() without calling apm_ops.stop(), and there are
3898 * paths to avoid running iwl_down() at all before leaving driver.
3899 * This (inexpensive) call *makes sure* device is reset.
3901 iwl_legacy_apm_stop(priv
);
3903 /* make sure we flush any pending irq or
3904 * tasklet for the driver
3906 spin_lock_irqsave(&priv
->lock
, flags
);
3907 iwl_legacy_disable_interrupts(priv
);
3908 spin_unlock_irqrestore(&priv
->lock
, flags
);
3910 iwl3945_synchronize_irq(priv
);
3912 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl3945_attribute_group
);
3914 cancel_delayed_work_sync(&priv
->_3945
.rfkill_poll
);
3916 iwl3945_dealloc_ucode_pci(priv
);
3919 iwl3945_rx_queue_free(priv
, &priv
->rxq
);
3920 iwl3945_hw_txq_ctx_free(priv
);
3922 iwl3945_unset_hw_params(priv
);
3924 /*netif_stop_queue(dev); */
3925 flush_workqueue(priv
->workqueue
);
3927 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
3928 * priv->workqueue... so we can't take down the workqueue
3930 destroy_workqueue(priv
->workqueue
);
3931 priv
->workqueue
= NULL
;
3932 iwl_legacy_free_traffic_mem(priv
);
3934 free_irq(pdev
->irq
, priv
);
3935 pci_disable_msi(pdev
);
3937 pci_iounmap(pdev
, priv
->hw_base
);
3938 pci_release_regions(pdev
);
3939 pci_disable_device(pdev
);
3940 pci_set_drvdata(pdev
, NULL
);
3942 iwl_legacy_free_channel_map(priv
);
3943 iwl_legacy_free_geos(priv
);
3944 kfree(priv
->scan_cmd
);
3945 if (priv
->beacon_skb
)
3946 dev_kfree_skb(priv
->beacon_skb
);
3948 ieee80211_free_hw(priv
->hw
);
3952 /*****************************************************************************
3954 * driver and module entry point
3956 *****************************************************************************/
3958 static struct pci_driver iwl3945_driver
= {
3960 .id_table
= iwl3945_hw_card_ids
,
3961 .probe
= iwl3945_pci_probe
,
3962 .remove
= __devexit_p(iwl3945_pci_remove
),
3963 .driver
.pm
= IWL_LEGACY_PM_OPS
,
3966 static int __init
iwl3945_init(void)
3970 pr_info(DRV_DESCRIPTION
", " DRV_VERSION
"\n");
3971 pr_info(DRV_COPYRIGHT
"\n");
3973 ret
= iwl3945_rate_control_register();
3975 pr_err("Unable to register rate control algorithm: %d\n", ret
);
3979 ret
= pci_register_driver(&iwl3945_driver
);
3981 pr_err("Unable to initialize PCI module\n");
3982 goto error_register
;
3988 iwl3945_rate_control_unregister();
3992 static void __exit
iwl3945_exit(void)
3994 pci_unregister_driver(&iwl3945_driver
);
3995 iwl3945_rate_control_unregister();
3998 MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX
));
4000 module_param_named(antenna
, iwl3945_mod_params
.antenna
, int, S_IRUGO
);
4001 MODULE_PARM_DESC(antenna
, "select antenna (1=Main, 2=Aux, default 0 [both])");
4002 module_param_named(swcrypto
, iwl3945_mod_params
.sw_crypto
, int, S_IRUGO
);
4003 MODULE_PARM_DESC(swcrypto
,
4004 "using software crypto (default 1 [software])");
4005 module_param_named(disable_hw_scan
, iwl3945_mod_params
.disable_hw_scan
,
4007 MODULE_PARM_DESC(disable_hw_scan
, "disable hardware scanning (default 1)");
4008 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
4009 module_param_named(debug
, iwlegacy_debug_level
, uint
, S_IRUGO
| S_IWUSR
);
4010 MODULE_PARM_DESC(debug
, "debug output mask");
4012 module_param_named(fw_restart
, iwl3945_mod_params
.restart_fw
, int, S_IRUGO
);
4013 MODULE_PARM_DESC(fw_restart
, "restart firmware in case of error");
4015 module_exit(iwl3945_exit
);
4016 module_init(iwl3945_init
);