1 /******************************************************************************
3 * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
24 * Contact Information:
25 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *****************************************************************************/
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/version.h>
33 #include <linux/init.h>
34 #include <linux/pci.h>
35 #include <linux/dma-mapping.h>
36 #include <linux/delay.h>
37 #include <linux/skbuff.h>
38 #include <linux/netdevice.h>
39 #include <linux/wireless.h>
40 #include <linux/firmware.h>
41 #include <linux/etherdevice.h>
42 #include <linux/if_arp.h>
44 #include <net/mac80211.h>
46 #include <asm/div64.h>
48 #include "iwl-eeprom.h"
52 #include "iwl-helpers.h"
55 static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv
*priv
,
56 struct iwl4965_tx_queue
*txq
);
58 /******************************************************************************
62 ******************************************************************************/
65 * module name, copyright, version, etc.
66 * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
69 #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux"
71 #ifdef CONFIG_IWLWIFI_DEBUG
77 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
83 #define DRV_VERSION IWLWIFI_VERSION VD VS
86 MODULE_DESCRIPTION(DRV_DESCRIPTION
);
87 MODULE_VERSION(DRV_VERSION
);
88 MODULE_AUTHOR(DRV_COPYRIGHT
);
89 MODULE_LICENSE("GPL");
91 __le16
*ieee80211_get_qos_ctrl(struct ieee80211_hdr
*hdr
)
93 u16 fc
= le16_to_cpu(hdr
->frame_control
);
94 int hdr_len
= ieee80211_get_hdrlen(fc
);
96 if ((fc
& 0x00cc) == (IEEE80211_STYPE_QOS_DATA
| IEEE80211_FTYPE_DATA
))
97 return (__le16
*) ((u8
*) hdr
+ hdr_len
- QOS_CONTROL_LEN
);
101 static const struct ieee80211_supported_band
*iwl4965_get_hw_mode(
102 struct iwl_priv
*priv
, enum ieee80211_band band
)
104 return priv
->hw
->wiphy
->bands
[band
];
107 static int iwl4965_is_empty_essid(const char *essid
, int essid_len
)
109 /* Single white space is for Linksys APs */
110 if (essid_len
== 1 && essid
[0] == ' ')
113 /* Otherwise, if the entire essid is 0, we assume it is hidden */
116 if (essid
[essid_len
] != '\0')
123 static const char *iwl4965_escape_essid(const char *essid
, u8 essid_len
)
125 static char escaped
[IW_ESSID_MAX_SIZE
* 2 + 1];
126 const char *s
= essid
;
129 if (iwl4965_is_empty_essid(essid
, essid_len
)) {
130 memcpy(escaped
, "<hidden>", sizeof("<hidden>"));
134 essid_len
= min(essid_len
, (u8
) IW_ESSID_MAX_SIZE
);
135 while (essid_len
--) {
147 /*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
150 * Theory of operation
152 * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
153 * of buffer descriptors, each of which points to one or more data buffers for
154 * the device to read from or fill. Driver and device exchange status of each
155 * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
156 * entries in each circular buffer, to protect against confusing empty and full
159 * The device reads or writes the data in the queues via the device's several
160 * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
162 * For Tx queue, there are low mark and high mark limits. If, after queuing
163 * the packet for Tx, free space become < low mark, Tx queue stopped. When
164 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
167 * The 4965 operates with up to 17 queues: One receive queue, one transmit
168 * queue (#4) for sending commands to the device firmware, and 15 other
169 * Tx queues that may be mapped to prioritized Tx DMA/FIFO channels.
171 * See more detailed info in iwl-4965-hw.h.
172 ***************************************************/
174 int iwl4965_queue_space(const struct iwl4965_queue
*q
)
176 int s
= q
->read_ptr
- q
->write_ptr
;
178 if (q
->read_ptr
> q
->write_ptr
)
183 /* keep some reserve to not confuse empty and full situations */
191 static inline int x2_queue_used(const struct iwl4965_queue
*q
, int i
)
193 return q
->write_ptr
> q
->read_ptr
?
194 (i
>= q
->read_ptr
&& i
< q
->write_ptr
) :
195 !(i
< q
->read_ptr
&& i
>= q
->write_ptr
);
198 static inline u8
get_cmd_index(struct iwl4965_queue
*q
, u32 index
, int is_huge
)
200 /* This is for scan command, the big buffer at end of command array */
202 return q
->n_window
; /* must be power of 2 */
204 /* Otherwise, use normal size buffers */
205 return index
& (q
->n_window
- 1);
209 * iwl4965_queue_init - Initialize queue's high/low-water and read/write indexes
211 static int iwl4965_queue_init(struct iwl_priv
*priv
, struct iwl4965_queue
*q
,
212 int count
, int slots_num
, u32 id
)
215 q
->n_window
= slots_num
;
218 /* count must be power-of-two size, otherwise iwl_queue_inc_wrap
219 * and iwl_queue_dec_wrap are broken. */
220 BUG_ON(!is_power_of_2(count
));
222 /* slots_num must be power-of-two size, otherwise
223 * get_cmd_index is broken. */
224 BUG_ON(!is_power_of_2(slots_num
));
226 q
->low_mark
= q
->n_window
/ 4;
230 q
->high_mark
= q
->n_window
/ 8;
231 if (q
->high_mark
< 2)
234 q
->write_ptr
= q
->read_ptr
= 0;
240 * iwl4965_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
242 static int iwl4965_tx_queue_alloc(struct iwl_priv
*priv
,
243 struct iwl4965_tx_queue
*txq
, u32 id
)
245 struct pci_dev
*dev
= priv
->pci_dev
;
247 /* Driver private data, only for Tx (not command) queues,
248 * not shared with device. */
249 if (id
!= IWL_CMD_QUEUE_NUM
) {
250 txq
->txb
= kmalloc(sizeof(txq
->txb
[0]) *
251 TFD_QUEUE_SIZE_MAX
, GFP_KERNEL
);
253 IWL_ERROR("kmalloc for auxiliary BD "
254 "structures failed\n");
260 /* Circular buffer of transmit frame descriptors (TFDs),
261 * shared with device */
262 txq
->bd
= pci_alloc_consistent(dev
,
263 sizeof(txq
->bd
[0]) * TFD_QUEUE_SIZE_MAX
,
267 IWL_ERROR("pci_alloc_consistent(%zd) failed\n",
268 sizeof(txq
->bd
[0]) * TFD_QUEUE_SIZE_MAX
);
285 * iwl4965_tx_queue_init - Allocate and initialize one tx/cmd queue
287 int iwl4965_tx_queue_init(struct iwl_priv
*priv
,
288 struct iwl4965_tx_queue
*txq
, int slots_num
, u32 txq_id
)
290 struct pci_dev
*dev
= priv
->pci_dev
;
295 * Alloc buffer array for commands (Tx or other types of commands).
296 * For the command queue (#4), allocate command space + one big
297 * command for scan, since scan command is very huge; the system will
298 * not have two scans at the same time, so only one is needed.
299 * For normal Tx queues (all other queues), no super-size command
302 len
= sizeof(struct iwl_cmd
) * slots_num
;
303 if (txq_id
== IWL_CMD_QUEUE_NUM
)
304 len
+= IWL_MAX_SCAN_SIZE
;
305 txq
->cmd
= pci_alloc_consistent(dev
, len
, &txq
->dma_addr_cmd
);
309 /* Alloc driver data array and TFD circular buffer */
310 rc
= iwl4965_tx_queue_alloc(priv
, txq
, txq_id
);
312 pci_free_consistent(dev
, len
, txq
->cmd
, txq
->dma_addr_cmd
);
316 txq
->need_update
= 0;
318 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
319 * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */
320 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX
& (TFD_QUEUE_SIZE_MAX
- 1));
322 /* Initialize queue's high/low-water marks, and head/tail indexes */
323 iwl4965_queue_init(priv
, &txq
->q
, TFD_QUEUE_SIZE_MAX
, slots_num
, txq_id
);
325 /* Tell device where to find queue */
326 iwl4965_hw_tx_queue_init(priv
, txq
);
332 * iwl4965_tx_queue_free - Deallocate DMA queue.
333 * @txq: Transmit queue to deallocate.
335 * Empty queue by removing and destroying all BD's.
337 * 0-fill, but do not free "txq" descriptor structure.
339 void iwl4965_tx_queue_free(struct iwl_priv
*priv
, struct iwl4965_tx_queue
*txq
)
341 struct iwl4965_queue
*q
= &txq
->q
;
342 struct pci_dev
*dev
= priv
->pci_dev
;
348 /* first, empty all BD's */
349 for (; q
->write_ptr
!= q
->read_ptr
;
350 q
->read_ptr
= iwl_queue_inc_wrap(q
->read_ptr
, q
->n_bd
))
351 iwl4965_hw_txq_free_tfd(priv
, txq
);
353 len
= sizeof(struct iwl_cmd
) * q
->n_window
;
354 if (q
->id
== IWL_CMD_QUEUE_NUM
)
355 len
+= IWL_MAX_SCAN_SIZE
;
357 /* De-alloc array of command/tx buffers */
358 pci_free_consistent(dev
, len
, txq
->cmd
, txq
->dma_addr_cmd
);
360 /* De-alloc circular buffer of TFDs */
362 pci_free_consistent(dev
, sizeof(struct iwl4965_tfd_frame
) *
363 txq
->q
.n_bd
, txq
->bd
, txq
->q
.dma_addr
);
365 /* De-alloc array of per-TFD driver data */
371 /* 0-fill queue descriptor structure */
372 memset(txq
, 0, sizeof(*txq
));
375 const u8 iwl4965_broadcast_addr
[ETH_ALEN
] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
377 /*************** STATION TABLE MANAGEMENT ****
378 * mac80211 should be examined to determine if sta_info is duplicating
379 * the functionality provided here
382 /**************************************************************/
384 #if 0 /* temporary disable till we add real remove station */
386 * iwl4965_remove_station - Remove driver's knowledge of station.
388 * NOTE: This does not remove station from device's station table.
390 static u8
iwl4965_remove_station(struct iwl_priv
*priv
, const u8
*addr
, int is_ap
)
392 int index
= IWL_INVALID_STATION
;
396 spin_lock_irqsave(&priv
->sta_lock
, flags
);
400 else if (is_broadcast_ether_addr(addr
))
401 index
= priv
->hw_setting
.bcast_sta_id
;
403 for (i
= IWL_STA_ID
; i
< priv
->hw_setting
.max_stations
; i
++)
404 if (priv
->stations
[i
].used
&&
405 !compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
411 if (unlikely(index
== IWL_INVALID_STATION
))
414 if (priv
->stations
[index
].used
) {
415 priv
->stations
[index
].used
= 0;
416 priv
->num_stations
--;
419 BUG_ON(priv
->num_stations
< 0);
422 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
428 * iwl4965_add_station_flags - Add station to tables in driver and device
430 u8
iwl4965_add_station_flags(struct iwl_priv
*priv
, const u8
*addr
,
431 int is_ap
, u8 flags
, void *ht_data
)
434 int index
= IWL_INVALID_STATION
;
435 struct iwl4965_station_entry
*station
;
436 unsigned long flags_spin
;
437 DECLARE_MAC_BUF(mac
);
439 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
442 else if (is_broadcast_ether_addr(addr
))
443 index
= priv
->hw_setting
.bcast_sta_id
;
445 for (i
= IWL_STA_ID
; i
< priv
->hw_setting
.max_stations
; i
++) {
446 if (!compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
452 if (!priv
->stations
[i
].used
&&
453 index
== IWL_INVALID_STATION
)
458 /* These two conditions have the same outcome, but keep them separate
459 since they have different meanings */
460 if (unlikely(index
== IWL_INVALID_STATION
)) {
461 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
465 if (priv
->stations
[index
].used
&&
466 !compare_ether_addr(priv
->stations
[index
].sta
.sta
.addr
, addr
)) {
467 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
472 IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index
, print_mac(mac
, addr
));
473 station
= &priv
->stations
[index
];
475 priv
->num_stations
++;
477 /* Set up the REPLY_ADD_STA command to send to device */
478 memset(&station
->sta
, 0, sizeof(struct iwl4965_addsta_cmd
));
479 memcpy(station
->sta
.sta
.addr
, addr
, ETH_ALEN
);
480 station
->sta
.mode
= 0;
481 station
->sta
.sta
.sta_id
= index
;
482 station
->sta
.station_flags
= 0;
484 #ifdef CONFIG_IWL4965_HT
485 /* BCAST station and IBSS stations do not work in HT mode */
486 if (index
!= priv
->hw_setting
.bcast_sta_id
&&
487 priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
)
488 iwl4965_set_ht_add_station(priv
, index
,
489 (struct ieee80211_ht_info
*) ht_data
);
490 #endif /*CONFIG_IWL4965_HT*/
492 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
494 /* Add station to device's station table */
495 iwl4965_send_add_station(priv
, &station
->sta
, flags
);
502 /*************** HOST COMMAND QUEUE FUNCTIONS *****/
505 * iwl4965_enqueue_hcmd - enqueue a uCode command
506 * @priv: device private data point
507 * @cmd: a point to the ucode command structure
509 * The function returns < 0 values to indicate the operation is
510 * failed. On success, it turns the index (> 0) of command in the
513 int iwl4965_enqueue_hcmd(struct iwl_priv
*priv
, struct iwl_host_cmd
*cmd
)
515 struct iwl4965_tx_queue
*txq
= &priv
->txq
[IWL_CMD_QUEUE_NUM
];
516 struct iwl4965_queue
*q
= &txq
->q
;
517 struct iwl4965_tfd_frame
*tfd
;
519 struct iwl_cmd
*out_cmd
;
521 u16 fix_size
= (u16
)(cmd
->len
+ sizeof(out_cmd
->hdr
));
522 dma_addr_t phys_addr
;
526 /* If any of the command structures end up being larger than
527 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
528 * we will need to increase the size of the TFD entries */
529 BUG_ON((fix_size
> TFD_MAX_PAYLOAD_SIZE
) &&
530 !(cmd
->meta
.flags
& CMD_SIZE_HUGE
));
532 if (iwl_is_rfkill(priv
)) {
533 IWL_DEBUG_INFO("Not sending command - RF KILL");
537 if (iwl4965_queue_space(q
) < ((cmd
->meta
.flags
& CMD_ASYNC
) ? 2 : 1)) {
538 IWL_ERROR("No space for Tx\n");
542 spin_lock_irqsave(&priv
->hcmd_lock
, flags
);
544 tfd
= &txq
->bd
[q
->write_ptr
];
545 memset(tfd
, 0, sizeof(*tfd
));
547 control_flags
= (u32
*) tfd
;
549 idx
= get_cmd_index(q
, q
->write_ptr
, cmd
->meta
.flags
& CMD_SIZE_HUGE
);
550 out_cmd
= &txq
->cmd
[idx
];
552 out_cmd
->hdr
.cmd
= cmd
->id
;
553 memcpy(&out_cmd
->meta
, &cmd
->meta
, sizeof(cmd
->meta
));
554 memcpy(&out_cmd
->cmd
.payload
, cmd
->data
, cmd
->len
);
556 /* At this point, the out_cmd now has all of the incoming cmd
559 out_cmd
->hdr
.flags
= 0;
560 out_cmd
->hdr
.sequence
= cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM
) |
561 INDEX_TO_SEQ(q
->write_ptr
));
562 if (out_cmd
->meta
.flags
& CMD_SIZE_HUGE
)
563 out_cmd
->hdr
.sequence
|= cpu_to_le16(SEQ_HUGE_FRAME
);
565 phys_addr
= txq
->dma_addr_cmd
+ sizeof(txq
->cmd
[0]) * idx
+
566 offsetof(struct iwl_cmd
, hdr
);
567 iwl4965_hw_txq_attach_buf_to_tfd(priv
, tfd
, phys_addr
, fix_size
);
569 IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
570 "%d bytes at %d[%d]:%d\n",
571 get_cmd_string(out_cmd
->hdr
.cmd
),
572 out_cmd
->hdr
.cmd
, le16_to_cpu(out_cmd
->hdr
.sequence
),
573 fix_size
, q
->write_ptr
, idx
, IWL_CMD_QUEUE_NUM
);
575 txq
->need_update
= 1;
577 /* Set up entry in queue's byte count circular buffer */
578 ret
= iwl4965_tx_queue_update_wr_ptr(priv
, txq
, 0);
580 /* Increment and update queue's write index */
581 q
->write_ptr
= iwl_queue_inc_wrap(q
->write_ptr
, q
->n_bd
);
582 iwl4965_tx_queue_update_write_ptr(priv
, txq
);
584 spin_unlock_irqrestore(&priv
->hcmd_lock
, flags
);
585 return ret
? ret
: idx
;
588 static void iwl4965_set_rxon_hwcrypto(struct iwl_priv
*priv
, int hw_decrypt
)
590 struct iwl4965_rxon_cmd
*rxon
= &priv
->staging_rxon
;
593 rxon
->filter_flags
&= ~RXON_FILTER_DIS_DECRYPT_MSK
;
595 rxon
->filter_flags
|= RXON_FILTER_DIS_DECRYPT_MSK
;
599 int iwl4965_send_statistics_request(struct iwl_priv
*priv
)
602 return iwl_send_cmd_pdu(priv
, REPLY_STATISTICS_CMD
,
603 sizeof(flags
), &flags
);
607 * iwl4965_rxon_add_station - add station into station table.
609 * there is only one AP station with id= IWL_AP_ID
610 * NOTE: mutex must be held before calling this fnction
612 static int iwl4965_rxon_add_station(struct iwl_priv
*priv
,
613 const u8
*addr
, int is_ap
)
617 /* Add station to device's station table */
618 #ifdef CONFIG_IWL4965_HT
619 struct ieee80211_conf
*conf
= &priv
->hw
->conf
;
620 struct ieee80211_ht_info
*cur_ht_config
= &conf
->ht_conf
;
623 (conf
->flags
& IEEE80211_CONF_SUPPORT_HT_MODE
) &&
624 (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
625 sta_id
= iwl4965_add_station_flags(priv
, addr
, is_ap
,
628 #endif /* CONFIG_IWL4965_HT */
629 sta_id
= iwl4965_add_station_flags(priv
, addr
, is_ap
,
632 /* Set up default rate scaling table in device's station table */
633 iwl4965_add_station(priv
, addr
, is_ap
);
639 * iwl4965_check_rxon_cmd - validate RXON structure is valid
641 * NOTE: This is really only useful during development and can eventually
642 * be #ifdef'd out once the driver is stable and folks aren't actively
645 static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd
*rxon
)
650 if (rxon
->flags
& RXON_FLG_BAND_24G_MSK
) {
651 error
|= le32_to_cpu(rxon
->flags
&
652 (RXON_FLG_TGJ_NARROW_BAND_MSK
|
653 RXON_FLG_RADAR_DETECT_MSK
));
655 IWL_WARNING("check 24G fields %d | %d\n",
658 error
|= (rxon
->flags
& RXON_FLG_SHORT_SLOT_MSK
) ?
659 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK
);
661 IWL_WARNING("check 52 fields %d | %d\n",
663 error
|= le32_to_cpu(rxon
->flags
& RXON_FLG_CCK_MSK
);
665 IWL_WARNING("check 52 CCK %d | %d\n",
668 error
|= (rxon
->node_addr
[0] | rxon
->bssid_addr
[0]) & 0x1;
670 IWL_WARNING("check mac addr %d | %d\n", counter
++, error
);
672 /* make sure basic rates 6Mbps and 1Mbps are supported */
673 error
|= (((rxon
->ofdm_basic_rates
& IWL_RATE_6M_MASK
) == 0) &&
674 ((rxon
->cck_basic_rates
& IWL_RATE_1M_MASK
) == 0));
676 IWL_WARNING("check basic rate %d | %d\n", counter
++, error
);
678 error
|= (le16_to_cpu(rxon
->assoc_id
) > 2007);
680 IWL_WARNING("check assoc id %d | %d\n", counter
++, error
);
682 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
))
683 == (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
));
685 IWL_WARNING("check CCK and short slot %d | %d\n",
688 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
))
689 == (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
));
691 IWL_WARNING("check CCK & auto detect %d | %d\n",
694 error
|= ((rxon
->flags
& (RXON_FLG_AUTO_DETECT_MSK
|
695 RXON_FLG_TGG_PROTECT_MSK
)) == RXON_FLG_TGG_PROTECT_MSK
);
697 IWL_WARNING("check TGG and auto detect %d | %d\n",
701 IWL_WARNING("Tuning to channel %d\n",
702 le16_to_cpu(rxon
->channel
));
705 IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
712 * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
713 * @priv: staging_rxon is compared to active_rxon
715 * If the RXON structure is changing enough to require a new tune,
716 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
717 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
719 static int iwl4965_full_rxon_required(struct iwl_priv
*priv
)
722 /* These items are only settable from the full RXON command */
723 if (!(priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) ||
724 compare_ether_addr(priv
->staging_rxon
.bssid_addr
,
725 priv
->active_rxon
.bssid_addr
) ||
726 compare_ether_addr(priv
->staging_rxon
.node_addr
,
727 priv
->active_rxon
.node_addr
) ||
728 compare_ether_addr(priv
->staging_rxon
.wlap_bssid_addr
,
729 priv
->active_rxon
.wlap_bssid_addr
) ||
730 (priv
->staging_rxon
.dev_type
!= priv
->active_rxon
.dev_type
) ||
731 (priv
->staging_rxon
.channel
!= priv
->active_rxon
.channel
) ||
732 (priv
->staging_rxon
.air_propagation
!=
733 priv
->active_rxon
.air_propagation
) ||
734 (priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
!=
735 priv
->active_rxon
.ofdm_ht_single_stream_basic_rates
) ||
736 (priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
!=
737 priv
->active_rxon
.ofdm_ht_dual_stream_basic_rates
) ||
738 (priv
->staging_rxon
.rx_chain
!= priv
->active_rxon
.rx_chain
) ||
739 (priv
->staging_rxon
.assoc_id
!= priv
->active_rxon
.assoc_id
))
742 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
743 * be updated with the RXON_ASSOC command -- however only some
744 * flag transitions are allowed using RXON_ASSOC */
746 /* Check if we are not switching bands */
747 if ((priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) !=
748 (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
))
751 /* Check if we are switching association toggle */
752 if ((priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) !=
753 (priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
))
759 static int iwl4965_send_rxon_assoc(struct iwl_priv
*priv
)
762 struct iwl4965_rx_packet
*res
= NULL
;
763 struct iwl4965_rxon_assoc_cmd rxon_assoc
;
764 struct iwl_host_cmd cmd
= {
765 .id
= REPLY_RXON_ASSOC
,
766 .len
= sizeof(rxon_assoc
),
767 .meta
.flags
= CMD_WANT_SKB
,
770 const struct iwl4965_rxon_cmd
*rxon1
= &priv
->staging_rxon
;
771 const struct iwl4965_rxon_cmd
*rxon2
= &priv
->active_rxon
;
773 if ((rxon1
->flags
== rxon2
->flags
) &&
774 (rxon1
->filter_flags
== rxon2
->filter_flags
) &&
775 (rxon1
->cck_basic_rates
== rxon2
->cck_basic_rates
) &&
776 (rxon1
->ofdm_ht_single_stream_basic_rates
==
777 rxon2
->ofdm_ht_single_stream_basic_rates
) &&
778 (rxon1
->ofdm_ht_dual_stream_basic_rates
==
779 rxon2
->ofdm_ht_dual_stream_basic_rates
) &&
780 (rxon1
->rx_chain
== rxon2
->rx_chain
) &&
781 (rxon1
->ofdm_basic_rates
== rxon2
->ofdm_basic_rates
)) {
782 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
786 rxon_assoc
.flags
= priv
->staging_rxon
.flags
;
787 rxon_assoc
.filter_flags
= priv
->staging_rxon
.filter_flags
;
788 rxon_assoc
.ofdm_basic_rates
= priv
->staging_rxon
.ofdm_basic_rates
;
789 rxon_assoc
.cck_basic_rates
= priv
->staging_rxon
.cck_basic_rates
;
790 rxon_assoc
.reserved
= 0;
791 rxon_assoc
.ofdm_ht_single_stream_basic_rates
=
792 priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
;
793 rxon_assoc
.ofdm_ht_dual_stream_basic_rates
=
794 priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
;
795 rxon_assoc
.rx_chain_select_flags
= priv
->staging_rxon
.rx_chain
;
797 rc
= iwl_send_cmd_sync(priv
, &cmd
);
801 res
= (struct iwl4965_rx_packet
*)cmd
.meta
.u
.skb
->data
;
802 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
803 IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n");
807 priv
->alloc_rxb_skb
--;
808 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
814 * iwl4965_commit_rxon - commit staging_rxon to hardware
816 * The RXON command in staging_rxon is committed to the hardware and
817 * the active_rxon structure is updated with the new data. This
818 * function correctly transitions out of the RXON_ASSOC_MSK state if
819 * a HW tune is required based on the RXON structure changes.
821 static int iwl4965_commit_rxon(struct iwl_priv
*priv
)
823 /* cast away the const for active_rxon in this function */
824 struct iwl4965_rxon_cmd
*active_rxon
= (void *)&priv
->active_rxon
;
825 DECLARE_MAC_BUF(mac
);
828 if (!iwl_is_alive(priv
))
831 /* always get timestamp with Rx frame */
832 priv
->staging_rxon
.flags
|= RXON_FLG_TSF2HOST_MSK
;
834 rc
= iwl4965_check_rxon_cmd(&priv
->staging_rxon
);
836 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
840 /* If we don't need to send a full RXON, we can use
841 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
842 * and other flags for the current radio configuration. */
843 if (!iwl4965_full_rxon_required(priv
)) {
844 rc
= iwl4965_send_rxon_assoc(priv
);
846 IWL_ERROR("Error setting RXON_ASSOC "
847 "configuration (%d).\n", rc
);
851 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
856 /* station table will be cleared */
857 priv
->assoc_station_added
= 0;
859 #ifdef CONFIG_IWL4965_SENSITIVITY
860 priv
->sensitivity_data
.state
= IWL_SENS_CALIB_NEED_REINIT
;
861 if (!priv
->error_recovering
)
862 priv
->start_calib
= 0;
864 iwl4965_init_sensitivity(priv
, CMD_ASYNC
, 1);
865 #endif /* CONFIG_IWL4965_SENSITIVITY */
867 /* If we are currently associated and the new config requires
868 * an RXON_ASSOC and the new config wants the associated mask enabled,
869 * we must clear the associated from the active configuration
870 * before we apply the new config */
871 if (iwl_is_associated(priv
) &&
872 (priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
)) {
873 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
874 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
876 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
877 sizeof(struct iwl4965_rxon_cmd
),
880 /* If the mask clearing failed then we set
881 * active_rxon back to what it was previously */
883 active_rxon
->filter_flags
|= RXON_FILTER_ASSOC_MSK
;
884 IWL_ERROR("Error clearing ASSOC_MSK on current "
885 "configuration (%d).\n", rc
);
890 IWL_DEBUG_INFO("Sending RXON\n"
891 "* with%s RXON_FILTER_ASSOC_MSK\n"
894 ((priv
->staging_rxon
.filter_flags
&
895 RXON_FILTER_ASSOC_MSK
) ? "" : "out"),
896 le16_to_cpu(priv
->staging_rxon
.channel
),
897 print_mac(mac
, priv
->staging_rxon
.bssid_addr
));
899 iwl4965_set_rxon_hwcrypto(priv
, priv
->cfg
->mod_params
->hw_crypto
);
900 /* Apply the new configuration */
901 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
902 sizeof(struct iwl4965_rxon_cmd
), &priv
->staging_rxon
);
904 IWL_ERROR("Error setting new configuration (%d).\n", rc
);
908 iwlcore_clear_stations_table(priv
);
910 #ifdef CONFIG_IWL4965_SENSITIVITY
911 if (!priv
->error_recovering
)
912 priv
->start_calib
= 0;
914 priv
->sensitivity_data
.state
= IWL_SENS_CALIB_NEED_REINIT
;
915 iwl4965_init_sensitivity(priv
, CMD_ASYNC
, 1);
916 #endif /* CONFIG_IWL4965_SENSITIVITY */
918 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
920 /* If we issue a new RXON command which required a tune then we must
921 * send a new TXPOWER command or we won't be able to Tx any frames */
922 rc
= iwl4965_hw_reg_send_txpower(priv
);
924 IWL_ERROR("Error setting Tx power (%d).\n", rc
);
928 /* Add the broadcast address so we can send broadcast frames */
929 if (iwl4965_rxon_add_station(priv
, iwl4965_broadcast_addr
, 0) ==
930 IWL_INVALID_STATION
) {
931 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
935 /* If we have set the ASSOC_MSK and we are in BSS mode then
936 * add the IWL_AP_ID to the station rate table */
937 if (iwl_is_associated(priv
) &&
938 (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
)) {
939 if (iwl4965_rxon_add_station(priv
, priv
->active_rxon
.bssid_addr
, 1)
940 == IWL_INVALID_STATION
) {
941 IWL_ERROR("Error adding AP address for transmit.\n");
944 priv
->assoc_station_added
= 1;
945 if (priv
->default_wep_key
&&
946 iwl_send_static_wepkey_cmd(priv
, 0))
947 IWL_ERROR("Could not send WEP static key.\n");
953 static int iwl4965_send_bt_config(struct iwl_priv
*priv
)
955 struct iwl4965_bt_cmd bt_cmd
= {
963 return iwl_send_cmd_pdu(priv
, REPLY_BT_CONFIG
,
964 sizeof(struct iwl4965_bt_cmd
), &bt_cmd
);
967 static int iwl4965_send_scan_abort(struct iwl_priv
*priv
)
970 struct iwl4965_rx_packet
*res
;
971 struct iwl_host_cmd cmd
= {
972 .id
= REPLY_SCAN_ABORT_CMD
,
973 .meta
.flags
= CMD_WANT_SKB
,
976 /* If there isn't a scan actively going on in the hardware
977 * then we are in between scan bands and not actually
978 * actively scanning, so don't send the abort command */
979 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
980 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
984 rc
= iwl_send_cmd_sync(priv
, &cmd
);
986 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
990 res
= (struct iwl4965_rx_packet
*)cmd
.meta
.u
.skb
->data
;
991 if (res
->u
.status
!= CAN_ABORT_STATUS
) {
992 /* The scan abort will return 1 for success or
993 * 2 for "failure". A failure condition can be
994 * due to simply not being in an active scan which
995 * can occur if we send the scan abort before we
996 * the microcode has notified us that a scan is
998 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res
->u
.status
);
999 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1000 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
1003 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1008 static int iwl4965_card_state_sync_callback(struct iwl_priv
*priv
,
1009 struct iwl_cmd
*cmd
,
1010 struct sk_buff
*skb
)
1018 * Use: Sets the device's internal card state to enable, disable, or halt
1020 * When in the 'enable' state the card operates as normal.
1021 * When in the 'disable' state, the card enters into a low power mode.
1022 * When in the 'halt' state, the card is shut down and must be fully
1023 * restarted to come back on.
1025 static int iwl4965_send_card_state(struct iwl_priv
*priv
, u32 flags
, u8 meta_flag
)
1027 struct iwl_host_cmd cmd
= {
1028 .id
= REPLY_CARD_STATE_CMD
,
1031 .meta
.flags
= meta_flag
,
1034 if (meta_flag
& CMD_ASYNC
)
1035 cmd
.meta
.u
.callback
= iwl4965_card_state_sync_callback
;
1037 return iwl_send_cmd(priv
, &cmd
);
1040 static int iwl4965_add_sta_sync_callback(struct iwl_priv
*priv
,
1041 struct iwl_cmd
*cmd
, struct sk_buff
*skb
)
1043 struct iwl4965_rx_packet
*res
= NULL
;
1046 IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
1050 res
= (struct iwl4965_rx_packet
*)skb
->data
;
1051 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1052 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1057 switch (res
->u
.add_sta
.status
) {
1058 case ADD_STA_SUCCESS_MSK
:
1064 /* We didn't cache the SKB; let the caller free it */
1068 int iwl4965_send_add_station(struct iwl_priv
*priv
,
1069 struct iwl4965_addsta_cmd
*sta
, u8 flags
)
1071 struct iwl4965_rx_packet
*res
= NULL
;
1073 struct iwl_host_cmd cmd
= {
1074 .id
= REPLY_ADD_STA
,
1075 .len
= sizeof(struct iwl4965_addsta_cmd
),
1076 .meta
.flags
= flags
,
1080 if (flags
& CMD_ASYNC
)
1081 cmd
.meta
.u
.callback
= iwl4965_add_sta_sync_callback
;
1083 cmd
.meta
.flags
|= CMD_WANT_SKB
;
1085 rc
= iwl_send_cmd(priv
, &cmd
);
1087 if (rc
|| (flags
& CMD_ASYNC
))
1090 res
= (struct iwl4965_rx_packet
*)cmd
.meta
.u
.skb
->data
;
1091 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1092 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1098 switch (res
->u
.add_sta
.status
) {
1099 case ADD_STA_SUCCESS_MSK
:
1100 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
1104 IWL_WARNING("REPLY_ADD_STA failed\n");
1109 priv
->alloc_rxb_skb
--;
1110 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1115 static int iwl4965_set_ccmp_dynamic_key_info(struct iwl_priv
*priv
,
1116 struct ieee80211_key_conf
*keyconf
,
1119 unsigned long flags
;
1120 __le16 key_flags
= 0;
1122 key_flags
|= (STA_KEY_FLG_CCMP
| STA_KEY_FLG_MAP_KEY_MSK
);
1123 key_flags
|= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
1125 if (sta_id
== priv
->hw_setting
.bcast_sta_id
)
1126 key_flags
|= STA_KEY_MULTICAST_MSK
;
1128 keyconf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1129 keyconf
->hw_key_idx
= keyconf
->keyidx
;
1131 key_flags
&= ~STA_KEY_FLG_INVALID
;
1133 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1134 priv
->stations
[sta_id
].keyinfo
.alg
= keyconf
->alg
;
1135 priv
->stations
[sta_id
].keyinfo
.keylen
= keyconf
->keylen
;
1137 memcpy(priv
->stations
[sta_id
].keyinfo
.key
, keyconf
->key
,
1140 memcpy(priv
->stations
[sta_id
].sta
.key
.key
, keyconf
->key
,
1143 priv
->stations
[sta_id
].sta
.key
.key_offset
1144 = (sta_id
% STA_KEY_MAX_NUM
);/*FIXME*/
1145 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
1146 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1147 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1149 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1151 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
1152 return iwl4965_send_add_station(priv
,
1153 &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
1156 static int iwl4965_set_tkip_dynamic_key_info(struct iwl_priv
*priv
,
1157 struct ieee80211_key_conf
*keyconf
,
1160 unsigned long flags
;
1163 keyconf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1164 keyconf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1165 keyconf
->hw_key_idx
= keyconf
->keyidx
;
1167 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1169 priv
->stations
[sta_id
].keyinfo
.alg
= keyconf
->alg
;
1170 priv
->stations
[sta_id
].keyinfo
.conf
= keyconf
;
1171 priv
->stations
[sta_id
].keyinfo
.keylen
= 16;
1173 /* This copy is acutally not needed: we get the key with each TX */
1174 memcpy(priv
->stations
[sta_id
].keyinfo
.key
, keyconf
->key
, 16);
1176 memcpy(priv
->stations
[sta_id
].sta
.key
.key
, keyconf
->key
, 16);
1178 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1183 static int iwl4965_clear_sta_key_info(struct iwl_priv
*priv
, u8 sta_id
)
1185 unsigned long flags
;
1187 priv
->key_mapping_key
= 0;
1189 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1190 memset(&priv
->stations
[sta_id
].keyinfo
, 0, sizeof(struct iwl4965_hw_key
));
1191 memset(&priv
->stations
[sta_id
].sta
.key
, 0, sizeof(struct iwl4965_keyinfo
));
1192 priv
->stations
[sta_id
].sta
.key
.key_flags
= STA_KEY_FLG_NO_ENC
;
1193 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1194 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1195 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1197 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
1198 iwl4965_send_add_station(priv
, &priv
->stations
[sta_id
].sta
, 0);
1202 static int iwl4965_set_dynamic_key(struct iwl_priv
*priv
,
1203 struct ieee80211_key_conf
*key
, u8 sta_id
)
1207 priv
->key_mapping_key
= 1;
1211 ret
= iwl4965_set_ccmp_dynamic_key_info(priv
, key
, sta_id
);
1214 ret
= iwl4965_set_tkip_dynamic_key_info(priv
, key
, sta_id
);
1217 ret
= iwl_set_wep_dynamic_key_info(priv
, key
, sta_id
);
1220 IWL_ERROR("Unknown alg: %s alg = %d\n", __func__
, key
->alg
);
1227 static void iwl4965_clear_free_frames(struct iwl_priv
*priv
)
1229 struct list_head
*element
;
1231 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
1232 priv
->frames_count
);
1234 while (!list_empty(&priv
->free_frames
)) {
1235 element
= priv
->free_frames
.next
;
1237 kfree(list_entry(element
, struct iwl4965_frame
, list
));
1238 priv
->frames_count
--;
1241 if (priv
->frames_count
) {
1242 IWL_WARNING("%d frames still in use. Did we lose one?\n",
1243 priv
->frames_count
);
1244 priv
->frames_count
= 0;
1248 static struct iwl4965_frame
*iwl4965_get_free_frame(struct iwl_priv
*priv
)
1250 struct iwl4965_frame
*frame
;
1251 struct list_head
*element
;
1252 if (list_empty(&priv
->free_frames
)) {
1253 frame
= kzalloc(sizeof(*frame
), GFP_KERNEL
);
1255 IWL_ERROR("Could not allocate frame!\n");
1259 priv
->frames_count
++;
1263 element
= priv
->free_frames
.next
;
1265 return list_entry(element
, struct iwl4965_frame
, list
);
1268 static void iwl4965_free_frame(struct iwl_priv
*priv
, struct iwl4965_frame
*frame
)
1270 memset(frame
, 0, sizeof(*frame
));
1271 list_add(&frame
->list
, &priv
->free_frames
);
1274 unsigned int iwl4965_fill_beacon_frame(struct iwl_priv
*priv
,
1275 struct ieee80211_hdr
*hdr
,
1276 const u8
*dest
, int left
)
1279 if (!iwl_is_associated(priv
) || !priv
->ibss_beacon
||
1280 ((priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) &&
1281 (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
)))
1284 if (priv
->ibss_beacon
->len
> left
)
1287 memcpy(hdr
, priv
->ibss_beacon
->data
, priv
->ibss_beacon
->len
);
1289 return priv
->ibss_beacon
->len
;
1292 static u8
iwl4965_rate_get_lowest_plcp(int rate_mask
)
1296 for (i
= IWL_RATE_1M_INDEX
; i
!= IWL_RATE_INVALID
;
1297 i
= iwl4965_rates
[i
].next_ieee
) {
1298 if (rate_mask
& (1 << i
))
1299 return iwl4965_rates
[i
].plcp
;
1302 return IWL_RATE_INVALID
;
1305 static int iwl4965_send_beacon_cmd(struct iwl_priv
*priv
)
1307 struct iwl4965_frame
*frame
;
1308 unsigned int frame_size
;
1312 frame
= iwl4965_get_free_frame(priv
);
1315 IWL_ERROR("Could not obtain free frame buffer for beacon "
1320 if (!(priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)) {
1321 rate
= iwl4965_rate_get_lowest_plcp(priv
->active_rate_basic
&
1323 if (rate
== IWL_INVALID_RATE
)
1324 rate
= IWL_RATE_6M_PLCP
;
1326 rate
= iwl4965_rate_get_lowest_plcp(priv
->active_rate_basic
& 0xF);
1327 if (rate
== IWL_INVALID_RATE
)
1328 rate
= IWL_RATE_1M_PLCP
;
1331 frame_size
= iwl4965_hw_get_beacon_cmd(priv
, frame
, rate
);
1333 rc
= iwl_send_cmd_pdu(priv
, REPLY_TX_BEACON
, frame_size
,
1336 iwl4965_free_frame(priv
, frame
);
1341 /******************************************************************************
1343 * Misc. internal state and helper functions
1345 ******************************************************************************/
1347 static void iwl4965_unset_hw_setting(struct iwl_priv
*priv
)
1349 if (priv
->hw_setting
.shared_virt
)
1350 pci_free_consistent(priv
->pci_dev
,
1351 sizeof(struct iwl4965_shared
),
1352 priv
->hw_setting
.shared_virt
,
1353 priv
->hw_setting
.shared_phys
);
1357 * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field
1359 * return : set the bit for each supported rate insert in ie
1361 static u16
iwl4965_supported_rate_to_ie(u8
*ie
, u16 supported_rate
,
1362 u16 basic_rate
, int *left
)
1364 u16 ret_rates
= 0, bit
;
1369 for (bit
= 1, i
= 0; i
< IWL_RATE_COUNT
; i
++, bit
<<= 1) {
1370 if (bit
& supported_rate
) {
1372 rates
[*cnt
] = iwl4965_rates
[i
].ieee
|
1373 ((bit
& basic_rate
) ? 0x80 : 0x00);
1377 (*cnt
>= IWL_SUPPORTED_RATES_IE_LEN
))
1386 * iwl4965_fill_probe_req - fill in all required fields and IE for probe request
1388 static u16
iwl4965_fill_probe_req(struct iwl_priv
*priv
,
1389 enum ieee80211_band band
,
1390 struct ieee80211_mgmt
*frame
,
1391 int left
, int is_direct
)
1395 u16 active_rates
, ret_rates
, cck_rates
, active_rate_basic
;
1396 #ifdef CONFIG_IWL4965_HT
1397 const struct ieee80211_supported_band
*sband
=
1398 iwl4965_get_hw_mode(priv
, band
);
1399 #endif /* CONFIG_IWL4965_HT */
1401 /* Make sure there is enough space for the probe request,
1402 * two mandatory IEs and the data */
1408 frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
1409 memcpy(frame
->da
, iwl4965_broadcast_addr
, ETH_ALEN
);
1410 memcpy(frame
->sa
, priv
->mac_addr
, ETH_ALEN
);
1411 memcpy(frame
->bssid
, iwl4965_broadcast_addr
, ETH_ALEN
);
1412 frame
->seq_ctrl
= 0;
1414 /* fill in our indirect SSID IE */
1421 pos
= &(frame
->u
.probe_req
.variable
[0]);
1422 *pos
++ = WLAN_EID_SSID
;
1425 /* fill in our direct SSID IE... */
1428 left
-= 2 + priv
->essid_len
;
1431 /* ... fill it in... */
1432 *pos
++ = WLAN_EID_SSID
;
1433 *pos
++ = priv
->essid_len
;
1434 memcpy(pos
, priv
->essid
, priv
->essid_len
);
1435 pos
+= priv
->essid_len
;
1436 len
+= 2 + priv
->essid_len
;
1439 /* fill in supported rate */
1445 /* ... fill it in... */
1446 *pos
++ = WLAN_EID_SUPP_RATES
;
1449 /* exclude 60M rate */
1450 active_rates
= priv
->rates_mask
;
1451 active_rates
&= ~IWL_RATE_60M_MASK
;
1453 active_rate_basic
= active_rates
& IWL_BASIC_RATES_MASK
;
1455 cck_rates
= IWL_CCK_RATES_MASK
& active_rates
;
1456 ret_rates
= iwl4965_supported_rate_to_ie(pos
, cck_rates
,
1457 active_rate_basic
, &left
);
1458 active_rates
&= ~ret_rates
;
1460 ret_rates
= iwl4965_supported_rate_to_ie(pos
, active_rates
,
1461 active_rate_basic
, &left
);
1462 active_rates
&= ~ret_rates
;
1466 if (active_rates
== 0)
1469 /* fill in supported extended rate */
1474 /* ... fill it in... */
1475 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
1477 iwl4965_supported_rate_to_ie(pos
, active_rates
,
1478 active_rate_basic
, &left
);
1482 #ifdef CONFIG_IWL4965_HT
1483 if (sband
&& sband
->ht_info
.ht_supported
) {
1484 struct ieee80211_ht_cap
*ht_cap
;
1486 *pos
++ = WLAN_EID_HT_CAPABILITY
;
1487 *pos
++ = sizeof(struct ieee80211_ht_cap
);
1488 ht_cap
= (struct ieee80211_ht_cap
*)pos
;
1489 ht_cap
->cap_info
= cpu_to_le16(sband
->ht_info
.cap
);
1490 memcpy(ht_cap
->supp_mcs_set
, sband
->ht_info
.supp_mcs_set
, 16);
1491 ht_cap
->ampdu_params_info
=(sband
->ht_info
.ampdu_factor
&
1492 IEEE80211_HT_CAP_AMPDU_FACTOR
) |
1493 ((sband
->ht_info
.ampdu_density
<< 2) &
1494 IEEE80211_HT_CAP_AMPDU_DENSITY
);
1495 len
+= 2 + sizeof(struct ieee80211_ht_cap
);
1497 #endif /*CONFIG_IWL4965_HT */
1506 static int iwl4965_send_qos_params_command(struct iwl_priv
*priv
,
1507 struct iwl4965_qosparam_cmd
*qos
)
1510 return iwl_send_cmd_pdu(priv
, REPLY_QOS_PARAM
,
1511 sizeof(struct iwl4965_qosparam_cmd
), qos
);
1514 static void iwl4965_activate_qos(struct iwl_priv
*priv
, u8 force
)
1516 unsigned long flags
;
1518 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
1521 if (!priv
->qos_data
.qos_enable
)
1524 spin_lock_irqsave(&priv
->lock
, flags
);
1525 priv
->qos_data
.def_qos_parm
.qos_flags
= 0;
1527 if (priv
->qos_data
.qos_cap
.q_AP
.queue_request
&&
1528 !priv
->qos_data
.qos_cap
.q_AP
.txop_request
)
1529 priv
->qos_data
.def_qos_parm
.qos_flags
|=
1530 QOS_PARAM_FLG_TXOP_TYPE_MSK
;
1531 if (priv
->qos_data
.qos_active
)
1532 priv
->qos_data
.def_qos_parm
.qos_flags
|=
1533 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
1535 #ifdef CONFIG_IWL4965_HT
1536 if (priv
->current_ht_config
.is_ht
)
1537 priv
->qos_data
.def_qos_parm
.qos_flags
|= QOS_PARAM_FLG_TGN_MSK
;
1538 #endif /* CONFIG_IWL4965_HT */
1540 spin_unlock_irqrestore(&priv
->lock
, flags
);
1542 if (force
|| iwl_is_associated(priv
)) {
1543 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
1544 priv
->qos_data
.qos_active
,
1545 priv
->qos_data
.def_qos_parm
.qos_flags
);
1547 iwl4965_send_qos_params_command(priv
,
1548 &(priv
->qos_data
.def_qos_parm
));
1553 * Power management (not Tx power!) functions
1555 #define MSEC_TO_USEC 1024
1557 #define NOSLP __constant_cpu_to_le16(0), 0, 0
1558 #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0
1559 #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
1560 #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
1561 __constant_cpu_to_le32(X1), \
1562 __constant_cpu_to_le32(X2), \
1563 __constant_cpu_to_le32(X3), \
1564 __constant_cpu_to_le32(X4)}
1567 /* default power management (not Tx power) table values */
1569 static struct iwl4965_power_vec_entry range_0
[IWL_POWER_AC
] = {
1570 {{NOSLP
, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1571 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
1572 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
1573 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
1574 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
1575 {{SLP
, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
1579 static struct iwl4965_power_vec_entry range_1
[IWL_POWER_AC
] = {
1580 {{NOSLP
, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1581 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
1582 SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
1583 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
1584 SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
1585 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
1586 SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
1587 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
1588 {{SLP
, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
1589 SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
1592 int iwl4965_power_init_handle(struct iwl_priv
*priv
)
1595 struct iwl4965_power_mgr
*pow_data
;
1596 int size
= sizeof(struct iwl4965_power_vec_entry
) * IWL_POWER_AC
;
1599 IWL_DEBUG_POWER("Initialize power \n");
1601 pow_data
= &(priv
->power_data
);
1603 memset(pow_data
, 0, sizeof(*pow_data
));
1605 pow_data
->active_index
= IWL_POWER_RANGE_0
;
1606 pow_data
->dtim_val
= 0xffff;
1608 memcpy(&pow_data
->pwr_range_0
[0], &range_0
[0], size
);
1609 memcpy(&pow_data
->pwr_range_1
[0], &range_1
[0], size
);
1611 rc
= pci_read_config_word(priv
->pci_dev
, PCI_LINK_CTRL
, &pci_pm
);
1615 struct iwl4965_powertable_cmd
*cmd
;
1617 IWL_DEBUG_POWER("adjust power command flags\n");
1619 for (i
= 0; i
< IWL_POWER_AC
; i
++) {
1620 cmd
= &pow_data
->pwr_range_0
[i
].cmd
;
1623 cmd
->flags
&= ~IWL_POWER_PCI_PM_MSK
;
1625 cmd
->flags
|= IWL_POWER_PCI_PM_MSK
;
1631 static int iwl4965_update_power_cmd(struct iwl_priv
*priv
,
1632 struct iwl4965_powertable_cmd
*cmd
, u32 mode
)
1637 struct iwl4965_power_vec_entry
*range
;
1639 struct iwl4965_power_mgr
*pow_data
;
1641 if (mode
> IWL_POWER_INDEX_5
) {
1642 IWL_DEBUG_POWER("Error invalid power mode \n");
1645 pow_data
= &(priv
->power_data
);
1647 if (pow_data
->active_index
== IWL_POWER_RANGE_0
)
1648 range
= &pow_data
->pwr_range_0
[0];
1650 range
= &pow_data
->pwr_range_1
[1];
1652 memcpy(cmd
, &range
[mode
].cmd
, sizeof(struct iwl4965_powertable_cmd
));
1654 #ifdef IWL_MAC80211_DISABLE
1655 if (priv
->assoc_network
!= NULL
) {
1656 unsigned long flags
;
1658 period
= priv
->assoc_network
->tim
.tim_period
;
1660 #endif /*IWL_MAC80211_DISABLE */
1661 skip
= range
[mode
].no_dtim
;
1670 cmd
->flags
&= ~IWL_POWER_SLEEP_OVER_DTIM_MSK
;
1672 __le32 slp_itrvl
= cmd
->sleep_interval
[IWL_POWER_VEC_SIZE
- 1];
1673 max_sleep
= (le32_to_cpu(slp_itrvl
) / period
) * period
;
1674 cmd
->flags
|= IWL_POWER_SLEEP_OVER_DTIM_MSK
;
1677 for (i
= 0; i
< IWL_POWER_VEC_SIZE
; i
++) {
1678 if (le32_to_cpu(cmd
->sleep_interval
[i
]) > max_sleep
)
1679 cmd
->sleep_interval
[i
] = cpu_to_le32(max_sleep
);
1682 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd
->flags
);
1683 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd
->tx_data_timeout
));
1684 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd
->rx_data_timeout
));
1685 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
1686 le32_to_cpu(cmd
->sleep_interval
[0]),
1687 le32_to_cpu(cmd
->sleep_interval
[1]),
1688 le32_to_cpu(cmd
->sleep_interval
[2]),
1689 le32_to_cpu(cmd
->sleep_interval
[3]),
1690 le32_to_cpu(cmd
->sleep_interval
[4]));
1695 static int iwl4965_send_power_mode(struct iwl_priv
*priv
, u32 mode
)
1697 u32
uninitialized_var(final_mode
);
1699 struct iwl4965_powertable_cmd cmd
;
1701 /* If on battery, set to 3,
1702 * if plugged into AC power, set to CAM ("continuously aware mode"),
1703 * else user level */
1705 case IWL_POWER_BATTERY
:
1706 final_mode
= IWL_POWER_INDEX_3
;
1709 final_mode
= IWL_POWER_MODE_CAM
;
1716 cmd
.keep_alive_beacons
= 0;
1718 iwl4965_update_power_cmd(priv
, &cmd
, final_mode
);
1720 rc
= iwl_send_cmd_pdu(priv
, POWER_TABLE_CMD
, sizeof(cmd
), &cmd
);
1722 if (final_mode
== IWL_POWER_MODE_CAM
)
1723 clear_bit(STATUS_POWER_PMI
, &priv
->status
);
1725 set_bit(STATUS_POWER_PMI
, &priv
->status
);
1730 int iwl4965_is_network_packet(struct iwl_priv
*priv
, struct ieee80211_hdr
*header
)
1732 /* Filter incoming packets to determine if they are targeted toward
1733 * this network, discarding packets coming from ourselves */
1734 switch (priv
->iw_mode
) {
1735 case IEEE80211_IF_TYPE_IBSS
: /* Header: Dest. | Source | BSSID */
1736 /* packets from our adapter are dropped (echo) */
1737 if (!compare_ether_addr(header
->addr2
, priv
->mac_addr
))
1739 /* {broad,multi}cast packets to our IBSS go through */
1740 if (is_multicast_ether_addr(header
->addr1
))
1741 return !compare_ether_addr(header
->addr3
, priv
->bssid
);
1742 /* packets to our adapter go through */
1743 return !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
1744 case IEEE80211_IF_TYPE_STA
: /* Header: Dest. | AP{BSSID} | Source */
1745 /* packets from our adapter are dropped (echo) */
1746 if (!compare_ether_addr(header
->addr3
, priv
->mac_addr
))
1748 /* {broad,multi}cast packets to our BSS go through */
1749 if (is_multicast_ether_addr(header
->addr1
))
1750 return !compare_ether_addr(header
->addr2
, priv
->bssid
);
1751 /* packets to our adapter go through */
1752 return !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
1760 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1762 static const char *iwl4965_get_tx_fail_reason(u32 status
)
1764 switch (status
& TX_STATUS_MSK
) {
1765 case TX_STATUS_SUCCESS
:
1767 TX_STATUS_ENTRY(SHORT_LIMIT
);
1768 TX_STATUS_ENTRY(LONG_LIMIT
);
1769 TX_STATUS_ENTRY(FIFO_UNDERRUN
);
1770 TX_STATUS_ENTRY(MGMNT_ABORT
);
1771 TX_STATUS_ENTRY(NEXT_FRAG
);
1772 TX_STATUS_ENTRY(LIFE_EXPIRE
);
1773 TX_STATUS_ENTRY(DEST_PS
);
1774 TX_STATUS_ENTRY(ABORTED
);
1775 TX_STATUS_ENTRY(BT_RETRY
);
1776 TX_STATUS_ENTRY(STA_INVALID
);
1777 TX_STATUS_ENTRY(FRAG_DROPPED
);
1778 TX_STATUS_ENTRY(TID_DISABLE
);
1779 TX_STATUS_ENTRY(FRAME_FLUSHED
);
1780 TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL
);
1781 TX_STATUS_ENTRY(TX_LOCKED
);
1782 TX_STATUS_ENTRY(NO_BEACON_ON_RADAR
);
1789 * iwl4965_scan_cancel - Cancel any currently executing HW scan
1791 * NOTE: priv->mutex is not required before calling this function
1793 static int iwl4965_scan_cancel(struct iwl_priv
*priv
)
1795 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
1796 clear_bit(STATUS_SCANNING
, &priv
->status
);
1800 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
1801 if (!test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
1802 IWL_DEBUG_SCAN("Queuing scan abort.\n");
1803 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1804 queue_work(priv
->workqueue
, &priv
->abort_scan
);
1807 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
1809 return test_bit(STATUS_SCANNING
, &priv
->status
);
1816 * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan
1817 * @ms: amount of time to wait (in milliseconds) for scan to abort
1819 * NOTE: priv->mutex must be held before calling this function
1821 static int iwl4965_scan_cancel_timeout(struct iwl_priv
*priv
, unsigned long ms
)
1823 unsigned long now
= jiffies
;
1826 ret
= iwl4965_scan_cancel(priv
);
1828 mutex_unlock(&priv
->mutex
);
1829 while (!time_after(jiffies
, now
+ msecs_to_jiffies(ms
)) &&
1830 test_bit(STATUS_SCANNING
, &priv
->status
))
1832 mutex_lock(&priv
->mutex
);
1834 return test_bit(STATUS_SCANNING
, &priv
->status
);
1840 static void iwl4965_sequence_reset(struct iwl_priv
*priv
)
1842 /* Reset ieee stats */
1844 /* We don't reset the net_device_stats (ieee->stats) on
1847 priv
->last_seq_num
= -1;
1848 priv
->last_frag_num
= -1;
1849 priv
->last_packet_time
= 0;
1851 iwl4965_scan_cancel(priv
);
1854 #define MAX_UCODE_BEACON_INTERVAL 4096
1855 #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
1857 static __le16
iwl4965_adjust_beacon_interval(u16 beacon_val
)
1860 u16 beacon_factor
= 0;
1863 (beacon_val
+ MAX_UCODE_BEACON_INTERVAL
)
1864 / MAX_UCODE_BEACON_INTERVAL
;
1865 new_val
= beacon_val
/ beacon_factor
;
1867 return cpu_to_le16(new_val
);
1870 static void iwl4965_setup_rxon_timing(struct iwl_priv
*priv
)
1872 u64 interval_tm_unit
;
1874 unsigned long flags
;
1875 struct ieee80211_conf
*conf
= NULL
;
1878 conf
= ieee80211_get_hw_conf(priv
->hw
);
1880 spin_lock_irqsave(&priv
->lock
, flags
);
1881 priv
->rxon_timing
.timestamp
.dw
[1] = cpu_to_le32(priv
->timestamp
>> 32);
1882 priv
->rxon_timing
.timestamp
.dw
[0] =
1883 cpu_to_le32(priv
->timestamp
& 0xFFFFFFFF);
1885 priv
->rxon_timing
.listen_interval
= INTEL_CONN_LISTEN_INTERVAL
;
1887 tsf
= priv
->timestamp
;
1889 beacon_int
= priv
->beacon_int
;
1890 spin_unlock_irqrestore(&priv
->lock
, flags
);
1892 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) {
1893 if (beacon_int
== 0) {
1894 priv
->rxon_timing
.beacon_interval
= cpu_to_le16(100);
1895 priv
->rxon_timing
.beacon_init_val
= cpu_to_le32(102400);
1897 priv
->rxon_timing
.beacon_interval
=
1898 cpu_to_le16(beacon_int
);
1899 priv
->rxon_timing
.beacon_interval
=
1900 iwl4965_adjust_beacon_interval(
1901 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
1904 priv
->rxon_timing
.atim_window
= 0;
1906 priv
->rxon_timing
.beacon_interval
=
1907 iwl4965_adjust_beacon_interval(conf
->beacon_int
);
1908 /* TODO: we need to get atim_window from upper stack
1909 * for now we set to 0 */
1910 priv
->rxon_timing
.atim_window
= 0;
1914 (le16_to_cpu(priv
->rxon_timing
.beacon_interval
) * 1024);
1915 result
= do_div(tsf
, interval_tm_unit
);
1916 priv
->rxon_timing
.beacon_init_val
=
1917 cpu_to_le32((u32
) ((u64
) interval_tm_unit
- result
));
1920 ("beacon interval %d beacon timer %d beacon tim %d\n",
1921 le16_to_cpu(priv
->rxon_timing
.beacon_interval
),
1922 le32_to_cpu(priv
->rxon_timing
.beacon_init_val
),
1923 le16_to_cpu(priv
->rxon_timing
.atim_window
));
1926 static int iwl4965_scan_initiate(struct iwl_priv
*priv
)
1928 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
1929 IWL_ERROR("APs don't scan.\n");
1933 if (!iwl_is_ready_rf(priv
)) {
1934 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
1938 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
1939 IWL_DEBUG_SCAN("Scan already in progress.\n");
1943 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
1944 IWL_DEBUG_SCAN("Scan request while abort pending. "
1949 IWL_DEBUG_INFO("Starting scan...\n");
1950 priv
->scan_bands
= 2;
1951 set_bit(STATUS_SCANNING
, &priv
->status
);
1952 priv
->scan_start
= jiffies
;
1953 priv
->scan_pass_start
= priv
->scan_start
;
1955 queue_work(priv
->workqueue
, &priv
->request_scan
);
1961 static void iwl4965_set_flags_for_phymode(struct iwl_priv
*priv
,
1962 enum ieee80211_band band
)
1964 if (band
== IEEE80211_BAND_5GHZ
) {
1965 priv
->staging_rxon
.flags
&=
1966 ~(RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
1967 | RXON_FLG_CCK_MSK
);
1968 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
1970 /* Copied from iwl4965_bg_post_associate() */
1971 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
1972 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
1974 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
1976 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
1977 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
1979 priv
->staging_rxon
.flags
|= RXON_FLG_BAND_24G_MSK
;
1980 priv
->staging_rxon
.flags
|= RXON_FLG_AUTO_DETECT_MSK
;
1981 priv
->staging_rxon
.flags
&= ~RXON_FLG_CCK_MSK
;
1986 * initialize rxon structure with default values from eeprom
1988 static void iwl4965_connection_init_rx_config(struct iwl_priv
*priv
)
1990 const struct iwl_channel_info
*ch_info
;
1992 memset(&priv
->staging_rxon
, 0, sizeof(priv
->staging_rxon
));
1994 switch (priv
->iw_mode
) {
1995 case IEEE80211_IF_TYPE_AP
:
1996 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_AP
;
1999 case IEEE80211_IF_TYPE_STA
:
2000 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_ESS
;
2001 priv
->staging_rxon
.filter_flags
= RXON_FILTER_ACCEPT_GRP_MSK
;
2004 case IEEE80211_IF_TYPE_IBSS
:
2005 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_IBSS
;
2006 priv
->staging_rxon
.flags
= RXON_FLG_SHORT_PREAMBLE_MSK
;
2007 priv
->staging_rxon
.filter_flags
= RXON_FILTER_BCON_AWARE_MSK
|
2008 RXON_FILTER_ACCEPT_GRP_MSK
;
2011 case IEEE80211_IF_TYPE_MNTR
:
2012 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_SNIFFER
;
2013 priv
->staging_rxon
.filter_flags
= RXON_FILTER_PROMISC_MSK
|
2014 RXON_FILTER_CTL2HOST_MSK
| RXON_FILTER_ACCEPT_GRP_MSK
;
2017 IWL_ERROR("Unsupported interface type %d\n", priv
->iw_mode
);
2022 /* TODO: Figure out when short_preamble would be set and cache from
2024 if (!hw_to_local(priv
->hw
)->short_preamble
)
2025 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
2027 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
2030 ch_info
= iwl_get_channel_info(priv
, priv
->band
,
2031 le16_to_cpu(priv
->staging_rxon
.channel
));
2034 ch_info
= &priv
->channel_info
[0];
2037 * in some case A channels are all non IBSS
2038 * in this case force B/G channel
2040 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) &&
2041 !(is_channel_ibss(ch_info
)))
2042 ch_info
= &priv
->channel_info
[0];
2044 priv
->staging_rxon
.channel
= cpu_to_le16(ch_info
->channel
);
2045 priv
->band
= ch_info
->band
;
2047 iwl4965_set_flags_for_phymode(priv
, priv
->band
);
2049 priv
->staging_rxon
.ofdm_basic_rates
=
2050 (IWL_OFDM_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
2051 priv
->staging_rxon
.cck_basic_rates
=
2052 (IWL_CCK_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
2054 priv
->staging_rxon
.flags
&= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK
|
2055 RXON_FLG_CHANNEL_MODE_PURE_40_MSK
);
2056 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
2057 memcpy(priv
->staging_rxon
.wlap_bssid_addr
, priv
->mac_addr
, ETH_ALEN
);
2058 priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
= 0xff;
2059 priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
= 0xff;
2060 iwl4965_set_rxon_chain(priv
);
2063 static int iwl4965_set_mode(struct iwl_priv
*priv
, int mode
)
2065 if (mode
== IEEE80211_IF_TYPE_IBSS
) {
2066 const struct iwl_channel_info
*ch_info
;
2068 ch_info
= iwl_get_channel_info(priv
,
2070 le16_to_cpu(priv
->staging_rxon
.channel
));
2072 if (!ch_info
|| !is_channel_ibss(ch_info
)) {
2073 IWL_ERROR("channel %d not IBSS channel\n",
2074 le16_to_cpu(priv
->staging_rxon
.channel
));
2079 priv
->iw_mode
= mode
;
2081 iwl4965_connection_init_rx_config(priv
);
2082 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
2084 iwlcore_clear_stations_table(priv
);
2086 /* dont commit rxon if rf-kill is on*/
2087 if (!iwl_is_ready_rf(priv
))
2090 cancel_delayed_work(&priv
->scan_check
);
2091 if (iwl4965_scan_cancel_timeout(priv
, 100)) {
2092 IWL_WARNING("Aborted scan still in progress after 100ms\n");
2093 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2097 iwl4965_commit_rxon(priv
);
2102 static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv
*priv
,
2103 struct ieee80211_tx_control
*ctl
,
2104 struct iwl_cmd
*cmd
,
2105 struct sk_buff
*skb_frag
,
2108 struct iwl4965_hw_key
*keyinfo
= &priv
->stations
[sta_id
].keyinfo
;
2109 struct iwl_wep_key
*wepkey
;
2112 BUG_ON(ctl
->key_idx
> 3);
2114 switch (keyinfo
->alg
) {
2116 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_CCM
;
2117 memcpy(cmd
->cmd
.tx
.key
, keyinfo
->key
, keyinfo
->keylen
);
2118 if (ctl
->flags
& IEEE80211_TXCTL_AMPDU
)
2119 cmd
->cmd
.tx
.tx_flags
|= TX_CMD_FLG_AGG_CCMP_MSK
;
2120 IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
2124 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_TKIP
;
2125 ieee80211_get_tkip_key(keyinfo
->conf
, skb_frag
,
2126 IEEE80211_TKIP_P2_KEY
, cmd
->cmd
.tx
.key
);
2127 IWL_DEBUG_TX("tx_cmd with tkip hwcrypto\n");
2131 wepkey
= &priv
->wep_keys
[ctl
->key_idx
];
2132 cmd
->cmd
.tx
.sec_ctl
= 0;
2133 if (priv
->default_wep_key
) {
2134 /* the WEP key was sent as static */
2135 keyidx
= ctl
->key_idx
;
2136 memcpy(&cmd
->cmd
.tx
.key
[3], wepkey
->key
,
2138 if (wepkey
->key_size
== WEP_KEY_LEN_128
)
2139 cmd
->cmd
.tx
.sec_ctl
|= TX_CMD_SEC_KEY128
;
2141 /* the WEP key was sent as dynamic */
2142 keyidx
= keyinfo
->keyidx
;
2143 memcpy(&cmd
->cmd
.tx
.key
[3], keyinfo
->key
,
2145 if (keyinfo
->keylen
== WEP_KEY_LEN_128
)
2146 cmd
->cmd
.tx
.sec_ctl
|= TX_CMD_SEC_KEY128
;
2149 cmd
->cmd
.tx
.sec_ctl
|= (TX_CMD_SEC_WEP
|
2150 (keyidx
& TX_CMD_SEC_MSK
) << TX_CMD_SEC_SHIFT
);
2152 IWL_DEBUG_TX("Configuring packet for WEP encryption "
2153 "with key %d\n", keyidx
);
2157 printk(KERN_ERR
"Unknown encode alg %d\n", keyinfo
->alg
);
2163 * handle build REPLY_TX command notification.
2165 static void iwl4965_build_tx_cmd_basic(struct iwl_priv
*priv
,
2166 struct iwl_cmd
*cmd
,
2167 struct ieee80211_tx_control
*ctrl
,
2168 struct ieee80211_hdr
*hdr
,
2169 int is_unicast
, u8 std_id
)
2172 u16 fc
= le16_to_cpu(hdr
->frame_control
);
2173 __le32 tx_flags
= cmd
->cmd
.tx
.tx_flags
;
2175 cmd
->cmd
.tx
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
2176 if (!(ctrl
->flags
& IEEE80211_TXCTL_NO_ACK
)) {
2177 tx_flags
|= TX_CMD_FLG_ACK_MSK
;
2178 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
)
2179 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2180 if (ieee80211_is_probe_response(fc
) &&
2181 !(le16_to_cpu(hdr
->seq_ctrl
) & 0xf))
2182 tx_flags
|= TX_CMD_FLG_TSF_MSK
;
2184 tx_flags
&= (~TX_CMD_FLG_ACK_MSK
);
2185 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2188 if (ieee80211_is_back_request(fc
))
2189 tx_flags
|= TX_CMD_FLG_ACK_MSK
| TX_CMD_FLG_IMM_BA_RSP_MASK
;
2192 cmd
->cmd
.tx
.sta_id
= std_id
;
2193 if (ieee80211_get_morefrag(hdr
))
2194 tx_flags
|= TX_CMD_FLG_MORE_FRAG_MSK
;
2196 qc
= ieee80211_get_qos_ctrl(hdr
);
2198 cmd
->cmd
.tx
.tid_tspec
= (u8
) (le16_to_cpu(*qc
) & 0xf);
2199 tx_flags
&= ~TX_CMD_FLG_SEQ_CTL_MSK
;
2201 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2203 if (ctrl
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
) {
2204 tx_flags
|= TX_CMD_FLG_RTS_MSK
;
2205 tx_flags
&= ~TX_CMD_FLG_CTS_MSK
;
2206 } else if (ctrl
->flags
& IEEE80211_TXCTL_USE_CTS_PROTECT
) {
2207 tx_flags
&= ~TX_CMD_FLG_RTS_MSK
;
2208 tx_flags
|= TX_CMD_FLG_CTS_MSK
;
2211 if ((tx_flags
& TX_CMD_FLG_RTS_MSK
) || (tx_flags
& TX_CMD_FLG_CTS_MSK
))
2212 tx_flags
|= TX_CMD_FLG_FULL_TXOP_PROT_MSK
;
2214 tx_flags
&= ~(TX_CMD_FLG_ANT_SEL_MSK
);
2215 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
2216 if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_ASSOC_REQ
||
2217 (fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_REASSOC_REQ
)
2218 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= cpu_to_le16(3);
2220 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= cpu_to_le16(2);
2222 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= 0;
2225 cmd
->cmd
.tx
.driver_txop
= 0;
2226 cmd
->cmd
.tx
.tx_flags
= tx_flags
;
2227 cmd
->cmd
.tx
.next_frame_len
= 0;
2229 static void iwl_update_tx_stats(struct iwl_priv
*priv
, u16 fc
, u16 len
)
2231 /* 0 - mgmt, 1 - cnt, 2 - data */
2232 int idx
= (fc
& IEEE80211_FCTL_FTYPE
) >> 2;
2233 priv
->tx_stats
[idx
].cnt
++;
2234 priv
->tx_stats
[idx
].bytes
+= len
;
2237 * iwl4965_get_sta_id - Find station's index within station table
2239 * If new IBSS station, create new entry in station table
2241 static int iwl4965_get_sta_id(struct iwl_priv
*priv
,
2242 struct ieee80211_hdr
*hdr
)
2245 u16 fc
= le16_to_cpu(hdr
->frame_control
);
2246 DECLARE_MAC_BUF(mac
);
2248 /* If this frame is broadcast or management, use broadcast station id */
2249 if (((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
) ||
2250 is_multicast_ether_addr(hdr
->addr1
))
2251 return priv
->hw_setting
.bcast_sta_id
;
2253 switch (priv
->iw_mode
) {
2255 /* If we are a client station in a BSS network, use the special
2256 * AP station entry (that's the only station we communicate with) */
2257 case IEEE80211_IF_TYPE_STA
:
2260 /* If we are an AP, then find the station, or use BCAST */
2261 case IEEE80211_IF_TYPE_AP
:
2262 sta_id
= iwl4965_hw_find_station(priv
, hdr
->addr1
);
2263 if (sta_id
!= IWL_INVALID_STATION
)
2265 return priv
->hw_setting
.bcast_sta_id
;
2267 /* If this frame is going out to an IBSS network, find the station,
2268 * or create a new station table entry */
2269 case IEEE80211_IF_TYPE_IBSS
:
2270 sta_id
= iwl4965_hw_find_station(priv
, hdr
->addr1
);
2271 if (sta_id
!= IWL_INVALID_STATION
)
2274 /* Create new station table entry */
2275 sta_id
= iwl4965_add_station_flags(priv
, hdr
->addr1
,
2276 0, CMD_ASYNC
, NULL
);
2278 if (sta_id
!= IWL_INVALID_STATION
)
2281 IWL_DEBUG_DROP("Station %s not in station map. "
2282 "Defaulting to broadcast...\n",
2283 print_mac(mac
, hdr
->addr1
));
2284 iwl_print_hex_dump(IWL_DL_DROP
, (u8
*) hdr
, sizeof(*hdr
));
2285 return priv
->hw_setting
.bcast_sta_id
;
2288 IWL_WARNING("Unknown mode of operation: %d", priv
->iw_mode
);
2289 return priv
->hw_setting
.bcast_sta_id
;
2294 * start REPLY_TX command process
2296 static int iwl4965_tx_skb(struct iwl_priv
*priv
,
2297 struct sk_buff
*skb
, struct ieee80211_tx_control
*ctl
)
2299 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2300 struct iwl4965_tfd_frame
*tfd
;
2302 int txq_id
= ctl
->queue
;
2303 struct iwl4965_tx_queue
*txq
= NULL
;
2304 struct iwl4965_queue
*q
= NULL
;
2305 dma_addr_t phys_addr
;
2306 dma_addr_t txcmd_phys
;
2307 dma_addr_t scratch_phys
;
2308 struct iwl_cmd
*out_cmd
= NULL
;
2309 u16 len
, idx
, len_org
;
2310 u8 id
, hdr_len
, unicast
;
2315 u8 wait_write_ptr
= 0;
2316 unsigned long flags
;
2319 spin_lock_irqsave(&priv
->lock
, flags
);
2320 if (iwl_is_rfkill(priv
)) {
2321 IWL_DEBUG_DROP("Dropping - RF KILL\n");
2326 IWL_DEBUG_DROP("Dropping - !priv->vif\n");
2330 if ((ctl
->tx_rate
->hw_value
& 0xFF) == IWL_INVALID_RATE
) {
2331 IWL_ERROR("ERROR: No TX rate available.\n");
2335 unicast
= !is_multicast_ether_addr(hdr
->addr1
);
2338 fc
= le16_to_cpu(hdr
->frame_control
);
2340 #ifdef CONFIG_IWLWIFI_DEBUG
2341 if (ieee80211_is_auth(fc
))
2342 IWL_DEBUG_TX("Sending AUTH frame\n");
2343 else if (ieee80211_is_assoc_request(fc
))
2344 IWL_DEBUG_TX("Sending ASSOC frame\n");
2345 else if (ieee80211_is_reassoc_request(fc
))
2346 IWL_DEBUG_TX("Sending REASSOC frame\n");
2349 /* drop all data frame if we are not associated */
2350 if (((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
) &&
2351 (!iwl_is_associated(priv
) ||
2352 ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) && !priv
->assoc_id
) ||
2353 !priv
->assoc_station_added
)) {
2354 IWL_DEBUG_DROP("Dropping - !iwl_is_associated\n");
2358 spin_unlock_irqrestore(&priv
->lock
, flags
);
2360 hdr_len
= ieee80211_get_hdrlen(fc
);
2362 /* Find (or create) index into station table for destination station */
2363 sta_id
= iwl4965_get_sta_id(priv
, hdr
);
2364 if (sta_id
== IWL_INVALID_STATION
) {
2365 DECLARE_MAC_BUF(mac
);
2367 IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
2368 print_mac(mac
, hdr
->addr1
));
2372 IWL_DEBUG_RATE("station Id %d\n", sta_id
);
2374 qc
= ieee80211_get_qos_ctrl(hdr
);
2376 u8 tid
= (u8
)(le16_to_cpu(*qc
) & 0xf);
2377 seq_number
= priv
->stations
[sta_id
].tid
[tid
].seq_number
&
2379 hdr
->seq_ctrl
= cpu_to_le16(seq_number
) |
2381 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG
));
2383 #ifdef CONFIG_IWL4965_HT
2384 /* aggregation is on for this <sta,tid> */
2385 if (ctl
->flags
& IEEE80211_TXCTL_AMPDU
)
2386 txq_id
= priv
->stations
[sta_id
].tid
[tid
].agg
.txq_id
;
2387 priv
->stations
[sta_id
].tid
[tid
].tfds_in_queue
++;
2388 #endif /* CONFIG_IWL4965_HT */
2391 /* Descriptor for chosen Tx queue */
2392 txq
= &priv
->txq
[txq_id
];
2395 spin_lock_irqsave(&priv
->lock
, flags
);
2397 /* Set up first empty TFD within this queue's circular TFD buffer */
2398 tfd
= &txq
->bd
[q
->write_ptr
];
2399 memset(tfd
, 0, sizeof(*tfd
));
2400 control_flags
= (u32
*) tfd
;
2401 idx
= get_cmd_index(q
, q
->write_ptr
, 0);
2403 /* Set up driver data for this TFD */
2404 memset(&(txq
->txb
[q
->write_ptr
]), 0, sizeof(struct iwl4965_tx_info
));
2405 txq
->txb
[q
->write_ptr
].skb
[0] = skb
;
2406 memcpy(&(txq
->txb
[q
->write_ptr
].status
.control
),
2407 ctl
, sizeof(struct ieee80211_tx_control
));
2409 /* Set up first empty entry in queue's array of Tx/cmd buffers */
2410 out_cmd
= &txq
->cmd
[idx
];
2411 memset(&out_cmd
->hdr
, 0, sizeof(out_cmd
->hdr
));
2412 memset(&out_cmd
->cmd
.tx
, 0, sizeof(out_cmd
->cmd
.tx
));
2415 * Set up the Tx-command (not MAC!) header.
2416 * Store the chosen Tx queue and TFD index within the sequence field;
2417 * after Tx, uCode's Tx response will return this value so driver can
2418 * locate the frame within the tx queue and do post-tx processing.
2420 out_cmd
->hdr
.cmd
= REPLY_TX
;
2421 out_cmd
->hdr
.sequence
= cpu_to_le16((u16
)(QUEUE_TO_SEQ(txq_id
) |
2422 INDEX_TO_SEQ(q
->write_ptr
)));
2424 /* Copy MAC header from skb into command buffer */
2425 memcpy(out_cmd
->cmd
.tx
.hdr
, hdr
, hdr_len
);
2428 * Use the first empty entry in this queue's command buffer array
2429 * to contain the Tx command and MAC header concatenated together
2430 * (payload data will be in another buffer).
2431 * Size of this varies, due to varying MAC header length.
2432 * If end is not dword aligned, we'll have 2 extra bytes at the end
2433 * of the MAC header (device reads on dword boundaries).
2434 * We'll tell device about this padding later.
2436 len
= priv
->hw_setting
.tx_cmd_len
+
2437 sizeof(struct iwl_cmd_header
) + hdr_len
;
2440 len
= (len
+ 3) & ~3;
2447 /* Physical address of this Tx command's header (not MAC header!),
2448 * within command buffer array. */
2449 txcmd_phys
= txq
->dma_addr_cmd
+ sizeof(struct iwl_cmd
) * idx
+
2450 offsetof(struct iwl_cmd
, hdr
);
2452 /* Add buffer containing Tx command and MAC(!) header to TFD's
2454 iwl4965_hw_txq_attach_buf_to_tfd(priv
, tfd
, txcmd_phys
, len
);
2456 if (!(ctl
->flags
& IEEE80211_TXCTL_DO_NOT_ENCRYPT
))
2457 iwl4965_build_tx_cmd_hwcrypto(priv
, ctl
, out_cmd
, skb
, sta_id
);
2459 /* Set up TFD's 2nd entry to point directly to remainder of skb,
2460 * if any (802.11 null frames have no payload). */
2461 len
= skb
->len
- hdr_len
;
2463 phys_addr
= pci_map_single(priv
->pci_dev
, skb
->data
+ hdr_len
,
2464 len
, PCI_DMA_TODEVICE
);
2465 iwl4965_hw_txq_attach_buf_to_tfd(priv
, tfd
, phys_addr
, len
);
2468 /* Tell 4965 about any 2-byte padding after MAC header */
2470 out_cmd
->cmd
.tx
.tx_flags
|= TX_CMD_FLG_MH_PAD_MSK
;
2472 /* Total # bytes to be transmitted */
2473 len
= (u16
)skb
->len
;
2474 out_cmd
->cmd
.tx
.len
= cpu_to_le16(len
);
2476 /* TODO need this for burst mode later on */
2477 iwl4965_build_tx_cmd_basic(priv
, out_cmd
, ctl
, hdr
, unicast
, sta_id
);
2479 /* set is_hcca to 0; it probably will never be implemented */
2480 iwl4965_hw_build_tx_cmd_rate(priv
, out_cmd
, ctl
, hdr
, sta_id
, 0);
2482 iwl_update_tx_stats(priv
, fc
, len
);
2484 scratch_phys
= txcmd_phys
+ sizeof(struct iwl_cmd_header
) +
2485 offsetof(struct iwl4965_tx_cmd
, scratch
);
2486 out_cmd
->cmd
.tx
.dram_lsb_ptr
= cpu_to_le32(scratch_phys
);
2487 out_cmd
->cmd
.tx
.dram_msb_ptr
= iwl_get_dma_hi_address(scratch_phys
);
2489 if (!ieee80211_get_morefrag(hdr
)) {
2490 txq
->need_update
= 1;
2492 u8 tid
= (u8
)(le16_to_cpu(*qc
) & 0xf);
2493 priv
->stations
[sta_id
].tid
[tid
].seq_number
= seq_number
;
2497 txq
->need_update
= 0;
2500 iwl_print_hex_dump(IWL_DL_TX
, out_cmd
->cmd
.payload
,
2501 sizeof(out_cmd
->cmd
.tx
));
2503 iwl_print_hex_dump(IWL_DL_TX
, (u8
*)out_cmd
->cmd
.tx
.hdr
,
2504 ieee80211_get_hdrlen(fc
));
2506 /* Set up entry for this TFD in Tx byte-count array */
2507 iwl4965_tx_queue_update_wr_ptr(priv
, txq
, len
);
2509 /* Tell device the write index *just past* this latest filled TFD */
2510 q
->write_ptr
= iwl_queue_inc_wrap(q
->write_ptr
, q
->n_bd
);
2511 rc
= iwl4965_tx_queue_update_write_ptr(priv
, txq
);
2512 spin_unlock_irqrestore(&priv
->lock
, flags
);
2517 if ((iwl4965_queue_space(q
) < q
->high_mark
)
2518 && priv
->mac80211_registered
) {
2519 if (wait_write_ptr
) {
2520 spin_lock_irqsave(&priv
->lock
, flags
);
2521 txq
->need_update
= 1;
2522 iwl4965_tx_queue_update_write_ptr(priv
, txq
);
2523 spin_unlock_irqrestore(&priv
->lock
, flags
);
2526 ieee80211_stop_queue(priv
->hw
, ctl
->queue
);
2532 spin_unlock_irqrestore(&priv
->lock
, flags
);
2537 static void iwl4965_set_rate(struct iwl_priv
*priv
)
2539 const struct ieee80211_supported_band
*hw
= NULL
;
2540 struct ieee80211_rate
*rate
;
2543 hw
= iwl4965_get_hw_mode(priv
, priv
->band
);
2545 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
2549 priv
->active_rate
= 0;
2550 priv
->active_rate_basic
= 0;
2552 for (i
= 0; i
< hw
->n_bitrates
; i
++) {
2553 rate
= &(hw
->bitrates
[i
]);
2554 if (rate
->hw_value
< IWL_RATE_COUNT
)
2555 priv
->active_rate
|= (1 << rate
->hw_value
);
2558 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
2559 priv
->active_rate
, priv
->active_rate_basic
);
2562 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
2563 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
2566 if (priv
->active_rate_basic
& IWL_CCK_BASIC_RATES_MASK
)
2567 priv
->staging_rxon
.cck_basic_rates
=
2568 ((priv
->active_rate_basic
&
2569 IWL_CCK_RATES_MASK
) >> IWL_FIRST_CCK_RATE
) & 0xF;
2571 priv
->staging_rxon
.cck_basic_rates
=
2572 (IWL_CCK_BASIC_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
2574 if (priv
->active_rate_basic
& IWL_OFDM_BASIC_RATES_MASK
)
2575 priv
->staging_rxon
.ofdm_basic_rates
=
2576 ((priv
->active_rate_basic
&
2577 (IWL_OFDM_BASIC_RATES_MASK
| IWL_RATE_6M_MASK
)) >>
2578 IWL_FIRST_OFDM_RATE
) & 0xFF;
2580 priv
->staging_rxon
.ofdm_basic_rates
=
2581 (IWL_OFDM_BASIC_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
2584 void iwl4965_radio_kill_sw(struct iwl_priv
*priv
, int disable_radio
)
2586 unsigned long flags
;
2588 if (!!disable_radio
== test_bit(STATUS_RF_KILL_SW
, &priv
->status
))
2591 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
2592 disable_radio
? "OFF" : "ON");
2594 if (disable_radio
) {
2595 iwl4965_scan_cancel(priv
);
2596 /* FIXME: This is a workaround for AP */
2597 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
2598 spin_lock_irqsave(&priv
->lock
, flags
);
2599 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
2600 CSR_UCODE_SW_BIT_RFKILL
);
2601 spin_unlock_irqrestore(&priv
->lock
, flags
);
2602 /* call the host command only if no hw rf-kill set */
2603 if (!test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
2604 iwl4965_send_card_state(priv
,
2605 CARD_STATE_CMD_DISABLE
,
2607 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2609 /* make sure mac80211 stop sending Tx frame */
2610 if (priv
->mac80211_registered
)
2611 ieee80211_stop_queues(priv
->hw
);
2616 spin_lock_irqsave(&priv
->lock
, flags
);
2617 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2619 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2620 spin_unlock_irqrestore(&priv
->lock
, flags
);
2625 spin_lock_irqsave(&priv
->lock
, flags
);
2626 iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
2627 if (!iwl_grab_nic_access(priv
))
2628 iwl_release_nic_access(priv
);
2629 spin_unlock_irqrestore(&priv
->lock
, flags
);
2631 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) {
2632 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2633 "disabled by HW switch\n");
2637 queue_work(priv
->workqueue
, &priv
->restart
);
2641 void iwl4965_set_decrypted_flag(struct iwl_priv
*priv
, struct sk_buff
*skb
,
2642 u32 decrypt_res
, struct ieee80211_rx_status
*stats
)
2645 le16_to_cpu(((struct ieee80211_hdr
*)skb
->data
)->frame_control
);
2647 if (priv
->active_rxon
.filter_flags
& RXON_FILTER_DIS_DECRYPT_MSK
)
2650 if (!(fc
& IEEE80211_FCTL_PROTECTED
))
2653 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res
);
2654 switch (decrypt_res
& RX_RES_STATUS_SEC_TYPE_MSK
) {
2655 case RX_RES_STATUS_SEC_TYPE_TKIP
:
2656 /* The uCode has got a bad phase 1 Key, pushes the packet.
2657 * Decryption will be done in SW. */
2658 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2659 RX_RES_STATUS_BAD_KEY_TTAK
)
2662 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2663 RX_RES_STATUS_BAD_ICV_MIC
)
2664 stats
->flag
|= RX_FLAG_MMIC_ERROR
;
2665 case RX_RES_STATUS_SEC_TYPE_WEP
:
2666 case RX_RES_STATUS_SEC_TYPE_CCMP
:
2667 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2668 RX_RES_STATUS_DECRYPT_OK
) {
2669 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
2670 stats
->flag
|= RX_FLAG_DECRYPTED
;
2680 #define IWL_PACKET_RETRY_TIME HZ
2682 int iwl4965_is_duplicate_packet(struct iwl_priv
*priv
, struct ieee80211_hdr
*header
)
2684 u16 sc
= le16_to_cpu(header
->seq_ctrl
);
2685 u16 seq
= (sc
& IEEE80211_SCTL_SEQ
) >> 4;
2686 u16 frag
= sc
& IEEE80211_SCTL_FRAG
;
2687 u16
*last_seq
, *last_frag
;
2688 unsigned long *last_time
;
2690 switch (priv
->iw_mode
) {
2691 case IEEE80211_IF_TYPE_IBSS
:{
2692 struct list_head
*p
;
2693 struct iwl4965_ibss_seq
*entry
= NULL
;
2694 u8
*mac
= header
->addr2
;
2695 int index
= mac
[5] & (IWL_IBSS_MAC_HASH_SIZE
- 1);
2697 __list_for_each(p
, &priv
->ibss_mac_hash
[index
]) {
2698 entry
= list_entry(p
, struct iwl4965_ibss_seq
, list
);
2699 if (!compare_ether_addr(entry
->mac
, mac
))
2702 if (p
== &priv
->ibss_mac_hash
[index
]) {
2703 entry
= kzalloc(sizeof(*entry
), GFP_ATOMIC
);
2705 IWL_ERROR("Cannot malloc new mac entry\n");
2708 memcpy(entry
->mac
, mac
, ETH_ALEN
);
2709 entry
->seq_num
= seq
;
2710 entry
->frag_num
= frag
;
2711 entry
->packet_time
= jiffies
;
2712 list_add(&entry
->list
, &priv
->ibss_mac_hash
[index
]);
2715 last_seq
= &entry
->seq_num
;
2716 last_frag
= &entry
->frag_num
;
2717 last_time
= &entry
->packet_time
;
2720 case IEEE80211_IF_TYPE_STA
:
2721 last_seq
= &priv
->last_seq_num
;
2722 last_frag
= &priv
->last_frag_num
;
2723 last_time
= &priv
->last_packet_time
;
2728 if ((*last_seq
== seq
) &&
2729 time_after(*last_time
+ IWL_PACKET_RETRY_TIME
, jiffies
)) {
2730 if (*last_frag
== frag
)
2732 if (*last_frag
+ 1 != frag
)
2733 /* out-of-order fragment */
2739 *last_time
= jiffies
;
2746 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
2748 #include "iwl-spectrum.h"
2750 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
2751 #define BEACON_TIME_MASK_HIGH 0xFF000000
2752 #define TIME_UNIT 1024
2755 * extended beacon time format
2756 * time in usec will be changed into a 32-bit value in 8:24 format
2757 * the high 1 byte is the beacon counts
2758 * the lower 3 bytes is the time in usec within one beacon interval
2761 static u32
iwl4965_usecs_to_beacons(u32 usec
, u32 beacon_interval
)
2765 u32 interval
= beacon_interval
* 1024;
2767 if (!interval
|| !usec
)
2770 quot
= (usec
/ interval
) & (BEACON_TIME_MASK_HIGH
>> 24);
2771 rem
= (usec
% interval
) & BEACON_TIME_MASK_LOW
;
2773 return (quot
<< 24) + rem
;
2776 /* base is usually what we get from ucode with each received frame,
2777 * the same as HW timer counter counting down
2780 static __le32
iwl4965_add_beacon_time(u32 base
, u32 addon
, u32 beacon_interval
)
2782 u32 base_low
= base
& BEACON_TIME_MASK_LOW
;
2783 u32 addon_low
= addon
& BEACON_TIME_MASK_LOW
;
2784 u32 interval
= beacon_interval
* TIME_UNIT
;
2785 u32 res
= (base
& BEACON_TIME_MASK_HIGH
) +
2786 (addon
& BEACON_TIME_MASK_HIGH
);
2788 if (base_low
> addon_low
)
2789 res
+= base_low
- addon_low
;
2790 else if (base_low
< addon_low
) {
2791 res
+= interval
+ base_low
- addon_low
;
2796 return cpu_to_le32(res
);
2799 static int iwl4965_get_measurement(struct iwl_priv
*priv
,
2800 struct ieee80211_measurement_params
*params
,
2803 struct iwl4965_spectrum_cmd spectrum
;
2804 struct iwl4965_rx_packet
*res
;
2805 struct iwl_host_cmd cmd
= {
2806 .id
= REPLY_SPECTRUM_MEASUREMENT_CMD
,
2807 .data
= (void *)&spectrum
,
2808 .meta
.flags
= CMD_WANT_SKB
,
2810 u32 add_time
= le64_to_cpu(params
->start_time
);
2812 int spectrum_resp_status
;
2813 int duration
= le16_to_cpu(params
->duration
);
2815 if (iwl_is_associated(priv
))
2817 iwl4965_usecs_to_beacons(
2818 le64_to_cpu(params
->start_time
) - priv
->last_tsf
,
2819 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2821 memset(&spectrum
, 0, sizeof(spectrum
));
2823 spectrum
.channel_count
= cpu_to_le16(1);
2825 RXON_FLG_TSF2HOST_MSK
| RXON_FLG_ANT_A_MSK
| RXON_FLG_DIS_DIV_MSK
;
2826 spectrum
.filter_flags
= MEASUREMENT_FILTER_FLAG
;
2827 cmd
.len
= sizeof(spectrum
);
2828 spectrum
.len
= cpu_to_le16(cmd
.len
- sizeof(spectrum
.len
));
2830 if (iwl_is_associated(priv
))
2831 spectrum
.start_time
=
2832 iwl4965_add_beacon_time(priv
->last_beacon_time
,
2834 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2836 spectrum
.start_time
= 0;
2838 spectrum
.channels
[0].duration
= cpu_to_le32(duration
* TIME_UNIT
);
2839 spectrum
.channels
[0].channel
= params
->channel
;
2840 spectrum
.channels
[0].type
= type
;
2841 if (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
2842 spectrum
.flags
|= RXON_FLG_BAND_24G_MSK
|
2843 RXON_FLG_AUTO_DETECT_MSK
| RXON_FLG_TGG_PROTECT_MSK
;
2845 rc
= iwl_send_cmd_sync(priv
, &cmd
);
2849 res
= (struct iwl4965_rx_packet
*)cmd
.meta
.u
.skb
->data
;
2850 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
2851 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
2855 spectrum_resp_status
= le16_to_cpu(res
->u
.spectrum
.status
);
2856 switch (spectrum_resp_status
) {
2857 case 0: /* Command will be handled */
2858 if (res
->u
.spectrum
.id
!= 0xff) {
2860 ("Replaced existing measurement: %d\n",
2861 res
->u
.spectrum
.id
);
2862 priv
->measurement_status
&= ~MEASUREMENT_READY
;
2864 priv
->measurement_status
|= MEASUREMENT_ACTIVE
;
2868 case 1: /* Command will not be handled */
2873 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
2879 static void iwl4965_txstatus_to_ieee(struct iwl_priv
*priv
,
2880 struct iwl4965_tx_info
*tx_sta
)
2883 tx_sta
->status
.ack_signal
= 0;
2884 tx_sta
->status
.excessive_retries
= 0;
2885 tx_sta
->status
.queue_length
= 0;
2886 tx_sta
->status
.queue_number
= 0;
2889 ieee80211_tx_status_irqsafe(priv
->hw
,
2890 tx_sta
->skb
[0], &(tx_sta
->status
));
2892 ieee80211_tx_status(priv
->hw
,
2893 tx_sta
->skb
[0], &(tx_sta
->status
));
2895 tx_sta
->skb
[0] = NULL
;
2899 * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
2901 * When FW advances 'R' index, all entries between old and new 'R' index
2902 * need to be reclaimed. As result, some free space forms. If there is
2903 * enough free space (> low mark), wake the stack that feeds us.
2905 int iwl4965_tx_queue_reclaim(struct iwl_priv
*priv
, int txq_id
, int index
)
2907 struct iwl4965_tx_queue
*txq
= &priv
->txq
[txq_id
];
2908 struct iwl4965_queue
*q
= &txq
->q
;
2911 if ((index
>= q
->n_bd
) || (x2_queue_used(q
, index
) == 0)) {
2912 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
2913 "is out of range [0-%d] %d %d.\n", txq_id
,
2914 index
, q
->n_bd
, q
->write_ptr
, q
->read_ptr
);
2918 for (index
= iwl_queue_inc_wrap(index
, q
->n_bd
);
2919 q
->read_ptr
!= index
;
2920 q
->read_ptr
= iwl_queue_inc_wrap(q
->read_ptr
, q
->n_bd
)) {
2921 if (txq_id
!= IWL_CMD_QUEUE_NUM
) {
2922 iwl4965_txstatus_to_ieee(priv
,
2923 &(txq
->txb
[txq
->q
.read_ptr
]));
2924 iwl4965_hw_txq_free_tfd(priv
, txq
);
2925 } else if (nfreed
> 1) {
2926 IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index
,
2927 q
->write_ptr
, q
->read_ptr
);
2928 queue_work(priv
->workqueue
, &priv
->restart
);
2933 /* if (iwl4965_queue_space(q) > q->low_mark && (txq_id >= 0) &&
2934 (txq_id != IWL_CMD_QUEUE_NUM) &&
2935 priv->mac80211_registered)
2936 ieee80211_wake_queue(priv->hw, txq_id); */
2942 static int iwl4965_is_tx_success(u32 status
)
2944 status
&= TX_STATUS_MSK
;
2945 return (status
== TX_STATUS_SUCCESS
)
2946 || (status
== TX_STATUS_DIRECT_DONE
);
2949 /******************************************************************************
2951 * Generic RX handler implementations
2953 ******************************************************************************/
2954 #ifdef CONFIG_IWL4965_HT
2956 static inline int iwl4965_get_ra_sta_id(struct iwl_priv
*priv
,
2957 struct ieee80211_hdr
*hdr
)
2959 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
)
2962 u8
*da
= ieee80211_get_DA(hdr
);
2963 return iwl4965_hw_find_station(priv
, da
);
2967 static struct ieee80211_hdr
*iwl4965_tx_queue_get_hdr(
2968 struct iwl_priv
*priv
, int txq_id
, int idx
)
2970 if (priv
->txq
[txq_id
].txb
[idx
].skb
[0])
2971 return (struct ieee80211_hdr
*)priv
->txq
[txq_id
].
2972 txb
[idx
].skb
[0]->data
;
2976 static inline u32
iwl4965_get_scd_ssn(struct iwl4965_tx_resp
*tx_resp
)
2978 __le32
*scd_ssn
= (__le32
*)((u32
*)&tx_resp
->status
+
2979 tx_resp
->frame_count
);
2980 return le32_to_cpu(*scd_ssn
) & MAX_SN
;
2985 * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue
2987 static int iwl4965_tx_status_reply_tx(struct iwl_priv
*priv
,
2988 struct iwl4965_ht_agg
*agg
,
2989 struct iwl4965_tx_resp_agg
*tx_resp
,
2993 struct agg_tx_status
*frame_status
= &tx_resp
->status
;
2994 struct ieee80211_tx_status
*tx_status
= NULL
;
2995 struct ieee80211_hdr
*hdr
= NULL
;
3000 if (agg
->wait_for_ba
)
3001 IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
3003 agg
->frame_count
= tx_resp
->frame_count
;
3004 agg
->start_idx
= start_idx
;
3005 agg
->rate_n_flags
= le32_to_cpu(tx_resp
->rate_n_flags
);
3008 /* # frames attempted by Tx command */
3009 if (agg
->frame_count
== 1) {
3010 /* Only one frame was attempted; no block-ack will arrive */
3011 status
= le16_to_cpu(frame_status
[0].status
);
3012 seq
= le16_to_cpu(frame_status
[0].sequence
);
3013 idx
= SEQ_TO_INDEX(seq
);
3014 txq_id
= SEQ_TO_QUEUE(seq
);
3016 /* FIXME: code repetition */
3017 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
3018 agg
->frame_count
, agg
->start_idx
, idx
);
3020 tx_status
= &(priv
->txq
[txq_id
].txb
[idx
].status
);
3021 tx_status
->retry_count
= tx_resp
->failure_frame
;
3022 tx_status
->queue_number
= status
& 0xff;
3023 tx_status
->queue_length
= tx_resp
->failure_rts
;
3024 tx_status
->control
.flags
&= ~IEEE80211_TXCTL_AMPDU
;
3025 tx_status
->flags
= iwl4965_is_tx_success(status
)?
3026 IEEE80211_TX_STATUS_ACK
: 0;
3027 iwl4965_hwrate_to_tx_control(priv
,
3028 le32_to_cpu(tx_resp
->rate_n_flags
),
3029 &tx_status
->control
);
3030 /* FIXME: code repetition end */
3032 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
3033 status
& 0xff, tx_resp
->failure_frame
);
3034 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
3035 iwl4965_hw_get_rate_n_flags(tx_resp
->rate_n_flags
));
3037 agg
->wait_for_ba
= 0;
3039 /* Two or more frames were attempted; expect block-ack */
3041 int start
= agg
->start_idx
;
3043 /* Construct bit-map of pending frames within Tx window */
3044 for (i
= 0; i
< agg
->frame_count
; i
++) {
3046 status
= le16_to_cpu(frame_status
[i
].status
);
3047 seq
= le16_to_cpu(frame_status
[i
].sequence
);
3048 idx
= SEQ_TO_INDEX(seq
);
3049 txq_id
= SEQ_TO_QUEUE(seq
);
3051 if (status
& (AGG_TX_STATE_FEW_BYTES_MSK
|
3052 AGG_TX_STATE_ABORT_MSK
))
3055 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
3056 agg
->frame_count
, txq_id
, idx
);
3058 hdr
= iwl4965_tx_queue_get_hdr(priv
, txq_id
, idx
);
3060 sc
= le16_to_cpu(hdr
->seq_ctrl
);
3061 if (idx
!= (SEQ_TO_SN(sc
) & 0xff)) {
3062 IWL_ERROR("BUG_ON idx doesn't match seq control"
3063 " idx=%d, seq_idx=%d, seq=%d\n",
3069 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
3070 i
, idx
, SEQ_TO_SN(sc
));
3074 sh
= (start
- idx
) + 0xff;
3075 bitmap
= bitmap
<< sh
;
3078 } else if (sh
< -64)
3079 sh
= 0xff - (start
- idx
);
3083 bitmap
= bitmap
<< sh
;
3086 bitmap
|= (1 << sh
);
3087 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
3088 start
, (u32
)(bitmap
& 0xFFFFFFFF));
3091 agg
->bitmap
= bitmap
;
3092 agg
->start_idx
= start
;
3093 agg
->rate_n_flags
= le32_to_cpu(tx_resp
->rate_n_flags
);
3094 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
3095 agg
->frame_count
, agg
->start_idx
,
3096 (unsigned long long)agg
->bitmap
);
3099 agg
->wait_for_ba
= 1;
3106 * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
3108 static void iwl4965_rx_reply_tx(struct iwl_priv
*priv
,
3109 struct iwl4965_rx_mem_buffer
*rxb
)
3111 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3112 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
3113 int txq_id
= SEQ_TO_QUEUE(sequence
);
3114 int index
= SEQ_TO_INDEX(sequence
);
3115 struct iwl4965_tx_queue
*txq
= &priv
->txq
[txq_id
];
3116 struct ieee80211_tx_status
*tx_status
;
3117 struct iwl4965_tx_resp
*tx_resp
= (void *)&pkt
->u
.raw
[0];
3118 u32 status
= le32_to_cpu(tx_resp
->status
);
3119 #ifdef CONFIG_IWL4965_HT
3120 int tid
= MAX_TID_COUNT
, sta_id
= IWL_INVALID_STATION
;
3121 struct ieee80211_hdr
*hdr
;
3125 if ((index
>= txq
->q
.n_bd
) || (x2_queue_used(&txq
->q
, index
) == 0)) {
3126 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
3127 "is out of range [0-%d] %d %d\n", txq_id
,
3128 index
, txq
->q
.n_bd
, txq
->q
.write_ptr
,
3133 #ifdef CONFIG_IWL4965_HT
3134 hdr
= iwl4965_tx_queue_get_hdr(priv
, txq_id
, index
);
3135 qc
= ieee80211_get_qos_ctrl(hdr
);
3138 tid
= le16_to_cpu(*qc
) & 0xf;
3140 sta_id
= iwl4965_get_ra_sta_id(priv
, hdr
);
3141 if (txq
->sched_retry
&& unlikely(sta_id
== IWL_INVALID_STATION
)) {
3142 IWL_ERROR("Station not known\n");
3146 if (txq
->sched_retry
) {
3147 const u32 scd_ssn
= iwl4965_get_scd_ssn(tx_resp
);
3148 struct iwl4965_ht_agg
*agg
= NULL
;
3153 agg
= &priv
->stations
[sta_id
].tid
[tid
].agg
;
3155 iwl4965_tx_status_reply_tx(priv
, agg
,
3156 (struct iwl4965_tx_resp_agg
*)tx_resp
, index
);
3158 if ((tx_resp
->frame_count
== 1) &&
3159 !iwl4965_is_tx_success(status
)) {
3160 /* TODO: send BAR */
3163 if (txq
->q
.read_ptr
!= (scd_ssn
& 0xff)) {
3165 index
= iwl_queue_dec_wrap(scd_ssn
& 0xff, txq
->q
.n_bd
);
3166 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
3167 "%d index %d\n", scd_ssn
, index
);
3168 freed
= iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
3169 priv
->stations
[sta_id
].tid
[tid
].tfds_in_queue
-= freed
;
3171 if (iwl4965_queue_space(&txq
->q
) > txq
->q
.low_mark
&&
3172 txq_id
>= 0 && priv
->mac80211_registered
&&
3173 agg
->state
!= IWL_EMPTYING_HW_QUEUE_DELBA
)
3174 ieee80211_wake_queue(priv
->hw
, txq_id
);
3176 iwl4965_check_empty_hw_queue(priv
, sta_id
, tid
, txq_id
);
3179 #endif /* CONFIG_IWL4965_HT */
3180 tx_status
= &(txq
->txb
[txq
->q
.read_ptr
].status
);
3182 tx_status
->retry_count
= tx_resp
->failure_frame
;
3183 tx_status
->queue_number
= status
;
3184 tx_status
->queue_length
= tx_resp
->bt_kill_count
;
3185 tx_status
->queue_length
|= tx_resp
->failure_rts
;
3187 iwl4965_is_tx_success(status
) ? IEEE80211_TX_STATUS_ACK
: 0;
3188 iwl4965_hwrate_to_tx_control(priv
, le32_to_cpu(tx_resp
->rate_n_flags
),
3189 &tx_status
->control
);
3191 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x "
3192 "retries %d\n", txq_id
, iwl4965_get_tx_fail_reason(status
),
3193 status
, le32_to_cpu(tx_resp
->rate_n_flags
),
3194 tx_resp
->failure_frame
);
3196 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index
);
3198 int freed
= iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
3199 #ifdef CONFIG_IWL4965_HT
3200 if (tid
!= MAX_TID_COUNT
)
3201 priv
->stations
[sta_id
].tid
[tid
].tfds_in_queue
-= freed
;
3202 if (iwl4965_queue_space(&txq
->q
) > txq
->q
.low_mark
&&
3204 priv
->mac80211_registered
)
3205 ieee80211_wake_queue(priv
->hw
, txq_id
);
3206 if (tid
!= MAX_TID_COUNT
)
3207 iwl4965_check_empty_hw_queue(priv
, sta_id
, tid
, txq_id
);
3210 #ifdef CONFIG_IWL4965_HT
3212 #endif /* CONFIG_IWL4965_HT */
3214 if (iwl_check_bits(status
, TX_ABORT_REQUIRED_MSK
))
3215 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
3219 static void iwl4965_rx_reply_alive(struct iwl_priv
*priv
,
3220 struct iwl4965_rx_mem_buffer
*rxb
)
3222 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3223 struct iwl4965_alive_resp
*palive
;
3224 struct delayed_work
*pwork
;
3226 palive
= &pkt
->u
.alive_frame
;
3228 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
3230 palive
->is_valid
, palive
->ver_type
,
3231 palive
->ver_subtype
);
3233 if (palive
->ver_subtype
== INITIALIZE_SUBTYPE
) {
3234 IWL_DEBUG_INFO("Initialization Alive received.\n");
3235 memcpy(&priv
->card_alive_init
,
3236 &pkt
->u
.alive_frame
,
3237 sizeof(struct iwl4965_init_alive_resp
));
3238 pwork
= &priv
->init_alive_start
;
3240 IWL_DEBUG_INFO("Runtime Alive received.\n");
3241 memcpy(&priv
->card_alive
, &pkt
->u
.alive_frame
,
3242 sizeof(struct iwl4965_alive_resp
));
3243 pwork
= &priv
->alive_start
;
3246 /* We delay the ALIVE response by 5ms to
3247 * give the HW RF Kill time to activate... */
3248 if (palive
->is_valid
== UCODE_VALID_OK
)
3249 queue_delayed_work(priv
->workqueue
, pwork
,
3250 msecs_to_jiffies(5));
3252 IWL_WARNING("uCode did not respond OK.\n");
3255 static void iwl4965_rx_reply_add_sta(struct iwl_priv
*priv
,
3256 struct iwl4965_rx_mem_buffer
*rxb
)
3258 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3260 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt
->u
.status
);
3264 static void iwl4965_rx_reply_error(struct iwl_priv
*priv
,
3265 struct iwl4965_rx_mem_buffer
*rxb
)
3267 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3269 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
3270 "seq 0x%04X ser 0x%08X\n",
3271 le32_to_cpu(pkt
->u
.err_resp
.error_type
),
3272 get_cmd_string(pkt
->u
.err_resp
.cmd_id
),
3273 pkt
->u
.err_resp
.cmd_id
,
3274 le16_to_cpu(pkt
->u
.err_resp
.bad_cmd_seq_num
),
3275 le32_to_cpu(pkt
->u
.err_resp
.error_info
));
3278 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
3280 static void iwl4965_rx_csa(struct iwl_priv
*priv
, struct iwl4965_rx_mem_buffer
*rxb
)
3282 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3283 struct iwl4965_rxon_cmd
*rxon
= (void *)&priv
->active_rxon
;
3284 struct iwl4965_csa_notification
*csa
= &(pkt
->u
.csa_notif
);
3285 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
3286 le16_to_cpu(csa
->channel
), le32_to_cpu(csa
->status
));
3287 rxon
->channel
= csa
->channel
;
3288 priv
->staging_rxon
.channel
= csa
->channel
;
3291 static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv
*priv
,
3292 struct iwl4965_rx_mem_buffer
*rxb
)
3294 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
3295 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3296 struct iwl4965_spectrum_notification
*report
= &(pkt
->u
.spectrum_notif
);
3298 if (!report
->state
) {
3299 IWL_DEBUG(IWL_DL_11H
| IWL_DL_INFO
,
3300 "Spectrum Measure Notification: Start\n");
3304 memcpy(&priv
->measure_report
, report
, sizeof(*report
));
3305 priv
->measurement_status
|= MEASUREMENT_READY
;
3309 static void iwl4965_rx_pm_sleep_notif(struct iwl_priv
*priv
,
3310 struct iwl4965_rx_mem_buffer
*rxb
)
3312 #ifdef CONFIG_IWLWIFI_DEBUG
3313 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3314 struct iwl4965_sleep_notification
*sleep
= &(pkt
->u
.sleep_notif
);
3315 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
3316 sleep
->pm_sleep_mode
, sleep
->pm_wakeup_src
);
3320 static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv
*priv
,
3321 struct iwl4965_rx_mem_buffer
*rxb
)
3323 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3324 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
3325 "notification for %s:\n",
3326 le32_to_cpu(pkt
->len
), get_cmd_string(pkt
->hdr
.cmd
));
3327 iwl_print_hex_dump(IWL_DL_RADIO
, pkt
->u
.raw
, le32_to_cpu(pkt
->len
));
3330 static void iwl4965_bg_beacon_update(struct work_struct
*work
)
3332 struct iwl_priv
*priv
=
3333 container_of(work
, struct iwl_priv
, beacon_update
);
3334 struct sk_buff
*beacon
;
3336 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
3337 beacon
= ieee80211_beacon_get(priv
->hw
, priv
->vif
, NULL
);
3340 IWL_ERROR("update beacon failed\n");
3344 mutex_lock(&priv
->mutex
);
3345 /* new beacon skb is allocated every time; dispose previous.*/
3346 if (priv
->ibss_beacon
)
3347 dev_kfree_skb(priv
->ibss_beacon
);
3349 priv
->ibss_beacon
= beacon
;
3350 mutex_unlock(&priv
->mutex
);
3352 iwl4965_send_beacon_cmd(priv
);
3355 static void iwl4965_rx_beacon_notif(struct iwl_priv
*priv
,
3356 struct iwl4965_rx_mem_buffer
*rxb
)
3358 #ifdef CONFIG_IWLWIFI_DEBUG
3359 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3360 struct iwl4965_beacon_notif
*beacon
= &(pkt
->u
.beacon_status
);
3361 u8 rate
= iwl4965_hw_get_rate(beacon
->beacon_notify_hdr
.rate_n_flags
);
3363 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
3364 "tsf %d %d rate %d\n",
3365 le32_to_cpu(beacon
->beacon_notify_hdr
.status
) & TX_STATUS_MSK
,
3366 beacon
->beacon_notify_hdr
.failure_frame
,
3367 le32_to_cpu(beacon
->ibss_mgr_status
),
3368 le32_to_cpu(beacon
->high_tsf
),
3369 le32_to_cpu(beacon
->low_tsf
), rate
);
3372 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
3373 (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)))
3374 queue_work(priv
->workqueue
, &priv
->beacon_update
);
3377 /* Service response to REPLY_SCAN_CMD (0x80) */
3378 static void iwl4965_rx_reply_scan(struct iwl_priv
*priv
,
3379 struct iwl4965_rx_mem_buffer
*rxb
)
3381 #ifdef CONFIG_IWLWIFI_DEBUG
3382 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3383 struct iwl4965_scanreq_notification
*notif
=
3384 (struct iwl4965_scanreq_notification
*)pkt
->u
.raw
;
3386 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif
->status
);
3390 /* Service SCAN_START_NOTIFICATION (0x82) */
3391 static void iwl4965_rx_scan_start_notif(struct iwl_priv
*priv
,
3392 struct iwl4965_rx_mem_buffer
*rxb
)
3394 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3395 struct iwl4965_scanstart_notification
*notif
=
3396 (struct iwl4965_scanstart_notification
*)pkt
->u
.raw
;
3397 priv
->scan_start_tsf
= le32_to_cpu(notif
->tsf_low
);
3398 IWL_DEBUG_SCAN("Scan start: "
3400 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
3402 notif
->band
? "bg" : "a",
3404 notif
->tsf_low
, notif
->status
, notif
->beacon_timer
);
3407 /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
3408 static void iwl4965_rx_scan_results_notif(struct iwl_priv
*priv
,
3409 struct iwl4965_rx_mem_buffer
*rxb
)
3411 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3412 struct iwl4965_scanresults_notification
*notif
=
3413 (struct iwl4965_scanresults_notification
*)pkt
->u
.raw
;
3415 IWL_DEBUG_SCAN("Scan ch.res: "
3417 "(TSF: 0x%08X:%08X) - %d "
3418 "elapsed=%lu usec (%dms since last)\n",
3420 notif
->band
? "bg" : "a",
3421 le32_to_cpu(notif
->tsf_high
),
3422 le32_to_cpu(notif
->tsf_low
),
3423 le32_to_cpu(notif
->statistics
[0]),
3424 le32_to_cpu(notif
->tsf_low
) - priv
->scan_start_tsf
,
3425 jiffies_to_msecs(elapsed_jiffies
3426 (priv
->last_scan_jiffies
, jiffies
)));
3428 priv
->last_scan_jiffies
= jiffies
;
3429 priv
->next_scan_jiffies
= 0;
3432 /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
3433 static void iwl4965_rx_scan_complete_notif(struct iwl_priv
*priv
,
3434 struct iwl4965_rx_mem_buffer
*rxb
)
3436 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3437 struct iwl4965_scancomplete_notification
*scan_notif
= (void *)pkt
->u
.raw
;
3439 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
3440 scan_notif
->scanned_channels
,
3441 scan_notif
->tsf_low
,
3442 scan_notif
->tsf_high
, scan_notif
->status
);
3444 /* The HW is no longer scanning */
3445 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
3447 /* The scan completion notification came in, so kill that timer... */
3448 cancel_delayed_work(&priv
->scan_check
);
3450 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
3451 (priv
->scan_bands
== 2) ? "2.4" : "5.2",
3452 jiffies_to_msecs(elapsed_jiffies
3453 (priv
->scan_pass_start
, jiffies
)));
3455 /* Remove this scanned band from the list
3456 * of pending bands to scan */
3459 /* If a request to abort was given, or the scan did not succeed
3460 * then we reset the scan state machine and terminate,
3461 * re-queuing another scan if one has been requested */
3462 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
3463 IWL_DEBUG_INFO("Aborted scan completed.\n");
3464 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
3466 /* If there are more bands on this scan pass reschedule */
3467 if (priv
->scan_bands
> 0)
3471 priv
->last_scan_jiffies
= jiffies
;
3472 priv
->next_scan_jiffies
= 0;
3473 IWL_DEBUG_INFO("Setting scan to off\n");
3475 clear_bit(STATUS_SCANNING
, &priv
->status
);
3477 IWL_DEBUG_INFO("Scan took %dms\n",
3478 jiffies_to_msecs(elapsed_jiffies(priv
->scan_start
, jiffies
)));
3480 queue_work(priv
->workqueue
, &priv
->scan_completed
);
3485 priv
->scan_pass_start
= jiffies
;
3486 queue_work(priv
->workqueue
, &priv
->request_scan
);
3489 /* Handle notification from uCode that card's power state is changing
3490 * due to software, hardware, or critical temperature RFKILL */
3491 static void iwl4965_rx_card_state_notif(struct iwl_priv
*priv
,
3492 struct iwl4965_rx_mem_buffer
*rxb
)
3494 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3495 u32 flags
= le32_to_cpu(pkt
->u
.card_state_notif
.flags
);
3496 unsigned long status
= priv
->status
;
3498 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
3499 (flags
& HW_CARD_DISABLED
) ? "Kill" : "On",
3500 (flags
& SW_CARD_DISABLED
) ? "Kill" : "On");
3502 if (flags
& (SW_CARD_DISABLED
| HW_CARD_DISABLED
|
3503 RF_CARD_DISABLED
)) {
3505 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
3506 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
3508 if (!iwl_grab_nic_access(priv
)) {
3510 priv
, HBUS_TARG_MBX_C
,
3511 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED
);
3513 iwl_release_nic_access(priv
);
3516 if (!(flags
& RXON_CARD_DISABLED
)) {
3517 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
3518 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
3519 if (!iwl_grab_nic_access(priv
)) {
3521 priv
, HBUS_TARG_MBX_C
,
3522 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED
);
3524 iwl_release_nic_access(priv
);
3528 if (flags
& RF_CARD_DISABLED
) {
3529 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
3530 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT
);
3531 iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
3532 if (!iwl_grab_nic_access(priv
))
3533 iwl_release_nic_access(priv
);
3537 if (flags
& HW_CARD_DISABLED
)
3538 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
3540 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
3543 if (flags
& SW_CARD_DISABLED
)
3544 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
3546 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
3548 if (!(flags
& RXON_CARD_DISABLED
))
3549 iwl4965_scan_cancel(priv
);
3551 if ((test_bit(STATUS_RF_KILL_HW
, &status
) !=
3552 test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) ||
3553 (test_bit(STATUS_RF_KILL_SW
, &status
) !=
3554 test_bit(STATUS_RF_KILL_SW
, &priv
->status
)))
3555 queue_work(priv
->workqueue
, &priv
->rf_kill
);
3557 wake_up_interruptible(&priv
->wait_command_queue
);
3561 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
3563 * Setup the RX handlers for each of the reply types sent from the uCode
3566 * This function chains into the hardware specific files for them to setup
3567 * any hardware specific handlers as well.
3569 static void iwl4965_setup_rx_handlers(struct iwl_priv
*priv
)
3571 priv
->rx_handlers
[REPLY_ALIVE
] = iwl4965_rx_reply_alive
;
3572 priv
->rx_handlers
[REPLY_ADD_STA
] = iwl4965_rx_reply_add_sta
;
3573 priv
->rx_handlers
[REPLY_ERROR
] = iwl4965_rx_reply_error
;
3574 priv
->rx_handlers
[CHANNEL_SWITCH_NOTIFICATION
] = iwl4965_rx_csa
;
3575 priv
->rx_handlers
[SPECTRUM_MEASURE_NOTIFICATION
] =
3576 iwl4965_rx_spectrum_measure_notif
;
3577 priv
->rx_handlers
[PM_SLEEP_NOTIFICATION
] = iwl4965_rx_pm_sleep_notif
;
3578 priv
->rx_handlers
[PM_DEBUG_STATISTIC_NOTIFIC
] =
3579 iwl4965_rx_pm_debug_statistics_notif
;
3580 priv
->rx_handlers
[BEACON_NOTIFICATION
] = iwl4965_rx_beacon_notif
;
3583 * The same handler is used for both the REPLY to a discrete
3584 * statistics request from the host as well as for the periodic
3585 * statistics notifications (after received beacons) from the uCode.
3587 priv
->rx_handlers
[REPLY_STATISTICS_CMD
] = iwl4965_hw_rx_statistics
;
3588 priv
->rx_handlers
[STATISTICS_NOTIFICATION
] = iwl4965_hw_rx_statistics
;
3590 priv
->rx_handlers
[REPLY_SCAN_CMD
] = iwl4965_rx_reply_scan
;
3591 priv
->rx_handlers
[SCAN_START_NOTIFICATION
] = iwl4965_rx_scan_start_notif
;
3592 priv
->rx_handlers
[SCAN_RESULTS_NOTIFICATION
] =
3593 iwl4965_rx_scan_results_notif
;
3594 priv
->rx_handlers
[SCAN_COMPLETE_NOTIFICATION
] =
3595 iwl4965_rx_scan_complete_notif
;
3596 priv
->rx_handlers
[CARD_STATE_NOTIFICATION
] = iwl4965_rx_card_state_notif
;
3597 priv
->rx_handlers
[REPLY_TX
] = iwl4965_rx_reply_tx
;
3599 /* Set up hardware specific Rx handlers */
3600 iwl4965_hw_rx_handler_setup(priv
);
3604 * iwl4965_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
3605 * @rxb: Rx buffer to reclaim
3607 * If an Rx buffer has an async callback associated with it the callback
3608 * will be executed. The attached skb (if present) will only be freed
3609 * if the callback returns 1
3611 static void iwl4965_tx_cmd_complete(struct iwl_priv
*priv
,
3612 struct iwl4965_rx_mem_buffer
*rxb
)
3614 struct iwl4965_rx_packet
*pkt
= (struct iwl4965_rx_packet
*)rxb
->skb
->data
;
3615 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
3616 int txq_id
= SEQ_TO_QUEUE(sequence
);
3617 int index
= SEQ_TO_INDEX(sequence
);
3618 int huge
= sequence
& SEQ_HUGE_FRAME
;
3620 struct iwl_cmd
*cmd
;
3622 /* If a Tx command is being handled and it isn't in the actual
3623 * command queue then there a command routing bug has been introduced
3624 * in the queue management code. */
3625 if (txq_id
!= IWL_CMD_QUEUE_NUM
)
3626 IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
3627 txq_id
, pkt
->hdr
.cmd
);
3628 BUG_ON(txq_id
!= IWL_CMD_QUEUE_NUM
);
3630 cmd_index
= get_cmd_index(&priv
->txq
[IWL_CMD_QUEUE_NUM
].q
, index
, huge
);
3631 cmd
= &priv
->txq
[IWL_CMD_QUEUE_NUM
].cmd
[cmd_index
];
3633 /* Input error checking is done when commands are added to queue. */
3634 if (cmd
->meta
.flags
& CMD_WANT_SKB
) {
3635 cmd
->meta
.source
->u
.skb
= rxb
->skb
;
3637 } else if (cmd
->meta
.u
.callback
&&
3638 !cmd
->meta
.u
.callback(priv
, cmd
, rxb
->skb
))
3641 iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
3643 if (!(cmd
->meta
.flags
& CMD_ASYNC
)) {
3644 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
3645 wake_up_interruptible(&priv
->wait_command_queue
);
3649 /************************** RX-FUNCTIONS ****************************/
3651 * Rx theory of operation
3653 * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs),
3654 * each of which point to Receive Buffers to be filled by 4965. These get
3655 * used not only for Rx frames, but for any command response or notification
3656 * from the 4965. The driver and 4965 manage the Rx buffers by means
3657 * of indexes into the circular buffer.
3660 * The host/firmware share two index registers for managing the Rx buffers.
3662 * The READ index maps to the first position that the firmware may be writing
3663 * to -- the driver can read up to (but not including) this position and get
3665 * The READ index is managed by the firmware once the card is enabled.
3667 * The WRITE index maps to the last position the driver has read from -- the
3668 * position preceding WRITE is the last slot the firmware can place a packet.
3670 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
3673 * During initialization, the host sets up the READ queue position to the first
3674 * INDEX position, and WRITE to the last (READ - 1 wrapped)
3676 * When the firmware places a packet in a buffer, it will advance the READ index
3677 * and fire the RX interrupt. The driver can then query the READ index and
3678 * process as many packets as possible, moving the WRITE index forward as it
3679 * resets the Rx queue buffers with new memory.
3681 * The management in the driver is as follows:
3682 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
3683 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
3684 * to replenish the iwl->rxq->rx_free.
3685 * + In iwl4965_rx_replenish (scheduled) if 'processed' != 'read' then the
3686 * iwl->rxq is replenished and the READ INDEX is updated (updating the
3687 * 'processed' and 'read' driver indexes as well)
3688 * + A received packet is processed and handed to the kernel network stack,
3689 * detached from the iwl->rxq. The driver 'processed' index is updated.
3690 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
3691 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
3692 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
3693 * were enough free buffers and RX_STALLED is set it is cleared.
3698 * iwl4965_rx_queue_alloc() Allocates rx_free
3699 * iwl4965_rx_replenish() Replenishes rx_free list from rx_used, and calls
3700 * iwl4965_rx_queue_restock
3701 * iwl4965_rx_queue_restock() Moves available buffers from rx_free into Rx
3702 * queue, updates firmware pointers, and updates
3703 * the WRITE index. If insufficient rx_free buffers
3704 * are available, schedules iwl4965_rx_replenish
3706 * -- enable interrupts --
3707 * ISR - iwl4965_rx() Detach iwl4965_rx_mem_buffers from pool up to the
3708 * READ INDEX, detaching the SKB from the pool.
3709 * Moves the packet buffer from queue to rx_used.
3710 * Calls iwl4965_rx_queue_restock to refill any empty
3717 * iwl4965_rx_queue_space - Return number of free slots available in queue.
3719 static int iwl4965_rx_queue_space(const struct iwl4965_rx_queue
*q
)
3721 int s
= q
->read
- q
->write
;
3724 /* keep some buffer to not confuse full and empty queue */
3732 * iwl4965_rx_queue_update_write_ptr - Update the write pointer for the RX queue
3734 int iwl4965_rx_queue_update_write_ptr(struct iwl_priv
*priv
, struct iwl4965_rx_queue
*q
)
3738 unsigned long flags
;
3740 spin_lock_irqsave(&q
->lock
, flags
);
3742 if (q
->need_update
== 0)
3745 /* If power-saving is in use, make sure device is awake */
3746 if (test_bit(STATUS_POWER_PMI
, &priv
->status
)) {
3747 reg
= iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
3749 if (reg
& CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP
) {
3750 iwl_set_bit(priv
, CSR_GP_CNTRL
,
3751 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
3755 rc
= iwl_grab_nic_access(priv
);
3759 /* Device expects a multiple of 8 */
3760 iwl_write_direct32(priv
, FH_RSCSR_CHNL0_WPTR
,
3762 iwl_release_nic_access(priv
);
3764 /* Else device is assumed to be awake */
3766 /* Device expects a multiple of 8 */
3767 iwl_write32(priv
, FH_RSCSR_CHNL0_WPTR
, q
->write
& ~0x7);
3773 spin_unlock_irqrestore(&q
->lock
, flags
);
3778 * iwl4965_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
3780 static inline __le32
iwl4965_dma_addr2rbd_ptr(struct iwl_priv
*priv
,
3781 dma_addr_t dma_addr
)
3783 return cpu_to_le32((u32
)(dma_addr
>> 8));
3788 * iwl4965_rx_queue_restock - refill RX queue from pre-allocated pool
3790 * If there are slots in the RX queue that need to be restocked,
3791 * and we have free pre-allocated buffers, fill the ranks as much
3792 * as we can, pulling from rx_free.
3794 * This moves the 'write' index forward to catch up with 'processed', and
3795 * also updates the memory address in the firmware to reference the new
3798 static int iwl4965_rx_queue_restock(struct iwl_priv
*priv
)
3800 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
3801 struct list_head
*element
;
3802 struct iwl4965_rx_mem_buffer
*rxb
;
3803 unsigned long flags
;
3806 spin_lock_irqsave(&rxq
->lock
, flags
);
3807 write
= rxq
->write
& ~0x7;
3808 while ((iwl4965_rx_queue_space(rxq
) > 0) && (rxq
->free_count
)) {
3809 /* Get next free Rx buffer, remove from free list */
3810 element
= rxq
->rx_free
.next
;
3811 rxb
= list_entry(element
, struct iwl4965_rx_mem_buffer
, list
);
3814 /* Point to Rx buffer via next RBD in circular buffer */
3815 rxq
->bd
[rxq
->write
] = iwl4965_dma_addr2rbd_ptr(priv
, rxb
->dma_addr
);
3816 rxq
->queue
[rxq
->write
] = rxb
;
3817 rxq
->write
= (rxq
->write
+ 1) & RX_QUEUE_MASK
;
3820 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3821 /* If the pre-allocated buffer pool is dropping low, schedule to
3823 if (rxq
->free_count
<= RX_LOW_WATERMARK
)
3824 queue_work(priv
->workqueue
, &priv
->rx_replenish
);
3827 /* If we've added more space for the firmware to place data, tell it.
3828 * Increment device's write pointer in multiples of 8. */
3829 if ((write
!= (rxq
->write
& ~0x7))
3830 || (abs(rxq
->write
- rxq
->read
) > 7)) {
3831 spin_lock_irqsave(&rxq
->lock
, flags
);
3832 rxq
->need_update
= 1;
3833 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3834 rc
= iwl4965_rx_queue_update_write_ptr(priv
, rxq
);
3843 * iwl4965_rx_replenish - Move all used packet from rx_used to rx_free
3845 * When moving to rx_free an SKB is allocated for the slot.
3847 * Also restock the Rx queue via iwl4965_rx_queue_restock.
3848 * This is called as a scheduled work item (except for during initialization)
3850 static void iwl4965_rx_allocate(struct iwl_priv
*priv
)
3852 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
3853 struct list_head
*element
;
3854 struct iwl4965_rx_mem_buffer
*rxb
;
3855 unsigned long flags
;
3856 spin_lock_irqsave(&rxq
->lock
, flags
);
3857 while (!list_empty(&rxq
->rx_used
)) {
3858 element
= rxq
->rx_used
.next
;
3859 rxb
= list_entry(element
, struct iwl4965_rx_mem_buffer
, list
);
3861 /* Alloc a new receive buffer */
3863 alloc_skb(priv
->hw_setting
.rx_buf_size
,
3864 __GFP_NOWARN
| GFP_ATOMIC
);
3866 if (net_ratelimit())
3867 printk(KERN_CRIT DRV_NAME
3868 ": Can not allocate SKB buffers\n");
3869 /* We don't reschedule replenish work here -- we will
3870 * call the restock method and if it still needs
3871 * more buffers it will schedule replenish */
3874 priv
->alloc_rxb_skb
++;
3877 /* Get physical address of RB/SKB */
3879 pci_map_single(priv
->pci_dev
, rxb
->skb
->data
,
3880 priv
->hw_setting
.rx_buf_size
, PCI_DMA_FROMDEVICE
);
3881 list_add_tail(&rxb
->list
, &rxq
->rx_free
);
3884 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3888 * this should be called while priv->lock is locked
3890 static void __iwl4965_rx_replenish(void *data
)
3892 struct iwl_priv
*priv
= data
;
3894 iwl4965_rx_allocate(priv
);
3895 iwl4965_rx_queue_restock(priv
);
3899 void iwl4965_rx_replenish(void *data
)
3901 struct iwl_priv
*priv
= data
;
3902 unsigned long flags
;
3904 iwl4965_rx_allocate(priv
);
3906 spin_lock_irqsave(&priv
->lock
, flags
);
3907 iwl4965_rx_queue_restock(priv
);
3908 spin_unlock_irqrestore(&priv
->lock
, flags
);
3911 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
3912 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
3913 * This free routine walks the list of POOL entries and if SKB is set to
3914 * non NULL it is unmapped and freed
3916 static void iwl4965_rx_queue_free(struct iwl_priv
*priv
, struct iwl4965_rx_queue
*rxq
)
3919 for (i
= 0; i
< RX_QUEUE_SIZE
+ RX_FREE_BUFFERS
; i
++) {
3920 if (rxq
->pool
[i
].skb
!= NULL
) {
3921 pci_unmap_single(priv
->pci_dev
,
3922 rxq
->pool
[i
].dma_addr
,
3923 priv
->hw_setting
.rx_buf_size
,
3924 PCI_DMA_FROMDEVICE
);
3925 dev_kfree_skb(rxq
->pool
[i
].skb
);
3929 pci_free_consistent(priv
->pci_dev
, 4 * RX_QUEUE_SIZE
, rxq
->bd
,
3934 int iwl4965_rx_queue_alloc(struct iwl_priv
*priv
)
3936 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
3937 struct pci_dev
*dev
= priv
->pci_dev
;
3940 spin_lock_init(&rxq
->lock
);
3941 INIT_LIST_HEAD(&rxq
->rx_free
);
3942 INIT_LIST_HEAD(&rxq
->rx_used
);
3944 /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
3945 rxq
->bd
= pci_alloc_consistent(dev
, 4 * RX_QUEUE_SIZE
, &rxq
->dma_addr
);
3949 /* Fill the rx_used queue with _all_ of the Rx buffers */
3950 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++)
3951 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
3953 /* Set us so that we have processed and used all buffers, but have
3954 * not restocked the Rx queue with fresh buffers */
3955 rxq
->read
= rxq
->write
= 0;
3956 rxq
->free_count
= 0;
3957 rxq
->need_update
= 0;
3961 void iwl4965_rx_queue_reset(struct iwl_priv
*priv
, struct iwl4965_rx_queue
*rxq
)
3963 unsigned long flags
;
3965 spin_lock_irqsave(&rxq
->lock
, flags
);
3966 INIT_LIST_HEAD(&rxq
->rx_free
);
3967 INIT_LIST_HEAD(&rxq
->rx_used
);
3968 /* Fill the rx_used queue with _all_ of the Rx buffers */
3969 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++) {
3970 /* In the reset function, these buffers may have been allocated
3971 * to an SKB, so we need to unmap and free potential storage */
3972 if (rxq
->pool
[i
].skb
!= NULL
) {
3973 pci_unmap_single(priv
->pci_dev
,
3974 rxq
->pool
[i
].dma_addr
,
3975 priv
->hw_setting
.rx_buf_size
,
3976 PCI_DMA_FROMDEVICE
);
3977 priv
->alloc_rxb_skb
--;
3978 dev_kfree_skb(rxq
->pool
[i
].skb
);
3979 rxq
->pool
[i
].skb
= NULL
;
3981 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
3984 /* Set us so that we have processed and used all buffers, but have
3985 * not restocked the Rx queue with fresh buffers */
3986 rxq
->read
= rxq
->write
= 0;
3987 rxq
->free_count
= 0;
3988 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3991 /* Convert linear signal-to-noise ratio into dB */
3992 static u8 ratio2dB
[100] = {
3993 /* 0 1 2 3 4 5 6 7 8 9 */
3994 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
3995 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
3996 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
3997 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
3998 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
3999 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
4000 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
4001 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
4002 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
4003 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
4006 /* Calculates a relative dB value from a ratio of linear
4007 * (i.e. not dB) signal levels.
4008 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
4009 int iwl4965_calc_db_from_ratio(int sig_ratio
)
4011 /* 1000:1 or higher just report as 60 dB */
4012 if (sig_ratio
>= 1000)
4015 /* 100:1 or higher, divide by 10 and use table,
4016 * add 20 dB to make up for divide by 10 */
4017 if (sig_ratio
>= 100)
4018 return (20 + (int)ratio2dB
[sig_ratio
/10]);
4020 /* We shouldn't see this */
4024 /* Use table for ratios 1:1 - 99:1 */
4025 return (int)ratio2dB
[sig_ratio
];
4028 #define PERFECT_RSSI (-20) /* dBm */
4029 #define WORST_RSSI (-95) /* dBm */
4030 #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
4032 /* Calculate an indication of rx signal quality (a percentage, not dBm!).
4033 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
4034 * about formulas used below. */
4035 int iwl4965_calc_sig_qual(int rssi_dbm
, int noise_dbm
)
4038 int degradation
= PERFECT_RSSI
- rssi_dbm
;
4040 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
4041 * as indicator; formula is (signal dbm - noise dbm).
4042 * SNR at or above 40 is a great signal (100%).
4043 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
4044 * Weakest usable signal is usually 10 - 15 dB SNR. */
4046 if (rssi_dbm
- noise_dbm
>= 40)
4048 else if (rssi_dbm
< noise_dbm
)
4050 sig_qual
= ((rssi_dbm
- noise_dbm
) * 5) / 2;
4052 /* Else use just the signal level.
4053 * This formula is a least squares fit of data points collected and
4054 * compared with a reference system that had a percentage (%) display
4055 * for signal quality. */
4057 sig_qual
= (100 * (RSSI_RANGE
* RSSI_RANGE
) - degradation
*
4058 (15 * RSSI_RANGE
+ 62 * degradation
)) /
4059 (RSSI_RANGE
* RSSI_RANGE
);
4063 else if (sig_qual
< 1)
4070 * iwl4965_rx_handle - Main entry function for receiving responses from uCode
4072 * Uses the priv->rx_handlers callback function array to invoke
4073 * the appropriate handlers, including command responses,
4074 * frame-received notifications, and other notifications.
4076 static void iwl4965_rx_handle(struct iwl_priv
*priv
)
4078 struct iwl4965_rx_mem_buffer
*rxb
;
4079 struct iwl4965_rx_packet
*pkt
;
4080 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
4083 unsigned long flags
;
4087 /* uCode's read index (stored in shared DRAM) indicates the last Rx
4088 * buffer that the driver may process (last buffer filled by ucode). */
4089 r
= iwl4965_hw_get_rx_read(priv
);
4092 /* Rx interrupt, but nothing sent from uCode */
4094 IWL_DEBUG(IWL_DL_RX
| IWL_DL_ISR
, "r = %d, i = %d\n", r
, i
);
4096 if (iwl4965_rx_queue_space(rxq
) > (RX_QUEUE_SIZE
/ 2))
4100 rxb
= rxq
->queue
[i
];
4102 /* If an RXB doesn't have a Rx queue slot associated with it,
4103 * then a bug has been introduced in the queue refilling
4104 * routines -- catch it here */
4105 BUG_ON(rxb
== NULL
);
4107 rxq
->queue
[i
] = NULL
;
4109 pci_dma_sync_single_for_cpu(priv
->pci_dev
, rxb
->dma_addr
,
4110 priv
->hw_setting
.rx_buf_size
,
4111 PCI_DMA_FROMDEVICE
);
4112 pkt
= (struct iwl4965_rx_packet
*)rxb
->skb
->data
;
4114 /* Reclaim a command buffer only if this packet is a response
4115 * to a (driver-originated) command.
4116 * If the packet (e.g. Rx frame) originated from uCode,
4117 * there is no command buffer to reclaim.
4118 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
4119 * but apparently a few don't get set; catch them here. */
4120 reclaim
= !(pkt
->hdr
.sequence
& SEQ_RX_FRAME
) &&
4121 (pkt
->hdr
.cmd
!= REPLY_RX_PHY_CMD
) &&
4122 (pkt
->hdr
.cmd
!= REPLY_RX
) &&
4123 (pkt
->hdr
.cmd
!= REPLY_COMPRESSED_BA
) &&
4124 (pkt
->hdr
.cmd
!= STATISTICS_NOTIFICATION
) &&
4125 (pkt
->hdr
.cmd
!= REPLY_TX
);
4127 /* Based on type of command response or notification,
4128 * handle those that need handling via function in
4129 * rx_handlers table. See iwl4965_setup_rx_handlers() */
4130 if (priv
->rx_handlers
[pkt
->hdr
.cmd
]) {
4131 IWL_DEBUG(IWL_DL_HOST_COMMAND
| IWL_DL_RX
| IWL_DL_ISR
,
4132 "r = %d, i = %d, %s, 0x%02x\n", r
, i
,
4133 get_cmd_string(pkt
->hdr
.cmd
), pkt
->hdr
.cmd
);
4134 priv
->rx_handlers
[pkt
->hdr
.cmd
] (priv
, rxb
);
4136 /* No handling needed */
4137 IWL_DEBUG(IWL_DL_HOST_COMMAND
| IWL_DL_RX
| IWL_DL_ISR
,
4138 "r %d i %d No handler needed for %s, 0x%02x\n",
4139 r
, i
, get_cmd_string(pkt
->hdr
.cmd
),
4144 /* Invoke any callbacks, transfer the skb to caller, and
4145 * fire off the (possibly) blocking iwl_send_cmd()
4146 * as we reclaim the driver command queue */
4147 if (rxb
&& rxb
->skb
)
4148 iwl4965_tx_cmd_complete(priv
, rxb
);
4150 IWL_WARNING("Claim null rxb?\n");
4153 /* For now we just don't re-use anything. We can tweak this
4154 * later to try and re-use notification packets and SKBs that
4155 * fail to Rx correctly */
4156 if (rxb
->skb
!= NULL
) {
4157 priv
->alloc_rxb_skb
--;
4158 dev_kfree_skb_any(rxb
->skb
);
4162 pci_unmap_single(priv
->pci_dev
, rxb
->dma_addr
,
4163 priv
->hw_setting
.rx_buf_size
,
4164 PCI_DMA_FROMDEVICE
);
4165 spin_lock_irqsave(&rxq
->lock
, flags
);
4166 list_add_tail(&rxb
->list
, &priv
->rxq
.rx_used
);
4167 spin_unlock_irqrestore(&rxq
->lock
, flags
);
4168 i
= (i
+ 1) & RX_QUEUE_MASK
;
4169 /* If there are a lot of unused frames,
4170 * restock the Rx queue so ucode wont assert. */
4175 __iwl4965_rx_replenish(priv
);
4181 /* Backtrack one entry */
4183 iwl4965_rx_queue_restock(priv
);
4187 * iwl4965_tx_queue_update_write_ptr - Send new write index to hardware
4189 static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv
*priv
,
4190 struct iwl4965_tx_queue
*txq
)
4194 int txq_id
= txq
->q
.id
;
4196 if (txq
->need_update
== 0)
4199 /* if we're trying to save power */
4200 if (test_bit(STATUS_POWER_PMI
, &priv
->status
)) {
4201 /* wake up nic if it's powered down ...
4202 * uCode will wake up, and interrupt us again, so next
4203 * time we'll skip this part. */
4204 reg
= iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
4206 if (reg
& CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP
) {
4207 IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg
);
4208 iwl_set_bit(priv
, CSR_GP_CNTRL
,
4209 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
4213 /* restore this queue's parameters in nic hardware. */
4214 rc
= iwl_grab_nic_access(priv
);
4217 iwl_write_direct32(priv
, HBUS_TARG_WRPTR
,
4218 txq
->q
.write_ptr
| (txq_id
<< 8));
4219 iwl_release_nic_access(priv
);
4221 /* else not in power-save mode, uCode will never sleep when we're
4222 * trying to tx (during RFKILL, we're not trying to tx). */
4224 iwl_write32(priv
, HBUS_TARG_WRPTR
,
4225 txq
->q
.write_ptr
| (txq_id
<< 8));
4227 txq
->need_update
= 0;
4232 #ifdef CONFIG_IWLWIFI_DEBUG
4233 static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd
*rxon
)
4235 DECLARE_MAC_BUF(mac
);
4237 IWL_DEBUG_RADIO("RX CONFIG:\n");
4238 iwl_print_hex_dump(IWL_DL_RADIO
, (u8
*) rxon
, sizeof(*rxon
));
4239 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon
->channel
));
4240 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon
->flags
));
4241 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
4242 le32_to_cpu(rxon
->filter_flags
));
4243 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon
->dev_type
);
4244 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
4245 rxon
->ofdm_basic_rates
);
4246 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon
->cck_basic_rates
);
4247 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
4248 print_mac(mac
, rxon
->node_addr
));
4249 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
4250 print_mac(mac
, rxon
->bssid_addr
));
4251 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon
->assoc_id
));
4255 static void iwl4965_enable_interrupts(struct iwl_priv
*priv
)
4257 IWL_DEBUG_ISR("Enabling interrupts\n");
4258 set_bit(STATUS_INT_ENABLED
, &priv
->status
);
4259 iwl_write32(priv
, CSR_INT_MASK
, CSR_INI_SET_MASK
);
4262 /* call this function to flush any scheduled tasklet */
4263 static inline void iwl_synchronize_irq(struct iwl_priv
*priv
)
4265 /* wait to make sure we flush pedding tasklet*/
4266 synchronize_irq(priv
->pci_dev
->irq
);
4267 tasklet_kill(&priv
->irq_tasklet
);
4270 static inline void iwl4965_disable_interrupts(struct iwl_priv
*priv
)
4272 clear_bit(STATUS_INT_ENABLED
, &priv
->status
);
4274 /* disable interrupts from uCode/NIC to host */
4275 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
4277 /* acknowledge/clear/reset any interrupts still pending
4278 * from uCode or flow handler (Rx/Tx DMA) */
4279 iwl_write32(priv
, CSR_INT
, 0xffffffff);
4280 iwl_write32(priv
, CSR_FH_INT_STATUS
, 0xffffffff);
4281 IWL_DEBUG_ISR("Disabled interrupts\n");
4284 static const char *desc_lookup(int i
)
4292 return "BAD_CHECKSUM";
4294 return "NMI_INTERRUPT";
4298 return "FATAL_ERROR";
4304 #define ERROR_START_OFFSET (1 * sizeof(u32))
4305 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
4307 static void iwl4965_dump_nic_error_log(struct iwl_priv
*priv
)
4310 u32 desc
, time
, count
, base
, data1
;
4311 u32 blink1
, blink2
, ilink1
, ilink2
;
4314 base
= le32_to_cpu(priv
->card_alive
.error_event_table_ptr
);
4316 if (!priv
->cfg
->ops
->lib
->is_valid_rtc_data_addr(base
)) {
4317 IWL_ERROR("Not valid error log pointer 0x%08X\n", base
);
4321 rc
= iwl_grab_nic_access(priv
);
4323 IWL_WARNING("Can not read from adapter at this time.\n");
4327 count
= iwl_read_targ_mem(priv
, base
);
4329 if (ERROR_START_OFFSET
<= count
* ERROR_ELEM_SIZE
) {
4330 IWL_ERROR("Start IWL Error Log Dump:\n");
4331 IWL_ERROR("Status: 0x%08lX, count: %d\n", priv
->status
, count
);
4334 desc
= iwl_read_targ_mem(priv
, base
+ 1 * sizeof(u32
));
4335 blink1
= iwl_read_targ_mem(priv
, base
+ 3 * sizeof(u32
));
4336 blink2
= iwl_read_targ_mem(priv
, base
+ 4 * sizeof(u32
));
4337 ilink1
= iwl_read_targ_mem(priv
, base
+ 5 * sizeof(u32
));
4338 ilink2
= iwl_read_targ_mem(priv
, base
+ 6 * sizeof(u32
));
4339 data1
= iwl_read_targ_mem(priv
, base
+ 7 * sizeof(u32
));
4340 data2
= iwl_read_targ_mem(priv
, base
+ 8 * sizeof(u32
));
4341 line
= iwl_read_targ_mem(priv
, base
+ 9 * sizeof(u32
));
4342 time
= iwl_read_targ_mem(priv
, base
+ 11 * sizeof(u32
));
4344 IWL_ERROR("Desc Time "
4345 "data1 data2 line\n");
4346 IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n",
4347 desc_lookup(desc
), desc
, time
, data1
, data2
, line
);
4348 IWL_ERROR("blink1 blink2 ilink1 ilink2\n");
4349 IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1
, blink2
,
4352 iwl_release_nic_access(priv
);
4355 #define EVENT_START_OFFSET (4 * sizeof(u32))
4358 * iwl4965_print_event_log - Dump error event log to syslog
4360 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
4362 static void iwl4965_print_event_log(struct iwl_priv
*priv
, u32 start_idx
,
4363 u32 num_events
, u32 mode
)
4366 u32 base
; /* SRAM byte address of event log header */
4367 u32 event_size
; /* 2 u32s, or 3 u32s if timestamp recorded */
4368 u32 ptr
; /* SRAM byte address of log data */
4369 u32 ev
, time
, data
; /* event log data */
4371 if (num_events
== 0)
4374 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
4377 event_size
= 2 * sizeof(u32
);
4379 event_size
= 3 * sizeof(u32
);
4381 ptr
= base
+ EVENT_START_OFFSET
+ (start_idx
* event_size
);
4383 /* "time" is actually "data" for mode 0 (no timestamp).
4384 * place event id # at far right for easier visual parsing. */
4385 for (i
= 0; i
< num_events
; i
++) {
4386 ev
= iwl_read_targ_mem(priv
, ptr
);
4388 time
= iwl_read_targ_mem(priv
, ptr
);
4391 IWL_ERROR("0x%08x\t%04u\n", time
, ev
); /* data, ev */
4393 data
= iwl_read_targ_mem(priv
, ptr
);
4395 IWL_ERROR("%010u\t0x%08x\t%04u\n", time
, data
, ev
);
4400 static void iwl4965_dump_nic_event_log(struct iwl_priv
*priv
)
4403 u32 base
; /* SRAM byte address of event log header */
4404 u32 capacity
; /* event log capacity in # entries */
4405 u32 mode
; /* 0 - no timestamp, 1 - timestamp recorded */
4406 u32 num_wraps
; /* # times uCode wrapped to top of log */
4407 u32 next_entry
; /* index of next entry to be written by uCode */
4408 u32 size
; /* # entries that we'll print */
4410 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
4411 if (!priv
->cfg
->ops
->lib
->is_valid_rtc_data_addr(base
)) {
4412 IWL_ERROR("Invalid event log pointer 0x%08X\n", base
);
4416 rc
= iwl_grab_nic_access(priv
);
4418 IWL_WARNING("Can not read from adapter at this time.\n");
4422 /* event log header */
4423 capacity
= iwl_read_targ_mem(priv
, base
);
4424 mode
= iwl_read_targ_mem(priv
, base
+ (1 * sizeof(u32
)));
4425 num_wraps
= iwl_read_targ_mem(priv
, base
+ (2 * sizeof(u32
)));
4426 next_entry
= iwl_read_targ_mem(priv
, base
+ (3 * sizeof(u32
)));
4428 size
= num_wraps
? capacity
: next_entry
;
4430 /* bail out if nothing in log */
4432 IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
4433 iwl_release_nic_access(priv
);
4437 IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
4440 /* if uCode has wrapped back to top of log, start at the oldest entry,
4441 * i.e the next one that uCode would fill. */
4443 iwl4965_print_event_log(priv
, next_entry
,
4444 capacity
- next_entry
, mode
);
4446 /* (then/else) start at top of log */
4447 iwl4965_print_event_log(priv
, 0, next_entry
, mode
);
4449 iwl_release_nic_access(priv
);
4453 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
4455 static void iwl4965_irq_handle_error(struct iwl_priv
*priv
)
4457 /* Set the FW error flag -- cleared on iwl4965_down */
4458 set_bit(STATUS_FW_ERROR
, &priv
->status
);
4460 /* Cancel currently queued command. */
4461 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
4463 #ifdef CONFIG_IWLWIFI_DEBUG
4464 if (iwl_debug_level
& IWL_DL_FW_ERRORS
) {
4465 iwl4965_dump_nic_error_log(priv
);
4466 iwl4965_dump_nic_event_log(priv
);
4467 iwl4965_print_rx_config_cmd(&priv
->staging_rxon
);
4471 wake_up_interruptible(&priv
->wait_command_queue
);
4473 /* Keep the restart process from trying to send host
4474 * commands by clearing the INIT status bit */
4475 clear_bit(STATUS_READY
, &priv
->status
);
4477 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
4478 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_FW_ERRORS
,
4479 "Restarting adapter due to uCode error.\n");
4481 if (iwl_is_associated(priv
)) {
4482 memcpy(&priv
->recovery_rxon
, &priv
->active_rxon
,
4483 sizeof(priv
->recovery_rxon
));
4484 priv
->error_recovering
= 1;
4486 queue_work(priv
->workqueue
, &priv
->restart
);
4490 static void iwl4965_error_recovery(struct iwl_priv
*priv
)
4492 unsigned long flags
;
4494 memcpy(&priv
->staging_rxon
, &priv
->recovery_rxon
,
4495 sizeof(priv
->staging_rxon
));
4496 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
4497 iwl4965_commit_rxon(priv
);
4499 iwl4965_rxon_add_station(priv
, priv
->bssid
, 1);
4501 spin_lock_irqsave(&priv
->lock
, flags
);
4502 priv
->assoc_id
= le16_to_cpu(priv
->staging_rxon
.assoc_id
);
4503 priv
->error_recovering
= 0;
4504 spin_unlock_irqrestore(&priv
->lock
, flags
);
4507 static void iwl4965_irq_tasklet(struct iwl_priv
*priv
)
4509 u32 inta
, handled
= 0;
4511 unsigned long flags
;
4512 #ifdef CONFIG_IWLWIFI_DEBUG
4516 spin_lock_irqsave(&priv
->lock
, flags
);
4518 /* Ack/clear/reset pending uCode interrupts.
4519 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
4520 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
4521 inta
= iwl_read32(priv
, CSR_INT
);
4522 iwl_write32(priv
, CSR_INT
, inta
);
4524 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
4525 * Any new interrupts that happen after this, either while we're
4526 * in this tasklet, or later, will show up in next ISR/tasklet. */
4527 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
4528 iwl_write32(priv
, CSR_FH_INT_STATUS
, inta_fh
);
4530 #ifdef CONFIG_IWLWIFI_DEBUG
4531 if (iwl_debug_level
& IWL_DL_ISR
) {
4532 /* just for debug */
4533 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
4534 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4535 inta
, inta_mask
, inta_fh
);
4539 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
4540 * atomic, make sure that inta covers all the interrupts that
4541 * we've discovered, even if FH interrupt came in just after
4542 * reading CSR_INT. */
4543 if (inta_fh
& CSR49_FH_INT_RX_MASK
)
4544 inta
|= CSR_INT_BIT_FH_RX
;
4545 if (inta_fh
& CSR49_FH_INT_TX_MASK
)
4546 inta
|= CSR_INT_BIT_FH_TX
;
4548 /* Now service all interrupt bits discovered above. */
4549 if (inta
& CSR_INT_BIT_HW_ERR
) {
4550 IWL_ERROR("Microcode HW error detected. Restarting.\n");
4552 /* Tell the device to stop sending interrupts */
4553 iwl4965_disable_interrupts(priv
);
4555 iwl4965_irq_handle_error(priv
);
4557 handled
|= CSR_INT_BIT_HW_ERR
;
4559 spin_unlock_irqrestore(&priv
->lock
, flags
);
4564 #ifdef CONFIG_IWLWIFI_DEBUG
4565 if (iwl_debug_level
& (IWL_DL_ISR
)) {
4566 /* NIC fires this, but we don't use it, redundant with WAKEUP */
4567 if (inta
& CSR_INT_BIT_SCD
)
4568 IWL_DEBUG_ISR("Scheduler finished to transmit "
4569 "the frame/frames.\n");
4571 /* Alive notification via Rx interrupt will do the real work */
4572 if (inta
& CSR_INT_BIT_ALIVE
)
4573 IWL_DEBUG_ISR("Alive interrupt\n");
4576 /* Safely ignore these bits for debug checks below */
4577 inta
&= ~(CSR_INT_BIT_SCD
| CSR_INT_BIT_ALIVE
);
4579 /* HW RF KILL switch toggled */
4580 if (inta
& CSR_INT_BIT_RF_KILL
) {
4582 if (!(iwl_read32(priv
, CSR_GP_CNTRL
) &
4583 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
))
4586 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_RF_KILL
| IWL_DL_ISR
,
4587 "RF_KILL bit toggled to %s.\n",
4588 hw_rf_kill
? "disable radio":"enable radio");
4590 /* Queue restart only if RF_KILL switch was set to "kill"
4591 * when we loaded driver, and is now set to "enable".
4592 * After we're Alive, RF_KILL gets handled by
4593 * iwl4965_rx_card_state_notif() */
4594 if (!hw_rf_kill
&& !test_bit(STATUS_ALIVE
, &priv
->status
)) {
4595 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
4596 queue_work(priv
->workqueue
, &priv
->restart
);
4599 handled
|= CSR_INT_BIT_RF_KILL
;
4602 /* Chip got too hot and stopped itself */
4603 if (inta
& CSR_INT_BIT_CT_KILL
) {
4604 IWL_ERROR("Microcode CT kill error detected.\n");
4605 handled
|= CSR_INT_BIT_CT_KILL
;
4608 /* Error detected by uCode */
4609 if (inta
& CSR_INT_BIT_SW_ERR
) {
4610 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
4612 iwl4965_irq_handle_error(priv
);
4613 handled
|= CSR_INT_BIT_SW_ERR
;
4616 /* uCode wakes up after power-down sleep */
4617 if (inta
& CSR_INT_BIT_WAKEUP
) {
4618 IWL_DEBUG_ISR("Wakeup interrupt\n");
4619 iwl4965_rx_queue_update_write_ptr(priv
, &priv
->rxq
);
4620 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[0]);
4621 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[1]);
4622 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[2]);
4623 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[3]);
4624 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[4]);
4625 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[5]);
4627 handled
|= CSR_INT_BIT_WAKEUP
;
4630 /* All uCode command responses, including Tx command responses,
4631 * Rx "responses" (frame-received notification), and other
4632 * notifications from uCode come through here*/
4633 if (inta
& (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
)) {
4634 iwl4965_rx_handle(priv
);
4635 handled
|= (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
);
4638 if (inta
& CSR_INT_BIT_FH_TX
) {
4639 IWL_DEBUG_ISR("Tx interrupt\n");
4640 handled
|= CSR_INT_BIT_FH_TX
;
4643 if (inta
& ~handled
)
4644 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta
& ~handled
);
4646 if (inta
& ~CSR_INI_SET_MASK
) {
4647 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
4648 inta
& ~CSR_INI_SET_MASK
);
4649 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh
);
4652 /* Re-enable all interrupts */
4653 /* only Re-enable if diabled by irq */
4654 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
4655 iwl4965_enable_interrupts(priv
);
4657 #ifdef CONFIG_IWLWIFI_DEBUG
4658 if (iwl_debug_level
& (IWL_DL_ISR
)) {
4659 inta
= iwl_read32(priv
, CSR_INT
);
4660 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
4661 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
4662 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
4663 "flags 0x%08lx\n", inta
, inta_mask
, inta_fh
, flags
);
4666 spin_unlock_irqrestore(&priv
->lock
, flags
);
4669 static irqreturn_t
iwl4965_isr(int irq
, void *data
)
4671 struct iwl_priv
*priv
= data
;
4672 u32 inta
, inta_mask
;
4677 spin_lock(&priv
->lock
);
4679 /* Disable (but don't clear!) interrupts here to avoid
4680 * back-to-back ISRs and sporadic interrupts from our NIC.
4681 * If we have something to service, the tasklet will re-enable ints.
4682 * If we *don't* have something, we'll re-enable before leaving here. */
4683 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
); /* just for debug */
4684 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
4686 /* Discover which interrupts are active/pending */
4687 inta
= iwl_read32(priv
, CSR_INT
);
4688 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
4690 /* Ignore interrupt if there's nothing in NIC to service.
4691 * This may be due to IRQ shared with another device,
4692 * or due to sporadic interrupts thrown from our NIC. */
4693 if (!inta
&& !inta_fh
) {
4694 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
4698 if ((inta
== 0xFFFFFFFF) || ((inta
& 0xFFFFFFF0) == 0xa5a5a5a0)) {
4699 /* Hardware disappeared. It might have already raised
4701 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta
);
4705 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4706 inta
, inta_mask
, inta_fh
);
4708 inta
&= ~CSR_INT_BIT_SCD
;
4710 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
4711 if (likely(inta
|| inta_fh
))
4712 tasklet_schedule(&priv
->irq_tasklet
);
4715 spin_unlock(&priv
->lock
);
4719 /* re-enable interrupts here since we don't have anything to service. */
4720 /* only Re-enable if diabled by irq */
4721 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
4722 iwl4965_enable_interrupts(priv
);
4723 spin_unlock(&priv
->lock
);
4727 /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
4728 * sending probe req. This should be set long enough to hear probe responses
4729 * from more than one AP. */
4730 #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
4731 #define IWL_ACTIVE_DWELL_TIME_52 (10)
4733 /* For faster active scanning, scan will move to the next channel if fewer than
4734 * PLCP_QUIET_THRESH packets are heard on this channel within
4735 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
4736 * time if it's a quiet channel (nothing responded to our probe, and there's
4737 * no other traffic).
4738 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
4739 #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
4740 #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
4742 /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
4743 * Must be set longer than active dwell time.
4744 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
4745 #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
4746 #define IWL_PASSIVE_DWELL_TIME_52 (10)
4747 #define IWL_PASSIVE_DWELL_BASE (100)
4748 #define IWL_CHANNEL_TUNE_TIME 5
4750 static inline u16
iwl4965_get_active_dwell_time(struct iwl_priv
*priv
,
4751 enum ieee80211_band band
)
4753 if (band
== IEEE80211_BAND_5GHZ
)
4754 return IWL_ACTIVE_DWELL_TIME_52
;
4756 return IWL_ACTIVE_DWELL_TIME_24
;
4759 static u16
iwl4965_get_passive_dwell_time(struct iwl_priv
*priv
,
4760 enum ieee80211_band band
)
4762 u16 active
= iwl4965_get_active_dwell_time(priv
, band
);
4763 u16 passive
= (band
!= IEEE80211_BAND_5GHZ
) ?
4764 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_24
:
4765 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_52
;
4767 if (iwl_is_associated(priv
)) {
4768 /* If we're associated, we clamp the maximum passive
4769 * dwell time to be 98% of the beacon interval (minus
4770 * 2 * channel tune time) */
4771 passive
= priv
->beacon_int
;
4772 if ((passive
> IWL_PASSIVE_DWELL_BASE
) || !passive
)
4773 passive
= IWL_PASSIVE_DWELL_BASE
;
4774 passive
= (passive
* 98) / 100 - IWL_CHANNEL_TUNE_TIME
* 2;
4777 if (passive
<= active
)
4778 passive
= active
+ 1;
4783 static int iwl4965_get_channels_for_scan(struct iwl_priv
*priv
,
4784 enum ieee80211_band band
,
4785 u8 is_active
, u8 direct_mask
,
4786 struct iwl4965_scan_channel
*scan_ch
)
4788 const struct ieee80211_channel
*channels
= NULL
;
4789 const struct ieee80211_supported_band
*sband
;
4790 const struct iwl_channel_info
*ch_info
;
4791 u16 passive_dwell
= 0;
4792 u16 active_dwell
= 0;
4795 sband
= iwl4965_get_hw_mode(priv
, band
);
4799 channels
= sband
->channels
;
4801 active_dwell
= iwl4965_get_active_dwell_time(priv
, band
);
4802 passive_dwell
= iwl4965_get_passive_dwell_time(priv
, band
);
4804 for (i
= 0, added
= 0; i
< sband
->n_channels
; i
++) {
4805 if (channels
[i
].flags
& IEEE80211_CHAN_DISABLED
)
4808 if (ieee80211_frequency_to_channel(channels
[i
].center_freq
) ==
4809 le16_to_cpu(priv
->active_rxon
.channel
)) {
4810 if (iwl_is_associated(priv
)) {
4812 ("Skipping current channel %d\n",
4813 le16_to_cpu(priv
->active_rxon
.channel
));
4816 } else if (priv
->only_active_channel
)
4819 scan_ch
->channel
= ieee80211_frequency_to_channel(channels
[i
].center_freq
);
4821 ch_info
= iwl_get_channel_info(priv
, band
,
4823 if (!is_channel_valid(ch_info
)) {
4824 IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
4829 if (!is_active
|| is_channel_passive(ch_info
) ||
4830 (channels
[i
].flags
& IEEE80211_CHAN_PASSIVE_SCAN
))
4831 scan_ch
->type
= 0; /* passive */
4833 scan_ch
->type
= 1; /* active */
4835 if (scan_ch
->type
& 1)
4836 scan_ch
->type
|= (direct_mask
<< 1);
4838 if (is_channel_narrow(ch_info
))
4839 scan_ch
->type
|= (1 << 7);
4841 scan_ch
->active_dwell
= cpu_to_le16(active_dwell
);
4842 scan_ch
->passive_dwell
= cpu_to_le16(passive_dwell
);
4844 /* Set txpower levels to defaults */
4845 scan_ch
->tpc
.dsp_atten
= 110;
4846 /* scan_pwr_info->tpc.dsp_atten; */
4848 /*scan_pwr_info->tpc.tx_gain; */
4849 if (band
== IEEE80211_BAND_5GHZ
)
4850 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (3 << 3)) | 3;
4852 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (5 << 3));
4853 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
4855 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
4859 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
4861 (scan_ch
->type
& 1) ? "ACTIVE" : "PASSIVE",
4862 (scan_ch
->type
& 1) ?
4863 active_dwell
: passive_dwell
);
4869 IWL_DEBUG_SCAN("total channels to scan %d \n", added
);
4873 static void iwl4965_init_hw_rates(struct iwl_priv
*priv
,
4874 struct ieee80211_rate
*rates
)
4878 for (i
= 0; i
< IWL_RATE_COUNT
; i
++) {
4879 rates
[i
].bitrate
= iwl4965_rates
[i
].ieee
* 5;
4880 rates
[i
].hw_value
= i
; /* Rate scaling will work on indexes */
4881 rates
[i
].hw_value_short
= i
;
4883 if ((i
> IWL_LAST_OFDM_RATE
) || (i
< IWL_FIRST_OFDM_RATE
)) {
4885 * If CCK != 1M then set short preamble rate flag.
4888 (iwl4965_rates
[i
].plcp
== IWL_RATE_1M_PLCP
) ?
4889 0 : IEEE80211_RATE_SHORT_PREAMBLE
;
4895 * iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom
4897 int iwl4965_init_geos(struct iwl_priv
*priv
)
4899 struct iwl_channel_info
*ch
;
4900 struct ieee80211_supported_band
*sband
;
4901 struct ieee80211_channel
*channels
;
4902 struct ieee80211_channel
*geo_ch
;
4903 struct ieee80211_rate
*rates
;
4906 if (priv
->bands
[IEEE80211_BAND_2GHZ
].n_bitrates
||
4907 priv
->bands
[IEEE80211_BAND_5GHZ
].n_bitrates
) {
4908 IWL_DEBUG_INFO("Geography modes already initialized.\n");
4909 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
4913 channels
= kzalloc(sizeof(struct ieee80211_channel
) *
4914 priv
->channel_count
, GFP_KERNEL
);
4918 rates
= kzalloc((sizeof(struct ieee80211_rate
) * (IWL_RATE_COUNT
+ 1)),
4925 /* 5.2GHz channels start after the 2.4GHz channels */
4926 sband
= &priv
->bands
[IEEE80211_BAND_5GHZ
];
4927 sband
->channels
= &channels
[ARRAY_SIZE(iwl_eeprom_band_1
)];
4929 sband
->bitrates
= &rates
[IWL_FIRST_OFDM_RATE
];
4930 sband
->n_bitrates
= IWL_RATE_COUNT
- IWL_FIRST_OFDM_RATE
;
4932 iwl4965_init_ht_hw_capab(priv
, &sband
->ht_info
, IEEE80211_BAND_5GHZ
);
4934 sband
= &priv
->bands
[IEEE80211_BAND_2GHZ
];
4935 sband
->channels
= channels
;
4937 sband
->bitrates
= rates
;
4938 sband
->n_bitrates
= IWL_RATE_COUNT
;
4940 iwl4965_init_ht_hw_capab(priv
, &sband
->ht_info
, IEEE80211_BAND_2GHZ
);
4942 priv
->ieee_channels
= channels
;
4943 priv
->ieee_rates
= rates
;
4945 iwl4965_init_hw_rates(priv
, rates
);
4947 for (i
= 0; i
< priv
->channel_count
; i
++) {
4948 ch
= &priv
->channel_info
[i
];
4950 /* FIXME: might be removed if scan is OK */
4951 if (!is_channel_valid(ch
))
4954 if (is_channel_a_band(ch
))
4955 sband
= &priv
->bands
[IEEE80211_BAND_5GHZ
];
4957 sband
= &priv
->bands
[IEEE80211_BAND_2GHZ
];
4959 geo_ch
= &sband
->channels
[sband
->n_channels
++];
4961 geo_ch
->center_freq
= ieee80211_channel_to_frequency(ch
->channel
);
4962 geo_ch
->max_power
= ch
->max_power_avg
;
4963 geo_ch
->max_antenna_gain
= 0xff;
4964 geo_ch
->hw_value
= ch
->channel
;
4966 if (is_channel_valid(ch
)) {
4967 if (!(ch
->flags
& EEPROM_CHANNEL_IBSS
))
4968 geo_ch
->flags
|= IEEE80211_CHAN_NO_IBSS
;
4970 if (!(ch
->flags
& EEPROM_CHANNEL_ACTIVE
))
4971 geo_ch
->flags
|= IEEE80211_CHAN_PASSIVE_SCAN
;
4973 if (ch
->flags
& EEPROM_CHANNEL_RADAR
)
4974 geo_ch
->flags
|= IEEE80211_CHAN_RADAR
;
4976 if (ch
->max_power_avg
> priv
->max_channel_txpower_limit
)
4977 priv
->max_channel_txpower_limit
=
4980 geo_ch
->flags
|= IEEE80211_CHAN_DISABLED
;
4983 /* Save flags for reg domain usage */
4984 geo_ch
->orig_flags
= geo_ch
->flags
;
4986 IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n",
4987 ch
->channel
, geo_ch
->center_freq
,
4988 is_channel_a_band(ch
) ? "5.2" : "2.4",
4989 geo_ch
->flags
& IEEE80211_CHAN_DISABLED
?
4990 "restricted" : "valid",
4994 if ((priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
== 0) &&
4995 priv
->cfg
->sku
& IWL_SKU_A
) {
4996 printk(KERN_INFO DRV_NAME
4997 ": Incorrectly detected BG card as ABG. Please send "
4998 "your PCI ID 0x%04X:0x%04X to maintainer.\n",
4999 priv
->pci_dev
->device
, priv
->pci_dev
->subsystem_device
);
5000 priv
->cfg
->sku
&= ~IWL_SKU_A
;
5003 printk(KERN_INFO DRV_NAME
5004 ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
5005 priv
->bands
[IEEE80211_BAND_2GHZ
].n_channels
,
5006 priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
);
5008 if (priv
->bands
[IEEE80211_BAND_2GHZ
].n_channels
)
5009 priv
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
5010 &priv
->bands
[IEEE80211_BAND_2GHZ
];
5011 if (priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
)
5012 priv
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
5013 &priv
->bands
[IEEE80211_BAND_5GHZ
];
5015 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
5021 * iwl4965_free_geos - undo allocations in iwl4965_init_geos
5023 void iwl4965_free_geos(struct iwl_priv
*priv
)
5025 kfree(priv
->ieee_channels
);
5026 kfree(priv
->ieee_rates
);
5027 clear_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
5030 /******************************************************************************
5032 * uCode download functions
5034 ******************************************************************************/
5036 static void iwl4965_dealloc_ucode_pci(struct iwl_priv
*priv
)
5038 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
5039 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
5040 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
5041 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
5042 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
5043 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
5047 * iwl4965_verify_inst_full - verify runtime uCode image in card vs. host,
5048 * looking at all data.
5050 static int iwl4965_verify_inst_full(struct iwl_priv
*priv
, __le32
*image
,
5058 IWL_DEBUG_INFO("ucode inst image size is %u\n", len
);
5060 rc
= iwl_grab_nic_access(priv
);
5064 iwl_write_direct32(priv
, HBUS_TARG_MEM_RADDR
, RTC_INST_LOWER_BOUND
);
5067 for (; len
> 0; len
-= sizeof(u32
), image
++) {
5068 /* read data comes through single port, auto-incr addr */
5069 /* NOTE: Use the debugless read so we don't flood kernel log
5070 * if IWL_DL_IO is set */
5071 val
= _iwl_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
5072 if (val
!= le32_to_cpu(*image
)) {
5073 IWL_ERROR("uCode INST section is invalid at "
5074 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5075 save_len
- len
, val
, le32_to_cpu(*image
));
5083 iwl_release_nic_access(priv
);
5087 ("ucode image in INSTRUCTION memory is good\n");
5094 * iwl4965_verify_inst_sparse - verify runtime uCode image in card vs. host,
5095 * using sample data 100 bytes apart. If these sample points are good,
5096 * it's a pretty good bet that everything between them is good, too.
5098 static int iwl4965_verify_inst_sparse(struct iwl_priv
*priv
, __le32
*image
, u32 len
)
5105 IWL_DEBUG_INFO("ucode inst image size is %u\n", len
);
5107 rc
= iwl_grab_nic_access(priv
);
5111 for (i
= 0; i
< len
; i
+= 100, image
+= 100/sizeof(u32
)) {
5112 /* read data comes through single port, auto-incr addr */
5113 /* NOTE: Use the debugless read so we don't flood kernel log
5114 * if IWL_DL_IO is set */
5115 iwl_write_direct32(priv
, HBUS_TARG_MEM_RADDR
,
5116 i
+ RTC_INST_LOWER_BOUND
);
5117 val
= _iwl_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
5118 if (val
!= le32_to_cpu(*image
)) {
5119 #if 0 /* Enable this if you want to see details */
5120 IWL_ERROR("uCode INST section is invalid at "
5121 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5131 iwl_release_nic_access(priv
);
5138 * iwl4965_verify_ucode - determine which instruction image is in SRAM,
5139 * and verify its contents
5141 static int iwl4965_verify_ucode(struct iwl_priv
*priv
)
5148 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
5149 len
= priv
->ucode_boot
.len
;
5150 rc
= iwl4965_verify_inst_sparse(priv
, image
, len
);
5152 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
5156 /* Try initialize */
5157 image
= (__le32
*)priv
->ucode_init
.v_addr
;
5158 len
= priv
->ucode_init
.len
;
5159 rc
= iwl4965_verify_inst_sparse(priv
, image
, len
);
5161 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
5165 /* Try runtime/protocol */
5166 image
= (__le32
*)priv
->ucode_code
.v_addr
;
5167 len
= priv
->ucode_code
.len
;
5168 rc
= iwl4965_verify_inst_sparse(priv
, image
, len
);
5170 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
5174 IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
5176 /* Since nothing seems to match, show first several data entries in
5177 * instruction SRAM, so maybe visual inspection will give a clue.
5178 * Selection of bootstrap image (vs. other images) is arbitrary. */
5179 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
5180 len
= priv
->ucode_boot
.len
;
5181 rc
= iwl4965_verify_inst_full(priv
, image
, len
);
5186 static void iwl4965_nic_start(struct iwl_priv
*priv
)
5188 /* Remove all resets to allow NIC to operate */
5189 iwl_write32(priv
, CSR_RESET
, 0);
5194 * iwl4965_read_ucode - Read uCode images from disk file.
5196 * Copy into buffers for card to fetch via bus-mastering
5198 static int iwl4965_read_ucode(struct iwl_priv
*priv
)
5200 struct iwl4965_ucode
*ucode
;
5202 const struct firmware
*ucode_raw
;
5203 const char *name
= priv
->cfg
->fw_name
;
5206 u32 ver
, inst_size
, data_size
, init_size
, init_data_size
, boot_size
;
5208 /* Ask kernel firmware_class module to get the boot firmware off disk.
5209 * request_firmware() is synchronous, file is in memory on return. */
5210 ret
= request_firmware(&ucode_raw
, name
, &priv
->pci_dev
->dev
);
5212 IWL_ERROR("%s firmware file req failed: Reason %d\n",
5217 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
5218 name
, ucode_raw
->size
);
5220 /* Make sure that we got at least our header! */
5221 if (ucode_raw
->size
< sizeof(*ucode
)) {
5222 IWL_ERROR("File size way too small!\n");
5227 /* Data from ucode file: header followed by uCode images */
5228 ucode
= (void *)ucode_raw
->data
;
5230 ver
= le32_to_cpu(ucode
->ver
);
5231 inst_size
= le32_to_cpu(ucode
->inst_size
);
5232 data_size
= le32_to_cpu(ucode
->data_size
);
5233 init_size
= le32_to_cpu(ucode
->init_size
);
5234 init_data_size
= le32_to_cpu(ucode
->init_data_size
);
5235 boot_size
= le32_to_cpu(ucode
->boot_size
);
5237 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver
);
5238 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
5240 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
5242 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
5244 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
5246 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
5249 /* Verify size of file vs. image size info in file's header */
5250 if (ucode_raw
->size
< sizeof(*ucode
) +
5251 inst_size
+ data_size
+ init_size
+
5252 init_data_size
+ boot_size
) {
5254 IWL_DEBUG_INFO("uCode file size %d too small\n",
5255 (int)ucode_raw
->size
);
5260 /* Verify that uCode images will fit in card's SRAM */
5261 if (inst_size
> IWL_MAX_INST_SIZE
) {
5262 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
5268 if (data_size
> IWL_MAX_DATA_SIZE
) {
5269 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
5274 if (init_size
> IWL_MAX_INST_SIZE
) {
5276 ("uCode init instr len %d too large to fit in\n",
5281 if (init_data_size
> IWL_MAX_DATA_SIZE
) {
5283 ("uCode init data len %d too large to fit in\n",
5288 if (boot_size
> IWL_MAX_BSM_SIZE
) {
5290 ("uCode boot instr len %d too large to fit in\n",
5296 /* Allocate ucode buffers for card's bus-master loading ... */
5298 /* Runtime instructions and 2 copies of data:
5299 * 1) unmodified from disk
5300 * 2) backup cache for save/restore during power-downs */
5301 priv
->ucode_code
.len
= inst_size
;
5302 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
5304 priv
->ucode_data
.len
= data_size
;
5305 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
5307 priv
->ucode_data_backup
.len
= data_size
;
5308 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
5310 /* Initialization instructions and data */
5311 if (init_size
&& init_data_size
) {
5312 priv
->ucode_init
.len
= init_size
;
5313 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
5315 priv
->ucode_init_data
.len
= init_data_size
;
5316 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
5318 if (!priv
->ucode_init
.v_addr
|| !priv
->ucode_init_data
.v_addr
)
5322 /* Bootstrap (instructions only, no data) */
5324 priv
->ucode_boot
.len
= boot_size
;
5325 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
5327 if (!priv
->ucode_boot
.v_addr
)
5331 /* Copy images into buffers for card's bus-master reads ... */
5333 /* Runtime instructions (first block of data in file) */
5334 src
= &ucode
->data
[0];
5335 len
= priv
->ucode_code
.len
;
5336 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len
);
5337 memcpy(priv
->ucode_code
.v_addr
, src
, len
);
5338 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
5339 priv
->ucode_code
.v_addr
, (u32
)priv
->ucode_code
.p_addr
);
5341 /* Runtime data (2nd block)
5342 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
5343 src
= &ucode
->data
[inst_size
];
5344 len
= priv
->ucode_data
.len
;
5345 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len
);
5346 memcpy(priv
->ucode_data
.v_addr
, src
, len
);
5347 memcpy(priv
->ucode_data_backup
.v_addr
, src
, len
);
5349 /* Initialization instructions (3rd block) */
5351 src
= &ucode
->data
[inst_size
+ data_size
];
5352 len
= priv
->ucode_init
.len
;
5353 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
5355 memcpy(priv
->ucode_init
.v_addr
, src
, len
);
5358 /* Initialization data (4th block) */
5359 if (init_data_size
) {
5360 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
];
5361 len
= priv
->ucode_init_data
.len
;
5362 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
5364 memcpy(priv
->ucode_init_data
.v_addr
, src
, len
);
5367 /* Bootstrap instructions (5th block) */
5368 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
+ init_data_size
];
5369 len
= priv
->ucode_boot
.len
;
5370 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len
);
5371 memcpy(priv
->ucode_boot
.v_addr
, src
, len
);
5373 /* We have our copies now, allow OS release its copies */
5374 release_firmware(ucode_raw
);
5378 IWL_ERROR("failed to allocate pci memory\n");
5380 iwl4965_dealloc_ucode_pci(priv
);
5383 release_firmware(ucode_raw
);
5391 * iwl4965_set_ucode_ptrs - Set uCode address location
5393 * Tell initialization uCode where to find runtime uCode.
5395 * BSM registers initially contain pointers to initialization uCode.
5396 * We need to replace them to load runtime uCode inst and data,
5397 * and to save runtime data when powering down.
5399 static int iwl4965_set_ucode_ptrs(struct iwl_priv
*priv
)
5404 unsigned long flags
;
5406 /* bits 35:4 for 4965 */
5407 pinst
= priv
->ucode_code
.p_addr
>> 4;
5408 pdata
= priv
->ucode_data_backup
.p_addr
>> 4;
5410 spin_lock_irqsave(&priv
->lock
, flags
);
5411 rc
= iwl_grab_nic_access(priv
);
5413 spin_unlock_irqrestore(&priv
->lock
, flags
);
5417 /* Tell bootstrap uCode where to find image to load */
5418 iwl_write_prph(priv
, BSM_DRAM_INST_PTR_REG
, pinst
);
5419 iwl_write_prph(priv
, BSM_DRAM_DATA_PTR_REG
, pdata
);
5420 iwl_write_prph(priv
, BSM_DRAM_DATA_BYTECOUNT_REG
,
5421 priv
->ucode_data
.len
);
5423 /* Inst bytecount must be last to set up, bit 31 signals uCode
5424 * that all new ptr/size info is in place */
5425 iwl_write_prph(priv
, BSM_DRAM_INST_BYTECOUNT_REG
,
5426 priv
->ucode_code
.len
| BSM_DRAM_INST_LOAD
);
5428 iwl_release_nic_access(priv
);
5430 spin_unlock_irqrestore(&priv
->lock
, flags
);
5432 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
5438 * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received
5440 * Called after REPLY_ALIVE notification received from "initialize" uCode.
5442 * The 4965 "initialize" ALIVE reply contains calibration data for:
5443 * Voltage, temperature, and MIMO tx gain correction, now stored in priv
5444 * (3945 does not contain this data).
5446 * Tell "initialize" uCode to go ahead and load the runtime uCode.
5448 static void iwl4965_init_alive_start(struct iwl_priv
*priv
)
5450 /* Check alive response for "valid" sign from uCode */
5451 if (priv
->card_alive_init
.is_valid
!= UCODE_VALID_OK
) {
5452 /* We had an error bringing up the hardware, so take it
5453 * all the way back down so we can try again */
5454 IWL_DEBUG_INFO("Initialize Alive failed.\n");
5458 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
5459 * This is a paranoid check, because we would not have gotten the
5460 * "initialize" alive if code weren't properly loaded. */
5461 if (iwl4965_verify_ucode(priv
)) {
5462 /* Runtime instruction load was bad;
5463 * take it all the way back down so we can try again */
5464 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
5468 /* Calculate temperature */
5469 priv
->temperature
= iwl4965_get_temperature(priv
);
5471 /* Send pointers to protocol/runtime uCode image ... init code will
5472 * load and launch runtime uCode, which will send us another "Alive"
5474 IWL_DEBUG_INFO("Initialization Alive received.\n");
5475 if (iwl4965_set_ucode_ptrs(priv
)) {
5476 /* Runtime instruction load won't happen;
5477 * take it all the way back down so we can try again */
5478 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
5484 queue_work(priv
->workqueue
, &priv
->restart
);
5489 * iwl4965_alive_start - called after REPLY_ALIVE notification received
5490 * from protocol/runtime uCode (initialization uCode's
5491 * Alive gets handled by iwl4965_init_alive_start()).
5493 static void iwl4965_alive_start(struct iwl_priv
*priv
)
5497 IWL_DEBUG_INFO("Runtime Alive received.\n");
5499 if (priv
->card_alive
.is_valid
!= UCODE_VALID_OK
) {
5500 /* We had an error bringing up the hardware, so take it
5501 * all the way back down so we can try again */
5502 IWL_DEBUG_INFO("Alive failed.\n");
5506 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
5507 * This is a paranoid check, because we would not have gotten the
5508 * "runtime" alive if code weren't properly loaded. */
5509 if (iwl4965_verify_ucode(priv
)) {
5510 /* Runtime instruction load was bad;
5511 * take it all the way back down so we can try again */
5512 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
5516 iwlcore_clear_stations_table(priv
);
5518 ret
= priv
->cfg
->ops
->lib
->alive_notify(priv
);
5520 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
5525 /* After the ALIVE response, we can send host commands to 4965 uCode */
5526 set_bit(STATUS_ALIVE
, &priv
->status
);
5528 /* Clear out the uCode error bit if it is set */
5529 clear_bit(STATUS_FW_ERROR
, &priv
->status
);
5531 if (iwl_is_rfkill(priv
))
5534 ieee80211_start_queues(priv
->hw
);
5536 priv
->active_rate
= priv
->rates_mask
;
5537 priv
->active_rate_basic
= priv
->rates_mask
& IWL_BASIC_RATES_MASK
;
5539 iwl4965_send_power_mode(priv
, IWL_POWER_LEVEL(priv
->power_mode
));
5541 if (iwl_is_associated(priv
)) {
5542 struct iwl4965_rxon_cmd
*active_rxon
=
5543 (struct iwl4965_rxon_cmd
*)(&priv
->active_rxon
);
5545 memcpy(&priv
->staging_rxon
, &priv
->active_rxon
,
5546 sizeof(priv
->staging_rxon
));
5547 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
5549 /* Initialize our rx_config data */
5550 iwl4965_connection_init_rx_config(priv
);
5551 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
5554 /* Configure Bluetooth device coexistence support */
5555 iwl4965_send_bt_config(priv
);
5557 /* Configure the adapter for unassociated operation */
5558 iwl4965_commit_rxon(priv
);
5560 /* At this point, the NIC is initialized and operational */
5561 priv
->notif_missed_beacons
= 0;
5563 iwl4965_rf_kill_ct_config(priv
);
5565 iwl_leds_register(priv
);
5567 IWL_DEBUG_INFO("ALIVE processing complete.\n");
5568 set_bit(STATUS_READY
, &priv
->status
);
5569 wake_up_interruptible(&priv
->wait_command_queue
);
5571 if (priv
->error_recovering
)
5572 iwl4965_error_recovery(priv
);
5574 iwlcore_low_level_notify(priv
, IWLCORE_START_EVT
);
5575 ieee80211_notify_mac(priv
->hw
, IEEE80211_NOTIFY_RE_ASSOC
);
5579 queue_work(priv
->workqueue
, &priv
->restart
);
5582 static void iwl4965_cancel_deferred_work(struct iwl_priv
*priv
);
5584 static void __iwl4965_down(struct iwl_priv
*priv
)
5586 unsigned long flags
;
5587 int exit_pending
= test_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5588 struct ieee80211_conf
*conf
= NULL
;
5590 IWL_DEBUG_INFO(DRV_NAME
" is going down\n");
5592 conf
= ieee80211_get_hw_conf(priv
->hw
);
5595 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5597 iwl_leds_unregister(priv
);
5599 iwlcore_low_level_notify(priv
, IWLCORE_STOP_EVT
);
5601 iwlcore_clear_stations_table(priv
);
5603 /* Unblock any waiting calls */
5604 wake_up_interruptible_all(&priv
->wait_command_queue
);
5606 /* Wipe out the EXIT_PENDING status bit if we are not actually
5607 * exiting the module */
5609 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5611 /* stop and reset the on-board processor */
5612 iwl_write32(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_NEVO_RESET
);
5614 /* tell the device to stop sending interrupts */
5615 spin_lock_irqsave(&priv
->lock
, flags
);
5616 iwl4965_disable_interrupts(priv
);
5617 spin_unlock_irqrestore(&priv
->lock
, flags
);
5618 iwl_synchronize_irq(priv
);
5620 if (priv
->mac80211_registered
)
5621 ieee80211_stop_queues(priv
->hw
);
5623 /* If we have not previously called iwl4965_init() then
5624 * clear all bits but the RF Kill and SUSPEND bits and return */
5625 if (!iwl_is_init(priv
)) {
5626 priv
->status
= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
5628 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
5630 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
5631 STATUS_GEO_CONFIGURED
|
5632 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
5637 /* ...otherwise clear out all the status bits but the RF Kill and
5638 * SUSPEND bits and continue taking the NIC down. */
5639 priv
->status
&= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
5641 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
5643 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
5644 STATUS_GEO_CONFIGURED
|
5645 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
5647 test_bit(STATUS_FW_ERROR
, &priv
->status
) <<
5650 spin_lock_irqsave(&priv
->lock
, flags
);
5651 iwl_clear_bit(priv
, CSR_GP_CNTRL
,
5652 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
5653 spin_unlock_irqrestore(&priv
->lock
, flags
);
5655 iwl4965_hw_txq_ctx_stop(priv
);
5656 iwl4965_hw_rxq_stop(priv
);
5658 spin_lock_irqsave(&priv
->lock
, flags
);
5659 if (!iwl_grab_nic_access(priv
)) {
5660 iwl_write_prph(priv
, APMG_CLK_DIS_REG
,
5661 APMG_CLK_VAL_DMA_CLK_RQT
);
5662 iwl_release_nic_access(priv
);
5664 spin_unlock_irqrestore(&priv
->lock
, flags
);
5668 iwl4965_hw_nic_stop_master(priv
);
5669 iwl_set_bit(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_SW_RESET
);
5670 iwl4965_hw_nic_reset(priv
);
5673 memset(&priv
->card_alive
, 0, sizeof(struct iwl4965_alive_resp
));
5675 if (priv
->ibss_beacon
)
5676 dev_kfree_skb(priv
->ibss_beacon
);
5677 priv
->ibss_beacon
= NULL
;
5679 /* clear out any free frames */
5680 iwl4965_clear_free_frames(priv
);
5683 static void iwl4965_down(struct iwl_priv
*priv
)
5685 mutex_lock(&priv
->mutex
);
5686 __iwl4965_down(priv
);
5687 mutex_unlock(&priv
->mutex
);
5689 iwl4965_cancel_deferred_work(priv
);
5692 #define MAX_HW_RESTARTS 5
5694 static int __iwl4965_up(struct iwl_priv
*priv
)
5699 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
5700 IWL_WARNING("Exit pending; will not bring the NIC up\n");
5704 if (test_bit(STATUS_RF_KILL_SW
, &priv
->status
)) {
5705 IWL_WARNING("Radio disabled by SW RF kill (module "
5707 iwl_rfkill_set_hw_state(priv
);
5711 if (!priv
->ucode_data_backup
.v_addr
|| !priv
->ucode_data
.v_addr
) {
5712 IWL_ERROR("ucode not available for device bringup\n");
5716 /* If platform's RF_KILL switch is NOT set to KILL */
5717 if (iwl_read32(priv
, CSR_GP_CNTRL
) &
5718 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
)
5719 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
5721 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
5722 if (!test_bit(STATUS_IN_SUSPEND
, &priv
->status
)) {
5723 iwl_rfkill_set_hw_state(priv
);
5724 IWL_WARNING("Radio disabled by HW RF Kill switch\n");
5729 iwl_rfkill_set_hw_state(priv
);
5730 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
5732 ret
= priv
->cfg
->ops
->lib
->hw_nic_init(priv
);
5734 IWL_ERROR("Unable to init nic\n");
5738 /* make sure rfkill handshake bits are cleared */
5739 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
5740 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
5741 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
5743 /* clear (again), then enable host interrupts */
5744 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
5745 iwl4965_enable_interrupts(priv
);
5747 /* really make sure rfkill handshake bits are cleared */
5748 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
5749 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
5751 /* Copy original ucode data image from disk into backup cache.
5752 * This will be used to initialize the on-board processor's
5753 * data SRAM for a clean start when the runtime program first loads. */
5754 memcpy(priv
->ucode_data_backup
.v_addr
, priv
->ucode_data
.v_addr
,
5755 priv
->ucode_data
.len
);
5757 /* We return success when we resume from suspend and rf_kill is on. */
5758 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
5761 for (i
= 0; i
< MAX_HW_RESTARTS
; i
++) {
5763 iwlcore_clear_stations_table(priv
);
5765 /* load bootstrap state machine,
5766 * load bootstrap program into processor's memory,
5767 * prepare to load the "initialize" uCode */
5768 ret
= priv
->cfg
->ops
->lib
->load_ucode(priv
);
5771 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret
);
5775 /* start card; "initialize" will load runtime ucode */
5776 iwl4965_nic_start(priv
);
5778 IWL_DEBUG_INFO(DRV_NAME
" is coming up\n");
5783 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5784 __iwl4965_down(priv
);
5786 /* tried to restart and config the device for as long as our
5787 * patience could withstand */
5788 IWL_ERROR("Unable to initialize device after %d attempts.\n", i
);
5793 /*****************************************************************************
5795 * Workqueue callbacks
5797 *****************************************************************************/
5799 static void iwl4965_bg_init_alive_start(struct work_struct
*data
)
5801 struct iwl_priv
*priv
=
5802 container_of(data
, struct iwl_priv
, init_alive_start
.work
);
5804 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5807 mutex_lock(&priv
->mutex
);
5808 iwl4965_init_alive_start(priv
);
5809 mutex_unlock(&priv
->mutex
);
5812 static void iwl4965_bg_alive_start(struct work_struct
*data
)
5814 struct iwl_priv
*priv
=
5815 container_of(data
, struct iwl_priv
, alive_start
.work
);
5817 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5820 mutex_lock(&priv
->mutex
);
5821 iwl4965_alive_start(priv
);
5822 mutex_unlock(&priv
->mutex
);
5825 static void iwl4965_bg_rf_kill(struct work_struct
*work
)
5827 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
, rf_kill
);
5829 wake_up_interruptible(&priv
->wait_command_queue
);
5831 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5834 mutex_lock(&priv
->mutex
);
5836 if (!iwl_is_rfkill(priv
)) {
5837 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_RF_KILL
,
5838 "HW and/or SW RF Kill no longer active, restarting "
5840 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5841 queue_work(priv
->workqueue
, &priv
->restart
);
5843 /* make sure mac80211 stop sending Tx frame */
5844 if (priv
->mac80211_registered
)
5845 ieee80211_stop_queues(priv
->hw
);
5847 if (!test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
5848 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
5849 "disabled by SW switch\n");
5851 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
5852 "Kill switch must be turned off for "
5853 "wireless networking to work.\n");
5855 iwl_rfkill_set_hw_state(priv
);
5857 mutex_unlock(&priv
->mutex
);
5860 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
5862 static void iwl4965_bg_scan_check(struct work_struct
*data
)
5864 struct iwl_priv
*priv
=
5865 container_of(data
, struct iwl_priv
, scan_check
.work
);
5867 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5870 mutex_lock(&priv
->mutex
);
5871 if (test_bit(STATUS_SCANNING
, &priv
->status
) ||
5872 test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
5873 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_SCAN
,
5874 "Scan completion watchdog resetting adapter (%dms)\n",
5875 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG
));
5877 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5878 iwl4965_send_scan_abort(priv
);
5880 mutex_unlock(&priv
->mutex
);
5883 static void iwl4965_bg_request_scan(struct work_struct
*data
)
5885 struct iwl_priv
*priv
=
5886 container_of(data
, struct iwl_priv
, request_scan
);
5887 struct iwl_host_cmd cmd
= {
5888 .id
= REPLY_SCAN_CMD
,
5889 .len
= sizeof(struct iwl4965_scan_cmd
),
5890 .meta
.flags
= CMD_SIZE_HUGE
,
5892 struct iwl4965_scan_cmd
*scan
;
5893 struct ieee80211_conf
*conf
= NULL
;
5895 enum ieee80211_band band
;
5899 conf
= ieee80211_get_hw_conf(priv
->hw
);
5901 mutex_lock(&priv
->mutex
);
5903 if (!iwl_is_ready(priv
)) {
5904 IWL_WARNING("request scan called when driver not ready.\n");
5908 /* Make sure the scan wasn't cancelled before this queued work
5909 * was given the chance to run... */
5910 if (!test_bit(STATUS_SCANNING
, &priv
->status
))
5913 /* This should never be called or scheduled if there is currently
5914 * a scan active in the hardware. */
5915 if (test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
5916 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
5917 "Ignoring second request.\n");
5922 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
5923 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
5927 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
5928 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
5932 if (iwl_is_rfkill(priv
)) {
5933 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
5937 if (!test_bit(STATUS_READY
, &priv
->status
)) {
5938 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
5942 if (!priv
->scan_bands
) {
5943 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
5948 priv
->scan
= kmalloc(sizeof(struct iwl4965_scan_cmd
) +
5949 IWL_MAX_SCAN_SIZE
, GFP_KERNEL
);
5956 memset(scan
, 0, sizeof(struct iwl4965_scan_cmd
) + IWL_MAX_SCAN_SIZE
);
5958 scan
->quiet_plcp_th
= IWL_PLCP_QUIET_THRESH
;
5959 scan
->quiet_time
= IWL_ACTIVE_QUIET_TIME
;
5961 if (iwl_is_associated(priv
)) {
5964 u32 suspend_time
= 100;
5965 u32 scan_suspend_time
= 100;
5966 unsigned long flags
;
5968 IWL_DEBUG_INFO("Scanning while associated...\n");
5970 spin_lock_irqsave(&priv
->lock
, flags
);
5971 interval
= priv
->beacon_int
;
5972 spin_unlock_irqrestore(&priv
->lock
, flags
);
5974 scan
->suspend_time
= 0;
5975 scan
->max_out_time
= cpu_to_le32(200 * 1024);
5977 interval
= suspend_time
;
5979 extra
= (suspend_time
/ interval
) << 22;
5980 scan_suspend_time
= (extra
|
5981 ((suspend_time
% interval
) * 1024));
5982 scan
->suspend_time
= cpu_to_le32(scan_suspend_time
);
5983 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
5984 scan_suspend_time
, interval
);
5987 /* We should add the ability for user to lock to PASSIVE ONLY */
5988 if (priv
->one_direct_scan
) {
5990 ("Kicking off one direct scan for '%s'\n",
5991 iwl4965_escape_essid(priv
->direct_ssid
,
5992 priv
->direct_ssid_len
));
5993 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
5994 scan
->direct_scan
[0].len
= priv
->direct_ssid_len
;
5995 memcpy(scan
->direct_scan
[0].ssid
,
5996 priv
->direct_ssid
, priv
->direct_ssid_len
);
5998 } else if (!iwl_is_associated(priv
) && priv
->essid_len
) {
5999 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
6000 scan
->direct_scan
[0].len
= priv
->essid_len
;
6001 memcpy(scan
->direct_scan
[0].ssid
, priv
->essid
, priv
->essid_len
);
6007 scan
->tx_cmd
.tx_flags
= TX_CMD_FLG_SEQ_CTL_MSK
;
6008 scan
->tx_cmd
.sta_id
= priv
->hw_setting
.bcast_sta_id
;
6009 scan
->tx_cmd
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
6012 switch (priv
->scan_bands
) {
6014 scan
->flags
= RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
;
6015 scan
->tx_cmd
.rate_n_flags
=
6016 iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP
,
6017 RATE_MCS_ANT_B_MSK
|RATE_MCS_CCK_MSK
);
6019 scan
->good_CRC_th
= 0;
6020 band
= IEEE80211_BAND_2GHZ
;
6024 scan
->tx_cmd
.rate_n_flags
=
6025 iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP
,
6026 RATE_MCS_ANT_B_MSK
);
6027 scan
->good_CRC_th
= IWL_GOOD_CRC_TH
;
6028 band
= IEEE80211_BAND_5GHZ
;
6032 IWL_WARNING("Invalid scan band count\n");
6036 /* We don't build a direct scan probe request; the uCode will do
6037 * that based on the direct_mask added to each channel entry */
6038 cmd_len
= iwl4965_fill_probe_req(priv
, band
,
6039 (struct ieee80211_mgmt
*)scan
->data
,
6040 IWL_MAX_SCAN_SIZE
- sizeof(*scan
), 0);
6042 scan
->tx_cmd
.len
= cpu_to_le16(cmd_len
);
6043 /* select Rx chains */
6045 /* Force use of chains B and C (0x6) for scan Rx.
6046 * Avoid A (0x1) because of its off-channel reception on A-band.
6047 * MIMO is not used here, but value is required to make uCode happy. */
6048 scan
->rx_chain
= RXON_RX_CHAIN_DRIVER_FORCE_MSK
|
6049 cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS
) |
6050 (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS
) |
6051 (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS
));
6053 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
)
6054 scan
->filter_flags
= RXON_FILTER_PROMISC_MSK
;
6058 ("Initiating direct scan for %s.\n",
6059 iwl4965_escape_essid(priv
->essid
, priv
->essid_len
));
6060 scan
->channel_count
=
6061 iwl4965_get_channels_for_scan(
6062 priv
, band
, 1, /* active */
6064 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
6066 IWL_DEBUG_SCAN("Initiating indirect scan.\n");
6067 scan
->channel_count
=
6068 iwl4965_get_channels_for_scan(
6069 priv
, band
, 0, /* passive */
6071 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
6074 cmd
.len
+= le16_to_cpu(scan
->tx_cmd
.len
) +
6075 scan
->channel_count
* sizeof(struct iwl4965_scan_channel
);
6077 scan
->len
= cpu_to_le16(cmd
.len
);
6079 set_bit(STATUS_SCAN_HW
, &priv
->status
);
6080 ret
= iwl_send_cmd_sync(priv
, &cmd
);
6084 queue_delayed_work(priv
->workqueue
, &priv
->scan_check
,
6085 IWL_SCAN_CHECK_WATCHDOG
);
6087 mutex_unlock(&priv
->mutex
);
6091 /* inform mac80211 scan aborted */
6092 queue_work(priv
->workqueue
, &priv
->scan_completed
);
6093 mutex_unlock(&priv
->mutex
);
6096 static void iwl4965_bg_up(struct work_struct
*data
)
6098 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, up
);
6100 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6103 mutex_lock(&priv
->mutex
);
6105 mutex_unlock(&priv
->mutex
);
6108 static void iwl4965_bg_restart(struct work_struct
*data
)
6110 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, restart
);
6112 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6116 queue_work(priv
->workqueue
, &priv
->up
);
6119 static void iwl4965_bg_rx_replenish(struct work_struct
*data
)
6121 struct iwl_priv
*priv
=
6122 container_of(data
, struct iwl_priv
, rx_replenish
);
6124 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6127 mutex_lock(&priv
->mutex
);
6128 iwl4965_rx_replenish(priv
);
6129 mutex_unlock(&priv
->mutex
);
6132 #define IWL_DELAY_NEXT_SCAN (HZ*2)
6134 static void iwl4965_bg_post_associate(struct work_struct
*data
)
6136 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
,
6137 post_associate
.work
);
6138 struct ieee80211_conf
*conf
= NULL
;
6140 DECLARE_MAC_BUF(mac
);
6142 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
6143 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__
);
6147 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
6149 print_mac(mac
, priv
->active_rxon
.bssid_addr
));
6152 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6155 mutex_lock(&priv
->mutex
);
6157 if (!priv
->vif
|| !priv
->is_open
) {
6158 mutex_unlock(&priv
->mutex
);
6161 iwl4965_scan_cancel_timeout(priv
, 200);
6163 conf
= ieee80211_get_hw_conf(priv
->hw
);
6165 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6166 iwl4965_commit_rxon(priv
);
6168 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl4965_rxon_time_cmd
));
6169 iwl4965_setup_rxon_timing(priv
);
6170 ret
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
6171 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
6173 IWL_WARNING("REPLY_RXON_TIMING failed - "
6174 "Attempting to continue.\n");
6176 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
6178 #ifdef CONFIG_IWL4965_HT
6179 if (priv
->current_ht_config
.is_ht
)
6180 iwl4965_set_rxon_ht(priv
, &priv
->current_ht_config
);
6181 #endif /* CONFIG_IWL4965_HT*/
6182 iwl4965_set_rxon_chain(priv
);
6183 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
6185 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
6186 priv
->assoc_id
, priv
->beacon_int
);
6188 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
6189 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
6191 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
6193 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
6194 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
6195 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
6197 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
6199 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
6200 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
6204 iwl4965_commit_rxon(priv
);
6206 switch (priv
->iw_mode
) {
6207 case IEEE80211_IF_TYPE_STA
:
6208 iwl4965_rate_scale_init(priv
->hw
, IWL_AP_ID
);
6211 case IEEE80211_IF_TYPE_IBSS
:
6213 /* clear out the station table */
6214 iwlcore_clear_stations_table(priv
);
6216 iwl4965_rxon_add_station(priv
, iwl4965_broadcast_addr
, 0);
6217 iwl4965_rxon_add_station(priv
, priv
->bssid
, 0);
6218 iwl4965_rate_scale_init(priv
->hw
, IWL_STA_ID
);
6219 iwl4965_send_beacon_cmd(priv
);
6224 IWL_ERROR("%s Should not be called in %d mode\n",
6225 __FUNCTION__
, priv
->iw_mode
);
6229 iwl4965_sequence_reset(priv
);
6231 #ifdef CONFIG_IWL4965_SENSITIVITY
6232 /* Enable Rx differential gain and sensitivity calibrations */
6233 iwl4965_chain_noise_reset(priv
);
6234 priv
->start_calib
= 1;
6235 #endif /* CONFIG_IWL4965_SENSITIVITY */
6237 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
6238 priv
->assoc_station_added
= 1;
6240 iwl4965_activate_qos(priv
, 0);
6242 /* we have just associated, don't start scan too early */
6243 priv
->next_scan_jiffies
= jiffies
+ IWL_DELAY_NEXT_SCAN
;
6244 mutex_unlock(&priv
->mutex
);
6247 static void iwl4965_bg_abort_scan(struct work_struct
*work
)
6249 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
, abort_scan
);
6251 if (!iwl_is_ready(priv
))
6254 mutex_lock(&priv
->mutex
);
6256 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
6257 iwl4965_send_scan_abort(priv
);
6259 mutex_unlock(&priv
->mutex
);
6262 static int iwl4965_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
);
6264 static void iwl4965_bg_scan_completed(struct work_struct
*work
)
6266 struct iwl_priv
*priv
=
6267 container_of(work
, struct iwl_priv
, scan_completed
);
6269 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_SCAN
, "SCAN complete scan\n");
6271 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6274 if (test_bit(STATUS_CONF_PENDING
, &priv
->status
))
6275 iwl4965_mac_config(priv
->hw
, ieee80211_get_hw_conf(priv
->hw
));
6277 ieee80211_scan_completed(priv
->hw
);
6279 /* Since setting the TXPOWER may have been deferred while
6280 * performing the scan, fire one off */
6281 mutex_lock(&priv
->mutex
);
6282 iwl4965_hw_reg_send_txpower(priv
);
6283 mutex_unlock(&priv
->mutex
);
6286 /*****************************************************************************
6288 * mac80211 entry point functions
6290 *****************************************************************************/
6292 #define UCODE_READY_TIMEOUT (2 * HZ)
6294 static int iwl4965_mac_start(struct ieee80211_hw
*hw
)
6296 struct iwl_priv
*priv
= hw
->priv
;
6299 IWL_DEBUG_MAC80211("enter\n");
6301 if (pci_enable_device(priv
->pci_dev
)) {
6302 IWL_ERROR("Fail to pci_enable_device\n");
6305 pci_restore_state(priv
->pci_dev
);
6306 pci_enable_msi(priv
->pci_dev
);
6308 ret
= request_irq(priv
->pci_dev
->irq
, iwl4965_isr
, IRQF_SHARED
,
6311 IWL_ERROR("Error allocating IRQ %d\n", priv
->pci_dev
->irq
);
6312 goto out_disable_msi
;
6315 /* we should be verifying the device is ready to be opened */
6316 mutex_lock(&priv
->mutex
);
6318 memset(&priv
->staging_rxon
, 0, sizeof(struct iwl4965_rxon_cmd
));
6319 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
6320 * ucode filename and max sizes are card-specific. */
6322 if (!priv
->ucode_code
.len
) {
6323 ret
= iwl4965_read_ucode(priv
);
6325 IWL_ERROR("Could not read microcode: %d\n", ret
);
6326 mutex_unlock(&priv
->mutex
);
6327 goto out_release_irq
;
6331 ret
= __iwl4965_up(priv
);
6333 mutex_unlock(&priv
->mutex
);
6336 goto out_release_irq
;
6338 IWL_DEBUG_INFO("Start UP work done.\n");
6340 if (test_bit(STATUS_IN_SUSPEND
, &priv
->status
))
6343 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
6344 * mac80211 will not be run successfully. */
6345 ret
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
6346 test_bit(STATUS_READY
, &priv
->status
),
6347 UCODE_READY_TIMEOUT
);
6349 if (!test_bit(STATUS_READY
, &priv
->status
)) {
6350 IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n",
6351 jiffies_to_msecs(UCODE_READY_TIMEOUT
));
6353 goto out_release_irq
;
6358 IWL_DEBUG_MAC80211("leave\n");
6362 free_irq(priv
->pci_dev
->irq
, priv
);
6364 pci_disable_msi(priv
->pci_dev
);
6365 pci_disable_device(priv
->pci_dev
);
6367 IWL_DEBUG_MAC80211("leave - failed\n");
6371 static void iwl4965_mac_stop(struct ieee80211_hw
*hw
)
6373 struct iwl_priv
*priv
= hw
->priv
;
6375 IWL_DEBUG_MAC80211("enter\n");
6377 if (!priv
->is_open
) {
6378 IWL_DEBUG_MAC80211("leave - skip\n");
6384 if (iwl_is_ready_rf(priv
)) {
6385 /* stop mac, cancel any scan request and clear
6386 * RXON_FILTER_ASSOC_MSK BIT
6388 mutex_lock(&priv
->mutex
);
6389 iwl4965_scan_cancel_timeout(priv
, 100);
6390 cancel_delayed_work(&priv
->post_associate
);
6391 mutex_unlock(&priv
->mutex
);
6396 flush_workqueue(priv
->workqueue
);
6397 free_irq(priv
->pci_dev
->irq
, priv
);
6398 pci_disable_msi(priv
->pci_dev
);
6399 pci_save_state(priv
->pci_dev
);
6400 pci_disable_device(priv
->pci_dev
);
6402 IWL_DEBUG_MAC80211("leave\n");
6405 static int iwl4965_mac_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
6406 struct ieee80211_tx_control
*ctl
)
6408 struct iwl_priv
*priv
= hw
->priv
;
6410 IWL_DEBUG_MAC80211("enter\n");
6412 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
) {
6413 IWL_DEBUG_MAC80211("leave - monitor\n");
6417 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb
->len
,
6418 ctl
->tx_rate
->bitrate
);
6420 if (iwl4965_tx_skb(priv
, skb
, ctl
))
6421 dev_kfree_skb_any(skb
);
6423 IWL_DEBUG_MAC80211("leave\n");
6427 static int iwl4965_mac_add_interface(struct ieee80211_hw
*hw
,
6428 struct ieee80211_if_init_conf
*conf
)
6430 struct iwl_priv
*priv
= hw
->priv
;
6431 unsigned long flags
;
6432 DECLARE_MAC_BUF(mac
);
6434 IWL_DEBUG_MAC80211("enter: type %d\n", conf
->type
);
6437 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
6441 spin_lock_irqsave(&priv
->lock
, flags
);
6442 priv
->vif
= conf
->vif
;
6444 spin_unlock_irqrestore(&priv
->lock
, flags
);
6446 mutex_lock(&priv
->mutex
);
6448 if (conf
->mac_addr
) {
6449 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac
, conf
->mac_addr
));
6450 memcpy(priv
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
6453 if (iwl_is_ready(priv
))
6454 iwl4965_set_mode(priv
, conf
->type
);
6456 mutex_unlock(&priv
->mutex
);
6458 IWL_DEBUG_MAC80211("leave\n");
6463 * iwl4965_mac_config - mac80211 config callback
6465 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
6466 * be set inappropriately and the driver currently sets the hardware up to
6467 * use it whenever needed.
6469 static int iwl4965_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
)
6471 struct iwl_priv
*priv
= hw
->priv
;
6472 const struct iwl_channel_info
*ch_info
;
6473 unsigned long flags
;
6476 mutex_lock(&priv
->mutex
);
6477 IWL_DEBUG_MAC80211("enter to channel %d\n", conf
->channel
->hw_value
);
6479 priv
->add_radiotap
= !!(conf
->flags
& IEEE80211_CONF_RADIOTAP
);
6481 if (!iwl_is_ready(priv
)) {
6482 IWL_DEBUG_MAC80211("leave - not ready\n");
6487 if (unlikely(!priv
->cfg
->mod_params
->disable_hw_scan
&&
6488 test_bit(STATUS_SCANNING
, &priv
->status
))) {
6489 IWL_DEBUG_MAC80211("leave - scanning\n");
6490 set_bit(STATUS_CONF_PENDING
, &priv
->status
);
6491 mutex_unlock(&priv
->mutex
);
6495 spin_lock_irqsave(&priv
->lock
, flags
);
6497 ch_info
= iwl_get_channel_info(priv
, conf
->channel
->band
,
6498 ieee80211_frequency_to_channel(conf
->channel
->center_freq
));
6499 if (!is_channel_valid(ch_info
)) {
6500 IWL_DEBUG_MAC80211("leave - invalid channel\n");
6501 spin_unlock_irqrestore(&priv
->lock
, flags
);
6506 #ifdef CONFIG_IWL4965_HT
6507 /* if we are switching from ht to 2.4 clear flags
6508 * from any ht related info since 2.4 does not
6510 if ((le16_to_cpu(priv
->staging_rxon
.channel
) != conf
->channel
->hw_value
)
6511 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
6512 && !(conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
)
6515 priv
->staging_rxon
.flags
= 0;
6516 #endif /* CONFIG_IWL4965_HT */
6518 iwlcore_set_rxon_channel(priv
, conf
->channel
->band
,
6519 ieee80211_frequency_to_channel(conf
->channel
->center_freq
));
6521 iwl4965_set_flags_for_phymode(priv
, conf
->channel
->band
);
6523 /* The list of supported rates and rate mask can be different
6524 * for each band; since the band may have changed, reset
6525 * the rate mask to what mac80211 lists */
6526 iwl4965_set_rate(priv
);
6528 spin_unlock_irqrestore(&priv
->lock
, flags
);
6530 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
6531 if (conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
) {
6532 iwl4965_hw_channel_switch(priv
, conf
->channel
);
6537 if (priv
->cfg
->ops
->lib
->radio_kill_sw
)
6538 priv
->cfg
->ops
->lib
->radio_kill_sw(priv
, !conf
->radio_enabled
);
6540 if (!conf
->radio_enabled
) {
6541 IWL_DEBUG_MAC80211("leave - radio disabled\n");
6545 if (iwl_is_rfkill(priv
)) {
6546 IWL_DEBUG_MAC80211("leave - RF kill\n");
6551 iwl4965_set_rate(priv
);
6553 if (memcmp(&priv
->active_rxon
,
6554 &priv
->staging_rxon
, sizeof(priv
->staging_rxon
)))
6555 iwl4965_commit_rxon(priv
);
6557 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
6559 IWL_DEBUG_MAC80211("leave\n");
6562 clear_bit(STATUS_CONF_PENDING
, &priv
->status
);
6563 mutex_unlock(&priv
->mutex
);
6567 static void iwl4965_config_ap(struct iwl_priv
*priv
)
6571 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6574 /* The following should be done only at AP bring up */
6575 if ((priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) == 0) {
6577 /* RXON - unassoc (to set timing command) */
6578 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6579 iwl4965_commit_rxon(priv
);
6582 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl4965_rxon_time_cmd
));
6583 iwl4965_setup_rxon_timing(priv
);
6584 ret
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
6585 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
6587 IWL_WARNING("REPLY_RXON_TIMING failed - "
6588 "Attempting to continue.\n");
6590 iwl4965_set_rxon_chain(priv
);
6592 /* FIXME: what should be the assoc_id for AP? */
6593 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
6594 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
6595 priv
->staging_rxon
.flags
|=
6596 RXON_FLG_SHORT_PREAMBLE_MSK
;
6598 priv
->staging_rxon
.flags
&=
6599 ~RXON_FLG_SHORT_PREAMBLE_MSK
;
6601 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
6602 if (priv
->assoc_capability
&
6603 WLAN_CAPABILITY_SHORT_SLOT_TIME
)
6604 priv
->staging_rxon
.flags
|=
6605 RXON_FLG_SHORT_SLOT_MSK
;
6607 priv
->staging_rxon
.flags
&=
6608 ~RXON_FLG_SHORT_SLOT_MSK
;
6610 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
6611 priv
->staging_rxon
.flags
&=
6612 ~RXON_FLG_SHORT_SLOT_MSK
;
6614 /* restore RXON assoc */
6615 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
6616 iwl4965_commit_rxon(priv
);
6617 iwl4965_activate_qos(priv
, 1);
6618 iwl4965_rxon_add_station(priv
, iwl4965_broadcast_addr
, 0);
6620 iwl4965_send_beacon_cmd(priv
);
6622 /* FIXME - we need to add code here to detect a totally new
6623 * configuration, reset the AP, unassoc, rxon timing, assoc,
6624 * clear sta table, add BCAST sta... */
6627 static int iwl4965_mac_config_interface(struct ieee80211_hw
*hw
,
6628 struct ieee80211_vif
*vif
,
6629 struct ieee80211_if_conf
*conf
)
6631 struct iwl_priv
*priv
= hw
->priv
;
6632 DECLARE_MAC_BUF(mac
);
6633 unsigned long flags
;
6639 if (priv
->vif
!= vif
) {
6640 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
6641 mutex_unlock(&priv
->mutex
);
6645 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
6646 (!conf
->beacon
|| !conf
->ssid_len
)) {
6648 ("Leaving in AP mode because HostAPD is not ready.\n");
6652 if (!iwl_is_alive(priv
))
6655 mutex_lock(&priv
->mutex
);
6658 IWL_DEBUG_MAC80211("bssid: %s\n",
6659 print_mac(mac
, conf
->bssid
));
6662 * very dubious code was here; the probe filtering flag is never set:
6664 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
6665 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
6668 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
6670 conf
->bssid
= priv
->mac_addr
;
6671 memcpy(priv
->bssid
, priv
->mac_addr
, ETH_ALEN
);
6672 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
6673 print_mac(mac
, conf
->bssid
));
6675 if (priv
->ibss_beacon
)
6676 dev_kfree_skb(priv
->ibss_beacon
);
6678 priv
->ibss_beacon
= conf
->beacon
;
6681 if (iwl_is_rfkill(priv
))
6684 if (conf
->bssid
&& !is_zero_ether_addr(conf
->bssid
) &&
6685 !is_multicast_ether_addr(conf
->bssid
)) {
6686 /* If there is currently a HW scan going on in the background
6687 * then we need to cancel it else the RXON below will fail. */
6688 if (iwl4965_scan_cancel_timeout(priv
, 100)) {
6689 IWL_WARNING("Aborted scan still in progress "
6691 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
6692 mutex_unlock(&priv
->mutex
);
6695 memcpy(priv
->staging_rxon
.bssid_addr
, conf
->bssid
, ETH_ALEN
);
6697 /* TODO: Audit driver for usage of these members and see
6698 * if mac80211 deprecates them (priv->bssid looks like it
6699 * shouldn't be there, but I haven't scanned the IBSS code
6700 * to verify) - jpk */
6701 memcpy(priv
->bssid
, conf
->bssid
, ETH_ALEN
);
6703 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
6704 iwl4965_config_ap(priv
);
6706 rc
= iwl4965_commit_rxon(priv
);
6707 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) && rc
)
6708 iwl4965_rxon_add_station(
6709 priv
, priv
->active_rxon
.bssid_addr
, 1);
6713 iwl4965_scan_cancel_timeout(priv
, 100);
6714 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6715 iwl4965_commit_rxon(priv
);
6719 spin_lock_irqsave(&priv
->lock
, flags
);
6720 if (!conf
->ssid_len
)
6721 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
6723 memcpy(priv
->essid
, conf
->ssid
, conf
->ssid_len
);
6725 priv
->essid_len
= conf
->ssid_len
;
6726 spin_unlock_irqrestore(&priv
->lock
, flags
);
6728 IWL_DEBUG_MAC80211("leave\n");
6729 mutex_unlock(&priv
->mutex
);
6734 static void iwl4965_configure_filter(struct ieee80211_hw
*hw
,
6735 unsigned int changed_flags
,
6736 unsigned int *total_flags
,
6737 int mc_count
, struct dev_addr_list
*mc_list
)
6741 * see also iwl4965_connection_init_rx_config
6746 static void iwl4965_mac_remove_interface(struct ieee80211_hw
*hw
,
6747 struct ieee80211_if_init_conf
*conf
)
6749 struct iwl_priv
*priv
= hw
->priv
;
6751 IWL_DEBUG_MAC80211("enter\n");
6753 mutex_lock(&priv
->mutex
);
6755 if (iwl_is_ready_rf(priv
)) {
6756 iwl4965_scan_cancel_timeout(priv
, 100);
6757 cancel_delayed_work(&priv
->post_associate
);
6758 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6759 iwl4965_commit_rxon(priv
);
6761 if (priv
->vif
== conf
->vif
) {
6763 memset(priv
->bssid
, 0, ETH_ALEN
);
6764 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
6765 priv
->essid_len
= 0;
6767 mutex_unlock(&priv
->mutex
);
6769 IWL_DEBUG_MAC80211("leave\n");
6774 #ifdef CONFIG_IWL4965_HT
6775 static void iwl4965_ht_conf(struct iwl_priv
*priv
,
6776 struct ieee80211_bss_conf
*bss_conf
)
6778 struct ieee80211_ht_info
*ht_conf
= bss_conf
->ht_conf
;
6779 struct ieee80211_ht_bss_info
*ht_bss_conf
= bss_conf
->ht_bss_conf
;
6780 struct iwl_ht_info
*iwl_conf
= &priv
->current_ht_config
;
6782 IWL_DEBUG_MAC80211("enter: \n");
6784 iwl_conf
->is_ht
= bss_conf
->assoc_ht
;
6786 if (!iwl_conf
->is_ht
)
6789 priv
->ps_mode
= (u8
)((ht_conf
->cap
& IEEE80211_HT_CAP_MIMO_PS
) >> 2);
6791 if (ht_conf
->cap
& IEEE80211_HT_CAP_SGI_20
)
6792 iwl_conf
->sgf
|= 0x1;
6793 if (ht_conf
->cap
& IEEE80211_HT_CAP_SGI_40
)
6794 iwl_conf
->sgf
|= 0x2;
6796 iwl_conf
->is_green_field
= !!(ht_conf
->cap
& IEEE80211_HT_CAP_GRN_FLD
);
6797 iwl_conf
->max_amsdu_size
=
6798 !!(ht_conf
->cap
& IEEE80211_HT_CAP_MAX_AMSDU
);
6800 iwl_conf
->supported_chan_width
=
6801 !!(ht_conf
->cap
& IEEE80211_HT_CAP_SUP_WIDTH
);
6802 iwl_conf
->extension_chan_offset
=
6803 ht_bss_conf
->bss_cap
& IEEE80211_HT_IE_CHA_SEC_OFFSET
;
6804 /* If no above or below channel supplied disable FAT channel */
6805 if (iwl_conf
->extension_chan_offset
!= IWL_EXT_CHANNEL_OFFSET_ABOVE
&&
6806 iwl_conf
->extension_chan_offset
!= IWL_EXT_CHANNEL_OFFSET_BELOW
)
6807 iwl_conf
->supported_chan_width
= 0;
6809 iwl_conf
->tx_mimo_ps_mode
=
6810 (u8
)((ht_conf
->cap
& IEEE80211_HT_CAP_MIMO_PS
) >> 2);
6811 memcpy(iwl_conf
->supp_mcs_set
, ht_conf
->supp_mcs_set
, 16);
6813 iwl_conf
->control_channel
= ht_bss_conf
->primary_channel
;
6814 iwl_conf
->tx_chan_width
=
6815 !!(ht_bss_conf
->bss_cap
& IEEE80211_HT_IE_CHA_WIDTH
);
6816 iwl_conf
->ht_protection
=
6817 ht_bss_conf
->bss_op_mode
& IEEE80211_HT_IE_HT_PROTECTION
;
6818 iwl_conf
->non_GF_STA_present
=
6819 !!(ht_bss_conf
->bss_op_mode
& IEEE80211_HT_IE_NON_GF_STA_PRSNT
);
6821 IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf
->control_channel
);
6822 IWL_DEBUG_MAC80211("leave\n");
6825 static inline void iwl4965_ht_conf(struct iwl_priv
*priv
,
6826 struct ieee80211_bss_conf
*bss_conf
)
6831 #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
6832 static void iwl4965_bss_info_changed(struct ieee80211_hw
*hw
,
6833 struct ieee80211_vif
*vif
,
6834 struct ieee80211_bss_conf
*bss_conf
,
6837 struct iwl_priv
*priv
= hw
->priv
;
6839 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes
);
6841 if (changes
& BSS_CHANGED_ERP_PREAMBLE
) {
6842 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
6843 bss_conf
->use_short_preamble
);
6844 if (bss_conf
->use_short_preamble
)
6845 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
6847 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
6850 if (changes
& BSS_CHANGED_ERP_CTS_PROT
) {
6851 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf
->use_cts_prot
);
6852 if (bss_conf
->use_cts_prot
&& (priv
->band
!= IEEE80211_BAND_5GHZ
))
6853 priv
->staging_rxon
.flags
|= RXON_FLG_TGG_PROTECT_MSK
;
6855 priv
->staging_rxon
.flags
&= ~RXON_FLG_TGG_PROTECT_MSK
;
6858 if (changes
& BSS_CHANGED_HT
) {
6859 IWL_DEBUG_MAC80211("HT %d\n", bss_conf
->assoc_ht
);
6860 iwl4965_ht_conf(priv
, bss_conf
);
6861 iwl4965_set_rxon_chain(priv
);
6864 if (changes
& BSS_CHANGED_ASSOC
) {
6865 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf
->assoc
);
6866 if (bss_conf
->assoc
) {
6867 priv
->assoc_id
= bss_conf
->aid
;
6868 priv
->beacon_int
= bss_conf
->beacon_int
;
6869 priv
->timestamp
= bss_conf
->timestamp
;
6870 priv
->assoc_capability
= bss_conf
->assoc_capability
;
6871 priv
->next_scan_jiffies
= jiffies
+
6872 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC
;
6873 queue_work(priv
->workqueue
, &priv
->post_associate
.work
);
6876 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf
->assoc
);
6878 } else if (changes
&& iwl_is_associated(priv
) && priv
->assoc_id
) {
6879 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes
);
6880 iwl4965_send_rxon_assoc(priv
);
6885 static int iwl4965_mac_hw_scan(struct ieee80211_hw
*hw
, u8
*ssid
, size_t len
)
6888 unsigned long flags
;
6889 struct iwl_priv
*priv
= hw
->priv
;
6891 IWL_DEBUG_MAC80211("enter\n");
6893 mutex_lock(&priv
->mutex
);
6894 spin_lock_irqsave(&priv
->lock
, flags
);
6896 if (!iwl_is_ready_rf(priv
)) {
6898 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
6902 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) { /* APs don't scan */
6904 IWL_ERROR("ERROR: APs don't scan\n");
6908 /* we don't schedule scan within next_scan_jiffies period */
6909 if (priv
->next_scan_jiffies
&&
6910 time_after(priv
->next_scan_jiffies
, jiffies
)) {
6914 /* if we just finished scan ask for delay */
6915 if (priv
->last_scan_jiffies
&& time_after(priv
->last_scan_jiffies
+
6916 IWL_DELAY_NEXT_SCAN
, jiffies
)) {
6921 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
6922 iwl4965_escape_essid(ssid
, len
), (int)len
);
6924 priv
->one_direct_scan
= 1;
6925 priv
->direct_ssid_len
= (u8
)
6926 min((u8
) len
, (u8
) IW_ESSID_MAX_SIZE
);
6927 memcpy(priv
->direct_ssid
, ssid
, priv
->direct_ssid_len
);
6929 priv
->one_direct_scan
= 0;
6931 rc
= iwl4965_scan_initiate(priv
);
6933 IWL_DEBUG_MAC80211("leave\n");
6936 spin_unlock_irqrestore(&priv
->lock
, flags
);
6937 mutex_unlock(&priv
->mutex
);
6942 static void iwl4965_mac_update_tkip_key(struct ieee80211_hw
*hw
,
6943 struct ieee80211_key_conf
*keyconf
, const u8
*addr
,
6944 u32 iv32
, u16
*phase1key
)
6946 struct iwl_priv
*priv
= hw
->priv
;
6947 u8 sta_id
= IWL_INVALID_STATION
;
6948 unsigned long flags
;
6949 __le16 key_flags
= 0;
6951 DECLARE_MAC_BUF(mac
);
6953 IWL_DEBUG_MAC80211("enter\n");
6955 sta_id
= iwl4965_hw_find_station(priv
, addr
);
6956 if (sta_id
== IWL_INVALID_STATION
) {
6957 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
6958 print_mac(mac
, addr
));
6962 iwl4965_scan_cancel_timeout(priv
, 100);
6964 key_flags
|= (STA_KEY_FLG_TKIP
| STA_KEY_FLG_MAP_KEY_MSK
);
6965 key_flags
|= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
6966 key_flags
&= ~STA_KEY_FLG_INVALID
;
6968 if (sta_id
== priv
->hw_setting
.bcast_sta_id
)
6969 key_flags
|= STA_KEY_MULTICAST_MSK
;
6971 spin_lock_irqsave(&priv
->sta_lock
, flags
);
6973 priv
->stations
[sta_id
].sta
.key
.key_offset
=
6974 (sta_id
% STA_KEY_MAX_NUM
);/* FIXME */
6975 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
6976 priv
->stations
[sta_id
].sta
.key
.tkip_rx_tsc_byte2
= (u8
) iv32
;
6978 for (i
= 0; i
< 5; i
++)
6979 priv
->stations
[sta_id
].sta
.key
.tkip_rx_ttak
[i
] =
6980 cpu_to_le16(phase1key
[i
]);
6982 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
6983 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
6985 iwl4965_send_add_station(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
6987 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
6989 IWL_DEBUG_MAC80211("leave\n");
6992 static int iwl4965_mac_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
6993 const u8
*local_addr
, const u8
*addr
,
6994 struct ieee80211_key_conf
*key
)
6996 struct iwl_priv
*priv
= hw
->priv
;
6997 DECLARE_MAC_BUF(mac
);
6999 u8 sta_id
= IWL_INVALID_STATION
;
7000 u8 is_default_wep_key
= 0;
7002 IWL_DEBUG_MAC80211("enter\n");
7004 if (!priv
->cfg
->mod_params
->hw_crypto
) {
7005 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
7009 if (is_zero_ether_addr(addr
))
7010 /* only support pairwise keys */
7013 sta_id
= iwl4965_hw_find_station(priv
, addr
);
7014 if (sta_id
== IWL_INVALID_STATION
) {
7015 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
7016 print_mac(mac
, addr
));
7021 mutex_lock(&priv
->mutex
);
7022 iwl4965_scan_cancel_timeout(priv
, 100);
7023 mutex_unlock(&priv
->mutex
);
7025 /* If we are getting WEP group key and we didn't receive any key mapping
7026 * so far, we are in legacy wep mode (group key only), otherwise we are
7028 * In legacy wep mode, we use another host command to the uCode */
7029 if (key
->alg
== ALG_WEP
&& sta_id
== priv
->hw_setting
.bcast_sta_id
&&
7030 priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
7032 is_default_wep_key
= !priv
->key_mapping_key
;
7034 is_default_wep_key
= priv
->default_wep_key
;
7039 if (is_default_wep_key
)
7040 ret
= iwl_set_default_wep_key(priv
, key
);
7042 ret
= iwl4965_set_dynamic_key(priv
, key
, sta_id
);
7044 IWL_DEBUG_MAC80211("enable hwcrypto key\n");
7047 if (is_default_wep_key
)
7048 ret
= iwl_remove_default_wep_key(priv
, key
);
7050 ret
= iwl4965_clear_sta_key_info(priv
, sta_id
);
7052 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
7058 IWL_DEBUG_MAC80211("leave\n");
7063 static int iwl4965_mac_conf_tx(struct ieee80211_hw
*hw
, int queue
,
7064 const struct ieee80211_tx_queue_params
*params
)
7066 struct iwl_priv
*priv
= hw
->priv
;
7067 unsigned long flags
;
7070 IWL_DEBUG_MAC80211("enter\n");
7072 if (!iwl_is_ready_rf(priv
)) {
7073 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7077 if (queue
>= AC_NUM
) {
7078 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue
);
7082 if (!priv
->qos_data
.qos_enable
) {
7083 priv
->qos_data
.qos_active
= 0;
7084 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
7087 q
= AC_NUM
- 1 - queue
;
7089 spin_lock_irqsave(&priv
->lock
, flags
);
7091 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_min
= cpu_to_le16(params
->cw_min
);
7092 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_max
= cpu_to_le16(params
->cw_max
);
7093 priv
->qos_data
.def_qos_parm
.ac
[q
].aifsn
= params
->aifs
;
7094 priv
->qos_data
.def_qos_parm
.ac
[q
].edca_txop
=
7095 cpu_to_le16((params
->txop
* 32));
7097 priv
->qos_data
.def_qos_parm
.ac
[q
].reserved1
= 0;
7098 priv
->qos_data
.qos_active
= 1;
7100 spin_unlock_irqrestore(&priv
->lock
, flags
);
7102 mutex_lock(&priv
->mutex
);
7103 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
7104 iwl4965_activate_qos(priv
, 1);
7105 else if (priv
->assoc_id
&& iwl_is_associated(priv
))
7106 iwl4965_activate_qos(priv
, 0);
7108 mutex_unlock(&priv
->mutex
);
7110 IWL_DEBUG_MAC80211("leave\n");
7114 static int iwl4965_mac_get_tx_stats(struct ieee80211_hw
*hw
,
7115 struct ieee80211_tx_queue_stats
*stats
)
7117 struct iwl_priv
*priv
= hw
->priv
;
7119 struct iwl4965_tx_queue
*txq
;
7120 struct iwl4965_queue
*q
;
7121 unsigned long flags
;
7123 IWL_DEBUG_MAC80211("enter\n");
7125 if (!iwl_is_ready_rf(priv
)) {
7126 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7130 spin_lock_irqsave(&priv
->lock
, flags
);
7132 for (i
= 0; i
< AC_NUM
; i
++) {
7133 txq
= &priv
->txq
[i
];
7135 avail
= iwl4965_queue_space(q
);
7137 stats
->data
[i
].len
= q
->n_window
- avail
;
7138 stats
->data
[i
].limit
= q
->n_window
- q
->high_mark
;
7139 stats
->data
[i
].count
= q
->n_window
;
7142 spin_unlock_irqrestore(&priv
->lock
, flags
);
7144 IWL_DEBUG_MAC80211("leave\n");
7149 static int iwl4965_mac_get_stats(struct ieee80211_hw
*hw
,
7150 struct ieee80211_low_level_stats
*stats
)
7152 IWL_DEBUG_MAC80211("enter\n");
7153 IWL_DEBUG_MAC80211("leave\n");
7158 static u64
iwl4965_mac_get_tsf(struct ieee80211_hw
*hw
)
7160 IWL_DEBUG_MAC80211("enter\n");
7161 IWL_DEBUG_MAC80211("leave\n");
7166 static void iwl4965_mac_reset_tsf(struct ieee80211_hw
*hw
)
7168 struct iwl_priv
*priv
= hw
->priv
;
7169 unsigned long flags
;
7171 mutex_lock(&priv
->mutex
);
7172 IWL_DEBUG_MAC80211("enter\n");
7174 priv
->lq_mngr
.lq_ready
= 0;
7175 #ifdef CONFIG_IWL4965_HT
7176 spin_lock_irqsave(&priv
->lock
, flags
);
7177 memset(&priv
->current_ht_config
, 0, sizeof(struct iwl_ht_info
));
7178 spin_unlock_irqrestore(&priv
->lock
, flags
);
7179 #endif /* CONFIG_IWL4965_HT */
7181 iwlcore_reset_qos(priv
);
7183 cancel_delayed_work(&priv
->post_associate
);
7185 spin_lock_irqsave(&priv
->lock
, flags
);
7187 priv
->assoc_capability
= 0;
7188 priv
->assoc_station_added
= 0;
7190 /* new association get rid of ibss beacon skb */
7191 if (priv
->ibss_beacon
)
7192 dev_kfree_skb(priv
->ibss_beacon
);
7194 priv
->ibss_beacon
= NULL
;
7196 priv
->beacon_int
= priv
->hw
->conf
.beacon_int
;
7197 priv
->timestamp
= 0;
7198 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
7199 priv
->beacon_int
= 0;
7201 spin_unlock_irqrestore(&priv
->lock
, flags
);
7203 if (!iwl_is_ready_rf(priv
)) {
7204 IWL_DEBUG_MAC80211("leave - not ready\n");
7205 mutex_unlock(&priv
->mutex
);
7209 /* we are restarting association process
7210 * clear RXON_FILTER_ASSOC_MSK bit
7212 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
7213 iwl4965_scan_cancel_timeout(priv
, 100);
7214 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
7215 iwl4965_commit_rxon(priv
);
7218 /* Per mac80211.h: This is only used in IBSS mode... */
7219 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
7221 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
7222 mutex_unlock(&priv
->mutex
);
7226 priv
->only_active_channel
= 0;
7228 iwl4965_set_rate(priv
);
7230 mutex_unlock(&priv
->mutex
);
7232 IWL_DEBUG_MAC80211("leave\n");
7235 static int iwl4965_mac_beacon_update(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
7236 struct ieee80211_tx_control
*control
)
7238 struct iwl_priv
*priv
= hw
->priv
;
7239 unsigned long flags
;
7241 mutex_lock(&priv
->mutex
);
7242 IWL_DEBUG_MAC80211("enter\n");
7244 if (!iwl_is_ready_rf(priv
)) {
7245 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7246 mutex_unlock(&priv
->mutex
);
7250 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
7251 IWL_DEBUG_MAC80211("leave - not IBSS\n");
7252 mutex_unlock(&priv
->mutex
);
7256 spin_lock_irqsave(&priv
->lock
, flags
);
7258 if (priv
->ibss_beacon
)
7259 dev_kfree_skb(priv
->ibss_beacon
);
7261 priv
->ibss_beacon
= skb
;
7265 IWL_DEBUG_MAC80211("leave\n");
7266 spin_unlock_irqrestore(&priv
->lock
, flags
);
7268 iwlcore_reset_qos(priv
);
7270 queue_work(priv
->workqueue
, &priv
->post_associate
.work
);
7272 mutex_unlock(&priv
->mutex
);
7277 /*****************************************************************************
7281 *****************************************************************************/
7283 #ifdef CONFIG_IWLWIFI_DEBUG
7286 * The following adds a new attribute to the sysfs representation
7287 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
7288 * used for controlling the debug level.
7290 * See the level definitions in iwl for details.
7293 static ssize_t
show_debug_level(struct device_driver
*d
, char *buf
)
7295 return sprintf(buf
, "0x%08X\n", iwl_debug_level
);
7297 static ssize_t
store_debug_level(struct device_driver
*d
,
7298 const char *buf
, size_t count
)
7300 char *p
= (char *)buf
;
7303 val
= simple_strtoul(p
, &p
, 0);
7305 printk(KERN_INFO DRV_NAME
7306 ": %s is not in hex or decimal form.\n", buf
);
7308 iwl_debug_level
= val
;
7310 return strnlen(buf
, count
);
7313 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
7314 show_debug_level
, store_debug_level
);
7316 #endif /* CONFIG_IWLWIFI_DEBUG */
7319 static ssize_t
show_temperature(struct device
*d
,
7320 struct device_attribute
*attr
, char *buf
)
7322 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7324 if (!iwl_is_alive(priv
))
7327 return sprintf(buf
, "%d\n", iwl4965_hw_get_temperature(priv
));
7330 static DEVICE_ATTR(temperature
, S_IRUGO
, show_temperature
, NULL
);
7332 static ssize_t
show_rs_window(struct device
*d
,
7333 struct device_attribute
*attr
,
7336 struct iwl_priv
*priv
= d
->driver_data
;
7337 return iwl4965_fill_rs_info(priv
->hw
, buf
, IWL_AP_ID
);
7339 static DEVICE_ATTR(rs_window
, S_IRUGO
, show_rs_window
, NULL
);
7341 static ssize_t
show_tx_power(struct device
*d
,
7342 struct device_attribute
*attr
, char *buf
)
7344 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7345 return sprintf(buf
, "%d\n", priv
->user_txpower_limit
);
7348 static ssize_t
store_tx_power(struct device
*d
,
7349 struct device_attribute
*attr
,
7350 const char *buf
, size_t count
)
7352 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7353 char *p
= (char *)buf
;
7356 val
= simple_strtoul(p
, &p
, 10);
7358 printk(KERN_INFO DRV_NAME
7359 ": %s is not in decimal form.\n", buf
);
7361 iwl4965_hw_reg_set_txpower(priv
, val
);
7366 static DEVICE_ATTR(tx_power
, S_IWUSR
| S_IRUGO
, show_tx_power
, store_tx_power
);
7368 static ssize_t
show_flags(struct device
*d
,
7369 struct device_attribute
*attr
, char *buf
)
7371 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7373 return sprintf(buf
, "0x%04X\n", priv
->active_rxon
.flags
);
7376 static ssize_t
store_flags(struct device
*d
,
7377 struct device_attribute
*attr
,
7378 const char *buf
, size_t count
)
7380 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7381 u32 flags
= simple_strtoul(buf
, NULL
, 0);
7383 mutex_lock(&priv
->mutex
);
7384 if (le32_to_cpu(priv
->staging_rxon
.flags
) != flags
) {
7385 /* Cancel any currently running scans... */
7386 if (iwl4965_scan_cancel_timeout(priv
, 100))
7387 IWL_WARNING("Could not cancel scan.\n");
7389 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
7391 priv
->staging_rxon
.flags
= cpu_to_le32(flags
);
7392 iwl4965_commit_rxon(priv
);
7395 mutex_unlock(&priv
->mutex
);
7400 static DEVICE_ATTR(flags
, S_IWUSR
| S_IRUGO
, show_flags
, store_flags
);
7402 static ssize_t
show_filter_flags(struct device
*d
,
7403 struct device_attribute
*attr
, char *buf
)
7405 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7407 return sprintf(buf
, "0x%04X\n",
7408 le32_to_cpu(priv
->active_rxon
.filter_flags
));
7411 static ssize_t
store_filter_flags(struct device
*d
,
7412 struct device_attribute
*attr
,
7413 const char *buf
, size_t count
)
7415 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7416 u32 filter_flags
= simple_strtoul(buf
, NULL
, 0);
7418 mutex_lock(&priv
->mutex
);
7419 if (le32_to_cpu(priv
->staging_rxon
.filter_flags
) != filter_flags
) {
7420 /* Cancel any currently running scans... */
7421 if (iwl4965_scan_cancel_timeout(priv
, 100))
7422 IWL_WARNING("Could not cancel scan.\n");
7424 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
7425 "0x%04X\n", filter_flags
);
7426 priv
->staging_rxon
.filter_flags
=
7427 cpu_to_le32(filter_flags
);
7428 iwl4965_commit_rxon(priv
);
7431 mutex_unlock(&priv
->mutex
);
7436 static DEVICE_ATTR(filter_flags
, S_IWUSR
| S_IRUGO
, show_filter_flags
,
7437 store_filter_flags
);
7439 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
7441 static ssize_t
show_measurement(struct device
*d
,
7442 struct device_attribute
*attr
, char *buf
)
7444 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7445 struct iwl4965_spectrum_notification measure_report
;
7446 u32 size
= sizeof(measure_report
), len
= 0, ofs
= 0;
7447 u8
*data
= (u8
*) & measure_report
;
7448 unsigned long flags
;
7450 spin_lock_irqsave(&priv
->lock
, flags
);
7451 if (!(priv
->measurement_status
& MEASUREMENT_READY
)) {
7452 spin_unlock_irqrestore(&priv
->lock
, flags
);
7455 memcpy(&measure_report
, &priv
->measure_report
, size
);
7456 priv
->measurement_status
= 0;
7457 spin_unlock_irqrestore(&priv
->lock
, flags
);
7459 while (size
&& (PAGE_SIZE
- len
)) {
7460 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
7461 PAGE_SIZE
- len
, 1);
7463 if (PAGE_SIZE
- len
)
7467 size
-= min(size
, 16U);
7473 static ssize_t
store_measurement(struct device
*d
,
7474 struct device_attribute
*attr
,
7475 const char *buf
, size_t count
)
7477 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7478 struct ieee80211_measurement_params params
= {
7479 .channel
= le16_to_cpu(priv
->active_rxon
.channel
),
7480 .start_time
= cpu_to_le64(priv
->last_tsf
),
7481 .duration
= cpu_to_le16(1),
7483 u8 type
= IWL_MEASURE_BASIC
;
7489 strncpy(buffer
, buf
, min(sizeof(buffer
), count
));
7490 channel
= simple_strtoul(p
, NULL
, 0);
7492 params
.channel
= channel
;
7495 while (*p
&& *p
!= ' ')
7498 type
= simple_strtoul(p
+ 1, NULL
, 0);
7501 IWL_DEBUG_INFO("Invoking measurement of type %d on "
7502 "channel %d (for '%s')\n", type
, params
.channel
, buf
);
7503 iwl4965_get_measurement(priv
, ¶ms
, type
);
7508 static DEVICE_ATTR(measurement
, S_IRUSR
| S_IWUSR
,
7509 show_measurement
, store_measurement
);
7510 #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
7512 static ssize_t
store_retry_rate(struct device
*d
,
7513 struct device_attribute
*attr
,
7514 const char *buf
, size_t count
)
7516 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7518 priv
->retry_rate
= simple_strtoul(buf
, NULL
, 0);
7519 if (priv
->retry_rate
<= 0)
7520 priv
->retry_rate
= 1;
7525 static ssize_t
show_retry_rate(struct device
*d
,
7526 struct device_attribute
*attr
, char *buf
)
7528 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7529 return sprintf(buf
, "%d", priv
->retry_rate
);
7532 static DEVICE_ATTR(retry_rate
, S_IWUSR
| S_IRUSR
, show_retry_rate
,
7535 static ssize_t
store_power_level(struct device
*d
,
7536 struct device_attribute
*attr
,
7537 const char *buf
, size_t count
)
7539 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7543 mode
= simple_strtoul(buf
, NULL
, 0);
7544 mutex_lock(&priv
->mutex
);
7546 if (!iwl_is_ready(priv
)) {
7551 if ((mode
< 1) || (mode
> IWL_POWER_LIMIT
) || (mode
== IWL_POWER_AC
))
7552 mode
= IWL_POWER_AC
;
7554 mode
|= IWL_POWER_ENABLED
;
7556 if (mode
!= priv
->power_mode
) {
7557 rc
= iwl4965_send_power_mode(priv
, IWL_POWER_LEVEL(mode
));
7559 IWL_DEBUG_MAC80211("failed setting power mode.\n");
7562 priv
->power_mode
= mode
;
7568 mutex_unlock(&priv
->mutex
);
7572 #define MAX_WX_STRING 80
7574 /* Values are in microsecond */
7575 static const s32 timeout_duration
[] = {
7582 static const s32 period_duration
[] = {
7590 static ssize_t
show_power_level(struct device
*d
,
7591 struct device_attribute
*attr
, char *buf
)
7593 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7594 int level
= IWL_POWER_LEVEL(priv
->power_mode
);
7597 p
+= sprintf(p
, "%d ", level
);
7599 case IWL_POWER_MODE_CAM
:
7601 p
+= sprintf(p
, "(AC)");
7603 case IWL_POWER_BATTERY
:
7604 p
+= sprintf(p
, "(BATTERY)");
7608 "(Timeout %dms, Period %dms)",
7609 timeout_duration
[level
- 1] / 1000,
7610 period_duration
[level
- 1] / 1000);
7613 if (!(priv
->power_mode
& IWL_POWER_ENABLED
))
7614 p
+= sprintf(p
, " OFF\n");
7616 p
+= sprintf(p
, " \n");
7618 return (p
- buf
+ 1);
7622 static DEVICE_ATTR(power_level
, S_IWUSR
| S_IRUSR
, show_power_level
,
7625 static ssize_t
show_channels(struct device
*d
,
7626 struct device_attribute
*attr
, char *buf
)
7628 /* all this shit doesn't belong into sysfs anyway */
7632 static DEVICE_ATTR(channels
, S_IRUSR
, show_channels
, NULL
);
7634 static ssize_t
show_statistics(struct device
*d
,
7635 struct device_attribute
*attr
, char *buf
)
7637 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7638 u32 size
= sizeof(struct iwl4965_notif_statistics
);
7639 u32 len
= 0, ofs
= 0;
7640 u8
*data
= (u8
*) & priv
->statistics
;
7643 if (!iwl_is_alive(priv
))
7646 mutex_lock(&priv
->mutex
);
7647 rc
= iwl4965_send_statistics_request(priv
);
7648 mutex_unlock(&priv
->mutex
);
7652 "Error sending statistics request: 0x%08X\n", rc
);
7656 while (size
&& (PAGE_SIZE
- len
)) {
7657 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
7658 PAGE_SIZE
- len
, 1);
7660 if (PAGE_SIZE
- len
)
7664 size
-= min(size
, 16U);
7670 static DEVICE_ATTR(statistics
, S_IRUGO
, show_statistics
, NULL
);
7672 static ssize_t
show_antenna(struct device
*d
,
7673 struct device_attribute
*attr
, char *buf
)
7675 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7677 if (!iwl_is_alive(priv
))
7680 return sprintf(buf
, "%d\n", priv
->antenna
);
7683 static ssize_t
store_antenna(struct device
*d
,
7684 struct device_attribute
*attr
,
7685 const char *buf
, size_t count
)
7688 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7693 if (sscanf(buf
, "%1i", &ant
) != 1) {
7694 IWL_DEBUG_INFO("not in hex or decimal form.\n");
7698 if ((ant
>= 0) && (ant
<= 2)) {
7699 IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant
);
7700 priv
->antenna
= (enum iwl4965_antenna
)ant
;
7702 IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant
);
7708 static DEVICE_ATTR(antenna
, S_IWUSR
| S_IRUGO
, show_antenna
, store_antenna
);
7710 static ssize_t
show_status(struct device
*d
,
7711 struct device_attribute
*attr
, char *buf
)
7713 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7714 if (!iwl_is_alive(priv
))
7716 return sprintf(buf
, "0x%08x\n", (int)priv
->status
);
7719 static DEVICE_ATTR(status
, S_IRUGO
, show_status
, NULL
);
7721 static ssize_t
dump_error_log(struct device
*d
,
7722 struct device_attribute
*attr
,
7723 const char *buf
, size_t count
)
7725 char *p
= (char *)buf
;
7728 iwl4965_dump_nic_error_log((struct iwl_priv
*)d
->driver_data
);
7730 return strnlen(buf
, count
);
7733 static DEVICE_ATTR(dump_errors
, S_IWUSR
, NULL
, dump_error_log
);
7735 static ssize_t
dump_event_log(struct device
*d
,
7736 struct device_attribute
*attr
,
7737 const char *buf
, size_t count
)
7739 char *p
= (char *)buf
;
7742 iwl4965_dump_nic_event_log((struct iwl_priv
*)d
->driver_data
);
7744 return strnlen(buf
, count
);
7747 static DEVICE_ATTR(dump_events
, S_IWUSR
, NULL
, dump_event_log
);
7749 /*****************************************************************************
7751 * driver setup and teardown
7753 *****************************************************************************/
7755 static void iwl4965_setup_deferred_work(struct iwl_priv
*priv
)
7757 priv
->workqueue
= create_workqueue(DRV_NAME
);
7759 init_waitqueue_head(&priv
->wait_command_queue
);
7761 INIT_WORK(&priv
->up
, iwl4965_bg_up
);
7762 INIT_WORK(&priv
->restart
, iwl4965_bg_restart
);
7763 INIT_WORK(&priv
->rx_replenish
, iwl4965_bg_rx_replenish
);
7764 INIT_WORK(&priv
->scan_completed
, iwl4965_bg_scan_completed
);
7765 INIT_WORK(&priv
->request_scan
, iwl4965_bg_request_scan
);
7766 INIT_WORK(&priv
->abort_scan
, iwl4965_bg_abort_scan
);
7767 INIT_WORK(&priv
->rf_kill
, iwl4965_bg_rf_kill
);
7768 INIT_WORK(&priv
->beacon_update
, iwl4965_bg_beacon_update
);
7769 INIT_DELAYED_WORK(&priv
->post_associate
, iwl4965_bg_post_associate
);
7770 INIT_DELAYED_WORK(&priv
->init_alive_start
, iwl4965_bg_init_alive_start
);
7771 INIT_DELAYED_WORK(&priv
->alive_start
, iwl4965_bg_alive_start
);
7772 INIT_DELAYED_WORK(&priv
->scan_check
, iwl4965_bg_scan_check
);
7774 iwl4965_hw_setup_deferred_work(priv
);
7776 tasklet_init(&priv
->irq_tasklet
, (void (*)(unsigned long))
7777 iwl4965_irq_tasklet
, (unsigned long)priv
);
7780 static void iwl4965_cancel_deferred_work(struct iwl_priv
*priv
)
7782 iwl4965_hw_cancel_deferred_work(priv
);
7784 cancel_delayed_work_sync(&priv
->init_alive_start
);
7785 cancel_delayed_work(&priv
->scan_check
);
7786 cancel_delayed_work(&priv
->alive_start
);
7787 cancel_delayed_work(&priv
->post_associate
);
7788 cancel_work_sync(&priv
->beacon_update
);
7791 static struct attribute
*iwl4965_sysfs_entries
[] = {
7792 &dev_attr_antenna
.attr
,
7793 &dev_attr_channels
.attr
,
7794 &dev_attr_dump_errors
.attr
,
7795 &dev_attr_dump_events
.attr
,
7796 &dev_attr_flags
.attr
,
7797 &dev_attr_filter_flags
.attr
,
7798 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
7799 &dev_attr_measurement
.attr
,
7801 &dev_attr_power_level
.attr
,
7802 &dev_attr_retry_rate
.attr
,
7803 &dev_attr_rs_window
.attr
,
7804 &dev_attr_statistics
.attr
,
7805 &dev_attr_status
.attr
,
7806 &dev_attr_temperature
.attr
,
7807 &dev_attr_tx_power
.attr
,
7812 static struct attribute_group iwl4965_attribute_group
= {
7813 .name
= NULL
, /* put in device directory */
7814 .attrs
= iwl4965_sysfs_entries
,
7817 static struct ieee80211_ops iwl4965_hw_ops
= {
7818 .tx
= iwl4965_mac_tx
,
7819 .start
= iwl4965_mac_start
,
7820 .stop
= iwl4965_mac_stop
,
7821 .add_interface
= iwl4965_mac_add_interface
,
7822 .remove_interface
= iwl4965_mac_remove_interface
,
7823 .config
= iwl4965_mac_config
,
7824 .config_interface
= iwl4965_mac_config_interface
,
7825 .configure_filter
= iwl4965_configure_filter
,
7826 .set_key
= iwl4965_mac_set_key
,
7827 .update_tkip_key
= iwl4965_mac_update_tkip_key
,
7828 .get_stats
= iwl4965_mac_get_stats
,
7829 .get_tx_stats
= iwl4965_mac_get_tx_stats
,
7830 .conf_tx
= iwl4965_mac_conf_tx
,
7831 .get_tsf
= iwl4965_mac_get_tsf
,
7832 .reset_tsf
= iwl4965_mac_reset_tsf
,
7833 .beacon_update
= iwl4965_mac_beacon_update
,
7834 .bss_info_changed
= iwl4965_bss_info_changed
,
7835 #ifdef CONFIG_IWL4965_HT
7836 .ampdu_action
= iwl4965_mac_ampdu_action
,
7837 #endif /* CONFIG_IWL4965_HT */
7838 .hw_scan
= iwl4965_mac_hw_scan
7841 static int iwl4965_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
7844 struct iwl_priv
*priv
;
7845 struct ieee80211_hw
*hw
;
7846 struct iwl_cfg
*cfg
= (struct iwl_cfg
*)(ent
->driver_data
);
7847 unsigned long flags
;
7848 DECLARE_MAC_BUF(mac
);
7850 /************************
7851 * 1. Allocating HW data
7852 ************************/
7854 /* Disabling hardware scan means that mac80211 will perform scans
7855 * "the hard way", rather than using device's scan. */
7856 if (cfg
->mod_params
->disable_hw_scan
) {
7857 IWL_DEBUG_INFO("Disabling hw_scan\n");
7858 iwl4965_hw_ops
.hw_scan
= NULL
;
7861 hw
= iwl_alloc_all(cfg
, &iwl4965_hw_ops
);
7867 /* At this point both hw and priv are allocated. */
7869 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
7871 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
7873 priv
->pci_dev
= pdev
;
7875 #ifdef CONFIG_IWLWIFI_DEBUG
7876 iwl_debug_level
= priv
->cfg
->mod_params
->debug
;
7877 atomic_set(&priv
->restrict_refcnt
, 0);
7880 /**************************
7881 * 2. Initializing PCI bus
7882 **************************/
7883 if (pci_enable_device(pdev
)) {
7885 goto out_ieee80211_free_hw
;
7888 pci_set_master(pdev
);
7890 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
7892 err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
7894 printk(KERN_WARNING DRV_NAME
7895 ": No suitable DMA available.\n");
7896 goto out_pci_disable_device
;
7899 err
= pci_request_regions(pdev
, DRV_NAME
);
7901 goto out_pci_disable_device
;
7903 pci_set_drvdata(pdev
, priv
);
7905 /* We disable the RETRY_TIMEOUT register (0x41) to keep
7906 * PCI Tx retries from interfering with C3 CPU state */
7907 pci_write_config_byte(pdev
, 0x41, 0x00);
7909 /***********************
7910 * 3. Read REV register
7911 ***********************/
7912 priv
->hw_base
= pci_iomap(pdev
, 0, 0);
7913 if (!priv
->hw_base
) {
7915 goto out_pci_release_regions
;
7918 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
7919 (unsigned long long) pci_resource_len(pdev
, 0));
7920 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv
->hw_base
);
7922 printk(KERN_INFO DRV_NAME
7923 ": Detected Intel Wireless WiFi Link %s\n", priv
->cfg
->name
);
7929 iwl_set_bit(priv
, CSR_GIO_CHICKEN_BITS
,
7930 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER
);
7932 iwl_set_bit(priv
, CSR_GP_CNTRL
, CSR_GP_CNTRL_REG_FLAG_INIT_DONE
);
7933 err
= iwl_poll_bit(priv
, CSR_GP_CNTRL
,
7934 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY
,
7935 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY
, 25000);
7937 IWL_DEBUG_INFO("Failed to init the card\n");
7940 /* Read the EEPROM */
7941 err
= iwl_eeprom_init(priv
);
7943 IWL_ERROR("Unable to init EEPROM\n");
7946 /* MAC Address location in EEPROM same for 3945/4965 */
7947 iwl_eeprom_get_mac(priv
, priv
->mac_addr
);
7948 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac
, priv
->mac_addr
));
7949 SET_IEEE80211_PERM_ADDR(priv
->hw
, priv
->mac_addr
);
7951 /************************
7952 * 5. Setup HW constants
7953 ************************/
7954 /* Device-specific setup */
7955 if (iwl4965_hw_set_hw_setting(priv
)) {
7956 IWL_ERROR("failed to set hw settings\n");
7960 /*******************
7962 *******************/
7964 err
= iwl_setup(priv
);
7966 goto out_unset_hw_settings
;
7967 /* At this point both hw and priv are initialized. */
7969 /**********************************
7970 * 7. Initialize module parameters
7971 **********************************/
7973 /* Disable radio (SW RF KILL) via parameter when loading driver */
7974 if (priv
->cfg
->mod_params
->disable
) {
7975 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
7976 IWL_DEBUG_INFO("Radio disabled.\n");
7979 if (priv
->cfg
->mod_params
->enable_qos
)
7980 priv
->qos_data
.qos_enable
= 1;
7982 /********************
7984 ********************/
7985 spin_lock_irqsave(&priv
->lock
, flags
);
7986 iwl4965_disable_interrupts(priv
);
7987 spin_unlock_irqrestore(&priv
->lock
, flags
);
7989 err
= sysfs_create_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
7991 IWL_ERROR("failed to create sysfs device attributes\n");
7992 goto out_unset_hw_settings
;
7995 err
= iwl_dbgfs_register(priv
, DRV_NAME
);
7997 IWL_ERROR("failed to create debugfs files\n");
7998 goto out_remove_sysfs
;
8001 iwl4965_setup_deferred_work(priv
);
8002 iwl4965_setup_rx_handlers(priv
);
8004 /********************
8006 ********************/
8007 pci_save_state(pdev
);
8008 pci_disable_device(pdev
);
8010 /* notify iwlcore to init */
8011 iwlcore_low_level_notify(priv
, IWLCORE_INIT_EVT
);
8015 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
8016 out_unset_hw_settings
:
8017 iwl4965_unset_hw_setting(priv
);
8019 pci_iounmap(pdev
, priv
->hw_base
);
8020 out_pci_release_regions
:
8021 pci_release_regions(pdev
);
8022 pci_set_drvdata(pdev
, NULL
);
8023 out_pci_disable_device
:
8024 pci_disable_device(pdev
);
8025 out_ieee80211_free_hw
:
8026 ieee80211_free_hw(priv
->hw
);
8031 static void __devexit
iwl4965_pci_remove(struct pci_dev
*pdev
)
8033 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
8034 struct list_head
*p
, *q
;
8036 unsigned long flags
;
8041 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
8043 if (priv
->mac80211_registered
) {
8044 ieee80211_unregister_hw(priv
->hw
);
8045 priv
->mac80211_registered
= 0;
8048 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
8052 /* make sure we flush any pending irq or
8053 * tasklet for the driver
8055 spin_lock_irqsave(&priv
->lock
, flags
);
8056 iwl4965_disable_interrupts(priv
);
8057 spin_unlock_irqrestore(&priv
->lock
, flags
);
8059 iwl_synchronize_irq(priv
);
8061 /* Free MAC hash list for ADHOC */
8062 for (i
= 0; i
< IWL_IBSS_MAC_HASH_SIZE
; i
++) {
8063 list_for_each_safe(p
, q
, &priv
->ibss_mac_hash
[i
]) {
8065 kfree(list_entry(p
, struct iwl4965_ibss_seq
, list
));
8069 iwlcore_low_level_notify(priv
, IWLCORE_REMOVE_EVT
);
8070 iwl_dbgfs_unregister(priv
);
8071 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
8073 iwl4965_dealloc_ucode_pci(priv
);
8076 iwl4965_rx_queue_free(priv
, &priv
->rxq
);
8077 iwl4965_hw_txq_ctx_free(priv
);
8079 iwl4965_unset_hw_setting(priv
);
8080 iwlcore_clear_stations_table(priv
);
8083 /*netif_stop_queue(dev); */
8084 flush_workqueue(priv
->workqueue
);
8086 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
8087 * priv->workqueue... so we can't take down the workqueue
8089 destroy_workqueue(priv
->workqueue
);
8090 priv
->workqueue
= NULL
;
8092 pci_iounmap(pdev
, priv
->hw_base
);
8093 pci_release_regions(pdev
);
8094 pci_disable_device(pdev
);
8095 pci_set_drvdata(pdev
, NULL
);
8097 iwl_free_channel_map(priv
);
8098 iwl4965_free_geos(priv
);
8100 if (priv
->ibss_beacon
)
8101 dev_kfree_skb(priv
->ibss_beacon
);
8103 ieee80211_free_hw(priv
->hw
);
8108 static int iwl4965_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
8110 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
8112 if (priv
->is_open
) {
8113 set_bit(STATUS_IN_SUSPEND
, &priv
->status
);
8114 iwl4965_mac_stop(priv
->hw
);
8118 pci_set_power_state(pdev
, PCI_D3hot
);
8123 static int iwl4965_pci_resume(struct pci_dev
*pdev
)
8125 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
8127 pci_set_power_state(pdev
, PCI_D0
);
8130 iwl4965_mac_start(priv
->hw
);
8132 clear_bit(STATUS_IN_SUSPEND
, &priv
->status
);
8136 #endif /* CONFIG_PM */
8138 /*****************************************************************************
8140 * driver and module entry point
8142 *****************************************************************************/
8144 static struct pci_driver iwl4965_driver
= {
8146 .id_table
= iwl4965_hw_card_ids
,
8147 .probe
= iwl4965_pci_probe
,
8148 .remove
= __devexit_p(iwl4965_pci_remove
),
8150 .suspend
= iwl4965_pci_suspend
,
8151 .resume
= iwl4965_pci_resume
,
8155 static int __init
iwl4965_init(void)
8159 printk(KERN_INFO DRV_NAME
": " DRV_DESCRIPTION
", " DRV_VERSION
"\n");
8160 printk(KERN_INFO DRV_NAME
": " DRV_COPYRIGHT
"\n");
8162 ret
= iwl4965_rate_control_register();
8164 IWL_ERROR("Unable to register rate control algorithm: %d\n", ret
);
8168 ret
= pci_register_driver(&iwl4965_driver
);
8170 IWL_ERROR("Unable to initialize PCI module\n");
8171 goto error_register
;
8173 #ifdef CONFIG_IWLWIFI_DEBUG
8174 ret
= driver_create_file(&iwl4965_driver
.driver
, &driver_attr_debug_level
);
8176 IWL_ERROR("Unable to create driver sysfs file\n");
8183 #ifdef CONFIG_IWLWIFI_DEBUG
8185 pci_unregister_driver(&iwl4965_driver
);
8188 iwl4965_rate_control_unregister();
8192 static void __exit
iwl4965_exit(void)
8194 #ifdef CONFIG_IWLWIFI_DEBUG
8195 driver_remove_file(&iwl4965_driver
.driver
, &driver_attr_debug_level
);
8197 pci_unregister_driver(&iwl4965_driver
);
8198 iwl4965_rate_control_unregister();
8201 module_exit(iwl4965_exit
);
8202 module_init(iwl4965_init
);